From 5591c29eb3c1b10db2415e396f568c7e92143ccc Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Sat, 24 Jun 2023 14:08:15 -0700 Subject: [PATCH] Use SDK macros for matrix detach constants The constants that need to be passed to gpio_matrix_in and gpio_matrix_out to detach an input or output pin from a peripheral vary by platform. Use SIG_GPIO_OUT_IDX to detach an output, and GPIO_MATRIX_CONST_ONE_INPUT and GPIO_MATRIX_CONST_ZERO_INPUT to detach an input. ESP32 before IDF 4.0 didn't define GPIO_MATRIX_CONST_*_INPUT, so add compatibility #defines for GPIO_FUNC_IN_LOW/HIGH. GPIO_FUNC_IN_LOW/HIGH exist in IDF 4.0+, but can't be used because they have the wrong values for ESP32-C3 at least in IDF 4.4.3 (https://github.com/espressif/esp-idf/issues/11737). --- cores/esp32/esp32-hal-matrix.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cores/esp32/esp32-hal-matrix.c b/cores/esp32/esp32-hal-matrix.c index 869761a9ac7..3a82f31aa99 100644 --- a/cores/esp32/esp32-hal-matrix.c +++ b/cores/esp32/esp32-hal-matrix.c @@ -17,8 +17,8 @@ #include "esp_system.h" #ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ +#include "soc/gpio_pins.h" #if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 -#include "esp32/rom/gpio.h" #elif CONFIG_IDF_TARGET_ESP32S2 #include "esp32s2/rom/gpio.h" #elif CONFIG_IDF_TARGET_ESP32S3 @@ -30,11 +30,10 @@ #endif #else // ESP32 Before IDF 4.0 #include "rom/gpio.h" +#define GPIO_MATRIX_CONST_ZERO_INPUT GPIO_FUNC_IN_LOW +#define GPIO_MATRIX_CONST_ONE_INPUT GPIO_FUNC_IN_HIGH #endif -#define MATRIX_DETACH_OUT_SIG 0x100 -#define MATRIX_DETACH_IN_LOW_PIN 0x30 -#define MATRIX_DETACH_IN_LOW_HIGH 0x38 void ARDUINO_ISR_ATTR pinMatrixOutAttach(uint8_t pin, uint8_t function, bool invertOut, bool invertEnable) { @@ -43,7 +42,7 @@ void ARDUINO_ISR_ATTR pinMatrixOutAttach(uint8_t pin, uint8_t function, bool inv void ARDUINO_ISR_ATTR pinMatrixOutDetach(uint8_t pin, bool invertOut, bool invertEnable) { - gpio_matrix_out(pin, MATRIX_DETACH_OUT_SIG, invertOut, invertEnable); + gpio_matrix_out(pin, SIG_GPIO_OUT_IDX, invertOut, invertEnable); } void ARDUINO_ISR_ATTR pinMatrixInAttach(uint8_t pin, uint8_t signal, bool inverted) @@ -53,7 +52,7 @@ void ARDUINO_ISR_ATTR pinMatrixInAttach(uint8_t pin, uint8_t signal, bool invert void ARDUINO_ISR_ATTR pinMatrixInDetach(uint8_t signal, bool high, bool inverted) { - gpio_matrix_in(high?MATRIX_DETACH_IN_LOW_HIGH:MATRIX_DETACH_IN_LOW_PIN, signal, inverted); + gpio_matrix_in(high?GPIO_MATRIX_CONST_ONE_INPUT:GPIO_MATRIX_CONST_ZERO_INPUT, signal, inverted); } /* void ARDUINO_ISR_ATTR intrMatrixAttach(uint32_t source, uint32_t inum){