杰理方案AC79整合LVGL触屏显示效果

demo_DevKitBoard

修改DevKitBoard.c


1.

代码:

SPI1_PLATFORM_DATA_BEGIN(spi1_data)
	.clk    = 96000000,
    .mode   = SPI_1WIRE_MODE,
    .port   = 'B',
    .attr   =  SPI_SCLK_L_UPL_SMPH | SPI_UNIDIR_MODE,//主机,CLK低 更新数据低,单向模式
SPI1_PLATFORM_DATA_END()

 2. 

代码:

static const struct ui_lcd_platform_data pdata = {
    .spi_id  = "spi1",
    .bl_pin = IO_PORTH_02,
    .cs_pin  = IO_PORTH_03,
    .rs_pin  = IO_PORTH_04,
    .rst_pin = IO_PORTH_05,

   	.touch_reset_pin = IO_PORTH_06,
   	.touch_int_pin = IO_PORTH_07,
	.te_pin  = -1,
    .lcd_if  = LCD_SPI,//屏幕接口类型还有 PAP , SPI
};

修改lcd_st7789v.c

1.

 代码 :

#define CONFIG_ST7789V_ID 4

 2.

代码:

#if TCFG_LCD_ST7789V_ENABLE//客户屏放最后
        lcd_w = 240;
        lcd_h = 280;
        lcd_bk_on = 1;
        lcd_bk_off = 0;
        lcd_choice = CONFIG_ST7789V_ID;
        printf("\n [lcd_drive] %s -[find_check_ST7789V] %d\n", __FUNCTION__, __LINE__);
        lcd_data_size = lcd_w * lcd_h * 2;
#endif

屏幕花屏解决:

注释掉这行。

 lcd_st7789v.c没问题的代码 



#include "system/includes.h"
#include "typedef.h"
#include "asm/pap.h"
#include "lcd_drive.h"
#include "lcd_config.h"

/*  ST7789V驱动说明 该驱动测试时使用的 wl80 79系列
 *  由于该IC推屏能力不够强 推屏的帧数较低 大概在25帧左右
 *  在推屏过程中需要使用TE屏幕帧中断 不然会有条纹
 *  由于ST7789V横屏配置无法调出没有条纹的配置
 *  所有只能使用竖屏加RGB旋转来实现UI横屏显示
 */

/* //pap的这个三个配置如下 在板级文件中进行修改
    .timing_setup 	= 0,					//具体看pap.h
    .timing_hold  	= 0,					//具体看pap.h
    .timing_width 	= 1,					//具体看pap.h
*/

#if TCFG_LCD_ST7789V_ENABLE


#define READ_ID 	0x04
#define REGFLAG_DELAY 0x45

void ST7789V_SetRange(u16 xs, u16 xe, u16 ys, u16 ye)
{
    /******UI每次发送数据都会调用开窗告诉屏幕要刷新那个区域***********/
    set_lcd_ui_x_y(xs, xe, ys, ye);
}
void ST7789V_SetRange_1(u16 xs, u16 xe, u16 ys, u16 ye)
{
    ys = ys + 20;
    ye = ye + 20;
    WriteCOM(0x2B);
    WriteDAT_8(ys >> 8);
    WriteDAT_8(ys);
    WriteDAT_8(ye >> 8);
    WriteDAT_8(ye);
    WriteCOM(0x2A);
    WriteDAT_8(xs >> 8);
    WriteDAT_8(xs);
    WriteDAT_8(xe >> 8);
    WriteDAT_8(xe);
    WriteCOM(0x2c);

}

void ST7789V_clear_screen(u32 color)
{
    ST7789V_SetRange_1(0, LCD_W-1, 0, LCD_H-1);
    lcd_interface_non_block_wait();
    WriteCOM(0x2c);

    u8 *buf = malloc(LCD_W * LCD_H * 2);
    if (!buf) {
        printf("no men in %s \n", __func__);
        return;
    }
    for (u32 i = 0; i < LCD_W * LCD_H; i++) {
        buf[2 * i] = (color >> 8) & 0xff;
        buf[2 * i + 1] = color & 0xff;
    }
    WriteDAT_DMA(buf, LCD_W * LCD_H * 2);
    free(buf);
}

