OpenEdv-开源电子网

 找回密码
 立即注册
查看: 2497|回复: 0

LVGL lv_img_set_src()。。程序通过点击hello world切换logo_img和sys_icon,切换logo_img图片来源无效,但是sys_icon是可换的

[复制链接]

1

主题

1

帖子

0

精华

新手上路

积分
45
金钱
45
注册时间
2016-4-24
在线时间
13 小时
发表于 2022-1-26 15:14:15 | 显示全部楼层 |阅读模式
1金钱
本帖最后由 正经小伙 于 2022-1-26 15:18 编辑

/**
* @file lv_port_disp.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.h"
#include "lv_port_indev.h"
#include "lv_port_fs.h"

#include "lv_btn.h"


#include "hwlcd.h"
#include "hwled.h"

#include "lv_apps\demo\demo.h"
#include "lv_tests\lv_test_theme\lv_test_theme_1.h"
#include "lv_tests\lv_test_theme\lv_test_theme_2.h"


LV_IMG_DECLARE(logo1);
LV_IMG_DECLARE(logo2);

lv_obj_t * sys_icon = NULL;
lv_obj_t * logo_img = NULL;
lv_obj_t *lv_lable_one = NULL;
lv_obj_t *main_scr = NULL;

/*--------------创建线程---------------*/
static rt_thread_t lcd_thread = RT_NULL;
static void lcd_thread_entry(void* parameter);

/**********************
*  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);
#if LV_USE_GPU
static void gpu_blend(lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa);
static void gpu_fill(lv_color_t * dest, uint32_t length, lv_color_t color);
#endif


#define LVGL_BUF_SIZE  (LV_HOR_RES_MAX*LV_VER_RES_MAX)

#define LV_DRAW_BUF1_ADDR   (LCD_USER_ADDR)
#define LV_DRAW_BUF2_ADDR   (LCD_USER_ADDR + LVGL_BUF_SIZE*sizeof(lv_color_t))
        
static lv_color_t draw_buf_3_1[LVGL_BUF_SIZE] __attribute__((at(LV_DRAW_BUF1_ADDR)));         
static lv_color_t draw_buf_3_2[LVGL_BUF_SIZE] __attribute__((at(LV_DRAW_BUF2_ADDR)));

void lv_port_disp_init(void)
{
    /*-------------------------
     * Initialize your display
     * -----------------------*/
    disp_init();

    /*-----------------------------
     * Create a buffer for drawing
     *----------------------------*/

                static lv_disp_buf_t draw_buf_dsc_3;
        
                lv_disp_buf_init(&draw_buf_dsc_3, draw_buf_3_1, draw_buf_3_2, LVGL_BUF_SIZE);   /*Initialize the display buffer*/

    /*-----------------------------------
     * Register the display in LittlevGL
     *----------------------------------*/

    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_PIXEL_WIDTH;
    disp_drv.ver_res = LCD_PIXEL_HEIGHT;
               

    /*Used to copy the buffer's content to the display*/
    disp_drv.flush_cb = disp_flush;

    /*Set a display buffer*/
    disp_drv.buffer = &draw_buf_dsc_3;

#if LV_USE_GPU
    /*Optionally add functions to access the GPU. (Only in buffered mode, LV_VDB_SIZE != 0)*/

    /*Blend two color array using opacity*/
    disp_drv.gpu_blend = gpu_blend;

    /*Fill a memory array with a color*/
    disp_drv.gpu_fill = gpu_fill;
#endif

    /*Finally register the driver*/
    lv_disp_drv_register(&disp_drv);
}

/**********************
*   STATIC FUNCTIONS
**********************/

/* Initialize your display and the required peripherals. */
static void disp_init(void)
{
    /*You code here*/
}

/* 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_CopyRect(area->x1,area->y1,area->x2,area->y2,(u16*)color_p);
    /* IMPORTANT!!!
     * Inform the graphics library that you are ready with the flushing*/
    lv_disp_flush_ready(disp_drv);
}

