wjklimek1 / SSD1322_OLED_library

Portable library for 256x64 OLED display with SSD1322 controller (with STM32F4 example project)
Other
35 stars 8 forks source link

SSD1322 OLED library

Portable library for 256x64 OLED display with SSD1322 controller (with STM32F4 example project)

Library is divided into three layers:

Provided example

Provided example is made for Nucleo F411RE development board with STM32F411RET6 MCU. Project was created in STM32CubeIDE. OLED is connected to following GPIOs:

SSD1322 pin STM32F411 GPIO Nucleo pin
RESET PA0 A0
DC PA1 A1
CS PA4 A2
SPI SCK PB0 A3
SPI MOSI PA10 D2

Click image below to watch effect of example code on YouTube

Examples with DMA

In a folder with examples for STM32F411 also two projects utilizing DMA data strasfers were included. First one uses DMA in blocking mode, so CPU has to wait for transmission end to leave a function. This still gives some preformance boost, especially for frame buffer transfers.

In a second example DMA works in non blocking mode, so CPU only commissions DMA transfer and then leaves function. That takes much less CPU time, but library in this example was changed slightly to handle CS pin in a different way.

Following changes were made to enable non blocking mode DMA:

This gives considerable preformance boost when huge data blocks, like frame buffer, are transfered. When DMA sends data through SPI, CPU can go on and do other useful task.

How to modify it to work with different MCU than STM32F411?

Due to layered structure of library you have to provide only following functions in SSD1322_HW_driver.c file:

Dont be afraid of that delay. It is only used in init sequence to drive RESET pin low for a few milliseconds.

SPI configuration

SSD1322 expects different SPI clock phase and polarity than CubeMX gives by default. Setting should be following:

Adafruit fonts

GFX library can draw text with fonts provided by AdafruitGFX library. To write text with Adafruit font include font file and select font with function:

void select_font(const GFXfont *new_gfx_font)

for example:

select_font(&FreeMono12pt7b);

When font is already selected you can use it to write text on screen. It works only for null terminated strings!

Bitmaps

Two bitmap formats are supported:

void draw_bitmap_8bpp(uint8_t *frame_buffer, const uint8_t *bitmap, uint16_t x0, uint16_t y0, uint16_t x_size, uint16_t y_size);

It draws bitmap where one pixel corresponds to one byte - just an 8bit grayscale bitmaps.

void draw_bitmap_4bpp(uint8_t *frame_buffer, const uint8_t *bitmap, uint16_t x0, uint16_t y0, uint16_t x_size, uint16_t y_size);

Here one byte in bitmap stores brightness value for two pixels - just like in the actual framebuffer.

To convert bitmaps to 8 or 4 bits per pixel grayscale depth you can use converter from this link, downloading software "Converting bitmap to Hex". It's a bit buggy but worked for most bitmaps I tried to convert.