@@ -101,6 +101,7 @@ void serial_set_transmit_pin(uint8_t pin); | |||
void serial_putchar(uint32_t c); | |||
void serial_write(const void *buf, unsigned int count); | |||
void serial_flush(void); | |||
int serial_room(void); | |||
int serial_available(void); | |||
int serial_getchar(void); | |||
int serial_peek(void); | |||
@@ -116,6 +117,7 @@ void serial2_end(void); | |||
void serial2_putchar(uint32_t c); | |||
void serial2_write(const void *buf, unsigned int count); | |||
void serial2_flush(void); | |||
int serial2_room(void); | |||
int serial2_available(void); | |||
int serial2_getchar(void); | |||
int serial2_peek(void); | |||
@@ -127,6 +129,7 @@ void serial3_end(void); | |||
void serial3_putchar(uint32_t c); | |||
void serial3_write(const void *buf, unsigned int count); | |||
void serial3_flush(void); | |||
int serial3_room(void); | |||
int serial3_available(void); | |||
int serial3_getchar(void); | |||
int serial3_peek(void); | |||
@@ -155,6 +158,7 @@ public: | |||
virtual int read(void) { return serial_getchar(); } | |||
virtual void flush(void) { serial_flush(); } | |||
virtual void clear(void) { serial_clear(); } | |||
virtual int room(void) { return serial_room(); } | |||
virtual size_t write(uint8_t c) { serial_putchar(c); return 1; } | |||
virtual size_t write(unsigned long n) { return write((uint8_t)n); } | |||
virtual size_t write(long n) { return write((uint8_t)n); } | |||
@@ -168,6 +172,7 @@ public: | |||
virtual size_t write9bit(uint32_t c) { serial_putchar(c); return 1; } | |||
}; | |||
extern HardwareSerial Serial1; | |||
extern void serialEvent1(void); | |||
class HardwareSerial2 : public HardwareSerial | |||
{ | |||
@@ -182,6 +187,7 @@ public: | |||
virtual int read(void) { return serial2_getchar(); } | |||
virtual void flush(void) { serial2_flush(); } | |||
virtual void clear(void) { serial2_clear(); } | |||
virtual int room(void) { return serial2_room(); } | |||
virtual size_t write(uint8_t c) { serial2_putchar(c); return 1; } | |||
virtual size_t write(unsigned long n) { return write((uint8_t)n); } | |||
virtual size_t write(long n) { return write((uint8_t)n); } | |||
@@ -195,6 +201,7 @@ public: | |||
virtual size_t write9bit(uint32_t c) { serial2_putchar(c); return 1; } | |||
}; | |||
extern HardwareSerial2 Serial2; | |||
extern void serialEvent2(void); | |||
class HardwareSerial3 : public HardwareSerial | |||
{ | |||
@@ -209,6 +216,7 @@ public: | |||
virtual int read(void) { return serial3_getchar(); } | |||
virtual void flush(void) { serial3_flush(); } | |||
virtual void clear(void) { serial3_clear(); } | |||
virtual int room(void) { return serial3_room(); } | |||
virtual size_t write(uint8_t c) { serial3_putchar(c); return 1; } | |||
virtual size_t write(unsigned long n) { return write((uint8_t)n); } | |||
virtual size_t write(long n) { return write((uint8_t)n); } | |||
@@ -222,6 +230,7 @@ public: | |||
virtual size_t write9bit(uint32_t c) { serial3_putchar(c); return 1; } | |||
}; | |||
extern HardwareSerial3 Serial3; | |||
extern void serialEvent3(void); | |||
#endif | |||
#endif |
@@ -2,3 +2,5 @@ | |||
HardwareSerial Serial1; | |||
void serialEvent1() __attribute__((weak)); | |||
void serialEvent1() {} |
@@ -2,3 +2,5 @@ | |||
HardwareSerial2 Serial2; | |||
void serialEvent2() __attribute__((weak)); | |||
void serialEvent2() {} |
@@ -2,3 +2,5 @@ | |||
HardwareSerial3 Serial3; | |||
void serialEvent3() __attribute__((weak)); | |||
void serialEvent3() {} |
@@ -107,7 +107,30 @@ static inline uint8_t digitalPinToTimer(uint8_t pin) | |||
return NOT_ON_TIMER; | |||
} | |||
// These serial port names are intended to allow libraries and architecture-neutral | |||
// sketches to automatically default to the correct port name for a particular type | |||
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN, | |||
// the first hardware serial port whose RX/TX pins are not dedicated to another use. | |||
// | |||
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor | |||
// | |||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial | |||
// | |||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library | |||
// | |||
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins. | |||
// | |||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX | |||
// pins are NOT connected to anything by default. | |||
// | |||
#define SERIAL_PORT_MONITOR Serial | |||
#define SERIAL_PORT_USBVIRTUAL Serial | |||
#define SERIAL_PORT_HARDWARE Serial1 | |||
#define SERIAL_PORT_HARDWARE1 Serial2 | |||
#define SERIAL_PORT_HARDWARE2 Serial3 | |||
#define SERIAL_PORT_HARDWARE_OPEN Serial1 | |||
#define SERIAL_PORT_HARDWARE_OPEN1 Serial2 | |||
#define SERIAL_PORT_HARDWARE_OPEN2 Serial3 | |||
#endif |
@@ -216,6 +216,16 @@ void serial_flush(void) | |||
while (transmitting) yield(); // wait | |||
} | |||
int serial_room(void) | |||
{ | |||
uint32_t head, tail; | |||
head = tx_buffer_head; | |||
tail = tx_buffer_tail; | |||
if (head >= tail) return TX_BUFFER_SIZE - 1 - head + tail; | |||
return tail - head - 1; | |||
} | |||
int serial_available(void) | |||
{ | |||
uint32_t head, tail; |
@@ -177,6 +177,16 @@ void serial2_flush(void) | |||
while (transmitting) yield(); // wait | |||
} | |||
int serial2_room(void) | |||
{ | |||
uint32_t head, tail; | |||
head = tx_buffer_head; | |||
tail = tx_buffer_tail; | |||
if (head >= tail) return TX_BUFFER_SIZE - 1 - head + tail; | |||
return tail - head - 1; | |||
} | |||
int serial2_available(void) | |||
{ | |||
uint32_t head, tail; |
@@ -171,6 +171,16 @@ void serial3_flush(void) | |||
while (transmitting) yield(); // wait | |||
} | |||
int serial3_room(void) | |||
{ | |||
uint32_t head, tail; | |||
head = tx_buffer_head; | |||
tail = tx_buffer_tail; | |||
if (head >= tail) return TX_BUFFER_SIZE - 1 - head + tail; | |||
return tail - head - 1; | |||
} | |||
int serial3_available(void) | |||
{ | |||
uint32_t head, tail; |
@@ -77,3 +77,6 @@ usb_seremu_class Serial; | |||
#endif | |||
#endif // F_CPU | |||
void serialEvent() __attribute__((weak)); | |||
void serialEvent() {} |
@@ -84,6 +84,7 @@ public: | |||
operator bool() { return usb_configuration; } | |||
}; | |||
extern usb_seremu_class Serial; | |||
extern void serialEvent(void); | |||
#endif // __cplusplus | |||
@@ -120,6 +121,7 @@ public: | |||
}; | |||
extern usb_seremu_class Serial; | |||
extern void serialEvent(void); | |||
#endif // __cplusplus | |||
@@ -100,6 +100,7 @@ public: | |||
}; | |||
extern usb_serial_class Serial; | |||
extern void serialEvent(void); | |||
#endif // __cplusplus | |||
@@ -135,6 +136,7 @@ public: | |||
}; | |||
extern usb_serial_class Serial; | |||
extern void serialEvent(void); | |||
#endif // __cplusplus | |||
#endif // F_CPU |
@@ -1,6 +1,6 @@ | |||
/* Teensyduino Core Library | |||
* http://www.pjrc.com/teensy/ | |||
* Copyright (c) 2013 PJRC.COM, LLC. | |||
* Copyright (c) 2014 PJRC.COM, LLC. | |||
* | |||
* Permission is hereby granted, free of charge, to any person obtaining | |||
* a copy of this software and associated documentation files (the | |||
@@ -28,5 +28,21 @@ | |||
* SOFTWARE. | |||
*/ | |||
#include "core_pins.h" | |||
#include "HardwareSerial.h" | |||
#include "usb_serial.h" | |||
#include "usb_seremu.h" | |||
void yield(void) __attribute__ ((weak)); | |||
void yield(void) {}; | |||
void yield(void) | |||
{ | |||
static uint8_t running=0; | |||
if (running) return; // TODO: does this need to be atomic? | |||
running = 1; | |||
if (Serial.available()) serialEvent(); | |||
if (Serial1.available()) serialEvent1(); | |||
if (Serial2.available()) serialEvent2(); | |||
if (Serial3.available()) serialEvent3(); | |||
running = 0; | |||
}; |