py32f0xx_ll_led.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /**
  2. ******************************************************************************
  3. * @file py32f0xx_ll_led.c
  4. * @author MCU Application Team
  5. * @brief LED LL module driver.
  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. #if defined(USE_FULL_LL_DRIVER)
  31. /* Includes ------------------------------------------------------------------*/
  32. #include "py32f0xx_ll_led.h"
  33. #include "py32f0xx_ll_bus.h"
  34. #ifdef USE_FULL_ASSERT
  35. #include "py32_assert.h"
  36. #else
  37. #define assert_param(expr) ((void)0U)
  38. #endif
  39. /** @addtogroup PY32F0xx_LL_Driver
  40. * @{
  41. */
  42. #if defined (LED)
  43. /** @addtogroup LED_LL
  44. * @{
  45. */
  46. /* Private types -------------------------------------------------------------*/
  47. /* Private variables ---------------------------------------------------------*/
  48. /* Private constants ---------------------------------------------------------*/
  49. /* Private macros ------------------------------------------------------------*/
  50. /** @defgroup LED_LL_Private_Macros LED Private Macros
  51. * @{
  52. */
  53. #define IS_LL_LED_COM_DRIVE(__VALUE__) (((__VALUE__) == LL_LED_COMDRIVE_LOW) ||\
  54. ((__VALUE__) == LL_LED_COMDRIVE_HIGH))
  55. #define IS_LL_LED_PRESCALER(__VALUE__) (((0x00u) < (__VALUE__)) && ((__VALUE__) <= (0xFFu)))
  56. #define IS_LL_LED_COM_SELECT(__VALUE__) (((__VALUE__) == LL_LED_COMSELECT_1COM) ||\
  57. ((__VALUE__) == LL_LED_COMSELECT_2COM) ||\
  58. ((__VALUE__) == LL_LED_COMSELECT_3COM) ||\
  59. ((__VALUE__) == LL_LED_COMSELECT_4COM))
  60. #define IS_LL_LED_LIGHT_TIME(__VALUE__) (((0x01u) < (__VALUE__)) && ((__VALUE__) <= (0xFFu)))
  61. #define IS_LL_LED_DEAD_TIME(__VALUE__) (((0x01u) < (__VALUE__)) && ((__VALUE__) <= (0xFFu)))
  62. /**
  63. * @}
  64. */
  65. /* Private function prototypes -----------------------------------------------*/
  66. /* Exported functions --------------------------------------------------------*/
  67. /** @addtogroup LED_LL_Exported_Functions
  68. * @{
  69. */
  70. /** @addtogroup LED_LL_EF_Init
  71. * @{
  72. */
  73. /**
  74. * @brief De-initialize LED registers.
  75. * @param LEDx LED Port
  76. * @retval An ErrorStatus enumeration value:
  77. * - SUCCESS: LED registers are de-initialized
  78. * - ERROR: Wrong LED
  79. */
  80. ErrorStatus LL_LED_DeInit(LED_TypeDef *LEDx)
  81. {
  82. ErrorStatus status = SUCCESS;
  83. /* Check the parameters */
  84. assert_param(IS_LED_ALL_INSTANCE(LEDx));
  85. /* Force and Release reset on clock of LEDx */
  86. if (LEDx == LED)
  87. {
  88. LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_LED);
  89. LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_LED);
  90. }
  91. else
  92. {
  93. status = ERROR;
  94. }
  95. return (status);
  96. }
  97. /**
  98. * @brief Initializes the LED registers according to the specified parameters in the LED_InitStruct.
  99. * @param LEDx LEDx Instance
  100. * @param LED_InitStruct pointer to a @ref LL_LED_InitTypeDef structure
  101. * that contains the configuration information for the specified LED peripheral.
  102. * @retval An ErrorStatus enumeration value:
  103. * - SUCCESS: LED registers are initialized according to LED_InitStruct content
  104. * - ERROR: Not applicable
  105. */
  106. ErrorStatus LL_LED_Init(LED_TypeDef *LEDx, LL_LED_InitTypeDef *LED_InitStruct)
  107. {
  108. /* Check the parameters */
  109. assert_param(IS_LED_ALL_INSTANCE(LEDx));
  110. assert_param(IS_LL_LED_COM_DRIVE(LED_InitStruct->ComDrive));
  111. assert_param(IS_LL_LED_PRESCALER(LED_InitStruct->Prescaler));
  112. assert_param(IS_LL_LED_COM_SELECT(LED_InitStruct->ComSelect));
  113. assert_param(IS_LL_LED_LIGHT_TIME(LED_InitStruct->LightTime));
  114. assert_param(IS_LL_LED_DEAD_TIME(LED_InitStruct->DeadTime));
  115. /* LED Register config */
  116. MODIFY_REG(LEDx->CR, (uint32_t)(LED_CR_LED_COM_SEL | LED_CR_EHS),
  117. (LED_InitStruct->ComSelect | LED_InitStruct->ComDrive));
  118. LL_LED_SetPrescaler(LEDx, LED_InitStruct->Prescaler);
  119. LL_LED_SetLightAndDeadTime(LEDx, LED_InitStruct->LightTime, LED_InitStruct->DeadTime);
  120. LL_LED_Enable(LEDx);
  121. return (SUCCESS);
  122. }
  123. /**
  124. * @brief Set each @ref LL_LED_InitTypeDef field to default value.
  125. * @param LED_InitStruct pointer to a @ref LL_LED_InitTypeDef structure
  126. * whose fields will be set to default values.
  127. * @retval None
  128. */
  129. void LL_LED_StructInit(LL_LED_InitTypeDef *LED_InitStruct)
  130. {
  131. /* Reset LED init structure parameters values */
  132. LED_InitStruct->ComDrive = LL_LED_COMDRIVE_LOW;
  133. LED_InitStruct->Prescaler = 0x0u;
  134. LED_InitStruct->ComSelect = LL_LED_COMSELECT_1COM;
  135. LED_InitStruct->LightTime = 0x0u;
  136. LED_InitStruct->DeadTime = 0x0u;
  137. }
  138. /**
  139. * @}
  140. */
  141. /**
  142. * @}
  143. */
  144. /**
  145. * @}
  146. */
  147. #endif /* defined (LED) */
  148. /**
  149. * @}
  150. */
  151. #endif /* USE_FULL_LL_DRIVER */
  152. /************************ (C) COPYRIGHT Puya Semiconductor *****END OF FILE****/