stm32l4xx_hal_irda_ex.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_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</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef __STM32L4xx_HAL_IRDA_EX_H
  37. #define __STM32L4xx_HAL_IRDA_EX_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32l4xx_hal_def.h"
  43. /** @addtogroup STM32L4xx_HAL_Driver
  44. * @{
  45. */
  46. /** @addtogroup IRDAEx
  47. * @{
  48. */
  49. /* Exported types ------------------------------------------------------------*/
  50. /* Exported constants --------------------------------------------------------*/
  51. /* Exported macros -----------------------------------------------------------*/
  52. /* Exported functions --------------------------------------------------------*/
  53. /* Private macros ------------------------------------------------------------*/
  54. /** @defgroup IRDAEx_Private_Macros IRDAEx Private Macros
  55. * @{
  56. */
  57. /** @brief Report the IRDA clock source.
  58. * @param __HANDLE__ specifies the IRDA Handle.
  59. * @param __CLOCKSOURCE__ output variable.
  60. * @retval IRDA clocking source, written in __CLOCKSOURCE__.
  61. */
  62. #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
  63. defined (STM32L496xx) || defined (STM32L4A6xx) || \
  64. defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
  65. #define IRDA_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
  66. do { \
  67. if((__HANDLE__)->Instance == USART1) \
  68. { \
  69. switch(__HAL_RCC_GET_USART1_SOURCE()) \
  70. { \
  71. case RCC_USART1CLKSOURCE_PCLK2: \
  72. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK2; \
  73. break; \
  74. case RCC_USART1CLKSOURCE_HSI: \
  75. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  76. break; \
  77. case RCC_USART1CLKSOURCE_SYSCLK: \
  78. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \
  79. break; \
  80. case RCC_USART1CLKSOURCE_LSE: \
  81. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  82. break; \
  83. default: \
  84. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \
  85. break; \
  86. } \
  87. } \
  88. else if((__HANDLE__)->Instance == USART2) \
  89. { \
  90. switch(__HAL_RCC_GET_USART2_SOURCE()) \
  91. { \
  92. case RCC_USART2CLKSOURCE_PCLK1: \
  93. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \
  94. break; \
  95. case RCC_USART2CLKSOURCE_HSI: \
  96. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  97. break; \
  98. case RCC_USART2CLKSOURCE_SYSCLK: \
  99. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \
  100. break; \
  101. case RCC_USART2CLKSOURCE_LSE: \
  102. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  103. break; \
  104. default: \
  105. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \
  106. break; \
  107. } \
  108. } \
  109. else if((__HANDLE__)->Instance == USART3) \
  110. { \
  111. switch(__HAL_RCC_GET_USART3_SOURCE()) \
  112. { \
  113. case RCC_USART3CLKSOURCE_PCLK1: \
  114. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \
  115. break; \
  116. case RCC_USART3CLKSOURCE_HSI: \
  117. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  118. break; \
  119. case RCC_USART3CLKSOURCE_SYSCLK: \
  120. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \
  121. break; \
  122. case RCC_USART3CLKSOURCE_LSE: \
  123. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  124. break; \
  125. default: \
  126. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \
  127. break; \
  128. } \
  129. } \
  130. else if((__HANDLE__)->Instance == UART4) \
  131. { \
  132. switch(__HAL_RCC_GET_UART4_SOURCE()) \
  133. { \
  134. case RCC_UART4CLKSOURCE_PCLK1: \
  135. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \
  136. break; \
  137. case RCC_UART4CLKSOURCE_HSI: \
  138. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  139. break; \
  140. case RCC_UART4CLKSOURCE_SYSCLK: \
  141. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \
  142. break; \
  143. case RCC_UART4CLKSOURCE_LSE: \
  144. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  145. break; \
  146. default: \
  147. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \
  148. break; \
  149. } \
  150. } \
  151. else if ((__HANDLE__)->Instance == UART5) \
  152. { \
  153. switch(__HAL_RCC_GET_UART5_SOURCE()) \
  154. { \
  155. case RCC_UART5CLKSOURCE_PCLK1: \
  156. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \
  157. break; \
  158. case RCC_UART5CLKSOURCE_HSI: \
  159. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  160. break; \
  161. case RCC_UART5CLKSOURCE_SYSCLK: \
  162. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \
  163. break; \
  164. case RCC_UART5CLKSOURCE_LSE: \
  165. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  166. break; \
  167. default: \
  168. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \
  169. break; \
  170. } \
  171. } \
  172. } while(0)
  173. #elif defined (STM32L431xx) || defined (STM32L433xx) || defined (STM32L443xx)
  174. #define IRDA_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
  175. do { \
  176. if((__HANDLE__)->Instance == USART1) \
  177. { \
  178. switch(__HAL_RCC_GET_USART1_SOURCE()) \
  179. { \
  180. case RCC_USART1CLKSOURCE_PCLK2: \
  181. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK2; \
  182. break; \
  183. case RCC_USART1CLKSOURCE_HSI: \
  184. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  185. break; \
  186. case RCC_USART1CLKSOURCE_SYSCLK: \
  187. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \
  188. break; \
  189. case RCC_USART1CLKSOURCE_LSE: \
  190. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  191. break; \
  192. default: \
  193. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \
  194. break; \
  195. } \
  196. } \
  197. else if((__HANDLE__)->Instance == USART2) \
  198. { \
  199. switch(__HAL_RCC_GET_USART2_SOURCE()) \
  200. { \
  201. case RCC_USART2CLKSOURCE_PCLK1: \
  202. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \
  203. break; \
  204. case RCC_USART2CLKSOURCE_HSI: \
  205. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  206. break; \
  207. case RCC_USART2CLKSOURCE_SYSCLK: \
  208. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \
  209. break; \
  210. case RCC_USART2CLKSOURCE_LSE: \
  211. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  212. break; \
  213. default: \
  214. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \
  215. break; \
  216. } \
  217. } \
  218. else if((__HANDLE__)->Instance == USART3) \
  219. { \
  220. switch(__HAL_RCC_GET_USART3_SOURCE()) \
  221. { \
  222. case RCC_USART3CLKSOURCE_PCLK1: \
  223. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \
  224. break; \
  225. case RCC_USART3CLKSOURCE_HSI: \
  226. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  227. break; \
  228. case RCC_USART3CLKSOURCE_SYSCLK: \
  229. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \
  230. break; \
  231. case RCC_USART3CLKSOURCE_LSE: \
  232. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  233. break; \
  234. default: \
  235. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \
  236. break; \
  237. } \
  238. } \
  239. } while(0)
  240. #elif defined (STM32L432xx) || defined (STM32L442xx)
  241. #define IRDA_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
  242. do { \
  243. if((__HANDLE__)->Instance == USART1) \
  244. { \
  245. switch(__HAL_RCC_GET_USART1_SOURCE()) \
  246. { \
  247. case RCC_USART1CLKSOURCE_PCLK2: \
  248. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK2; \
  249. break; \
  250. case RCC_USART1CLKSOURCE_HSI: \
  251. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  252. break; \
  253. case RCC_USART1CLKSOURCE_SYSCLK: \
  254. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \
  255. break; \
  256. case RCC_USART1CLKSOURCE_LSE: \
  257. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  258. break; \
  259. default: \
  260. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \
  261. break; \
  262. } \
  263. } \
  264. else if((__HANDLE__)->Instance == USART2) \
  265. { \
  266. switch(__HAL_RCC_GET_USART2_SOURCE()) \
  267. { \
  268. case RCC_USART2CLKSOURCE_PCLK1: \
  269. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \
  270. break; \
  271. case RCC_USART2CLKSOURCE_HSI: \
  272. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  273. break; \
  274. case RCC_USART2CLKSOURCE_SYSCLK: \
  275. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \
  276. break; \
  277. case RCC_USART2CLKSOURCE_LSE: \
  278. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  279. break; \
  280. default: \
  281. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \
  282. break; \
  283. } \
  284. } \
  285. } while(0)
  286. #elif defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx)
  287. #define IRDA_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
  288. do { \
  289. if((__HANDLE__)->Instance == USART1) \
  290. { \
  291. switch(__HAL_RCC_GET_USART1_SOURCE()) \
  292. { \
  293. case RCC_USART1CLKSOURCE_PCLK2: \
  294. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK2; \
  295. break; \
  296. case RCC_USART1CLKSOURCE_HSI: \
  297. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  298. break; \
  299. case RCC_USART1CLKSOURCE_SYSCLK: \
  300. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \
  301. break; \
  302. case RCC_USART1CLKSOURCE_LSE: \
  303. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  304. break; \
  305. default: \
  306. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \
  307. break; \
  308. } \
  309. } \
  310. else if((__HANDLE__)->Instance == USART2) \
  311. { \
  312. switch(__HAL_RCC_GET_USART2_SOURCE()) \
  313. { \
  314. case RCC_USART2CLKSOURCE_PCLK1: \
  315. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \
  316. break; \
  317. case RCC_USART2CLKSOURCE_HSI: \
  318. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  319. break; \
  320. case RCC_USART2CLKSOURCE_SYSCLK: \
  321. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \
  322. break; \
  323. case RCC_USART2CLKSOURCE_LSE: \
  324. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  325. break; \
  326. default: \
  327. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \
  328. break; \
  329. } \
  330. } \
  331. else if((__HANDLE__)->Instance == USART3) \
  332. { \
  333. switch(__HAL_RCC_GET_USART3_SOURCE()) \
  334. { \
  335. case RCC_USART3CLKSOURCE_PCLK1: \
  336. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \
  337. break; \
  338. case RCC_USART3CLKSOURCE_HSI: \
  339. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  340. break; \
  341. case RCC_USART3CLKSOURCE_SYSCLK: \
  342. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \
  343. break; \
  344. case RCC_USART3CLKSOURCE_LSE: \
  345. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  346. break; \
  347. default: \
  348. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \
  349. break; \
  350. } \
  351. } \
  352. else if((__HANDLE__)->Instance == UART4) \
  353. { \
  354. switch(__HAL_RCC_GET_UART4_SOURCE()) \
  355. { \
  356. case RCC_UART4CLKSOURCE_PCLK1: \
  357. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \
  358. break; \
  359. case RCC_UART4CLKSOURCE_HSI: \
  360. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  361. break; \
  362. case RCC_UART4CLKSOURCE_SYSCLK: \
  363. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \
  364. break; \
  365. case RCC_UART4CLKSOURCE_LSE: \
  366. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  367. break; \
  368. default: \
  369. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \
  370. break; \
  371. } \
  372. } \
  373. } while(0)
  374. #endif
  375. /**
  376. * @}
  377. */
  378. /* Exported functions --------------------------------------------------------*/
  379. /**
  380. * @}
  381. */
  382. /**
  383. * @}
  384. */
  385. #ifdef __cplusplus
  386. }
  387. #endif
  388. #endif /* __STM32L4xx_HAL_IRDA_EX_H */
  389. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/