You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1305 lines
51 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32wbxx_ll_tim.c
  4. * @author MCD Application Team
  5. * @brief TIM LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST 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. */
  19. #if defined(USE_FULL_LL_DRIVER)
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "stm32wbxx_ll_tim.h"
  22. #include "stm32wbxx_ll_bus.h"
  23. #ifdef USE_FULL_ASSERT
  24. #include "stm32_assert.h"
  25. #else
  26. #define assert_param(expr) ((void)0U)
  27. #endif /* USE_FULL_ASSERT */
  28. /** @addtogroup STM32WBxx_LL_Driver
  29. * @{
  30. */
  31. #if defined (TIM1) || defined (TIM2) || defined (TIM16) || defined (TIM7)
  32. /** @addtogroup TIM_LL
  33. * @{
  34. */
  35. /* Private types -------------------------------------------------------------*/
  36. /* Private variables ---------------------------------------------------------*/
  37. /* Private constants ---------------------------------------------------------*/
  38. /* Private macros ------------------------------------------------------------*/
  39. /** @addtogroup TIM_LL_Private_Macros
  40. * @{
  41. */
  42. #define IS_LL_TIM_COUNTERMODE(__VALUE__) (((__VALUE__) == LL_TIM_COUNTERMODE_UP) \
  43. || ((__VALUE__) == LL_TIM_COUNTERMODE_DOWN) \
  44. || ((__VALUE__) == LL_TIM_COUNTERMODE_CENTER_UP) \
  45. || ((__VALUE__) == LL_TIM_COUNTERMODE_CENTER_DOWN) \
  46. || ((__VALUE__) == LL_TIM_COUNTERMODE_CENTER_UP_DOWN))
  47. #define IS_LL_TIM_CLOCKDIVISION(__VALUE__) (((__VALUE__) == LL_TIM_CLOCKDIVISION_DIV1) \
  48. || ((__VALUE__) == LL_TIM_CLOCKDIVISION_DIV2) \
  49. || ((__VALUE__) == LL_TIM_CLOCKDIVISION_DIV4))
  50. #define IS_LL_TIM_OCMODE(__VALUE__) (((__VALUE__) == LL_TIM_OCMODE_FROZEN) \
  51. || ((__VALUE__) == LL_TIM_OCMODE_ACTIVE) \
  52. || ((__VALUE__) == LL_TIM_OCMODE_INACTIVE) \
  53. || ((__VALUE__) == LL_TIM_OCMODE_TOGGLE) \
  54. || ((__VALUE__) == LL_TIM_OCMODE_FORCED_INACTIVE) \
  55. || ((__VALUE__) == LL_TIM_OCMODE_FORCED_ACTIVE) \
  56. || ((__VALUE__) == LL_TIM_OCMODE_PWM1) \
  57. || ((__VALUE__) == LL_TIM_OCMODE_PWM2) \
  58. || ((__VALUE__) == LL_TIM_OCMODE_RETRIG_OPM1) \
  59. || ((__VALUE__) == LL_TIM_OCMODE_RETRIG_OPM2) \
  60. || ((__VALUE__) == LL_TIM_OCMODE_COMBINED_PWM1) \
  61. || ((__VALUE__) == LL_TIM_OCMODE_COMBINED_PWM2) \
  62. || ((__VALUE__) == LL_TIM_OCMODE_ASSYMETRIC_PWM1) \
  63. || ((__VALUE__) == LL_TIM_OCMODE_ASSYMETRIC_PWM2))
  64. #define IS_LL_TIM_OCSTATE(__VALUE__) (((__VALUE__) == LL_TIM_OCSTATE_DISABLE) \
  65. || ((__VALUE__) == LL_TIM_OCSTATE_ENABLE))
  66. #define IS_LL_TIM_OCPOLARITY(__VALUE__) (((__VALUE__) == LL_TIM_OCPOLARITY_HIGH) \
  67. || ((__VALUE__) == LL_TIM_OCPOLARITY_LOW))
  68. #define IS_LL_TIM_OCIDLESTATE(__VALUE__) (((__VALUE__) == LL_TIM_OCIDLESTATE_LOW) \
  69. || ((__VALUE__) == LL_TIM_OCIDLESTATE_HIGH))
  70. #define IS_LL_TIM_ACTIVEINPUT(__VALUE__) (((__VALUE__) == LL_TIM_ACTIVEINPUT_DIRECTTI) \
  71. || ((__VALUE__) == LL_TIM_ACTIVEINPUT_INDIRECTTI) \
  72. || ((__VALUE__) == LL_TIM_ACTIVEINPUT_TRC))
  73. #define IS_LL_TIM_ICPSC(__VALUE__) (((__VALUE__) == LL_TIM_ICPSC_DIV1) \
  74. || ((__VALUE__) == LL_TIM_ICPSC_DIV2) \
  75. || ((__VALUE__) == LL_TIM_ICPSC_DIV4) \
  76. || ((__VALUE__) == LL_TIM_ICPSC_DIV8))
  77. #define IS_LL_TIM_IC_FILTER(__VALUE__) (((__VALUE__) == LL_TIM_IC_FILTER_FDIV1) \
  78. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV1_N2) \
  79. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV1_N4) \
  80. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV1_N8) \
  81. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV2_N6) \
  82. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV2_N8) \
  83. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV4_N6) \
  84. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV4_N8) \
  85. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV8_N6) \
  86. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV8_N8) \
  87. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV16_N5) \
  88. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV16_N6) \
  89. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV16_N8) \
  90. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV32_N5) \
  91. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV32_N6) \
  92. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV32_N8))
  93. #define IS_LL_TIM_IC_POLARITY(__VALUE__) (((__VALUE__) == LL_TIM_IC_POLARITY_RISING) \
  94. || ((__VALUE__) == LL_TIM_IC_POLARITY_FALLING) \
  95. || ((__VALUE__) == LL_TIM_IC_POLARITY_BOTHEDGE))
  96. #define IS_LL_TIM_ENCODERMODE(__VALUE__) (((__VALUE__) == LL_TIM_ENCODERMODE_X2_TI1) \
  97. || ((__VALUE__) == LL_TIM_ENCODERMODE_X2_TI2) \
  98. || ((__VALUE__) == LL_TIM_ENCODERMODE_X4_TI12))
  99. #define IS_LL_TIM_IC_POLARITY_ENCODER(__VALUE__) (((__VALUE__) == LL_TIM_IC_POLARITY_RISING) \
  100. || ((__VALUE__) == LL_TIM_IC_POLARITY_FALLING))
  101. #define IS_LL_TIM_OSSR_STATE(__VALUE__) (((__VALUE__) == LL_TIM_OSSR_DISABLE) \
  102. || ((__VALUE__) == LL_TIM_OSSR_ENABLE))
  103. #define IS_LL_TIM_OSSI_STATE(__VALUE__) (((__VALUE__) == LL_TIM_OSSI_DISABLE) \
  104. || ((__VALUE__) == LL_TIM_OSSI_ENABLE))
  105. #define IS_LL_TIM_LOCK_LEVEL(__VALUE__) (((__VALUE__) == LL_TIM_LOCKLEVEL_OFF) \
  106. || ((__VALUE__) == LL_TIM_LOCKLEVEL_1) \
  107. || ((__VALUE__) == LL_TIM_LOCKLEVEL_2) \
  108. || ((__VALUE__) == LL_TIM_LOCKLEVEL_3))
  109. #define IS_LL_TIM_BREAK_STATE(__VALUE__) (((__VALUE__) == LL_TIM_BREAK_DISABLE) \
  110. || ((__VALUE__) == LL_TIM_BREAK_ENABLE))
  111. #define IS_LL_TIM_BREAK_POLARITY(__VALUE__) (((__VALUE__) == LL_TIM_BREAK_POLARITY_LOW) \
  112. || ((__VALUE__) == LL_TIM_BREAK_POLARITY_HIGH))
  113. #define IS_LL_TIM_BREAK_FILTER(__VALUE__) (((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV1) \
  114. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV1_N2) \
  115. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV1_N4) \
  116. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV1_N8) \
  117. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV2_N6) \
  118. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV2_N8) \
  119. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV4_N6) \
  120. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV4_N8) \
  121. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV8_N6) \
  122. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV8_N8) \
  123. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV16_N5) \
  124. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV16_N6) \
  125. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV16_N8) \
  126. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV32_N5) \
  127. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV32_N6) \
  128. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV32_N8))
  129. #define IS_LL_TIM_BREAK2_STATE(__VALUE__) (((__VALUE__) == LL_TIM_BREAK2_DISABLE) \
  130. || ((__VALUE__) == LL_TIM_BREAK2_ENABLE))
  131. #define IS_LL_TIM_BREAK2_POLARITY(__VALUE__) (((__VALUE__) == LL_TIM_BREAK2_POLARITY_LOW) \
  132. || ((__VALUE__) == LL_TIM_BREAK2_POLARITY_HIGH))
  133. #define IS_LL_TIM_BREAK2_FILTER(__VALUE__) (((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV1) \
  134. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV1_N2) \
  135. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV1_N4) \
  136. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV1_N8) \
  137. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV2_N6) \
  138. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV2_N8) \
  139. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV4_N6) \
  140. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV4_N8) \
  141. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV8_N6) \
  142. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV8_N8) \
  143. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV16_N5) \
  144. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV16_N6) \
  145. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV16_N8) \
  146. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV32_N5) \
  147. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV32_N6) \
  148. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV32_N8))
  149. #define IS_LL_TIM_AUTOMATIC_OUTPUT_STATE(__VALUE__) (((__VALUE__) == LL_TIM_AUTOMATICOUTPUT_DISABLE) \
  150. || ((__VALUE__) == LL_TIM_AUTOMATICOUTPUT_ENABLE))
  151. /**
  152. * @}
  153. */
  154. /* Private function prototypes -----------------------------------------------*/
  155. /** @defgroup TIM_LL_Private_Functions TIM Private Functions
  156. * @{
  157. */
  158. static ErrorStatus OC1Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct);
  159. static ErrorStatus OC2Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct);
  160. static ErrorStatus OC3Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct);
  161. static ErrorStatus OC4Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct);
  162. static ErrorStatus OC5Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct);
  163. static ErrorStatus OC6Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct);
  164. static ErrorStatus IC1Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct);
  165. static ErrorStatus IC2Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct);
  166. static ErrorStatus IC3Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct);
  167. static ErrorStatus IC4Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct);
  168. /**
  169. * @}
  170. */
  171. /* Exported functions --------------------------------------------------------*/
  172. /** @addtogroup TIM_LL_Exported_Functions
  173. * @{
  174. */
  175. /** @addtogroup TIM_LL_EF_Init
  176. * @{
  177. */
  178. /**
  179. * @brief Set TIMx registers to their reset values.
  180. * @param TIMx Timer instance
  181. * @retval An ErrorStatus enumeration value:
  182. * - SUCCESS: TIMx registers are de-initialized
  183. * - ERROR: invalid TIMx instance
  184. */
  185. ErrorStatus LL_TIM_DeInit(TIM_TypeDef *TIMx)
  186. {
  187. ErrorStatus result = SUCCESS;
  188. /* Check the parameters */
  189. assert_param(IS_TIM_INSTANCE(TIMx));
  190. if (TIMx == TIM1)
  191. {
  192. LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_TIM1);
  193. LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_TIM1);
  194. }
  195. else if (TIMx == TIM2)
  196. {
  197. LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM2);
  198. LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM2);
  199. }
  200. else if (TIMx == TIM16)
  201. {
  202. LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_TIM16);
  203. LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_TIM16);
  204. }
  205. else if (TIMx == TIM17)
  206. {
  207. LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_TIM17);
  208. LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_TIM17);
  209. }
  210. else
  211. {
  212. result = ERROR;
  213. }
  214. return result;
  215. }
  216. /**
  217. * @brief Set the fields of the time base unit configuration data structure
  218. * to their default values.
  219. * @param TIM_InitStruct pointer to a @ref LL_TIM_InitTypeDef structure (time base unit configuration data structure)
  220. * @retval None
  221. */
  222. void LL_TIM_StructInit(LL_TIM_InitTypeDef *TIM_InitStruct)
  223. {
  224. /* Set the default configuration */
  225. TIM_InitStruct->Prescaler = (uint16_t)0x0000;
  226. TIM_InitStruct->CounterMode = LL_TIM_COUNTERMODE_UP;
  227. TIM_InitStruct->Autoreload = 0xFFFFFFFFU;
  228. TIM_InitStruct->ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
  229. TIM_InitStruct->RepetitionCounter = 0x00000000U;
  230. }
  231. /**
  232. * @brief Configure the TIMx time base unit.
  233. * @param TIMx Timer Instance
  234. * @param TIM_InitStruct pointer to a @ref LL_TIM_InitTypeDef structure (TIMx time base unit configuration data structure)
  235. * @retval An ErrorStatus enumeration value:
  236. * - SUCCESS: TIMx registers are de-initialized
  237. * - ERROR: not applicable
  238. */
  239. ErrorStatus LL_TIM_Init(TIM_TypeDef *TIMx, LL_TIM_InitTypeDef *TIM_InitStruct)
  240. {
  241. uint32_t tmpcr1;
  242. /* Check the parameters */
  243. assert_param(IS_TIM_INSTANCE(TIMx));
  244. assert_param(IS_LL_TIM_COUNTERMODE(TIM_InitStruct->CounterMode));
  245. assert_param(IS_LL_TIM_CLOCKDIVISION(TIM_InitStruct->ClockDivision));
  246. tmpcr1 = LL_TIM_ReadReg(TIMx, CR1);
  247. if (IS_TIM_COUNTER_MODE_SELECT_INSTANCE(TIMx))
  248. {
  249. /* Select the Counter Mode */
  250. MODIFY_REG(tmpcr1, (TIM_CR1_DIR | TIM_CR1_CMS), TIM_InitStruct->CounterMode);
  251. }
  252. if (IS_TIM_CLOCK_DIVISION_INSTANCE(TIMx))
  253. {
  254. /* Set the clock division */
  255. MODIFY_REG(tmpcr1, TIM_CR1_CKD, TIM_InitStruct->ClockDivision);
  256. }
  257. /* Write to TIMx CR1 */
  258. LL_TIM_WriteReg(TIMx, CR1, tmpcr1);
  259. /* Set the Autoreload value */
  260. LL_TIM_SetAutoReload(TIMx, TIM_InitStruct->Autoreload);
  261. /* Set the Prescaler value */
  262. LL_TIM_SetPrescaler(TIMx, TIM_InitStruct->Prescaler);
  263. if (IS_TIM_REPETITION_COUNTER_INSTANCE(TIMx))
  264. {
  265. /* Set the Repetition Counter value */
  266. LL_TIM_SetRepetitionCounter(TIMx, TIM_InitStruct->RepetitionCounter);
  267. }
  268. /* Generate an update event to reload the Prescaler
  269. and the repetition counter value (if applicable) immediately */
  270. LL_TIM_GenerateEvent_UPDATE(TIMx);
  271. return SUCCESS;
  272. }
  273. /**
  274. * @brief Set the fields of the TIMx output channel configuration data
  275. * structure to their default values.
  276. * @param TIM_OC_InitStruct pointer to a @ref LL_TIM_OC_InitTypeDef structure (the output channel configuration data structure)
  277. * @retval None
  278. */
  279. void LL_TIM_OC_StructInit(LL_TIM_OC_InitTypeDef *TIM_OC_InitStruct)
  280. {
  281. /* Set the default configuration */
  282. TIM_OC_InitStruct->OCMode = LL_TIM_OCMODE_FROZEN;
  283. TIM_OC_InitStruct->OCState = LL_TIM_OCSTATE_DISABLE;
  284. TIM_OC_InitStruct->OCNState = LL_TIM_OCSTATE_DISABLE;
  285. TIM_OC_InitStruct->CompareValue = 0x00000000U;
  286. TIM_OC_InitStruct->OCPolarity = LL_TIM_OCPOLARITY_HIGH;
  287. TIM_OC_InitStruct->OCNPolarity = LL_TIM_OCPOLARITY_HIGH;
  288. TIM_OC_InitStruct->OCIdleState = LL_TIM_OCIDLESTATE_LOW;
  289. TIM_OC_InitStruct->OCNIdleState = LL_TIM_OCIDLESTATE_LOW;
  290. }
  291. /**
  292. * @brief Configure the TIMx output channel.
  293. * @param TIMx Timer Instance
  294. * @param Channel This parameter can be one of the following values:
  295. * @arg @ref LL_TIM_CHANNEL_CH1
  296. * @arg @ref LL_TIM_CHANNEL_CH2
  297. * @arg @ref LL_TIM_CHANNEL_CH3
  298. * @arg @ref LL_TIM_CHANNEL_CH4
  299. * @arg @ref LL_TIM_CHANNEL_CH5
  300. * @arg @ref LL_TIM_CHANNEL_CH6
  301. * @param TIM_OC_InitStruct pointer to a @ref LL_TIM_OC_InitTypeDef structure (TIMx output channel configuration data structure)
  302. * @retval An ErrorStatus enumeration value:
  303. * - SUCCESS: TIMx output channel is initialized
  304. * - ERROR: TIMx output channel is not initialized
  305. */
  306. ErrorStatus LL_TIM_OC_Init(TIM_TypeDef *TIMx, uint32_t Channel, LL_TIM_OC_InitTypeDef *TIM_OC_InitStruct)
  307. {
  308. ErrorStatus result = ERROR;
  309. switch (Channel)
  310. {
  311. case LL_TIM_CHANNEL_CH1:
  312. result = OC1Config(TIMx, TIM_OC_InitStruct);
  313. break;
  314. case LL_TIM_CHANNEL_CH2:
  315. result = OC2Config(TIMx, TIM_OC_InitStruct);
  316. break;
  317. case LL_TIM_CHANNEL_CH3:
  318. result = OC3Config(TIMx, TIM_OC_InitStruct);
  319. break;
  320. case LL_TIM_CHANNEL_CH4:
  321. result = OC4Config(TIMx, TIM_OC_InitStruct);
  322. break;
  323. case LL_TIM_CHANNEL_CH5:
  324. result = OC5Config(TIMx, TIM_OC_InitStruct);
  325. break;
  326. case LL_TIM_CHANNEL_CH6:
  327. result = OC6Config(TIMx, TIM_OC_InitStruct);
  328. break;
  329. default:
  330. break;
  331. }
  332. return result;
  333. }
  334. /**
  335. * @brief Set the fields of the TIMx input channel configuration data
  336. * structure to their default values.
  337. * @param TIM_ICInitStruct pointer to a @ref LL_TIM_IC_InitTypeDef structure (the input channel configuration data structure)
  338. * @retval None
  339. */
  340. void LL_TIM_IC_StructInit(LL_TIM_IC_InitTypeDef *TIM_ICInitStruct)
  341. {
  342. /* Set the default configuration */
  343. TIM_ICInitStruct->ICPolarity = LL_TIM_IC_POLARITY_RISING;
  344. TIM_ICInitStruct->ICActiveInput = LL_TIM_ACTIVEINPUT_DIRECTTI;
  345. TIM_ICInitStruct->ICPrescaler = LL_TIM_ICPSC_DIV1;
  346. TIM_ICInitStruct->ICFilter = LL_TIM_IC_FILTER_FDIV1;
  347. }
  348. /**
  349. * @brief Configure the TIMx input channel.
  350. * @param TIMx Timer Instance
  351. * @param Channel This parameter can be one of the following values:
  352. * @arg @ref LL_TIM_CHANNEL_CH1
  353. * @arg @ref LL_TIM_CHANNEL_CH2
  354. * @arg @ref LL_TIM_CHANNEL_CH3
  355. * @arg @ref LL_TIM_CHANNEL_CH4
  356. * @param TIM_IC_InitStruct pointer to a @ref LL_TIM_IC_InitTypeDef structure (TIMx input channel configuration data structure)
  357. * @retval An ErrorStatus enumeration value:
  358. * - SUCCESS: TIMx output channel is initialized
  359. * - ERROR: TIMx output channel is not initialized
  360. */
  361. ErrorStatus LL_TIM_IC_Init(TIM_TypeDef *TIMx, uint32_t Channel, LL_TIM_IC_InitTypeDef *TIM_IC_InitStruct)
  362. {
  363. ErrorStatus result = ERROR;
  364. switch (Channel)
  365. {
  366. case LL_TIM_CHANNEL_CH1:
  367. result = IC1Config(TIMx, TIM_IC_InitStruct);
  368. break;
  369. case LL_TIM_CHANNEL_CH2:
  370. result = IC2Config(TIMx, TIM_IC_InitStruct);
  371. break;
  372. case LL_TIM_CHANNEL_CH3:
  373. result = IC3Config(TIMx, TIM_IC_InitStruct);
  374. break;
  375. case LL_TIM_CHANNEL_CH4:
  376. result = IC4Config(TIMx, TIM_IC_InitStruct);
  377. break;
  378. default:
  379. break;
  380. }
  381. return result;
  382. }
  383. /**
  384. * @brief Fills each TIM_EncoderInitStruct field with its default value
  385. * @param TIM_EncoderInitStruct pointer to a @ref LL_TIM_ENCODER_InitTypeDef structure (encoder interface configuration data structure)
  386. * @retval None
  387. */
  388. void LL_TIM_ENCODER_StructInit(LL_TIM_ENCODER_InitTypeDef *TIM_EncoderInitStruct)
  389. {
  390. /* Set the default configuration */
  391. TIM_EncoderInitStruct->EncoderMode = LL_TIM_ENCODERMODE_X2_TI1;
  392. TIM_EncoderInitStruct->IC1Polarity = LL_TIM_IC_POLARITY_RISING;
  393. TIM_EncoderInitStruct->IC1ActiveInput = LL_TIM_ACTIVEINPUT_DIRECTTI;
  394. TIM_EncoderInitStruct->IC1Prescaler = LL_TIM_ICPSC_DIV1;
  395. TIM_EncoderInitStruct->IC1Filter = LL_TIM_IC_FILTER_FDIV1;
  396. TIM_EncoderInitStruct->IC2Polarity = LL_TIM_IC_POLARITY_RISING;
  397. TIM_EncoderInitStruct->IC2ActiveInput = LL_TIM_ACTIVEINPUT_DIRECTTI;
  398. TIM_EncoderInitStruct->IC2Prescaler = LL_TIM_ICPSC_DIV1;
  399. TIM_EncoderInitStruct->IC2Filter = LL_TIM_IC_FILTER_FDIV1;
  400. }
  401. /**
  402. * @brief Configure the encoder interface of the timer instance.
  403. * @param TIMx Timer Instance
  404. * @param TIM_EncoderInitStruct pointer to a @ref LL_TIM_ENCODER_InitTypeDef structure (TIMx encoder interface configuration data structure)
  405. * @retval An ErrorStatus enumeration value:
  406. * - SUCCESS: TIMx registers are de-initialized
  407. * - ERROR: not applicable
  408. */
  409. ErrorStatus LL_TIM_ENCODER_Init(TIM_TypeDef *TIMx, LL_TIM_ENCODER_InitTypeDef *TIM_EncoderInitStruct)
  410. {
  411. uint32_t tmpccmr1;
  412. uint32_t tmpccer;
  413. /* Check the parameters */
  414. assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(TIMx));
  415. assert_param(IS_LL_TIM_ENCODERMODE(TIM_EncoderInitStruct->EncoderMode));
  416. assert_param(IS_LL_TIM_IC_POLARITY_ENCODER(TIM_EncoderInitStruct->IC1Polarity));
  417. assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_EncoderInitStruct->IC1ActiveInput));
  418. assert_param(IS_LL_TIM_ICPSC(TIM_EncoderInitStruct->IC1Prescaler));
  419. assert_param(IS_LL_TIM_IC_FILTER(TIM_EncoderInitStruct->IC1Filter));
  420. assert_param(IS_LL_TIM_IC_POLARITY_ENCODER(TIM_EncoderInitStruct->IC2Polarity));
  421. assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_EncoderInitStruct->IC2ActiveInput));
  422. assert_param(IS_LL_TIM_ICPSC(TIM_EncoderInitStruct->IC2Prescaler));
  423. assert_param(IS_LL_TIM_IC_FILTER(TIM_EncoderInitStruct->IC2Filter));
  424. /* Disable the CC1 and CC2: Reset the CC1E and CC2E Bits */
  425. TIMx->CCER &= (uint32_t)~(TIM_CCER_CC1E | TIM_CCER_CC2E);
  426. /* Get the TIMx CCMR1 register value */
  427. tmpccmr1 = LL_TIM_ReadReg(TIMx, CCMR1);
  428. /* Get the TIMx CCER register value */
  429. tmpccer = LL_TIM_ReadReg(TIMx, CCER);
  430. /* Configure TI1 */
  431. tmpccmr1 &= (uint32_t)~(TIM_CCMR1_CC1S | TIM_CCMR1_IC1F | TIM_CCMR1_IC1PSC);
  432. tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC1ActiveInput >> 16U);
  433. tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC1Filter >> 16U);
  434. tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC1Prescaler >> 16U);
  435. /* Configure TI2 */
  436. tmpccmr1 &= (uint32_t)~(TIM_CCMR1_CC2S | TIM_CCMR1_IC2F | TIM_CCMR1_IC2PSC);
  437. tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC2ActiveInput >> 8U);
  438. tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC2Filter >> 8U);
  439. tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC2Prescaler >> 8U);
  440. /* Set TI1 and TI2 polarity and enable TI1 and TI2 */
  441. tmpccer &= (uint32_t)~(TIM_CCER_CC1P | TIM_CCER_CC1NP | TIM_CCER_CC2P | TIM_CCER_CC2NP);
  442. tmpccer |= (uint32_t)(TIM_EncoderInitStruct->IC1Polarity);
  443. tmpccer |= (uint32_t)(TIM_EncoderInitStruct->IC2Polarity << 4U);
  444. tmpccer |= (uint32_t)(TIM_CCER_CC1E | TIM_CCER_CC2E);
  445. /* Set encoder mode */
  446. LL_TIM_SetEncoderMode(TIMx, TIM_EncoderInitStruct->EncoderMode);
  447. /* Write to TIMx CCMR1 */
  448. LL_TIM_WriteReg(TIMx, CCMR1, tmpccmr1);
  449. /* Write to TIMx CCER */
  450. LL_TIM_WriteReg(TIMx, CCER, tmpccer);
  451. return SUCCESS;
  452. }
  453. /**
  454. * @brief Set the fields of the TIMx Hall sensor interface configuration data
  455. * structure to their default values.
  456. * @param TIM_HallSensorInitStruct pointer to a @ref LL_TIM_HALLSENSOR_InitTypeDef structure (HALL sensor interface configuration data structure)
  457. * @retval None
  458. */
  459. void LL_TIM_HALLSENSOR_StructInit(LL_TIM_HALLSENSOR_InitTypeDef *TIM_HallSensorInitStruct)
  460. {
  461. /* Set the default configuration */
  462. TIM_HallSensorInitStruct->IC1Polarity = LL_TIM_IC_POLARITY_RISING;
  463. TIM_HallSensorInitStruct->IC1Prescaler = LL_TIM_ICPSC_DIV1;
  464. TIM_HallSensorInitStruct->IC1Filter = LL_TIM_IC_FILTER_FDIV1;
  465. TIM_HallSensorInitStruct->CommutationDelay = 0U;
  466. }
  467. /**
  468. * @brief Configure the Hall sensor interface of the timer instance.
  469. * @note TIMx CH1, CH2 and CH3 inputs connected through a XOR
  470. * to the TI1 input channel
  471. * @note TIMx slave mode controller is configured in reset mode.
  472. Selected internal trigger is TI1F_ED.
  473. * @note Channel 1 is configured as input, IC1 is mapped on TRC.
  474. * @note Captured value stored in TIMx_CCR1 correspond to the time elapsed
  475. * between 2 changes on the inputs. It gives information about motor speed.
  476. * @note Channel 2 is configured in output PWM 2 mode.
  477. * @note Compare value stored in TIMx_CCR2 corresponds to the commutation delay.
  478. * @note OC2REF is selected as trigger output on TRGO.
  479. * @note LL_TIM_IC_POLARITY_BOTHEDGE must not be used for TI1 when it is used
  480. * when TIMx operates in Hall sensor interface mode.
  481. * @param TIMx Timer Instance
  482. * @param TIM_HallSensorInitStruct pointer to a @ref LL_TIM_HALLSENSOR_InitTypeDef structure (TIMx HALL sensor interface configuration data structure)
  483. * @retval An ErrorStatus enumeration value:
  484. * - SUCCESS: TIMx registers are de-initialized
  485. * - ERROR: not applicable
  486. */
  487. ErrorStatus LL_TIM_HALLSENSOR_Init(TIM_TypeDef *TIMx, LL_TIM_HALLSENSOR_InitTypeDef *TIM_HallSensorInitStruct)
  488. {
  489. uint32_t tmpcr2;
  490. uint32_t tmpccmr1;
  491. uint32_t tmpccer;
  492. uint32_t tmpsmcr;
  493. /* Check the parameters */
  494. assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(TIMx));
  495. assert_param(IS_LL_TIM_IC_POLARITY_ENCODER(TIM_HallSensorInitStruct->IC1Polarity));
  496. assert_param(IS_LL_TIM_ICPSC(TIM_HallSensorInitStruct->IC1Prescaler));
  497. assert_param(IS_LL_TIM_IC_FILTER(TIM_HallSensorInitStruct->IC1Filter));
  498. /* Disable the CC1 and CC2: Reset the CC1E and CC2E Bits */
  499. TIMx->CCER &= (uint32_t)~(TIM_CCER_CC1E | TIM_CCER_CC2E);
  500. /* Get the TIMx CR2 register value */
  501. tmpcr2 = LL_TIM_ReadReg(TIMx, CR2);
  502. /* Get the TIMx CCMR1 register value */
  503. tmpccmr1 = LL_TIM_ReadReg(TIMx, CCMR1);
  504. /* Get the TIMx CCER register value */
  505. tmpccer = LL_TIM_ReadReg(TIMx, CCER);
  506. /* Get the TIMx SMCR register value */
  507. tmpsmcr = LL_TIM_ReadReg(TIMx, SMCR);
  508. /* Connect TIMx_CH1, CH2 and CH3 pins to the TI1 input */
  509. tmpcr2 |= TIM_CR2_TI1S;
  510. /* OC2REF signal is used as trigger output (TRGO) */
  511. tmpcr2 |= LL_TIM_TRGO_OC2REF;
  512. /* Configure the slave mode controller */
  513. tmpsmcr &= (uint32_t)~(TIM_SMCR_TS | TIM_SMCR_SMS);
  514. tmpsmcr |= LL_TIM_TS_TI1F_ED;
  515. tmpsmcr |= LL_TIM_SLAVEMODE_RESET;
  516. /* Configure input channel 1 */
  517. tmpccmr1 &= (uint32_t)~(TIM_CCMR1_CC1S | TIM_CCMR1_IC1F | TIM_CCMR1_IC1PSC);
  518. tmpccmr1 |= (uint32_t)(LL_TIM_ACTIVEINPUT_TRC >> 16U);
  519. tmpccmr1 |= (uint32_t)(TIM_HallSensorInitStruct->IC1Filter >> 16U);
  520. tmpccmr1 |= (uint32_t)(TIM_HallSensorInitStruct->IC1Prescaler >> 16U);
  521. /* Configure input channel 2 */
  522. tmpccmr1 &= (uint32_t)~(TIM_CCMR1_OC2M | TIM_CCMR1_OC2FE | TIM_CCMR1_OC2PE | TIM_CCMR1_OC2CE);
  523. tmpccmr1 |= (uint32_t)(LL_TIM_OCMODE_PWM2 << 8U);
  524. /* Set Channel 1 polarity and enable Channel 1 and Channel2 */
  525. tmpccer &= (uint32_t)~(TIM_CCER_CC1P | TIM_CCER_CC1NP | TIM_CCER_CC2P | TIM_CCER_CC2NP);
  526. tmpccer |= (uint32_t)(TIM_HallSensorInitStruct->IC1Polarity);
  527. tmpccer |= (uint32_t)(TIM_CCER_CC1E | TIM_CCER_CC2E);
  528. /* Write to TIMx CR2 */
  529. LL_TIM_WriteReg(TIMx, CR2, tmpcr2);
  530. /* Write to TIMx SMCR */
  531. LL_TIM_WriteReg(TIMx, SMCR, tmpsmcr);
  532. /* Write to TIMx CCMR1 */
  533. LL_TIM_WriteReg(TIMx, CCMR1, tmpccmr1);
  534. /* Write to TIMx CCER */
  535. LL_TIM_WriteReg(TIMx, CCER, tmpccer);
  536. /* Write to TIMx CCR2 */
  537. LL_TIM_OC_SetCompareCH2(TIMx, TIM_HallSensorInitStruct->CommutationDelay);
  538. return SUCCESS;
  539. }
  540. /**
  541. * @brief Set the fields of the Break and Dead Time configuration data structure
  542. * to their default values.
  543. * @param TIM_BDTRInitStruct pointer to a @ref LL_TIM_BDTR_InitTypeDef structure (Break and Dead Time configuration data structure)
  544. * @retval None
  545. */
  546. void LL_TIM_BDTR_StructInit(LL_TIM_BDTR_InitTypeDef *TIM_BDTRInitStruct)
  547. {
  548. /* Set the default configuration */
  549. TIM_BDTRInitStruct->OSSRState = LL_TIM_OSSR_DISABLE;
  550. TIM_BDTRInitStruct->OSSIState = LL_TIM_OSSI_DISABLE;
  551. TIM_BDTRInitStruct->LockLevel = LL_TIM_LOCKLEVEL_OFF;
  552. TIM_BDTRInitStruct->DeadTime = (uint8_t)0x00;
  553. TIM_BDTRInitStruct->BreakState = LL_TIM_BREAK_DISABLE;
  554. TIM_BDTRInitStruct->BreakPolarity = LL_TIM_BREAK_POLARITY_LOW;
  555. TIM_BDTRInitStruct->BreakFilter = LL_TIM_BREAK_FILTER_FDIV1;
  556. TIM_BDTRInitStruct->Break2State = LL_TIM_BREAK2_DISABLE;
  557. TIM_BDTRInitStruct->Break2Polarity = LL_TIM_BREAK2_POLARITY_LOW;
  558. TIM_BDTRInitStruct->Break2Filter = LL_TIM_BREAK2_FILTER_FDIV1;
  559. TIM_BDTRInitStruct->AutomaticOutput = LL_TIM_AUTOMATICOUTPUT_DISABLE;
  560. }
  561. /**
  562. * @brief Configure the Break and Dead Time feature of the timer instance.
  563. * @note As the bits BK2P, BK2E, BK2F[3:0], BKF[3:0], AOE, BKP, BKE, OSSI, OSSR
  564. * and DTG[7:0] can be write-locked depending on the LOCK configuration, it
  565. * can be necessary to configure all of them during the first write access to
  566. * the TIMx_BDTR register.
  567. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  568. * a timer instance provides a break input.
  569. * @note Macro IS_TIM_BKIN2_INSTANCE(TIMx) can be used to check whether or not
  570. * a timer instance provides a second break input.
  571. * @param TIMx Timer Instance
  572. * @param TIM_BDTRInitStruct pointer to a @ref LL_TIM_BDTR_InitTypeDef structure (Break and Dead Time configuration data structure)
  573. * @retval An ErrorStatus enumeration value:
  574. * - SUCCESS: Break and Dead Time is initialized
  575. * - ERROR: not applicable
  576. */
  577. ErrorStatus LL_TIM_BDTR_Init(TIM_TypeDef *TIMx, LL_TIM_BDTR_InitTypeDef *TIM_BDTRInitStruct)
  578. {
  579. uint32_t tmpbdtr = 0;
  580. /* Check the parameters */
  581. assert_param(IS_TIM_BREAK_INSTANCE(TIMx));
  582. assert_param(IS_LL_TIM_OSSR_STATE(TIM_BDTRInitStruct->OSSRState));
  583. assert_param(IS_LL_TIM_OSSI_STATE(TIM_BDTRInitStruct->OSSIState));
  584. assert_param(IS_LL_TIM_LOCK_LEVEL(TIM_BDTRInitStruct->LockLevel));
  585. assert_param(IS_LL_TIM_BREAK_STATE(TIM_BDTRInitStruct->BreakState));
  586. assert_param(IS_LL_TIM_BREAK_POLARITY(TIM_BDTRInitStruct->BreakPolarity));
  587. assert_param(IS_LL_TIM_AUTOMATIC_OUTPUT_STATE(TIM_BDTRInitStruct->AutomaticOutput));
  588. /* Set the Lock level, the Break enable Bit and the Polarity, the OSSR State,
  589. the OSSI State, the dead time value and the Automatic Output Enable Bit */
  590. /* Set the BDTR bits */
  591. MODIFY_REG(tmpbdtr, TIM_BDTR_DTG, TIM_BDTRInitStruct->DeadTime);
  592. MODIFY_REG(tmpbdtr, TIM_BDTR_LOCK, TIM_BDTRInitStruct->LockLevel);
  593. MODIFY_REG(tmpbdtr, TIM_BDTR_OSSI, TIM_BDTRInitStruct->OSSIState);
  594. MODIFY_REG(tmpbdtr, TIM_BDTR_OSSR, TIM_BDTRInitStruct->OSSRState);
  595. MODIFY_REG(tmpbdtr, TIM_BDTR_BKE, TIM_BDTRInitStruct->BreakState);
  596. MODIFY_REG(tmpbdtr, TIM_BDTR_BKP, TIM_BDTRInitStruct->BreakPolarity);
  597. MODIFY_REG(tmpbdtr, TIM_BDTR_AOE, TIM_BDTRInitStruct->AutomaticOutput);
  598. MODIFY_REG(tmpbdtr, TIM_BDTR_MOE, TIM_BDTRInitStruct->AutomaticOutput);
  599. if (IS_TIM_ADVANCED_INSTANCE(TIMx))
  600. {
  601. assert_param(IS_LL_TIM_BREAK_FILTER(TIM_BDTRInitStruct->BreakFilter));
  602. MODIFY_REG(tmpbdtr, TIM_BDTR_BKF, TIM_BDTRInitStruct->BreakFilter);
  603. }
  604. if (IS_TIM_BKIN2_INSTANCE(TIMx))
  605. {
  606. assert_param(IS_LL_TIM_BREAK2_STATE(TIM_BDTRInitStruct->Break2State));
  607. assert_param(IS_LL_TIM_BREAK2_POLARITY(TIM_BDTRInitStruct->Break2Polarity));
  608. assert_param(IS_LL_TIM_BREAK2_FILTER(TIM_BDTRInitStruct->Break2Filter));
  609. /* Set the BREAK2 input related BDTR bit-fields */
  610. MODIFY_REG(tmpbdtr, TIM_BDTR_BK2F, (TIM_BDTRInitStruct->Break2Filter));
  611. MODIFY_REG(tmpbdtr, TIM_BDTR_BK2E, TIM_BDTRInitStruct->Break2State);
  612. MODIFY_REG(tmpbdtr, TIM_BDTR_BK2P, TIM_BDTRInitStruct->Break2Polarity);
  613. }
  614. /* Set TIMx_BDTR */
  615. LL_TIM_WriteReg(TIMx, BDTR, tmpbdtr);
  616. return SUCCESS;
  617. }
  618. /**
  619. * @}
  620. */
  621. /**
  622. * @}
  623. */
  624. /** @addtogroup TIM_LL_Private_Functions TIM Private Functions
  625. * @brief Private functions
  626. * @{
  627. */
  628. /**
  629. * @brief Configure the TIMx output channel 1.
  630. * @param TIMx Timer Instance
  631. * @param TIM_OCInitStruct pointer to the the TIMx output channel 1 configuration data structure
  632. * @retval An ErrorStatus enumeration value:
  633. * - SUCCESS: TIMx registers are de-initialized
  634. * - ERROR: not applicable
  635. */
  636. static ErrorStatus OC1Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct)
  637. {
  638. uint32_t tmpccmr1;
  639. uint32_t tmpccer;
  640. uint32_t tmpcr2;
  641. /* Check the parameters */
  642. assert_param(IS_TIM_CC1_INSTANCE(TIMx));
  643. assert_param(IS_LL_TIM_OCMODE(TIM_OCInitStruct->OCMode));
  644. assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCState));
  645. assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCPolarity));
  646. assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCNState));
  647. assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCNPolarity));
  648. /* Disable the Channel 1: Reset the CC1E Bit */
  649. CLEAR_BIT(TIMx->CCER, TIM_CCER_CC1E);
  650. /* Get the TIMx CCER register value */
  651. tmpccer = LL_TIM_ReadReg(TIMx, CCER);
  652. /* Get the TIMx CR2 register value */
  653. tmpcr2 = LL_TIM_ReadReg(TIMx, CR2);
  654. /* Get the TIMx CCMR1 register value */
  655. tmpccmr1 = LL_TIM_ReadReg(TIMx, CCMR1);
  656. /* Reset Capture/Compare selection Bits */
  657. CLEAR_BIT(tmpccmr1, TIM_CCMR1_CC1S);
  658. /* Set the Output Compare Mode */
  659. MODIFY_REG(tmpccmr1, TIM_CCMR1_OC1M, TIM_OCInitStruct->OCMode);
  660. /* Set the Output Compare Polarity */
  661. MODIFY_REG(tmpccer, TIM_CCER_CC1P, TIM_OCInitStruct->OCPolarity);
  662. /* Set the Output State */
  663. MODIFY_REG(tmpccer, TIM_CCER_CC1E, TIM_OCInitStruct->OCState);
  664. if (IS_TIM_BREAK_INSTANCE(TIMx))
  665. {
  666. assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCNIdleState));
  667. assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCIdleState));
  668. /* Set the complementary output Polarity */
  669. MODIFY_REG(tmpccer, TIM_CCER_CC1NP, TIM_OCInitStruct->OCNPolarity << 2U);
  670. /* Set the complementary output State */
  671. MODIFY_REG(tmpccer, TIM_CCER_CC1NE, TIM_OCInitStruct->OCNState << 2U);
  672. /* Set the Output Idle state */
  673. MODIFY_REG(tmpcr2, TIM_CR2_OIS1, TIM_OCInitStruct->OCIdleState);
  674. /* Set the complementary output Idle state */
  675. MODIFY_REG(tmpcr2, TIM_CR2_OIS1N, TIM_OCInitStruct->OCNIdleState << 1U);
  676. }
  677. /* Write to TIMx CR2 */
  678. LL_TIM_WriteReg(TIMx, CR2, tmpcr2);
  679. /* Write to TIMx CCMR1 */
  680. LL_TIM_WriteReg(TIMx, CCMR1, tmpccmr1);
  681. /* Set the Capture Compare Register value */
  682. LL_TIM_OC_SetCompareCH1(TIMx, TIM_OCInitStruct->CompareValue);
  683. /* Write to TIMx CCER */
  684. LL_TIM_WriteReg(TIMx, CCER, tmpccer);
  685. return SUCCESS;
  686. }
  687. /**
  688. * @brief Configure the TIMx output channel 2.
  689. * @param TIMx Timer Instance
  690. * @param TIM_OCInitStruct pointer to the the TIMx output channel 2 configuration data structure
  691. * @retval An ErrorStatus enumeration value:
  692. * - SUCCESS: TIMx registers are de-initialized
  693. * - ERROR: not applicable
  694. */
  695. static ErrorStatus OC2Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct)
  696. {
  697. uint32_t tmpccmr1;
  698. uint32_t tmpccer;
  699. uint32_t tmpcr2;
  700. /* Check the parameters */
  701. assert_param(IS_TIM_CC2_INSTANCE(TIMx));
  702. assert_param(IS_LL_TIM_OCMODE(TIM_OCInitStruct->OCMode));
  703. assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCState));
  704. assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCPolarity));
  705. assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCNState));
  706. assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCNPolarity));
  707. /* Disable the Channel 2: Reset the CC2E Bit */
  708. CLEAR_BIT(TIMx->CCER, TIM_CCER_CC2E);
  709. /* Get the TIMx CCER register value */
  710. tmpccer = LL_TIM_ReadReg(TIMx, CCER);
  711. /* Get the TIMx CR2 register value */
  712. tmpcr2 = LL_TIM_ReadReg(TIMx, CR2);
  713. /* Get the TIMx CCMR1 register value */
  714. tmpccmr1 = LL_TIM_ReadReg(TIMx, CCMR1);
  715. /* Reset Capture/Compare selection Bits */
  716. CLEAR_BIT(tmpccmr1, TIM_CCMR1_CC2S);
  717. /* Select the Output Compare Mode */
  718. MODIFY_REG(tmpccmr1, TIM_CCMR1_OC2M, TIM_OCInitStruct->OCMode << 8U);
  719. /* Set the Output Compare Polarity */
  720. MODIFY_REG(tmpccer, TIM_CCER_CC2P, TIM_OCInitStruct->OCPolarity << 4U);
  721. /* Set the Output State */
  722. MODIFY_REG(tmpccer, TIM_CCER_CC2E, TIM_OCInitStruct->OCState << 4U);
  723. if (IS_TIM_BREAK_INSTANCE(TIMx))
  724. {
  725. assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCNIdleState));
  726. assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCIdleState));
  727. /* Set the complementary output Polarity */
  728. MODIFY_REG(tmpccer, TIM_CCER_CC2NP, TIM_OCInitStruct->OCNPolarity << 6U);
  729. /* Set the complementary output State */
  730. MODIFY_REG(tmpccer, TIM_CCER_CC2NE, TIM_OCInitStruct->OCNState << 6U);
  731. /* Set the Output Idle state */
  732. MODIFY_REG(tmpcr2, TIM_CR2_OIS2, TIM_OCInitStruct->OCIdleState << 2U);
  733. /* Set the complementary output Idle state */
  734. MODIFY_REG(tmpcr2, TIM_CR2_OIS2N, TIM_OCInitStruct->OCNIdleState << 3U);
  735. }
  736. /* Write to TIMx CR2 */
  737. LL_TIM_WriteReg(TIMx, CR2, tmpcr2);
  738. /* Write to TIMx CCMR1 */
  739. LL_TIM_WriteReg(TIMx, CCMR1, tmpccmr1);
  740. /* Set the Capture Compare Register value */
  741. LL_TIM_OC_SetCompareCH2(TIMx, TIM_OCInitStruct->CompareValue);
  742. /* Write to TIMx CCER */
  743. LL_TIM_WriteReg(TIMx, CCER, tmpccer);
  744. return SUCCESS;
  745. }
  746. /**
  747. * @brief Configure the TIMx output channel 3.
  748. * @param TIMx Timer Instance
  749. * @param TIM_OCInitStruct pointer to the the TIMx output channel 3 configuration data structure
  750. * @retval An ErrorStatus enumeration value:
  751. * - SUCCESS: TIMx registers are de-initialized
  752. * - ERROR: not applicable
  753. */
  754. static ErrorStatus OC3Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct)
  755. {
  756. uint32_t tmpccmr2;
  757. uint32_t tmpccer;
  758. uint32_t tmpcr2;
  759. /* Check the parameters */
  760. assert_param(IS_TIM_CC3_INSTANCE(TIMx));
  761. assert_param(IS_LL_TIM_OCMODE(TIM_OCInitStruct->OCMode));
  762. assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCState));
  763. assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCPolarity));
  764. assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCNState));
  765. assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCNPolarity));
  766. /* Disable the Channel 3: Reset the CC3E Bit */
  767. CLEAR_BIT(TIMx->CCER, TIM_CCER_CC3E);
  768. /* Get the TIMx CCER register value */
  769. tmpccer = LL_TIM_ReadReg(TIMx, CCER);
  770. /* Get the TIMx CR2 register value */
  771. tmpcr2 = LL_TIM_ReadReg(TIMx, CR2);
  772. /* Get the TIMx CCMR2 register value */
  773. tmpccmr2 = LL_TIM_ReadReg(TIMx, CCMR2);
  774. /* Reset Capture/Compare selection Bits */
  775. CLEAR_BIT(tmpccmr2, TIM_CCMR2_CC3S);
  776. /* Select the Output Compare Mode */
  777. MODIFY_REG(tmpccmr2, TIM_CCMR2_OC3M, TIM_OCInitStruct->OCMode);
  778. /* Set the Output Compare Polarity */
  779. MODIFY_REG(tmpccer, TIM_CCER_CC3P, TIM_OCInitStruct->OCPolarity << 8U);
  780. /* Set the Output State */
  781. MODIFY_REG(tmpccer, TIM_CCER_CC3E, TIM_OCInitStruct->OCState << 8U);
  782. if (IS_TIM_BREAK_INSTANCE(TIMx))
  783. {
  784. assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCNIdleState));
  785. assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCIdleState));
  786. /* Set the complementary output Polarity */
  787. MODIFY_REG(tmpccer, TIM_CCER_CC3NP, TIM_OCInitStruct->OCNPolarity << 10U);
  788. /* Set the complementary output State */
  789. MODIFY_REG(tmpccer, TIM_CCER_CC3NE, TIM_OCInitStruct->OCNState << 10U);
  790. /* Set the Output Idle state */
  791. MODIFY_REG(tmpcr2, TIM_CR2_OIS3, TIM_OCInitStruct->OCIdleState << 4U);
  792. /* Set the complementary output Idle state */
  793. MODIFY_REG(tmpcr2, TIM_CR2_OIS3N, TIM_OCInitStruct->OCNIdleState << 5U);
  794. }
  795. /* Write to TIMx CR2 */
  796. LL_TIM_WriteReg(TIMx, CR2, tmpcr2);
  797. /* Write to TIMx CCMR2 */
  798. LL_TIM_WriteReg(TIMx, CCMR2, tmpccmr2);
  799. /* Set the Capture Compare Register value */
  800. LL_TIM_OC_SetCompareCH3(TIMx, TIM_OCInitStruct->CompareValue);
  801. /* Write to TIMx CCER */
  802. LL_TIM_WriteReg(TIMx, CCER, tmpccer);
  803. return SUCCESS;
  804. }
  805. /**
  806. * @brief Configure the TIMx output channel 4.
  807. * @param TIMx Timer Instance
  808. * @param TIM_OCInitStruct pointer to the the TIMx output channel 4 configuration data structure
  809. * @retval An ErrorStatus enumeration value:
  810. * - SUCCESS: TIMx registers are de-initialized
  811. * - ERROR: not applicable
  812. */
  813. static ErrorStatus OC4Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct)
  814. {
  815. uint32_t tmpccmr2;
  816. uint32_t tmpccer;
  817. uint32_t tmpcr2;
  818. /* Check the parameters */
  819. assert_param(IS_TIM_CC4_INSTANCE(TIMx));
  820. assert_param(IS_LL_TIM_OCMODE(TIM_OCInitStruct->OCMode));
  821. assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCState));
  822. assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCPolarity));
  823. assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCNPolarity));
  824. assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCNState));
  825. /* Disable the Channel 4: Reset the CC4E Bit */
  826. CLEAR_BIT(TIMx->CCER, TIM_CCER_CC4E);
  827. /* Get the TIMx CCER register value */
  828. tmpccer = LL_TIM_ReadReg(TIMx, CCER);
  829. /* Get the TIMx CR2 register value */
  830. tmpcr2 = LL_TIM_ReadReg(TIMx, CR2);
  831. /* Get the TIMx CCMR2 register value */
  832. tmpccmr2 = LL_TIM_ReadReg(TIMx, CCMR2);
  833. /* Reset Capture/Compare selection Bits */
  834. CLEAR_BIT(tmpccmr2, TIM_CCMR2_CC4S);
  835. /* Select the Output Compare Mode */
  836. MODIFY_REG(tmpccmr2, TIM_CCMR2_OC4M, TIM_OCInitStruct->OCMode << 8U);
  837. /* Set the Output Compare Polarity */
  838. MODIFY_REG(tmpccer, TIM_CCER_CC4P, TIM_OCInitStruct->OCPolarity << 12U);
  839. /* Set the Output State */
  840. MODIFY_REG(tmpccer, TIM_CCER_CC4E, TIM_OCInitStruct->OCState << 12U);
  841. if (IS_TIM_BREAK_INSTANCE(TIMx))
  842. {
  843. assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCNIdleState));
  844. assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCIdleState));
  845. /* Set the Output Idle state */
  846. MODIFY_REG(tmpcr2, TIM_CR2_OIS4, TIM_OCInitStruct->OCIdleState << 6U);
  847. }
  848. /* Write to TIMx CR2 */
  849. LL_TIM_WriteReg(TIMx, CR2, tmpcr2);
  850. /* Write to TIMx CCMR2 */
  851. LL_TIM_WriteReg(TIMx, CCMR2, tmpccmr2);
  852. /* Set the Capture Compare Register value */
  853. LL_TIM_OC_SetCompareCH4(TIMx, TIM_OCInitStruct->CompareValue);
  854. /* Write to TIMx CCER */
  855. LL_TIM_WriteReg(TIMx, CCER, tmpccer);
  856. return SUCCESS;
  857. }
  858. /**
  859. * @brief Configure the TIMx output channel 5.
  860. * @param TIMx Timer Instance
  861. * @param TIM_OCInitStruct pointer to the the TIMx output channel 5 configuration data structure
  862. * @retval An ErrorStatus enumeration value:
  863. * - SUCCESS: TIMx registers are de-initialized
  864. * - ERROR: not applicable
  865. */
  866. static ErrorStatus OC5Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct)
  867. {
  868. uint32_t tmpccmr3;
  869. uint32_t tmpccer;
  870. /* Check the parameters */
  871. assert_param(IS_TIM_CC5_INSTANCE(TIMx));
  872. assert_param(IS_LL_TIM_OCMODE(TIM_OCInitStruct->OCMode));
  873. assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCState));
  874. assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCPolarity));
  875. assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCNPolarity));
  876. assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCNState));
  877. /* Disable the Channel 5: Reset the CC5E Bit */
  878. CLEAR_BIT(TIMx->CCER, TIM_CCER_CC5E);
  879. /* Get the TIMx CCER register value */
  880. tmpccer = LL_TIM_ReadReg(TIMx, CCER);
  881. /* Get the TIMx CCMR3 register value */
  882. tmpccmr3 = LL_TIM_ReadReg(TIMx, CCMR3);
  883. /* Select the Output Compare Mode */
  884. MODIFY_REG(tmpccmr3, TIM_CCMR3_OC5M, TIM_OCInitStruct->OCMode);
  885. /* Set the Output Compare Polarity */
  886. MODIFY_REG(tmpccer, TIM_CCER_CC5P, TIM_OCInitStruct->OCPolarity << 16U);
  887. /* Set the Output State */
  888. MODIFY_REG(tmpccer, TIM_CCER_CC5E, TIM_OCInitStruct->OCState << 16U);
  889. if (IS_TIM_BREAK_INSTANCE(TIMx))
  890. {
  891. assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCNIdleState));
  892. assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCIdleState));
  893. /* Set the Output Idle state */
  894. MODIFY_REG(TIMx->CR2, TIM_CR2_OIS5, TIM_OCInitStruct->OCIdleState << 8U);
  895. }
  896. /* Write to TIMx CCMR3 */
  897. LL_TIM_WriteReg(TIMx, CCMR3, tmpccmr3);
  898. /* Set the Capture Compare Register value */
  899. LL_TIM_OC_SetCompareCH5(TIMx, TIM_OCInitStruct->CompareValue);
  900. /* Write to TIMx CCER */
  901. LL_TIM_WriteReg(TIMx, CCER, tmpccer);
  902. return SUCCESS;
  903. }
  904. /**
  905. * @brief Configure the TIMx output channel 6.
  906. * @param TIMx Timer Instance
  907. * @param TIM_OCInitStruct pointer to the the TIMx output channel 6 configuration data structure
  908. * @retval An ErrorStatus enumeration value:
  909. * - SUCCESS: TIMx registers are de-initialized
  910. * - ERROR: not applicable
  911. */
  912. static ErrorStatus OC6Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct)
  913. {
  914. uint32_t tmpccmr3;
  915. uint32_t tmpccer;
  916. /* Check the parameters */
  917. assert_param(IS_TIM_CC6_INSTANCE(TIMx));
  918. assert_param(IS_LL_TIM_OCMODE(TIM_OCInitStruct->OCMode));
  919. assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCState));
  920. assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCPolarity));
  921. assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCNPolarity));
  922. assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCNState));
  923. /* Disable the Channel 5: Reset the CC6E Bit */
  924. CLEAR_BIT(TIMx->CCER, TIM_CCER_CC6E);
  925. /* Get the TIMx CCER register value */
  926. tmpccer = LL_TIM_ReadReg(TIMx, CCER);
  927. /* Get the TIMx CCMR3 register value */
  928. tmpccmr3 = LL_TIM_ReadReg(TIMx, CCMR3);
  929. /* Select the Output Compare Mode */
  930. MODIFY_REG(tmpccmr3, TIM_CCMR3_OC6M, TIM_OCInitStruct->OCMode << 8U);
  931. /* Set the Output Compare Polarity */
  932. MODIFY_REG(tmpccer, TIM_CCER_CC6P, TIM_OCInitStruct->OCPolarity << 20U);
  933. /* Set the Output State */
  934. MODIFY_REG(tmpccer, TIM_CCER_CC6E, TIM_OCInitStruct->OCState << 20U);
  935. if (IS_TIM_BREAK_INSTANCE(TIMx))
  936. {
  937. assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCNIdleState));
  938. assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCIdleState));
  939. /* Set the Output Idle state */
  940. MODIFY_REG(TIMx->CR2, TIM_CR2_OIS6, TIM_OCInitStruct->OCIdleState << 10U);
  941. }
  942. /* Write to TIMx CCMR3 */
  943. LL_TIM_WriteReg(TIMx, CCMR3, tmpccmr3);
  944. /* Set the Capture Compare Register value */
  945. LL_TIM_OC_SetCompareCH6(TIMx, TIM_OCInitStruct->CompareValue);
  946. /* Write to TIMx CCER */
  947. LL_TIM_WriteReg(TIMx, CCER, tmpccer);
  948. return SUCCESS;
  949. }
  950. /**
  951. * @brief Configure the TIMx input channel 1.
  952. * @param TIMx Timer Instance
  953. * @param TIM_ICInitStruct pointer to the the TIMx input channel 1 configuration data structure
  954. * @retval An ErrorStatus enumeration value:
  955. * - SUCCESS: TIMx registers are de-initialized
  956. * - ERROR: not applicable
  957. */
  958. static ErrorStatus IC1Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct)
  959. {
  960. /* Check the parameters */
  961. assert_param(IS_TIM_CC1_INSTANCE(TIMx));
  962. assert_param(IS_LL_TIM_IC_POLARITY(TIM_ICInitStruct->ICPolarity));
  963. assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_ICInitStruct->ICActiveInput));
  964. assert_param(IS_LL_TIM_ICPSC(TIM_ICInitStruct->ICPrescaler));
  965. assert_param(IS_LL_TIM_IC_FILTER(TIM_ICInitStruct->ICFilter));
  966. /* Disable the Channel 1: Reset the CC1E Bit */
  967. TIMx->CCER &= (uint32_t)~TIM_CCER_CC1E;
  968. /* Select the Input and set the filter and the prescaler value */
  969. MODIFY_REG(TIMx->CCMR1,
  970. (TIM_CCMR1_CC1S | TIM_CCMR1_IC1F | TIM_CCMR1_IC1PSC),
  971. (TIM_ICInitStruct->ICActiveInput | TIM_ICInitStruct->ICFilter | TIM_ICInitStruct->ICPrescaler) >> 16U);
  972. /* Select the Polarity and set the CC1E Bit */
  973. MODIFY_REG(TIMx->CCER,
  974. (TIM_CCER_CC1P | TIM_CCER_CC1NP),
  975. (TIM_ICInitStruct->ICPolarity | TIM_CCER_CC1E));
  976. return SUCCESS;
  977. }
  978. /**
  979. * @brief Configure the TIMx input channel 2.
  980. * @param TIMx Timer Instance
  981. * @param TIM_ICInitStruct pointer to the the TIMx input channel 2 configuration data structure
  982. * @retval An ErrorStatus enumeration value:
  983. * - SUCCESS: TIMx registers are de-initialized
  984. * - ERROR: not applicable
  985. */
  986. static ErrorStatus IC2Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct)
  987. {
  988. /* Check the parameters */
  989. assert_param(IS_TIM_CC2_INSTANCE(TIMx));
  990. assert_param(IS_LL_TIM_IC_POLARITY(TIM_ICInitStruct->ICPolarity));
  991. assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_ICInitStruct->ICActiveInput));
  992. assert_param(IS_LL_TIM_ICPSC(TIM_ICInitStruct->ICPrescaler));
  993. assert_param(IS_LL_TIM_IC_FILTER(TIM_ICInitStruct->ICFilter));
  994. /* Disable the Channel 2: Reset the CC2E Bit */
  995. TIMx->CCER &= (uint32_t)~TIM_CCER_CC2E;
  996. /* Select the Input and set the filter and the prescaler value */
  997. MODIFY_REG(TIMx->CCMR1,
  998. (TIM_CCMR1_CC2S | TIM_CCMR1_IC2F | TIM_CCMR1_IC2PSC),
  999. (TIM_ICInitStruct->ICActiveInput | TIM_ICInitStruct->ICFilter | TIM_ICInitStruct->ICPrescaler) >> 8U);
  1000. /* Select the Polarity and set the CC2E Bit */
  1001. MODIFY_REG(TIMx->CCER,
  1002. (TIM_CCER_CC2P | TIM_CCER_CC2NP),
  1003. ((TIM_ICInitStruct->ICPolarity << 4U) | TIM_CCER_CC2E));
  1004. return SUCCESS;
  1005. }
  1006. /**
  1007. * @brief Configure the TIMx input channel 3.
  1008. * @param TIMx Timer Instance
  1009. * @param TIM_ICInitStruct pointer to the the TIMx input channel 3 configuration data structure
  1010. * @retval An ErrorStatus enumeration value:
  1011. * - SUCCESS: TIMx registers are de-initialized
  1012. * - ERROR: not applicable
  1013. */
  1014. static ErrorStatus IC3Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct)
  1015. {
  1016. /* Check the parameters */
  1017. assert_param(IS_TIM_CC3_INSTANCE(TIMx));
  1018. assert_param(IS_LL_TIM_IC_POLARITY(TIM_ICInitStruct->ICPolarity));
  1019. assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_ICInitStruct->ICActiveInput));
  1020. assert_param(IS_LL_TIM_ICPSC(TIM_ICInitStruct->ICPrescaler));
  1021. assert_param(IS_LL_TIM_IC_FILTER(TIM_ICInitStruct->ICFilter));
  1022. /* Disable the Channel 3: Reset the CC3E Bit */
  1023. TIMx->CCER &= (uint32_t)~TIM_CCER_CC3E;
  1024. /* Select the Input and set the filter and the prescaler value */
  1025. MODIFY_REG(TIMx->CCMR2,
  1026. (TIM_CCMR2_CC3S | TIM_CCMR2_IC3F | TIM_CCMR2_IC3PSC),
  1027. (TIM_ICInitStruct->ICActiveInput | TIM_ICInitStruct->ICFilter | TIM_ICInitStruct->ICPrescaler) >> 16U);
  1028. /* Select the Polarity and set the CC3E Bit */
  1029. MODIFY_REG(TIMx->CCER,
  1030. (TIM_CCER_CC3P | TIM_CCER_CC3NP),
  1031. ((TIM_ICInitStruct->ICPolarity << 8U) | TIM_CCER_CC3E));
  1032. return SUCCESS;
  1033. }
  1034. /**
  1035. * @brief Configure the TIMx input channel 4.
  1036. * @param TIMx Timer Instance
  1037. * @param TIM_ICInitStruct pointer to the the TIMx input channel 4 configuration data structure
  1038. * @retval An ErrorStatus enumeration value:
  1039. * - SUCCESS: TIMx registers are de-initialized
  1040. * - ERROR: not applicable
  1041. */
  1042. static ErrorStatus IC4Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct)
  1043. {
  1044. /* Check the parameters */
  1045. assert_param(IS_TIM_CC4_INSTANCE(TIMx));
  1046. assert_param(IS_LL_TIM_IC_POLARITY(TIM_ICInitStruct->ICPolarity));
  1047. assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_ICInitStruct->ICActiveInput));
  1048. assert_param(IS_LL_TIM_ICPSC(TIM_ICInitStruct->ICPrescaler));
  1049. assert_param(IS_LL_TIM_IC_FILTER(TIM_ICInitStruct->ICFilter));
  1050. /* Disable the Channel 4: Reset the CC4E Bit */
  1051. TIMx->CCER &= (uint32_t)~TIM_CCER_CC4E;
  1052. /* Select the Input and set the filter and the prescaler value */
  1053. MODIFY_REG(TIMx->CCMR2,
  1054. (TIM_CCMR2_CC4S | TIM_CCMR2_IC4F | TIM_CCMR2_IC4PSC),
  1055. (TIM_ICInitStruct->ICActiveInput | TIM_ICInitStruct->ICFilter | TIM_ICInitStruct->ICPrescaler) >> 8U);
  1056. /* Select the Polarity and set the CC2E Bit */
  1057. MODIFY_REG(TIMx->CCER,
  1058. (TIM_CCER_CC4P | TIM_CCER_CC4NP),
  1059. ((TIM_ICInitStruct->ICPolarity << 12U) | TIM_CCER_CC4E));
  1060. return SUCCESS;
  1061. }
  1062. /**
  1063. * @}
  1064. */
  1065. /**
  1066. * @}
  1067. */
  1068. #endif /* TIM1 || TIM2 || TIM16 || TIM17 */
  1069. /**
  1070. * @}
  1071. */
  1072. #endif /* USE_FULL_LL_DRIVER */
  1073. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/