void ST7789V_Fill(u8 *img, u16 len)
{
    ST7789V_SetRange_1(0, LCD_W-1, 0, LCD_H-1);
    printf("ST7789V_Fill>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\r\n");
    lcd_interface_non_block_wait();
    WriteCOM(0x2c);
    WriteDAT_DMA(img, len);
}

void ST7789V_SleepInMode(void)
{
    WriteCOM(0x10); //Sleep in
    lcd_delay(120); //Delay 120ms
}

void ST7789V_SleepOutMode(void)
{
    WriteCOM(0x11); //Sleep out
    lcd_delay(120);  //Delay 120ms
}

void st7789_shown_image(u8 *buff, u16 x_addr, u16 y_addr, u16 width, u16 height)
{
    lcd_interface_non_block_wait();
    ST7789V_SetRange(x_addr, y_addr, width, height);
    WriteDAT_DMA(buff, width * height * 2);
}

static void ST7789V_set_direction(u8 dir)
{

}

static void ST7789V_draw(u8 *map, u32 size)//获取Ui发送出来的数据
{
    ui_send_data_ready(map, size);
}

static void ST7789V_draw_1(u8 *buf, u32 size, int width, int height)//获取camera发送出来的数据 //数据帧数以camera为基准
{
    camera_send_data_ready(buf, size, width, height);
}

static void ST7789V_reset(void)
{
    printf("reset \n");
    lcd_rst_pinstate(1);
    lcd_rs_pinstate(1);
    lcd_cs_pinstate(1);

    lcd_rst_pinstate(1);
    lcd_delay(60);
    lcd_rst_pinstate(0);
    lcd_delay(10);
    lcd_rst_pinstate(1);
    lcd_delay(100);
}

typedef struct {
    u8 cmd;
    u8 cnt;
    u8 dat[128];
} InitCode;

static const InitCode code1[] = {

     {0x01, 0},				// soft reset
    {REGFLAG_DELAY, 120},	// delay 120ms
    {0x11, 0},				// sleep out
    {REGFLAG_DELAY, 120},
    {0x36, 1, {0x00}},
    {0x3A, 1, {0x05}},
    {0xB2, 5, {0x0c, 0x0c, 0x00, 0x33, 0x33}},
    {0xB7, 1, {0x22}},
    {0xBB, 1, {0x36}},
    {0xC2, 1, {0x01}},
    {0xC3, 1, {0x19}},
    {0xC4, 1, {0x20}},
    {0xC6, 1, {0x0F}},
    {0xD0, 2, {0xA4, 0xA1}},
    /* {0xE0,14, {0x70,0x04,0x08,0x09,0x09,0x05,0x2A,0x33,0x41,0x07,0x13,0x13,0x29,0x2F}},
    /* {0xE1,14, {0x70,0x03,0x09,0x0A,0x09,0x06,0x2B,0x34,0x41,0x07,0x12,0x14,0x28,0x2E}}, */
    {0xE0, 14, {0xF0, 0x0B, 0x11, 0x0E, 0x0D, 0x19, 0x36, 0x33, 0x4B, 0x07, 0x14, 0x14, 0x2C, 0x2E}},
    {0xE1, 14, {0xF0, 0x0D, 0x12, 0x0B, 0x09, 0x03, 0x32, 0x44, 0x48, 0x39, 0x16, 0x16, 0x2D, 0x30}},
    {0X21, 0},
    {0X2A, 4, {0x00, 0x00, 0x00, 0xEF}},
    {0X2B, 4, {0x00, 0x14, 0x01, 0x2C}},
    {0X29, 0},
    {REGFLAG_DELAY, 20},
    {0X2C, 0},
    {REGFLAG_DELAY, 20},
};

static void ST7789V_init_code(const InitCode *code, u8 cnt)
{
    for (u8 i = 0; i < cnt; i++) {
        if (code[i].cmd == REGFLAG_DELAY) {
            lcd_delay(code[i].cnt);
        } else {
            WriteCOM(code[i].cmd);
            for (u8 j = 0; j < code[i].cnt; j++) {
                WriteDAT_8(code[i].dat[j]);
            }
        }
    }
}

static void ST7789V_led_ctrl(u8 status)
{
    //背光控制以及放在//lcd_te_driver.c 优化开机显示
    lcd_bl_pinstate(status);
}

