Exemplo n.º 1
0
/**
  * @brief Initializes the ADC1 peripheral according to the specified parameters
  * @param[in] ADC1_ConversionMode: specifies the conversion mode
  * can be one of the values of @ref ADC1_ConvMode_TypeDef.
  * @param[in] ADC1_Channel: specifies the channel to convert
  * can be one of the values of @ref ADC1_Channel_TypeDef.
  * @param[in] ADC1_PrescalerSelection: specifies the ADC1 prescaler
  * can be one of the values of @ref ADC1_PresSel_TypeDef.
  * @param[in] ADC1_ExtTrigger: specifies the external trigger
  * can be one of the values of @ref ADC1_ExtTrig_TypeDef.
  * @param[in] ADC1_ExtTriggerState: specifies the external trigger new state
  * can be one of the values of @ref FunctionalState.
  * @param[in] ADC1_Align: specifies the converted data alignement
  * can be one of the values of @ref ADC1_Align_TypeDef.
  * @param[in] ADC1_SchmittTriggerChannel: specifies the schmitt trigger channel
  * can be one of the values of @ref ADC1_SchmittTrigg_TypeDef.
  * @param[in] ADC1_SchmittTriggerState: specifies the schmitt trigger state
  * can be one of the values of @ref FunctionalState.
  * @retval None
  */
void ADC1_Init(ADC1_ConvMode_TypeDef ADC1_ConversionMode, ADC1_Channel_TypeDef ADC1_Channel, ADC1_PresSel_TypeDef ADC1_PrescalerSelection, ADC1_ExtTrig_TypeDef ADC1_ExtTrigger, FunctionalState ADC1_ExtTriggerState, ADC1_Align_TypeDef ADC1_Align, ADC1_SchmittTrigg_TypeDef ADC1_SchmittTriggerChannel, FunctionalState ADC1_SchmittTriggerState)
{

    /* Check the parameters */
    assert_param(IS_ADC1_CONVERSIONMODE_OK(ADC1_ConversionMode));
    assert_param(IS_ADC1_CHANNEL_OK(ADC1_Channel));
    assert_param(IS_ADC1_PRESSEL_OK(ADC1_PrescalerSelection));
    assert_param(IS_ADC1_EXTTRIG_OK(ADC1_ExtTrigger));
    assert_param(IS_FUNCTIONALSTATE_OK(((ADC1_ExtTriggerState))));
    assert_param(IS_ADC1_ALIGN_OK(ADC1_Align));
    assert_param(IS_ADC1_SCHMITTTRIG_OK(ADC1_SchmittTriggerChannel));
    assert_param(IS_FUNCTIONALSTATE_OK(ADC1_SchmittTriggerState));

    /*-----------------CR1 & CSR configuration --------------------*/
    /* Configure the conversion mode and the channel to convert
    respectively according to ADC1_ConversionMode & ADC1_Channel values  &  ADC1_Align values */
    ADC1_ConversionConfig(ADC1_ConversionMode, ADC1_Channel, ADC1_Align);
    /* Select the prescaler division factor according to ADC1_PrescalerSelection values */
    ADC1_PrescalerConfig(ADC1_PrescalerSelection);

    /*-----------------CR2 configuration --------------------*/
    /* Configure the external trigger state and event respectively
    according to NewState, ADC1_ExtTrigger */
    ADC1_ExternalTriggerConfig(ADC1_ExtTrigger, ADC1_ExtTriggerState);

    /*------------------TDR configuration ---------------------------*/
    /* Configure the schmitt trigger channel and state respectively
    according to ADC1_SchmittTriggerChannel & ADC1_SchmittTriggerNewState  values */
    ADC1_SchmittTriggerConfig(ADC1_SchmittTriggerChannel, ADC1_SchmittTriggerState);

    /* Enable the ADC1 peripheral */
    ADC1->CR1 |= ADC1_CR1_ADON;

}
Exemplo n.º 2
0
/**
  * @brief   Enables or disables the specified peripheral CLK.
  * @param   CLK_Peripheral : This parameter specifies the peripheral clock to gate.
  * This parameter can be any of the  @ref CLK_Peripheral_TypeDef enumeration.
  * @param   NewState : New state of specified peripheral clock.
  * This parameter can be any of the @ref FunctionalState enumeration.
  * @retval None
  */
