diff options
| author | Bernard Xiong <[email protected]> | 2021-05-28 16:20:08 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-05-28 16:20:08 +0800 |
| commit | 92beddf3bccf6346e26aa097f82464456fb8e6bd (patch) | |
| tree | 197e4a108118dda016ea02274172f0c40e7ee8ed /bsp/ls1cdev/drivers/touch.c | |
| parent | b18a99b44240ec3152011e159cc24a5af8dff0ce (diff) | |
| parent | 03f4d40e30f3c94e1db0b3a65b3610dee695694a (diff) | |
Merge pull request #4737 from mysterywolf/3,1,xformatv3.1.5
[lts 3.1.x] format codes
Diffstat (limited to 'bsp/ls1cdev/drivers/touch.c')
| -rw-r--r-- | bsp/ls1cdev/drivers/touch.c | 92 |
1 files changed, 46 insertions, 46 deletions
diff --git a/bsp/ls1cdev/drivers/touch.c b/bsp/ls1cdev/drivers/touch.c index 37a4b19213..1535faf444 100644 --- a/bsp/ls1cdev/drivers/touch.c +++ b/bsp/ls1cdev/drivers/touch.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -7,13 +7,13 @@ * Date Author Notes * 2017-12-30 Sundm75 first version */ - + #include <rtthread.h> #include <rtdevice.h> #include <stdbool.h> #include <drivers/spi.h> #include "ls1c.h" -#include "ls1c_gpio.h" +#include "ls1c_gpio.h" #include "ls1c_spi.h" #include "drv_spi.h" #include "touch.h" @@ -44,7 +44,7 @@ TOUCH INT: 84 */ #define IS_TOUCH_UP() gpio_get(TOUCH_INT_PIN) -#define led_gpio 52 // led1指示 +#define led_gpio 52 // led1指示 #define DUMMY 0x00 @@ -88,12 +88,12 @@ s A2-A0 MODE SER/DFR PD1-PD0 #if defined(_ILI_HORIZONTAL_DIRECTION_) #define MIN_X_DEFAULT 2047 #define MAX_X_DEFAULT 47 -#define MIN_Y_DEFAULT 102 -#define MAX_Y_DEFAULT 1939 +#define MIN_Y_DEFAULT 102 +#define MAX_Y_DEFAULT 1939 #else #define MIN_X_DEFAULT 47 #define MAX_X_DEFAULT 2047 -#define MIN_Y_DEFAULT 1939 +#define MIN_Y_DEFAULT 1939 #define MAX_Y_DEFAULT 102 #endif @@ -105,29 +105,29 @@ s A2-A0 MODE SER/DFR PD1-PD0 /*宏定义 */ -#define TOUCH_SPI_X SPI1 -#define TOUCH_INT_PIN 84 -#define TOUCH_CS_PIN 49 +#define TOUCH_SPI_X SPI1 +#define TOUCH_INT_PIN 84 +#define TOUCH_CS_PIN 49 #define TOUCH_SCK_PIN 46 #define TOUCH_MISO_PIN 47 -#define TOUCH_MOSI_PIN 48 +#define TOUCH_MOSI_PIN 48 /*创建结构体将需要用到的东西进行打包*/ -struct rtgui_touch_device +struct rtgui_touch_device { struct rt_device parent; /* 用于注册设备*/ - rt_uint16_t x, y; /* 记录读取到的位置值 */ + rt_uint16_t x, y; /* 记录读取到的位置值 */ - rt_bool_t calibrating; /* 触摸校准标志 */ - rt_touch_calibration_func_t calibration_func;/* 触摸函数 函数指针 */ + rt_bool_t calibrating; /* 触摸校准标志 */ + rt_touch_calibration_func_t calibration_func;/* 触摸函数 函数指针 */ - rt_uint16_t min_x, max_x; /* 校准后 X 方向最小 最大值 */ + rt_uint16_t min_x, max_x; /* 校准后 X 方向最小 最大值 */ rt_uint16_t min_y, max_y; /* 校准后 Y 方向最小 最大值 */ - struct rt_spi_device * spi_device; /* SPI 设备 用于通信 */ - struct rt_event event; /* 事件同步,用于“笔中断” */ + struct rt_spi_device * spi_device; /* SPI 设备 用于通信 */ + struct rt_event event; /* 事件同步,用于“笔中断” */ }; static struct rtgui_touch_device *touch = RT_NULL; @@ -255,14 +255,14 @@ static void rtgui_touch_calculate(void) rt_uint32_t total_x = 0; rt_uint32_t total_y = 0; for(k=0; k<2; k++) - { + { // sorting the ADC value for(i=0; i<SAMP_CNT-1; i++) { min=i; for (j=i+1; j<SAMP_CNT; j++) { - if (tmpxy[k][min] > tmpxy[k][j]) + if (tmpxy[k][min] > tmpxy[k][j]) min=j; } temp = tmpxy[k][i]; @@ -329,11 +329,11 @@ void ls1c_touch_irqhandler(void) /* TouchScreen */ { if(gpio_get(TOUCH_INT_PIN)==0) { - /* 触摸屏按下后操作 */ + /* 触摸屏按下后操作 */ if (gpio_level_low == gpio_get(led_gpio)) - gpio_set(led_gpio, gpio_level_high); + gpio_set(led_gpio, gpio_level_high); else - gpio_set(led_gpio, gpio_level_low); + gpio_set(led_gpio, gpio_level_low); touch_int_cmd(RT_FALSE); rt_event_send(&touch->event, 1); } @@ -341,19 +341,19 @@ void ls1c_touch_irqhandler(void) /* TouchScreen */ /*管脚初始化,配置中断打开SPI1 CS0 设备*/ rt_inline void touch_init(void) -{ +{ unsigned int touch_int_gpio = TOUCH_INT_PIN; // 触摸屏中断 - int touch_irq = LS1C_GPIO_TO_IRQ(touch_int_gpio); - - // 初始化按键中断 - gpio_set_irq_type(touch_int_gpio, IRQ_TYPE_EDGE_FALLING); - rt_hw_interrupt_install(touch_irq, ls1c_touch_irqhandler, RT_NULL, "touch"); - rt_hw_interrupt_umask(touch_irq); - gpio_init(touch_int_gpio, gpio_mode_input); - - // 初始化led - gpio_init(led_gpio, gpio_mode_output); - gpio_set(led_gpio, gpio_level_high); + int touch_irq = LS1C_GPIO_TO_IRQ(touch_int_gpio); + + // 初始化按键中断 + gpio_set_irq_type(touch_int_gpio, IRQ_TYPE_EDGE_FALLING); + rt_hw_interrupt_install(touch_irq, ls1c_touch_irqhandler, RT_NULL, "touch"); + rt_hw_interrupt_umask(touch_irq); + gpio_init(touch_int_gpio, gpio_mode_input); + + // 初始化led + gpio_init(led_gpio, gpio_mode_output); + gpio_set(led_gpio, gpio_level_high); } @@ -363,7 +363,7 @@ static rt_err_t rtgui_touch_init (rt_device_t dev) rt_uint8_t send; rt_uint8_t recv_buffer[2]; struct rtgui_touch_device * touch_device = (struct rtgui_touch_device *)dev; - + touch_init(); rt_kprintf("touch_init ...\n"); send = START | DIFFERENTIAL | POWER_MODE0; @@ -440,18 +440,18 @@ static void touch_thread_entry(void *parameter) emouse.x = touch->x; emouse.y = touch->y; - if(touch_down != RT_TRUE) - { + if(touch_down != RT_TRUE) + { touch_int_cmd(RT_TRUE); break; - } + } if ((touch->calibrating == RT_TRUE) && (touch->calibration_func != RT_NULL)) { /* 触摸校准处理 */ /* callback function */ touch->calibration_func(emouse.x, emouse.y); - + } else { @@ -482,7 +482,7 @@ static void touch_thread_entry(void *parameter) /* calculation */ rtgui_touch_calculate(); - + /* send mouse event */ emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON; emouse.parent.sender = RT_NULL; @@ -532,7 +532,7 @@ static void touch_thread_entry(void *parameter) rt_err_t rtgui_touch_hw_init(const char * spi_device_name) { - rt_uint32_t arg[2]; + rt_uint32_t arg[2]; struct rt_device * spi_device; struct rt_thread * touch_thread; rt_err_t err; @@ -550,12 +550,12 @@ rt_err_t rtgui_touch_hw_init(const char * spi_device_name) rt_kprintf("Open spi1 failed %08X, exit thread....\n", err); return; } - + /* config spi */ { struct rt_spi_configuration cfg; cfg.data_width = 8; - cfg.mode = RT_SPI_MODE_0; + cfg.mode = RT_SPI_MODE_0; cfg.max_hz = 200 * 1000; /* 200K */ rt_spi_configure((struct rt_spi_device *)spi_device, &cfg); } @@ -573,7 +573,7 @@ rt_err_t rtgui_touch_hw_init(const char * spi_device_name) touch->min_x = MIN_X_DEFAULT; touch->max_x = MAX_X_DEFAULT; - touch->min_y = MIN_Y_DEFAULT; + touch->min_y = MIN_Y_DEFAULT; touch->max_y = MAX_Y_DEFAULT; /* init device structure */ @@ -584,7 +584,7 @@ rt_err_t rtgui_touch_hw_init(const char * spi_device_name) /* register touch device to RT-Thread */ rt_device_register(&(touch->parent), "touch", RT_DEVICE_FLAG_RDWR); - + touch_thread = rt_thread_create("touch_thread", touch_thread_entry, RT_NULL, |
