mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 01:07:45 +01:00
Support advanced UART customization (#4465)
* Add methods to get hardware uart details. * Fix `setRxBufferSize` error. --------- Co-authored-by: Your Name <you@example.com>
This commit is contained in:
parent
79f861f012
commit
9922eb83e2
5 changed files with 17 additions and 2 deletions
|
@ -100,8 +100,8 @@ void ESP32ArduinoUARTComponent::setup() {
|
|||
invert = true;
|
||||
if (rx_pin_ != nullptr && rx_pin_->is_inverted())
|
||||
invert = true;
|
||||
this->hw_serial_->begin(this->baud_rate_, get_config(), rx, tx, invert);
|
||||
this->hw_serial_->setRxBufferSize(this->rx_buffer_size_);
|
||||
this->hw_serial_->begin(this->baud_rate_, get_config(), rx, tx, invert);
|
||||
}
|
||||
|
||||
void ESP32ArduinoUARTComponent::dump_config() {
|
||||
|
|
|
@ -28,6 +28,9 @@ class ESP32ArduinoUARTComponent : public UARTComponent, public Component {
|
|||
|
||||
uint32_t get_config();
|
||||
|
||||
HardwareSerial *get_hw_serial() { return this->hw_serial_; }
|
||||
uint8_t get_hw_serial_number() { return this->number_; }
|
||||
|
||||
protected:
|
||||
void check_logger_conflict() override;
|
||||
|
||||
|
|
|
@ -79,7 +79,12 @@ void IDFUARTComponent::setup() {
|
|||
return;
|
||||
}
|
||||
|
||||
err = uart_driver_install(this->uart_num_, this->rx_buffer_size_, 0, 0, nullptr, 0);
|
||||
err = uart_driver_install(this->uart_num_, /* UART RX ring buffer size. */ this->rx_buffer_size_,
|
||||
/* UART TX ring buffer size. If set to zero, driver will not use TX buffer, TX function will
|
||||
block task until all data have been sent out.*/
|
||||
0,
|
||||
/* UART event queue size/depth. */ 20, &(this->uart_event_queue_),
|
||||
/* Flags used to allocate the interrupt. */ 0);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGW(TAG, "uart_driver_install failed: %s", esp_err_to_name(err));
|
||||
this->mark_failed();
|
||||
|
|
|
@ -23,9 +23,13 @@ class IDFUARTComponent : public UARTComponent, public Component {
|
|||
int available() override;
|
||||
void flush() override;
|
||||
|
||||
uint8_t get_hw_serial_number() { return this->uart_num_; }
|
||||
QueueHandle_t *get_uart_event_queue() { return &this->uart_event_queue_; }
|
||||
|
||||
protected:
|
||||
void check_logger_conflict() override;
|
||||
uart_port_t uart_num_;
|
||||
QueueHandle_t uart_event_queue_;
|
||||
uart_config_t get_config_();
|
||||
SemaphoreHandle_t lock_;
|
||||
|
||||
|
|
|
@ -30,6 +30,9 @@ class RP2040UartComponent : public UARTComponent, public Component {
|
|||
|
||||
uint16_t get_config();
|
||||
|
||||
bool is_hw_serial() { return this->hw_serial_; }
|
||||
HardwareSerial *get_hw_serial() { return this->serial_; }
|
||||
|
||||
protected:
|
||||
void check_logger_conflict() override {}
|
||||
bool hw_serial_{false};
|
||||
|
|
Loading…
Reference in a new issue