* fix mbedtls bad pointer in function call (prototype mismatch) * fix issue with weak families functions implemented in static library, it will never be linked. fixed by redefining prototypes inside families * [ln882x] add support for lightning ln882x & ln882h families * add i2c (wire) support * add analog (adc) support * add watchdog support * [ln882x] changed default uart 0/1 pins; added board wl2s * [ln882x] fix IRQ & ADC pins * [ln882x] boards cosmetic * [ln882x] wifi sta use otp mac addr by default; re-enabled wifi powersave mode * [ln882x] clang-format clean code * [ln882x] clang-format clean code * Update families.json * Apply suggestions from code review * [ln882x] reformat json board files * [ln882x] os_queue cleanup * [ln882x] removed Beken auto-download command * [ln882x] removed personal script file * [ln882x] removed unusefull pi section in debugging.md * [ln882x] removed Arduino.h and changed private I2C definition * [ln882x] updated README.md * [ln882x] changed pin naming scheme to PA/PB * [ln882x] clean code * [ln882x] clean code * [ln882x] add ota image verification * Update push-dev.yml * [ln882x] fix boards ADC missing inputs] * [ln882x] removed reg_xxx fixup files and use include guards instead * [ln882x] cleanup code * [ln882x] cleanup code * [ln882x] fix lt_init weak functions linking * [ln882x] revert lt_api.h modification, fixed with previous commit * [ln882x] setup UF2 firmware for flasher with partitions * [ln882x] update README.md * [ln882x] include ln_wifi.h and ln_serial.h to avoid including bad headers on case insensitive systems * [ln882x] Replace RingBuffer by SerialRingBuffer * [ln882x] clang-format * [ln882x] update README.md * Apply suggestions from code review * Reformat board JSON files * Add mkdocs link redirect * Update ltchiptool to v4.12.0 --------- Co-authored-by: Kuba Szczodrzyński <kuba@szczodrzynski.pl>
100 lines
2.0 KiB
C++
100 lines
2.0 KiB
C++
/* Copyright (c) Etienne Le Cousin 2024-02-10. */
|
|
|
|
#include "SerialPrivate.h"
|
|
|
|
extern Serial_t *serial_handles[SER_PORT_NUM];
|
|
|
|
#if LT_HW_UART0
|
|
SerialClass Serial0(0, PIN_SERIAL0_RX, PIN_SERIAL0_TX);
|
|
|
|
static void callback_uart0(void) {
|
|
SerialData *data = (SerialData *)Serial0.data;
|
|
char ch;
|
|
while (serial_read(serial_handles[0], &ch, 1)) {
|
|
data->buf.store_char(ch);
|
|
}
|
|
}
|
|
#else
|
|
#define callback_uart0 NULL
|
|
#endif
|
|
#if LT_HW_UART1
|
|
SerialClass Serial1(1, PIN_SERIAL1_RX, PIN_SERIAL1_TX);
|
|
|
|
static void callback_uart1(void) {
|
|
SerialData *data = (SerialData *)Serial1.data;
|
|
char ch;
|
|
while (serial_read(serial_handles[1], &ch, 1)) {
|
|
data->buf.store_char(ch);
|
|
}
|
|
}
|
|
#else
|
|
#define callback_uart1 NULL
|
|
#endif
|
|
#if LT_HW_UART2
|
|
SerialClass Serial2(2, PIN_SERIAL2_RX, PIN_SERIAL2_TX);
|
|
|
|
static void callback_uart2(void) {
|
|
SerialData *data = (SerialData *)Serial2.data;
|
|
char ch;
|
|
while (serial_read(serial_handles[2], &ch, 1)) {
|
|
data->buf.store_char(ch);
|
|
}
|
|
}
|
|
#else
|
|
#define callback_uart2 NULL
|
|
#endif
|
|
|
|
// clang-format off
|
|
static const serial_rx_callbcak serial_rx_callbacks[SER_PORT_NUM] = {
|
|
callback_uart0,
|
|
callback_uart1,
|
|
callback_uart2
|
|
};
|
|
// clang-format on
|
|
|
|
void SerialClass::begin(unsigned long baudrate, uint16_t config) {
|
|
if (!this->data) {
|
|
this->data = new SerialData();
|
|
this->buf = &BUF;
|
|
}
|
|
|
|
if (this->baudrate != baudrate || this->config != config)
|
|
this->configure(baudrate, config);
|
|
}
|
|
|
|
void SerialClass::configure(unsigned long baudrate, uint16_t config) {
|
|
if (!this->data)
|
|
return;
|
|
|
|
serial_init(serial_handles[port], (serial_port_id_t)port, baudrate, serial_rx_callbacks[port]);
|
|
|
|
this->baudrate = baudrate;
|
|
this->config = config;
|
|
}
|
|
|
|
void SerialClass::end() {
|
|
if (!this->data)
|
|
return;
|
|
|
|
serial_deinit(serial_handles[port]);
|
|
|
|
delete (SerialData *)this->data;
|
|
delete this->buf;
|
|
this->data = NULL;
|
|
this->buf = NULL;
|
|
this->baudrate = 0;
|
|
}
|
|
|
|
void SerialClass::flush() {
|
|
if (!this->data)
|
|
return;
|
|
serial_flush(serial_handles[port]);
|
|
}
|
|
|
|
size_t SerialClass::write(uint8_t c) {
|
|
if (!this->data)
|
|
return 0;
|
|
serial_putchar(serial_handles[port], c);
|
|
return 1;
|
|
}
|