espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.77k stars 7.31k forks source link

Driver/GPIO: Add more getter functions into GPIO driver (IDFGH-10156) #11427

Open andylinpersonal opened 1 year ago

andylinpersonal commented 1 year ago

Is your feature request related to a problem?

Describe the solution you'd like.

Add the following missing getter functions into <driver/gpio.h> <driver/rtc_io.h> and HAL/LL layers


// ${IDF_PATH}/components/driver/gpio.h

esp_err_t gpio_get_pull_mode(gpio_num_t gpio_num, gpio_pull_mode_t *p_pull);

esp_err_t gpio_get_pull_mode_in_sleep(gpio_num_t gpio_num, gpio_pull_mode_t *p_pull);

esp_err_t gpio_get_direction(gpio_num_t gpio_num, gpio_mode_t *p_mode);

esp_err_t gpio_get_direction_in_sleep(gpio_num_t gpio_num, gpio_mode_t *p_mode);

esp_err_t gpio_is_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t *p_intr_type);

esp_err_t gpio_is_isr_service_installed(int* p_intr_alloc_flags);

esp_err_t gpio_get_intr_mode(gpio_num_t gpio_num, gpio_int_type_t *p_int_type, int *p_intr_alloc_flag);

esp_err_t gpio_is_intr_enabled(gpio_num_t gpio_num, bool *p_intr_en);

esp_err_t gpio_get_isr_handler(gpio_num_t gpio_num, gpio_isr_t* p_handler, void **p_arg); 

esp_err_t gpio_is_hold_enabled(gpio_num_t gpio_num, bool *p_en);

esp_err_t gpio_connected_to_io_mux(gpio_num_t gpio_num, bool *p_iomux_en);

esp_err_t gpio_get_iomux_signals(uint32_t gpio_num, uint32_t *p_in_signal_idx, uint32_t *p_out_signal_idx);

esp_err_t gpio_is_hold_enabled_in_sleep(bool *p_en);

esp_err_t gpio_is_sleep_sel_enabled(gpio_num_t gpio_num, bool *p_en);

esp_err_t gpio_is_wakeup_enable_in_deep_sleep(gpio_num_t gpio_num, bool *p_en);

// ${IDF_PATH}/components/driver/rtc_io.h

esp_err_t rtc_gpio_get_direction(gpio_num_t gpio_num, rtc_gpio_mode_t *p_mode);

esp_err_t rtc_gpio_get_direction_in_sleep(gpio_num_t gpio_num, rtc_gpio_mode_t *p_mode);

esp_err_t rtc_gpio_is_pullup_enabled(gpio_num_t gpio_num, bool *p_en);

esp_err_t rtc_gpio_is_pulldown_enabled(gpio_num_t gpio_num, bool *p_en);

esp_err_t rtc_gpio_is_hold_enabled(gpio_num_t gpio_num, bool *p_en);

esp_err_t rtc_gpio_get_wakeup_type(gpio_num_t gpio_num, gpio_int_type_t *p_intr_type);

Describe alternatives you've considered.

Currently no. Some states can be read from their own registers despite bypassing the protection provided by the spinlock in the GPIO's context But others can’t be accessed without modifying esp-idf, e.g. Registered ISR handler held inside a static variable in a *.c file.

Additional context.

No response

Maksons commented 1 year ago

+1 GPIO driver need improvements ! My need was to use own ISR handler, for getting 'timestamp' before any GPIO processing. There is gpio_isr_register() but it usage not documented, no examples and GPIO context used in driver is static (privat), imposible to use. Had to create copy of GPIO context (hal, spinlock, etc) and not sure if it is safe.