Skip to content

Commit 9d86df9

Browse files
authored
feat(interrupt): Add filter config and state query (#180)
* feat(interrupt): Add filter config and state query * Update interrupt to support configuring flex filter as well as setting glitch filter * Update interrupt to allow querying of active state of interrupt pins * Update interrupt to rename InterruptConfig to PinConfig for clarity * Update interrupt example to better test the different APIs * Update button example accordingly * doc: rebuild
1 parent 2ba3aad commit 9d86df9

File tree

103 files changed

+599
-399
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+599
-399
lines changed

components/button/example/main/button_example.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ extern "C" void app_main(void) {
104104
.interrupt_type = espp::Interrupt::Type::ANY_EDGE,
105105
.pullup_enabled = false,
106106
.pulldown_enabled = false,
107-
.enable_pin_glitch_filter = true,
107+
.filter_type = espp::Interrupt::FilterType::PIN_GLITCH_FILTER,
108108
},
109109
.task_config =
110110
{

components/button/include/button.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class Button : protected Interrupt {
2525

2626
/// \brief The configuration for the button
2727
struct Config {
28-
std::string_view name{"Button"}; ///< Name of the button
29-
InterruptConfig interrupt_config; ///< Configuration for the GPIO interrupt
30-
Task::BaseConfig task_config{}; ///< Configuration for the button task
28+
std::string_view name{"Button"}; ///< Name of the button
29+
Interrupt::PinConfig interrupt_config; ///< Configuration for the GPIO interrupt
30+
Task::BaseConfig task_config{}; ///< Configuration for the button task
3131
espp::Logger::Verbosity log_level = espp::Logger::Verbosity::WARN; ///< Log level for this class
3232
};
3333

components/interrupt/example/main/interrupt_example.cpp

Lines changed: 47 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)