'uart' and 'improv_serial' need to understand non-UART logger configurations (#6998)

This commit is contained in:
Kevin P. Fleming 2024-06-30 19:52:05 -04:00 committed by GitHub
parent b89dea97d9
commit 5278ae4b5e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 256 additions and 20 deletions

View file

@ -57,7 +57,7 @@ optional<uint8_t> ImprovSerialComponent::read_byte_() {
} }
} }
break; break;
#if defined(CONFIG_ESP_CONSOLE_USB_CDC) && (defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)) #ifdef USE_LOGGER_USB_CDC
case logger::UART_SELECTION_USB_CDC: case logger::UART_SELECTION_USB_CDC:
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
if (esp_usb_console_available_for_read()) { if (esp_usb_console_available_for_read()) {
@ -68,15 +68,15 @@ optional<uint8_t> ImprovSerialComponent::read_byte_() {
byte = data; byte = data;
} }
break; break;
#endif // USE_ESP32_VARIANT_ESP32S2 || USE_ESP32_VARIANT_ESP32S3 #endif // USE_LOGGER_USB_CDC
#if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32S3) #ifdef USE_LOGGER_USB_SERIAL_JTAG
case logger::UART_SELECTION_USB_SERIAL_JTAG: { case logger::UART_SELECTION_USB_SERIAL_JTAG: {
if (usb_serial_jtag_read_bytes((char *) &data, 1, 0)) { if (usb_serial_jtag_read_bytes((char *) &data, 1, 0)) {
byte = data; byte = data;
} }
break; break;
} }
#endif // USE_ESP32_VARIANT_ESP32C3 || USE_ESP32_VARIANT_ESP32C6 || USE_ESP32_VARIANT_ESP32S3 #endif // USE_LOGGER_USB_SERIAL_JTAG
default: default:
break; break;
} }
@ -99,19 +99,19 @@ void ImprovSerialComponent::write_data_(std::vector<uint8_t> &data) {
#endif // !USE_ESP32_VARIANT_ESP32C3 && !USE_ESP32_VARIANT_ESP32S2 && !USE_ESP32_VARIANT_ESP32S3 #endif // !USE_ESP32_VARIANT_ESP32C3 && !USE_ESP32_VARIANT_ESP32S2 && !USE_ESP32_VARIANT_ESP32S3
uart_write_bytes(this->uart_num_, data.data(), data.size()); uart_write_bytes(this->uart_num_, data.data(), data.size());
break; break;
#if defined(CONFIG_ESP_CONSOLE_USB_CDC) && (defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)) #ifdef USE_LOGGER_USB_CDC
case logger::UART_SELECTION_USB_CDC: { case logger::UART_SELECTION_USB_CDC: {
const char *msg = (char *) data.data(); const char *msg = (char *) data.data();
esp_usb_console_write_buf(msg, data.size()); esp_usb_console_write_buf(msg, data.size());
break; break;
} }
#endif // USE_ESP32_VARIANT_ESP32S2 || USE_ESP32_VARIANT_ESP32S3 #endif // USE_LOGGER_USB_CDC
#if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32S3) #ifdef USE_LOGGER_USB_SERIAL_JTAG
case logger::UART_SELECTION_USB_SERIAL_JTAG: case logger::UART_SELECTION_USB_SERIAL_JTAG:
usb_serial_jtag_write_bytes((char *) data.data(), data.size(), 20 / portTICK_PERIOD_MS); usb_serial_jtag_write_bytes((char *) data.data(), data.size(), 20 / portTICK_PERIOD_MS);
usb_serial_jtag_ll_txfifo_flush(); // fixes for issue in IDF 4.4.7 usb_serial_jtag_ll_txfifo_flush(); // fixes for issue in IDF 4.4.7
break; break;
#endif // USE_ESP32_VARIANT_ESP32C3 || USE_ESP32_VARIANT_ESP32S3 #endif // USE_LOGGER_USB_SERIAL_JTAG
default: default:
break; break;
} }

View file

