stm8l15x_syscfg.c

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

C
501
字号
      /* Open the Input Output switch */
      RI->IOSR1 &= (uint8_t) (~ (uint8_t)((uint8_t)1 << IOSwitchIndex));
    }
  }

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

  /* The Input Output switch control bit is in the IOSR3 register */
  else if (IOSwitchRegsiter == (uint8_t) 0x30)
  {
    if (NewState != DISABLE)
    {
      /* Close the Input Output switch */
      RI->IOSR3 |= (uint8_t) ((uint8_t)1 << IOSwitchIndex);
    }
    else
    {
      /* Open the Input Output switch */
      RI->IOSR3 &= (uint8_t) (~ (uint8_t) ((uint8_t) 1 << IOSwitchIndex));
    }
  }

  /* The Input Output switch control bit is in the IOSR4 register */
  else
  {
    if (NewState != DISABLE)
    {
      /* Close the Input Output switch */
      RI->IOSR4 |= (uint8_t) ((uint8_t)1 << IOSwitchIndex);
    }
    else
    {
      /* Open the Input Output switch */
      RI->IOSR4 &= (uint8_t) (~ (uint8_t) ((uint8_t) 1 << IOSwitchIndex));
    }
  }
}

/**
  * @brief  Configures the Pull-up and Pull-down Resistors
  * @param  RI_Resistor: selects the resistor to connect,
  *          This parameter can be one of the following values:
  *            @arg RI_Resistor_10KPU: 10K pull up
  *            @arg RI_Resistor_400KPU: 400K pull up
  *            @arg RI_Resistor_10KPD: 10K pull down
  *            @arg RI_Resistor_400KPD: 400K pull down      
  * @retval None
  */
void SYSCFG_RIResistorConfig(RI_Resistor_TypeDef RI_Resistor, FunctionalState NewState)
{
  /* Check the parameters */
  assert_param(IS_RI_RESISTOR(RI_Resistor));
  assert_param(IS_FUNCTIONAL_STATE(NewState));

  if (NewState != DISABLE)
  {
    /* Enable the resistor */
    RI->RCR |= (uint8_t) RI_Resistor;
  }
  else
  {
    /* Disable the Resistor */
    RI->RCR &= (uint8_t) (~RI_Resistor);
  }
}

/**
  * @}
  */

/** @defgroup SYSCFG_Group2 SYSCFG configuration
 *  @brief   SYSCFG configuration
 *
@verbatim   
 ===============================================================================
                           SYSCFG configuration functions
 ===============================================================================  
  
       ===================================================================      
                        SYSCFG Driver: how to use it for remapping
       =================================================================== 
       
         1. To remap the alternate function of some peripherals (such as: USART,
            SPI, TIMs...), use SYSCFG_REMAPPinConfig()
          
         2. To remap the DMA channels of ADC1 and TIM4, use SYSCFG_REMAPDMAChannelConfig()

@endverbatim
  * @{
  */

/**
  * @brief  Deinitializes the Remapping registers to their default reset values.
  * @param  None
  * @retval None
  */
void SYSCFG_REMAPDeInit(void)
{
  /*!< Set RMPCR1 to reset value */
  SYSCFG->RMPCR1 = SYSCFG_RMPCR1_RESET_VALUE;

  /*!< Set RMPCR2 to reset value */
  SYSCFG->RMPCR2 = SYSCFG_RMPCR2_RESET_VALUE;

  /*!< Set RMPCR3 to reset value */
  SYSCFG->RMPCR3 = SYSCFG_RMPCR3_RESET_VALUE;
}

/**
  * @brief  Changes the mapping of the specified pins.
  * @param  REMAP_Pin: selects the pin to remap.
  *          This parameter can be one of the following values:
  *            @arg REMAP_Pin_USART1TxRxPortA: USART1 Tx- Rx (PC3- PC2) remapping to PA2- PA3
  *            @arg REMAP_Pin_USART1TxRxPortC: USART1 Tx- Rx (PC3- PC2) remapping to PC5- PC6 
  *            @arg REMAP_Pin_USART1Clk: USART1 CK (PC4) remapping to PA0
  *            @arg REMAP_Pin_SPI1Full: SPI1 MISO- MOSI- SCK- NSS(PB7- PB6- PB5- PB4)
  *                                     remapping to PA2- PA3- PC6- PC5
  *            @arg REMAP_Pin_ADC1ExtTRIG1: ADC1 External Trigger 1 (PA6) remapping to PD0
  *            @arg REMAP_Pin_TIM2TRIGPortA: TIM2 Trigger (PB3) remapping to PA4
  *            @arg REMAP_Pin_TIM3TRIGPortA: TIM3 Trigger (PD1) remapping to PA5
  *            @arg REMAP_Pin_TIM2TRIGLSE: TIM2 Trigger remapping to LSE
  *            @arg REMAP_Pin_TIM3TRIGLSE: TIM3 Trigger remapping to LSE
  *            @arg REMAP_Pin_SPI2Full: SPI2 MISO- MOSI- SCK- NSS(PG7- PG6- PG5- PG4)
  *                                     remapping to PI3- PI2- PI1- PI0
  *            @arg REMAP_Pin_TIM3TRIGPortG: TIM3 Trigger (PD1) remapping to PG3
  *            @arg REMAP_Pin_TIM23BKIN: TIM2 Break Input (PA4) remapping to PG0
  *                                      and TIM3 Break Input (PA5) remapping to PG1
  *            @arg REMAP_Pin_SPI1PortF: SPI1 MISO- MOSI- SCK- NSS(PB7- PB6- PB5- PB4)
  *                                      remapping to PF0- PF1- PF2- PF3
  *            @arg REMAP_Pin_USART3TxRxPortF: USART3 Tx- Rx (PG1- PG0) remapping to PF0- PF1
  *            @arg REMAP_Pin_USART3Clk: USART3 CK (PG2) remapping to PF2
  *            @arg REMAP_Pin_TIM3Channel1: TIM3 Channel 1 (PB1) remapping to PI0 
  *            @arg REMAP_Pin_TIM3Channel2: TIM3 Channel 2 (PD0) remapping to PI3
  *            @arg REMAP_Pin_CCO: CCO (PC4) remapping to PE2
  *            @arg REMAP_Pin_TIM2Channel1: TIM2 Channel 1 (PB0) remapping to PC5
  *            @arg REMAP_Pin_TIM2Channel2: TIM2 Channel 2 (PB2) remapping to PC6                                       
  * @param  NewState: This parameter can be ENABLE or DISABLE.
  * @retval None
  */
