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.

stm32l1xx_nucleo.h 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /**
  2. ******************************************************************************
  3. * @file stm32l1xx_nucleo.h
  4. * @author MCD Application Team
  5. * @brief This file contains definitions for:
  6. * - LEDs and push-button available on STM32L1XX-Nucleo Kit
  7. * from STMicroelectronics
  8. * - LCD, joystick and microSD available on Adafruit 1.8 TFT LCD
  9. * shield (reference ID 802)
  10. ******************************************************************************
  11. * @attention
  12. *
  13. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  14. * All rights reserved.</center></h2>
  15. *
  16. * This software component is licensed by ST under BSD 3-Clause license,
  17. * the "License"; You may not use this file except in compliance with the
  18. * License. You may obtain a copy of the License at:
  19. * opensource.org/licenses/BSD-3-Clause
  20. *
  21. ******************************************************************************
  22. */
  23. /* Define to prevent recursive inclusion -------------------------------------*/
  24. #ifndef __STM32L1XX_NUCLEO_H
  25. #define __STM32L1XX_NUCLEO_H
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. /** @addtogroup BSP
  30. * @{
  31. */
  32. /** @addtogroup STM32L1XX_NUCLEO
  33. * @{
  34. */
  35. /* Includes ------------------------------------------------------------------*/
  36. #include "stm32l1xx_hal.h"
  37. /** @defgroup STM32L1XX_NUCLEO_Exported_Types Exported Types
  38. * @{
  39. */
  40. typedef enum
  41. {
  42. LED2 = 0,
  43. LED_GREEN = LED2
  44. } Led_TypeDef;
  45. typedef enum
  46. {
  47. BUTTON_USER = 0,
  48. /* Alias */
  49. BUTTON_KEY = BUTTON_USER
  50. } Button_TypeDef;
  51. typedef enum
  52. {
  53. BUTTON_MODE_GPIO = 0,
  54. BUTTON_MODE_EXTI = 1
  55. } ButtonMode_TypeDef;
  56. typedef enum
  57. {
  58. JOY_NONE = 0,
  59. JOY_SEL = 1,
  60. JOY_DOWN = 2,
  61. JOY_LEFT = 3,
  62. JOY_RIGHT = 4,
  63. JOY_UP = 5
  64. } JOYState_TypeDef;
  65. /**
  66. * @}
  67. */
  68. /** @defgroup STM32L1XX_NUCLEO_Exported_Constants Exported Constants
  69. * @{
  70. */
  71. /**
  72. * @brief Define for STM32L1xx_NUCLEO board
  73. */
  74. #if !defined (USE_STM32L1xx_NUCLEO)
  75. #define USE_STM32L1xx_NUCLEO
  76. #endif
  77. /** @defgroup STM32L1XX_NUCLEO_LED LED Constants
  78. * @{
  79. */
  80. #define LEDn 1
  81. #define LED2_PIN GPIO_PIN_5
  82. #define LED2_GPIO_PORT GPIOA
  83. #define LED2_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  84. #define LED2_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
  85. #define LEDx_GPIO_CLK_ENABLE(__INDEX__) do { if((__INDEX__) == 0) LED2_GPIO_CLK_ENABLE();} while(0)
  86. #define LEDx_GPIO_CLK_DISABLE(__INDEX__) (((__INDEX__) == 0) ? LED2_GPIO_CLK_DISABLE() : 0)
  87. /**
  88. * @}
  89. */
  90. /** @defgroup STM32L1XX_NUCLEO_BUTTON BUTTON Constants
  91. * @{
  92. */
  93. #define BUTTONn 1
  94. /**
  95. * @brief User push-button
  96. */
  97. #define USER_BUTTON_PIN GPIO_PIN_13
  98. #define USER_BUTTON_GPIO_PORT GPIOC
  99. #define USER_BUTTON_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
  100. #define USER_BUTTON_GPIO_CLK_DISABLE() __HAL_RCC_GPIOC_CLK_DISABLE()
  101. #define USER_BUTTON_EXTI_IRQn EXTI15_10_IRQn
  102. /* Aliases */
  103. #define KEY_BUTTON_PIN USER_BUTTON_PIN
  104. #define KEY_BUTTON_GPIO_PORT USER_BUTTON_GPIO_PORT
  105. #define KEY_BUTTON_GPIO_CLK_ENABLE() USER_BUTTON_GPIO_CLK_ENABLE()
  106. #define KEY_BUTTON_GPIO_CLK_DISABLE() USER_BUTTON_GPIO_CLK_DISABLE()
  107. #define KEY_BUTTON_EXTI_IRQn USER_BUTTON_EXTI_IRQn
  108. #define BUTTONx_GPIO_CLK_ENABLE(__INDEX__) do { if((__INDEX__) == 0) USER_BUTTON_GPIO_CLK_ENABLE();} while(0)
  109. #define BUTTONx_GPIO_CLK_DISABLE(__INDEX__) (((__INDEX__) == 0) ? USER_BUTTON_GPIO_CLK_DISABLE() : 0)
  110. /**
  111. * @}
  112. */
  113. /** @addtogroup STM32L1XX_NUCLEO_BUS BUS Constants
  114. * @{
  115. */
  116. /*###################### SPI1 ###################################*/
  117. #define NUCLEO_SPIx SPI1
  118. #define NUCLEO_SPIx_CLK_ENABLE() __HAL_RCC_SPI1_CLK_ENABLE()
  119. #define NUCLEO_SPIx_SCK_AF GPIO_AF5_SPI1
  120. #define NUCLEO_SPIx_SCK_GPIO_PORT GPIOA
  121. #define NUCLEO_SPIx_SCK_PIN GPIO_PIN_5
  122. #define NUCLEO_SPIx_SCK_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  123. #define NUCLEO_SPIx_SCK_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
  124. #define NUCLEO_SPIx_MISO_MOSI_AF GPIO_AF5_SPI1
  125. #define NUCLEO_SPIx_MISO_MOSI_GPIO_PORT GPIOA
  126. #define NUCLEO_SPIx_MISO_MOSI_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  127. #define NUCLEO_SPIx_MISO_MOSI_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
  128. #define NUCLEO_SPIx_MISO_PIN GPIO_PIN_6
  129. #define NUCLEO_SPIx_MOSI_PIN GPIO_PIN_7
  130. /* Maximum Timeout values for flags waiting loops. These timeouts are not based
  131. on accurate values, they just guarantee that the application will not remain
  132. stuck if the SPI communication is corrupted.
  133. You may modify these timeout values depending on CPU frequency and application
  134. conditions (interrupts routines ...). */
  135. #define NUCLEO_SPIx_TIMEOUT_MAX 1000
  136. /**
  137. * @brief SD Control Lines management
  138. */
  139. #define SD_CS_LOW() HAL_GPIO_WritePin(SD_CS_GPIO_PORT, SD_CS_PIN, GPIO_PIN_RESET)
  140. #define SD_CS_HIGH() HAL_GPIO_WritePin(SD_CS_GPIO_PORT, SD_CS_PIN, GPIO_PIN_SET)
  141. /**
  142. * @brief LCD Control Lines management
  143. */
  144. #define LCD_CS_LOW() HAL_GPIO_WritePin(LCD_CS_GPIO_PORT, LCD_CS_PIN, GPIO_PIN_RESET)
  145. #define LCD_CS_HIGH() HAL_GPIO_WritePin(LCD_CS_GPIO_PORT, LCD_CS_PIN, GPIO_PIN_SET)
  146. #define LCD_DC_LOW() HAL_GPIO_WritePin(LCD_DC_GPIO_PORT, LCD_DC_PIN, GPIO_PIN_RESET)
  147. #define LCD_DC_HIGH() HAL_GPIO_WritePin(LCD_DC_GPIO_PORT, LCD_DC_PIN, GPIO_PIN_SET)
  148. /**
  149. * @brief SD Control Interface pins (shield D4)
  150. */
  151. #define SD_CS_PIN GPIO_PIN_5
  152. #define SD_CS_GPIO_PORT GPIOB
  153. #define SD_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
  154. #define SD_CS_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
  155. /**
  156. * @brief LCD Control Interface pins (shield D10)
  157. */
  158. #define LCD_CS_PIN GPIO_PIN_6
  159. #define LCD_CS_GPIO_PORT GPIOB
  160. #define LCD_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
  161. #define LCD_CS_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
  162. /**
  163. * @brief LCD Data/Command Interface pins
  164. */
  165. #define LCD_DC_PIN GPIO_PIN_9
  166. #define LCD_DC_GPIO_PORT GPIOA
  167. #define LCD_DC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  168. #define LCD_DC_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
  169. /*##################### ADC1 ###################################*/
  170. /**
  171. * @brief ADC Interface pins
  172. * used to detect motion of Joystick available on Adafruit 1.8 TFT shield
  173. */
  174. #define NUCLEO_ADCx ADC1
  175. #define NUCLEO_ADCx_CLK_ENABLE() __HAL_RCC_ADC1_CLK_ENABLE()
  176. #define NUCLEO_ADCx_CLK_DISABLE() __HAL_RCC_ADC1_CLK_DISABLE()
  177. #define NUCLEO_ADCx_GPIO_PORT GPIOB
  178. #define NUCLEO_ADCx_GPIO_PIN GPIO_PIN_0
  179. #define NUCLEO_ADCx_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
  180. #define NUCLEO_ADCx_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
  181. /**
  182. * @}
  183. */
  184. /**
  185. * @}
  186. */
  187. /** @addtogroup STM32L1XX_NUCLEO_Exported_Functions
  188. * @{
  189. */
  190. uint32_t BSP_GetVersion(void);
  191. /** @addtogroup STM32L1XX_NUCLEO_LED_Functions
  192. * @{
  193. */
  194. void BSP_LED_Init(Led_TypeDef Led);
  195. void BSP_LED_DeInit(Led_TypeDef Led);
  196. void BSP_LED_On(Led_TypeDef Led);
  197. void BSP_LED_Off(Led_TypeDef Led);
  198. void BSP_LED_Toggle(Led_TypeDef Led);
  199. /**
  200. * @}
  201. */
  202. /** @addtogroup STM32L1XX_NUCLEO_BUTTON_Functions
  203. * @{
  204. */
  205. void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode);
  206. void BSP_PB_DeInit(Button_TypeDef Button);
  207. uint32_t BSP_PB_GetState(Button_TypeDef Button);
  208. #if defined(HAL_ADC_MODULE_ENABLED)
  209. uint8_t BSP_JOY_Init(void);
  210. JOYState_TypeDef BSP_JOY_GetState(void);
  211. void BSP_JOY_DeInit(void);
  212. #endif /* HAL_ADC_MODULE_ENABLED */
  213. /**
  214. * @}
  215. */
  216. /**
  217. * @}
  218. */
  219. /**
  220. * @}
  221. */
  222. /**
  223. * @}
  224. */
  225. #ifdef __cplusplus
  226. }
  227. #endif
  228. #endif /* __STM32L1XX_NUCLEO_H */
  229. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/