Skip to content

Commit

Permalink
Fix T3.x SerialEventX when format is passed in.
Browse files Browse the repository at this point in the history
Before there were two different begin Methods that were wrappers
to the c begin and format functions.  The code that checked for SerialEvent being defined
in a sketch was only in the begin method where format was not passed in.

Changed these to have only one begin method, with an optional format descriptor
If format is not specified I pass in: (uint32_t)-1 which the begin method checks
for if it is -1 format is not called otherwise it is.

Note: with T4.x the default was always 0 and the format code was always done, but did not want to this here on the off chance there are T3.x sketches out there where
maybe the first call SerialX.begin(baud, some-not-default-format)... and later call
SerialX.begin(baud), and expected the format not to change.
  • Loading branch information
KurtE committed Aug 14, 2024
1 parent 87a6366 commit 2b69ca9
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 37 deletions.
37 changes: 6 additions & 31 deletions teensy3/HardwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,7 @@ class HardwareSerial : public Stream
#else //(__MK64FX512__) || defined(__MK66FX1M0__)
enum {CNT_HARDWARE_SERIAL = 3};
#endif
virtual void begin(uint32_t baud);
virtual void begin(uint32_t baud, uint32_t format) {
serial_begin(BAUD2DIV(baud));
serial_format(format); }
virtual void begin(uint32_t baud, uint32_t format=(uint32_t)-1);
virtual void end(void) { serial_end(); }
virtual void transmitterEnable(uint8_t pin) { serial_set_transmit_pin(pin); }
virtual void setRX(uint8_t pin) { serial_set_rx(pin); }
Expand Down Expand Up @@ -336,10 +333,7 @@ class HardwareSerial2 : public HardwareSerial
{
public:
constexpr HardwareSerial2(void (* const se)()) : HardwareSerial(se) {}
virtual void begin(uint32_t baud);
virtual void begin(uint32_t baud, uint32_t format) {
serial2_begin(BAUD2DIV2(baud));
serial2_format(format); }
virtual void begin(uint32_t baud, uint32_t format=(uint32_t)-1);
virtual void end(void) { serial2_end(); }
virtual void transmitterEnable(uint8_t pin) { serial2_set_transmit_pin(pin); }
virtual void setRX(uint8_t pin) { serial2_set_rx(pin); }
Expand Down Expand Up @@ -375,10 +369,7 @@ class HardwareSerial3 : public HardwareSerial
{
public:
constexpr HardwareSerial3(void (* const se)()) : HardwareSerial(se) {}
virtual void begin(uint32_t baud);
virtual void begin(uint32_t baud, uint32_t format) {
serial3_begin(BAUD2DIV3(baud));
serial3_format(format); }
virtual void begin(uint32_t baud, uint32_t format=(uint32_t)-1);
virtual void end(void) { serial3_end(); }
virtual void transmitterEnable(uint8_t pin) { serial3_set_transmit_pin(pin); }
virtual void setRX(uint8_t pin) { serial3_set_rx(pin); }
Expand Down Expand Up @@ -414,10 +405,7 @@ class HardwareSerial4 : public HardwareSerial
{
public:
constexpr HardwareSerial4(void (* const se)()) : HardwareSerial(se) {}
virtual void begin(uint32_t baud);
virtual void begin(uint32_t baud, uint32_t format) {
serial4_begin(BAUD2DIV3(baud));
serial4_format(format); }
virtual void begin(uint32_t baud, uint32_t format=(uint32_t)-1);
virtual void end(void) { serial4_end(); }
virtual void transmitterEnable(uint8_t pin) { serial4_set_transmit_pin(pin); }
virtual void setRX(uint8_t pin) { serial4_set_rx(pin); }
Expand Down Expand Up @@ -453,10 +441,7 @@ class HardwareSerial5 : public HardwareSerial
{
public:
constexpr HardwareSerial5(void (* const se)()) : HardwareSerial(se) {}
virtual void begin(uint32_t baud);
virtual void begin(uint32_t baud, uint32_t format) {
serial5_begin(BAUD2DIV3(baud));
serial5_format(format); }
virtual void begin(uint32_t baud, uint32_t format=(uint32_t)-1);
virtual void end(void) { serial5_end(); }
virtual void transmitterEnable(uint8_t pin) { serial5_set_transmit_pin(pin); }
virtual void setRX(uint8_t pin) { serial5_set_rx(pin); }
Expand Down Expand Up @@ -492,17 +477,7 @@ class HardwareSerial6 : public HardwareSerial
{
public:
constexpr HardwareSerial6(void (* const se)()) : HardwareSerial(se) {}
#if defined(__MK66FX1M0__) // For LPUART just pass baud straight in.
virtual void begin(uint32_t baud);
virtual void begin(uint32_t baud, uint32_t format) {
serial6_begin(baud);
serial6_format(format); }
#else
virtual void begin(uint32_t baud);
virtual void begin(uint32_t baud, uint32_t format) {
serial6_begin(BAUD2DIV3(baud));
serial6_format(format); }
#endif
virtual void begin(uint32_t baud, uint32_t format=(uint32_t)-1);
virtual void end(void) { serial6_end(); }
virtual void transmitterEnable(uint8_t pin) { serial6_set_transmit_pin(pin); }
virtual void setRX(uint8_t pin) { serial6_set_rx(pin); }
Expand Down
3 changes: 2 additions & 1 deletion teensy3/HardwareSerial1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ uint8_t _serialEvent1_default __attribute__((weak)) PROGMEM = 0 ;

HardwareSerial Serial1(&serialEvent1);

void HardwareSerial::begin(uint32_t baud) {
void HardwareSerial::begin(uint32_t baud, uint32_t format) {
serial_begin(BAUD2DIV(baud));
if (format != (uint32_t)-1) serial_format(format);
if (!_serialEvent1_default) addToSerialEventsList();
}

3 changes: 2 additions & 1 deletion teensy3/HardwareSerial2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ HardwareSerial2 Serial2(&serialEvent2);

uint8_t _serialEvent2_default __attribute__((weak)) PROGMEM = 0 ;

void HardwareSerial2::begin(uint32_t baud) {
void HardwareSerial2::begin(uint32_t baud, uint32_t format) {
serial2_begin(BAUD2DIV2(baud));
if (format != (uint32_t)-1) serial2_format(format);
if (!_serialEvent2_default) addToSerialEventsList();
}
3 changes: 2 additions & 1 deletion teensy3/HardwareSerial3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ HardwareSerial3 Serial3(&serialEvent3);

uint8_t _serialEvent3_default __attribute__((weak)) PROGMEM = 0 ;

void HardwareSerial3::begin(uint32_t baud) {
void HardwareSerial3::begin(uint32_t baud, uint32_t format) {
serial3_begin(BAUD2DIV3(baud));
if (format != (uint32_t)-1) serial3_format(format);
if (!_serialEvent3_default) addToSerialEventsList();
}
3 changes: 2 additions & 1 deletion teensy3/HardwareSerial4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ HardwareSerial4 Serial4(&serialEvent4);

uint8_t _serialEvent4_default __attribute__((weak)) PROGMEM = 0 ;

void HardwareSerial4::begin(uint32_t baud) {
void HardwareSerial4::begin(uint32_t baud, uint32_t format) {
serial4_begin(BAUD2DIV3(baud));
if (format != (uint32_t)-1) serial4_format(format);
if (!_serialEvent4_default) addToSerialEventsList();
}

Expand Down
3 changes: 2 additions & 1 deletion teensy3/HardwareSerial5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ HardwareSerial5 Serial5(&serialEvent5);

uint8_t _serialEvent5_default __attribute__((weak)) PROGMEM = 0 ;

void HardwareSerial5::begin(uint32_t baud) {
void HardwareSerial5::begin(uint32_t baud, uint32_t format) {
serial5_begin(BAUD2DIV3(baud));
if (format != (uint32_t)-1) serial5_format(format);
if (!_serialEvent5_default) addToSerialEventsList();
}

Expand Down
3 changes: 2 additions & 1 deletion teensy3/HardwareSerial6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ HardwareSerial6 Serial6(&serialEvent6);

uint8_t _serialEvent6_default __attribute__((weak)) PROGMEM = 0 ;

void HardwareSerial6::begin(uint32_t baud) {
void HardwareSerial6::begin(uint32_t baud, uint32_t format) {
#if defined(__MK66FX1M0__) // For LPUART just pass baud straight in.
serial6_begin(baud);
#else
serial6_begin(BAUD2DIV3(baud));
#endif
if (format != (uint32_t)-1) serial6_format(format);
if (!_serialEvent6_default) addToSerialEventsList();
}

Expand Down

0 comments on commit 2b69ca9

Please sign in to comment.