tae32f53xx_ll_dali.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. /**
  2. ******************************************************************************
  3. * @file tae32f53xx_ll_dali.h
  4. * @author MCD Application Team
  5. * @brief Header file for DALI module
  6. *
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * <h2><center>&copy; Copyright (c) 2020 Tai-Action.
  11. * All rights reserved.</center></h2>
  12. *
  13. * This software is licensed by Tai-Action under BSD 3-Clause license,
  14. * the "License"; You may not use this file except in compliance with the
  15. * License. You may obtain a copy of the License at:
  16. * opensource.org/licenses/BSD-3-Clause
  17. *
  18. ******************************************************************************
  19. */
  20. /* Define to prevent recursive inclusion -------------------------------------*/
  21. #ifndef _TAE32F53XX_LL_DALI_H_
  22. #define _TAE32F53XX_LL_DALI_H_
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif /* __cplusplus */
  26. /* Includes ------------------------------------------------------------------*/
  27. #include "tae32f53xx_ll_def.h"
  28. /** @addtogroup TAE32F53xx_LL_Driver
  29. * @{
  30. */
  31. /** @addtogroup DALI_LL
  32. * @{
  33. */
  34. /* Exported constants --------------------------------------------------------*/
  35. /* Exported types ------------------------------------------------------------*/
  36. /** @defgroup DALI_LL_Exported_Types DALI LL Exported Types
  37. * @brief DALI LL Exported Types
  38. * @{
  39. */
  40. /** @defgroup DALI_Mode_Selection DALI mode selection
  41. * @brief DALI mode selection
  42. * @{
  43. */
  44. typedef enum {
  45. DALI_MODE_SLAVE = 0, /*!< Slave mode */
  46. DALI_MODE_MASTER = DALI_CR_MODE, /*!< Master mode */
  47. } DALI_ModeETypeDef;
  48. /**
  49. * @}
  50. */
  51. /** @defgroup DALI_Forward_Message_Length DALI forward frame message length
  52. * @brief DALI forward frame message length
  53. * @{
  54. */
  55. typedef enum {
  56. DALI_MESSAGELENGTH_16Bit = 0, /*!< DALI Forward frame message length sets to 16 bits */
  57. DALI_MESSAGELENGTH_17Bit = DALI_CR_ML_0, /*!< DALI Forward frame message length sets to 17 bits */
  58. DALI_MESSAGELENGTH_18Bit = DALI_CR_ML_1, /*!< DALI Forward frame message length sets to 18 bits */
  59. DALI_MESSAGELENGTH_24Bit = (DALI_CR_ML_0 | DALI_CR_ML_1), /*!< DALI Forward frame message length sets to 24 bits */
  60. } DALI_MsgLenETypeDef;
  61. /**
  62. * @}
  63. */
  64. /** @defgroup DALI_Polarity_Selection DALI polarity selection
  65. * @brief DALI polarity selection
  66. * @{
  67. */
  68. typedef enum {
  69. DALI_POLARITY_ACTIVE_HIGH = 0, /*!< Active High */
  70. DALI_POLARITY_ACTIVE_LOW = DALI_CR_POL, /*!< Active Low */
  71. } DALI_PolETypeDef;
  72. /**
  73. * @}
  74. */
  75. /** @defgroup DALI_Filter_Selection DALI filter selection
  76. * @brief DALI filter selection
  77. * @{
  78. */
  79. typedef enum {
  80. DALI_FILTER_DISABLE = 0, /*!< Disable filter feature */
  81. DALI_FILTER_ENABLE = DALI_FCR_FE, /*!< Enable filter feature */
  82. } DALI_FilterETypeDef;
  83. /**
  84. * @}
  85. */
  86. /** @defgroup DALI_Interrupt_definition DALI Interrupt Definition
  87. * @brief DALI Interrupt Definition
  88. * @{
  89. */
  90. typedef enum {
  91. DALI_IT_BEIE = DALI_CR_BEIE, /*!< DALI Backward Error Interrupt Enable */
  92. DALI_IT_FEIE = DALI_CR_FEIE, /*!< DALI Forward Error Interrupt Enable */
  93. DALI_IT_BDIE = DALI_CR_BDIE, /*!< DALI Backward Done Interrupt Enable */
  94. DALI_IT_FDIE = DALI_CR_FDIE, /*!< DALI Forward Done Interrupt Enable */
  95. } DALI_IntETypeDef;
  96. /**
  97. * @}
  98. */
  99. /** @defgroup DALI_Pending_Flag_definition DALI Pending Flag Definition
  100. * @brief DALI Pending Flag Definition
  101. * @{
  102. */
  103. typedef enum {
  104. DALI_FLAG_BEIF = DALI_ISR_BEIF, /*!< DALI Backward Error Pending Flag */
  105. DALI_FLAG_FEIF = DALI_ISR_FEIF, /*!< DALI Forward Error Pending Flag */
  106. DALI_FLAG_BDIF = DALI_ISR_BDIF, /*!< DALI Backward Done Pending Flag */
  107. DALI_FLAG_FDIF = DALI_ISR_FDIF, /*!< DALI Forward Done Pending Flag */
  108. } DALI_FlagTypeDef;
  109. /**
  110. * @}
  111. */
  112. /** @defgroup DALI_Status_Flag_definition DALI Status Flag Definition
  113. * @brief DALI Status Flag Definition
  114. * @{
  115. */
  116. typedef enum {
  117. DALI_FLAG_BSY = DALI_ISR_BSY, /*!< DALI BUSY Status Flag */
  118. } DALI_StatusTypeDef;
  119. /**
  120. * @}
  121. */
  122. /** @defgroup DALI_Baudrate_definition DALI Baudrate Definition
  123. * @brief DALI Baudrate Definition
  124. * @{
  125. */
  126. typedef enum {
  127. DALI_BAUDRATE_1K2 = 1200U, /*!< DALI Baudrate 1.2K */
  128. DALI_BAUDRATE_2K4 = 2400U, /*!< DALI Baudrate 2.4K */
  129. DALI_BAUDRATE_4K8 = 4800U, /*!< DALI Baudrate 4.8K */
  130. } DALI_BaudETypeDef;
  131. /**
  132. * @}
  133. */
  134. /**
  135. * @brief DALI Initialization Structure definition
  136. */
  137. typedef struct __DALI_InitTypeDef {
  138. DALI_ModeETypeDef Mode; /*!< Specifies the DALI working mode.
  139. This parameter can be a value in @ref DALI_ModeETypeDef */
  140. DALI_BaudETypeDef Baudrate; /*!< Specifies the DALI division value
  141. This parameter can be a value in @ref DALI_BaudETypeDef */
  142. DALI_MsgLenETypeDef MessageLen; /*!< Specifies the DALI Forward frame message length.
  143. This parameter can be a value in @ref DALI_MsgLenETypeDef */
  144. DALI_PolETypeDef Polarity; /*!< Specifies the DALI polarity
  145. This parameter can be a value in @ref DALI_PolETypeDef */
  146. DALI_FilterETypeDef Filter; /*!< Specifies the DALI enable filter or not.
  147. This parameter can be a value in @ref DALI_FilterETypeDef */
  148. uint16_t FilterCounter; /*!< Specifies the DALI filter counter value (in APB1 Clock)
  149. This parameter can be a number in range from 0 to 0xFFFF */
  150. uint16_t ForwardDelay; /*!< Specifies the DALI forward frame delay timing.
  151. This parameter can be a number in range from 0 to 511
  152. DelayTime(ms) = (22 + ForwardDelay) * T */
  153. uint16_t BackwardDelay; /*!< Specifies the DALI backward frame delay timing.
  154. This parameter can be a number in range from 0 to 127
  155. DelayTime(ms) = (7 + BackwardDelay) * T */
  156. } DALI_InitTypeDef;
  157. /**
  158. * @}
  159. */
  160. /* Exported macro ------------------------------------------------------------*/
  161. /** @defgroup DALI_LL_Exported_Macros DALI LL Exported Macros
  162. * @brief DALI LL Exported Macros
  163. * @{
  164. */
  165. /**
  166. * @brief Enable the DALI peripheral
  167. * @param __INSTANCE__ DALI peripheral
  168. * @return None
  169. */
  170. #define __LL_DALI_ENABLE(__INSTANCE__) SET_BIT((__INSTANCE__)->CR, DALI_CR_PEN)
  171. /**
  172. * @brief Disable the DALI peripheral
  173. * @param __INSTANCE__ DALI peripheral
  174. * @return None
  175. */
  176. #define __LL_DALI_DISABLE(__INSTANCE__) CLEAR_BIT((__INSTANCE__)->CR, DALI_CR_PEN)
  177. /**
  178. * @brief Enable the specified DALI Interrupts
  179. * @param __INSTANCE__ DALI peripheral
  180. * @param __IT__ specifies the DALI interrupt source to enable.
  181. * This parameter can be any combination of @enum DALI_IntETypeDef in
  182. * @ref DALI_Interrupt_definition
  183. * @return None
  184. */
  185. #define __LL_DALI_IT_ENABLE(__INSTANCE__, __IT__) SET_BIT((__INSTANCE__)->CR, (__IT__))
  186. /**
  187. * @brief Disable the specified DALI Interrupts
  188. * @param __INSTANCE__ DALI peripheral
  189. * @param __IT__ specifies the DALI interrupt source to disable.
  190. * This parameter can be any combination of @enum DALI_IntETypeDef in
  191. * @ref DALI_Interrupt_definition
  192. * @return None
  193. */
  194. #define __LL_DALI_IT_DISABLE(__INSTANCE__, __IT__) CLEAR_BIT((__INSTANCE__)->CR, (__IT__))
  195. /**
  196. * @brief Check whether the specified DALI Channel interrupt source is set or not.
  197. * @param __INSTANCE__ DALI peripheral
  198. * @param __IT__ specifies the DALI Channel interrupt source to check.
  199. * This parameter can be ONE of @enum DALI_IntETypeDef in @ref DALI_Interrupt_definition
  200. @return The state of __IT__ (SET or RESET).
  201. */
  202. #define __LL_DALI_IT_SOURCE_CHECK(__INSTANCE__, __IT__) ((READ_BIT((__INSTANCE__)->CR, (__IT__)) == (__IT__)) ? SET : RESET)
  203. /**
  204. * @brief Clear the specified pending flags
  205. * @param __INSTANCE__ DALI peripheral.
  206. * @param __FLAG__ Specifies the DALI pending flag to clear.
  207. * This parameter can be any combination of @enum DALI_FlagTypeDef in
  208. * @ref DALI_Pending_Flag_definition
  209. * @return None
  210. */
  211. #define __LL_DALI_PENDING_FLAG_CLEAR(__INSTANCE__, __FLAG__) WRITE_REG((__INSTANCE__)->ISR, (__FLAG__))
  212. /**
  213. * @brief Check whether the specified pending flag is SET or not.
  214. * @param __INSTANCE__ DALI peripheral.
  215. * @param __FLAG__ Specifies the DALI pending flag to get.
  216. * This parameter can be ONE of @enum DALI_FlagTypeDef in @ref DALI_Pending_Flag_definition
  217. * @return The new state of __FLAG__ (SET or RESET).
  218. */
  219. #define __LL_DALI_PENDING_FLAG_GET(__INSTANCE__, __FLAG__) ((READ_BIT((__INSTANCE__)->ISR, (__FLAG__)) == (__FLAG__)) ? SET : RESET)
  220. /**
  221. * @brief Check whether the specified status flag is SET or not.
  222. * @param __INSTANCE__ DALI peripheral.
  223. * @param __FLAG__ Specifies the DALI pending flag to get.
  224. * This parameter can be ONE of @enum DALI_StatusTypeDef in @ref DALI_Status_Flag_definition
  225. * @return The new state of __FLAG__ (SET or RESET).
  226. */
  227. #define __LL_DALI_STATUS_FLAG_GET(__INSTANCE__, __STA__) ((READ_BIT((__INSTANCE__)->ISR, (__STA__)) == (__STA__)) ? SET : RESET)
  228. /**
  229. * @brief DALI master writes forward data to DALI_FDR register on runtime
  230. * @param __INSTANCE__ DALI peripheral.
  231. * @param __DATA__ Forward frame data
  232. * @return None
  233. */
  234. #define __LL_DALI_MSTR_WRITE_FORWARD_DATA(__INSTANCE__, __DATA__) WRITE_REG((__INSTANCE__)->FDR, (__DATA__) & 0xFFFFFFUL)
  235. /**
  236. * @brief DALI master reads backward data from DALI_BDR register on runtime
  237. * @param __INSTANCE__ DALI peripheral.
  238. * @return Backward data
  239. */
  240. #define __LL_DALI_MSTR_READ_BACKWARD_DATA(__INSTANCE__) (READ_REG((__INSTANCE__)->BDR) & 0xFFUL)
  241. /**
  242. * @brief DALI slave writes backward data to DALI_BDR register on runtime
  243. * @param __INSTANCE__ DALI peripheral.
  244. * @param __DATA__ Backward frame data
  245. * @return None
  246. */
  247. #define __LL_DALI_SLV_WRITE_BACKWARD_DATA(__INSTANCE__, __DATA__) WRITE_REG((__INSTANCE__)->BDR, (__DATA__) & 0xFFUL)
  248. /**
  249. * @brief DALI slave reads forward data from DALI_FDR register on runtime
  250. * @param __INSTANCE__ DALI peripheral.
  251. * @return Forward data
  252. */
  253. #define __LL_DALI_SLV_READ_FORWARD_DATA(__INSTANCE__) (READ_REG((__INSTANCE__)->FDR) & 0xFFFFFFUL)
  254. /**
  255. * @}
  256. */
  257. /* Exported functions --------------------------------------------------------*/
  258. /** @addtogroup DALI_LL_Exported_Functions
  259. * @{
  260. */
  261. /** @addtogroup DALI_LL_Exported_Functions_Group1
  262. * @{
  263. */
  264. LL_StatusETypeDef LL_DALI_Init(DALI_TypeDef *Instance, DALI_InitTypeDef *Init);
  265. LL_StatusETypeDef LL_DALI_DeInit(DALI_TypeDef *Instance);
  266. void LL_DALI_MspInit(DALI_TypeDef *Instance);
  267. void LL_DALI_MspDeInit(DALI_TypeDef *Instance);
  268. /**
  269. * @}
  270. */
  271. /** @addtogroup DALI_LL_Exported_Functions_Group2
  272. * @{
  273. */
  274. LL_StatusETypeDef LL_DALI_WaitForLastOperation(DALI_TypeDef *Instance, uint32_t Timeout);
  275. /**
  276. * @}
  277. */
  278. /** @addtogroup DALI_LL_Exported_Functions_Group3
  279. * @{
  280. */
  281. LL_StatusETypeDef LL_DALI_Master_Transmit(DALI_TypeDef *Instance, uint32_t ForwardData);
  282. LL_StatusETypeDef LL_DALI_Master_Transmit_IT(DALI_TypeDef *Instance, uint32_t ForwardData);
  283. LL_StatusETypeDef LL_DALI_Master_Receive(DALI_TypeDef *Instance, uint8_t *BackwardData);
  284. LL_StatusETypeDef LL_DALI_Master_Receive_IT(DALI_TypeDef *Instance);
  285. LL_StatusETypeDef LL_DALI_Slave_Transmit(DALI_TypeDef *Instance, uint8_t BackwardData);
  286. LL_StatusETypeDef LL_DALI_Slave_Transmit_IT(DALI_TypeDef *Instance, uint8_t BackwardData);
  287. LL_StatusETypeDef LL_DALI_Slave_Receive(DALI_TypeDef *Instance, uint32_t *ForwardData);
  288. LL_StatusETypeDef LL_DALI_Slave_Receive_IT(DALI_TypeDef *Instance);
  289. /**
  290. * @}
  291. */
  292. /** @addtogroup DALI_LL_Exported_Functions_Interrupt
  293. * @{
  294. */
  295. void LL_DALI_IRQHandler(DALI_TypeDef *Instance);
  296. void LL_DALI_MstrRecviveDoneCallback(DALI_TypeDef *Instance);
  297. void LL_DALI_MstrRecviveErrorCallback(DALI_TypeDef *Instance);
  298. void LL_DALI_MstrTransmitDoneCallback(DALI_TypeDef *Instance);
  299. void LL_DALI_MstrTransmitErrorCallback(DALI_TypeDef *Instance);
  300. void LL_DALI_SlvReceiveDoneCallback(DALI_TypeDef *Instance);
  301. void LL_DALI_SlvReceiveErrorCallback(DALI_TypeDef *Instance);
  302. void LL_DALI_SlvTransmitDoneCallback(DALI_TypeDef *Instance);
  303. void LL_DALI_SlvTransmitErrorCallback(DALI_TypeDef *Instance);
  304. /**
  305. * @}
  306. */
  307. /**
  308. * @}
  309. */
  310. /* Private constants ---------------------------------------------------------*/
  311. /** @defgroup DALI_LL_Private_Constants DALI LL private constants
  312. * @brief DALI LL private constants
  313. * @{
  314. */
  315. /**
  316. * @brief Max timeout for DALI operations, Default 1000 ticks
  317. */
  318. #define DALI_TIMEOUT_MAX_VALUE 1000UL
  319. /**
  320. * @}
  321. */
  322. /* Private macros ------------------------------------------------------------*/
  323. /** @defgroup DALI_LL_Private_Macros DALI LL private macros
  324. * @brief DALI LL private macros
  325. * @{
  326. */
  327. /**
  328. * @brief Judge is DALI mode or not
  329. * @param __MODE__ mode to judge
  330. * @retval 0 isn't DALI mode
  331. * @retval 1 is DALI mode
  332. */
  333. #define IS_DALI_MODE(__MODE__) (((__MODE__) == DALI_MODE_MASTER) || \
  334. ((__MODE__) == DALI_MODE_SLAVE))
  335. /**
  336. * @brief Judge is DALI message length or not
  337. * @param __LEN__ length to judge
  338. * @retval 0 isn't DALI message length
  339. * @retval 1 is DALI message length
  340. */
  341. #define IS_DALI_MESSAGE_LEN(__LEN__) (((__LEN__) == DALI_MESSAGELENGTH_16Bit) || \
  342. ((__LEN__) == DALI_MESSAGELENGTH_17Bit) || \
  343. ((__LEN__) == DALI_MESSAGELENGTH_18Bit) || \
  344. ((__LEN__) == DALI_MESSAGELENGTH_24Bit))
  345. /**
  346. * @brief Judge is DALI polarity or not
  347. * @param __POL__ polarity to judge
  348. * @retval 0 isn't DALI polarity
  349. * @retval 1 is DALI polarity
  350. */
  351. #define IS_DALI_POLARITY(__POL__) (((__POL__) == DALI_POLARITY_ACTIVE_HIGH) || \
  352. ((__POL__) == DALI_POLARITY_ACTIVE_LOW))
  353. /**
  354. * @brief Judge is DALI filter enable or not
  355. * @param __EN__ enable to judge
  356. * @retval 0 isn't DALI filter enable
  357. * @retval 1 is DALI filter enable
  358. */
  359. #define IS_DALI_FILTER_ENABLE(__EN__) (((__EN__) == DALI_FILTER_DISABLE) || \
  360. ((__EN__) == DALI_FILTER_ENABLE))
  361. /**
  362. * @brief Judge is DALI filter counter or not
  363. * @param __CNT__ counter to judge
  364. * @retval 0 isn't DALI filter counter
  365. * @retval 1 is DALI filter counter
  366. */
  367. #define IS_DALI_FILTER_COUNTER(__CNT__) ((__CNT__) <= 0xFFFFUL)
  368. /**
  369. * @brief Judge is DALI forward delay or not
  370. * @param __DLY__ delay to judge
  371. * @retval 0 isn't DALI forward delay
  372. * @retval 1 is DALI forward delay
  373. */
  374. #define IS_DALI_FORWARD_DELAY(__DLY__) ((__DLY__) <= 0x1FFUL)
  375. /**
  376. * @brief Judge is DALI backward delay or not
  377. * @param __DLY__ delay to judge
  378. * @retval 0 isn't DALI backward delay
  379. * @retval 1 is DALI backward delay
  380. */
  381. #define IS_DALI_BACKWARD_DELAY(__DLY__) ((__DLY__) <= 0x7FUL)
  382. /**
  383. * @brief Judge is DALI prescale or not
  384. * @param __PSC__ prescale to judge
  385. * @retval 0 isn't DALI prescale
  386. * @retval 1 is DALI prescale
  387. */
  388. #define IS_DALI_PRESCALE(__PSC__) ((__PSC__) <= 0xFFFUL)
  389. /**
  390. * @brief Judge is DALI supported baudrate or not
  391. * @param __BRT__ Baudrate to judge
  392. * @retval 0 isn't DALI supported baudrate
  393. * @retval 1 is DALI supported baudrate
  394. */
  395. #define IS_DALI_BAUDRATE(__BRT__) (((__BRT__) == DALI_BAUDRATE_1K2) || \
  396. ((__BRT__) == DALI_BAUDRATE_2K4) || \
  397. ((__BRT__) == DALI_BAUDRATE_4K8))
  398. /**
  399. * @}
  400. */
  401. /* Private types -------------------------------------------------------------*/
  402. /* Private variables ---------------------------------------------------------*/
  403. /* Private functions ---------------------------------------------------------*/
  404. /**
  405. * @}
  406. */
  407. /**
  408. * @}
  409. */
  410. #ifdef __cplusplus
  411. }
  412. #endif /* __cplusplus */
  413. #endif /* _TAE32F53XX_LL_DALI_H_ */
  414. /************************* (C) COPYRIGHT Tai-Action *****END OF FILE***********/