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