void Hw_Input_Chage_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_IOMUX, ENABLE);
GPIOMUX->NRST_PIN_KEY = (uint32_t)(0x00005AE1); //KEY
GPIOMUX->PKG_PIN_SEL &= (uint32_t)(0xFFFFFF00); //NRSTPA0_PIN_SEL = 0
GPIOMUX->NRST_PIN_KEY = (uint32_t)(0x00005AE1); //KEY
GPIOMUX->NRST_PA0_SEL |= (uint32_t)(0x00000007); //bit0:NRST 1 PA0 bit1-2:SWCLK 11 PB5 bit5-6:SWDIO 00 PD5
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; //引脚输入模式
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_2;
GPIO_InitStructure.GPIO_Schmit = GPIO_Schmit_Disable;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //内部上拉
//NRST --> PA0
//GPIO_IOMUX_ChangePin(IOMUX_PIN2, IOMUX_NRST_SEL_NRST);// TSSOP16 PIN2(NRST)PA0 IO IOMUX_NRST_SEL_NRST IOMUX_NRST_SEL_PA0
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void Hw_Key_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
//SWCLK PB5 as GPIO
//GPIO_IOMUX_ChangePin(IOMUX_PIN11, IOMUX_PB5_SEL_PB5); //TSSOP20PIN11(PD5)PB5 IO
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; //引脚输入模式
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_2;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //内部上拉
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* 配置EXTI */
EXTI_InitStructure.EXTI_Line = EXTI_Line5;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource5);
EXTI_ClearITPendingBit(EXTI_Line5);
NVIC_InitStructure.NVIC_IRQChannel = EXTI5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
//SWCLK
unsigned char Hw_Key_Get_Power_Key_Value(void)
{
return GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_5);
}
unsigned char g_temp = 0;
void EXTI5_IRQHandler(void)
{
if(EXTI_GetFlagStatus(EXTI_Line5) != RESET)
{
g_temp = !g_temp;
if(g_temp)
Hw_Led_Green_Enable();
else
Hw_Led_Green_Disable();
EXTI_ClearITPendingBit(EXTI_Line5);
}
}
|