stm32f7xx_hal_irda_ex.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_irda_ex.h
  4. * @author MCD Application Team
  5. * @version V1.2.0
  6. * @date 30-December-2016
  7. * @brief Header file of IRDA HAL Extension module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32F7xx_HAL_IRDA_EX_H
  39. #define __STM32F7xx_HAL_IRDA_EX_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f7xx_hal_def.h"
  45. /** @addtogroup STM32F7xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup IRDAEx
  49. * @{
  50. */
  51. /* Exported types ------------------------------------------------------------*/
  52. /* Exported constants --------------------------------------------------------*/
  53. /** @defgroup IRDAEx_Extended_Exported_Constants IRDAEx Extended Exported Constants
  54. * @{
  55. */
  56. /** @defgroup IRDAEx_Word_Length IRDAEx Word Length
  57. * @{
  58. */
  59. #define IRDA_WORDLENGTH_7B ((uint32_t)USART_CR1_M_1)
  60. #define IRDA_WORDLENGTH_8B ((uint32_t)0x00000000U)
  61. #define IRDA_WORDLENGTH_9B ((uint32_t)USART_CR1_M_0)
  62. /**
  63. * @}
  64. */
  65. /**
  66. * @}
  67. */
  68. /* Exported macro ------------------------------------------------------------*/
  69. /* Private macros ------------------------------------------------------------*/
  70. /** @defgroup IRDAEx_Private_Macros IRDAEx Private Macros
  71. * @{
  72. */
  73. /** @brief Reports the IRDA clock source.
  74. * @param __HANDLE__: specifies the IRDA Handle
  75. * @param __CLOCKSOURCE__ : output variable
  76. * @retval IRDA clocking source, written in __CLOCKSOURCE__.
  77. */
  78. #define IRDA_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
  79. do { \
  80. if((__HANDLE__)->Instance == USART1) \
  81. { \
  82. switch(__HAL_RCC_GET_USART1_SOURCE()) \
  83. { \
  84. case RCC_USART1CLKSOURCE_PCLK2: \
  85. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK2; \
  86. break; \
  87. case RCC_USART1CLKSOURCE_HSI: \
  88. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  89. break; \
  90. case RCC_USART1CLKSOURCE_SYSCLK: \
  91. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \
  92. break; \
  93. case RCC_USART1CLKSOURCE_LSE: \
  94. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  95. break; \
  96. default: \
  97. break; \
  98. } \
  99. } \
  100. else if((__HANDLE__)->Instance == USART2) \
  101. { \
  102. switch(__HAL_RCC_GET_USART2_SOURCE()) \
  103. { \
  104. case RCC_USART2CLKSOURCE_PCLK1: \
  105. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \
  106. break; \
  107. case RCC_USART2CLKSOURCE_HSI: \
  108. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  109. break; \
  110. case RCC_USART2CLKSOURCE_SYSCLK: \
  111. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \
  112. break; \
  113. case RCC_USART2CLKSOURCE_LSE: \
  114. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  115. break; \
  116. default: \
  117. break; \
  118. } \
  119. } \
  120. else if((__HANDLE__)->Instance == USART3) \
  121. { \
  122. switch(__HAL_RCC_GET_USART3_SOURCE()) \
  123. { \
  124. case RCC_USART3CLKSOURCE_PCLK1: \
  125. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \
  126. break; \
  127. case RCC_USART3CLKSOURCE_HSI: \
  128. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  129. break; \
  130. case RCC_USART3CLKSOURCE_SYSCLK: \
  131. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \
  132. break; \
  133. case RCC_USART3CLKSOURCE_LSE: \
  134. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  135. break; \
  136. default: \
  137. break; \
  138. } \
  139. } \
  140. else if((__HANDLE__)->Instance == USART6) \
  141. { \
  142. switch(__HAL_RCC_GET_USART6_SOURCE()) \
  143. { \
  144. case RCC_USART6CLKSOURCE_PCLK2: \
  145. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK2; \
  146. break; \
  147. case RCC_USART6CLKSOURCE_HSI: \
  148. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  149. break; \
  150. case RCC_USART6CLKSOURCE_SYSCLK: \
  151. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \
  152. break; \
  153. case RCC_USART6CLKSOURCE_LSE: \
  154. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  155. break; \
  156. default: \
  157. break; \
  158. } \
  159. } \
  160. } while(0)
  161. /** @brief Reports the mask to apply to retrieve the received data
  162. * according to the word length and to the parity bits activation.
  163. * @param __HANDLE__: specifies the IRDA Handle
  164. * @retval mask to apply to USART RDR register value.
  165. */
  166. #define IRDA_MASK_COMPUTATION(__HANDLE__) \
  167. do { \
  168. if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_9B) \
  169. { \
  170. if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE) \
  171. { \
  172. (__HANDLE__)->Mask = 0x01FF ; \
  173. } \
  174. else \
  175. { \
  176. (__HANDLE__)->Mask = 0x00FF ; \
  177. } \
  178. } \
  179. else if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_8B) \
  180. { \
  181. if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE) \
  182. { \
  183. (__HANDLE__)->Mask = 0x00FF ; \
  184. } \
  185. else \
  186. { \
  187. (__HANDLE__)->Mask = 0x007F ; \
  188. } \
  189. } \
  190. else if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_7B) \
  191. { \
  192. if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE) \
  193. { \
  194. (__HANDLE__)->Mask = 0x007F ; \
  195. } \
  196. else \
  197. { \
  198. (__HANDLE__)->Mask = 0x003F ; \
  199. } \
  200. } \
  201. } while(0)
  202. #define IS_IRDA_WORD_LENGTH(LENGTH) (((LENGTH) == IRDA_WORDLENGTH_7B) || \
  203. ((LENGTH) == IRDA_WORDLENGTH_8B) || \
  204. ((LENGTH) == IRDA_WORDLENGTH_9B))
  205. /**
  206. * @}
  207. */
  208. /* Exported functions --------------------------------------------------------*/
  209. /**
  210. * @}
  211. */
  212. /**
  213. * @}
  214. */
  215. #ifdef __cplusplus
  216. }
  217. #endif
  218. #endif /* __STM32F7xx_HAL_IRDA_EX_H */
  219. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/