技术解读

以下内容由 GitRead 中文社区 编辑团队基于项目 README 与官方资料整理, 结合中文开发者的常见使用场景补充技术选型建议。具体以项目官方文档为准。

深度技术分析:STM32 图形驱动项目 “RobertoBenjami/stm32_graphics_display_drivers”

项目背景与痛点

STM32 微控制器在嵌入式系统中广受欢迎,因其优秀的性能、丰富的外设以及卓越的功耗表现。然而,要在这些设备上实现丰富的图形显示功能却并不容易。尤其在处理多种不同类型的 LCD 显示器时,开发人员可能需要花费大量时间和精力去编写和调试相应的驱动代码。正是为了解决这个问题,“RobertoBenjami/stm32_graphics_display_drivers” 项目诞生了。它提供了一整套针对 STM32 微控制器的图形驱动实现,涵盖了多种通讯接口(如 SPI、GPIO 和 FSMC),以及各种类型的 LCD 显示器(如 ST7735、ST7783、ILI9325、ILI9341 等)。

核心技术揭秘

为了实现一套高效的图形驱动,项目采用了模块化的设计思路,分为多个独立但又密切相关的组件。其技术架构主要包括以下部分:

  1. 抽象层 (Abstraction Layer):提供统一的接口来操作各种类型的显示器和通信接口,将底层硬件的具体细节隐藏起来。
  2. 驱动逻辑 (Driver Logic):实现具体的驱动逻辑,包括数据传输、初始化等操作。这些逻辑针对不同的 LCD 类型和接口协议进行优化。
  3. 通讯接口 (Communication Interfaces):支持多样的通信方式,如 SPI(通过 DMA)、GPIO 和 FSMC(也通过 DMA),极大地方便了系统集成。

以下是简化的核心架构示意图:

graph TD subgraph "驱动系统" A[抽象层] --> B[驱动逻辑] B --> C[ST7735] B --> D[ST7783] B --> E[ILI9325] B --> F[其他LCD] subgraph "通信模块" G[SPI(DMA)] --> B H[GPIO] --> B I[FSMC(DMA)] --> B end end

每个通信模块通过调用下层的硬件抽象接口,实现与 LCD 显示器的数据交互,从而大大减少了开发人员的工作量,使得只需专注于上层应用逻辑。

功能亮点与差异

该项目的亮点在于其高度的灵活性和可扩展性。不论是新老款的 STM32 微控制器,或是层出不穷的新款显示器和驱动技术,都能够在该项目中找到一个通用的、标准的实现方式。此外,根据不同应用需求,开发者可以轻松地选择或新增支持的显示器类型和通信协议。

对比同类竞品,该项目更加强调模块化和易用性,在不牺牲功能性和性能的情况下,显著降低了开发难度,尤其适合没有大量资源投入到驱动开发中的团队。

应用场景与落地建议

在生产环境中使用该项目时,需要注意的是,不同的 STM32 微控制器接口(如 SPI、GPIO)的硬件配置存在差异,这可能会影响到某些驱动的适配和运行性能。开发人员应根据实际硬件规格进行细致检查,并适当调整驱动配置以保证最佳性能。

总体而言,此项目适用于需要广泛支持多样化 LCD 显示器的嵌入式项目,如智能家居、工业控制器,以及任何希望用有限的硬件资源实现丰富视觉效果的应用。

综合评价

优点:

  • 模块化设计:完整的一套模块化驱动方案,大大减少了开发时间和复杂度。
  • 丰富的支持:提供了多种常用显示器和接口的支持,适应性强。
  • 灵活性高:接口和驱动逻辑分离,方便开发者自行扩展或替换。

缺点:

  • 复杂度:对于非资深开发者而言,学习和掌握整个系统需要一定时间。
  • 定制化:某些特定需求可能仍需定制化开发。

总之,“RobertoBenjami/stm32_graphics_display_drivers” 无疑为嵌入式图形显示开发者提供了一把利器,能够显著提高开发效率,特别是在需要处理多种 LCD 类型的复杂嵌入式项目中。

简要分析

热度分
968
价值分
459
活跃状态
活跃

语言占比

C
HTML

README

STM32Fxxx graphics display drivers

Layer chart, examples circuits and settings:

LCD I/O and touchscreen I/O driver:

  • lcd_io_spi: software SPI, hardware SPI, hardware SPI with DMA
  • lcd_io_gpio8: 8 bit paralell without analog resistive touchscreen
  • lcd_io_gpio16: 16 bit paralell without analog resistive touchscreen
  • lcd_io_fsmc8: 8 bit paralell without analog resistive touchscreen + FSMC or FSMC with DMA
  • lcd_io_fsmc16: 16 bit paralell without analog resistive touchscreen + FSMC or FSMC with DMA
  • lcdts_io_gpio8: 8 bit paralell with analog resistive touchscreen
  • lcdts_io_fsmc8: 8 bit paralell with analog resistive touchscreen + FSMC or FSMC with DMA
  • ts_xpt2046: XPT2046 touchscreen driver, software and hardware SPI, 4 or 5 wires
  • lcdts_io_spi_xpt2046: LCD and XPT2046 in common SPI, software and hardware SPI with DMA (DMA only in LCD)
