Select one of the symbols to view example projects that use it.
 
Outline
#include <stdio.h>
#include "esp_sleep.h"
#include "ulp_riscv.h"
#include "ulp_main.h"
#include "driver/touch_pad.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#define TOUCH_BUTTON_NUM
button
init_touch_pad()
init_ulp_program()
app_main()
Files
loading...
SourceVuESP-IDF Framework and Examplestouch samplemain/ulp_riscv_touch_example_main.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 *//* ... */ /* ULP RISC-V touch sensor example */ #include <stdio.h> #include "esp_sleep.h" #include "ulp_riscv.h" #include "ulp_main.h" #include "driver/touch_pad.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h"7 includes extern const uint8_t _binary_ulp_main_bin_start[]; extern const uint8_t _binary_ulp_main_bin_end[]; #define TOUCH_BUTTON_NUM 14U static const touch_pad_t button[TOUCH_BUTTON_NUM] = { TOUCH_PAD_NUM1, TOUCH_PAD_NUM2, TOUCH_PAD_NUM3, TOUCH_PAD_NUM4, TOUCH_PAD_NUM5, TOUCH_PAD_NUM6, TOUCH_PAD_NUM7, TOUCH_PAD_NUM8, TOUCH_PAD_NUM9, TOUCH_PAD_NUM10, TOUCH_PAD_NUM11, TOUCH_PAD_NUM12, TOUCH_PAD_NUM13, TOUCH_PAD_NUM14 }{...}; static void init_touch_pad(void) { /* Initialize touch pad peripheral. */ touch_pad_init(); for (int i = 0; i < TOUCH_BUTTON_NUM; i++) { touch_pad_config(button[i]); }{...} /* Denoise setting at TouchSensor 0. */ touch_pad_denoise_t denoise = { /* The bits to be cancelled are determined according to the noise level. */ .grade = TOUCH_PAD_DENOISE_BIT4, .cap_level = TOUCH_PAD_DENOISE_CAP_L4, }{...}; touch_pad_denoise_set_config(&denoise); touch_pad_denoise_enable(); /* Enable touch sensor clock. Work mode is "timer trigger". */ touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); touch_pad_fsm_start(); }{ ... } static void init_ulp_program(void) { esp_err_t err = ulp_riscv_load_binary(_binary_ulp_main_bin_start, (_binary_ulp_main_bin_end - _binary_ulp_main_bin_start)); ESP_ERROR_CHECK(err); /* The first argument is the period index, which is not used by the ULP-RISC-V timer * The second argument is the period in microseconds, which gives a wakeup time period of: 20ms *//* ... */ ulp_set_wakeup_period(0, 20000); /* Start the ULP program */ err = ulp_riscv_run(); ESP_ERROR_CHECK(err); }{ ... } void app_main(void) { /* If user is using USB-serial-jtag then idf monitor needs some time to * re-connect to the USB port. We wait 1 sec here to allow for it to make the reconnection * before we print anything. Otherwise the chip will go back to sleep again before the user * has time to monitor any output. *//* ... */ vTaskDelay(pdMS_TO_TICKS(1000)); esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); /* not a wakeup from ULP, load the firmware */ if (cause != ESP_SLEEP_WAKEUP_ULP) { printf("Not a ULP-RISC-V wakeup, initializing ...\n"); /* Initialize Touch peripheral */ init_touch_pad(); /* Initialize ULP core */ init_ulp_program(); }{...} /* ULP RISC-V detected a touch input */ if (cause == ESP_SLEEP_WAKEUP_ULP) { printf("ULP-RISC-V woke up the main CPU! \n"); uint32_t touch_data = ulp_touch_data; for (int i = 0; i < TOUCH_BUTTON_NUM; i++) { if ((touch_data >> button[i]) & 0x1) { printf("T%d touched\n", button[i]); }{...} }{...} printf("\n"); }{...} /* Go to sleep, only the ULP RISC-V will run */ printf("Entering in deep sleep\n\n"); /* Small delay to ensure the messages are printed */ vTaskDelay(100); /* Keep RTC_PERIPH powered on to keep all touch pad channels active */ esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON); ESP_ERROR_CHECK(esp_sleep_enable_ulp_wakeup()); esp_deep_sleep_start(); }{ ... }
Details