Coder Social home page Coder Social logo

robertobenjami / stm32_hal_graphics_display_drivers Goto Github PK

View Code? Open in Web Editor NEW
60.0 6.0 19.0 3.06 MB

STM32 graphics LCD and Touchscreen drivers (LCD: st7735, st7781, ili9325, ili9328, ili9341, ili9488, Touch: analog resistive, xpt2046, stmpe811)

C 98.89% HTML 1.11%
ili9341 ili9488 st7735 stm32 ili9328 ili9325 lcd-display st7781 i2c spi

stm32_hal_graphics_display_drivers's Introduction

STM32 graphics display drivers with HAL

What should be set first?

Set the peripherals and GPIO pins in cubemx according to the comments in the io driver header.

Which files should we add to the project?

Upper layer:

  • stm32_adafruit_lcd.h, stm32_adafruit_lcd.c, lcd.h, bmp.h
  • Fonts folder
  • if used touchscreen: stm32_adafruit_ts.h, stm32_adafruit_ts.c, ts.h

Middle layer (must be added to the project according to the type of LCD)

  • lcd / hx8347g.h, hx8347g.c (hx8347 lcd driver)
  • lcd / ili9325.h, ili9325.c (ili9325 lcd driver)
  • lcd / ili9328.h, ili9328.c (ili9328 lcd driver)
  • lcd / ili9341.h, ili9341.c (ili9341 lcd driver)
  • lcd / ili9488.h, ili9488.c (ili9488 lcd driver)
  • lcd / st7735.h, st7735.c (st7735 lcd driver)
  • lcd / st7781.h, st7781.c (st7781 lcd driver)

Lower layer (only the necessary files are added)

  • lcd_io.h (this is always necessary)
  • io_spi / lcd_io_spi_hal.h, lcd_io_spi_hal.c (SPI lcd io driver)
  • io_spi / lcd_io_spi_dma2d_hal.h, lcd_io_spi_dma2d_hal.c (SPI lcd io driver with DMA2D bitdepth convert)
  • io_spi / lcdts_io_xpt2046_spi_hal.h, lcdts_io_xpt2046_spi_hal.c (SPI lcd io and touchscreen driver in shared SPI pins)
  • io_spi / ts_xpt2046.h, ts_xpt2046.c (hardware and software SPI touchscreen driver)
  • io_gpio / lcd_io_gpio8_hal.h, lcd_io_gpio8_hal.c (8bit paralell lcd io driver in GPIO)
  • io_gpio / lcd_io_gpio16_hal.h, lcd_io_gpio16_hal.c (16bit paralell lcd io driver in GPIO)
  • io_gpio / lcdts_io_gpio8_hal.h, lcdts_io_gpio8_hal.c (8bit paralell lcd io driver in GPIO with analog resistive touchscreen)
  • io_fscm / lcd_io_fsmc8_hal.h, lcd_io_fsmc8_hal.c (8bit paralell lcd io driver in FSMC hardware)
  • io_fscm / lcd_io_fsmc16_hal.h, lcd_io_fsmc16_hal.c (16bit paralell lcd io driver in FSMC hardware)
  • io_i2c / ts_stmpe811qtr.h, ts_stmpe811qtr.c (i2c stmpe811 touchscreen driver)

Note

I rewrote the graphics driver. I changed the old baremetal style to HAL. Why? Many new processor families have appeared recently, and managing the differences between each processor family in a bare-metal way has become too complicated. Using the HAL, the operation of a given i/o peripheral only needs to be done once, the deviations are done by the processor's own libraries for me. Deficiencies will also be filled in this way, because in the old days there are processor families where the selection is quite incomplete.

How It Works?

Take the example program “appLcdSpeedTest.c” as an example.

Upper layer

The “appLcdSpeedTest.c” uses the functions of the upper layer of the driver (stm32_adafruit_lcd.h / c). This layer contains many drawing functions (initialization, point, line, rectangle, circle, oval, some filled shapes, text, bitmap, image, point and image readback, etc.), if we need more, we can supplement it. This part of the driver is the same for all display types.

  • bmp.h is required for the bitmap function, it contains the description of the bitmap header
  • lcd.h is a port for upper and middle layer communication.

The following things can be set in this layer stm32_adafruit_lcd.h:

  • default font size: LCD_DEFAULT_FONT
  • default background color: LCD_DEFAULT_BACKCOLOR
  • default drawing color: LCD_DEFAULT_TEXTCOLOR

We can change these in the program at any time with the functions BSP_LCD_SetFont, BSP_LCD_SetBackColor, BSP_LCD_SetTextColor.

lcd.h:

  • 16-bit color code byte sequence reversal: LCD_REVERSE16

We only turn this on if we want to draw in DMA mode with the fsmc8 io interface (the DMA controller can only work in this way). If we turn it on, we must also store all color codes and bitmap data in reverse byte order in our program.

The difference between bitmap and image drawing:

  • The bitmap is drawn from the bottom up, the bitmap data must contain the bitmap header.
  • The image draws from top to bottom and contains only the pointer containing the raw bit pattern. Therefore, the size of the image must also be specified.

Middle layer

This layer contains only a few drawing functions (initialization, cursor position setting, drawing window setting, point drawing, horizontal and vertical line drawing, bitmap drawing, image drawing and readback). The upper layer must map all the drawing functions to these few drawing functions. This layer depends on the type of display, because the drawing functions on each display can be solved with a different method, so we have to add the files of the display we use to the project (e.g. ili9341.h / c).

The following things can be set in this layer:

