Add gpio_init_mask64 function #2907
No reviewers
Labels
No labels
bazel
bluetooth
board settings
boot_stage2
bug
build
c++
can't reproduce
clang
clib-interface
cmsis
code cleanliness
code size
compiler version issues
cyw43_driver
debug
discussion
documentation
duplicate
dynamic_clock
elf2uf2
enhancement
errata
filesystem
flash layout
floating point
FreeRTOS
hardware_adc
hardware_claim
hardware_clocks
hardware_dma
hardware_exception
hardware_flash
hardware_gpio
hardware_i2c
hardware_irq
hardware_pio
hardware_pwm
hardware_rcp
hardware_rtc
hardware_spi
hardware_sync
hardware_uart
hardware_vreg
hardware_watchdog
hardware_xosc
help wanted
host
IAR
installation
invalid
linker scripts
lto
lwip
mbedtls
missing API
needs reporter detail
networking
newlib
newlib-multicore
non-c
non-cmake
non-gcc
openocd
orphan PR
OS integration
pico_async_context
pico_base
pico_binary_info
pico_flash
picolibc
pico_lwip
pico_malloc
pico_multicore
pico_printf
pico_runtime
pico_stdio
pico_stdio_usb
pico_sync
pico_time
pico_util
pioasm
port
question
review
review2
rtos interop
runtime init
static library
svd
test
tinyusb
vscode
wifi integration
wontfix
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-raspberrypi/pico-sdk!2907
Loading…
Reference in a new issue
No description provided.
Delete branch "gpio_init_mask64"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Add
gpio_init_mask64function mirroring the othermask64/masked64GPIO functions used by RP2350B with more than 32 GPIO's.See #2643
@ -41,23 +41,23 @@ extern "C" {* \brief General Purpose Input/Output (GPIO) API@ -281,29 +281,38 @@ void gpio_deinit(uint gpio) {gpio_set_function(gpio, GPIO_FUNC_NULL);gpio_set_function_maskeddoesProbably makes sense to do the same here?
@ -281,29 +281,38 @@ void gpio_deinit(uint gpio) {gpio_set_function(gpio, GPIO_FUNC_NULL);Similarly,
gpio_set_function_masked64does@ -281,29 +281,38 @@ void gpio_deinit(uint gpio) {gpio_set_function(gpio, GPIO_FUNC_NULL);i reimplemented
@ -281,29 +281,38 @@ void gpio_deinit(uint gpio) {gpio_set_function(gpio, GPIO_FUNC_NULL);i reimplemented
@ -281,29 +281,38 @@ void gpio_deinit(uint gpio) {gpio_set_function(gpio, GPIO_FUNC_NULL);It's only a small optimisation, but is it worth doing:
(or is it better to assume that this function will never be called with an empty
gpio_mask?)@ -281,29 +281,38 @@ void gpio_deinit(uint gpio) {gpio_set_function(gpio, GPIO_FUNC_NULL);Is it worth just doing this, rather than duplicating the code?
Or even just a define?
@ -281,29 +281,38 @@ void gpio_deinit(uint gpio) {gpio_set_function(gpio, GPIO_FUNC_NULL);it is an unlikely parameter and the code still works, so we don't want to increase code size
@ -281,29 +281,38 @@ void gpio_deinit(uint gpio) {gpio_set_function(gpio, GPIO_FUNC_NULL);yeah probably cleaner to #ifdef it in the header - though some people may be sad that the function appears/disappears
@ -281,29 +281,38 @@ void gpio_deinit(uint gpio) {gpio_set_function(gpio, GPIO_FUNC_NULL);Maybe #ifdef it as an inline function in the header, so code using mask64 still compiles, and you can still do type checking? I agree having the mask64 functions disappear entirely would be bad, for anyone writing more universal code.
@ -281,29 +281,38 @@ void gpio_deinit(uint gpio) {gpio_set_function(gpio, GPIO_FUNC_NULL);yeah that's what i'm suggesting - some people may get confused/bitten by the fact that sometimes the outline function exists and sometimes it doesn't too, maybe I'll allow it with a #undef in the gpio.c
@ -281,29 +281,38 @@ void gpio_deinit(uint gpio) {gpio_set_function(gpio, GPIO_FUNC_NULL);actually i changed my mind; #defining one function to another makes the doxygen confusing, so using static inline instead
@ -281,29 +281,38 @@ void gpio_deinit(uint gpio) {gpio_set_function(gpio, GPIO_FUNC_NULL);The condition in the header file is
#if NUM_BANK0_GPIOS <= 32so this line ought to be?
@ -281,29 +281,38 @@ void gpio_deinit(uint gpio) {gpio_set_function(gpio, GPIO_FUNC_NULL);Hmmm...
The implementation of
gpio_init_mask(and alsogpio_init_mask64) simply callsgpio_initin a loop. Butgpio_initdoes:and
gpio_set_dircallsgpio_set_dir_in_masked, andgpio_putcallsgpio_clr_mask.So maybe it'd be more efficient if
gpio_init_maskwas changed to:? 🤔
@ -281,29 +281,38 @@ void gpio_deinit(uint gpio) {gpio_set_function(gpio, GPIO_FUNC_NULL);Yeah, I agree with this - it's presumably a large speedup, given the
set_dir_inandclr_maskcan be single coprocessor instructions@ -281,29 +281,38 @@ void gpio_deinit(uint gpio) {gpio_set_function(gpio, GPIO_FUNC_NULL);nice good catch - presumably applies to 64 bit variant too
@ -281,29 +281,38 @@ void gpio_deinit(uint gpio) {gpio_set_function(gpio, GPIO_FUNC_NULL);This comment probably belongs next to
#if NUM_BANK0_GPIOS > 32rather than here?@ -281,29 +281,38 @@ void gpio_deinit(uint gpio) {gpio_set_function(gpio, GPIO_FUNC_NULL);IMHO this should be
as per my original suggestion. Note that the second parameter to
gpio_set_dir_maskedisn'tGPIO_IN/GPIO_OUT, but a per-gpio direction value. See https://www.raspberrypi.com/documentation/pico-sdk/hardware.html#group_hardware_gpio_1gaa64fdceff54dda03f4427f04c2f9ced2@ -281,29 +281,38 @@ void gpio_deinit(uint gpio) {gpio_set_function(gpio, GPIO_FUNC_NULL);true dat
@ -281,29 +281,38 @@ void gpio_deinit(uint gpio) {gpio_set_function(gpio, GPIO_FUNC_NULL);si
Oops?
@ -295,4 +286,4 @@if (gpio_mask & 1u) {gpio_set_function(i, fn);}gpio_mask >>= 1;Thinking on this some more, I guess you could just iterate between the first-set-bit and last-set-bit by using both
__builtin_ctzand__builtin_ltz, and then you wouldn't need theif (!gpio_mask)check inside the loop-body?And then would
be any more efficient than
?