Skip to content

Commit

Permalink
GPIO driver: register all pintypes as generic /dev/gpioN
Browse files Browse the repository at this point in the history
  • Loading branch information
jarivanewijk authored and xiaoxiang781216 committed Dec 10, 2021
1 parent efc949b commit 2e47ef3
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ GPIO9 as an interrupt pin.

At the nsh, we can turn the outputs on and off with the following::

nsh> gpio -o 1 /dev/gpout0
nsh> gpio -o 1 /dev/gpout1
nsh> gpio -o 1 /dev/gpio0
nsh> gpio -o 1 /dev/gpio1

nsh> gpio -o 0 /dev/gpout0
nsh> gpio -o 0 /dev/gpout1
nsh> gpio -o 0 /dev/gpio0
nsh> gpio -o 0 /dev/gpio1

We can use the interrupt pin to send a signal when the interrupt fires::

nsh> gpio -w 14 /dev/gpint2
nsh> gpio -w 14 /dev/gpio2

The pin is configured as a rising edge interrupt, so after issuing the
above command, connect it to 3.3V.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ This is a test for the GPIO driver. It includes the 3 LEDs and one, arbitrary, G
For this example, GPIO22 was used.
At the nsh, we can turn LEDs on and off with the following::

nsh> gpio -o 1 /dev/gpout0
nsh> gpio -o 0 /dev/gpout1
nsh> gpio -o 1 /dev/gpio0
nsh> gpio -o 0 /dev/gpio0

We can use the interrupt pin to send a signal when the interrupt fires::

nsh> gpio -w 14 /dev/gpint0
nsh> gpio -w 14 /dev/gpio2

The pin is configured to as a rising edge interrupt, so after issuing the
above command, connect it to 3.3V.
Expand Down
9 changes: 7 additions & 2 deletions boards/risc-v/esp32c3/esp32c3-devkit/src/esp32c3_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ static int gpint_enable(FAR struct gpio_dev_s *dev, bool enable)

int esp32c3_gpio_init(void)
{
int pincount = 0;
int i;

#if BOARD_NGPIOOUT > 0
Expand All @@ -292,14 +293,16 @@ int esp32c3_gpio_init(void)
g_gpout[i].gpio.gp_pintype = GPIO_OUTPUT_PIN;
g_gpout[i].gpio.gp_ops = &gpout_ops;
g_gpout[i].id = i;
gpio_pin_register(&g_gpout[i].gpio, i);
gpio_pin_register(&g_gpout[i].gpio, pincount);

/* Configure the pins that will be used as output */

esp32c3_gpio_matrix_out(g_gpiooutputs[i], SIG_GPIO_OUT_IDX, 0, 0);
esp32c3_configgpio(g_gpiooutputs[i], OUTPUT_FUNCTION_1 |
INPUT_FUNCTION_1);
esp32c3_gpiowrite(g_gpiooutputs[i], 0);

pincount++;
}
#endif

Expand All @@ -311,11 +314,13 @@ int esp32c3_gpio_init(void)
g_gpint[i].esp32c3gpio.gpio.gp_pintype = GPIO_INTERRUPT_PIN;
g_gpint[i].esp32c3gpio.gpio.gp_ops = &gpint_ops;
g_gpint[i].esp32c3gpio.id = i;
gpio_pin_register(&g_gpint[i].esp32c3gpio.gpio, i);
gpio_pin_register(&g_gpint[i].esp32c3gpio.gpio, pincount);

/* Configure the pins that will be used as interrupt input */

esp32c3_configgpio(g_gpiointinputs[i], INPUT_FUNCTION_1 | PULLDOWN);

pincount++;
}
#endif

Expand Down
13 changes: 10 additions & 3 deletions boards/xtensa/esp32/esp32-devkitc/src/esp32_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ static int gpint_enable(FAR struct gpio_dev_s *dev, bool enable)