ili9341.h (or other display.h):

  • interface type (only for some types): INTERFACE
  • Rotation every 90 degrees: ORIENTATION
  • clear screen during initialization: INITCLEAR
  • color order (if the red and blue colors are swapped, you can change it here): COLORMODE
  • color depth for drawing: WRITEBITDEPTH
  • color depth for reading: READBITDEPTH
  • do not change the screen size: LCD_PIXEL_WIDTH, LCD_PIXEL_HEIGHT

Lower layer

Carries out the delivery of the data required for initialization and drawing over a physical channel. The physical channel can be an SPI interface or a parallel interface. The parallel interface can use the GPIO pins “lcd_io_gpiox_hal.h / c”, or if the controller contains FSC/FSMC peripherals, we use the “lcd_io_fsmcx_hal.h / c” interface, because it is much faster.

Touchscreen

The touchscreen driver has only 2 layers.

Upper layer

  • stm32_adafruit_ts.h, stm32_adafruit_ts.c, ts.h

Setting in stm32_adafruit_ts.h:

  • TS_CINDEX values that are necessary to calculate the screen coordinate from the AD value of the touchscreen. It is possible to produce with the App TouchCalib or the App / Paint application.

Lower layer

There are 4 types of touchscreen drivers

  • Analog resistive touchscreen with GPIO 8 bits (io_gpio / lcdts_io_gpio8_hal.h, lcdts_io_gpio8_hal.c)
  • Xpt2046 touchscreen driver on independent SPI channel (io_spi / ts_xpt2046.h, ts_xpt2046.c). This driver can also work with software SPI, so you can connect it to any pin and you don't need an SPI peripheral.
  • Xpt2046 touchscreen driver on shared SPI channel (io_spi / lcdts_io_xpt2046_spi_hal.h, lcdts_io_xpt2046_spi_hal.c)
  • Stmpe811 touchscreen driver on I2C channel (io_i2c / ts_stmpe811qtr.h, ts_stmpe811qtr.c)

stm32_hal_graphics_display_drivers's People

Contributors

robertobenjami avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

stm32_hal_graphics_display_drivers's Issues

Can't use lcd_io_hal_spi with stm32g474re

Hey Roberto,

Thanks for such a detailed library for TFT lcd's combination with STM32. I am fairly new at programming in embedded and am trying to use this repository's lcd_io_hal_spi to control my ili9486 (without touch) with my STM32G474RE. After all the steps and files have been imported in my cubeide project when I try to start by using BSP_INIT() and BSP_LCD_Clear(), it does not give any output on the LCD. Can you let me know why you think this is happening?

ILI9486 Scroll function divide by zero error

File: ili9486.c
Function: void ili9486_Scroll(int16_t Scroll, uint16_t TopFix, uint16_t BottonFix)
Since the static uint16_t scrparam[4] array is zero initialized, the line
Scroll = (0 - Scroll) % scrparam[2];
will generate a divide by zero error when executed the first time.

ILI9486 16bit data transfer error

File: ili9486.c

The parameters for some of the commands must be transferred in 8 bit mode, even though the hardware support 16bit mode.
These commands include:

  • ILI9486_CASET (0x2A)
  • ILI9486_PASET (0x2B)
  • ILI9486_VSCRDEF (0x33)
  • ILI9486_VSCRSADD (0x37)

These affect the SETWINDOW, SETCURSOR macros and the ili9486_Scroll function.

STM32F405 SPI DMA

Hello,

I have configured the driver for an ILI9488 display and SPI. However, when I turn on LCD_DMA_TX I get the error:

/Core/Src/Lcd/lcdts_io_xpt2046_spi_hal.c:491:23: error: 'LCD_SPI_HANDLE' undeclared (first use in this function); did you mean 'LCDTS_SPI_HANDLE'?

Where is the error?

Regards Sascha

You have a pretty good handle on the STM32 interfaces for the LCD's

I am wondering if you might be willing to lend a hand with something I am working on. I know diddly about the STM32's and I am wanting to provide the user of my project with the ability to use the STM32 MCU's with an LCD attached.

The tricky bit is what I am needing is for the bus drivers to be designed as a runtime thing and not a compile time.

for example, What is called FSMC and GPIO bust types in your library are I8080 interfaces. One has the ability to do DMA transfers and the other doesn't. I need to have the 8 and 16 lane versions of both of those combined into a single I8080 driver. The determination if whether to use FSMC or not is going to be based on how the frame buffer gets allocated and a flag being supplied that specifies that DMA memory is to be used for the allocation. Now I know that all of the memory on the STM32' is DMA capable memory so the flag would not actually do anything other then let the driver know what the intention is. The pin numbers that are to be used get passed to a function that builds the driver.

Here is what I am working on..

https://github.com/kdschlosser/lvgl_micropython

That repo combines MicroPython and the LVGL GUI framework together. This allows for fast development that is not MCU specific. So if a user creates a UI it is done in Python code and that code would be portable across ESP32, STM32, RP2, SAMD, ... It is also able to run on Windows, Unix, macOS, Android, Webassembly (Emscripten)

I am creating a common API across all of the different ports that MicroPython supports. Currently working with I8080, SPI and RGB data busses and I would like to add MIPI in the future.

Didn't know if it would be something you would be interested in lending a hand with. I know the MicroPython side of things and that is where I would be able to help out with it. I can provide the framework that is being used to attach the MCU specific connection methods to MicroPython and I can tweak the other ports if the framework needs to be added onto for whatever reason.

Here is an example of the framework for the RGB bus driver, this is for the3 ESP32

https://github.com/kdschlosser/lvgl_micropython/blob/main/ext_mod/lcd_bus/esp32_src/rgb_bus.c

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.