PS2摇杆问题未解决
This commit is contained in:
parent
48ba6d81fb
commit
a3f4581804
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -674,7 +674,7 @@
|
|||
<GroupNumber>4</GroupNumber>
|
||||
<FileNumber>37</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\User\PS2\bsp_PS2.c</PathWithFileName>
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
<TargetCommonOption>
|
||||
<Device>STM32F103VE</Device>
|
||||
<Vendor>STMicroelectronics</Vendor>
|
||||
<PackID>Keil.STM32F1xx_DFP.2.1.0</PackID>
|
||||
<PackID>Keil.STM32F1xx_DFP.2.0.0</PackID>
|
||||
<PackURL>http://www.keil.com/pack/</PackURL>
|
||||
<Cpu>IRAM(0x20000000,0x10000) IROM(0x08000000,0x80000) CPUTYPE("Cortex-M3") CLOCK(12000000) ELITTLE</Cpu>
|
||||
<FlashUtilSpec></FlashUtilSpec>
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "bsp_PS2.h"
|
||||
|
||||
|
||||
|
||||
#define MeasurementRange 30
|
||||
|
||||
/*
|
||||
|
@ -199,18 +200,19 @@ void Key_Scan(void* parameter)
|
|||
queue_status = rt_mq_recv(key_scan_queue, &recv_data, sizeof(recv_data), RT_WAITING_FOREVER);
|
||||
if(queue_status == RT_EOK && recv_data == 1)
|
||||
{
|
||||
setting_data = Read_X_Data(PS2_X_PORT, PS2_X_PIN);
|
||||
setting_data = Read_X_Data();
|
||||
if(setting_data == 1)
|
||||
setting_data = 1;
|
||||
else if(setting_data == 0)
|
||||
setting_data = 2;
|
||||
|
||||
setting_data = Read_Y_Data(PS2_Y_PORT, PS2_Y_PIN);
|
||||
setting_data = Read_Y_Data();
|
||||
if(setting_data == 1)
|
||||
setting_data = 3;
|
||||
else if(setting_data == 0)
|
||||
setting_data = 4;
|
||||
|
||||
rt_kprintf("key data: %d",setting_data);
|
||||
rt_mq_send(setting_data_queue, &setting_data, sizeof(setting_data));
|
||||
}
|
||||
}
|
||||
|
@ -226,11 +228,14 @@ void Run(void)
|
|||
key_scan_queue = rt_mq_create("key_scan_queue", 1, 1, RT_IPC_FLAG_FIFO);
|
||||
|
||||
/**********创建线程************/
|
||||
Setting_thread =
|
||||
rt_thread_create("Setting", Setting, RT_NULL, 512, 1, 20);
|
||||
Setting_thread = rt_thread_create("Setting", Setting, RT_NULL, 512, 1, 20);
|
||||
if (Setting_thread != RT_NULL)
|
||||
rt_thread_startup(Setting_thread);
|
||||
|
||||
KeyScan_thread = rt_thread_create("KeyScan", Key_Scan, RT_NULL, 512, 2, 20);
|
||||
if (KeyScan_thread != RT_NULL)
|
||||
rt_thread_startup(KeyScan_thread);
|
||||
|
||||
GetWave_thread = /* 线程控制块指针 */
|
||||
rt_thread_create( "GetWave", /* 线程名字 */
|
||||
ADCx_GetWaveData, /* 线程入口函数 */
|
||||
|
@ -250,10 +255,6 @@ void Run(void)
|
|||
20); /* 线程时间片 */
|
||||
if (PlotWave_thread != RT_NULL)
|
||||
rt_thread_startup(PlotWave_thread);
|
||||
|
||||
KeyScan_thread = rt_thread_create("KeyScan", Key_Scan, RT_NULL, 512, 2, 20);
|
||||
if(KeyScan_thread != RT_NULL)
|
||||
rt_thread_startup(KeyScan_thread);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ static void EXTI_NVIC_Config(void)
|
|||
NVIC_Init(&NVIC_InitStruct);
|
||||
}
|
||||
|
||||
static void PS2_Key_Config(void)
|
||||
void PS2_Key_Config(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
EXTI_InitTypeDef EXTI_InitStruct;
|
||||
|
@ -30,13 +30,11 @@ static void PS2_Key_Config(void)
|
|||
//³õʼ»¯SW
|
||||
GPIO_InitStruct.GPIO_Pin = PS2_SW_PIN;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(PS2_SW_PORT, &GPIO_InitStruct);
|
||||
|
||||
//³õʼ»¯X
|
||||
GPIO_InitStruct.GPIO_Pin = PS2_X_PIN;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(PS2_X_PORT, &GPIO_InitStruct);
|
||||
|
||||
//³õʼ»¯Y
|
||||
|
@ -57,13 +55,17 @@ static void PS2_Key_Config(void)
|
|||
EXTI_Init(&EXTI_InitStruct);
|
||||
}
|
||||
|
||||
uint8_t Read_X_Data(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
|
||||
uint8_t Read_X_Data(void)
|
||||
{
|
||||
return GPIO_ReadInputDataBit(PS2_X_PORT, PS2_X_PIN);
|
||||
}
|
||||
|
||||
uint8_t Read_Y_Data(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
|
||||
uint8_t Read_Y_Data(void)
|
||||
{
|
||||
return GPIO_ReadInputDataBit(PS2_Y_PORT, PS2_Y_PIN);
|
||||
}
|
||||
|
||||
uint8_t Read_SW_Data(void)
|
||||
{
|
||||
return GPIO_ReadInputDataBit(PS2_SW_PORT, PS2_SW_PIN);
|
||||
}
|
||||
|
|
|
@ -7,17 +7,18 @@
|
|||
#define PS2_SW_PORT GPIOA
|
||||
#define PS2_SW_CLK RCC_APB2Periph_GPIOA
|
||||
|
||||
#define PS2_X_PIN GPIO_Pin_5
|
||||
#define PS2_X_PIN GPIO_Pin_14
|
||||
#define PS2_X_PORT GPIOB
|
||||
#define PS2_X_CLK RCC_APB2Periph_GPIOB
|
||||
|
||||
#define PS2_Y_PIN GPIO_Pin_6
|
||||
#define PS2_Y_PIN GPIO_Pin_15
|
||||
#define PS2_Y_PORT GPIOB
|
||||
#define PS2_Y_CLK RCC_APB2Periph_GPIOB
|
||||
|
||||
|
||||
uint8_t Read_X_Data(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
|
||||
uint8_t Read_Y_Data(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
|
||||
void PS2_Key_Config(void);
|
||||
uint8_t Read_X_Data(void);
|
||||
uint8_t Read_Y_Data(void);
|
||||
uint8_t Read_SW_Data(void);
|
||||
|
||||
#endif /* __bsp_PS2_H */
|
||||
|
||||
|
|
16
User/board.c
16
User/board.c
|
@ -1,14 +1,27 @@
|
|||
/* 开发板硬件相关头文件 */
|
||||
/*
|
||||
*************************************************************************
|
||||
* 包含的头文件
|
||||
*************************************************************************
|
||||
*/
|
||||
/* STM32 固件库头文件 */
|
||||
#include "stm32f10x.h"
|
||||
|
||||
/* 开发板硬件bsp头文件 */
|
||||
#include "board.h"
|
||||
#include "bsp_ili9341_lcd.h"
|
||||
#include "bsp_adc.h"
|
||||
#include "bsp_TiMbase.h"
|
||||
#include "bsp_led.h"
|
||||
#include "bsp_usart.h"
|
||||
#include "bsp_key_exti.h"
|
||||
#include "bsp_PS2.h"
|
||||
|
||||
/* RT-Thread相关头文件 */
|
||||
#include <rthw.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
|
||||
|
||||
#if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
|
||||
#define RT_HEAP_SIZE 1024
|
||||
/* 从内部SRAM里面分配一部分静态内存来作为rtt的堆空间,这里配置为4KB */
|
||||
|
@ -45,6 +58,7 @@ void rt_hw_board_init()
|
|||
USART_Config();
|
||||
ADCx_Init();
|
||||
EXTI_Key_Config();
|
||||
PS2_Key_Config();
|
||||
BASIC_TIM_Init();
|
||||
|
||||
//其中0、3、5、6 模式适合从左至右显示文字,
|
||||
|
|
11
User/board.h
11
User/board.h
|
@ -1,18 +1,7 @@
|
|||
#ifndef __BOARD_H__
|
||||
#define __BOARD_H__
|
||||
|
||||
/*
|
||||
*************************************************************************
|
||||
* 包含的头文件
|
||||
*************************************************************************
|
||||
*/
|
||||
/* STM32 固件库头文件 */
|
||||
#include "stm32f10x.h"
|
||||
|
||||
/* 开发板硬件bsp头文件 */
|
||||
#include "bsp_led.h"
|
||||
#include "bsp_usart.h"
|
||||
#include "bsp_key_exti.h"
|
||||
|
||||
/*
|
||||
*************************************************************************
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
#include "OSC.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "bsp_led.h"
|
||||
|
||||
|
||||
volatile uint32_t Time_us = 0; // us 计时变量
|
||||
|
||||
|
@ -41,8 +43,9 @@ void BASIC_TIM_IRQHandler (void)
|
|||
*/
|
||||
void EXTI2_IRQnHandler(void)
|
||||
{
|
||||
if(EXTI_GetFlagStatus(EXTI_Line2) != RESET)
|
||||
if(EXTI_GetITStatus(EXTI_Line2) != RESET)
|
||||
{
|
||||
LED1_ON;
|
||||
rt_interrupt_enter();
|
||||
rt_mq_send(setting_data_queue,
|
||||
&setting_data_set,
|
||||
|
|
Loading…
Reference in New Issue