Direct manipulation of GRIO's 32-39 for ESP32

insanoff
Posts: 15
Joined: Sat Aug 10, 2019 9:10 am

Direct manipulation of GRIO's 32-39 for ESP32

Postby insanoff » Wed May 20, 2020 9:26 am

Hi Folks,

I could not find anywhere how to define GRIO's 32-39 using macros. This is how I thought it could be done:

Code: Select all

REG_WRITE(GPIO_IN1_REG, BIT34);
But apparently it is not the case. In gpio.h file it is defined as:

Code: Select all

#define GPIO_SEL_34             ((uint64_t)(((uint64_t)1)<<34))
Definitely I did not understand the idea behind the ESP32 GPIO definition. I would like to know how to define GPIO34 as an input enabling the internal pull down.

Thanks!
Adam

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: Direct manipulation of GRIO's 32-39 for ESP32

Postby ESP_igrr » Wed May 20, 2020 9:39 am

Hi insanoff,

The bits of GPIO_IN_REG map to GPIOs 0-31, and the bits of GPIO_IN1_REG map to GPIOs 32 and up. So to access GPIO32, you need to read bit 0 of GPIO_IN1_REG. Same applies to other GPIO-related registers (output, output enable, etc).

GPIO_SEL_34 macro in gpio.h is useful mainly for the pin_bit_mask member of gpio_config_t structure — it is a 64 bit bit mask which can be used for all GPIOs. If you are not using the GPIO driver and controlling GPIOs directly instead, you don't need to use GPIO_SEL_xx macros.

insanoff
Posts: 15
Joined: Sat Aug 10, 2019 9:10 am

Re: Direct manipulation of GRIO's 32-39 for ESP32

Postby insanoff » Wed May 20, 2020 5:42 pm

ESP_igrr wrote:
Wed May 20, 2020 9:39 am
Hi insanoff,

The bits of GPIO_IN_REG map to GPIOs 0-31, and the bits of GPIO_IN1_REG map to GPIOs 32 and up. So to access GPIO32, you need to read bit 0 of GPIO_IN1_REG. Same applies to other GPIO-related registers (output, output enable, etc).

GPIO_SEL_34 macro in gpio.h is useful mainly for the pin_bit_mask member of gpio_config_t structure — it is a 64 bit bit mask which can be used for all GPIOs. If you are not using the GPIO driver and controlling GPIOs directly instead, you don't need to use GPIO_SEL_xx macros.
Hi ESP_igrr, thank you for the reply.

I am a bit confused. :? What is the difference between "gpio_set_level(GPIO_NUM_5, 1);" and "REG_WRITE(GPIO_OUT_W1TS_REG, BIT5)"? In general, why we have these options and where I can learn about I/O manipulations?

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: Direct manipulation of GRIO's 32-39 for ESP32

Postby ESP_igrr » Wed May 20, 2020 8:25 pm

Not much practical difference between these two, with these specific arguments. The call to gpio_set_level is safer because it can check that the pin number is not out of bounds. It will also keep working on future chips, which may have different GPIO register names. On the other hand, direct register access will be slightly faster.

Who is online

Users browsing this forum: No registered users and 105 guests