void ST7789V_test(void)
{
    lcd_bl_pinstate(lcd_bk_on);
    while (1) {
        os_time_dly(100);
        ST7789V_clear_screen(BLUE);
        printf("LCD_ST7789V_TSET_BLUE\n");
        os_time_dly(100);
        ST7789V_clear_screen(GREEN);
        printf("LCD_ST7789V_TSET_GRED\n");
        os_time_dly(100);
        ST7789V_clear_screen(RED);
        printf("LCD_ST7789V_TSET_BRRED\n");
        os_time_dly(100);
        ST7789V_clear_screen(YELLOW);
        printf("LCD_ST7789V_TSET_YELLOW\n");
    }
}

static int ST7789V_init(void)
{
    printf("LCD_ST7789V init_start\n");
    ST7789V_reset();

    ST7789V_led_ctrl(lcd_bk_on);

    ST7789V_init_code(code1, sizeof(code1) / sizeof(code1[0]));
    ST7789V_set_direction(ROTATE_DEGREE_90);
    init_TE(ST7789V_Fill);


    //ST7789V_test();

    printf("LCD_ST7789V config succes\n");
    return 0;
}


static void ST7789V_lvgl_Fill(u16 xs, u16 xe, u16 ys, u16 ye, u8 *img)
{
    u32 len = 0;
    lcd_interface_non_block_wait();
    len = (xe + 1 - xs) * (ye + 1 - ys) * 2;

    ST7789V_SetRange_1(xs,xe,ys,ye);

    WriteDAT_DMA(img, len);


}



REGISTER_LCD_DEV(LCD_ST7789V) = {
    .name              = "ST7789V",
    .lcd_width         = LCD_W,
    .lcd_height        = LCD_H,
    .color_format      = LCD_COLOR_RGB565,
    .column_addr_align = 1,
    .row_addr_align    = 1,
    .LCD_Init          = ST7789V_init,
    .SetDrawArea       = ST7789V_SetRange,
    .LCD_Draw          = ST7789V_draw,
    .LCD_Draw_1        = ST7789V_draw_1,
    .LCD_DrawToDev     = ST7789V_Fill,//应用层直接到设备接口层,需要做好缓冲区共用互斥,慎用!
    .LCD_Lvgl_Full     = ST7789V_lvgl_Fill,
    .LCD_ClearScreen   = ST7789V_clear_screen,
    .Reset             = ST7789V_reset,
    .BackLightCtrl     = ST7789V_led_ctrl,
};

#endif


修改屏幕尺寸 

cst816t.c触摸屏代码  


#include "system/includes.h"
#include "asm/port_waked_up.h"
#include "typedef.h"
#include "os/os_api.h"
#include "asm/iic.h"
#include "device/iic.h"
#include "device/device.h"
#include "lcd_config.h"
#include "app_config.h"
#include "system/includes.h"
#include "gpio.h"
#include "ui_api.h"
#include "touch_event.h"
#include "sys_common.h"

#if TCFG_TOUCH_CST816T_ENABLE
#define TEST 0

#if 1
#define log_info(x, ...)    printf("\n[touch]>" x " \n", ## __VA_ARGS__)
#else
#define log_info(...)
#endif

struct touch_hdl {
    u16 x;
    u16 y;
    u8 status;
    u8 fingers;
};
struct touch_hdl lvgl_touch_hdl;

static OS_SEM touch_sem;

void *get_touch_x_y(void)
{
    return &lvgl_touch_hdl;
}

void get_touch_x_y_status(u16 *x, u16 *y, u8 *status)
{
    *x = lvgl_touch_hdl.x;
    *y = lvgl_touch_hdl.y;
    *status = lvgl_touch_hdl.status;
}
extern int ui_touch_msg_post(struct touch_event *event);


