stm8l15x_syscfg.c

来自「STM8L的tim4定时器使用」· C语言 代码 · 共 501 行 · 第 1/2 页

C
501
字号
/**
  ******************************************************************************
  * @file    stm8l15x_syscfg.c
  * @author  MCD Application Team
  * @version V1.5.0
  * @date    13-May-2011
  * @brief   This file provides firmware functions to manage the following 
  *          functionalities of the RI and SYSCFG:
  *            - RI configuration
  *            - SYSCFG configuration
  *
  *  @verbatim
  *  
  *          ===================================================================
  *                                 How to use this driver
  *          ===================================================================
  *          This driver provides functions to configure the RI and SYSCFG
  *          These functions are split in 2 groups: 
  *   
  *          1. RI configuration: this group includes all needed functions 
  *             to configure the RI:
  *                   - Routing the TIM1 Input capture channels
  *                   - Close and Open the I/O switches
  *                   - Close and Open the analog switches
  *                   - Configure the internal Pull-up and Pull-down resistors
  *           
  *          2. SYSCFG configuration: this group includes all needed functions 
  *             to configure the SYSCFG:
  *                   - Configure the alternate function remapping of some peripherals
  *                     such as: USART, SPI, TIMs...
  *                     Remapping possibilities depends on the device (low-density,
  *                     medium-density or high density) so it is recommended to   
  *                     refer to the product reference manual.
  *                   - Configure the DMA channels remapping of ADC1 and TIM4
  *
  *  @endverbatim            
  *    
  ******************************************************************************
  *
  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  *
  * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  ******************************************************************************  
  */

/* Includes ------------------------------------------------------------------*/
#include "stm8l15x_syscfg.h"

/** @addtogroup STM8L15x_StdPeriph_Driver
  * @{
  */
  
/** @defgroup SYSCFG
  * @brief SYSCFG driver modules
  * @{
  */
  
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/** @defgroup SYSCFG_Private_Functions
  * @{
  */

/** @defgroup SYSCFG_Group1 RI configuration
 *  @brief   RI configuration
 *
@verbatim   
 ===============================================================================
                           RI configuration functions
 ===============================================================================  
  
       ===================================================================      
                        SYSCFG Driver: how to configure RI
       =================================================================== 
       
         1. By default, TIM1 Input Capture channels 2 and 3 are connected to the
            I/O port assigned in the datasheet pinout (default routing).
            TIM1 Input Capture channels 2 and 3 can be routed by calling 
            SYSCFG_RITIMInputCaptureConfig()
            Refer to the device reference manual for more details about 
            TIM1 input capture routing
          
         2. For more details about using SYSCFG_RIIOSwitchConfig()
            and SYSCFG_RIAnalogSwitchConfig() with COMP1 and COMP2, refer to
            comparators driver
            
         3. To output the Internal reference voltage VREFINT, configure corresponding
            GPIO pin in input mode using GPIO_Init() then use SYSCFG_RIIOSwitchConfig()
       
         4. To use the internal Pull-up and Pull-down resistors call
            SYSCFG_RIResistorConfig()

@endverbatim
  * @{
  */

/**
  * @brief  Deinitializes the RI registers to their default reset values.
  * @param  None
  * @retval None
  */
void SYSCFG_RIDeInit(void)
{
  RI->ICR1   = RI_ICR1_RESET_VALUE;     /*!< Set RI->ICR1 to reset value */
  RI->ICR2   = RI_ICR2_RESET_VALUE;     /*!< Set RI->ICR2 to reset value */
  RI->IOSR1  = RI_IOSR1_RESET_VALUE;    /*!< Set RI->IOSR1 to reset value */
  RI->IOSR2  = RI_IOSR2_RESET_VALUE;    /*!< Set RI->IOSR2 to reset value */
  RI->IOSR3  = RI_IOSR3_RESET_VALUE;    /*!< Set RI->IOSR3 to reset value */
  RI->IOSR4  = RI_IOSR4_RESET_VALUE;    /*!< Set RI->IOSR3 to reset value */
  RI->ASCR1  = RI_ASCR1_RESET_VALUE;    /*!< Set RI->ASCR1 to reset value */
  RI->ASCR2  = RI_ASCR2_RESET_VALUE;    /*!< Set RI->ASCR2 to reset value */
  RI->RCR    = RI_RCR_RESET_VALUE;      /*!< Set RI->RCR to reset value */
}

/**
  * @brief  Configures the routing interface to select which Input Output pin
  *         to be routed to TIM1 Input Capture.
  * @param  RI_InputCapture: selects the TIM1 input capture2 RI_InputCapture_IC2
  *         or the TIM1 input capture3 RI_InputCapture_IC3
  * @param  RI_InputCaptureRouting: selects the value to set in TIM1 Input Capture
  *         routing register ICRx and can be from RI_InputCaptureRouting_0 to
  *         RI_InputCaptureRouting_22.
  * @retval None.
  */
