py32f002b_ll_lptim.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /**
  2. ******************************************************************************
  3. * @file py32f002b_ll_lptim.c
  4. * @author MCU Application Team
  5. * @brief LPTIM 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 "py32f002b_ll_lptim.h"
  33. #include "py32f002b_ll_bus.h"
  34. #include "py32f002b_ll_rcc.h"
  35. #ifdef USE_FULL_ASSERT
  36. #include "py32_assert.h"
  37. #else
  38. #define assert_param(expr) ((void)0U)
  39. #endif /* USE_FULL_ASSERT */
  40. /** @addtogroup PY32F002B_LL_Driver
  41. * @{
  42. */
  43. #if defined (LPTIM)
  44. /** @addtogroup LPTIM_LL
  45. * @{
  46. */
  47. /* Private types -------------------------------------------------------------*/
  48. /* Private variables ---------------------------------------------------------*/
  49. /* Private constants ---------------------------------------------------------*/
  50. /* Private macros ------------------------------------------------------------*/
  51. /** @addtogroup LPTIM_LL_Private_Macros
  52. * @{
  53. */
  54. #define IS_LL_LPTIM_CLOCK_PRESCALER(__VALUE__) (((__VALUE__) == LL_LPTIM_PRESCALER_DIV1) \
  55. || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV2) \
  56. || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV4) \
  57. || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV8) \
  58. || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV16) \
  59. || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV32) \
  60. || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV64) \
  61. || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV128))
  62. #define IS_LL_LPTIM_UPDATA_MODE(__VALUE__) (((__VALUE__) == LL_LPTIM_UPDATE_MODE_IMMEDIATE) \
  63. || ((__VALUE__) == LL_LPTIM_UPDATE_MODE_ENDOFPERIOD)) \
  64. /**
  65. * @}
  66. */
  67. /* Private function prototypes -----------------------------------------------*/
  68. /* Private functions ---------------------------------------------------------*/
  69. /** @defgroup LPTIM_Private_Functions LPTIM Private Functions
  70. * @{
  71. */
  72. /**
  73. * @}
  74. */
  75. /* Exported functions --------------------------------------------------------*/
  76. /** @addtogroup LPTIM_LL_Exported_Functions
  77. * @{
  78. */
  79. /** @addtogroup LPTIM_LL_EF_Init
  80. * @{
  81. */
  82. /**
  83. * @brief Set LPTIMx registers to their reset values.
  84. * @param LPTIMx LP Timer instance
  85. * @retval An ErrorStatus enumeration value:
  86. * - SUCCESS: LPTIMx registers are de-initialized
  87. * - ERROR: invalid LPTIMx instance
  88. */
  89. ErrorStatus LL_LPTIM_DeInit(LPTIM_TypeDef *LPTIMx)
  90. {
  91. ErrorStatus result = SUCCESS;
  92. /* Check the parameters */
  93. assert_param(IS_LPTIM_INSTANCE(LPTIMx));
  94. if (LPTIMx == LPTIM)
  95. {
  96. LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_LPTIM1);
  97. LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_LPTIM1);
  98. }
  99. else
  100. {
  101. result = ERROR;
  102. }
  103. return result;
  104. }
  105. /**
  106. * @brief Set each fields of the LPTIM_InitStruct structure to its default
  107. * value.
  108. * @param LPTIM_InitStruct pointer to a @ref LL_LPTIM_InitTypeDef structure
  109. * @retval None
  110. */
  111. void LL_LPTIM_StructInit(LL_LPTIM_InitTypeDef *LPTIM_InitStruct)
  112. {
  113. /* Set the default configuration */
  114. LPTIM_InitStruct->Prescaler = LL_LPTIM_PRESCALER_DIV1;
  115. LPTIM_InitStruct->UpdateMode = LL_LPTIM_UPDATE_MODE_IMMEDIATE;
  116. }
  117. /**
  118. * @brief Configure the LPTIMx peripheral according to the specified parameters.
  119. * @note LL_LPTIM_Init can only be called when the LPTIM instance is disabled.
  120. * @note LPTIMx can be disabled using unitary function @ref LL_LPTIM_Disable().
  121. * @param LPTIMx LP Timer Instance
  122. * @param LPTIM_InitStruct pointer to a @ref LL_LPTIM_InitTypeDef structure
  123. * @retval An ErrorStatus enumeration value:
  124. * - SUCCESS: LPTIMx instance has been initialized
  125. * - ERROR: LPTIMx instance hasn't been initialized
  126. */
  127. ErrorStatus LL_LPTIM_Init(LPTIM_TypeDef *LPTIMx, LL_LPTIM_InitTypeDef *LPTIM_InitStruct)
  128. {
  129. ErrorStatus result = SUCCESS;
  130. /* Check the parameters */
  131. assert_param(IS_LPTIM_INSTANCE(LPTIMx));
  132. assert_param(IS_LL_LPTIM_CLOCK_PRESCALER(LPTIM_InitStruct->Prescaler));
  133. assert_param(IS_LL_LPTIM_UPDATA_MODE(LPTIM_InitStruct->UpdateMode));
  134. /* The LPTIMx_CFGR register must only be modified when the LPTIM is disabled
  135. (ENABLE bit is reset to 0).
  136. */
  137. if (LL_LPTIM_IsEnabled(LPTIMx) == 1UL)
  138. {
  139. result = ERROR;
  140. }
  141. else
  142. {
  143. /* Set PRESC bitfield according to Prescaler value */
  144. MODIFY_REG(LPTIMx->CFGR,
  145. (LPTIM_CFGR_PRESC | LPTIM_CFGR_PRELOAD),
  146. LPTIM_InitStruct->Prescaler |
  147. LPTIM_InitStruct->UpdateMode);
  148. }
  149. return result;
  150. }
  151. /**
  152. * @}
  153. */
  154. /**
  155. * @}
  156. */
  157. /**
  158. * @}
  159. */
  160. #endif /* LPTIM */
  161. /**
  162. * @}
  163. */
  164. #endif /* USE_FULL_LL_DRIVER */
  165. /************************ (C) COPYRIGHT Puya *****END OF FILE****/