mirror of
https://github.com/esphome/esphome.git
synced 2024-11-29 12:55:46 +01:00
Support for Arduino 2 and serial port on ESP32-S2 and ESP32-C3 (#3436)
This commit is contained in:
parent
7c30d6254e
commit
d2f37cf3f9
@ -51,7 +51,7 @@ class ImprovSerialComponent : public Component {
|
||||
void write_data_(std::vector<uint8_t> &data);
|
||||
|
||||
#ifdef USE_ARDUINO
|
||||
HardwareSerial *hw_serial_{nullptr};
|
||||
Stream *hw_serial_{nullptr};
|
||||
#endif
|
||||
#ifdef USE_ESP_IDF
|
||||
uart_port_t uart_num_;
|
||||
|
@ -149,13 +149,25 @@ void Logger::pre_setup() {
|
||||
case UART_SELECTION_UART0_SWAP:
|
||||
#endif
|
||||
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;
|
||||
case UART_SELECTION_UART1:
|
||||
this->hw_serial_ = &Serial1;
|
||||
Serial1.begin(this->baud_rate_);
|
||||
#ifdef USE_ESP8266
|
||||
Serial1.setDebugOutput(ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE);
|
||||
#endif
|
||||
break;
|
||||
#if defined(USE_ESP32) && !defined(USE_ESP32_VARIANT_ESP32C3) && !defined(USE_ESP32_VARIANT_ESP32S2)
|
||||
case UART_SELECTION_UART2:
|
||||
this->hw_serial_ = &Serial2;
|
||||
Serial2.begin(this->baud_rate_);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
@ -186,16 +198,6 @@ void Logger::pre_setup() {
|
||||
// Install UART driver using an event queue here
|
||||
uart_driver_install(uart_num_, uart_buffer_size, uart_buffer_size, 10, nullptr, 0);
|
||||
#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
|
||||
else {
|
||||
|
@ -40,7 +40,7 @@ class Logger : public Component {
|
||||
void set_baud_rate(uint32_t baud_rate);
|
||||
uint32_t get_baud_rate() const { return baud_rate_; }
|
||||
#ifdef USE_ARDUINO
|
||||
HardwareSerial *get_hw_serial() const { return hw_serial_; }
|
||||
Stream *get_hw_serial() const { return hw_serial_; }
|
||||
#endif
|
||||
#ifdef USE_ESP_IDF
|
||||
uart_port_t get_uart_num() const { return uart_num_; }
|
||||
@ -119,7 +119,7 @@ class Logger : public Component {
|
||||
int tx_buffer_size_{0};
|
||||
UARTSelection uart_{UART_SELECTION_UART0};
|
||||
#ifdef USE_ARDUINO
|
||||
HardwareSerial *hw_serial_{nullptr};
|
||||
Stream *hw_serial_{nullptr};
|
||||
#endif
|
||||
#ifdef USE_ESP_IDF
|
||||
uart_port_t uart_num_;
|
||||
|
Loading…
Reference in New Issue
Block a user