esp32-wrover-kit: Don't use User GPIO Subsystem to control LED

The GPIO_LEDx are already used by esp32_userleds.c, they shouldn't
be used by esp32_gpio.c. This patch also includes the GPIO Input
example (GPIN) that was missing.
This commit is contained in:
Alan C. Assis 2021-04-03 09:33:17 -03:00 committed by Xiang Xiao
parent c7c3683845
commit ec1b89e264
2 changed files with 80 additions and 4 deletions

View File

@ -107,7 +107,8 @@
/* GPIO pins used by the GPIO Subsystem */
#define BOARD_NGPIOOUT 3 /* Amount of GPIO Output pins */
#define BOARD_NGPIOIN 1 /* Amount of GPIO Input pins */
#define BOARD_NGPIOOUT 1 /* Amount of GPIO Output pins */
#define BOARD_NGPIOINT 1 /* Amount of GPIO Input w/ Interruption pins */
#endif /* __BOARDS_XTENSA_ESP32_ESP32_WROVER_KIT_INCLUDE_BOARD_H */

View File

@ -48,11 +48,23 @@
# error "NGPIOINT is > 0 and GPIO interrupts aren't enabled"
#endif
/* Output pins. GPIO16 is used as an example, any other outputs could be
* used.
*/
#define GPIO_OUT1 16
/* Input pins. GPIO17 is used as an example, any other inputs could be
* used.
*/
#define GPIO_IN1 17
/* Interrupt pins. GPIO22 is used as an example, any other inputs could be
* used.
*/
#define GPIO_IRQPIN 22
#define GPIO_IRQPIN1 22
/****************************************************************************
* Private Types
@ -79,6 +91,10 @@ static int gpout_read(FAR struct gpio_dev_s *dev, FAR bool *value);
static int gpout_write(FAR struct gpio_dev_s *dev, bool value);
#endif
#if BOARD_NGPIOIN > 0
static int gpin_read(FAR struct gpio_dev_s *dev, FAR bool *value);
#endif
#if BOARD_NGPIOINT > 0
static int gpint_read(FAR struct gpio_dev_s *dev, FAR bool *value);
static int gpint_attach(FAR struct gpio_dev_s *dev,
@ -103,12 +119,31 @@ static const struct gpio_operations_s gpout_ops =
static const uint32_t g_gpiooutputs[BOARD_NGPIOOUT] =
{
GPIO_LED1, GPIO_LED2, GPIO_LED3
GPIO_OUT1
};
static struct esp32gpio_dev_s g_gpout[BOARD_NGPIOOUT];
#endif
#if BOARD_NGPIOIN > 0
static const struct gpio_operations_s gpin_ops =
{
.go_read = gpin_read,
.go_write = NULL,
.go_attach = NULL,
.go_enable = NULL,
};
/* This array maps the GPIO pins used as INTERRUPT INPUTS */
static const uint32_t g_gpioinputs[BOARD_NGPIOIN] =
{
GPIO_IN1
};
static struct esp32gpio_dev_s g_gpin[BOARD_NGPIOIN];
#endif
#if BOARD_NGPIOINT > 0
static const struct gpio_operations_s gpint_ops =
{
@ -122,7 +157,7 @@ static const struct gpio_operations_s gpint_ops =
static const uint32_t g_gpiointinputs[BOARD_NGPIOINT] =
{
GPIO_IRQPIN,
GPIO_IRQPIN1,
};
static struct esp32gpint_dev_s g_gpint[BOARD_NGPIOINT];
@ -166,6 +201,24 @@ static int gpout_write(FAR struct gpio_dev_s *dev, bool value)
}
#endif
/****************************************************************************
* Name: gpin_read
****************************************************************************/
#if BOARD_NGPIOIN > 0
static int gpin_read(FAR struct gpio_dev_s *dev, FAR bool *value)
{
FAR struct esp32gpio_dev_s *esp32gpio = (FAR struct esp32gpio_dev_s *)dev;
DEBUGASSERT(esp32gpio != NULL && value != NULL);
DEBUGASSERT(esp32gpio->id < BOARD_NGPIOIN);
gpioinfo("Reading... pin %d\n", g_gpioinputs[esp32gpio->id]);
*value = esp32_gpioread(g_gpioinputs[esp32gpio->id]);
return OK;
}
#endif
/****************************************************************************
* Name: esp32gpio_interrupt
****************************************************************************/
@ -296,6 +349,28 @@ int esp32_gpio_init(void)
}
#endif
pincount = 0;
#if BOARD_NGPIOIN > 0
for (i = 0; i < BOARD_NGPIOIN; i++)
{
/* Setup and register the GPIO pin */
g_gpin[i].gpio.gp_pintype = GPIO_INPUT_PIN;
g_gpin[i].gpio.gp_ops = &gpin_ops;
g_gpin[i].id = i;
gpio_pin_register(&g_gpin[i].gpio, pincount);
/* Configure the pins that will be used as INPUT */
esp32_configgpio(g_gpioinputs[i], INPUT_FUNCTION_3);
pincount++;
}
#endif
pincount = 0;
#if BOARD_NGPIOINT > 0
for (i = 0; i < BOARD_NGPIOINT; i++)
{