From b95c246c20ea04cbd6f819e3aafed70827fe2305 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 20 Mar 2023 14:38:33 +0100 Subject: [PATCH] prepare for when UART PR#4465 is merged. --- .github/workflows/main.yml | 12 ++++++ .../LinBusListener_esp32_arduino.cpp | 8 +++- .../truma_inetbox/LinBusListener_esp_idf.cpp | 10 ++++- .../truma_inetbox/LinBusListener_rp2040.cpp | 8 +++- components/uart/__init__.py | 1 + tests/.gitignore | 5 +++ tests/test.esp32_ard.uart.yaml | 41 +++++++++++++++++++ tests/test.esp32_idf.uart.yaml | 41 +++++++++++++++++++ tests/test.rp2040.uart.yaml | 41 +++++++++++++++++++ 9 files changed, 163 insertions(+), 4 deletions(-) create mode 100644 tests/.gitignore create mode 100644 tests/test.esp32_ard.uart.yaml create mode 100644 tests/test.esp32_idf.uart.yaml create mode 100644 tests/test.rp2040.uart.yaml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d474bf0..22eaef8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -26,14 +26,26 @@ jobs: fail-fast: false matrix: include: + - id: test + file: tests/test.esp32_ard.uart.yaml + name: Test tests/test.esp32_ard.uart.yaml + pio_cache_key: test.esp32_ard.uart - id: test file: tests/test.esp32_ard.yaml name: Test tests/test.esp32_ard.yaml pio_cache_key: test.esp32_ard + - id: test + file: tests/test.esp32_idf.uart.yaml + name: Test tests/test.esp32_idf.uart.yaml + pio_cache_key: test.esp32_idf.uart - id: test file: tests/test.esp32_idf.yaml name: Test tests/test.esp32_idf.yaml pio_cache_key: test.esp32_idf + - id: test + file: tests/test.rp2040.uart.yaml + name: Test tests/test.rp2040.uart.yaml + pio_cache_key: test.rp2040.uart - id: test file: tests/test.rp2040.yaml name: Test tests/test.rp2040.yaml diff --git a/components/truma_inetbox/LinBusListener_esp32_arduino.cpp b/components/truma_inetbox/LinBusListener_esp32_arduino.cpp index 4dd33cd..d92fc0e 100644 --- a/components/truma_inetbox/LinBusListener_esp32_arduino.cpp +++ b/components/truma_inetbox/LinBusListener_esp32_arduino.cpp @@ -4,7 +4,12 @@ #include "driver/uart.h" #include "soc/uart_struct.h" #include "soc/uart_reg.h" +#ifdef CUSTOM_ESPHOME_UART #include "esphome/components/uart/truma_uart_component_esp32_arduino.h" +#define ESPHOME_UART uart::truma_ESP32ArduinoUARTComponent +#else +#define ESPHOME_UART uart::ESP32ArduinoUARTComponent +#endif // CUSTOM_ESPHOME_UART #include "esphome/components/uart/uart_component_esp32_arduino.h" namespace esphome { @@ -15,7 +20,7 @@ static const char *const TAG = "truma_inetbox.LinBusListener"; #define QUEUE_WAIT_BLOCKING (portTickType) portMAX_DELAY void LinBusListener::setup_framework() { - auto uartComp = static_cast(this->parent_); + auto uartComp = static_cast(this->parent_); auto uart_num = uartComp->get_hw_serial_number(); auto hw_serial = uartComp->get_hw_serial(); @@ -76,5 +81,6 @@ void LinBusListener::eventTask_(void *args) { } // namespace esphome #undef QUEUE_WAIT_BLOCKING +#undef ESPHOME_UART #endif // USE_ESP32_FRAMEWORK_ARDUINO \ No newline at end of file diff --git a/components/truma_inetbox/LinBusListener_esp_idf.cpp b/components/truma_inetbox/LinBusListener_esp_idf.cpp index c3ab886..91f8a6b 100644 --- a/components/truma_inetbox/LinBusListener_esp_idf.cpp +++ b/components/truma_inetbox/LinBusListener_esp_idf.cpp @@ -2,7 +2,12 @@ #include "LinBusListener.h" #include "esphome/core/log.h" #include "soc/uart_reg.h" +#ifdef CUSTOM_ESPHOME_UART #include "esphome/components/uart/truma_uart_component_esp_idf.h" +#define ESPHOME_UART uart::truma_IDFUARTComponent +#else +#define ESPHOME_UART uart::IDFUARTComponent +#endif // CUSTOM_ESPHOME_UART #include "esphome/components/uart/uart_component_esp_idf.h" namespace esphome { @@ -14,7 +19,7 @@ static const char *const TAG = "truma_inetbox.LinBusListener"; void LinBusListener::setup_framework() { // uartSetFastReading - auto uartComp = static_cast(this->parent_); + auto uartComp = static_cast(this->parent_); auto uart_num = uartComp->get_hw_serial_number(); @@ -60,7 +65,7 @@ void LinBusListener::setup_framework() { void LinBusListener::uartEventTask_(void *args) { LinBusListener *instance = (LinBusListener *) args; - auto uartComp = static_cast(instance->parent_); + auto uartComp = static_cast(instance->parent_); auto uart_num = uartComp->get_hw_serial_number(); auto uartEventQueue = uartComp->get_uart_event_queue(); uart_event_t event; @@ -92,5 +97,6 @@ void LinBusListener::eventTask_(void *args) { } // namespace esphome #undef QUEUE_WAIT_BLOCKING +#undef ESPHOME_UART #endif // USE_ESP32_FRAMEWORK_ESP_IDF \ No newline at end of file diff --git a/components/truma_inetbox/LinBusListener_rp2040.cpp b/components/truma_inetbox/LinBusListener_rp2040.cpp index a6def53..cced687 100644 --- a/components/truma_inetbox/LinBusListener_rp2040.cpp +++ b/components/truma_inetbox/LinBusListener_rp2040.cpp @@ -1,7 +1,12 @@ #ifdef USE_RP2040 #include "LinBusListener.h" #include "esphome/core/log.h" +#ifdef CUSTOM_ESPHOME_UART #include "esphome/components/uart/truma_uart_component_rp2040.h" +#define ESPHOME_UART uart::truma_RP2040UartComponent +#else +#define ESPHOME_UART uart::RP2040UartComponent +#endif // CUSTOM_ESPHOME_UART #include "esphome/components/uart/uart_component_rp2040.h" #include @@ -18,7 +23,7 @@ static const char *const TAG = "truma_inetbox.LinBusListener"; #define QUEUE_WAIT_DONT_BLOCK (TickType_t) 0 void LinBusListener::setup_framework() { - auto uartComp = static_cast(this->parent_); + auto uartComp = static_cast(this->parent_); auto is_hw_serial = uartComp->is_hw_serial(); if (!is_hw_serial) { ESP_LOGW(TAG, "Must use hardware serial SerialPIO is not supported."); @@ -113,5 +118,6 @@ extern void loop1() { } #undef QUEUE_WAIT_DONT_BLOCK +#undef ESPHOME_UART #endif // USE_RP2040 diff --git a/components/uart/__init__.py b/components/uart/__init__.py index 2139ad2..1a2fa66 100644 --- a/components/uart/__init__.py +++ b/components/uart/__init__.py @@ -216,6 +216,7 @@ async def to_code(config): cg.add_global(uart_ns.using) var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) + cg.add_build_flag("-DCUSTOM_ESPHOME_UART"); cg.add(var.set_baud_rate(config[CONF_BAUD_RATE])) diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..d8b4157 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1,5 @@ +# Gitignore settings for ESPHome +# This is an example and may include too much for your use-case. +# You can modify this file to suit your needs. +/.esphome/ +/secrets.yaml diff --git a/tests/test.esp32_ard.uart.yaml b/tests/test.esp32_ard.uart.yaml new file mode 100644 index 0000000..17e61d6 --- /dev/null +++ b/tests/test.esp32_ard.uart.yaml @@ -0,0 +1,41 @@ +esphome: + name: "esp32-ard-uart" + + on_boot: + then: + # read time from external source (connected via I2C) + - ds1307.read_time + +external_components: + # https://github.com/esphome/esphome/pull/4465 + - source: github://pr#4465 + components: [uart] + - source: + type: local + path: ../components + components: [truma_inetbox] + +esp32: + board: esp32dev + framework: + type: arduino + +i2c: + sda: 14 + scl: 27 + scan: false + id: i2c_bus_a + +time: + - platform: ds1307 + update_interval: never + id: esptime + +uart: !include test.common.uart.yaml +truma_inetbox: !include test.common.truma_inetbox.yaml +binary_sensor: !include test.common.binary_sensor.yaml +button: !include test.common.button.yaml +climate: !include test.common.climate.yaml +number: !include test.common.number.yaml +sensor: !include test.common.sensor.yaml +switch: !include test.common.switch.yaml \ No newline at end of file diff --git a/tests/test.esp32_idf.uart.yaml b/tests/test.esp32_idf.uart.yaml new file mode 100644 index 0000000..1ed3e5e --- /dev/null +++ b/tests/test.esp32_idf.uart.yaml @@ -0,0 +1,41 @@ +esphome: + name: "esp32-idf-uart" + + on_boot: + then: + # read time from external source (connected via I2C) + - ds1307.read_time + +external_components: + # https://github.com/esphome/esphome/pull/4465 + - source: github://pr#4465 + components: [uart] + - source: + type: local + path: ../components + components: [truma_inetbox] + +esp32: + board: esp32dev + framework: + type: esp-idf + +i2c: + sda: 14 + scl: 27 + scan: false + id: i2c_bus_a + +time: + - platform: ds1307 + update_interval: never + id: esptime + +uart: !include test.common.uart.yaml +truma_inetbox: !include test.common.truma_inetbox.yaml +binary_sensor: !include test.common.binary_sensor.yaml +button: !include test.common.button.yaml +climate: !include test.common.climate.yaml +number: !include test.common.number.yaml +sensor: !include test.common.sensor.yaml +switch: !include test.common.switch.yaml \ No newline at end of file diff --git a/tests/test.rp2040.uart.yaml b/tests/test.rp2040.uart.yaml new file mode 100644 index 0000000..1025f71 --- /dev/null +++ b/tests/test.rp2040.uart.yaml @@ -0,0 +1,41 @@ +esphome: + name: "rp2040-uart" + + on_boot: + then: + # read time from external source (connected via I2C) + - ds1307.read_time + +external_components: + # https://github.com/esphome/esphome/pull/4465 + - source: github://pr#4465 + components: [uart] + - source: + type: local + path: ../components + components: [truma_inetbox] + +rp2040: + board: rpipicow + framework: + platform_version: https://github.com/maxgerhardt/platform-raspberrypi.git + +i2c: + sda: 14 + scl: 27 + scan: false + id: i2c_bus_a + +time: + - platform: ds1307 + update_interval: never + id: esptime + +uart: !include test.common.uart.yaml +truma_inetbox: !include test.common.truma_inetbox.yaml +binary_sensor: !include test.common.binary_sensor.yaml +button: !include test.common.button.yaml +climate: !include test.common.climate.yaml +number: !include test.common.number.yaml +sensor: !include test.common.sensor.yaml +switch: !include test.common.switch.yaml \ No newline at end of file