接上文| # 【开鸿智谷NiobeU4开发板免费试用体验】控温(1); |
感谢开鸿智谷研发人员依然小烨哥和 大佬们的支持指导。
准备在上文基础上增加LCD。本文参考大佬们成功移植,
LCD方法:
- 拷贝一份显示驱动,
- 修改显示驱动
- 修改新案例目录名下.application_config
- 修改新案例目录名下BUILD.gn
- 修改新案例目录名下程序
起动系统及MobaXterm,
cd niobeu4_src/vendor/openvalley/niobeu4/demo/301_user/
拷贝一份显示驱动
git clone https://github.com/lvgl/lvgl.git
参考指令:
cd ~/niobeu4_src/vendor/openvalley/niobeu4/demo/301_user
cp -rf ../107_hdf_spi/st7735.h
cp -rf ../107_hdf_spi/st7735s.c
cp -f lvgl/examples/porting/lv_port_disp_template.c lvgl/lv_port_disp.c
cp -f lvgl/examples/porting/lv_port_disp_template.h lvgl/lv_port_disp.h
修改显示驱动
配置文件lv_conf.h
复制lvgl/lv_conf_template.h为lvgl/lv_conf.h
将#if 0改为1
暂时将542行的#define LV_USE_WIN 1 改为0
暂时将 39行#define LV_MEM_SIZE (128U * 1024U) / [bytes] /改为
#define LV_MEM_SIZE (12U * 1024U) / [bytes] /
按需提供堆大小,过大可能编译不过,过小可能影响创建对象。
#if 1
#ifndef LV_CONF_H
#define LV_CONF_H
#include <stdint.h>
#define LV_COLOR_DEPTH 16
#define LV_COLOR_CHROMA_KEY lv_color_hex(0x00ff00)
#define LV_USE_BUILTIN_MALLOC 1
#if LV_USE_BUILTIN_MALLOC
#define LV_MEM_SIZE (12U * 1024U)
#define LV_MEM_ADR 0
#if LV_MEM_ADR == 0
#undef LV_MEM_POOL_INCLUDE
#undef LV_MEM_POOL_ALLOC
#endif
#endif
#define LV_USE_BUILTIN_MEMCPY 1
#define LV_USE_BUILTIN_SNPRINTF 1
#if LV_USE_BUILTIN_SNPRINTF
#define LV_SPRINTF_USE_FLOAT 0
#endif
#define LV_STDLIB_INCLUDE <stdint.h>
#define LV_MALLOC lv_malloc_builtin
#define LV_REALLOC lv_realloc_builtin
#define LV_FREE lv_free_builtin
#define LV_MEMSET lv_memset_builtin
#define LV_MEMCPY lv_memcpy_builtin
#define LV_SNPRINTF lv_snprintf_builtin
#define LV_VSNPRINTF lv_vsnprintf_builtin
#define LV_STRLEN lv_strlen_builtin
#define LV_STRNCPY lv_strncpy_builtin
#define LV_TICK_CUSTOM 0
#if LV_TICK_CUSTOM
#define LV_TICK_CUSTOM_INCLUDE "Arduino.h"
#define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis())
#endif
#define LV_DPI_DEF 130
#define LV_USE_DRAW_MASKS 1
#define LV_USE_DRAW_SW 1
#if LV_USE_DRAW_SW
#define LV_DRAW_SW_COMPLEX 1
#define LV_DRAW_SW_LAYER_SIMPLE_BUF_SIZE (24 * 1024)
#define LV_DRAW_SW_LAYER_SIMPLE_FALLBACK_BUF_SIZE (3 * 1024)
#define LV_DRAW_SW_SHADOW_CACHE_SIZE 0
#define LV_DRAW_SW_CIRCLE_CACHE_SIZE 4
#define LV_DRAW_SW_GRADIENT_CACHE_DEF_SIZE 0
#define LV_DRAW_SW_GRADIENT_DITHER 0
#if LV_DRAW_SW_GRADIENT_DITHER
#define LV_DRAW_SW_GRADIENT_DITHER_ERROR_DIFFUSION 0
#endif
#define LV_DRAW_SW_FONT_SUBPX 0
#if LV_DRAW_SW_FONT_SUBPX
#define LV_DRAW_SW_FONT_SUBPX_BGR 0
#endif
#endif
#define LV_USE_DRAW_SDL 0
#if LV_USE_DRAW_SDL
#define LV_DRAW_SDL_INCLUDE_PATH <SDL2/SDL.h>
#define LV_DRAW_SDL_LRU_SIZE (1024 * 1024 * 8)
#define LV_DRAW_SDL_CUSTOM_BLEND_MODE (SDL_VERSION_ATLEAST(2, 0, 6))
#endif
#define LV_USE_GPU_ARM2D 0
#define LV_USE_GPU_STM32_DMA2D 0
#if LV_USE_GPU_STM32_DMA2D
#define LV_GPU_DMA2D_CMSIS_INCLUDE
#endif
#define LV_USE_GPU_GD32_IPA 0
#define LV_USE_GPU_NXP_PXP 0
#if LV_USE_GPU_NXP_PXP
#define LV_USE_GPU_NXP_PXP_AUTO_INIT 0
#endif
#define LV_USE_GPU_NXP_VG_LITE 0
#define LV_USE_GPU_SWM341_DMA2D 0
#if LV_USE_GPU_SWM341_DMA2D
#define LV_GPU_SWM341_DMA2D_INCLUDE "SWM341.h"
#endif
#define LV_USE_LOG 0
#if LV_USE_LOG
#define LV_LOG_LEVEL LV_LOG_LEVEL_WARN
#define LV_LOG_PRINTF 0
#define LV_LOG_USE_TIMESTAMP 1
#define LV_LOG_TRACE_MEM 1
#define LV_LOG_TRACE_TIMER 1
#define LV_LOG_TRACE_INDEV 1
#define LV_LOG_TRACE_DISP_REFR 1
#define LV_LOG_TRACE_EVENT 1
#define LV_LOG_TRACE_OBJ_CREATE 1
#define LV_LOG_TRACE_LAYOUT 1
#define LV_LOG_TRACE_ANIM 1
#endif
#define LV_USE_ASSERT_NULL 1
#define LV_USE_ASSERT_MALLOC 1
#define LV_USE_ASSERT_STYLE 0
#define LV_USE_ASSERT_MEM_INTEGRITY 0
#define LV_USE_ASSERT_OBJ 0
#define LV_ASSERT_HANDLER_INCLUDE <stdint.h>
#define LV_ASSERT_HANDLER while(1);
#define LV_USE_PERF_MONITOR 0
#if LV_USE_PERF_MONITOR
#define LV_USE_PERF_MONITOR_POS LV_ALIGN_BOTTOM_RIGHT
#endif
#define LV_USE_MEM_MONITOR 0
#if LV_USE_MEM_MONITOR
#define LV_USE_MEM_MONITOR_POS LV_ALIGN_BOTTOM_LEFT
#endif
#define LV_USE_REFR_DEBUG 0
#define LV_DISP_ROT_MAX_BUF (10*1024)
#define LV_USE_USER_DATA 1
#define LV_ENABLE_GC 0
#if LV_ENABLE_GC != 0
#define LV_GC_INCLUDE "gc.h"
#endif
#define LV_IMG_CACHE_DEF_SIZE 0
#define LV_GRADIENT_MAX_STOPS 2
#define LV_COLOR_MIX_ROUND_OFS 0
#define LV_BIG_ENDIAN_SYSTEM 0
#define LV_ATTRIBUTE_TICK_INC
#define LV_ATTRIBUTE_TIMER_HANDLER
#define LV_ATTRIBUTE_FLUSH_READY
#define LV_ATTRIBUTE_MEM_ALIGN_SIZE 1
#define LV_ATTRIBUTE_MEM_ALIGN
#define LV_ATTRIBUTE_LARGE_CONST
#define LV_ATTRIBUTE_LARGE_RAM_ARRAY
#define LV_ATTRIBUTE_FAST_MEM
#define LV_EXPORT_CONST_INT(int_value) struct _silence_gcc_warning
#define LV_USE_LARGE_COORD 0
#define LV_FONT_MONTSERRAT_8 0
#define LV_FONT_MONTSERRAT_10 0
#define LV_FONT_MONTSERRAT_12 0
#define LV_FONT_MONTSERRAT_14 1
#define LV_FONT_MONTSERRAT_16 0
#define LV_FONT_MONTSERRAT_18 0
#define LV_FONT_MONTSERRAT_20 0
#define LV_FONT_MONTSERRAT_22 0
#define LV_FONT_MONTSERRAT_24 0
#define LV_FONT_MONTSERRAT_26 0
#define LV_FONT_MONTSERRAT_28 0
#define LV_FONT_MONTSERRAT_30 0
#define LV_FONT_MONTSERRAT_32 0
#define LV_FONT_MONTSERRAT_34 0
#define LV_FONT_MONTSERRAT_36 0
#define LV_FONT_MONTSERRAT_38 0
#define LV_FONT_MONTSERRAT_40 0
#define LV_FONT_MONTSERRAT_42 0
#define LV_FONT_MONTSERRAT_44 0
#define LV_FONT_MONTSERRAT_46 0
#define LV_FONT_MONTSERRAT_48 0
#define LV_FONT_MONTSERRAT_12_SUBPX 0
#define LV_FONT_MONTSERRAT_28_COMPRESSED 0
#define LV_FONT_DEJAVU_16_PERSIAN_HEBREW 0
#define LV_FONT_SIMSUN_16_CJK 0
#define LV_FONT_UNSCII_8 0
#define LV_FONT_UNSCII_16 0
#define LV_FONT_CUSTOM_DECLARE
#define LV_FONT_DEFAULT &lv_font_montserrat_14
#define LV_FONT_FMT_TXT_LARGE 0
#define LV_USE_FONT_COMPRESSED 0
#define LV_USE_FONT_PLACEHOLDER 1
#define LV_TXT_ENC LV_TXT_ENC_UTF8
#define LV_TXT_BREAK_CHARS " ,.;:-_)]}"
#define LV_TXT_LINE_BREAK_LONG_LEN 0
#define LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN 3
#define LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN 3
#define LV_TXT_COLOR_CMD "#"
#define LV_USE_BIDI 0
#if LV_USE_BIDI
#define LV_BIDI_BASE_DIR_DEF LV_BASE_DIR_AUTO
#endif
#define LV_USE_ARABIC_PERSIAN_CHARS 0
#define LV_USE_ANIMIMG 1
#define LV_USE_ARC 1
#define LV_USE_BAR 1
#define LV_USE_BTN 1
#define LV_USE_BTNMATRIX 1
#define LV_USE_CALENDAR 1
#if LV_USE_CALENDAR
#define LV_CALENDAR_WEEK_STARTS_MONDAY 0
#if LV_CALENDAR_WEEK_STARTS_MONDAY
#define LV_CALENDAR_DEFAULT_DAY_NAMES {"Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"}
#else
#define LV_CALENDAR_DEFAULT_DAY_NAMES {"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"}
#endif
#define LV_CALENDAR_DEFAULT_MONTH_NAMES {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
#define LV_USE_CALENDAR_HEADER_ARROW 1
#define LV_USE_CALENDAR_HEADER_DROPDOWN 1
#endif
#define LV_USE_CANVAS 1
#define LV_USE_CHART 1
#define LV_USE_CHECKBOX 1
#define LV_USE_COLORWHEEL 1
#define LV_USE_DROPDOWN 1
#define LV_USE_IMG 1
#define LV_USE_IMGBTN 1
#define LV_USE_KEYBOARD 1
#define LV_USE_LABEL 1
#if LV_USE_LABEL
#define LV_LABEL_TEXT_SELECTION 1
#define LV_LABEL_LONG_TXT_HINT 1
#endif
#define LV_USE_LED 1
#define LV_USE_LINE 1
#define LV_USE_LIST 1
#define LV_USE_MENU 1
#define LV_USE_METER 1
#define LV_USE_MSGBOX 1
#define LV_USE_ROLLER 1
#define LV_USE_SLIDER 1
#define LV_USE_SPAN 1
#if LV_USE_SPAN
#define LV_SPAN_SNIPPET_STACK_SIZE 64
#endif
#define LV_USE_SPINBOX 1
#define LV_USE_SPINNER 1
#define LV_USE_SWITCH 1
#define LV_USE_TEXTAREA 1
#if LV_USE_TEXTAREA != 0
#define LV_TEXTAREA_DEF_PWD_SHOW_TIME 1500
#endif
#define LV_USE_TABLE 1
#define LV_USE_TABVIEW 1
#define LV_USE_TILEVIEW 1
#define LV_USE_WIN 0
#define LV_USE_THEME_DEFAULT 1
#if LV_USE_THEME_DEFAULT
#define LV_THEME_DEFAULT_DARK 0
#define LV_THEME_DEFAULT_GROW 1
#define LV_THEME_DEFAULT_TRANSITION_TIME 80
#endif
#define LV_USE_THEME_BASIC 1
#define LV_USE_THEME_MONO 1
#define LV_USE_FLEX 1
#define LV_USE_GRID 1
#define LV_USE_FS_STDIO 0
#if LV_USE_FS_STDIO
#define LV_FS_STDIO_LETTER '\0'
#define LV_FS_STDIO_PATH ""
#define LV_FS_STDIO_CACHE_SIZE 0
#endif
#define LV_USE_FS_POSIX 0
#if LV_USE_FS_POSIX
#define LV_FS_POSIX_LETTER '\0'
#define LV_FS_POSIX_PATH ""
#define LV_FS_POSIX_CACHE_SIZE 0
#endif
#define LV_USE_FS_WIN32 0
#if LV_USE_FS_WIN32
#define LV_FS_WIN32_LETTER '\0'
#define LV_FS_WIN32_PATH ""
#define LV_FS_WIN32_CACHE_SIZE 0
#endif
#define LV_USE_FS_FATFS 0
#if LV_USE_FS_FATFS
#define LV_FS_FATFS_LETTER '\0'
#define LV_FS_FATFS_CACHE_SIZE 0
#endif
#define LV_USE_PNG 0
#define LV_USE_BMP 0
#define LV_USE_SJPG 0
#define LV_USE_GIF 0
#define LV_USE_QRCODE 0
#define LV_USE_FREETYPE 0
#if LV_USE_FREETYPE
#define LV_FREETYPE_CACHE_SIZE (16 * 1024)
#if LV_FREETYPE_CACHE_SIZE >= 0
#define LV_FREETYPE_SBIT_CACHE 0
#define LV_FREETYPE_CACHE_FT_FACES 0
#define LV_FREETYPE_CACHE_FT_SIZES 0
#endif
#endif
#define LV_USE_TINY_TTF 0
#if LV_USE_TINY_TTF
#define LV_TINY_TTF_FILE_SUPPORT 0
#endif
#define LV_USE_RLOTTIE 0
#define LV_USE_FFMPEG 0
#if LV_USE_FFMPEG
#define LV_FFMPEG_DUMP_FORMAT 0
#endif
#define LV_USE_SNAPSHOT 0
#define LV_USE_MONKEY 0
#define LV_USE_GRIDNAV 0
#define LV_USE_FRAGMENT 0
#define LV_USE_IMGFONT 0
#if LV_USE_IMGFONT
#define LV_IMGFONT_PATH_MAX_LEN 64
#define LV_IMGFONT_USE_IMG_CACHE_HEADER 0
#endif
#define LV_USE_MSG 0
#define LV_USE_IME_PINYIN 0
#if LV_USE_IME_PINYIN
#define LV_IME_PINYIN_USE_DEFAULT_DICT 1
#define LV_IME_PINYIN_CAND_TEXT_NUM 6
#define LV_IME_PINYIN_USE_K9_MODE 1
#if LV_IME_PINYIN_USE_K9_MODE == 1
#define LV_IME_PINYIN_K9_CAND_TEXT_NUM 3
#endif
#endif
#define LV_USE_FILE_EXPLORER 0
#if LV_USE_FILE_EXPLORER
#define LV_FILE_EXPLORER_PATH_MAX_LEN (128)
#define LV_FILE_EXPLORER_QUICK_ACCESS 1
#endif
#define LV_BUILD_EXAMPLES 1
#define LV_USE_DEMO_WIDGETS 0
#if LV_USE_DEMO_WIDGETS
#define LV_DEMO_WIDGETS_SLIDESHOW 0
#endif
#define LV_USE_DEMO_KEYPAD_AND_ENCODER 0
#define LV_USE_DEMO_BENCHMARK 0
#if LV_USE_DEMO_BENCHMARK
#define LV_DEMO_BENCHMARK_RGB565A8 0
#endif
#define LV_USE_DEMO_STRESS 0
#define LV_USE_DEMO_MUSIC 0
#if LV_USE_DEMO_MUSIC
#define LV_DEMO_MUSIC_SQUARE 0
#define LV_DEMO_MUSIC_LANDSCAPE 0
#define LV_DEMO_MUSIC_ROUND 0
#define LV_DEMO_MUSIC_LARGE 0
#define LV_DEMO_MUSIC_AUTO_PLAY 0
#endif
#endif
#endif
配置文件lv_port_disp.h
将里面的#if 0改为1,
加入:
#include "../st7735.h"
#define LV_LVGL_H_INCLUDE_SIMPLE 1
#define MY_DISP_HOR_RES ROW_PIXEL
#define MY_DISP_VER_RES COL_PIXEL
#if 1
#include "../st7735.h"
#ifndef LV_PORT_DISP_TEMPL_H
#define LV_PORT_DISP_TEMPL_H
#ifdef __cplusplus
extern "C" {
#endif
#if defined(LV_LVGL_H_INCLUDE_SIMPLE)
#include "lvgl.h"
#else
#include "lvgl/lvgl.h"
#endif
#define LV_LVGL_H_INCLUDE_SIMPLE 1
#define MY_DISP_HOR_RES ROW_PIXEL
#define MY_DISP_VER_RES COL_PIXEL
配置文件lv_port_disp.c
将里面的#if 0改为1,#include "lv_port_disp_template.h"改为#include "lv_port_disp.h"
修改disp_init(void)加入LcdInit();
修改 lv_port_disp_init(void),
删掉Example for 2)和 Example for 3) 内对应的代码
修改static void disp_flush(),
/ Put a pixel to the display. For example: /
/*put_px(x, y, color_p) /改为lcd_draw_point(x,y,color_p->full);尾部加LcdPush();代码
#if 1
#include "lv_port_disp.h"
#include <stdbool.h>
#ifndef MY_DISP_HOR_RES
#warning Please define or replace the macro MY_DISP_HOR_RES with the actual screen width, default value 320 is used for now.
#define MY_DISP_HOR_RES 320
#endif
#ifndef MY_DISP_VER_RES
#warning Please define or replace the macro MY_DISP_HOR_RES with the actual screen height, default value 240 is used for now.
#define MY_DISP_VER_RES 240
#endif
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);
void lv_port_disp_init(void)
{
LcdInit();
static lv_disp_draw_buf_t draw_buf_dsc_1;
static lv_color_t buf_1[MY_DISP_HOR_RES * 10];
lv_disp_draw_buf_init(&draw_buf_dsc_1, buf_1, NULL, MY_DISP_HOR_RES * 10);
static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.hor_res = MY_DISP_HOR_RES;
disp_drv.ver_res = MY_DISP_VER_RES;
disp_drv.flush_cb = disp_flush;
disp_drv.draw_buf = &draw_buf_dsc_1;
lv_disp_drv_register(&disp_drv);
}
static void disp_init(void)
{
LcdInit();
}
volatile bool disp_flush_enabled = true;
void disp_enable_update(void)
{
disp_flush_enabled = true;
}
void disp_disable_update(void)
{
disp_flush_enabled = false;
}
static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
{
if(disp_flush_enabled) {
int32_t x;
int32_t y;
for(y = area->y1; y <= area->y2; y++) {
for(x = area->x1; x <= area->x2; x++) {
lcd_draw_point(x,y,color_p->full);
color_p++;
}
}
LcdPush(); }
lv_disp_flush_ready(disp_drv);
}
#else
typedef int keep_pedantic_happy;
#endif
修改lv_tick_inc
此处修改方式与参考文件不同,此处修改如下
在/home/lst/niobeu4_src/vendor/openvalley/niobeu4/demo/301_user/lvgl/src/hal/lv_hal_tick.c中加入LOS_Msleep(tick_period);如下
/**
* You have to call this function periodically
* [url=home.php?mod=space&uid=3142012]@param[/url] tick_period the call period of this function in milliseconds
*/
LV_ATTRIBUTE_TICK_INC void lv_tick_inc(uint32_t tick_period)
{
tick_irq_flag = 0;
sys_time += tick_period;
LOS_Msleep(tick_period);
}
修改新案例目录名下.application_config
在MobaXterm右侧
在niobeu4_src/vendor/openvalley/niobeu4/demo/301_user目录
下打开# .application_config文件,修改内容:
config NIOBEU4_APPLICATION_301
bool "301_user"
select DRIVERS
select DRIVERS_HDF
select DRIVERS_HDF_PLATFORM
select DRIVERS_HDF_CONFIG_MACRO
select DRIVERS_HDF_PLATFORM_SPI
select DRIVERS_HDF_PLATFORM_GPIO
select DRIVERS_HDF_PLATFORM_ADC
修改新案例目录名下BUILD.gn
在MobaXterm右侧
在niobeu4_src/vendor/openvalley/niobeu4/demo/301_user目录
下打开BUILD.gn文件,修改内容:
将lv_conf.h添加到工程头文件包含路径。
即修改
niobeu4_src/vendor/openvalley/niobeu4/demo/301_user/BUILD.gn
include_dirs = [
下添加一行"lvgl/",
import("//kernel/liteos_m/liteos.gni")
assert(defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO), "Must Config LOSCFG_DRIVERS_HDF_CONFIG_MACRO in kernel/liteos_m menuconfig!")
assert(defined(LOSCFG_DRIVERS_HDF_PLATFORM_SPI), "Must Config LOSCFG_DRIVERS_HDF_PLATFORM_SPI in kernel/liteos_m menuconfig!")
assert(defined(LOSCFG_DRIVERS_HDF_PLATFORM_GPIO), "Must Config LOSCFG_DRIVERS_HDF_PLATFORM_GPIO in kernel/liteos_m menuconfig!")
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name){
sources = [
"os_thread_example.c",
"st7735s.c",
"lvgl/src/core/lv_disp.c",
"lvgl/src/core/lv_event.c",
"lvgl/src/core/lv_group.c",
"lvgl/src/core/lv_indev_scroll.c",
"lvgl/src/core/lv_indev.c",
"lvgl/src/core/lv_obj_class.c",
"lvgl/src/core/lv_obj_draw.c",
"lvgl/src/core/lv_obj_pos.c",
"lvgl/src/core/lv_obj_scroll.c",
"lvgl/src/core/lv_obj_style_gen.c",
"lvgl/src/core/lv_obj_style.c",
"lvgl/src/core/lv_obj_tree.c",
"lvgl/src/core/lv_obj.c",
"lvgl/src/core/lv_refr.c",
"lvgl/src/core/lv_theme.c",
"lvgl/src/draw/sw/lv_draw_sw_arc.c",
"lvgl/src/draw/sw/lv_draw_sw_blend.c",
"lvgl/src/draw/sw/lv_draw_sw_dither.c",
"lvgl/src/draw/sw/lv_draw_sw_gradient.c",
"lvgl/src/draw/sw/lv_draw_sw_img.c",
"lvgl/src/draw/sw/lv_draw_sw_layer.c",
"lvgl/src/draw/sw/lv_draw_sw_letter.c",
"lvgl/src/draw/sw/lv_draw_sw_line.c",
"lvgl/src/draw/sw/lv_draw_sw_polygon.c",
"lvgl/src/draw/sw/lv_draw_sw_rect.c",
"lvgl/src/draw/sw/lv_draw_sw_transform.c",
"lvgl/src/draw/sw/lv_draw_sw.c",
"lvgl/src/draw/lv_draw_arc.c",
"lvgl/src/draw/lv_draw_img.c",
"lvgl/src/draw/lv_draw_label.c",
"lvgl/src/draw/lv_draw_layer.c",
"lvgl/src/draw/lv_draw_line.c",
"lvgl/src/draw/lv_draw_mask.c",
"lvgl/src/draw/lv_draw_rect.c",
"lvgl/src/draw/lv_draw_transform.c",
"lvgl/src/draw/lv_draw_triangle.c",
"lvgl/src/draw/lv_draw.c",
"lvgl/src/draw/lv_img_buf.c",
"lvgl/src/draw/lv_img_cache.c",
"lvgl/src/draw/lv_img_decoder.c",
"lvgl/src/font/lv_font_fmt_txt.c",
"lvgl/src/font/lv_font.c",
"lvgl/src/font/lv_font_montserrat_12.c",
"lvgl/src/font/lv_font_montserrat_14.c",
"lvgl/src/font/lv_font_montserrat_16.c",
"lvgl/src/hal/lv_hal_disp.c",
"lvgl/src/hal/lv_hal_indev.c",
"lvgl/src/hal/lv_hal_tick.c",
"lvgl/src/layouts/flex/lv_flex.c",
"lvgl/src/layouts/grid/lv_grid.c",
"lvgl/src/libs/bmp/lv_bmp.c",
"lvgl/src/libs/ffmpeg/lv_ffmpeg.c",
"lvgl/src/libs/freetype/lv_freetype.c",
"lvgl/src/libs/fsdrv/lv_fs_fatfs.c",
"lvgl/src/libs/fsdrv/lv_fs_posix.c",
"lvgl/src/libs/fsdrv/lv_fs_stdio.c",
"lvgl/src/libs/fsdrv/lv_fs_win32.c",
"lvgl/src/libs/gif/gifdec.c",
"lvgl/src/libs/gif/lv_gif.c",
"lvgl/src/libs/png/lodepng.c",
"lvgl/src/libs/png/lv_png.c",
"lvgl/src/libs/qrcode/lv_qrcode.c",
"lvgl/src/libs/qrcode/qrcodegen.c",
"lvgl/src/libs/rlottie/lv_rlottie.c",
"lvgl/src/libs/sjpg/lv_sjpg.c",
"lvgl/src/libs/sjpg/tjpgd.c",
"lvgl/src/misc/lv_anim_timeline.c",
"lvgl/src/misc/lv_anim.c",
"lvgl/src/misc/lv_area.c",
"lvgl/src/misc/lv_async.c",
"lvgl/src/misc/lv_bidi.c",
"lvgl/src/misc/lv_color.c",
"lvgl/src/misc/lv_fs.c",
"lvgl/src/misc/lv_gc.c",
"lvgl/src/misc/lv_ll.c",
"lvgl/src/misc/lv_log.c",
"lvgl/src/misc/lv_lru.c",
"lvgl/src/misc/lv_malloc_builtin.c",
"lvgl/src/misc/lv_math.c",
"lvgl/src/misc/lv_mem.c",
"lvgl/src/misc/lv_memcpy_builtin.c",
"lvgl/src/misc/lv_printf.c",
"lvgl/src/misc/lv_style_gen.c",
"lvgl/src/misc/lv_style.c",
"lvgl/src/misc/lv_templ.c",
"lvgl/src/misc/lv_timer.c",
"lvgl/src/misc/lv_tlsf.c",
"lvgl/src/misc/lv_txt_ap.c",
"lvgl/src/misc/lv_txt.c",
"lvgl/src/misc/lv_utils.c",
"lvgl/src/others/file_explorer/lv_file_explorer.c",
"lvgl/src/others/fragment/lv_fragment_manager.c",
"lvgl/src/others/fragment/lv_fragment.c",
"lvgl/src/others/gridnav/lv_gridnav.c",
"lvgl/src/others/ime/lv_ime_pinyin.c",
"lvgl/src/others/imgfont/lv_imgfont.c",
"lvgl/src/others/monkey/lv_monkey.c",
"lvgl/src/others/msg/lv_msg.c",
"lvgl/src/others/snapshot/lv_snapshot.c",
"lvgl/src/themes/basic/lv_theme_basic.c",
"lvgl/src/themes/default/lv_theme_default.c",
"lvgl/src/themes/mono/lv_theme_mono.c",
"lvgl/src/widgets/animimg/lv_animimg.c",
"lvgl/src/widgets/arc/lv_arc.c",
"lvgl/src/widgets/bar/lv_bar.c",
"lvgl/src/widgets/btn/lv_btn.c",
"lvgl/src/widgets/btnmatrix/lv_btnmatrix.c",
"lvgl/src/widgets/calendar/lv_calendar_header_arrow.c",
"lvgl/src/widgets/calendar/lv_calendar_header_dropdown.c",
"lvgl/src/widgets/calendar/lv_calendar.c",
"lvgl/src/widgets/canvas/lv_canvas.c",
"lvgl/src/widgets/chart/lv_chart.c",
"lvgl/src/widgets/checkbox/lv_checkbox.c",
"lvgl/src/widgets/colorwheel/lv_colorwheel.c",
"lvgl/src/widgets/dropdown/lv_dropdown.c",
"lvgl/src/widgets/img/lv_img.c",
"lvgl/src/widgets/imgbtn/lv_imgbtn.c",
"lvgl/src/widgets/keyboard/lv_keyboard.c",
"lvgl/src/widgets/label/lv_label.c",
"lvgl/src/widgets/led/lv_led.c",
"lvgl/src/widgets/line/lv_line.c",
"lvgl/src/widgets/list/lv_list.c",
"lvgl/src/widgets/menu/lv_menu.c",
"lvgl/src/widgets/meter/lv_meter.c",
"lvgl/src/widgets/msgbox/lv_msgbox.c",
"lvgl/src/widgets/objx_templ/lv_objx_templ.c",
"lvgl/src/widgets/roller/lv_roller.c",
"lvgl/src/widgets/slider/lv_slider.c",
"lvgl/src/widgets/span/lv_span.c",
"lvgl/src/widgets/spinbox/lv_spinbox.c",
"lvgl/src/widgets/spinner/lv_spinner.c",
"lvgl/src/widgets/switch/lv_switch.c",
"lvgl/src/widgets/table/lv_table.c",
"lvgl/src/widgets/tabview/lv_tabview.c",
"lvgl/src/widgets/textarea/lv_textarea.c",
"lvgl/src/widgets/tileview/lv_tileview.c",
"lvgl/lv_port_disp.c",
"lvgl/demos/stress/lv_demo_stress.c",
]
include_dirs = [
"//drivers/hdf_core/framework/include/platform/",
"//drivers/hdf_core/framework/include/utils/",
"//drivers/hdf_core/framework/support/platform/include/spi",
"//drivers/hdf_core/adapter/khdf/liteos_m/osal/include/",
"//drivers/hdf_core/framework/include/core/",
"//drivers/hdf_core/framework/include/osal/",
"//drivers/hdf_core/framework/support/platform/include/gpio",
"//kernel/liteos_m/kernel/include",
"//device/soc/esp/esp32/components/esp_adc_cal/include/",
"//device/soc/esp/esp32/components/driver/esp32/include/",
".",
"lvgl/",
"lvgl/src",
]
}
修改新案例目录名下程序
/home/lst/niobeu4_src/vendor/openvalley/niobeu4/demo/301_user 下
os_thread_example.c
#include <stdio.h>
#include "stdint.h"
#include "los_task.h"
#include "ohos_run.h"
#include "st7735.h"
#include <math.h>
#include "lv_port_disp.h"
#include "lvgl.h"
#include "demos/lv_demos.h"
#include "esp_adc_cal.h"
#include "gpio_if.h"
#define PWR_SW_PIN_INDEX 2
#define KEY_LED_OFF 0
#define KEY_LED_ON 1
#define BLUE_LED_PIN_INDEX 0
#define RED_LED_PIN_INDEX 1
UINT32 button_o=0,key_stateBLUE=0,key_stateRED=0;
void lv_tick_handle(UINT32 arg)
{
printf("%s start tick\r\n", __FUNCTION__);
while(1)
{
lv_tick_inc(50);
lv_timer_handler();
}
}
UINT32 Example_TaskLo(UINT32 arg)
{
uint16_t key_state = 0;
while(1){
LOS_Msleep(30);
if (button_o==55){
button_o=0;
printf("[key_state] sw4 : %d\n", key_state);
if (key_stateRED){
GpioWrite(RED_LED_PIN_INDEX, KEY_LED_OFF);
key_stateRED=0;
printf("[RED_LED] sw4 : Off\n");
}
else{
GpioWrite(RED_LED_PIN_INDEX, KEY_LED_ON);
key_stateRED=1;
printf("[RED_LED] sw4 : ON\n");
}
}
if (button_o==66){
button_o=0;
printf("[key_state] sw5 : %d\n", key_state);
if (key_stateBLUE){GpioWrite(BLUE_LED_PIN_INDEX, KEY_LED_OFF);
key_stateBLUE=0;
printf("[BLUE_LED] sw5 : Off\n");
}
else{
GpioWrite(BLUE_LED_PIN_INDEX, KEY_LED_ON);
key_stateBLUE=1;
printf("[BLUE_LED] sw5 : ON\n");
}
}
}
}
void StartHdfSPITest(void)
{
int raw;
UINT32 g_lv_time_task;
TSK_INIT_PARAM_S task = { 0 };
task.pfnTaskEntry = (TSK_ENTRY_FUNC)lv_tick_handle;
task.pcName = "lv_time_task";
task.uwStackSize = 0x1000;
task.usTaskPrio = 25 - 1;
GpioSetDir(PWR_SW_PIN_INDEX, GPIO_DIR_OUT);
GpioWrite(PWR_SW_PIN_INDEX, 1);
adc1_config_width(ADC_WIDTH_12Bit);
adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_DB_11);
printf("[key_led] ADC init\n");
lv_init();
lv_port_disp_init();
LOS_TaskCreate(&g_lv_time_task, &task);
lv_obj_t * btn_sw4 = lv_btn_create(lv_scr_act());
lv_obj_set_pos(btn_sw4, 10, 10);
lv_obj_set_size(btn_sw4, 110, 25);
lv_obj_t * label_sw4 = lv_label_create(btn_sw4);
lv_obj_center(label_sw4);
lv_obj_t * btn_sw5 = lv_btn_create(lv_scr_act());
lv_obj_set_pos(btn_sw5, 10, 45);
lv_obj_set_size(btn_sw5, 110, 25);
lv_obj_t * label_sw5 = lv_label_create(btn_sw5);
lv_obj_center(label_sw5);
GpioSetDir(RED_LED_PIN_INDEX, GPIO_DIR_OUT);
GpioSetDir(BLUE_LED_PIN_INDEX, GPIO_DIR_OUT);
task.pfnTaskEntry = (TSK_ENTRY_FUNC)Example_TaskLo;
task.pcName = "Example_TaskLo";
task.uwStackSize = 0x1000;
task.usTaskPrio = 25 ;
LOS_TaskCreate(&g_lv_time_task, &task);
while(1)
{ lv_label_set_text(label_sw4, "SW4 Release");
lv_label_set_text(label_sw5, "SW5 Release");
LOS_Msleep(200);
lv_task_handler();
raw = adc1_get_raw(ADC1_CHANNEL_0);
UINT32 button_s=0;
if (raw < 100)
{
LOS_Msleep(30);
lv_label_set_text(label_sw4, "SW4 Pressed");
raw = adc1_get_raw(ADC1_CHANNEL_0);
if (raw < 100)
{
button_o=55;
button_s++;
printf("[key_led] sw4 pressed raw: %d\n", raw);
while(adc1_get_raw(ADC1_CHANNEL_0)< 100){ LOS_Msleep(30);
button_s++;
if (button_s>34){
printf("[key_led] sw4 pressed long: %d\n", raw);
}
if (button_s>240){button_s=240;}
}
button_s=0;
printf("[key_led] sw4 pressed up: %d\n", raw);
}
}
else if (raw >1000 && raw < 3000)
{
LOS_Msleep(30);
lv_label_set_text(label_sw5, "SW5 Pressed");
raw = adc1_get_raw(ADC1_CHANNEL_0);
if (raw >1000 && raw < 3000)
{
button_o=66;
button_s++;
printf("[key_led] sw5 pressed raw: %d\n", raw);
raw = adc1_get_raw(ADC1_CHANNEL_0);
while(raw >1000 && raw < 3000){ LOS_Msleep(30);
button_s++;
if (button_s>34){
printf("[key_led] sw5 pressed long: %d\n", raw);
}
if (button_s>240){button_s=240;}
raw = adc1_get_raw(ADC1_CHANNEL_0);
}
button_s=0;
printf("[key_led] sw5 pressed up: %d\n", raw);
}
}
}
}
OHOS_APP_RUN(StartHdfSPITest);
```![1665816283026.jpg](
构建源码
- 进入源码根目录,执行hb set命令并选择openvalley下的iotlink。
hb set
hb build –f
构建成功会提示类似如下信息。
[OHOS INFO] iotlink build success
[OHOS INFO] cost time: 0:03:28
ls /home/lst/niobeu4_src/out/niobeu4/iotlink/bin/
| 固件名称 | 用途 |
| ---------------- | ------------------------------- |
| OHOS_Image.bin | OpenHarmony内核及应用镜像文件 |
| bootloader.bin | 启动引导镜像文件 |
| partitions.bin | 分区表镜像文件 |
烧录镜像
- 通过MobaXterm软件ssh登录服务器,将生成的文件Download到Windows系统下,如图所示。
Windows下可以使用Flash_Download_Tool
工具进行烧录,点击这里开始下载。
- 在windows下解压flash_download_tool_3.9.2.rar。
- 双击解压后得到的烧录工具flash_download_tool_3.9.2.exe,chipType选择 ESP32, workMode选择 develop,进入主界面。
图4 Flash_Download_Tool
打开页面图
固件对应烧录地址如下。
//out/niobeu4/iotlink/bin/bootloader.bin
//out/niobeu4/iotlink/bin/partitions.bin
//out/niobeu4/iotlink/OHOS_Image.bin
图6 烧录设置页面图
- 点击 START 开始下载。下载过程中,下载工具会读取 flash 的信息和芯片的 MAC 地址。我们可以通过勾选框选择是否烧录该文件,一般我们在首次烧录时会全部烧录,为了加快开发效率,调试时只需烧录
OHOS_Image.bin
即可。下载完成后,可以看到如下提示。
图7 烧录成功页面图
运行镜像
烧录完成后需要按下复位键复位设备,程序才会启动。
com:
[1;32m<--------------- OHOS Application Start Here --------------->[0m
[key_led] ADC init
[2022-10-15 14:44:16.096]
I (161) wifi_init: WiFi RX IRAM OP enabled
E (596) gpio: gpio_set_drive_capability(596): GPIO number error
E (706) spi_master: c
[2022-10-15 14:44:16.197]
heck_trans_valid(706): trans tx_buffer should be NULL and SPI_TRANS_USE_TXDATA should be cleared to skip MOSI phase.
E (706) spi
[2022-10-15 14:44:16.338]
lv_tick_handle start tick
[2022-10-15 14:45:56.791]
[key_led] sw4 pressed raw: 0
[key_state] sw4 : 0
[RED_LED] sw4 : ON
[2022-10-15 14:45:58.261]
[key_led] sw4 pressed long: 0
[key_led] sw4 pressed long: 0
[key_led] sw4 pressed long: 0
[key_led] sw4 pressed long: 0
[key_led] sw4 pressed long: 0
[key_led] sw4 pressed long: 0
[key_led] sw4 pressed long: 0
[key_led] sw4 pressed long: 0
[key_led] sw4 pressed long: 0
[key_led] sw4 pressed long: 0
[key_led] sw4 pressed up: 0
[2022-10-15 14:46:02.024]
[key_led] sw5 pressed raw: 1923
[key_state] sw5 : 0
[BLUE_LED] sw5 : ON
[2022-10-15 14:46:02.984]
[key_led] sw5 pressed up: 4095
[2022-10-15 14:46:04.647]
[key_led] sw4 pressed raw: 0
[key_state] sw4 : 0
[RED_LED] sw4 : Off
[2022-10-15 14:46:04.869]
[key_led] sw4 pressed up: 0
[2022-10-15 14:46:06.101]
[key_led] sw4 pressed raw: 0
[key_state] sw4 : 0
[RED_LED] sw4 : ON
[2022-10-15 14:46:06.235]
[key_led] sw4 pressed up: 0
[2022-10-15 14:46:07.282]
[key_led] sw5 pressed raw: 1923
[key_state] sw5 : 0
[BLUE_LED] sw5 : Off
达到预期状态。