移植lvgl

news/2024/9/27 22:26:38

板子:stm32f407zgt6

屏幕:浦阳1.69触摸屏(该款触摸屏幕显示芯片为:ST7789。触摸芯片为:CST816)

教程:正点原子移植教程。

一、踩坑点

  1. 启动文件的stack_size要由0x400改为0x800,否则demo会白屏

  2. lv_task_tc()可以放在一个定时器中断函数中,每5ms进入一次中断。

  3. 关键是修改lv_port_disp_template.clv_port_indev_template.c

lv_port_disp_template.c

/*** @file lv_port_disp_templ.c**//*Copy this file as "lv_port_disp.c" and set this value to "1" to enable content*/
#if 1/**********************      INCLUDES*********************/
#include "lv_port_disp_template.h"
#include "../../lvgl.h"
#include "lcd.h"
#include "lcd_init.h"/**********************      DEFINES*********************//***********************      TYPEDEFS**********************//***********************  STATIC PROTOTYPES**********************/
static void disp_init(void);static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
//static void gpu_fill(lv_disp_drv_t * disp_drv, lv_color_t * dest_buf, lv_coord_t dest_width,
//        const lv_area_t * fill_area, lv_color_t color);/***********************  STATIC VARIABLES**********************//***********************      MACROS**********************//***********************   GLOBAL FUNCTIONS**********************/void lv_port_disp_init(void)
{/*-------------------------* Initialize your display* -----------------------*/disp_init();/*-----------------------------* Create a buffer for drawing*----------------------------*//* Example for 1) */static lv_disp_draw_buf_t draw_buf_dsc_1;static lv_color_t buf_1[LCD_W * 150];                          /*A buffer for 10 rows*/lv_disp_draw_buf_init(&draw_buf_dsc_1, buf_1, NULL, LCD_W* 150);   /*Initialize the display buffer*//* Example for 2) */
//    static lv_disp_draw_buf_t draw_buf_dsc_2;
//    static lv_color_t buf_2_1[MY_DISP_HOR_RES * 10];                        /*A buffer for 10 rows*/
//    static lv_color_t buf_2_2[MY_DISP_HOR_RES * 10];                        /*An other buffer for 10 rows*/
//    lv_disp_draw_buf_init(&draw_buf_dsc_2, buf_2_1, buf_2_2, MY_DISP_HOR_RES * 10);   /*Initialize the display buffer*//* Example for 3) also set disp_drv.full_refresh = 1 below*/
//    static lv_disp_draw_buf_t draw_buf_dsc_3;
//    static lv_color_t buf_3_1[MY_DISP_HOR_RES * MY_DISP_VER_RES];            /*A screen sized buffer*/
//    static lv_color_t buf_3_2[MY_DISP_HOR_RES * MY_DISP_VER_RES];            /*Another screen sized buffer*/
//    lv_disp_draw_buf_init(&draw_buf_dsc_3, buf_3_1, buf_3_2, MY_DISP_VER_RES * LV_VER_RES_MAX);   /*Initialize the display buffer*//*-----------------------------------* Register the display in LVGL*----------------------------------*/static lv_disp_drv_t disp_drv;                         /*Descriptor of a display driver*/lv_disp_drv_init(&disp_drv);                    /*Basic initialization*//*Set up the functions to access to your display*//*Set the resolution of the display*/disp_drv.hor_res = LCD_W;disp_drv.ver_res = LCD_H;/*Used to copy the buffer's content to the display*/disp_drv.flush_cb = disp_flush;/*Set a display buffer*/disp_drv.draw_buf = &draw_buf_dsc_1;/*Required for Example 3)*///disp_drv.full_refresh = 1/* Fill a memory array with a color if you have GPU.* Note that, in lv_conf.h you can enable GPUs that has built-in support in LVGL.* But if you have a different GPU you can use with this callback.*///disp_drv.gpu_fill_cb = gpu_fill;/*Finally register the driver*/lv_disp_drv_register(&disp_drv);
}/***********************   STATIC FUNCTIONS**********************//*Initialize your display and the required peripherals.*/
static void disp_init(void)
{LCD_Init();
}/*Flush the content of the internal buffer the specific area on the display*You can use DMA or any hardware acceleration to do this operation in the background but*'lv_disp_flush_ready()' has to be called when finished.*/
static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
{LCD_Color_Fill(area->x1, area->y1, area->x2, area->y2,(u16*)color_p);lv_disp_flush_ready(disp_drv);
}/*OPTIONAL: GPU INTERFACE*//*If your MCU has hardware accelerator (GPU) then you can use it to fill a memory with a color*/
//static void gpu_fill(lv_disp_drv_t * disp_drv, lv_color_t * dest_buf, lv_coord_t dest_width,
//                    const lv_area_t * fill_area, lv_color_t color)
//{
//    /*It's an example code which should be done by your GPU*/
//    int32_t x, y;
//    dest_buf += dest_width * fill_area->y1; /*Go to the first line*/
//
//    for(y = fill_area->y1; y <= fill_area->y2; y++) {
//        for(x = fill_area->x1; x <= fill_area->x2; x++) {
//            dest_buf[x] = color;
//        }
//        dest_buf+=dest_width;    /*Go to the next line*/
//    }
//}#else /*Enable this file at the top*//*This dummy typedef exists purely to silence -Wpedantic.*/
typedef int keep_pedantic_happy;
#endif

lv_port_indev_template.c

