Browse Source

[bsp][lpc55sxx]add: adaptation LVGL (#7585)

Shicheng Chu 2 years ago
parent
commit
62afa5a9dc

+ 16 - 0
bsp/lpc55sxx/lpc55s69_nxp_evk/applications/lvgl/SConscript

@@ -0,0 +1,16 @@
+from building import *
+import os
+
+cwd = GetCurrentDir()
+group = []
+src = Glob('*.c')
+CPPPATH = [cwd]
+
+list = os.listdir(cwd)
+for d in list:
+    path = os.path.join(cwd, d)
+    if os.path.isfile(os.path.join(path, 'SConscript')):
+        group = group + SConscript(os.path.join(d, 'SConscript'))
+
+group = group + DefineGroup('LVGL-port', src, depend = ['BSP_USING_LVGL'], CPPPATH = CPPPATH)
+Return('group')

+ 17 - 0
bsp/lpc55sxx/lpc55s69_nxp_evk/applications/lvgl/demo/SConscript

@@ -0,0 +1,17 @@
+from building import *
+import os
+
+cwd = GetCurrentDir()
+group = []
+src = Glob('*.c')
+CPPPATH = [cwd]
+
+list = os.listdir(cwd)
+for d in list:
+    path = os.path.join(cwd, d)
+    if os.path.isfile(os.path.join(path, 'SConscript')):
+        group = group + SConscript(os.path.join(d, 'SConscript'))
+
+group = group + DefineGroup('LVGL-demo', src, depend = ['BSP_USING_LVGL', 'BSP_USING_LVGL_DEMO'], CPPPATH = CPPPATH)
+
+Return('group')

+ 17 - 0
bsp/lpc55sxx/lpc55s69_nxp_evk/applications/lvgl/demo/lv_demo.c

@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author        Notes
+ * 2023-05-30     Chushicheng   first version
+ */
+#include <lvgl.h>
+
+void lv_user_gui_init(void)
+{
+    /* display demo; you may replace with your LVGL application at here */
+    extern void lv_demo_calendar(void);
+    lv_demo_calendar();
+}

+ 51 - 0
bsp/lpc55sxx/lpc55s69_nxp_evk/applications/lvgl/demo/lv_demo_calendar.c

@@ -0,0 +1,51 @@
+#include <lvgl.h>
+
+#define LCD_W 480
+#define LCD_H 320
+
+static void event_handler(lv_event_t * e)
+{
+    lv_event_code_t code = lv_event_get_code(e);
+    lv_obj_t * obj = lv_event_get_current_target(e);
+
+    if(code == LV_EVENT_VALUE_CHANGED) {
+        lv_calendar_date_t date;
+        if(lv_calendar_get_pressed_date(obj, &date)) {
+            LV_LOG_USER("Clicked date: %02d.%02d.%d", date.day, date.month, date.year);
+        }
+    }
+}
+
+void lv_demo_calendar(void)
+{
+    lv_obj_t  * calendar = lv_calendar_create(lv_scr_act());
+    lv_obj_set_size(calendar, LCD_W, LCD_H);
+    lv_obj_align(calendar, LV_ALIGN_CENTER, 0, 0);
+    lv_obj_add_event_cb(calendar, event_handler, LV_EVENT_ALL, NULL);
+
+    lv_calendar_set_today_date(calendar, 2021, 02, 23);
+    lv_calendar_set_showed_date(calendar, 2021, 02);
+
+    /*Highlight a few days*/
+    static lv_calendar_date_t highlighted_days[3];       /*Only its pointer will be saved so should be static*/
+    highlighted_days[0].year = 2021;
+    highlighted_days[0].month = 02;
+    highlighted_days[0].day = 6;
+
+    highlighted_days[1].year = 2021;
+    highlighted_days[1].month = 02;
+    highlighted_days[1].day = 11;
+
+    highlighted_days[2].year = 2022;
+    highlighted_days[2].month = 02;
+    highlighted_days[2].day = 22;
+
+    lv_calendar_set_highlighted_dates(calendar, highlighted_days, 3);
+
+#if LV_USE_CALENDAR_HEADER_DROPDOWN
+    lv_calendar_header_dropdown_create(calendar);
+#elif LV_USE_CALENDAR_HEADER_ARROW
+    lv_calendar_header_arrow_create(calendar);
+#endif
+    lv_calendar_set_showed_date(calendar, 2021, 10);
+}

+ 19 - 0
bsp/lpc55sxx/lpc55s69_nxp_evk/applications/lvgl/lv_conf.h

@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author        Notes
+ * 2023-05-30     Chushicheng   First version
+ */
+#ifndef LV_CONF_H
+#define LV_CONF_H
+
+#define LV_COLOR_16_SWAP    1
+#define LV_COLOR_DEPTH      16
+#define LV_USE_PERF_MONITOR 1
+#define LV_HOR_RES_MAX      480
+#define LV_VER_RES_MAX      320
+
+#endif

+ 59 - 0
bsp/lpc55sxx/lpc55s69_nxp_evk/applications/lvgl/lv_port_disp.c

@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2023-05-30     Chushicheng  First version
+ */
+#include <lvgl.h>
+#include "drv_st7796.h"
+
+#define LCD_W    480
+#define LCD_H    320
+#define MY_DISP_HOR_RES     LCD_W
+#define DISP_BUFFER_LINES   (LCD_H/5)
+
+/*A static or global variable to store the buffers*/
+static lv_disp_draw_buf_t disp_buf;
+
+/*Descriptor of a display driver*/
+static lv_disp_drv_t disp_drv;
+
+/*Static or global buffer(s). The second buffer is optional*/
+static lv_color_t buf_1[MY_DISP_HOR_RES * DISP_BUFFER_LINES];
+
+/*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)
+{
+    /* color_p is a buffer pointer; the buffer is provided by LVGL */
+    lcd_load(area->x1, area->x2, area->y1, area->y2, color_p);
+
+    /*IMPORTANT!!!
+     *Inform the graphics library that you are ready with the flushing*/
+    lv_disp_flush_ready(disp_drv);
+}
+
+void lv_port_disp_init(void)
+{
+    /*Initialize `disp_buf` with the buffer(s). With only one buffer use NULL instead buf_2 */
+    lv_disp_draw_buf_init(&disp_buf, buf_1, RT_NULL, MY_DISP_HOR_RES * DISP_BUFFER_LINES);
+
+    lv_disp_drv_init(&disp_drv); /*Basic initialization*/
+
+    /*Set the resolution of the display*/
+    disp_drv.hor_res = LCD_W;
+    disp_drv.ver_res = LCD_H;
+
+    /*Set a display buffer*/
+    disp_drv.draw_buf = &disp_buf;
+
+    /*Used to copy the buffer's content to the display*/
+    disp_drv.flush_cb = disp_flush;
+
+    /*Finally register the driver*/
+    lv_disp_drv_register(&disp_drv);
+}