void CLK_PeripheralClockConfig(CLK_Peripheral_TypeDef CLK_Peripheral, FunctionalState NewState)
{

    /* Check the parameters */
    assert_param(IS_FUNCTIONALSTATE_OK(NewState));
    assert_param(IS_CLK_PERIPHERAL_OK(CLK_Peripheral));

    if (((uint8_t)CLK_Peripheral & (uint8_t)0x10) == 0x00)
    {
        if (NewState != DISABLE)
        {
            /* Enable the peripheral Clock */
            CLK->PCKENR1 |= (uint8_t)((uint8_t)1 << ((uint8_t)CLK_Peripheral & (uint8_t)0x0F));
        }
        else
        {
            /* Disable the peripheral Clock */
            CLK->PCKENR1 &= (uint8_t)(~(uint8_t)(((uint8_t)1 << ((uint8_t)CLK_Peripheral & (uint8_t)0x0F))));
        }
    }
    else
    {
        if (NewState != DISABLE)
        {
            /* Enable the peripheral Clock */
            CLK->PCKENR2 |= (uint8_t)((uint8_t)1 << ((uint8_t)CLK_Peripheral & (uint8_t)0x0F));
        }
        else
        {
            /* Disable the peripheral Clock */
            CLK->PCKENR2 &= (uint8_t)(~(uint8_t)(((uint8_t)1 << ((uint8_t)CLK_Peripheral & (uint8_t)0x0F))));
        }
    }

}
Exemplo n.º 3
0
/**
  * @brief  Enables or disables the TIM3 Capture Compare Channel x.
  * @param   TIM3_Channel specifies the TIM3 Channel.
  * This parameter can be one of the following values:
  *                       - TIM3_CHANNEL_1: TIM3 Channel1
  *                       - TIM3_CHANNEL_2: TIM3 Channel2
  * @param   NewState specifies the TIM3 Channel CCxE bit new state.
  * This parameter can be: ENABLE or DISABLE.
  * @retval None
  */
void TIM3_CCxCmd(TIM3_Channel_TypeDef TIM3_Channel, FunctionalState NewState)
{
    /* Check the parameters */
    assert_param(IS_TIM3_CHANNEL_OK(TIM3_Channel));
    assert_param(IS_FUNCTIONALSTATE_OK(NewState));

    if (TIM3_Channel == TIM3_CHANNEL_1)
    {
        /* Set or Reset the CC1E Bit */
        if (NewState != DISABLE)
        {
            TIM3->CCER1 |= TIM3_CCER1_CC1E;
        }
        else
        {
            TIM3->CCER1 &= (uint8_t)(~TIM3_CCER1_CC1E);
        }

    }
    else
    {
        /* Set or Reset the CC2E Bit */
        if (NewState != DISABLE)
        {
            TIM3->CCER1 |= TIM3_CCER1_CC2E;
        }
        else
        {
            TIM3->CCER1 &= (uint8_t)(~TIM3_CCER1_CC2E);
        }
    }

}
Exemplo n.º 4
0
/**
  * @brief   Enables or disables the specified CLK interrupts.
  * @param   CLK_IT This parameter specifies the interrupt sources.
  * It can be one of the values of @ref CLK_IT_TypeDef.
  * @param   NewState New state of the Interrupt.
  * Value accepted ENABLE, DISABLE.
  * @retval None
  */
