Skip to content

Commit

Permalink
GPIO: Add gpio_get_io_config() and xxx_is_enabled().
Browse files Browse the repository at this point in the history
Signed-off-by: IhorNehrutsa <[email protected]>
  • Loading branch information
IhorNehrutsa committed Nov 22, 2024
1 parent f420609 commit e0523c1
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 1 deletion.
58 changes: 58 additions & 0 deletions components/esp_driver_gpio/include/driver/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 33 additions & 1 deletion components/esp_driver_gpio/src/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
46 changes: 46 additions & 0 deletions components/hal/include/hal/gpio_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit e0523c1

Please sign in to comment.