@@ -19,21 +19,34 @@ extern "C" void app_main(void) {
1919 event.gpio_num , event.active );
2020 };
2121
22+ espp::Interrupt::PinConfig io0 = {
23+ .gpio_num = GPIO_NUM_0,
24+ .callback = callback,
25+ .active_level = espp::Interrupt::ActiveLevel::LOW,
26+ .interrupt_type = espp::Interrupt::Type::ANY_EDGE,
27+ .pullup_enabled = true ,
28+ .pulldown_enabled = false ,
29+ // flexible filter requiring configuration (default is provided as 5us
30+ // threshold in 10us window), but other configurations can be manually
31+ // set as below
32+ .filter_type = espp::Interrupt::FilterType::FLEX_GLITCH_FILTER,
33+ .filter_config = {.window_width_ns = 10000 , .window_threshold_ns = 5000 },
34+ };
35+ espp::Interrupt::PinConfig io12 = {
36+ .gpio_num = GPIO_NUM_12,
37+ .callback = callback,
38+ .active_level = espp::Interrupt::ActiveLevel::LOW,
39+ .interrupt_type = espp::Interrupt::Type::ANY_EDGE,
40+ .pullup_enabled = true ,
41+ .pulldown_enabled = false ,
42+ // pre-configured 2 clock pulse width filter
43+ .filter_type = espp::Interrupt::FilterType::PIN_GLITCH_FILTER,
44+ };
45+
2246 // make an interrupt for a single gpio
2347 {
2448 espp::Interrupt interrupt ({
25- .interrupts =
26- {
27- {
28- .gpio_num = GPIO_NUM_0,
29- .callback = callback,
30- .active_level = espp::Interrupt::ActiveLevel::LOW,
31- .interrupt_type = espp::Interrupt::Type::ANY_EDGE,
32- .pullup_enabled = true ,
33- .pulldown_enabled = false ,
34- .enable_pin_glitch_filter = true ,
35- },
36- },
49+ .interrupts = {io0},
3750 .task_config =
3851 {
3952 .name = " Interrupt task" ,
@@ -48,19 +61,8 @@ extern "C" void app_main(void) {
4861
4962 // make multiple interrupts for multiple gpios
5063 {
51- espp::Interrupt interrupt12 ({
52- .interrupts =
53- {
54- {
55- .gpio_num = GPIO_NUM_0,
56- .callback = callback,
57- .active_level = espp::Interrupt::ActiveLevel::LOW,
58- .interrupt_type = espp::Interrupt::Type::ANY_EDGE,
59- .pullup_enabled = true ,
60- .pulldown_enabled = false ,
61- .enable_pin_glitch_filter = true ,
62- },
63- },
64+ espp::Interrupt interrupt0 ({
65+ .interrupts = {io0},
6466 .task_config =
6567 {
6668 .name = " Interrupt task" ,
@@ -70,19 +72,8 @@ extern "C" void app_main(void) {
7072 .log_level = espp::Logger::Verbosity::DEBUG,
7173 });
7274
73- espp::Interrupt interrupt0 ({
74- .interrupts =
75- {
76- {
77- .gpio_num = GPIO_NUM_12,
78- .callback = callback,
79- .active_level = espp::Interrupt::ActiveLevel::LOW,
80- .interrupt_type = espp::Interrupt::Type::ANY_EDGE,
81- .pullup_enabled = true ,
82- .pulldown_enabled = false ,
83- .enable_pin_glitch_filter = true ,
84- },
85- },
75+ espp::Interrupt interrupt12 ({
76+ .interrupts = {io12},
8677 .task_config =
8778 {
8879 .name = " Interrupt 0 task" ,
@@ -92,26 +83,23 @@ extern "C" void app_main(void) {
9283 .log_level = espp::Logger::Verbosity::DEBUG,
9384 });
9485
95- std::this_thread::sleep_for (5s);
86+ std::this_thread::sleep_for (2s);
87+
88+ // now lets read the instantaneous state of the interrupt pins
89+ auto is_0_active = interrupt0.is_active (io0);
90+ auto is_12_active = interrupt12.is_active (io12);
91+ logger.info (" Instantaneous state of pin 0: {}" , is_0_active);
92+ logger.info (" Instantaneous state of pin 12: {}" , is_12_active);
93+
94+ std::this_thread::sleep_for (2s);
9695 }
9796
9897 // make a single interrupt for multiple GPIOs
9998 // make an interrupt for a single gpio
10099 {
101100 // Register for interrupts on a few pins (GPIO_NUM_0, GPIO_NUM_12)
102101 espp::Interrupt interrupt ({
103- .interrupts =
104- {
105- {
106- .gpio_num = GPIO_NUM_0,
107- .callback = callback,
108- .active_level = espp::Interrupt::ActiveLevel::LOW,
109- .interrupt_type = espp::Interrupt::Type::ANY_EDGE,
110- .pullup_enabled = true ,
111- .pulldown_enabled = false ,
112- .enable_pin_glitch_filter = true ,
113- },
114- },
102+ .interrupts = {io0},
115103 .task_config =
116104 {
117105 .name = " Interrupt task" ,
@@ -122,17 +110,15 @@ extern "C" void app_main(void) {
122110 });
123111
124112 // use the add_interrupt method to add another interrupt
125- interrupt.add_interrupt ({
126- .gpio_num = GPIO_NUM_12,
127- .callback = callback,
128- .active_level = espp::Interrupt::ActiveLevel::LOW,
129- .interrupt_type = espp::Interrupt::Type::ANY_EDGE,
130- .pullup_enabled = true ,
131- .pulldown_enabled = false ,
132- .enable_pin_glitch_filter = true ,
133- });
113+ interrupt.add_interrupt (io12);
134114
135- std::this_thread::sleep_for (5s);
115+ std::this_thread::sleep_for (2s);
116+
117+ // now lets read the instantaneous state of the interrupt pins
118+ auto active_states = interrupt.get_active_states ();
119+ logger.info (" Instantaneous state of pins: {}" , active_states);
120+
121+ std::this_thread::sleep_for (2s);
136122 }
137123
138124 // ! [interrupt example]
0 commit comments