help with bundles for GPIO

ulaoulao
Posts: 21
Joined: Thu Jun 13, 2024 6:25 pm

help with bundles for GPIO

Postby ulaoulao » Thu Jun 20, 2024 2:31 pm

Looking at useing my esp32-s3 chip with this code

Code: Select all

// configure GPIO
const int bundleA_gpios[] = {0, 1};
gpio_config_t io_conf = {
    .mode = GPIO_MODE_OUTPUT,
};
for (int i = 0; i < sizeof(bundleA_gpios) / sizeof(bundleA_gpios[0]); i++) {
    io_conf.pin_bit_mask = 1ULL << bundleA_gpios[i];
    gpio_config(&io_conf);
}
// Create bundleA, output only
dedic_gpio_bundle_handle_t bundleA = NULL;
dedic_gpio_bundle_config_t bundleA_config = {
    .gpio_array = bundleA_gpios,
    .array_size = sizeof(bundleA_gpios) / sizeof(bundleA_gpios[0]),
    .flags = {
        .out_en = 1,
    },
};
ESP_ERROR_CHECK(dedic_gpio_new_bundle(&bundleA_config, &bundleA));
I got from https://docs.espressif.com/projects/esp ... _gpio.html


My goal is to change GPIO pins 0 and 1 output levels with it. And I will also need to read the pin states equally as fast as possible. If achievable I want to also change the pin directions with the goal of speed in mind. I need to do some bitbang work and the built in functions are about 30nS a cycle. Looks like the bundling is thew way to go but this example is output only. I'm not following the example or documentation well enough to see how to allow input and output along with setting the direction of the ports ( if possible ) with this method.

I added these defines but not able to change output

Code: Select all

#define HIGH(dedic_io_num)  __asm__ __volatile__ ("ee.set_bit_gpio_out %0" : : "I"(dedic_io_num) : );
#define LOW(dedic_io_num)  __asm__ __volatile__ ("ee.clr_bit_gpio_out %0" : : "I"(dedic_io_num) : );
Last edited by ulaoulao on Thu Jun 20, 2024 7:39 pm, edited 1 time in total.

MicroController
Posts: 1725
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: help with bundles for GPIO

Postby MicroController » Thu Jun 20, 2024 6:56 pm

ulaoulao wrote:
Thu Jun 20, 2024 2:31 pm
this part is a bit confusing
.array_size = sizeof(bundleA_gpios) / sizeof(bundleA_gpios[0]),
why divide by the first pin? In my case 0 ?
This is a common C idiom to have the compiler calculate the number of elements an array has.
Notice the sizeof operator being used. The whole expression yields the number of bytes the array occupies divided by the number of bytes any one item in the array occupies.

ulaoulao
Posts: 21
Joined: Thu Jun 13, 2024 6:25 pm

Re: help with bundles for GPIO

Postby ulaoulao » Thu Jun 20, 2024 9:52 pm

yeah sorry I realized that after I posted it and I think I edited it when you were replying. but the main question is still unresolved.

I did solve me other issue

Ok, turns out its set by bit.
#define HIGH(dedic_io_num) __asm__ __volatile__ ("ee.set_bit_gpio_out %0" : : "I"( bit goes here not pin [/b ) : );

I just had a bad example because they used 1 instead of 1<< 1
Last edited by ulaoulao on Fri Jun 21, 2024 2:55 am, edited 1 time in total.

ulaoulao
Posts: 21
Joined: Thu Jun 13, 2024 6:25 pm

Re: help with bundles for GPIO

Postby ulaoulao » Fri Jun 21, 2024 2:07 am

So last puzzle is how can I do the same thing for setting port direction

MicroController
Posts: 1725
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: help with bundles for GPIO

Postby MicroController » Fri Jun 21, 2024 10:25 am

What do you mean by changing port direction?
Pins can be input and output at the same time, so no need to 'activate' input each time before reading the pin's state.
If you want to effectively tri-state a pin this is equivalent to disabling output of that pin, and enabling output again when needed.
AFAIK, the enable/disable output ("OE") bits reside in the IOMUX peripheral and can only be modfied via the IOMUX, i.e. not 'directly' (/fast) from the CPU like the output of the dedicated GPIO.
Alternatively you may be able to use the IO pin in open-drain mode.

MicroController
Posts: 1725
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: help with bundles for GPIO

Postby MicroController » Fri Jun 21, 2024 10:35 am

Btw, note that the dedicated GPIO driver 'dynamically' allocates the bits in the deciated IO register to IO pins/bundles. If at any point there's more than one 'bundle' acquired, the physical bit number of a given pin in the IO register may change and no longer match the immediate value you used in the inline assembly.

