py32f0xx_ll_led.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. /**
  2. ******************************************************************************
  3. * @file py32f0xx_ll_led.h
  4. * @author MCU Application Team
  5. * @brief Header file of LED LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2023 Puya Semiconductor Co.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by Puya under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. * @attention
  19. *
  20. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  21. * All rights reserved.</center></h2>
  22. *
  23. * This software component is licensed by ST under BSD 3-Clause license,
  24. * the "License"; You may not use this file except in compliance with the
  25. * License. You may obtain a copy of the License at:
  26. * opensource.org/licenses/BSD-3-Clause
  27. *
  28. ******************************************************************************
  29. */
  30. /* Define to prevent recursive inclusion -------------------------------------*/
  31. #ifndef PY32F0XX_LL_LED_H
  32. #define PY32F0XX_LL_LED_H
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "py32f0xx.h"
  38. /** @addtogroup PY32F0xx_LL_Driver
  39. * @{
  40. */
  41. #if defined (LED)
  42. /** @defgroup LED_LL LED
  43. * @{
  44. */
  45. /* Private types -------------------------------------------------------------*/
  46. /* Private variables ---------------------------------------------------------*/
  47. /* Private constants ---------------------------------------------------------*/
  48. /* Private macros ------------------------------------------------------------*/
  49. /* Exported types ------------------------------------------------------------*/
  50. /** @defgroup LED_LL_Exported_Types LED Exported Types
  51. * @{
  52. */
  53. /**
  54. * @brief LED Init Structure definition
  55. */
  56. typedef struct
  57. {
  58. uint32_t ComDrive; /*!< Specifies the LED COM drive capability.
  59. This parameter can be a value of @ref LED_LL_EC_ComDrive */
  60. uint32_t Prescaler; /*!< Specifies the prescaler value used to divide the LED clock.
  61. This parameter can be a number between Min_Data = 0x00(div1) and Max_Data = 0xFF(div256) */
  62. uint32_t ComSelect; /*!< Specifies the number of COM open.
  63. This parameter can be a value of @ref LED_LL_EC_ComSelct */
  64. uint32_t LightTime; /*!< Specifies LED Lighting time.
  65. This parameter can be a number between Min_Data = 1 and Max_Data = 0xFF */
  66. uint32_t DeadTime; /*!< Specifies LED Dead time.
  67. This parameter can be a number between Min_Data = 1 and Max_Data = 0xFF */
  68. } LL_LED_InitTypeDef;
  69. /**
  70. * @}
  71. */
  72. /* Exported Constants --------------------------------------------------------*/
  73. /** @defgroup LED_LL_Exported_constants LED Exported Constants
  74. * @{
  75. */
  76. /** @defgroup LED_LL_EC_ComDrive ComDrive
  77. * @{
  78. */
  79. #define LL_LED_COMDRIVE_LOW 0x00000000U
  80. #define LL_LED_COMDRIVE_HIGH LED_CR_EHS
  81. /**
  82. * @}
  83. */
  84. /** @defgroup LED_LL_EC_ComSelct Number of COM Open
  85. * @{
  86. */
  87. #define LL_LED_COMSELECT_1COM 0x00000000U
  88. #define LL_LED_COMSELECT_2COM LED_CR_LED_COM_SEL_0
  89. #define LL_LED_COMSELECT_3COM LED_CR_LED_COM_SEL_1
  90. #define LL_LED_COMSELECT_4COM (LED_CR_LED_COM_SEL_1 | LED_CR_LED_COM_SEL_0)
  91. /**
  92. * @}
  93. */
  94. /** @defgroup LED_LL_EC_DisplayValue LED Display Value
  95. * @{
  96. */
  97. #define LL_LED_DISP_NONE 0x00U
  98. #define LL_LED_DISP_FULL 0xFFU
  99. #define LL_LED_DISP_0 0x3FU
  100. #define LL_LED_DISP_1 0x06U
  101. #define LL_LED_DISP_2 0x5BU
  102. #define LL_LED_DISP_3 0x4FU
  103. #define LL_LED_DISP_4 0x66U
  104. #define LL_LED_DISP_5 0x6DU
  105. #define LL_LED_DISP_6 0x7DU
  106. #define LL_LED_DISP_7 0x07U
  107. #define LL_LED_DISP_8 0x7FU
  108. #define LL_LED_DISP_9 0x6FU
  109. #define LL_LED_DISP_A 0x77U
  110. #define LL_LED_DISP_B 0x7CU
  111. #define LL_LED_DISP_C 0x39U
  112. #define LL_LED_DISP_D 0x5EU
  113. #define LL_LED_DISP_E 0x79U
  114. #define LL_LED_DISP_F 0x71U
  115. #define LL_LED_DISP_H 0x76U
  116. #define LL_LED_DISP_P 0x73U
  117. #define LL_LED_DISP_U 0x3EU
  118. #define LL_LED_DISP_DOT 0x80U
  119. /**
  120. * @}
  121. */
  122. /** @defgroup LED_LL_EC_ComDisplay LED COM Select
  123. * @{
  124. */
  125. #define LL_LED_COM0 0x00000000U
  126. #define LL_LED_COM1 0x00000004U
  127. #define LL_LED_COM2 0x00000008U
  128. #define LL_LED_COM3 0x0000000CU
  129. /**
  130. * @}
  131. */
  132. /** @defgroup LED_LL_EC_DataReg Data Register Mask and Position
  133. * @{
  134. */
  135. #define LL_LED_DR_DATA LED_DR0_DATA0
  136. #define LL_LED_DR_DATA_Pos LED_DR0_DATA0_Pos
  137. /**
  138. * @}
  139. */
  140. /**
  141. * @}
  142. */
  143. /* Exported functions --------------------------------------------------------*/
  144. /** @defgroup LED_LL_Exported_Functions LED Exported Functions
  145. * @{
  146. */
  147. /**
  148. * @brief Set the LED COM drive capability.
  149. * @param LEDx LED Instance
  150. * @param ComDrive This parameter can be one of the following values:
  151. * @arg @ref LL_LED_COMDRIVE_LOW
  152. * @arg @ref LL_LED_COMDRIVE_HIGH
  153. * @retval None
  154. */
  155. __STATIC_INLINE void LL_LED_SetComDrive(LED_TypeDef *LEDx, uint32_t ComDrive)
  156. {
  157. MODIFY_REG(LEDx->CR, LED_CR_EHS, ComDrive);
  158. }
  159. /**
  160. * @brief Get the LED COM drive capability.
  161. * @param LEDx LED Instance
  162. * @retval Returned value can be one of the following values:
  163. * @arg @ref LL_LED_COMDRIVE_LOW
  164. * @arg @ref LL_LED_COMDRIVE_HIGH
  165. */
  166. __STATIC_INLINE uint32_t LL_LED_GetComDrive(LED_TypeDef *LEDx)
  167. {
  168. return (READ_BIT(LEDx->CR, LED_CR_EHS));
  169. }
  170. /**
  171. * @brief Enable LED Interrupt.
  172. * @param LEDx LED Instance
  173. * @retval None
  174. */
  175. __STATIC_INLINE void LL_LED_EnableIT(LED_TypeDef *LEDx)
  176. {
  177. SET_BIT(LEDx->CR, LED_CR_IE);
  178. }
  179. /**
  180. * @brief Disable LED Interrupt.
  181. * @param LEDx LED Instance
  182. * @retval None
  183. */
  184. __STATIC_INLINE void LL_LED_DisableIT(LED_TypeDef *LEDx)
  185. {
  186. CLEAR_BIT(LEDx->CR, LED_CR_IE);
  187. }
  188. /**
  189. * @brief Check if LED Interrupt is enabled
  190. * @param LEDx LED Instance
  191. * @retval State of bit (1 or 0).
  192. */
  193. __STATIC_INLINE uint32_t LL_LED_IsEnabledIT(LED_TypeDef *LEDx)
  194. {
  195. return ((READ_BIT(LEDx->CR, LED_CR_IE) == (LED_CR_IE)) ? 1UL : 0UL);
  196. }
  197. /**
  198. * @brief Set he number of COM open.
  199. * @param LEDx LED Instance
  200. * @param ComNum This parameter can be one of the following values:
  201. * @arg @ref LL_LED_COMSELECT_1COM
  202. * @arg @ref LL_LED_COMSELECT_2COM
  203. * @arg @ref LL_LED_COMSELECT_3COM
  204. * @arg @ref LL_LED_COMSELECT_4COM
  205. * @retval None
  206. */
  207. __STATIC_INLINE void LL_LED_SetComNum(LED_TypeDef *LEDx, uint32_t ComNum)
  208. {
  209. MODIFY_REG(LEDx->CR, LED_CR_LED_COM_SEL, ComNum);
  210. }
  211. /**
  212. * @brief Get the number of COM open.
  213. * @param LEDx LED Instance
  214. * @retval Returned value can be one of the following values:
  215. * @arg @ref LL_LED_COMSELECT_1COM
  216. * @arg @ref LL_LED_COMSELECT_2COM
  217. * @arg @ref LL_LED_COMSELECT_3COM
  218. * @arg @ref LL_LED_COMSELECT_4COM
  219. */
  220. __STATIC_INLINE uint32_t LL_LED_GetComNum(LED_TypeDef *LEDx)
  221. {
  222. return (READ_BIT(LEDx->CR, LED_CR_LED_COM_SEL));
  223. }
  224. /**
  225. * @brief Enable LED.
  226. * @param LEDx LED Instance
  227. * @retval None
  228. */
  229. __STATIC_INLINE void LL_LED_Enable(LED_TypeDef *LEDx)
  230. {
  231. SET_BIT(LEDx->CR, LED_CR_LEDON);
  232. }
  233. /**
  234. * @brief Disable LED.
  235. * @param LEDx LED Instance
  236. * @retval None
  237. */
  238. __STATIC_INLINE void LL_LED_Disable(LED_TypeDef *LEDx)
  239. {
  240. CLEAR_BIT(LEDx->CR, LED_CR_LEDON);
  241. }
  242. /**
  243. * @brief Checks if LED is enabled
  244. * @param LEDx LED Instance
  245. * @retval State of bit (1 or 0).
  246. */
  247. __STATIC_INLINE uint32_t LL_LED_IsEnabled(LED_TypeDef *LEDx)
  248. {
  249. return ((READ_BIT(LEDx->CR, LED_CR_LEDON) == (LED_CR_LEDON)) ? 1UL : 0UL);
  250. }
  251. /**
  252. * @brief Set the LED prescale Value.
  253. * @param LEDx LED Instance
  254. * @param Prescaler This parameter can be a number between Min_Data = 0x00(div1)
  255. * and Max_Data = 0xFF(div256)
  256. * @retval None
  257. */
  258. __STATIC_INLINE void LL_LED_SetPrescaler(LED_TypeDef *LEDx, uint32_t Prescaler)
  259. {
  260. MODIFY_REG(LEDx->PR, LED_PR_PR, (Prescaler << LED_PR_PR_Pos));
  261. }
  262. /**
  263. * @brief Return LED Prescaler Value.
  264. * @param LEDx LED Instance
  265. * @retval Returned value can be a number between Min_Data = 0x00(div1)
  266. * and Max_Data = 0xFF(div256)
  267. */
  268. __STATIC_INLINE uint32_t LL_LED_GetPrescaler(LED_TypeDef *LEDx)
  269. {
  270. return (READ_BIT(LEDx->PR, LED_PR_PR) >> LED_PR_PR_Pos);
  271. }
  272. /**
  273. * @brief Set the LED Lighting and Dead time.
  274. * @param LEDx LED Instance
  275. * @param LightTime This parameter can be a number between Min_Data = 1 and
  276. * Max_Data = 0xFF
  277. * @param DeadTime This parameter can be a number between Min_Data = 1 and
  278. * Max_Data = 0xFF
  279. * @retval None
  280. */
  281. __STATIC_INLINE void LL_LED_SetLightAndDeadTime(LED_TypeDef *LEDx,\
  282. uint32_t LightTime, uint32_t DeadTime)
  283. {
  284. MODIFY_REG(LEDx->TR, (LED_TR_T1 | LED_TR_T2), ((LightTime << LED_TR_T1_Pos) |\
  285. (DeadTime << LED_TR_T2_Pos)));
  286. }
  287. /**
  288. * @brief Set the LED Lighting time.
  289. * @param LEDx LED Instance
  290. * @param LightTime This parameter can be a number between Min_Data = 1 and
  291. * Max_Data = 0xFF
  292. * @retval None
  293. */
  294. __STATIC_INLINE void LL_LED_SetLightTime(LED_TypeDef *LEDx, uint32_t LightTime)
  295. {
  296. MODIFY_REG(LEDx->TR, LED_TR_T1, (LightTime << LED_TR_T1_Pos));
  297. }
  298. /**
  299. * @brief Set the LED Dead time.
  300. * @param LEDx LED Instance
  301. * @param DeadTime This parameter can be a number between Min_Data = 1 and
  302. * Max_Data = 0xFF
  303. * @retval None
  304. */
  305. __STATIC_INLINE void LL_LED_SetDeadTime(LED_TypeDef *LEDx, uint32_t DeadTime)
  306. {
  307. MODIFY_REG(LEDx->TR, LED_TR_T2, (DeadTime << LED_TR_T2_Pos));
  308. }
  309. /**
  310. * @brief Get the LED Lighting time.
  311. * @param LEDx LED Instance
  312. * @retval Returned value can be a number between Min_Data = 1 and
  313. * Max_Data = 0xFF
  314. */
  315. __STATIC_INLINE uint32_t LL_LED_GetLightTime(LED_TypeDef *LEDx)
  316. {
  317. return (READ_BIT(LEDx->TR, LED_TR_T1) >> LED_TR_T1_Pos);
  318. }
  319. /**
  320. * @brief Get the LED Dead time.
  321. * @param LEDx LED Instance
  322. * @retval Returned value can be a number between Min_Data = 1 and
  323. * Max_Data = 0xFF
  324. */
  325. __STATIC_INLINE uint32_t LL_LED_GetDeadTime(LED_TypeDef *LEDx)
  326. {
  327. return (READ_BIT(LEDx->TR, LED_TR_T2) >> LED_TR_T2_Pos);
  328. }
  329. /**
  330. * @brief Set the LED display value.
  331. * @param LEDx LED Instance
  332. * @param comCh Specify COM channels.This parameter can be one of the following values:
  333. * @arg @ref LL_LED_COM0
  334. * @arg @ref LL_LED_COM1
  335. * @arg @ref LL_LED_COM2
  336. * @arg @ref LL_LED_COM3
  337. * @param data Specify display values.This parameter can be one of the following values:
  338. * @arg @ref LL_LED_DISP_NONE
  339. * @arg @ref LL_LED_DISP_FULL
  340. * @arg @ref LL_LED_DISP_0
  341. * @arg @ref LL_LED_DISP_1
  342. * @arg @ref LL_LED_DISP_2
  343. * @arg @ref LL_LED_DISP_3
  344. * @arg @ref LL_LED_DISP_4
  345. * @arg @ref LL_LED_DISP_5
  346. * @arg @ref LL_LED_DISP_6
  347. * @arg @ref LL_LED_DISP_7
  348. * @arg @ref LL_LED_DISP_8
  349. * @arg @ref LL_LED_DISP_9
  350. * @arg @ref LL_LED_DISP_A
  351. * @arg @ref LL_LED_DISP_B
  352. * @arg @ref LL_LED_DISP_C
  353. * @arg @ref LL_LED_DISP_D
  354. * @arg @ref LL_LED_DISP_E
  355. * @arg @ref LL_LED_DISP_F
  356. * @arg @ref LL_LED_DISP_H
  357. * @arg @ref LL_LED_DISP_P
  358. * @arg @ref LL_LED_DISP_U
  359. * @arg @ref LL_LED_DISP_DOT
  360. * @retval None
  361. */
  362. __STATIC_INLINE void LL_LED_SetDisplayValue(LED_TypeDef *LEDx,uint32_t comCh,\
  363. uint32_t data)
  364. {
  365. MODIFY_REG((*((uint32_t *)((uint32_t)&(LEDx->DR0) + comCh))), LL_LED_DR_DATA,\
  366. (data << LL_LED_DR_DATA_Pos));
  367. }
  368. /**
  369. * @brief Get the LED display value.
  370. * @param LEDx LED Instance
  371. * @param comCh Specify COM channels.This parameter can be one of the following values:
  372. * @arg @ref LL_LED_COM0
  373. * @arg @ref LL_LED_COM1
  374. * @arg @ref LL_LED_COM2
  375. * @arg @ref LL_LED_COM3
  376. * @retval Returned value can be one of the following values:
  377. * @arg @ref LL_LED_DISP_NONE
  378. * @arg @ref LL_LED_DISP_FULL
  379. * @arg @ref LL_LED_DISP_0
  380. * @arg @ref LL_LED_DISP_1
  381. * @arg @ref LL_LED_DISP_2
  382. * @arg @ref LL_LED_DISP_3
  383. * @arg @ref LL_LED_DISP_4
  384. * @arg @ref LL_LED_DISP_5
  385. * @arg @ref LL_LED_DISP_6
  386. * @arg @ref LL_LED_DISP_7
  387. * @arg @ref LL_LED_DISP_8
  388. * @arg @ref LL_LED_DISP_9
  389. * @arg @ref LL_LED_DISP_A
  390. * @arg @ref LL_LED_DISP_B
  391. * @arg @ref LL_LED_DISP_C
  392. * @arg @ref LL_LED_DISP_D
  393. * @arg @ref LL_LED_DISP_E
  394. * @arg @ref LL_LED_DISP_F
  395. * @arg @ref LL_LED_DISP_H
  396. * @arg @ref LL_LED_DISP_P
  397. * @arg @ref LL_LED_DISP_U
  398. * @arg @ref LL_LED_DISP_DOT
  399. */
  400. __STATIC_INLINE uint32_t LL_LED_GetDisplayValue(LED_TypeDef *LEDx, uint32_t comCh)
  401. {
  402. return ((READ_BIT((*((uint32_t *)((uint32_t)&(LEDx->DR0) + comCh))), LL_LED_DR_DATA))\
  403. >> LL_LED_DR_DATA_Pos);
  404. }
  405. /**
  406. * @brief Get the LED interrupt flag.
  407. * @param LEDx LED Instance
  408. * @retval State of bit (1 or 0).
  409. */
  410. __STATIC_INLINE uint32_t LL_LED_IsActiveFlag_IT(LED_TypeDef *LEDx)
  411. {
  412. return ((READ_BIT(LEDx->IR, LED_IR_FLAG) == (LED_IR_FLAG)) ? 1UL : 0UL);
  413. }
  414. /**
  415. * @brief the LED interrupt flag.
  416. * @param LEDx LED Instance
  417. * @retval None
  418. */
  419. __STATIC_INLINE void LL_LED_ClearFlag_IT(LED_TypeDef *LEDx)
  420. {
  421. SET_BIT(LEDx->IR, LED_IR_FLAG);
  422. }
  423. #if defined(USE_FULL_LL_DRIVER)
  424. /** @defgroup LED_LL_EF_Init Initialization and de-initialization functions
  425. * @{
  426. */
  427. ErrorStatus LL_LED_DeInit(LED_TypeDef *LEDx);
  428. ErrorStatus LL_LED_Init(LED_TypeDef *LEDx, LL_LED_InitTypeDef *LED_InitStruct);
  429. void LL_LED_StructInit(LL_LED_InitTypeDef *LED_InitStruct);
  430. /**
  431. * @}
  432. */
  433. #endif /* USE_FULL_LL_DRIVER */
  434. /**
  435. * @}
  436. */
  437. /**
  438. * @}
  439. */
  440. #endif /* LED */
  441. /**
  442. * @}
  443. */
  444. #ifdef __cplusplus
  445. }
  446. #endif
  447. #endif /* PY32F0xx_LL_LED_H */
  448. /************************ (C) COPYRIGHT Puya *****END OF FILE****/