Browse Source

C Serial1 functions like: serial_print(const char *)

Found some of our code has these defined, plus had in another test sketch so defined them hopefully with C bindings, but calls Serial1 object code
main
Kurt Eckhardt 5 years ago
parent
commit
2cde1573a3
2 changed files with 51 additions and 0 deletions
  1. +14
    -0
      teensy4/HardwareSerial.h
  2. +37
    -0
      teensy4/HardwareSerial1.cpp

+ 14
- 0
teensy4/HardwareSerial.h View File

#endif // __cplusplus #endif // __cplusplus




// c functions to call c++ code in case some programs call the old functions
// Defined under extern "C" {}

#ifdef __cplusplus
extern "C" {
#endif
extern void serial_print(const char *p);
extern void serial_phex(uint32_t n);
extern void serial_phex16(uint32_t n);
extern void serial_phex32(uint32_t n);

#ifdef __cplusplus
}
#endif




// TODO: replace with proper divisor+oversample calculation // TODO: replace with proper divisor+oversample calculation

+ 37
- 0
teensy4/HardwareSerial1.cpp View File



void serialEvent1() __attribute__((weak)); void serialEvent1() __attribute__((weak));
void serialEvent1() {Serial1.disableSerialEvents(); } // No use calling this so disable if called... void serialEvent1() {Serial1.disableSerialEvents(); } // No use calling this so disable if called...

// C wrapper functions to help take care of places that used to call these from standard C
void serial_print(const char *p)
{
Serial1.write(p);
}

static void serial_phex1(uint32_t n)
{
n &= 15;
if (n < 10) {
Serial1.write('0' + n);
} else {
Serial1.write('A' - 10 + n);
}
}

void serial_phex(uint32_t n)
{
serial_phex1(n >> 4);
serial_phex1(n);
}

void serial_phex16(uint32_t n)
{
serial_phex(n >> 8);
serial_phex(n);
}

void serial_phex32(uint32_t n)
{
serial_phex(n >> 24);
serial_phex(n >> 16);
serial_phex(n >> 8);
serial_phex(n);
}


Loading…
Cancel
Save