Merge pull request #2604 from willianchanlovegithub/469

[bsp][stm32][f469-disco]Add touch drivers
This commit is contained in:
Bernard Xiong authored and GitHub committed 2019-04-23 22:14:42 +08:00
commit 54faef99f6
10 files changed
+696 -44

No files matched your search

@@ -26,6 +26,19 @@ menu "Onboard Peripheral Drivers"
select FAL_USING_SFUD_PORT
default n
config BSP_USING_TOUCH
bool "Enable TOUCH"
select BSP_USING_I2C1
default n
if BSP_USING_TOUCH
config BSP_TOUCH_INT_PIN
int "Touch interrupt pin"
default 149
config BSP_I2C_NAME
string "I2C Bus Name"
default "i2c1"
endif
config BSP_MOUNT_QSPI_WITH_LFS
bool "Mount QSPI flash to / with little fs"
depends on BSP_USING_QSPI_FLASH
@@ -55,6 +68,24 @@ menu "On-chip Peripheral Drivers"
depends on BSP_USING_UART3 && RT_SERIAL_USING_DMA
default n
endif
menuconfig BSP_USING_I2C1
bool "Enable I2C1 BUS (software simulation)"
default n
select RT_USING_I2C
select RT_USING_I2C_BITOPS
select RT_USING_PIN
if BSP_USING_I2C1
comment "Notice: PB8 --> 24; PB9 --> 25"
config BSP_I2C1_SCL_PIN
int "I2C1 scl pin number"
range 1 176
default 24
config BSP_I2C1_SDA_PIN
int "I2C1 sda pin number"
range 1 176
default 25
endif
config BSP_USING_QSPI
bool "Enable QSPI BUS"
@@ -20,6 +20,9 @@ if GetDepend(['PKG_USING_FAL']):
if GetDepend(['BSP_USING_LCD_OTM8009A']):
src += Glob('ports/drv_lcd_otm8009a.c')
if GetDepend(['BSP_USING_TOUCH']):
src += Glob('ports/touch/*.c')
path = [cwd]
path += [cwd + '/CubeMX_Config/Inc']
@@ -0,0 +1,9 @@
from building import *
cwd = GetCurrentDir()
src = Glob('*.c')
CPPPATH = [cwd, str(Dir('#'))]
group = DefineGroup('touch', src, depend = ['BSP_USING_TOUCH'], CPPPATH = CPPPATH)
Return('group')
@@ -0,0 +1,196 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-02-08 Zhangyihong the first version
*/
#include "drv_touch.h"
#include <string.h>
#ifdef BSP_USING_TOUCH
#ifdef PKG_USING_GUIENGINE
#include <rtgui/event.h>
#include <rtgui/rtgui_server.h>
#elif defined(PKG_USING_LITTLEVGL2RTT)
#include <littlevgl2rtt.h>
#endif
#define BSP_TOUCH_SAMPLE_HZ (50)
#define DBG_ENABLE
#define DBG_SECTION_NAME "TOUCH"
#define DBG_LEVEL DBG_LOG
#define DBG_COLOR
#include <rtdbg.h>
static rt_list_t driver_list;
void rt_touch_drivers_register(touch_drv_t drv)
{
rt_list_insert_before(&driver_list, &drv->list);
}
static void post_down_event(rt_uint16_t x, rt_uint16_t y, rt_tick_t ts)
{
#ifdef PKG_USING_GUIENGINE
struct rtgui_event_mouse emouse;
emouse.parent.sender = RT_NULL;
emouse.wid = RT_NULL;
emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
emouse.button = RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN;
emouse.x = x;
emouse.y = y;
emouse.ts = rt_tick_get();
emouse.id = ts;
rtgui_server_post_event(&emouse.parent, sizeof(emouse));
#elif defined(PKG_USING_LITTLEVGL2RTT)
littlevgl2rtt_send_input_event(x, y, LITTLEVGL2RTT_INPUT_DOWN);
#endif
}
static void post_motion_event(rt_uint16_t x, rt_uint16_t y, rt_tick_t ts)
{
#ifdef PKG_USING_GUIENGINE
struct rtgui_event_mouse emouse;
emouse.parent.sender = RT_NULL;
emouse.wid = RT_NULL;
emouse.button = RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN;
emouse.parent.type = RTGUI_EVENT_MOUSE_MOTION;
emouse.x = x;
emouse.y = y;
emouse.ts = rt_tick_get();
emouse.id = ts;
rtgui_server_post_event(&emouse.parent, sizeof(emouse));
#elif defined(PKG_USING_LITTLEVGL2RTT)
littlevgl2rtt_send_input_event(x, y, LITTLEVGL2RTT_INPUT_MOVE);
#endif
}
static void post_up_event(rt_uint16_t x, rt_uint16_t y, rt_tick_t ts)
{
#ifdef PKG_USING_GUIENGINE
struct rtgui_event_mouse emouse;
emouse.parent.sender = RT_NULL;
emouse.wid = RT_NULL;
emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
emouse.button = RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_UP;
emouse.x = x;
emouse.y = y;
emouse.ts = rt_tick_get();
emouse.id = ts;
rtgui_server_post_event(&emouse.parent, sizeof(emouse));
#elif defined(PKG_USING_LITTLEVGL2RTT)
littlevgl2rtt_send_input_event(x, y, LITTLEVGL2RTT_INPUT_MOVE);
#endif
}
static void touch_thread_entry(void *parameter)
{
touch_drv_t touch = (touch_drv_t)parameter;
struct touch_message msg;
rt_tick_t emouse_id = 0;
touch->ops->isr_enable(RT_TRUE);
while (1)
{
if (rt_sem_take(touch->isr_sem, 10) != RT_EOK)
{
continue;
}
while(touch->ops->read_point(&msg) == RT_EOK)
{
switch (msg.event)
{
case TOUCH_EVENT_UP:
post_up_event(msg.x, msg.y, emouse_id);
break;
case TOUCH_EVENT_DOWN:
emouse_id = rt_tick_get();
post_down_event(msg.x, msg.y, emouse_id);
break;
case TOUCH_EVENT_MOVE:
post_motion_event(msg.x, msg.y, emouse_id);
break;
default:
break;
}
rt_thread_delay(RT_TICK_PER_SECOND / BSP_TOUCH_SAMPLE_HZ);
}
touch->ops->isr_enable(RT_TRUE);
}
}
static int rt_touch_driver_init(void)
{
rt_list_init(&driver_list);
return 0;
}
INIT_BOARD_EXPORT(rt_touch_driver_init);
static struct rt_i2c_bus_device *i2c_bus = RT_NULL;
static int rt_touch_thread_init(void)
{
rt_list_t *l;
touch_drv_t current_driver;
rt_thread_t tid = RT_NULL;
i2c_bus = (struct rt_i2c_bus_device *)rt_device_find(BSP_I2C_NAME);
RT_ASSERT(i2c_bus);
current_driver = RT_NULL;
if (rt_device_open((rt_device_t)i2c_bus, RT_DEVICE_OFLAG_RDWR) != RT_EOK)
return -1;
for (l = driver_list.next; l != &driver_list; l = l->next)
{
if (rt_list_entry(l, struct touch_drivers, list)->probe(i2c_bus))
{
current_driver = rt_list_entry(l, struct touch_drivers, list);
break;
}
}
if (current_driver == RT_NULL)
{
LOG_E("no touch screen or do not have driver\r\n");
rt_device_close((rt_device_t)i2c_bus);
return -1;
}
current_driver->ops->init(i2c_bus);
LOG_I("touch screen found driver\r\n");
tid = rt_thread_create("touch", touch_thread_entry, current_driver, 2048, 27, 20);
if (tid == RT_NULL)
{
current_driver->ops->deinit();
rt_device_close((rt_device_t)i2c_bus);
return -1;
}
rt_thread_startup(tid);
return 0;
}
static void touch_init_thread_entry(void *parameter)
{
rt_touch_thread_init();
}
static int touc_bg_init(void)
{
rt_thread_t tid = RT_NULL;
tid = rt_thread_create("touchi", touch_init_thread_entry, RT_NULL, 2048, 28, 20);
if (tid == RT_NULL)
{
return -1;
}
rt_thread_startup(tid);
return 0;
}
INIT_APP_EXPORT(touc_bg_init);
#endif
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-02-08 Zhangyihong the first version
*/
#ifndef __DRV_TOUCH_H__
#define __DRV_TOUCH_H__
#include "rtthread.h"
#include "rtdevice.h"
#define TOUCH_DBG_LEVEL DBG_LOG
#define IIC_RETRY_NUM 2
#define TOUCH_EVENT_UP (0x01)
#define TOUCH_EVENT_DOWN (0x02)
#define TOUCH_EVENT_MOVE (0x03)
#define TOUCH_EVENT_NONE (0x80)
struct touch_message
{
rt_uint16_t x;
rt_uint16_t y;
rt_uint8_t event;
};
typedef struct touch_message *touch_msg_t;
struct touch_ops
{
void (* isr_enable)(rt_bool_t);
rt_err_t (* read_point)(touch_msg_t);
void (* init)(struct rt_i2c_bus_device *);
void (* deinit)(void);
};
typedef struct touch_ops *touch_ops_t;
struct touch_drivers
{
rt_list_t list;
unsigned char address;
rt_bool_t (*probe)(struct rt_i2c_bus_device *i2c_bus);
rt_sem_t isr_sem;
touch_ops_t ops;
void *user_data;
};
typedef struct touch_drivers *touch_drv_t;
extern void rt_touch_drivers_register(touch_drv_t drv);
#endif
File diff suppressed because it is too large. Load diff
+18
View File
@@ -2135,6 +2135,9 @@
<file>
<name>$PROJ_DIR$\..\libraries\HAL_Drivers\drv_usart.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\libraries\HAL_Drivers\drv_soft_i2c.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\libraries\HAL_Drivers\drv_common.c</name>
</file>
@@ -2159,6 +2162,15 @@
</group>
<group>
<name>DeviceDrivers</name>
<file>
<name>$PROJ_DIR$\..\..\..\components\drivers\i2c\i2c_core.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\drivers\i2c\i2c_dev.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\drivers\i2c\i2c-bit-ops.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\drivers\misc\pin.c</name>
</file>
@@ -2291,5 +2303,11 @@
<file>
<name>$PROJ_DIR$\..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_usart.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_i2c.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_i2c_ex.c</name>
</file>
</group>
</project>
File diff suppressed because it is too large. Load diff
+43 -1
View File
@@ -359,7 +359,7 @@
<MiscControls />
<Define>USE_HAL_DRIVER, STM32F469xx</Define>
<Undefine />
<IncludePath>.;..\..\..\include;applications;board;board\CubeMX_Config\Inc;board\ports;..\libraries\HAL_Drivers;..\libraries\HAL_Drivers\config;..\..\..\libcpu\arm\common;..\..\..\libcpu\arm\cortex-m4;..\..\..\components\drivers\include;..\..\..\components\drivers\include;..\..\..\components\drivers\include;..\..\..\components\finsh;..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Inc;..\libraries\STM32F4xx_HAL\CMSIS\Device\ST\STM32F4xx\Include;..\libraries\STM32F4xx_HAL\CMSIS\Include</IncludePath>
<IncludePath>.;..\..\..\include;applications;board;board\CubeMX_Config\Inc;board\ports;..\libraries\HAL_Drivers;..\libraries\HAL_Drivers\config;..\..\..\libcpu\arm\common;..\..\..\libcpu\arm\cortex-m4;..\..\..\components\drivers\include;..\..\..\components\drivers\include;..\..\..\components\drivers\include;..\..\..\components\drivers\include;..\..\..\components\finsh;..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Inc;..\libraries\STM32F4xx_HAL\CMSIS\Device\ST\STM32F4xx\Include;..\libraries\STM32F4xx_HAL\CMSIS\Include</IncludePath>
</VariousControls>
</Cads>
<Aads>
@@ -561,6 +561,13 @@
<FilePath>..\libraries\HAL_Drivers\drv_usart.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>drv_soft_i2c.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\HAL_Drivers\drv_soft_i2c.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>drv_common.c</FileName>
@@ -609,6 +616,27 @@
</Group>
<Group>
<GroupName>DeviceDrivers</GroupName>
<Files>
<File>
<FileName>i2c_core.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\drivers\i2c\i2c_core.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>i2c_dev.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\drivers\i2c\i2c_dev.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>i2c-bit-ops.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\drivers\i2c\i2c-bit-ops.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>pin.c</FileName>
@@ -909,6 +937,20 @@
<FilePath>..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_usart.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>stm32f4xx_hal_i2c.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_i2c.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>stm32f4xx_hal_i2c_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_i2c_ex.c</FilePath>
</File>
</Files>
</Group>
</Groups>
</Target>
+26 -1
View File
@@ -338,7 +338,7 @@
<MiscControls></MiscControls>
<Define>USE_HAL_DRIVER, STM32F469xx</Define>
<Undefine></Undefine>
<IncludePath>.;..\..\..\include;applications;board;board\CubeMX_Config\Inc;board\ports;..\libraries\HAL_Drivers;..\libraries\HAL_Drivers\config;..\..\..\libcpu\arm\common;..\..\..\libcpu\arm\cortex-m4;..\..\..\components\drivers\include;..\..\..\components\drivers\include;..\..\..\components\drivers\include;..\..\..\components\finsh;..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Inc;..\libraries\STM32F4xx_HAL\CMSIS\Device\ST\STM32F4xx\Include;..\libraries\STM32F4xx_HAL\CMSIS\Include</IncludePath>
<IncludePath>.;..\..\..\include;applications;board;board\CubeMX_Config\Inc;board\ports;..\libraries\HAL_Drivers;..\libraries\HAL_Drivers\config;..\..\..\libcpu\arm\common;..\..\..\libcpu\arm\cortex-m4;..\..\..\components\drivers\include;..\..\..\components\drivers\include;..\..\..\components\drivers\include;..\..\..\components\drivers\include;..\..\..\components\finsh;..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Inc;..\libraries\STM32F4xx_HAL\CMSIS\Device\ST\STM32F4xx\Include;..\libraries\STM32F4xx_HAL\CMSIS\Include</IncludePath>
</VariousControls>
</Cads>
<Aads>
@@ -542,6 +542,21 @@
<Group>
<GroupName>DeviceDrivers</GroupName>
<Files>
<File>
<FileName>i2c_core.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\drivers\i2c\i2c_core.c</FilePath>
</File>
<File>
<FileName>i2c_dev.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\drivers\i2c\i2c_dev.c</FilePath>
</File>
<File>
<FileName>i2c-bit-ops.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\drivers\i2c\i2c-bit-ops.c</FilePath>
</File>
<File>
<FileName>pin.c</FileName>
<FileType>1</FileType>
@@ -762,6 +777,16 @@
<FileType>1</FileType>
<FilePath>..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_usart.c</FilePath>
</File>
<File>
<FileName>stm32f4xx_hal_i2c.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_i2c.c</FilePath>
</File>
<File>
<FileName>stm32f4xx_hal_i2c_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_i2c_ex.c</FilePath>
</File>
</Files>
</Group>
</Groups>