From 4b7670236ee28cf7238f6f6b5220a4f7025bf7b1 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 7 Feb 2026 13:09:18 +0100 Subject: [PATCH 01/19] Add UART driver to kernel --- .../Bindings/espressif,esp32-uart.yaml | 27 ++ .../Include/tactility/bindings/esp32_uart.h | 16 ++ .../Include/tactility/drivers/esp32_uart.h | 21 ++ .../Source/drivers/esp32_i2s.cpp | 2 +- .../Source/drivers/esp32_uart.cpp | 271 ++++++++++++++++++ TactilityKernel/Bindings/uart-controller.yaml | 1 + .../tactility/drivers/uart_controller.h | 179 ++++++++++++ .../Source/drivers/uart_controller.cpp | 54 ++++ 8 files changed, 570 insertions(+), 1 deletion(-) create mode 100644 Platforms/PlatformEsp32/Bindings/espressif,esp32-uart.yaml create mode 100644 Platforms/PlatformEsp32/Include/tactility/bindings/esp32_uart.h create mode 100644 Platforms/PlatformEsp32/Include/tactility/drivers/esp32_uart.h create mode 100644 Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp create mode 100644 TactilityKernel/Bindings/uart-controller.yaml create mode 100644 TactilityKernel/Include/tactility/drivers/uart_controller.h create mode 100644 TactilityKernel/Source/drivers/uart_controller.cpp diff --git a/Platforms/PlatformEsp32/Bindings/espressif,esp32-uart.yaml b/Platforms/PlatformEsp32/Bindings/espressif,esp32-uart.yaml new file mode 100644 index 000000000..f39b11c64 --- /dev/null +++ b/Platforms/PlatformEsp32/Bindings/espressif,esp32-uart.yaml @@ -0,0 +1,27 @@ +description: ESP32 UART Controller + +include: ["uart-controller.yaml"] + +compatible: "espressif,esp32-uart" + +properties: + port: + type: int + required: true + description: | + The port number, defined by uart_port_t. + Depending on the hardware, these values are available: UART_NUM_0, UART_NUM_1, UART_NUM_2 + pin-tx: + type: int + required: true + description: TX pin + pin-rx: + type: int + required: true + description: RX pin + pin-cts: + type: int + description: CTS pin + pin-rts: + type: int + description: RTS pin diff --git a/Platforms/PlatformEsp32/Include/tactility/bindings/esp32_uart.h b/Platforms/PlatformEsp32/Include/tactility/bindings/esp32_uart.h new file mode 100644 index 000000000..6c82fe86f --- /dev/null +++ b/Platforms/PlatformEsp32/Include/tactility/bindings/esp32_uart.h @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +DEFINE_DEVICETREE(esp32_uart, struct Esp32UartConfig) + +#ifdef __cplusplus +} +#endif diff --git a/Platforms/PlatformEsp32/Include/tactility/drivers/esp32_uart.h b/Platforms/PlatformEsp32/Include/tactility/drivers/esp32_uart.h new file mode 100644 index 000000000..e4a2a76cd --- /dev/null +++ b/Platforms/PlatformEsp32/Include/tactility/drivers/esp32_uart.h @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct Esp32UartConfig { + uart_port_t port; + int pinTx; + int pinRx; + int pinCts; + int pinRts; +}; + +#ifdef __cplusplus +} +#endif diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_i2s.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_i2s.cpp index 5082dd245..ec012e65b 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_i2s.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_i2s.cpp @@ -15,7 +15,7 @@ #define TAG "esp32_i2s" struct InternalData { - Mutex mutex { 0 }; + Mutex mutex {}; i2s_chan_handle_t tx_handle = nullptr; i2s_chan_handle_t rx_handle = nullptr; I2sConfig config {}; diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp new file mode 100644 index 000000000..09716935a --- /dev/null +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp @@ -0,0 +1,271 @@ +// SPDX-License-Identifier: Apache-2.0 +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#define TAG "esp32_uart" + +struct InternalData { + Mutex mutex {}; + UartConfig config {}; + bool config_set = false; + bool initialized = false; + + InternalData() { + mutex_construct(&mutex); + } + + ~InternalData() { + mutex_destruct(&mutex); + } +}; + +#define GET_CONFIG(device) ((Esp32UartConfig*)device->config) +#define GET_DATA(device) ((InternalData*)device_get_driver_data(device)) + +#define lock(data) mutex_lock(&data->mutex); +#define unlock(data) mutex_unlock(&data->mutex); + +extern "C" { + +static error_t cleanup_uart(InternalData* driver_data, uart_port_t port) { + if (driver_data->initialized) { + uart_driver_delete(port); + driver_data->initialized = false; + } + return ERROR_NONE; +} + +static uart_parity_t to_esp32_parity(enum UartParity parity) { + switch (parity) { + case UART_CONTROLLER_PARITY_DISABLE: return UART_PARITY_DISABLE; + case UART_CONTROLLER_PARITY_EVEN: return UART_PARITY_EVEN; + case UART_CONTROLLER_PARITY_ODD: return UART_PARITY_ODD; + default: return UART_PARITY_DISABLE; + } +} + +static uart_word_length_t to_esp32_data_bits(enum UartDataBits bits) { + switch (bits) { + case UART_CONTROLLER_DATA_5_BITS: return UART_DATA_5_BITS; + case UART_CONTROLLER_DATA_6_BITS: return UART_DATA_6_BITS; + case UART_CONTROLLER_DATA_7_BITS: return UART_DATA_7_BITS; + case UART_CONTROLLER_DATA_8_BITS: return UART_DATA_8_BITS; + default: return UART_DATA_8_BITS; + } +} + +static uart_stop_bits_t to_esp32_stop_bits(enum UartStopBits bits) { + switch (bits) { + case UART_CONTROLLER_STOP_BITS_1: return UART_STOP_BITS_1; + case UART_CONTROLLER_STOP_BITS_1_5: return UART_STOP_BITS_1_5; + case UART_CONTROLLER_STOP_BITS_2: return UART_STOP_BITS_2; + default: return UART_STOP_BITS_1; + } +} + +static error_t read_byte(Device* device, uint8_t* out, TickType_t timeout) { + if (xPortInIsrContext()) return ERROR_ISR_STATUS; + auto* driver_data = GET_DATA(device); + auto* dts_config = GET_CONFIG(device); + if (!driver_data->initialized) return ERROR_INVALID_STATE; + + int len = uart_read_bytes(dts_config->port, out, 1, timeout); + if (len < 0) return ERROR_RESOURCE; + if (len == 0) return ERROR_TIMEOUT; + return ERROR_NONE; +} + +static error_t write_byte(Device* device, uint8_t out, TickType_t timeout) { + if (xPortInIsrContext()) return ERROR_ISR_STATUS; + auto* driver_data = GET_DATA(device); + auto* dts_config = GET_CONFIG(device); + if (!driver_data->initialized) return ERROR_INVALID_STATE; + + int len = uart_write_bytes(dts_config->port, (const char*)&out, 1); + if (len < 0) return ERROR_RESOURCE; + + // uart_write_bytes is non-blocking on the buffer but we might want to wait for it to be sent? + // The API signature has timeout, but ESP-IDF's uart_write_bytes doesn't use it for blocking. + // However, if we want to ensure it's SENT, we could use uart_wait_tx_done. + if (timeout > 0) { + esp_err_t err = uart_wait_tx_done(dts_config->port, timeout); + if (err == ESP_ERR_TIMEOUT) return ERROR_TIMEOUT; + if (err != ESP_OK) return ERROR_RESOURCE; + } + + return ERROR_NONE; +} + +static error_t write_bytes(Device* device, uint8_t* buffer, size_t buffer_size, TickType_t timeout) { + if (xPortInIsrContext()) return ERROR_ISR_STATUS; + auto* driver_data = GET_DATA(device); + auto* dts_config = GET_CONFIG(device); + if (!driver_data->initialized) return ERROR_INVALID_STATE; + + int len = uart_write_bytes(dts_config->port, (const char*)buffer, buffer_size); + if (len < 0) return ERROR_RESOURCE; + + if (timeout > 0) { + esp_err_t err = uart_wait_tx_done(dts_config->port, timeout); + if (err == ESP_ERR_TIMEOUT) return ERROR_TIMEOUT; + if (err != ESP_OK) return ERROR_RESOURCE; + } + + return ERROR_NONE; +} + +static error_t read_bytes(Device* device, uint8_t* buffer, size_t buffer_size, TickType_t timeout) { + if (xPortInIsrContext()) return ERROR_ISR_STATUS; + auto* driver_data = GET_DATA(device); + auto* dts_config = GET_CONFIG(device); + if (!driver_data->initialized) return ERROR_INVALID_STATE; + + int len = uart_read_bytes(dts_config->port, buffer, buffer_size, timeout); + if (len < 0) return ERROR_RESOURCE; + if (len < (int)buffer_size) return ERROR_TIMEOUT; + + return ERROR_NONE; +} + +static int available(Device* device, TickType_t timeout) { + auto* driver_data = GET_DATA(device); + auto* dts_config = GET_CONFIG(device); + if (!driver_data->initialized) return -1; + + size_t size; + esp_err_t err = uart_get_buffered_data_len(dts_config->port, &size); + if (err != ESP_OK) return -1; + return (int)size; +} + +static error_t set_config(Device* device, const struct UartConfig* config) { + if (xPortInIsrContext()) return ERROR_ISR_STATUS; + + auto* driver_data = GET_DATA(device); + auto* dts_config = GET_CONFIG(device); + lock(driver_data); + + cleanup_uart(driver_data, dts_config->port); + driver_data->config_set = false; + + uart_config_t uart_cfg = { + .baud_rate = (int)config->baud_rate, + .data_bits = to_esp32_data_bits(config->data_bits), + .parity = to_esp32_parity(config->parity), + .stop_bits = to_esp32_stop_bits(config->stop_bits), + .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, + .rx_flow_thls = 0, + .source_clk = UART_SCLK_DEFAULT, + }; + + if (config->cts_pin != -1 || config->rts_pin != -1) { + uart_cfg.flow_ctrl = UART_HW_FLOWCTRL_CTS_RTS; + if (config->cts_pin != -1 && config->rts_pin == -1) uart_cfg.flow_ctrl = UART_HW_FLOWCTRL_CTS; + if (config->cts_pin == -1 && config->rts_pin != -1) uart_cfg.flow_ctrl = UART_HW_FLOWCTRL_RTS; + } + + esp_err_t esp_error = uart_param_config(dts_config->port, &uart_cfg); + if (esp_error == ESP_OK) { + esp_error = uart_set_pin(dts_config->port, dts_config->pinTx, dts_config->pinRx, dts_config->pinCts, dts_config->pinRts); + } + if (esp_error == ESP_OK) { + // We use a buffer size of 1024 for both RX and TX by default + esp_error = uart_driver_install(dts_config->port, 1024 * 2, 0, 0, NULL, 0); + } + + if (esp_error != ESP_OK) { + LOG_E(TAG, "Failed to initialize UART: %s", esp_err_to_name(esp_error)); + unlock(driver_data); + return esp_err_to_error(esp_error); + } + + driver_data->initialized = true; + memcpy(&driver_data->config, config, sizeof(UartConfig)); + driver_data->config_set = true; + + unlock(driver_data); + return ERROR_NONE; +} + +static error_t get_config(Device* device, struct UartConfig* config) { + auto* driver_data = GET_DATA(device); + + lock(driver_data); + if (!driver_data->config_set) { + unlock(driver_data); + return ERROR_RESOURCE; + } + memcpy(config, &driver_data->config, sizeof(UartConfig)); + unlock(driver_data); + + return ERROR_NONE; +} + +static error_t start(Device* device) { + ESP_LOGI(TAG, "start %s", device->name); + auto* data = new(std::nothrow) InternalData(); + if (!data) return ERROR_OUT_OF_MEMORY; + + device_set_driver_data(device, data); + + return ERROR_NONE; +} + +static error_t stop(Device* device) { + ESP_LOGI(TAG, "stop %s", device->name); + auto* driver_data = GET_DATA(device); + auto* dts_config = GET_CONFIG(device); + + lock(driver_data); + cleanup_uart(driver_data, dts_config->port); + unlock(driver_data); + + device_set_driver_data(device, nullptr); + delete driver_data; + return ERROR_NONE; +} + +static error_t reset(Device* device) { + ESP_LOGI(TAG, "reset %s", device->name); + auto* driver_data = GET_DATA(device); + auto* dts_config = GET_CONFIG(device); + lock(driver_data); + cleanup_uart(driver_data, dts_config->port); + unlock(driver_data); + return ERROR_NONE; +} + +const static UartControllerApi esp32_uart_api = { + .read_byte = read_byte, + .write_byte = write_byte, + .write_bytes = write_bytes, + .read_bytes = read_bytes, + .available = available, + .set_config = set_config, + .get_config = get_config, + .reset = reset +}; + +extern struct Module platform_module; + +Driver esp32_uart_driver = { + .name = "esp32_uart", + .compatible = (const char*[]) { "espressif,esp32-uart", nullptr }, + .start_device = start, + .stop_device = stop, + .api = (void*)&esp32_uart_api, + .device_type = &UART_CONTROLLER_TYPE, + .owner = &platform_module, + .internal = nullptr +}; + +} // extern "C" diff --git a/TactilityKernel/Bindings/uart-controller.yaml b/TactilityKernel/Bindings/uart-controller.yaml new file mode 100644 index 000000000..4284a22b2 --- /dev/null +++ b/TactilityKernel/Bindings/uart-controller.yaml @@ -0,0 +1 @@ +description: UART controller diff --git a/TactilityKernel/Include/tactility/drivers/uart_controller.h b/TactilityKernel/Include/tactility/drivers/uart_controller.h new file mode 100644 index 000000000..dc2adfd35 --- /dev/null +++ b/TactilityKernel/Include/tactility/drivers/uart_controller.h @@ -0,0 +1,179 @@ +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#include +#include + +/** + * @brief UART parity modes + */ +enum UartParity { + UART_CONTROLLER_PARITY_DISABLE = 0x0, + UART_CONTROLLER_PARITY_EVEN = 0x1, + UART_CONTROLLER_PARITY_ODD = 0x2, +}; + +/** + * @brief UART data bits + */ +enum UartDataBits { + UART_CONTROLLER_DATA_5_BITS = 0x0, + UART_CONTROLLER_DATA_6_BITS = 0x1, + UART_CONTROLLER_DATA_7_BITS = 0x2, + UART_CONTROLLER_DATA_8_BITS = 0x3, +}; + +/** + * @brief UART stop bits + */ +enum UartStopBits { + UART_CONTROLLER_STOP_BITS_1 = 0x1, + UART_CONTROLLER_STOP_BITS_1_5 = 0x2, + UART_CONTROLLER_STOP_BITS_2 = 0x3, +}; + +/** + * @brief UART Config + */ +struct UartConfig { + uint32_t baud_rate; + enum UartDataBits data_bits; + enum UartParity parity; + enum UartStopBits stop_bits; + int8_t tx_pin; + int8_t rx_pin; + int8_t cts_pin; + int8_t rts_pin; +}; + +/** + * @brief API for UART controller drivers. + */ +struct UartControllerApi { + /** + * @brief Reads a single byte from UART. + * @param[in] device the UART controller device + * @param[out] out the buffer to store the read byte + * @param[in] timeout the maximum time to wait for the operation to complete + * @retval ERROR_NONE when the read operation was successful + * @retval ERROR_TIMEOUT when the operation timed out + */ + error_t (*read_byte)(struct Device* device, uint8_t* out, TickType_t timeout); + + /** + * @brief Writes a single byte to UART. + * @param[in] device the UART controller device + * @param[in] out the byte to write + * @param[in] timeout the maximum time to wait for the operation to complete + * @retval ERROR_NONE when the write operation was successful + * @retval ERROR_TIMEOUT when the operation timed out + */ + error_t (*write_byte)(struct Device* device, uint8_t out, TickType_t timeout); + + /** + * @brief Writes multiple bytes to UART. + * @param[in] device the UART controller device + * @param[in] buffer the buffer containing the data to write + * @param[in] buffer_size the number of bytes to write + * @param[in] timeout the maximum time to wait for the operation to complete + * @retval ERROR_NONE when the write operation was successful + * @retval ERROR_TIMEOUT when the operation timed out + */ + error_t (*write_bytes)(struct Device* device, uint8_t* buffer, size_t buffer_size, TickType_t timeout); + + /** + * @brief Reads multiple bytes from UART. + * @param[in] device the UART controller device + * @param[out] buffer the buffer to store the read data + * @param[in] buffer_size the number of bytes to read + * @param[in] timeout the maximum time to wait for the operation to complete + * @retval ERROR_NONE when the read operation was successful + * @retval ERROR_TIMEOUT when the operation timed out + */ + error_t (*read_bytes)(struct Device* device, uint8_t* buffer, size_t buffer_size, TickType_t timeout); + + /** + * @brief Returns the number of bytes available for reading. + * @param[in] device the UART controller device + * @param[in] timeout the maximum time to wait for the operation to complete + * @return the number of bytes available, or a negative error code on failure + */ + int (*available)(struct Device* device, TickType_t timeout); + + /** + * @brief Sets the UART configuration. + * @param[in] device the UART controller device + * @param[in] config the new configuration + * @retval ERROR_NONE when the operation was successful + */ + error_t (*set_config)(struct Device* device, const struct UartConfig* config); + + /** + * @brief Gets the current UART configuration. + * @param[in] device the UART controller device + * @param[out] config the buffer to store the current configuration + * @retval ERROR_NONE when the operation was successful + */ + error_t (*get_config)(struct Device* device, struct UartConfig* config); + + /** + * @brief Resets the UART controller. Must configure it again before it can be used. + * @param[in] device the UART controller device + * @retval ERROR_NONE when the operation was successful + */ + error_t (*reset)(struct Device* device); +}; + +/** + * @brief Reads a single byte from UART using the specified controller. + */ +error_t uart_controller_read_byte(struct Device* device, uint8_t* out, TickType_t timeout); + +/** + * @brief Writes a single byte to UART using the specified controller. + */ +error_t uart_controller_write_byte(struct Device* device, uint8_t out, TickType_t timeout); + +/** + * @brief Writes multiple bytes to UART using the specified controller. + */ +error_t uart_controller_write_bytes(struct Device* device, uint8_t* buffer, size_t buffer_size, TickType_t timeout); + +/** + * @brief Reads multiple bytes from UART using the specified controller. + */ +error_t uart_controller_read_bytes(struct Device* device, uint8_t* buffer, size_t buffer_size, TickType_t timeout); + +/** + * @brief Returns the number of bytes available for reading using the specified controller. + */ +int uart_controller_available(struct Device* device, TickType_t timeout); + +/** + * @brief Sets the UART configuration using the specified controller. + */ +error_t uart_controller_set_config(struct Device* device, const struct UartConfig* config); + +/** + * @brief Gets the current UART configuration using the specified controller. + */ +error_t uart_controller_get_config(struct Device* device, struct UartConfig* config); + +/** + * @brief Resets the UART controller using the specified controller. + */ +error_t uart_controller_reset(struct Device* device); + +extern const struct DeviceType UART_CONTROLLER_TYPE; + +#ifdef __cplusplus +} +#endif diff --git a/TactilityKernel/Source/drivers/uart_controller.cpp b/TactilityKernel/Source/drivers/uart_controller.cpp new file mode 100644 index 000000000..72c65eaee --- /dev/null +++ b/TactilityKernel/Source/drivers/uart_controller.cpp @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: Apache-2.0 +#include +#include +#include + +#define UART_DRIVER_API(driver) ((struct UartControllerApi*)driver->api) + +extern "C" { + +error_t uart_controller_read_byte(struct Device* device, uint8_t* out, TickType_t timeout) { + const auto* driver = device_get_driver(device); + return UART_DRIVER_API(driver)->read_byte(device, out, timeout); +} + +error_t uart_controller_write_byte(struct Device* device, uint8_t out, TickType_t timeout) { + const auto* driver = device_get_driver(device); + return UART_DRIVER_API(driver)->write_byte(device, out, timeout); +} + +error_t uart_controller_write_bytes(struct Device* device, uint8_t* buffer, size_t buffer_size, TickType_t timeout) { + const auto* driver = device_get_driver(device); + return UART_DRIVER_API(driver)->write_bytes(device, buffer, buffer_size, timeout); +} + +error_t uart_controller_read_bytes(struct Device* device, uint8_t* buffer, size_t buffer_size, TickType_t timeout) { + const auto* driver = device_get_driver(device); + return UART_DRIVER_API(driver)->read_bytes(device, buffer, buffer_size, timeout); +} + +int uart_controller_available(struct Device* device, TickType_t timeout) { + const auto* driver = device_get_driver(device); + return UART_DRIVER_API(driver)->available(device, timeout); +} + +error_t uart_controller_set_config(struct Device* device, const struct UartConfig* config) { + const auto* driver = device_get_driver(device); + return UART_DRIVER_API(driver)->set_config(device, config); +} + +error_t uart_controller_get_config(struct Device* device, struct UartConfig* config) { + const auto* driver = device_get_driver(device); + return UART_DRIVER_API(driver)->get_config(device, config); +} + +error_t uart_controller_reset(struct Device* device) { + const auto* driver = device_get_driver(device); + return UART_DRIVER_API(driver)->reset(device); +} + +extern const struct DeviceType UART_CONTROLLER_TYPE { + .name = "uart-controller" +}; + +} From 0ddadc10a2346e125c0769465ac3b5a7307f932f Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 7 Feb 2026 13:38:49 +0100 Subject: [PATCH 02/19] Add SPI kernel driver --- .../Include/tactility/drivers/esp32_spi.h | 23 ++++ .../Source/drivers/esp32_spi.cpp | 122 ++++++++++++++++++ Platforms/PlatformEsp32/Source/module.cpp | 6 + .../tactility/drivers/spi_controller.h | 84 ++++++++++++ .../Source/drivers/spi_controller.cpp | 34 +++++ 5 files changed, 269 insertions(+) create mode 100644 Platforms/PlatformEsp32/Include/tactility/drivers/esp32_spi.h create mode 100644 Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp create mode 100644 TactilityKernel/Include/tactility/drivers/spi_controller.h create mode 100644 TactilityKernel/Source/drivers/spi_controller.cpp diff --git a/Platforms/PlatformEsp32/Include/tactility/drivers/esp32_spi.h b/Platforms/PlatformEsp32/Include/tactility/drivers/esp32_spi.h new file mode 100644 index 000000000..0731cfbb6 --- /dev/null +++ b/Platforms/PlatformEsp32/Include/tactility/drivers/esp32_spi.h @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct Esp32SpiConfig { + spi_host_device_t host; + int pin_mosi; + int pin_miso; + int pin_sclk; + int pin_wp; + int pin_hd; + int max_transfer_sz; +}; + +#ifdef __cplusplus +} +#endif diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp new file mode 100644 index 000000000..8190d1322 --- /dev/null +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: Apache-2.0 +#include +#include + +#include +#include +#include + +#define TAG "esp32_spi" + +#define GET_CONFIG(device) ((const struct Esp32SpiConfig*)device_get_config(device)) +#define GET_DATA(device) ((struct InternalData*)device_get_driver_data(device)) + +extern "C" { + +struct InternalData { + Mutex mutex; + bool initialized; + + InternalData() { + mutex_construct(&mutex); + } + + ~InternalData() { + mutex_destruct(&mutex); + } +}; + +static error_t reset(Device* device) { + auto* driver_data = GET_DATA(device); + auto* dts_config = GET_CONFIG(device); + + if (driver_data->initialized) { + spi_bus_free(dts_config->host); + driver_data->initialized = false; + } + + spi_bus_config_t buscfg = { + .mosi_io_num = dts_config->pin_mosi, + .miso_io_num = dts_config->pin_miso, + .sclk_io_num = dts_config->pin_sclk, + .quadwp_io_num = dts_config->pin_wp, + .quadhd_io_num = dts_config->pin_hd, + .max_transfer_sz = dts_config->max_transfer_sz, + }; + + esp_err_t ret = spi_bus_initialize(dts_config->host, &buscfg, SPI_DMA_CH_AUTO); + if (ret != ESP_OK) { + ESP_LOGE(TAG, "Failed to initialize SPI bus: %s", esp_err_to_name(ret)); + return ERROR_RESOURCE; + } + + driver_data->initialized = true; + return ERROR_NONE; +} + +static error_t lock(Device* device) { + auto* driver_data = GET_DATA(device); + mutex_lock(&driver_data->mutex); + return ERROR_NONE; +} + +static error_t try_lock(Device* device, TickType_t timeout) { + auto* driver_data = GET_DATA(device); + if (mutex_try_lock_timed(&driver_data->mutex, timeout)) { + return ERROR_NONE; + } + return ERROR_TIMEOUT; +} + +static error_t unlock(Device* device) { + auto* driver_data = GET_DATA(device); + mutex_unlock(&driver_data->mutex); + return ERROR_NONE; +} + +static error_t start(Device* device) { + ESP_LOGI(TAG, "start %s", device->name); + auto* data = new(std::nothrow) InternalData(); + if (!data) return ERROR_OUT_OF_MEMORY; + + data->initialized = false; + device_set_driver_data(device, data); + + return reset(device); +} + +static error_t stop(Device* device) { + ESP_LOGI(TAG, "stop %s", device->name); + auto* driver_data = GET_DATA(device); + auto* dts_config = GET_CONFIG(device); + + if (driver_data->initialized) { + spi_bus_free(dts_config->host); + } + + device_set_driver_data(device, nullptr); + delete driver_data; + return ERROR_NONE; +} + +const static struct SpiControllerApi esp32_spi_api = { + .reset = reset, + .lock = lock, + .try_lock = try_lock, + .unlock = unlock +}; + +extern struct Module platform_module; + +Driver esp32_spi_driver = { + .name = "esp32_spi", + .compatible = (const char*[]) { "espressif,esp32-spi", nullptr }, + .start_device = start, + .stop_device = stop, + .api = (void*)&esp32_spi_api, + .device_type = &SPI_CONTROLLER_TYPE, + .owner = &platform_module, + .internal = nullptr +}; + +} // extern "C" diff --git a/Platforms/PlatformEsp32/Source/module.cpp b/Platforms/PlatformEsp32/Source/module.cpp index 0671803f2..576006967 100644 --- a/Platforms/PlatformEsp32/Source/module.cpp +++ b/Platforms/PlatformEsp32/Source/module.cpp @@ -7,6 +7,8 @@ extern "C" { extern Driver esp32_gpio_driver; extern Driver esp32_i2c_driver; extern Driver esp32_i2s_driver; +extern Driver esp32_spi_driver; +extern Driver esp32_uart_driver; static error_t start() { /* We crash when construct fails, because if a single driver fails to construct, @@ -14,6 +16,8 @@ static error_t start() { check(driver_construct_add(&esp32_gpio_driver) == ERROR_NONE); check(driver_construct_add(&esp32_i2c_driver) == ERROR_NONE); check(driver_construct_add(&esp32_i2s_driver) == ERROR_NONE); + check(driver_construct_add(&esp32_spi_driver) == ERROR_NONE); + check(driver_construct_add(&esp32_uart_driver) == ERROR_NONE); return ERROR_NONE; } @@ -23,6 +27,8 @@ static error_t stop() { check(driver_remove_destruct(&esp32_gpio_driver) == ERROR_NONE); check(driver_remove_destruct(&esp32_i2c_driver) == ERROR_NONE); check(driver_remove_destruct(&esp32_i2s_driver) == ERROR_NONE); + check(driver_remove_destruct(&esp32_spi_driver) == ERROR_NONE); + check(driver_remove_destruct(&esp32_uart_driver) == ERROR_NONE); return ERROR_NONE; } diff --git a/TactilityKernel/Include/tactility/drivers/spi_controller.h b/TactilityKernel/Include/tactility/drivers/spi_controller.h new file mode 100644 index 000000000..e2364056b --- /dev/null +++ b/TactilityKernel/Include/tactility/drivers/spi_controller.h @@ -0,0 +1,84 @@ +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#include +#include + +/** + * @brief API for SPI controller drivers. + */ +struct SpiControllerApi { + /** + * @brief Resets the SPI controller. + * @param[in] device the SPI controller device + * @retval ERROR_NONE when the operation was successful + */ + error_t (*reset)(struct Device* device); + + /** + * @brief Locks the SPI controller. + * @param[in] device the SPI controller device + * @retval ERROR_NONE when the operation was successful + */ + error_t (*lock)(struct Device* device); + + /** + * @brief Tries to lock the SPI controller. + * @param[in] device the SPI controller device + * @param[in] timeout the maximum time to wait for the lock + * @retval ERROR_NONE when the operation was successful + * @retval ERROR_TIMEOUT when the operation timed out + */ + error_t (*try_lock)(struct Device* device, TickType_t timeout); + + /** + * @brief Unlocks the SPI controller. + * @param[in] device the SPI controller device + * @retval ERROR_NONE when the operation was successful + */ + error_t (*unlock)(struct Device* device); +}; + +/** + * @brief Resets the SPI controller using the specified controller. + * @param[in] device the SPI controller device + * @retval ERROR_NONE when the operation was successful + */ +error_t spi_controller_reset(struct Device* device); + +/** + * @brief Locks the SPI controller using the specified controller. + * @param[in] device the SPI controller device + * @retval ERROR_NONE when the operation was successful + */ +error_t spi_controller_lock(struct Device* device); + +/** + * @brief Tries to lock the SPI controller using the specified controller. + * @param[in] device the SPI controller device +* @param[in] timeout the maximum time to wait for the lock + * @retval ERROR_NONE when the operation was successful + * @retval ERROR_TIMEOUT when the operation timed out + */ +error_t spi_controller_try_lock(struct Device* device, TickType_t timeout)); + +/** + * @brief Unlocks the SPI controller using the specified controller. + * @param[in] device the SPI controller device + * @retval ERROR_NONE when the operation was successful + */ +error_t spi_controller_unlock(struct Device* device); + +extern const struct DeviceType SPI_CONTROLLER_TYPE; + +#ifdef __cplusplus +} +#endif diff --git a/TactilityKernel/Source/drivers/spi_controller.cpp b/TactilityKernel/Source/drivers/spi_controller.cpp new file mode 100644 index 000000000..f10e8a007 --- /dev/null +++ b/TactilityKernel/Source/drivers/spi_controller.cpp @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: Apache-2.0 +#include +#include +#include + +#define SPI_DRIVER_API(driver) ((struct SpiControllerApi*)driver->api) + +extern "C" { + +error_t spi_controller_reset(struct Device* device) { + const auto* driver = device_get_driver(device); + return SPI_DRIVER_API(driver)->reset(device); +} + +error_t spi_controller_lock(struct Device* device) { + const auto* driver = device_get_driver(device); + return SPI_DRIVER_API(driver)->lock(device); +} + +error_t spi_controller_try_lock(struct Device* device, TickType_t timeout) { + const auto* driver = device_get_driver(device); + return SPI_DRIVER_API(driver)->try_lock(device, timeout); +} + +error_t spi_controller_unlock(struct Device* device) { + const auto* driver = device_get_driver(device); + return SPI_DRIVER_API(driver)->unlock(device); +} + +extern const struct DeviceType SPI_CONTROLLER_TYPE { + .name = "spi-controller" +}; + +} From fa447489a78ad6090d17a804aabbdd4ace01ad11 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 7 Feb 2026 13:39:01 +0100 Subject: [PATCH 03/19] Update try_lock: add timeout --- TactilityKernel/Include/tactility/device.h | 4 +++- TactilityKernel/Source/device.cpp | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/TactilityKernel/Include/tactility/device.h b/TactilityKernel/Include/tactility/device.h index 4f76d8664..d0604f12e 100644 --- a/TactilityKernel/Include/tactility/device.h +++ b/TactilityKernel/Include/tactility/device.h @@ -10,6 +10,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { @@ -212,9 +213,10 @@ void device_lock(struct Device* device); * Try to lock the device for exclusive access. * * @param[in,out] device non-null device pointer + * @param[in] timeout how long to wait for the lock * @return true if the device was locked successfully */ -bool device_try_lock(struct Device* device); +bool device_try_lock(struct Device* device, TickType_t timeout); /** * Unlock the device. diff --git a/TactilityKernel/Source/device.cpp b/TactilityKernel/Source/device.cpp index 9420b1db4..fb29dc22a 100644 --- a/TactilityKernel/Source/device.cpp +++ b/TactilityKernel/Source/device.cpp @@ -293,8 +293,8 @@ void device_lock(struct Device* device) { mutex_lock(&device->internal->mutex); } -bool device_try_lock(struct Device* device) { - return mutex_try_lock(&device->internal->mutex); +bool device_try_lock(struct Device* device, TickType_t timeout) { + return mutex_try_lock(&device->internal->mutex, timeout); } void device_unlock(struct Device* device) { From 0adfb9e47b73671b6c4f316eb27039d54ed15210 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 7 Feb 2026 13:40:30 +0100 Subject: [PATCH 04/19] Simplify try_lock for mutex and recursive mutex. --- Modules/lvgl-module/Source/arch/lvgl_posix.c | 2 +- Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp | 2 +- TactilityKernel/Include/tactility/concurrent/mutex.h | 7 +------ .../Include/tactility/concurrent/recursive_mutex.h | 7 +------ TactilityKernel/Include/tactility/drivers/spi_controller.h | 2 +- TactilityKernel/Source/concurrent/dispatcher.cpp | 4 ++-- Tests/TactilityKernel/Source/MutexTest.cpp | 4 ++-- Tests/TactilityKernel/Source/RecursiveMutexTest.cpp | 4 ++-- 8 files changed, 11 insertions(+), 21 deletions(-) diff --git a/Modules/lvgl-module/Source/arch/lvgl_posix.c b/Modules/lvgl-module/Source/arch/lvgl_posix.c index 846af03e4..b9ebe268d 100644 --- a/Modules/lvgl-module/Source/arch/lvgl_posix.c +++ b/Modules/lvgl-module/Source/arch/lvgl_posix.c @@ -45,7 +45,7 @@ bool lvgl_lock(void) { bool lvgl_try_lock_timed(uint32_t timeout) { if (!lvgl_mutex_initialised) return false; - return recursive_mutex_try_lock_timed(&lvgl_mutex, millis_to_ticks(timeout)); + return recursive_mutex_try_lock(&lvgl_mutex, millis_to_ticks(timeout)); } void lvgl_unlock(void) { diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp index 8190d1322..46c99f50f 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp @@ -62,7 +62,7 @@ static error_t lock(Device* device) { static error_t try_lock(Device* device, TickType_t timeout) { auto* driver_data = GET_DATA(device); - if (mutex_try_lock_timed(&driver_data->mutex, timeout)) { + if (mutex_try_lock(&driver_data->mutex, timeout)) { return ERROR_NONE; } return ERROR_TIMEOUT; diff --git a/TactilityKernel/Include/tactility/concurrent/mutex.h b/TactilityKernel/Include/tactility/concurrent/mutex.h index a6e0d579e..12b196ff1 100644 --- a/TactilityKernel/Include/tactility/concurrent/mutex.h +++ b/TactilityKernel/Include/tactility/concurrent/mutex.h @@ -32,12 +32,7 @@ inline static void mutex_lock(struct Mutex* mutex) { xSemaphoreTake(mutex->handle, portMAX_DELAY); } -inline static bool mutex_try_lock(struct Mutex* mutex) { - check(xPortInIsrContext() != pdTRUE); - return xSemaphoreTake(mutex->handle, 0) == pdTRUE; -} - -inline static bool mutex_try_lock_timed(struct Mutex* mutex, TickType_t timeout) { +inline static bool mutex_try_lock(struct Mutex* mutex, TickType_t timeout) { check(xPortInIsrContext() != pdTRUE); return xSemaphoreTake(mutex->handle, timeout) == pdTRUE; } diff --git a/TactilityKernel/Include/tactility/concurrent/recursive_mutex.h b/TactilityKernel/Include/tactility/concurrent/recursive_mutex.h index 0863f81e0..a7b12299d 100644 --- a/TactilityKernel/Include/tactility/concurrent/recursive_mutex.h +++ b/TactilityKernel/Include/tactility/concurrent/recursive_mutex.h @@ -39,12 +39,7 @@ inline static bool recursive_mutex_is_locked(struct RecursiveMutex* mutex) { } } -inline static bool recursive_mutex_try_lock(struct RecursiveMutex* mutex) { - check(xPortInIsrContext() != pdTRUE); - return xSemaphoreTakeRecursive(mutex->handle, 0) == pdTRUE; -} - -inline static bool recursive_mutex_try_lock_timed(struct RecursiveMutex* mutex, TickType_t timeout) { +inline static bool recursive_mutex_try_lock(struct RecursiveMutex* mutex, TickType_t timeout) { check(xPortInIsrContext() != pdTRUE); return xSemaphoreTakeRecursive(mutex->handle, timeout) == pdTRUE; } diff --git a/TactilityKernel/Include/tactility/drivers/spi_controller.h b/TactilityKernel/Include/tactility/drivers/spi_controller.h index e2364056b..509d4a2b9 100644 --- a/TactilityKernel/Include/tactility/drivers/spi_controller.h +++ b/TactilityKernel/Include/tactility/drivers/spi_controller.h @@ -68,7 +68,7 @@ error_t spi_controller_lock(struct Device* device); * @retval ERROR_NONE when the operation was successful * @retval ERROR_TIMEOUT when the operation timed out */ -error_t spi_controller_try_lock(struct Device* device, TickType_t timeout)); +error_t spi_controller_try_lock(struct Device* device, TickType_t timeout); /** * @brief Unlocks the SPI controller using the specified controller. diff --git a/TactilityKernel/Source/concurrent/dispatcher.cpp b/TactilityKernel/Source/concurrent/dispatcher.cpp index 5b13d027b..24bdaca8e 100644 --- a/TactilityKernel/Source/concurrent/dispatcher.cpp +++ b/TactilityKernel/Source/concurrent/dispatcher.cpp @@ -58,7 +58,7 @@ error_t dispatcher_dispatch_timed(DispatcherHandle_t dispatcher, void* callbackC auto* data = dispatcher_data(dispatcher); // Mutate - if (!mutex_try_lock_timed(&data->mutex, timeout)) { + if (!mutex_try_lock(&data->mutex, timeout)) { #ifdef ESP_PLATFORM LOG_E(TAG, "Mutex acquisition timeout"); #endif @@ -115,7 +115,7 @@ error_t dispatcher_consume_timed(DispatcherHandle_t dispatcher, TickType_t timeo // Mutate bool processing = true; do { - if (mutex_try_lock_timed(&data->mutex, 10)) { + if (mutex_try_lock(&data->mutex, 10)) { if (!data->queue.empty()) { // Make a copy, so it's thread-safe when we unlock auto entry = data->queue.front(); diff --git a/Tests/TactilityKernel/Source/MutexTest.cpp b/Tests/TactilityKernel/Source/MutexTest.cpp index bc5d70b74..5b3f2979b 100644 --- a/Tests/TactilityKernel/Source/MutexTest.cpp +++ b/Tests/TactilityKernel/Source/MutexTest.cpp @@ -26,8 +26,8 @@ TEST_CASE("mutex_try_lock should succeed on first lock but not on second") { Mutex mutex = { 0 }; mutex_construct(&mutex); - CHECK_EQ(mutex_try_lock(&mutex), true); - CHECK_EQ(mutex_try_lock(&mutex), false); + CHECK_EQ(mutex_try_lock(&mutex, 0), true); + CHECK_EQ(mutex_try_lock(&mutex, 0), false); mutex_unlock(&mutex); mutex_destruct(&mutex); diff --git a/Tests/TactilityKernel/Source/RecursiveMutexTest.cpp b/Tests/TactilityKernel/Source/RecursiveMutexTest.cpp index 30bf6c435..d77b31c24 100644 --- a/Tests/TactilityKernel/Source/RecursiveMutexTest.cpp +++ b/Tests/TactilityKernel/Source/RecursiveMutexTest.cpp @@ -43,8 +43,8 @@ TEST_CASE("recursive_mutex_try_lock should lock multiple times from the same thr RecursiveMutex mutex = { 0 }; recursive_mutex_construct(&mutex); - CHECK_EQ(recursive_mutex_try_lock(&mutex), true); - CHECK_EQ(recursive_mutex_try_lock(&mutex), true); + CHECK_EQ(recursive_mutex_try_lock(&mutex, 0), true); + CHECK_EQ(recursive_mutex_try_lock(&mutex, 0), true); recursive_mutex_unlock(&mutex); CHECK_EQ(recursive_mutex_is_locked(&mutex), true); recursive_mutex_unlock(&mutex); From 0cbbe577291019b406516242c382d7098a434b3d Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 7 Feb 2026 13:55:53 +0100 Subject: [PATCH 05/19] Fixes --- Modules/hal-device-module/Source/drivers/hal_device.cpp | 4 +++- Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp | 3 ++- Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp | 9 +++++++-- .../Include/tactility/drivers/uart_controller.h | 5 ++--- TactilityKernel/Source/drivers/gpio_controller.cpp | 2 +- TactilityKernel/Source/drivers/i2c_controller.cpp | 2 +- TactilityKernel/Source/drivers/i2s_controller.cpp | 2 +- TactilityKernel/Source/drivers/spi_controller.cpp | 2 +- TactilityKernel/Source/drivers/uart_controller.cpp | 6 +++--- 9 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Modules/hal-device-module/Source/drivers/hal_device.cpp b/Modules/hal-device-module/Source/drivers/hal_device.cpp index e51ba3ea3..0041237fd 100644 --- a/Modules/hal-device-module/Source/drivers/hal_device.cpp +++ b/Modules/hal-device-module/Source/drivers/hal_device.cpp @@ -110,7 +110,9 @@ static error_t stop(Device* device) { extern "C" { -extern const struct DeviceType HAL_DEVICE_TYPE {0}; +const struct DeviceType HAL_DEVICE_TYPE { + "hal-device" +}; extern struct Module hal_device_module; diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp index 46c99f50f..6cff102ce 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp @@ -1,4 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 +#include #include #include @@ -8,7 +9,7 @@ #define TAG "esp32_spi" -#define GET_CONFIG(device) ((const struct Esp32SpiConfig*)device_get_config(device)) +#define GET_CONFIG(device) ((const struct Esp32SpiConfig*)device->config) #define GET_DATA(device) ((struct InternalData*)device_get_driver_data(device)) extern "C" { diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp index 09716935a..4f9bc8b6a 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -136,7 +137,7 @@ static error_t read_bytes(Device* device, uint8_t* buffer, size_t buffer_size, T return ERROR_NONE; } -static int available(Device* device, TickType_t timeout) { +static int available(Device* device) { auto* driver_data = GET_DATA(device); auto* dts_config = GET_CONFIG(device); if (!driver_data->initialized) return -1; @@ -163,8 +164,12 @@ static error_t set_config(Device* device, const struct UartConfig* config) { .parity = to_esp32_parity(config->parity), .stop_bits = to_esp32_stop_bits(config->stop_bits), .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_thls = 0, + .rx_flow_ctrl_thresh = 0, .source_clk = UART_SCLK_DEFAULT, + .flags = { + .allow_pd = 0, + .backup_before_sleep = 0 + } }; if (config->cts_pin != -1 || config->rts_pin != -1) { diff --git a/TactilityKernel/Include/tactility/drivers/uart_controller.h b/TactilityKernel/Include/tactility/drivers/uart_controller.h index dc2adfd35..529e0d701 100644 --- a/TactilityKernel/Include/tactility/drivers/uart_controller.h +++ b/TactilityKernel/Include/tactility/drivers/uart_controller.h @@ -103,10 +103,9 @@ struct UartControllerApi { /** * @brief Returns the number of bytes available for reading. * @param[in] device the UART controller device - * @param[in] timeout the maximum time to wait for the operation to complete * @return the number of bytes available, or a negative error code on failure */ - int (*available)(struct Device* device, TickType_t timeout); + int (*available)(struct Device* device); /** * @brief Sets the UART configuration. @@ -155,7 +154,7 @@ error_t uart_controller_read_bytes(struct Device* device, uint8_t* buffer, size_ /** * @brief Returns the number of bytes available for reading using the specified controller. */ -int uart_controller_available(struct Device* device, TickType_t timeout); +int uart_controller_available(struct Device* device); /** * @brief Sets the UART configuration using the specified controller. diff --git a/TactilityKernel/Source/drivers/gpio_controller.cpp b/TactilityKernel/Source/drivers/gpio_controller.cpp index f7e3a5832..376409bdb 100644 --- a/TactilityKernel/Source/drivers/gpio_controller.cpp +++ b/TactilityKernel/Source/drivers/gpio_controller.cpp @@ -32,7 +32,7 @@ error_t gpio_controller_get_pin_count(struct Device* device, uint32_t* count) { return GPIO_DRIVER_API(driver)->get_pin_count(device, count); } -extern const struct DeviceType GPIO_CONTROLLER_TYPE { +const struct DeviceType GPIO_CONTROLLER_TYPE { .name = "gpio-controller" }; diff --git a/TactilityKernel/Source/drivers/i2c_controller.cpp b/TactilityKernel/Source/drivers/i2c_controller.cpp index 31a92519e..0fbafaf38 100644 --- a/TactilityKernel/Source/drivers/i2c_controller.cpp +++ b/TactilityKernel/Source/drivers/i2c_controller.cpp @@ -49,7 +49,7 @@ error_t i2c_controller_has_device_at_address(Device* device, uint8_t address, Ti return I2C_DRIVER_API(driver)->write(device, address, message, 2, timeout); } -extern const struct DeviceType I2C_CONTROLLER_TYPE { +const struct DeviceType I2C_CONTROLLER_TYPE { .name = "i2c-controller" }; diff --git a/TactilityKernel/Source/drivers/i2s_controller.cpp b/TactilityKernel/Source/drivers/i2s_controller.cpp index e4c04c726..a228d3bdd 100644 --- a/TactilityKernel/Source/drivers/i2s_controller.cpp +++ b/TactilityKernel/Source/drivers/i2s_controller.cpp @@ -32,7 +32,7 @@ error_t i2s_controller_reset(struct Device* device) { return I2S_DRIVER_API(driver)->reset(device); } -extern const struct DeviceType I2S_CONTROLLER_TYPE { +const struct DeviceType I2S_CONTROLLER_TYPE { .name = "i2s-controller" }; diff --git a/TactilityKernel/Source/drivers/spi_controller.cpp b/TactilityKernel/Source/drivers/spi_controller.cpp index f10e8a007..7b0c6c342 100644 --- a/TactilityKernel/Source/drivers/spi_controller.cpp +++ b/TactilityKernel/Source/drivers/spi_controller.cpp @@ -27,7 +27,7 @@ error_t spi_controller_unlock(struct Device* device) { return SPI_DRIVER_API(driver)->unlock(device); } -extern const struct DeviceType SPI_CONTROLLER_TYPE { +const struct DeviceType SPI_CONTROLLER_TYPE { .name = "spi-controller" }; diff --git a/TactilityKernel/Source/drivers/uart_controller.cpp b/TactilityKernel/Source/drivers/uart_controller.cpp index 72c65eaee..986be61fb 100644 --- a/TactilityKernel/Source/drivers/uart_controller.cpp +++ b/TactilityKernel/Source/drivers/uart_controller.cpp @@ -27,9 +27,9 @@ error_t uart_controller_read_bytes(struct Device* device, uint8_t* buffer, size_ return UART_DRIVER_API(driver)->read_bytes(device, buffer, buffer_size, timeout); } -int uart_controller_available(struct Device* device, TickType_t timeout) { +int uart_controller_available(struct Device* device) { const auto* driver = device_get_driver(device); - return UART_DRIVER_API(driver)->available(device, timeout); + return UART_DRIVER_API(driver)->available(device); } error_t uart_controller_set_config(struct Device* device, const struct UartConfig* config) { @@ -47,7 +47,7 @@ error_t uart_controller_reset(struct Device* device) { return UART_DRIVER_API(driver)->reset(device); } -extern const struct DeviceType UART_CONTROLLER_TYPE { +const struct DeviceType UART_CONTROLLER_TYPE { .name = "uart-controller" }; From c4743e6869bccdd452b33578c8da376a155c660e Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 7 Feb 2026 13:59:11 +0100 Subject: [PATCH 06/19] Fixes --- Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp | 2 +- Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp | 6 +++--- TactilityKernel/Include/tactility/drivers/spi_controller.h | 2 +- TactilityKernel/Include/tactility/drivers/uart_controller.h | 4 ++-- TactilityKernel/Source/drivers/uart_controller.cpp | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp index 6cff102ce..6514cbca4 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp @@ -16,7 +16,7 @@ extern "C" { struct InternalData { Mutex mutex; - bool initialized; + bool initialized = false; InternalData() { mutex_construct(&mutex); diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp index 4f9bc8b6a..a068fa69c 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp @@ -32,8 +32,8 @@ struct InternalData { #define GET_CONFIG(device) ((Esp32UartConfig*)device->config) #define GET_DATA(device) ((InternalData*)device_get_driver_data(device)) -#define lock(data) mutex_lock(&data->mutex); -#define unlock(data) mutex_unlock(&data->mutex); +#define lock(data) mutex_lock(&data->mutex) +#define unlock(data) mutex_unlock(&data->mutex) extern "C" { @@ -106,7 +106,7 @@ static error_t write_byte(Device* device, uint8_t out, TickType_t timeout) { return ERROR_NONE; } -static error_t write_bytes(Device* device, uint8_t* buffer, size_t buffer_size, TickType_t timeout) { +static error_t write_bytes(Device* device, const uint8_t* buffer, size_t buffer_size, TickType_t timeout) { if (xPortInIsrContext()) return ERROR_ISR_STATUS; auto* driver_data = GET_DATA(device); auto* dts_config = GET_CONFIG(device); diff --git a/TactilityKernel/Include/tactility/drivers/spi_controller.h b/TactilityKernel/Include/tactility/drivers/spi_controller.h index 509d4a2b9..82defec5f 100644 --- a/TactilityKernel/Include/tactility/drivers/spi_controller.h +++ b/TactilityKernel/Include/tactility/drivers/spi_controller.h @@ -64,7 +64,7 @@ error_t spi_controller_lock(struct Device* device); /** * @brief Tries to lock the SPI controller using the specified controller. * @param[in] device the SPI controller device -* @param[in] timeout the maximum time to wait for the lock + * @param[in] timeout the maximum ticks to wait for the lock * @retval ERROR_NONE when the operation was successful * @retval ERROR_TIMEOUT when the operation timed out */ diff --git a/TactilityKernel/Include/tactility/drivers/uart_controller.h b/TactilityKernel/Include/tactility/drivers/uart_controller.h index 529e0d701..24b99a541 100644 --- a/TactilityKernel/Include/tactility/drivers/uart_controller.h +++ b/TactilityKernel/Include/tactility/drivers/uart_controller.h @@ -87,7 +87,7 @@ struct UartControllerApi { * @retval ERROR_NONE when the write operation was successful * @retval ERROR_TIMEOUT when the operation timed out */ - error_t (*write_bytes)(struct Device* device, uint8_t* buffer, size_t buffer_size, TickType_t timeout); + error_t (*write_bytes)(struct Device* device, const uint8_t* buffer, size_t buffer_size, TickType_t timeout); /** * @brief Reads multiple bytes from UART. @@ -144,7 +144,7 @@ error_t uart_controller_write_byte(struct Device* device, uint8_t out, TickType_ /** * @brief Writes multiple bytes to UART using the specified controller. */ -error_t uart_controller_write_bytes(struct Device* device, uint8_t* buffer, size_t buffer_size, TickType_t timeout); +error_t uart_controller_write_bytes(struct Device* device, const uint8_t* buffer, size_t buffer_size, TickType_t timeout); /** * @brief Reads multiple bytes from UART using the specified controller. diff --git a/TactilityKernel/Source/drivers/uart_controller.cpp b/TactilityKernel/Source/drivers/uart_controller.cpp index 986be61fb..21d70f3e0 100644 --- a/TactilityKernel/Source/drivers/uart_controller.cpp +++ b/TactilityKernel/Source/drivers/uart_controller.cpp @@ -17,7 +17,7 @@ error_t uart_controller_write_byte(struct Device* device, uint8_t out, TickType_ return UART_DRIVER_API(driver)->write_byte(device, out, timeout); } -error_t uart_controller_write_bytes(struct Device* device, uint8_t* buffer, size_t buffer_size, TickType_t timeout) { +error_t uart_controller_write_bytes(struct Device* device, const uint8_t* buffer, size_t buffer_size, TickType_t timeout) { const auto* driver = device_get_driver(device); return UART_DRIVER_API(driver)->write_bytes(device, buffer, buffer_size, timeout); } From c5345bd9648055896cab3b1ad6b00796b2a96a39 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 7 Feb 2026 14:06:27 +0100 Subject: [PATCH 07/19] Simplify esp32_i2c config access --- .../PlatformEsp32/Include/tactility/drivers/esp32_i2c.h | 1 - Platforms/PlatformEsp32/Source/drivers/esp32_i2c.cpp | 5 ----- Tactility/Source/hal/i2c/I2c.cpp | 5 ++--- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/Platforms/PlatformEsp32/Include/tactility/drivers/esp32_i2c.h b/Platforms/PlatformEsp32/Include/tactility/drivers/esp32_i2c.h index 67fc6d837..b754fa961 100644 --- a/Platforms/PlatformEsp32/Include/tactility/drivers/esp32_i2c.h +++ b/Platforms/PlatformEsp32/Include/tactility/drivers/esp32_i2c.h @@ -17,7 +17,6 @@ struct Esp32I2cConfig { bool pinSclPullUp; }; -error_t esp32_i2c_get_port(struct Device* device, i2c_port_t* port); #ifdef __cplusplus } diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_i2c.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_i2c.cpp index b6992805e..b3827dc2a 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_i2c.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_i2c.cpp @@ -144,11 +144,6 @@ static error_t write_register(Device* device, uint8_t address, uint8_t reg, cons return esp_err_to_error(error); } -error_t esp32_i2c_get_port(struct Device* device, i2c_port_t* port) { - auto* config = GET_CONFIG(device); - *port = config->port; - return ERROR_NONE; -} static error_t start(Device* device) { ESP_LOGI(TAG, "start %s", device->name); diff --git a/Tactility/Source/hal/i2c/I2c.cpp b/Tactility/Source/hal/i2c/I2c.cpp index 50242e5b9..ae8bb62e4 100644 --- a/Tactility/Source/hal/i2c/I2c.cpp +++ b/Tactility/Source/hal/i2c/I2c.cpp @@ -37,9 +37,8 @@ Device* findDevice(i2c_port_t port) { auto* driver = device_get_driver(device); if (driver == nullptr) return true; if (!driver_is_compatible(driver, "espressif,esp32-i2c")) return true; - i2c_port_t port; - if (esp32_i2c_get_port(device, &port) != ERROR_NONE) return true; - if (port != params_ptr->port) return true; + auto* config = static_cast(device->config); + if (config->port != params_ptr->port) return true; // Found it, stop iterating params_ptr->device = device; return false; From 6a88f6617dc265f4722910470a022c32bc0b91a8 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 7 Feb 2026 15:04:49 +0100 Subject: [PATCH 08/19] Fixes --- .../Source/drivers/esp32_uart.cpp | 172 ++++++++++++++---- TactilityKernel/Include/tactility/device.h | 2 +- .../tactility/drivers/gpio_controller.h | 2 + .../tactility/drivers/i2c_controller.h | 2 + .../tactility/drivers/i2s_controller.h | 2 + .../tactility/drivers/spi_controller.h | 2 + .../tactility/drivers/uart_controller.h | 47 ++++- .../Source/drivers/uart_controller.cpp | 19 +- 8 files changed, 206 insertions(+), 42 deletions(-) diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp index a068fa69c..33ff913a5 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp @@ -18,7 +18,7 @@ struct InternalData { Mutex mutex {}; UartConfig config {}; bool config_set = false; - bool initialized = false; + bool is_open = false; InternalData() { mutex_construct(&mutex); @@ -37,14 +37,6 @@ struct InternalData { extern "C" { -static error_t cleanup_uart(InternalData* driver_data, uart_port_t port) { - if (driver_data->initialized) { - uart_driver_delete(port); - driver_data->initialized = false; - } - return ERROR_NONE; -} - static uart_parity_t to_esp32_parity(enum UartParity parity) { switch (parity) { case UART_CONTROLLER_PARITY_DISABLE: return UART_PARITY_DISABLE; @@ -77,9 +69,16 @@ static error_t read_byte(Device* device, uint8_t* out, TickType_t timeout) { if (xPortInIsrContext()) return ERROR_ISR_STATUS; auto* driver_data = GET_DATA(device); auto* dts_config = GET_CONFIG(device); - if (!driver_data->initialized) return ERROR_INVALID_STATE; + + lock(driver_data); + if (!driver_data->is_open) { + unlock(driver_data); + return ERROR_INVALID_STATE; + } int len = uart_read_bytes(dts_config->port, out, 1, timeout); + unlock(driver_data); + if (len < 0) return ERROR_RESOURCE; if (len == 0) return ERROR_TIMEOUT; return ERROR_NONE; @@ -89,18 +88,29 @@ static error_t write_byte(Device* device, uint8_t out, TickType_t timeout) { if (xPortInIsrContext()) return ERROR_ISR_STATUS; auto* driver_data = GET_DATA(device); auto* dts_config = GET_CONFIG(device); - if (!driver_data->initialized) return ERROR_INVALID_STATE; + + lock(driver_data); + if (!driver_data->is_open) { + unlock(driver_data); + return ERROR_INVALID_STATE; + } int len = uart_write_bytes(dts_config->port, (const char*)&out, 1); - if (len < 0) return ERROR_RESOURCE; + if (len < 0) { + unlock(driver_data); + return ERROR_RESOURCE; + } // uart_write_bytes is non-blocking on the buffer but we might want to wait for it to be sent? // The API signature has timeout, but ESP-IDF's uart_write_bytes doesn't use it for blocking. // However, if we want to ensure it's SENT, we could use uart_wait_tx_done. if (timeout > 0) { esp_err_t err = uart_wait_tx_done(dts_config->port, timeout); + unlock(driver_data); if (err == ESP_ERR_TIMEOUT) return ERROR_TIMEOUT; if (err != ESP_OK) return ERROR_RESOURCE; + } else { + unlock(driver_data); } return ERROR_NONE; @@ -110,15 +120,26 @@ static error_t write_bytes(Device* device, const uint8_t* buffer, size_t buffer_ if (xPortInIsrContext()) return ERROR_ISR_STATUS; auto* driver_data = GET_DATA(device); auto* dts_config = GET_CONFIG(device); - if (!driver_data->initialized) return ERROR_INVALID_STATE; + + lock(driver_data); + if (!driver_data->is_open) { + unlock(driver_data); + return ERROR_INVALID_STATE; + } int len = uart_write_bytes(dts_config->port, (const char*)buffer, buffer_size); - if (len < 0) return ERROR_RESOURCE; + if (len < 0) { + unlock(driver_data); + return ERROR_RESOURCE; + } if (timeout > 0) { esp_err_t err = uart_wait_tx_done(dts_config->port, timeout); + unlock(driver_data); if (err == ESP_ERR_TIMEOUT) return ERROR_TIMEOUT; if (err != ESP_OK) return ERROR_RESOURCE; + } else { + unlock(driver_data); } return ERROR_NONE; @@ -128,9 +149,16 @@ static error_t read_bytes(Device* device, uint8_t* buffer, size_t buffer_size, T if (xPortInIsrContext()) return ERROR_ISR_STATUS; auto* driver_data = GET_DATA(device); auto* dts_config = GET_CONFIG(device); - if (!driver_data->initialized) return ERROR_INVALID_STATE; + + lock(driver_data); + if (!driver_data->is_open) { + unlock(driver_data); + return ERROR_INVALID_STATE; + } int len = uart_read_bytes(dts_config->port, buffer, buffer_size, timeout); + unlock(driver_data); + if (len < 0) return ERROR_RESOURCE; if (len < (int)buffer_size) return ERROR_TIMEOUT; @@ -140,10 +168,17 @@ static error_t read_bytes(Device* device, uint8_t* buffer, size_t buffer_size, T static int available(Device* device) { auto* driver_data = GET_DATA(device); auto* dts_config = GET_CONFIG(device); - if (!driver_data->initialized) return -1; + + lock(driver_data); + if (!driver_data->is_open) { + unlock(driver_data); + return -1; + } size_t size; esp_err_t err = uart_get_buffered_data_len(dts_config->port, &size); + unlock(driver_data); + if (err != ESP_OK) return -1; return (int)size; } @@ -155,8 +190,10 @@ static error_t set_config(Device* device, const struct UartConfig* config) { auto* dts_config = GET_CONFIG(device); lock(driver_data); - cleanup_uart(driver_data, dts_config->port); - driver_data->config_set = false; + if (driver_data->is_open) { + unlock(driver_data); + return ERROR_INVALID_STATE; + } uart_config_t uart_cfg = { .baud_rate = (int)config->baud_rate, @@ -182,18 +219,13 @@ static error_t set_config(Device* device, const struct UartConfig* config) { if (esp_error == ESP_OK) { esp_error = uart_set_pin(dts_config->port, dts_config->pinTx, dts_config->pinRx, dts_config->pinCts, dts_config->pinRts); } - if (esp_error == ESP_OK) { - // We use a buffer size of 1024 for both RX and TX by default - esp_error = uart_driver_install(dts_config->port, 1024 * 2, 0, 0, NULL, 0); - } if (esp_error != ESP_OK) { - LOG_E(TAG, "Failed to initialize UART: %s", esp_err_to_name(esp_error)); + LOG_E(TAG, "Failed to configure UART: %s", esp_err_to_name(esp_error)); unlock(driver_data); return esp_err_to_error(esp_error); } - driver_data->initialized = true; memcpy(&driver_data->config, config, sizeof(UartConfig)); driver_data->config_set = true; @@ -201,6 +233,60 @@ static error_t set_config(Device* device, const struct UartConfig* config) { return ERROR_NONE; } +static error_t open(Device* device) { + if (xPortInIsrContext()) return ERROR_ISR_STATUS; + auto* driver_data = GET_DATA(device); + auto* dts_config = GET_CONFIG(device); + + lock(driver_data); + if (driver_data->is_open) { + unlock(driver_data); + return ERROR_NONE; + } + + if (!driver_data->config_set) { + unlock(driver_data); + return ERROR_INVALID_STATE; + } + + esp_err_t esp_error = uart_driver_install(dts_config->port, 1024, 0, 0, NULL, 0); + if (esp_error != ESP_OK) { + LOG_E(TAG, "Failed to install UART driver: %s", esp_err_to_name(esp_error)); + unlock(driver_data); + return esp_err_to_error(esp_error); + } + + driver_data->is_open = true; + + unlock(driver_data); + return ERROR_NONE; +} + +static error_t close(Device* device) { + if (xPortInIsrContext()) return ERROR_ISR_STATUS; + auto* driver_data = GET_DATA(device); + auto* dts_config = GET_CONFIG(device); + + lock(driver_data); + if (!driver_data->is_open) { + unlock(driver_data); + return ERROR_INVALID_STATE; + } + uart_driver_delete(dts_config->port); + driver_data->is_open = false; + unlock(driver_data); + + return ERROR_NONE; +} + +static bool is_open(Device* device) { + auto* driver_data = GET_DATA(device); + lock(driver_data); + bool status = driver_data->is_open; + unlock(driver_data); + return status; +} + static error_t get_config(Device* device, struct UartConfig* config) { auto* driver_data = GET_DATA(device); @@ -215,6 +301,22 @@ static error_t get_config(Device* device, struct UartConfig* config) { return ERROR_NONE; } +static error_t flush_input(Device* device) { + auto* driver_data = GET_DATA(device); + auto* dts_config = GET_CONFIG(device); + + lock(driver_data); + if (!driver_data->is_open) { + unlock(driver_data); + return ERROR_INVALID_STATE; + } + + esp_err_t err = uart_flush_input(dts_config->port); + unlock(driver_data); + + return esp_err_to_error(err); +} + static error_t start(Device* device) { ESP_LOGI(TAG, "start %s", device->name); auto* data = new(std::nothrow) InternalData(); @@ -231,24 +333,17 @@ static error_t stop(Device* device) { auto* dts_config = GET_CONFIG(device); lock(driver_data); - cleanup_uart(driver_data, dts_config->port); + if (driver_data->is_open) { + unlock(driver_data); + return ERROR_INVALID_STATE; + } + device_set_driver_data(device, nullptr); unlock(driver_data); - device_set_driver_data(device, nullptr); delete driver_data; return ERROR_NONE; } -static error_t reset(Device* device) { - ESP_LOGI(TAG, "reset %s", device->name); - auto* driver_data = GET_DATA(device); - auto* dts_config = GET_CONFIG(device); - lock(driver_data); - cleanup_uart(driver_data, dts_config->port); - unlock(driver_data); - return ERROR_NONE; -} - const static UartControllerApi esp32_uart_api = { .read_byte = read_byte, .write_byte = write_byte, @@ -257,7 +352,10 @@ const static UartControllerApi esp32_uart_api = { .available = available, .set_config = set_config, .get_config = get_config, - .reset = reset + .open = open, + .close = close, + .is_open = is_open, + .flush_input = flush_input }; extern struct Module platform_module; diff --git a/TactilityKernel/Include/tactility/device.h b/TactilityKernel/Include/tactility/device.h index d0604f12e..81c34c860 100644 --- a/TactilityKernel/Include/tactility/device.h +++ b/TactilityKernel/Include/tactility/device.h @@ -46,7 +46,7 @@ struct Device { /** * Holds a device pointer and a compatible string. * The device must not be constructed, added or started yet. - * This is used by the devicetree code generator and the application init sequence. + * This is used by the devicetree code generator and the application init sequence::. */ struct CompatibleDevice { struct Device* device; diff --git a/TactilityKernel/Include/tactility/drivers/gpio_controller.h b/TactilityKernel/Include/tactility/drivers/gpio_controller.h index e81e2590b..cd15fe30e 100644 --- a/TactilityKernel/Include/tactility/drivers/gpio_controller.h +++ b/TactilityKernel/Include/tactility/drivers/gpio_controller.h @@ -9,6 +9,8 @@ extern "C" { #include "gpio.h" #include +struct Device; + struct GpioControllerApi { /** * @brief Sets the logical level of a GPIO pin. diff --git a/TactilityKernel/Include/tactility/drivers/i2c_controller.h b/TactilityKernel/Include/tactility/drivers/i2c_controller.h index fe54628f2..96ce39fd7 100644 --- a/TactilityKernel/Include/tactility/drivers/i2c_controller.h +++ b/TactilityKernel/Include/tactility/drivers/i2c_controller.h @@ -13,6 +13,8 @@ extern "C" { #include #include +struct Device; + /** * @brief API for I2C controller drivers. */ diff --git a/TactilityKernel/Include/tactility/drivers/i2s_controller.h b/TactilityKernel/Include/tactility/drivers/i2s_controller.h index 8afe72625..13f473091 100644 --- a/TactilityKernel/Include/tactility/drivers/i2s_controller.h +++ b/TactilityKernel/Include/tactility/drivers/i2s_controller.h @@ -14,6 +14,8 @@ extern "C" { #include #include +struct Device; + /** * @brief I2S communication format */ diff --git a/TactilityKernel/Include/tactility/drivers/spi_controller.h b/TactilityKernel/Include/tactility/drivers/spi_controller.h index 82defec5f..f248759ae 100644 --- a/TactilityKernel/Include/tactility/drivers/spi_controller.h +++ b/TactilityKernel/Include/tactility/drivers/spi_controller.h @@ -12,6 +12,8 @@ extern "C" { #include #include +struct Device; + /** * @brief API for SPI controller drivers. */ diff --git a/TactilityKernel/Include/tactility/drivers/uart_controller.h b/TactilityKernel/Include/tactility/drivers/uart_controller.h index 24b99a541..dd316d639 100644 --- a/TactilityKernel/Include/tactility/drivers/uart_controller.h +++ b/TactilityKernel/Include/tactility/drivers/uart_controller.h @@ -12,6 +12,8 @@ extern "C" { #include #include +struct Device; + /** * @brief UART parity modes */ @@ -124,11 +126,32 @@ struct UartControllerApi { error_t (*get_config)(struct Device* device, struct UartConfig* config); /** - * @brief Resets the UART controller. Must configure it again before it can be used. + * @brief Opens the UART controller. * @param[in] device the UART controller device * @retval ERROR_NONE when the operation was successful */ - error_t (*reset)(struct Device* device); + error_t (*open)(struct Device* device); + + /** + * @brief Closes the UART controller. + * @param[in] device the UART controller device + * @retval ERROR_NONE when the operation was successful + */ + error_t (*close)(struct Device* device); + + /** + * @brief Checks if the UART controller is open. + * @param[in] device the UART controller device + * @return true if open, false otherwise + */ + bool (*is_open)(struct Device* device); + + /** + * @brief Flushes the UART input buffer. + * @param[in] device the UART controller device + * @retval ERROR_NONE when the operation was successful + */ + error_t (*flush_input)(struct Device* device); }; /** @@ -166,11 +189,31 @@ error_t uart_controller_set_config(struct Device* device, const struct UartConfi */ error_t uart_controller_get_config(struct Device* device, struct UartConfig* config); +/** + * @brief Opens the UART controller using the specified controller. + */ +error_t uart_controller_open(struct Device* device); + +/** + * @brief Closes the UART controller using the specified controller. + */ +error_t uart_controller_close(struct Device* device); + +/** + * @brief Checks if the UART controller is open using the specified controller. + */ +bool uart_controller_is_open(struct Device* device); + /** * @brief Resets the UART controller using the specified controller. */ error_t uart_controller_reset(struct Device* device); +/** + * @brief Flushes the UART input buffer using the specified controller. + */ +error_t uart_controller_flush_input(struct Device* device); + extern const struct DeviceType UART_CONTROLLER_TYPE; #ifdef __cplusplus diff --git a/TactilityKernel/Source/drivers/uart_controller.cpp b/TactilityKernel/Source/drivers/uart_controller.cpp index 21d70f3e0..25ddb9d6b 100644 --- a/TactilityKernel/Source/drivers/uart_controller.cpp +++ b/TactilityKernel/Source/drivers/uart_controller.cpp @@ -42,9 +42,24 @@ error_t uart_controller_get_config(struct Device* device, struct UartConfig* con return UART_DRIVER_API(driver)->get_config(device, config); } -error_t uart_controller_reset(struct Device* device) { +error_t uart_controller_open(struct Device* device) { const auto* driver = device_get_driver(device); - return UART_DRIVER_API(driver)->reset(device); + return UART_DRIVER_API(driver)->open(device); +} + +error_t uart_controller_close(struct Device* device) { + const auto* driver = device_get_driver(device); + return UART_DRIVER_API(driver)->close(device); +} + +bool uart_controller_is_open(struct Device* device) { + const auto* driver = device_get_driver(device); + return UART_DRIVER_API(driver)->is_open(device); +} + +error_t uart_controller_flush_input(struct Device* device) { + const auto* driver = device_get_driver(device); + return UART_DRIVER_API(driver)->flush_input(device); } const struct DeviceType UART_CONTROLLER_TYPE { From 9a401ac795a9644bc10455c81e70009563421284 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 7 Feb 2026 15:08:00 +0100 Subject: [PATCH 09/19] Fix --- .../Source/drivers/esp32_uart.cpp | 34 ++++++++----------- .../tactility/drivers/uart_controller.h | 4 --- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp index 33ff913a5..458d86948 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp @@ -209,12 +209,6 @@ static error_t set_config(Device* device, const struct UartConfig* config) { } }; - if (config->cts_pin != -1 || config->rts_pin != -1) { - uart_cfg.flow_ctrl = UART_HW_FLOWCTRL_CTS_RTS; - if (config->cts_pin != -1 && config->rts_pin == -1) uart_cfg.flow_ctrl = UART_HW_FLOWCTRL_CTS; - if (config->cts_pin == -1 && config->rts_pin != -1) uart_cfg.flow_ctrl = UART_HW_FLOWCTRL_RTS; - } - esp_err_t esp_error = uart_param_config(dts_config->port, &uart_cfg); if (esp_error == ESP_OK) { esp_error = uart_set_pin(dts_config->port, dts_config->pinTx, dts_config->pinRx, dts_config->pinCts, dts_config->pinRts); @@ -233,6 +227,20 @@ static error_t set_config(Device* device, const struct UartConfig* config) { return ERROR_NONE; } +static error_t get_config(Device* device, struct UartConfig* config) { + auto* driver_data = GET_DATA(device); + + lock(driver_data); + if (!driver_data->config_set) { + unlock(driver_data); + return ERROR_RESOURCE; + } + memcpy(config, &driver_data->config, sizeof(UartConfig)); + unlock(driver_data); + + return ERROR_NONE; +} + static error_t open(Device* device) { if (xPortInIsrContext()) return ERROR_ISR_STATUS; auto* driver_data = GET_DATA(device); @@ -287,20 +295,6 @@ static bool is_open(Device* device) { return status; } -static error_t get_config(Device* device, struct UartConfig* config) { - auto* driver_data = GET_DATA(device); - - lock(driver_data); - if (!driver_data->config_set) { - unlock(driver_data); - return ERROR_RESOURCE; - } - memcpy(config, &driver_data->config, sizeof(UartConfig)); - unlock(driver_data); - - return ERROR_NONE; -} - static error_t flush_input(Device* device) { auto* driver_data = GET_DATA(device); auto* dts_config = GET_CONFIG(device); diff --git a/TactilityKernel/Include/tactility/drivers/uart_controller.h b/TactilityKernel/Include/tactility/drivers/uart_controller.h index dd316d639..5e74d7a14 100644 --- a/TactilityKernel/Include/tactility/drivers/uart_controller.h +++ b/TactilityKernel/Include/tactility/drivers/uart_controller.h @@ -50,10 +50,6 @@ struct UartConfig { enum UartDataBits data_bits; enum UartParity parity; enum UartStopBits stop_bits; - int8_t tx_pin; - int8_t rx_pin; - int8_t cts_pin; - int8_t rts_pin; }; /** From 91b76105712b661f8928386d1da8bfd7a4375814 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 7 Feb 2026 15:13:12 +0100 Subject: [PATCH 10/19] Add device_find_by_name --- TactilityKernel/Include/tactility/device.h | 8 ++++++++ TactilityKernel/Source/device.cpp | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/TactilityKernel/Include/tactility/device.h b/TactilityKernel/Include/tactility/device.h index 81c34c860..44f651270 100644 --- a/TactilityKernel/Include/tactility/device.h +++ b/TactilityKernel/Include/tactility/device.h @@ -259,6 +259,14 @@ void device_for_each_child(struct Device* device, void* callback_context, bool(* */ void device_for_each_of_type(const struct DeviceType* type, void* callback_context, bool(*on_device)(struct Device* device, void* context)); +/** + * Find a device by its name. + * + * @param[in] name non-null device name to look up + * @return the device pointer if found, or NULL if not found + */ +struct Device* device_find_by_name(const char* name); + #ifdef __cplusplus } #endif diff --git a/TactilityKernel/Source/device.cpp b/TactilityKernel/Source/device.cpp index fb29dc22a..066d10fe3 100644 --- a/TactilityKernel/Source/device.cpp +++ b/TactilityKernel/Source/device.cpp @@ -338,4 +338,17 @@ void device_for_each_of_type(const DeviceType* type, void* callbackContext, bool ledger_unlock(); } +Device* device_find_by_name(const char* name) { + Device* found = nullptr; + ledger_lock(); + for (auto* device : ledger.devices) { + if (device->name != nullptr && std::strcmp(device->name, name) == 0) { + found = device; + break; + } + } + ledger_unlock(); + return found; +} + } // extern "C" From 452f3053f690cd803e1e33d3a45f7cc856437607 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 7 Feb 2026 16:54:14 +0100 Subject: [PATCH 11/19] Refactor UART usage --- Devices/lilygo-tdeck/Source/Configuration.cpp | 25 --- Devices/lilygo-tdeck/Source/Init.cpp | 2 +- Devices/lilygo-tdeck/lilygo,tdeck.dts | 10 + .../Source/drivers/esp32_spi.cpp | 62 +++--- .../Source/drivers/esp32_uart.cpp | 26 +-- .../Include/Tactility/hal/Configuration.h | 5 - .../Tactility/hal/uart/Configuration.h | 43 ---- Tactility/Include/Tactility/hal/uart/Uart.h | 131 ------------ .../Include/Tactility/hal/uart/UartCompat.h | 17 -- Tactility/Private/Tactility/hal/gps/GpsInit.h | 4 +- Tactility/Private/Tactility/hal/gps/Probe.h | 5 +- Tactility/Private/Tactility/hal/gps/Ublox.h | 9 +- .../Private/Tactility/hal/uart/UartEsp.h | 36 ---- .../Private/Tactility/hal/uart/UartInit.h | 9 - .../Private/Tactility/hal/uart/UartPosix.h | 47 ----- Tactility/Source/Tactility.cpp | 5 +- Tactility/Source/app/addgps/AddGps.cpp | 28 ++- .../Source/app/gpssettings/GpsSettings.cpp | 18 +- .../Source/app/i2cscanner/I2cHelpers.cpp | 2 +- Tactility/Source/hal/Hal.cpp | 3 - Tactility/Source/hal/gps/GpsDevice.cpp | 34 +++- Tactility/Source/hal/gps/GpsInit.cpp | 93 +++++---- Tactility/Source/hal/gps/Probe.cpp | 36 ++-- Tactility/Source/hal/gps/Ublox.cpp | 86 ++++---- Tactility/Source/hal/uart/Uart.cpp | 192 ------------------ Tactility/Source/hal/uart/UartEsp.cpp | 157 -------------- Tactility/Source/hal/uart/UartPosix.cpp | 191 ----------------- TactilityC/Include/tt_hal_uart.h | 7 + TactilityC/Source/tt_hal_uart.cpp | 47 ++--- TactilityKernel/Include/tactility/device.h | 8 + .../tactility/drivers/spi_controller.h | 14 -- .../tactility/drivers/uart_controller.h | 28 ++- TactilityKernel/Source/device.cpp | 14 ++ .../Source/drivers/spi_controller.cpp | 5 - .../Source/drivers/uart_controller.cpp | 50 ++++- TactilityKernel/Source/kernel_symbols.c | 23 ++- 36 files changed, 373 insertions(+), 1099 deletions(-) delete mode 100644 Tactility/Include/Tactility/hal/uart/Configuration.h delete mode 100644 Tactility/Include/Tactility/hal/uart/Uart.h delete mode 100644 Tactility/Include/Tactility/hal/uart/UartCompat.h delete mode 100644 Tactility/Private/Tactility/hal/uart/UartEsp.h delete mode 100644 Tactility/Private/Tactility/hal/uart/UartInit.h delete mode 100644 Tactility/Private/Tactility/hal/uart/UartPosix.h delete mode 100644 Tactility/Source/hal/uart/Uart.cpp delete mode 100644 Tactility/Source/hal/uart/UartEsp.cpp delete mode 100644 Tactility/Source/hal/uart/UartPosix.cpp diff --git a/Devices/lilygo-tdeck/Source/Configuration.cpp b/Devices/lilygo-tdeck/Source/Configuration.cpp index b01785fe6..73b3c7a8b 100644 --- a/Devices/lilygo-tdeck/Source/Configuration.cpp +++ b/Devices/lilygo-tdeck/Source/Configuration.cpp @@ -50,30 +50,5 @@ extern const Configuration hardwareConfiguration = { .isMutable = false, .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display } - }, - .uart { - uart::Configuration { - .name = "Grove", - .port = UART_NUM_1, - .rxPin = GPIO_NUM_44, - .txPin = GPIO_NUM_43, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 38400, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } - } } }; diff --git a/Devices/lilygo-tdeck/Source/Init.cpp b/Devices/lilygo-tdeck/Source/Init.cpp index 416bf8301..b0635dbe5 100644 --- a/Devices/lilygo-tdeck/Source/Init.cpp +++ b/Devices/lilygo-tdeck/Source/Init.cpp @@ -58,7 +58,7 @@ bool initBoot() { std::vector gps_configurations; gps_service->getGpsConfigurations(gps_configurations); if (gps_configurations.empty()) { - if (gps_service->addGpsConfiguration(tt::hal::gps::GpsConfiguration {.uartName = "Grove", .baudRate = 38400, .model = tt::hal::gps::GpsModel::UBLOX10})) { + if (gps_service->addGpsConfiguration(tt::hal::gps::GpsConfiguration {.uartName = "uart0", .baudRate = 38400, .model = tt::hal::gps::GpsModel::UBLOX10})) { LOGGER.info("Configured internal GPS"); } else { LOGGER.error("Failed to configure internal GPS"); diff --git a/Devices/lilygo-tdeck/lilygo,tdeck.dts b/Devices/lilygo-tdeck/lilygo,tdeck.dts index 559af7ec0..6d59a9aab 100644 --- a/Devices/lilygo-tdeck/lilygo,tdeck.dts +++ b/Devices/lilygo-tdeck/lilygo,tdeck.dts @@ -4,6 +4,7 @@ #include #include #include +#include // Reference: https://wiki.lilygo.cc/get_started/en/Wearable/T-Deck-Plus/T-Deck-Plus.html#Pin-Overview / { @@ -40,4 +41,13 @@ pin-data-in = ; pin-mclk = ; }; + + uart0 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <43>; + pin-rx = <44>; + pin-cts = ; + pin-rtx = ; + }; }; diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp index 6514cbca4..261cb751e 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp @@ -3,9 +3,10 @@ #include #include +#include #include #include -#include +#include #define TAG "esp32_spi" @@ -27,34 +28,6 @@ struct InternalData { } }; -static error_t reset(Device* device) { - auto* driver_data = GET_DATA(device); - auto* dts_config = GET_CONFIG(device); - - if (driver_data->initialized) { - spi_bus_free(dts_config->host); - driver_data->initialized = false; - } - - spi_bus_config_t buscfg = { - .mosi_io_num = dts_config->pin_mosi, - .miso_io_num = dts_config->pin_miso, - .sclk_io_num = dts_config->pin_sclk, - .quadwp_io_num = dts_config->pin_wp, - .quadhd_io_num = dts_config->pin_hd, - .max_transfer_sz = dts_config->max_transfer_sz, - }; - - esp_err_t ret = spi_bus_initialize(dts_config->host, &buscfg, SPI_DMA_CH_AUTO); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to initialize SPI bus: %s", esp_err_to_name(ret)); - return ERROR_RESOURCE; - } - - driver_data->initialized = true; - return ERROR_NONE; -} - static error_t lock(Device* device) { auto* driver_data = GET_DATA(device); mutex_lock(&driver_data->mutex); @@ -83,7 +56,35 @@ static error_t start(Device* device) { data->initialized = false; device_set_driver_data(device, data); - return reset(device); + auto* driver_data = GET_DATA(device); + auto* dts_config = GET_CONFIG(device); + + if (driver_data->initialized) { + spi_bus_free(dts_config->host); + driver_data->initialized = false; + } + + spi_bus_config_t buscfg = { + .mosi_io_num = dts_config->pin_mosi, + .miso_io_num = dts_config->pin_miso, + .sclk_io_num = dts_config->pin_sclk, + .data2_io_num = dts_config->pin_wp, + .data3_io_num = dts_config->pin_hd, + .data4_io_num = GPIO_NUM_NC, + .data5_io_num = GPIO_NUM_NC, + .data6_io_num = GPIO_NUM_NC, + .data7_io_num = GPIO_NUM_NC, + .max_transfer_sz = dts_config->max_transfer_sz, + }; + + esp_err_t ret = spi_bus_initialize(dts_config->host, &buscfg, SPI_DMA_CH_AUTO); + if (ret != ESP_OK) { + ESP_LOGE(TAG, "Failed to initialize SPI bus: %s", esp_err_to_name(ret)); + return ERROR_RESOURCE; + } + + driver_data->initialized = true; + return ERROR_NONE; } static error_t stop(Device* device) { @@ -101,7 +102,6 @@ static error_t stop(Device* device) { } const static struct SpiControllerApi esp32_spi_api = { - .reset = reset, .lock = lock, .try_lock = try_lock, .unlock = unlock diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp index 458d86948..bfc9a0333 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp @@ -14,23 +14,23 @@ #define TAG "esp32_uart" -struct InternalData { +struct Esp32UartInternal { Mutex mutex {}; UartConfig config {}; bool config_set = false; bool is_open = false; - InternalData() { + Esp32UartInternal() { mutex_construct(&mutex); } - ~InternalData() { + ~Esp32UartInternal() { mutex_destruct(&mutex); } }; #define GET_CONFIG(device) ((Esp32UartConfig*)device->config) -#define GET_DATA(device) ((InternalData*)device_get_driver_data(device)) +#define GET_DATA(device) ((Esp32UartInternal*)device_get_driver_data(device)) #define lock(data) mutex_lock(&data->mutex) #define unlock(data) mutex_unlock(&data->mutex) @@ -165,7 +165,7 @@ static error_t read_bytes(Device* device, uint8_t* buffer, size_t buffer_size, T return ERROR_NONE; } -static int available(Device* device) { +static error_t get_available(Device* device, size_t* available_bytes) { auto* driver_data = GET_DATA(device); auto* dts_config = GET_CONFIG(device); @@ -175,12 +175,11 @@ static int available(Device* device) { return -1; } - size_t size; - esp_err_t err = uart_get_buffered_data_len(dts_config->port, &size); + esp_err_t err = uart_get_buffered_data_len(dts_config->port, available_bytes); unlock(driver_data); - if (err != ESP_OK) return -1; - return (int)size; + if (err != ESP_OK) return esp_err_to_error(err); + return ERROR_NONE; } static error_t set_config(Device* device, const struct UartConfig* config) { @@ -249,11 +248,13 @@ static error_t open(Device* device) { lock(driver_data); if (driver_data->is_open) { unlock(driver_data); - return ERROR_NONE; + LOG_W(TAG, "Already open"); + return ERROR_INVALID_STATE; } if (!driver_data->config_set) { unlock(driver_data); + LOG_E(TAG, "open failed: config not set"); return ERROR_INVALID_STATE; } @@ -278,6 +279,7 @@ static error_t close(Device* device) { lock(driver_data); if (!driver_data->is_open) { unlock(driver_data); + LOG_W(TAG, "Already closed"); return ERROR_INVALID_STATE; } uart_driver_delete(dts_config->port); @@ -313,7 +315,7 @@ static error_t flush_input(Device* device) { static error_t start(Device* device) { ESP_LOGI(TAG, "start %s", device->name); - auto* data = new(std::nothrow) InternalData(); + auto* data = new(std::nothrow) Esp32UartInternal(); if (!data) return ERROR_OUT_OF_MEMORY; device_set_driver_data(device, data); @@ -343,7 +345,7 @@ const static UartControllerApi esp32_uart_api = { .write_byte = write_byte, .write_bytes = write_bytes, .read_bytes = read_bytes, - .available = available, + .get_available = get_available, .set_config = set_config, .get_config = get_config, .open = open, diff --git a/Tactility/Include/Tactility/hal/Configuration.h b/Tactility/Include/Tactility/hal/Configuration.h index bbaad9c58..3dc8f86fa 100644 --- a/Tactility/Include/Tactility/hal/Configuration.h +++ b/Tactility/Include/Tactility/hal/Configuration.h @@ -2,8 +2,6 @@ #include #include -#include -#include "i2c/I2c.h" namespace tt::hal { @@ -43,9 +41,6 @@ struct Configuration { /** A list of SPI interface configurations */ const std::vector spi = {}; - - /** A list of UART interface configurations */ - const std::vector uart = {}; }; } // namespace diff --git a/Tactility/Include/Tactility/hal/uart/Configuration.h b/Tactility/Include/Tactility/hal/uart/Configuration.h deleted file mode 100644 index 733afb108..000000000 --- a/Tactility/Include/Tactility/hal/uart/Configuration.h +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include "UartCompat.h" - -namespace tt::hal::uart { - -#ifdef ESP_PLATFORM - -struct Configuration { - /** The unique name for this UART */ - std::string name; - /** The port identifier (e.g. UART_NUM_0) */ - uart_port_t port; - /** Receive GPIO pin */ - gpio_num_t rxPin; - /** Transmit GPIO pin */ - gpio_num_t txPin; - /** Read-To-Send GPIO pin */ - gpio_num_t rtsPin; - /** Clear-To-Send Send GPIO pin */ - gpio_num_t ctsPin; - /** Receive buffer size in bytes */ - unsigned int rxBufferSize; - /** Transmit buffer size in bytes */ - unsigned int txBufferSize; - /** Native configuration */ - uart_config_t config; -}; - -#else - -struct Configuration { - /** The unique name for this UART */ - std::string name; - /** The port identifier (e.g. UART_NUM_0) */ - uart_port_t port; - /** Initial baud rate in bits per second */ - uint32_t baudRate; -}; - -#endif - -} \ No newline at end of file diff --git a/Tactility/Include/Tactility/hal/uart/Uart.h b/Tactility/Include/Tactility/hal/uart/Uart.h deleted file mode 100644 index 8ff8c5e18..000000000 --- a/Tactility/Include/Tactility/hal/uart/Uart.h +++ /dev/null @@ -1,131 +0,0 @@ -#pragma once - -#include - -#include "../gpio/Gpio.h" -#include "Tactility/Lock.h" -#include "UartCompat.h" -#include "Tactility/hal/uart/Configuration.h" - -#include -#include - -namespace tt::hal::uart { - -constexpr TickType_t defaultTimeout = 10 / portTICK_PERIOD_MS; - -enum class InitMode { - ByTactility, // Tactility will initialize it in the correct bootup phase - ByExternal, // The device is already initialized and Tactility should assume it works - Disabled // Not initialized by default -}; - -enum class Status { - Started, - Stopped, - Unknown -}; - -class Uart { - - uint32_t id; - -public: - - Uart(); - virtual ~Uart(); - - uint32_t getId() const { return id; } - - virtual bool start() = 0; - virtual bool isStarted() const = 0; - - virtual bool stop() = 0; - - /** - * Read up to a specified amount of bytes - * @param[out] buffer - * @param[in] bufferSize - * @param[in] timeout - * @return the amount of bytes that were read - */ - virtual size_t readBytes(std::byte* buffer, size_t bufferSize, TickType_t timeout = defaultTimeout) = 0; - - size_t readBytes(std::uint8_t* buffer, size_t bufferSize, TickType_t timeout = defaultTimeout) { - return readBytes(reinterpret_cast(buffer), bufferSize, timeout); - } - - /** Read a single byte */ - virtual bool readByte(std::byte* output, TickType_t timeout = defaultTimeout) = 0; - - bool readByte(char* output, TickType_t timeout = defaultTimeout) { - return readByte(reinterpret_cast(output), timeout); - } - - bool readByte(uint8_t* output, TickType_t timeout = defaultTimeout) { - return readByte(reinterpret_cast(output), timeout); - } - - /** - * Read up to a specified amount of bytes - * @param[in] buffer - * @param[in] bufferSize - * @param[in] timeout - * @return the amount of bytes that were read - */ - virtual size_t writeBytes(const std::byte* buffer, size_t bufferSize, TickType_t timeout = defaultTimeout) = 0; - - size_t writeBytes(const std::uint8_t* buffer, size_t bufferSize, TickType_t timeout = defaultTimeout) { - return writeBytes(reinterpret_cast(buffer), bufferSize, timeout); - } - - /** @return the amount of bytes available for reading */ - virtual size_t available(TickType_t timeout = defaultTimeout) = 0; - - /** Set the baud rate for the specified port */ - virtual bool setBaudRate(uint32_t baudRate, TickType_t timeout = defaultTimeout) = 0; - - /** Get the baud rate for the specified port */ - virtual uint32_t getBaudRate() = 0; - - /** Flush input buffers */ - virtual void flushInput() = 0; - - /** - * Write a string (excluding null terminator character) - * @param[in] buffer - * @param[in] timeout - * @return the amount of bytes that were written - */ - bool writeString(const char* buffer, TickType_t timeout = defaultTimeout); - - /** - * Read a buffer as a string until the specified character (the "untilChar" is included in the result) - * @warning if the input data doesn't return "untilByte" then the device goes out of memory - */ - std::string readStringUntil(char untilChar, TickType_t timeout = defaultTimeout); - - /** - * Read a buffer as a byte array until the specified character (the "untilChar" is included in the result) - * @return the amount of bytes read from UART - */ - size_t readUntil(std::byte* buffer, size_t bufferSize, uint8_t untilByte, TickType_t timeout = defaultTimeout, bool addNullTerminator = true); -}; - -/** - * Opens a UART. - * @param[in] name the UART name as specified in the board configuration. - * @return the UART when it was successfully opened, or nullptr when it is in use. - */ -std::unique_ptr open(std::string name); - -/** - * Opens a UART. - * @param[in] port the UART port as specified in the board configuration. - * @return the UART when it was successfully opened, or nullptr when it is in use. - */ -std::unique_ptr open(uart_port_t port); - -std::vector getNames(); - -} // namespace tt::hal::uart diff --git a/Tactility/Include/Tactility/hal/uart/UartCompat.h b/Tactility/Include/Tactility/hal/uart/UartCompat.h deleted file mode 100644 index eb65eb7aa..000000000 --- a/Tactility/Include/Tactility/hal/uart/UartCompat.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#ifdef ESP_PLATFORM - -#include -#include -#include - -#else - -#define UART_NUM_MAX 3 -typedef int uart_port_t; - -typedef struct { -} uart_config_t; - -#endif diff --git a/Tactility/Private/Tactility/hal/gps/GpsInit.h b/Tactility/Private/Tactility/hal/gps/GpsInit.h index 6d0b94fb5..6197a1d7e 100644 --- a/Tactility/Private/Tactility/hal/gps/GpsInit.h +++ b/Tactility/Private/Tactility/hal/gps/GpsInit.h @@ -2,13 +2,13 @@ #include "Tactility/hal/gps/GpsDevice.h" -namespace tt::hal::uart { class Uart; } +struct Device; namespace tt::hal::gps { /** * Init sequence on UART for a specific GPS model. */ -bool init(uart::Uart& uart, GpsModel type); +bool init(::Device* uart, GpsModel type); } diff --git a/Tactility/Private/Tactility/hal/gps/Probe.h b/Tactility/Private/Tactility/hal/gps/Probe.h index b9236e269..6f91b1f82 100644 --- a/Tactility/Private/Tactility/hal/gps/Probe.h +++ b/Tactility/Private/Tactility/hal/gps/Probe.h @@ -1,10 +1,9 @@ #pragma once -#include "Tactility/hal/gps/GpsDevice.h" -#include "Tactility/hal/uart/Uart.h" +struct Device; namespace tt::hal::gps { -GpsModel probe(uart::Uart& iart); +GpsModel probe(::Device* uart); } diff --git a/Tactility/Private/Tactility/hal/gps/Ublox.h b/Tactility/Private/Tactility/hal/gps/Ublox.h index bb6745d34..078778ca7 100644 --- a/Tactility/Private/Tactility/hal/gps/Ublox.h +++ b/Tactility/Private/Tactility/hal/gps/Ublox.h @@ -1,11 +1,12 @@ #pragma once #include "Tactility/hal/gps/GpsDevice.h" -#include "Tactility/hal/uart/Uart.h" #include #include +struct Device; + namespace tt::hal::gps::ublox { void checksum(uint8_t* message, size_t length); @@ -14,14 +15,14 @@ void checksum(uint8_t* message, size_t length); uint8_t makePacket(uint8_t classId, uint8_t messageId, const uint8_t* payload, uint8_t payloadSize, uint8_t* bufferOut); template -inline void sendPacket(uart_port_t port, uint8_t type, uint8_t id, uint8_t data[DataSize], const char* errorMessage, TickType_t timeout) { +inline void sendPacket(::Device* uart, uint8_t type, uint8_t id, uint8_t data[DataSize], const char* errorMessage, uint32_t timeout) { static uint8_t buffer[250] = {0}; size_t length = makePacket(type, id, data, DataSize, buffer); // hal::uart::writeBytes(port, buffer, length); } -GpsModel probe(uart::Uart& uart); +GpsModel probe(::Device* uart); -bool init(uart::Uart& uart, GpsModel model); +bool init(::Device* uart, GpsModel model); } // namespace tt::service::gps diff --git a/Tactility/Private/Tactility/hal/uart/UartEsp.h b/Tactility/Private/Tactility/hal/uart/UartEsp.h deleted file mode 100644 index 650d8f84f..000000000 --- a/Tactility/Private/Tactility/hal/uart/UartEsp.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once -#ifdef ESP_PLATFORM - -#include "Tactility/Mutex.h" -#include "Tactility/hal/uart/Uart.h" -#include "Tactility/hal/uart/Configuration.h" - -namespace tt::hal::uart { - -class UartEsp final : public Uart { - - Mutex mutex; - const Configuration& configuration; - bool started = false; - -public: - - explicit UartEsp(const Configuration& configuration) : configuration(configuration) {} - - bool start() override; - bool isStarted() const override; - bool stop() override; - size_t readBytes(std::byte* buffer, size_t bufferSize, TickType_t timeout) override; - bool readByte(std::byte* output, TickType_t timeout) override; - size_t writeBytes(const std::byte* buffer, size_t bufferSize, TickType_t timeout) override; - size_t available(TickType_t timeout) override; - bool setBaudRate(uint32_t baudRate, TickType_t timeout) override; - uint32_t getBaudRate() override; - void flushInput() override; -}; - -std::unique_ptr create(const Configuration& configuration); - -} // namespace tt::hal::uart - -#endif \ No newline at end of file diff --git a/Tactility/Private/Tactility/hal/uart/UartInit.h b/Tactility/Private/Tactility/hal/uart/UartInit.h deleted file mode 100644 index c4dd58d6c..000000000 --- a/Tactility/Private/Tactility/hal/uart/UartInit.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include "Tactility/hal/uart/Uart.h" - -namespace tt::hal::uart { - -bool init(const std::vector& configurations); - -} diff --git a/Tactility/Private/Tactility/hal/uart/UartPosix.h b/Tactility/Private/Tactility/hal/uart/UartPosix.h deleted file mode 100644 index 471bd2f7b..000000000 --- a/Tactility/Private/Tactility/hal/uart/UartPosix.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once -#ifndef ESP_PLATFORM - -#include "Tactility/Mutex.h" -#include "Tactility/hal/uart/Configuration.h" -#include "Tactility/hal/uart/Uart.h" - -#include - -namespace tt::hal::uart { - -class UartPosix final : public Uart { - -private: - struct AutoCloseFileDeleter { - void operator()(FILE* file) { - fclose(file); - } - }; - - Mutex mutex; - const Configuration& configuration; - std::unique_ptr device; - - bool awaitAvailable(TickType_t timeout); - -public: - - explicit UartPosix(const Configuration& configuration) : configuration(configuration) {} - - bool start() final; - bool isStarted() const final; - bool stop() final; - size_t readBytes(std::byte* buffer, size_t bufferSize, TickType_t timeout) final; - bool readByte(std::byte* output, TickType_t timeout) final; - size_t writeBytes(const std::byte* buffer, size_t bufferSize, TickType_t timeout) final; - size_t available(TickType_t timeout) final; - bool setBaudRate(uint32_t baudRate, TickType_t timeout) final; - uint32_t getBaudRate() final; - void flushInput() final; -}; - -std::unique_ptr create(const Configuration& configuration); - -} // namespace tt::hal::uart - -#endif \ No newline at end of file diff --git a/Tactility/Source/Tactility.cpp b/Tactility/Source/Tactility.cpp index e748d68bf..5d83a1a81 100644 --- a/Tactility/Source/Tactility.cpp +++ b/Tactility/Source/Tactility.cpp @@ -26,8 +26,9 @@ #include #include -#include +#include #include +#include #include #ifdef ESP_PLATFORM @@ -180,7 +181,7 @@ static void registerInternalApps() { addAppManifest(app::chat::manifest); #endif - if (!hal::getConfiguration()->uart.empty()) { + if (device_exists_of_type(&UART_CONTROLLER_TYPE)) { addAppManifest(app::addgps::manifest); addAppManifest(app::gpssettings::manifest); } diff --git a/Tactility/Source/app/addgps/AddGps.cpp b/Tactility/Source/app/addgps/AddGps.cpp index c589580c3..8bf12e165 100644 --- a/Tactility/Source/app/addgps/AddGps.cpp +++ b/Tactility/Source/app/addgps/AddGps.cpp @@ -3,11 +3,11 @@ #include #include #include -#include #include #include #include +#include "tactility/drivers/uart_controller.h" #include #include @@ -21,6 +21,8 @@ class AddGpsApp final : public App { lv_obj_t* modelDropdown = nullptr; lv_obj_t* baudDropdown = nullptr; + std::vector<::Device*> devices; + // Store as string instead of int, so app startup doesn't require parsing all entries. // We only need to parse back to int when adding the new GPS entry std::array baudRates = { 9600, 19200, 28800, 38400, 57600, 115200 }; @@ -69,6 +71,24 @@ class AddGpsApp final : public App { } } + void updateUartDevices() { + devices.clear(); + device_for_each_of_type(&UART_CONTROLLER_TYPE, &devices, [](auto* device, auto* context){ + auto* vector_ptr = static_cast*>(context); + vector_ptr->push_back(device); + return true; + }); + } + + std::string getUartDropdownNames() { + std::vector names; + names.push_back(""); + for (auto* device: devices) { + names.push_back(device->name); + } + return string::join(names, "\n"); + } + public: void onShow(AppContext& app, lv_obj_t* parent) final { @@ -95,9 +115,9 @@ class AddGpsApp final : public App { uartDropdown = lv_dropdown_create(uart_wrapper); - auto uart_names = hal::uart::getNames(); - uart_names.insert(uart_names.begin(), ""); - auto uart_options = string::join(uart_names, "\n"); + updateUartDevices(); + + auto uart_options = getUartDropdownNames(); lv_dropdown_set_options(uartDropdown, uart_options.c_str()); lv_obj_align(uartDropdown, LV_ALIGN_TOP_RIGHT, 0, 0); lv_obj_set_width(uartDropdown, LV_PCT(50)); diff --git a/Tactility/Source/app/gpssettings/GpsSettings.cpp b/Tactility/Source/app/gpssettings/GpsSettings.cpp index 710c75ef7..c0ef599d3 100644 --- a/Tactility/Source/app/gpssettings/GpsSettings.cpp +++ b/Tactility/Source/app/gpssettings/GpsSettings.cpp @@ -292,14 +292,18 @@ class GpsSettingsApp final : public App { lv_obj_add_flag(statusLabelWidget, LV_OBJ_FLAG_HIDDEN); } - lv_obj_clean(gpsConfigWrapper); - std::vector configurations; - auto gps_service = tt::service::gps::findGpsService(); - if (gps_service && gps_service->getGpsConfigurations(configurations)) { - int index = 0; - for (auto& configuration : configurations) { - createGpsView(configuration, index++); + if (!lv_obj_has_flag(gpsConfigWrapper, LV_OBJ_FLAG_HIDDEN)) { + lv_obj_clean(gpsConfigWrapper); + std::vector configurations; + auto gps_service = tt::service::gps::findGpsService(); + if (gps_service && gps_service->getGpsConfigurations(configurations)) { + int index = 0; + for (auto& configuration : configurations) { + createGpsView(configuration, index++); + } } + } else { + lv_obj_clean(gpsConfigWrapper); } } } diff --git a/Tactility/Source/app/i2cscanner/I2cHelpers.cpp b/Tactility/Source/app/i2cscanner/I2cHelpers.cpp index 985f0240b..97ba2d01a 100644 --- a/Tactility/Source/app/i2cscanner/I2cHelpers.cpp +++ b/Tactility/Source/app/i2cscanner/I2cHelpers.cpp @@ -1,7 +1,7 @@ #include "Tactility/app/i2cscanner/I2cHelpers.h" -#include #include +#include #include #include diff --git a/Tactility/Source/hal/Hal.cpp b/Tactility/Source/hal/Hal.cpp index 9b1ed1cf9..b392e1a47 100644 --- a/Tactility/Source/hal/Hal.cpp +++ b/Tactility/Source/hal/Hal.cpp @@ -3,9 +3,7 @@ #include #include #include -#include #include -#include #include #include @@ -67,7 +65,6 @@ void init(const Configuration& configuration) { kernel::publishSystemEvent(kernel::SystemEvent::BootInitHalBegin); check(spi::init(configuration.spi), "SPI init failed"); - check(uart::init(configuration.uart), "UART init failed"); if (configuration.initBoot != nullptr) { check(configuration.initBoot(), "Init boot failed"); diff --git a/Tactility/Source/hal/gps/GpsDevice.cpp b/Tactility/Source/hal/gps/GpsDevice.cpp index a78eea00a..3c2b6d343 100644 --- a/Tactility/Source/hal/gps/GpsDevice.cpp +++ b/Tactility/Source/hal/gps/GpsDevice.cpp @@ -1,9 +1,11 @@ #include #include #include -#include #include +#include +#include + #include #include @@ -16,25 +18,34 @@ static const auto LOGGER = Logger("GpsDevice"); int32_t GpsDevice::threadMain() { uint8_t buffer[GPS_UART_BUFFER_SIZE]; - auto uart = uart::open(configuration.uartName); + auto* uart = device_find_by_name(configuration.uartName); if (uart == nullptr) { - LOGGER.error("Failed to open UART {}", configuration.uartName); + LOGGER.error("Failed to find UART {}", configuration.uartName); return -1; } - if (!uart->start()) { - LOGGER.error("Failed to start UART {}", configuration.uartName); + struct UartConfig uartConfig = { + .baud_rate = configuration.baudRate, + .data_bits = UART_CONTROLLER_DATA_8_BITS, + .parity = UART_CONTROLLER_PARITY_DISABLE, + .stop_bits = UART_CONTROLLER_STOP_BITS_1 + }; + + error_t error = uart_controller_set_config(uart, &uartConfig); + if (error != ERROR_NONE) { + LOGGER.error("Failed to configure UART {}: {}", configuration.baudRate, configuration.uartName, error_to_string(error)); return -1; } - if (!uart->setBaudRate(static_cast(configuration.baudRate))) { - LOGGER.error("Failed to set baud rate to {} for UART {}", configuration.baudRate, configuration.uartName); + error = uart_controller_open(uart); + if (error != ERROR_NONE) { + LOGGER.error("Failed to open UART {}: {}", configuration.uartName, error_to_string(error)); return -1; } GpsModel model = configuration.model; if (model == GpsModel::Unknown) { - model = probe(*uart); + model = probe(uart); if (model == GpsModel::Unknown) { LOGGER.error("Probe failed"); setState(State::Error); @@ -45,7 +56,7 @@ int32_t GpsDevice::threadMain() { this->model = model; mutex.unlock(); - if (!init(*uart, model)) { + if (!init(uart, model)) { LOGGER.error("Init failed"); setState(State::Error); return -1; @@ -55,7 +66,8 @@ int32_t GpsDevice::threadMain() { // Reference: https://gpsd.gitlab.io/gpsd/NMEA.html while (!isThreadInterrupted()) { - size_t bytes_read = uart->readUntil(reinterpret_cast(buffer), GPS_UART_BUFFER_SIZE, '\n', 100 / portTICK_PERIOD_MS); + size_t bytes_read = 0; + uart_controller_read_until(uart, buffer, GPS_UART_BUFFER_SIZE, '\n', true, &bytes_read, 100 / portTICK_PERIOD_MS); // Thread might've been interrupted in the meanwhile if (isThreadInterrupted()) { @@ -103,7 +115,7 @@ int32_t GpsDevice::threadMain() { } } - if (uart->isStarted() && !uart->stop()) { + if (uart_controller_close(uart) != ERROR_NONE) { LOGGER.warn("Failed to stop UART {}", configuration.uartName); } diff --git a/Tactility/Source/hal/gps/GpsInit.cpp b/Tactility/Source/hal/gps/GpsInit.cpp index 3aefdacad..02f80efe1 100644 --- a/Tactility/Source/hal/gps/GpsInit.cpp +++ b/Tactility/Source/hal/gps/GpsInit.cpp @@ -5,18 +5,21 @@ #include #include +#include +#include + #include namespace tt::hal::gps { static const auto LOGGER = Logger("Gps"); -bool initMtk(uart::Uart& uart); -bool initMtkL76b(uart::Uart& uart); -bool initMtkPa1616s(uart::Uart& uart); -bool initAtgm336h(uart::Uart& uart); -bool initUc6580(uart::Uart& uart); -bool initAg33xx(uart::Uart& uart); +bool initMtk(::Device* uart); +bool initMtkL76b(::Device* uart); +bool initMtkPa1616s(::Device* uart); +bool initAtgm336h(::Device* uart); +bool initUc6580(::Device* uart); +bool initAg33xx(::Device* uart); // region CAS @@ -73,7 +76,7 @@ static uint8_t makeCASPacket(uint8_t* buffer, uint8_t class_id, uint8_t msg_id, return (payload_size + 10); } -GpsResponse getACKCas(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32_t waitMillis) +GpsResponse getACKCas(::Device* uart, uint8_t class_id, uint8_t msg_id, uint32_t waitMillis) { uint32_t startTime = kernel::getMillis(); uint8_t buffer[CAS_ACK_NACK_MSG_SIZE] = {0}; @@ -87,8 +90,10 @@ GpsResponse getACKCas(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32 // ACK-ACK | 0xBA | 0xCE | 0x04 | 0x00 | 0x05 | 0x01 | 0xXX | 0xXX | 0x00 | 0x00 | 0xXX | 0xXX | 0xXX | 0xXX | while (kernel::getTicks() - startTime < waitMillis) { - if (uart.available()) { - uart.readByte(&buffer[bufferPos++]); + size_t available = 0; + uart_controller_get_available(uart, &available); + if (available > 0) { + uart_controller_read_byte(uart, &buffer[bufferPos++], 1); // keep looking at the first two bytes of buffer until // we have found the CAS frame header (0xBA, 0xCE), if not @@ -136,7 +141,7 @@ GpsResponse getACKCas(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32 // endregion -bool init(uart::Uart& uart, GpsModel type) { +bool init(::Device* uart, GpsModel type) { switch (type) { case GpsModel::Unknown: check(false); @@ -167,58 +172,58 @@ bool init(uart::Uart& uart, GpsModel type) { return false; } -bool initAg33xx(uart::Uart& uart) { - uart.writeString("$PAIR066,1,0,1,0,0,1*3B\r\n"); // Enable GPS+GALILEO+NAVIC +bool initAg33xx(::Device* uart) { + uart_controller_write_bytes(uart, (const uint8_t*)"$PAIR066,1,0,1,0,0,1*3B\r\n", 25, 250); // Enable GPS+GALILEO+NAVIC // Configure NMEA (sentences will output once per fix) - uart.writeString("$PAIR062,0,1*3F\r\n"); // GGA ON - uart.writeString("$PAIR062,1,0*3F\r\n"); // GLL OFF - uart.writeString("$PAIR062,2,0*3C\r\n"); // GSA OFF - uart.writeString("$PAIR062,3,0*3D\r\n"); // GSV OFF - uart.writeString("$PAIR062,4,1*3B\r\n"); // RMC ON - uart.writeString("$PAIR062,5,0*3B\r\n"); // VTG OFF - uart.writeString("$PAIR062,6,0*38\r\n"); // ZDA ON + uart_controller_write_bytes(uart, (const uint8_t*)"$PAIR062,0,1*3F\r\n", 17, 250); // GGA ON + uart_controller_write_bytes(uart, (const uint8_t*)"$PAIR062,1,0*3F\r\n", 17, 250); // GLL OFF + uart_controller_write_bytes(uart, (const uint8_t*)"$PAIR062,2,0*3C\r\n", 17, 250); // GSA OFF + uart_controller_write_bytes(uart, (const uint8_t*)"$PAIR062,3,0*3D\r\n", 17, 250); // GSV OFF + uart_controller_write_bytes(uart, (const uint8_t*)"$PAIR062,4,1*3B\r\n", 17, 250); // RMC ON + uart_controller_write_bytes(uart, (const uint8_t*)"$PAIR062,5,0*3B\r\n", 17, 250); // VTG OFF + uart_controller_write_bytes(uart, (const uint8_t*)"$PAIR062,6,0*38\r\n", 17, 250); // ZDA ON kernel::delayMillis(250); - uart.writeString("$PAIR513*3D\r\n"); // save configuration + uart_controller_write_bytes(uart, (const uint8_t*)"$PAIR513*3D\r\n", 13, 250); // save configuration return true; } -bool initUc6580(uart::Uart& uart) { +bool initUc6580(::Device* uart) { // The Unicore UC6580 can use a lot of sat systems, enable it to // use GPS L1 & L5 + BDS B1I & B2a + GLONASS L1 + GALILEO E1 & E5a + SBAS + QZSS // This will reset the receiver, so wait a bit afterwards // The paranoid will wait for the OK*04 confirmation response after each command. - uart.writeString("$CFGSYS,h35155\r\n"); + uart_controller_write_bytes(uart, (const uint8_t*)"$CFGSYS,h35155\r\n", 16, 250); kernel::delayMillis(750); // Must be done after the CFGSYS command // Turn off GSV messages, we don't really care about which and where the sats are, maybe someday. - uart.writeString("$CFGMSG,0,3,0\r\n"); + uart_controller_write_bytes(uart, (const uint8_t*)"$CFGMSG,0,3,0\r\n", 15, 250); kernel::delayMillis(250); // Turn off GSA messages, TinyGPS++ doesn't use this message. - uart.writeString("$CFGMSG,0,2,0\r\n"); + uart_controller_write_bytes(uart, (const uint8_t*)"$CFGMSG,0,2,0\r\n", 15, 250); kernel::delayMillis(250); // Turn off NOTICE __TXT messages, these may provide Unicore some info but we don't care. - uart.writeString("$CFGMSG,6,0,0\r\n"); + uart_controller_write_bytes(uart, (const uint8_t*)"$CFGMSG,6,0,0\r\n", 15, 250); kernel::delayMillis(250); - uart.writeString("$CFGMSG,6,1,0\r\n"); + uart_controller_write_bytes(uart, (const uint8_t*)"$CFGMSG,6,1,0\r\n", 15, 250); kernel::delayMillis(250); return true; } -bool initAtgm336h(uart::Uart& uart) { +bool initAtgm336h(::Device* uart) { uint8_t buffer[256]; // Set the intial configuration of the device - these _should_ work for most AT6558 devices int msglen = makeCASPacket(buffer, 0x06, 0x07, sizeof(_message_CAS_CFG_NAVX_CONF), _message_CAS_CFG_NAVX_CONF); - uart.writeBytes(buffer, msglen); + uart_controller_write_bytes(uart, buffer, msglen, 250); if (getACKCas(uart, 0x06, 0x07, 250) != GpsResponse::Ok) { LOGGER.warn("ATGM336H: Could not set Config"); } // Set the update frequence to 1Hz msglen = makeCASPacket(buffer, 0x06, 0x04, sizeof(_message_CAS_CFG_RATE_1HZ), _message_CAS_CFG_RATE_1HZ); - uart.writeBytes(buffer, msglen); + uart_controller_write_bytes(uart, buffer, msglen, 250); if (getACKCas(uart, 0x06, 0x04, 250) != GpsResponse::Ok) { LOGGER.warn("ATGM336H: Could not set Update Frequency"); } @@ -230,7 +235,7 @@ bool initAtgm336h(uart::Uart& uart) { // Construct a CAS-CFG-MSG packet uint8_t cas_cfg_msg_packet[] = {0x4e, fields[i], 0x01, 0x00}; msglen = makeCASPacket(buffer, 0x06, 0x01, sizeof(cas_cfg_msg_packet), cas_cfg_msg_packet); - uart.writeBytes(buffer, msglen); + uart_controller_write_bytes(uart, buffer, msglen, 250); if (getACKCas(uart, 0x06, 0x01, 250) != GpsResponse::Ok) { LOGGER.warn("ATGM336H: Could not enable NMEA MSG: {}", fields[i]); } @@ -238,53 +243,53 @@ bool initAtgm336h(uart::Uart& uart) { return true; } -bool initMtkPa1616s(uart::Uart& uart) { +bool initMtkPa1616s(::Device* uart) { // PA1616S is used in some GPS breakout boards from Adafruit // PA1616S does not have GLONASS capability. PA1616D does, but is not implemented here. - uart.writeString("$PMTK353,1,0,0,0,0*2A\r\n"); + uart_controller_write_bytes(uart, (const uint8_t*)"$PMTK353,1,0,0,0,0*2A\r\n", 23, 250); // Above command will reset the GPS and takes longer before it will accept new commands kernel::delayMillis(1000); // Only ask for RMC and GGA (GNRMC and GNGGA) - uart.writeString("$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28\r\n"); + uart_controller_write_bytes(uart, (const uint8_t*)"$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28\r\n", 51, 250); kernel::delayMillis(250); // Enable SBAS / WAAS - uart.writeString("$PMTK301,2*2E\r\n"); + uart_controller_write_bytes(uart, (const uint8_t*)"$PMTK301,2*2E\r\n", 15, 250); kernel::delayMillis(250); return true; } -bool initMtkL76b(uart::Uart& uart) { +bool initMtkL76b(::Device* uart) { // Waveshare Pico-GPS hat uses the L76B with 9600 baud // Initialize the L76B Chip, use GPS + GLONASS // See note in L76_Series_GNSS_Protocol_Specification, chapter 3.29 - uart.writeString("$PMTK353,1,1,0,0,0*2B\r\n"); + uart_controller_write_bytes(uart, (const uint8_t*)"$PMTK353,1,1,0,0,0*2B\r\n", 23, 250); // Above command will reset the GPS and takes longer before it will accept new commands kernel::delayMillis(1000); // only ask for RMC and GGA (GNRMC and GNGGA) // See note in L76_Series_GNSS_Protocol_Specification, chapter 2.1 - uart.writeString("$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28\r\n"); + uart_controller_write_bytes(uart, (const uint8_t*)"$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28\r\n", 51, 250); kernel::delayMillis(250); // Enable SBAS - uart.writeString("$PMTK301,2*2E\r\n"); + uart_controller_write_bytes(uart, (const uint8_t*)"$PMTK301,2*2E\r\n", 15, 250); kernel::delayMillis(250); // Enable PPS for 2D/3D fix only - uart.writeString("$PMTK285,3,100*3F\r\n"); + uart_controller_write_bytes(uart, (const uint8_t*)"$PMTK285,3,100*3F\r\n", 19, 250); kernel::delayMillis(250); // Switch to Fitness Mode, for running and walking purpose with low speed (<5 m/s) - uart.writeString("$PMTK886,1*29\r\n"); + uart_controller_write_bytes(uart, (const uint8_t*)"$PMTK886,1*29\r\n", 15, 250); kernel::delayMillis(250); return true; } -bool initMtk(uart::Uart& uart) { +bool initMtk(::Device* uart) { // Initialize the L76K Chip, use GPS + GLONASS + BEIDOU - uart.writeString("$PCAS04,7*1E\r\n"); + uart_controller_write_bytes(uart, (const uint8_t*)"$PCAS04,7*1E\r\n", 14, 250); kernel::delayMillis(250); // only ask for RMC and GGA - uart.writeString("$PCAS03,1,0,0,0,1,0,0,0,0,0,,,0,0*02\r\n"); + uart_controller_write_bytes(uart, (const uint8_t*)"$PCAS03,1,0,0,0,1,0,0,0,0,0,,,0,0*02\r\n", 38, 250); kernel::delayMillis(250); // Switch to Vehicle Mode, since SoftRF enables Aviation < 2g - uart.writeString("$PCAS11,3*1E\r\n"); + uart_controller_write_bytes(uart, (const uint8_t*)"$PCAS11,3*1E\r\n", 14, 250); kernel::delayMillis(250); return true; } diff --git a/Tactility/Source/hal/gps/Probe.cpp b/Tactility/Source/hal/gps/Probe.cpp index 18431f82b..0dc2402fe 100644 --- a/Tactility/Source/hal/gps/Probe.cpp +++ b/Tactility/Source/hal/gps/Probe.cpp @@ -1,9 +1,11 @@ #include "Tactility/hal/gps/GpsDevice.h" #include "Tactility/hal/gps/Ublox.h" #include -#include #include +#include +#include + #include static const auto LOGGER = tt::Logger("Gps"); @@ -41,7 +43,7 @@ char* strnstr(const char* s, const char* find, size_t slen) { /** * From: https://github.com/meshtastic/firmware/blob/f81d3b045dd1b7e3ca7870af3da915ff4399ea98/src/gps/GPS.cpp */ -GpsResponse getAck(uart::Uart& uart, const char* message, uint32_t waitMillis) { +GpsResponse getAck(::Device* uart, const char* message, uint32_t waitMillis) { uint8_t buffer[768] = {0}; uint8_t b; int bytesRead = 0; @@ -50,8 +52,10 @@ GpsResponse getAck(uart::Uart& uart, const char* message, uint32_t waitMillis) { std::string debugmsg = ""; #endif while (kernel::getMillis() < startTimeout) { - if (uart.available()) { - uart.readByte(&b); + size_t available = 0; + uart_controller_get_available(uart, &available); + if (available > 0) { + uart_controller_read_byte(uart, &b, 1); #ifdef GPS_DEBUG debugmsg += vformat("%c", (b >= 32 && b <= 126) ? b : '.'); @@ -82,8 +86,8 @@ GpsResponse getAck(uart::Uart& uart, const char* message, uint32_t waitMillis) { #define PROBE_SIMPLE(UART, CHIP, TOWRITE, RESPONSE, DRIVER, TIMEOUT, ...) \ do { \ LOGGER.info("Probing for {} ({})", CHIP, TOWRITE); \ - UART.flushInput(); \ - UART.writeString(TOWRITE "\r\n", TIMEOUT); \ + uart_controller_flush_input(UART); \ + uart_controller_write_bytes(UART, (const uint8_t*)(TOWRITE "\r\n"), strlen(TOWRITE "\r\n"), TIMEOUT); \ if (getAck(UART, RESPONSE, TIMEOUT) == GpsResponse::Ok) { \ LOGGER.info("Probe detected {} {}", CHIP, #DRIVER); \ return DRIVER; \ @@ -93,15 +97,15 @@ GpsResponse getAck(uart::Uart& uart, const char* message, uint32_t waitMillis) { /** * From: https://github.com/meshtastic/firmware/blob/f81d3b045dd1b7e3ca7870af3da915ff4399ea98/src/gps/GPS.cpp */ -GpsModel probe(uart::Uart& uart) { +GpsModel probe(::Device* uart) { // Close all NMEA sentences, valid for L76K, ATGM336H (and likely other AT6558 devices) - uart.writeString("$PCAS03,0,0,0,0,0,0,0,0,0,0,,,0,0*02\r\n"); + uart_controller_write_bytes(uart, (const uint8_t*)"$PCAS03,0,0,0,0,0,0,0,0,0,0,,,0,0*02\r\n", 40, 500); kernel::delayMillis(20); // Close NMEA sequences on Ublox - uart.writeString("$PUBX,40,GLL,0,0,0,0,0,0*5C\r\n"); - uart.writeString("$PUBX,40,GSV,0,0,0,0,0,0*59\r\n"); - uart.writeString("$PUBX,40,VTG,0,0,0,0,0,0*5E\r\n"); + uart_controller_write_bytes(uart, (const uint8_t*)"$PUBX,40,GLL,0,0,0,0,0,0*5C\r\n", 29, 500); + uart_controller_write_bytes(uart, (const uint8_t*)"$PUBX,40,GSV,0,0,0,0,0,0*59\r\n", 29, 500); + uart_controller_write_bytes(uart, (const uint8_t*)"$PUBX,40,VTG,0,0,0,0,0,0*5E\r\n", 29, 500); kernel::delayMillis(20); // Unicore UFirebirdII Series: UC6580, UM620, UM621, UM670A, UM680A, or UM681A @@ -114,9 +118,9 @@ GpsModel probe(uart::Uart& uart) { PROBE_SIMPLE(uart, "ATGM332D", "$PCAS06,1*1A", "$GPTXT,01,01,02,HW=ATGM332D", GpsModel::ATGM336H, 500); /* Airoha (Mediatek) AG3335A/M/S, A3352Q, Quectel L89 2.0, SimCom SIM65M */ - uart.writeString("$PAIR062,2,0*3C\r\n"); // GSA OFF to reduce volume - uart.writeString("$PAIR062,3,0*3D\r\n"); // GSV OFF to reduce volume - uart.writeString("$PAIR513*3D\r\n"); // save configuration + uart_controller_write_bytes(uart, (const uint8_t*)"$PAIR062,2,0*3C\r\n", 17, 500); // GSA OFF to reduce volume + uart_controller_write_bytes(uart, (const uint8_t*)"$PAIR062,3,0*3D\r\n", 17, 500); // GSV OFF to reduce volume + uart_controller_write_bytes(uart, (const uint8_t*)"$PAIR513*3D\r\n", 13, 500); // save configuration PROBE_SIMPLE(uart, "AG3335", "$PAIR021*39", "$PAIR021,AG3335", GpsModel::AG3335, 500); PROBE_SIMPLE(uart, "AG3352", "$PAIR021*39", "$PAIR021,AG3352", GpsModel::AG3352, 500); PROBE_SIMPLE(uart, "LC86", "$PQTMVERNO*58", "$PQTMVERNO,LC86", GpsModel::AG3352, 500); @@ -124,7 +128,7 @@ GpsModel probe(uart::Uart& uart) { PROBE_SIMPLE(uart, "L76K", "$PCAS06,0*1B", "$GPTXT,01,01,02,SW=", GpsModel::MTK, 500); // Close all NMEA sentences, valid for L76B MTK platform (Waveshare Pico GPS) - uart.writeString("$PMTK514,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*2E\r\n"); + uart_controller_write_bytes(uart, (const uint8_t*)"$PMTK514,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*2E\r\n", 51, 500); kernel::delayMillis(20); PROBE_SIMPLE(uart, "L76B", "$PMTK605*31", "Quectel-L76B", GpsModel::MTK_L76B, 500); @@ -134,7 +138,7 @@ GpsModel probe(uart::Uart& uart) { if (ublox_result != GpsModel::Unknown) { return ublox_result; } else { - LOGGER.warn("No GNSS Module (baud rate {})", uart.getBaudRate()); + LOGGER.warn("No GNSS Module"); return GpsModel::Unknown; } } diff --git a/Tactility/Source/hal/gps/Ublox.cpp b/Tactility/Source/hal/gps/Ublox.cpp index 778f71c9f..8f1ad83e1 100644 --- a/Tactility/Source/hal/gps/Ublox.cpp +++ b/Tactility/Source/hal/gps/Ublox.cpp @@ -1,23 +1,25 @@ #include #include -#include #include #include +#include +#include + #include namespace tt::hal::gps::ublox { static const auto LOGGER = Logger("Ublox"); -bool initUblox6(uart::Uart& uart); -bool initUblox789(uart::Uart& uart, GpsModel model); -bool initUblox10(uart::Uart& uart); +bool initUblox6(::Device* uart); +bool initUblox789(::Device* uart, GpsModel model); +bool initUblox10(::Device* uart); #define SEND_UBX_PACKET(UART, BUFFER, TYPE, ID, DATA, ERRMSG, TIMEOUT) \ do { \ auto msglen = makePacket(TYPE, ID, DATA, sizeof(DATA), BUFFER); \ - UART.writeBytes(BUFFER, sizeof(BUFFER)); \ + uart_controller_write_bytes(UART, BUFFER, msglen, TIMEOUT); \ if (getAck(UART, TYPE, ID, TIMEOUT) != GpsResponse::Ok) { \ LOGGER.info("Sending packet failed: {}", #ERRMSG); \ } \ @@ -56,7 +58,7 @@ uint8_t makePacket(uint8_t classId, uint8_t messageId, const uint8_t* payload, u return (payloadSize + 8U); } -GpsResponse getAck(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32_t waitMillis) { +GpsResponse getAck(::Device* uart, uint8_t class_id, uint8_t msg_id, uint32_t waitMillis) { uint8_t b; uint8_t ack = 0; const uint8_t ackP[2] = {class_id, msg_id}; @@ -86,8 +88,10 @@ GpsResponse getAck(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32_t #endif return GpsResponse::Ok; // ACK received } - if (uart.available()) { - uart.readByte(&b); + size_t available = 0; + uart_controller_get_available(uart, &available); + if (available > 0) { + uart_controller_read_byte(uart, &b, 1); if (b == frame_errors[sCounter]) { sCounter++; if (sCounter == 26) { @@ -124,15 +128,18 @@ GpsResponse getAck(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32_t return GpsResponse::None; // No response received within timeout } -static int getAck(uart::Uart& uart, uint8_t* buffer, uint16_t size, uint8_t requestedClass, uint8_t requestedId, TickType_t timeout) { +static int getAck(::Device* uart, uint8_t* buffer, uint16_t size, uint8_t requestedClass, uint8_t requestedId, uint32_t timeout) { uint16_t ubxFrameCounter = 0; uint32_t startTime = kernel::getTicks(); uint16_t needRead = 0; while (kernel::getTicks() - startTime < timeout) { - while (uart.available()) { + size_t available = 0; + uart_controller_get_available(uart, &available); + while (available > 0) { uint8_t c; - uart.readByte(&c); + uart_controller_read_byte(uart, &c, 1); + available--; switch (ubxFrameCounter) { case 0: @@ -174,7 +181,8 @@ static int getAck(uart::Uart& uart, uint8_t* buffer, uint16_t size, uint8_t requ ubxFrameCounter = 0; break; } - auto read_bytes = uart.readBytes(buffer, needRead, 250 / portTICK_PERIOD_MS); + auto read_bytes = 0U; + uart_controller_read_bytes(uart, buffer, needRead, 250 / portTICK_PERIOD_MS); if (read_bytes != needRead) { ubxFrameCounter = 0; } else { @@ -203,21 +211,21 @@ static struct uBloxGnssModelInfo { uint8_t protocol_version; } ublox_info; -GpsModel probe(uart::Uart& uart) { +GpsModel probe(::Device* uart) { LOGGER.info("Probing for U-blox"); constexpr auto DETECTED_MESSAGE = "{} detected, using {} Module"; uint8_t cfg_rate[] = {0xB5, 0x62, 0x06, 0x08, 0x00, 0x00, 0x00, 0x00}; checksum(cfg_rate, sizeof(cfg_rate)); - uart.flushInput(); - uart.writeBytes(cfg_rate, sizeof(cfg_rate)); + uart_controller_flush_input(uart); + uart_controller_write_bytes(uart, cfg_rate, sizeof(cfg_rate), 500); // Check that the returned response class and message ID are correct GpsResponse response = getAck(uart, 0x06, 0x08, 750); if (response == GpsResponse::None) { - LOGGER.warn("No GNSS Module (baudrate {})", uart.getBaudRate()); + LOGGER.warn("No GNSS Module"); return GpsModel::Unknown; } else if (response == GpsResponse::FrameErrors) { - LOGGER.warn("UBlox Frame Errors (baudrate {})", uart.getBaudRate()); + LOGGER.warn("UBlox Frame Errors"); } uint8_t buffer[256]; @@ -230,8 +238,8 @@ GpsModel probe(uart::Uart& uart) { }; // Get Ublox gnss module hardware and software info checksum(_message_MONVER, sizeof(_message_MONVER)); - uart.flushInput(); - uart.writeBytes(_message_MONVER, sizeof(_message_MONVER)); + uart_controller_flush_input(uart); + uart_controller_write_bytes(uart, _message_MONVER, sizeof(_message_MONVER), 500); uint16_t ack_response_len = getAck(uart, buffer, sizeof(buffer), 0x0A, 0x04, 1200); if (ack_response_len) { @@ -303,7 +311,7 @@ GpsModel probe(uart::Uart& uart) { return GpsModel::Unknown; } -bool init(uart::Uart& uart, GpsModel model) { +bool init(::Device* uart, GpsModel model) { LOGGER.info("U-blox init"); switch (model) { case GpsModel::UBLOX6: @@ -320,19 +328,19 @@ bool init(uart::Uart& uart, GpsModel model) { } } -bool initUblox10(uart::Uart& uart) { +bool initUblox10(::Device* uart) { uint8_t buffer[256]; kernel::delayMillis(1000); - uart.flushInput(); + uart_controller_flush_input(uart); SEND_UBX_PACKET(uart, buffer, 0x06, 0x8A, _message_VALSET_DISABLE_NMEA_RAM, "disable NMEA messages in M10 RAM", 300); kernel::delayMillis(750); - uart.flushInput(); + uart_controller_flush_input(uart); SEND_UBX_PACKET(uart, buffer, 0x06, 0x8A, _message_VALSET_DISABLE_NMEA_BBR, "disable NMEA messages in M10 BBR", 300); kernel::delayMillis(750); - uart.flushInput(); + uart_controller_flush_input(uart); SEND_UBX_PACKET(uart, buffer, 0x06, 0x8A, _message_VALSET_DISABLE_TXT_INFO_RAM, "disable Info messages for M10 GPS RAM", 300); kernel::delayMillis(750); - uart.flushInput(); + uart_controller_flush_input(uart); SEND_UBX_PACKET(uart, buffer, 0x06, 0x8A, _message_VALSET_DISABLE_TXT_INFO_BBR, "disable Info messages for M10 GPS BBR", 300); kernel::delayMillis(750); SEND_UBX_PACKET(uart, buffer, 0x06, 0x8A, _message_VALSET_PM_RAM, "enable powersave for M10 GPS RAM", 300); @@ -362,7 +370,7 @@ bool initUblox10(uart::Uart& uart) { // BBR will survive a restart, and power off for a while, but modules with small backup // batteries or super caps will not retain the config for a long power off time. auto packet_size = makePacket(0x06, 0x09, _message_SAVE_10, sizeof(_message_SAVE_10), buffer); - uart.writeBytes(buffer, packet_size); + uart_controller_write_bytes(uart, buffer, packet_size, 2000); if (getAck(uart, 0x06, 0x09, 2000) != GpsResponse::Ok) { LOGGER.warn("Unable to save GNSS module config"); } else { @@ -371,15 +379,15 @@ bool initUblox10(uart::Uart& uart) { return true; } -bool initUblox789(uart::Uart& uart, GpsModel model) { +bool initUblox789(::Device* uart, GpsModel model) { uint8_t buffer[256]; if (model == GpsModel::UBLOX7) { LOGGER.debug("Set GPS+SBAS"); auto msglen = makePacket(0x06, 0x3e, _message_GNSS_7, sizeof(_message_GNSS_7), buffer); - uart.writeBytes(buffer, msglen); + uart_controller_write_bytes(uart, buffer, msglen, 800); } else { // 8,9 auto msglen = makePacket(0x06, 0x3e, _message_GNSS_8, sizeof(_message_GNSS_8), buffer); - uart.writeBytes(buffer, msglen); + uart_controller_write_bytes(uart, buffer, msglen, 800); } if (getAck(uart, 0x06, 0x3e, 800) == GpsResponse::NotAck) { @@ -396,15 +404,15 @@ bool initUblox789(uart::Uart& uart, GpsModel model) { kernel::delayMillis(1000); } - uart.flushInput(); + uart_controller_flush_input(uart); SEND_UBX_PACKET(uart, buffer, 0x06, 0x02, _message_DISABLE_TXT_INFO, "disable text info messages", 500); if (model == GpsModel::UBLOX8) { // 8 - uart.flushInput(); + uart_controller_flush_input(uart); SEND_UBX_PACKET(uart, buffer, 0x06, 0x39, _message_JAM_8, "enable interference resistance", 500); - uart.flushInput(); + uart_controller_flush_input(uart); SEND_UBX_PACKET(uart, buffer, 0x06, 0x23, _message_NAVX5_8, "configure NAVX5_8 settings", 500); } else { // 6,7,9 SEND_UBX_PACKET(uart, buffer, 0x06, 0x39, _message_JAM_6_7, "enable interference resistance", 500); @@ -421,13 +429,13 @@ bool initUblox789(uart::Uart& uart, GpsModel model) { SEND_UBX_PACKET(uart, buffer, 0x06, 0x01, _message_GGA, "enable NMEA GGA", 500); if (ublox_info.protocol_version >= 18) { - uart.flushInput(); + uart_controller_flush_input(uart); SEND_UBX_PACKET(uart, buffer, 0x06, 0x86, _message_PMS, "enable powersave for GPS", 500); SEND_UBX_PACKET(uart, buffer, 0x06, 0x3B, _message_CFG_PM2, "enable powersave details for GPS", 500); // For M8 we want to enable NMEA version 4.10 so we can see the additional satellites. if (model == GpsModel::UBLOX8) { - uart.flushInput(); + uart_controller_flush_input(uart); SEND_UBX_PACKET(uart, buffer, 0x06, 0x17, _message_NMEA, "enable NMEA 4.10", 500); } } else { @@ -436,7 +444,7 @@ bool initUblox789(uart::Uart& uart, GpsModel model) { } auto packet_size = makePacket(0x06, 0x09, _message_SAVE, sizeof(_message_SAVE), buffer); - uart.writeBytes(buffer, packet_size); + uart_controller_write_bytes(uart, buffer, packet_size, 2000); if (getAck(uart, 0x06, 0x09, 2000) != GpsResponse::Ok) { LOGGER.warn("Unable to save GNSS module config"); } else { @@ -445,10 +453,10 @@ bool initUblox789(uart::Uart& uart, GpsModel model) { return true; } -bool initUblox6(uart::Uart& uart) { +bool initUblox6(::Device* uart) { uint8_t buffer[256]; - uart.flushInput(); + uart_controller_flush_input(uart); SEND_UBX_PACKET(uart, buffer, 0x06, 0x02, _message_DISABLE_TXT_INFO, "disable text info messages", 500); SEND_UBX_PACKET(uart, buffer, 0x06, 0x39, _message_JAM_6_7, "enable interference resistance", 500); @@ -463,14 +471,14 @@ bool initUblox6(uart::Uart& uart) { SEND_UBX_PACKET(uart, buffer, 0x06, 0x01, _message_RMC, "enable NMEA RMC", 500); SEND_UBX_PACKET(uart, buffer, 0x06, 0x01, _message_GGA, "enable NMEA GGA", 500); - uart.flushInput(); + uart_controller_flush_input(uart); SEND_UBX_PACKET(uart, buffer, 0x06, 0x11, _message_CFG_RXM_ECO, "enable powersave ECO mode for Neo-6", 500); SEND_UBX_PACKET(uart, buffer, 0x06, 0x3B, _message_CFG_PM2, "enable powersave details for GPS", 500); SEND_UBX_PACKET(uart, buffer, 0x06, 0x01, _message_AID, "disable UBX-AID", 500); auto packet_size = makePacket(0x06, 0x09, _message_SAVE, sizeof(_message_SAVE), buffer); - uart.writeBytes(buffer, packet_size); + uart_controller_write_bytes(uart, buffer, packet_size, 2000); if (getAck(uart, 0x06, 0x09, 2000) != GpsResponse::Ok) { LOGGER.warn("Unable to save GNSS module config"); } else { diff --git a/Tactility/Source/hal/uart/Uart.cpp b/Tactility/Source/hal/uart/Uart.cpp deleted file mode 100644 index 444fe2744..000000000 --- a/Tactility/Source/hal/uart/Uart.cpp +++ /dev/null @@ -1,192 +0,0 @@ -#include "Tactility/hal/uart/Uart.h" - -#include -#include - -#include -#include -#include - -#ifdef ESP_PLATFORM -#include -#include -#else -#include -#include -#endif - -namespace tt::hal::uart { - -static const auto LOGGER = Logger("UART"); - -constexpr uint32_t uartIdNotInUse = 0; - -struct UartEntry { - uint32_t usageId = uartIdNotInUse; - Configuration configuration; -}; - -static std::vector uartEntries = {}; -static uint32_t lastUartId = uartIdNotInUse; - -bool init(const std::vector& configurations) { - LOGGER.info("Init"); - for (const auto& configuration: configurations) { - uartEntries.push_back({ - .usageId = uartIdNotInUse, - .configuration = configuration - }); - } - - return true; -} - -bool Uart::writeString(const char* buffer, TickType_t timeout) { - auto size = strlen(buffer); - writeBytes((std::byte*)buffer, size, timeout); - return true; -} - -size_t Uart::readUntil(std::byte* buffer, size_t bufferSize, uint8_t untilByte, TickType_t timeout, bool addNullTerminator) { - TickType_t start_time = kernel::getTicks(); - auto* buffer_write_ptr = reinterpret_cast(buffer); - uint8_t* buffer_limit = buffer_write_ptr + bufferSize - 1; // Keep 1 extra char as mull terminator - TickType_t timeout_left = timeout; - while (readByte(reinterpret_cast(buffer_write_ptr), timeout_left) && buffer_write_ptr < buffer_limit) { -#ifdef DEBUG_READ_UNTIL - // If first successful read and we're not receiving an empty response - if (buffer_write_ptr == buffer && *buffer_write_ptr != 0x00U && *buffer_write_ptr != untilByte) { - printf(">>"); - } -#endif - - if (*buffer_write_ptr == untilByte) { - // TODO: Fix when untilByte is null terminator char already - if (addNullTerminator) { - buffer_write_ptr++; - *buffer_write_ptr = 0x00U; - } - break; - } - -#ifdef DEBUG_READ_UNTIL - printf("%c", *buffer_write_ptr); -#endif - - buffer_write_ptr++; - - TickType_t now = kernel::getTicks(); - if (now > (start_time + timeout)) { -#ifdef DEBUG_READ_UNTIL - LOGGER.warn("readUntil() timeout"); -#endif - break; - } else { - timeout_left = timeout - (now - start_time); - } - } - -#ifdef DEBUG_READ_UNTIL - // If we read data and it's not an empty response - if (buffer_write_ptr != buffer && *buffer != 0x00U && *buffer != untilByte) { - printf("\n"); - } -#endif - - if (addNullTerminator && (buffer_write_ptr > reinterpret_cast(buffer))) { - return reinterpret_cast(buffer_write_ptr) - reinterpret_cast(buffer) - 1UL; - } else { - return reinterpret_cast(buffer_write_ptr) - reinterpret_cast(buffer); - } -} - -static std::unique_ptr open(UartEntry& entry) { - if (entry.usageId != uartIdNotInUse) { - LOGGER.error("UART in use: {}", entry.configuration.name); - return nullptr; - } - - auto uart = create(entry.configuration); - assert(uart != nullptr); - entry.usageId = uart->getId(); - LOGGER.info("Opened {}", entry.usageId); - return uart; -} - -std::unique_ptr open(uart_port_t port) { - LOGGER.info("Open {}", static_cast(port)); - - auto result = std::views::filter(uartEntries, [port](auto& entry) { - return entry.configuration.port == port; - }); - - if (result.empty()) { - LOGGER.error("UART not found: {}", static_cast(port)); - return nullptr; - } - - return open(*result.begin()); -} - -std::unique_ptr open(std::string name) { - LOGGER.info("Open {}", name); - - auto result = std::views::filter(uartEntries, [&name](auto& entry) { - return entry.configuration.name == name; - }); - - if (result.empty()) { - LOGGER.error("UART not found: {}", name); - return nullptr; - } - - return open(*result.begin()); -} - -void close(uint32_t uartId) { - LOGGER.info("Close {}", uartId); - auto result = std::views::filter(uartEntries, [&uartId](auto& entry) { - return entry.usageId == uartId; - }); - - if (!result.empty()) { - auto& entry = *result.begin(); - entry.usageId = uartIdNotInUse; - } else { - LOGGER.warn("Auto-closing UART, but can't find it"); - } -} - -std::vector getNames() { - std::vector names; -#ifdef ESP_PLATFORM - for (auto& config : getConfiguration()->uart) { - names.push_back(config.name); - } -#else - DIR* dir = opendir("/dev"); - if (dir == nullptr) { - LOGGER.error("Failed to read /dev"); - return names; - } - struct dirent* current_entry; - while ((current_entry = readdir(dir)) != nullptr) { - auto name = std::string(current_entry->d_name); - if (name.starts_with("tty")) { - auto path = std::string("/dev/") + name; - names.push_back(path); - } - } - - closedir(dir); -#endif - return names; -} - -Uart::Uart() : id(++lastUartId) {} - -Uart::~Uart() { - close(getId()); -} - -} // namespace tt::hal::uart diff --git a/Tactility/Source/hal/uart/UartEsp.cpp b/Tactility/Source/hal/uart/UartEsp.cpp deleted file mode 100644 index 6b6fb2bc1..000000000 --- a/Tactility/Source/hal/uart/UartEsp.cpp +++ /dev/null @@ -1,157 +0,0 @@ -#ifdef ESP_PLATFORM - -#include - -#include -#include -#include - -#include -#include - -namespace tt::hal::uart { - -static const auto LOGGER = Logger("UART"); - -bool UartEsp::start() { - LOGGER.info("[{}] Starting", configuration.name); - - auto lock = mutex.asScopedLock(); - lock.lock(); - - if (started) { - LOGGER.error("[{}] Starting: Already started", configuration.name); - return false; - } - - int intr_alloc_flags; -#if CONFIG_UART_ISR_IN_IRAM - intr_alloc_flags = ESP_INTR_FLAG_IRAM; -#else - intr_alloc_flags = 0; -#endif - - esp_err_t result = uart_param_config(configuration.port, &configuration.config); - if (result != ESP_OK) { - LOGGER.error("[{}] Starting: Failed to configure: {}", configuration.name, esp_err_to_name(result)); - return false; - } - - if (uart_is_driver_installed(configuration.port)) { - LOGGER.error("[{}] Driver was still installed. You probably forgot to stop, or another system uses/used the driver.", configuration.name); - uart_driver_delete(configuration.port); - } - - result = uart_set_pin(configuration.port, configuration.txPin, configuration.rxPin, configuration.rtsPin, configuration.ctsPin); - if (result != ESP_OK) { - LOGGER.error("[{}] Starting: Failed set pins: {}", configuration.name, esp_err_to_name(result)); - return false; - } - - result = uart_driver_install(configuration.port, (int)configuration.rxBufferSize, (int)configuration.txBufferSize, 0, nullptr, intr_alloc_flags); - if (result != ESP_OK) { - LOGGER.error("[{}] Starting: Failed to install driver: {}", configuration.name, esp_err_to_name(result)); - return false; - } - - started = true; - - LOGGER.info("[{}] Started", configuration.name); - return true; -} - -bool UartEsp::stop() { - LOGGER.info("[{}] Stopping", configuration.name); - - auto lock = mutex.asScopedLock(); - lock.lock(); - - if (!started) { - LOGGER.error("[{}] Stopping: Not started", configuration.name); - return false; - } - - esp_err_t result = uart_driver_delete(configuration.port); - if (result != ESP_OK) { - LOGGER.error("[{}] Stopping: Failed to delete driver: {}", configuration.name, esp_err_to_name(result)); - return false; - } - - started = false; - - LOGGER.info("[{}] Stopped", configuration.name); - return true; -} - -bool UartEsp::isStarted() const { - auto lock = mutex.asScopedLock(); - lock.lock(); - return started; -} - -size_t UartEsp::readBytes(std::byte* buffer, size_t bufferSize, TickType_t timeout) { - auto lock = mutex.asScopedLock(); - if (!lock.lock(timeout)) { - return false; - } - - auto start_time = kernel::getTicks(); - auto lock_time = kernel::getTicks() - start_time; - auto remaining_timeout = std::max(timeout - lock_time, 0UL); - auto result = uart_read_bytes(configuration.port, buffer, bufferSize, remaining_timeout); - return result; -} - -bool UartEsp::readByte(std::byte* output, TickType_t timeout) { - return readBytes(output, 1, timeout) == 1; -} - -size_t UartEsp::writeBytes(const std::byte* buffer, size_t bufferSize, TickType_t timeout) { - auto lock = mutex.asScopedLock(); - if (!lock.lock(timeout)) { - return false; - } - - return uart_write_bytes(configuration.port, buffer, bufferSize); -} - -size_t UartEsp::available(TickType_t timeout) { - auto lock = mutex.asScopedLock(); - if (!lock.lock(timeout)) { - return false; - } - - size_t size = 0; - uart_get_buffered_data_len(configuration.port, &size); - return size; -} - -void UartEsp::flushInput() { - uart_flush_input(configuration.port); -} - -uint32_t UartEsp::getBaudRate() { - uint32_t baud_rate = 0; - auto result = uart_get_baudrate(configuration.port, &baud_rate); - ESP_ERROR_CHECK_WITHOUT_ABORT(result); - return baud_rate; -} - -bool UartEsp::setBaudRate(uint32_t baudRate, TickType_t timeout) { - auto lock = mutex.asScopedLock(); - if (!lock.lock(timeout)) { - return false; - } - - auto result = uart_set_baudrate(configuration.port, baudRate); - ESP_ERROR_CHECK_WITHOUT_ABORT(result); - return result == ESP_OK; -} - -std::unique_ptr create(const Configuration& configuration) { - return std::make_unique(configuration); -} - -} // namespace tt::hal::uart - -#endif diff --git a/Tactility/Source/hal/uart/UartPosix.cpp b/Tactility/Source/hal/uart/UartPosix.cpp deleted file mode 100644 index 74d13987b..000000000 --- a/Tactility/Source/hal/uart/UartPosix.cpp +++ /dev/null @@ -1,191 +0,0 @@ -#ifndef ESP_PLATFORM - -#include -#include -#include -#include - -#include -#include -#include -#include - -namespace tt::hal::uart { - -static const auto LOGGER = Logger("UART"); - -bool UartPosix::start() { - auto lock = mutex.asScopedLock(); - lock.lock(); - - if (device != nullptr) { - LOGGER.error("[{}] Starting: Already started", configuration.name); - return false; - } - - auto file = fopen(configuration.name.c_str(), "w"); - if (file == nullptr) { - LOGGER.error("[{}] Open device failed", configuration.name); - return false; - } - - auto new_device = std::unique_ptr(file); - - struct termios tty; - if (tcgetattr(fileno(file), &tty) < 0) { - LOGGER.error("[{}] tcgetattr failed: {}", configuration.name, strerror(errno)); - return false; - } - - if (cfsetospeed(&tty, (speed_t)configuration.baudRate) == -1) { - LOGGER.error("[{}] Setting output speed failed", configuration.name); - } - - if (cfsetispeed(&tty, (speed_t)configuration.baudRate) == -1) { - LOGGER.error("[{}] Setting input speed failed", configuration.name); - } - - tty.c_cflag |= (CLOCAL | CREAD); /* ignore modem controls */ - tty.c_cflag &= ~CSIZE; - tty.c_cflag |= CS8; /* 8-bit characters */ - tty.c_cflag &= ~PARENB; /* no parity bit */ - tty.c_cflag &= ~CSTOPB; /* only need 1 stop bit */ - tty.c_cflag &= ~CRTSCTS; /* no hardware flowcontrol */ - - tty.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); - tty.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); - tty.c_oflag &= ~OPOST; - - /* fetch bytes as they become available */ - tty.c_cc[VMIN] = 1; - tty.c_cc[VTIME] = 1; - - if (tcsetattr(fileno(file), TCSANOW, &tty) != 0) { - LOGGER.error("[{}] tcsetattr failed: {}", configuration.name, strerror(errno)); - return false; - } - - device = std::move(new_device); - - LOGGER.info("[{}] Started", configuration.name); - return true; -} - -bool UartPosix::stop() { - auto lock = mutex.asScopedLock(); - lock.lock(); - - if (device == nullptr) { - LOGGER.error("[{}] Stopping: Not started", configuration.name); - return false; - } - - device = nullptr; - - LOGGER.info("[{}] Stopped", configuration.name); - return true; -} - -bool UartPosix::isStarted() const { - auto lock = mutex.asScopedLock(); - lock.lock(); - return device != nullptr; -} - -size_t UartPosix::readBytes(std::byte* buffer, size_t bufferSize, TickType_t timeout) { - auto lock = mutex.asScopedLock(); - if (!lock.lock(timeout)) { - return false; - } - - if (awaitAvailable(timeout)) { - return read(fileno(device.get()), buffer, bufferSize); - } else { - return 0; - } -} - -bool UartPosix::readByte(std::byte* output, TickType_t timeout) { - if (awaitAvailable(timeout)) { - return read(fileno(device.get()), output, 1) == 1; - } else { - return false; - } -} - -size_t UartPosix::writeBytes(const std::byte* buffer, size_t bufferSize, TickType_t timeout) { - if (!mutex.lock(timeout)) { - return false; - } - - return write(fileno(device.get()), buffer, bufferSize); -} - -size_t UartPosix::available(TickType_t timeout) { - auto lock = mutex.asScopedLock(); - if (!lock.lock(timeout)) { - return false; - } - - uint32_t bytes_available = 0; - ioctl(fileno(device.get()), FIONREAD, bytes_available); - return bytes_available; -} - -void UartPosix::flushInput() { - // TODO -} - -uint32_t UartPosix::getBaudRate() { - struct termios tty; - if (tcgetattr(fileno(device.get()), &tty) < 0) { - LOGGER.error("[{}] tcgetattr failed: {}", configuration.name, strerror(errno)); - return false; - } else { - return (uint32_t)cfgetispeed(&tty); - } -} - -bool UartPosix::setBaudRate(uint32_t baudRate, TickType_t timeout) { - auto lock = mutex.asScopedLock(); - if (!lock.lock(timeout)) { - return false; - } - - struct termios tty; - if (tcgetattr(fileno(device.get()), &tty) < 0) { - LOGGER.error("[{}] tcgetattr failed: {}", configuration.name, strerror(errno)); - return false; - } - - if (cfsetospeed(&tty, (speed_t)configuration.baudRate) == -1) { - LOGGER.error("[{}] Failed to set output speed", configuration.name); - return false; - } - - if (cfsetispeed(&tty, (speed_t)configuration.baudRate) == -1) { - LOGGER.error("[{}] Failed to set input speed", configuration.name); - return false; - } - - return true; -} - -bool UartPosix::awaitAvailable(TickType_t timeout) { - auto start_time = kernel::getTicks(); - do { - if (available(timeout) > 0) { - return true; - } - kernel::delayTicks(timeout / 10); - } while ((kernel::getTicks() - start()) < timeout); - return false; -} - -std::unique_ptr create(const Configuration& configuration) { - return std::make_unique(configuration); -} - -} // namespace tt::hal::uart - -#endif diff --git a/TactilityC/Include/tt_hal_uart.h b/TactilityC/Include/tt_hal_uart.h index 4d56f17af..8f787aa08 100644 --- a/TactilityC/Include/tt_hal_uart.h +++ b/TactilityC/Include/tt_hal_uart.h @@ -9,6 +9,13 @@ extern "C" { #endif +/** + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * WARNING: THIS API IS NON-FUNCTIONAL AND DEPRECATED. + * IT WILL BE REMOVED IN A FUTURE RELEASE ONCE OFFICIAL APPS ARE MIGRATED. +* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + */ + /** * @file tt_hal_uart.h * @brief C HAL interface for UART devices used by Tactility C modules. diff --git a/TactilityC/Source/tt_hal_uart.cpp b/TactilityC/Source/tt_hal_uart.cpp index 89e9b15dd..13a988fde 100644 --- a/TactilityC/Source/tt_hal_uart.cpp +++ b/TactilityC/Source/tt_hal_uart.cpp @@ -1,84 +1,61 @@ #include "tt_hal_uart.h" -#include #include -using namespace tt::hal; - -struct UartWrapper { - std::shared_ptr uart; -}; - -#define HANDLE_AS_UART(handle) static_cast(handle)->uart - extern "C" { size_t tt_hal_uart_get_count() { - return uart::getNames().size(); + return 0; } bool tt_hal_uart_get_name(size_t index, char* name, size_t nameSizeLimit) { - assert(index < uart::getNames().size()); - auto source_name = uart::getNames()[index]; - return strncpy(name, source_name.c_str(), nameSizeLimit) != nullptr; + return false; } UartHandle tt_hal_uart_alloc(size_t index) { - assert(index < uart::getNames().size()); - auto* wrapper = new UartWrapper(); - auto name = uart::getNames()[index]; - wrapper->uart = uart::open(name); - assert(wrapper->uart != nullptr); - return wrapper; + return nullptr; } void tt_hal_uart_free(UartHandle handle) { - auto* wrapper = static_cast(handle); - assert(wrapper->uart != nullptr); - if (wrapper->uart->isStarted()) { - wrapper->uart->stop(); - } - delete wrapper; } bool tt_hal_uart_start(UartHandle handle) { - return HANDLE_AS_UART(handle)->start(); + return false; } bool tt_hal_uart_is_started(UartHandle handle) { - return HANDLE_AS_UART(handle)->isStarted(); + return false; } bool tt_hal_uart_stop(UartHandle handle) { - return HANDLE_AS_UART(handle)->stop(); + return false; } size_t tt_hal_uart_read_bytes(UartHandle handle, char* buffer, size_t bufferSize, TickType_t timeout) { - return HANDLE_AS_UART(handle)->readBytes(reinterpret_cast(buffer), bufferSize, timeout); + return 0; } bool tt_hal_uart_read_byte(UartHandle handle, char* output, TickType_t timeout) { - return HANDLE_AS_UART(handle)->readByte(reinterpret_cast(output), timeout); + return false; } size_t tt_hal_uart_write_bytes(UartHandle handle, const char* buffer, size_t bufferSize, TickType_t timeout) { - return HANDLE_AS_UART(handle)->writeBytes(reinterpret_cast(buffer), bufferSize, timeout); + return 0; } size_t tt_hal_uart_available(UartHandle handle) { - return HANDLE_AS_UART(handle)->available(); + return 0; } bool tt_hal_uart_set_baud_rate(UartHandle handle, size_t baud_rate) { - return HANDLE_AS_UART(handle)->setBaudRate(baud_rate); + return false; } uint32_t tt_hal_uart_get_baud_rate(UartHandle handle) { - return HANDLE_AS_UART(handle)->getBaudRate(); + return 0; } void tt_hal_uart_flush_input(UartHandle handle) { - HANDLE_AS_UART(handle)->flushInput(); } } diff --git a/TactilityKernel/Include/tactility/device.h b/TactilityKernel/Include/tactility/device.h index 44f651270..d0b147917 100644 --- a/TactilityKernel/Include/tactility/device.h +++ b/TactilityKernel/Include/tactility/device.h @@ -259,6 +259,14 @@ void device_for_each_child(struct Device* device, void* callback_context, bool(* */ void device_for_each_of_type(const struct DeviceType* type, void* callback_context, bool(*on_device)(struct Device* device, void* context)); +/** + * Check if a device of the specified type exists. + * + * @param[in] type the type to check + * @return true if a device of the specified type exists + */ +bool device_exists_of_type(const struct DeviceType* type); + /** * Find a device by its name. * diff --git a/TactilityKernel/Include/tactility/drivers/spi_controller.h b/TactilityKernel/Include/tactility/drivers/spi_controller.h index f248759ae..11c4d0d84 100644 --- a/TactilityKernel/Include/tactility/drivers/spi_controller.h +++ b/TactilityKernel/Include/tactility/drivers/spi_controller.h @@ -18,13 +18,6 @@ struct Device; * @brief API for SPI controller drivers. */ struct SpiControllerApi { - /** - * @brief Resets the SPI controller. - * @param[in] device the SPI controller device - * @retval ERROR_NONE when the operation was successful - */ - error_t (*reset)(struct Device* device); - /** * @brief Locks the SPI controller. * @param[in] device the SPI controller device @@ -49,13 +42,6 @@ struct SpiControllerApi { error_t (*unlock)(struct Device* device); }; -/** - * @brief Resets the SPI controller using the specified controller. - * @param[in] device the SPI controller device - * @retval ERROR_NONE when the operation was successful - */ -error_t spi_controller_reset(struct Device* device); - /** * @brief Locks the SPI controller using the specified controller. * @param[in] device the SPI controller device diff --git a/TactilityKernel/Include/tactility/drivers/uart_controller.h b/TactilityKernel/Include/tactility/drivers/uart_controller.h index 5e74d7a14..428760e35 100644 --- a/TactilityKernel/Include/tactility/drivers/uart_controller.h +++ b/TactilityKernel/Include/tactility/drivers/uart_controller.h @@ -101,9 +101,10 @@ struct UartControllerApi { /** * @brief Returns the number of bytes available for reading. * @param[in] device the UART controller device - * @return the number of bytes available, or a negative error code on failure + * @param[out] available the number of bytes available + * @return ERROR_NONE on success */ - int (*available)(struct Device* device); + error_t (*get_available)(struct Device* device, size_t* available); /** * @brief Sets the UART configuration. @@ -171,9 +172,23 @@ error_t uart_controller_write_bytes(struct Device* device, const uint8_t* buffer error_t uart_controller_read_bytes(struct Device* device, uint8_t* buffer, size_t buffer_size, TickType_t timeout); /** - * @brief Returns the number of bytes available for reading using the specified controller. + * @brief Reads from UART until a specific byte is encountered. + * @param[in] device the UART controller device + * @param[out] buffer the buffer to store the read data + * @param[in] buffer_size the size of the buffer + * @param[in] until_byte the byte to look for + * @param[in] timeout the maximum time to wait for the operation to complete + * @param[in] add_null_terminator whether to add a null terminator after the until_byte + * @param[out] bytes_read the number of bytes read (excluding null terminator if added) + * @retval ERROR_NONE when the operation was successful + * @retval ERROR_TIMEOUT when the operation timed out */ -int uart_controller_available(struct Device* device); +error_t uart_controller_read_until(struct Device* device, uint8_t* buffer, size_t buffer_size, uint8_t until_byte, bool add_null_terminator, size_t* bytes_read, TickType_t timeout); + +/** + * @brief Get the number of bytes available for reading using the specified controller. + */ +error_t uart_controller_get_available(struct Device* device, size_t* available); /** * @brief Sets the UART configuration using the specified controller. @@ -200,11 +215,6 @@ error_t uart_controller_close(struct Device* device); */ bool uart_controller_is_open(struct Device* device); -/** - * @brief Resets the UART controller using the specified controller. - */ -error_t uart_controller_reset(struct Device* device); - /** * @brief Flushes the UART input buffer using the specified controller. */ diff --git a/TactilityKernel/Source/device.cpp b/TactilityKernel/Source/device.cpp index 066d10fe3..3e19b5b5c 100644 --- a/TactilityKernel/Source/device.cpp +++ b/TactilityKernel/Source/device.cpp @@ -338,6 +338,20 @@ void device_for_each_of_type(const DeviceType* type, void* callbackContext, bool ledger_unlock(); } +bool device_exists_of_type(const DeviceType* type) { + bool found = false; + ledger_lock(); + for (auto* device : ledger.devices) { + auto* driver = device->internal->driver; + if (driver != nullptr && driver->device_type == type) { + found = true; + break; + } + } + ledger_unlock(); + return found; +} + Device* device_find_by_name(const char* name) { Device* found = nullptr; ledger_lock(); diff --git a/TactilityKernel/Source/drivers/spi_controller.cpp b/TactilityKernel/Source/drivers/spi_controller.cpp index 7b0c6c342..b5e654cfe 100644 --- a/TactilityKernel/Source/drivers/spi_controller.cpp +++ b/TactilityKernel/Source/drivers/spi_controller.cpp @@ -7,11 +7,6 @@ extern "C" { -error_t spi_controller_reset(struct Device* device) { - const auto* driver = device_get_driver(device); - return SPI_DRIVER_API(driver)->reset(device); -} - error_t spi_controller_lock(struct Device* device) { const auto* driver = device_get_driver(device); return SPI_DRIVER_API(driver)->lock(device); diff --git a/TactilityKernel/Source/drivers/uart_controller.cpp b/TactilityKernel/Source/drivers/uart_controller.cpp index 25ddb9d6b..46631114a 100644 --- a/TactilityKernel/Source/drivers/uart_controller.cpp +++ b/TactilityKernel/Source/drivers/uart_controller.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #define UART_DRIVER_API(driver) ((struct UartControllerApi*)driver->api) @@ -27,9 +28,54 @@ error_t uart_controller_read_bytes(struct Device* device, uint8_t* buffer, size_ return UART_DRIVER_API(driver)->read_bytes(device, buffer, buffer_size, timeout); } -int uart_controller_available(struct Device* device) { +error_t uart_controller_read_until(struct Device* device, uint8_t* buffer, size_t buffer_size, uint8_t until_byte, bool add_null_terminator, size_t* bytes_read, TickType_t timeout) { + size_t read_count = 0; + TickType_t start_time = get_ticks(); + uint8_t* buffer_write_ptr = buffer; + uint8_t* buffer_limit = buffer + buffer_size; + if (add_null_terminator) { + buffer_limit--; + } + TickType_t timeout_left = timeout; + error_t result = ERROR_NONE; + + while (buffer_write_ptr < buffer_limit) { + result = uart_controller_read_byte(device, buffer_write_ptr, timeout_left); + if (result != ERROR_NONE) { + break; + } + + read_count++; + + if (*buffer_write_ptr == until_byte) { + if (add_null_terminator) { + buffer_write_ptr++; + *buffer_write_ptr = 0x00U; + } + break; + } + + buffer_write_ptr++; + + TickType_t now = get_ticks(); + if (now > (start_time + timeout)) { + result = ERROR_TIMEOUT; + break; + } else { + timeout_left = timeout - (now - start_time); + } + } + + if (bytes_read != nullptr) { + *bytes_read = read_count; + } + + return result; +} + +error_t uart_controller_get_available(struct Device* device, size_t* available) { const auto* driver = device_get_driver(device); - return UART_DRIVER_API(driver)->available(device); + return UART_DRIVER_API(driver)->get_available(device, available); } error_t uart_controller_set_config(struct Device* device, const struct UartConfig* config) { diff --git a/TactilityKernel/Source/kernel_symbols.c b/TactilityKernel/Source/kernel_symbols.c index 27085fbac..e9686ea25 100644 --- a/TactilityKernel/Source/kernel_symbols.c +++ b/TactilityKernel/Source/kernel_symbols.c @@ -1,8 +1,10 @@ #include #include +#include #include #include -#include +#include +#include #include #include #include @@ -41,6 +43,7 @@ const struct ModuleSymbol KERNEL_SYMBOLS[] = { DEFINE_MODULE_SYMBOL(device_for_each), DEFINE_MODULE_SYMBOL(device_for_each_child), DEFINE_MODULE_SYMBOL(device_for_each_of_type), + DEFINE_MODULE_SYMBOL(device_exists_of_type), // driver DEFINE_MODULE_SYMBOL(driver_construct), DEFINE_MODULE_SYMBOL(driver_destruct), @@ -76,6 +79,24 @@ const struct ModuleSymbol KERNEL_SYMBOLS[] = { DEFINE_MODULE_SYMBOL(i2s_controller_get_config), DEFINE_MODULE_SYMBOL(i2s_controller_reset), DEFINE_MODULE_SYMBOL(I2S_CONTROLLER_TYPE), + // drivers/spi_controller + DEFINE_MODULE_SYMBOL(spi_controller_lock), + DEFINE_MODULE_SYMBOL(spi_controller_try_lock), + DEFINE_MODULE_SYMBOL(spi_controller_unlock), + // drivers/uart_controller + DEFINE_MODULE_SYMBOL(uart_controller_open), + DEFINE_MODULE_SYMBOL(uart_controller_close), + DEFINE_MODULE_SYMBOL(uart_controller_is_open), + DEFINE_MODULE_SYMBOL(uart_controller_read_byte), + DEFINE_MODULE_SYMBOL(uart_controller_read_bytes), + DEFINE_MODULE_SYMBOL(uart_controller_read_until), + DEFINE_MODULE_SYMBOL(uart_controller_write_byte), + DEFINE_MODULE_SYMBOL(uart_controller_write_bytes), + DEFINE_MODULE_SYMBOL(uart_controller_set_config), + DEFINE_MODULE_SYMBOL(uart_controller_get_config), + DEFINE_MODULE_SYMBOL(uart_controller_get_available), + DEFINE_MODULE_SYMBOL(uart_controller_flush_input), + DEFINE_MODULE_SYMBOL(UART_CONTROLLER_TYPE), // concurrent/dispatcher DEFINE_MODULE_SYMBOL(dispatcher_alloc), DEFINE_MODULE_SYMBOL(dispatcher_free), From 7a397e7249fcfdc3211c2a7be4875dcccc89d0cf Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 7 Feb 2026 17:35:18 +0100 Subject: [PATCH 12/19] Updated dts files for uart and removed old configs --- .../cyd-2432s028r/Source/Configuration.cpp | 26 ------- Devices/cyd-2432s028r/cyd,2432s028r.dts | 10 +++ .../cyd-2432s028rv3/Source/Configuration.cpp | 25 ------- Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts | 10 +++ .../cyd-8048s043c/Source/Configuration.cpp | 26 ------- Devices/cyd-8048s043c/cyd,8048s043c.dts | 10 +++ .../Source/Configuration.cpp | 50 ------------- .../elecrow,crowpanel-advance-28.dts | 19 +++++ .../Source/Configuration.cpp | 50 ------------- .../elecrow,crowpanel-advance-35.dts | 19 +++++ .../Source/Configuration.cpp | 50 ------------- .../elecrow,crowpanel-advance-50.dts | 19 +++++ .../Source/Configuration.cpp | 26 ------- .../elecrow,crowpanel-basic-28.dts | 10 +++ .../Source/Configuration.cpp | 26 ------- .../elecrow,crowpanel-basic-35.dts | 10 +++ .../Source/Configuration.cpp | 26 ------- .../elecrow,crowpanel-basic-50.dts | 10 +++ .../Source/Configuration.cpp | 26 ------- .../guition,jc2432w328c.dts | 17 ++++- .../Source/Configuration.cpp | 26 ------- .../guition,jc3248w535c.dts | 15 +++- .../Source/Configuration.cpp | 26 ------- .../guition,jc8048w550c.dts | 14 +++- Devices/lilygo-tdeck/Source/Init.cpp | 2 +- Devices/lilygo-tdeck/lilygo,tdeck.dts | 2 +- .../Source/Configuration.cpp | 25 ------- .../lilygo-tdongle-s3/lilygo,tdongle-s3.dts | 10 +++ .../Source/Configuration.cpp | 23 ------ Devices/lilygo-tlora-pager/Source/Init.cpp | 2 +- .../lilygo-tlora-pager/lilygo,tlora-pager.dts | 19 +++++ .../Source/Configuration.cpp | 26 ------- .../m5stack,cardputer-adv.dts | 10 +++ .../Source/Configuration.cpp | 25 ------- .../m5stack-cardputer/m5stack,cardputer.dts | 10 +++ .../m5stack-core2/Source/Configuration.cpp | 25 ------- Devices/m5stack-core2/m5stack,core2.dts | 10 +++ .../m5stack-cores3/Source/Configuration.cpp | 71 ------------------- Devices/m5stack-cores3/m5stack,cores3.dts | 10 +++ .../Source/Configuration.cpp | 25 ------- .../m5stack,stickc-plus.dts | 10 +++ .../Source/Configuration.cpp | 25 ------- .../m5stack,stickc-plus2.dts | 10 +++ .../Source/Configuration.cpp | 26 ------- .../waveshare,esp32-s3-geek.dts | 10 +++ .../Source/Configuration.cpp | 3 +- .../Source/Configuration.cpp | 26 ------- .../waveshare,s3-touch-lcd-43.dts | 10 +++ 48 files changed, 269 insertions(+), 692 deletions(-) diff --git a/Devices/cyd-2432s028r/Source/Configuration.cpp b/Devices/cyd-2432s028r/Source/Configuration.cpp index 6469188aa..30856c74d 100644 --- a/Devices/cyd-2432s028r/Source/Configuration.cpp +++ b/Devices/cyd-2432s028r/Source/Configuration.cpp @@ -80,31 +80,5 @@ extern const Configuration hardwareConfiguration = { .isMutable = false, .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display }, - }, - - .uart { - uart::Configuration { - .name = "P1", - .port = UART_NUM_1, - .rxPin = GPIO_NUM_1, - .txPin = GPIO_NUM_3, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 115200, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } - } } }; diff --git a/Devices/cyd-2432s028r/cyd,2432s028r.dts b/Devices/cyd-2432s028r/cyd,2432s028r.dts index 75d49819a..6bc797bdc 100644 --- a/Devices/cyd-2432s028r/cyd,2432s028r.dts +++ b/Devices/cyd-2432s028r/cyd,2432s028r.dts @@ -3,6 +3,7 @@ #include #include #include +#include / { compatible = "root"; @@ -20,4 +21,13 @@ pin-sda = <27>; pin-scl = <22>; }; + + uart1 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <3>; + pin-rx = <1>; + pin-cts = ; + pin-rtx = ; + }; }; diff --git a/Devices/cyd-2432s028rv3/Source/Configuration.cpp b/Devices/cyd-2432s028rv3/Source/Configuration.cpp index bb410444a..30856c74d 100644 --- a/Devices/cyd-2432s028rv3/Source/Configuration.cpp +++ b/Devices/cyd-2432s028rv3/Source/Configuration.cpp @@ -80,30 +80,5 @@ extern const Configuration hardwareConfiguration = { .isMutable = false, .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display }, - }, - .uart { - uart::Configuration { - .name = "P1", - .port = UART_NUM_1, - .rxPin = GPIO_NUM_1, - .txPin = GPIO_NUM_3, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 115200, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } - } } }; diff --git a/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts b/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts index d0219b0d1..159334a9d 100644 --- a/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts +++ b/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts @@ -3,6 +3,7 @@ #include #include #include +#include / { compatible = "root"; @@ -20,4 +21,13 @@ pin-sda = <27>; pin-scl = <22>; }; + + uart1 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <3>; + pin-rx = <1>; + pin-cts = ; + pin-rtx = ; + }; }; diff --git a/Devices/cyd-8048s043c/Source/Configuration.cpp b/Devices/cyd-8048s043c/Source/Configuration.cpp index 045826bdd..296d2b4ef 100644 --- a/Devices/cyd-8048s043c/Source/Configuration.cpp +++ b/Devices/cyd-8048s043c/Source/Configuration.cpp @@ -46,31 +46,5 @@ extern const Configuration hardwareConfiguration = { .isMutable = false, .lock = nullptr } - }, - .uart { - // P4 header, JST SH 1.0, GND / 3.3V / IO17 / IO18 - uart::Configuration { - .name = "UART1", - .port = UART_NUM_1, - .rxPin = GPIO_NUM_17, - .txPin = GPIO_NUM_18, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 9600, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } - } } }; diff --git a/Devices/cyd-8048s043c/cyd,8048s043c.dts b/Devices/cyd-8048s043c/cyd,8048s043c.dts index 9ae77bbf7..4cde60eb4 100644 --- a/Devices/cyd-8048s043c/cyd,8048s043c.dts +++ b/Devices/cyd-8048s043c/cyd,8048s043c.dts @@ -3,6 +3,7 @@ #include #include #include +#include / { compatible = "root"; @@ -30,4 +31,13 @@ pin-sda = <17>; pin-scl = <18>; }; + + uart1 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <18>; + pin-rx = <17>; + pin-cts = ; + pin-rtx = ; + }; }; diff --git a/Devices/elecrow-crowpanel-advance-28/Source/Configuration.cpp b/Devices/elecrow-crowpanel-advance-28/Source/Configuration.cpp index 65f0050f4..69c29928b 100644 --- a/Devices/elecrow-crowpanel-advance-28/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-advance-28/Source/Configuration.cpp @@ -70,55 +70,5 @@ extern const Configuration hardwareConfiguration = { .isMutable = false, .lock = nullptr // No custom lock needed } - }, - .uart { - // "UART0-IN" - uart::Configuration { - .name = "UART0", - .port = UART_NUM_1, - .rxPin = GPIO_NUM_44, - .txPin = GPIO_NUM_43, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 115200, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } - }, - // "UART1-OUT" - uart::Configuration { - .name = "UART1", - .port = UART_NUM_2, - .rxPin = GPIO_NUM_18, - .txPin = GPIO_NUM_17, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 115200, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } - } } }; diff --git a/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts b/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts index 2b2413459..54682b82b 100644 --- a/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts +++ b/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts @@ -3,6 +3,7 @@ #include #include #include +#include / { compatible = "root"; @@ -22,4 +23,22 @@ pin-sda-pullup; pin-scl-pullup; }; + + uart0 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <43>; + pin-rx = <44>; + pin-cts = ; + pin-rtx = ; + }; + + uart1 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <17>; + pin-rx = <18>; + pin-cts = ; + pin-rtx = ; + }; }; diff --git a/Devices/elecrow-crowpanel-advance-35/Source/Configuration.cpp b/Devices/elecrow-crowpanel-advance-35/Source/Configuration.cpp index 366e7f1ee..2ab3df9a1 100644 --- a/Devices/elecrow-crowpanel-advance-35/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-advance-35/Source/Configuration.cpp @@ -72,55 +72,5 @@ extern const Configuration hardwareConfiguration = { .isMutable = false, .lock = nullptr // No custom lock needed } - }, - .uart { - // "UART0-IN" - uart::Configuration { - .name = "UART0", - .port = UART_NUM_1, - .rxPin = GPIO_NUM_44, - .txPin = GPIO_NUM_43, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 115200, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } - }, - // "UART1-OUT" - uart::Configuration { - .name = "UART1", - .port = UART_NUM_2, - .rxPin = GPIO_NUM_18, - .txPin = GPIO_NUM_17, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 115200, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } - } } }; diff --git a/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts b/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts index f68edd52d..6ff37fafe 100644 --- a/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts +++ b/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts @@ -3,6 +3,7 @@ #include #include #include +#include / { compatible = "root"; @@ -22,4 +23,22 @@ pin-sda-pullup; pin-scl-pullup; }; + + uart0 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <43>; + pin-rx = <44>; + pin-cts = ; + pin-rtx = ; + }; + + uart1 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <17>; + pin-rx = <18>; + pin-cts = ; + pin-rtx = ; + }; }; diff --git a/Devices/elecrow-crowpanel-advance-50/Source/Configuration.cpp b/Devices/elecrow-crowpanel-advance-50/Source/Configuration.cpp index 9953173f7..0284c3a8f 100644 --- a/Devices/elecrow-crowpanel-advance-50/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-advance-50/Source/Configuration.cpp @@ -56,55 +56,5 @@ extern const Configuration hardwareConfiguration = { .isMutable = false, .lock = nullptr // No custom lock needed } - }, - .uart { - // "UART0-OUT" - uart::Configuration { - .name = "UART0", - .port = UART_NUM_1, - .rxPin = GPIO_NUM_44, - .txPin = GPIO_NUM_43, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 115200, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } - }, - // "UART1-OUT" - uart::Configuration { - .name = "UART1", - .port = UART_NUM_2, - .rxPin = GPIO_NUM_19, - .txPin = GPIO_NUM_20, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 115200, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } - } } }; diff --git a/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts b/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts index c4ad962ca..6d4c4032d 100644 --- a/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts +++ b/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts @@ -3,6 +3,7 @@ #include #include #include +#include / { compatible = "root"; @@ -22,4 +23,22 @@ pin-sda-pullup; pin-scl-pullup; }; + + uart0 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <43>; + pin-rx = <44>; + pin-cts = ; + pin-rtx = ; + }; + + uart1 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <20>; + pin-rx = <19>; + pin-cts = ; + pin-rtx = ; + }; }; diff --git a/Devices/elecrow-crowpanel-basic-28/Source/Configuration.cpp b/Devices/elecrow-crowpanel-basic-28/Source/Configuration.cpp index 163679fb6..9bcb16f42 100644 --- a/Devices/elecrow-crowpanel-basic-28/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-basic-28/Source/Configuration.cpp @@ -72,31 +72,5 @@ extern const Configuration hardwareConfiguration = { .isMutable = false, .lock = nullptr // No custom lock needed } - }, - .uart { - // "UART1" - uart::Configuration { - .name = "UART1", - .port = UART_NUM_1, - .rxPin = GPIO_NUM_16, - .txPin = GPIO_NUM_17, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 115200, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } - } } }; diff --git a/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts b/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts index 3ad279f9a..2aa30d24f 100644 --- a/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts +++ b/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts @@ -3,6 +3,7 @@ #include #include #include +#include / { compatible = "root"; @@ -22,4 +23,13 @@ pin-sda-pullup; pin-scl-pullup; }; + + uart1 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <17>; + pin-rx = <16>; + pin-cts = ; + pin-rtx = ; + }; }; diff --git a/Devices/elecrow-crowpanel-basic-35/Source/Configuration.cpp b/Devices/elecrow-crowpanel-basic-35/Source/Configuration.cpp index 8459cb7ae..70f80e85e 100644 --- a/Devices/elecrow-crowpanel-basic-35/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-basic-35/Source/Configuration.cpp @@ -74,31 +74,5 @@ extern const Configuration hardwareConfiguration = { .isMutable = false, .lock = nullptr // No custom lock needed } - }, - .uart { - // "UART1" - uart::Configuration { - .name = "UART1", - .port = UART_NUM_1, - .rxPin = GPIO_NUM_3, - .txPin = GPIO_NUM_1, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 115200, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } - } } }; diff --git a/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts b/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts index df62cb93f..4353a338f 100644 --- a/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts +++ b/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts @@ -3,6 +3,7 @@ #include #include #include +#include / { compatible = "root"; @@ -22,4 +23,13 @@ pin-sda-pullup; pin-scl-pullup; }; + + uart1 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <1>; + pin-rx = <3>; + pin-cts = ; + pin-rtx = ; + }; }; diff --git a/Devices/elecrow-crowpanel-basic-50/Source/Configuration.cpp b/Devices/elecrow-crowpanel-basic-50/Source/Configuration.cpp index 012b3b3f4..c1cde04fd 100644 --- a/Devices/elecrow-crowpanel-basic-50/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-basic-50/Source/Configuration.cpp @@ -46,31 +46,5 @@ extern const Configuration hardwareConfiguration = { .isMutable = false, .lock = nullptr } - }, - .uart { - // "UART1" - uart::Configuration { - .name = "UART1", - .port = UART_NUM_1, - .rxPin = GPIO_NUM_44, - .txPin = GPIO_NUM_43, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 115200, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } - } } }; diff --git a/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts b/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts index 180927959..65b9bc864 100644 --- a/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts +++ b/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts @@ -3,6 +3,7 @@ #include #include #include +#include / { compatible = "root"; @@ -22,4 +23,13 @@ pin-sda-pullup; pin-scl-pullup; }; + + uart0 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <43>; + pin-rx = <44>; + pin-cts = ; + pin-rtx = ; + }; }; diff --git a/Devices/guition-jc2432w328c/Source/Configuration.cpp b/Devices/guition-jc2432w328c/Source/Configuration.cpp index 2e2e3d218..2336ac695 100644 --- a/Devices/guition-jc2432w328c/Source/Configuration.cpp +++ b/Devices/guition-jc2432w328c/Source/Configuration.cpp @@ -80,31 +80,5 @@ extern const Configuration hardwareConfiguration = { .isMutable = false, .lock = nullptr } - }, - .uart { - //CN1 header, JST SH 1.25, GND / IO22 / IO21 / 3.3V - uart::Configuration { - .name = "UART1", - .port = UART_NUM_1, - .rxPin = GPIO_NUM_21, - .txPin = GPIO_NUM_22, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 9600, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } - } } }; diff --git a/Devices/guition-jc2432w328c/guition,jc2432w328c.dts b/Devices/guition-jc2432w328c/guition,jc2432w328c.dts index beee8c653..509011754 100644 --- a/Devices/guition-jc2432w328c/guition,jc2432w328c.dts +++ b/Devices/guition-jc2432w328c/guition,jc2432w328c.dts @@ -3,6 +3,7 @@ #include #include #include +#include / { compatible = "root"; @@ -13,7 +14,7 @@ gpio-count = <40>; }; - i2c_internal { + i2c_internal: i2c0 { compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; @@ -21,12 +22,22 @@ pin-scl = <32>; }; - /* CN1 header */ - i2c_external { + // CN1 header + i2c_external: i2c1 { compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; pin-sda = <21>; pin-scl = <22>; }; + + // CN1 header, JST SH 1.25, GND / IO22 / IO21 / 3.3V + uart1 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <22>; + pin-rx = <21>; + pin-cts = ; + pin-rtx = ; + }; }; diff --git a/Devices/guition-jc3248w535c/Source/Configuration.cpp b/Devices/guition-jc3248w535c/Source/Configuration.cpp index c7fab1764..e40ece0e1 100644 --- a/Devices/guition-jc3248w535c/Source/Configuration.cpp +++ b/Devices/guition-jc3248w535c/Source/Configuration.cpp @@ -74,31 +74,5 @@ extern const Configuration hardwareConfiguration = { .isMutable = false, .lock = nullptr } - }, - .uart { - //P1 header, JST SH 1.25, 5V / TXD (43) / RXD (44) / GND - uart::Configuration { - .name = "UART0", - .port = UART_NUM_0, - .rxPin = GPIO_NUM_44, - .txPin = GPIO_NUM_43, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 115200, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } - } } }; diff --git a/Devices/guition-jc3248w535c/guition,jc3248w535c.dts b/Devices/guition-jc3248w535c/guition,jc3248w535c.dts index 3a557e14f..c6319faaa 100644 --- a/Devices/guition-jc3248w535c/guition,jc3248w535c.dts +++ b/Devices/guition-jc3248w535c/guition,jc3248w535c.dts @@ -3,6 +3,7 @@ #include #include #include +#include / { compatible = "root"; @@ -13,7 +14,7 @@ gpio-count = <49>; }; - i2c_internal { + i2c_internal: i2c0 { compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; @@ -23,7 +24,7 @@ pin-scl-pullup; }; - i2c_external { + i2c_external: i2c1 { compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; @@ -32,4 +33,14 @@ pin-sda-pullup; pin-scl-pullup; }; + + // P1 header + uart0 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <43>; + pin-rx = <44>; + pin-cts = ; + pin-rtx = ; + }; }; diff --git a/Devices/guition-jc8048w550c/Source/Configuration.cpp b/Devices/guition-jc8048w550c/Source/Configuration.cpp index af29c62a8..bb4eba0b5 100644 --- a/Devices/guition-jc8048w550c/Source/Configuration.cpp +++ b/Devices/guition-jc8048w550c/Source/Configuration.cpp @@ -45,31 +45,5 @@ extern const Configuration hardwareConfiguration = { .isMutable = false, .lock = nullptr } - }, - .uart { - //P4 header, JST SH 1.0, GND / 3.3V / IO17 / IO18 - uart::Configuration { - .name = "UART1", - .port = UART_NUM_1, - .rxPin = GPIO_NUM_17, - .txPin = GPIO_NUM_18, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 9600, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } - } } }; diff --git a/Devices/guition-jc8048w550c/guition,jc8048w550c.dts b/Devices/guition-jc8048w550c/guition,jc8048w550c.dts index f253f164d..87b49ea0c 100644 --- a/Devices/guition-jc8048w550c/guition,jc8048w550c.dts +++ b/Devices/guition-jc8048w550c/guition,jc8048w550c.dts @@ -3,6 +3,7 @@ #include #include #include +#include / { compatible = "root"; @@ -13,7 +14,7 @@ gpio-count = <49>; }; - i2c_internal { + i2c_internal: i2c0 { compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; @@ -23,7 +24,7 @@ pin-scl-pullup; }; - i2c_external { + i2c_external: i2c1 { compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; @@ -32,4 +33,13 @@ pin-sda-pullup; pin-scl-pullup; }; + + uart1 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <18>; + pin-rx = <17>; + pin-cts = ; + pin-rtx = ; + }; }; diff --git a/Devices/lilygo-tdeck/Source/Init.cpp b/Devices/lilygo-tdeck/Source/Init.cpp index b0635dbe5..6604afd33 100644 --- a/Devices/lilygo-tdeck/Source/Init.cpp +++ b/Devices/lilygo-tdeck/Source/Init.cpp @@ -58,7 +58,7 @@ bool initBoot() { std::vector gps_configurations; gps_service->getGpsConfigurations(gps_configurations); if (gps_configurations.empty()) { - if (gps_service->addGpsConfiguration(tt::hal::gps::GpsConfiguration {.uartName = "uart0", .baudRate = 38400, .model = tt::hal::gps::GpsModel::UBLOX10})) { + if (gps_service->addGpsConfiguration(tt::hal::gps::GpsConfiguration {.uartName = "uart1", .baudRate = 38400, .model = tt::hal::gps::GpsModel::UBLOX10})) { LOGGER.info("Configured internal GPS"); } else { LOGGER.error("Failed to configure internal GPS"); diff --git a/Devices/lilygo-tdeck/lilygo,tdeck.dts b/Devices/lilygo-tdeck/lilygo,tdeck.dts index 6d59a9aab..f1929eaaa 100644 --- a/Devices/lilygo-tdeck/lilygo,tdeck.dts +++ b/Devices/lilygo-tdeck/lilygo,tdeck.dts @@ -42,7 +42,7 @@ pin-mclk = ; }; - uart0 { + uart1 { compatible = "espressif,esp32-uart"; port = ; pin-tx = <43>; diff --git a/Devices/lilygo-tdongle-s3/Source/Configuration.cpp b/Devices/lilygo-tdongle-s3/Source/Configuration.cpp index be584bd9a..310b321c1 100644 --- a/Devices/lilygo-tdongle-s3/Source/Configuration.cpp +++ b/Devices/lilygo-tdongle-s3/Source/Configuration.cpp @@ -44,30 +44,5 @@ extern const Configuration hardwareConfiguration = { .isMutable = false, .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display }, - }, - .uart { - uart::Configuration { - .name = "STEMMA QT", - .port = UART_NUM_1, - .rxPin = GPIO_NUM_44, - .txPin = GPIO_NUM_43, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 38400, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } - } } }; diff --git a/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts b/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts index de2eb43ea..288980602 100644 --- a/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts +++ b/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts @@ -3,6 +3,7 @@ #include #include #include +#include / { compatible = "root"; @@ -22,4 +23,13 @@ pin-sda-pullup; pin-scl-pullup; }; + + stemma_qt: uart1 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <43>; + pin-rx = <44>; + pin-cts = ; + pin-rtx = ; + }; }; diff --git a/Devices/lilygo-tlora-pager/Source/Configuration.cpp b/Devices/lilygo-tlora-pager/Source/Configuration.cpp index f34d5ade4..55d1f135d 100644 --- a/Devices/lilygo-tlora-pager/Source/Configuration.cpp +++ b/Devices/lilygo-tlora-pager/Source/Configuration.cpp @@ -60,28 +60,5 @@ extern const Configuration hardwareConfiguration = { .initMode = spi::InitMode::ByTactility, .isMutable = false, .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display - }}, - .uart {uart::Configuration { - .name = "Internal", - .port = UART_NUM_1, - .rxPin = GPIO_NUM_4, - .txPin = GPIO_NUM_12, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 38400, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } }} }; diff --git a/Devices/lilygo-tlora-pager/Source/Init.cpp b/Devices/lilygo-tlora-pager/Source/Init.cpp index 3a98576f7..f02a8ea86 100644 --- a/Devices/lilygo-tlora-pager/Source/Init.cpp +++ b/Devices/lilygo-tlora-pager/Source/Init.cpp @@ -41,7 +41,7 @@ bool tpagerInit() { gps_service->getGpsConfigurations(gps_configurations); if (gps_configurations.empty()) { if (gps_service->addGpsConfiguration(tt::hal::gps::GpsConfiguration { - .uartName = "Internal", + .uartName = "uart0", .baudRate = 38400, .model = tt::hal::gps::GpsModel::UBLOX10 })) { diff --git a/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts b/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts index 92d56abd7..da8f7fc2f 100644 --- a/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts +++ b/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts @@ -4,6 +4,7 @@ #include #include #include +#include // Reference: https://wiki.lilygo.cc/get_started/en/LoRa_GPS/T-LoraPager/T-LoraPager.html#Pin-Overview / { @@ -34,4 +35,22 @@ pin-data-in = <17>; pin-mclk = <10>; }; + + uart_internal: uart0 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <12>; + pin-rx = <4>; + pin-cts = ; + pin-rtx = ; + }; + + uart_external: uart1 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <43>; + pin-rx = <44>; + pin-cts = ; + pin-rtx = ; + }; }; diff --git a/Devices/m5stack-cardputer-adv/Source/Configuration.cpp b/Devices/m5stack-cardputer-adv/Source/Configuration.cpp index f2382e362..fb7fcad82 100644 --- a/Devices/m5stack-cardputer-adv/Source/Configuration.cpp +++ b/Devices/m5stack-cardputer-adv/Source/Configuration.cpp @@ -79,31 +79,5 @@ extern const Configuration hardwareConfiguration = { .isMutable = false, .lock = nullptr }, - - }, - .uart { - uart::Configuration { - .name = "Port A", - .port = UART_NUM_1, - .rxPin = GPIO_NUM_2, - .txPin = GPIO_NUM_1, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 115200, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } - } } }; diff --git a/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts b/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts index ab968b529..d1e72e5c7 100644 --- a/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts +++ b/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts @@ -4,6 +4,7 @@ #include #include #include +#include // Reference: https://docs.m5stack.com/en/core/Cardputer-Adv / { @@ -45,4 +46,13 @@ pin-data-in = <46>; pin-mclk = ; }; + + uart_port_a: uart1 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <1>; + pin-rx = <2>; + pin-cts = ; + pin-rtx = ; + }; }; diff --git a/Devices/m5stack-cardputer/Source/Configuration.cpp b/Devices/m5stack-cardputer/Source/Configuration.cpp index 818975a35..76a8219d4 100644 --- a/Devices/m5stack-cardputer/Source/Configuration.cpp +++ b/Devices/m5stack-cardputer/Source/Configuration.cpp @@ -78,30 +78,5 @@ extern const Configuration hardwareConfiguration = { .lock = nullptr }, - }, - .uart { - uart::Configuration { - .name = "Port A", - .port = UART_NUM_1, - .rxPin = GPIO_NUM_2, - .txPin = GPIO_NUM_1, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 115200, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } - } } }; diff --git a/Devices/m5stack-cardputer/m5stack,cardputer.dts b/Devices/m5stack-cardputer/m5stack,cardputer.dts index 6095eb653..1bc763093 100644 --- a/Devices/m5stack-cardputer/m5stack,cardputer.dts +++ b/Devices/m5stack-cardputer/m5stack,cardputer.dts @@ -4,6 +4,7 @@ #include #include #include +#include // Reference: https://docs.m5stack.com/en/core/Cardputer / { @@ -36,4 +37,13 @@ pin-data-in = <46>; pin-mclk = ; }; + + uart_port_a: uart1 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <1>; + pin-rx = <2>; + pin-cts = ; + pin-rtx = ; + }; }; diff --git a/Devices/m5stack-core2/Source/Configuration.cpp b/Devices/m5stack-core2/Source/Configuration.cpp index 5ffdc6735..fb664d45c 100644 --- a/Devices/m5stack-core2/Source/Configuration.cpp +++ b/Devices/m5stack-core2/Source/Configuration.cpp @@ -46,30 +46,5 @@ extern const Configuration hardwareConfiguration = { .isMutable = false, .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display } - }, - .uart { - uart::Configuration { - .name = "Port A", // Grove - .port = UART_NUM_1, - .rxPin = GPIO_NUM_32, - .txPin = GPIO_NUM_33, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 115200, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } - }, } }; diff --git a/Devices/m5stack-core2/m5stack,core2.dts b/Devices/m5stack-core2/m5stack,core2.dts index 089b6fde5..800c3ae27 100644 --- a/Devices/m5stack-core2/m5stack,core2.dts +++ b/Devices/m5stack-core2/m5stack,core2.dts @@ -4,6 +4,7 @@ #include #include #include +#include // Reference: https://docs.m5stack.com/en/core/Core2 / { @@ -46,4 +47,13 @@ pin-data-in = <34>; pin-mclk = ; }; + + uart_port_a: uart1 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <33>; + pin-rx = <32>; + pin-cts = ; + pin-rtx = ; + }; }; diff --git a/Devices/m5stack-cores3/Source/Configuration.cpp b/Devices/m5stack-cores3/Source/Configuration.cpp index 331923d6f..199ad4161 100644 --- a/Devices/m5stack-cores3/Source/Configuration.cpp +++ b/Devices/m5stack-cores3/Source/Configuration.cpp @@ -46,76 +46,5 @@ extern const Configuration hardwareConfiguration = { .isMutable = false, .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display } - }, - .uart { - uart::Configuration { - .name = "Port A", - .port = UART_NUM_1, - .rxPin = GPIO_NUM_2, - .txPin = GPIO_NUM_1, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 115200, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } - }, - uart::Configuration { - .name = "Port B", - .port = UART_NUM_1, - .rxPin = GPIO_NUM_9, - .txPin = GPIO_NUM_8, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 115200, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } - }, - uart::Configuration { - .name = "Port C", - .port = UART_NUM_1, - .rxPin = GPIO_NUM_18, - .txPin = GPIO_NUM_17, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 115200, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } - } } }; diff --git a/Devices/m5stack-cores3/m5stack,cores3.dts b/Devices/m5stack-cores3/m5stack,cores3.dts index a35822c25..3fc9f3645 100644 --- a/Devices/m5stack-cores3/m5stack,cores3.dts +++ b/Devices/m5stack-cores3/m5stack,cores3.dts @@ -4,6 +4,7 @@ #include #include #include +#include // Reference: https://docs.m5stack.com/en/core/CoreS3 / { @@ -68,4 +69,13 @@ pin-data-in = <14>; pin-mclk = <0>; }; + + uart_port_a: uart1 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <1>; + pin-rx = <2>; + pin-cts = ; + pin-rtx = ; + }; }; diff --git a/Devices/m5stack-stickc-plus/Source/Configuration.cpp b/Devices/m5stack-stickc-plus/Source/Configuration.cpp index abd858337..18c8ba49f 100644 --- a/Devices/m5stack-stickc-plus/Source/Configuration.cpp +++ b/Devices/m5stack-stickc-plus/Source/Configuration.cpp @@ -52,30 +52,5 @@ extern const Configuration hardwareConfiguration = { .isMutable = false, .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display } - }, - .uart { - uart::Configuration { - .name = "Grove", - .port = UART_NUM_1, - .rxPin = GPIO_NUM_32, - .txPin = GPIO_NUM_33, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 115200, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } - }, } }; diff --git a/Devices/m5stack-stickc-plus/m5stack,stickc-plus.dts b/Devices/m5stack-stickc-plus/m5stack,stickc-plus.dts index 762794ba7..1395138a0 100644 --- a/Devices/m5stack-stickc-plus/m5stack,stickc-plus.dts +++ b/Devices/m5stack-stickc-plus/m5stack,stickc-plus.dts @@ -3,6 +3,7 @@ #include #include #include +#include / { compatible = "root"; @@ -32,4 +33,13 @@ pin-sda-pullup; pin-scl-pullup; }; + + uart_grove: uart1 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <33>; + pin-rx = <32>; + pin-cts = ; + pin-rtx = ; + }; }; diff --git a/Devices/m5stack-stickc-plus2/Source/Configuration.cpp b/Devices/m5stack-stickc-plus2/Source/Configuration.cpp index d6c907ae8..b266e2f2c 100644 --- a/Devices/m5stack-stickc-plus2/Source/Configuration.cpp +++ b/Devices/m5stack-stickc-plus2/Source/Configuration.cpp @@ -54,30 +54,5 @@ extern const Configuration hardwareConfiguration = { .isMutable = false, .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display } - }, - .uart { - uart::Configuration { - .name = "Grove", - .port = UART_NUM_1, - .rxPin = GPIO_NUM_32, - .txPin = GPIO_NUM_33, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 115200, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } - }, } }; diff --git a/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts b/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts index 162a18e54..61857f0a0 100644 --- a/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts +++ b/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts @@ -2,6 +2,7 @@ #include #include #include +#include / { compatible = "root"; @@ -31,4 +32,13 @@ pin-sda-pullup; pin-scl-pullup; }; + + uart_grove: uart1 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <33>; + pin-rx = <32>; + pin-cts = ; + pin-rtx = ; + }; }; diff --git a/Devices/waveshare-esp32-s3-geek/Source/Configuration.cpp b/Devices/waveshare-esp32-s3-geek/Source/Configuration.cpp index bb6317334..ef39aac17 100644 --- a/Devices/waveshare-esp32-s3-geek/Source/Configuration.cpp +++ b/Devices/waveshare-esp32-s3-geek/Source/Configuration.cpp @@ -49,31 +49,5 @@ extern const Configuration hardwareConfiguration = { .isMutable = false, .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display } - }, - .uart { - //UART Header - uart::Configuration { - .name = "UART0", - .port = UART_NUM_0, - .rxPin = GPIO_NUM_44, - .txPin = GPIO_NUM_43, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 115200, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } - } } }; \ No newline at end of file diff --git a/Devices/waveshare-esp32-s3-geek/waveshare,esp32-s3-geek.dts b/Devices/waveshare-esp32-s3-geek/waveshare,esp32-s3-geek.dts index 2654dfc36..3f2399a12 100644 --- a/Devices/waveshare-esp32-s3-geek/waveshare,esp32-s3-geek.dts +++ b/Devices/waveshare-esp32-s3-geek/waveshare,esp32-s3-geek.dts @@ -3,6 +3,7 @@ #include #include #include +#include / { compatible = "root"; @@ -22,4 +23,13 @@ pin-sda-pullup; pin-scl-pullup; }; + + uart0 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <43>; + pin-rx = <44>; + pin-cts = ; + pin-rtx = ; + }; }; diff --git a/Devices/waveshare-s3-touch-lcd-147/Source/Configuration.cpp b/Devices/waveshare-s3-touch-lcd-147/Source/Configuration.cpp index 164cb66cf..ec73e5023 100644 --- a/Devices/waveshare-s3-touch-lcd-147/Source/Configuration.cpp +++ b/Devices/waveshare-s3-touch-lcd-147/Source/Configuration.cpp @@ -68,6 +68,5 @@ extern const Configuration hardwareConfiguration = { .isMutable = false, .lock = nullptr } - }, - .uart {} + } }; diff --git a/Devices/waveshare-s3-touch-lcd-43/Source/Configuration.cpp b/Devices/waveshare-s3-touch-lcd-43/Source/Configuration.cpp index 2d1335770..f0b3d53e7 100644 --- a/Devices/waveshare-s3-touch-lcd-43/Source/Configuration.cpp +++ b/Devices/waveshare-s3-touch-lcd-43/Source/Configuration.cpp @@ -39,31 +39,5 @@ extern const Configuration hardwareConfiguration = { .isMutable = false, .lock = nullptr } - }, - .uart { - // "UART1" - uart::Configuration { - .name = "UART1", - .port = UART_NUM_1, - .rxPin = GPIO_NUM_44, - .txPin = GPIO_NUM_43, - .rtsPin = GPIO_NUM_NC, - .ctsPin = GPIO_NUM_NC, - .rxBufferSize = 1024, - .txBufferSize = 1024, - .config = { - .baud_rate = 115200, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0, - } - } - } } }; diff --git a/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts b/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts index 4c2826f0d..9ebec09a8 100644 --- a/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts +++ b/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts @@ -3,6 +3,7 @@ #include #include #include +#include / { compatible = "root"; @@ -22,4 +23,13 @@ pin-sda-pullup; pin-scl-pullup; }; + + uart0 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <43>; + pin-rx = <44>; + pin-cts = ; + pin-rtx = ; + }; }; From 5bdbdd6d0c40177c57d48f7f558fa4fc741d8180 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 7 Feb 2026 17:52:35 +0100 Subject: [PATCH 13/19] Fixes --- Devices/cyd-2432s028r/cyd,2432s028r.dts | 2 +- Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts | 2 +- Devices/cyd-8048s043c/cyd,8048s043c.dts | 2 +- .../elecrow,crowpanel-advance-28.dts | 4 ++-- .../elecrow,crowpanel-advance-35.dts | 4 ++-- .../elecrow,crowpanel-advance-50.dts | 4 ++-- .../elecrow,crowpanel-basic-28.dts | 2 +- .../elecrow,crowpanel-basic-35.dts | 2 +- .../elecrow,crowpanel-basic-50.dts | 2 +- .../guition,jc2432w328c.dts | 2 +- .../guition,jc3248w535c.dts | 2 +- .../guition,jc8048w550c.dts | 2 +- Devices/lilygo-tdeck/lilygo,tdeck.dts | 2 +- .../lilygo-tdongle-s3/lilygo,tdongle-s3.dts | 2 +- .../lilygo-tlora-pager/lilygo,tlora-pager.dts | 4 ++-- .../m5stack,cardputer-adv.dts | 2 +- .../m5stack-cardputer/m5stack,cardputer.dts | 2 +- Devices/m5stack-core2/m5stack,core2.dts | 2 +- Devices/m5stack-cores3/m5stack,cores3.dts | 2 +- .../m5stack-papers3/Source/Configuration.cpp | 1 + .../m5stack,stickc-plus.dts | 2 +- .../m5stack,stickc-plus2.dts | 2 +- Devices/simulator/Source/Simulator.cpp | 12 +----------- .../waveshare,esp32-s3-geek.dts | 2 +- .../waveshare,s3-touch-lcd-43.dts | 2 +- .../Source/drivers/esp32_i2c.cpp | 12 ++++++------ .../Source/drivers/esp32_i2s.cpp | 12 ++++++------ .../Source/drivers/esp32_spi.cpp | 19 ++++++++++--------- .../Source/drivers/esp32_uart.cpp | 2 +- Tactility/Source/hal/gps/GpsDevice.cpp | 2 +- 30 files changed, 53 insertions(+), 61 deletions(-) diff --git a/Devices/cyd-2432s028r/cyd,2432s028r.dts b/Devices/cyd-2432s028r/cyd,2432s028r.dts index 6bc797bdc..177e55ec3 100644 --- a/Devices/cyd-2432s028r/cyd,2432s028r.dts +++ b/Devices/cyd-2432s028r/cyd,2432s028r.dts @@ -28,6 +28,6 @@ pin-tx = <3>; pin-rx = <1>; pin-cts = ; - pin-rtx = ; + pin-rts = ; }; }; diff --git a/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts b/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts index 159334a9d..d956bcfc3 100644 --- a/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts +++ b/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts @@ -28,6 +28,6 @@ pin-tx = <3>; pin-rx = <1>; pin-cts = ; - pin-rtx = ; + pin-rts = ; }; }; diff --git a/Devices/cyd-8048s043c/cyd,8048s043c.dts b/Devices/cyd-8048s043c/cyd,8048s043c.dts index 4cde60eb4..a952c4a40 100644 --- a/Devices/cyd-8048s043c/cyd,8048s043c.dts +++ b/Devices/cyd-8048s043c/cyd,8048s043c.dts @@ -38,6 +38,6 @@ pin-tx = <18>; pin-rx = <17>; pin-cts = ; - pin-rtx = ; + pin-rts = ; }; }; diff --git a/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts b/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts index 54682b82b..9e729f0a5 100644 --- a/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts +++ b/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts @@ -30,7 +30,7 @@ pin-tx = <43>; pin-rx = <44>; pin-cts = ; - pin-rtx = ; + pin-rts = ; }; uart1 { @@ -39,6 +39,6 @@ pin-tx = <17>; pin-rx = <18>; pin-cts = ; - pin-rtx = ; + pin-rts = ; }; }; diff --git a/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts b/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts index 6ff37fafe..ba5260fad 100644 --- a/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts +++ b/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts @@ -30,7 +30,7 @@ pin-tx = <43>; pin-rx = <44>; pin-cts = ; - pin-rtx = ; + pin-rts = ; }; uart1 { @@ -39,6 +39,6 @@ pin-tx = <17>; pin-rx = <18>; pin-cts = ; - pin-rtx = ; + pin-rts = ; }; }; diff --git a/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts b/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts index 6d4c4032d..ef5932566 100644 --- a/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts +++ b/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts @@ -30,7 +30,7 @@ pin-tx = <43>; pin-rx = <44>; pin-cts = ; - pin-rtx = ; + pin-rts = ; }; uart1 { @@ -39,6 +39,6 @@ pin-tx = <20>; pin-rx = <19>; pin-cts = ; - pin-rtx = ; + pin-rts = ; }; }; diff --git a/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts b/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts index 2aa30d24f..5b60dbab6 100644 --- a/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts +++ b/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts @@ -30,6 +30,6 @@ pin-tx = <17>; pin-rx = <16>; pin-cts = ; - pin-rtx = ; + pin-rts = ; }; }; diff --git a/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts b/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts index 4353a338f..1978876e6 100644 --- a/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts +++ b/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts @@ -30,6 +30,6 @@ pin-tx = <1>; pin-rx = <3>; pin-cts = ; - pin-rtx = ; + pin-rts = ; }; }; diff --git a/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts b/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts index 65b9bc864..43493e3a7 100644 --- a/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts +++ b/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts @@ -30,6 +30,6 @@ pin-tx = <43>; pin-rx = <44>; pin-cts = ; - pin-rtx = ; + pin-rts = ; }; }; diff --git a/Devices/guition-jc2432w328c/guition,jc2432w328c.dts b/Devices/guition-jc2432w328c/guition,jc2432w328c.dts index 509011754..24c50b625 100644 --- a/Devices/guition-jc2432w328c/guition,jc2432w328c.dts +++ b/Devices/guition-jc2432w328c/guition,jc2432w328c.dts @@ -38,6 +38,6 @@ pin-tx = <22>; pin-rx = <21>; pin-cts = ; - pin-rtx = ; + pin-rts = ; }; }; diff --git a/Devices/guition-jc3248w535c/guition,jc3248w535c.dts b/Devices/guition-jc3248w535c/guition,jc3248w535c.dts index c6319faaa..326df34c2 100644 --- a/Devices/guition-jc3248w535c/guition,jc3248w535c.dts +++ b/Devices/guition-jc3248w535c/guition,jc3248w535c.dts @@ -41,6 +41,6 @@ pin-tx = <43>; pin-rx = <44>; pin-cts = ; - pin-rtx = ; + pin-rts = ; }; }; diff --git a/Devices/guition-jc8048w550c/guition,jc8048w550c.dts b/Devices/guition-jc8048w550c/guition,jc8048w550c.dts index 87b49ea0c..b0514a676 100644 --- a/Devices/guition-jc8048w550c/guition,jc8048w550c.dts +++ b/Devices/guition-jc8048w550c/guition,jc8048w550c.dts @@ -40,6 +40,6 @@ pin-tx = <18>; pin-rx = <17>; pin-cts = ; - pin-rtx = ; + pin-rts = ; }; }; diff --git a/Devices/lilygo-tdeck/lilygo,tdeck.dts b/Devices/lilygo-tdeck/lilygo,tdeck.dts index f1929eaaa..fd8c22b9f 100644 --- a/Devices/lilygo-tdeck/lilygo,tdeck.dts +++ b/Devices/lilygo-tdeck/lilygo,tdeck.dts @@ -48,6 +48,6 @@ pin-tx = <43>; pin-rx = <44>; pin-cts = ; - pin-rtx = ; + pin-rts = ; }; }; diff --git a/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts b/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts index 288980602..bc5b5b341 100644 --- a/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts +++ b/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts @@ -30,6 +30,6 @@ pin-tx = <43>; pin-rx = <44>; pin-cts = ; - pin-rtx = ; + pin-rts = ; }; }; diff --git a/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts b/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts index da8f7fc2f..69bcfcad6 100644 --- a/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts +++ b/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts @@ -42,7 +42,7 @@ pin-tx = <12>; pin-rx = <4>; pin-cts = ; - pin-rtx = ; + pin-rts = ; }; uart_external: uart1 { @@ -51,6 +51,6 @@ pin-tx = <43>; pin-rx = <44>; pin-cts = ; - pin-rtx = ; + pin-rts = ; }; }; diff --git a/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts b/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts index d1e72e5c7..b616f418b 100644 --- a/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts +++ b/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts @@ -53,6 +53,6 @@ pin-tx = <1>; pin-rx = <2>; pin-cts = ; - pin-rtx = ; + pin-rts = ; }; }; diff --git a/Devices/m5stack-cardputer/m5stack,cardputer.dts b/Devices/m5stack-cardputer/m5stack,cardputer.dts index 1bc763093..1eb50b041 100644 --- a/Devices/m5stack-cardputer/m5stack,cardputer.dts +++ b/Devices/m5stack-cardputer/m5stack,cardputer.dts @@ -44,6 +44,6 @@ pin-tx = <1>; pin-rx = <2>; pin-cts = ; - pin-rtx = ; + pin-rts = ; }; }; diff --git a/Devices/m5stack-core2/m5stack,core2.dts b/Devices/m5stack-core2/m5stack,core2.dts index 800c3ae27..f8e1b6a6a 100644 --- a/Devices/m5stack-core2/m5stack,core2.dts +++ b/Devices/m5stack-core2/m5stack,core2.dts @@ -54,6 +54,6 @@ pin-tx = <33>; pin-rx = <32>; pin-cts = ; - pin-rtx = ; + pin-rts = ; }; }; diff --git a/Devices/m5stack-cores3/m5stack,cores3.dts b/Devices/m5stack-cores3/m5stack,cores3.dts index 3fc9f3645..5cc2d785b 100644 --- a/Devices/m5stack-cores3/m5stack,cores3.dts +++ b/Devices/m5stack-cores3/m5stack,cores3.dts @@ -76,6 +76,6 @@ pin-tx = <1>; pin-rx = <2>; pin-cts = ; - pin-rtx = ; + pin-rts = ; }; }; diff --git a/Devices/m5stack-papers3/Source/Configuration.cpp b/Devices/m5stack-papers3/Source/Configuration.cpp index 922de9207..b97319637 100644 --- a/Devices/m5stack-papers3/Source/Configuration.cpp +++ b/Devices/m5stack-papers3/Source/Configuration.cpp @@ -1,5 +1,6 @@ #include "devices/Display.h" #include "devices/SdCard.h" +#include #include #include diff --git a/Devices/m5stack-stickc-plus/m5stack,stickc-plus.dts b/Devices/m5stack-stickc-plus/m5stack,stickc-plus.dts index 1395138a0..2b3c57887 100644 --- a/Devices/m5stack-stickc-plus/m5stack,stickc-plus.dts +++ b/Devices/m5stack-stickc-plus/m5stack,stickc-plus.dts @@ -40,6 +40,6 @@ pin-tx = <33>; pin-rx = <32>; pin-cts = ; - pin-rtx = ; + pin-rts = ; }; }; diff --git a/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts b/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts index 61857f0a0..83f936a11 100644 --- a/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts +++ b/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts @@ -39,6 +39,6 @@ pin-tx = <33>; pin-rx = <32>; pin-cts = ; - pin-rtx = ; + pin-rts = ; }; }; diff --git a/Devices/simulator/Source/Simulator.cpp b/Devices/simulator/Source/Simulator.cpp index 9903ef6ae..b60d84566 100644 --- a/Devices/simulator/Source/Simulator.cpp +++ b/Devices/simulator/Source/Simulator.cpp @@ -21,15 +21,5 @@ static std::vector> createDevices() { extern const Configuration hardwareConfiguration = { .initBoot = nullptr, - .createDevices = createDevices, - .uart = { - uart::Configuration { - .name = "/dev/ttyUSB0", - .baudRate = 115200 - }, - uart::Configuration { - .name = "/dev/ttyACM0", - .baudRate = 115200 - } - } + .createDevices = createDevices }; diff --git a/Devices/waveshare-esp32-s3-geek/waveshare,esp32-s3-geek.dts b/Devices/waveshare-esp32-s3-geek/waveshare,esp32-s3-geek.dts index 3f2399a12..963dba0f4 100644 --- a/Devices/waveshare-esp32-s3-geek/waveshare,esp32-s3-geek.dts +++ b/Devices/waveshare-esp32-s3-geek/waveshare,esp32-s3-geek.dts @@ -30,6 +30,6 @@ pin-tx = <43>; pin-rx = <44>; pin-cts = ; - pin-rtx = ; + pin-rts = ; }; }; diff --git a/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts b/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts index 9ebec09a8..2c2fc2a64 100644 --- a/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts +++ b/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts @@ -30,6 +30,6 @@ pin-tx = <43>; pin-rx = <44>; pin-cts = ; - pin-rtx = ; + pin-rts = ; }; }; diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_i2c.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_i2c.cpp index b3827dc2a..36186f379 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_i2c.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_i2c.cpp @@ -12,20 +12,20 @@ #define TAG "esp32_i2c" #define ACK_CHECK_EN 1 -struct InternalData { +struct Esp32SpiInternal { Mutex mutex { 0 }; - InternalData() { + Esp32SpiInternal() { mutex_construct(&mutex); } - ~InternalData() { + ~Esp32SpiInternal() { mutex_destruct(&mutex); } }; #define GET_CONFIG(device) ((Esp32I2cConfig*)device->config) -#define GET_DATA(device) ((InternalData*)device_get_driver_data(device)) +#define GET_DATA(device) ((Esp32SpiInternal*)device_get_driver_data(device)) #define lock(data) mutex_lock(&data->mutex); #define unlock(data) mutex_unlock(&data->mutex); @@ -172,14 +172,14 @@ static error_t start(Device* device) { LOG_E(TAG, "Failed to install driver at port %d: %s", static_cast(dts_config->port), esp_err_to_name(error)); return ERROR_RESOURCE; } - auto* data = new InternalData(); + auto* data = new Esp32SpiInternal(); device_set_driver_data(device, data); return ERROR_NONE; } static error_t stop(Device* device) { ESP_LOGI(TAG, "stop %s", device->name); - auto* driver_data = static_cast(device_get_driver_data(device)); + auto* driver_data = static_cast(device_get_driver_data(device)); i2c_port_t port = GET_CONFIG(device)->port; esp_err_t result = i2c_driver_delete(port); diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_i2s.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_i2s.cpp index ec012e65b..7998faecb 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_i2s.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_i2s.cpp @@ -14,31 +14,31 @@ #define TAG "esp32_i2s" -struct InternalData { +struct Esp32SpiInternal { Mutex mutex {}; i2s_chan_handle_t tx_handle = nullptr; i2s_chan_handle_t rx_handle = nullptr; I2sConfig config {}; bool config_set = false; - InternalData() { + Esp32SpiInternal() { mutex_construct(&mutex); } - ~InternalData() { + ~Esp32SpiInternal() { mutex_destruct(&mutex); } }; #define GET_CONFIG(device) ((Esp32I2sConfig*)device->config) -#define GET_DATA(device) ((InternalData*)device_get_driver_data(device)) +#define GET_DATA(device) ((Esp32SpiInternal*)device_get_driver_data(device)) #define lock(data) mutex_lock(&data->mutex); #define unlock(data) mutex_unlock(&data->mutex); extern "C" { -static error_t cleanup_channel_handles(InternalData* driver_data) { +static error_t cleanup_channel_handles(Esp32SpiInternal* driver_data) { // TODO: error handling of i2ss functions if (driver_data->tx_handle) { i2s_channel_disable(driver_data->tx_handle); @@ -188,7 +188,7 @@ static error_t get_config(Device* device, struct I2sConfig* config) { static error_t start(Device* device) { ESP_LOGI(TAG, "start %s", device->name); - auto* data = new(std::nothrow) InternalData(); + auto* data = new(std::nothrow) Esp32SpiInternal(); if (!data) return ERROR_OUT_OF_MEMORY; device_set_driver_data(device, data); diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp index 261cb751e..920691501 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp @@ -11,19 +11,19 @@ #define TAG "esp32_spi" #define GET_CONFIG(device) ((const struct Esp32SpiConfig*)device->config) -#define GET_DATA(device) ((struct InternalData*)device_get_driver_data(device)) +#define GET_DATA(device) ((struct Esp32SpiInternal*)device_get_driver_data(device)) extern "C" { -struct InternalData { +struct Esp32SpiInternal { Mutex mutex; bool initialized = false; - InternalData() { + Esp32SpiInternal() { mutex_construct(&mutex); } - ~InternalData() { + ~Esp32SpiInternal() { mutex_destruct(&mutex); } }; @@ -50,18 +50,17 @@ static error_t unlock(Device* device) { static error_t start(Device* device) { ESP_LOGI(TAG, "start %s", device->name); - auto* data = new(std::nothrow) InternalData(); + auto* data = new(std::nothrow) Esp32SpiInternal(); if (!data) return ERROR_OUT_OF_MEMORY; data->initialized = false; device_set_driver_data(device, data); - auto* driver_data = GET_DATA(device); auto* dts_config = GET_CONFIG(device); - if (driver_data->initialized) { + if (data->initialized) { spi_bus_free(dts_config->host); - driver_data->initialized = false; + data->initialized = false; } spi_bus_config_t buscfg = { @@ -79,11 +78,13 @@ static error_t start(Device* device) { esp_err_t ret = spi_bus_initialize(dts_config->host, &buscfg, SPI_DMA_CH_AUTO); if (ret != ESP_OK) { + delete data; + device_set_driver_data(device, nullptr); ESP_LOGE(TAG, "Failed to initialize SPI bus: %s", esp_err_to_name(ret)); return ERROR_RESOURCE; } - driver_data->initialized = true; + data->initialized = true; return ERROR_NONE; } diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp index bfc9a0333..f6b1234a0 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp @@ -172,7 +172,7 @@ static error_t get_available(Device* device, size_t* available_bytes) { lock(driver_data); if (!driver_data->is_open) { unlock(driver_data); - return -1; + return ERROR_INVALID_STATE; } esp_err_t err = uart_get_buffered_data_len(dts_config->port, available_bytes); diff --git a/Tactility/Source/hal/gps/GpsDevice.cpp b/Tactility/Source/hal/gps/GpsDevice.cpp index 3c2b6d343..10c964f59 100644 --- a/Tactility/Source/hal/gps/GpsDevice.cpp +++ b/Tactility/Source/hal/gps/GpsDevice.cpp @@ -33,7 +33,7 @@ int32_t GpsDevice::threadMain() { error_t error = uart_controller_set_config(uart, &uartConfig); if (error != ERROR_NONE) { - LOGGER.error("Failed to configure UART {}: {}", configuration.baudRate, configuration.uartName, error_to_string(error)); + LOGGER.error("Failed to configure UART {}: {}", configuration.uartName, error_to_string(error)); return -1; } From 01e42437f82f01f7c6ec2931d02efa9cffbc3cc5 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 7 Feb 2026 18:08:44 +0100 Subject: [PATCH 14/19] Fixes --- Devices/m5stack-tab5/Source/Configuration.cpp | 1 + .../waveshare,s3-touch-lcd-43.dts | 2 +- .../PlatformEsp32/Source/drivers/esp32_i2s.cpp | 12 ++++++------ .../PlatformEsp32/Source/drivers/esp32_spi.cpp | 14 ++++++++------ Tactility/Private/Tactility/hal/gps/Ublox.h | 7 ------- Tactility/Source/hal/gps/GpsInit.cpp | 3 ++- Tactility/Source/hal/gps/Ublox.cpp | 3 ++- TactilityKernel/Include/tactility/device.h | 2 +- 8 files changed, 21 insertions(+), 23 deletions(-) diff --git a/Devices/m5stack-tab5/Source/Configuration.cpp b/Devices/m5stack-tab5/Source/Configuration.cpp index f9016d56d..0bf8e45e1 100644 --- a/Devices/m5stack-tab5/Source/Configuration.cpp +++ b/Devices/m5stack-tab5/Source/Configuration.cpp @@ -1,5 +1,6 @@ #include "devices/Display.h" #include "devices/SdCard.h" +#include #include diff --git a/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts b/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts index 2c2fc2a64..21757ad14 100644 --- a/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts +++ b/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts @@ -24,7 +24,7 @@ pin-scl-pullup; }; - uart0 { + uart1 { compatible = "espressif,esp32-uart"; port = ; pin-tx = <43>; diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_i2s.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_i2s.cpp index 7998faecb..258f70634 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_i2s.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_i2s.cpp @@ -14,31 +14,31 @@ #define TAG "esp32_i2s" -struct Esp32SpiInternal { +struct Esp32I2sInternal { Mutex mutex {}; i2s_chan_handle_t tx_handle = nullptr; i2s_chan_handle_t rx_handle = nullptr; I2sConfig config {}; bool config_set = false; - Esp32SpiInternal() { + Esp32I2sInternal() { mutex_construct(&mutex); } - ~Esp32SpiInternal() { + ~Esp32I2sInternal() { mutex_destruct(&mutex); } }; #define GET_CONFIG(device) ((Esp32I2sConfig*)device->config) -#define GET_DATA(device) ((Esp32SpiInternal*)device_get_driver_data(device)) +#define GET_DATA(device) ((Esp32I2sInternal*)device_get_driver_data(device)) #define lock(data) mutex_lock(&data->mutex); #define unlock(data) mutex_unlock(&data->mutex); extern "C" { -static error_t cleanup_channel_handles(Esp32SpiInternal* driver_data) { +static error_t cleanup_channel_handles(Esp32I2sInternal* driver_data) { // TODO: error handling of i2ss functions if (driver_data->tx_handle) { i2s_channel_disable(driver_data->tx_handle); @@ -188,7 +188,7 @@ static error_t get_config(Device* device, struct I2sConfig* config) { static error_t start(Device* device) { ESP_LOGI(TAG, "start %s", device->name); - auto* data = new(std::nothrow) Esp32SpiInternal(); + auto* data = new(std::nothrow) Esp32I2sInternal(); if (!data) return ERROR_OUT_OF_MEMORY; device_set_driver_data(device, data); diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp index 920691501..c551b7e64 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp @@ -53,16 +53,14 @@ static error_t start(Device* device) { auto* data = new(std::nothrow) Esp32SpiInternal(); if (!data) return ERROR_OUT_OF_MEMORY; - data->initialized = false; + if (data->initialized) { + return ERROR_INVALID_STATE; + } + device_set_driver_data(device, data); auto* dts_config = GET_CONFIG(device); - if (data->initialized) { - spi_bus_free(dts_config->host); - data->initialized = false; - } - spi_bus_config_t buscfg = { .mosi_io_num = dts_config->pin_mosi, .miso_io_num = dts_config->pin_miso, @@ -73,7 +71,11 @@ static error_t start(Device* device) { .data5_io_num = GPIO_NUM_NC, .data6_io_num = GPIO_NUM_NC, .data7_io_num = GPIO_NUM_NC, + .data_io_default_level = false, .max_transfer_sz = dts_config->max_transfer_sz, + .flags = 0, + .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, + .intr_flags = 0 }; esp_err_t ret = spi_bus_initialize(dts_config->host, &buscfg, SPI_DMA_CH_AUTO); diff --git a/Tactility/Private/Tactility/hal/gps/Ublox.h b/Tactility/Private/Tactility/hal/gps/Ublox.h index 078778ca7..4ff86c9fd 100644 --- a/Tactility/Private/Tactility/hal/gps/Ublox.h +++ b/Tactility/Private/Tactility/hal/gps/Ublox.h @@ -14,13 +14,6 @@ void checksum(uint8_t* message, size_t length); // From https://github.com/meshtastic/firmware/blob/7648391f91f2b84e367ae2b38220b30936fb45b1/src/gps/GPS.cpp#L128 uint8_t makePacket(uint8_t classId, uint8_t messageId, const uint8_t* payload, uint8_t payloadSize, uint8_t* bufferOut); -template -inline void sendPacket(::Device* uart, uint8_t type, uint8_t id, uint8_t data[DataSize], const char* errorMessage, uint32_t timeout) { - static uint8_t buffer[250] = {0}; - size_t length = makePacket(type, id, data, DataSize, buffer); -// hal::uart::writeBytes(port, buffer, length); -} - GpsModel probe(::Device* uart); bool init(::Device* uart, GpsModel model); diff --git a/Tactility/Source/hal/gps/GpsInit.cpp b/Tactility/Source/hal/gps/GpsInit.cpp index 02f80efe1..7deeb7cb1 100644 --- a/Tactility/Source/hal/gps/GpsInit.cpp +++ b/Tactility/Source/hal/gps/GpsInit.cpp @@ -81,6 +81,7 @@ GpsResponse getACKCas(::Device* uart, uint8_t class_id, uint8_t msg_id, uint32_t uint32_t startTime = kernel::getMillis(); uint8_t buffer[CAS_ACK_NACK_MSG_SIZE] = {0}; uint8_t bufferPos = 0; + TickType_t waitTicks = pdMS_TO_TICKS(waitMillis); // CAS-ACK-(N)ACK structure // | H1 | H2 | Payload Len | cls | msg | Payload | Checksum (4) | @@ -89,7 +90,7 @@ GpsResponse getACKCas(::Device* uart, uint8_t class_id, uint8_t msg_id, uint32_t // ACK-NACK| 0xBA | 0xCE | 0x04 | 0x00 | 0x05 | 0x00 | 0xXX | 0xXX | 0x00 | 0x00 | 0xXX | 0xXX | 0xXX | 0xXX | // ACK-ACK | 0xBA | 0xCE | 0x04 | 0x00 | 0x05 | 0x01 | 0xXX | 0xXX | 0x00 | 0x00 | 0xXX | 0xXX | 0xXX | 0xXX | - while (kernel::getTicks() - startTime < waitMillis) { + while (kernel::getTicks() - startTime < waitTicks) { size_t available = 0; uart_controller_get_available(uart, &available); if (available > 0) { diff --git a/Tactility/Source/hal/gps/Ublox.cpp b/Tactility/Source/hal/gps/Ublox.cpp index 8f1ad83e1..88c12ac6d 100644 --- a/Tactility/Source/hal/gps/Ublox.cpp +++ b/Tactility/Source/hal/gps/Ublox.cpp @@ -64,6 +64,7 @@ GpsResponse getAck(::Device* uart, uint8_t class_id, uint8_t msg_id, uint32_t wa const uint8_t ackP[2] = {class_id, msg_id}; uint8_t buf[10] = {0xB5, 0x62, 0x05, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00}; uint32_t startTime = kernel::getMillis(); + TickType_t waitTicks = pdMS_TO_TICKS(waitMillis); const char frame_errors[] = "More than 100 frame errors"; int sCounter = 0; #ifdef GPS_DEBUG @@ -81,7 +82,7 @@ GpsResponse getAck(::Device* uart, uint8_t class_id, uint8_t msg_id, uint32_t wa buf[9] += buf[8]; } - while (kernel::getTicks() - startTime < waitMillis) { + while (kernel::getTicks() - startTime < waitTicks) { if (ack > 9) { #ifdef GPS_DEBUG LOGGER.info("Got ACK for class {:02X} message {:02X} in {}ms", class_id, msg_id, kernel::getMillis() - startTime); diff --git a/TactilityKernel/Include/tactility/device.h b/TactilityKernel/Include/tactility/device.h index d0b147917..1be4b4984 100644 --- a/TactilityKernel/Include/tactility/device.h +++ b/TactilityKernel/Include/tactility/device.h @@ -46,7 +46,7 @@ struct Device { /** * Holds a device pointer and a compatible string. * The device must not be constructed, added or started yet. - * This is used by the devicetree code generator and the application init sequence::. + * This is used by the devicetree code generator and the application init sequence. */ struct CompatibleDevice { struct Device* device; From 4d53d81dc77e03560a61115eb581a25b6afcaa7a Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 7 Feb 2026 18:44:01 +0100 Subject: [PATCH 15/19] Fixes --- Devices/cyd-2432s024c/Source/Configuration.cpp | 1 + Devices/cyd-2432s028r/Source/Configuration.cpp | 1 + Devices/cyd-2432s028rv3/Source/Configuration.cpp | 1 + Devices/cyd-2432s032c/Source/Configuration.cpp | 1 + Devices/cyd-4848s040c/Source/Configuration.cpp | 1 + Devices/cyd-8048s043c/Source/Configuration.cpp | 1 + Devices/cyd-e32r28t/Source/Configuration.cpp | 1 + Devices/cyd-e32r32p/Source/Configuration.cpp | 1 + Devices/elecrow-crowpanel-advance-28/Source/Configuration.cpp | 1 + Devices/elecrow-crowpanel-advance-35/Source/Configuration.cpp | 1 + Devices/elecrow-crowpanel-advance-50/Source/Configuration.cpp | 1 + Devices/elecrow-crowpanel-basic-28/Source/Configuration.cpp | 1 + Devices/elecrow-crowpanel-basic-35/Source/Configuration.cpp | 1 + Devices/elecrow-crowpanel-basic-50/Source/Configuration.cpp | 1 + Devices/guition-jc2432w328c/Source/Configuration.cpp | 1 + Devices/guition-jc3248w535c/Source/Configuration.cpp | 1 + Devices/guition-jc8048w550c/Source/Configuration.cpp | 1 + Devices/lilygo-tdeck/Source/Configuration.cpp | 1 + Devices/lilygo-tdisplay-s3/Source/Configuration.cpp | 1 + Devices/lilygo-tdisplay/Source/Configuration.cpp | 1 + Devices/lilygo-tdongle-s3/Source/Configuration.cpp | 1 + Devices/lilygo-tlora-pager/Source/Configuration.cpp | 1 + Devices/m5stack-cardputer-adv/Source/Configuration.cpp | 1 + Devices/m5stack-cardputer/Source/Configuration.cpp | 1 + Devices/m5stack-core2/Source/Configuration.cpp | 1 + Devices/m5stack-cores3/Source/Configuration.cpp | 2 +- Devices/m5stack-stickc-plus/Source/Configuration.cpp | 1 + Devices/m5stack-stickc-plus2/Source/Configuration.cpp | 1 + Devices/unphone/Source/Configuration.cpp | 1 + Devices/waveshare-esp32-s3-geek/Source/Configuration.cpp | 1 + Devices/waveshare-s3-lcd-13/Source/Configuration.cpp | 1 + Devices/waveshare-s3-touch-lcd-128/Source/Configuration.cpp | 1 + Devices/waveshare-s3-touch-lcd-147/Source/Configuration.cpp | 1 + Devices/waveshare-s3-touch-lcd-43/Source/Configuration.cpp | 1 + Devices/wireless-tag-wt32-sc01-plus/Source/Configuration.cpp | 1 + Tactility/Private/Tactility/hal/gps/Ublox.h | 2 +- Tactility/Source/hal/gps/Ublox.cpp | 2 +- 37 files changed, 37 insertions(+), 3 deletions(-) diff --git a/Devices/cyd-2432s024c/Source/Configuration.cpp b/Devices/cyd-2432s024c/Source/Configuration.cpp index 2b9ccad6e..fdb0ef5d4 100644 --- a/Devices/cyd-2432s024c/Source/Configuration.cpp +++ b/Devices/cyd-2432s024c/Source/Configuration.cpp @@ -1,5 +1,6 @@ #include "devices/Display.h" #include "devices/SdCard.h" +#include #include #include diff --git a/Devices/cyd-2432s028r/Source/Configuration.cpp b/Devices/cyd-2432s028r/Source/Configuration.cpp index 30856c74d..316446135 100644 --- a/Devices/cyd-2432s028r/Source/Configuration.cpp +++ b/Devices/cyd-2432s028r/Source/Configuration.cpp @@ -1,5 +1,6 @@ #include "devices/Display.h" #include "devices/SdCard.h" +#include #include #include diff --git a/Devices/cyd-2432s028rv3/Source/Configuration.cpp b/Devices/cyd-2432s028rv3/Source/Configuration.cpp index 30856c74d..316446135 100644 --- a/Devices/cyd-2432s028rv3/Source/Configuration.cpp +++ b/Devices/cyd-2432s028rv3/Source/Configuration.cpp @@ -1,5 +1,6 @@ #include "devices/Display.h" #include "devices/SdCard.h" +#include #include #include diff --git a/Devices/cyd-2432s032c/Source/Configuration.cpp b/Devices/cyd-2432s032c/Source/Configuration.cpp index 75f46e608..2b1478e16 100644 --- a/Devices/cyd-2432s032c/Source/Configuration.cpp +++ b/Devices/cyd-2432s032c/Source/Configuration.cpp @@ -1,5 +1,6 @@ #include "devices/Display.h" #include "devices/SdCard.h" +#include #include #include diff --git a/Devices/cyd-4848s040c/Source/Configuration.cpp b/Devices/cyd-4848s040c/Source/Configuration.cpp index 42d914fd9..e8500904e 100644 --- a/Devices/cyd-4848s040c/Source/Configuration.cpp +++ b/Devices/cyd-4848s040c/Source/Configuration.cpp @@ -1,5 +1,6 @@ #include "devices/St7701Display.h" #include "devices/SdCard.h" +#include #include #include diff --git a/Devices/cyd-8048s043c/Source/Configuration.cpp b/Devices/cyd-8048s043c/Source/Configuration.cpp index 296d2b4ef..51baa0972 100644 --- a/Devices/cyd-8048s043c/Source/Configuration.cpp +++ b/Devices/cyd-8048s043c/Source/Configuration.cpp @@ -1,6 +1,7 @@ #include "PwmBacklight.h" #include "devices/Display.h" #include "devices/SdCard.h" +#include #include diff --git a/Devices/cyd-e32r28t/Source/Configuration.cpp b/Devices/cyd-e32r28t/Source/Configuration.cpp index 986d3420c..4e4e91498 100644 --- a/Devices/cyd-e32r28t/Source/Configuration.cpp +++ b/Devices/cyd-e32r28t/Source/Configuration.cpp @@ -1,5 +1,6 @@ #include "devices/SdCard.h" #include "devices/Display.h" +#include #include #include diff --git a/Devices/cyd-e32r32p/Source/Configuration.cpp b/Devices/cyd-e32r32p/Source/Configuration.cpp index 795ca4cc1..f21b7c68f 100644 --- a/Devices/cyd-e32r32p/Source/Configuration.cpp +++ b/Devices/cyd-e32r32p/Source/Configuration.cpp @@ -1,6 +1,7 @@ #include "devices/SdCard.h" #include "devices/Display.h" #include "devices/Power.h" +#include #include #include diff --git a/Devices/elecrow-crowpanel-advance-28/Source/Configuration.cpp b/Devices/elecrow-crowpanel-advance-28/Source/Configuration.cpp index 69c29928b..51cc6e32d 100644 --- a/Devices/elecrow-crowpanel-advance-28/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-advance-28/Source/Configuration.cpp @@ -1,6 +1,7 @@ #include "PwmBacklight.h" #include "devices/Display.h" #include "devices/SdCard.h" +#include #include #include diff --git a/Devices/elecrow-crowpanel-advance-35/Source/Configuration.cpp b/Devices/elecrow-crowpanel-advance-35/Source/Configuration.cpp index 2ab3df9a1..90f32beb0 100644 --- a/Devices/elecrow-crowpanel-advance-35/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-advance-35/Source/Configuration.cpp @@ -1,5 +1,6 @@ #include "devices/Display.h" #include "devices/SdCard.h" +#include #include #include diff --git a/Devices/elecrow-crowpanel-advance-50/Source/Configuration.cpp b/Devices/elecrow-crowpanel-advance-50/Source/Configuration.cpp index 0284c3a8f..293c1f30d 100644 --- a/Devices/elecrow-crowpanel-advance-50/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-advance-50/Source/Configuration.cpp @@ -1,5 +1,6 @@ #include "devices/Display.h" #include "devices/SdCard.h" +#include #include #include diff --git a/Devices/elecrow-crowpanel-basic-28/Source/Configuration.cpp b/Devices/elecrow-crowpanel-basic-28/Source/Configuration.cpp index 9bcb16f42..f81c3f785 100644 --- a/Devices/elecrow-crowpanel-basic-28/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-basic-28/Source/Configuration.cpp @@ -1,6 +1,7 @@ #include "PwmBacklight.h" #include "devices/Display.h" #include "devices/SdCard.h" +#include #include #include diff --git a/Devices/elecrow-crowpanel-basic-35/Source/Configuration.cpp b/Devices/elecrow-crowpanel-basic-35/Source/Configuration.cpp index 70f80e85e..882444207 100644 --- a/Devices/elecrow-crowpanel-basic-35/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-basic-35/Source/Configuration.cpp @@ -2,6 +2,7 @@ #include "Tactility/lvgl/LvglSync.h" #include "devices/Display.h" #include "devices/SdCard.h" +#include #include #include diff --git a/Devices/elecrow-crowpanel-basic-50/Source/Configuration.cpp b/Devices/elecrow-crowpanel-basic-50/Source/Configuration.cpp index c1cde04fd..b9da4fd23 100644 --- a/Devices/elecrow-crowpanel-basic-50/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-basic-50/Source/Configuration.cpp @@ -1,5 +1,6 @@ #include "devices/Display.h" #include "devices/SdCard.h" +#include #include #include diff --git a/Devices/guition-jc2432w328c/Source/Configuration.cpp b/Devices/guition-jc2432w328c/Source/Configuration.cpp index 2336ac695..4ad1382ac 100644 --- a/Devices/guition-jc2432w328c/Source/Configuration.cpp +++ b/Devices/guition-jc2432w328c/Source/Configuration.cpp @@ -1,5 +1,6 @@ #include "devices/Display.h" #include "devices/SdCard.h" +#include #include #include diff --git a/Devices/guition-jc3248w535c/Source/Configuration.cpp b/Devices/guition-jc3248w535c/Source/Configuration.cpp index e40ece0e1..29c1d7131 100644 --- a/Devices/guition-jc3248w535c/Source/Configuration.cpp +++ b/Devices/guition-jc3248w535c/Source/Configuration.cpp @@ -1,5 +1,6 @@ #include "devices/Display.h" #include "devices/SdCard.h" +#include #include #include diff --git a/Devices/guition-jc8048w550c/Source/Configuration.cpp b/Devices/guition-jc8048w550c/Source/Configuration.cpp index bb4eba0b5..a6e82c6a4 100644 --- a/Devices/guition-jc8048w550c/Source/Configuration.cpp +++ b/Devices/guition-jc8048w550c/Source/Configuration.cpp @@ -1,6 +1,7 @@ #include "PwmBacklight.h" #include "devices/Display.h" #include "devices/SdCard.h" +#include #include diff --git a/Devices/lilygo-tdeck/Source/Configuration.cpp b/Devices/lilygo-tdeck/Source/Configuration.cpp index 73b3c7a8b..49e21597b 100644 --- a/Devices/lilygo-tdeck/Source/Configuration.cpp +++ b/Devices/lilygo-tdeck/Source/Configuration.cpp @@ -4,6 +4,7 @@ #include "devices/Sdcard.h" #include "devices/TdeckKeyboard.h" #include "devices/TrackballDevice.h" +#include #include #include diff --git a/Devices/lilygo-tdisplay-s3/Source/Configuration.cpp b/Devices/lilygo-tdisplay-s3/Source/Configuration.cpp index c6a629aca..61287a607 100644 --- a/Devices/lilygo-tdisplay-s3/Source/Configuration.cpp +++ b/Devices/lilygo-tdisplay-s3/Source/Configuration.cpp @@ -1,5 +1,6 @@ #include "devices/Display.h" #include "devices/Power.h" +#include #include #include diff --git a/Devices/lilygo-tdisplay/Source/Configuration.cpp b/Devices/lilygo-tdisplay/Source/Configuration.cpp index ee5b51794..9c049e35e 100644 --- a/Devices/lilygo-tdisplay/Source/Configuration.cpp +++ b/Devices/lilygo-tdisplay/Source/Configuration.cpp @@ -1,4 +1,5 @@ #include "devices/Display.h" +#include #include #include diff --git a/Devices/lilygo-tdongle-s3/Source/Configuration.cpp b/Devices/lilygo-tdongle-s3/Source/Configuration.cpp index 310b321c1..1e1adb264 100644 --- a/Devices/lilygo-tdongle-s3/Source/Configuration.cpp +++ b/Devices/lilygo-tdongle-s3/Source/Configuration.cpp @@ -1,5 +1,6 @@ #include "devices/Display.h" #include "devices/Sdcard.h" +#include #include #include diff --git a/Devices/lilygo-tlora-pager/Source/Configuration.cpp b/Devices/lilygo-tlora-pager/Source/Configuration.cpp index 55d1f135d..969a9b4fb 100644 --- a/Devices/lilygo-tlora-pager/Source/Configuration.cpp +++ b/Devices/lilygo-tlora-pager/Source/Configuration.cpp @@ -3,6 +3,7 @@ #include "devices/TpagerEncoder.h" #include "devices/TpagerKeyboard.h" #include "devices/TpagerPower.h" +#include #include #include diff --git a/Devices/m5stack-cardputer-adv/Source/Configuration.cpp b/Devices/m5stack-cardputer-adv/Source/Configuration.cpp index fb7fcad82..7dfce0d56 100644 --- a/Devices/m5stack-cardputer-adv/Source/Configuration.cpp +++ b/Devices/m5stack-cardputer-adv/Source/Configuration.cpp @@ -2,6 +2,7 @@ #include "devices/SdCard.h" #include "devices/CardputerKeyboard.h" #include "devices/CardputerPower.h" +#include #include #include diff --git a/Devices/m5stack-cardputer/Source/Configuration.cpp b/Devices/m5stack-cardputer/Source/Configuration.cpp index 76a8219d4..ebc107ff5 100644 --- a/Devices/m5stack-cardputer/Source/Configuration.cpp +++ b/Devices/m5stack-cardputer/Source/Configuration.cpp @@ -3,6 +3,7 @@ #include "devices/CardputerEncoder.h" #include "devices/CardputerKeyboard.h" #include "devices/CardputerPower.h" +#include #include #include diff --git a/Devices/m5stack-core2/Source/Configuration.cpp b/Devices/m5stack-core2/Source/Configuration.cpp index fb664d45c..e71cc9560 100644 --- a/Devices/m5stack-core2/Source/Configuration.cpp +++ b/Devices/m5stack-core2/Source/Configuration.cpp @@ -1,6 +1,7 @@ #include "devices/Display.h" #include "devices/SdCard.h" #include "devices/Power.h" +#include #include #include diff --git a/Devices/m5stack-cores3/Source/Configuration.cpp b/Devices/m5stack-cores3/Source/Configuration.cpp index 199ad4161..ffa11dd74 100644 --- a/Devices/m5stack-cores3/Source/Configuration.cpp +++ b/Devices/m5stack-cores3/Source/Configuration.cpp @@ -1,9 +1,9 @@ #include "InitBoot.h" #include "devices/Display.h" #include "devices/SdCard.h" +#include #include -#include #include #include diff --git a/Devices/m5stack-stickc-plus/Source/Configuration.cpp b/Devices/m5stack-stickc-plus/Source/Configuration.cpp index 18c8ba49f..8899fc0a1 100644 --- a/Devices/m5stack-stickc-plus/Source/Configuration.cpp +++ b/Devices/m5stack-stickc-plus/Source/Configuration.cpp @@ -1,5 +1,6 @@ #include "devices/Display.h" #include "devices/Power.h" +#include #include #include diff --git a/Devices/m5stack-stickc-plus2/Source/Configuration.cpp b/Devices/m5stack-stickc-plus2/Source/Configuration.cpp index b266e2f2c..1600b9532 100644 --- a/Devices/m5stack-stickc-plus2/Source/Configuration.cpp +++ b/Devices/m5stack-stickc-plus2/Source/Configuration.cpp @@ -1,4 +1,5 @@ #include "devices/Display.h" +#include #include #include diff --git a/Devices/unphone/Source/Configuration.cpp b/Devices/unphone/Source/Configuration.cpp index a55f02f12..c8d71b5a4 100644 --- a/Devices/unphone/Source/Configuration.cpp +++ b/Devices/unphone/Source/Configuration.cpp @@ -1,6 +1,7 @@ #include "UnPhoneFeatures.h" #include "devices/Hx8357Display.h" #include "devices/SdCard.h" +#include #include #include diff --git a/Devices/waveshare-esp32-s3-geek/Source/Configuration.cpp b/Devices/waveshare-esp32-s3-geek/Source/Configuration.cpp index ef39aac17..5dd262d97 100644 --- a/Devices/waveshare-esp32-s3-geek/Source/Configuration.cpp +++ b/Devices/waveshare-esp32-s3-geek/Source/Configuration.cpp @@ -1,5 +1,6 @@ #include "devices/Display.h" #include "devices/SdCard.h" +#include #include #include diff --git a/Devices/waveshare-s3-lcd-13/Source/Configuration.cpp b/Devices/waveshare-s3-lcd-13/Source/Configuration.cpp index 6105c2531..d211a1f3c 100644 --- a/Devices/waveshare-s3-lcd-13/Source/Configuration.cpp +++ b/Devices/waveshare-s3-lcd-13/Source/Configuration.cpp @@ -1,5 +1,6 @@ #include "devices/Display.h" #include "devices/SdCard.h" +#include #include #include diff --git a/Devices/waveshare-s3-touch-lcd-128/Source/Configuration.cpp b/Devices/waveshare-s3-touch-lcd-128/Source/Configuration.cpp index 7a6e4107a..d871491c2 100644 --- a/Devices/waveshare-s3-touch-lcd-128/Source/Configuration.cpp +++ b/Devices/waveshare-s3-touch-lcd-128/Source/Configuration.cpp @@ -1,5 +1,6 @@ #include "devices/Display.h" #include "devices/SdCard.h" +#include #include #include diff --git a/Devices/waveshare-s3-touch-lcd-147/Source/Configuration.cpp b/Devices/waveshare-s3-touch-lcd-147/Source/Configuration.cpp index ec73e5023..7c1524fe8 100644 --- a/Devices/waveshare-s3-touch-lcd-147/Source/Configuration.cpp +++ b/Devices/waveshare-s3-touch-lcd-147/Source/Configuration.cpp @@ -1,5 +1,6 @@ #include "devices/Display.h" #include "devices/Sdcard.h" +#include #include #include diff --git a/Devices/waveshare-s3-touch-lcd-43/Source/Configuration.cpp b/Devices/waveshare-s3-touch-lcd-43/Source/Configuration.cpp index f0b3d53e7..52063bf45 100644 --- a/Devices/waveshare-s3-touch-lcd-43/Source/Configuration.cpp +++ b/Devices/waveshare-s3-touch-lcd-43/Source/Configuration.cpp @@ -1,5 +1,6 @@ #include "devices/Display.h" #include "devices/SdCard.h" +#include #include diff --git a/Devices/wireless-tag-wt32-sc01-plus/Source/Configuration.cpp b/Devices/wireless-tag-wt32-sc01-plus/Source/Configuration.cpp index fdf44b16d..e1ce2c8c6 100644 --- a/Devices/wireless-tag-wt32-sc01-plus/Source/Configuration.cpp +++ b/Devices/wireless-tag-wt32-sc01-plus/Source/Configuration.cpp @@ -1,5 +1,6 @@ #include "devices/Display.h" #include "devices/SdCard.h" +#include #include #include diff --git a/Tactility/Private/Tactility/hal/gps/Ublox.h b/Tactility/Private/Tactility/hal/gps/Ublox.h index 4ff86c9fd..64398d327 100644 --- a/Tactility/Private/Tactility/hal/gps/Ublox.h +++ b/Tactility/Private/Tactility/hal/gps/Ublox.h @@ -18,4 +18,4 @@ GpsModel probe(::Device* uart); bool init(::Device* uart, GpsModel model); -} // namespace tt::service::gps +} diff --git a/Tactility/Source/hal/gps/Ublox.cpp b/Tactility/Source/hal/gps/Ublox.cpp index 88c12ac6d..8f0c7567d 100644 --- a/Tactility/Source/hal/gps/Ublox.cpp +++ b/Tactility/Source/hal/gps/Ublox.cpp @@ -63,7 +63,7 @@ GpsResponse getAck(::Device* uart, uint8_t class_id, uint8_t msg_id, uint32_t wa uint8_t ack = 0; const uint8_t ackP[2] = {class_id, msg_id}; uint8_t buf[10] = {0xB5, 0x62, 0x05, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint32_t startTime = kernel::getMillis(); + uint32_t startTime = kernel::getTicks(); TickType_t waitTicks = pdMS_TO_TICKS(waitMillis); const char frame_errors[] = "More than 100 frame errors"; int sCounter = 0; From 164da48a96f3392460a9bf42532adffd20c65771 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 7 Feb 2026 19:28:04 +0100 Subject: [PATCH 16/19] Fixes --- Devices/m5stack-cardputer/Source/Configuration.cpp | 2 +- Devices/m5stack-tab5/Source/Configuration.cpp | 1 + .../PlatformEsp32/Include/tactility/drivers/esp32_spi.h | 2 +- Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp | 2 +- Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp | 1 - Tactility/Source/hal/gps/Ublox.cpp | 7 ++++--- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Devices/m5stack-cardputer/Source/Configuration.cpp b/Devices/m5stack-cardputer/Source/Configuration.cpp index ebc107ff5..9c2757c2e 100644 --- a/Devices/m5stack-cardputer/Source/Configuration.cpp +++ b/Devices/m5stack-cardputer/Source/Configuration.cpp @@ -11,7 +11,7 @@ using namespace tt::hal; -bool initBoot() { +static bool initBoot() { return driver::pwmbacklight::init(LCD_PIN_BACKLIGHT, 512); } diff --git a/Devices/m5stack-tab5/Source/Configuration.cpp b/Devices/m5stack-tab5/Source/Configuration.cpp index 0bf8e45e1..4c400858a 100644 --- a/Devices/m5stack-tab5/Source/Configuration.cpp +++ b/Devices/m5stack-tab5/Source/Configuration.cpp @@ -3,6 +3,7 @@ #include #include +#include using namespace tt::hal; diff --git a/Platforms/PlatformEsp32/Include/tactility/drivers/esp32_spi.h b/Platforms/PlatformEsp32/Include/tactility/drivers/esp32_spi.h index 0731cfbb6..e008805b1 100644 --- a/Platforms/PlatformEsp32/Include/tactility/drivers/esp32_spi.h +++ b/Platforms/PlatformEsp32/Include/tactility/drivers/esp32_spi.h @@ -15,7 +15,7 @@ struct Esp32SpiConfig { int pin_sclk; int pin_wp; int pin_hd; - int max_transfer_sz; + int max_transfer_size; }; #ifdef __cplusplus diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp index c551b7e64..f5a20322c 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp @@ -72,7 +72,7 @@ static error_t start(Device* device) { .data6_io_num = GPIO_NUM_NC, .data7_io_num = GPIO_NUM_NC, .data_io_default_level = false, - .max_transfer_sz = dts_config->max_transfer_sz, + .max_transfer_sz = dts_config->max_transfer_size, .flags = 0, .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, .intr_flags = 0 diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp index f6b1234a0..22b85f74d 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp @@ -326,7 +326,6 @@ static error_t start(Device* device) { static error_t stop(Device* device) { ESP_LOGI(TAG, "stop %s", device->name); auto* driver_data = GET_DATA(device); - auto* dts_config = GET_CONFIG(device); lock(driver_data); if (driver_data->is_open) { diff --git a/Tactility/Source/hal/gps/Ublox.cpp b/Tactility/Source/hal/gps/Ublox.cpp index 8f0c7567d..aabae2573 100644 --- a/Tactility/Source/hal/gps/Ublox.cpp +++ b/Tactility/Source/hal/gps/Ublox.cpp @@ -129,12 +129,13 @@ GpsResponse getAck(::Device* uart, uint8_t class_id, uint8_t msg_id, uint32_t wa return GpsResponse::None; // No response received within timeout } -static int getAck(::Device* uart, uint8_t* buffer, uint16_t size, uint8_t requestedClass, uint8_t requestedId, uint32_t timeout) { +static int getAck(::Device* uart, uint8_t* buffer, uint16_t size, uint8_t requestedClass, uint8_t requestedId, uint32_t timeoutMillis) { uint16_t ubxFrameCounter = 0; - uint32_t startTime = kernel::getTicks(); + TickType_t startTime = kernel::getTicks(); + TickType_t timeoutTicks = pdMS_TO_TICKS(timeoutMillis); uint16_t needRead = 0; - while (kernel::getTicks() - startTime < timeout) { + while ((kernel::getTicks() - startTime) < timeoutTicks) { size_t available = 0; uart_controller_get_available(uart, &available); while (available > 0) { From fb2574dfbbb3ffbd7044f949c1ae3a5026d5bf22 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 7 Feb 2026 19:51:41 +0100 Subject: [PATCH 17/19] Fixes --- Devices/m5stack-tab5/Source/Configuration.cpp | 2 +- .../Source/drivers/esp32_spi.cpp | 4 -- .../Source/drivers/esp32_uart.cpp | 68 ++++++++++--------- 3 files changed, 38 insertions(+), 36 deletions(-) diff --git a/Devices/m5stack-tab5/Source/Configuration.cpp b/Devices/m5stack-tab5/Source/Configuration.cpp index 4c400858a..eab607a8d 100644 --- a/Devices/m5stack-tab5/Source/Configuration.cpp +++ b/Devices/m5stack-tab5/Source/Configuration.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include using namespace tt::hal; diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp index f5a20322c..dcc205320 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp @@ -53,10 +53,6 @@ static error_t start(Device* device) { auto* data = new(std::nothrow) Esp32SpiInternal(); if (!data) return ERROR_OUT_OF_MEMORY; - if (data->initialized) { - return ERROR_INVALID_STATE; - } - device_set_driver_data(device, data); auto* dts_config = GET_CONFIG(device); diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp index 22b85f74d..98f0a1107 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp @@ -186,7 +186,6 @@ static error_t set_config(Device* device, const struct UartConfig* config) { if (xPortInIsrContext()) return ERROR_ISR_STATUS; auto* driver_data = GET_DATA(device); - auto* dts_config = GET_CONFIG(device); lock(driver_data); if (driver_data->is_open) { @@ -194,31 +193,6 @@ static error_t set_config(Device* device, const struct UartConfig* config) { return ERROR_INVALID_STATE; } - uart_config_t uart_cfg = { - .baud_rate = (int)config->baud_rate, - .data_bits = to_esp32_data_bits(config->data_bits), - .parity = to_esp32_parity(config->parity), - .stop_bits = to_esp32_stop_bits(config->stop_bits), - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_DEFAULT, - .flags = { - .allow_pd = 0, - .backup_before_sleep = 0 - } - }; - - esp_err_t esp_error = uart_param_config(dts_config->port, &uart_cfg); - if (esp_error == ESP_OK) { - esp_error = uart_set_pin(dts_config->port, dts_config->pinTx, dts_config->pinRx, dts_config->pinCts, dts_config->pinRts); - } - - if (esp_error != ESP_OK) { - LOG_E(TAG, "Failed to configure UART: %s", esp_err_to_name(esp_error)); - unlock(driver_data); - return esp_err_to_error(esp_error); - } - memcpy(&driver_data->config, config, sizeof(UartConfig)); driver_data->config_set = true; @@ -241,6 +215,7 @@ static error_t get_config(Device* device, struct UartConfig* config) { } static error_t open(Device* device) { + ESP_LOGI(TAG, "%s open", device->name); if (xPortInIsrContext()) return ERROR_ISR_STATUS; auto* driver_data = GET_DATA(device); auto* dts_config = GET_CONFIG(device); @@ -248,23 +223,53 @@ static error_t open(Device* device) { lock(driver_data); if (driver_data->is_open) { unlock(driver_data); - LOG_W(TAG, "Already open"); + LOG_W(TAG, "%s is already open", device->name); return ERROR_INVALID_STATE; } if (!driver_data->config_set) { unlock(driver_data); - LOG_E(TAG, "open failed: config not set"); + LOG_E(TAG, "%s open failed: config not set", device->name); return ERROR_INVALID_STATE; } esp_err_t esp_error = uart_driver_install(dts_config->port, 1024, 0, 0, NULL, 0); if (esp_error != ESP_OK) { - LOG_E(TAG, "Failed to install UART driver: %s", esp_err_to_name(esp_error)); + LOG_E(TAG, "%s failed to install: %s", device->name, esp_err_to_name(esp_error)); unlock(driver_data); return esp_err_to_error(esp_error); } + uart_config_t uart_config = { + .baud_rate = (int)driver_data->config.baud_rate, + .data_bits = to_esp32_data_bits(driver_data->config.data_bits), + .parity = to_esp32_parity(driver_data->config.parity), + .stop_bits = to_esp32_stop_bits(driver_data->config.stop_bits), + .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, + .rx_flow_ctrl_thresh = 0, + .source_clk = UART_SCLK_DEFAULT, + .flags = { + .allow_pd = 0, + .backup_before_sleep = 0 + } + }; + + esp_error = uart_param_config(dts_config->port, &uart_config); + if (esp_error != ESP_OK) { + LOG_E(TAG, "%s failed to configure: %s", device->name, esp_err_to_name(esp_error)); + uart_driver_delete(dts_config->port); + unlock(driver_data); + return ERROR_RESOURCE; + } + + esp_error = uart_set_pin(dts_config->port, dts_config->pinTx, dts_config->pinRx, dts_config->pinCts, dts_config->pinRts); + if (esp_error != ESP_OK) { + LOG_E(TAG, "%s failed to set uart pins: %s", device->name, esp_err_to_name(esp_error)); + uart_driver_delete(dts_config->port); + unlock(driver_data); + return ERROR_RESOURCE; + } + driver_data->is_open = true; unlock(driver_data); @@ -272,6 +277,7 @@ static error_t open(Device* device) { } static error_t close(Device* device) { + ESP_LOGI(TAG, "%s close", device->name); if (xPortInIsrContext()) return ERROR_ISR_STATUS; auto* driver_data = GET_DATA(device); auto* dts_config = GET_CONFIG(device); @@ -314,7 +320,7 @@ static error_t flush_input(Device* device) { } static error_t start(Device* device) { - ESP_LOGI(TAG, "start %s", device->name); + ESP_LOGI(TAG, "%s start", device->name); auto* data = new(std::nothrow) Esp32UartInternal(); if (!data) return ERROR_OUT_OF_MEMORY; @@ -324,7 +330,7 @@ static error_t start(Device* device) { } static error_t stop(Device* device) { - ESP_LOGI(TAG, "stop %s", device->name); + ESP_LOGI(TAG, "%s stop", device->name); auto* driver_data = GET_DATA(device); lock(driver_data); From b23a9c93ac1500c18bcbd0369ca15e4204e9662e Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 7 Feb 2026 20:22:01 +0100 Subject: [PATCH 18/19] Fixes --- .../PlatformEsp32/Source/drivers/esp32_uart.cpp | 10 +++++++--- Tactility/Source/hal/gps/Ublox.cpp | 14 +++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp index 98f0a1107..f8a0ed597 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_uart.cpp @@ -245,7 +245,7 @@ static error_t open(Device* device) { .data_bits = to_esp32_data_bits(driver_data->config.data_bits), .parity = to_esp32_parity(driver_data->config.parity), .stop_bits = to_esp32_stop_bits(driver_data->config.stop_bits), - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, + .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, // Flow control is not yet exposed via UartConfig .rx_flow_ctrl_thresh = 0, .source_clk = UART_SCLK_DEFAULT, .flags = { @@ -254,6 +254,10 @@ static error_t open(Device* device) { } }; + if (dts_config->pinCts != UART_PIN_NO_CHANGE || dts_config->pinRts != UART_PIN_NO_CHANGE) { + LOG_W(TAG, "%s: CTS/RTS pins are defined but hardware flow control is disabled (not supported in UartConfig)", device->name); + } + esp_error = uart_param_config(dts_config->port, &uart_config); if (esp_error != ESP_OK) { LOG_E(TAG, "%s failed to configure: %s", device->name, esp_err_to_name(esp_error)); @@ -338,10 +342,10 @@ static error_t stop(Device* device) { unlock(driver_data); return ERROR_INVALID_STATE; } - device_set_driver_data(device, nullptr); unlock(driver_data); - + device_set_driver_data(device, nullptr); delete driver_data; + return ERROR_NONE; } diff --git a/Tactility/Source/hal/gps/Ublox.cpp b/Tactility/Source/hal/gps/Ublox.cpp index aabae2573..9171ddacd 100644 --- a/Tactility/Source/hal/gps/Ublox.cpp +++ b/Tactility/Source/hal/gps/Ublox.cpp @@ -16,10 +16,10 @@ bool initUblox6(::Device* uart); bool initUblox789(::Device* uart, GpsModel model); bool initUblox10(::Device* uart); -#define SEND_UBX_PACKET(UART, BUFFER, TYPE, ID, DATA, ERRMSG, TIMEOUT) \ +#define SEND_UBX_PACKET(UART, BUFFER, TYPE, ID, DATA, ERRMSG, TIMEOUT_MILLIS) \ do { \ auto msglen = makePacket(TYPE, ID, DATA, sizeof(DATA), BUFFER); \ - uart_controller_write_bytes(UART, BUFFER, msglen, TIMEOUT); \ + uart_controller_write_bytes(UART, BUFFER, msglen, TIMEOUT_MILLIS / portTICK_PERIOD_MS); \ if (getAck(UART, TYPE, ID, TIMEOUT) != GpsResponse::Ok) { \ LOGGER.info("Sending packet failed: {}", #ERRMSG); \ } \ @@ -220,7 +220,7 @@ GpsModel probe(::Device* uart) { uint8_t cfg_rate[] = {0xB5, 0x62, 0x06, 0x08, 0x00, 0x00, 0x00, 0x00}; checksum(cfg_rate, sizeof(cfg_rate)); uart_controller_flush_input(uart); - uart_controller_write_bytes(uart, cfg_rate, sizeof(cfg_rate), 500); + uart_controller_write_bytes(uart, cfg_rate, sizeof(cfg_rate), 500 / portTICK_PERIOD_MS); // Check that the returned response class and message ID are correct GpsResponse response = getAck(uart, 0x06, 0x08, 750); if (response == GpsResponse::None) { @@ -372,7 +372,7 @@ bool initUblox10(::Device* uart) { // BBR will survive a restart, and power off for a while, but modules with small backup // batteries or super caps will not retain the config for a long power off time. auto packet_size = makePacket(0x06, 0x09, _message_SAVE_10, sizeof(_message_SAVE_10), buffer); - uart_controller_write_bytes(uart, buffer, packet_size, 2000); + uart_controller_write_bytes(uart, buffer, packet_size, 2000 / portTICK_PERIOD_MS); if (getAck(uart, 0x06, 0x09, 2000) != GpsResponse::Ok) { LOGGER.warn("Unable to save GNSS module config"); } else { @@ -386,10 +386,10 @@ bool initUblox789(::Device* uart, GpsModel model) { if (model == GpsModel::UBLOX7) { LOGGER.debug("Set GPS+SBAS"); auto msglen = makePacket(0x06, 0x3e, _message_GNSS_7, sizeof(_message_GNSS_7), buffer); - uart_controller_write_bytes(uart, buffer, msglen, 800); + uart_controller_write_bytes(uart, buffer, msglen, 800 / portTICK_PERIOD_MS); } else { // 8,9 auto msglen = makePacket(0x06, 0x3e, _message_GNSS_8, sizeof(_message_GNSS_8), buffer); - uart_controller_write_bytes(uart, buffer, msglen, 800); + uart_controller_write_bytes(uart, buffer, msglen, 800 / portTICK_PERIOD_MS); } if (getAck(uart, 0x06, 0x3e, 800) == GpsResponse::NotAck) { @@ -446,7 +446,7 @@ bool initUblox789(::Device* uart, GpsModel model) { } auto packet_size = makePacket(0x06, 0x09, _message_SAVE, sizeof(_message_SAVE), buffer); - uart_controller_write_bytes(uart, buffer, packet_size, 2000); + uart_controller_write_bytes(uart, buffer, packet_size, 2000 / portTICK_PERIOD_MS); if (getAck(uart, 0x06, 0x09, 2000) != GpsResponse::Ok) { LOGGER.warn("Unable to save GNSS module config"); } else { From 98c76d7367581310b858d872d6edb988694784b7 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 7 Feb 2026 20:32:38 +0100 Subject: [PATCH 19/19] Fix --- Tactility/Source/hal/gps/Ublox.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tactility/Source/hal/gps/Ublox.cpp b/Tactility/Source/hal/gps/Ublox.cpp index 9171ddacd..be8d15e48 100644 --- a/Tactility/Source/hal/gps/Ublox.cpp +++ b/Tactility/Source/hal/gps/Ublox.cpp @@ -20,7 +20,7 @@ bool initUblox10(::Device* uart); do { \ auto msglen = makePacket(TYPE, ID, DATA, sizeof(DATA), BUFFER); \ uart_controller_write_bytes(UART, BUFFER, msglen, TIMEOUT_MILLIS / portTICK_PERIOD_MS); \ - if (getAck(UART, TYPE, ID, TIMEOUT) != GpsResponse::Ok) { \ + if (getAck(UART, TYPE, ID, TIMEOUT_MILLIS) != GpsResponse::Ok) { \ LOGGER.info("Sending packet failed: {}", #ERRMSG); \ } \ } while (0)