RTT下移植LVGL到W601_文件系统移植

1 篇文章 0 订阅

RTT下移植LVGL到W601_显示驱动移植

声明

个人学习笔记,不保证正确

参考资料

移植参考

DFS参考

图片

图片在线转换

环境

win10

keil5

硬件

正点原子w601开发板

步骤流程

1.在显示驱动移植完成的基础上添加tf卡驱动,文件系统

更新软件包
 pkgs --update
生成keil工程
scons --target=mdk5

2.移植文件系统到lvgl

1.lvgl官方提供了参考移植文档

2.lv_port_fs.h


#ifndef LV_PORT_FS_H
#define LV_PORT_FS_H

#ifdef __cplusplus
extern "C" {
#endif


#include "lvgl.h"

void lv_port_fs_init(void);

#ifdef __cplusplus
} /*extern "C"*/
#endif

#endif /*LV_PORT_FS_TEMPL_H*/

3.lv_port_fs.c

/**
 * @file lv_port_fs_templ.c
 *
 */

/*Copy this file as "lv_port_fs.c" and set this value to "1" to enable content*/
#if 1

/*********************
 *      INCLUDES
 *********************/
#include "lv_port_fs.h"
#include "lvgl.h"
#include <dfs_posix.h>
/*********************
 *      DEFINES
 *********************/

/**********************
 *      TYPEDEFS
 **********************/

/**********************
 *  STATIC PROTOTYPES
 **********************/
static void *fs_open(lv_fs_drv_t *drv, const char *path, lv_fs_mode_t mode);
static lv_fs_res_t fs_close(lv_fs_drv_t *drv, void *file_p);
static lv_fs_res_t fs_read(lv_fs_drv_t *drv, void *file_p, void *buf, uint32_t btr, uint32_t *br);
static lv_fs_res_t fs_write(lv_fs_drv_t *drv, void *file_p, const void *buf, uint32_t btw, uint32_t *bw);
static lv_fs_res_t fs_seek(lv_fs_drv_t *drv, void *file_p, uint32_t pos, lv_fs_whence_t whence);
//static lv_fs_res_t fs_size(lv_fs_drv_t *drv, void *file_p, uint32_t *size_p);
static lv_fs_res_t fs_tell(lv_fs_drv_t *drv, void *file_p, uint32_t *pos_p);

static void *fs_dir_open(lv_fs_drv_t *drv, const char *path);
static lv_fs_res_t fs_dir_read(lv_fs_drv_t *drv, void *rddir_p, char *fn);
static lv_fs_res_t fs_dir_close(lv_fs_drv_t *drv, void *rddir_p);

/**********************
 *  STATIC VARIABLES
 **********************/

/**********************
 * GLOBAL PROTOTYPES
 **********************/

/**********************
 *      MACROS
 **********************/

/**********************
 *   GLOBAL FUNCTIONS
 **********************/

void lv_port_fs_init(void)
{

	 
    /*Add a simple drive to open images*/
    static lv_fs_drv_t fs_drv;
    lv_fs_drv_init(&fs_drv);

    /*Set up fields...*/
    fs_drv.letter = 'S';
    fs_drv.open_cb = fs_open;
    fs_drv.close_cb = fs_close;
    fs_drv.read_cb = fs_read;
    fs_drv.write_cb = fs_write;
    fs_drv.seek_cb = fs_seek;
    fs_drv.tell_cb = fs_tell;

    fs_drv.dir_close_cb = fs_dir_close;
    fs_drv.dir_open_cb = fs_dir_open;
    fs_drv.dir_read_cb = fs_dir_read;

    lv_fs_drv_register(&fs_drv);
}

/**
 * Open a file
 * @param drv       pointer to a driver where this function belongs
 * @param path      path to the file beginning with the driver letter (e.g. S:/folder/file.txt)
 * @param mode      read: FS_MODE_RD, write: FS_MODE_WR, both: FS_MODE_RD | FS_MODE_WR
 * @return          a file descriptor or NULL on error
 */
