mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
36e8526046
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
63 lines
1.7 KiB
Makefile
63 lines
1.7 KiB
Makefile
BOARD ?= nucleo-f767zi
|
|
|
|
# Custom per-board pin configuration (e.g. for setting PORT_IN, PIN_IN_0, ...)
|
|
# can be provided in a Makefile.$(BOARD) file:
|
|
-include Makefile.$(BOARD)
|
|
|
|
# Choose two input pins and two pins that do not conflict with stdio. All four
|
|
# *can* be on the same GPIO port, but the two output pins and the two inputs
|
|
# pins *must* be on the same port, respectively. Connect the first input to the
|
|
# first output pin and the second input pin to the second output pin, e.g. using
|
|
# jumper wires.
|
|
PORT_IN ?=
|
|
PORT_OUT ?=
|
|
PIN_IN_0 ?= 0
|
|
PIN_IN_1 ?= 1
|
|
PIN_OUT_0 ?= 2
|
|
PIN_OUT_1 ?= 3
|
|
|
|
# Boards that require tweaking for low ROM
|
|
LOW_ROM_BOARDS := \
|
|
nucleo-l011k4 \
|
|
stm32f030f4-demo \
|
|
#
|
|
|
|
ifneq (,$(filter $(BOARD),$(LOW_ROM_BOARDS)))
|
|
LOW_ROM ?= 1
|
|
endif
|
|
LOW_ROM ?= 0
|
|
|
|
include ../Makefile.periph_common
|
|
|
|
FEATURES_REQUIRED += periph_gpio_ll
|
|
FEATURES_OPTIONAL += periph_gpio_ll_irq
|
|
FEATURES_OPTIONAL += periph_gpio_ll_irq_level_triggered_high
|
|
FEATURES_OPTIONAL += periph_gpio_ll_irq_level_triggered_low
|
|
|
|
USEMODULE += ztimer_usec
|
|
|
|
include $(RIOTBASE)/Makefile.include
|
|
|
|
ifneq (,$(PORT_OUT))
|
|
CFLAGS += -DPORT_OUT=GPIO_PORT_$(PORT_OUT)
|
|
CFLAGS += -DPORT_OUT_NUM=$(PORT_OUT)
|
|
endif
|
|
ifneq (,$(PORT_IN))
|
|
CFLAGS += -DPORT_IN=GPIO_PORT_$(PORT_IN)
|
|
CFLAGS += -DPORT_IN_NUM=$(PORT_IN)
|
|
endif
|
|
CFLAGS += -DPIN_IN_0=$(PIN_IN_0)
|
|
CFLAGS += -DPIN_IN_1=$(PIN_IN_1)
|
|
CFLAGS += -DPIN_OUT_0=$(PIN_OUT_0)
|
|
CFLAGS += -DPIN_OUT_1=$(PIN_OUT_1)
|
|
CFLAGS += -DLOW_ROM=$(LOW_ROM)
|
|
|
|
ifneq ($(CPU),esp32)
|
|
# We only need 1 thread (+ the Idle thread on some platforms) and we really
|
|
# want this app working on all boards.
|
|
CFLAGS += -DMAXTHREADS=2
|
|
else
|
|
# ESP32x SoCs uses an extra thread for esp_timer
|
|
CFLAGS += -DMAXTHREADS=3
|
|
endif
|