瀏覽代碼

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
teensy4-core
Kurt Eckhardt 5 年之前
父節點
當前提交
2cde1573a3
共有 2 個檔案被更改,包括 51 行新增0 行删除
  1. +14
    -0
      teensy4/HardwareSerial.h
  2. +37
    -0
      teensy4/HardwareSerial1.cpp

+ 14
- 0
teensy4/HardwareSerial.h 查看文件

@@ -265,6 +265,20 @@ extern void serialEvent8(void);
#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

+ 37
- 0
teensy4/HardwareSerial1.cpp 查看文件

@@ -71,3 +71,40 @@ HardwareSerial Serial1(&IMXRT_LPUART6, &UART6_Hardware, tx_buffer1, SERIAL1_TX_B

void serialEvent1() __attribute__((weak));
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…
取消
儲存