currently I use nrf_gpio_pins_set() and and nrf_gpio_pins_clear() from nrf_gpio.h to set and clear specific GPIO ports, respectively. If I want to change the current state of -say- 4 GPIO ports at once (some of them may be cleared, some of them may be set), how do I do that? It would be important that the change on all pins happens at the same time.
Read the GPIO port to get the current state, set and clear bits in that value, then write it back.
Just as there is a GPIO->OUTSET and a GPIO->OUTCLR register, so there is a GPIO->OUT register you can write to set the whole register at once.
If you want to do this you probably have to bypass the nrf_gpio functions, and write directly to the GPIO registers.
Fortunately it isn't as scary as it sounds ;)
To set/clear many pins at once you can write to the OUTSET or OUTCLR registers in the NRF_GPIO peripheral.
If you want to set and clear many pins at once you have to use the OUT register.
Say you want to set pins P0.08-P0.011 to 0xA you could do it like this:
pin_mask = 0xF << 8;
NRF_GPIO->OUT = (NRF_GPIO->OUT & ~pin_mask) | (0xA << 8);
You can still use the nrf_gpio driver to configure the outputs, and set/clear individual pins.
Thanks RK, thanks Torbjørn,
now I see the idea. If I look at the nrf_gpio_pins_toggle() function, I see how the GPIO->OUT register state read. Is there anything I should be aware of when directly reading/writing the OUT register?
And can I accept both answers? :)
I can't think of any concerns when accessing GPIO->OUT, other than making sure you don't change bits in the register that you are not supposed to change.
There is no way to accept multiple answers unfortunately, but RK's answer already got more upvotes so I suggest you accept that ;)
Thank you both!