/*** @file lv_port_indev_templ.c**//*Copy this file as "lv_port_indev.c" and set this value to "1" to enable content*/
#if 1/**********************      INCLUDES*********************/
#include "lv_port_indev_template.h"
#include "lvgl.h"
#include "CST816.h"/**********************      DEFINES*********************//***********************      TYPEDEFS**********************//***********************  STATIC PROTOTYPES**********************/static void touchpad_init(void);
static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
static bool touchpad_is_pressed(void);
static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y);/***********************  STATIC VARIABLES**********************/
lv_indev_t * indev_touchpad;
extern CST816_Info	CST816_Instance;/***********************      MACROS**********************//***********************   GLOBAL FUNCTIONS**********************/void lv_port_indev_init(void)
{/*** Here you will find example implementation of input devices supported by LittelvGL:*  - Touchpad*  - Mouse (with cursor support)*  - Keypad (supports GUI usage only with key)*  - Encoder (supports GUI usage only with: left, right, push)*  - Button (external buttons to press points on the screen)**  The `..._read()` function are only examples.*  You should shape them according to your hardware*/static lv_indev_drv_t indev_drv;/*------------------* Touchpad* -----------------*//*Initialize your touchpad if you have*/touchpad_init();/*Register a touchpad input device*/lv_indev_drv_init(&indev_drv);indev_drv.type = LV_INDEV_TYPE_POINTER;indev_drv.read_cb = touchpad_read;indev_touchpad = lv_indev_drv_register(&indev_drv);}/***********************   STATIC FUNCTIONS**********************//*------------------* Touchpad* -----------------*//*Initialize your touchpad*/
static void touchpad_init(void)
{/*Your code comes here*/CST816_Init();CST816_RESET();
}/*Will be called by the library to read the touchpad*/
static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
{static lv_coord_t last_x = 0;static lv_coord_t last_y = 0;/*Save the pressed coordinates and the state*/if(touchpad_is_pressed()) {touchpad_get_xy(&last_x, &last_y);data->state = LV_INDEV_STATE_PR;} else {data->state = LV_INDEV_STATE_REL;}/*Set the last pressed coordinates*/data->point.x = last_x;data->point.y = last_y;
}/*Return true is the touchpad is pressed*/
static bool touchpad_is_pressed(void)
{/*Your code comes here*/if(CST816_Get_FingerNum()!=0x00 && CST816_Get_FingerNum()!=0xFF){return true;}else{return false;}
}/*Get the x and y coordinates if the touchpad is pressed*/
static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y)
{/*Your code comes here*/CST816_Get_XY_AXIS();(*x) = CST816_Instance.X_Pos;(*y) = CST816_Instance.Y_Pos;
}#else /*Enable this file at the top*//*This dummy typedef exists purely to silence -Wpedantic.*/
typedef int keep_pedantic_happy;
#endif

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hjln.cn/news/46994.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈,一经查实,立即删除!

相关文章

typroa图片上传脚本

typroa的图片上传脚本,针对Telegraph-Image项目,适用于macOS和Linux系统。安装json处理器macOSbrew install jqLinux:# Debian/Ubuntu apt install jq -y​ 脚本配置 编辑脚本,在以下位置填入你的图床url: # 自定义URL部分 base_url=""注意:网址url后不需要加 …

HTML中的文本居中

本文将详细介绍如何在HTML中实现文本居中,包括使用不同的HTML标签和CSS属性来达到这一目的。HTML中的文本居中 参考:html center text 在网页设计中,文本居中是一种常见的布局需求,用于提高页面的美观性和用户体验。HTML(HyperText Markup Language)作为构建网页内容的标…

HbuilderX 4.15版本 text标签不能用v-html渲染,会失效

如题,注意uni-notice-bar组件,里面用了标签v-html渲染,所以4.15版本的uni-notice-bar组件不要用,坑

论文阅读:T-RAG: LESSONS FROM THE LLM TRENCHES

T-RAG: LESSONS FROM THE LLM TRENCHES(https://arxiv.org/abs/2402.07483) https://github.com/jiangnanboy/paper_read_note一.概述大型语言模型(llm)越来越多地应用于各个领域,包括对私有企业文档的问答,其中数据安全性和鲁棒性至关重要。检索增强生成(retrieve - augment…

论文阅读:UniMS-RAG: Unified Multi-Source RAG for Personalised Dialogue

UniMS-RAG: Unified Multi-Source RAG for Personalised Dialogue(https://arxiv.org/abs/2401.13256) https://github.com/jiangnanboy/paper_read_note一.概述本研究探讨如何分解RAG过程,加入多文件检索、记忆和个人信息等元素。大型语言模型(llm)在自然语言任务中表现出色…

Windows defender:威胁服务已经停止

前言 最近遇到了一件棘手的事情,Windows defender无法启动,Windows更新失败。 我是发现电脑的好多文件被劫持,图片,excel表格,pdf文档,好多文件后缀被改为.locked,想解锁得花费0.1bit,大概5万元。 网上的操作挺多的,又是命令行又是搞注册表的,没啥卵用。 环境 版本:…

学习记录

1. 用户注册用户可以通过注册功能创建自己的账户。注册信息包括以下内容: - 用户ID(学号) - 用户名(姓名) - 手机号码 - 用户单位(班级)首次注册后,用户的姓名将被记录,无需每次输入。2. 设定每周学习目标每周一,用户可以设定学习目标,包括具体的任务目标,如完成数…

redis——P2:对P1的思考

到P1结束,redis都已经是一个不错的服务了,具体体现在缓存应用程序需要的数据,甚至在内存爆满的条件下还可以提供服务,似乎目的已经达成。但是实际上可能会遇到一些极端的情况,比如宕机。如果redis宕机了怎么办?目前所有的数据都存储在内存当中,宕机意为着失去所有缓存的…