Skip to content

Commit

Permalink
added high level init_gpio function to setup GPIO usage
Browse files Browse the repository at this point in the history
  • Loading branch information
ftylitak committed Aug 4, 2023
1 parent 74a6315 commit 33b18e0
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions ports/esp32/esp32_ulp.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,27 @@

#if defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S3)

#if CONFIG_IDF_TARGET_ESP32
#include "esp32/ulp.h"
#elif CONFIG_IDF_TARGET_ESP32S2
#include "esp32s2/ulp.h"
#elif CONFIG_IDF_TARGET_ESP32S3
#include "esp32s3/ulp.h"
#endif

#include "esp_err.h"

#include "soc/rtc_cntl_reg.h"
#include "soc/sens_reg.h"
#include "soc/rtc_periph.h"
#include "driver/gpio.h"
#include "driver/rtc_io.h"
#include "esp_sleep.h"

// #define RTC_GPIO_MODE_INPUT_ONLY 0
// #include "soc/rtc_periph.h"
#include "hal/rtc_io_ll.h"

typedef struct _esp32_ulp_obj_t
{
mp_obj_base_t base;
Expand All @@ -46,6 +64,9 @@ STATIC mp_obj_t esp32_ulp_make_new(const mp_obj_type_t *type, size_t n_args, siz
// check arguments
mp_arg_check_num(n_args, n_kw, 0, 0, false);

// Disable logging from the ROM code after deep sleep.
esp_deep_sleep_disable_rom_logging();

// return constant object
return (mp_obj_t)&esp32_ulp_obj;
}
Expand Down Expand Up @@ -91,9 +112,28 @@ STATIC mp_obj_t esp32_ulp_run(mp_obj_t self_in, mp_obj_t entry_point_in)
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_ulp_run_obj, esp32_ulp_run);

/* Initialize selected GPIO as RTC IO, enable input, disable pullup and pulldown */
STATIC mp_obj_t esp32_ulp_init_gpio(mp_obj_t self_in, mp_obj_t gpio_num_in)
{
mp_uint_t gpio_num = mp_obj_get_int(gpio_num_in);

rtc_gpio_init(gpio_num);
rtc_gpio_set_direction(gpio_num, RTC_GPIO_MODE_INPUT_ONLY);
rtc_gpio_pulldown_en(gpio_num);
rtc_gpio_pullup_dis(gpio_num);
rtc_gpio_hold_en(gpio_num);

// instruct to keep RTC peripherals powered on after when in deep sleep
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);

return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_ulp_init_gpio_obj, esp32_ulp_init_gpio);

STATIC const mp_rom_map_elem_t esp32_ulp_locals_dict_table[] = {
{MP_ROM_QSTR(MP_QSTR_set_wakeup_period), MP_ROM_PTR(&esp32_ulp_set_wakeup_period_obj)},
{MP_ROM_QSTR(MP_QSTR_load_binary), MP_ROM_PTR(&esp32_ulp_load_binary_obj)},
{MP_ROM_QSTR(MP_QSTR_init_gpio), MP_ROM_PTR(&esp32_ulp_init_gpio_obj)},
{MP_ROM_QSTR(MP_QSTR_run), MP_ROM_PTR(&esp32_ulp_run_obj)},

#ifdef CONFIG_IDF_TARGET_ESP32
Expand Down

0 comments on commit 33b18e0

Please sign in to comment.