Support for Arduino 2 and serial port on ESP32-S2 and ESP32-C3 (#3436)

This commit is contained in:
Jens-Christian Skibakk 2022-05-09 06:17:22 +02:00 committed by GitHub
parent 7c30d6254e
commit d2f37cf3f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 13 deletions

View File

@ -51,7 +51,7 @@ class ImprovSerialComponent : public Component {
void write_data_(std::vector<uint8_t> &data); void write_data_(std::vector<uint8_t> &data);
#ifdef USE_ARDUINO #ifdef USE_ARDUINO
HardwareSerial *hw_serial_{nullptr}; Stream *hw_serial_{nullptr};
#endif #endif
#ifdef USE_ESP_IDF #ifdef USE_ESP_IDF
uart_port_t uart_num_; uart_port_t uart_num_;

View File

@ -149,13 +149,25 @@ void Logger::pre_setup() {
case UART_SELECTION_UART0_SWAP: case UART_SELECTION_UART0_SWAP:
#endif #endif
this->hw_serial_ = &Serial; this->hw_serial_ = &Serial;
Serial.begin(this->baud_rate_);
#ifdef USE_ESP8266
if (this->uart_ == UART_SELECTION_UART0_SWAP) {
Serial.swap();
}
Serial.setDebugOutput(ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE);
#endif
break; break;
case UART_SELECTION_UART1: case UART_SELECTION_UART1:
this->hw_serial_ = &Serial1; this->hw_serial_ = &Serial1;
Serial1.begin(this->baud_rate_);
#ifdef USE_ESP8266
Serial1.setDebugOutput(ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE);
#endif
break; break;
#if defined(USE_ESP32) && !defined(USE_ESP32_VARIANT_ESP32C3) && !defined(USE_ESP32_VARIANT_ESP32S2) #if defined(USE_ESP32) && !defined(USE_ESP32_VARIANT_ESP32C3) && !defined(USE_ESP32_VARIANT_ESP32S2)
case UART_SELECTION_UART2: case UART_SELECTION_UART2:
this->hw_serial_ = &Serial2; this->hw_serial_ = &Serial2;
Serial2.begin(this->baud_rate_);
break; break;
#endif #endif
} }
@ -186,16 +198,6 @@ void Logger::pre_setup() {
// Install UART driver using an event queue here // Install UART driver using an event queue here
uart_driver_install(uart_num_, uart_buffer_size, uart_buffer_size, 10, nullptr, 0); uart_driver_install(uart_num_, uart_buffer_size, uart_buffer_size, 10, nullptr, 0);
#endif #endif
#ifdef USE_ARDUINO
this->hw_serial_->begin(this->baud_rate_);
#ifdef USE_ESP8266
if (this->uart_ == UART_SELECTION_UART0_SWAP) {
this->hw_serial_->swap();
}
this->hw_serial_->setDebugOutput(ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE);
#endif
#endif // USE_ARDUINO
} }
#ifdef USE_ESP8266 #ifdef USE_ESP8266
else { else {

View File

@ -40,7 +40,7 @@ class Logger : public Component {
void set_baud_rate(uint32_t baud_rate); void set_baud_rate(uint32_t baud_rate);
uint32_t get_baud_rate() const { return baud_rate_; } uint32_t get_baud_rate() const { return baud_rate_; }
#ifdef USE_ARDUINO #ifdef USE_ARDUINO
HardwareSerial *get_hw_serial() const { return hw_serial_; } Stream *get_hw_serial() const { return hw_serial_; }
#endif #endif
#ifdef USE_ESP_IDF #ifdef USE_ESP_IDF
uart_port_t get_uart_num() const { return uart_num_; } uart_port_t get_uart_num() const { return uart_num_; }
@ -119,7 +119,7 @@ class Logger : public Component {
int tx_buffer_size_{0}; int tx_buffer_size_{0};
UARTSelection uart_{UART_SELECTION_UART0}; UARTSelection uart_{UART_SELECTION_UART0};
#ifdef USE_ARDUINO #ifdef USE_ARDUINO
HardwareSerial *hw_serial_{nullptr}; Stream *hw_serial_{nullptr};
#endif #endif
#ifdef USE_ESP_IDF #ifdef USE_ESP_IDF
uart_port_t uart_num_; uart_port_t uart_num_;