ulaoulao
Posts: 21
Joined: Thu Jun 13, 2024 6:25 pm

Re: help with bundles for GPIO

Postby ulaoulao » Fri Jun 21, 2024 12:22 pm

"Pins can be input and output at the same time," -- Ok a concept I'm not aware of. With AVR you get pull ups while in, or Hi-V when low and in. The output you get dirrect High or low no pullups.

made an image,



so if this chip can do both. I'm guessing we have
activate input high or low pullups/downs
in input mode that's a pull up /down
in output mode is it a virtual like pull up/down? Or like the AVR where its dirrect to +5/ ground
how does it work in both mode?



Looking at the options here I see that now.

GPIO_MODE_DISABLE
GPIO_MODE_INPUT
GPIO_MODE_OUTPUT
GPIO_MODE_OUTPUT_OD <-- I guess this is an open drain, controlled via the pull up? high or floating?
GPIO_MODE_INPUT_OUTPUT_OD <-- I guess this is an open drain, controlled via the pull up? high or floating?
GPIO_MODE_INPUT_OUTPUT <-- I need this

I guess another questions is can I change these modes after I set the bundle? Or do I need to delete and redefine the bundle.

"If at any point there's more than one 'bundle' acquired", the only way that happens is be me calling dedic_gpio_new_bundle right?


thx for the answers.
Attachments
pins.png
pins.png (9.92 KiB) Viewed 1388 times
Last edited by ulaoulao on Fri Jun 21, 2024 12:40 pm, edited 1 time in total.

MicroController
Posts: 1725
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: help with bundles for GPIO

Postby MicroController » Fri Jun 21, 2024 12:40 pm

..._OUTPUT is 'real' output with the ESP connecting either supply voltage (high) or GND (low) to the pin. (a.k.a. 'push-pull')
..._OUTPUT_OD is 'open-drain' output where the ESP basically connects either GND (low) to the pin or 'nothing' (high) (leaving the pin 'floating').
"If at any point there's more than one 'bundle' acquired", the only way that happens is be me calling dedic_gpio_new_bundle right?
Yep. Just be aware of it when/if your project grows :)

MicroController
Posts: 1725
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: help with bundles for GPIO

Postby MicroController » Fri Jun 21, 2024 1:01 pm

I guess another questions is can I change these modes after I set the bundle? Or do I need to delete and redefine the bundle.
It looks like gpio_set_direction() would not affect the signal currently routed to a pin, so I think you should be able to reconfigure the 'direction' without it messing up an existing Dedicated GPIO setup.

ulaoulao
Posts: 21
Joined: Thu Jun 13, 2024 6:25 pm

Re: help with bundles for GPIO

Postby ulaoulao » Fri Jun 21, 2024 1:59 pm

I'm pretty sure it is not possible to do this level of work without an understanding of the questions above. I looked everywhere for a diagram of how the electronics related to the registers and found nothing.

for example

ee.set_bit_gpio_out

what does that register really do? If the input and output can co-exist then we need two registers for that, not one. If this sets the pull up, then the clr_bit_gpio_out must disable it. so how do we set/clr the pull down?

I see cheesiness stuff out there
https://edm.eeworld.com.cn/dk_esp32_s3_ ... ual_cn.pdf

that explained a few resisters with no info.
1.6.9
EE.SET_BIT_GPIO_OUT
EE.CLR_BIT_GPIO_OUT
EE.GET_GPIO_IN

hyper link shows Chinese description is
该指令为 CPU GPIO 专用指令。功能为置位 GPIO_OUT 某些比特。赋值内容取决于 8-bit 立即数 imm256。
google convert says
This instruction is a CPU GPIO-specific instruction. The function is to set certain bits of GPIO_OUT. The assignment content depends on the 8-bit immediate imm256.
Not sure that helps any, Code does not dictate electricity. Components do. So if a bit is changed it must toggle the state of a transistor that connects a pin to something, So if we have pull ups and pull downs that can be used at the same time. You need two registers. A pull up registers and a pull down resister.

so maybe
SET_BIT_GPIO_OUT pull up register for out
CLR_BIT_GPIO_OUT pull down register for out
but then how to clear bits, I can only write a bit. The way is reads, is if Its one register. But we would need two.


in both output input mode, setting the output high, reading the input is kind of pointless because it will also be high same as low. So not sure the point in doing both input and out at the same time.This is the point of toggling the direction. And I need to toggle it fast.

Who is online

Users browsing this forum: Majestic-12 [Bot] and 274 guests