static void *fs_open(lv_fs_drv_t *drv, const char *path, lv_fs_mode_t mode)
{
    int fp;
    int flag;

    switch (mode)
    {
    case LV_FS_MODE_WR:
        flag = O_WRONLY | O_CREAT;
        break;
    case LV_FS_MODE_RD:
        flag = O_WRONLY | O_CREAT;
        break;
    case LV_FS_MODE_RD | LV_FS_MODE_WR:
        flag = O_RDWR | O_CREAT;
        break;
    default:
        return NULL;
        break;
    }

    fp = open(path, flag);
    if (fp < 0)
    {
        return NULL;
    }
    else
    {
        return (void *)fp;
    }
}

/**
 * Close an opened file
 * @param drv       pointer to a driver where this function belongs
 * @param file_p    pointer to a file_t variable. (opened with fs_open)
 * @return          LV_FS_RES_OK: no error or  any error from @lv_fs_res_t enum
 */
static lv_fs_res_t fs_close(lv_fs_drv_t *drv, void *file_p)
{
 
    lv_fs_res_t res = LV_FS_RES_FS_ERR;
    if (close((int)file_p) == 0)
    {
        res = LV_FS_RES_OK;
    }
    return res;
}

/**
 * Read data from an opened file
 * @param drv       pointer to a driver where this function belongs
 * @param file_p    pointer to a file_t variable.
 * @param buf       pointer to a memory block where to store the read data
 * @param btr       number of Bytes To Read
 * @param br        the real number of read bytes (Byte Read)
 * @return          LV_FS_RES_OK: no error or  any error from @lv_fs_res_t enum
 */
static lv_fs_res_t fs_read(lv_fs_drv_t *drv, void *file_p, void *buf, uint32_t btr, uint32_t *br)
{
 
    lv_fs_res_t res = LV_FS_RES_FS_ERR;
    int ret = read((int)file_p, buf, btr);
    if (ret >= 0)
    {
        *br = ret;
        res = LV_FS_RES_OK;
    }
    return res;
}

/**
 * Write into a file
 * @param drv       pointer to a driver where this function belongs
 * @param file_p    pointer to a file_t variable
 * @param buf       pointer to a buffer with the bytes to write
 * @param btr       Bytes To Write
 * @param br        the number of real written bytes (Bytes Written). NULL if unused.
 * @return          LV_FS_RES_OK: no error or  any error from @lv_fs_res_t enum
 */
static lv_fs_res_t fs_write(lv_fs_drv_t *drv, void *file_p, const void *buf, uint32_t btw, uint32_t *bw)
{
 
    lv_fs_res_t res = LV_FS_RES_FS_ERR;
    int ret = read((int)file_p, (void *)buf, btw);
    if (ret >= 0)
    {
        *bw = ret;
        res = LV_FS_RES_OK;
    }

    return res;
}

/**
 * Set the read write pointer. Also expand the file size if necessary.
 * @param drv       pointer to a driver where this function belongs
 * @param file_p    pointer to a file_t variable. (opened with fs_open )
 * @param pos       the new position of read write pointer
 * @param whence    tells from where to interpret the `pos`. See @lv_fs_whence_t
 * @return          LV_FS_RES_OK: no error or  any error from @lv_fs_res_t enum
 */
static lv_fs_res_t fs_seek(lv_fs_drv_t *drv, void *file_p, uint32_t pos, lv_fs_whence_t whence)
{
 
    lv_fs_res_t res = LV_FS_RES_UNKNOWN;

    int fd = (int)file_p;
    if (lseek(fd, pos, SEEK_SET) >= 0)
        res = LV_FS_RES_OK;

    return res;
}
/**
 * Give the position of the read write pointer
 * @param drv       pointer to a driver where this function belongs
 * @param file_p    pointer to a file_t variable.
 * @param pos_p     pointer to to store the result
 * @return          LV_FS_RES_OK: no error or  any error from @lv_fs_res_t enum
 */
static lv_fs_res_t fs_tell(lv_fs_drv_t *drv, void *file_p, uint32_t *pos_p)
{
 
    lv_fs_res_t res = LV_FS_RES_UNKNOWN;

    int fd = (int)file_p;
    off_t pos = lseek(fd, 0, SEEK_CUR);
    if (pos >= 0)
    {
        *pos_p = pos;
        res = LV_FS_RES_OK;
    }

    return res;
}