stm family spi gpio8 gpio16 fsmc8 fsmc16 ts_gpio8 ts_fsmc8 ts_xpt2046 spi_xpt2046 note
STM32F0 + + +
STM32F1 + + + + +
STM32F2 + + + + + + + + +
STM32F3 + + +
STM32F4 + + + + + + + + +
STM32F7 + + +
STM32G0 + + not tested
STM32G4 + + not tested
STM32L0 + + + not tested
STM32L1 + + +
STM32L4 + + + not tested
STM32L5 + + not tested
STM32H7 + +

LCD driver:

  • st7735 (SPI mode tested)
  • st7783 (8 bit paralell mode tested)
  • ili9325 (8 bit paralell mode tested)
  • ili9328 (8 bit paralell mode tested)
  • ili9341 (SPI, 8 bit and 16 bit paralell mode, SPI with LTDC mode tested)
  • ili9486 (8 bit paralell mode tested)
  • ili9488 (SPI, 8 bit paralell mode tested)
  • hx8347g (8 bit paralell mode tested)

App:

  • LcdSpeedTest: Lcd speed test
  • TouchCalib: Touchscreen calibration program
  • Paint: Arduino paint clone
  • JpgViewer: JPG file viewer from SD card or pendrive
  • AnalogClock: Analog Clock demo (printf: the result, i use the SWO pin for ST-LINK Serial Wire Viewer (SWV). See:examples/Src/syscalls.c)
  • 3d filled vector (from https://github.com/cbm80amiga/ST7789_3D_Filled_Vector_Ext)

How to use starting from zero?

  1. Create project for Cubemx or CubeIDE
  • setting the RCC (Crystal/ceramic resonator)
  • setting the debug (SYS / serial wire or trace assyn sw)
  • setting the timebase source (i like the basic timer for this)
  • if FSMC : setting the FSMC (chip select, memory type = LCD, Lcd reg select, data = 8 or 16 bits, timing)
  • if SDCARD : setting the SDIO mode, enable the FATFS, FATFS: USE_LFN, MAX_SS = 4096, FS_LOCK = 5, RTC enabled
  • if USB pendrive : setting the USB host, setting the USB power, enable the FATFS, USE_LFN, MAX_SS = 4096, FS_LOCK = 5
  • if JPG : enabled the LIBJPEG
  • setting the clock configuration
  • project settings: project name, toolchain = truestudio, stack size = 0x800
  • generate source code
  1. Truestudio or CubeIDE
  • open projects from file system (only Truestudio)
  • open main.c
  • add USER CODE BEGIN PFP: void mainApp(void);
  • add USER CODE BEGIN WHILE: mainApp();
  • open main.h
  • add USER CODE BEGIN Includes (#include “stm32f1xx_hal.h” or #include “stm32f4xx_hal.h” or …)
  • add 2 new folder for Src folder (App, Lcd)
  • copy file(s) from App/… to App
  • copy 4 or 7 files from Drivers to Lcd (lcd.h, bmp.h, stm32_adafruit_lcd.h / c, if touch: ts.h, stm32_adafruit_ts.h / c)
  • copy Fonts folder to Lcd folder
  • copy io driver to Lcd folder (lcd_io_…h / c or lcdts_io…h / c or…)
  • copy lcd driver to Lcd folder (st7735.h / c or ili9325.h /c or…)
  • if printf to SWO : copy syscalls.c to Src folder
  • setting the configuration the io driver header file (pin settings, speed settings etc…)
  • setting the LCD configuration (orientation, touchscreen)
  • add include path : Src/Lcd
  • setting the compile options (Enable paralell build, optimalization)
  • compile, run …

Example (please unzip the app you like):

  • f103c8t_app: (stm32f103c8t HAL applications, cubemx, truestudio)
  • f103c8t_app_rtos: (stm32f103c8t HAL-FreeRtos applications, cubemx, truestudio)
  • f407vet_app: (stm32f407vet HAL-applications, cubemx, truestudio)
  • f407vet_app_rtos: (stm32f407vet HAL-FreeRtos applications, cubemx, truestudio)
  • f407vet_app_fsmc: (stm32f407vet HAL applications, FSMC, cubemx, truestudio)
  • f407vet_app_rtos_fsmc: (stm32f407vet HAL-FreeRtos applications, FSMC, cubemx, truestudio)
  • f407vet_app_fsmc16: (stm32f407vet HAL applications, FSMC 16 bit, cubemx, truestudio)
  • f407zet_app_fsmc16_extsram: (stm32f407zet HAL applications, FSMC 16 bit, external 1MB SRAM, cubemx, truestudio)

https://lujji.github.io/blog/stlink-clone-trace/

评论

暂无评论