Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lvgl adaptation of touch screen xpt2046 for BSP #6114

Merged
merged 9 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -29,8 +29,14 @@ static void input_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
void lv_port_indev_input(rt_int16_t x, rt_int16_t y, lv_indev_state_t state)
{
last_state = state;
#ifdef BSP_USING_TOUCH_CAP
last_x = LCD_W - y;
last_y = x;
#endif /* BSP_USING_TOUCH_CAP */
#ifdef BSP_USING_TOUCH_RES
last_x = x;
last_y = y;
#endif /* BSP_USING_TOUCH_RES */
}

void lv_port_indev_init(void)
Expand Down
41 changes: 32 additions & 9 deletions bsp/stm32/stm32f407-atk-explorer/board/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,38 @@ menu "Onboard Peripheral Drivers"
bool "Enable lcd fill test"
default y
endif

config BSP_USING_TOUCH
bool "Use LCD TOUCH"
select BSP_USING_I2C2

menuconfig BSP_USING_TOUCH
bool "Use LCD TOUCH (Default Res)"
default n
if BSP_USING_TOUCH
config BSP_TOUCH_INT_PIN
int "Touch interrupt pin, PB1"
default 17
config BSP_USING_TOUCH_CAP
bool "Use LCD TOUCH Capacitance (i2c2)"
select BSP_USING_I2C2
default n
if BSP_USING_TOUCH_CAP
config BSP_TOUCH_INT_PIN
int "Touch interrupt pin, PB1"
default 17
endif

config BSP_USING_TOUCH_RES
bool "Use LCD TOUCH Resistance (sspi1)"
select RT_USING_TOUCH
select RT_TOUCH_PIN_IRQ
select BSP_USING_SOFT_SPI
select BSP_USING_SOFT_SPI1
select BSP_USING_ONBOARD_LCD
default y
if BSP_USING_TOUCH_RES
config BSP_XPT2046_CS_PIN
string "pin name for the chip select pin"
default "PC.13"

config BSP_XPT2046_IRQ_PIN
string "pin name for the irq pin"
default "PB.1"
endif
endif

config BSP_USING_LVGL
Expand Down Expand Up @@ -374,7 +397,7 @@ menu "On-chip Peripheral Drivers"

menuconfig BSP_USING_I2C1
bool "Enable I2C1 BUS (software simulation)"
default y
default n
select RT_USING_I2C
select RT_USING_I2C_BITOPS
select RT_USING_PIN
Expand All @@ -391,7 +414,7 @@ menu "On-chip Peripheral Drivers"

menuconfig BSP_USING_I2C2
bool "Enable LCD Touch BUS (software simulation)"
default y
default n
select RT_USING_I2C
select RT_USING_I2C_BITOPS
select RT_USING_PIN
Expand Down
10 changes: 8 additions & 2 deletions bsp/stm32/stm32f407-atk-explorer/board/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@ if GetDepend(['BSP_USING_SRAM']):
if GetDepend(['BSP_USING_ONBOARD_LCD']):
src += Glob('ports/drv_lcd.c')

if GetDepend(['BSP_USING_TOUCH']):
src += Glob('ports/touch/*.c')
if GetDepend(['BSP_USING_TOUCH_CAP']):
src += Glob('ports/touch/drv_touch_ft.c')
src += Glob('ports/touch/drv_touch.c')
path += [cwd + '/ports/touch']

if GetDepend(['BSP_USING_TOUCH_RES']):
src += Glob('ports/touch/drv_touch_xpt.c')
src += Glob('ports/touch/drv_xpt2046_init.c')
path += [cwd + '/ports/touch']

startup_path_prefix = SDK_LIB
Expand Down
74 changes: 65 additions & 9 deletions bsp/stm32/stm32f407-atk-explorer/board/ports/drv_lcd.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-12-28 unknow copy by STemwin
* 2021-12-29 xiangxistu port for lvgl <lcd_fill_array>
* 2022-6-26 solar Improve the api required for resistive touch screen calibration
*/

#include <board.h>
Expand Down Expand Up @@ -472,14 +473,69 @@ void LCD_Clear(uint32_t color)
}
}

