This is a simple library for ST MCU's in order to write characters on a SSD1306 display.
I created this library just to learn how SSD1306 controller works and eventually to use it for future projects. It is designed to be easy to undestand and modify as you want.
Actually you can only write 7-bit characters. You cannot draw single pixels.
Support is limited only to a subset of SSD1306 functionalities:
- Fundamental commands
- Only page addressing mode (with scrolling support)
- Hardware Configuration (needed for initialization)
- Timing & Driving Scheme Setting (also needed for initialization)
Sourcecode should be easy to undestand. This limited function set is enough to write characters and for scrolling.
You need the HAL driver in order to use the library. Please refer to you board documentation for how to create a new project with you editor.
I use a STM32F3 EVAL board with IAR Embedded Workbench IDE.
For IAR, just copy /Src
and /Inc
inside the same directories of you project.
When open a workspace, add to the directory User from the workspace all files inside Src directory.
In my case, the I2C handle does not work if I declare it only inside the main.c. You need to declare it also in main.h with extern keyword.
Example:
main.c:
/* Private variables ---------------------------------------------------------*/
I2C_HandleTypeDef i2c1Handle;
main.h:
/* Exported functions ------------------------------------------------------- */
extern I2C_HandleTypeDef i2c1Handle;
extern void Error_Handler(void);
Please allow VLA (Variable Length Arrays) from C/C++ Compiler options.
If you want to learn or improve this library, you may be interested to read 'How it works' section.
After HAL_Init()
, SystemClock_Config()
and I2C configuration, declare a SSD1306_HandleTypeDef
structure and initialize it with the function ssd1306_Init()
. See ssd1306.c
for function explanatory and also SSD1306_HandleTypeDef
struct definition inside ssd1306.h
for some hints.
Use ssd1306_write_string()
to write something and ssd1306_set_cursor_position()
for scrolling. That's all.
Library functions are assigned to three main layers.
High layer functions |
Mid layer functions |
Low layer functions |
Low layer functions are used to communicate with the ssd1306 controller.
Mid layer functions are usually mapped with the functionalities described at COMMAND TABLE section inside the datasheet.
High layer functions combines mid layer functions in order to show a better and simple interface of the library to the user.
Usually, a single layer only call functions declared in the layer below it.
I made this library in order to learn how ssd1306 driver works and for fun. Code should be clear so you can easily edit it in order to improve speed if you need optimizations.
I chose only I2C functions operating in blocking mode. You can easily edit low layer functions in order to use interrupts and DMA.