Loading...
Searching...
No Matches
gpio_ll_arch.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2023 Gunar Schorcht <gunar@schorcht.net>
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
20#ifndef GPIO_LL_ARCH_H
21#define GPIO_LL_ARCH_H
22
23#include "architecture.h"
24#include "periph/gpio_ll.h"
25#include "periph_cpu.h"
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31#ifndef DOXYGEN /* hide implementation specific details from Doxygen */
32
36#define GPIO_PORT_NUMOF 5
37
41#define GPIO_PORT(num) (GPIOA_BASE + ((num) << 10))
42
46#define GPIO_PORT_NUM(port) (((port) - GPIOA_BASE) >> 10)
47
48static inline uword_t gpio_ll_read(gpio_port_t port)
49{
50 return ((GPIO_Type *)port)->ISTAT;
51}
52
53static inline uword_t gpio_ll_read_output(gpio_port_t port)
54{
55 return ((GPIO_Type *)port)->OCTL;
56}
57
58static inline void gpio_ll_set(gpio_port_t port, uword_t mask)
59{
60 ((GPIO_Type *)port)->BOP = mask;
61}
62
63static inline void gpio_ll_clear(gpio_port_t port, uword_t mask)
64{
65 ((GPIO_Type *)port)->BOP = mask << 16;
66}
67
68static inline void gpio_ll_toggle(gpio_port_t port, uword_t mask)
69{
70 unsigned irq_state = irq_disable();
71 ((GPIO_Type *)port)->OCTL ^= mask;
72 irq_restore(irq_state);
73}
74
75static inline void gpio_ll_write(gpio_port_t port, uword_t value)
76{
77 ((GPIO_Type *)port)->OCTL = value;
78}
79
80static inline gpio_port_t gpio_get_port(gpio_t pin)
81{
82 return pin & 0xfffffff0UL;
83}
84
85static inline uint8_t gpio_get_pin_num(gpio_t pin)
86{
87 return pin & 0xfUL;
88}
89
90static inline gpio_port_t gpio_port_pack_addr(void *addr)
91{
92 return (gpio_port_t)addr;
93}
94
95static inline void * gpio_port_unpack_addr(gpio_port_t port)
96{
97 if (port < GPIOA_BASE) {
98 return (void *)port;
99 }
100
101 return NULL;
102}
103
104static inline bool is_gpio_port_num_valid(uint_fast8_t num)
105{
106 return num < GPIO_PORT_NUMOF;
107}
108
109#endif /* DOXYGEN */
110
111#ifdef __cplusplus
112}
113#endif
114
115#endif /* GPIO_LL_ARCH_H */
Platform-independent access to architecture details.
Peripheral GPIO Low-Level API.
MAYBE_INLINE void irq_restore(unsigned state)
This function restores the IRQ disable bit in the status register to the value contained within passe...
MAYBE_INLINE unsigned irq_disable(void)
This function sets the IRQ disable bit in the status register.
static uint8_t gpio_get_pin_num(gpio_t pin)
Extract the pin number from a gpio_t
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 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.
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.
Definition gpio_ll.h:87
uint< NUM > _t uword_t
Word sized unsigned integer.
Shared CPU specific definitions for the STM32 family.