Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bring in arduino libraries and PCD8544 libraries to support Nokia LCD…
… display of temp, status
- Loading branch information
Lawrence
committed
Jan 16, 2012
1 parent
505998e
commit 19e2c0d
Showing
38 changed files
with
13,097 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.