From 8f9227fbd599743f3313b99c5d3a29222d4b1446 Mon Sep 17 00:00:00 2001 From: SlashDevin Date: Fri, 12 May 2017 16:23:26 -0400 Subject: [PATCH] Add library.properties for #11 * Move EXTERNAL_PCINT to header * Update version comments --- NeoSWSerial.cpp | 112 +++++++++++++++++++++++---------------------- NeoSWSerial.h | 42 +++++++++-------- library.properties | 9 ++++ 3 files changed, 90 insertions(+), 73 deletions(-) create mode 100644 library.properties diff --git a/NeoSWSerial.cpp b/NeoSWSerial.cpp index 28fd3c3..9e1d703 100644 --- a/NeoSWSerial.cpp +++ b/NeoSWSerial.cpp @@ -410,84 +410,88 @@ void NeoSWSerial::rxChar( uint8_t c ) } // rxChar -#ifndef NEOSWSERIAL_EXTERNAL_PCINT //---------------------------------------------------------------------------- -// Must define all of the vectors even though only one is used. -// This handy PCINT code for different boards is based on PinChangeInterrupt.* -// from the excellent Cosa project: http://github.com/mikaelpatel/Cosa +#ifdef NEOSWSERIAL_EXTERNAL_PCINT -#define PCINT_ISR(vec,pin) \ -extern "C" { \ -ISR(PCINT ## vec ## _vect) \ -{ \ - NeoSWSerial::rxISR(pin); \ -} } + // Client code must call NeoSWSerial::rxISR(PINB) in PCINT handler -#if defined(__AVR_ATtiny261__) | \ - defined(__AVR_ATtiny461__) | \ - defined(__AVR_ATtiny861__) +#else -ISR(PCINT0_vect) -{ - if (GIFR & _BV(INTF0)) { - NeoSWSerial::rxISR(PINA); - } else { - NeoSWSerial::rxISR(PINB); + // Must define all of the vectors even though only one is used. + + // This handy PCINT code for different boards is based on PinChangeInterrupt.* + // from the excellent Cosa project: http://github.com/mikaelpatel/Cosa + + #define PCINT_ISR(vec,pin) \ + extern "C" { \ + ISR(PCINT ## vec ## _vect) \ + { \ + NeoSWSerial::rxISR(pin); \ + } } + + #if defined(__AVR_ATtiny261__) | \ + defined(__AVR_ATtiny461__) | \ + defined(__AVR_ATtiny861__) + + ISR(PCINT0_vect) + { + if (GIFR & _BV(INTF0)) { + NeoSWSerial::rxISR(PINA); + } else { + NeoSWSerial::rxISR(PINB); + } } -} -#elif defined(__AVR_ATtiny25__) | \ - defined(__AVR_ATtiny45__) | \ - defined(__AVR_ATtiny85__) + #elif defined(__AVR_ATtiny25__) | \ + defined(__AVR_ATtiny45__) | \ + defined(__AVR_ATtiny85__) -PCINT_ISR(0, PINB); + PCINT_ISR(0, PINB); -#elif defined(__AVR_ATtiny24__) | \ - defined(__AVR_ATtiny44__) | \ - defined(__AVR_ATtiny84__) + #elif defined(__AVR_ATtiny24__) | \ + defined(__AVR_ATtiny44__) | \ + defined(__AVR_ATtiny84__) -PCINT_ISR(0, PINA); -PCINT_ISR(1, PINB); + PCINT_ISR(0, PINA); + PCINT_ISR(1, PINB); -#elif defined(__AVR_ATmega328P__) + #elif defined(__AVR_ATmega328P__) -PCINT_ISR(0, PINB); -PCINT_ISR(1, PINC); -PCINT_ISR(2, PIND); + PCINT_ISR(0, PINB); + PCINT_ISR(1, PINC); + PCINT_ISR(2, PIND); -#elif defined(__AVR_ATmega32U4__) + #elif defined(__AVR_ATmega32U4__) -PCINT_ISR(0, PINB); + PCINT_ISR(0, PINB); -#elif defined(__AVR_AT90USB1286__) + #elif defined(__AVR_AT90USB1286__) -PCINT_ISR(0, PINB); + PCINT_ISR(0, PINB); -#elif defined(__AVR_ATmega2560__) + #elif defined(__AVR_ATmega2560__) -PCINT_ISR(0, PINB); -PCINT_ISR(1, PINJ); -PCINT_ISR(2, PINK); + PCINT_ISR(0, PINB); + PCINT_ISR(1, PINJ); + PCINT_ISR(2, PINK); -#elif defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644P__) + #elif defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644P__) -PCINT_ISR(0, PINA); -PCINT_ISR(1, PINB); -PCINT_ISR(2, PINC); -PCINT_ISR(3, PIND); + PCINT_ISR(0, PINA); + PCINT_ISR(1, PINB); + PCINT_ISR(2, PINC); + PCINT_ISR(3, PIND); -#elif defined(__AVR_ATmega2560RFR2__) + #elif defined(__AVR_ATmega2560RFR2__) -PCINT_ISR(0, PINB); -PCINT_ISR(1, PINE); + PCINT_ISR(0, PINB); + PCINT_ISR(1, PINE); -#else - #error MCU not supported by NeoSWSerial! -#endif + #else + #error MCU not supported by NeoSWSerial! + #endif -#else -// It's assumed that client code will call NeoSWSerial::rxISR(PINB) in PCINT handler #endif //----------------------------------------------------------------------------- diff --git a/NeoSWSerial.h b/NeoSWSerial.h index 8c20055..0b56bdb 100644 --- a/NeoSWSerial.h +++ b/NeoSWSerial.h @@ -47,15 +47,17 @@ // service routines, the buffer size should be chosen to be a // power of 2 (i.e., 2, 4, 8, 16, 32, 64,...). // -// Nov/Dec 2014 jboyton - Created -// Jun 2015 jboyton - Added support for 8 MHz system clock. Timer 2 had to -// be used since the timer 0 prescaler was inadequate -// for this. The supported baud rates for 8 MHz are 9600 -// and 19200. -// Nov 2015 SlashDev - Add support for other boards, -// add end() and attach/detachInterrupt -// Jun 2016 SlashDev - Add support for all character values -// Mar 2017 SlashDev - Add GPL +// v1.0 Nov 2014 jboyton - Created +// v1.1 Jun 2015 jboyton - Added support for 8 MHz system clock. Timer 2 had to +// be used since the timer 0 prescaler was inadequate +// for this. The supported baud rates for 8 MHz are 9600 +// and 19200. +// v2.0 Nov 2015 SlashDev - Add support for other boards, +// add end() and attach/detachInterrupt +// v2.1 Jun 2016 SlashDev - Add support for all character values +// v2.2 Mar 2017 Dionorgua - Add option to disable pre-defined PCINT ISRs. +// v2.3 Mar 2017 SlashDev - Add GPL +// v3.0.0 May 2017 SlashDev - Convert to new Arduino IDE library class NeoSWSerial : public Stream { @@ -70,16 +72,16 @@ class NeoSWSerial : public Stream _isr = (isr_t) NULL; } - void begin(uint16_t baudRate=9600); // initialize, set baudrate, listen - void listen(); // enable RX interrupts - void ignore(); // disable RX interrupts - void setBaudRate(uint16_t baudRate); // set baud rate (9600 [default], 19200, 38400) - int available(); // returns number of characters in buffer - int read(); // get one character from buffer - size_t write(uint8_t txChar); // transmit a character - virtual int peek() { return 0; }; - virtual void flush() {}; - void end() { ignore(); } + void begin(uint16_t baudRate=9600); // initialize, set baudrate, listen + void listen(); // enable RX interrupts + void ignore(); // disable RX interrupts + void setBaudRate(uint16_t baudRate); // 9600 [default], 19200, 38400 + virtual int available(); + virtual int read(); + virtual size_t write(uint8_t txChar); + virtual int peek() { return 0; }; + virtual void flush() {}; + void end() { ignore(); } typedef void (* isr_t)( uint8_t ); void attachInterrupt( isr_t fn ); @@ -101,5 +103,7 @@ class NeoSWSerial : public Stream public: // visible only so the ISRs can call it... static void rxISR( uint8_t port_input_register ); + + //#define NEOSWSERIAL_EXTERNAL_PCINT // uncomment to use your own PCINT ISRs }; #endif diff --git a/library.properties b/library.properties new file mode 100644 index 0000000..1a6624d --- /dev/null +++ b/library.properties @@ -0,0 +1,9 @@ +name=NeoSWSerial +version=3.0.0 +author=SlashDevin +maintainer=SlashDevin +sentence=An efficient replacement for SoftwareSerial at baud rates 9600, 19200 and 38400. +category=Communication +url=https://github.com/SlashDevin/NeoSWSerial +architectures=avr +includes=NeoSWSerial.h