From 448c8d8c6a86cce953ff08945bd410dc5f245432 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 10 May 2023 14:34:32 -0300 Subject: [PATCH 1/4] Avoid log_i() message the first time a bus is assigned --- cores/esp32/esp32-hal-periman.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-periman.c b/cores/esp32/esp32-hal-periman.c index a990e3824ef..67046630549 100644 --- a/cores/esp32/esp32-hal-periman.c +++ b/cores/esp32/esp32-hal-periman.c @@ -35,7 +35,7 @@ bool perimanSetPinBus(uint8_t pin, peripheral_bus_type_t type, void * bus){ } otype = pins[pin].type; obus = pins[pin].bus; - if(type == otype && bus == obus){ + if(type != ESP32_BUS_TYPE_INIT && type == otype && bus == obus){ log_i("Bus already set"); return true; } From 807f2c9abaa79993d25af07e3ebe9ab4cd0ed20e Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 10 May 2023 17:34:59 -0300 Subject: [PATCH 2/4] Prevent operation with ESP32_BUS_TYPE_INIT --- cores/esp32/esp32-hal-periman.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cores/esp32/esp32-hal-periman.c b/cores/esp32/esp32-hal-periman.c index 67046630549..7947dd7fb94 100644 --- a/cores/esp32/esp32-hal-periman.c +++ b/cores/esp32/esp32-hal-periman.c @@ -25,7 +25,7 @@ bool perimanSetPinBus(uint8_t pin, peripheral_bus_type_t type, void * bus){ log_e("Invalid pin: %u", pin); return false; } - if(type >= ESP32_BUS_TYPE_MAX){ + if(type >= ESP32_BUS_TYPE_MAX) { log_e("Invalid type: %u", (unsigned int)type); return false; } @@ -33,6 +33,10 @@ bool perimanSetPinBus(uint8_t pin, peripheral_bus_type_t type, void * bus){ log_e("Bus is NULL"); return false; } + if (type == ESP32_BUS_TYPE_INIT && bus != NULL) { + log_e("Can't set a Bus to INIT Type"); + return false; + } otype = pins[pin].type; obus = pins[pin].bus; if(type != ESP32_BUS_TYPE_INIT && type == otype && bus == obus){ @@ -59,7 +63,7 @@ void * perimanGetPinBus(uint8_t pin, peripheral_bus_type_t type){ log_e("Invalid pin: %u", pin); return NULL; } - if(type >= ESP32_BUS_TYPE_MAX){ + if(type >= ESP32_BUS_TYPE_MAX || type == ESP32_BUS_TYPE_INIT){ log_e("Invalid type: %u", (unsigned int)type); return NULL; } @@ -78,7 +82,7 @@ peripheral_bus_type_t perimanGetPinBusType(uint8_t pin){ } bool perimanSetBusDeinit(peripheral_bus_type_t type, peripheral_bus_deinit_cb_t cb){ - if(type >= ESP32_BUS_TYPE_MAX){ + if(type >= ESP32_BUS_TYPE_MAX || type == ESP32_BUS_TYPE_INIT){ log_e("Invalid type: %u", (unsigned int)type); return false; } From 8ca8b97c235b7fe4cf290069e293543ef670c9be Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 10 May 2023 17:36:45 -0300 Subject: [PATCH 3/4] keeps coding style --- cores/esp32/esp32-hal-periman.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/esp32/esp32-hal-periman.c b/cores/esp32/esp32-hal-periman.c index 7947dd7fb94..2026e3cbb3e 100644 --- a/cores/esp32/esp32-hal-periman.c +++ b/cores/esp32/esp32-hal-periman.c @@ -25,7 +25,7 @@ bool perimanSetPinBus(uint8_t pin, peripheral_bus_type_t type, void * bus){ log_e("Invalid pin: %u", pin); return false; } - if(type >= ESP32_BUS_TYPE_MAX) { + if(type >= ESP32_BUS_TYPE_MAX){ log_e("Invalid type: %u", (unsigned int)type); return false; } @@ -33,7 +33,7 @@ bool perimanSetPinBus(uint8_t pin, peripheral_bus_type_t type, void * bus){ log_e("Bus is NULL"); return false; } - if (type == ESP32_BUS_TYPE_INIT && bus != NULL) { + if (type == ESP32_BUS_TYPE_INIT && bus != NULL){ log_e("Can't set a Bus to INIT Type"); return false; } From a97ca62f7488a8f3460bc1617853035f07449ac5 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Thu, 11 May 2023 08:58:17 -0300 Subject: [PATCH 4/4] do not print messages on INIT bus type --- cores/esp32/esp32-hal-periman.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cores/esp32/esp32-hal-periman.c b/cores/esp32/esp32-hal-periman.c index 2026e3cbb3e..70d994b66dc 100644 --- a/cores/esp32/esp32-hal-periman.c +++ b/cores/esp32/esp32-hal-periman.c @@ -39,8 +39,10 @@ bool perimanSetPinBus(uint8_t pin, peripheral_bus_type_t type, void * bus){ } otype = pins[pin].type; obus = pins[pin].bus; - if(type != ESP32_BUS_TYPE_INIT && type == otype && bus == obus){ - log_i("Bus already set"); + if(type == otype && bus == obus){ + if (type != ESP32_BUS_TYPE_INIT) { + log_i("Bus already set"); + } return true; } if(obus != NULL){