void CLK_ITConfig(CLK_IT_TypeDef CLK_IT, FunctionalState NewState)
{
  /* check the parameters */
  assert_param(IS_FUNCTIONALSTATE_OK(NewState));
  assert_param(IS_CLK_IT_OK(CLK_IT));
  
  if (NewState != DISABLE)
  {
    switch (CLK_IT)
    {
    case CLK_IT_SWIF: /* Enable the clock switch interrupt */
      CLK->SWCR |= CLK_SWCR_SWIEN;
      break;
    case CLK_IT_CSSD: /* Enable the clock security system detection interrupt */
      CLK->CSSR |= CLK_CSSR_CSSDIE;
      break;
    default:
      break;
    }
  }
  else  /*(NewState == DISABLE)*/
  {
    switch (CLK_IT)
    {
    case CLK_IT_SWIF: /* Disable the clock switch interrupt */
      CLK->SWCR  &= (uint8_t)(~CLK_SWCR_SWIEN);
      break;
    case CLK_IT_CSSD: /* Disable the clock security system detection interrupt */
      CLK->CSSR &= (uint8_t)(~CLK_CSSR_CSSDIE);
      break;
    default:
      break;
    }
  }
}
Exemplo n.º 5
0
/**
  * @brief Configure the ADC1 conversion on external trigger event.
  * @par Full description:
  * The selected external trigger evant can be enabled or disabled.
  * @param[in] ADC1_ExtTrigger to select the External trigger event.
  * can have one of the values of @ref ADC1_ExtTrig_TypeDef.
  * @param[in] NewState to enable/disable the selected external trigger
  * can have one of the values of @ref FunctionalState.
  * @retval None
  */
void ADC1_ExternalTriggerConfig(ADC1_ExtTrig_TypeDef ADC1_ExtTrigger, FunctionalState NewState)
{

    /* Check the parameters */
    assert_param(IS_ADC1_EXTTRIG_OK(ADC1_ExtTrigger));
    assert_param(IS_FUNCTIONALSTATE_OK(NewState));

    /* Clear the external trigger selection bits */
    ADC1->CR2 &= (u8)(~ADC1_CR2_EXTSEL);

    if (NewState != DISABLE)
    {
        /* Enable the selected external Trigger */
        ADC1->CR2 |= (u8)(ADC1_CR2_EXTTRIG);
    }
    else /* NewState == DISABLE */
    {
        /* Disable the selected external trigger */
        ADC1->CR2 &= (u8)(~ADC1_CR2_EXTTRIG);
    }

    /* Set the slected external trigger */
    ADC1->CR2 |= (u8)(ADC1_ExtTrigger);

}
Exemplo n.º 6
0
/**
  * @brief Enables or disables the analog watchdog for the given channel.
  * @param[in] Channel specifies the desired Channel.
  * It can be set of the values of @ref ADC1_Channel_TypeDef.
  * @param[in] NewState specifies the analog watchdog new state.
  * can have one of the values of @ref FunctionalState.
  * @retval None
  */
void ADC1_AWDChannelConfig(ADC1_Channel_TypeDef Channel, FunctionalState NewState)
{
    /* Check the parameters */
    assert_param(IS_FUNCTIONALSTATE_OK(NewState));
    assert_param(IS_ADC1_CHANNEL_OK(Channel));

    if (Channel < (u8)8)
    {
        if (NewState != DISABLE)
        {
            ADC1->AWCRL |= (u8)((u8)1 << Channel);
        }
        else /* NewState == DISABLE */
        {
            ADC1->AWCRL &= (u8)(~((u8)1 << Channel));
        }
    }
    else
    {
        if (NewState != DISABLE)
        {
            ADC1->AWCRH |= (u8)((u8)1 << (Channel - (u8)8));
        }
        else /* NewState == DISABLE */
        {
            ADC1->AWCRH &= (u8)(~((u8)1 << (Channel - (u8)8)));
        }
    }
}
Exemplo n.º 7
0
/**
  * @brief   Enables or Disables the Flash interrupt mode
  * @param  NewState : The new state of the flash interrupt mode
  *         This parameter can be a value of @ref FunctionalState enumeration.
  * @retval None
  */
void FLASH_ITConfig(FunctionalState NewState)
{
      /* Check parameter */
  assert_param(IS_FUNCTIONALSTATE_OK(NewState));

    if (NewState != DISABLE)
    {
        FLASH->CR1 |= FLASH_CR1_IE; /* Enables the interrupt sources */
    }
    else
    {
        FLASH->CR1 &= (uint8_t)(~FLASH_CR1_IE); /* Disables the interrupt sources */
    }
}
Exemplo n.º 8
0
/**
  * @brief  Enables or Disables the ADC1 data store into the Data Buffer registers rather than in the Data Register
  * @param   NewState: specifies the selected mode enabled or disabled state.
  * @retval None
  */
