Skip to content

arch/risc-v: Add dedicated GPIO support for esp32[-s2|-s3|-c3|-c6|-h2] #16223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion Documentation/platforms/risc-v/esp32c3/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ CAN/TWAI Yes
DMA No
DS No
eFuse Yes Also virtual mode supported
GPIO Yes
GPIO Yes Dedicated GPIO supported
HMAC No
I2C Yes Master and Slave mode supported
I2S Yes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,42 @@ We can use the interrupt pin to send a signal when the interrupt fires::
The pin is configured as a rising edge interrupt, so after issuing the
above command, connect it to 3.3V.

To use dedicated gpio for controling multiple gpio pin at the same time
or having better response time, you need to enable
`CONFIG_ESPRESSIF_DEDICATED_GPIO` option. Dedicated GPIO is suitable
for faster response times required applications like simulate serial/parallel
interfaces in a bit-banging way.
After this option enabled GPIO4 and GPIO5 pins are ready to used as dedicated GPIO pins
as input/output mode. These pins are for example, you can use any pin up to 8 pins for
input and 8 pins for output for dedicated gpio.
To write and read data from dedicated gpio, you need to use
`GPIOC_BUNDLE_WR` and `GPIOC_BUNDLE_RD` commands.

The following snippet demonstrates how to read/write to dedicated GPIO pins:

.. code-block:: C

int fd; = open("/dev/gpio3", O_RDWR);
int rd_val = 0;
struct gpio_bundle_wr_arg_s wr_arg;

wr_arg.mask = 0xffff;
wr_arg.value = 0;
while(1)
{
ioctl(fd, GPIOC_BUNDLE_WR, &wr_arg);
if (toggle == 0)
{
wr_arg.value = 3;
}
else
{
wr_arg.value = 0;
}
ioctl(fd, GPIOC_BUNDLE_RD, &rd_val);
printf("rd_val: %d", rd_val);
}

i2c
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,42 @@ We can use the interrupt pin to send a signal when the interrupt fires::
The pin is configured as a rising edge interrupt, so after issuing the
above command, connect it to 3.3V.

To use dedicated gpio for controling multiple gpio pin at the same time
or having better response time, you need to enable
`CONFIG_ESPRESSIF_DEDICATED_GPIO` option. Dedicated GPIO is suitable
for faster response times required applications like simulate serial/parallel
interfaces in a bit-banging way.
After this option enabled GPIO4 and GPIO5 pins are ready to used as dedicated GPIO pins
as input/output mode. These pins are for example, you can use any pin up to 8 pins for
input and 8 pins for output for dedicated gpio.
To write and read data from dedicated gpio, you need to use
`GPIOC_BUNDLE_WR` and `GPIOC_BUNDLE_RD` commands.

The following snippet demonstrates how to read/write to dedicated GPIO pins:

.. code-block:: C

int fd; = open("/dev/gpio3", O_RDWR);
int rd_val = 0;
struct gpio_bundle_wr_arg_s wr_arg;

wr_arg.mask = 0xffff;
wr_arg.value = 0;
while(1)
{
ioctl(fd, GPIOC_BUNDLE_WR, &wr_arg);
if (toggle == 0)
{
wr_arg.value = 3;
}
else
{
wr_arg.value = 0;
}
ioctl(fd, GPIOC_BUNDLE_RD, &rd_val);
printf("rd_val: %d", rd_val);
}

i2c
---

Expand Down
2 changes: 1 addition & 1 deletion Documentation/platforms/risc-v/esp32c6/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ CAN/TWAI Yes
DMA Yes
ECC No
eFuse Yes
GPIO Yes
GPIO Yes Dedicated GPIO supported
HMAC No
I2C Yes Master and Slave mode supported
I2S Yes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,42 @@ We can use the interrupt pin to send a signal when the interrupt fires::
The pin is configured as a rising edge interrupt, so after issuing the
above command, connect it to 3.3V.

To use dedicated gpio for controling multiple gpio pin at the same time
or having better response time, you need to enable
`CONFIG_ESPRESSIF_DEDICATED_GPIO` option. Dedicated GPIO is suitable
for faster response times required applications like simulate serial/parallel
interfaces in a bit-banging way.
After this option enabled GPIO4 and GPIO5 pins are ready to used as dedicated GPIO pins
as input/output mode. These pins are for example, you can use any pin up to 8 pins for
input and 8 pins for output for dedicated gpio.
To write and read data from dedicated gpio, you need to use
`GPIOC_BUNDLE_WR` and `GPIOC_BUNDLE_RD` commands.

The following snippet demonstrates how to read/write to dedicated GPIO pins:

.. code-block:: C

int fd; = open("/dev/gpio3", O_RDWR);
int rd_val = 0;
struct gpio_bundle_wr_arg_s wr_arg;

