Skip to content

Commit 34fd679

Browse files
committed
key: split wakeup & sleep key
1 parent f4c8f92 commit 34fd679

File tree

4 files changed

+48
-26
lines changed

4 files changed

+48
-26
lines changed

main/Kconfig.projbuild

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -125,35 +125,57 @@ config ENABLE_WAKEUP_KEY
125125
help
126126
Select this to enable WakeUp Key.
127127

128-
config USE_WAKEUP_KEY_FOR_SLEEP
129-
bool "Use WakeUp Key for Sleep"
130-
default n
131-
depends on ENABLE_WAKEUP_KEY
132-
help
133-
Select whether to use WakeUp Key for Sleep.
134-
135128
config WAKEUP_KEY_HOLD_TIME
136129
int "WakeUp Key Hold Time (ms)"
137-
default 2000
130+
default 1000
138131
depends on ENABLE_WAKEUP_KEY
139132

140-
choice WAKEUP_KEY_MODE
141-
prompt "WakeUp Key Mode"
142-
default WAKEUP_KEY_MODE_LOW
133+
choice WAKEUP_KEY_ACTIVE_LEVEL
134+
prompt "WakeUp Key Active Level"
135+
default WAKEUP_KEY_ACTIVE_LOW
143136
depends on ENABLE_WAKEUP_KEY
144137
help
145-
Select WakeUp Key Mode.
138+
Select WakeUp Key Active Level.
146139

147-
config WAKEUP_KEY_MODE_HIGH
148-
bool "High level is pressed"
149-
config WAKEUP_KEY_MODE_LOW
150-
bool "Low level is pressed"
140+
config WAKEUP_KEY_ACTIVE_HIGH
141+
bool "Active High"
142+
config WAKEUP_KEY_ACTIVE_LOW
143+
bool "Active Low"
151144
endchoice
152145

153146
config WAKEUP_KEY_PIN
154147
int "WakeUp Key Pin"
155148
default 0
156149
depends on ENABLE_WAKEUP_KEY
150+
151+
config ENABLE_SLEEP_KEY
152+
bool "Enable Sleep Key"
153+
default n
154+
help
155+
Select this to enable Sleep Key.
156+
157+
config SLEEP_KEY_HOLD_TIME
158+
int "Sleep Key Hold Time (ms)"
159+
default 1000
160+
depends on ENABLE_SLEEP_KEY
161+
162+
choice SLEEP_KEY_ACTIVE_LEVEL
163+
prompt "Sleep Key Active Level"
164+
default SLEEP_KEY_ACTIVE_LOW
165+
depends on ENABLE_SLEEP_KEY
166+
help
167+
Select Sleep Key Active Level.
168+
169+
config SLEEP_KEY_ACTIVE_HIGH
170+
bool "Active High"
171+
config SLEEP_KEY_ACTIVE_LOW
172+
bool "Active Low"
173+
endchoice
174+
175+
config SLEEP_KEY_PIN
176+
int "Sleep Key Pin"
177+
default 0
178+
depends on ENABLE_SLEEP_KEY
157179
endmenu
158180

159181
menu "Audio Configuration"

main/src/os/core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void os_enter_sleep_mode(void)
2323
{
2424
ESP_LOGI(TAG, "entering sleep mode");
2525

26-
#ifdef CONFIG_WAKEUP_KEY_MODE_LOW
26+
#ifdef CONFIG_WAKEUP_KEY_ACTIVE_LOW
2727
esp_sleep_enable_ext1_wakeup(1ULL << CONFIG_WAKEUP_KEY_PIN, ESP_EXT1_WAKEUP_ALL_LOW);
2828
#else
2929
esp_sleep_enable_ext1_wakeup(1ULL << CONFIG_WAKEUP_KEY_PIN, ESP_EXT1_WAKEUP_ANY_HIGH);
@@ -41,7 +41,7 @@ void core_init(void)
4141
if (esp_sleep_get_wakeup_cause() != ESP_SLEEP_WAKEUP_UNDEFINED) {
4242
vTaskDelayUntil(&xLastWakeTime, CONFIG_WAKEUP_KEY_HOLD_TIME / portTICK_RATE_MS);
4343

44-
#ifdef CONFIG_WAKEUP_KEY_MODE_LOW
44+
#ifdef CONFIG_WAKEUP_KEY_ACTIVE_LOW
4545
if (gpio_get_level(CONFIG_WAKEUP_KEY_PIN) == 0) {
4646
#else
4747
if (gpio_get_level(CONFIG_WAKEUP_KEY_PIN) == 1) {

main/src/os/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void user_init(void)
5555
led_init();
5656
#endif
5757

58-
#ifdef CONFIG_USE_WAKEUP_KEY_FOR_SLEEP
58+
#ifdef CONFIG_ENABLE_SLEEP_KEY
5959
key_init();
6060
#endif
6161

main/src/user/key.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#define TAG "key"
1919

20-
#ifdef CONFIG_USE_WAKEUP_KEY_FOR_SLEEP
20+
#ifdef CONFIG_ENABLE_SLEEP_KEY
2121
static void key_sleep_handle(void)
2222
{
2323
xEventGroupClearBits(user_event_group, KEY_SCAN_BIT);
@@ -33,21 +33,21 @@ static void key_sleep_handle(void)
3333

3434
os_enter_sleep_mode();
3535
}
36-
#endif // CONFIG_USE_WAKEUP_KEY_FOR_SLEEP
36+
#endif // CONFIG_ENABLE_SLEEP_KEY
3737

3838
static void key_task_handle(void *pvParameter)
3939
{
40-
#ifdef CONFIG_USE_WAKEUP_KEY_FOR_SLEEP
40+
#ifdef CONFIG_ENABLE_SLEEP_KEY
4141
uint16_t count[] = {0};
42-
uint8_t gpio_pin[] = {CONFIG_WAKEUP_KEY_PIN};
42+
uint8_t gpio_pin[] = {CONFIG_SLEEP_KEY_PIN};
4343
uint8_t gpio_val[] = {
44-
#ifdef CONFIG_WAKEUP_KEY_MODE_LOW
44+
#ifdef CONFIG_SLEEP_KEY_ACTIVE_LOW
4545
0
4646
#else
4747
1
4848
#endif
4949
};
50-
uint16_t gpio_hold[] = {CONFIG_WAKEUP_KEY_HOLD_TIME};
50+
uint16_t gpio_hold[] = {CONFIG_SLEEP_KEY_HOLD_TIME};
5151
void (*key_handle[])(void) = {key_sleep_handle};
5252

5353
portTickType xLastWakeTime;
@@ -89,7 +89,7 @@ static void key_task_handle(void *pvParameter)
8989

9090
vTaskDelayUntil(&xLastWakeTime, 10 / portTICK_RATE_MS);
9191
}
92-
#endif // CONFIG_USE_WAKEUP_KEY_FOR_SLEEP
92+
#endif // CONFIG_ENABLE_SLEEP_KEY
9393
}
9494

9595
void key_init(void)

0 commit comments

Comments
 (0)