Skip to content

Commit

Permalink
Bring in arduino libraries and PCD8544 libraries to support Nokia LCD…
Browse files Browse the repository at this point in the history
… display of temp, status
  • Loading branch information
Lawrence committed Jan 16, 2012
1 parent 505998e commit 19e2c0d
Show file tree
Hide file tree
Showing 38 changed files with 13,097 additions and 14 deletions.
3 changes: 2 additions & 1 deletion README.mediawiki
Expand Up @@ -8,7 +8,7 @@ I've made the following modififcations:
* Fixed USB serial sync issues and SPI read issues encountered
* Ability to use a single thermocouple, SSR
* Optionally turn off temp moving average (Since it'll likely slow pid response rate)
* Nokia 3310 LCD support
=== Warnings ===

Expand All @@ -25,6 +25,7 @@ Here's the expected pin configuration:
* <code>C6</code> MAX6675 CS (Bottom, Optional, untested)
* <code>D0,D1</code> Zero cross detector reserved (Unimplemented)
* <code>D2,D3</code> Uart1 (Reserved)
* <code>F0,1,4,5,6</code> LCD RST,CS,D/C,DIN/MOSI,SCLK (Note: this is through a 5v to 3.3v 4050D level shifter!!)
* <code>D6,D7</code> Solid state relay Top, Bottom (Active-low. Pullups recommended)
* <code>E6</code> Status LED (active high, to match arduino conventions unfortunately)
Expand Down
15 changes: 11 additions & 4 deletions avr/Makefile
@@ -1,6 +1,6 @@
# Hey Emacs, this is a -*- makefile -*-
#----------------------------------------------------------------------------
# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al.
# WinAVR Makefile Template written by Eric B. Weddington, J�rg Wunsch, et al.
#
# Released to the Public Domain
#
Expand Down Expand Up @@ -45,7 +45,8 @@ TARGET = ovencon


# List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c oven_ssr.c oven_timing.c oven_pid.c oven_profile.c max6675.c usb_serial.c
SRC = oven_ssr.c oven_timing.c oven_pid.c oven_profile.c max6675.c usb_serial.c arduino/wiring.c arduino/pins_teensy.c
#$(TARGET).c oven_ssr.c oven_timing.c oven_pid.c oven_profile.c max6676.c usb_serial.c


# MCU name, you MUST set this to match the board you are using
Expand Down Expand Up @@ -76,7 +77,7 @@ OBJDIR = .


# List C++ source files here. (C dependencies are automatically generated.)
CPPSRC =
CPPSRC = $(TARGET).cpp arduino/WInterrupts.cpp arduino/wiring.cpp arduino/PCD8544.cpp arduino/Print.cpp arduino/WString.cpp


# List Assembler source files here.
Expand Down Expand Up @@ -106,7 +107,7 @@ DEBUG = dwarf-2
# Each directory must be seperated by a space.
# Use forward slashes for directory separators.
# For a directory that has spaces, enclose it in quotes.
EXTRAINCDIRS =
EXTRAINCDIRS = arduino


# Compiler flag to set the C Standard level.
Expand Down Expand Up @@ -591,6 +592,12 @@ clean_list :
$(REMOVE) $(TARGET).map
$(REMOVE) $(TARGET).sym
$(REMOVE) $(TARGET).lss
$(REMOVE) $(TARGET).o
$(REMOVE) $(CPPSRC:%.cpp=$(OBJDIR)/%.o)
$(REMOVE) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst)
$(REMOVE) $(CPPSRC:%.cpp=$(OBJDIR)/%.s)
$(REMOVE) $(CPPSRC:%.cpp=$(OBJDIR)/%.d)
$(REMOVE) $(CPPSRC:%.cpp=$(OBJDIR)/%.i)
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o)
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst)
$(REMOVE) $(SRC:.c=.s)
Expand Down
170 changes: 170 additions & 0 deletions avr/arduino/HardwareSerial.cpp
@@ -0,0 +1,170 @@
/* UART (hardware serial) for Teensy & Teensy++
* http://www.pjrc.com/teensy/
* Copyright (c) 2008 PJRC.COM, LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#include <avr/io.h>
#include <avr/interrupt.h>
#include "core_pins.h"
#include "HardwareSerial.h"

#define RX_BUFFER_SIZE 64
static volatile uint8_t rx_buffer[RX_BUFFER_SIZE];
static volatile uint8_t rx_buffer_head = 0;
static volatile uint8_t rx_buffer_tail = 0;

#define TX_BUFFER_SIZE 40
static volatile uint8_t tx_buffer[TX_BUFFER_SIZE];
static volatile uint8_t tx_buffer_head = 0;
static volatile uint8_t tx_buffer_tail = 0;
static volatile uint8_t transmitting = 0;
static volatile uint8_t tx_enable_pin = 255;

// Public Methods //////////////////////////////////////////////////////////////

void HardwareSerial::_begin(uint16_t baud_count, uint8_t txen_pin)
{
tx_enable_pin = txen_pin;
if (txen_pin < 255) {
pinMode(txen_pin, OUTPUT);
digitalWrite(txen_pin, LOW);
}
if (baud_count & 1) {
UCSR1A = (1<<U2X1);
UBRR1 = baud_count - 1;
} else {
UCSR1A = 0;
UBRR1 = (baud_count >> 1) - 1;
}
if (!(UCSR1B & (1<<TXEN1))) {
rx_buffer_head = 0;
rx_buffer_tail = 0;
tx_buffer_head = 0;
tx_buffer_tail = 0;
transmitting = 0;
UCSR1C = (1<<UCSZ11) | (1<<UCSZ10);
UCSR1B = (1<<RXEN1) | (1<<TXCIE1) | (1<<TXEN1) | (1<<RXCIE1);
}
}

void HardwareSerial::end(void)
{
while (transmitting) ; // wait for buffered data to send
UCSR1B = 0;
rx_buffer_head = 0;
rx_buffer_tail = 0;
}

int HardwareSerial::available(void)
{
uint8_t head, tail;

head = rx_buffer_head;
tail = rx_buffer_tail;
if (head >= tail) return head - tail;
return RX_BUFFER_SIZE + head - tail;
}

int HardwareSerial::peek(void)
{
uint8_t head, tail;

head = rx_buffer_head;
tail = rx_buffer_tail;
if (head == tail) return -1;
return rx_buffer[tail];
}

int HardwareSerial::read(void)
{
uint8_t c, i;

if (rx_buffer_head == rx_buffer_tail) return -1;
i = rx_buffer_tail + 1;
if (i >= RX_BUFFER_SIZE) i = 0;
c = rx_buffer[i];
rx_buffer_tail = i;
return c;
}

void HardwareSerial::flush()
{
rx_buffer_head = rx_buffer_tail;
}

void HardwareSerial::write(uint8_t c)
{
uint8_t i;

if (!(UCSR1B & (1<<TXEN1))) return;
if (tx_enable_pin < 255 && !transmitting) {
digitalWrite(tx_enable_pin, HIGH);
}
i = tx_buffer_head + 1;
if (i >= TX_BUFFER_SIZE) i = 0;
while (tx_buffer_tail == i) ; // wait until space in buffer
tx_buffer[i] = c;
transmitting = 1;
tx_buffer_head = i;
UCSR1B = (1<<RXEN1) | (1<<TXCIE1) | (1<<TXEN1) | (1<<RXCIE1) | (1<<UDRIE1);
}

ISR(USART1_RX_vect)
{
uint8_t c, i;

c = UDR1;
i = rx_buffer_head + 1;
if (i >= RX_BUFFER_SIZE) i = 0;
if (i != rx_buffer_tail) {
rx_buffer[i] = c;
rx_buffer_head = i;
}
}

ISR(USART1_UDRE_vect)
{
uint8_t i;

if (tx_buffer_head == tx_buffer_tail) {
// buffer is empty, disable transmit interrupt
UCSR1B = (1<<RXEN1) | (1<<TXCIE1) | (1<<TXEN1) | (1<<RXCIE1);
} else {
i = tx_buffer_tail + 1;
if (i >= TX_BUFFER_SIZE) i = 0;
UDR1 = tx_buffer[i];
tx_buffer_tail = i;
}
}

ISR(USART1_TX_vect)
{
transmitting = 0;
if (tx_enable_pin < 255) {
digitalWrite(tx_enable_pin, LOW);
}
}

// Preinstantiate Objects //////////////////////////////////////////////////////

// On Teensy the "Serial" object maps to USB. If the user wants to
// the UART, they need to instantiate this object themselves.
// http://www.pjrc.com/teensy/td_uart.html
24 changes: 24 additions & 0 deletions avr/arduino/HardwareSerial.h
@@ -0,0 +1,24 @@
#ifndef HardwareSerial_h
#define HardwareSerial_h

#include <inttypes.h>
#include "Stream.h"

class HardwareSerial : public Stream
{
public:
inline void begin(uint32_t baud, uint8_t txen_pin=255) {
//_begin((F_CPU / 4 / baud - 1) / 2, pin);
_begin(((F_CPU / 8) + (baud / 2)) / baud, txen_pin);
}
void _begin(uint16_t baud_count, uint8_t pin);
void end(void);
virtual int available(void);
virtual int peek(void);
virtual int read(void);
virtual void flush(void);
virtual void write(uint8_t);
using Print::write;
};

#endif

0 comments on commit 19e2c0d

Please sign in to comment.