TUKS MCU Introductory course / TUKS-COURSE-TIMER
Committer:
elmot
Date:
Fri Feb 24 21:13:56 2017 +0000
Revision:
1:d0dfbce63a89
Ready-to-copy

Who changed what in which revision?

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