ESP 32 Pin re-mapping

User avatar
Fuzzyzilla
Posts: 22
Joined: Sun Apr 23, 2017 3:19 am

ESP 32 Pin re-mapping

Postby Fuzzyzilla » Sat May 20, 2017 7:03 pm

Hello!
There is a lot of talk all over the place about the ESP-32's ability to re-map it's internal peripherals to different pins. There is not, however, very much explanation on how to actually do this (in layman's terms, anyway. Sure, there are crazy port-manipulating magic things you can do, but that's not very accessible)...
I know some hardware peripherals, like the DACs, cannot be remapped. But what about the touch sensors? The SD Card?
I'm asking because I've run out of output pins in my project... I am not, however, using the input-only pins, so, could I re-map things like the touch sensors to there instead to gain some extra pins?

If so, how can I do this?

Thanks!

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: ESP 32 Pin re-mapping

Postby WiFive » Sat May 20, 2017 8:46 pm

what about the touch sensors?
No

The SD Card?
No, not until spi mode is supported

ESP_Sprite
Posts: 8926
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP 32 Pin re-mapping

Postby ESP_Sprite » Sun May 21, 2017 5:33 am

Also, in general, it's not that hard. if you use a driver in esp-idf, you actually don't have to do much at all: most drivers will need to be fed the GPIO they act on in the initialization call: just enter any GPIO you want and it will be routed automatically.

If you want to do it manually, these are the steps.

Code: Select all

//Connect the pin to the GPIO matrix.
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[pin_number], PIN_FUNC_GPIO);
//Set the direction. GPIO_MODE_INPUT always makes it an input, GPIO_MODE_OUTPUT always makes it an output, GPIO_MODE_INPUT_OUTPUT lets the peripheral decide what direction it has. You usually want the last one.
gpio_set_direction(bus_config->miso_io_num, GPIO_MODE_INPUT_OUTPUT);
//Connect the output functionality of a peripheral to the pin you want. This allows a peripheral to set the direction of the pin (in case it's configured as GPIO_INPUT_OUTPUT) and set the output value.
gpio_matrix_out(pin_number, io_signal_out, false, false);
//Connect the input functionality of a peripheral to the pin. This allows the peripheral to read the signal indicated from this pin.
gpio_matrix_in(pin_number, io_signal_in, false);
In this example, pin_number is the GPIO pin number. io_signal_in and io_signal_out are values identifying the peripheral and signal you want to route: signal numbers can be found in esp-idf/components/soc/esp32/include/soc/gpio_sig_map.h . Use *_IN_IDX as possible values for io_signal_in, *_OUT_IDX for io_signal_out.

As stated before: if you use a driver included in esp-idf, you don't have to worry about all the above: you can usually just tell the driver which pin you want to use and it'll take care of the signal routing for you. Also, you cannot route all signals this way: analog-ish signals, JTAG signals, SD-card signals and MII (Ethernet) signals do not go through the GPIO matrix and can have no or very little ability to be re-routed.

Does that clarify things a bit?

Who is online

Users browsing this forum: No registered users and 73 guests