prepare for when UART PR#4465 is merged.

This commit is contained in:
Your Name
2023-03-20 14:38:33 +01:00
parent 9ce5eb1f38
commit b95c246c20
9 changed files with 163 additions and 4 deletions

View File

@@ -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<esphome::uart::truma_ESP32ArduinoUARTComponent *>(this->parent_);
auto uartComp = static_cast<ESPHOME_UART *>(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

View File

@@ -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<uart::truma_IDFUARTComponent *>(this->parent_);
auto uartComp = static_cast<ESPHOME_UART *>(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<uart::truma_IDFUARTComponent *>(instance->parent_);
auto uartComp = static_cast<ESPHOME_UART *>(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

View File

@@ -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 <SerialUART.h>
@@ -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<esphome::uart::truma_RP2040UartComponent *>(this->parent_);
auto uartComp = static_cast<ESPHOME_UART *>(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

View File

@@ -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]))