void ADC1_DataBufferCmd(FunctionalState NewState)
{
    /* Check the parameters */
    assert_param(IS_FUNCTIONALSTATE_OK(NewState));

    if (NewState != DISABLE)
    {
        ADC1->CR3 |= ADC1_CR3_DBUF;
    }
    else /* NewState == DISABLE */
    {
        ADC1->CR3 &= (uint8_t)(~ADC1_CR3_DBUF);
    }
}
Exemplo n.º 9
0
/**
  * @brief Configures the external pull-up on GPIOx pins.
  * @param[in] GPIOx : Select the GPIO peripheral number (x = A to I).
  * @param[in] GPIO_Pin : This parameter contains the pin number, it can be one or many members
  * of the @ref GPIO_Pin_TypeDef enumeration.
  * @param[in] NewState : The new state of the pull up pin.
 * This parameter can be any of the @ref FunctionalState enumeration.
  * @retval void : None
  * @par Required preconditions:
  * None
  * @par Called functions:
  * None
  * @par Example:
  * This example shows how to call the function:
  * @code
  * GPIO_ExternalPullUpConfig(GPIOA, GPIO_PIN_6 | GPIO_PIN_7,ENABLE);
  * @endcode
  */
void GPIO_ExternalPullUpConfig(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin, FunctionalState NewState)
{
  /* Check the parameters */
  assert_param(IS_GPIO_PIN_OK(GPIO_Pin));
  assert_param(IS_FUNCTIONALSTATE_OK(NewState));

  if (NewState != DISABLE) /* External Pull-Up Set*/
  {
    GPIOx->CR1 |= GPIO_Pin;
  } else /* External Pull-Up Reset*/
  {
    GPIOx->CR1 &= (u8)(~(GPIO_Pin));
  }
}
Exemplo n.º 10
0
/**
  * @brief  Enables or Disables the ADC1 scan mode.
  * @param  NewState: specifies the selected mode enabled or disabled state.
  * @retval None
  */
void ADC1_ScanModeCmd(FunctionalState NewState)
{
    /* Check the parameters */
    assert_param(IS_FUNCTIONALSTATE_OK(NewState));

    if (NewState != DISABLE)
    {
        ADC1->CR2 |= ADC1_CR2_SCAN;
    }
    else /* NewState == DISABLE */
    {
        ADC1->CR2 &= (uint8_t)(~ADC1_CR2_SCAN);
    }
}
Exemplo n.º 11
0
/**
  * @brief Enables or disables the TIM6 peripheral.
  * @param[in] NewState : The new state of the TIM6 peripheral.
  * This parameter can be any of the @ref FunctionalState enumeration.
  * @retval None
  */
void TIM6_Cmd(FunctionalState NewState)
{
    /* Check the parameters */
    assert_param(IS_FUNCTIONALSTATE_OK(NewState));

    /* set or Reset the CEN Bit */
    if (NewState == ENABLE)
    {
        TIM6->CR1 |= TIM6_CR1_CEN ;
    }
    else
    {
        TIM6->CR1 &= (u8)(~TIM6_CR1_CEN) ;
    }
}
Exemplo n.º 12
0
/**
  * @brief Enables or Disables the TIM6 Update event.
  * @param[in] NewState : The new state of the TIM6 peripheral Preload register.
  * This parameter can be any of the @ref FunctionalState enumeration.
  * @retval None
  */
void TIM6_UpdateDisableConfig(FunctionalState NewState)
{
    /* Check the parameters */
    assert_param(IS_FUNCTIONALSTATE_OK(NewState));

    /* Set or Reset the UDIS Bit */
    if (NewState == ENABLE)
    {
        TIM6->CR1 |= TIM6_CR1_UDIS ;
    }
    else
    {
        TIM6->CR1 &= (u8)(~TIM6_CR1_UDIS) ;
    }
}
Exemplo n.º 13
0
/**
  * @brief  Enables or disables the TIM3 peripheral Preload Register on CCR2.
  * @param   NewState new state of the Capture Compare Preload register.
  * This parameter can be ENABLE or DISABLE.
  * @retval None
  */
