更新触摸驱动

This commit is contained in:
Aladdin-Wang 2020-03-29 22:26:46 +08:00
parent 092d54210c
commit 35796aab20
12 changed files with 2124 additions and 211 deletions

View File

@ -1345,7 +1345,7 @@
<GroupNumber>9</GroupNumber>
<FileNumber>85</FileNumber>
<FileType>1</FileType>
<tvExp>1</tvExp>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\Drivers\Touch_Driver\bsp_touch_gtxx.c</PathWithFileName>

View File

@ -118,7 +118,7 @@ CONFIG_RT_SYSTEM_WORKQUEUE_STACKSIZE=2048
CONFIG_RT_SYSTEM_WORKQUEUE_PRIORITY=23
CONFIG_RT_USING_SERIAL=y
# CONFIG_RT_SERIAL_USING_DMA is not set
CONFIG_RT_SERIAL_RB_BUFSZ=64
CONFIG_RT_SERIAL_RB_BUFSZ=128
# CONFIG_RT_USING_CAN is not set
# CONFIG_RT_USING_HWTIMER is not set
# CONFIG_RT_USING_CPUTIME is not set
@ -462,7 +462,13 @@ CONFIG_PKG_SHT3X_VER="latest"
# CONFIG_PKG_USING_PCA9685 is not set
# CONFIG_PKG_USING_I2C_TOOLS is not set
# CONFIG_PKG_USING_NRF24L01 is not set
# CONFIG_PKG_USING_TOUCH_DRIVERS is not set
CONFIG_PKG_USING_TOUCH_DRIVERS=y
CONFIG_PKG_USING_GT9147=y
CONFIG_PKG_GT9147_PATH="/packages/peripherals/touch/gt9147"
# CONFIG_PKG_USING_GT9147_V100 is not set
CONFIG_PKG_USING_GT9147_LATEST_VERSION=y
CONFIG_PKG_GT9147_VER="latest"
# CONFIG_PKG_USING_FT6206 is not set
# CONFIG_PKG_USING_MAX17048 is not set
# CONFIG_PKG_USING_RPLIDAR is not set
# CONFIG_PKG_USING_AS608 is not set
@ -524,7 +530,7 @@ CONFIG_BSP_USING_SDRAM=y
# CONFIG_BSP_USING_QSPI_FLASH is not set
CONFIG_BSP_USING_QSPI_MemoryMapped=y
# CONFIG_BSP_USING_LCD is not set
CONFIG_BSP_USING_TOUCH=y
# CONFIG_BSP_USING_TOUCH is not set
# CONFIG_BSP_USING_MPU6050 is not set
# CONFIG_BSP_USING_POT is not set
# CONFIG_BSP_USING_SDCARD is not set
@ -548,6 +554,13 @@ CONFIG_BSP_USING_I2C1=y
#
CONFIG_BSP_I2C1_SCL_PIN=60
CONFIG_BSP_I2C1_SDA_PIN=61
CONFIG_BSP_USING_I2C2=y
#
# Notice: PB6 --> 22; PB7 --> 23
#
CONFIG_BSP_I2C2_SCL_PIN=116
CONFIG_BSP_I2C2_SDA_PIN=117
CONFIG_BSP_USING_ONCHIP_RTC=y
CONFIG_BSP_RTC_USING_LSE=y
# CONFIG_BSP_RTC_USING_LSI is not set

View File

