stm32wbxx_nucleo.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /**
  2. ******************************************************************************
  3. * @file stm32wbxx_nucleo.h
  4. * @author MCD Application Team
  5. * @brief This file contains definitions for:
  6. * - LEDs and push-button available on STM32WBXX-Nucleo Kit
  7. * from STMicroelectronics
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * Copyright (c) 2019-2021 STMicroelectronics.
  12. * All rights reserved.
  13. *
  14. * This software is licensed under terms that can be found in the LICENSE file
  15. * in the root directory of this software component.
  16. * If no LICENSE file comes with this software, it is provided AS-IS.
  17. *
  18. ******************************************************************************
  19. */
  20. /* Define to prevent recursive inclusion -------------------------------------*/
  21. #ifndef __STM32WBXX_NUCLEO_H
  22. #define __STM32WBXX_NUCLEO_H
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /** @addtogroup BSP
  27. * @{
  28. */
  29. /** @addtogroup STM32WBXX_NUCLEO
  30. * @{
  31. */
  32. /* Includes ------------------------------------------------------------------*/
  33. #include "stm32wbxx_hal.h"
  34. /** @defgroup STM32WBXX_NUCLEO_Exported_Types Exported Types
  35. * @{
  36. */
  37. typedef enum
  38. {
  39. LED1 = 0,
  40. LED2 = 1,
  41. LED3 = 2,
  42. /* Color led aliases */
  43. LED_BLUE = LED1,
  44. LED_GREEN = LED2,
  45. LED_RED = LED3
  46. }Led_TypeDef;
  47. typedef enum
  48. {
  49. BUTTON_SW1 = 0,
  50. BUTTON_SW2 = 1,
  51. BUTTON_SW3 = 2,
  52. }Button_TypeDef;
  53. typedef enum
  54. {
  55. BUTTON_MODE_GPIO = 0,
  56. BUTTON_MODE_EXTI = 1
  57. }ButtonMode_TypeDef;
  58. typedef enum
  59. {
  60. JOY_NONE = 0,
  61. JOY_SEL = 1,
  62. JOY_DOWN = 2,
  63. JOY_LEFT = 3,
  64. JOY_RIGHT = 4,
  65. JOY_UP = 5
  66. } JOYState_TypeDef;
  67. /**
  68. * @}
  69. */
  70. /** @defgroup STM32WBXX_NUCLEO_Exported_Constants Exported Constants
  71. * @{
  72. */
  73. /**
  74. * @brief Define for STM32WBXX_NUCLEO board
  75. */
  76. #if !defined (USE_STM32WBXX_NUCLEO)
  77. #define USE_STM32WBXX_NUCLEO
  78. #endif
  79. /** @defgroup STM32WBXX_NUCLEO_LED LED Constants
  80. * @{
  81. */
  82. #define LEDn 3
  83. #define LED1_PIN GPIO_PIN_5
  84. #define LED1_GPIO_PORT GPIOB
  85. #define LED1_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
  86. #define LED1_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
  87. #define LED2_PIN GPIO_PIN_0
  88. #define LED2_GPIO_PORT GPIOB
  89. #define LED2_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
  90. #define LED2_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
  91. #define LED3_PIN GPIO_PIN_1
  92. #define LED3_GPIO_PORT GPIOB
  93. #define LED3_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
  94. #define LED3_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
  95. #define LEDx_GPIO_CLK_ENABLE(__INDEX__) __HAL_RCC_GPIOB_CLK_ENABLE() /* All Led on same port */
  96. #define LEDx_GPIO_CLK_DISABLE(__INDEX__) __HAL_RCC_GPIOB_CLK_DISABLE() /* All Led on same port */
  97. /**
  98. * @}
  99. */
  100. /** @defgroup STM32WBXX_NUCLEO_BUTTON BUTTON Constants
  101. * @{
  102. */
  103. #define BUTTONn 3
  104. /**
  105. * @brief Key push-button
  106. */
  107. #define BUTTON_SW1_PIN GPIO_PIN_4
  108. #define BUTTON_SW1_GPIO_PORT GPIOC
  109. #define BUTTON_SW1_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
  110. #define BUTTON_SW1_GPIO_CLK_DISABLE() __HAL_RCC_GPIOC_CLK_DISABLE()
  111. #define BUTTON_SW1_EXTI_LINE GPIO_PIN_4
  112. #ifdef CORE_CM0PLUS
  113. #define BUTTON_SW1_EXTI_IRQn EXTI15_4_IRQn
  114. #else
  115. #define BUTTON_SW1_EXTI_IRQn EXTI4_IRQn
  116. #endif
  117. #define BUTTON_SW2_PIN GPIO_PIN_0
  118. #define BUTTON_SW2_GPIO_PORT GPIOD
  119. #define BUTTON_SW2_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
  120. #define BUTTON_SW2_GPIO_CLK_DISABLE() __HAL_RCC_GPIOD_CLK_DISABLE()
  121. #define BUTTON_SW2_EXTI_LINE GPIO_PIN_0
  122. #ifdef CORE_CM0PLUS
  123. #define BUTTON_SW2_EXTI_IRQn EXTI1_0_IRQn
  124. #else
  125. #define BUTTON_SW2_EXTI_IRQn EXTI0_IRQn
  126. #endif
  127. #define BUTTON_SW3_PIN GPIO_PIN_1
  128. #define BUTTON_SW3_GPIO_PORT GPIOD
  129. #define BUTTON_SW3_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
  130. #define BUTTON_SW3_GPIO_CLK_DISABLE() __HAL_RCC_GPIOD_CLK_DISABLE()
  131. #define BUTTON_SW3_EXTI_LINE GPIO_PIN_1
  132. #ifdef CORE_CM0PLUS
  133. #define BUTTON_SW3_EXTI_IRQn EXTI1_0_IRQn
  134. #else
  135. #define BUTTON_SW3_EXTI_IRQn EXTI1_IRQn
  136. #endif
  137. #define BUTTONx_GPIO_CLK_ENABLE(__INDEX__) do { if ((__INDEX__) == BUTTON_SW1) BUTTON_SW1_GPIO_CLK_ENABLE(); else \
  138. if ((__INDEX__) == BUTTON_SW2) BUTTON_SW2_GPIO_CLK_ENABLE(); else \
  139. if ((__INDEX__) == BUTTON_SW3) BUTTON_SW3_GPIO_CLK_ENABLE();} while(0)
  140. #define BUTTONx_GPIO_CLK_DISABLE(__INDEX__) do { if ((__INDEX__) == BUTTON_SW1) BUTTON_SW1_GPIO_CLK_DISABLE(); else \
  141. if ((__INDEX__) == BUTTON_SW2) BUTTON_SW2_GPIO_CLK_DISABLE(); else \
  142. if ((__INDEX__) == BUTTON_SW3) BUTTON_SW3_GPIO_CLK_DISABLE();} while(0)
  143. /**
  144. * @}
  145. */
  146. /** @addtogroup STM32WBXX_NUCLEO_BUS BUS Constants
  147. * @{
  148. */
  149. /*###################### SPI1 ###################################*/
  150. #define NUCLEO_SPIx SPI1
  151. #define NUCLEO_SPIx_CLK_ENABLE() __HAL_RCC_SPI1_CLK_ENABLE()
  152. #define NUCLEO_SPIx_SCK_AF GPIO_AF5_SPI1
  153. #define NUCLEO_SPIx_SCK_GPIO_PORT GPIOA
  154. #define NUCLEO_SPIx_SCK_PIN GPIO_PIN_5
  155. #define NUCLEO_SPIx_SCK_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  156. #define NUCLEO_SPIx_SCK_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
  157. #define NUCLEO_SPIx_MISO_MOSI_AF GPIO_AF5_SPI1
  158. #define NUCLEO_SPIx_MISO_MOSI_GPIO_PORT GPIOA
  159. #define NUCLEO_SPIx_MISO_MOSI_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  160. #define NUCLEO_SPIx_MISO_MOSI_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
  161. #define NUCLEO_SPIx_MISO_PIN GPIO_PIN_6
  162. #define NUCLEO_SPIx_MOSI_PIN GPIO_PIN_7
  163. /* Maximum Timeout values for flags waiting loops. These timeouts are not based
  164. on accurate values, they just guarantee that the application will not remain
  165. stuck if the SPI communication is corrupted.
  166. You may modify these timeout values depending on CPU frequency and application
  167. conditions (interrupts routines ...). */
  168. #define NUCLEO_SPIx_TIMEOUT_MAX 1000
  169. /**
  170. * @brief SD Control Lines management
  171. */
  172. #define SD_CS_LOW() HAL_GPIO_WritePin(SD_CS_GPIO_PORT, SD_CS_PIN, GPIO_PIN_RESET)
  173. #define SD_CS_HIGH() HAL_GPIO_WritePin(SD_CS_GPIO_PORT, SD_CS_PIN, GPIO_PIN_SET)
  174. /**
  175. * @brief LCD Control Lines management
  176. */
  177. #define LCD_CS_LOW() HAL_GPIO_WritePin(LCD_CS_GPIO_PORT, LCD_CS_PIN, GPIO_PIN_RESET)
  178. #define LCD_CS_HIGH() HAL_GPIO_WritePin(LCD_CS_GPIO_PORT, LCD_CS_PIN, GPIO_PIN_SET)
  179. #define LCD_DC_LOW() HAL_GPIO_WritePin(LCD_DC_GPIO_PORT, LCD_DC_PIN, GPIO_PIN_RESET)
  180. #define LCD_DC_HIGH() HAL_GPIO_WritePin(LCD_DC_GPIO_PORT, LCD_DC_PIN, GPIO_PIN_SET)
  181. /**
  182. * @brief SD Control Interface pins
  183. */
  184. #define SD_CS_PIN GPIO_PIN_10
  185. #define SD_CS_GPIO_PORT GPIOC
  186. #define SD_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
  187. #define SD_CS_GPIO_CLK_DISABLE() __HAL_RCC_GPIOC_CLK_DISABLE()
  188. /**
  189. * @brief LCD Control Interface pins
  190. */
  191. #define LCD_CS_PIN GPIO_PIN_4
  192. #define LCD_CS_GPIO_PORT GPIOA
  193. #define LCD_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  194. #define LCD_CS_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
  195. /**
  196. * @brief LCD Data/Command Interface pins
  197. */
  198. #define LCD_DC_PIN GPIO_PIN_12
  199. #define LCD_DC_GPIO_PORT GPIOC
  200. #define LCD_DC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
  201. #define LCD_DC_GPIO_CLK_DISABLE() __HAL_RCC_GPIOC_CLK_DISABLE()
  202. /*##################### ADC1 ###################################*/
  203. /**
  204. * @brief ADC Interface pins
  205. * used to detect motion of Joystick available on Adafruit 1.8" TFT shield
  206. */
  207. #define NUCLEO_ADCx ADC1
  208. #define NUCLEO_ADCx_CLK_ENABLE() __HAL_RCC_ADC_CLK_ENABLE()
  209. #define NUCLEO_ADCx_GPIO_PORT GPIOA
  210. #define NUCLEO_ADCx_GPIO_PIN GPIO_PIN_0
  211. #define NUCLEO_ADCx_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  212. #define NUCLEO_ADCx_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
  213. /**
  214. * @}
  215. */
  216. /**
  217. * @}
  218. */
  219. /** @addtogroup STM32WBXX_NUCLEO_Exported_Functions
  220. * @{
  221. */
  222. uint32_t BSP_GetVersion(void);
  223. /** @addtogroup STM32WBXX_NUCLEO_LED_Functions
  224. * @{
  225. */
  226. void BSP_LED_Init(Led_TypeDef Led);
  227. void BSP_LED_DeInit(Led_TypeDef Led);
  228. void BSP_LED_On(Led_TypeDef Led);
  229. void BSP_LED_Off(Led_TypeDef Led);
  230. void BSP_LED_Toggle(Led_TypeDef Led);
  231. /**
  232. * @}
  233. */
  234. /** @addtogroup STM32WBXX_NUCLEO_BUTTON_Functions
  235. * @{
  236. */
  237. void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode);
  238. void BSP_PB_DeInit(Button_TypeDef Button);
  239. uint32_t BSP_PB_GetState(Button_TypeDef Button);
  240. #ifdef HAL_ADC_MODULE_ENABLED
  241. uint8_t BSP_JOY_Init(void);
  242. JOYState_TypeDef BSP_JOY_GetState(void);
  243. #endif /* HAL_ADC_MODULE_ENABLED */
  244. /**
  245. * @}
  246. */
  247. /**
  248. * @}
  249. */
  250. /**
  251. * @}
  252. */
  253. /**
  254. * @}
  255. */
  256. #ifdef __cplusplus
  257. }
  258. #endif
  259. #endif /* __STM32WBXX_NUCLEO_H */