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
20 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_hal_irda_ex.h
  4. * @author MCD Application Team
  5. * @brief Header file of IRDA HAL Extended module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef STM32H7xx_HAL_IRDA_EX_H
  21. #define STM32H7xx_HAL_IRDA_EX_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32h7xx_hal_def.h"
  27. /** @addtogroup STM32H7xx_HAL_Driver
  28. * @{
  29. */
  30. /** @defgroup IRDAEx IRDAEx
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. /* Exported constants --------------------------------------------------------*/
  35. /** @defgroup IRDAEx_Extended_Exported_Constants IRDAEx Extended Exported Constants
  36. * @{
  37. */
  38. /** @defgroup IRDAEx_Word_Length IRDAEx Word Length
  39. * @{
  40. */
  41. #define IRDA_WORDLENGTH_7B USART_CR1_M1 /*!< 7-bit long frame */
  42. #define IRDA_WORDLENGTH_8B 0x00000000U /*!< 8-bit long frame */
  43. #define IRDA_WORDLENGTH_9B USART_CR1_M0 /*!< 9-bit long frame */
  44. /**
  45. * @}
  46. */
  47. /**
  48. * @}
  49. */
  50. /* Exported macros -----------------------------------------------------------*/
  51. /* Private macros ------------------------------------------------------------*/
  52. /** @defgroup IRDAEx_Private_Macros IRDAEx Private Macros
  53. * @{
  54. */
  55. /** @brief Report the IRDA clock source.
  56. * @param __HANDLE__ specifies the IRDA Handle.
  57. * @param __CLOCKSOURCE__ output variable.
  58. * @retval IRDA clocking source, written in __CLOCKSOURCE__.
  59. */
  60. #define IRDA_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
  61. do { \
  62. if((__HANDLE__)->Instance == USART1) \
  63. { \
  64. switch(__HAL_RCC_GET_USART1_SOURCE()) \
  65. { \
  66. case RCC_USART1CLKSOURCE_D2PCLK2: \
  67. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_D2PCLK2; \
  68. break; \
  69. case RCC_USART1CLKSOURCE_PLL2: \
  70. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL2Q; \
  71. break; \
  72. case RCC_USART1CLKSOURCE_PLL3: \
  73. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL3Q; \
  74. break; \
  75. case RCC_USART1CLKSOURCE_HSI: \
  76. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  77. break; \
  78. case RCC_USART1CLKSOURCE_CSI: \
  79. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_CSI; \
  80. break; \
  81. case RCC_USART1CLKSOURCE_LSE: \
  82. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  83. break; \
  84. default: \
  85. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \
  86. break; \
  87. } \
  88. } \
  89. else if((__HANDLE__)->Instance == USART2) \
  90. { \
  91. switch(__HAL_RCC_GET_USART2_SOURCE()) \
  92. { \
  93. case RCC_USART2CLKSOURCE_D2PCLK1: \
  94. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_D2PCLK1; \
  95. break; \
  96. case RCC_USART2CLKSOURCE_PLL2: \
  97. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL2Q; \
  98. break; \
  99. case RCC_USART2CLKSOURCE_PLL3: \
  100. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL3Q; \
  101. break; \
  102. case RCC_USART2CLKSOURCE_HSI: \
  103. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  104. break; \
  105. case RCC_USART2CLKSOURCE_CSI: \
  106. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_CSI; \
  107. break; \
  108. case RCC_USART2CLKSOURCE_LSE: \
  109. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  110. break; \
  111. default: \
  112. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \
  113. break; \
  114. } \
  115. } \
  116. else if((__HANDLE__)->Instance == USART3) \
  117. { \
  118. switch(__HAL_RCC_GET_USART3_SOURCE()) \
  119. { \
  120. case RCC_USART3CLKSOURCE_D2PCLK1: \
  121. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_D2PCLK1; \
  122. break; \
  123. case RCC_USART3CLKSOURCE_PLL2: \
  124. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL2Q; \
  125. break; \
  126. case RCC_USART3CLKSOURCE_PLL3: \
  127. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL3Q; \
  128. break; \
  129. case RCC_USART3CLKSOURCE_HSI: \
  130. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  131. break; \
  132. case RCC_USART3CLKSOURCE_CSI: \
  133. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_CSI; \
  134. break; \
  135. case RCC_USART3CLKSOURCE_LSE: \
  136. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  137. break; \
  138. default: \
  139. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \
  140. break; \
  141. } \
  142. } \
  143. else if((__HANDLE__)->Instance == UART4) \
  144. { \
  145. switch(__HAL_RCC_GET_UART4_SOURCE()) \
  146. { \
  147. case RCC_UART4CLKSOURCE_D2PCLK1: \
  148. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_D2PCLK1; \
  149. break; \
  150. case RCC_UART4CLKSOURCE_PLL2: \
  151. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL2Q; \
  152. break; \
  153. case RCC_UART4CLKSOURCE_PLL3: \
  154. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL3Q; \
  155. break; \
  156. case RCC_UART4CLKSOURCE_HSI: \
  157. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  158. break; \
  159. case RCC_UART4CLKSOURCE_CSI: \
  160. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_CSI; \
  161. break; \
  162. case RCC_UART4CLKSOURCE_LSE: \
  163. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  164. break; \
  165. default: \
  166. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \
  167. break; \
  168. } \
  169. } \
  170. else if ((__HANDLE__)->Instance == UART5) \
  171. { \
  172. switch(__HAL_RCC_GET_UART5_SOURCE()) \
  173. { \
  174. case RCC_UART5CLKSOURCE_D2PCLK1: \
  175. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_D2PCLK1; \
  176. break; \
  177. case RCC_UART5CLKSOURCE_PLL2: \
  178. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL2Q; \
  179. break; \
  180. case RCC_UART5CLKSOURCE_PLL3: \
  181. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL3Q; \
  182. break; \
  183. case RCC_UART5CLKSOURCE_HSI: \
  184. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  185. break; \
  186. case RCC_UART5CLKSOURCE_CSI: \
  187. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_CSI; \
  188. break; \
  189. case RCC_UART5CLKSOURCE_LSE: \
  190. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  191. break; \
  192. default: \
  193. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \
  194. break; \
  195. } \
  196. } \
  197. else if((__HANDLE__)->Instance == USART6) \
  198. { \
  199. switch(__HAL_RCC_GET_USART6_SOURCE()) \
  200. { \
  201. case RCC_USART6CLKSOURCE_D2PCLK2: \
  202. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_D2PCLK2; \
  203. break; \
  204. case RCC_USART6CLKSOURCE_PLL2: \
  205. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL2Q; \
  206. break; \
  207. case RCC_USART6CLKSOURCE_PLL3: \
  208. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL3Q; \
  209. break; \
  210. case RCC_USART6CLKSOURCE_HSI: \
  211. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  212. break; \
  213. case RCC_USART6CLKSOURCE_CSI: \
  214. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_CSI; \
  215. break; \
  216. case RCC_USART6CLKSOURCE_LSE: \
  217. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  218. break; \
  219. default: \
  220. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \
  221. break; \
  222. } \
  223. } \
  224. else if((__HANDLE__)->Instance == UART7) \
  225. { \
  226. switch(__HAL_RCC_GET_UART7_SOURCE()) \
  227. { \
  228. case RCC_UART7CLKSOURCE_D2PCLK1: \
  229. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_D2PCLK1; \
  230. break; \
  231. case RCC_UART7CLKSOURCE_PLL2: \
  232. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL2Q; \
  233. break; \
  234. case RCC_UART7CLKSOURCE_PLL3: \
  235. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL3Q; \
  236. break; \
  237. case RCC_UART7CLKSOURCE_HSI: \
  238. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  239. break; \
  240. case RCC_UART7CLKSOURCE_CSI: \
  241. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_CSI; \
  242. break; \
  243. case RCC_UART7CLKSOURCE_LSE: \
  244. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  245. break; \
  246. default: \
  247. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \
  248. break; \
  249. } \
  250. } \
  251. else if((__HANDLE__)->Instance == UART8) \
  252. { \
  253. switch(__HAL_RCC_GET_UART8_SOURCE()) \
  254. { \
  255. case RCC_UART8CLKSOURCE_D2PCLK1: \
  256. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_D2PCLK1; \
  257. break; \
  258. case RCC_UART8CLKSOURCE_PLL2: \
  259. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL2Q; \
  260. break; \
  261. case RCC_UART8CLKSOURCE_PLL3: \
  262. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL3Q; \
  263. break; \
  264. case RCC_UART8CLKSOURCE_HSI: \
  265. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  266. break; \
  267. case RCC_UART8CLKSOURCE_CSI: \
  268. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_CSI; \
  269. break; \
  270. case RCC_UART8CLKSOURCE_LSE: \
  271. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  272. break; \
  273. default: \
  274. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \
  275. break; \
  276. } \
  277. } \
  278. else \
  279. { \
  280. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \
  281. } \
  282. } while(0U)
  283. /** @brief Compute the mask to apply to retrieve the received data
  284. * according to the word length and to the parity bits activation.
  285. * @param __HANDLE__ specifies the IRDA Handle.
  286. * @retval None, the mask to apply to the associated UART RDR register is stored in (__HANDLE__)->Mask field.
  287. */
  288. #define IRDA_MASK_COMPUTATION(__HANDLE__) \
  289. do { \
  290. if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_9B) \
  291. { \
  292. if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE) \
  293. { \
  294. (__HANDLE__)->Mask = 0x01FFU ; \
  295. } \
  296. else \
  297. { \
  298. (__HANDLE__)->Mask = 0x00FFU ; \
  299. } \
  300. } \
  301. else if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_8B) \
  302. { \
  303. if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE) \
  304. { \
  305. (__HANDLE__)->Mask = 0x00FFU ; \
  306. } \
  307. else \
  308. { \
  309. (__HANDLE__)->Mask = 0x007FU ; \
  310. } \
  311. } \
  312. else if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_7B) \
  313. { \
  314. if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE) \
  315. { \
  316. (__HANDLE__)->Mask = 0x007FU ; \
  317. } \
  318. else \
  319. { \
  320. (__HANDLE__)->Mask = 0x003FU ; \
  321. } \
  322. } \
  323. else \
  324. { \
  325. (__HANDLE__)->Mask = 0x0000U; \
  326. } \
  327. } while(0U)
  328. /** @brief Ensure that IRDA frame length is valid.
  329. * @param __LENGTH__ IRDA frame length.
  330. * @retval SET (__LENGTH__ is valid) or RESET (__LENGTH__ is invalid)
  331. */
  332. #define IS_IRDA_WORD_LENGTH(__LENGTH__) (((__LENGTH__) == IRDA_WORDLENGTH_7B) || \
  333. ((__LENGTH__) == IRDA_WORDLENGTH_8B) || \
  334. ((__LENGTH__) == IRDA_WORDLENGTH_9B))
  335. /**
  336. * @}
  337. */
  338. /* Exported functions --------------------------------------------------------*/
  339. /**
  340. * @}
  341. */
  342. /**
  343. * @}
  344. */
  345. #ifdef __cplusplus
  346. }
  347. #endif
  348. #endif /* STM32H7xx_HAL_IRDA_EX_H */
  349. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/