##include
#include
#define TOUCH_DOWNDELAYCOUNT 4
#define TOUCH_UPDELAYCOUNT 10
uint8 Touch_Update;
uint8 TOUCH_Tos_TaskID;
_Touch_Event Touch_Event;
const uint16 TOUCH_CROSS_ADDR[5][2]={
{TOUCH_CROSS_GAUGE,TOUCH_CROSS_GAUGE},//左上角校准点位置
{LCD_XSIZE-TOUCH_CROSS_GAUGE,TOUCH_CROSS_GAUGE},//右上角校准点位置
{LCD_XSIZE-TOUCH_CROSS_GAUGE,LCD_YSIZE-TOUCH_CROSS_GAUGE},//右下角校准点位置
{TOUCH_CROSS_GAUGE,LCD_YSIZE-TOUCH_CROSS_GAUGE},//左下角校准点位置
{LCD_XSIZE/2,LCD_YSIZE/2}//中间校准点位置
};
volatile uint16 TOUCH_ADC_Value[TOUCH_ADC_BUFSize][TOUCH_ADC_CHN]; //触摸屏ADC采集池
uint16 TOUCH_ADC_XValue,TOUCH_ADC_YValue;//触摸屏ADC模数值
void Touch_ADCY_Config()
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//强拉接地
GPIO_Init(GPIOC, &GPIO_InitStructure);
PCout(5)=0;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;//强拉接VCC
GPIO_Init(GPIOB, &GPIO_InitStructure);
PBout(1)=1;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode =GPIO_Mode_IPD;//上拉输入
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;//模拟输入
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void Touch_ADCX_Config()
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
PCout(4)=0;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_Init(GPIOB, &GPIO_InitStructure);
PBout(0)=1;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;//上拉输入
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;//模拟输入
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void Touch_UpIngEvent()
{
if(Touch_Event.UpIng_Event)
{
DeBug("TOUCH_EVENT_UPING");
Touch_Event.UpIng_Event=Null;
}
}
void Touch_DownIngEvent()
{
if(Touch_Event.DownIng_Event)
{
DeBug("TOUCH_EVENT_DOWNING");
Touch_Event.DownIng_Event=Null;
}
}
void Touch_UpDelayEvent()
{
if(Touch_Event.Up_Event)
{
DeBug("TOUCH_EVENT_UP");
Touch_Event.Up_Event=Null;
}
}
void Touch_DownDelayEvent()
{
if(Touch_Event.Down_Event)
{
DeBug("TOUCH_EVENT_DOWN");
Touch_Event.Down_Event=Null;
}
}
void Task_GetTouch(void *Tags)
{
static uint32 Temp_ADC1,Temp_ADC2,Temp_ADC11;
TOUCH_Tos_TaskID=Tos_TaskCurrent;
while(1)
{
Tos_TaskDelay(100);
Touch_ADCX_Config();
Tos_TaskDelay(10);
Temp_ADC11=AvrFilter_ByWords((uint16 *)&TOUCH_ADC_Value[0][1],TOUCH_ADC_BUFSize,TOUCH_ADC_BUFSize);
if(Temp_ADC11>100)
{
Tos_TaskDelay(10);
Temp_ADC1=AvrFilter_ByWords((uint16 *)&TOUCH_ADC_Value[0][1],TOUCH_ADC_BUFSize,TOUCH_ADC_BUFSize);
Touch_ADCY_Config();
Tos_TaskDelay(10);
Temp_ADC2=AvrFilter_ByWords((uint16 *)&TOUCH_ADC_Value[0][0],TOUCH_ADC_BUFSize,TOUCH_ADC_BUFSize);
if(__fabs(Temp_ADC11-Temp_ADC1)<20&Temp_ADC2>400)//消抖
{
SPK_ON;
TOUCH_ADC_YValue=Temp_ADC2;
TOUCH_ADC_XValue=Temp_ADC1;
if(Touch_Update==TOUCH_DOWNING){Touch_Update=TOUCH_DOWN;}
if(Touch_Update!=TOUCH_DOWN)
{
Touch_Update=TOUCH_DOWNING;
Touch_Event.DownIng_Event=Touch_DownIngEvent;
Touch_Event.Down_Event=Touch_DownDelayEvent;
if(Touch_Event.DownIng_Event)Touch_Event.DownIng_Event();//当存在按下事件时触发
Touch_Event.UpIng_Event=Touch_UpIngEvent;//事件测试
Touch_Event.DownDelay_Count=0;
}
if(Touch_Update==TOUCH_DOWN)
{
if(Touch_Event.DownDelay_Count
{
Touch_Event.DownDelay_Count++;
}else if(Touch_Event.Down_Event)Touch_Event.Down_Event();//当存在持续按下事件时触发
}
SPK_OFF;
DeBug("X=%d Y=%d",TOUCH_ADC_XValue,TOUCH_ADC_YValue);
}
}else
{
if(Touch_Update==TOUCH_UPING){Touch_Update=TOUCH_UP;}
if(Touch_Update!=TOUCH_UP)//触摸屏第一次按下触发
{
Touch_Update=TOUCH_UPING;
if(Touch_Event.UpIng_Event)Touch_Event.UpIng_Event();//当存在放下动作时触发
Touch_Event.UpDelay_Count=0;//按下第一次时清除按下时间计数
Touch_Event.Up_Event=Touch_UpDelayEvent;//事件测试
}
if(Touch_Update==TOUCH_UP)//触摸屏一直按下
{
if(Touch_Event.UpDelay_Count
{
Touch_Event.UpDelay_Count++;
}else if(Touch_Event.Up_Event)Touch_Event.Up_Event();//当存在持续未按下触发
}
}
}
}
void Touch_ADC1_Configuration(void)
{
ADC_InitTypeDef ADC_InitStructure;
ADC_DeInit(ADC1); //将外设 ADC1 的全部寄存器重设为缺省值
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; //ADC工作模式:ADC1和ADC2工作在独立模式
ADC_InitStructure.ADC_ScanConvMode =ENABLE; //模数转换工作在扫描模式
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; //模数转换工作在连续转换模式
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; //外部触发转换关闭
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //ADC数据右对齐
ADC_InitStructure.ADC_NbrOfChannel =TOUCH_ADC_CHN; //顺序进行规则转换的ADC通道的数目
ADC_Init(ADC1, &ADC_InitStructure); //根据ADC_InitStruct中指定的参数初始化外设ADCx的寄存器
ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 2, ADC_SampleTime_239Cycles5);
ADC_Cmd(ADC1, ENABLE); //使能指定的ADC1
ADC_ResetCalibration(ADC1); //复位指定的ADC1的校准寄存器
while(ADC_GetResetCalibrationStatu s(ADC1)); //获取ADC1复位校准寄存器的状态,设置状态则等待
ADC_StartCalibration(ADC1); //开始指定ADC1的校准状态
while(ADC_GetCalibrationStatus(ADC1)); //获取指定ADC1的校准程序,设置状态则等待
}
void Touch_DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure;
DMA_DeInit(DMA1_Channel1); //将DMA的通道1寄存器重设为缺省值
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&ADC1->DR; //DMA外设ADC基地址
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&TOUCH_ADC_Value; //DMA内存基地址
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; //内存作为数据传输的目的地
DMA_InitStructure.DMA_BufferSize = TOUCH_ADC_BUFSize*TOUCH_ADC_CHN; //DMA通道的DMA缓存的大小
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //外设地址寄存器不变
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //内存地址寄存器递增
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; //数据宽度为16位
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; //数据宽度为16位
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //工作在循环缓存模式
DMA_InitStructure.DMA_Priority = DMA_Priority_High; //DMA通道 x拥有高优先级
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //DMA通道x没有设置为内存到内存传输
DMA_Init(DMA1_Channel1, &DMA_InitStructure); //根据DMA_InitStruct中指定的参数初始化DMA的通道
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
DMA_Cmd(DMA1_Channel1, ENABLE);
DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE);
ADC_DMACmd(ADC1, ENABLE);
}
void Touch_ADC_Init()
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOB, ENABLE);
Touch_ADC1_Configuration();
Touch_DMA_Configuration();
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
DMA_Cmd(DMA1_Channel1, ENABLE);
Touch_Event.UpIng_Event=Null;
Touch_Event.Up_Event=Null;
Touch_Event.DownIng_Event=Null;
Touch_Event.Down_Event=Null;
Touch_Event.UpDelay_Count=0;//延迟周期数后执行延迟任务
Touch_Event.DownDelay_Count=0;//延迟周期数后执行延迟任务
}
void DeviceMount_Touch()
{
_Tos_Device_Tab[DeviceId_TOUCH].DeviceId=DeviceId_TOUCH;
_Tos_Device_Tab[DeviceId_TOUCH].DeviceName="TOUCH";
_Tos_Device_Tab[DeviceId_TOUCH].DeviceOwnerId=Null;
_Tos_Device_Tab[DeviceId_TOUCH].DeviceVirtue=ReadOnly|WriteOnly|CharDerice;
_Tos_Device_Tab[DeviceId_TOUCH].DeviceState=NotBusy;
_Tos_Device_Tab[DeviceId_TOUCH].Init=Touch_ADC_Init;
_Tos_Device_Tab[DeviceId_TOUCH].Write=Null;
_Tos_Device_Tab[DeviceId_TOUCH].Read=Null;
_Tos_Device_Tab[DeviceId_TOUCH].Exit=Null;
}
void TouchScreen_DrawCross(uint16 X0,uint16 Y0,uint16 R,uint16 FColor)
{
TGui_Draw_Line(X0-R,Y0,X0+R,Y0,FColor);
TGui_Draw_Line(X0,Y0-R,X0,Y0+R,FColor);
}
void TouchScreen_GetTouch(uint16 *VX,uint16 *VY)
{
uint16 X_BUF[4];
uint16 Y_BUF[10];
uint8 i;
while(1)
{
Tos_TaskDelay(10);
if(Touch_Update==TOUCH_DOWN)
{
*VX=TOUCH_ADC_XValue;
// *VY=TOUCH_ADC_YValue;
return;
while(1)
{
if(Touch_Update==TOUCH_UP)return;
Tos_TaskDelay(10);
}
}
}
}
void TouchScreen_Correct()
{
int8 i;
uint16 X,Y;
for(i=0;i<5;i++)
{
LCD_Clear_Screen(Color_Black);
TouchScreen_DrawCross(TOUCH_CROSS_ADDR[i][0],TOUCH_CROSS_ADDR[i][1],TOUCH_CROSS_SIZE,Color_White);
TouchScreen_GetTouch(&X,&Y);
DeBug("nihao");
Tos_TaskDelay(1000);
}
}
#include
#define TOUCH_DOWNDELAYCOUNT 4
#define TOUCH_UPDELAYCOUNT 10
uint8 Touch_Update;
uint8 TOUCH_Tos_TaskID;
_Touch_Event Touch_Event;
const uint16 TOUCH_CROSS_ADDR[5][2]={
{TOUCH_CROSS_GAUGE,TOUCH_CROSS_GAUGE},//左上角校准点位置
{LCD_XSIZE-TOUCH_CROSS_GAUGE,TOUCH_CROSS_GAUGE},//右上角校准点位置
{LCD_XSIZE-TOUCH_CROSS_GAUGE,LCD_YSIZE-TOUCH_CROSS_GAUGE},//右下角校准点位置
{TOUCH_CROSS_GAUGE,LCD_YSIZE-TOUCH_CROSS_GAUGE},//左下角校准点位置
{LCD_XSIZE/2,LCD_YSIZE/2}//中间校准点位置
};
volatile uint16 TOUCH_ADC_Value[TOUCH_ADC_BUFSize][TOUCH_ADC_CHN]; //触摸屏ADC采集池
uint16 TOUCH_ADC_XValue,TOUCH_ADC_YValue;//触摸屏ADC模数值
void Touch_ADCY_Config()
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//强拉接地
GPIO_Init(GPIOC, &GPIO_InitStructure);
PCout(5)=0;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;//强拉接VCC
GPIO_Init(GPIOB, &GPIO_InitStructure);
PBout(1)=1;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode =GPIO_Mode_IPD;//上拉输入
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;//模拟输入
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void Touch_ADCX_Config()
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
PCout(4)=0;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_Init(GPIOB, &GPIO_InitStructure);
PBout(0)=1;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;//上拉输入
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;//模拟输入
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void Touch_UpIngEvent()
{
if(Touch_Event.UpIng_Event)
{
DeBug("TOUCH_EVENT_UPING");
Touch_Event.UpIng_Event=Null;
}
}
void Touch_DownIngEvent()
{
if(Touch_Event.DownIng_Event)
{
DeBug("TOUCH_EVENT_DOWNING");
Touch_Event.DownIng_Event=Null;
}
}
void Touch_UpDelayEvent()
{
if(Touch_Event.Up_Event)
{
DeBug("TOUCH_EVENT_UP");
Touch_Event.Up_Event=Null;
}
}
void Touch_DownDelayEvent()
{
if(Touch_Event.Down_Event)
{
DeBug("TOUCH_EVENT_DOWN");
Touch_Event.Down_Event=Null;
}
}
void Task_GetTouch(void *Tags)
{
static uint32 Temp_ADC1,Temp_ADC2,Temp_ADC11;
TOUCH_Tos_TaskID=Tos_TaskCurrent;
while(1)
{
Tos_TaskDelay(100);
Touch_ADCX_Config();
Tos_TaskDelay(10);
Temp_ADC11=AvrFilter_ByWords((uint16 *)&TOUCH_ADC_Value[0][1],TOUCH_ADC_BUFSize,TOUCH_ADC_BUFSize);
if(Temp_ADC11>100)
{
Tos_TaskDelay(10);
Temp_ADC1=AvrFilter_ByWords((uint16 *)&TOUCH_ADC_Value[0][1],TOUCH_ADC_BUFSize,TOUCH_ADC_BUFSize);
Touch_ADCY_Config();
Tos_TaskDelay(10);
Temp_ADC2=AvrFilter_ByWords((uint16 *)&TOUCH_ADC_Value[0][0],TOUCH_ADC_BUFSize,TOUCH_ADC_BUFSize);
if(__fabs(Temp_ADC11-Temp_ADC1)<20&Temp_ADC2>400)//消抖
{
SPK_ON;
TOUCH_ADC_YValue=Temp_ADC2;
TOUCH_ADC_XValue=Temp_ADC1;
if(Touch_Update==TOUCH_DOWNING){Touch_Update=TOUCH_DOWN;}
if(Touch_Update!=TOUCH_DOWN)
{
Touch_Update=TOUCH_DOWNING;
Touch_Event.DownIng_Event=Touch_DownIngEvent;
Touch_Event.Down_Event=Touch_DownDelayEvent;
if(Touch_Event.DownIng_Event)Touch_Event.DownIng_Event();//当存在按下事件时触发
Touch_Event.UpIng_Event=Touch_UpIngEvent;//事件测试
Touch_Event.DownDelay_Count=0;
}
if(Touch_Update==TOUCH_DOWN)
{
if(Touch_Event.DownDelay_Count
{
Touch_Event.DownDelay_Count++;
}else if(Touch_Event.Down_Event)Touch_Event.Down_Event();//当存在持续按下事件时触发
}
SPK_OFF;
DeBug("X=%d Y=%d",TOUCH_ADC_XValue,TOUCH_ADC_YValue);
}
}else
{
if(Touch_Update==TOUCH_UPING){Touch_Update=TOUCH_UP;}
if(Touch_Update!=TOUCH_UP)//触摸屏第一次按下触发
{
Touch_Update=TOUCH_UPING;
if(Touch_Event.UpIng_Event)Touch_Event.UpIng_Event();//当存在放下动作时触发
Touch_Event.UpDelay_Count=0;//按下第一次时清除按下时间计数
Touch_Event.Up_Event=Touch_UpDelayEvent;//事件测试
}
if(Touch_Update==TOUCH_UP)//触摸屏一直按下
{
if(Touch_Event.UpDelay_Count
{
Touch_Event.UpDelay_Count++;
}else if(Touch_Event.Up_Event)Touch_Event.Up_Event();//当存在持续未按下触发
}
}
}
}
void Touch_ADC1_Configuration(void)
{
ADC_InitTypeDef ADC_InitStructure;
ADC_DeInit(ADC1); //将外设 ADC1 的全部寄存器重设为缺省值
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; //ADC工作模式:ADC1和ADC2工作在独立模式
ADC_InitStructure.ADC_ScanConvMode =ENABLE; //模数转换工作在扫描模式
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; //模数转换工作在连续转换模式
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; //外部触发转换关闭
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //ADC数据右对齐
ADC_InitStructure.ADC_NbrOfChannel =TOUCH_ADC_CHN; //顺序进行规则转换的ADC通道的数目
ADC_Init(ADC1, &ADC_InitStructure); //根据ADC_InitStruct中指定的参数初始化外设ADCx的寄存器
ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 2, ADC_SampleTime_239Cycles5);
ADC_Cmd(ADC1, ENABLE); //使能指定的ADC1
ADC_ResetCalibration(ADC1); //复位指定的ADC1的校准寄存器
while(ADC_GetResetCalibrationStatu
ADC_StartCalibration(ADC1); //开始指定ADC1的校准状态
while(ADC_GetCalibrationStatus(ADC1)); //获取指定ADC1的校准程序,设置状态则等待
}
void Touch_DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure;
DMA_DeInit(DMA1_Channel1); //将DMA的通道1寄存器重设为缺省值
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&ADC1->DR; //DMA外设ADC基地址
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&TOUCH_ADC_Value; //DMA内存基地址
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; //内存作为数据传输的目的地
DMA_InitStructure.DMA_BufferSize = TOUCH_ADC_BUFSize*TOUCH_ADC_CHN; //DMA通道的DMA缓存的大小
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //外设地址寄存器不变
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //内存地址寄存器递增
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; //数据宽度为16位
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; //数据宽度为16位
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //工作在循环缓存模式
DMA_InitStructure.DMA_Priority = DMA_Priority_High; //DMA通道 x拥有高优先级
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //DMA通道x没有设置为内存到内存传输
DMA_Init(DMA1_Channel1, &DMA_InitStructure); //根据DMA_InitStruct中指定的参数初始化DMA的通道
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
DMA_Cmd(DMA1_Channel1, ENABLE);
DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE);
ADC_DMACmd(ADC1, ENABLE);
}
void Touch_ADC_Init()
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOB, ENABLE);
Touch_ADC1_Configuration();
Touch_DMA_Configuration();
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
DMA_Cmd(DMA1_Channel1, ENABLE);
Touch_Event.UpIng_Event=Null;
Touch_Event.Up_Event=Null;
Touch_Event.DownIng_Event=Null;
Touch_Event.Down_Event=Null;
Touch_Event.UpDelay_Count=0;//延迟周期数后执行延迟任务
Touch_Event.DownDelay_Count=0;//延迟周期数后执行延迟任务
}
void DeviceMount_Touch()
{
_Tos_Device_Tab[DeviceId_TOUCH].DeviceId=DeviceId_TOUCH;
_Tos_Device_Tab[DeviceId_TOUCH].DeviceName="TOUCH";
_Tos_Device_Tab[DeviceId_TOUCH].DeviceOwnerId=Null;
_Tos_Device_Tab[DeviceId_TOUCH].DeviceVirtue=ReadOnly|WriteOnly|CharDerice;
_Tos_Device_Tab[DeviceId_TOUCH].DeviceState=NotBusy;
_Tos_Device_Tab[DeviceId_TOUCH].Init=Touch_ADC_Init;
_Tos_Device_Tab[DeviceId_TOUCH].Write=Null;
_Tos_Device_Tab[DeviceId_TOUCH].Read=Null;
_Tos_Device_Tab[DeviceId_TOUCH].Exit=Null;
}
void TouchScreen_DrawCross(uint16 X0,uint16 Y0,uint16 R,uint16 FColor)
{
TGui_Draw_Line(X0-R,Y0,X0+R,Y0,FColor);
TGui_Draw_Line(X0,Y0-R,X0,Y0+R,FColor);
}
void TouchScreen_GetTouch(uint16 *VX,uint16 *VY)
{
uint16 X_BUF[4];
uint16 Y_BUF[10];
uint8 i;
while(1)
{
Tos_TaskDelay(10);
if(Touch_Update==TOUCH_DOWN)
{
*VX=TOUCH_ADC_XValue;
// *VY=TOUCH_ADC_YValue;
return;
while(1)
{
if(Touch_Update==TOUCH_UP)return;
Tos_TaskDelay(10);
}
}
}
}
void TouchScreen_Correct()
{
int8 i;
uint16 X,Y;
for(i=0;i<5;i++)
{
LCD_Clear_Screen(Color_Black);
TouchScreen_DrawCross(TOUCH_CROSS_ADDR[i][0],TOUCH_CROSS_ADDR[i][1],TOUCH_CROSS_SIZE,Color_White);
TouchScreen_GetTouch(&X,&Y);
DeBug("nihao");
Tos_TaskDelay(1000);
}
}