void SYSCFG_REMAPPinConfig(REMAP_Pin_TypeDef REMAP_Pin, FunctionalState NewState)
{
  uint8_t regindex = 0;
  /* Check the parameters */
  assert_param(IS_REMAP_PIN(REMAP_Pin));
  assert_param(IS_FUNCTIONAL_STATE(NewState));

  /* Read register index */
  regindex = (uint8_t) ((uint16_t) REMAP_Pin >> 8);

  /* Check if REMAP_Pin is in RMPCR1 register */
  if (regindex == 0x01)
  {
    SYSCFG->RMPCR1 &= (uint8_t)((uint8_t)((uint8_t)REMAP_Pin << 4) | (uint8_t)0x0F);
    if (NewState != DISABLE)
    {
      SYSCFG->RMPCR1 |= (uint8_t)((uint16_t)REMAP_Pin & (uint16_t)0x00F0);
    }
  }
  /* Check if REMAP_Pin is in RMPCR2 register */
  else if (regindex == 0x02)
  {
    if (NewState != DISABLE)
    {
      SYSCFG->RMPCR2 |= (uint8_t) REMAP_Pin;
    }
    else
    {
      SYSCFG->RMPCR2 &= (uint8_t)((uint16_t)(~(uint16_t)REMAP_Pin));
    }
  }
  /* REMAP_Pin is in RMPCR3 register */
  else
  {
    if (NewState != DISABLE)
    {
      SYSCFG->RMPCR3 |= (uint8_t) REMAP_Pin;
    }
    else
    {
      SYSCFG->RMPCR3 &= (uint8_t)((uint16_t)(~(uint16_t)REMAP_Pin));
    }
  }
}

/**
  * @brief  Remaps the DMA Channel to the specific peripheral (ADC or TIM4)
  * @param  REMAP_DMAChannel: specifies the DMA Channel to remap.
  *          This parameter can be one of the following values:
  *            @arg REMAP_DMA1Channel_ADC1ToChannel0: ADC1 DMA1 req/ack mapped on DMA1 channel 0
  *            @arg REMAP_DMA1Channel_ADC1ToChannel1: ADC1 DMA1 req/ack mapped on DMA1 channel 1
  *            @arg REMAP_DMA1Channel_ADC1ToChannel2: ADC1 DMA1 req/ack mapped on DMA1 channel 2
  *            @arg REMAP_DMA1Channel_ADC1ToChannel3: ADC1 DMA1 req/ack mapped on DMA1 channel 3
  *            @arg REMAP_DMA1Channel_TIM4ToChannel0: TIM4 DMA1 req/ack mapped on DMA1 channel 0
  *            @arg REMAP_DMA1Channel_TIM4ToChannel1: TIM4 DMA1 req/ack mapped on DMA1 channel 1
  *            @arg REMAP_DMA1Channel_TIM4ToChannel2: TIM4 DMA1 req/ack mapped on DMA1 channel 2
  *            @arg REMAP_DMA1Channel_TIM4ToChannel3: TIM4 DMA1 req/ack mapped on DMA1 channel 3              
  * @retval None
  */
void SYSCFG_REMAPDMAChannelConfig(REMAP_DMAChannel_TypeDef REMAP_DMAChannel)
{
  /* Check the parameters */
  assert_param(IS_REMAP_DMACHANNEL(REMAP_DMAChannel));

  /* Check if the TIM4 DMA channel is selected: bits 4 --> 7 are set */
  if ((REMAP_DMAChannel & 0xF0) != RESET)
  {
    /* Reset the TIM4 DMA channels */
    SYSCFG->RMPCR1 &= (uint8_t) (~SYSCFG_RMPCR1_TIM4DMA_REMAP);
  }
  /* ADC DMA channel is selected: bits 4 --> 7 are reset */
  else
  {
    /* Reset the ADC DMA channels */
    SYSCFG->RMPCR1 &= (uint8_t) (~SYSCFG_RMPCR1_ADC1DMA_REMAP);
  }
  /* Set the DMA Channels remapping */
  SYSCFG->RMPCR1 |= (uint8_t) ((uint8_t)0x0F & REMAP_DMAChannel);
}

/**
  * @}
  */ 

/**
  * @}
  */ 
  
/**
  * @}
  */

/**
  * @}
  */

/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/

⌨️ 快捷键说明

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