//#define CST816T_ADDRESS 0x2A
#define CST816T_ADDRESS_W 0x2A
#define CST816T_ADDRESS_R 0x2B
// 无触摸
#define CST816T_STATE_RELEASE 0xFF
// 检测到触摸
#define CST816T_STATE_PRESS_DOWN 0x00
// 上滑
#define CST816T_STATE_SLIDE_UP 0x01
// 下滑
#define CST816T_STATE_SLIDE_DOWN 0x02
// 左滑
#define CST816T_STATE_SLIDE_LEFT 0x03
// 右滑
#define CST816T_STATE_SLIDE_RIGHT 0x04
// 单击
#define CST816T_STATE_SINGLE_CLICK 0x05
// 双击
#define CST816T_STATE_DOUBLE_CLICK 0x0B
// 长按
#define CST816T_STATE_LONG_PRESS 0x0C

static void *iic = NULL;

static u8 touch_status = 0;




static void get_FT6236_xy(u16 addr, u16 *x, u16 *y)
{
    u8 buf[4];
    for (u8 i = 0; i < 4; i++) {
        rdFT6236Reg((addr + i), &buf[i]);	//读取XY坐标值
    }
    *y = (((u16)(buf[2] & 0X0F) << 8) + buf[3]);
    *x = ((u16)(buf[0] & 0X0F) << 8) + buf[1];
}

static u8 tp_last_staus = ELM_EVENT_TOUCH_UP;
static int tp_down_cnt = 0;



void CST816T_SendByte(uint8_t regID,uint8_t* regDat)
{
	//I2C_write(0x15, Addr,Data, 1);
	 u8 ret = 1;

    dev_ioctl(iic, IIC_IOCTL_START, 0);
    if (dev_ioctl(iic, IIC_IOCTL_TX_WITH_START_BIT, CST816T_ADDRESS_W)) {
        ret = 0;
        log_info("iic write err!!! line : %d \n", __LINE__);
        goto exit;
    }
    delay(100);
    if (dev_ioctl(iic, IIC_IOCTL_TX, regID & 0xff)) {
        ret = 0;
        log_info("iic write err!!! line : %d \n", __LINE__);
        goto exit;
    }
    delay(100);
    if (dev_ioctl(iic, IIC_IOCTL_TX_WITH_STOP_BIT, *regDat)) {
        ret = 0;
        log_info("iic write err!!! line : %d \n", __LINE__);
        goto exit;
    }
    delay(100);

exit:
    dev_ioctl(iic, IIC_IOCTL_STOP, 0);
}

void CST816T_ReceiveByte(uint8_t regID,uint8_t* Data)
{
	//I2C_read(0x15, Addr,Data, 1);
	 u8 ret = 1;
    dev_ioctl(iic, IIC_IOCTL_START, 0);
    if (dev_ioctl(iic, IIC_IOCTL_TX_WITH_START_BIT, CST816T_ADDRESS_W)) {
        ret = 0;
        log_info("iic write err!!! line : %d \n", __LINE__);
        goto exit;
    }
    delay(100);
    if (dev_ioctl(iic, IIC_IOCTL_TX, regID & 0xff)) {
        ret = 0;;
        log_info("iic write err!!! line : %d \n", __LINE__);
        goto exit;
    }
    delay(100);
    if (dev_ioctl(iic, IIC_IOCTL_TX_WITH_START_BIT, CST816T_ADDRESS_R)) {
        ret = 0;
        goto exit;
    }
    delay(100);
    dev_ioctl(iic, IIC_IOCTL_RX_WITH_STOP_BIT, (u32)Data);
exit:
    dev_ioctl(iic, IIC_IOCTL_STOP, 0);

}

#define CST816T_TOUCH_W 240
#define CST816T_TOUCH_H 280

void CST816_GetAction(void)
{
	uint8_t data[6];
	uint16_t X=0,Y=0;


	CST816T_ReceiveByte(0x01,data);
	CST816T_ReceiveByte(0x03,data+1);
	CST816T_ReceiveByte(0x04,data+2);
	CST816T_ReceiveByte(0x05,data+3);
	CST816T_ReceiveByte(0x06,data+4);
	// 读手指的个数
	CST816T_ReceiveByte(0x02,data+5);


	lvgl_touch_hdl.x=(uint16_t)((data[1]&0x0F)<<8)|data[2];//(temp[0]&0X0F)<<4|
	lvgl_touch_hdl.y=(uint16_t)((data[3]&0x0F)<<8)|data[4];//(temp[2]&0X0F)<<4|

    /*
	if(X<CST816T_TOUCH_W&&Y<CST816T_TOUCH_H)
	{
		X_Axis=X;
		Y_Axis=Y;
	}*/
	// 手指的数量
	lvgl_touch_hdl.fingers = data[5];

    if(lvgl_touch_hdl.fingers > 0 && lvgl_touch_hdl.x>0 && lvgl_touch_hdl.y>0){
		lvgl_touch_hdl.status=1;
	}else{
		lvgl_touch_hdl.status=0;
	}


	//printf("Sta:%X,X:%d,Y:%d finger:%d \t\n",lvgl_touch_hdl.status,lvgl_touch_hdl.x,lvgl_touch_hdl.y,lvgl_touch_hdl.fingers);
}