/*
* 描述: 创建LCD线程
* 参数: 无
* 返回: 无
*/
u8 Create_LCD_Thread(void)
{
        lcd_thread =                          /* 线程控制块指针 */
    rt_thread_create( "lcd_thread",              /* 线程名字 */
                      lcd_thread_entry,   /* 线程入口函数 */
                      RT_NULL,             /* 线程入口函数参数 */
                      4096,                 /* 线程栈大小 */
                      5,                  /* 线程的优先级 */
                      20);                 /* 线程时间片 */

        /* 启动线程,开启调度 */
        if(lcd_thread != RT_NULL)
        {
                rt_thread_startup(lcd_thread);
        }
        else
        {
                return 0;
        }        
        return  RT_EOK;
}
void lable_event_handler(lv_obj_t *obj , lv_event_t event)
{
        static u8 img_i = 0;
        if(obj == lv_lable_one)
        {
                lv_obj_invalidate(logo_img);
                switch(event)
                {
                        case LV_EVENT_RELEASED:
                        {
                                if(0 == img_i)
                                {
                                        LOGO1_IMG_SHOW();
                                        img_i = 1;
                                        LED0_ON();  
                                }
                                else
                                {
                                        LOGO2_IMG_SHOW();
                                        img_i = 0;        
                                        LED0_OFF();  
                                }
                        }break;
                        case LV_EVENT_PRESSED:
                        {
                                 
                        }break;
                        default:break;
                }

        }
}
/*
* 描述: LCD线程入口函数
* 参数: 无
* 返回: 无*/
static void lcd_thread_entry(void* parameter)
{        

        
        HW_LCD_Init();
        
        lv_init();                                                                                        //lvgl系统初始化
        lv_port_disp_init();                                                //lvgl显示接口初始化,放在lv_init()的后面
        lv_port_indev_init();                                                //lvgl输入接口初始化,放在lv_init()的后面
        lv_port_fs_init();

        main_scr = lv_scr_act();
        
        //demo_create();
        //lv_test_theme_1(lv_theme_night_init(210, NULL));
        //lv_test_theme_2();

        
        lv_lable_one = lv_label_create(main_scr,NULL);
        
        lv_obj_set_click(lv_lable_one,true);
        lv_obj_set_event_cb(lv_lable_one,lable_event_handler);
        
        lv_label_set_text(lv_lable_one,"Hello Word");
        lv_obj_set_pos(lv_lable_one,1000,0);
        
        logo_img = lv_img_create(main_scr,NULL);
        
        sys_icon = lv_img_create(main_scr, NULL);
        
        while (1)
        {                        
                lv_task_handler();
                rt_thread_delay(5);   /* 延时5个tick */
        }
}

void LOGO1_IMG_SHOW(void)
{
        lv_img_set_src(logo_img,"F:/logo1.bin");
        lv_obj_set_pos(logo_img,0,0);
        
        lv_img_set_src(sys_icon, LV_SYMBOL_OK "Accept1");
        lv_obj_set_pos(sys_icon,300,300);
}
void LOGO2_IMG_SHOW(void)
{
        lv_img_set_src(logo_img,"F:/logo2.bin");
        lv_obj_set_pos(logo_img,0,0);
        
        lv_img_set_src(sys_icon, LV_SYMBOL_OK "Accept2");
        lv_obj_set_pos(sys_icon,300,300);
}


/*OPTIONAL: GPU INTERFACE*/
#if LV_USE_GPU

/* If your MCU has hardware accelerator (GPU) then you can use it to blend to memories using opacity
* It can be used only in buffered mode (LV_VDB_SIZE != 0 in lv_conf.h)*/
static void gpu_blend(lv_disp_drv_t * disp_drv, lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa)
{
    /*It's an example code which should be done by your GPU*/
    uint32_t i;
    for(i = 0; i < length; i++) {
        dest = lv_color_mix(dest, src, opa);
    }
}

/* If your MCU has hardware accelerator (GPU) then you can use it to fill a memory with a color
* It can be used only in buffered mode (LV_VDB_SIZE != 0 in lv_conf.h)*/
static void gpu_fill_cb(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*/
    uint32_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*/
    }
}

#endif  /*LV_USE_GPU*/

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

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


正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2024-6-8 11:02

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表