void TIM3_OC2PreloadConfig(FunctionalState NewState)
{
    /* Check the parameters */
    assert_param(IS_FUNCTIONALSTATE_OK(NewState));

    /* Set or Reset the OC2PE Bit */
    if (NewState != DISABLE)
    {
        TIM3->CCMR2 |= TIM3_CCMR_OCxPE;
    }
    else
    {
        TIM3->CCMR2 &= (uint8_t)(~TIM3_CCMR_OCxPE);
    }
}
Exemplo n.º 14
0
/**
  * @brief  Enables or disables the TIM3 peripheral.
  * @param   NewState new state of the TIM3 peripheral. This parameter can
  * be ENABLE or DISABLE.
  * @retval None
  */
void TIM3_Cmd(FunctionalState NewState)
{
    /* Check the parameters */
    assert_param(IS_FUNCTIONALSTATE_OK(NewState));

    /* set or Reset the CEN Bit */
    if (NewState != DISABLE)
    {
        TIM3->CR1 |= (uint8_t)TIM3_CR1_CEN;
    }
    else
    {
        TIM3->CR1 &= (uint8_t)(~TIM3_CR1_CEN);
    }
}
Exemplo n.º 15
0
/**
  * @brief Enables or disables TIM6 peripheral Preload register on ARR.
  * @param[in] NewState : The new state of the TIM6 peripheral Preload register.
  * This parameter can be any of the @ref FunctionalState enumeration.
  * @retval None
  */
void TIM6_ARRPreloadConfig(FunctionalState NewState)
{
    /* Check the parameters */
    assert_param(IS_FUNCTIONALSTATE_OK(NewState));

    /* Set or Reset the ARPE Bit */
    if (NewState == ENABLE)
    {
        TIM6->CR1 |= TIM6_CR1_ARPE ;
    }
    else
    {
        TIM6->CR1 &= (u8)(~TIM6_CR1_ARPE) ;
    }
}
Exemplo n.º 16
0
/**
  * @brief  Enables or disables TIM2 peripheral Preload register on ARR.
  * @param   NewState new state of the TIM2 peripheral Preload register.
  * This parameter can be ENABLE or DISABLE.
  * @retval None
  */
void TIM2_ARRPreloadConfig(FunctionalState NewState)
{
    /* Check the parameters */
    assert_param(IS_FUNCTIONALSTATE_OK(NewState));

    /* Set or Reset the ARPE Bit */
    if (NewState != DISABLE)
    {
        TIM2->CR1 |= (uint8_t)TIM2_CR1_ARPE;
    }
    else
    {
        TIM2->CR1 &= (uint8_t)(~TIM2_CR1_ARPE);
    }
}
Exemplo n.º 17
0
void TIM6_SelectMasterSlaveMode(FunctionalState NewState)
{
    /* Check the parameters */
    assert_param(IS_FUNCTIONALSTATE_OK(NewState));

    /* Set or Reset the MSM Bit */
    if (NewState == ENABLE)
    {
        TIM6->SMCR |= TIM6_SMCR_MSM;
    }
    else
    {
        TIM6->SMCR &= (u8)(~TIM6_SMCR_MSM);
    }
}
Exemplo n.º 18
0
/**
  * @brief  Configures the slow active halt wake up
  * @param   NewState: specifies the Slow Active Halt wake up state.
  * can be set of the following values:
  * - DISABLE: Slow Active Halt mode disabled;
  * - ENABLE:  Slow Active Halt mode enabled.
  * @retval None
  */
void CLK_SlowActiveHaltWakeUpCmd(FunctionalState NewState)
{
  /* check the parameters */
  assert_param(IS_FUNCTIONALSTATE_OK(NewState));
  
  if (NewState != DISABLE)
  {
    /* Set S_ACTHALT bit */
    CLK->ICKR |= CLK_ICKR_SWUAH;
  }
  else
  {
    /* Reset S_ACTHALT bit */
    CLK->ICKR &= (uint8_t)(~CLK_ICKR_SWUAH);
  }
}
Exemplo n.º 19
0
/**
  * @brief Enables or Disables the ADC1 peripheral.
  * @param[in] NewState: specifies the peripheral enabled or disabled state.
  * @retval None
  */