static void cst816t_interrupt(void)
{
    os_sem_post(&touch_sem);
}


void CST816T_Init(void)
{
	uint8_t ChipID=0;
	uint8_t FwVersion=0;

	//CST816T_Reset( );//芯片上电初始化

    os_sem_create(&touch_sem, 0);

    extern const struct ui_devices_cfg ui_cfg_data;
    static const struct ui_lcd_platform_data *pdata;
    pdata = (struct ui_lcd_platform_data *)ui_cfg_data.private_data;





    gpio_direction_output(pdata->touch_reset_pin, 0);
    os_time_dly(80);
    gpio_direction_output(pdata->touch_reset_pin, 1);
    os_time_dly(100);

    //用于打开一个设备
    iic = dev_open("iic0", NULL);

    os_time_dly(500);

    CST816T_ReceiveByte(0xa7,&ChipID);
	CST816T_ReceiveByte(0xa9,&FwVersion);
	printf("ChipID:%X\r\n",ChipID);
	printf("FwVersion:%d\r\n",FwVersion);



    //注册中断注意触摸用的事件0 屏幕TE用的事件1
    port_wakeup_reg(EVENT_IO_0, pdata->touch_int_pin, EDGE_NEGATIVE, cst816t_interrupt);


    struct touch_event t;
    u8 last_action = ELM_EVENT_TOUCH_UP;
    while (1) {
        os_sem_pend(&touch_sem, 0);

        CST816_GetAction();

        t.x = lvgl_touch_hdl.x;
        t.y = lvgl_touch_hdl.y;

        if(lvgl_touch_hdl.fingers > 0 && lvgl_touch_hdl.x>0 && lvgl_touch_hdl.y>0){
            if(last_action == ELM_EVENT_TOUCH_DOWN){
                t.action = ELM_EVENT_TOUCH_MOVE;
            }else{
                t.action = ELM_EVENT_TOUCH_DOWN;
            }
        }else{
            t.action = ELM_EVENT_TOUCH_UP;
        }
        last_action = t.action;

        //ui_touch_msg_post(&t);
    }
}

void CST816T_ClrBaseDatas(void)
{
	lvgl_touch_hdl.fingers = 0;
	lvgl_touch_hdl.status = CST816T_STATE_RELEASE;
	lvgl_touch_hdl.x = 0;
	lvgl_touch_hdl.y = 0;
}



uint8_t CST816T_is_pressed(void){

	//CST816_GetAction();

	if(lvgl_touch_hdl.fingers > 0 && lvgl_touch_hdl.x>0 && lvgl_touch_hdl.y>0){
		return 1;
	}else{
		return 0;
	}
}


void CST816T_get_xy(uint16_t* x,uint16_t* y){
	*x = lvgl_touch_hdl.x;
	*y = lvgl_touch_hdl.y;
}



static void cst816t_touch_test_task(void *priv)
{
    CST816T_Init();
}

void set_touch_enable(void)
{

}

void set_touch_disable(void)
{

}



static int cst816t_task_init(void)
{
    //return thread_fork("cst816t_touch_test_task", 29, 1024, 0, NULL, cst816t_touch_test_task, NULL);
    return os_task_create(cst816t_touch_test_task, NULL, 25, 1000, 0, "cst816t_touch_test_task");
}
late_initcall(cst816t_task_init);

#endif

显示效果展示

运行时报错解决:

1. 

如果出现这种错误,只需要将其它的 开关关掉即可。

如:

#define USE_LCD_240X320                           0
#define USE_LCD_320X480                           0

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

除不掉的灰色

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值