Portable SSD1306 OLED driver for STM32 using STM32Cube HAL, with pluggable I2C/SPI transport callbacks.
- Transport-agnostic architecture (I2C and SPI)
- No hard dependency on a specific STM32 peripheral instance
- Config-driven display setup through
OLED_Config - Built-in SSD1306 initialization sequence
- Full-screen operations (
OLED_Clear,OLED_Fill,OLED_DrawBitmap) - Partial updates via
OLED_DrawBitmapRectandOLED_SetAddressWindow - Display control APIs:
OLED_DisplayOnOLED_SetInvertOLED_SetEntireDisplayOnOLED_SetContrast
- Graphics adapter (
OLED_GfxFlushCallback) for external framebuffer pipelines
include/ssd1306.h: public APIsrc/ssd1306.c: driver implementationexamples/base_init_i2c.c: I2C transport exampleexamples/base_init_spi.c: SPI transport exampleexamples/draw_bitmap_i2c.c: I2C bitmap rendering exampleexamples/display_controls_i2c.c: display control API exampleexamples/partial_update_i2c.c: partial update examplesrc/main.c: local demo with controls + animated partial updatesdocumentation.md: detailed API/usage documentation
- Configure your STM32 clock/GPIO/bus peripheral (I2C or SPI).
- Implement a transport callback (
OLED_SendI2CFnorOLED_SendSPIFn). - Fill
OLED_Configwith display size and callback. - Call
OLED_Init(&oled). - Render using
OLED_Clear,OLED_Fill,OLED_DrawBitmap, orOLED_DrawBitmapRect. - Use control APIs (
OLED_SetInvert,OLED_SetContrast,OLED_DisplayOn) as needed.
OLED_Config oled = {
.bus_type = OLED_BUS_I2C,
.width = 128U,
.height = 64U,
.user_context = &hi2c,
.transport = {
.i2c = {
.i2c_address_7bit = 0x3CU,
.send_fn = oled_send_i2c
}
}
};
if (OLED_Init(&oled) != OLED_OK) {
Error_Handler();
}
OLED_Fill(&oled, 0x00U);OLED_Config oled = {
.bus_type = OLED_BUS_SPI,
.width = 128U,
.height = 64U,
.user_context = &hspi,
.transport = {
.spi = {
.send_fn = oled_send_spi
}
}
};OLED_OK: successOLED_ERR_INVALID_ARG: bad arguments/configOLED_ERR_IO: bus transfer failure
- For I2C, use SSD1306 7-bit address (
0x3Cis common). - For SPI, your callback should drive D/C (command/data select) and optionally CS.
OLED_DrawBitmaprequires a full framebuffer of exactlyOLED_BufferSize(cfg)bytes.OLED_DrawBitmapRectlength must match rectangle bytes:(column_end - column_start + 1) * (page_end - page_start + 1).
See documentation.md for complete API details.