Frederick Huang / mbed-STM32L452

Dependents:   STM32L452_Nucleo_ticker

Fork of mbed-dev by mbed official

Committer:
Kojto
Date:
Tue Feb 14 14:44:10 2017 +0000
Revision:
158:b23ee177fd68
This updates the lib to the mbed lib v136

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 158:b23ee177fd68 1 /**
Kojto 158:b23ee177fd68 2 ******************************************************************************
Kojto 158:b23ee177fd68 3 * @file stm32l0xx_ll_lptim.c
Kojto 158:b23ee177fd68 4 * @author MCD Application Team
Kojto 158:b23ee177fd68 5 * @version V1.7.0
Kojto 158:b23ee177fd68 6 * @date 31-May-2016
Kojto 158:b23ee177fd68 7 * @brief LPTIM LL module driver.
Kojto 158:b23ee177fd68 8 ******************************************************************************
Kojto 158:b23ee177fd68 9 * @attention
Kojto 158:b23ee177fd68 10 *
Kojto 158:b23ee177fd68 11 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
Kojto 158:b23ee177fd68 12 *
Kojto 158:b23ee177fd68 13 * Redistribution and use in source and binary forms, with or without modification,
Kojto 158:b23ee177fd68 14 * are permitted provided that the following conditions are met:
Kojto 158:b23ee177fd68 15 * 1. Redistributions of source code must retain the above copyright notice,
Kojto 158:b23ee177fd68 16 * this list of conditions and the following disclaimer.
Kojto 158:b23ee177fd68 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
Kojto 158:b23ee177fd68 18 * this list of conditions and the following disclaimer in the documentation
Kojto 158:b23ee177fd68 19 * and/or other materials provided with the distribution.
Kojto 158:b23ee177fd68 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Kojto 158:b23ee177fd68 21 * may be used to endorse or promote products derived from this software
Kojto 158:b23ee177fd68 22 * without specific prior written permission.
Kojto 158:b23ee177fd68 23 *
Kojto 158:b23ee177fd68 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Kojto 158:b23ee177fd68 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Kojto 158:b23ee177fd68 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Kojto 158:b23ee177fd68 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Kojto 158:b23ee177fd68 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Kojto 158:b23ee177fd68 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Kojto 158:b23ee177fd68 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Kojto 158:b23ee177fd68 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Kojto 158:b23ee177fd68 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Kojto 158:b23ee177fd68 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Kojto 158:b23ee177fd68 34 *
Kojto 158:b23ee177fd68 35 ******************************************************************************
Kojto 158:b23ee177fd68 36 */
Kojto 158:b23ee177fd68 37 #if defined(USE_FULL_LL_DRIVER)
Kojto 158:b23ee177fd68 38
Kojto 158:b23ee177fd68 39 /* Includes ------------------------------------------------------------------*/
Kojto 158:b23ee177fd68 40 #include "stm32l0xx_ll_lptim.h"
Kojto 158:b23ee177fd68 41 #include "stm32l0xx_ll_bus.h"
Kojto 158:b23ee177fd68 42
Kojto 158:b23ee177fd68 43 #ifdef USE_FULL_ASSERT
Kojto 158:b23ee177fd68 44 #include "stm32_assert.h"
Kojto 158:b23ee177fd68 45 #else
Kojto 158:b23ee177fd68 46 #define assert_param(expr) ((void)0U)
Kojto 158:b23ee177fd68 47 #endif
Kojto 158:b23ee177fd68 48
Kojto 158:b23ee177fd68 49 /** @addtogroup STM32L0xx_LL_Driver
Kojto 158:b23ee177fd68 50 * @{
Kojto 158:b23ee177fd68 51 */
Kojto 158:b23ee177fd68 52
Kojto 158:b23ee177fd68 53 #if defined (LPTIM1) || defined (LPTIM2)
Kojto 158:b23ee177fd68 54
Kojto 158:b23ee177fd68 55 /** @addtogroup LPTIM_LL
Kojto 158:b23ee177fd68 56 * @{
Kojto 158:b23ee177fd68 57 */
Kojto 158:b23ee177fd68 58
Kojto 158:b23ee177fd68 59 /* Private types -------------------------------------------------------------*/
Kojto 158:b23ee177fd68 60 /* Private variables ---------------------------------------------------------*/
Kojto 158:b23ee177fd68 61 /* Private constants ---------------------------------------------------------*/
Kojto 158:b23ee177fd68 62 /* Private macros ------------------------------------------------------------*/
Kojto 158:b23ee177fd68 63 /** @addtogroup LPTIM_LL_Private_Macros
Kojto 158:b23ee177fd68 64 * @{
Kojto 158:b23ee177fd68 65 */
Kojto 158:b23ee177fd68 66 #define IS_LPTIM_CLOCK_SOURCE(__VALUE__) (((__VALUE__) == LL_LPTIM_CLK_SOURCE_INTERNAL) \
Kojto 158:b23ee177fd68 67 || ((__VALUE__) == LL_LPTIM_CLK_SOURCE_EXTERNAL))
Kojto 158:b23ee177fd68 68
Kojto 158:b23ee177fd68 69 #define IS_LPTIM_CLOCK_PRESCALER(__VALUE__) (((__VALUE__) == LL_LPTIM_PRESCALER_DIV1) \
Kojto 158:b23ee177fd68 70 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV2) \
Kojto 158:b23ee177fd68 71 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV4) \
Kojto 158:b23ee177fd68 72 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV8) \
Kojto 158:b23ee177fd68 73 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV16) \
Kojto 158:b23ee177fd68 74 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV32) \
Kojto 158:b23ee177fd68 75 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV64) \
Kojto 158:b23ee177fd68 76 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV128))
Kojto 158:b23ee177fd68 77
Kojto 158:b23ee177fd68 78 #define IS_LPTIM_WAVEFORM(__VALUE__) (((__VALUE__) == LL_LPTIM_OUTPUT_WAVEFORM_PWM) \
Kojto 158:b23ee177fd68 79 || ((__VALUE__) == LL_LPTIM_OUTPUT_WAVEFORM_SETONCE))
Kojto 158:b23ee177fd68 80
Kojto 158:b23ee177fd68 81 #define IS_LPTIM_OUTPUT_POLARITY(__VALUE__) (((__VALUE__) == LL_LPTIM_OUTPUT_POLARITY_REGULAR) \
Kojto 158:b23ee177fd68 82 || ((__VALUE__) == LL_LPTIM_OUTPUT_POLARITY_INVERSE))
Kojto 158:b23ee177fd68 83 /**
Kojto 158:b23ee177fd68 84 * @}
Kojto 158:b23ee177fd68 85 */
Kojto 158:b23ee177fd68 86
Kojto 158:b23ee177fd68 87
Kojto 158:b23ee177fd68 88 /* Private function prototypes -----------------------------------------------*/
Kojto 158:b23ee177fd68 89 /* Exported functions --------------------------------------------------------*/
Kojto 158:b23ee177fd68 90 /** @addtogroup LPTIM_LL_Exported_Functions
Kojto 158:b23ee177fd68 91 * @{
Kojto 158:b23ee177fd68 92 */
Kojto 158:b23ee177fd68 93
Kojto 158:b23ee177fd68 94 /** @addtogroup LPTIM_LL_EF_Init
Kojto 158:b23ee177fd68 95 * @{
Kojto 158:b23ee177fd68 96 */
Kojto 158:b23ee177fd68 97
Kojto 158:b23ee177fd68 98 /**
Kojto 158:b23ee177fd68 99 * @brief Set LPTIMx registers to their reset values.
Kojto 158:b23ee177fd68 100 * @param LPTIMx LP Timer instance
Kojto 158:b23ee177fd68 101 * @retval An ErrorStatus enumeration value:
Kojto 158:b23ee177fd68 102 * - SUCCESS: LPTIMx registers are de-initialized
Kojto 158:b23ee177fd68 103 * - ERROR: invalid LPTIMx instance
Kojto 158:b23ee177fd68 104 */
Kojto 158:b23ee177fd68 105 ErrorStatus LL_LPTIM_DeInit(LPTIM_TypeDef* LPTIMx)
Kojto 158:b23ee177fd68 106 {
Kojto 158:b23ee177fd68 107 ErrorStatus result = SUCCESS;
Kojto 158:b23ee177fd68 108
Kojto 158:b23ee177fd68 109 /* Check the parameters */
Kojto 158:b23ee177fd68 110 assert_param(IS_LPTIM_INSTANCE(LPTIMx));
Kojto 158:b23ee177fd68 111
Kojto 158:b23ee177fd68 112 if (LPTIMx == LPTIM1)
Kojto 158:b23ee177fd68 113 {
Kojto 158:b23ee177fd68 114 LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_LPTIM1);
Kojto 158:b23ee177fd68 115 LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_LPTIM1);
Kojto 158:b23ee177fd68 116 }
Kojto 158:b23ee177fd68 117 #if defined(LPTIM2)
Kojto 158:b23ee177fd68 118 else if (LPTIMx == LPTIM2)
Kojto 158:b23ee177fd68 119 {
Kojto 158:b23ee177fd68 120 LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_LPTIM2);
Kojto 158:b23ee177fd68 121 LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_LPTIM2);
Kojto 158:b23ee177fd68 122 }
Kojto 158:b23ee177fd68 123 #endif
Kojto 158:b23ee177fd68 124 else
Kojto 158:b23ee177fd68 125 {
Kojto 158:b23ee177fd68 126 result = ERROR;
Kojto 158:b23ee177fd68 127 }
Kojto 158:b23ee177fd68 128
Kojto 158:b23ee177fd68 129 return result;
Kojto 158:b23ee177fd68 130 }
Kojto 158:b23ee177fd68 131
Kojto 158:b23ee177fd68 132 /**
Kojto 158:b23ee177fd68 133 * @brief Set each fields of the LPTIM_InitStruct structure to its default
Kojto 158:b23ee177fd68 134 * value.
Kojto 158:b23ee177fd68 135 * @param LPTIM_InitStruct pointer to a @ref LL_LPTIM_InitTypeDef structure
Kojto 158:b23ee177fd68 136 * @retval None
Kojto 158:b23ee177fd68 137 */
Kojto 158:b23ee177fd68 138 void LL_LPTIM_StructInit(LL_LPTIM_InitTypeDef* LPTIM_InitStruct)
Kojto 158:b23ee177fd68 139 {
Kojto 158:b23ee177fd68 140 /* Set the default configuration */
Kojto 158:b23ee177fd68 141 LPTIM_InitStruct->ClockSource = LL_LPTIM_CLK_SOURCE_INTERNAL;
Kojto 158:b23ee177fd68 142 LPTIM_InitStruct->Prescaler = LL_LPTIM_PRESCALER_DIV1;
Kojto 158:b23ee177fd68 143 LPTIM_InitStruct->Waveform = LL_LPTIM_OUTPUT_WAVEFORM_PWM;
Kojto 158:b23ee177fd68 144 LPTIM_InitStruct->Polarity = LL_LPTIM_OUTPUT_POLARITY_REGULAR;
Kojto 158:b23ee177fd68 145 }
Kojto 158:b23ee177fd68 146
Kojto 158:b23ee177fd68 147 /**
Kojto 158:b23ee177fd68 148 * @brief Configure the LPTIMx peripheral according to the specified parameters.
Kojto 158:b23ee177fd68 149 * @note LL_LPTIM_Init can only be called when the LPTIM instance is disabled.
Kojto 158:b23ee177fd68 150 * @note LPTIMx can be disabled using unitary function @ref LL_LPTIM_Disable().
Kojto 158:b23ee177fd68 151 * @param LPTIMx LP Timer Instance
Kojto 158:b23ee177fd68 152 * @param LPTIM_InitStruct pointer to a @ref LL_LPTIM_InitTypeDef structure
Kojto 158:b23ee177fd68 153 * @retval An ErrorStatus enumeration value:
Kojto 158:b23ee177fd68 154 * - SUCCESS: LPTIMx instance has been initialized
Kojto 158:b23ee177fd68 155 * - ERROR: LPTIMx instance hasn't been initialized
Kojto 158:b23ee177fd68 156 */
Kojto 158:b23ee177fd68 157 ErrorStatus LL_LPTIM_Init(LPTIM_TypeDef * LPTIMx, LL_LPTIM_InitTypeDef* LPTIM_InitStruct)
Kojto 158:b23ee177fd68 158 {
Kojto 158:b23ee177fd68 159 ErrorStatus result = SUCCESS;
Kojto 158:b23ee177fd68 160
Kojto 158:b23ee177fd68 161 /* The LPTIMx_CFGR register must only be modified when the LPTIM is disabled
Kojto 158:b23ee177fd68 162 (ENABLE bit is reset to 0).
Kojto 158:b23ee177fd68 163 */
Kojto 158:b23ee177fd68 164 if (LL_LPTIM_IsEnabled(LPTIMx))
Kojto 158:b23ee177fd68 165 {
Kojto 158:b23ee177fd68 166 result = ERROR;
Kojto 158:b23ee177fd68 167 }
Kojto 158:b23ee177fd68 168 else
Kojto 158:b23ee177fd68 169 {
Kojto 158:b23ee177fd68 170 /* Check the parameters */
Kojto 158:b23ee177fd68 171 assert_param(IS_LPTIM_INSTANCE(LPTIMx));
Kojto 158:b23ee177fd68 172 assert_param(IS_LPTIM_CLOCK_SOURCE(LPTIM_InitStruct->ClockSource));
Kojto 158:b23ee177fd68 173 assert_param(IS_LPTIM_CLOCK_PRESCALER(LPTIM_InitStruct->Prescaler));
Kojto 158:b23ee177fd68 174 assert_param(IS_LPTIM_WAVEFORM(LPTIM_InitStruct->Waveform));
Kojto 158:b23ee177fd68 175 assert_param(IS_LPTIM_OUTPUT_POLARITY(LPTIM_InitStruct->Polarity));
Kojto 158:b23ee177fd68 176
Kojto 158:b23ee177fd68 177 /* Set CKSEL bitfield according to ClockSource value */
Kojto 158:b23ee177fd68 178 /* Set PRESC bitfield according to Prescaler value */
Kojto 158:b23ee177fd68 179 /* Set WAVE bitfield according to Waveform value */
Kojto 158:b23ee177fd68 180 /* Set WAVEPOL bitfield according to Polarity value */
Kojto 158:b23ee177fd68 181 MODIFY_REG(LPTIMx->CFGR,
Kojto 158:b23ee177fd68 182 (LPTIM_CFGR_CKSEL | LPTIM_CFGR_PRESC | LPTIM_CFGR_WAVE| LPTIM_CFGR_WAVPOL),
Kojto 158:b23ee177fd68 183 LPTIM_InitStruct->ClockSource | \
Kojto 158:b23ee177fd68 184 LPTIM_InitStruct->Prescaler | \
Kojto 158:b23ee177fd68 185 LPTIM_InitStruct->Waveform | \
Kojto 158:b23ee177fd68 186 LPTIM_InitStruct->Polarity);
Kojto 158:b23ee177fd68 187 }
Kojto 158:b23ee177fd68 188
Kojto 158:b23ee177fd68 189 return result;
Kojto 158:b23ee177fd68 190 }
Kojto 158:b23ee177fd68 191
Kojto 158:b23ee177fd68 192 /**
Kojto 158:b23ee177fd68 193 * @}
Kojto 158:b23ee177fd68 194 */
Kojto 158:b23ee177fd68 195
Kojto 158:b23ee177fd68 196 /**
Kojto 158:b23ee177fd68 197 * @}
Kojto 158:b23ee177fd68 198 */
Kojto 158:b23ee177fd68 199
Kojto 158:b23ee177fd68 200 /**
Kojto 158:b23ee177fd68 201 * @}
Kojto 158:b23ee177fd68 202 */
Kojto 158:b23ee177fd68 203
Kojto 158:b23ee177fd68 204 #endif /* defined (LPTIM1) || defined (LPTIM2) */
Kojto 158:b23ee177fd68 205
Kojto 158:b23ee177fd68 206 /**
Kojto 158:b23ee177fd68 207 * @}
Kojto 158:b23ee177fd68 208 */
Kojto 158:b23ee177fd68 209
Kojto 158:b23ee177fd68 210 #endif /* USE_FULL_LL_DRIVER */
Kojto 158:b23ee177fd68 211
Kojto 158:b23ee177fd68 212 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/