9#include "driver/uart.h"
11#include "freertos/FreeRTOS.h"
12#include "freertos/task.h"
26 int kRxBufBytes = 2048,
int kTxBufBytes = 0>
30 uart_config_t uart_cfg = {};
31 uart_cfg.baud_rate =
static_cast<int>(kBaud);
32 uart_cfg.data_bits = UART_DATA_8_BITS;
33 uart_cfg.parity = UART_PARITY_DISABLE;
34 uart_cfg.stop_bits = UART_STOP_BITS_1;
35 uart_cfg.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;
36 uart_cfg.rx_flow_ctrl_thresh = 0;
37 uart_cfg.source_clk = UART_SCLK_DEFAULT;
38 esp_err_t err = uart_driver_install(kPort, kRxBufBytes, kTxBufBytes, 0,
nullptr, 0);
42 err = uart_param_config(kPort, &uart_cfg);
46 err = uart_set_pin(kPort, kTxGpio, kRxGpio, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
50 void write(
const std::uint8_t* data, std::size_t len)
noexcept {
52 (void)uart_write_bytes(kPort, data,
static_cast<int>(len));
56 std::size_t
read(std::uint8_t* out, std::size_t max, std::uint32_t timeout_ms)
noexcept {
57 const int n = uart_read_bytes(kPort, out,
static_cast<int>(max), pdMS_TO_TICKS(timeout_ms));
58 return (n < 0) ? 0U :
static_cast<std::size_t
>(n);
61 void flush_rx() noexcept { uart_flush_input(kPort); }
63 void delay_ms_impl(std::uint32_t ms)
noexcept { vTaskDelay(pdMS_TO_TICKS(ms)); }
CRTP base for PSUP serial transport.
Definition fdo2_uart_interface.hpp:32
Template UART bridge: one concrete type per (port, TX, RX, baud) tuple.
Definition hf_fdo2_esp_uart.hpp:27
std::size_t read(std::uint8_t *out, std::size_t max, std::uint32_t timeout_ms) noexcept
Definition hf_fdo2_esp_uart.hpp:56
static esp_err_t Install() noexcept
Definition hf_fdo2_esp_uart.hpp:29
void flush_rx() noexcept
Definition hf_fdo2_esp_uart.hpp:61
void delay_ms_impl(std::uint32_t ms) noexcept
Definition hf_fdo2_esp_uart.hpp:63
void write(const std::uint8_t *data, std::size_t len) noexcept
Definition hf_fdo2_esp_uart.hpp:50
Umbrella header for the HF-FDO2 (FDO2-G2) UART driver.
constexpr uint32_t kFdo2G2DefaultBaud
Default UART speed after power-up per FDO2-G2 data sheet §4.
Definition fdo2_types.hpp:22
Definition hf_fdo2_esp_uart.hpp:17