void ADC1_Cmd(FunctionalState NewState)
{

    /* Check the parameters */
    assert_param(IS_FUNCTIONALSTATE_OK(NewState));

    if (NewState != DISABLE)
    {
        ADC1->CR1 |= ADC1_CR1_ADON;
    }
    else /* NewState == DISABLE */
    {
        ADC1->CR1 &= (u8)(~ADC1_CR1_ADON);
    }

}
Exemplo n.º 20
0
/**
  * @brief   Configures the High Speed Internal oscillator (HSI).
  * @par Full description:
  * If CLK_FastHaltWakeup is enabled, HSI oscillator is automatically
  * switched-on (HSIEN=1) and selected as next clock master
  * (CKM=SWI=HSI) when resuming from HALT/ActiveHalt modes.\n
  * @param   NewState this parameter is the Wake-up Mode state.
  * @retval None
  */
void CLK_FastHaltWakeUpCmd(FunctionalState NewState)
{
  /* check the parameters */
  assert_param(IS_FUNCTIONALSTATE_OK(NewState));
  
  if (NewState != DISABLE)
  {
    /* Set FHWU bit (HSI oscillator is automatically switched-on) */
    CLK->ICKR |= CLK_ICKR_FHWU;
  }
  else  /* FastHaltWakeup = DISABLE */
  {
    /* Reset FHWU bit */
    CLK->ICKR &= (uint8_t)(~CLK_ICKR_FHWU);
  }
}
Exemplo n.º 21
0
/**
  * @brief  Starts or Stops manually the clock switch execution.
  * @par Full description:
  * NewState parameter set the SWEN.
  * @param   NewState new state of SWEN, value accepted ENABLE, DISABLE.
  * @retval None
  */
void CLK_ClockSwitchCmd(FunctionalState NewState)
{
  /* Check the parameters */
  assert_param(IS_FUNCTIONALSTATE_OK(NewState));
  
  if (NewState != DISABLE )
  {
    /* Enable the Clock Switch */
    CLK->SWCR |= CLK_SWCR_SWEN;
  }
  else
  {
    /* Disable the Clock Switch */
    CLK->SWCR &= (uint8_t)(~CLK_SWCR_SWEN);
  }
}
Exemplo n.º 22
0
/**
  * @brief  Enables or disablle the Configurable Clock Output (CCO).
  * @param   NewState : New state of CCEN bit (CCO register).
  * This parameter can be any of the @ref FunctionalState enumeration.
  * @retval None
  */
void CLK_CCOCmd(FunctionalState NewState)
{
  /* Check the parameters */
  assert_param(IS_FUNCTIONALSTATE_OK(NewState));
  
  if (NewState != DISABLE)
  {
    /* Set CCOEN bit */
    CLK->CCOR |= CLK_CCOR_CCOEN;
  }
  else
  {
    /* Reset CCOEN bit */
    CLK->CCOR &= (uint8_t)(~CLK_CCOR_CCOEN);
  }
}
Exemplo n.º 23
0
/**
  * @brief  Enables or disables the ADC1 interrupt.
  * @param   ADC1_IT specifies the name of the interrupt to enable or disable.
  * This parameter can be one of the following values:
  *    - ADC1_IT_AWDITEN : Analog WDG interrupt enable
  *    - ADC1_IT_EOCITEN  : EOC iterrupt enable
  * @param   NewState specifies the state of the interrupt to apply.
  * @retval None
  */
