Mistake on this page?
Report an issue in GitHub or email us
boards.h
1 /**
2  * Copyright (c) 2014 - 2019, Nordic Semiconductor ASA
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without modification,
7  * are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form, except as embedded into a Nordic
13  * Semiconductor ASA integrated circuit in a product or a software update for
14  * such product, must reproduce the above copyright notice, this list of
15  * conditions and the following disclaimer in the documentation and/or other
16  * materials provided with the distribution.
17  *
18  * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
19  * contributors may be used to endorse or promote products derived from this
20  * software without specific prior written permission.
21  *
22  * 4. This software, with or without modification, must only be used with a
23  * Nordic Semiconductor ASA integrated circuit.
24  *
25  * 5. Any software provided in binary form under this license must not be reverse
26  * engineered, decompiled, modified and/or disassembled.
27  *
28  * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
29  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
30  * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
31  * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
32  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
34  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
37  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38  *
39  */
40 #ifndef BOARDS_H
41 #define BOARDS_H
42 
43 #include "nrf_gpio.h"
44 #include "nordic_common.h"
45 
46 #if defined(BOARD_NRF6310)
47  #include "nrf6310.h"
48 #elif defined(BOARD_PCA10000)
49  #include "pca10000.h"
50 #elif defined(BOARD_PCA10001)
51  #include "pca10001.h"
52 #elif defined(BOARD_PCA10002)
53  #include "pca10000.h"
54 #elif defined(BOARD_PCA10003)
55  #include "pca10003.h"
56 #elif defined(BOARD_PCA20006)
57  #include "pca20006.h"
58 #elif defined(BOARD_PCA10028)
59  #include "pca10028.h"
60 #elif defined(BOARD_PCA10031)
61  #include "pca10031.h"
62 #elif defined(BOARD_PCA10036)
63  #include "pca10036.h"
64 #elif defined(BOARD_PCA10040)
65  #include "pca10040.h"
66 #elif defined(BOARD_PCA10056)
67  #include "pca10056.h"
68 #elif defined(BOARD_PCA10100)
69  #include "pca10100.h"
70 #elif defined(BOARD_PCA20020)
71  #include "pca20020.h"
72 #elif defined(BOARD_PCA10059)
73  #include "pca10059.h"
74 #elif defined(BOARD_WT51822)
75  #include "wt51822.h"
76 #elif defined(BOARD_N5DK1)
77  #include "n5_starterkit.h"
78 #elif defined (BOARD_D52DK1)
79  #include "d52_starterkit.h"
80 #elif defined (BOARD_ARDUINO_PRIMO)
81  #include "arduino_primo.h"
82 #elif defined (CUSTOM_BOARD_INC)
83  #include STRINGIFY(CUSTOM_BOARD_INC.h)
84 #elif defined(BOARD_CUSTOM)
85  #include "custom_board.h"
86 #else
87 #error "Board is not defined"
88 
89 #endif
90 
91 #ifdef __cplusplus
92 extern "C" {
93 #endif
94 
95 /**@defgroup BSP_BOARD_INIT_FLAGS Board initialization flags.
96  * @{ */
97 #define BSP_INIT_NONE 0 /**< No initialization of LEDs or buttons (@ref bsp_board_init).*/
98 #define BSP_INIT_LEDS (1 << 0) /**< Enable LEDs during initialization (@ref bsp_board_init).*/
99 #define BSP_INIT_BUTTONS (1 << 1) /**< Enable buttons during initialization (@ref bsp_board_init).*/
100 /**@} */
101 
102 /**
103  * Function for returning the state of an LED.
104  *
105  * @param led_idx LED index (starting from 0), as defined in the board-specific header.
106  *
107  * @return True if the LED is turned on.
108  */
109 bool bsp_board_led_state_get(uint32_t led_idx);
110 
111 /**
112  * Function for turning on an LED.
113  *
114  * @param led_idx LED index (starting from 0), as defined in the board-specific header.
115  */
116 void bsp_board_led_on(uint32_t led_idx);
117 
118 /**
119  * Function for turning off an LED.
120  *
121  * @param led_idx LED index (starting from 0), as defined in the board-specific header.
122  */
123 void bsp_board_led_off(uint32_t led_idx);
124 
125 /**
126  * Function for inverting the state of an LED.
127  *
128  * @param led_idx LED index (starting from 0), as defined in the board-specific header.
129  */
130 void bsp_board_led_invert(uint32_t led_idx);
131 /**
132  * Function for turning off all LEDs.
133  */
134 void bsp_board_leds_off(void);
135 
136 /**
137  * Function for turning on all LEDs.
138  */
139 void bsp_board_leds_on(void);
140 
141 /**
142  * Function for initializing the BSP handling for the board.
143  *
144  * @note This also initializes the USB DFU trigger library if @ref BOARDS_WITH_USB_DFU_TRIGGER is 1.
145  *
146  * @param[in] init_flags Flags specifying what to initialize (LEDs/buttons).
147  * See @ref BSP_BOARD_INIT_FLAGS.
148  */
149 void bsp_board_init(uint32_t init_flags);
150 
151 /**
152  * Function for converting pin number to LED index.
153  *
154  * @param pin_number Pin number.
155  *
156  * @return LED index of the given pin or 0xFFFFFFFF if invalid pin provided.
157  */
158 uint32_t bsp_board_pin_to_led_idx(uint32_t pin_number);
159 
160 /**
161  * Function for converting LED index to pin number.
162  *
163  * @param led_idx LED index.
164  *
165  * @return Pin number.
166  */
167 uint32_t bsp_board_led_idx_to_pin(uint32_t led_idx);
168 
169 /**
170  * Function for returning the state of a button.
171  *
172  * @param button_idx Button index (starting from 0), as defined in the board-specific header.
173  *
174  * @return True if the button is pressed.
175  */
176 bool bsp_board_button_state_get(uint32_t button_idx);
177 
178 /**
179  * Function for converting pin number to button index.
180  *
181  * @param pin_number Pin number.
182  *
183  * @return Button index of the given pin or 0xFFFFFFFF if invalid pin provided.
184  */
185 uint32_t bsp_board_pin_to_button_idx(uint32_t pin_number);
186 
187 
188 /**
189  * Function for converting button index to pin number.
190  *
191  * @param button_idx Button index.
192  *
193  * @return Pin number.
194  */
195 uint32_t bsp_board_button_idx_to_pin(uint32_t button_idx);
196 
197 #define BSP_BOARD_LED_0 0
198 #define BSP_BOARD_LED_1 1
199 #define BSP_BOARD_LED_2 2
200 #define BSP_BOARD_LED_3 3
201 #define BSP_BOARD_LED_4 4
202 #define BSP_BOARD_LED_5 5
203 #define BSP_BOARD_LED_6 6
204 #define BSP_BOARD_LED_7 7
205 
206 #define PIN_MASK(_pin) /*lint -save -e504 */ \
207  (1u << (uint32_t)((_pin) & (~P0_PIN_NUM))) \
208  /*lint -restore */
209 
210 #define PIN_PORT(_pin) (((_pin) >= P0_PIN_NUM) ? NRF_P1 : NRF_GPIO)
211 
212 #ifdef BSP_LED_0
213 #define BSP_LED_0_MASK PIN_MASK(BSP_LED_0)
214 #define BSP_LED_0_PORT PIN_PORT(BSP_LED_0)
215 #else
216 #define BSP_LED_0_MASK 0
217 #define BSP_LED_0_PORT 0
218 #endif
219 #ifdef BSP_LED_1
220 #define BSP_LED_1_MASK PIN_MASK(BSP_LED_1)
221 #define BSP_LED_1_PORT PIN_PORT(BSP_LED_1)
222 #else
223 #define BSP_LED_1_MASK 0
224 #define BSP_LED_1_PORT 0
225 #endif
226 #ifdef BSP_LED_2
227 #define BSP_LED_2_MASK PIN_MASK(BSP_LED_2)
228 #define BSP_LED_2_PORT PIN_PORT(BSP_LED_2)
229 #else
230 #define BSP_LED_2_MASK 0
231 #define BSP_LED_2_PORT 0
232 #endif
233 #ifdef BSP_LED_3
234 #define BSP_LED_3_MASK PIN_MASK(BSP_LED_3)
235 #define BSP_LED_3_PORT PIN_PORT(BSP_LED_3)
236 #else
237 #define BSP_LED_3_MASK 0
238 #define BSP_LED_3_PORT 0
239 #endif
240 #ifdef BSP_LED_4
241 #define BSP_LED_4_MASK PIN_MASK(BSP_LED_4)
242 #define BSP_LED_4_PORT PIN_PORT(BSP_LED_4)
243 #else
244 #define BSP_LED_4_MASK 0
245 #define BSP_LED_4_PORT 0
246 #endif
247 #ifdef BSP_LED_5
248 #define BSP_LED_5_MASK PIN_MASK(BSP_LED_5)
249 #define BSP_LED_5_PORT PIN_PORT(BSP_LED_5)
250 #else
251 #define BSP_LED_5_MASK 0
252 #define BSP_LED_5_PORT 0
253 #endif
254 #ifdef BSP_LED_6
255 #define BSP_LED_6_MASK PIN_MASK(BSP_LED_6)
256 #define BSP_LED_6_PORT PIN_PORT(BSP_LED_6)
257 #else
258 #define BSP_LED_6_MASK 0
259 #define BSP_LED_6_PORT 0
260 #endif
261 #ifdef BSP_LED_7
262 #define BSP_LED_7_MASK PIN_MASK(BSP_LED_7)
263 #define BSP_LED_7_PORT PIN_PORT(BSP_LED_7)
264 #else
265 #define BSP_LED_7_MASK 0
266 #define BSP_LED_7_PORT 0
267 #endif
268 
269 
270 #define LEDS_MASK (BSP_LED_0_MASK | BSP_LED_1_MASK | \
271  BSP_LED_2_MASK | BSP_LED_3_MASK | \
272  BSP_LED_4_MASK | BSP_LED_5_MASK | \
273  BSP_LED_6_MASK | BSP_LED_7_MASK)
274 
275 #define BSP_BOARD_BUTTON_0 0
276 #define BSP_BOARD_BUTTON_1 1
277 #define BSP_BOARD_BUTTON_2 2
278 #define BSP_BOARD_BUTTON_3 3
279 #define BSP_BOARD_BUTTON_4 4
280 #define BSP_BOARD_BUTTON_5 5
281 #define BSP_BOARD_BUTTON_6 6
282 #define BSP_BOARD_BUTTON_7 7
283 
284 
285 #ifdef BSP_BUTTON_0
286 #define BSP_BUTTON_0_MASK (1<<BSP_BUTTON_0)
287 #else
288 #define BSP_BUTTON_0_MASK 0
289 #endif
290 #ifdef BSP_BUTTON_1
291 #define BSP_BUTTON_1_MASK (1<<BSP_BUTTON_1)
292 #else
293 #define BSP_BUTTON_1_MASK 0
294 #endif
295 #ifdef BSP_BUTTON_2
296 #define BSP_BUTTON_2_MASK (1<<BSP_BUTTON_2)
297 #else
298 #define BSP_BUTTON_2_MASK 0
299 #endif
300 #ifdef BSP_BUTTON_3
301 #define BSP_BUTTON_3_MASK (1<<BSP_BUTTON_3)
302 #else
303 #define BSP_BUTTON_3_MASK 0
304 #endif
305 #ifdef BSP_BUTTON_4
306 #define BSP_BUTTON_4_MASK (1<<BSP_BUTTON_4)
307 #else
308 #define BSP_BUTTON_4_MASK 0
309 #endif
310 #ifdef BSP_BUTTON_5
311 #define BSP_BUTTON_5_MASK (1<<BSP_BUTTON_5)
312 #else
313 #define BSP_BUTTON_5_MASK 0
314 #endif
315 #ifdef BSP_BUTTON_6
316 #define BSP_BUTTON_6_MASK (1<<BSP_BUTTON_6)
317 #else
318 #define BSP_BUTTON_6_MASK 0
319 #endif
320 #ifdef BSP_BUTTON_7
321 #define BSP_BUTTON_7_MASK (1<<BSP_BUTTON_7)
322 #else
323 #define BSP_BUTTON_7_MASK 0
324 #endif
325 
326 #define BUTTONS_MASK (BSP_BUTTON_0_MASK | BSP_BUTTON_1_MASK | \
327  BSP_BUTTON_2_MASK | BSP_BUTTON_3_MASK | \
328  BSP_BUTTON_4_MASK | BSP_BUTTON_5_MASK | \
329  BSP_BUTTON_6_MASK | BSP_BUTTON_7_MASK)
330 
331 
332 #define LEDS_OFF(leds_mask) do { ASSERT(sizeof(leds_mask) == 4); \
333  NRF_GPIO->OUTSET = (leds_mask) & (LEDS_MASK & LEDS_INV_MASK); \
334  NRF_GPIO->OUTCLR = (leds_mask) & (LEDS_MASK & ~LEDS_INV_MASK); } while (0)
335 
336 #define LEDS_ON(leds_mask) do { ASSERT(sizeof(leds_mask) == 4); \
337  NRF_GPIO->OUTCLR = (leds_mask) & (LEDS_MASK & LEDS_INV_MASK); \
338  NRF_GPIO->OUTSET = (leds_mask) & (LEDS_MASK & ~LEDS_INV_MASK); } while (0)
339 
340 #define LED_IS_ON(leds_mask) ((leds_mask) & (NRF_GPIO->OUT ^ LEDS_INV_MASK) )
341 
342 #define LEDS_INVERT(leds_mask) do { uint32_t gpio_state = NRF_GPIO->OUT; \
343  ASSERT(sizeof(leds_mask) == 4); \
344  NRF_GPIO->OUTSET = ((leds_mask) & ~gpio_state); \
345  NRF_GPIO->OUTCLR = ((leds_mask) & gpio_state); } while (0)
346 
347 #define LEDS_CONFIGURE(leds_mask) do { uint32_t pin; \
348  ASSERT(sizeof(leds_mask) == 4); \
349  for (pin = 0; pin < 32; pin++) \
350  if ( (leds_mask) & (1 << pin) ) \
351  nrf_gpio_cfg_output(pin); } while (0)
352 
353 #ifdef __cplusplus
354 }
355 #endif
356 
357 #endif
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.