Browse Source

Use constexpr constructors for all Serial classes

teensy4-core
PaulStoffregen 7 years ago
parent
commit
768926244c
3 changed files with 10 additions and 0 deletions
  1. +6
    -0
      teensy3/HardwareSerial.h
  2. +2
    -0
      teensy3/usb_seremu.h
  3. +2
    -0
      teensy3/usb_serial.h

+ 6
- 0
teensy3/HardwareSerial.h View File

class HardwareSerial : public Stream class HardwareSerial : public Stream
{ {
public: public:
constexpr HardwareSerial() {}
virtual void begin(uint32_t baud) { serial_begin(BAUD2DIV(baud)); } virtual void begin(uint32_t baud) { serial_begin(BAUD2DIV(baud)); }
virtual void begin(uint32_t baud, uint32_t format) { virtual void begin(uint32_t baud, uint32_t format) {
serial_begin(BAUD2DIV(baud)); serial_begin(BAUD2DIV(baud));
class HardwareSerial2 : public HardwareSerial class HardwareSerial2 : public HardwareSerial
{ {
public: public:
constexpr HardwareSerial2() {}
virtual void begin(uint32_t baud) { serial2_begin(BAUD2DIV2(baud)); } virtual void begin(uint32_t baud) { serial2_begin(BAUD2DIV2(baud)); }
virtual void begin(uint32_t baud, uint32_t format) { virtual void begin(uint32_t baud, uint32_t format) {
serial2_begin(BAUD2DIV2(baud)); serial2_begin(BAUD2DIV2(baud));
class HardwareSerial3 : public HardwareSerial class HardwareSerial3 : public HardwareSerial
{ {
public: public:
constexpr HardwareSerial3() {}
virtual void begin(uint32_t baud) { serial3_begin(BAUD2DIV3(baud)); } virtual void begin(uint32_t baud) { serial3_begin(BAUD2DIV3(baud)); }
virtual void begin(uint32_t baud, uint32_t format) { virtual void begin(uint32_t baud, uint32_t format) {
serial3_begin(BAUD2DIV3(baud)); serial3_begin(BAUD2DIV3(baud));
class HardwareSerial4 : public HardwareSerial class HardwareSerial4 : public HardwareSerial
{ {
public: public:
constexpr HardwareSerial4() {}
virtual void begin(uint32_t baud) { serial4_begin(BAUD2DIV3(baud)); } virtual void begin(uint32_t baud) { serial4_begin(BAUD2DIV3(baud)); }
virtual void begin(uint32_t baud, uint32_t format) { virtual void begin(uint32_t baud, uint32_t format) {
serial4_begin(BAUD2DIV3(baud)); serial4_begin(BAUD2DIV3(baud));
class HardwareSerial5 : public HardwareSerial class HardwareSerial5 : public HardwareSerial
{ {
public: public:
constexpr HardwareSerial5() {}
virtual void begin(uint32_t baud) { serial5_begin(BAUD2DIV3(baud)); } virtual void begin(uint32_t baud) { serial5_begin(BAUD2DIV3(baud)); }
virtual void begin(uint32_t baud, uint32_t format) { virtual void begin(uint32_t baud, uint32_t format) {
serial5_begin(BAUD2DIV3(baud)); serial5_begin(BAUD2DIV3(baud));
class HardwareSerial6 : public HardwareSerial class HardwareSerial6 : public HardwareSerial
{ {
public: public:
constexpr HardwareSerial6() {}
#if defined(__MK66FX1M0__) // For LPUART just pass baud straight in. #if defined(__MK66FX1M0__) // For LPUART just pass baud straight in.
virtual void begin(uint32_t baud) { serial6_begin(baud); } virtual void begin(uint32_t baud) { serial6_begin(baud); }
virtual void begin(uint32_t baud, uint32_t format) { virtual void begin(uint32_t baud, uint32_t format) {

+ 2
- 0
teensy3/usb_seremu.h View File

class usb_seremu_class : public Stream class usb_seremu_class : public Stream
{ {
public: public:
constexpr usb_seremu_class() {}
void begin(long) { /* TODO: call a function that tries to wait for enumeration */ }; void begin(long) { /* TODO: call a function that tries to wait for enumeration */ };
void end() { /* TODO: flush output and shut down USB port */ }; void end() { /* TODO: flush output and shut down USB port */ };
virtual int available() { return usb_seremu_available(); } virtual int available() { return usb_seremu_available(); }
class usb_seremu_class : public Stream class usb_seremu_class : public Stream
{ {
public: public:
constexpr usb_seremu_class() {}
void begin(long) { }; void begin(long) { };
void end() { }; void end() { };
virtual int available() { return 0; } virtual int available() { return 0; }

+ 2
- 0
teensy3/usb_serial.h View File

class usb_serial_class : public Stream class usb_serial_class : public Stream
{ {
public: public:
constexpr usb_serial_class() {}
void begin(long) { void begin(long) {
uint32_t millis_begin = systick_millis_count; uint32_t millis_begin = systick_millis_count;
while (!(*this)) { while (!(*this)) {
class usb_serial_class : public Stream class usb_serial_class : public Stream
{ {
public: public:
constexpr usb_serial_class() {}
void begin(long) { }; void begin(long) { };
void end() { }; void end() { };
virtual int available() { return 0; } virtual int available() { return 0; }

Loading…
Cancel
Save