123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980 |
- /**
- ******************************************************************************
- * @file py32f002b_hal_lptim.c
- * @author MCU Application Team
- * @brief LPTIM HAL module driver.
- * This file provides firmware functions to manage the following
- * functionalities of the Low Power Timer (LPTIM) peripheral:
- * + Initialization and de-initialization functions.
- * + Start/Stop operation functions in polling mode.
- * + Start/Stop operation functions in interrupt mode.
- * + Reading operation functions.
- * + Peripheral State functions.
- *
- @verbatim
- ==============================================================================
- ##### How to use this driver #####
- ==============================================================================
- [..]
- The LPTIM HAL driver can be used as follows:
- (#)Initialize the LPTIM low level resources by implementing the
- HAL_LPTIM_MspInit():
- (++) Enable the LPTIM interface clock using __HAL_RCC_LPTIMx_CLK_ENABLE().
- (++) In case of using interrupts (e.g. HAL_LPTIM_PWM_Start_IT()):
- (+++) Configure the LPTIM interrupt priority using HAL_NVIC_SetPriority().
- (+++) Enable the LPTIM IRQ handler using HAL_NVIC_EnableIRQ().
- (+++) In LPTIM IRQ handler, call HAL_LPTIM_IRQHandler().
- (#)Initialize the LPTIM HAL using HAL_LPTIM_Init(). This function
- configures mainly:
- (++) The instance: LPTIM1 or LPTIM2.
- (++) Clock: the counter clock.
- (+++) Source : it can be either the ULPTIM input (IN1) or one of
- the internal clock; (APB, LSE, LSI or HSI).
- (+++) Prescaler: select the clock divider.
- (#)Six modes are available:
- (++) PWM Mode: To generate a PWM signal with specified period and pulse,
- call HAL_LPTIM_PWM_Start() or HAL_LPTIM_PWM_Start_IT() for interruption
- mode.
- (++) One Pulse Mode: To generate pulse with specified width in response
- to a stimulus, call HAL_LPTIM_OnePulse_Start() or
- HAL_LPTIM_OnePulse_Start_IT() for interruption mode.
- (++) Set once Mode: In this mode, the output changes the level (from
- low level to high level if the output polarity is configured high, else
- the opposite) when a compare match occurs. To start this mode, call
- HAL_LPTIM_SetOnce_Start() or HAL_LPTIM_SetOnce_Start_IT() for
- interruption mode.
- (++) Encoder Mode: To use the encoder interface call
- HAL_LPTIM_Encoder_Start() or HAL_LPTIM_Encoder_Start_IT() for
- interruption mode. Only available for LPTIM1 instance.
- (++) Time out Mode: an active edge on one selected trigger input rests
- the counter. The first trigger event will start the timer, any
- successive trigger event will reset the counter and the timer will
- restart. To start this mode call HAL_LPTIM_TimeOut_Start_IT() or
- HAL_LPTIM_TimeOut_Start_IT() for interruption mode.
- (++) Counter Mode: counter can be used to count external events on
- the LPTIM Input1 or it can be used to count internal clock cycles.
- To start this mode, call HAL_LPTIM_Counter_Start() or
- HAL_LPTIM_Counter_Start_IT() for interruption mode.
- (#) User can stop any process by calling the corresponding API:
- HAL_LPTIM_Xxx_Stop() or HAL_LPTIM_Xxx_Stop_IT() if the process is
- already started in interruption mode.
- (#) De-initialize the LPTIM peripheral using HAL_LPTIM_DeInit().
- *** Callback registration ***
- =============================================
- [..]
- The compilation define USE_HAL_LPTIM_REGISTER_CALLBACKS when set to 1
- allows the user to configure dynamically the driver callbacks.
- [..]
- Use Function @ref HAL_LPTIM_RegisterCallback() to register a callback.
- @ref HAL_LPTIM_RegisterCallback() takes as parameters the HAL peripheral handle,
- the Callback ID and a pointer to the user callback function.
- [..]
- Use function @ref HAL_LPTIM_UnRegisterCallback() to reset a callback to the
- default weak function.
- @ref HAL_LPTIM_UnRegisterCallback takes as parameters the HAL peripheral handle,
- and the Callback ID.
- [..]
- These functions allow to register/unregister following callbacks:
- (+) MspInitCallback : LPTIM Base Msp Init Callback.
- (+) MspDeInitCallback : LPTIM Base Msp DeInit Callback.
- (+) CompareMatchCallback : Compare match Callback.
- (+) AutoReloadMatchCallback : Auto-reload match Callback.
- (+) TriggerCallback : External trigger event detection Callback.
- (+) CompareWriteCallback : Compare register write complete Callback.
- (+) AutoReloadWriteCallback : Auto-reload register write complete Callback.
- (+) DirectionUpCallback : Up-counting direction change Callback.
- (+) DirectionDownCallback : Down-counting direction change Callback.
- [..]
- By default, after the Init and when the state is HAL_LPTIM_STATE_RESET
- all interrupt callbacks are set to the corresponding weak functions:
- examples @ref HAL_LPTIM_TriggerCallback(), @ref HAL_LPTIM_CompareMatchCallback().
- [..]
- Exception done for MspInit and MspDeInit functions that are reset to the legacy weak
- functionalities in the Init/DeInit only when these callbacks are null
- (not registered beforehand). If not, MspInit or MspDeInit are not null, the Init/DeInit
- keep and use the user MspInit/MspDeInit callbacks (registered beforehand)
- [..]
- Callbacks can be registered/unregistered in HAL_LPTIM_STATE_READY state only.
- Exception done MspInit/MspDeInit that can be registered/unregistered
- in HAL_LPTIM_STATE_READY or HAL_LPTIM_STATE_RESET state,
- thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
- In that case first register the MspInit/MspDeInit user callbacks
- using @ref HAL_LPTIM_RegisterCallback() before calling DeInit or Init function.
- [..]
- When The compilation define USE_HAL_LPTIM_REGISTER_CALLBACKS is set to 0 or
- not defined, the callback registration feature is not available and all callbacks
- are set to the corresponding weak functions.
- @endverbatim
- ******************************************************************************
- * @attention
- *
- * <h2><center>© Copyright (c) 2023 Puya Semiconductor Co.
- * All rights reserved.</center></h2>
- *
- * This software component is licensed by Puya under BSD 3-Clause license,
- * the "License"; You may not use this file except in compliance with the
- * License. You may obtain a copy of the License at:
- * opensource.org/licenses/BSD-3-Clause
- *
- ******************************************************************************
- * @attention
- *
- * <h2><center>© Copyright (c) 2016 STMicroelectronics.
- * All rights reserved.</center></h2>
- *
- * This software component is licensed by ST under BSD 3-Clause license,
- * the "License"; You may not use this file except in compliance with the
- * License. You may obtain a copy of the License at:
- * opensource.org/licenses/BSD-3-Clause
- *
- ******************************************************************************
- */
- /* Includes ------------------------------------------------------------------*/
- #include "py32f0xx_hal.h"
- /** @addtogroup PY32F002B_HAL_Driver
- * @{
- */
- /** @defgroup LPTIM LPTIM
- * @brief LPTIM HAL module driver.
- * @{
- */
- #ifdef HAL_LPTIM_MODULE_ENABLED
- /* Private typedef -----------------------------------------------------------*/
- /* Private define ------------------------------------------------------------*/
- /* Private macro -------------------------------------------------------------*/
- /* Private variables ---------------------------------------------------------*/
- /* Private function prototypes -----------------------------------------------*/
- #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
- static void LPTIM_ResetCallback(LPTIM_HandleTypeDef *lptim);
- #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
- /* Exported functions --------------------------------------------------------*/
- /** @defgroup LPTIM_Exported_Functions LPTIM Exported Functions
- * @{
- */
- /** @defgroup LPTIM_Exported_Functions_Group1 Initialization/de-initialization functions
- * @brief Initialization and Configuration functions.
- *
- @verbatim
- ==============================================================================
- ##### Initialization and de-initialization functions #####
- ==============================================================================
- [..] This section provides functions allowing to:
- (+) Initialize the LPTIM according to the specified parameters in the
- LPTIM_InitTypeDef and initialize the associated handle.
- (+) DeInitialize the LPTIM peripheral.
- (+) Initialize the LPTIM MSP.
- (+) DeInitialize the LPTIM MSP.
- @endverbatim
- * @{
- */
- /**
- * @brief Initialize the LPTIM according to the specified parameters in the
- * LPTIM_InitTypeDef and initialize the associated handle.
- * @param hlptim LPTIM handle
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_LPTIM_Init(LPTIM_HandleTypeDef *hlptim)
- {
- uint32_t tmpcfgr;
- /* Check the LPTIM handle allocation */
- if(hlptim == NULL)
- {
- return HAL_ERROR;
- }
- /* Check the parameters */
- assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
- assert_param(IS_LPTIM_CLOCK_PRESCALER(hlptim->Init.Prescaler));
- if(hlptim->State == HAL_LPTIM_STATE_RESET)
- {
- /* Allocate lock resource and initialize it */
- hlptim->Lock = HAL_UNLOCKED;
- #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
- /* Reset interrupt callbacks to legacy weak callbacks */
- LPTIM_ResetCallback(hlptim);
- if(hlptim->MspInitCallback == NULL)
- {
- hlptim->MspInitCallback = HAL_LPTIM_MspInit;
- }
- /* Init the low level hardware : GPIO, CLOCK, NVIC */
- hlptim->MspInitCallback(hlptim);
- #else
- /* Init the low level hardware : GPIO, CLOCK, NVIC */
- HAL_LPTIM_MspInit(hlptim);
- #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
- }
- /* Change the LPTIM state */
- hlptim->State = HAL_LPTIM_STATE_BUSY;
- /* Get the LPTIMx CFGR value */
- tmpcfgr = hlptim->Instance->CFGR;
- /* Clear PRESC, PRELOAD */
- tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_PRELOAD | LPTIM_CFGR_PRESC));
- /* Set initialization parameters */
- tmpcfgr |= (hlptim->Init.Prescaler|hlptim->Init.UpdateMode);
- /* Write to LPTIMx CFGR */
- hlptim->Instance->CFGR = tmpcfgr;
- /* Change the LPTIM state */
- hlptim->State = HAL_LPTIM_STATE_READY;
- /* Return function status */
- return HAL_OK;
- }
- /**
- * @brief DeInitialize the LPTIM peripheral.
- * @param hlptim LPTIM handle
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_LPTIM_DeInit(LPTIM_HandleTypeDef *hlptim)
- {
- /* Check the LPTIM handle allocation */
- if(hlptim == NULL)
- {
- return HAL_ERROR;
- }
- /* Change the LPTIM state */
- hlptim->State = HAL_LPTIM_STATE_BUSY;
- /* Disable the LPTIM Peripheral Clock */
- __HAL_LPTIM_DISABLE(hlptim);
- #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
- if(hlptim->MspDeInitCallback == NULL)
- {
- hlptim->MspDeInitCallback = HAL_LPTIM_MspDeInit;
- }
- /* DeInit the low level hardware: CLOCK, NVIC.*/
- hlptim->MspDeInitCallback(hlptim);
- #else
- /* DeInit the low level hardware: CLOCK, NVIC.*/
- HAL_LPTIM_MspDeInit(hlptim);
- #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
- /* Change the LPTIM state */
- hlptim->State = HAL_LPTIM_STATE_RESET;
- /* Release Lock */
- __HAL_UNLOCK(hlptim);
- /* Return function status */
- return HAL_OK;
- }
- /**
- * @brief Initialize the LPTIM MSP.
- * @param hlptim LPTIM handle
- * @retval None
- */
- __weak void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef *hlptim)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hlptim);
- /* NOTE : This function should not be modified, when the callback is needed,
- the HAL_LPTIM_MspInit could be implemented in the user file
- */
- }
- /**
- * @brief DeInitialize LPTIM MSP.
- * @param hlptim LPTIM handle
- * @retval None
- */
- __weak void HAL_LPTIM_MspDeInit(LPTIM_HandleTypeDef *hlptim)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hlptim);
- /* NOTE : This function should not be modified, when the callback is needed,
- the HAL_LPTIM_MspDeInit could be implemented in the user file
- */
- }
- /**
- * @}
- */
- /** @defgroup LPTIM_Exported_Functions_Group2 LPTIM Start-Stop operation functions
- * @brief Start-Stop operation functions.
- *
- @verbatim
- ==============================================================================
- ##### LPTIM Start Stop operation functions #####
- ==============================================================================
- [..] This section provides functions allowing to:
- (+) Start the Set once mode.
- (+) Stop the Set once mode.
- (+) Start the Set continues mode.
- (+) Stop the Set continues mode.
- @endverbatim
- * @{
- */
- /**
- * @brief Start the LPTIM in Set once mode.
- * @param hlptim LPTIM handle
- * @param Period Specifies the Autoreload value.
- * This parameter must be a value between 0x0000 and 0xFFFF.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
- {
- /* Check the parameters */
- assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
- assert_param(IS_LPTIM_PERIOD(Period));
- /* Set the LPTIM state */
- hlptim->State= HAL_LPTIM_STATE_BUSY;
- /* Enable the Peripheral */
- __HAL_LPTIM_ENABLE(hlptim);
- /* Load the period value in the autoreload register */
- __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
- /* Start timer in single mode */
- __HAL_LPTIM_START_SINGLE(hlptim);
- /* Change the TIM state*/
- hlptim->State= HAL_LPTIM_STATE_READY;
- /* Return function status */
- return HAL_OK;
- }
- /**
- * @brief Stop the LPTIM Set once mode.
- * @param hlptim LPTIM handle
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop(LPTIM_HandleTypeDef *hlptim)
- {
- /* Check the parameters */
- assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
- /* Set the LPTIM state */
- hlptim->State= HAL_LPTIM_STATE_BUSY;
- /* Disable the Peripheral */
- __HAL_LPTIM_DISABLE(hlptim);
- /* Change the TIM state*/
- hlptim->State= HAL_LPTIM_STATE_READY;
- /* Return function status */
- return HAL_OK;
- }
- /**
- * @brief Start the LPTIM Set once mode in interrupt mode.
- * @param hlptim LPTIM handle
- * @param Period Specifies the Autoreload value.
- * This parameter must be a value between 0x0000 and 0xFFFF.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
- {
- /* Check the parameters */
- assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
- assert_param(IS_LPTIM_PERIOD(Period));
- /* Set the LPTIM state */
- hlptim->State= HAL_LPTIM_STATE_BUSY;
- /* Enable Autoreload match interrupt */
- __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
- /* Enable the Peripheral */
- __HAL_LPTIM_ENABLE(hlptim);
- /* Load the period value in the autoreload register */
- __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
- /* Start timer in single mode */
- __HAL_LPTIM_START_SINGLE(hlptim);
- /* Change the TIM state*/
- hlptim->State= HAL_LPTIM_STATE_READY;
- /* Return function status */
- return HAL_OK;
- }
- /**
- * @brief Stop the LPTIM Set once mode in interrupt mode.
- * @param hlptim LPTIM handle
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop_IT(LPTIM_HandleTypeDef *hlptim)
- {
- /* Check the parameters */
- assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
- /* Set the LPTIM state */
- hlptim->State= HAL_LPTIM_STATE_BUSY;
- /* Disable the Peripheral */
- __HAL_LPTIM_DISABLE(hlptim);
- /* Disable Autoreload match interrupt */
- __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
- /* Change the TIM state*/
- hlptim->State= HAL_LPTIM_STATE_READY;
- /* Return function status */
- return HAL_OK;
- }
- #if defined(LPTIM_CR_CNTSTRT)
- /**
- * @brief Start the LPTIM in Set continue mode.
- * @param hlptim LPTIM handle
- * @param Period Specifies the Autoreload value.
- * This parameter must be a value between 0x0000 and 0xFFFF.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_LPTIM_SetContinue_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
- {
- /* Check the parameters */
- assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
- assert_param(IS_LPTIM_PERIOD(Period));
- /* Set the LPTIM state */
- hlptim->State= HAL_LPTIM_STATE_BUSY;
- /* Enable the Peripheral */
- __HAL_LPTIM_ENABLE(hlptim);
- /* Load the period value in the autoreload register */
- __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
- /* Start timer in continue mode */
- __HAL_LPTIM_START_CONTINUE(hlptim);
- /* Change the TIM state*/
- hlptim->State= HAL_LPTIM_STATE_READY;
- /* Return function status */
- return HAL_OK;
- }
- /**
- * @brief Stop the LPTIM Set continue mode.
- * @param hlptim LPTIM handle
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_LPTIM_SetContinue_Stop(LPTIM_HandleTypeDef *hlptim)
- {
- /* Check the parameters */
- assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
- /* Set the LPTIM state */
- hlptim->State= HAL_LPTIM_STATE_BUSY;
- /* Disable the Peripheral */
- __HAL_LPTIM_DISABLE(hlptim);
- /* Change the TIM state*/
- hlptim->State= HAL_LPTIM_STATE_READY;
- /* Return function status */
- return HAL_OK;
- }
- /**
- * @brief Start the LPTIM Set continue mode in interrupt mode.
- * @param hlptim LPTIM handle
- * @param Period Specifies the Autoreload value.
- * This parameter must be a value between 0x0000 and 0xFFFF.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_LPTIM_SetContinue_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
- {
- /* Check the parameters */
- assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
- assert_param(IS_LPTIM_PERIOD(Period));
- /* Set the LPTIM state */
- hlptim->State= HAL_LPTIM_STATE_BUSY;
- /* Enable Autoreload match interrupt */
- __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
- /* Enable the Peripheral */
- __HAL_LPTIM_ENABLE(hlptim);
- /* Load the period value in the autoreload register */
- __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
- /* Start timer in continue mode */
- __HAL_LPTIM_START_CONTINUE(hlptim);
- /* Change the TIM state*/
- hlptim->State= HAL_LPTIM_STATE_READY;
- /* Return function status */
- return HAL_OK;
- }
- /**
- * @brief Stop the LPTIM Set continue mode in interrupt mode.
- * @param hlptim LPTIM handle
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_LPTIM_SetContinue_Stop_IT(LPTIM_HandleTypeDef *hlptim)
- {
- /* Check the parameters */
- assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
- /* Set the LPTIM state */
- hlptim->State= HAL_LPTIM_STATE_BUSY;
- /* Disable the Peripheral */
- __HAL_LPTIM_DISABLE(hlptim);
- /* Disable Autoreload match interrupt */
- __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
- /* Change the TIM state*/
- hlptim->State= HAL_LPTIM_STATE_READY;
- /* Return function status */
- return HAL_OK;
- }
- #endif
- /**
- * @}
- */
- /** @defgroup LPTIM_Exported_Functions_Group3 LPTIM Read operation functions
- * @brief Read operation functions.
- *
- @verbatim
- ==============================================================================
- ##### LPTIM Read operation functions #####
- ==============================================================================
- [..] This section provides LPTIM Reading functions.
- (+) Read the counter value.
- (+) Read the period (Auto-reload) value.
- (+) Read the pulse (Compare)value.
- @endverbatim
- * @{
- */
- /**
- * @brief Return the current counter value.
- * @param hlptim LPTIM handle
- * @retval Counter value.
- */
- uint32_t HAL_LPTIM_ReadCounter(LPTIM_HandleTypeDef *hlptim)
- {
- /* Check the parameters */
- assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
- return (hlptim->Instance->CNT);
- }
- /**
- * @brief Return the current Autoreload (Period) value.
- * @param hlptim LPTIM handle
- * @retval Autoreload value.
- */
- uint32_t HAL_LPTIM_ReadAutoReload(LPTIM_HandleTypeDef *hlptim)
- {
- /* Check the parameters */
- assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
- return (hlptim->Instance->ARR);
- }
- /**
- * @brief Counter synchronous reset.
- * @param hlptim pointer to a LPTIM_HandleTypeDef structure that contains
- * the configuration information for LPTIM module.
- * @retval None
- */
- uint32_t HAL_LPTIM_ResetCounter(LPTIM_HandleTypeDef *hlptim)
- {
- /* Check the parameters */
- assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
- if(READ_BIT(hlptim->Instance->CR, LPTIM_CR_COUNTRST) == 0)
- {
- SET_BIT(hlptim->Instance->CR, LPTIM_CR_COUNTRST);
- }
- else
- {
- return HAL_ERROR;
- }
- return HAL_OK;
- }
- /**
- * @}
- */
- /** @defgroup LPTIM_Exported_Functions_Group4 LPTIM IRQ handler and callbacks
- * @brief LPTIM IRQ handler.
- *
- @verbatim
- ==============================================================================
- ##### LPTIM IRQ handler and callbacks #####
- ==============================================================================
- [..] This section provides LPTIM IRQ handler and callback functions called within
- the IRQ handler:
- (+) LPTIM interrupt request handler
- (+) Compare match Callback
- (+) Auto-reload match Callback
- (+) External trigger event detection Callback
- (+) Compare register write complete Callback
- (+) Auto-reload register write complete Callback
- (+) Up-counting direction change Callback
- (+) Down-counting direction change Callback
- @endverbatim
- * @{
- */
- /**
- * @brief Handle LPTIM interrupt request.
- * @param hlptim LPTIM handle
- * @retval None
- */
- void HAL_LPTIM_IRQHandler(LPTIM_HandleTypeDef *hlptim)
- {
- /* Autoreload match interrupt */
- if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARRM) != RESET)
- {
- if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARRM) != RESET)
- {
- /* Clear Autoreload match flag */
- __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARRM);
- /* Autoreload match Callback */
- #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
- hlptim->AutoReloadMatchCallback(hlptim);
- #else
- HAL_LPTIM_AutoReloadMatchCallback(hlptim);
- #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
- }
- }
- /* Autoreload Update completed interrupt */
- if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARROK) != RESET)
- {
- if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARROK) != RESET)
- {
- /* Clear Autoreload Update completed flag */
- __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
- /* Autoreload Update completed Callback */
- #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
- hlptim->HAL_LPTIM_AutoReloadUpdateCompletedCallback(hlptim);
- #else
- HAL_LPTIM_AutoReloadUpdateCompletedCallback(hlptim);
- #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
- }
- }
- }
- /**
- * @brief Autoreload match callback in non-blocking mode.
- * @param hlptim LPTIM handle
- * @retval None
- */
- __weak void HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef *hlptim)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hlptim);
- /* NOTE : This function should not be modified, when the callback is needed,
- the HAL_LPTIM_AutoReloadMatchCallback could be implemented in the user file
- */
- }
- /**
- * @brief Autoreload Update completed callback in non-blocking mode.
- * @param hlptim LPTIM handle
- * @retval None
- */
- __weak void HAL_LPTIM_AutoReloadUpdateCompletedCallback(LPTIM_HandleTypeDef *hlptim)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hlptim);
- /* NOTE : This function should not be modified, when the callback is needed,
- the HAL_LPTIM_AutoReloadUpdateCompletedCallback could be implemented in the user file
- */
- }
- #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
- /**
- * @brief Register a User LPTIM callback to be used instead of the weak predefined callback
- * @param hlptim LPTIM handle
- * @param CallbackID ID of the callback to be registered
- * This parameter can be one of the following values:
- * @arg @ref HAL_LPTIM_MSPINIT_CB_ID LPTIM Base Msp Init Callback ID
- * @arg @ref HAL_LPTIM_MSPDEINIT_CB_ID LPTIM Base Msp DeInit Callback ID
- * @arg @ref HAL_LPTIM_AUTORELOAD_MATCH_CB_ID Auto-reload match Callback ID
- * @param pCallback pointer to the callback function
- * @retval status
- */
- HAL_StatusTypeDef HAL_LPTIM_RegisterCallback(LPTIM_HandleTypeDef * hlptim,
- HAL_LPTIM_CallbackIDTypeDef CallbackID,
- pLPTIM_CallbackTypeDef pCallback)
- {
- HAL_StatusTypeDef status = HAL_OK;
- if(pCallback == NULL)
- {
- return HAL_ERROR;
- }
- /* Process locked */
- __HAL_LOCK(hlptim);
- if(hlptim->State == HAL_LPTIM_STATE_READY)
- {
- switch (CallbackID)
- {
- case HAL_LPTIM_MSPINIT_CB_ID :
- hlptim->MspInitCallback = pCallback;
- break;
- case HAL_LPTIM_MSPDEINIT_CB_ID :
- hlptim->MspDeInitCallback = pCallback;
- break;
- case HAL_LPTIM_AUTORELOAD_MATCH_CB_ID :
- hlptim->AutoReloadMatchCallback = pCallback;
- break;
- default :
- /* Return error status */
- status = HAL_ERROR;
- break;
- }
- }
- else if(hlptim->State == HAL_LPTIM_STATE_RESET)
- {
- switch (CallbackID)
- {
- case HAL_LPTIM_MSPINIT_CB_ID :
- hlptim->MspInitCallback = pCallback;
- break;
- case HAL_LPTIM_MSPDEINIT_CB_ID :
- hlptim->MspDeInitCallback = pCallback;
- break;
- default :
- /* Return error status */
- status = HAL_ERROR;
- break;
- }
- }
- else
- {
- /* Return error status */
- status = HAL_ERROR;
- }
- /* Release Lock */
- __HAL_UNLOCK(hlptim);
- return status;
- }
- /**
- * @brief Unregister a LPTIM callback
- * LLPTIM callback is redirected to the weak predefined callback
- * @param hlptim LPTIM handle
- * @param CallbackID ID of the callback to be unregistered
- * This parameter can be one of the following values:
- * @arg @ref HAL_LPTIM_MSPINIT_CB_ID LPTIM Base Msp Init Callback ID
- * @arg @ref HAL_LPTIM_MSPDEINIT_CB_ID LPTIM Base Msp DeInit Callback ID
- * @arg @ref HAL_LPTIM_AUTORELOAD_MATCH_CB_ID Auto-reload match Callback ID
- * @retval status
- */
- HAL_StatusTypeDef HAL_LPTIM_UnRegisterCallback(LPTIM_HandleTypeDef * hlptim,
- HAL_LPTIM_CallbackIDTypeDef CallbackID)
- {
- HAL_StatusTypeDef status = HAL_OK;
- /* Process locked */
- __HAL_LOCK(hlptim);
- if(hlptim->State == HAL_LPTIM_STATE_READY)
- {
- switch (CallbackID)
- {
- case HAL_LPTIM_MSPINIT_CB_ID :
- hlptim->MspInitCallback = HAL_LPTIM_MspInit; /* Legacy weak MspInit Callback */
- break;
- case HAL_LPTIM_MSPDEINIT_CB_ID :
- hlptim->MspDeInitCallback = HAL_LPTIM_MspDeInit; /* Legacy weak Msp DeInit Callback */
- break;
- case HAL_LPTIM_AUTORELOAD_MATCH_CB_ID :
- hlptim->AutoReloadMatchCallback = HAL_LPTIM_AutoReloadMatchCallback; /* Legacy weak IC Msp DeInit Callback */
- break;
- default :
- /* Return error status */
- status = HAL_ERROR;
- break;
- }
- }
- else if(hlptim->State == HAL_LPTIM_STATE_RESET)
- {
- switch (CallbackID)
- {
- case HAL_LPTIM_MSPINIT_CB_ID :
- hlptim->MspInitCallback = HAL_LPTIM_MspInit; /* Legacy weak MspInit Callback */
- break;
- case HAL_LPTIM_MSPDEINIT_CB_ID :
- hlptim->MspDeInitCallback = HAL_LPTIM_MspDeInit; /* Legacy weak Msp DeInit Callback */
- break;
- default :
- /* Return error status */
- status = HAL_ERROR;
- break;
- }
- }
- else
- {
- /* Return error status */
- status = HAL_ERROR;
- }
- /* Release Lock */
- __HAL_UNLOCK(hlptim);
- return status;
- }
- #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
- /**
- * @}
- */
- /** @defgroup LPTIM_Group5 Peripheral State functions
- * @brief Peripheral State functions.
- *
- @verbatim
- ==============================================================================
- ##### Peripheral State functions #####
- ==============================================================================
- [..]
- This subsection permits to get in run-time the status of the peripheral.
- @endverbatim
- * @{
- */
- /**
- * @brief Return the LPTIM handle state.
- * @param hlptim LPTIM handle
- * @retval HAL state
- */
- HAL_LPTIM_StateTypeDef HAL_LPTIM_GetState(LPTIM_HandleTypeDef *hlptim)
- {
- /* Return LPTIM handle state */
- return hlptim->State;
- }
- /**
- * @}
- */
- /**
- * @}
- */
- /* Private functions ---------------------------------------------------------*/
- /** @defgroup LPTIM_Private_Functions LPTIM Private Functions
- * @{
- */
- #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
- /**
- * @brief Reset interrupt callbacks to the legacy weak callbacks.
- * @param lptim pointer to a LPTIM_HandleTypeDef structure that contains
- * the configuration information for LPTIM module.
- * @retval None
- */
- static void LPTIM_ResetCallback(LPTIM_HandleTypeDef *lptim)
- {
- /* Reset the LPTIM callback to the legacy weak callbacks */
- lptim->AutoReloadMatchCallback = HAL_LPTIM_AutoReloadMatchCallback; /* Auto-reload match Callback */
- }
- #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
- /**
- * @}
- */
- #endif /* HAL_LPTIM_MODULE_ENABLED */
- /**
- * @}
- */
- /**
- * @}
- */
- /************************ (C) COPYRIGHT Puya *****END OF FILE****/
|