ESP32
[ESP-IDF][ble_hid_device_demo][4] EXT1 Wakup 추가하기
하니_즐거운하루
2024. 1. 12. 15:04
: ble_hid_device_demo 프로젝트에 EXT1 Wakeup 기능을 추가해 보았습니다.
▶ menuconfig 에 "Example Configuration" 추가하기
→ Kconfig.projbuild 파일이 기본적으로 없는 상태 입니다.
→ main/ 아래에 Kconfig.projbuild 파일 추가 및 menu 추가
menu "Example Configuration"
endmenu
→ menuconfig 실행하면 다음처럼 "Example Configuration" 이 추가됩니다.
→ deep_sleep 프로젝트에서 EXT1 관련 내용 복사해 Kconfig.projbuild 에 추가 하기
config EXAMPLE_EXT1_WAKEUP
bool "Enable wakeup from GPIO (ext1)"
default y
depends on SOC_PM_SUPPORT_EXT1_WAKEUP
help
~~중략 ~~
menu "EXT1 wakeup configuration"
visible if EXAMPLE_EXT1_WAKEUP
config EXAMPLE_EXT1_WAKEUP_PIN_1
int "Enable wakeup from PIN_1"
depends on !IDF_TARGET_ESP32
default 2 if !IDF_TARGET_ESP32H2
default 10 if IDF_TARGET_ESP32H2
range 0 7 if IDF_TARGET_ESP32C6
range 7 14 if IDF_TARGET_ESP32H2
range 0 21 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32S3
choice EXAMPLE_EXT1_WAKEUP_PIN_1_SEL
prompt "Enable wakeup from PIN_1"
default EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_2
depends on IDF_TARGET_ESP32
config EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_0
bool "GPIO 0"
config EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_2
bool "GPIO 2"
config EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_4
bool "GPIO 4"
config EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_12
bool "GPIO 12"
config EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_13
bool "GPIO 13"
config EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_14
bool "GPIO 14"
config EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_15
bool "GPIO 15"
config EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_25
bool "GPIO 25"
config EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_26
bool "GPIO 26"
config EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_27
bool "GPIO 27"
config EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_32
bool "GPIO 32"
config EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_33
bool "GPIO 33"
config EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_34
bool "GPIO 34"
config EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_35
bool "GPIO 35"
config EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_36
bool "GPIO 36"
config EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_37
bool "GPIO 37"
config EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_38
bool "GPIO 38"
config EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_39
bool "GPIO 39"
endchoice
config EXAMPLE_EXT1_WAKEUP_PIN_1
int
depends on IDF_TARGET_ESP32
default 0 if EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_0
default 2 if EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_2
default 4 if EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_4
default 12 if EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_12
default 13 if EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_13
default 14 if EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_14
default 15 if EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_15
default 25 if EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_25
default 26 if EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_26
default 27 if EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_27
default 32 if EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_32
default 33 if EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_33
default 34 if EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_34
default 35 if EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_35
default 36 if EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_36
default 37 if EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_37
default 38 if EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_38
default 39 if EXAMPLE_EXT1_WAKEUP_PIN_1_SEL_39
choice EXAMPLE_EXT1_WAKEUP_MODE_SEL
prompt "Select wakeup mode from EXT1"
default ESP_EXT1_WAKEUP_ANY_HIGH
config ESP_EXT1_WAKEUP_ANY_LOW
bool "GPIO any low level"
depends on !IDF_TARGET_ESP32
config ESP_EXT1_WAKEUP_ALL_LOW
bool "GPIO all low level"
depends on IDF_TARGET_ESP32
config ESP_EXT1_WAKEUP_ANY_HIGH
bool "GPIO any high level"
endchoice
config EXAMPLE_EXT1_WAKEUP_MODE
int
default 0 if ESP_EXT1_WAKEUP_ANY_LOW
default 0 if ESP_EXT1_WAKEUP_ALL_LOW
default 1 if ESP_EXT1_WAKEUP_ANY_HIGH
config EXAMPLE_EXT1_USE_INTERNAL_PULLUPS
bool "Use internal pull-up/downs for EXT1 wakeup source"
default n
depends on EXAMPLE_EXT1_WAKEUP
help
~~중략 ~~
endmenu
▶ EXT1 Wakeup 관련 코드 추가하기
→ deep_sleep 프로젝트에서 example_deep_sleep_register_ext1_wakeup() 함수 가져오기
#if CONFIG_EXAMPLE_EXT1_WAKEUP
void example_deep_sleep_register_ext1_wakeup(void)
{
const int ext_wakeup_pin_1 = CONFIG_EXAMPLE_EXT1_WAKEUP_PIN_1;
const uint64_t ext_wakeup_pin_1_mask = 1ULL << ext_wakeup_pin_1;
printf("Enabling EXT1 wakeup on pins GPIO%d \n", ext_wakeup_pin_1);
const esp_sleep_ext1_wakeup_mode_t ext_wakeup_mode = CONFIG_EXAMPLE_EXT1_WAKEUP_MODE;
ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup(ext_wakeup_pin_1_mask, ext_wakeup_mode));
/* If there are no external pull-up/downs, tie wakeup pins to inactive level with internal pull-up/downs via RTC IO
* during deepsleep. However, RTC IO relies on the RTC_PERIPH power domain. Keeping this power domain on will
* increase some power comsumption. However, if we turn off the RTC_PERIPH domain or if certain chips lack the RTC_PERIPH
* domain, we will use the HOLD feature to maintain the pull-up and pull-down on the pins during sleep.*/
#if CONFIG_EXAMPLE_EXT1_USE_INTERNAL_PULLUPS
#if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
if (ext_wakeup_mode) {
ESP_ERROR_CHECK(rtc_gpio_pullup_dis(ext_wakeup_pin_1));
ESP_ERROR_CHECK(rtc_gpio_pulldown_en(ext_wakeup_pin_1));
} else {
ESP_ERROR_CHECK(rtc_gpio_pulldown_dis(ext_wakeup_pin_1));
ESP_ERROR_CHECK(rtc_gpio_pullup_en(ext_wakeup_pin_1));
}
#else
if (ext_wakeup_mode) {
ESP_ERROR_CHECK(gpio_pullup_dis(ext_wakeup_pin_1));
ESP_ERROR_CHECK(gpio_pulldown_en(ext_wakeup_pin_1));
} else {
ESP_ERROR_CHECK(gpio_pulldown_dis(ext_wakeup_pin_1));
ESP_ERROR_CHECK(gpio_pullup_en(ext_wakeup_pin_1));
}
#endif
#endif // CONFIG_EXAMPLE_EXT1_USE_INTERNAL_PULLUPS
}
#endif // CONFIG_EXAMPLE_EXT1_WAKEUP
→ 초기화 루틴중 적당한 위치에 아래코드 추가하면 OK
example_deep_sleep_register_ext1_wakeup();
→ deep_sleep 모드 넣기
esp_deep_sleep_start();
▶ deep_sleep 상태에서 Wakeup에 사용된 GPIO 핀을 High로 올리면 Wakeup 이 발생합니다.
→ Wakeup 로그
suspend_timer_callback: enter suspend
>>>>>>> GPIO_2 번 하이로 올리기
ESP-ROM:esp32c6-20220919
Build:Sep 19 2022
rst:0x5 (SLEEP_WAKEUP),boot:0x6e (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:2
load:0x40875720,len:0x1804
load:0x4086c410,len:0xde0
load:0x4086e610,len:0x2df8
entry 0x4086c41a
I (24) boot: ESP-IDF v5.2-beta1-263-ge49823f10c 2nd stage bootloader
~~ 중략 ~~
I (374) cpu_start: App version: 2af23e7-dirty
I (380) cpu_start: Compile time: Jan 16 2024 11:08:47
I (386) cpu_start: ELF file SHA256: 57fd0e46ad985b01...
I (392) cpu_start: ESP-IDF: v5.2-beta1-263-ge49823f10c
I (398) cpu_start: Min chip rev: v0.0
I (403) cpu_start: Max chip rev: v0.99
I (408) cpu_start: Chip rev: v0.0
I (413) heap_init: Initializing. RAM available for dynamic allocation:
I (420) heap_init: At 4081AE20 len 000617F0 (389 KiB): RAM
I (426) heap_init: At 4087C610 len 00002F54 (11 KiB): RAM
I (432) heap_init: At 50000064 len 00003F84 (15 KiB): RTCRAM
I (439) spi_flash: detected chip: generic
I (443) spi_flash: flash io: dio
W (447) spi_flash: Detected size(8192k) larger than the size in the binary image header(4096k). Using the size in the binary image header.
I (460) sleep: Configure to isolate all GPIO pins in sleep state
I (467) sleep: Enable automatic switching of GPIO sleep configuration
I (474) coexist: coex firmware version: e41c5cb
I (479) coexist: coexist rom version 5b8dcfa
I (484) main_task: Started on CPU0
I (484) main_task: Calling app_main()
~~ 중략 ~~
Enabling EXT1 wakeup on pins GPIO2
반응형