void SYSCFG_RITIMInputCaptureConfig(RI_InputCapture_TypeDef RI_InputCapture,
                                    RI_InputCaptureRouting_TypeDef RI_InputCaptureRouting)
{
  /* Check the parameters */
  assert_param(IS_RI_INPUTCAPTURE(RI_InputCapture));
  assert_param(IS_RI_INPUTCAPTUREROUTING(RI_InputCaptureRouting));

  /* Check whether Input Capture 2 is selected */
  if (RI_InputCapture == RI_InputCapture_IC2)
  {
    /* Set the value in ICR1 register to route TIM input Capture 2 */
    RI->ICR1 = (uint8_t) RI_InputCaptureRouting;
  }

  else /* The Input Capture 3 is selected */
  {
    /* Set the value in ICR2 register to route TIM input capture 3 */
    RI->ICR2 = (uint8_t) RI_InputCaptureRouting;
  }
}

/**
  * @brief  Enables or disables the Routing Interface Analog switch.
  * @param  RI_AnalogSwitch: Analog Switch
  *          This parameter can be one of the following values:
  *            @arg RI_AnalogSwitch_0: Analog switch 0
  *            @arg RI_AnalogSwitch_1: Analog switch 1
  *            @arg RI_AnalogSwitch_2: Analog switch 2
  *            @arg RI_AnalogSwitch_3: Analog switch 3
  *            @arg RI_AnalogSwitch_4: Analog switch 4
  *            @arg RI_AnalogSwitch_5: Analog switch 5
  *            @arg RI_AnalogSwitch_6: Analog switch 6
  *            @arg RI_AnalogSwitch_7: Analog switch 7
  *            @arg RI_AnalogSwitch_8: Analog switch 8
  *            @arg RI_AnalogSwitch_9: Analog switch 9
  *            @arg RI_AnalogSwitch_10: Analog switch 10
  *            @arg RI_AnalogSwitch_11: Analog switch 11
  *            @arg RI_AnalogSwitch_12: Analog switch 14                          
  * @param  NewState: new state of the analog switch.
  *         This parameter can be ENABLE or DISABLE.
  * @retval None
  */
void SYSCFG_RIAnalogSwitchConfig(RI_AnalogSwitch_TypeDef RI_AnalogSwitch,
                                 FunctionalState NewState)
{
  uint8_t AnalogSwitchRegister, AnalogSwitchIndex = 0;

  /* Check the parameters */
  assert_param(IS_RI_ANALOGSWITCH(RI_AnalogSwitch));
  assert_param(IS_FUNCTIONAL_STATE(NewState));

  /* Get the analog switch register ASCR1 or ASCR2 */
  AnalogSwitchRegister = (uint8_t) (RI_AnalogSwitch & (uint8_t) 0xF0);

  /* Get the analog switch bit index in ASCRx register */
  AnalogSwitchIndex = (uint8_t) (RI_AnalogSwitch & (uint8_t) 0x0F);

  if (NewState != DISABLE)
  {
    if (AnalogSwitchRegister == (uint8_t) 0x10)
    {
      /* Enable the analog switch */
      RI->ASCR1 |= (uint8_t) ((uint8_t)1 << (uint8_t) AnalogSwitchIndex);
    }
    else
    {
      /* Enable the analog switch */
      RI->ASCR2 |= (uint8_t) ((uint8_t)1 << (uint8_t) AnalogSwitchIndex);
    }
  }
  else
  {
    if (AnalogSwitchRegister == (uint8_t) 0x10)
    {
      /* Disable the analog switch */
      RI->ASCR1 &= (uint8_t) (~(uint8_t)((uint8_t)1 <<  AnalogSwitchIndex));
    }
    else
    {
      /* Disable the analog switch */
      RI->ASCR2 &= (uint8_t) (~ (uint8_t)((uint8_t)1 << AnalogSwitchIndex));
    }
  }
}

/**
  * @brief  Closes or Opens the routing interface Input Output switches.
  * @param  RI_IOSwitch: can be one of RI_IOSwitch_1..RI_IOSwitch_24
  * @param  NewState: new state of the Input Output Switch.
  *         This parameter can be ENABLE or DISABLE.
  * @retval None.
  */
void SYSCFG_RIIOSwitchConfig(RI_IOSwitch_TypeDef RI_IOSwitch,
                             FunctionalState NewState)
{
  uint8_t IOSwitchRegsiter, IOSwitchIndex = 0;

  /* Check the parameters */
  assert_param(IS_RI_IOSWITCH(RI_IOSwitch));
  assert_param(IS_FUNCTIONAL_STATE(NewState));

  /* Get the Input Output switch bit index in IOSRx register */
  IOSwitchIndex = (uint8_t) (RI_IOSwitch & (uint8_t) 0x0F);

  /* Get the Input Output switch register IOSR1, IOSR2 or IOSR3 */
  IOSwitchRegsiter = (uint8_t) (RI_IOSwitch & (uint8_t) 0xF0);

  /* Check whether the Input Output switch control bit is in the IOSR1 register */
  if (IOSwitchRegsiter == (uint8_t) 0x10)
  {
    if (NewState != DISABLE)
    {
      /* Close the Input Output switch */
      RI->IOSR1 |= (uint8_t) ((uint8_t)1 << IOSwitchIndex);
    }
    else
    {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?