Make serial work with most chips by default

This commit is contained in:
Elmo Mäntynen 2013-07-21 12:45:45 +03:00
parent fc5c497256
commit 8c781e155c
2 changed files with 16 additions and 10 deletions

View File

@ -91,11 +91,7 @@ void serial_write(uint8_t data) {
} }
// Data Register Empty Interrupt handler // Data Register Empty Interrupt handler
#ifdef __AVR_ATmega644P__ ISR(Serial_UDRE_vect)
ISR(USART0_UDRE_vect)
#else
ISR(USART_UDRE_vect)
#endif
{ {
// Temporary tx_buffer_tail (to optimize for volatile) // Temporary tx_buffer_tail (to optimize for volatile)
uint8_t tail = tx_buffer_tail; uint8_t tail = tx_buffer_tail;
@ -144,11 +140,7 @@ uint8_t serial_read()
} }
} }
#ifdef __AVR_ATmega644P__ ISR(Serial_RX_vect)
ISR(USART0_RX_vect)
#else
ISR(USART_RX_vect)
#endif
{ {
uint8_t data = UDR0; uint8_t data = UDR0;
uint8_t next_head; uint8_t next_head;

View File

@ -27,6 +27,20 @@
#include "nuts_bolts.h" #include "nuts_bolts.h"
#if defined(USART_RX_vect) // For atmega328p (Arduino Uno) etc.
#define Serial_RX_vect USART_RX_vect
#define Serial_UDRE_vect USART_UDRE_vect
#elif defined(USART0_RX_vect) // For atmega644p, atmega1280 and atmega2560 (ArduinoMEGA) etc.
#define Serial_RX_vect USART0_RX_vect
#define Serial_UDRE_vect USART0_UDRE_vect
#elif defined(USART_RXC_vect) // For some odd chips
#define Serial_RX_vect USART_RXC_vect
#define Serial_UDRE_vect USART_UDRE_vect
#elif defined(USART1_RX_vect)// Some AVRs have 1 USB and a single USART (USART1), though the USB is often preffered for serial comms (like Arduino Leonardo etc.)
#define Serial1_RX_vect USART1_RX_vect
#define Serial1_UDRE_vect USART1_UDRE_vect
#endif
#ifndef RX_BUFFER_SIZE #ifndef RX_BUFFER_SIZE
#define RX_BUFFER_SIZE 128 #define RX_BUFFER_SIZE 128
#endif #endif