aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino/HardwareSerial.h
diff options
context:
space:
mode:
Diffstat (limited to 'cores/arduino/HardwareSerial.h')
-rw-r--r--cores/arduino/HardwareSerial.h95
1 files changed, 48 insertions, 47 deletions
diff --git a/cores/arduino/HardwareSerial.h b/cores/arduino/HardwareSerial.h
index 0f62262..226bf57 100644
--- a/cores/arduino/HardwareSerial.h
+++ b/cores/arduino/HardwareSerial.h
@@ -18,6 +18,7 @@
Modified 28 September 2010 by Mark Sproul
Modified 14 August 2012 by Alarus
+ Modified 3 December 2013 by Matthijs Kooijman
*/
#ifndef HardwareSerial_h
@@ -37,23 +38,44 @@
#define SERIAL_BUFFER_SIZE 64
#endif
+// Define config for Serial.begin(baud, config);
+#define SERIAL_5N1 0x00
+#define SERIAL_6N1 0x02
+#define SERIAL_7N1 0x04
+#define SERIAL_8N1 0x06
+#define SERIAL_5N2 0x08
+#define SERIAL_6N2 0x0A
+#define SERIAL_7N2 0x0C
+#define SERIAL_8N2 0x0E
+#define SERIAL_5E1 0x20
+#define SERIAL_6E1 0x22
+#define SERIAL_7E1 0x24
+#define SERIAL_8E1 0x26
+#define SERIAL_5E2 0x28
+#define SERIAL_6E2 0x2A
+#define SERIAL_7E2 0x2C
+#define SERIAL_8E2 0x2E
+#define SERIAL_5O1 0x30
+#define SERIAL_6O1 0x32
+#define SERIAL_7O1 0x34
+#define SERIAL_8O1 0x36
+#define SERIAL_5O2 0x38
+#define SERIAL_6O2 0x3A
+#define SERIAL_7O2 0x3C
+#define SERIAL_8O2 0x3E
+
class HardwareSerial : public Stream
{
protected:
- volatile uint8_t *_ubrrh;
- volatile uint8_t *_ubrrl;
- volatile uint8_t *_ucsra;
- volatile uint8_t *_ucsrb;
- volatile uint8_t *_ucsrc;
- volatile uint8_t *_udr;
- uint8_t _rxen;
- uint8_t _txen;
- uint8_t _rxcie;
- uint8_t _udrie;
- uint8_t _u2x;
- bool transmitting;
+ volatile uint8_t * const _ubrrh;
+ volatile uint8_t * const _ubrrl;
+ volatile uint8_t * const _ucsra;
+ volatile uint8_t * const _ucsrb;
+ volatile uint8_t * const _ucsrc;
+ volatile uint8_t * const _udr;
+ // Has any byte been written to the UART since begin()
+ bool _written;
- public:
volatile uint8_t _rx_buffer_head;
volatile uint8_t _rx_buffer_tail;
volatile uint8_t _tx_buffer_head;
@@ -65,12 +87,12 @@ class HardwareSerial : public Stream
unsigned char _rx_buffer[SERIAL_BUFFER_SIZE];
unsigned char _tx_buffer[SERIAL_BUFFER_SIZE];
- HardwareSerial(
+ public:
+ inline HardwareSerial(
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
- volatile uint8_t *ucsrc, volatile uint8_t *udr,
- uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udrie, uint8_t u2x);
- void begin(unsigned long);
+ volatile uint8_t *ucsrc, volatile uint8_t *udr);
+ void begin(unsigned long baud) { begin(baud, SERIAL_8N1); }
void begin(unsigned long, uint8_t);
void end();
virtual int available(void);
@@ -83,49 +105,28 @@ class HardwareSerial : public Stream
inline size_t write(unsigned int n) { return write((uint8_t)n); }
inline size_t write(int n) { return write((uint8_t)n); }
using Print::write; // pull in write(str) and write(buf, size) from Print
- operator bool();
-};
+ operator bool() { return true; }
-// Define config for Serial.begin(baud, config);
-#define SERIAL_5N1 0x00
-#define SERIAL_6N1 0x02
-#define SERIAL_7N1 0x04
-#define SERIAL_8N1 0x06
-#define SERIAL_5N2 0x08
-#define SERIAL_6N2 0x0A
-#define SERIAL_7N2 0x0C
-#define SERIAL_8N2 0x0E
-#define SERIAL_5E1 0x20
-#define SERIAL_6E1 0x22
-#define SERIAL_7E1 0x24
-#define SERIAL_8E1 0x26
-#define SERIAL_5E2 0x28
-#define SERIAL_6E2 0x2A
-#define SERIAL_7E2 0x2C
-#define SERIAL_8E2 0x2E
-#define SERIAL_5O1 0x30
-#define SERIAL_6O1 0x32
-#define SERIAL_7O1 0x34
-#define SERIAL_8O1 0x36
-#define SERIAL_5O2 0x38
-#define SERIAL_6O2 0x3A
-#define SERIAL_7O2 0x3C
-#define SERIAL_8O2 0x3E
+ // Interrupt handlers - Not intended to be called externally
+ inline void _rx_complete_irq(void);
+ void _tx_udr_empty_irq(void);
+};
#if defined(UBRRH) || defined(UBRR0H)
extern HardwareSerial Serial;
-#elif defined(USBCON)
- #include "USBAPI.h"
-// extern HardwareSerial Serial_;
+ #define HAVE_HWSERIAL0
#endif
#if defined(UBRR1H)
extern HardwareSerial Serial1;
+ #define HAVE_HWSERIAL1
#endif
#if defined(UBRR2H)
extern HardwareSerial Serial2;
+ #define HAVE_HWSERIAL2
#endif
#if defined(UBRR3H)
extern HardwareSerial Serial3;
+ #define HAVE_HWSERIAL3
#endif
extern void serialEventRun(void) __attribute__((weak));