首页 > 其他分享 >移植lvgl

移植lvgl

时间:2024-06-18 20:24:37浏览次数:20  
标签:disp indev drv lv static lvgl buf 移植

板子: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

标签:disp,indev,drv,lv,static,lvgl,buf,移植
From: https://www.cnblogs.com/chaoj/p/18255030

相关文章

  • 海思SD3403,SS928/926,hi3519dv500,hi3516dv500移植yolov7,yolov8(23)SS928/SD3403推理y
    今天抽空测试了一下3403跑yolov8的速度,源码还没改完,后处理还是先用CPU来跑了,这样速度会拖慢一点,先看看效果。实际用的是4T算力的,里面是有两个NPU,一个叫SVP_NNN,一个叫NNN,用的方式还不一样,分别用SVP_ACL接口和ACL接口。我是没有时间去研究ACL,用的SVP_ACL的方式。下面是对比。......
  • N32移植cherry usb
    目前的项目用到了USB,N32自带的USB库比较难用。考虑用开源的USB库。例如tinyusb(比较全)和cherryusb(比较好移植,有地方问)。本文以cherryusb为例子进行讲述,tinyusb放另外一篇文章中去讲。N32和STM32F103的USBIP用的是一致的都是fsdev这个IP,所以N32的移植可以完全参考STM32去搞......
  • LVGL btn组件
    /***************************************************filename:widget_line.c*author:[email protected]*date:2024/06/17*brief:移植LVGL,实现在屏幕上显示一个按钮,按钮上有一个标签,当用户通过触摸屏点击了该按钮,则显示一个新的屏幕对象*not......
  • 海思SD3403,SS928/926,hi3519dv500,hi3516dv500移植yolov7,yolov8(22)hi3516dv500/19dv5
     最近太忙更新不及时,SS928跑yolov8的文章各位朋友不要催,最近在测试自己魔改的yolov8,测完有结论了跟大家分享。魔改的yolov8在dv500系列里有些小问题,能正常运行,但是优化报错,在做更细致的测试。 先分享一下最近对比RK3588做的测试结果。RK3588算是嵌入式AI里的顶配级别存在......
  • CC2500和CC1101移植说明
    主要通过如何移植、移植注意、关于芯片配置、如何生成导出配置四大步骤来说明CC2500和CC1101移植首先通过下图1这个宏进行选择 &如何移植要移植的部分在CC2500_hal.c和CC2500_hal.h中, 搜索"//移植"就可以定位到库所需的依赖,需要根据您的环境实现这些函数&移植......
  • N32G45XVL-STB之移植LVGL(8.4.0)
    目录概述1系统软硬件1.1软件版本信息1.2 ST7796-LCD1.3 MCUIO与LCDPIN对应关系2认识LVGL2.1 LVGL官网2.2下载V8.4.03移植LVGL3.1硬件驱动实现3.2添加LVGL库文件3.3移植和硬件相关的代码3.3.1驱动接口相关文件介绍3.3.2重新接口函数3.4配置.h文......
  • 034【GD32F470】MQ-3酒精检测传感器STM32移植教程
    2.31MQ-3酒精检测传感器MQ-3气体传感器所使用的气敏材料是在清洁空气中电导率较低的二氧化锡(Sn0)。当传感器所处环境中存在酒精蒸气时,传感器的电导率随空气中酒精蒸气浓度的增加而增大。使用简单的电路即可将电导率的变化转换为与该气体浓度相对应的输出信号。2.31.1......
  • lvgl table的使用(重绘,事件,行选中,点击,蒙版)
     ////验证//密码//人脸//刷卡#include"baseapp.h"staticlv_group_t*appGroupBtn;staticlv_obj_t*infoMeterLVGLBrushCard=NULL;staticlv_obj_t*infoTextareaMeterPasswdValue;staticlv_obj_t*appObjCamera;staticlv_obj_t*appObjCameraAiFaceImg;stat......
  • STM32 + RT-Thread + LVGL
    一、基本信息MCU:STM32F103ZET6RT-Thread:5.0.2LVGL:8.3.11LCD:ST7735s编译环境:RTThreadstudio二、LVGL移植要求16、32或64位微控制器或处理器建议速度大于16MHz闪存/ROM:>64kB(建议180kB)内存:8kB(建议24kB)1个帧缓冲器:在MCU、外部RAM或显示控制器中LVGL的......
  • LVGL多端移植测试
    说明:端午在家宅,进行了LVGL的多端移植测试。目标是使用Squreline绘图生成的同一段代码,实现在PC端、安卓端、彩屏单片机端、单色屏单片机端四端显示。最终目标我是想实现在任意一端操作界面,其他几端都能实现同步变化。目前已经实现了四端的简单显示:安卓手机端、墨水屏手机......