You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

370 lines
11 KiB

1 year ago
1 year ago
1 year ago
  1. /**
  2. * Copyright (c) 2014 - 2021, 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. #include "nrf_gpio.h"
  43. #include "nordic_common.h"
  44. #if defined(BOARD_NRF6310)
  45. #include "nrf6310.h"
  46. #elif defined(BOARD_PCA10000)
  47. #include "pca10000.h"
  48. #elif defined(BOARD_PCA10001)
  49. #include "pca10001.h"
  50. #elif defined(BOARD_PCA10002)
  51. #include "pca10000.h"
  52. #elif defined(BOARD_PCA10003)
  53. #include "pca10003.h"
  54. #elif defined(BOARD_PCA20006)
  55. #include "pca20006.h"
  56. #elif defined(BOARD_PCA10028)
  57. #include "pca10028.h"
  58. #elif defined(BOARD_PCA10031)
  59. #include "pca10031.h"
  60. #elif defined(BOARD_PCA10036)
  61. #include "pca10036.h"
  62. #elif defined(BOARD_PCA10040)
  63. #include "pca10040.h"
  64. #elif defined(BOARD_PCA10056)
  65. #include "pca10056.h"
  66. #elif defined(BOARD_PCA10100)
  67. #include "pca10100.h"
  68. #elif defined(BOARD_QING_FENG_NRF52833)
  69. #include "pca_qingfeng52833.h"
  70. #elif defined(BOARD_PCA10112)
  71. #include "pca10112.h"
  72. #elif defined(BOARD_PCA20020)
  73. #include "pca20020.h"
  74. #elif defined(BOARD_PCA10059)
  75. #include "pca10059.h"
  76. #elif defined(BOARD_WT51822)
  77. #include "wt51822.h"
  78. #elif defined(BOARD_N5DK1)
  79. #include "n5_starterkit.h"
  80. #elif defined (BOARD_D52DK1)
  81. #include "d52_starterkit.h"
  82. #elif defined (BOARD_ARDUINO_PRIMO)
  83. #include "arduino_primo.h"
  84. #elif defined (CUSTOM_BOARD_INC)
  85. #include STRINGIFY(CUSTOM_BOARD_INC.h)
  86. #elif defined(BOARD_CUSTOM)
  87. #include "custom_board.h"
  88. #else
  89. #error "Board is not defined"
  90. #endif
  91. #if defined (SHIELD_BSP_INC)
  92. #include STRINGIFY(SHIELD_BSP_INC.h)
  93. #endif
  94. #ifdef __cplusplus
  95. extern "C" {
  96. #endif
  97. /**@defgroup BSP_BOARD_INIT_FLAGS Board initialization flags.
  98. * @{ */
  99. #define BSP_INIT_NONE 0 /**< No initialization of LEDs or buttons (@ref bsp_board_init).*/
  100. #define BSP_INIT_LEDS (1 << 0) /**< Enable LEDs during initialization (@ref bsp_board_init).*/
  101. #define BSP_INIT_BUTTONS (1 << 1) /**< Enable buttons during initialization (@ref bsp_board_init).*/
  102. /**@} */
  103. /**
  104. * Function for returning the state of an LED.
  105. *
  106. * @param led_idx LED index (starting from 0), as defined in the board-specific header.
  107. *
  108. * @return True if the LED is turned on.
  109. */
  110. bool bsp_board_led_state_get(uint32_t led_idx);
  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. * Function for turning off an LED.
  119. *
  120. * @param led_idx LED index (starting from 0), as defined in the board-specific header.
  121. */
  122. void bsp_board_led_off(uint32_t led_idx);
  123. /**
  124. * Function for inverting the state of an LED.
  125. *
  126. * @param led_idx LED index (starting from 0), as defined in the board-specific header.
  127. */
  128. void bsp_board_led_invert(uint32_t led_idx);
  129. /**
  130. * Function for turning off all LEDs.
  131. */
  132. void bsp_board_leds_off(void);
  133. /**
  134. * Function for turning on all LEDs.
  135. */
  136. void bsp_board_leds_on(void);
  137. /**
  138. * Function for initializing the BSP handling for the board.
  139. *
  140. * @note This also initializes the USB DFU trigger library if @ref BOARDS_WITH_USB_DFU_TRIGGER is 1.
  141. *
  142. * @param[in] init_flags Flags specifying what to initialize (LEDs/buttons).
  143. * See @ref BSP_BOARD_INIT_FLAGS.
  144. */
  145. void bsp_board_init(uint32_t init_flags);
  146. /**
  147. * Function for converting pin number to LED index.
  148. *
  149. * @param pin_number Pin number.
  150. *
  151. * @return LED index of the given pin or 0xFFFFFFFF if invalid pin provided.
  152. */
  153. uint32_t bsp_board_pin_to_led_idx(uint32_t pin_number);
  154. /**
  155. * Function for converting LED index to pin number.
  156. *
  157. * @param led_idx LED index.
  158. *
  159. * @return Pin number.
  160. */
  161. uint32_t bsp_board_led_idx_to_pin(uint32_t led_idx);
  162. /**
  163. * Function for returning the state of a button.
  164. *
  165. * @param button_idx Button index (starting from 0), as defined in the board-specific header.
  166. *
  167. * @return True if the button is pressed.
  168. */
  169. bool bsp_board_button_state_get(uint32_t button_idx);
  170. /**
  171. * Function for converting pin number to button index.
  172. *
  173. * @param pin_number Pin number.
  174. *
  175. * @return Button index of the given pin or 0xFFFFFFFF if invalid pin provided.
  176. */
  177. uint32_t bsp_board_pin_to_button_idx(uint32_t pin_number);
  178. /**
  179. * Function for converting button index to pin number.
  180. *
  181. * @param button_idx Button index.
  182. *
  183. * @return Pin number.
  184. */
  185. uint32_t bsp_board_button_idx_to_pin(uint32_t button_idx);
  186. #define BSP_BOARD_LED_0 0
  187. #define BSP_BOARD_LED_1 1
  188. #define BSP_BOARD_LED_2 2
  189. #define BSP_BOARD_LED_3 3
  190. #define BSP_BOARD_LED_4 4
  191. #define BSP_BOARD_LED_5 5
  192. #define BSP_BOARD_LED_6 6
  193. #define BSP_BOARD_LED_7 7
  194. #define PIN_MASK(_pin) /*lint -save -e504 */ \
  195. (1u << (uint32_t)((_pin) & (~P0_PIN_NUM))) \
  196. /*lint -restore */
  197. #define PIN_PORT(_pin) (((_pin) >= P0_PIN_NUM) ? NRF_P1 : NRF_GPIO)
  198. #ifdef BSP_LED_0
  199. #define BSP_LED_0_MASK PIN_MASK(BSP_LED_0)
  200. #define BSP_LED_0_PORT PIN_PORT(BSP_LED_0)
  201. #else
  202. #define BSP_LED_0_MASK 0
  203. #define BSP_LED_0_PORT 0
  204. #endif
  205. #ifdef BSP_LED_1
  206. #define BSP_LED_1_MASK PIN_MASK(BSP_LED_1)
  207. #define BSP_LED_1_PORT PIN_PORT(BSP_LED_1)
  208. #else
  209. #define BSP_LED_1_MASK 0
  210. #define BSP_LED_1_PORT 0
  211. #endif
  212. #ifdef BSP_LED_2
  213. #define BSP_LED_2_MASK PIN_MASK(BSP_LED_2)
  214. #define BSP_LED_2_PORT PIN_PORT(BSP_LED_2)
  215. #else
  216. #define BSP_LED_2_MASK 0
  217. #define BSP_LED_2_PORT 0
  218. #endif
  219. #ifdef BSP_LED_3
  220. #define BSP_LED_3_MASK PIN_MASK(BSP_LED_3)
  221. #define BSP_LED_3_PORT PIN_PORT(BSP_LED_3)
  222. #else
  223. #define BSP_LED_3_MASK 0
  224. #define BSP_LED_3_PORT 0
  225. #endif
  226. #ifdef BSP_LED_4
  227. #define BSP_LED_4_MASK PIN_MASK(BSP_LED_4)
  228. #define BSP_LED_4_PORT PIN_PORT(BSP_LED_4)
  229. #else
  230. #define BSP_LED_4_MASK 0
  231. #define BSP_LED_4_PORT 0
  232. #endif
  233. #ifdef BSP_LED_5
  234. #define BSP_LED_5_MASK PIN_MASK(BSP_LED_5)
  235. #define BSP_LED_5_PORT PIN_PORT(BSP_LED_5)
  236. #else
  237. #define BSP_LED_5_MASK 0
  238. #define BSP_LED_5_PORT 0
  239. #endif
  240. #ifdef BSP_LED_6
  241. #define BSP_LED_6_MASK PIN_MASK(BSP_LED_6)
  242. #define BSP_LED_6_PORT PIN_PORT(BSP_LED_6)
  243. #else
  244. #define BSP_LED_6_MASK 0
  245. #define BSP_LED_6_PORT 0
  246. #endif
  247. #ifdef BSP_LED_7
  248. #define BSP_LED_7_MASK PIN_MASK(BSP_LED_7)
  249. #define BSP_LED_7_PORT PIN_PORT(BSP_LED_7)
  250. #else
  251. #define BSP_LED_7_MASK 0
  252. #define BSP_LED_7_PORT 0
  253. #endif
  254. #define LEDS_MASK (BSP_LED_0_MASK | BSP_LED_1_MASK | \
  255. BSP_LED_2_MASK | BSP_LED_3_MASK | \
  256. BSP_LED_4_MASK | BSP_LED_5_MASK | \
  257. BSP_LED_6_MASK | BSP_LED_7_MASK)
  258. #define BSP_BOARD_BUTTON_0 0
  259. #define BSP_BOARD_BUTTON_1 1
  260. #define BSP_BOARD_BUTTON_2 2
  261. #define BSP_BOARD_BUTTON_3 3
  262. #define BSP_BOARD_BUTTON_4 4
  263. #define BSP_BOARD_BUTTON_5 5
  264. #define BSP_BOARD_BUTTON_6 6
  265. #define BSP_BOARD_BUTTON_7 7
  266. #ifdef BSP_BUTTON_0
  267. #define BSP_BUTTON_0_MASK (1<<BSP_BUTTON_0)
  268. #else
  269. #define BSP_BUTTON_0_MASK 0
  270. #endif
  271. #ifdef BSP_BUTTON_1
  272. #define BSP_BUTTON_1_MASK (1<<BSP_BUTTON_1)
  273. #else
  274. #define BSP_BUTTON_1_MASK 0
  275. #endif
  276. #ifdef BSP_BUTTON_2
  277. #define BSP_BUTTON_2_MASK (1<<BSP_BUTTON_2)
  278. #else
  279. #define BSP_BUTTON_2_MASK 0
  280. #endif
  281. #ifdef BSP_BUTTON_3
  282. #define BSP_BUTTON_3_MASK (1<<BSP_BUTTON_3)
  283. #else
  284. #define BSP_BUTTON_3_MASK 0
  285. #endif
  286. #ifdef BSP_BUTTON_4
  287. #define BSP_BUTTON_4_MASK (1<<BSP_BUTTON_4)
  288. #else
  289. #define BSP_BUTTON_4_MASK 0
  290. #endif
  291. #ifdef BSP_BUTTON_5
  292. #define BSP_BUTTON_5_MASK (1<<BSP_BUTTON_5)
  293. #else
  294. #define BSP_BUTTON_5_MASK 0
  295. #endif
  296. #ifdef BSP_BUTTON_6
  297. #define BSP_BUTTON_6_MASK (1<<BSP_BUTTON_6)
  298. #else
  299. #define BSP_BUTTON_6_MASK 0
  300. #endif
  301. #ifdef BSP_BUTTON_7
  302. #define BSP_BUTTON_7_MASK (1<<BSP_BUTTON_7)
  303. #else
  304. #define BSP_BUTTON_7_MASK 0
  305. #endif
  306. #define BUTTONS_MASK (BSP_BUTTON_0_MASK | BSP_BUTTON_1_MASK | \
  307. BSP_BUTTON_2_MASK | BSP_BUTTON_3_MASK | \
  308. BSP_BUTTON_4_MASK | BSP_BUTTON_5_MASK | \
  309. BSP_BUTTON_6_MASK | BSP_BUTTON_7_MASK)
  310. /* This macro is supporting only P0 and should not be used if LEDs are on other ports. */
  311. #define LEDS_OFF(leds_mask) do { ASSERT(sizeof(leds_mask) == 4); \
  312. NRF_GPIO->OUTSET = (leds_mask) & (LEDS_MASK & LEDS_INV_MASK); \
  313. NRF_GPIO->OUTCLR = (leds_mask) & (LEDS_MASK & ~LEDS_INV_MASK); } while (0)
  314. /* This macro is supporting only P0 and should not be used if LEDs are on other ports. */
  315. #define LEDS_ON(leds_mask) do { ASSERT(sizeof(leds_mask) == 4); \
  316. NRF_GPIO->OUTCLR = (leds_mask) & (LEDS_MASK & LEDS_INV_MASK); \
  317. NRF_GPIO->OUTSET = (leds_mask) & (LEDS_MASK & ~LEDS_INV_MASK); } while (0)
  318. /* This macro is supporting only P0 and should not be used if LEDs are on other ports. */
  319. #define LED_IS_ON(leds_mask) ((leds_mask) & (NRF_GPIO->OUT ^ LEDS_INV_MASK) )
  320. /* This macro is supporting only P0 and should not be used if LEDs are on other ports. */
  321. #define LEDS_INVERT(leds_mask) do { uint32_t gpio_state = NRF_GPIO->OUT; \
  322. ASSERT(sizeof(leds_mask) == 4); \
  323. NRF_GPIO->OUTSET = ((leds_mask) & ~gpio_state); \
  324. NRF_GPIO->OUTCLR = ((leds_mask) & gpio_state); } while (0)
  325. /* This macro is supporting only P0 and should not be used if LEDs are on other ports. */
  326. #define LEDS_CONFIGURE(leds_mask) do { uint32_t pin; \
  327. ASSERT(sizeof(leds_mask) == 4); \
  328. for (pin = 0; pin < 32; pin++) \
  329. if ( (leds_mask) & (1 << pin) ) \
  330. nrf_gpio_cfg_output(pin); } while (0)
  331. #ifdef __cplusplus
  332. }
  333. #endif
  334. #endif