@ -96,10 +96,24 @@ void ESP32ArduinoUARTComponent::setup() {
next_uart_num++; next_uart_num++;
} else { } else {
#ifdef USE_LOGGER #ifdef USE_LOGGER
// The logger doesn't use this UART component, instead it targets the UARTs bool logger_uses_hardware_uart = true;
// directly (i.e. Serial/Serial0, Serial1, and Serial2). If the logger is
// enabled, skip the UART that it is configured to use. #ifdef USE_LOGGER_USB_CDC
if (logger::global_logger->get_baud_rate() > 0 && logger::global_logger->get_uart() == next_uart_num) { if (logger::global_logger->get_uart() == logger::UART_SELECTION_USB_CDC) {
// this is not a hardware UART, ignore it
logger_uses_hardware_uart = false;
}
#endif // USE_LOGGER_USB_CDC
#ifdef USE_LOGGER_USB_SERIAL_JTAG
if (logger::global_logger->get_uart() == logger::UART_SELECTION_USB_SERIAL_JTAG) {
// this is not a hardware UART, ignore it
logger_uses_hardware_uart = false;
}
#endif // USE_LOGGER_USB_SERIAL_JTAG
if (logger_uses_hardware_uart && logger::global_logger->get_baud_rate() > 0 &&
logger::global_logger->get_uart() == next_uart_num) {
next_uart_num++; next_uart_num++;
} }
#endif // USE_LOGGER #endif // USE_LOGGER

View file

@ -60,10 +60,30 @@ uart_config_t IDFUARTComponent::get_config_() {
void IDFUARTComponent::setup() { void IDFUARTComponent::setup() {
static uint8_t next_uart_num = 0; static uint8_t next_uart_num = 0;
#ifdef USE_LOGGER #ifdef USE_LOGGER
if (logger::global_logger->get_uart_num() == next_uart_num) bool logger_uses_hardware_uart = true;
#ifdef USE_LOGGER_USB_CDC
if (logger::global_logger->get_uart() == logger::UART_SELECTION_USB_CDC) {
// this is not a hardware UART, ignore it
logger_uses_hardware_uart = false;
}
#endif // USE_LOGGER_USB_CDC
#ifdef USE_LOGGER_USB_SERIAL_JTAG
if (logger::global_logger->get_uart() == logger::UART_SELECTION_USB_SERIAL_JTAG) {
// this is not a hardware UART, ignore it
logger_uses_hardware_uart = false;
}
#endif // USE_LOGGER_USB_SERIAL_JTAG
if (logger_uses_hardware_uart && logger::global_logger->get_baud_rate() > 0 &&
logger::global_logger->get_uart_num() == next_uart_num) {
next_uart_num++; next_uart_num++;
#endif }
#endif // USE_LOGGER
if (next_uart_num >= UART_NUM_MAX) { if (next_uart_num >= UART_NUM_MAX) {
ESP_LOGW(TAG, "Maximum number of UART components created already."); ESP_LOGW(TAG, "Maximum number of UART components created already.");
this->mark_failed(); this->mark_failed();

View file

@ -0,0 +1,8 @@
esphome:
on_boot:
then:
- logger.log: Hello world
logger:
level: DEBUG
hardware_uart: USB_CDC

View file

@ -0,0 +1,8 @@
esphome:
on_boot:
then:
- logger.log: Hello world
logger:
level: DEBUG
hardware_uart: USB_SERIAL_JTAG

View file

@ -0,0 +1 @@
<<: !include common-usb_cdc.yaml

View file

@ -0,0 +1 @@
<<: !include common-usb_cdc.yaml

View file

@ -0,0 +1 @@
<<: !include common-usb_cdc.yaml

View file

@ -0,0 +1 @@
<<: !include common-usb_cdc.yaml

View file

@ -0,0 +1 @@
<<: !include common-usb_serial_jtag.yaml

View file

@ -0,0 +1 @@
<<: !include common-usb_serial_jtag.yaml

View file

@ -1 +1 @@
<<: !include common.yaml <<: !include common-default_uart.yaml

View file

@ -1 +1 @@
<<: !include common.yaml <<: !include common-default_uart.yaml

View file

@ -1 +1 @@
<<: !include common.yaml <<: !include common-default_uart.yaml

View file

@ -1 +1 @@
<<: !include common.yaml <<: !include common-default_uart.yaml

View file

@ -1 +1 @@
<<: !include common.yaml <<: !include common-default_uart.yaml

View file

@ -1 +1 @@
<<: !include common.yaml <<: !include common-default_uart.yaml

View file

@ -0,0 +1,30 @@
<<: !include ../logger/common-usb_cdc.yaml
esphome:
on_boot:
then:
- uart.write:
id: uart_1
data: 'Hello World'
- uart.write:
id: uart_1
data: [0x00, 0x20, 0x42]
uart:
- id: uart_1
tx_pin: 4
rx_pin: 5
baud_rate: 9600
data_bits: 8
rx_buffer_size: 512
parity: EVEN
stop_bits: 2
- id: uart_2
tx_pin: 6
rx_pin: 7
baud_rate: 9600
data_bits: 8
rx_buffer_size: 512
parity: EVEN
stop_bits: 2

View file

@ -0,0 +1,30 @@
<<: !include ../logger/common-usb_cdc.yaml
esphome:
on_boot:
then:
- uart.write:
id: uart_1
data: 'Hello World'
- uart.write:
id: uart_1
data: [0x00, 0x20, 0x42]
uart:
- id: uart_1
tx_pin: 4
rx_pin: 5
baud_rate: 9600
data_bits: 8
rx_buffer_size: 512
parity: EVEN
stop_bits: 2
- id: uart_2
tx_pin: 6
rx_pin: 7
baud_rate: 9600
data_bits: 8
rx_buffer_size: 512
parity: EVEN
stop_bits: 2

View file

@ -0,0 +1,30 @@
<<: !include ../logger/common-usb_cdc.yaml
esphome:
on_boot:
then:
- uart.write:
id: uart_1
data: 'Hello World'
- uart.write:
id: uart_1
data: [0x00, 0x20, 0x42]
uart:
- id: uart_1
tx_pin: 4
rx_pin: 5
baud_rate: 9600
data_bits: 8
rx_buffer_size: 512
parity: EVEN
stop_bits: 2
- id: uart_2
tx_pin: 6
rx_pin: 7
baud_rate: 9600
data_bits: 8
rx_buffer_size: 512
parity: EVEN
stop_bits: 2

View file

@ -0,0 +1,30 @@
<<: !include ../logger/common-usb_cdc.yaml
esphome:
on_boot:
then:
- uart.write:
id: uart_1
data: 'Hello World'
- uart.write:
id: uart_1
data: [0x00, 0x20, 0x42]
uart:
- id: uart_1
tx_pin: 4
rx_pin: 5
baud_rate: 9600
data_bits: 8
rx_buffer_size: 512
parity: EVEN
stop_bits: 2
- id: uart_2
tx_pin: 6
rx_pin: 7
baud_rate: 9600
data_bits: 8
rx_buffer_size: 512
parity: EVEN
stop_bits: 2

View file

@ -0,0 +1,30 @@
<<: !include ../logger/common-usb_serial_jtag.yaml
esphome:
on_boot:
then:
- uart.write:
id: uart_1
data: 'Hello World'
- uart.write:
id: uart_1
data: [0x00, 0x20, 0x42]
uart:
- id: uart_1
tx_pin: 4
rx_pin: 5
baud_rate: 9600
data_bits: 8
rx_buffer_size: 512
parity: EVEN
stop_bits: 2
- id: uart_2
tx_pin: 6
rx_pin: 7
baud_rate: 9600
data_bits: 8
rx_buffer_size: 512
parity: EVEN
stop_bits: 2

View file

@ -0,0 +1,30 @@
<<: !include ../logger/common-usb_serial_jtag.yaml
esphome:
on_boot:
then:
- uart.write:
id: uart_1
data: 'Hello World'
- uart.write:
id: uart_1
data: [0x00, 0x20, 0x42]
uart:
- id: uart_1
tx_pin: 4
rx_pin: 5
baud_rate: 9600
data_bits: 8
rx_buffer_size: 512
parity: EVEN
stop_bits: 2
- id: uart_2
tx_pin: 6
rx_pin: 7
baud_rate: 9600
data_bits: 8
rx_buffer_size: 512
parity: EVEN
stop_bits: 2