Skip to content

Commit 21101b6

Browse files
committed
[ISSUE-17]: code cleanup and doc
1 parent cf7a0ad commit 21101b6

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

examples/0button/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
### Listening on button press event
22

33
This example demonstrates how to set up an ISR on GPIO event.
4+
First, input direction must be enabled on the GPIO pin,
5+
and direct peripherial input must be configured.
6+
Next, the interrupt must be set up (GPIO PIN register).
7+
Finally, ISR has to be assigned to the interrupt (`_xtos_set_interrupt_handler_arg`).
8+
9+
In DPORT, the interrupt channel is assigned to every GPIO interrupts.
10+
Thus, within the ISR (`button_isr`), it must be checked where, on which GPIO has the interrupt occured.
11+
After the interrupt is served, within the ISR, the interrupt status has to be cleared.
412

513
#### Hardware components
614

examples/0button/buttonisr.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,17 @@
3131
// ================ Local function declarations =================
3232
static void _button_init();
3333
static void _button_cycle(uint64_t u64Ticks);
34+
static void _button_isr(void *pvParam);
3435

3536
// =================== Global constants ================
3637
const bool gbStartAppCpu = START_APP_CPU;
3738
const uint16_t gu16Tim00Divisor = TIM0_0_DIVISOR;
3839
const uint64_t gu64tckSchedulePeriod = (CLK_FREQ_HZ / SCHEDULE_FREQ_HZ);
3940

4041
// ==================== Local Data ================
41-
static volatile bool gbLedOn = false;
4242
static const char acMessage[] = "Button pressed.\n";
4343

44-
// Implementation
45-
44+
// ================ Local function definitions =================
4645
IRAM_ATTR static void _button_isr(void *pvParam) {
4746
bool bButtonEvent = gsGPIO.STATUS & (1 << BUTTON_GPIO);
4847
if (bButtonEvent) {
@@ -57,6 +56,8 @@ IRAM_ATTR static void _button_isr(void *pvParam) {
5756
}
5857

5958
static void _button_init() {
59+
// setup iomux & gpio regs
60+
// note: GPIO0 is "preconfigured"
6061
IomuxGpioConfReg rIOMux;
6162
rIOMux.raw = iomux_get_gpioconf(BUTTON_GPIO);
6263
rIOMux.u1FunIE = 1;
@@ -66,6 +67,7 @@ static void _button_init() {
6667
.u5PinIntEn = 5
6768
};
6869
gsGPIO.PIN[BUTTON_GPIO] = sPinReg;
70+
gsGPIO.STATUS_W1TC = (1 << BUTTON_GPIO);
6971

7072
// register ISR and enable it
7173
ECpu eCpu = CPU_PRO;
@@ -74,7 +76,6 @@ static void _button_init() {
7476
*prDportIntMap = INT_CH;
7577
_xtos_set_interrupt_handler_arg(INT_CH, _button_isr, 0);
7678
ets_isr_unmask(1 << INT_CH);
77-
7879
}
7980

8081
static void _button_cycle(uint64_t u64Ticks) {

0 commit comments

Comments
 (0)