void ADC1_ITConfig(ADC1_IT_TypeDef ADC1_IT, FunctionalState NewState)
{
    /* Check the parameters */
    assert_param(IS_ADC1_IT_OK(ADC1_IT));
    assert_param(IS_FUNCTIONALSTATE_OK(NewState));

    if (NewState != DISABLE)
    {
        /* Enable the ADC1 interrupts */
        ADC1->CSR |= (uint8_t)ADC1_IT;
    }
    else  /* NewState == DISABLE */
    {
        /* Disable the ADC1 interrupts */
        ADC1->CSR &= (uint8_t)((uint16_t)~(uint16_t)ADC1_IT);
    }
}
Exemplo n.º 24
0
/**
  * @brief Enables or disables the specified TIM6 interrupts.
  * @param[in] TIM6_IT : Specifies the TIM6 interrupts sources to be enabled or disabled.
  * This parameter can be any combination of the @ref TIM6_IT_TypeDef enumeration.
  * @param[in] NewState : The new state of the TIM6 peripheral.
	* This parameter can be any of the @ref FunctionalState enumeration.
  * @retval None
  * @par Required preconditions:
  * If QST option bit is enabled, the TIM6 Interrupt vector will be mapped on IRQ number 2 (irq0).
  * Otherwise, it will be mapped on IRQ number 27 (irq25).
  */
void TIM6_ITConfig(TIM6_IT_TypeDef TIM6_IT, FunctionalState NewState)
{
    /* Check the parameters */
    assert_param(IS_TIM6_IT_OK(TIM6_IT));
    assert_param(IS_FUNCTIONALSTATE_OK(NewState));

    if (NewState == ENABLE)
    {
        /* Enable the Interrupt sources */
        TIM6->IER |= (u8)TIM6_IT;
    }
    else
    {
        /* Disable the Interrupt sources */
        TIM6->IER &= (u8)(~(u8)TIM6_IT);
    }
}
Exemplo n.º 25
0
/**
  * @brief  Enables or disables the ADC2 interrupt.
  * @param   NewState specifies the state of ADC2 interrupt.
  * @retval None
  */
void ADC2_ITConfig(FunctionalState NewState)
{

    /* Check the parameters */
    assert_param(IS_FUNCTIONALSTATE_OK(NewState));

    if (NewState != DISABLE)
    {
        /* Enable the ADC2 interrupts */
        ADC2->CSR |= (uint8_t)ADC2_CSR_EOCIE;
    }
    else  /*NewState == DISABLE */
    {
        /* Disable the ADC2 interrupts */
        ADC2->CSR &= (uint8_t)(~ADC2_CSR_EOCIE);
    }

}
Exemplo n.º 26
0
/**
  * @brief Enables or disables the ADC1 Schmitt Trigger on a selected channel.
  * @param[in] ADC1_SchmittTriggerChannel specifies the desired Channel.
  * It can be set of the values of @ref ADC1_SchmittTrigg_TypeDef.
  * @param[in] NewState specifies Channel new status.
  * can have one of the values of @ref FunctionalState.
  * @retval None
  */
void ADC1_SchmittTriggerConfig(ADC1_SchmittTrigg_TypeDef ADC1_SchmittTriggerChannel, FunctionalState NewState)
{

    /* Check the parameters */
    assert_param(IS_ADC1_SCHMITTTRIG_OK(ADC1_SchmittTriggerChannel));
    assert_param(IS_FUNCTIONALSTATE_OK(NewState));

    if (ADC1_SchmittTriggerChannel == ADC1_SCHMITTTRIG_ALL)
    {
        if (NewState != DISABLE)
        {
            ADC1->TDRL &= (u8)0x0;
            ADC1->TDRH &= (u8)0x0;
        }
        else /* NewState == DISABLE */
        {
            ADC1->TDRL |= (u8)0xFF;
            ADC1->TDRH |= (u8)0xFF;
        }
    }
    else if (ADC1_SchmittTriggerChannel < ADC1_SCHMITTTRIG_CHANNEL8)
    {
        if (NewState != DISABLE)
        {
            ADC1->TDRL &= (u8)(~(u8)((u8)0x01 << (u8)ADC1_SchmittTriggerChannel));
        }
        else /* NewState == DISABLE */
        {
            ADC1->TDRL |= (u8)((u8)0x01 << (u8)ADC1_SchmittTriggerChannel);
        }
    }
    else /* ADC1_SchmittTriggerChannel >= ADC1_SCHMITTTRIG_CHANNEL8 */
    {
        if (NewState != DISABLE)
        {
            ADC1->TDRH &= (u8)(~(u8)((u8)0x01 << ((u8)ADC1_SchmittTriggerChannel - (u8)8)));
        }
        else /* NewState == DISABLE */
        {
            ADC1->TDRH |= (u8)((u8)0x01 << ((u8)ADC1_SchmittTriggerChannel - (u8)8));
        }
    }

}
Exemplo n.º 27
0
/**
  * @brief  configures the Switch from one clock to another
  * @param   CLK_SwitchMode select the clock switch mode.
  * It can be set of the values of @ref CLK_SwitchMode_TypeDef
  * @param   CLK_NewClock choice of the future clock.
  * It can be set of the values of @ref CLK_Source_TypeDef
  * @param   NewState Enable or Disable the Clock Switch interrupt.
  * @param   CLK_CurrentClockState current clock to switch OFF or to keep ON.
  * It can be set of the values of @ref CLK_CurrentClockState_TypeDef
  * @retval ErrorStatus this shows the clock switch status (ERROR/SUCCESS).
  */