void LCD_DrawLine(const char *pixel, rt_uint16_t x1, rt_uint16_t y1, rt_uint16_t x2, rt_uint16_t y2)
{
rt_uint16_t t;
int xerr = 0, yerr = 0, delta_x, delta_y, distance;
int incx, incy, uRow, uCol;
delta_x = x2 - x1; //计算坐标增量
delta_y = y2 - y1;
uRow = x1;
uCol = y1;

if (delta_x > 0)
incx = 1; //设置单步方向
else if (delta_x == 0)
incx = 0; //垂直线
else
{
incx = -1;
delta_x = -delta_x;
}

if (delta_y > 0)
incy = 1;
else if (delta_y == 0)
incy = 0; //水平线
else
{
incy = -1;
delta_y = -delta_y;
}

if (delta_x > delta_y)
distance = delta_x; //选取基本增量坐标轴
else
distance = delta_y;

for (t = 0; t <= distance + 1; t++) //画线输出
{
// LCD_DrawPoint(uRow, uCol); //画点
LCD_Fast_DrawPoint(pixel, uRow, uCol);
xerr += delta_x;
yerr += delta_y;

if (xerr > distance)
{
xerr -= distance;
uRow += incx;
}

if (yerr > distance)
{
yerr -= distance;
uCol += incy;
}
}
}
void LCD_HLine(const char *pixel, int x1, int x2, int y)
{
int xsize = x2 - x1 + 1;
LCD_SetCursor(x1, y);
LCD_WriteRAM_Prepare();
uint16_t *p = (uint16_t *)pixel;
for (; xsize > 0; xsize--)
LCD->RAM = *p;
LCD_DrawLine(pixel, x1, y, x2, y);
}

void LCD_VLine(const char *pixel, int x, int y1, int y2)
{
LCD_DrawLine(pixel, x, y1, x, y2);
}

void LCD_BlitLine(const char *pixel, int x, int y, rt_size_t size)
Expand Down Expand Up @@ -1788,7 +1844,7 @@ static rt_err_t drv_lcd_init(struct rt_device *device)
}
else if (lcddev.id == 0X1963)
{
LCD_WR_REG(0xE2); //Set PLL with OSC = 10MHz (hardware), Multiplier N = 35, 250MHz < VCO < 800MHz = OSC*(N+1), VCO = 300MHz
LCD_WR_REG(0xE2); //Set PLL with OSC = 10MHz (hardware), Multiplier N = 35, 250MHz < VCO < 800MHz = OSC*(N+1), VCO = 300MHz
LCD_WR_DATA(0x1D); //参数1
LCD_WR_DATA(0x02); //参数2 Divider M = 2, PLL = 300/(M+1) = 100MHz
LCD_WR_DATA(0x04); //参数3 Validate M and N values
Expand Down Expand Up @@ -1882,7 +1938,7 @@ struct rt_device_graphic_ops fsmc_lcd_ops =
LCD_Fast_DrawPoint,
LCD_ReadPoint,
LCD_HLine,
RT_NULL,
LCD_VLine,
LCD_BlitLine,
};

Expand Down
16 changes: 14 additions & 2 deletions bsp/stm32/stm32f407-atk-explorer/board/ports/drv_lcd.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand All @@ -13,9 +13,15 @@
#include "rtdevice.h"
#include <drv_common.h>

#ifdef BSP_USING_TOUCH_CAP
#define LCD_W 800
#define LCD_H 480
#endif // BSP_USING_TOUCH_CAP

#ifdef BSP_USING_TOUCH_RES
#define LCD_W 320
#define LCD_H 480
#endif // BSP_USING_TOUCH_RES

//LCD重要参数集
typedef struct
Expand Down Expand Up @@ -49,7 +55,13 @@ typedef struct
#define D2U_L2R 6 //从下到上,从左到右
#define D2U_R2L 7 //从下到上,从右到左

#define DFT_SCAN_DIR L2R_U2D //默认的扫描方向
#ifdef BSP_USING_TOUCH_CAP
#define DFT_SCAN_DIR L2R_U2D //电容触摸屏默认的扫描方向
#endif // BSP_USING_TOUCH_CAP

#ifdef BSP_USING_TOUCH_RES
#define DFT_SCAN_DIR D2U_L2R //电阻触摸屏默认的扫描方向
#endif // BSP_USING_TOUCH_RES

//LCD分辨率设置
#define SSD_HOR_RESOLUTION 800 //LCD水平分辨率
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand All @@ -10,7 +10,7 @@

#include <rtconfig.h>

#ifdef BSP_USING_TOUCH
#ifdef BSP_USING_TOUCH_CAP
#include "drv_touch.h"
#include <string.h>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand All @@ -19,7 +19,7 @@
#include <stdint.h>
#include <string.h>

#ifdef BSP_USING_TOUCH
#ifdef BSP_USING_TOUCH_CAP

#define DBG_ENABLE
#define DBG_SECTION_NAME "TOUCH.ft"
Expand Down
Loading