添加了触屏驱动,加入了触屏校准功能
This commit is contained in:
@@ -58,8 +58,18 @@ void Error_Handler(void);
|
|||||||
/* USER CODE END EFP */
|
/* USER CODE END EFP */
|
||||||
|
|
||||||
/* Private defines -----------------------------------------------------------*/
|
/* Private defines -----------------------------------------------------------*/
|
||||||
|
#define TDOUT_Pin GPIO_PIN_8
|
||||||
|
#define TDOUT_GPIO_Port GPIOF
|
||||||
|
#define TDIN_Pin GPIO_PIN_9
|
||||||
|
#define TDIN_GPIO_Port GPIOF
|
||||||
|
#define TPEN_Pin GPIO_PIN_10
|
||||||
|
#define TPEN_GPIO_Port GPIOF
|
||||||
#define LCD_BL_Pin GPIO_PIN_0
|
#define LCD_BL_Pin GPIO_PIN_0
|
||||||
#define LCD_BL_GPIO_Port GPIOB
|
#define LCD_BL_GPIO_Port GPIOB
|
||||||
|
#define TCLK_Pin GPIO_PIN_1
|
||||||
|
#define TCLK_GPIO_Port GPIOB
|
||||||
|
#define TCS_Pin GPIO_PIN_2
|
||||||
|
#define TCS_GPIO_Port GPIOB
|
||||||
/* USER CODE BEGIN Private defines */
|
/* USER CODE BEGIN Private defines */
|
||||||
|
|
||||||
/* USER CODE END Private defines */
|
/* USER CODE END Private defines */
|
||||||
|
|||||||
@@ -151,14 +151,34 @@ static void MX_GPIO_Init(void)
|
|||||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
|
||||||
/* GPIO Ports Clock Enable */
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
__HAL_RCC_GPIOG_CLK_ENABLE();
|
||||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(TDIN_GPIO_Port, TDIN_Pin, GPIO_PIN_SET);
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
/*Configure GPIO pin Output Level */
|
||||||
HAL_GPIO_WritePin(LCD_BL_GPIO_Port, LCD_BL_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(LCD_BL_GPIO_Port, LCD_BL_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOB, TCLK_Pin|TCS_Pin, GPIO_PIN_SET);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : TDOUT_Pin TPEN_Pin */
|
||||||
|
GPIO_InitStruct.Pin = TDOUT_Pin|TPEN_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : TDIN_Pin */
|
||||||
|
GPIO_InitStruct.Pin = TDIN_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||||
|
HAL_GPIO_Init(TDIN_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
/*Configure GPIO pin : LCD_BL_Pin */
|
/*Configure GPIO pin : LCD_BL_Pin */
|
||||||
GPIO_InitStruct.Pin = LCD_BL_Pin;
|
GPIO_InitStruct.Pin = LCD_BL_Pin;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
@@ -166,6 +186,13 @@ static void MX_GPIO_Init(void)
|
|||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
HAL_GPIO_Init(LCD_BL_GPIO_Port, &GPIO_InitStruct);
|
HAL_GPIO_Init(LCD_BL_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : TCLK_Pin TCS_Pin */
|
||||||
|
GPIO_InitStruct.Pin = TCLK_Pin|TCS_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||||
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FSMC initialization function */
|
/* FSMC initialization function */
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
main.c:66:5:main 8 static
|
main.c:66:5:main 8 static
|
||||||
main.c:110:6:SystemClock_Config 72 static
|
main.c:110:6:SystemClock_Config 72 static
|
||||||
main.c:149:13:MX_GPIO_Init 40 static
|
main.c:149:13:MX_GPIO_Init 48 static
|
||||||
main.c:172:13:MX_FSMC_Init 40 static
|
main.c:199:13:MX_FSMC_Init 40 static
|
||||||
main.c:236:6:Error_Handler 4 static,ignoring_inline_asm
|
main.c:263:6:Error_Handler 4 static,ignoring_inline_asm
|
||||||
|
|||||||
@@ -5,13 +5,16 @@
|
|||||||
|
|
||||||
# Add inputs and outputs from these tool invocations to the build variables
|
# Add inputs and outputs from these tool invocations to the build variables
|
||||||
C_SRCS += \
|
C_SRCS += \
|
||||||
../HW_Devices/LCD.c
|
../HW_Devices/LCD.c \
|
||||||
|
../HW_Devices/touch.c
|
||||||
|
|
||||||
OBJS += \
|
OBJS += \
|
||||||
./HW_Devices/LCD.o
|
./HW_Devices/LCD.o \
|
||||||
|
./HW_Devices/touch.o
|
||||||
|
|
||||||
C_DEPS += \
|
C_DEPS += \
|
||||||
./HW_Devices/LCD.d
|
./HW_Devices/LCD.d \
|
||||||
|
./HW_Devices/touch.d
|
||||||
|
|
||||||
|
|
||||||
# Each subdirectory must supply rules for building sources it contributes
|
# Each subdirectory must supply rules for building sources it contributes
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
HW_Devices/touch.o: ../HW_Devices/touch.c ../HW_Devices/touch.h \
|
||||||
|
../Core/Inc/main.h ../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal.h \
|
||||||
|
../Core/Inc/stm32f1xx_hal_conf.h \
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc.h \
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_def.h \
|
||||||
|
../Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h \
|
||||||
|
../Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xe.h \
|
||||||
|
../Drivers/CMSIS/Include/core_cm3.h \
|
||||||
|
../Drivers/CMSIS/Include/cmsis_version.h \
|
||||||
|
../Drivers/CMSIS/Include/cmsis_compiler.h \
|
||||||
|
../Drivers/CMSIS/Include/cmsis_gcc.h \
|
||||||
|
../Drivers/CMSIS/Device/ST/STM32F1xx/Include/system_stm32f1xx.h \
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h \
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc_ex.h \
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio.h \
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio_ex.h \
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_exti.h \
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma.h \
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma_ex.h \
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_cortex.h \
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash.h \
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash_ex.h \
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_sram.h \
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_fsmc.h \
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_pwr.h \
|
||||||
|
../HW_Devices/LCD.h
|
||||||
|
|
||||||
|
../HW_Devices/touch.h:
|
||||||
|
|
||||||
|
../Core/Inc/main.h:
|
||||||
|
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal.h:
|
||||||
|
|
||||||
|
../Core/Inc/stm32f1xx_hal_conf.h:
|
||||||
|
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc.h:
|
||||||
|
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_def.h:
|
||||||
|
|
||||||
|
../Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h:
|
||||||
|
|
||||||
|
../Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xe.h:
|
||||||
|
|
||||||
|
../Drivers/CMSIS/Include/core_cm3.h:
|
||||||
|
|
||||||
|
../Drivers/CMSIS/Include/cmsis_version.h:
|
||||||
|
|
||||||
|
../Drivers/CMSIS/Include/cmsis_compiler.h:
|
||||||
|
|
||||||
|
../Drivers/CMSIS/Include/cmsis_gcc.h:
|
||||||
|
|
||||||
|
../Drivers/CMSIS/Device/ST/STM32F1xx/Include/system_stm32f1xx.h:
|
||||||
|
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h:
|
||||||
|
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc_ex.h:
|
||||||
|
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio.h:
|
||||||
|
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio_ex.h:
|
||||||
|
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_exti.h:
|
||||||
|
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma.h:
|
||||||
|
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma_ex.h:
|
||||||
|
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_cortex.h:
|
||||||
|
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash.h:
|
||||||
|
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash_ex.h:
|
||||||
|
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_sram.h:
|
||||||
|
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_fsmc.h:
|
||||||
|
|
||||||
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_pwr.h:
|
||||||
|
|
||||||
|
../HW_Devices/LCD.h:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
touch.c:18:6:TP_Write_Byte 24 static
|
||||||
|
touch.c:34:10:TP_Read_AD 24 static
|
||||||
|
touch.c:68:10:TP_Read_XOY 48 static
|
||||||
|
touch.c:95:6:TP_Read_XY_ADC 24 static
|
||||||
|
touch.c:109:9:TP_Read_XY2 24 static
|
||||||
|
touch.c:129:6:TP_Server 16 static
|
||||||
|
touch.c:140:6:TP_DrwaTrage 40 static
|
||||||
|
touch.c:150:6:TP_adjustment 160 static
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
SW_APPs/Main_APP.o: ../SW_APPs/Main_APP.c \
|
SW_APPs/Main_APP.o: ../SW_APPs/Main_APP.c ../SW_APPs/Main_APP.h \
|
||||||
/Users/wuwenfeng/STM32CubeIDE/workspace_1.7.0/m3s/HW_Devices/LCD.h \
|
/Users/wuwenfeng/STM32CubeIDE/workspace_1.7.0/m3s/HW_Devices/LCD.h \
|
||||||
../Core/Inc/main.h ../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal.h \
|
../Core/Inc/main.h ../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal.h \
|
||||||
../Core/Inc/stm32f1xx_hal_conf.h \
|
../Core/Inc/stm32f1xx_hal_conf.h \
|
||||||
@@ -25,7 +25,10 @@ SW_APPs/Main_APP.o: ../SW_APPs/Main_APP.c \
|
|||||||
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_fsmc.h \
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_fsmc.h \
|
||||||
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_pwr.h \
|
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_pwr.h \
|
||||||
../SW_APPs/windows.h \
|
../SW_APPs/windows.h \
|
||||||
/Users/wuwenfeng/STM32CubeIDE/workspace_1.7.0/m3s/HW_Devices/lcd.h
|
/Users/wuwenfeng/STM32CubeIDE/workspace_1.7.0/m3s/HW_Devices/lcd.h \
|
||||||
|
/Users/wuwenfeng/STM32CubeIDE/workspace_1.7.0/m3s/HW_Devices/touch.h
|
||||||
|
|
||||||
|
../SW_APPs/Main_APP.h:
|
||||||
|
|
||||||
/Users/wuwenfeng/STM32CubeIDE/workspace_1.7.0/m3s/HW_Devices/LCD.h:
|
/Users/wuwenfeng/STM32CubeIDE/workspace_1.7.0/m3s/HW_Devices/LCD.h:
|
||||||
|
|
||||||
@@ -82,3 +85,5 @@ SW_APPs/Main_APP.o: ../SW_APPs/Main_APP.c \
|
|||||||
../SW_APPs/windows.h:
|
../SW_APPs/windows.h:
|
||||||
|
|
||||||
/Users/wuwenfeng/STM32CubeIDE/workspace_1.7.0/m3s/HW_Devices/lcd.h:
|
/Users/wuwenfeng/STM32CubeIDE/workspace_1.7.0/m3s/HW_Devices/lcd.h:
|
||||||
|
|
||||||
|
/Users/wuwenfeng/STM32CubeIDE/workspace_1.7.0/m3s/HW_Devices/touch.h:
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
Main_APP.c:10:6:main_app 32 static
|
Main_APP.c:16:6:main_app 32 static
|
||||||
|
|||||||
Binary file not shown.
+11135
-8361
File diff suppressed because it is too large
Load Diff
+948
-726
File diff suppressed because it is too large
Load Diff
@@ -21,5 +21,6 @@
|
|||||||
"./Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.o"
|
"./Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.o"
|
||||||
"./Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_fsmc.o"
|
"./Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_fsmc.o"
|
||||||
"./HW_Devices/LCD.o"
|
"./HW_Devices/LCD.o"
|
||||||
|
"./HW_Devices/touch.o"
|
||||||
"./SW_APPs/Main_APP.o"
|
"./SW_APPs/Main_APP.o"
|
||||||
"./SW_APPs/windows.o"
|
"./SW_APPs/windows.o"
|
||||||
|
|||||||
@@ -0,0 +1,303 @@
|
|||||||
|
/*
|
||||||
|
* touch.c
|
||||||
|
*
|
||||||
|
* Created on: 2021年8月7日
|
||||||
|
* Author: wuwenfeng
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "touch.h"
|
||||||
|
#include "LCD.h"
|
||||||
|
//默认为touchtype=0的数据.
|
||||||
|
#define CMD_RDX 0X90
|
||||||
|
#define CMD_RDY 0XD0
|
||||||
|
|
||||||
|
|
||||||
|
//SPI写数据
|
||||||
|
//向触摸屏IC写入1byte数据
|
||||||
|
//num:要写入的数据
|
||||||
|
void TP_Write_Byte(char num)
|
||||||
|
{
|
||||||
|
for(uint8_t count=0;count<8;count++)
|
||||||
|
{
|
||||||
|
if(num&0x80){TDIN(1);}
|
||||||
|
else {TDIN(0);}
|
||||||
|
num<<=1;
|
||||||
|
TCLK(0);
|
||||||
|
TCLK(1); //上升沿有效
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//SPI读数据
|
||||||
|
//从触摸屏IC读取adc值
|
||||||
|
//CMD:指令
|
||||||
|
//返回值:读到的数据
|
||||||
|
uint16_t TP_Read_AD(char CMD)
|
||||||
|
{
|
||||||
|
uint16_t Num=0;
|
||||||
|
TCLK(0); //先拉低时钟
|
||||||
|
TDIN(0); //拉低数据线
|
||||||
|
TCS(0); //选中触摸屏IC
|
||||||
|
TP_Write_Byte(CMD);//发送命令字
|
||||||
|
HAL_GetTick();
|
||||||
|
HAL_GetTick();
|
||||||
|
HAL_GetTick();
|
||||||
|
HAL_GetTick();
|
||||||
|
HAL_GetTick();
|
||||||
|
HAL_GetTick();
|
||||||
|
TCLK(1); //给1个时钟,清除BUSY
|
||||||
|
TCLK(0);
|
||||||
|
for(uint8_t count=0;count<16;count++)//读出16位数据,只有高12位有效
|
||||||
|
{
|
||||||
|
Num<<=1;
|
||||||
|
TCLK(0); //下降沿有效
|
||||||
|
TCLK(1);;
|
||||||
|
if(TDOUT){Num++;}
|
||||||
|
}
|
||||||
|
Num>>=4; //只有高12位有效.
|
||||||
|
TCS(1); //释放片选
|
||||||
|
return(Num);
|
||||||
|
}
|
||||||
|
|
||||||
|
//读取一个坐标值(x或者y)
|
||||||
|
//连续读取READ_TIMES次数据,对这些数据升序排列,
|
||||||
|
//然后去掉最低和最高LOST_VAL个数,取平均值
|
||||||
|
//xy:指令(CMD_RDX/CMD_RDY)
|
||||||
|
//返回值:读到的数据
|
||||||
|
#define READ_TIMES 5 //读取次数
|
||||||
|
#define LOST_VAL 1 //丢弃值
|
||||||
|
uint16_t TP_Read_XOY(uint8_t xy)
|
||||||
|
{
|
||||||
|
uint16_t i, j;
|
||||||
|
uint16_t buf[READ_TIMES];
|
||||||
|
uint16_t sum=0;
|
||||||
|
uint16_t temp;
|
||||||
|
for(i=0;i<READ_TIMES;i++)buf[i]=TP_Read_AD(xy);
|
||||||
|
for(i=0;i<READ_TIMES-1; i++)//排序
|
||||||
|
{
|
||||||
|
for(j=i+1;j<READ_TIMES;j++)
|
||||||
|
{
|
||||||
|
if(buf[i]>buf[j])//升序排列
|
||||||
|
{
|
||||||
|
temp=buf[i];
|
||||||
|
buf[i]=buf[j];
|
||||||
|
buf[j]=temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sum=0;
|
||||||
|
for(i=LOST_VAL;i<READ_TIMES-LOST_VAL;i++)sum+=buf[i];
|
||||||
|
temp=sum/(READ_TIMES-2*LOST_VAL);
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
//读取x,y坐标
|
||||||
|
//x,y:读取到的坐标ADC值
|
||||||
|
void TP_Read_XY_ADC(int16_t *x,int16_t *y)
|
||||||
|
{
|
||||||
|
int16_t xtemp,ytemp;
|
||||||
|
xtemp=TP_Read_XOY(CMD_RDX);
|
||||||
|
ytemp=TP_Read_XOY(CMD_RDY);
|
||||||
|
*x=xtemp;
|
||||||
|
*y=ytemp;
|
||||||
|
}
|
||||||
|
//连续2次读取触摸屏IC,且这两次的偏差不能超过
|
||||||
|
//ERR_RANGE,满足条件,则认为读数正确,否则读数错误.
|
||||||
|
//该函数能大大提高准确度
|
||||||
|
//x,y:读取到的坐标值
|
||||||
|
//返回值:0,失败;1,成功。
|
||||||
|
#define ERR_RANGE 10 //误差范围
|
||||||
|
uint8_t TP_Read_XY2(int16_t *x,int16_t *y)
|
||||||
|
{
|
||||||
|
int16_t x1,y1;
|
||||||
|
int16_t x2,y2;
|
||||||
|
|
||||||
|
TP_Read_XY_ADC(&x1,&y1);
|
||||||
|
|
||||||
|
TP_Read_XY_ADC(&x2,&y2);
|
||||||
|
|
||||||
|
if(((x2<=x1&&x1<x2+ERR_RANGE)||(x1<=x2&&x2<x1+ERR_RANGE))//前后两次采样在+-50内
|
||||||
|
&&((y2<=y1&&y1<y2+ERR_RANGE)||(y1<=y2&&y2<y1+ERR_RANGE)))
|
||||||
|
{
|
||||||
|
*x=(x1+x2)/2;
|
||||||
|
*y=(y1+y2)/2;
|
||||||
|
return 1;
|
||||||
|
}else return 0;
|
||||||
|
}
|
||||||
|
touch_device t0;// t0 yyds~
|
||||||
|
touch_config tconfig;
|
||||||
|
//触摸更新服务
|
||||||
|
void TP_Server()
|
||||||
|
{
|
||||||
|
if(TPEN==0)
|
||||||
|
{
|
||||||
|
TP_Read_XY2(&t0.adc_x,&t0.adc_y);
|
||||||
|
t0.pix_x=(t0.adc_x/tconfig.x_acc)-tconfig.x_offset;
|
||||||
|
t0.pix_y=(t0.adc_y/tconfig.y_acc)-tconfig.y_offset;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TP_DrwaTrage(int x,int y,int r)
|
||||||
|
{
|
||||||
|
Draw_Circle(x,y,r+1,GRAY);
|
||||||
|
Draw_Circle(x,y,r,RED);
|
||||||
|
LCD_DrawLine(x,y,x+10,y,RED);
|
||||||
|
LCD_DrawLine(x,y,x,y+10,RED);
|
||||||
|
LCD_DrawLine(x,y,x-10,y,RED);
|
||||||
|
LCD_DrawLine(x,y,x,y-10,RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TP_adjustment()
|
||||||
|
{
|
||||||
|
char str[64];
|
||||||
|
uint16_t y_adc,x_adc,step=0,r=10;
|
||||||
|
uint16_t y1,y2,y3,y4,x1,x2,x3,x4;
|
||||||
|
int y5,x5,xd,xl,yd,yl;
|
||||||
|
float acc_x,acc_y;
|
||||||
|
int offset_x,offset_y;
|
||||||
|
uint32_t wait=HAL_GetTick()+50000,ms100=0;
|
||||||
|
LCD_Clear(GRAY);
|
||||||
|
LCD_ShowString(0,50,"Calibrate the touch screen",16,RED,RED);
|
||||||
|
//TP_DrwaTrage(30,30,10);
|
||||||
|
while(HAL_GetTick()<wait)
|
||||||
|
{
|
||||||
|
if(TPEN==0)
|
||||||
|
{
|
||||||
|
wait=HAL_GetTick()+50000;
|
||||||
|
|
||||||
|
TP_Read_XY2(&x_adc,&y_adc);
|
||||||
|
sprintf(str,"ADC_X:%04d",x_adc);
|
||||||
|
LCD_ShowString(100, 0, str, 16, RED, GRAY);
|
||||||
|
sprintf(str,"ADC_Y:%04d",y_adc);
|
||||||
|
LCD_ShowString(100, 16, str, 16, RED, GRAY);
|
||||||
|
|
||||||
|
if(HAL_GetTick()>ms100)
|
||||||
|
{
|
||||||
|
ms100=HAL_GetTick()+100;
|
||||||
|
if(r>0){r--;}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(step==0)
|
||||||
|
{
|
||||||
|
TP_DrwaTrage(30,30,r);
|
||||||
|
if(r==0)
|
||||||
|
{
|
||||||
|
step+=1;
|
||||||
|
y1=y_adc;
|
||||||
|
x1=x_adc;
|
||||||
|
sprintf(str,"point_1 x:%d y:%d",x1,y1);
|
||||||
|
LCD_ShowString(0,66,str,16,RED,RED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(step==1)
|
||||||
|
{
|
||||||
|
if(TPEN==1)
|
||||||
|
{
|
||||||
|
step+=1;
|
||||||
|
r=10;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if(step==2)
|
||||||
|
{
|
||||||
|
TP_DrwaTrage(290,30,r);
|
||||||
|
if(r==0)
|
||||||
|
{
|
||||||
|
step+=1;
|
||||||
|
y2=y_adc;
|
||||||
|
x2=x_adc;
|
||||||
|
sprintf(str,"point_2 x:%d y:%d",x2,y2);
|
||||||
|
LCD_ShowString(0,66+16,str,16,RED,RED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(step==3)
|
||||||
|
{
|
||||||
|
if(TPEN==1)
|
||||||
|
{
|
||||||
|
step+=1;
|
||||||
|
r=10;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if(step==4)
|
||||||
|
{
|
||||||
|
TP_DrwaTrage(30,210,r);
|
||||||
|
if(r==0)
|
||||||
|
{
|
||||||
|
step+=1;
|
||||||
|
y3=y_adc;
|
||||||
|
x3=x_adc;
|
||||||
|
sprintf(str,"point_3 x:%d y:%d",x3,y3);
|
||||||
|
LCD_ShowString(0,66+16+16,str,16,RED,RED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(step==5)
|
||||||
|
{
|
||||||
|
if(TPEN==1)
|
||||||
|
{
|
||||||
|
step+=1;
|
||||||
|
r=10;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if(step==6)
|
||||||
|
{
|
||||||
|
TP_DrwaTrage(290,210,r);
|
||||||
|
if(r==0)
|
||||||
|
{
|
||||||
|
step+=1;
|
||||||
|
y4=y_adc;
|
||||||
|
x4=x_adc;
|
||||||
|
sprintf(str,"point_4 x:%d y:%d",x4,y4);
|
||||||
|
LCD_ShowString(0,66+16+16+16,str,16,RED,RED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(step==7)
|
||||||
|
{
|
||||||
|
if(TPEN==1)
|
||||||
|
{
|
||||||
|
step+=1;
|
||||||
|
r=10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(step==8)
|
||||||
|
{
|
||||||
|
xd=((x1+x3)/2);
|
||||||
|
xl=((x2+x4)/2);
|
||||||
|
yd=((y1+y2)/2);
|
||||||
|
yl=((y3+y4)/2);
|
||||||
|
x5=xl-xd;
|
||||||
|
y5=yl-yd;
|
||||||
|
if(x5<0||y5<0)
|
||||||
|
{
|
||||||
|
sprintf(str,"ERROR");
|
||||||
|
LCD_ShowString(0,66+16+16+16+16,str,16,RED, GRAY);
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
acc_x=x5/260.0;
|
||||||
|
acc_y=y5/180.0;
|
||||||
|
|
||||||
|
offset_x=(((xd/acc_x)-30)+((xl/acc_x)-290))/2;
|
||||||
|
offset_y=(((yd/acc_y)-30)+((yl/acc_y)-210))/2;
|
||||||
|
|
||||||
|
tconfig.x_acc=acc_x;
|
||||||
|
tconfig.x_offset=offset_x;
|
||||||
|
tconfig.y_acc=acc_y;
|
||||||
|
tconfig.y_offset=offset_y;
|
||||||
|
|
||||||
|
sprintf(str,"x_acc=%f y_acc=%f",acc_x,acc_y);
|
||||||
|
LCD_ShowString(0,66+16+16+16+16,str,16,RED,RED);
|
||||||
|
sprintf(str,"x_offset=%d y_offset=%d",offset_x,offset_y);
|
||||||
|
LCD_ShowString(0,66+16+16+16+16+16,str,16,RED,RED);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
HAL_Delay(1000);
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* touch.h
|
||||||
|
*
|
||||||
|
* Created on: 2021Äê8ÔÂ7ÈÕ
|
||||||
|
* Author: wuwenfeng
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TOUCH_H_
|
||||||
|
#define TOUCH_H_
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define TCLK(x) HAL_GPIO_WritePin(TCLK_GPIO_Port,TCLK_Pin,x)
|
||||||
|
#define TCS(x) HAL_GPIO_WritePin(TCS_GPIO_Port,TCS_Pin,x)
|
||||||
|
#define TDIN(x) HAL_GPIO_WritePin(TDIN_GPIO_Port,TDIN_Pin,x)
|
||||||
|
#define TDOUT HAL_GPIO_ReadPin(TDOUT_GPIO_Port,TDOUT_Pin)
|
||||||
|
#define TPEN HAL_GPIO_ReadPin(TPEN_GPIO_Port,TPEN_Pin)
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
char begin;
|
||||||
|
float x_acc;
|
||||||
|
float y_acc;
|
||||||
|
int x_offset;
|
||||||
|
int y_offset;
|
||||||
|
char end;
|
||||||
|
}touch_config;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint16_t adc_x;
|
||||||
|
uint16_t adc_y;
|
||||||
|
int pix_x;
|
||||||
|
int pix_y;
|
||||||
|
char move_flag;
|
||||||
|
}touch_device;
|
||||||
|
|
||||||
|
|
||||||
|
void TP_Server();
|
||||||
|
void TP_adjustment();
|
||||||
|
|
||||||
|
#endif /* TOUCH_H_ */
|
||||||
@@ -4,12 +4,19 @@
|
|||||||
* Created on: Aug 6, 2021
|
* Created on: Aug 6, 2021
|
||||||
* Author: wuwenfeng
|
* Author: wuwenfeng
|
||||||
*/
|
*/
|
||||||
|
#include "Main_APP.h"
|
||||||
#include "LCD.h"
|
#include "LCD.h"
|
||||||
#include "windows.h"
|
#include "windows.h"
|
||||||
|
#include "touch.h"
|
||||||
|
|
||||||
|
extern touch_device t0;
|
||||||
|
|
||||||
|
task run_loop;//Ö÷Ñ»·×´Ì¬»ú
|
||||||
|
|
||||||
void main_app()
|
void main_app()
|
||||||
{
|
{
|
||||||
LCDx_Init();
|
LCDx_Init();
|
||||||
|
TP_adjustment();
|
||||||
|
|
||||||
UI *ui=UI_Init(BLACK);
|
UI *ui=UI_Init(BLACK);
|
||||||
|
|
||||||
@@ -21,15 +28,22 @@ void main_app()
|
|||||||
ui->refresh_ui_flag=1;
|
ui->refresh_ui_flag=1;
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
|
{
|
||||||
|
LCD_set_dot(t0.pix_x, t0.pix_y, RED);
|
||||||
|
/*
|
||||||
|
switch(run_loop.sw)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
if(ui->refresh_ui_flag==1)
|
if(ui->refresh_ui_flag==1)
|
||||||
{
|
{
|
||||||
ui->refresh_ui_flag=0;
|
ui->refresh_ui_flag=0;
|
||||||
Refresh_UI(ui);
|
Refresh_UI(ui);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
TP_Server();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,12 @@
|
|||||||
#ifndef MAIN_APP_H_
|
#ifndef MAIN_APP_H_
|
||||||
#define MAIN_APP_H_
|
#define MAIN_APP_H_
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int sw;
|
||||||
|
char change_flag;
|
||||||
|
}task;
|
||||||
|
|
||||||
void main_app();
|
void main_app();
|
||||||
|
|
||||||
#endif /* MAIN_APP_H_ */
|
#endif /* MAIN_APP_H_ */
|
||||||
|
|||||||
@@ -75,5 +75,6 @@
|
|||||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||||
<listEntry value="4"/>
|
<listEntry value="4"/>
|
||||||
</listAttribute>
|
</listAttribute>
|
||||||
|
<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?><memoryBlockExpressionList context="reserved-for-future-use"/>"/>
|
||||||
<stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
|
<stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
|
||||||
</launchConfiguration>
|
</launchConfiguration>
|
||||||
|
|||||||
@@ -13,32 +13,37 @@ Mcu.IP3=SYS
|
|||||||
Mcu.IPNb=4
|
Mcu.IPNb=4
|
||||||
Mcu.Name=STM32F103Z(C-D-E)Tx
|
Mcu.Name=STM32F103Z(C-D-E)Tx
|
||||||
Mcu.Package=LQFP144
|
Mcu.Package=LQFP144
|
||||||
Mcu.Pin0=OSC_IN
|
Mcu.Pin0=PF8
|
||||||
Mcu.Pin1=OSC_OUT
|
Mcu.Pin1=PF9
|
||||||
Mcu.Pin10=PE13
|
Mcu.Pin10=PE8
|
||||||
Mcu.Pin11=PE14
|
Mcu.Pin11=PE9
|
||||||
Mcu.Pin12=PE15
|
Mcu.Pin12=PE10
|
||||||
Mcu.Pin13=PD8
|
Mcu.Pin13=PE11
|
||||||
Mcu.Pin14=PD9
|
Mcu.Pin14=PE12
|
||||||
Mcu.Pin15=PD10
|
Mcu.Pin15=PE13
|
||||||
Mcu.Pin16=PD14
|
Mcu.Pin16=PE14
|
||||||
Mcu.Pin17=PD15
|
Mcu.Pin17=PE15
|
||||||
Mcu.Pin18=PD0
|
Mcu.Pin18=PD8
|
||||||
Mcu.Pin19=PD1
|
Mcu.Pin19=PD9
|
||||||
Mcu.Pin2=PB0
|
Mcu.Pin2=PF10
|
||||||
Mcu.Pin20=PD4
|
Mcu.Pin20=PD10
|
||||||
Mcu.Pin21=PD5
|
Mcu.Pin21=PD14
|
||||||
Mcu.Pin22=PG12
|
Mcu.Pin22=PD15
|
||||||
Mcu.Pin23=VP_SYS_VS_ND
|
Mcu.Pin23=PD0
|
||||||
Mcu.Pin24=VP_SYS_VS_Systick
|
Mcu.Pin24=PD1
|
||||||
Mcu.Pin3=PG0
|
Mcu.Pin25=PD4
|
||||||
Mcu.Pin4=PE7
|
Mcu.Pin26=PD5
|
||||||
Mcu.Pin5=PE8
|
Mcu.Pin27=PG12
|
||||||
Mcu.Pin6=PE9
|
Mcu.Pin28=VP_SYS_VS_ND
|
||||||
Mcu.Pin7=PE10
|
Mcu.Pin29=VP_SYS_VS_Systick
|
||||||
Mcu.Pin8=PE11
|
Mcu.Pin3=OSC_IN
|
||||||
Mcu.Pin9=PE12
|
Mcu.Pin4=OSC_OUT
|
||||||
Mcu.PinsNb=25
|
Mcu.Pin5=PB0
|
||||||
|
Mcu.Pin6=PB1
|
||||||
|
Mcu.Pin7=PB2
|
||||||
|
Mcu.Pin8=PG0
|
||||||
|
Mcu.Pin9=PE7
|
||||||
|
Mcu.PinsNb=30
|
||||||
Mcu.ThirdPartyNb=0
|
Mcu.ThirdPartyNb=0
|
||||||
Mcu.UserConstants=
|
Mcu.UserConstants=
|
||||||
Mcu.UserName=STM32F103ZETx
|
Mcu.UserName=STM32F103ZETx
|
||||||
@@ -63,6 +68,18 @@ PB0.GPIOParameters=GPIO_Label
|
|||||||
PB0.GPIO_Label=LCD_BL
|
PB0.GPIO_Label=LCD_BL
|
||||||
PB0.Locked=true
|
PB0.Locked=true
|
||||||
PB0.Signal=GPIO_Output
|
PB0.Signal=GPIO_Output
|
||||||
|
PB1.GPIOParameters=GPIO_Speed,PinState,GPIO_Label
|
||||||
|
PB1.GPIO_Label=TCLK
|
||||||
|
PB1.GPIO_Speed=GPIO_SPEED_FREQ_HIGH
|
||||||
|
PB1.Locked=true
|
||||||
|
PB1.PinState=GPIO_PIN_SET
|
||||||
|
PB1.Signal=GPIO_Output
|
||||||
|
PB2.GPIOParameters=GPIO_Speed,PinState,GPIO_Label
|
||||||
|
PB2.GPIO_Label=TCS
|
||||||
|
PB2.GPIO_Speed=GPIO_SPEED_FREQ_HIGH
|
||||||
|
PB2.Locked=true
|
||||||
|
PB2.PinState=GPIO_PIN_SET
|
||||||
|
PB2.Signal=GPIO_Output
|
||||||
PD0.Signal=FSMC_D2_DA2
|
PD0.Signal=FSMC_D2_DA2
|
||||||
PD1.Signal=FSMC_D3_DA3
|
PD1.Signal=FSMC_D3_DA3
|
||||||
PD10.Signal=FSMC_D15_DA15
|
PD10.Signal=FSMC_D15_DA15
|
||||||
@@ -81,6 +98,20 @@ PE15.Signal=FSMC_D12_DA12
|
|||||||
PE7.Signal=FSMC_D4_DA4
|
PE7.Signal=FSMC_D4_DA4
|
||||||
PE8.Signal=FSMC_D5_DA5
|
PE8.Signal=FSMC_D5_DA5
|
||||||
PE9.Signal=FSMC_D6_DA6
|
PE9.Signal=FSMC_D6_DA6
|
||||||
|
PF10.GPIOParameters=GPIO_Label
|
||||||
|
PF10.GPIO_Label=TPEN
|
||||||
|
PF10.Locked=true
|
||||||
|
PF10.Signal=GPIO_Input
|
||||||
|
PF8.GPIOParameters=GPIO_Label
|
||||||
|
PF8.GPIO_Label=TDOUT
|
||||||
|
PF8.Locked=true
|
||||||
|
PF8.Signal=GPIO_Input
|
||||||
|
PF9.GPIOParameters=GPIO_Speed,PinState,GPIO_Label
|
||||||
|
PF9.GPIO_Label=TDIN
|
||||||
|
PF9.GPIO_Speed=GPIO_SPEED_FREQ_HIGH
|
||||||
|
PF9.Locked=true
|
||||||
|
PF9.PinState=GPIO_PIN_SET
|
||||||
|
PF9.Signal=GPIO_Output
|
||||||
PG0.Signal=FSMC_A10
|
PG0.Signal=FSMC_A10
|
||||||
PG12.Mode=NorPsramChipSelect4_1
|
PG12.Mode=NorPsramChipSelect4_1
|
||||||
PG12.Signal=FSMC_NE4
|
PG12.Signal=FSMC_NE4
|
||||||
|
|||||||
Reference in New Issue
Block a user