diff --git a/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/SConscript b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/SConscript index 470f1ed26..83178ff93 100644 --- a/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/SConscript +++ b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/SConscript @@ -24,6 +24,9 @@ if GetDepend('BSP_USING_LCD_XIDATONG'): src += ['ports/ok1052lcd.c'] src += ['ports/drv_lcd.c'] src += ['../../../../rt-thread/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_elcdif.c'] +if GetDepend('BSP_USING_I2C1'): + src += ['ports/touch.c'] + src += ['ports/drv_touch.c'] group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES=CPPDEFINES) Return('group') diff --git a/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/board.c b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/board.c index be037421a..3386f1f43 100644 --- a/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/board.c +++ b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/board.c @@ -1361,6 +1361,39 @@ void imxrt_lcd_pins_init(void) } #endif +#ifdef BSP_USING_I2C1 +void imxrt_lcd_iic1_init() +{ + IOMUXC_SetPinMux( + IOMUXC_GPIO_AD_B1_00_LPI2C1_SCL, /* GPIO_AD_B1_00 is configured as LPI2C1_SCL */ + 1U); /* Software Input On Field: Force input path of pad GPIO_AD_B1_00 */ + IOMUXC_SetPinMux( + IOMUXC_GPIO_AD_B1_01_LPI2C1_SDA, /* GPIO_AD_B1_01 is configured as LPI2C1_SDA */ + 1U); /* Software Input On Field: Force input path of pad GPIO_AD_B1_01 */ + IOMUXC_SetPinConfig( + IOMUXC_GPIO_AD_B1_00_LPI2C1_SCL, /* GPIO_AD_B1_00 PAD functional properties : */ + 0xD8B0u); /* Slew Rate Field: Slow Slew Rate + Drive Strength Field: R0/6 + Speed Field: medium(100MHz) + Open Drain Enable Field: Open Drain Enabled + Pull / Keep Enable Field: Pull/Keeper Enabled + Pull / Keep Select Field: Keeper + Pull Up / Down Config. Field: 22K Ohm Pull Up + Hyst. Enable Field: Hysteresis Disabled */ + IOMUXC_SetPinConfig( + IOMUXC_GPIO_AD_B1_01_LPI2C1_SDA, /* GPIO_AD_B1_01 PAD functional properties : */ + 0xD8B0u); /* Slew Rate Field: Slow Slew Rate + Drive Strength Field: R0/6 + Speed Field: medium(100MHz) + Open Drain Enable Field: Open Drain Enabled + Pull / Keep Enable Field: Pull/Keeper Enabled + Pull / Keep Select Field: Keeper + Pull Up / Down Config. Field: 22K Ohm Pull Up + Hyst. Enable Field: Hysteresis Disabled */ + +} +#endif + void rt_hw_board_init() { BOARD_ConfigMPU(); @@ -1405,6 +1438,10 @@ void rt_hw_board_init() imxrt_lcd_pins_init(); #endif +#ifdef BSP_USING_I2C1 + imxrt_lcd_iic1_init(); +#endif + #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) rt_console_set_device(RT_CONSOLE_DEVICE_NAME); #endif diff --git a/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/ports/dev_touch.h b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/ports/dev_touch.h deleted file mode 100644 index 2b40ee1e7..000000000 --- a/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/ports/dev_touch.h +++ /dev/null @@ -1,40 +0,0 @@ -/* -* Copyright (c) 2020 AIIT XUOS Lab -* XiUOS is licensed under Mulan PSL v2. -* You can use this software according to the terms and conditions of the Mulan PSL v2. -* You may obtain a copy of Mulan PSL v2 at: -* http://license.coscl.org.cn/MulanPSL2 -* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, -* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, -* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. -* See the Mulan PSL v2 for more details. -*/ - -/** -* @file dev_touch.h -* @brief define touch dev function using bus driver framework -* @version 1.0 -* @author AIIT XUOS Lab -* @date 2021-04-24 -*/ - -#ifndef DEV_TOUCH_H -#define DEV_TOUCH_H - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif -struct TouchDataStandard -{ - uint16 x; - uint16 y; -}; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/ports/drv_touch.c b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/ports/drv_touch.c new file mode 100644 index 000000000..3e28105db --- /dev/null +++ b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/ports/drv_touch.c @@ -0,0 +1,207 @@ +#include +#include +#include "drv_touch.h" +#ifdef BSP_USING_I2C1 +rt_uint8_t CTP_CFG_GT911[] = { + 0x5B,0xE0,0x01,0x10,0x01,0x0A,0x0D,0x00,0x01,0x0A, + 0x28,0x0F,0x5A,0x3C,0x03,0x05,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x87,0x28,0x09, + 0x32,0x34,0x0C,0x08,0x00,0x00,0x00,0x02,0x02,0x1D, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x28,0x55,0x94,0xC5,0x02,0x07,0x00,0x00,0x04, + 0x8D,0x2B,0x00,0x80,0x32,0x00,0x75,0x3A,0x00,0x6C, + 0x43,0x00,0x64,0x4F,0x00,0x64,0x00,0x00,0x00,0x00, + 0xF0,0x4A,0x3A,0xFF,0xFF,0x27,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x04,0x06,0x08,0x0A,0x0C,0x0E,0x10,0x12, + 0x14,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x26,0x24,0x22,0x21,0x20,0x1F,0x1E,0x1D, + 0x0C,0x0A,0x08,0x06,0x04,0x02,0x00,0xFF,0xFF,0xFF, + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x81,0x01 +}; +rt_uint8_t config[GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH] + = {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff}; + +void ok1052_touch_init(struct rt_touch_device *touch) +{ + rt_int32_t ret = -1; + rt_int32_t i = 0; + rt_uint8_t check_sum = 0; + rt_int32_t retry = 0; + rt_uint8_t cfg_num =0x80FE - 0x8047+1 ; + struct rt_i2c_msg msgs_w; + const rt_uint8_t* cfg_info = CTP_CFG_GT911; + + rt_uint8_t cfg_info_len = CFG_GROUP_LEN(CTP_CFG_GT911) ; + + rt_memset(&config[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH); + rt_memcpy(&config[GTP_ADDR_LENGTH], cfg_info,cfg_info_len); + rt_ok1052_t dev = (rt_ok1052_t)touch; + check_sum = 0; + for (i = GTP_ADDR_LENGTH; i < cfg_num+GTP_ADDR_LENGTH; i++) + { + check_sum += config[i]; + } + config[ cfg_num+GTP_ADDR_LENGTH] = (~check_sum) + 1; + config[ cfg_num+GTP_ADDR_LENGTH+1] = 1; + + msgs_w.addr = RT_GTP_ADDRESS; + msgs_w.flags = RT_I2C_WR; + msgs_w.len = cfg_num + GTP_ADDR_LENGTH+2; + msgs_w.buf = config; + + ret = rt_i2c_transfer(dev->i2c,&msgs_w,1); + if (ret < 0) + { + rt_kprintf("I2C write end_cmd error!\n"); + ret = 0; + } +} + +TouchDataStandard_drv Pre_Touch_Point = {0}; +static rt_size_t ok1052_touch_readpoint(struct rt_touch_device *touch, void *buf, rt_size_t touch_num) +{ + int ret = 0; + static int int_time = 0; + if(0 == int_time) + { + ok1052_touch_init(touch); + int_time =1; + } + rt_uint8_t end_cmd[3] = { GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF, 0 }; + rt_uint8_t point_data[2 + 1 + 8 * GTP_MAX_TOUCH + 1]={GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF}; + rt_uint8_t retries = 0; + rt_uint8_t finger = 0; + rt_uint8_t touch_num1 = 0; + static rt_uint16_t pre_touch = 0; + rt_uint8_t* coor_data = NULL; + if (touch_num == 0 || touch_num > GTP_MAX_TOUCH) + { + return 0; + } + TouchDataStandard_drv *result = (TouchDataStandard_drv *)buf; + rt_ok1052_t dev = (rt_ok1052_t)touch; + struct rt_i2c_msg msgs[2]; + struct rt_i2c_msg msgs_w; + msgs[0].addr = RT_GTP_ADDRESS; + msgs[0].flags = RT_I2C_WR; + msgs[0].len = GTP_ADDR_LENGTH; + msgs[0].buf = &point_data[0]; + + msgs[1].addr = RT_GTP_ADDRESS; + msgs[1].flags = RT_I2C_RD; + msgs[1].len = 12-GTP_ADDR_LENGTH; + msgs[1].buf = &point_data[GTP_ADDR_LENGTH]; + while(retries < 5) + { + if(2 != rt_i2c_transfer(dev->i2c,msgs,2)) + { + retries++; + if(retries >= 5) + { + return -RT_ERROR; + } + } + else + { + break; + } + } + finger = point_data[GTP_ADDR_LENGTH];//状态寄存器数据 + if (finger == 0x00) //没有数据,退出 + { + ret = 0; + goto exit_work_func; + } + if((finger & 0x80) == 0)//判断buffer status位 + { + ret = 0; + goto exit_work_func;//坐标未就绪,数据无效 + } + touch_num1 = finger & 0x0f;//坐标点数 + if(touch_num1 > GTP_MAX_TOUCH) + { + ret = 0; + goto exit_work_func;//大于最大支持点数,错误退出 + } + if (touch_num1) + { + coor_data = &point_data[0 * 8 + 3]; + result->x = coor_data[1] | (coor_data[2] << 8); //x坐标 + result->y = coor_data[3] | (coor_data[4] << 8); //y坐标 + } + else if(pre_touch) + { + *result = Pre_Touch_Point; + result->x = -1; + result->y = -1; + } + pre_touch = touch_num1; +exit_work_func: + { + msgs_w.addr = RT_GTP_ADDRESS; + msgs_w.flags = RT_I2C_WR; + msgs_w.len = 3; + msgs_w.buf = &end_cmd[0]; + + ret = rt_i2c_transfer(dev->i2c,&msgs_w,1); + if (ret < 0) + { + rt_kprintf("I2C write end_cmd error!\n"); + ret = 0; + } + } + return ret; + +} + +static rt_size_t ok1052_touch_control(struct rt_touch_device *touch, int cmd, void *arg) +{ + rt_err_t result = RT_EOK; + RT_ASSERT(touch != RT_NULL); + + /* If necessary, please implement this control function yourself */ + + return result; +} + +static struct rt_touch_ops ok1052_ops = +{ + .touch_readpoint = ok1052_touch_readpoint, + .touch_control = ok1052_touch_control, +}; + +static int ok1052_hw_init(void) +{ + rt_ok1052_t dev_obj = rt_malloc(sizeof(struct rt_ok1052)); + if (dev_obj != RT_NULL) + { + rt_memset(dev_obj, 0x0, sizeof(struct rt_ok1052)); + dev_obj->i2c= (struct rt_i2c_bus_device *)rt_device_find(OK1052_TOUCH_IIC_NAME); + RT_ASSERT(dev_obj->i2c != RT_NULL ); + dev_obj->parent.info.type = RT_TOUCH_TYPE_RESISTANCE; + dev_obj->parent.info.vendor = RT_TOUCH_VENDOR_UNKNOWN; + dev_obj->parent.info.point_num = GTP_MAX_TOUCH; + dev_obj->parent.info.range_x = GTP_MAX_WIDTH; + dev_obj->parent.info.range_y = GTP_MAX_HEIGHT; +#ifdef RT_TOUCH_PIN_IRQ + dev_obj->parent.config.irq_pin.pin = BSP_OK1052_IRQ_PIN; + dev_obj->parent.config.irq_pin.mode = PIN_MODE_INPUT; + +#endif /* RT_TOUCH_PIN_IRQ */ + dev_obj->parent.ops = &ok1052_ops; + rt_hw_touch_register(&(dev_obj->parent), OK1052_TOUCH_NAME, RT_DEVICE_FLAG_INT_RX, RT_NULL); + return RT_EOK; + } + else + { + return -RT_ERROR; + } +} + +INIT_APP_EXPORT(ok1052_hw_init); +#endif \ No newline at end of file diff --git a/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/ports/drv_touch.h b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/ports/drv_touch.h new file mode 100644 index 000000000..8e1f0a941 --- /dev/null +++ b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/ports/drv_touch.h @@ -0,0 +1,76 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** +* @file dev_touch.h +* @brief define touch dev function using bus driver framework +* @version 1.0 +* @author AIIT XUOS Lab +* @date 2021-04-24 +*/ + +#ifndef DEV_TOUCH_H +#define DEV_TOUCH_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +#define CFG_GROUP_LEN(p_cfg_grp) (sizeof(p_cfg_grp) / sizeof(p_cfg_grp[0])) +#define OK1052_TOUCH_NAME "touch" +#define OK1052_TOUCH_IIC_NAME "i2c1" +#define BSP_OK1052_IRQ_PIN (62) +/*设定使用的电容屏IIC设备地址*/ +#define GTP_ADDRESS 0xBA +#define RT_GTP_ADDRESS (GTP_ADDRESS >> 1) +#define GTP_MAX_HEIGHT 272 +#define GTP_MAX_WIDTH 480 +#define GTP_INT_TRIGGER 0 +#define GTP_MAX_TOUCH 5 + +#define GTP_CONFIG_MAX_LENGTH 240 +#define GTP_ADDR_LENGTH 2 + +// Registers define +#define GTP_READ_COOR_ADDR 0x814E +#define GTP_REG_SLEEP 0x8040 +#define GTP_REG_SENSOR_ID 0x814A +#define GTP_REG_CONFIG_DATA 0x8047 +#define GTP_REG_VERSION 0x8140 + +typedef struct +{ + uint16_t x; + uint16_t y; +}TouchDataStandard_drv; + + + + +struct rt_ok1052 +{ + struct rt_touch_device parent; + struct rt_i2c_bus_device *i2c; +}; +typedef struct rt_ok1052 *rt_ok1052_t; + + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/ports/touch.c b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/ports/touch.c new file mode 100644 index 000000000..3f626cd94 --- /dev/null +++ b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/ports/touch.c @@ -0,0 +1,322 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2019-05-20 tyustli the first version + */ + +#include "touch.h" +#include +#ifdef RT_USING_POSIX +#include +#include +#ifdef RT_USING_POSIX_TERMIOS +#include +#endif +#endif +#define DBG_TAG "touch" +#define DBG_LVL DBG_INFO +#include + +/* ISR for touch interrupt */ +void rt_hw_touch_isr(rt_touch_t touch) +{ + RT_ASSERT(touch); + if (touch->parent.rx_indicate == RT_NULL) + { + return; + } + + if (touch->irq_handle != RT_NULL) + { + touch->irq_handle(touch); + } + + touch->parent.rx_indicate(&touch->parent, 1); +} + +#ifdef RT_TOUCH_PIN_IRQ +static void touch_irq_callback(void *param) +{ + rt_hw_touch_isr((rt_touch_t)param); +} +#endif + +/* touch interrupt initialization function */ +static rt_err_t rt_touch_irq_init(rt_touch_t touch) +{ +#ifdef RT_TOUCH_PIN_IRQ + if (touch->config.irq_pin.pin == RT_PIN_NONE) + { + return -RT_EINVAL; + } + + rt_pin_mode(touch->config.irq_pin.pin, touch->config.irq_pin.mode); + + if (touch->config.irq_pin.mode == PIN_MODE_INPUT_PULLDOWN) + { + rt_pin_attach_irq(touch->config.irq_pin.pin, PIN_IRQ_MODE_RISING, touch_irq_callback, (void *)touch); + } + else if (touch->config.irq_pin.mode == PIN_MODE_INPUT_PULLUP) + { + rt_pin_attach_irq(touch->config.irq_pin.pin, PIN_IRQ_MODE_FALLING, touch_irq_callback, (void *)touch); + } + else if (touch->config.irq_pin.mode == PIN_MODE_INPUT) + { + rt_pin_attach_irq(touch->config.irq_pin.pin, PIN_IRQ_MODE_RISING_FALLING, touch_irq_callback, (void *)touch); + } + + rt_pin_irq_enable(touch->config.irq_pin.pin, PIN_IRQ_ENABLE); +#endif + + return RT_EOK; +} + +/* touch interrupt enable */ +static void rt_touch_irq_enable(rt_touch_t touch) +{ +#ifdef RT_TOUCH_PIN_IRQ + if (touch->config.irq_pin.pin != RT_PIN_NONE) + { + rt_pin_irq_enable(touch->config.irq_pin.pin, RT_TRUE); + } +#else + touch->ops->touch_control(touch, RT_TOUCH_CTRL_ENABLE_INT, RT_NULL); +#endif +} + +/* touch interrupt disable */ +static void rt_touch_irq_disable(rt_touch_t touch) +{ +#ifdef RT_TOUCH_PIN_IRQ + if (touch->config.irq_pin.pin != RT_PIN_NONE) + { + rt_pin_irq_enable(touch->config.irq_pin.pin, RT_FALSE); + } +#else + touch->ops->touch_control(touch, RT_TOUCH_CTRL_DISABLE_INT, RT_NULL); +#endif +} + +static rt_err_t rt_touch_open(rt_device_t dev, rt_uint16_t oflag) +{ + rt_touch_t touch; + RT_ASSERT(dev != RT_NULL); + touch = (rt_touch_t)dev; + + if (oflag & RT_DEVICE_FLAG_INT_RX && dev->flag & RT_DEVICE_FLAG_INT_RX) + { + /* Initialization touch interrupt */ + rt_touch_irq_init(touch); + } + + return RT_EOK; +} + +static rt_err_t rt_touch_close(rt_device_t dev) +{ + rt_touch_t touch; + RT_ASSERT(dev != RT_NULL); + touch = (rt_touch_t)dev; + + /* touch disable interrupt */ + rt_touch_irq_disable(touch); + + return RT_EOK; +} + +static rt_size_t rt_touch_read(rt_device_t dev, rt_off_t pos, void *buf, rt_size_t len) +{ + rt_touch_t touch; + rt_size_t result = 0; + RT_ASSERT(dev != RT_NULL); + touch = (rt_touch_t)dev; + + if (buf == NULL || len == 0) + { + return 0; + } + + result = touch->ops->touch_readpoint(touch, buf, len); + + return result; +} + +static rt_err_t rt_touch_control(rt_device_t dev, int cmd, void *args) +{ + rt_touch_t touch; + rt_err_t result = RT_EOK; + RT_ASSERT(dev != RT_NULL); + touch = (rt_touch_t)dev; + + switch (cmd) + { + case RT_TOUCH_CTRL_SET_MODE: + result = touch->ops->touch_control(touch, RT_TOUCH_CTRL_SET_MODE, args); + + if (result == RT_EOK) + { + rt_uint16_t mode; + mode = *(rt_uint16_t*)args; + if (mode == RT_DEVICE_FLAG_INT_RX) + { + rt_touch_irq_enable(touch); /* enable interrupt */ + } + } + + break; + case RT_TOUCH_CTRL_SET_X_RANGE: + result = touch->ops->touch_control(touch, RT_TOUCH_CTRL_SET_X_RANGE, args); + + if (result == RT_EOK) + { + touch->info.range_x = *(rt_int32_t *)args; + LOG_D("set x coordinate range :%d\n", touch->info.range_x); + } + + break; + case RT_TOUCH_CTRL_SET_Y_RANGE: + result = touch->ops->touch_control(touch, RT_TOUCH_CTRL_SET_Y_RANGE, args); + + if (result == RT_EOK) + { + touch->info.range_y = *(rt_uint32_t *)args; + LOG_D("set y coordinate range :%d \n", touch->info.range_x); + } + + break; + case RT_TOUCH_CTRL_DISABLE_INT: + rt_touch_irq_disable(touch); + break; + case RT_TOUCH_CTRL_ENABLE_INT: + rt_touch_irq_enable(touch); + break; + + case RT_TOUCH_CTRL_GET_ID: + case RT_TOUCH_CTRL_GET_INFO: + default: + return touch->ops->touch_control(touch, cmd, args); + } + + return result; +} + +#ifdef RT_USING_POSIX +static int touch_fops_open(struct dfs_fd *fd) +{ + rt_err_t ret = RT_EOK; + rt_uint16_t flags = 0; + rt_device_t device; + device = (rt_device_t)fd->data; + RT_ASSERT(device != RT_NULL); + flags = RT_DEVICE_FLAG_INT_RX; + ret = rt_device_open(device, flags); + if (ret == RT_EOK) + { + return RT_EOK; + } + else + { + return ret; + } + +} + +static int touch_fops_close(struct dfs_fd *fd) +{ + rt_device_t device; + device = (rt_device_t)fd->data; + rt_device_close(device); + return RT_EOK; +} + +static int touch_fops_ioctl(struct dfs_fd *fd, int cmd, void *args) +{ + rt_device_t device; + device = (rt_device_t)fd->data; + return rt_device_control(device, cmd, args); +} + +static int touch_fops_read(struct dfs_fd *fd, void *buf, size_t count) +{ + int size = 0; + rt_device_t device; + device = (rt_device_t)fd->data; + return rt_device_read(device, -1, buf, count); +} + + + +const static struct dfs_file_ops touch_fops = +{ + touch_fops_open, + touch_fops_close, + touch_fops_ioctl, + touch_fops_read, + RT_NULL, + RT_NULL, /* flush */ + RT_NULL, /* lseek */ + RT_NULL, /* getdents */ + RT_NULL,/*poll*/ +}; +#endif + + +#ifdef RT_USING_DEVICE_OPS +const static struct rt_device_ops rt_touch_ops = +{ + RT_NULL, + rt_touch_open, + rt_touch_close, + rt_touch_read, + RT_NULL, + rt_touch_control +}; +#endif + +/* + * touch register + */ +int rt_hw_touch_register(rt_touch_t touch, + const char *name, + rt_uint32_t flag, + void *data) +{ + rt_int8_t result; + rt_device_t device; + RT_ASSERT(touch != RT_NULL); + + device = &touch->parent; + +#ifdef RT_USING_DEVICE_OPS + device->ops = &rt_touch_ops; +#else + device->init = RT_NULL; + device->open = rt_touch_open; + device->close = rt_touch_close; + device->read = rt_touch_read; + device->write = RT_NULL; + device->control = rt_touch_control; +#endif + device->type = RT_Device_Class_Touch; + device->rx_indicate = RT_NULL; + device->tx_complete = RT_NULL; + device->user_data = data; +#ifdef RT_USING_POSIX + device->fops = &touch_fops; +#endif + result = rt_device_register(device, name, flag | RT_DEVICE_FLAG_STANDALONE); + + if (result != RT_EOK) + { + LOG_E("rt_touch register err code: %d", result); + return result; + } + + LOG_I("rt_touch init success"); + + return RT_EOK; +} diff --git a/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/ports/touch.h b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/ports/touch.h new file mode 100644 index 000000000..d935ee7b9 --- /dev/null +++ b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/ports/touch.h @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2019-05-20 tyustli the first version + */ + +#ifndef __TOUCH_H__ +#define __TOUCH_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define RT_TOUCH_PIN_IRQ + +#ifdef RT_USING_RTC +#define rt_touch_get_ts() time(RT_NULL) /* API for the touch to get the timestamp */ +#else +#define rt_touch_get_ts() rt_tick_get() /* API for the touch to get the timestamp */ +#endif + +#define RT_PIN_NONE 0xFFFF /* RT PIN NONE */ + +/* Touch vendor types */ +#define RT_TOUCH_VENDOR_UNKNOWN (0) /* unknown */ +#define RT_TOUCH_VENDOR_GT (1) /* GTxx series */ +#define RT_TOUCH_VENDOR_FT (2) /* FTxx series */ + +/* Touch ic type*/ +#define RT_TOUCH_TYPE_NONE (0) /* touch ic none */ +#define RT_TOUCH_TYPE_CAPACITANCE (1) /* capacitance ic */ +#define RT_TOUCH_TYPE_RESISTANCE (2) /* resistance ic */ + +/* Touch control cmd types */ +#define RT_TOUCH_CTRL_GET_ID (0) /* Get device id */ +#define RT_TOUCH_CTRL_GET_INFO (1) /* Get touch info */ +#define RT_TOUCH_CTRL_SET_MODE (2) /* Set touch's work mode. ex. RT_TOUCH_MODE_POLLING,RT_TOUCH_MODE_INT */ +#define RT_TOUCH_CTRL_SET_X_RANGE (3) /* Set x coordinate range */ +#define RT_TOUCH_CTRL_SET_Y_RANGE (4) /* Set y coordinate range */ +#define RT_TOUCH_CTRL_SET_X_TO_Y (5) /* Set X Y coordinate exchange */ +#define RT_TOUCH_CTRL_DISABLE_INT (6) /* Disable interrupt */ +#define RT_TOUCH_CTRL_ENABLE_INT (7) /* Enable interrupt */ +#define RT_TOUCH_CTRL_POWER_ON (8) /* Touch Power On */ +#define RT_TOUCH_CTRL_POWER_OFF (9) /* Touch Power Off */ +#define RT_TOUCH_CTRL_GET_STATUS (10) /* Get Touch Power Status */ + +/* Touch event */ +#define RT_TOUCH_EVENT_NONE (0) /* Touch none */ +#define RT_TOUCH_EVENT_UP (1) /* Touch up event */ +#define RT_TOUCH_EVENT_DOWN (2) /* Touch down event */ +#define RT_TOUCH_EVENT_MOVE (3) /* Touch move event */ + +struct rt_touch_info +{ + rt_uint8_t type; /* The touch type */ + rt_uint8_t vendor; /* Vendor of touchs */ + rt_uint8_t point_num; /* Support point num */ + rt_int32_t range_x; /* X coordinate range */ + rt_int32_t range_y; /* Y coordinate range */ +}; + +struct rt_touch_config +{ +#ifdef RT_TOUCH_PIN_IRQ + struct rt_device_pin_mode irq_pin; /* Interrupt pin, The purpose of this pin is to notification read data */ +#endif + char *dev_name; /* The name of the communication device */ + void *user_data; +}; + +typedef struct rt_touch_device *rt_touch_t; +struct rt_touch_device +{ + struct rt_device parent; /* The standard device */ + struct rt_touch_info info; /* The touch info data */ + struct rt_touch_config config; /* The touch config data */ + + const struct rt_touch_ops *ops; /* The touch ops */ + rt_err_t (*irq_handle)(rt_touch_t touch); /* Called when an interrupt is generated, registered by the driver */ +}; + +struct rt_touch_data +{ + rt_uint8_t event; /* The touch event of the data */ + rt_uint8_t track_id; /* Track id of point */ + rt_uint8_t width; /* Point of width */ + rt_uint16_t x_coordinate; /* Point of x coordinate */ + rt_uint16_t y_coordinate; /* Point of y coordinate */ + rt_tick_t timestamp; /* The timestamp when the data was received */ +}; + +struct rt_touch_ops +{ + rt_size_t (*touch_readpoint)(struct rt_touch_device *touch, void *buf, rt_size_t touch_num); + rt_err_t (*touch_control)(struct rt_touch_device *touch, int cmd, void *arg); +}; + +int rt_hw_touch_register(rt_touch_t touch, + const char *name, + rt_uint32_t flag, + void *data); + +/* if you doesn't use pin device. you must call this function in your touch irq callback */ +void rt_hw_touch_isr(rt_touch_t touch); + +#ifdef __cplusplus +} +#endif + +#endif /* __TOUCH_H__ */