stm32_leds.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 Otto-von-Guericke-Universität Magdeburg
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 
9 #pragma once
10 
25 /* Using gpio_ll_arch for GPIO access. On STM32, accessing the GPIO output
26  * buffer via GPIO LL even works when the GPIO LL feature/module is not in
27  * use */
28 #include "periph/gpio_ll.h"
29 #include "kernel_defines.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
39 #if defined(LED0_PORT_NUM) && defined (LED0_PIN_NUM)
40 # define LED0_PIN GPIO_PIN(LED0_PORT_NUM, LED0_PIN_NUM)
41 # define LED0_MASK (1 << LED0_PIN_NUM)
42 # if IS_ACTIVE(LED0_IS_INVERTED)
43 # define LED0_ON gpio_ll_clear(LED0_PORT, LED0_MASK)
44 # define LED0_OFF gpio_ll_set(LED0_PORT, LED0_MASK)
45 # else
46 # define LED0_ON gpio_ll_set(LED0_PORT, LED0_MASK)
47 # define LED0_OFF gpio_ll_clear(LED0_PORT, LED0_MASK)
48 # endif
49 # define LED0_TOGGLE gpio_ll_toggle(LED0_PORT, LED0_MASK)
50 #endif
51 
52 #if defined(LED1_PORT_NUM) && defined (LED1_PIN_NUM)
53 # define LED1_PIN GPIO_PIN(LED1_PORT_NUM, LED1_PIN_NUM)
54 # define LED1_MASK (1 << LED1_PIN_NUM)
55 # if IS_ACTIVE(LED1_IS_INVERTED)
56 # define LED1_ON gpio_ll_clear(LED1_PORT, LED1_MASK)
57 # define LED1_OFF gpio_ll_set(LED1_PORT, LED1_MASK)
58 # else
59 # define LED1_ON gpio_ll_set(LED1_PORT, LED1_MASK)
60 # define LED1_OFF gpio_ll_clear(LED1_PORT, LED1_MASK)
61 # endif
62 # define LED1_TOGGLE gpio_ll_toggle(LED1_PORT, LED1_MASK)
63 #endif
64 
65 #if defined(LED2_PORT_NUM) && defined (LED2_PIN_NUM)
66 # define LED2_PIN GPIO_PIN(LED2_PORT_NUM, LED2_PIN_NUM)
67 # define LED2_MASK (1 << LED2_PIN_NUM)
68 # if IS_ACTIVE(LED2_IS_INVERTED)
69 # define LED2_ON gpio_ll_clear(LED2_PORT, LED2_MASK)
70 # define LED2_OFF gpio_ll_set(LED2_PORT, LED2_MASK)
71 # else
72 # define LED2_ON gpio_ll_set(LED2_PORT, LED2_MASK)
73 # define LED2_OFF gpio_ll_clear(LED2_PORT, LED2_MASK)
74 # endif
75 # define LED2_TOGGLE gpio_ll_toggle(LED2_PORT, LED2_MASK)
76 #endif
77 
78 #if defined(LED3_PORT_NUM) && defined (LED3_PIN_NUM)
79 # define LED3_PIN GPIO_PIN(LED3_PORT_NUM, LED3_PIN_NUM)
80 # define LED3_MASK (1 << LED3_PIN_NUM)
81 # if IS_ACTIVE(LED3_IS_INVERTED)
82 # define LED3_ON gpio_ll_clear(LED3_PORT, LED3_MASK)
83 # define LED3_OFF gpio_ll_set(LED3_PORT, LED3_MASK)
84 # else
85 # define LED3_ON gpio_ll_set(LED3_PORT, LED3_MASK)
86 # define LED3_OFF gpio_ll_clear(LED3_PORT, LED3_MASK)
87 # endif
88 # define LED3_TOGGLE gpio_ll_toggle(LED3_PORT, LED3_MASK)
89 #endif
90 
91 #if defined(LED4_PORT_NUM) && defined (LED4_PIN_NUM)
92 # define LED4_PIN GPIO_PIN(LED4_PORT_NUM, LED4_PIN_NUM)
93 # define LED4_MASK (1 << LED4_PIN_NUM)
94 # if IS_ACTIVE(LED4_IS_INVERTED)
95 # define LED4_ON gpio_ll_clear(LED4_PORT, LED4_MASK)
96 # define LED4_OFF gpio_ll_set(LED4_PORT, LED4_MASK)
97 # else
98 # define LED4_ON gpio_ll_set(LED4_PORT, LED4_MASK)
99 # define LED4_OFF gpio_ll_clear(LED4_PORT, LED4_MASK)
100 # endif
101 # define LED4_TOGGLE gpio_ll_toggle(LED4_PORT, LED4_MASK)
102 #endif
103 
104 #if defined(LED5_PORT_NUM) && defined (LED5_PIN_NUM)
105 # define LED5_PIN GPIO_PIN(LED5_PORT_NUM, LED5_PIN_NUM)
106 # define LED5_MASK (1 << LED5_PIN_NUM)
107 # if IS_ACTIVE(LED5_IS_INVERTED)
108 # define LED5_ON gpio_ll_clear(LED5_PORT, LED5_MASK)
109 # define LED5_OFF gpio_ll_set(LED5_PORT, LED5_MASK)
110 # else
111 # define LED5_ON gpio_ll_set(LED5_PORT, LED5_MASK)
112 # define LED5_OFF gpio_ll_clear(LED5_PORT, LED5_MASK)
113 # endif
114 # define LED5_TOGGLE gpio_ll_toggle(LED5_PORT, LED5_MASK)
115 #endif
116 
117 #if defined(LED6_PORT_NUM) && defined (LED6_PIN_NUM)
118 # define LED6_PIN GPIO_PIN(LED6_PORT_NUM, LED6_PIN_NUM)
119 # define LED6_MASK (1 << LED6_PIN_NUM)
120 # if IS_ACTIVE(LED6_IS_INVERTED)
121 # define LED6_ON gpio_ll_clear(LED6_PORT, LED6_MASK)
122 # define LED6_OFF gpio_ll_set(LED6_PORT, LED6_MASK)
123 # else
124 # define LED6_ON gpio_ll_set(LED6_PORT, LED6_MASK)
125 # define LED6_OFF gpio_ll_clear(LED6_PORT, LED6_MASK)
126 # endif
127 # define LED6_TOGGLE gpio_ll_toggle(LED6_PORT, LED6_MASK)
128 #endif
129 
130 #if defined(LED7_PORT_NUM) && defined (LED7_PIN_NUM)
131 # define LED7_PIN GPIO_PIN(LED7_PORT_NUM, LED7_PIN_NUM)
132 # define LED7_MASK (1 << LED7_PIN_NUM)
133 # if IS_ACTIVE(LED7_IS_INVERTED)
134 # define LED7_ON gpio_ll_clear(LED7_PORT, LED7_MASK)
135 # define LED7_OFF gpio_ll_set(LED7_PORT, LED7_MASK)
136 # else
137 # define LED7_ON gpio_ll_set(LED7_PORT, LED7_MASK)
138 # define LED7_OFF gpio_ll_clear(LED7_PORT, LED7_MASK)
139 # endif
140 # define LED7_TOGGLE gpio_ll_toggle(LED7_PORT, LED7_MASK)
141 #endif
142 
145 #ifdef __cplusplus
146 }
147 #endif
148 
Peripheral GPIO Low-Level API.
Common macros and compiler attributes/pragmas configuration.