mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-06 14:14:33 +02:00
gpio: fix GPIO_IS_VALID_(OUTPUT_)GPIO macro
... which has the potential of doing bit shift by a negative amount
This commit is contained in:
@@ -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)
|
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 = {
|
gpio_config_t cfg = {
|
||||||
.pin_bit_mask = BIT64(gpio_num),
|
.pin_bit_mask = BIT64(gpio_num),
|
||||||
.mode = GPIO_MODE_DISABLE,
|
.mode = GPIO_MODE_DISABLE,
|
||||||
|
@@ -24,9 +24,11 @@ extern "C" {
|
|||||||
|
|
||||||
#define GPIO_PIN_COUNT (SOC_GPIO_PIN_COUNT)
|
#define GPIO_PIN_COUNT (SOC_GPIO_PIN_COUNT)
|
||||||
/// Check whether it is a valid GPIO number
|
/// 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
|
/// 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;
|
typedef intr_handle_t gpio_isr_handle_t;
|
||||||
|
@@ -597,7 +597,7 @@ esp_err_t ledc_channel_config(const ledc_channel_config_t *ledc_conf)
|
|||||||
{
|
{
|
||||||
LEDC_ARG_CHECK(ledc_conf, "ledc_conf");
|
LEDC_ARG_CHECK(ledc_conf, "ledc_conf");
|
||||||
uint32_t speed_mode = ledc_conf->speed_mode;
|
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 ledc_channel = ledc_conf->channel;
|
||||||
uint32_t timer_select = ledc_conf->timer_sel;
|
uint32_t timer_select = ledc_conf->timer_sel;
|
||||||
uint32_t intr_type = ledc_conf->intr_type;
|
uint32_t intr_type = ledc_conf->intr_type;
|
||||||
|
@@ -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 ++) {
|
for (int i = 0; i < sizeof(pin_array)/sizeof(int); i ++) {
|
||||||
const int io = pin_array[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;
|
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)
|
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);
|
gpio_reset_pin(cs_gpio_num);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user