27#include "periph_cpu.h"
37# define GPIO_APB_BASE PORT_SEC
39# define GPIO_APB_BASE PORT
43#if defined(PORT_IOBUS_SEC)
44# define GPIO_IOBUS_BASE PORT_IOBUS_SEC
45#elif defined(PORT_IOBUS)
46# define GPIO_IOBUS_BASE PORT_IOBUS
48# define GPIO_IOBUS_BASE GPIO_APB_BASE
54#define GPIO_PORT(num) ((uintptr_t)&GPIO_IOBUS_BASE->Group[(num)])
59#define GPIO_PORT_NUM(port) \
60 (((port) - (uintptr_t)&GPIO_IOBUS_BASE->Group[0]) / sizeof(GPIO_IOBUS_BASE->Group[0]))
62static inline PortGroup *sam0_gpio_iobus2ap(PortGroup *iobus)
64 const uintptr_t iobus_base = (uintptr_t)GPIO_IOBUS_BASE;
65 const uintptr_t apb_base = (uintptr_t)GPIO_APB_BASE;
67 return (PortGroup *)((uintptr_t)iobus - (iobus_base - apb_base));
72 PortGroup *p = (PortGroup *)port;
73 if (!
IS_USED(MODULE_PERIPH_GPIO_FAST_READ)) {
74 p = sam0_gpio_iobus2ap(p);
81 PortGroup *p = (PortGroup *)port;
87 PortGroup *p = (PortGroup *)port;
93 PortGroup *p = (PortGroup *)port;
99 PortGroup *p = (PortGroup *)port;
100 p->OUTTGL.reg = mask;
105 PortGroup *p = (PortGroup *)port;
111 PortGroup *p = (PortGroup *)port;
112 p->DIRSET.reg = outputs;
117 PortGroup *p = (PortGroup *)port;
118 p->DIRCLR.reg = inputs;
150 return (num <
ARRAY_SIZE(GPIO_IOBUS_BASE->Group));
Platform-independent access to architecture details.
#define ARRAY_SIZE(a)
Calculate the number of elements in a static array.
Peripheral GPIO Low-Level API.
static uint8_t gpio_get_pin_num(gpio_t pin)
Extract the pin number from a gpio_t
static void gpio_ll_switch_dir_output(gpio_port_t port, uword_t outputs)
Turn GPIO pins specified by the bitmask outputs to outputs.
static void gpio_ll_set(gpio_port_t port, uword_t mask)
Perform an reg |= mask operation on the I/O register of the port.
static void gpio_ll_switch_dir_input(gpio_port_t port, uword_t inputs)
Turn GPIO pins specified by the bitmask inputs to inputs.
static gpio_port_t gpio_port_pack_addr(void *addr)
Pack a pointer into a gpio_port_t.
static uword_t gpio_ll_read(gpio_port_t port)
Get the current input value of all GPIO pins of the given port as bitmask.
static gpio_port_t gpio_get_port(gpio_t pin)
Extract the gpio_port_t from a gpio_t
static void * gpio_port_unpack_addr(gpio_port_t port)
Extract a data pointer that was packed by gpio_port_pack_addr.
#define GPIO_PORT(num)
Get the gpio_port_t value of the port identified by num.
static bool is_gpio_port_num_valid(uint_fast8_t num)
Check if the given number is a valid argument for GPIO_PORT.
static uword_t gpio_ll_read_output(gpio_port_t port)
Get the current output value of all GPIO pins of the given port as bitmask.
static void gpio_ll_clear(gpio_port_t port, uword_t mask)
Perform an reg &= ~mask operation on the I/O register of the port.
static void gpio_ll_toggle(gpio_port_t port, uword_t mask)
Perform an reg ^= mask operation on the I/O register of the port.
static void gpio_ll_write(gpio_port_t port, uword_t state)
Perform a masked write operation on the I/O register of the port.
uintptr_t gpio_port_t
GPIO port type.
uint< NUM > _t uword_t
Word sized unsigned integer.
#define IS_USED(module)
Checks whether a module is being used or not.