合宙ESP32C3使用PlatformIO开发点亮ST7735S

本文介绍了如何在ESP32-C3开发板上使用ESP-IDF框架与LVGL库进行屏幕显示和基本交互,包括核心板介绍、屏幕驱动、开发环境配置、LVGL组件安装及示例代码实现,还涉及了GPIO、SPI等接口的使用和按键事件处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

开发背景

image

模块使用的合宙的ESP32-C3(经典款) 购买连接

CORE ESP32核心板是基于乐鑫ESP32-C3进行设计的一款核心板,尺寸仅有21mm*51mm,板边采用邮票孔设计,方便开发者在不同场景下的使用。核心板支持UART、GPIO、SPI、I2C、ADC、PWM等接口,可根据实际需要选择。

屏幕使用的LuatOS屏幕扩展板 购买连接

驱动芯片:ST7735S 屏幕尺寸:80 X 160

我们使用VSCODE,安装PlatformIO插件进行开发

首先在Platforms中安装Espressif 32

都说lvgl暂不支持新版的idfV5版本

这里我们安装Espressif 325.4.0版本,ESP-IDF版本是v4.4.5

完整的代码我放在GITEE

模块信息

image

image

屏幕信息

image

开发过程

创建项目

配置
Name ESP32C3 ST7735S
Board Espressif ESP32-C3-DevKitM-1
Framework Espidf

项目名称可以自己随意更改

image

在最新版idf开发时我一直使用的esp32-c3-devkitc-02,更换为v4.x后始终不会打印,耽误了一点时间

修改配置文件

[env:esp32-c3-devkitm-1]
;平台 
platform = espressif32@5.4.0
;模块
board = esp32-c3-devkitm-1
;闪存芯片接口方式
board_build.flash_mode = dio
;框架
framework = espidf
;串口监视波特率
monitor_speed = 115200
;串口监视过滤器 解码异常 颜色展示
monitor_filters = direct, esp32_exception_decoder
;内置调试器 重点是配置这个
debug_tool = esp-builtin

安装依赖

我这里git拉取都使用的ssh的方式,如果是http的方式,自己修改一下连接

LVGL 依赖库

git submodule add -b release/v7 git@github.com:lvgl/lvgl.git components/lvgl

ESP32 芯片系列的 LVGL 驱动库

git submodule add git@github.com:lvgl/lvgl_esp32_drivers.git components/lvgl_esp32_drivers

直接编译会提示'SPI_HOST_MAX' undeclared错误

components\lvgl_esp32_drivers\lvgl_helpers.c: In function 'lvgl_spi_driver_init':
components\lvgl_esp32_drivers\lvgl_helpers.c:157:28: error: 'SPI_HOST_MAX' undeclared (first use in this function); did you mean 'GPIO_PORT_MAX'?
     assert((0 <= host) && (SPI_HOST_MAX > host));

components\lvgl_esp32_drivers\lvgl_helpers.h头部增加

#define SPI_HOST_MAX    2

components\lvgl_esp32_drivers目录提交一下git更改

Lvgl 示例

git submodule add -b release/v7 git@github.com:littlevgl/lv_examples.git components/lv_examples/lv_examples

为了等下测试方便,我们这里自己新增一些文件

增加自定义文件

增加文件:components\lv_examples\CMakeLists.txt

if(ESP_PLATFORM)

file(GLOB_RECURSE SOURCES lv_examples/*.c)

idf_component_register(SRCS ${SOURCES}
                       INCLUDE_DIRS .
                       REQUIRES lvgl)

else()
    message(FATAL_ERROR "LVGL LV examples: ESP_PLATFORM is not defined. Try reinstalling ESP-IDF.")
endif()

增加文件:components\lv_examples\component.mk

#
# Component Makefile
#

CFLAGS += -DLV_LVGL_H_INCLUDE_SIMPLE

COMPONENT_SRCDIRS := lv_examples           \
    lv_examples/src/lv_demo_benchmark      \
    lv_examples/src/lv_demo_keypad_encoder \
    lv_examples/src/demo_stress            \
    lv_examples/src/lv_demo_widgets        \
    lv_examples/src/lv_ex_style            \
    lv_examples/src/lv_ex_widgets          \
    lv_examples/assets

COMPONENT_ADD_INCLUDEDIRS := $(COMPONENT_SRCDIRS) .

增加文件:components\lv_examples\Kconfig

# Kconfig for lv_examples v7.4.0

menu "lv_examples configuration"

    config LV_EX_PRINTF
        bool "Enable printf-ing data in demos and examples."
    
    choice LV_EX_CHOICE
        prompt "Select the demo you want to run."
        default LV_USE_DEMO_WIDGETS

        config LV_USE_DEMO_WIDGETS
            bool "Show demo widgets."

        config LV_USE_DEMO_KEYPAD_AND_ENCODER
            bool "Demonstrate the usage of encoder and keyboard."

        config LV_USE_DEMO_BENCHMARK
            bool "Benchmark your system."

        config LV_USE_DEMO_STRESS
            bool "Stress test for LVGL."
    endchoice
    
    config LV_DEMO_WIDGETS_SLIDESHOW
        bool "Slide demo widgets automatically."
        depends on LV_USE_DEMO_WIDGETS
        default y
endmenu

增加文件:components\lv_examples\lv_ex_conf.h

/**
 * @file lv_ex_conf.h
 * Configuration file for v7.4.0
 *
 */
/*
 * COPY THIS FILE AS lv_ex_conf.h
 */

#if 1 /*Set it to "1" to enable the content*/

#ifndef LV_EX_CONF_H
#define LV_EX_CONF_H


/*******************
 * GENERAL SETTING
 *******************/

/* Enable printf-ing data in demoes and examples */
#ifdef CONFIG_LV_EX_PRINTF
#define LV_EX_PRINTF       1
#else
#define LV_EX_PRINTF       0
#endif

#define LV_EX_KEYBOARD     0       /*Add PC keyboard support to some examples (`lv_drivers` repository is required)*/
#define LV_EX_MOUSEWHEEL   0       /*Add 'encoder' (mouse wheel) support to some examples (`lv_drivers` repository is required)*/

/*********************
 * DEMO USAGE
 *********************/

/*Show some widget*/
#ifdef CONFIG_LV_USE_DEMO_WIDGETS
#define LV_USE_DEMO_WIDGETS        1
#else
#define LV_USE_DEMO_WIDGETS        0
#endif

#if LV_USE_DEMO_WIDGETS
#ifdef CONFIG_LV_DEMO_WIDGETS_SLIDESHOW
#define LV_DEMO_WIDGETS_SLIDESHOW   1
#else
#define LV_DEMO_WIDGETS_SLIDESHOW   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值