+ 59 - 0
bsp/lpc55sxx/lpc55s69_nxp_evk/applications/lvgl/lv_port_indev.c

@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2023-05-30     Chushicheng  First version
+ */
+#include <lvgl.h>
+#include <rtdevice.h>
+#include "drv_gt911.h"
+
+#define LCD_W    480
+#define LCD_H    320
+
+lv_indev_t *touch_indev;
+
+static lv_indev_state_t last_state = LV_INDEV_STATE_REL;
+static rt_int16_t last_x = 0;
+static rt_int16_t last_y = 0;
+
+static gt911_input_t ctp_input;
+static capt_t *capt = RT_NULL;
+
+static void input_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
+{
+    gt911_ctp_read(&capt->gt911, &ctp_input);
+
+    if (ctp_input.num_pos > 0)
+    {
+        last_x = 480 - ctp_input.pos[0].pos_y;
+        last_y = ctp_input.pos[0].pos_x;
+        last_state = LV_INDEV_STATE_PR;
+    }
+    else
+    {
+        last_state = LV_INDEV_STATE_REL;
+    }
+    data->point.x = last_x;
+    data->point.y = last_y;
+    data->state = last_state;
+}
+
+void lv_port_indev_init(void)
+{
+    static lv_indev_drv_t indev_drv;
+
+    rt_device_t dev = rt_device_find("capt");
+    RT_ASSERT(dev != RT_NULL);
+    capt = (capt_t*)dev->user_data;
+
+    lv_indev_drv_init(&indev_drv); /*Basic initialization*/
+    indev_drv.type = LV_INDEV_TYPE_POINTER;
+    indev_drv.read_cb = input_read;
+
+    /*Register the driver in LVGL and save the created input device object*/
+    touch_indev = lv_indev_drv_register(&indev_drv);
+}

+ 12 - 0
bsp/lpc55sxx/lpc55s69_nxp_evk/board/Kconfig

@@ -336,6 +336,18 @@ menu "Board extended module Drivers"
                     default "i2c1"
             endif
 
+    config BSP_USING_LVGL
+        bool "Enable LVGL for LCD"
+        select PKG_USING_LVGL
+        select BSP_USING_NXP_LCDM_S
+        default n
+
+    if BSP_USING_LVGL
+        config BSP_USING_LVGL_DEMO
+            bool "Enable LVGL demo"
+            default y
+    endif
+
 endmenu
 
 endmenu