Minimal SH1106 128x64 I2C OLED driver.
Application scenarios
- A 1.3-inch status display.
- A menu on a handheld instrument.
- A bring-up display for a new board.
Contract
void sh1106_init(sh1106_port_t port);
void sh1106_clear(sh1106_port_t port);
void sh1106_set_contrast(sh1106_port_t port, uint8_t value);
void sh1106_write_page(sh1106_port_t port, uint8_t page, uint8_t column,
const uint8_t *data, uint8_t width);
writesends commands with control 0x00 and data with control 0x40.initsends the SH1106 DC-DC, timing, and COM sequence.clearfills all eight pages with zeros.write_pagewrites one page (8 pixels) atcolumn.- The caller owns the page buffer; no framebuffer or font is included.
Parameters
- I2C address
0x3Cor0x3Dis selected in the adapter. widthmust fitcolumn + width <= 128.- Contrast
0..255;0xFFis a common start.
Memory and timing
- 8 bytes of state plus the port context.
clearsends 1024 data bytes; split into adapter-sized chunks.- SH1106 has 132 columns; visible RAM starts at column 2.
Integration
sh1106_port_t port = board_sh1106_port();
sh1106_init(port);
sh1106_clear(port);
uint8_t row[128] = {0};
row[0] = 0x3C;
sh1106_write_page(port, 2, 0, row, 128);
Adapters
- The adapter handles the I2C address, bus speed, and reset pin.
- Reference: u8g2
u8x8_d_ssd1306_128x64_noname.cSH1106 sequence (BSD-2-Clause). - Verify the panel's DC-DC and COM configuration.
When not to use
- An SSD1306 panel; use the
ssd1306unit. - Text and graphics; add a font/renderer above this page API.
Verification
make test covers the init sequence, clear, contrast, and a page write with
the SH1106 column offset.
API
sh1106.h ↗Extracted from the public header at the catalog tag. The README contract above is the behavior reference.
Functions
void sh1106_init(sh1106_port_t port);void sh1106_clear(sh1106_port_t port);void sh1106_set_contrast(sh1106_port_t port, uint8_t value);void sh1106_write_page(sh1106_port_t port, uint8_t page, uint8_t column, const uint8_t *data, uint8_t width);Types
sh1106_port_t structvoid *context;
uint8_t (*write)(void *context, uint8_t control, const uint8_t *data, uint16_t length);