/**
 * Initialize a 'lv_fs_dir_t' variable for directory reading
 * @param drv       pointer to a driver where this function belongs
 * @param path      path to a directory
 * @return          pointer to the directory read descriptor or NULL on error
 */
static void *fs_dir_open(lv_fs_drv_t *drv, const char *path)
{
 
    void *dir = NULL;
    /*Add your code here*/
    // dir = ... /*Add your code here*/
    return dir;
}

/**
 * Read the next filename form a directory.
 * The name of the directories will begin with '/'
 * @param drv       pointer to a driver where this function belongs
 * @param rddir_p   pointer to an initialized 'lv_fs_dir_t' variable
 * @param fn        pointer to a buffer to store the filename
 * @return          LV_FS_RES_OK: no error or  any error from @lv_fs_res_t enum
 */
static lv_fs_res_t fs_dir_read(lv_fs_drv_t *drv, void *rddir_p, char *fn)
{
 
    lv_fs_res_t res = LV_FS_RES_NOT_IMP;

    /*Add your code here*/

    return res;
}

/**
 * Close the directory reading
 * @param drv       pointer to a driver where this function belongs
 * @param rddir_p   pointer to an initialized 'lv_fs_dir_t' variable
 * @return          LV_FS_RES_OK: no error or  any error from @lv_fs_res_t enum
 */
static lv_fs_res_t fs_dir_close(lv_fs_drv_t *drv, void *rddir_p)
{
 
    lv_fs_res_t res = LV_FS_RES_NOT_IMP;

    /*Add your code here*/

    return res;
}

#else /*Enable this file at the top*/

/*This dummy typedef exists purely to silence -Wpedantic.*/
typedef int keep_pedantic_happy;
#endif

4.main.c

/*
 * Copyright (c) 2006-2018, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2019-05-07     yangjie      first implementation
 */

#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include <drv_lcd.h>
#include <rttlogo.h>
#include <dfs_fs.h>
#define DBG_TAG "MIAN"
#define DBG_LVL DBG_LOG

#include <rtdbg.h>

static rt_thread_t lvgl_tid = RT_NULL;
static rt_timer_t lvgl_timer = RT_NULL;

#include "lv_port_disp.h"
#include "lv_obj.h"
#include "lv_port_fs.h"

void demo(void)
{
    lv_obj_t *label1 = lv_label_create(lv_scr_act());
    lv_label_set_long_mode(label1, LV_LABEL_LONG_WRAP); /*Break the long lines*/
    lv_label_set_recolor(label1, true);                 /*Enable re-coloring by commands in the text*/
    lv_label_set_text(label1, "#0000ff Re-color# #ff00ff words# #ff0000 of a# label, align the lines to the center "
                              "and wrap long text automatically.");
    lv_obj_set_width(label1, 150); /*Set smaller width to make the lines wrap*/
    lv_obj_set_style_text_align(label1, LV_TEXT_ALIGN_CENTER, 0);
    lv_obj_align(label1, LV_ALIGN_CENTER, 0, -40);

    lv_obj_t *label2 = lv_label_create(lv_scr_act());
    lv_label_set_long_mode(label2, LV_LABEL_LONG_SCROLL_CIRCULAR); /*Circular scroll*/
    lv_obj_set_width(label2, 150);
    lv_label_set_text(label2, "It is a circularly scrolling text. ");
    lv_obj_align(label2, LV_ALIGN_CENTER, 0, 40);
}
MSH_CMD_EXPORT(demo, demo);

void demo_fs(int argc,char *argv[])
{
	char temp_buf[50];
	
	if(argc==1)
	{
		rt_kprintf("sys para error");
		return ;
	}
	rt_sprintf(temp_buf,"S:/weather/%s.bin",argv[1]);
	rt_kprintf("file path  %s",temp_buf);
	lv_obj_t * icon = lv_img_create(lv_scr_act());
	lv_img_set_src(icon, temp_buf);
	lv_obj_align(icon, LV_ALIGN_CENTER, 0, 0);
}
MSH_CMD_EXPORT(demo_fs, demo_fs);

