oscilloscope/User/PS2/bsp_PS2.c

62 lines
1.4 KiB
C

#include "stm32f10x_gpio.h"
#include "bsp_PS2.h"
#include "bsp_adc.h"
//X和Y的配置在ADC中
static void EXTI_NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStruct;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
//配置PS2的SW中断
NVIC_InitStruct.NVIC_IRQChannel = EXTI2_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);
}
void PS2_Key_Config(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
EXTI_InitTypeDef EXTI_InitStruct;
//配置中断优先级
EXTI_NVIC_Config();
//初始化GPIO
RCC_APB2PeriphClockCmd(PS2_SW_CLK, ENABLE);
//初始化SW
GPIO_InitStruct.GPIO_Pin = PS2_SW_PIN;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(PS2_SW_PORT, &GPIO_InitStruct);
//初始化EXTI
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource2);
//初始化SW中断
EXTI_InitStruct.EXTI_Line = EXTI_Line2;
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStruct);
}
uint8_t Read_X_Data(void)
{
return Get_X_Data();
}
uint8_t Read_Y_Data(void)
{
return Get_Y_Data();
}
uint8_t Read_SW_Data(void)
{
return GPIO_ReadInputDataBit(PS2_SW_PORT, PS2_SW_PIN);
}