int esp32_gpio_init(void)
{
int pincount = 0;
int i;

#if BOARD_NGPIOOUT > 0
Expand All @@ -336,14 +337,16 @@ int esp32_gpio_init(void)
g_gpout[i].gpio.gp_pintype = GPIO_OUTPUT_PIN;
g_gpout[i].gpio.gp_ops = &gpout_ops;
g_gpout[i].id = i;
gpio_pin_register(&g_gpout[i].gpio, i);
gpio_pin_register(&g_gpout[i].gpio, pincount);

/* Configure the pins that will be used as output */

esp32_gpio_matrix_out(g_gpiooutputs[i], SIG_GPIO_OUT_IDX, 0, 0);
esp32_configgpio(g_gpiooutputs[i], OUTPUT_FUNCTION_3 |
INPUT_FUNCTION_3);
esp32_gpiowrite(g_gpiooutputs[i], 0);

pincount++;
}
#endif

Expand All @@ -355,11 +358,13 @@ int esp32_gpio_init(void)
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, 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

Expand All @@ -371,11 +376,13 @@ int esp32_gpio_init(void)
g_gpint[i].esp32gpio.gpio.gp_pintype = GPIO_INTERRUPT_PIN;
g_gpint[i].esp32gpio.gpio.gp_ops = &gpint_ops;
g_gpint[i].esp32gpio.id = i;
gpio_pin_register(&g_gpint[i].esp32gpio.gpio, i);
gpio_pin_register(&g_gpint[i].esp32gpio.gpio, pincount);

/* Configure the pins that will be used as interrupt input */

esp32_configgpio(g_gpiointinputs[i], INPUT_FUNCTION_3 | PULLDOWN);

pincount++;
}
#endif

Expand Down
13 changes: 10 additions & 3 deletions boards/xtensa/esp32/esp32-wrover-kit/src/esp32_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ static int gpint_enable(FAR struct gpio_dev_s *dev, bool enable)

int esp32_gpio_init(void)
{
int pincount = 0;
int i;

#if BOARD_NGPIOOUT > 0
Expand All @@ -336,14 +337,16 @@ int esp32_gpio_init(void)
g_gpout[i].gpio.gp_pintype = GPIO_OUTPUT_PIN;
g_gpout[i].gpio.gp_ops = &gpout_ops;
g_gpout[i].id = i;
gpio_pin_register(&g_gpout[i].gpio, i);
gpio_pin_register(&g_gpout[i].gpio, pincount);

/* Configure the pins that will be used as output */

esp32_gpio_matrix_out(g_gpiooutputs[i], SIG_GPIO_OUT_IDX, 0, 0);
esp32_configgpio(g_gpiooutputs[i], OUTPUT_FUNCTION_3 |
INPUT_FUNCTION_3);
esp32_gpiowrite(g_gpiooutputs[i], 0);

pincount++;
}
#endif

Expand All @@ -355,11 +358,13 @@ int esp32_gpio_init(void)
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, 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

Expand All @@ -371,11 +376,13 @@ int esp32_gpio_init(void)
g_gpint[i].esp32gpio.gpio.gp_pintype = GPIO_INTERRUPT_PIN;
g_gpint[i].esp32gpio.gpio.gp_ops = &gpint_ops;
g_gpint[i].esp32gpio.id = i;
gpio_pin_register(&g_gpint[i].esp32gpio.gpio, i);
gpio_pin_register(&g_gpint[i].esp32gpio.gpio, pincount);

/* Configure the pins that will be used as interrupt input */

esp32_configgpio(g_gpiointinputs[i], INPUT_FUNCTION_3 | PULLDOWN);

pincount++;
}
#endif

Expand Down
13 changes: 10 additions & 3 deletions boards/xtensa/esp32/ttgo_lora_esp32/src/esp32_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ static int gpint_enable(FAR struct gpio_dev_s *dev, bool enable)

