26#include "driver/gpio.h"
27#include "driver/uart.h"
31#include "freertos/FreeRTOS.h"
32#include "freertos/task.h"
40static constexpr const char* TAG_UART_RVC =
"BNO08x_UART_RVC";
56 uart_port_t
port = UART_NUM_1;
83 cfg.baud_rate =
static_cast<int>(config_.
baud_rate);
84 cfg.data_bits = UART_DATA_8_BITS;
85 cfg.parity = UART_PARITY_DISABLE;
86 cfg.stop_bits = UART_STOP_BITS_1;
87 cfg.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;
89 esp_err_t err = uart_param_config(config_.
port, &cfg);
91 ESP_LOGE(TAG_UART_RVC,
"uart_param_config failed: %s", esp_err_to_name(err));
95 err = uart_set_pin(config_.
port, config_.
tx_pin, config_.
rx_pin, UART_PIN_NO_CHANGE,
98 ESP_LOGE(TAG_UART_RVC,
"uart_set_pin failed: %s", esp_err_to_name(err));
102 err = uart_driver_install(config_.
port, RX_BUF_SIZE, 0, 0,
nullptr, 0);
104 ESP_LOGE(TAG_UART_RVC,
"uart_driver_install failed: %s", esp_err_to_name(err));
109 if (config_.
rst_pin != GPIO_NUM_NC) {
110 gpio_config_t io_conf{};
111 io_conf.pin_bit_mask = (1ULL << config_.
rst_pin);
112 io_conf.mode = GPIO_MODE_OUTPUT;
113 io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
114 io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
115 io_conf.intr_type = GPIO_INTR_DISABLE;
116 gpio_config(&io_conf);
119 gpio_set_level(config_.
rst_pin, 0);
120 vTaskDelay(pdMS_TO_TICKS(2));
121 gpio_set_level(config_.
rst_pin, 1);
122 vTaskDelay(pdMS_TO_TICKS(200));
126 ESP_LOGI(TAG_UART_RVC,
"UART RVC bus opened on port %d (TX:%d, RX:%d, %lu baud)", config_.
port,
133 uart_driver_delete(config_.
port);
134 initialized_ =
false;
144 int Read(uint8_t* data, uint32_t length)
noexcept {
147 int ret = uart_read_bytes(config_.
port, data, length, 0);
148 return (ret >= 0) ? ret : -1;
151 int Write(
const uint8_t* , uint32_t )
noexcept {
160 vTaskDelay(pdMS_TO_TICKS(ms));
164 return static_cast<uint32_t
>(esp_timer_get_time());
183 if (config_.
rst_pin != GPIO_NUM_NC)
184 gpio_set_level(config_.
rst_pin,
188 if (config_.
boot_pin != GPIO_NUM_NC)
200 static constexpr int RX_BUF_SIZE = 256;
202 bool initialized_{
false};
CRTP-based communication interface for the BNO08x IMU family.
BNO085Interface
Identifies the host interface type that a CommInterface provides.
Definition bno08x_comm_interface.hpp:25
@ UARTRVC
UART in RVC mode (PS1=1, PS0=0). RVC frames only.
ESP32 UART CommInterface for BNO08x RVC mode.
Definition esp32_uart_rvc_bus.hpp:50
BNO085Interface GetInterfaceType() noexcept
Definition esp32_uart_rvc_bus.hpp:74
int Read(uint8_t *data, uint32_t length) noexcept
Read raw bytes from UART.
Definition esp32_uart_rvc_bus.hpp:144
uint32_t GetTimeUs() noexcept
Definition esp32_uart_rvc_bus.hpp:163
void Close() noexcept
Definition esp32_uart_rvc_bus.hpp:131
void GpioSet(bno08x::CtrlPin pin, bno08x::GpioSignal signal) noexcept
Set a control pin to the specified signal state (required by CommInterface)
Definition esp32_uart_rvc_bus.hpp:180
Esp32UartRvcBus()
Definition esp32_uart_rvc_bus.hpp:64
bool Open() noexcept
Definition esp32_uart_rvc_bus.hpp:78
void Delay(uint32_t ms) noexcept
Definition esp32_uart_rvc_bus.hpp:159
bool DataAvailable() noexcept
Definition esp32_uart_rvc_bus.hpp:155
int Write(const uint8_t *, uint32_t) noexcept
Definition esp32_uart_rvc_bus.hpp:151
~Esp32UartRvcBus()
Definition esp32_uart_rvc_bus.hpp:67
Esp32UartRvcBus(const UartConfig &config)
Definition esp32_uart_rvc_bus.hpp:65
CRTP base class for BNO08x communication interfaces.
Definition bno08x_comm_interface.hpp:92
CtrlPin
Identifies the hardware control pins of the BNO08x.
Definition bno08x_comm_interface.hpp:58
@ PS0
Protocol select bit 0 (active-high on the physical pin)
@ BOOTN
Bootloader entry (active-low on the physical pin)
@ RSTN
Hardware reset (active-low on the physical pin)
@ PS1
Protocol select bit 1 (active-high on the physical pin)
@ WAKE
Wake from suspend, SPI mode only (active-low on the physical pin)
GpioSignal
Abstract signal level for control pins.
Definition bno08x_comm_interface.hpp:74
@ ACTIVE
Pin function is asserted.
UART configuration for RVC mode.
Definition esp32_uart_rvc_bus.hpp:55
uart_port_t port
UART port number.
Definition esp32_uart_rvc_bus.hpp:56
gpio_num_t boot_pin
Boot pin (BOOTN, GPIO_NUM_NC if not used)
Definition esp32_uart_rvc_bus.hpp:61
gpio_num_t rst_pin
Reset pin (RSTN, active-low, GPIO_NUM_NC if not used)
Definition esp32_uart_rvc_bus.hpp:60
uint32_t baud_rate
Baud rate (BNO08x RVC is always 115200)
Definition esp32_uart_rvc_bus.hpp:59
gpio_num_t rx_pin
UART RX pin.
Definition esp32_uart_rvc_bus.hpp:58
gpio_num_t tx_pin
UART TX pin.
Definition esp32_uart_rvc_bus.hpp:57