Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers/periph_gpio_ll: Implement API to switch direction #20292

Merged
merged 4 commits into from
Feb 5, 2024

Conversation

maribu
Copy link
Member

@maribu maribu commented Jan 23, 2024

Contribution description

This adds two functions:

void gpio_ll_switch_dir_output(gpio_port_t port, uword_t outputs);
void gpio_ll_switch_dir_input(gpio_port_t port, uword_t inputs);

The first configures GPIO pins specified by a bitmask as output, the second configures the specified pins as input.

The main use case is to allow bit-banging bidirectional protocols using more basic GPIO peripherals that do not implement open drain mode, such as found e.g. on MSP430, ATmega, or SAM0.

It is not intended to implement this feature on modern MCUs with sophisticated GPIO peripherals.

This PR provides implementations for ATmega and SAM0, the only two GPIO peripherals currently supported by GPIO LL that lack open drain mode.

Testing procedure

The GPIO LL test was extended to also test for switching the direction, if supported.

make BOARD=samr21-xpro flash test-with-config -j
Building application "tests_gpio_ll" for "samr21-xpro" with MCU "samd21".

"make" -C /home/maribu/Repos/software/RIOT/master/pkg/cmsis/ 
"make" -C /home/maribu/Repos/software/RIOT/master/boards/common/init
"make" -C /home/maribu/Repos/software/RIOT/master/boards/samr21-xpro
"make" -C /home/maribu/Repos/software/RIOT/master/core
"make" -C /home/maribu/Repos/software/RIOT/master/core/lib
"make" -C /home/maribu/Repos/software/RIOT/master/cpu/samd21
"make" -C /home/maribu/Repos/software/RIOT/master/drivers
"make" -C /home/maribu/Repos/software/RIOT/master/sys
"make" -C /home/maribu/Repos/software/RIOT/master/drivers/periph_common
"make" -C /home/maribu/Repos/software/RIOT/master/cpu/cortexm_common
"make" -C /home/maribu/Repos/software/RIOT/master/cpu/sam0_common
"make" -C /home/maribu/Repos/software/RIOT/master/sys/auto_init
"make" -C /home/maribu/Repos/software/RIOT/master/cpu/samd21/periph
"make" -C /home/maribu/Repos/software/RIOT/master/sys/div
"make" -C /home/maribu/Repos/software/RIOT/master/cpu/samd21/vectors
"make" -C /home/maribu/Repos/software/RIOT/master/sys/frac
"make" -C /home/maribu/Repos/software/RIOT/master/sys/isrpipe
"make" -C /home/maribu/Repos/software/RIOT/master/cpu/sam0_common/periph
"make" -C /home/maribu/Repos/software/RIOT/master/sys/libc
"make" -C /home/maribu/Repos/software/RIOT/master/sys/malloc_thread_safe
"make" -C /home/maribu/Repos/software/RIOT/master/sys/newlib_syscalls_default
"make" -C /home/maribu/Repos/software/RIOT/master/sys/pm_layered
"make" -C /home/maribu/Repos/software/RIOT/master/sys/preprocessor
"make" -C /home/maribu/Repos/software/RIOT/master/sys/stdio_uart
"make" -C /home/maribu/Repos/software/RIOT/master/sys/test_utils/interactive_sync
"make" -C /home/maribu/Repos/software/RIOT/master/sys/test_utils/print_stack_usage
"make" -C /home/maribu/Repos/software/RIOT/master/sys/tsrb
"make" -C /home/maribu/Repos/software/RIOT/master/sys/ztimer
"make" -C /home/maribu/Repos/software/RIOT/master/cpu/cortexm_common/periph
   text	  data	   bss	   dec	   hex	filename
  22012	   176	  2708	 24896	  6140	/home/maribu/Repos/software/RIOT/master/tests/periph/gpio_ll/bin/samr21-xpro/tests_gpio_ll.elf
