📄 stm32l1xx_syscfg.c
字号:
/* Clear the input capture select bits */
tmpreg &= (uint32_t)(~(IC_ROUTING_MASK << 12));
/* Set RI_InputCaptureRouting bits */
tmpreg |= (uint32_t)( (RI_InputCaptureRouting << 12));
}
/* Write to RI->ICR register */
RI->ICR = tmpreg;
}
/**
* @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 resistor.
* @arg RI_Resistor_400KPU: 400K pull-up resistor.
* @arg RI_Resistor_10KPD: 10K pull-down resistor.
* @arg RI_Resistor_400KPD: 400K pull-down resistor.
* @param NewState: New state of the analog switch associated to the selected
* resistor.
* This parameter can be:
* ENABLE so the selected resistor is connected
* or DISABLE so the selected resistor is disconnected.
* @note To avoid extra power consumption, only one resistor should be enabled
* at a time.
* @retval None
*/
void SYSCFG_RIResistorConfig(uint32_t 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 */
COMP->CSR |= (uint32_t) RI_Resistor;
}
else
{
/* Disable the Resistor */
COMP->CSR &= (uint32_t) (~RI_Resistor);
}
}
/**
* @brief Configures the ADC channels speed.
* @param RI_Channel selects the channel.
* This parameter can be one of the following values:
* @arg RI_Channel_3: Channel 3 is selected.
* @arg RI_Channel_8: Channel 8 is selected.
* @arg RI_Channel_13: Channel 13 is selected.
* @param RI_ChannelSpeed: The speed of the selected ADC channel
* This parameter can be:
* RI_ChannelSpeed_Fast: The selected channel is a fast ADC channel
* or RI_ChannelSpeed_Slow: The selected channel is a slow ADC channel.
* @retval None
*/
void SYSCFG_RIChannelSpeedConfig(uint32_t RI_Channel, uint32_t RI_ChannelSpeed)
{
/* Check the parameters */
assert_param(IS_RI_CHANNEL(RI_Channel));
assert_param(IS_RI_CHANNELSPEED(RI_ChannelSpeed));
if(RI_ChannelSpeed != RI_ChannelSpeed_Fast)
{
/* Set the selected channel as a slow ADC channel */
COMP->CSR &= (uint32_t) (~RI_Channel);
}
else
{
/* Set the selected channel as a fast ADC channel */
COMP->CSR |= (uint32_t) (RI_Channel);
}
}
/**
* @brief Close or Open the routing interface Input Output switches.
* @param RI_IOSwitch: selects the I/O analog switch number.
* This parameter can be one of the following values:
* @param RI_IOSwitch_CH0 --> RI_IOSwitch_CH15.
* @param RI_IOSwitch_CH18 --> RI_IOSwitch_CH25.
* @param RI_IOSwitch_GR10_1 --> RI_IOSwitch_GR10_4.
* @param RI_IOSwitch_GR6_1 --> RI_IOSwitch_GR6_2.
* @param RI_IOSwitch_GR5_1 --> RI_IOSwitch_GR5_3.
* @param RI_IOSwitch_GR4_1 --> RI_IOSwitch_GR4_3.
* @param RI_IOSwitch_VCOMP
* RI_IOSwitch_CH27
* @param RI_IOSwitch_CH28 --> RI_IOSwitch_CH30
* @param RI_IOSwitch_GR10_1 --> RI_IOSwitch_GR10_4
* @param RI_IOSwitch_GR6_1
* @param RI_IOSwitch_GR6_2
* @param RI_IOSwitch_GR5_1 --> RI_IOSwitch_GR5_3
* @param RI_IOSwitch_GR4_1 --> RI_IOSwitch_GR4_4
* @param RI_IOSwitch_CH0b --> RI_IOSwitch_CH3b
* @param RI_IOSwitch_CH6b --> RI_IOSwitch_CH12b
* @param RI_IOSwitch_GR6_3
* @param RI_IOSwitch_GR6_4
* @param RI_IOSwitch_GR5_4
* @param NewState: New state of the analog switch.
* This parameter can be
* ENABLE so the Input Output switch is closed
* or DISABLE so the Input Output switch is open.
* @retval None
*/
void SYSCFG_RIIOSwitchConfig(uint32_t RI_IOSwitch, FunctionalState NewState)
{
uint32_t ioswitchmask = 0;
/* Check the parameters */
assert_param(IS_RI_IOSWITCH(RI_IOSwitch));
/* Read Analog switch register index */
ioswitchmask = RI_IOSwitch >> 31;
/* Get Bits[30:0] of the IO switch */
RI_IOSwitch &= 0x7FFFFFFF;
if (NewState != DISABLE)
{
if (ioswitchmask != 0)
{
/* Close the analog switches */
RI->ASCR1 |= RI_IOSwitch;
}
else
{
/* Open the analog switches */
RI->ASCR2 |= RI_IOSwitch;
}
}
else
{
if (ioswitchmask != 0)
{
/* Close the analog switches */
RI->ASCR1 &= (~ (uint32_t)RI_IOSwitch);
}
else
{
/* Open the analog switches */
RI->ASCR2 &= (~ (uint32_t)RI_IOSwitch);
}
}
}
/**
* @brief Enable or disable the switch control mode.
* @param NewState: New state of the switch control mode. This parameter can
* be ENABLE: ADC analog switches closed if the corresponding
* I/O switch is also closed.
* When using COMP1, switch control mode must be enabled.
* or DISABLE: ADC analog switches open or controlled by the ADC interface.
* When using the ADC for acquisition, switch control mode
* must be disabled.
* @note COMP1 comparator and ADC cannot be used at the same time since
* they share the ADC switch matrix.
* @retval None
*/
void SYSCFG_RISwitchControlModeCmd(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(NewState));
if (NewState != DISABLE)
{
/* Enable the Switch control mode */
RI->ASCR1 |= (uint32_t) RI_ASCR1_SCM;
}
else
{
/* Disable the Switch control mode */
RI->ASCR1 &= (uint32_t)(~RI_ASCR1_SCM);
}
}
/**
* @brief Enable or disable Hysteresis of the input schmitt triger of Ports A..E
* When the I/Os are programmed in input mode by standard I/O port
* registers, the Schmitt trigger and the hysteresis are enabled by default.
* When hysteresis is disabled, it is possible to read the
* corresponding port with a trigger level of VDDIO/2.
* @param RI_Port: selects the GPIO Port.
* This parameter can be one of the following values:
* @arg RI_PortA: Port A is selected
* @arg RI_PortB: Port B is selected
* @arg RI_PortC: Port C is selected
* @arg RI_PortD: Port D is selected
* @arg RI_PortE: Port E is selected
* @arg RI_PortF: Port F is selected
* @arg RI_PortG: Port G is selected
* @param RI_Pin : Selects the pin(s) on which to enable or disable hysteresis.
* This parameter can any value from RI_Pin_x where x can be (0..15) or RI_Pin_All.
* @param NewState new state of the Hysteresis.
* This parameter can be:
* ENABLE so the Hysteresis is on
* or DISABLE so the Hysteresis is off
* @retval None
*/
void SYSCFG_RIHysteresisConfig(uint8_t RI_Port, uint16_t RI_Pin,
FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_RI_PORT(RI_Port));
assert_param(IS_RI_PIN(RI_Pin));
assert_param(IS_FUNCTIONAL_STATE(NewState));
if(RI_Port == RI_PortA)
{
if (NewState != DISABLE)
{
/* Hysteresis on */
RI->HYSCR1 &= (uint32_t)~((uint32_t)RI_Pin);
}
else
{
/* Hysteresis off */
RI->HYSCR1 |= (uint32_t) RI_Pin;
}
}
else if(RI_Port == RI_PortB)
{
if (NewState != DISABLE)
{
/* Hysteresis on */
RI->HYSCR1 &= (uint32_t) (~((uint32_t)RI_Pin) << 16);
}
else
{
/* Hysteresis off */
RI->HYSCR1 |= (uint32_t) ((uint32_t)(RI_Pin) << 16);
}
}
else if(RI_Port == RI_PortC)
{
if (NewState != DISABLE)
{
/* Hysteresis on */
RI->HYSCR2 &= (uint32_t) (~((uint32_t)RI_Pin));
}
else
{
/* Hysteresis off */
RI->HYSCR2 |= (uint32_t) (RI_Pin );
}
}
else if(RI_Port == RI_PortD)
{
if (NewState != DISABLE)
{
/* Hysteresis on */
RI->HYSCR2 &= (uint32_t) (~((uint32_t)RI_Pin) << 16);
}
else
{
/* Hysteresis off */
RI->HYSCR2 |= (uint32_t) ((uint32_t)(RI_Pin) << 16);
}
}
else if(RI_Port == RI_PortE)
{
if (NewState != DISABLE)
{
/* Hysteresis on */
RI->HYSCR3 &= (uint32_t) (~((uint32_t)RI_Pin));
}
else
{
/* Hysteresis off */
RI->HYSCR3 |= (uint32_t) (RI_Pin );
}
}
else if(RI_Port == RI_PortF)
{
if (NewState != DISABLE)
{
/* Hysteresis on */
RI->HYSCR3 &= (uint32_t) (~((uint32_t)RI_Pin) << 16);
}
else
{
/* Hysteresis off */
RI->HYSCR3 |= (uint32_t) ((uint32_t)(RI_Pin) << 16);
}
}
else /* RI_Port == RI_PortG */
{
if (NewState != DISABLE)
{
/* Hysteresis on */
RI->HYSCR4 &= (uint32_t) (~((uint32_t)RI_Pin));
}
else
{
/* Hysteresis off */
RI->HYSCR4 |= (uint32_t) (RI_Pin);
}
}
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/******************* (C) COPYRIGHT 2012 STMicroelectronics *****END OF FILE****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -