67 setup_pin_if_needed(this->
rx_pin_);
69 setup_pin_if_needed(this->
tx_pin_);
74 constexpr uint32_t valid_tx_uart_0 = __bitset({0, 12, 16, 28});
75 constexpr uint32_t valid_tx_uart_1 = __bitset({4, 8, 20, 24});
77 constexpr uint32_t valid_rx_uart_0 = __bitset({1, 13, 17, 29});
78 constexpr uint32_t valid_rx_uart_1 = __bitset({5, 9, 21, 25});
85 ESP_LOGD(TAG,
"An inverted TX pin %u can only be used with SerialPIO", this->
tx_pin_->
get_pin());
89 }
else if (pin_in_mask(this->
tx_pin_->
get_pin(), valid_tx_uart_1)) {
92 ESP_LOGD(TAG,
"TX pin %u can only be used with SerialPIO", this->
tx_pin_->
get_pin());
99 ESP_LOGD(TAG,
"An inverted RX pin %u can only be used with SerialPIO", this->
rx_pin_->
get_pin());
103 }
else if (pin_in_mask(this->
rx_pin_->
get_pin(), valid_rx_uart_1)) {
106 ESP_LOGD(TAG,
"RX pin %u can only be used with SerialPIO", this->
rx_pin_->
get_pin());
117 const bool tx_configured = (this->
tx_pin_ !=
nullptr);
118 const bool rx_configured = (this->
rx_pin_ !=
nullptr);
120 if (tx_configured && rx_configured) {
122 if (tx_hw != -1 && rx_hw != -1 && tx_hw == rx_hw) {
125 }
else if (tx_configured) {
127 }
else if (rx_configured) {
133 ESP_LOGD(TAG,
"Using SerialPIO as UART%d is taken by the logger", hw_uart);
139 const size_t rx_queue_size = rx_configured ? this->
rx_buffer_size_ : 1;
141 ESP_LOGV(TAG,
"Using SerialPIO");
144 auto *serial =
new SerialPIO(tx, rx, rx_queue_size);
147 gpio_set_outover(tx, GPIO_OVERRIDE_INVERT);
149 gpio_set_inover(rx, GPIO_OVERRIDE_INVERT);
152 ESP_LOGV(TAG,
"Using Hardware Serial");
153 SerialUART *serial = hw_uart == 0 ? &Serial1 : &Serial2;
158 serial->setFIFOSize(rx_queue_size);