ErrorStatus CLK_ClockSwitchConfig(CLK_SwitchMode_TypeDef CLK_SwitchMode, CLK_Source_TypeDef CLK_NewClock, FunctionalState ITState, CLK_CurrentClockState_TypeDef CLK_CurrentClockState)
{

    CLK_Source_TypeDef clock_master;
    uint16_t DownCounter = CLK_TIMEOUT;
    ErrorStatus Swif = ERROR;

    /* Check the parameters */
    assert_param(IS_CLK_SOURCE_OK(CLK_NewClock));
    assert_param(IS_CLK_SWITCHMODE_OK(CLK_SwitchMode));
    assert_param(IS_FUNCTIONALSTATE_OK(ITState));
    assert_param(IS_CLK_CURRENTCLOCKSTATE_OK(CLK_CurrentClockState));

    /* Current clock master saving */
    clock_master = (CLK_Source_TypeDef)CLK->CMSR;

    /* Automatic switch mode management */
    if (CLK_SwitchMode == CLK_SWITCHMODE_AUTO)
    {

        /* Enables Clock switch */
        CLK->SWCR |= CLK_SWCR_SWEN;

        /* Enables or Disables Switch interrupt */
        if (ITState != DISABLE)
        {
            CLK->SWCR |= CLK_SWCR_SWIEN;
        }
        else
        {
            CLK->SWCR &= (uint8_t)(~CLK_SWCR_SWIEN);
        }

        /* Selection of the target clock source */
        CLK->SWR = (uint8_t)CLK_NewClock;

        while ((((CLK->SWCR & CLK_SWCR_SWBSY) != 0 )&& (DownCounter != 0)))
        {
            DownCounter--;
        }

        if (DownCounter != 0)
        {
            Swif = SUCCESS;
        }
        else
        {
            Swif = ERROR;
        }

    }
    else /* CLK_SwitchMode == CLK_SWITCHMODE_MANUAL */
    {

        /* Enables or Disables Switch interrupt  if required  */
        if (ITState != DISABLE)
        {
            CLK->SWCR |= CLK_SWCR_SWIEN;
        }
        else
        {
            CLK->SWCR &= (uint8_t)(~CLK_SWCR_SWIEN);
        }

        /* Selection of the target clock source */
        CLK->SWR = (uint8_t)CLK_NewClock;

        /* In manual mode, there is no risk to be stuck in a loop, value returned
          is then always SUCCESS */
        Swif = SUCCESS;

    }

    /* Switch OFF current clock if required */
    if ((CLK_CurrentClockState == CLK_CURRENTCLOCKSTATE_DISABLE) && ( clock_master == CLK_SOURCE_HSI))
    {
        CLK->ICKR &= (uint8_t)(~CLK_ICKR_HSIEN);
    }
    else if ((CLK_CurrentClockState == CLK_CURRENTCLOCKSTATE_DISABLE) && ( clock_master == CLK_SOURCE_LSI))
    {
        CLK->ICKR &= (uint8_t)(~CLK_ICKR_LSIEN);
    }
    else if ((CLK_CurrentClockState == CLK_CURRENTCLOCKSTATE_DISABLE) && ( clock_master == CLK_SOURCE_HSE))
    {
        CLK->ECKR &= (uint8_t)(~CLK_ECKR_HSEEN);
    }

    return(Swif);

}