static void lvgl_thread_entry(void *parameter)
{

    lv_init();
    lv_port_disp_init();
	  lv_port_fs_init();
    //demo();
    while (1)
    {
        lv_task_handler();
        rt_thread_mdelay(5); /* 官方手册是提议至少 5 ms */
    }
}

static void lvgl_timeout(void *parameter)
{
    lv_tick_inc(10); /* 因为一个时钟是 10ms */
}

int main(void)
{
    lcd_clear(WHITE);
		
    lvgl_tid = rt_thread_create("lvgl",
                                lvgl_thread_entry,
                                RT_NULL,
                                4096, /* stack size */
                                12,   /* priority */
                                5);   /* time slice */
    if (lvgl_tid != RT_NULL)
        rt_thread_startup(lvgl_tid);

    lvgl_timer = rt_timer_create("lvgl_timer",
                                 lvgl_timeout,
                                 RT_NULL,
                                 1, /* 超时时间,单位是时钟节拍 */
                                 RT_TIMER_FLAG_PERIODIC);
    if (lvgl_timer != RT_NULL)
        rt_timer_start(lvgl_timer);
		
		if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
    {
        LOG_I("Filesystem initialized!");
    }
    else
    {
        LOG_E("Failed to initialize filesystem!");
    }

    return 0;
}

测试

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
【RT-Thread作品秀】基于 lvgl 的漏电保护装置校验仪 UI 界面设计作者:赵加文 概述低压漏电引起的各种安全事故已经严重影响到生产生活,威胁到生命财产安全。而解决这一现象的设备就是漏电保护开关,漏电保护开关的漏报率、误报率是很关键的参数,因此有必要对漏电保护开关的性能进行测试。因此,漏电保护装置校验仪是很有必要的。 开发环境硬件:ART-Pi 开发板,正点原子 480*272 4.3寸 RGB 屏幕 RT-Thread版本:4.0.3 开发工具及版本: RT-Thread Studio 2.0.0 :编写 编译 调试 下载代码 STM32CubeMX 6.1.0: codeBlocks 20.03:用于在 PC 机上进行 lvgl 模拟 MCU_Font V2.0: 用于转换中文,然后使得中文能够在 lvgl 中显示 RT-Thread使用情况概述在 UI 设计的整个过程中,使用到 RT-Thread 的部分主要有以下几个方面: 内核部分:动态线程,信号量 组件部分:PIN 设备、I2C 设备、TOUCH 设备框架、LCD 设备框架、finsh 组件 软件包部分:littlevgl2rtt、gt9147 硬件框架软件框架说明系统整体流程图: 软件模块说明整个UI 系统设计所遵循的是 lvgl 图形库的一个回调函数的机制,将各个事件与对应的操作所绑定起来,当滑动滑条时对应的滑条的回调函数就会被触发,那么就会执行滑条回调函数的内容,当滑动点击文本框时,文本框对应的回调函数就会被触发,进而创建键盘的控件,通过键盘输入所需要的数据。 演示效果图片展示: 演示视频: 比赛感悟这次参赛,之前还没有使用过 RT-Thread studio 这个集成开发环境,这次在使用 ART-Pi 的时候全程是使用 RT-Thread studio 这个开发环境,在使用的过程中也碰到了很多问题,有时候明明配置了相关组件,但是保存之后,并没有代码添加到工程里。现在也没有弄明白问题出在哪里,虽然存在着这里问题,但是在使用的过程中,还是非常的方便,整个开发过程就如同搭积木一样方便,与 RTT操作系统贴合的非常的紧密。 除此之外,便是在使用 lvgl 的过程中碰到了很多的问题,现在网上的教程基本是 lvgl v6 版本的教程,关于 lvgl v7 版本的教程很少,而且 v6版本与 V7 版本的 API 相差很大,不能按照 V6 版本来使用 V7 ,在这个过程中摸索了好多,同时也感受到了 lvgl 的魅力,使用在嵌入式系统上是非常不错的选择。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值