int esp32_gpio_init(void)
{
int pincount = 0;
int i;

#if BOARD_NGPIOOUT > 0
Expand All @@ -336,14 +337,16 @@ int esp32_gpio_init(void)
g_gpout[i].gpio.gp_pintype = GPIO_OUTPUT_PIN;
g_gpout[i].gpio.gp_ops = &gpout_ops;
g_gpout[i].id = i;
gpio_pin_register(&g_gpout[i].gpio, i);
gpio_pin_register(&g_gpout[i].gpio, pincount);

/* Configure the pins that will be used as output */

esp32_gpio_matrix_out(g_gpiooutputs[i], SIG_GPIO_OUT_IDX, 0, 0);
esp32_configgpio(g_gpiooutputs[i], OUTPUT_FUNCTION_3 |
INPUT_FUNCTION_3);
esp32_gpiowrite(g_gpiooutputs[i], 0);

pincount++;
}
#endif

Expand All @@ -355,11 +358,13 @@ int esp32_gpio_init(void)
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, 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

Expand All @@ -371,11 +376,13 @@ int esp32_gpio_init(void)
g_gpint[i].esp32gpio.gpio.gp_pintype = GPIO_INTERRUPT_PIN;
g_gpint[i].esp32gpio.gpio.gp_ops = &gpint_ops;
g_gpint[i].esp32gpio.id = i;
gpio_pin_register(&g_gpint[i].esp32gpio.gpio, i);
gpio_pin_register(&g_gpint[i].esp32gpio.gpio, pincount);

/* Configure the pins that will be used as interrupt input */

esp32_configgpio(g_gpiointinputs[i], INPUT_FUNCTION_3 | PULLDOWN);

pincount++;
}
#endif

Expand Down
14 changes: 11 additions & 3 deletions boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ static int gpint_enable(FAR struct gpio_dev_s *dev, bool enable)

int esp32s2_gpio_init(void)
{
int pincount = 0;

#if BOARD_NGPIOOUT > 0
for (int i = 0; i < BOARD_NGPIOOUT; i++)
{
Expand All @@ -412,14 +414,16 @@ int esp32s2_gpio_init(void)
g_gpout[i].gpio.gp_pintype = GPIO_OUTPUT_PIN;
g_gpout[i].gpio.gp_ops = &gpout_ops;
g_gpout[i].id = i;
gpio_pin_register(&g_gpout[i].gpio, i);
gpio_pin_register(&g_gpout[i].gpio, pincount);

/* Configure the pins that will be used as output */

esp32s2_gpio_matrix_out(g_gpiooutputs[i], SIG_GPIO_OUT_IDX, 0, 0);
esp32s2_configgpio(g_gpiooutputs[i], OUTPUT_FUNCTION_1 |
INPUT_FUNCTION_1);
esp32s2_gpiowrite(g_gpiooutputs[i], 0);

pincount++;
}
#endif

Expand All @@ -431,11 +435,13 @@ int esp32s2_gpio_init(void)
g_gpin[i].gpio.gp_pintype = GPIO_INPUT_PIN_PULLDOWN;
g_gpin[i].gpio.gp_ops = &gpin_ops;
g_gpin[i].id = i;
gpio_pin_register(&g_gpin[i].gpio, i);
gpio_pin_register(&g_gpin[i].gpio, pincount);

/* Configure the pins that will be used as interrupt input */

esp32s2_configgpio(g_gpioinputs[i], INPUT_FUNCTION_1 | PULLDOWN);

pincount++;
}
#endif

Expand All @@ -447,11 +453,13 @@ int esp32s2_gpio_init(void)
g_gpint[i].esp32s2gpio.gpio.gp_pintype = GPIO_INTERRUPT_PIN;
g_gpint[i].esp32s2gpio.gpio.gp_ops = &gpint_ops;
g_gpint[i].esp32s2gpio.id = i;
gpio_pin_register(&g_gpint[i].esp32s2gpio.gpio, i);
gpio_pin_register(&g_gpint[i].esp32s2gpio.gpio, pincount);

/* Configure the pins that will be used as interrupt input */

esp32s2_configgpio(g_gpiointinputs[i], INPUT_FUNCTION_1 | PULLDOWN);

pincount++;
}
#endif

Expand Down
Loading

0 comments on commit 2e47ef3

Please sign in to comment.