stm32f7xx_hal_irda_ex.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_irda_ex.h
  4. * @author MCD Application Team
  5. * @brief Header file of IRDA HAL Extension 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 __STM32F7xx_HAL_IRDA_EX_H
  37. #define __STM32F7xx_HAL_IRDA_EX_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32f7xx_hal_def.h"
  43. /** @addtogroup STM32F7xx_HAL_Driver
  44. * @{
  45. */
  46. /** @addtogroup IRDAEx
  47. * @{
  48. */
  49. /* Exported types ------------------------------------------------------------*/
  50. /* Exported constants --------------------------------------------------------*/
  51. /** @defgroup IRDAEx_Extended_Exported_Constants IRDAEx Extended Exported Constants
  52. * @{
  53. */
  54. /** @defgroup IRDAEx_Word_Length IRDAEx Word Length
  55. * @{
  56. */
  57. #define IRDA_WORDLENGTH_7B ((uint32_t)USART_CR1_M_1)
  58. #define IRDA_WORDLENGTH_8B ((uint32_t)0x00000000U)
  59. #define IRDA_WORDLENGTH_9B ((uint32_t)USART_CR1_M_0)
  60. /**
  61. * @}
  62. */
  63. /**
  64. * @}
  65. */
  66. /* Exported macro ------------------------------------------------------------*/
  67. /* Private macros ------------------------------------------------------------*/
  68. /** @defgroup IRDAEx_Private_Macros IRDAEx Private Macros
  69. * @{
  70. */
  71. /** @brief Reports the IRDA clock source.
  72. * @param __HANDLE__ specifies the IRDA Handle
  73. * @param __CLOCKSOURCE__ output variable
  74. * @retval IRDA clocking source, written in __CLOCKSOURCE__.
  75. */
  76. #define IRDA_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
  77. do { \
  78. if((__HANDLE__)->Instance == USART1) \
  79. { \
  80. switch(__HAL_RCC_GET_USART1_SOURCE()) \
  81. { \
  82. case RCC_USART1CLKSOURCE_PCLK2: \
  83. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK2; \
  84. break; \
  85. case RCC_USART1CLKSOURCE_HSI: \
  86. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  87. break; \
  88. case RCC_USART1CLKSOURCE_SYSCLK: \
  89. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \
  90. break; \
  91. case RCC_USART1CLKSOURCE_LSE: \
  92. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  93. break; \
  94. default: \
  95. break; \
  96. } \
  97. } \
  98. else if((__HANDLE__)->Instance == USART2) \
  99. { \
  100. switch(__HAL_RCC_GET_USART2_SOURCE()) \
  101. { \
  102. case RCC_USART2CLKSOURCE_PCLK1: \
  103. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \
  104. break; \
  105. case RCC_USART2CLKSOURCE_HSI: \
  106. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  107. break; \
  108. case RCC_USART2CLKSOURCE_SYSCLK: \
  109. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \
  110. break; \
  111. case RCC_USART2CLKSOURCE_LSE: \
  112. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  113. break; \
  114. default: \
  115. break; \
  116. } \
  117. } \
  118. else if((__HANDLE__)->Instance == USART3) \
  119. { \
  120. switch(__HAL_RCC_GET_USART3_SOURCE()) \
  121. { \
  122. case RCC_USART3CLKSOURCE_PCLK1: \
  123. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \
  124. break; \
  125. case RCC_USART3CLKSOURCE_HSI: \
  126. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  127. break; \
  128. case RCC_USART3CLKSOURCE_SYSCLK: \
  129. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \
  130. break; \
  131. case RCC_USART3CLKSOURCE_LSE: \
  132. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  133. break; \
  134. default: \
  135. break; \
  136. } \
  137. } \
  138. else if((__HANDLE__)->Instance == USART6) \
  139. { \
  140. switch(__HAL_RCC_GET_USART6_SOURCE()) \
  141. { \
  142. case RCC_USART6CLKSOURCE_PCLK2: \
  143. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK2; \
  144. break; \
  145. case RCC_USART6CLKSOURCE_HSI: \
  146. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
  147. break; \
  148. case RCC_USART6CLKSOURCE_SYSCLK: \
  149. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \
  150. break; \
  151. case RCC_USART6CLKSOURCE_LSE: \
  152. (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
  153. break; \
  154. default: \
  155. break; \
  156. } \
  157. } \
  158. } while(0)
  159. /** @brief Reports the mask to apply to retrieve the received data
  160. * according to the word length and to the parity bits activation.
  161. * @param __HANDLE__ specifies the IRDA Handle
  162. * @retval mask to apply to USART RDR register value.
  163. */
  164. #define IRDA_MASK_COMPUTATION(__HANDLE__) \
  165. do { \
  166. if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_9B) \
  167. { \
  168. if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE) \
  169. { \
  170. (__HANDLE__)->Mask = 0x01FF ; \
  171. } \
  172. else \
  173. { \
  174. (__HANDLE__)->Mask = 0x00FF ; \
  175. } \
  176. } \
  177. else if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_8B) \
  178. { \
  179. if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE) \
  180. { \
  181. (__HANDLE__)->Mask = 0x00FF ; \
  182. } \
  183. else \
  184. { \
  185. (__HANDLE__)->Mask = 0x007F ; \
  186. } \
  187. } \
  188. else if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_7B) \
  189. { \
  190. if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE) \
  191. { \
  192. (__HANDLE__)->Mask = 0x007F ; \
  193. } \
  194. else \
  195. { \
  196. (__HANDLE__)->Mask = 0x003F ; \
  197. } \
  198. } \
  199. } while(0)
  200. #define IS_IRDA_WORD_LENGTH(LENGTH) (((LENGTH) == IRDA_WORDLENGTH_7B) || \
  201. ((LENGTH) == IRDA_WORDLENGTH_8B) || \
  202. ((LENGTH) == IRDA_WORDLENGTH_9B))
  203. /**
  204. * @}
  205. */
  206. /* Exported functions --------------------------------------------------------*/
  207. /**
  208. * @}
  209. */
  210. /**
  211. * @}
  212. */
  213. #ifdef __cplusplus
  214. }
  215. #endif
  216. #endif /* __STM32F7xx_HAL_IRDA_EX_H */
  217. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/