/home/maribu/Repos/software/RIOT/master/dist/tools/edbg/edbg.sh flash /home/maribu/Repos/software/RIOT/master/tests/periph/gpio_ll/bin/samr21-xpro/tests_gpio_ll.bin
### Flashing Target ###
Debugger: ATMEL EDBG CMSIS-DAP ATML2127031800009225 03.25.01B6 (S)
Clock frequency: 16.0 MHz
Target: SAM R21G18 (Rev C)
Verification...
at address 0x4 expected 0x6d, read 0x15
Error: verification failed
Debugger: ATMEL EDBG CMSIS-DAP ATML2127031800009225 03.25.01B6 (S)
Clock frequency: 16.0 MHz
Target: SAM R21G18 (Rev C)
Programming...... done.
Verification...... done.
Done flashing
r
/home/maribu/Repos/software/RIOT/master/dist/tools/pyterm/pyterm -p "/dev/ttyACM0" -b "115200" --no-reconnect --noprefix --no-repeat-command-on-empty-line 
Connect to serial port /dev/ttyACM0
Welcome to pyterm!
Type '/exit' to exit.
READY
s
START
main(): This is RIOT! (Version: 2024.01-devel-683-g93372-drivers/periph/gpio_ll/switch_dir)
Test / Hardware Details:
========================
Cabling:
(INPUT -- OUTPUT)
  P1.23 (PB23) -- P0.8 (PA8)
  P1.2 (PB2) -- P0.14 (PA14)
Number of pull resistor values supported: 1
Number of drive strengths supported: 2
Number of slew rates supported: 1
Valid GPIO ports:
- PORT 0 (PORT A)
- PORT 1 (PORT B)
- PORT 2 (PORT C)

Testing gpio_port_pack_addr()
=============================

All OK

Testing gpip_ng_init()
======================

Testing is_gpio_port_num_valid() is true for PORT_OUT and PORT_IN:

Testing input configurations for PIN_IN_0:
Support for input with pull up: yes
state: in, pull: up, value: on, drive: weak
Support for input with pull down: yes
state: in, pull: down, value: off, drive: weak
Support for input with pull to bus level: no
Support for floating input (no pull resistors): yes
state: in, pull: none, value: off, drive: weak

Testing output configurations for PIN_OUT_0:
Support for output (push-pull) with initial value of LOW: yes
state: out-pp, value: off, drive: weak
Output is indeed LOW: yes
state: out-pp, value: on, drive: weak
Output can be pushed HIGH: yes
Support for output (push-pull) with initial value of HIGH: yes
state: out-pp, value: on, drive: weak
Output is indeed HIGH: yes
Support for output (open drain with pull up) with initial value of LOW: no
Support for output (open drain with pull up) with initial value of HIGH: no
Support for output (open drain) with initial value of LOW: no
Support for output (open drain) with initial value of HIGH: no
Support for output (open source) with initial value of LOW: no
Support for output (open source) with initial value of HIGH: no
Support for output (open source with pull down) with initial value of HIGH: no
Support for output (open source with pull down) with initial value of LOW: no

Support for disconnecting GPIO: yes
state: off, pull: none, value: off, drive: weak
Output can indeed be pulled LOW: yes
Output can indeed be pulled HIGH: yes

Testing Reading/Writing GPIO Ports
==================================

testing initial value of 0 after init
...OK
testing setting both outputs_optional simultaneously
...OK
testing clearing both outputs_optional simultaneously
...OK
testing toggling first output (0 --> 1)
...OK
testing toggling first output (1 --> 0)
...OK
testing toggling second output (0 --> 1)
...OK
testing toggling second output (1 --> 0)
...OK
testing setting first output and clearing second with write
...OK
testing setting second output and clearing first with write
...OK
All input/output operations worked as expected

Testing External IRQs
=====================

