Skip to content

Commit

Permalink
Add library.properties for #11
Browse files Browse the repository at this point in the history
*  Move EXTERNAL_PCINT to header
*  Update version comments
  • Loading branch information
SlashDevin committed May 12, 2017
1 parent d6f762d commit 8f9227f
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 73 deletions.
112 changes: 58 additions & 54 deletions NeoSWSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

//-----------------------------------------------------------------------------
Expand Down
42 changes: 23 additions & 19 deletions NeoSWSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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 );
Expand All @@ -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
9 changes: 9 additions & 0 deletions library.properties
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8f9227f

Please sign in to comment.