wr_arg.mask = 0xffff;
wr_arg.value = 0;
while(1)
{
ioctl(fd, GPIOC_BUNDLE_WR, &wr_arg);
if (toggle == 0)
{
wr_arg.value = 3;
}
else
{
wr_arg.value = 0;
}
ioctl(fd, GPIOC_BUNDLE_RD, &rd_val);
printf("rd_val: %d", rd_val);
}

i2c
---

Expand Down
2 changes: 1 addition & 1 deletion Documentation/platforms/risc-v/esp32h2/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ DMA Yes
DS No
ECC No
eFuse Yes
GPIO Yes
GPIO Yes Dedicated GPIO supported
HMAC No
I2C Yes Master and Slave mode supported
I2S Yes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,36 @@ At the nsh, we can turn the GPIO output on and off with the following::
nsh> gpio -o 1 /dev/gpio0
nsh> gpio -o 0 /dev/gpio0

To use dedicated gpio, you need to enable `CONFIG_ESPRESSIF_DEDICATED_GPIO` option.
After this option enabled GPIO6 and GPIO5 pins are ready to used as dedicated GPIO pins
as input/output mode. To write and read data from dedicated gpio, you need to use
`GPIOC_BUNDLE_WR` and `GPIOC_BUNDLE_RD` commands.

The following snippet demonstrates how to read/write to dedicated GPIO pins:

.. code-block:: C
int fd; = open("/dev/gpio3", O_RDWR);
int rd_val = 0;
struct gpio_bundle_wr_arg_s wr_arg;
wr_arg.mask = 0xffff;
wr_arg.value = 0;
while(1)
{
ioctl(fd, GPIOC_BUNDLE_WR, &wr_arg);
if (toggle == 0)
{
wr_arg.value = 3;
}
else
{
wr_arg.value = 0;
}
ioctl(fd, GPIOC_BUNDLE_RD, &rd_val);
printf("rd_val: %d", rd_val);
}
i2c
---

Expand Down
2 changes: 1 addition & 1 deletion Documentation/platforms/xtensa/esp32s2/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ CAN/TWAI Yes
DAC No
DMA Yes
eFuse Yes
GPIO Yes
GPIO Yes Dedicated GPIO supported
I2C Yes Master and Slave mode supported
I2S Yes
LED/PWM Yes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,42 @@ interrupt fires::
The pin is configured to trigger an interrupt on the rising edge, so after
issuing the above command, connect it to 3.3V.

To use dedicated gpio for controling multiple gpio pin at the same time
or having better response time, you need to enable
`CONFIG_ESPRESSIF_DEDICATED_GPIO` option. Dedicated GPIO is suitable
for faster response times required applications like simulate serial/parallel
interfaces in a bit-banging way.
After this option enabled GPIO4 and GPIO5 pins are ready to used as dedicated GPIO pins
as input/output mode. These pins are for example, you can use any pin up to 8 pins for
input and 8 pins for output for dedicated gpio.
To write and read data from dedicated gpio, you need to use
`GPIOC_BUNDLE_WR` and `GPIOC_BUNDLE_RD` commands.

The following snippet demonstrates how to read/write to dedicated GPIO pins:

.. code-block:: C
int fd; = open("/dev/gpio3", O_RDWR);
int rd_val = 0;
struct gpio_bundle_wr_arg_s wr_arg;
wr_arg.mask = 0xffff;
wr_arg.value = 0;
while(1)
{
ioctl(fd, GPIOC_BUNDLE_WR, &wr_arg);
if (toggle == 0)
{
wr_arg.value = 3;
}
else
{
wr_arg.value = 0;
}
ioctl(fd, GPIOC_BUNDLE_RD, &rd_val);
printf("rd_val: %d", rd_val);
}
i2c
---

Expand Down
2 changes: 1 addition & 1 deletion Documentation/platforms/xtensa/esp32s3/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ Camera No
CAN/TWAI Yes
DMA Yes
eFuse Yes
GPIO Yes
GPIO Yes Dedicated GPIO supported
I2C Yes Master and Slave mode supported
I2S Yes
LCD No
Expand Down
6 changes: 6 additions & 0 deletions arch/risc-v/src/common/espressif/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@ config ESPRESSIF_USBSERIAL
select OTHER_UART_SERIALDRIVER
select ARCH_HAVE_SERIAL_TERMIOS

config ESPRESSIF_DEDICATED_GPIO
bool "Dedicated GPIO"
default n
---help---
Enable dedicated GPIO support for faster response time

config ESPRESSIF_GPIO_IRQ
bool "GPIO pin interrupts"
default n
Expand Down
4 changes: 4 additions & 0 deletions arch/risc-v/src/common/espressif/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ ifeq ($(CONFIG_ESP_RMT),y)
endif
endif

ifeq ($(CONFIG_ESPRESSIF_DEDICATED_GPIO),y)
CHIP_CSRCS += esp_dedic_gpio.c
endif

ifeq ($(CONFIG_ESPRESSIF_TEMP),y)
CHIP_CSRCS += esp_temperature_sensor.c
endif
Expand Down
Loading
Loading