| /** |
| * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
| * |
| * Redistribution and use in source and binary forms, with or without modification, |
| * are permitted provided that the following conditions are met: |
| * 1. Redistributions of source code must retain the above copyright notice, |
| * this list of conditions and the following disclaimer. |
| * 2. Redistributions in binary form must reproduce the above copyright notice, |
| * this list of conditions and the following disclaimer in the documentation |
| * and/or other materials provided with the distribution. |
| * 3. Neither the name of STMicroelectronics nor the names of its contributors |
| * may be used to endorse or promote products derived from this software |
| * without specific prior written permission. |
| * |
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| */ |
| |
| #include "os/mynewt.h" |
| #include "mcu/stm32_hal.h" |
| |
| /* XXX: Included functions are copied verbatim from stm32l0xx_hal_tim.c |
| * because they are defined in STM32Cube L0 as static functions. |
| */ |
| #if MYNEWT_VAL(MCU_STM32L0) |
| #include "stm32l0xx_hal.h" |
| |
| void TIM_Base_SetConfig(TIM_TypeDef *TIMx, TIM_Base_InitTypeDef *Structure) |
| { |
| uint32_t tmpcr1 = 0U; |
| tmpcr1 = TIMx->CR1; |
| |
| /* Set TIM Time Base Unit parameters ---------------------------------------*/ |
| if(IS_TIM_CC1_INSTANCE(TIMx) != RESET) |
| { |
| /* Select the Counter Mode */ |
| tmpcr1 &= ~(TIM_CR1_DIR | TIM_CR1_CMS); |
| tmpcr1 |= Structure->CounterMode; |
| } |
| |
| if(IS_TIM_CC1_INSTANCE(TIMx) != RESET) |
| { |
| /* Set the clock division */ |
| tmpcr1 &= ~TIM_CR1_CKD; |
| tmpcr1 |= (uint32_t)Structure->ClockDivision; |
| } |
| |
| TIMx->CR1 = tmpcr1; |
| |
| /* Set the Autoreload value */ |
| TIMx->ARR = (uint32_t)Structure->Period ; |
| |
| /* Set the Prescaler value */ |
| TIMx->PSC = (uint32_t)Structure->Prescaler; |
| |
| /* Generate an update event to reload the Prescaler value immediatly */ |
| TIMx->EGR = TIM_EGR_UG; |
| } |
| |
| void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState) |
| { |
| uint32_t tmp = 0U; |
| |
| /* Check the parameters */ |
| assert_param(IS_TIM_CCX_INSTANCE(TIMx,Channel)); |
| |
| tmp = TIM_CCER_CC1E << Channel; |
| |
| /* Reset the CCxE Bit */ |
| TIMx->CCER &= ~tmp; |
| |
| /* Set or reset the CCxE Bit */ |
| TIMx->CCER |= (uint32_t)(ChannelState << Channel); |
| } |
| |
| #endif |
| |
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |