Skip to content

Commit a926445

Browse files
lucasssvazacassis
authored andcommitted
boards: Fix buttons GPIO IRQ on ESP boards
1 parent cd5e536 commit a926445

File tree

10 files changed

+44
-24
lines changed

10 files changed

+44
-24
lines changed

boards/xtensa/esp32/esp32-devkitc/src/esp32_buttons.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ uint32_t board_buttons(void)
130130
int board_button_irq(int id, xcpt_t irqhandler, void *arg)
131131
{
132132
int ret;
133-
DEBUGASSERT(id == BUTTON_BOOT);
133+
DEBUGASSERT(id == 0);
134134

135135
int irq = ESP32_PIN2IRQ(BUTTON_BOOT);
136136

boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_buttons.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ uint32_t board_buttons(void)
130130
int board_button_irq(int id, xcpt_t irqhandler, void *arg)
131131
{
132132
int ret;
133-
DEBUGASSERT(id == BUTTON_BOOT);
133+
DEBUGASSERT(id == 0);
134134

135135
int irq = ESP32_PIN2IRQ(BUTTON_BOOT);
136136

boards/xtensa/esp32/esp32-lyrat/src/esp32_buttons.c

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <stdio.h>
3232

3333
#include <nuttx/arch.h>
34+
#include <arch/board/board.h>
3435
#include <nuttx/board.h>
3536
#include <nuttx/irq.h>
3637
#include <arch/irq.h>
@@ -39,6 +40,24 @@
3940

4041
#include "esp32-lyrat.h"
4142

43+
/****************************************************************************
44+
* Pre-processor Definitions
45+
****************************************************************************/
46+
47+
#ifndef ARRAY_SIZE
48+
# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
49+
#endif
50+
51+
/****************************************************************************
52+
* Private Data
53+
****************************************************************************/
54+
55+
static const int g_buttons[] =
56+
{
57+
BUTTON_REC,
58+
BUTTON_MODE
59+
};
60+
4261
/****************************************************************************
4362
* Public Functions
4463
****************************************************************************/
@@ -56,9 +75,11 @@
5675

5776
uint32_t board_button_initialize(void)
5877
{
59-
esp32_configgpio(BUTTON_MODE, INPUT_FUNCTION_3 | PULLUP);
60-
esp32_configgpio(BUTTON_REC, INPUT_FUNCTION_3 | PULLUP);
61-
return 1;
78+
/* GPIOs 36 and 39 do not support PULLUP/PULLDOWN */
79+
80+
esp32_configgpio(BUTTON_MODE, INPUT_FUNCTION_3);
81+
esp32_configgpio(BUTTON_REC, INPUT_FUNCTION_3);
82+
return NUM_BUTTONS;
6283
}
6384

6485
/****************************************************************************
@@ -77,22 +98,18 @@ uint32_t board_buttons(void)
7798
uint8_t ret = 0;
7899
int n = 0;
79100

80-
const uint8_t btn_id_arr[] =
81-
{
82-
BUTTON_REC,
83-
BUTTON_MODE
84-
};
85-
86-
for (uint8_t btn_id = 0; btn_id < sizeof(btn_id_arr); btn_id++)
101+
for (uint8_t btn_id = 0; btn_id < ARRAY_SIZE(g_buttons); btn_id++)
87102
{
88103
iinfo("Reading button %d\n", btn_id);
89-
bool b0 = esp32_gpioread(btn_id_arr[btn_id]);
104+
105+
const int button_gpio = g_buttons[btn_id];
106+
bool b0 = esp32_gpioread(button_gpio);
90107

91108
for (int i = 0; i < 10; i++)
92109
{
93110
up_mdelay(1); /* TODO */
94111

95-
bool b1 = esp32_gpioread(btn_id_arr[btn_id]);
112+
bool b1 = esp32_gpioread(button_gpio);
96113

97114
if (b0 == b1)
98115
{
@@ -139,8 +156,11 @@ uint32_t board_buttons(void)
139156
#ifdef CONFIG_ARCH_IRQBUTTONS
140157
int board_button_irq(int id, xcpt_t irqhandler, void *arg)
141158
{
159+
DEBUGASSERT(id < ARRAY_SIZE(g_buttons));
160+
142161
int ret;
143-
int irq = ESP32_PIN2IRQ(id);
162+
int pin = g_buttons[id];
163+
int irq = ESP32_PIN2IRQ(pin);
144164

145165
if (NULL != irqhandler)
146166
{
@@ -155,7 +175,7 @@ int board_button_irq(int id, xcpt_t irqhandler, void *arg)
155175
return ret;
156176
}
157177

158-
gpioinfo("Attach %p\n", irqhandler);
178+
gpioinfo("Attach %p to pin %d\n", irqhandler, pin);
159179

160180
gpioinfo("Enabling the interrupt\n");
161181

@@ -165,7 +185,7 @@ int board_button_irq(int id, xcpt_t irqhandler, void *arg)
165185
}
166186
else
167187
{
168-
gpioinfo("Disable the interrupt\n");
188+
gpioinfo("Disabled interrupts from pin %d\n", pin);
169189
esp32_gpioirqdisable(irq);
170190
}
171191

boards/xtensa/esp32/esp32-sparrow-kit/src/esp32_buttons.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ uint32_t board_buttons(void)
130130
int board_button_irq(int id, xcpt_t irqhandler, void *arg)
131131
{
132132
int ret;
133-
DEBUGASSERT(id == BUTTON_BOOT);
133+
DEBUGASSERT(id == 0);
134134

135135
int irq = ESP32_PIN2IRQ(BUTTON_BOOT);
136136

boards/xtensa/esp32/esp32-wrover-kit/src/esp32_buttons.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ uint32_t board_buttons(void)
130130
int board_button_irq(int id, xcpt_t irqhandler, void *arg)
131131
{
132132
int ret;
133-
DEBUGASSERT(id == BUTTON_BOOT);
133+
DEBUGASSERT(id == 0);
134134

135135
int irq = ESP32_PIN2IRQ(BUTTON_BOOT);
136136

boards/xtensa/esp32/lilygo_tbeam_lora_gps/src/esp32_buttons.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ uint32_t board_buttons(void)
130130
int board_button_irq(int id, xcpt_t irqhandler, void *arg)
131131
{
132132
int ret;
133-
DEBUGASSERT(id == BUTTON_BOOT);
133+
DEBUGASSERT(id == 0);
134134

135135
int irq = ESP32_PIN2IRQ(BUTTON_BOOT);
136136

boards/xtensa/esp32/ttgo_eink5_v2/src/esp32_buttons.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ uint32_t board_buttons(void)
132132
int board_button_irq(int id, xcpt_t irqhandler, void *arg)
133133
{
134134
int ret;
135-
DEBUGASSERT(id == BUTTON_BOOT);
135+
DEBUGASSERT(id == 0);
136136

137137
int irq = ESP32_PIN2IRQ(BUTTON_BOOT);
138138

boards/xtensa/esp32/ttgo_lora_esp32/src/esp32_buttons.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ uint32_t board_buttons(void)
130130
int board_button_irq(int id, xcpt_t irqhandler, void *arg)
131131
{
132132
int ret;
133-
DEBUGASSERT(id == BUTTON_BOOT);
133+
DEBUGASSERT(id == 0);
134134

135135
int irq = ESP32_PIN2IRQ(BUTTON_BOOT);
136136

boards/xtensa/esp32/ttgo_t_display_esp32/src/esp32_buttons.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ uint32_t board_buttons(void)
130130
int board_button_irq(int id, xcpt_t irqhandler, void *arg)
131131
{
132132
int ret;
133-
DEBUGASSERT(id == BUTTON_BOOT);
133+
DEBUGASSERT(id == 0);
134134

135135
int irq = ESP32_PIN2IRQ(BUTTON_BOOT);
136136

boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_buttons.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ uint32_t board_buttons(void)
128128
int board_button_irq(int id, xcpt_t irqhandler, void *arg)
129129
{
130130
int ret;
131-
DEBUGASSERT(id == BUTTON_BOOT);
131+
DEBUGASSERT(id == 0);
132132

133133
int irq = ESP32S3_PIN2IRQ(BUTTON_BOOT);
134134

0 commit comments

Comments
 (0)