8 #include <hardware/uart.h> 17 static const char *
const TAG =
"uart.arduino_rp2040";
23 config |= UART_PARITY_NONE;
25 config |= UART_PARITY_EVEN;
27 config |= UART_PARITY_ODD;
32 config |= SERIAL_DATA_5;
35 config |= SERIAL_DATA_6;
38 config |= SERIAL_DATA_7;
41 config |= SERIAL_DATA_8;
46 config |= SERIAL_STOP_BIT_1;
48 config |= SERIAL_STOP_BIT_2;
55 ESP_LOGCONFIG(TAG,
"Setting up UART bus...");
59 constexpr uint32_t valid_tx_uart_0 = __bitset({0, 12, 16, 28});
60 constexpr uint32_t valid_tx_uart_1 = __bitset({4, 8, 20, 24});
62 constexpr uint32_t valid_rx_uart_0 = __bitset({1, 13, 17, 29});
63 constexpr uint32_t valid_rx_uart_1 = __bitset({5, 9, 21, 25});
70 ESP_LOGD(TAG,
"An inverted TX pin %u can only be used with SerialPIO", this->
tx_pin_->
get_pin());
74 }
else if (((1 << this->
tx_pin_->
get_pin()) & valid_tx_uart_1) != 0) {
77 ESP_LOGD(TAG,
"TX pin %u can only be used with SerialPIO", this->
tx_pin_->
get_pin());
84 ESP_LOGD(TAG,
"An inverted RX pin %u can only be used with SerialPIO", this->
rx_pin_->
get_pin());
88 }
else if (((1 << this->
rx_pin_->
get_pin()) & valid_rx_uart_1) != 0) {
91 ESP_LOGD(TAG,
"RX pin %u can only be used with SerialPIO", this->
rx_pin_->
get_pin());
98 ESP_LOGD(TAG,
"Using SerialPIO as UART%d is taken by the logger", tx_hw);
104 if (tx_hw == -1 || rx_hw == -1 || tx_hw != rx_hw) {
105 ESP_LOGV(TAG,
"Using SerialPIO");
111 gpio_set_outover(tx, GPIO_OVERRIDE_INVERT);
113 gpio_set_inover(rx, GPIO_OVERRIDE_INVERT);
116 ESP_LOGV(TAG,
"Using Hardware Serial");
133 ESP_LOGCONFIG(TAG,
"UART Bus:");
136 if (this->
rx_pin_ !=
nullptr) {
139 ESP_LOGCONFIG(TAG,
" Baud Rate: %u baud", this->
baud_rate_);
140 ESP_LOGCONFIG(TAG,
" Data Bits: %u", this->
data_bits_);
142 ESP_LOGCONFIG(TAG,
" Stop bits: %u", this->
stop_bits_);
144 ESP_LOGCONFIG(TAG,
" Using hardware serial");
146 ESP_LOGCONFIG(TAG,
" Using SerialPIO");
151 this->
serial_->write(data, len);
152 #ifdef USE_UART_DEBUGGER 153 for (
size_t i = 0; i <
len; i++) {
167 this->
serial_->readBytes(data, len);
168 #ifdef USE_UART_DEBUGGER 169 for (
size_t i = 0; i <
len; i++) {
177 ESP_LOGVV(TAG,
" Flushing...");
bool read_array(uint8_t *data, size_t len) override
void dump_config() override
InternalGPIOPin * tx_pin_
UARTParityOptions parity_
bool peek_byte(uint8_t *data) override
virtual uint8_t get_pin() const =0
InternalGPIOPin * rx_pin_
void write_array(const uint8_t *data, size_t len) override
Implementation of SPI Controller mode.
bool check_read_timeout_(size_t len=1)
CallbackManager< void(UARTDirection, uint8_t)> debug_callback_
const LogString * parity_to_str(UARTParityOptions parity)
virtual bool is_inverted() const =0