Testing rising edge on PIN_IN_0
... OK
Testing falling edge on PIN_IN_0
... OK
Testing both edges on PIN_IN_0
... OK
Testing masking of IRQs (still both edges on PIN_IN_0)
... OK
Testing level-triggered on HIGH on PIN_IN_0 (when input is LOW when setting up IRQ)
... OK
Testing level-triggered on HIGH on PIN_IN_0 (when input is HIGH when setting up IRQ)
... OK
Testing level-triggered on LOW on PIN_IN_0 (when input is HIGH when setting up IRQ)
... OK
Testing level-triggered on LOW on PIN_IN_0 (when input is LOW when setting up IRQ)
... OK

Testing Switching Direction
===========================

Input pin can be switched to output (push-pull) mode: yes
Pin behaves as output after switched to output mode: yes
Returning back to input had no side effects on config: yes
Pin behaves as input after switched back to input mode: yes


TEST SUCCEEDED

Issues/PRs references

Depends on and includes: #20290

@maribu maribu added Type: new feature The issue requests / The PR implemements a new feature for RIOT State: waiting for other PR State: The PR requires another PR to be merged first CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jan 23, 2024
@github-actions github-actions bot added Platform: ARM Platform: This PR/issue effects ARM-based platforms Area: doc Area: Documentation Area: tests Area: tests and testing framework Platform: AVR Platform: This PR/issue effects AVR-based platforms Area: drivers Area: Device drivers Platform: ESP Platform: This PR/issue effects ESP-based platforms Area: cpu Area: CPU/MCU ports labels Jan 23, 2024
@riot-ci
Copy link

riot-ci commented Jan 23, 2024

Murdock results

✔️ PASSED

06a0537 cpu/sam0_common: Implement gpio_ll_switch_dir

Success Failures Total Runtime
8626 0 8627 08m:18s

Artifacts

@maribu maribu changed the title drivers/periph_gpio_ll: Implement API to swicht direction drivers/periph_gpio_ll: Implement API to switch direction Jan 24, 2024
@maribu maribu force-pushed the drivers/periph/gpio_ll/switch_dir branch from 9337249 to 8abf4eb Compare February 5, 2024 09:48
@github-actions github-actions bot removed Area: doc Area: Documentation Platform: ESP Platform: This PR/issue effects ESP-based platforms labels Feb 5, 2024
@maribu maribu added Area: doc Area: Documentation Platform: ESP Platform: This PR/issue effects ESP-based platforms and removed State: waiting for other PR State: The PR requires another PR to be merged first labels Feb 5, 2024
@maribu maribu removed Area: doc Area: Documentation Platform: ESP Platform: This PR/issue effects ESP-based platforms labels Feb 5, 2024
This adds two functions:

    void gpio_ll_switch_dir_output(gpio_port_t port, uword_t outputs);
    void gpio_ll_switch_dir_input(gpio_port_t port, uword_t inputs);

The first configures GPIO pins specified by a bitmask as output, the
second configures the specified pins as input.

The main use case is to allow bit-banging bidirectional protocols using
more basic GPIO peripherals that do not implement open drain mode, such
as found e.g. on MSP430, ATmega, or SAM0.

It is not intended to implement this feature on modern MCUs with
sophisticated GPIO peripherals.
@maribu maribu force-pushed the drivers/periph/gpio_ll/switch_dir branch from 8abf4eb to 06a0537 Compare February 5, 2024 09:56
@benpicco benpicco added this pull request to the merge queue Feb 5, 2024
Merged via the queue into RIOT-OS:master with commit 6deca8b Feb 5, 2024
26 checks passed
@maribu maribu deleted the drivers/periph/gpio_ll/switch_dir branch February 5, 2024 13:37
@maribu
Copy link
Member Author

maribu commented Feb 5, 2024

Thx :-)

@MrKevinWeiss MrKevinWeiss added this to the Release 2024.04 milestone Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: cpu Area: CPU/MCU ports Area: drivers Area: Device drivers Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ARM Platform: This PR/issue effects ARM-based platforms Platform: AVR Platform: This PR/issue effects AVR-based platforms Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants