The API was based on the assumption that GPIO ports are mapped in memory
sanely, so that a `GPIO_PORT(num)` macro would work allow for constant
folding when `num` is known and still be efficient when it is not.
Some MCUs, however, will need a look up tables to efficiently translate
GPIO port numbers to the port's base address. This will prevent the use
of such a `GPIO_PORT(num)` macro in constant initializers.
As a result, we rather provide `GPIO_PORT_0`, `GPIO_PORT_1`, etc. macros
for each GPIO port present (regardless of MCU naming scheme), as well as
`GPIO_PORT_A`, `GPIO_PORT_B`, etc. macros if (and only if) the MCU port
naming scheme uses letters rather than numbers.
These can be defined as macros to the peripheral base address even when
those are randomly mapped into the address space. In addition, a C
function `gpio_port()` replaces the role of the `GPIO_PORT()` and
`gpio_port_num()` the `GPIO_PORT_NUM()` macro. Those functions will
still be implemented as efficient as possible and will allow constant
folding where it was formerly possible. Hence, there is no downside for
MCUs with sane peripheral memory mapping, but it is highly beneficial
for the crazy ones.
There are also two benefits for the non-crazy MCUs:
1. We can now test for valid port numbers with `#ifdef GPIO_PORT_<NUM>`
- This directly benefits the test in `tests/periph/gpio_ll`, which
can now provide a valid GPIO port for each and every board
- Writing to invalid memory mapped I/O addresses was treated as
triggering undefined behavior by the compiler and used as a
optimization opportunity
2. We can now detect at compile time if the naming scheme of the MCU
uses letters or numbers, and produce more user friendly output.
- This is directly applied in the test app
Test for periph/gpio_ll
This application will use two output and two input GPIOs, which have to be connected via a jumper wire. The test will change the value of the two pins output pins and use the input pins to read the value back in. If the value read doesn't match the expected result, the test aborts and fails.
If IRQ support is provided, the test will additionally walk through every IRQ configuration for the first GPIO pin given and iterate over any trigger condition possible. It will check that edge trigger and (if supported) level trigger IRQs trigger exactly on the configured triggers.
Configuration
Configure in the Makefile or set via environment variables the number of
the output GPIO port to use via the PORT_OUT variable. The PIN_OUT_0 and
PIN_OUT_1 variables select the pins to use within that GPIO port. The input
GPIO port is set via PORT_IN. Both PORT_IN == PORT_OUT and
PORT_IN != PORT_OUT is valid. The input pin number within PORT_IN are set
via PIN_IN_0 and PIN_IN_1. PIN_IN_0 has to be wired to PIN_OUT_0, and
PIN_IN_1 to PIN_OUT_1.
Expected Failures
Implementations are allowed to not electrically disconnect GPIO pins in state
GPIO_DISCONNECT. The test will however test for pins to be electrically
disconnected. For every MCU supported by GPIO LL so far at least some pins can
be electrically disconnected. You might need to change the GPIO pins tested
if the test for disconnected GPIOs being also electrically disconnected.
When features such as periph_gpio_ll_pull_up or periph_gpio_ll_open_drain
are provided, this test expect those to be available on the tested pins. If
those features are not available on all pins, suitable pins need to be
selected for the test to pass.