Skip to content

Commit 87acbf4

Browse files
authored
Update and rename lp_core_pulse_counter_example_main.c to lp_core_gpio_wake_up_example_main.c
1 parent b9fae93 commit 87acbf4

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

examples/espidf-ulp-lp/src/lp_core_pulse_counter_example_main.c renamed to examples/espidf-ulp-lp/src/lp_core_gpio_wake_up_example_main.c

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* SPDX-License-Identifier: Unlicense OR CC0-1.0
55
*/
6-
/* LP core gpio example
6+
/* ULP LP-Core GPIO wake-up example
77
88
This example code is in the Public Domain (or CC0 licensed, at your option.)
99
@@ -13,22 +13,30 @@
1313
*/
1414

1515
#include <stdio.h>
16-
#include <inttypes.h>
1716
#include "esp_sleep.h"
18-
#include "driver/gpio.h"
1917
#include "driver/rtc_io.h"
20-
#include "freertos/FreeRTOS.h"
21-
#include "freertos/task.h"
2218
#include "ulp_lp_core.h"
2319
#include "ulp_main.h"
24-
#include "lp_core_uart.h"
20+
#include "freertos/FreeRTOS.h"
21+
#include "freertos/task.h"
22+
23+
#define WAKEUP_PIN 2
2524

2625
extern const uint8_t ulp_main_bin_start[] asm("_binary_ulp_main_bin_start");
2726
extern const uint8_t ulp_main_bin_end[] asm("_binary_ulp_main_bin_end");
2827

29-
3028
static void init_ulp_program(void);
3129

30+
static void wakeup_gpio_init(void)
31+
{
32+
/* Configure the button GPIO as input, enable wakeup */
33+
rtc_gpio_init(WAKEUP_PIN);
34+
rtc_gpio_set_direction(WAKEUP_PIN, RTC_GPIO_MODE_INPUT_ONLY);
35+
rtc_gpio_pulldown_dis(WAKEUP_PIN);
36+
rtc_gpio_pullup_en(WAKEUP_PIN);
37+
rtc_gpio_wakeup_enable(WAKEUP_PIN, GPIO_INTR_NEGEDGE);
38+
}
39+
3240
void app_main(void)
3341
{
3442
/* If user is using USB-serial-jtag then idf monitor needs some time to
@@ -38,46 +46,39 @@ void app_main(void)
3846
*/
3947
vTaskDelay(pdMS_TO_TICKS(1000));
4048

41-
/* Initialize selected GPIO as RTC IO, enable input/output, disable pullup and pulldown */
42-
printf("Using pin %d as pulse counter input\n", CONFIG_EXAMPLE_PULSE_COUNT_PIN);
43-
rtc_gpio_init(CONFIG_EXAMPLE_PULSE_COUNT_PIN);
44-
rtc_gpio_set_direction(CONFIG_EXAMPLE_PULSE_COUNT_PIN, RTC_GPIO_MODE_INPUT_OUTPUT);
45-
rtc_gpio_pulldown_dis(CONFIG_EXAMPLE_PULSE_COUNT_PIN);
46-
rtc_gpio_pullup_dis(CONFIG_EXAMPLE_PULSE_COUNT_PIN);
47-
48-
printf("ULP will wake up processor after every %d pulses\n", CONFIG_EXAMPLE_PULSE_COUNT_WAKEUP_LIMIT);
49+
wakeup_gpio_init();
4950

5051
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
5152
/* not a wakeup from ULP, load the firmware */
5253
if (cause != ESP_SLEEP_WAKEUP_ULP) {
5354
printf("Not a ULP wakeup, initializing it! \n");
5455
init_ulp_program();
55-
} else {
56-
printf("ULP woke up the main CPU!\n");
57-
printf("Pulse count: %"PRIu32"\n", ulp_pulse_count);
56+
}
57+
58+
/* ULP read and detected a change in WAKEUP_PIN, prints */
59+
if (cause == ESP_SLEEP_WAKEUP_ULP) {
60+
printf("ULP woke up the main CPU! \n");
5861
}
5962

6063
/* Go back to sleep, only the ULP will run */
61-
printf("Entering in deep sleep\n\n");
64+
printf("Entering deep sleep\n\n");
6265

6366
/* Small delay to ensure the messages are printed */
67+
vTaskDelay(100 / portTICK_PERIOD_MS);
68+
6469
ESP_ERROR_CHECK( esp_sleep_enable_ulp_wakeup());
6570

6671
esp_deep_sleep_start();
6772
}
6873

6974
static void init_ulp_program(void)
7075
{
71-
lp_core_uart_cfg_t uart_cfg = LP_CORE_UART_DEFAULT_CONFIG();
72-
73-
ESP_ERROR_CHECK(lp_core_uart_init(&uart_cfg));
74-
7576
esp_err_t err = ulp_lp_core_load_binary(ulp_main_bin_start, (ulp_main_bin_end - ulp_main_bin_start));
7677
ESP_ERROR_CHECK(err);
7778

7879
/* Start the program */
7980
ulp_lp_core_cfg_t cfg = {
80-
.wakeup_source = ULP_LP_CORE_WAKEUP_SOURCE_HP_CPU,
81+
.wakeup_source = ULP_LP_CORE_WAKEUP_SOURCE_LP_IO,
8182
};
8283

8384
err = ulp_lp_core_run(&cfg);

0 commit comments

Comments
 (0)