diff --git a/components/driver/gpio.c b/components/driver/gpio.c index 9b3dbae6e9..0abbbeb5e0 100644 --- a/components/driver/gpio.c +++ b/components/driver/gpio.c @@ -392,7 +392,7 @@ esp_err_t gpio_config(const gpio_config_t *pGPIOConfig) esp_err_t gpio_reset_pin(gpio_num_t gpio_num) { - assert(gpio_num >= 0 && GPIO_IS_VALID_GPIO(gpio_num)); + assert(GPIO_IS_VALID_GPIO(gpio_num)); gpio_config_t cfg = { .pin_bit_mask = BIT64(gpio_num), .mode = GPIO_MODE_DISABLE, diff --git a/components/driver/include/driver/gpio.h b/components/driver/include/driver/gpio.h index b03c89e5c5..f71f47aa0c 100644 --- a/components/driver/include/driver/gpio.h +++ b/components/driver/include/driver/gpio.h @@ -24,9 +24,11 @@ extern "C" { #define GPIO_PIN_COUNT (SOC_GPIO_PIN_COUNT) /// Check whether it is a valid GPIO number -#define GPIO_IS_VALID_GPIO(gpio_num) (((1ULL << (gpio_num)) & SOC_GPIO_VALID_GPIO_MASK) != 0) +#define GPIO_IS_VALID_GPIO(gpio_num) ((gpio_num >= 0) && \ + (((1ULL << (gpio_num)) & SOC_GPIO_VALID_GPIO_MASK) != 0)) /// Check whether it can be a valid GPIO number of output mode -#define GPIO_IS_VALID_OUTPUT_GPIO(gpio_num) (((1ULL << (gpio_num)) & SOC_GPIO_VALID_OUTPUT_GPIO_MASK) != 0) +#define GPIO_IS_VALID_OUTPUT_GPIO(gpio_num) ((gpio_num >= 0) && \ + (((1ULL << (gpio_num)) & SOC_GPIO_VALID_OUTPUT_GPIO_MASK) != 0)) typedef intr_handle_t gpio_isr_handle_t; diff --git a/components/driver/ledc.c b/components/driver/ledc.c index 6bec8b05e7..7ca4ff9569 100644 --- a/components/driver/ledc.c +++ b/components/driver/ledc.c @@ -597,7 +597,7 @@ esp_err_t ledc_channel_config(const ledc_channel_config_t *ledc_conf) { LEDC_ARG_CHECK(ledc_conf, "ledc_conf"); uint32_t speed_mode = ledc_conf->speed_mode; - uint32_t gpio_num = ledc_conf->gpio_num; + int gpio_num = ledc_conf->gpio_num; uint32_t ledc_channel = ledc_conf->channel; uint32_t timer_select = ledc_conf->timer_sel; uint32_t intr_type = ledc_conf->intr_type; diff --git a/components/driver/spi_common.c b/components/driver/spi_common.c index c81f8d173e..000b1379a5 100644 --- a/components/driver/spi_common.c +++ b/components/driver/spi_common.c @@ -690,7 +690,9 @@ esp_err_t spicommon_bus_free_io_cfg(const spi_bus_config_t *bus_cfg) }; for (int i = 0; i < sizeof(pin_array)/sizeof(int); i ++) { const int io = pin_array[i]; - if (io >= 0 && GPIO_IS_VALID_GPIO(io)) gpio_reset_pin(io); + if (GPIO_IS_VALID_GPIO(io)) { + gpio_reset_pin(io); + } } return ESP_OK; } @@ -717,7 +719,7 @@ void spicommon_cs_initialize(spi_host_device_t host, int cs_io_num, int cs_num, void spicommon_cs_free_io(int cs_gpio_num) { - assert(cs_gpio_num>=0 && GPIO_IS_VALID_GPIO(cs_gpio_num)); + assert(GPIO_IS_VALID_GPIO(cs_gpio_num)); gpio_reset_pin(cs_gpio_num); }