@ -0,0 +1,127 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-06-01 tyustli the first version
*/
#include <rtthread.h>
#include "gt9147.h"
#define THREAD_PRIORITY 5
#define THREAD_STACK_SIZE 1024
#define THREAD_TIMESLICE 5
#define GT9147_RST_PIN 59
#define GT9147_IRQ_PIN 23
static rt_thread_t gt9147_thread = RT_NULL;
static rt_sem_t gt9147_sem = RT_NULL;
static rt_device_t dev = RT_NULL;
struct rt_touch_data *read_data;
static struct rt_touch_info info;
static void gt9147_entry(void *parameter)
{
rt_device_control(dev, RT_TOUCH_CTRL_GET_INFO, &info);
read_data = (struct rt_touch_data *)rt_malloc(sizeof(struct rt_touch_data) * info.point_num);
while (1)
{
rt_sem_take(gt9147_sem, RT_WAITING_FOREVER);
if (rt_device_read(dev, 0, read_data, info.point_num) == info.point_num)
{
for (rt_uint8_t i = 0; i < info.point_num; i++)
{
if (read_data[i].event == RT_TOUCH_EVENT_DOWN || read_data[i].event == RT_TOUCH_EVENT_MOVE)
{
rt_kprintf("%d %d %d %d %d\n", read_data[i].track_id,
read_data[i].x_coordinate,
read_data[i].y_coordinate,
read_data[i].timestamp,
read_data[i].width);
}
}
}
rt_device_control(dev, RT_TOUCH_CTRL_ENABLE_INT, RT_NULL);
}
}
static rt_err_t rx_callback(rt_device_t dev, rt_size_t size)
{
rt_sem_release(gt9147_sem);
rt_device_control(dev, RT_TOUCH_CTRL_DISABLE_INT, RT_NULL);
return 0;
}
static int rt_hw_gt9147_port(void)
{
struct rt_touch_config config;
rt_uint8_t rst;
rst = GT9147_RST_PIN;
config.dev_name = "i2c2";
config.irq_pin.pin = GT9147_IRQ_PIN;
config.irq_pin.mode = PIN_MODE_INPUT_PULLDOWN;
config.user_data = &rst;
rt_hw_gt9147_init("gt", &config);
return 0;
}
/* Test function */
int gt9147_init(void)
{
void *id;
rt_hw_gt9147_port();
dev = rt_device_find("gt");
if (dev == RT_NULL)
{
rt_kprintf("can't find device gt\n");
return -1;
}
if (rt_device_open(dev, RT_DEVICE_FLAG_INT_RX) != RT_EOK)
{
rt_kprintf("open device failed!");
return -1;
}
id = rt_malloc(sizeof(rt_uint8_t) * 8);
rt_device_control(dev, RT_TOUCH_CTRL_GET_ID, id);
rt_uint8_t * read_id = (rt_uint8_t *)id;
rt_kprintf("id = %c %c %c %c \n", read_id[0], read_id[1], read_id[2], read_id[3]);
//rt_device_control(dev, RT_TOUCH_CTRL_SET_X_RANGE, &x); /* if possible you can set your x y coordinate*/
//rt_device_control(dev, RT_TOUCH_CTRL_SET_Y_RANGE, &y);
rt_device_control(dev, RT_TOUCH_CTRL_GET_INFO, id);
rt_kprintf("range_x = %d \n", (*(struct rt_touch_info*)id).range_x);
rt_kprintf("range_y = %d \n", (*(struct rt_touch_info*)id).range_y);
rt_kprintf("point_num = %d \n", (*(struct rt_touch_info*)id).point_num);
rt_free(id);
rt_device_set_rx_indicate(dev, rx_callback);
gt9147_sem = rt_sem_create("dsem", 0, RT_IPC_FLAG_FIFO);
if (gt9147_sem == RT_NULL)
{
rt_kprintf("create dynamic semaphore failed.\n");
return -1;
}
gt9147_thread = rt_thread_create("gt9147",
gt9147_entry,
RT_NULL,
THREAD_STACK_SIZE,
THREAD_PRIORITY,
THREAD_TIMESLICE);
if (gt9147_thread != RT_NULL)
rt_thread_startup(gt9147_thread);
return 0;
}
//INIT_APP_EXPORT(gt9147_init);

View File

@ -26,7 +26,7 @@ static void sht30_collect_thread_entry(void *parameter)
sht3x_device = sht3x_init("i2c1", 0x44);
//此处需要短暂的延时,否则会出现连续读取失败的问题,感谢网友的提醒
rt_thread_mdelay(150);
rt_thread_mdelay(1000);
while (1)
{
@ -40,7 +40,7 @@ static void sht30_collect_thread_entry(void *parameter)
rt_kprintf("read sht3x fail.\r\n");
break;
}
rt_thread_mdelay(2000);
rt_thread_mdelay(5000);
}
}

View File

@ -18,20 +18,19 @@
/* USER CODE BEGIN STM32TouchController */
#include <STM32TouchController.hpp>
#include "gt9xx.h"
extern "C"
{
int32_t GTP_Init_Panel(void);
extern int gt9147_init(void);
}
extern int16_t volatile pre_x[1];
extern int16_t volatile pre_y[1];
//extern struct rt_touch_data *read_data;
void STM32TouchController::init()
{
/**
* Initialize touch controller and driver
*
*/
GTP_Init_Panel();
gt9147_init();
}
bool STM32TouchController::sampleTouch(int32_t& x, int32_t& y)
@ -47,15 +46,15 @@ bool STM32TouchController::sampleTouch(int32_t& x, int32_t& y)
*
*/
if(pre_x[0] == -1 && pre_y[0] == -1)
//if(read_data[0].x_coordinate == -1 && read_data[0].y_coordinate == -1)
{
return false;
}
else
//else
{
x = pre_x[0];
y = pre_y[0];
return true;
//x = read_data[0].x_coordinate;
// y = read_data[0].y_coordinate;
//return true;
}
}

View File

@ -43,9 +43,6 @@ menu "Onboard Peripheral Drivers"
select BSP_USING_LTDC
select BSP_USING_SDRAM
default n
config BSP_USING_TOUCH
bool "Enable TOUCH_GT9XX"
default n
config BSP_USING_MPU6050
bool "Enable MPU6050 (i2c4)"
@ -197,6 +194,23 @@ menuconfig BSP_USING_SPI
range 1 176
default 23
endif
menuconfig BSP_USING_I2C2
bool "Enable I2C2 BUS (software simulation)"
default n
select RT_USING_I2C
select RT_USING_I2C_BITOPS
select RT_USING_PIN
if BSP_USING_I2C2
comment "Notice: PB6 --> 22; PB7 --> 23"
config BSP_I2C2_SCL_PIN
int "I2C2 scl pin number"
range 1 176
default 22
config BSP_I2C2_SDA_PIN
int "I2C2 sda pin number"
range 1 176
default 23
endif
menuconfig BSP_USING_ONCHIP_RTC
bool "Enable RTC"

View File

@ -24,10 +24,6 @@ if GetDepend(['BSP_USING_SDCARD']):
if GetDepend(['BSP_USING_QSPI_MemoryMapped']):
src += Glob('ports/qspi_memorymapped.c')
if GetDepend(['BSP_USING_TOUCH']):
src += Glob('ports/bsp_i2c_touch.c')
src += Glob('ports/gt9xx.c')
path = [cwd]
path += [cwd + '/CubeMX_Config/Inc']
path += [cwd + '/ports']

View File

@ -338,7 +338,7 @@
<MiscControls></MiscControls>
<Define>STM32F767xx, USE_HAL_DRIVER, RT_USING_ARM_LIBC</Define>
<Undefine></Undefine>
<IncludePath>.;rt-thread\include;applications;.;board;board\CubeMX_Config\Inc;board\ports;libraries\HAL_Drivers;libraries\HAL_Drivers\config;board\CubeMX_Config\Src;board\CubeMX_Config\Middlewares\ST\touchgfx\framework\include;board\CubeMX_Config\Src\generated\fonts\include;board\CubeMX_Config\Src\generated\gui_generated\include;board\CubeMX_Config\Src\generated\images\include;board\CubeMX_Config\Src\generated\texts\include;board\CubeMX_Config\Src\gui\include;packages\at_device-latest\inc;packages\at_device-latest\class\esp8266;packages\netutils-latest\ntp;packages\sht3x-latest;rt-thread\libcpu\arm\common;rt-thread\libcpu\arm\cortex-m7;rt-thread\components\cplusplus;rt-thread\components\drivers\include;rt-thread\components\drivers\include;rt-thread\components\drivers\include;rt-thread\components\drivers\include;rt-thread\components\drivers\spi;rt-thread\components\drivers\include;rt-thread\components\drivers\include;rt-thread\components\drivers\touch;rt-thread\components\drivers\include;rt-thread\components\finsh;rt-thread\components\libc\compilers\armlibc;rt-thread\components\libc\compilers\common;rt-thread\components\net\at\include;rt-thread\components\net\at\at_socket;rt-thread\components\net\netdev\include;rt-thread\components\net\sal_socket\include;rt-thread\components\net\sal_socket\include\socket;rt-thread\components\net\sal_socket\impl;rt-thread\components\net\sal_socket\include\socket\sys_socket;rt-thread\components\utilities\ulog;libraries\STM32F7xx_HAL\STM32F7xx_HAL_Driver\Inc;libraries\STM32F7xx_HAL\CMSIS\Device\ST\STM32F7xx\Include;libraries\STM32F7xx_HAL\CMSIS\Include</IncludePath>
<IncludePath>.;rt-thread\include;applications;.;board;board\CubeMX_Config\Inc;board\ports;libraries\HAL_Drivers;libraries\HAL_Drivers\config;board\CubeMX_Config\Src;board\CubeMX_Config\Middlewares\ST\touchgfx\framework\include;board\CubeMX_Config\Src\generated\fonts\include;board\CubeMX_Config\Src\generated\gui_generated\include;board\CubeMX_Config\Src\generated\images\include;board\CubeMX_Config\Src\generated\texts\include;board\CubeMX_Config\Src\gui\include;packages\at_device-latest\inc;packages\at_device-latest\class\esp8266;packages\gt9147-latest\inc;packages\netutils-latest\ntp;packages\sht3x-latest;rt-thread\libcpu\arm\common;rt-thread\libcpu\arm\cortex-m7;rt-thread\components\cplusplus;rt-thread\components\drivers\include;rt-thread\components\drivers\include;rt-thread\components\drivers\include;rt-thread\components\drivers\include;rt-thread\components\drivers\spi;rt-thread\components\drivers\include;rt-thread\components\drivers\include;rt-thread\components\drivers\touch;rt-thread\components\drivers\include;rt-thread\components\finsh;rt-thread\components\libc\compilers\armlibc;rt-thread\components\libc\compilers\common;rt-thread\components\net\at\include;rt-thread\components\net\at\at_socket;rt-thread\components\net\netdev\include;rt-thread\components\net\sal_socket\include;rt-thread\components\net\sal_socket\include\socket;rt-thread\components\net\sal_socket\impl;rt-thread\components\net\sal_socket\include\socket\sys_socket;rt-thread\components\utilities\ulog;libraries\STM32F7xx_HAL\STM32F7xx_HAL_Driver\Inc;libraries\STM32F7xx_HAL\CMSIS\Device\ST\STM32F7xx\Include;libraries\STM32F7xx_HAL\CMSIS\Include</IncludePath>
</VariousControls>
</Cads>
<Aads>
@ -462,6 +462,11 @@
<FileType>1</FileType>
<FilePath>applications\main.c</FilePath>
</File>
<File>
<FileName>gtxx_ccollect.c</FileName>
<FileType>1</FileType>
<FilePath>.\applications\gtxx_ccollect.c</FilePath>
</File>
<File>
<FileName>sht30_ccollect.c</FileName>
<FileType>1</FileType>
@ -487,16 +492,6 @@
<FileType>1</FileType>
<FilePath>board\ports\qspi_memorymapped.c</FilePath>
</File>
<File>
<FileName>bsp_i2c_touch.c</FileName>
<FileType>1</FileType>
<FilePath>board\ports\bsp_i2c_touch.c</FilePath>
</File>
<File>
<FileName>gt9xx.c</FileName>
<FileType>1</FileType>
<FilePath>board\ports\gt9xx.c</FilePath>
</File>
<File>
<FileName>startup_stm32f767xx.s</FileName>
<FileType>2</FileType>
@ -739,6 +734,16 @@
</File>
</Files>
</Group>
<Group>
<GroupName>gt9147</GroupName>
<Files>
<File>
<FileName>gt9147.c</FileName>
<FileType>1</FileType>
<FilePath>packages\gt9147-latest\src\gt9147.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>NetUtils</GroupName>
<Files>

View File

@ -85,6 +85,7 @@ static void i2c_start(struct rt_i2c_bit_ops *ops)
SDA_L(ops);
i2c_delay(ops);
SCL_L(ops);
i2c_delay(ops);
}
static void i2c_restart(struct rt_i2c_bit_ops *ops)
@ -95,6 +96,7 @@ static void i2c_restart(struct rt_i2c_bit_ops *ops)
SDA_L(ops);
i2c_delay(ops);
SCL_L(ops);
i2c_delay(ops);
}
static void i2c_stop(struct rt_i2c_bit_ops *ops)

View File

@ -84,7 +84,7 @@
#define RT_SYSTEM_WORKQUEUE_STACKSIZE 2048
#define RT_SYSTEM_WORKQUEUE_PRIORITY 23
#define RT_USING_SERIAL
#define RT_SERIAL_RB_BUFSZ 64
#define RT_SERIAL_RB_BUFSZ 128
#define RT_USING_I2C
#define RT_USING_I2C_BITOPS
#define RT_USING_PIN
@ -209,6 +209,9 @@
#define PKG_USING_SHT3X
#define PKG_USING_SHT3X_LATEST_VERSION
#define PKG_USING_TOUCH_DRIVERS
#define PKG_USING_GT9147
#define PKG_USING_GT9147_LATEST_VERSION
/* miscellaneous packages */
@ -227,7 +230,6 @@
#define BSP_USING_USB_TO_USART
#define BSP_USING_SDRAM
#define BSP_USING_QSPI_MemoryMapped
#define BSP_USING_TOUCH
/* On-chip Peripheral Drivers */
@ -241,6 +243,12 @@
#define BSP_I2C1_SCL_PIN 60
#define BSP_I2C1_SDA_PIN 61
#define BSP_USING_I2C2
/* Notice: PB6 --> 22; PB7 --> 23 */
#define BSP_I2C2_SCL_PIN 116
#define BSP_I2C2_SDA_PIN 117
#define BSP_USING_ONCHIP_RTC
#define BSP_RTC_USING_LSE
#define BSP_USING_FMC