stm32l0xx_hal_smartcard_ex.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /**
  2. ******************************************************************************
  3. * @file stm32l0xx_hal_smartcard_ex.h
  4. * @author MCD Application Team
  5. * @brief Header file of SMARTCARD HAL Extended module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2016 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* Define to prevent recursive inclusion -------------------------------------*/
  19. #ifndef STM32L0xx_HAL_SMARTCARD_EX_H
  20. #define STM32L0xx_HAL_SMARTCARD_EX_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #if !defined (STM32L010x4) && !defined (STM32L010x6)
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32l0xx_hal_def.h"
  27. /** @addtogroup STM32L0xx_HAL_Driver
  28. * @{
  29. */
  30. /** @addtogroup SMARTCARDEx
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. /* Exported constants --------------------------------------------------------*/
  35. /** @addtogroup SMARTCARDEx_Exported_Constants SMARTCARD Extended Exported Constants
  36. * @{
  37. */
  38. /** @defgroup SMARTCARDEx_Transmission_Completion_Indication SMARTCARD Transmission Completion Indication
  39. * @{
  40. */
  41. #if defined(USART_TCBGT_SUPPORT)
  42. #define SMARTCARD_TCBGT SMARTCARD_IT_TCBGT /*!< SMARTCARD transmission complete before guard time */
  43. #endif /* USART_TCBGT_SUPPORT */
  44. #define SMARTCARD_TC SMARTCARD_IT_TC /*!< SMARTCARD transmission complete (flag raised when guard time has elapsed) */
  45. /**
  46. * @}
  47. */
  48. /** @defgroup SMARTCARDEx_Advanced_Features_Initialization_Type SMARTCARD advanced feature initialization type
  49. * @{
  50. */
  51. #define SMARTCARD_ADVFEATURE_NO_INIT 0x00000000U /*!< No advanced feature initialization */
  52. #define SMARTCARD_ADVFEATURE_TXINVERT_INIT 0x00000001U /*!< TX pin active level inversion */
  53. #define SMARTCARD_ADVFEATURE_RXINVERT_INIT 0x00000002U /*!< RX pin active level inversion */
  54. #define SMARTCARD_ADVFEATURE_DATAINVERT_INIT 0x00000004U /*!< Binary data inversion */
  55. #define SMARTCARD_ADVFEATURE_SWAP_INIT 0x00000008U /*!< TX/RX pins swap */
  56. #define SMARTCARD_ADVFEATURE_RXOVERRUNDISABLE_INIT 0x00000010U /*!< RX overrun disable */
  57. #define SMARTCARD_ADVFEATURE_DMADISABLEONERROR_INIT 0x00000020U /*!< DMA disable on Reception Error */
  58. #define SMARTCARD_ADVFEATURE_MSBFIRST_INIT 0x00000080U /*!< Most significant bit sent/received first */
  59. #if defined(USART_TCBGT_SUPPORT)
  60. #define SMARTCARD_ADVFEATURE_TXCOMPLETION 0x00000100U /*!< TX completion indication before of after guard time */
  61. #endif /* USART_TCBGT_SUPPORT */
  62. /**
  63. * @}
  64. */
  65. /** @defgroup SMARTCARDEx_Flags SMARTCARD Flags
  66. * Elements values convention: 0xXXXX
  67. * - 0xXXXX : Flag mask in the ISR register
  68. * @{
  69. */
  70. #if defined(USART_TCBGT_SUPPORT)
  71. #define SMARTCARD_FLAG_TCBGT USART_ISR_TCBGT /*!< SMARTCARD transmission complete before guard time completion */
  72. #endif /* USART_TCBGT_SUPPORT */
  73. #define SMARTCARD_FLAG_REACK USART_ISR_REACK /*!< SMARTCARD receive enable acknowledge flag */
  74. #define SMARTCARD_FLAG_TEACK USART_ISR_TEACK /*!< SMARTCARD transmit enable acknowledge flag */
  75. #define SMARTCARD_FLAG_BUSY USART_ISR_BUSY /*!< SMARTCARD busy flag */
  76. #define SMARTCARD_FLAG_EOBF USART_ISR_EOBF /*!< SMARTCARD end of block flag */
  77. #define SMARTCARD_FLAG_RTOF USART_ISR_RTOF /*!< SMARTCARD receiver timeout flag */
  78. #define SMARTCARD_FLAG_TXE USART_ISR_TXE /*!< SMARTCARD transmit data register empty */
  79. #define SMARTCARD_FLAG_TC USART_ISR_TC /*!< SMARTCARD transmission complete */
  80. #define SMARTCARD_FLAG_RXNE USART_ISR_RXNE /*!< SMARTCARD read data register not empty */
  81. #define SMARTCARD_FLAG_IDLE USART_ISR_IDLE /*!< SMARTCARD idle line detection */
  82. #define SMARTCARD_FLAG_ORE USART_ISR_ORE /*!< SMARTCARD overrun error */
  83. #define SMARTCARD_FLAG_NE USART_ISR_NE /*!< SMARTCARD noise error */
  84. #define SMARTCARD_FLAG_FE USART_ISR_FE /*!< SMARTCARD frame error */
  85. #define SMARTCARD_FLAG_PE USART_ISR_PE /*!< SMARTCARD parity error */
  86. /**
  87. * @}
  88. */
  89. /** @defgroup SMARTCARDEx_Interrupt_definition SMARTCARD Interrupts Definition
  90. * Elements values convention: 000ZZZZZ0XXYYYYYb
  91. * - YYYYY : Interrupt source position in the XX register (5 bits)
  92. * - XX : Interrupt source register (2 bits)
  93. * - 01: CR1 register
  94. * - 10: CR2 register
  95. * - 11: CR3 register
  96. * - ZZZZZ : Flag position in the ISR register(5 bits)
  97. * @{
  98. */
  99. #define SMARTCARD_IT_PE 0x0028U /*!< SMARTCARD parity error interruption */
  100. #define SMARTCARD_IT_TXE 0x0727U /*!< SMARTCARD transmit data register empty interruption */
  101. #define SMARTCARD_IT_TC 0x0626U /*!< SMARTCARD transmission complete interruption */
  102. #define SMARTCARD_IT_RXNE 0x0525U /*!< SMARTCARD read data register not empty interruption */
  103. #define SMARTCARD_IT_IDLE 0x0424U /*!< SMARTCARD idle line detection interruption */
  104. #define SMARTCARD_IT_ERR 0x0060U /*!< SMARTCARD error interruption */
  105. #define SMARTCARD_IT_ORE 0x0300U /*!< SMARTCARD overrun error interruption */
  106. #define SMARTCARD_IT_NE 0x0200U /*!< SMARTCARD noise error interruption */
  107. #define SMARTCARD_IT_FE 0x0100U /*!< SMARTCARD frame error interruption */
  108. #define SMARTCARD_IT_EOB 0x0C3BU /*!< SMARTCARD end of block interruption */
  109. #define SMARTCARD_IT_RTO 0x0B3AU /*!< SMARTCARD receiver timeout interruption */
  110. #if defined(USART_TCBGT_SUPPORT)
  111. #define SMARTCARD_IT_TCBGT 0x1978U /*!< SMARTCARD transmission complete before guard time completion interruption */
  112. #endif /* USART_TCBGT_SUPPORT */
  113. /**
  114. * @}
  115. */
  116. /** @defgroup SMARTCARDEx_IT_CLEAR_Flags SMARTCARD Interruption Clear Flags
  117. * @{
  118. */
  119. #define SMARTCARD_CLEAR_PEF USART_ICR_PECF /*!< SMARTCARD parity error clear flag */
  120. #define SMARTCARD_CLEAR_FEF USART_ICR_FECF /*!< SMARTCARD framing error clear flag */
  121. #define SMARTCARD_CLEAR_NEF USART_ICR_NCF /*!< SMARTCARD noise error detected clear flag */
  122. #define SMARTCARD_CLEAR_OREF USART_ICR_ORECF /*!< SMARTCARD overrun error clear flag */
  123. #define SMARTCARD_CLEAR_IDLEF USART_ICR_IDLECF /*!< SMARTCARD idle line detected clear flag */
  124. #define SMARTCARD_CLEAR_TCF USART_ICR_TCCF /*!< SMARTCARD transmission complete clear flag */
  125. #if defined(USART_TCBGT_SUPPORT)
  126. #define SMARTCARD_CLEAR_TCBGTF USART_ICR_TCBGTCF /*!< SMARTCARD transmission complete before guard time completion clear flag */
  127. #endif /* USART_TCBGT_SUPPORT */
  128. #define SMARTCARD_CLEAR_RTOF USART_ICR_RTOCF /*!< SMARTCARD receiver time out clear flag */
  129. #define SMARTCARD_CLEAR_EOBF USART_ICR_EOBCF /*!< SMARTCARD end of block clear flag */
  130. /**
  131. * @}
  132. */
  133. /**
  134. * @}
  135. */
  136. /* Exported macros -----------------------------------------------------------*/
  137. /* Private macros ------------------------------------------------------------*/
  138. /** @defgroup SMARTCARDEx_Private_Macros SMARTCARD Extended Private Macros
  139. * @{
  140. */
  141. /** @brief Set the Transmission Completion flag
  142. * @param __HANDLE__ specifies the SMARTCARD Handle.
  143. * @note If TCBGT (Transmission Complete Before Guard Time) flag is not available or if
  144. * AdvancedInit.TxCompletionIndication is not already filled, the latter is forced
  145. * to SMARTCARD_TC (transmission completion indication when guard time has elapsed).
  146. * @retval None
  147. */
  148. #if defined(USART_TCBGT_SUPPORT)
  149. #define SMARTCARD_TRANSMISSION_COMPLETION_SETTING(__HANDLE__) \
  150. do { \
  151. if (HAL_IS_BIT_CLR((__HANDLE__)->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_TXCOMPLETION)) \
  152. { \
  153. (__HANDLE__)->AdvancedInit.TxCompletionIndication = SMARTCARD_TC; \
  154. } \
  155. else \
  156. { \
  157. assert_param(IS_SMARTCARD_TRANSMISSION_COMPLETION((__HANDLE__)->AdvancedInit.TxCompletionIndication)); \
  158. } \
  159. } while(0U)
  160. #else
  161. #define SMARTCARD_TRANSMISSION_COMPLETION_SETTING(__HANDLE__) \
  162. do { \
  163. (__HANDLE__)->AdvancedInit.TxCompletionIndication = SMARTCARD_TC; \
  164. } while(0U)
  165. #endif /* USART_TCBGT_SUPPORT */
  166. /** @brief Return the transmission completion flag.
  167. * @param __HANDLE__ specifies the SMARTCARD Handle.
  168. * @note Based on AdvancedInit.TxCompletionIndication setting, return TC or TCBGT flag.
  169. * When TCBGT flag (Transmission Complete Before Guard Time) is not available, TC flag is
  170. * reported.
  171. * @retval Transmission completion flag
  172. */
  173. #if defined(USART_TCBGT_SUPPORT)
  174. #define SMARTCARD_TRANSMISSION_COMPLETION_FLAG(__HANDLE__) \
  175. (((__HANDLE__)->AdvancedInit.TxCompletionIndication == SMARTCARD_TC) ? (SMARTCARD_FLAG_TC) : (SMARTCARD_FLAG_TCBGT))
  176. #else
  177. #define SMARTCARD_TRANSMISSION_COMPLETION_FLAG(__HANDLE__) (SMARTCARD_FLAG_TC)
  178. #endif /* USART_TCBGT_SUPPORT */
  179. /** @brief Ensure that SMARTCARD frame transmission completion used flag is valid.
  180. * @param __TXCOMPLETE__ SMARTCARD frame transmission completion used flag.
  181. * @retval SET (__TXCOMPLETE__ is valid) or RESET (__TXCOMPLETE__ is invalid)
  182. */
  183. #if defined(USART_TCBGT_SUPPORT)
  184. #define IS_SMARTCARD_TRANSMISSION_COMPLETION(__TXCOMPLETE__) (((__TXCOMPLETE__) == SMARTCARD_TCBGT) || \
  185. ((__TXCOMPLETE__) == SMARTCARD_TC))
  186. #else
  187. #define IS_SMARTCARD_TRANSMISSION_COMPLETION(__TXCOMPLETE__) ((__TXCOMPLETE__) == SMARTCARD_TC)
  188. #endif /* USART_TCBGT_SUPPORT */
  189. /**
  190. * @}
  191. */
  192. /* Exported functions --------------------------------------------------------*/
  193. /** @addtogroup SMARTCARDEx_Exported_Functions
  194. * @{
  195. */
  196. /* Initialization and de-initialization functions ****************************/
  197. /* IO operation methods *******************************************************/
  198. /** @addtogroup SMARTCARDEx_Exported_Functions_Group1
  199. * @{
  200. */
  201. /* Peripheral Control functions ***********************************************/
  202. void HAL_SMARTCARDEx_BlockLength_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t BlockLength);
  203. void HAL_SMARTCARDEx_TimeOut_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t TimeOutValue);
  204. HAL_StatusTypeDef HAL_SMARTCARDEx_EnableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard);
  205. HAL_StatusTypeDef HAL_SMARTCARDEx_DisableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard);
  206. /**
  207. * @}
  208. */
  209. /* Exported functions --------------------------------------------------------*/
  210. /** @addtogroup SMARTCARDEx_Exported_Functions_Group2
  211. * @{
  212. */
  213. /* IO operation functions *****************************************************/
  214. /**
  215. * @}
  216. */
  217. /**
  218. * @}
  219. */
  220. /* Private functions ---------------------------------------------------------*/
  221. /**
  222. * @}
  223. */
  224. /**
  225. * @}
  226. */
  227. #endif /* !defined (STM32L010x4) && !defined (STM32L010x6) */
  228. #ifdef __cplusplus
  229. }
  230. #endif
  231. #endif /* STM32L0xx_HAL_SMARTCARD_EX_H */