diff --git a/components/esp_driver_gpio/include/driver/gpio.h b/components/esp_driver_gpio/include/driver/gpio.h index 4d5d63b57c01..c7e12a693207 100644 --- a/components/esp_driver_gpio/include/driver/gpio.h +++ b/components/esp_driver_gpio/include/driver/gpio.h @@ -590,6 +590,64 @@ esp_err_t gpio_deep_sleep_wakeup_disable(gpio_num_t gpio_num); */ esp_err_t gpio_dump_io_configuration(FILE *out_stream, uint64_t io_bit_mask); +/** + * @brief Get the configuration for an IO + * + * @param gpio_num GPIO number + * @param pu Pull-up enabled or not + * @param pd Pull-down enabled or not + * @param ie Input enabled or not + * @param oe Output enabled or not + * @param od Open-drain enabled or not + * @param drv Drive strength value + * @param fun_sel IOMUX function selection value + * @param sig_out Outputting peripheral signal index + * @param slp_sel Pin sleep mode enabled or not + */ +void gpio_get_io_config(uint32_t gpio_num, + bool *pu, bool *pd, bool *ie, bool *oe, bool *od, uint32_t *drv, + uint32_t *fun_sel, uint32_t *sig_out, bool *slp_sel); + +/** + * @brief Return pull-up status on GPIO. + * + * @param gpio_num GPIO number + * @return if GPIO gpio_num`s FUN_PU is true + */ +bool gpio_pullup_is_enabled(uint32_t gpio_num); + +/** + * @brief Return pull-down status on GPIO. + * + * @param gpio_num GPIO number + * @return if GPIO gpio_num`s FUN_PD is true + */ +bool gpio_pulldown_is_enabled(uint32_t gpio_num); + +/** + * @brief Return slp-sel status on GPIO. + * + * @param gpio_num GPIO number + * @return if GPIO gpio_num`s SLP_SEL is true + */ +bool gpio_sleep_sel_is_enabled(uint32_t gpio_num); + +/** + * @brief Return slp-pull-up status on GPIO. + * + * @param gpio_num GPIO number + * @return if GPIO gpio_num`s SLP_PU is true + */ +bool gpio_sleep_pullup_is_enabled(uint32_t gpio_num); + +/** + * @brief Return slp-pull-down status on GPIO. + * + * @param gpio_num GPIO number + * @return if GPIO gpio_num`s SLP_PD is true + */ +bool gpio_sleep_pulldown_is_enabled(uint32_t gpio_num); + #ifdef __cplusplus } #endif diff --git a/components/esp_driver_gpio/src/gpio.c b/components/esp_driver_gpio/src/gpio.c index a63ab11375aa..4b639c2db68c 100644 --- a/components/esp_driver_gpio/src/gpio.c +++ b/components/esp_driver_gpio/src/gpio.c @@ -1055,10 +1055,42 @@ esp_err_t gpio_dump_io_configuration(FILE *out_stream, uint64_t io_bit_mask) fprintf(out_stream, " SleepSelEn: %d\n", slp_sel); fprintf(out_stream, "\n"); } - fprintf(out_stream, "=================IO DUMP End==================\n"); + fprintf(out_stream, "=================IO DUMP End=================\n"); return ESP_OK; } +void gpio_get_io_config(uint32_t gpio_num, + bool *pu, bool *pd, bool *ie, bool *oe, bool *od, uint32_t *drv, + uint32_t *fun_sel, uint32_t *sig_out, bool *slp_sel) +{ + gpio_hal_get_io_config(gpio_context.gpio_hal, gpio_num, pu, pd, ie, oe, od, drv, fun_sel, sig_out, slp_sel); +} + +bool gpio_pullup_is_enabled(uint32_t gpio_num) +{ + return gpio_hal_pullup_is_enabled(gpio_context.gpio_hal, gpio_num); +} + +bool gpio_pulldown_is_enabled(uint32_t gpio_num) +{ + return gpio_hal_pulldown_is_enabled(gpio_context.gpio_hal, gpio_num); +} + +bool gpio_sleep_sel_is_enabled(uint32_t gpio_num) +{ + return gpio_hal_sleep_sel_is_enabled(gpio_context.gpio_hal, gpio_num); +} + +bool gpio_sleep_pullup_is_enabled(uint32_t gpio_num) +{ + return gpio_hal_sleep_pullup_is_enabled(gpio_context.gpio_hal, gpio_num); +} + +bool gpio_sleep_pulldown_is_enabled(uint32_t gpio_num) +{ + return gpio_hal_sleep_pulldown_is_enabled(gpio_context.gpio_hal, gpio_num); +} + esp_err_t gpio_func_sel(gpio_num_t gpio_num, uint32_t func) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); diff --git a/components/hal/include/hal/gpio_hal.h b/components/hal/include/hal/gpio_hal.h index 6954fb8990fd..b052a4dd0c2f 100644 --- a/components/hal/include/hal/gpio_hal.h +++ b/components/hal/include/hal/gpio_hal.h @@ -52,6 +52,52 @@ typedef struct { #define gpio_hal_get_io_config(hal, gpio_num, pu, pd, ie, oe, od, drv, fun_sel, sig_out, slp_sel) \ gpio_ll_get_io_config((hal)->dev, gpio_num, pu, pd, ie, oe, od, drv, fun_sel, sig_out, slp_sel) + +/** + * @brief Return pull-up status on GPIO. + * + * @param hal Context of the HAL layer + * @param gpio_num GPIO number + * @return if GPIO gpio_num`s FUN_PU is true + */ +#define gpio_hal_pullup_is_enabled(hal, gpio_num) gpio_ll_pullup_is_enabled((hal)->dev, gpio_num) + +/** + * @brief Return pull-down status on GPIO. + * + * @param hal Context of the HAL layer + * @param gpio_num GPIO number + * @return if GPIO gpio_num`s FUN_PD is true + */ +#define gpio_hal_pulldown_is_enabled(hal, gpio_num) gpio_ll_pulldown_is_enabled((hal)->dev, gpio_num) + +/** + * @brief Return slp-sel status on GPIO. + * + * @param hal Context of the HAL layer + * @param gpio_num GPIO number + * @return if GPIO gpio_num`s SLP_SEL is true + */ +#define gpio_hal_sleep_sel_is_enabled(hal, gpio_num) gpio_ll_sleep_sel_is_enabled((hal)->dev, gpio_num) + +/** + * @brief Return slp-pull-up status on GPIO. + * + * @param hal Context of the HAL layer + * @param gpio_num GPIO number + * @return if GPIO gpio_num`s SLP_PU is true + */ +#define gpio_hal_sleep_pullup_is_enabled(hal, gpio_num) gpio_ll_sleep_pullup_is_enabled((hal)->dev, gpio_num) + +/** + * @brief Return slp-pull-down status on GPIO. + * + * @param hal Context of the HAL layer + * @param gpio_num GPIO number + * @return if GPIO gpio_num`s SLP_PD is true + */ +#define gpio_hal_sleep_pulldown_is_enabled(hal, gpio_num) gpio_ll_sleep_pulldown_is_enabled((hal)->dev, gpio_num) + /** * @brief Enable pull-up on GPIO. *