GPS Device
Loading...
Searching...
No Matches
ssd1309.c File Reference

SSD1309 display driver implementation file. More...

#include <stdbool.h>
#include "ssd1309.h"
#include "common.h"
#include "err.h"
#include "modules.h"
#include "stm32f401re.h"
#include "stm32f401re_gpio.h"
#include "stm32f401re_i2c.h"
#include "log.h"
#include "cmd.h"
#include "init.h"
Include dependency graph for ssd1309.c:

Go to the source code of this file.

Classes

struct  ssd1309_handle_s
 Internal structure representing the SSD1309 hardware instance. More...
struct  internal_state_s
 Internal state of the SysTick driver. More...

Macros

#define SSD1309_ADDR_W   0x3C
 I2C write address for the SSD1309 (7-bit address 0x3C, write mode).
#define SSD1309_ADDR_R   0x3D
 I2C read address for the SSD1309 (7-bit address 0x3D, read mode).
#define SSD1309_PAGE_NUM   8
 Number of pages in the SSD1309 display (8 pages × 8 rows = 64 rows).
#define SSD1309_BITS_IN_PAGE   8
 Number of pixel rows per page.
#define SSD1309_COL_NUM   128
 Number of columns in the display.
#define SSD1309_MAX_LINES   8
 Maximum number of text lines on the display (one per page).

Functions

static ERR_te ssd1309_cmd_start_handler (uint32_t argc, char **argv)
 CLI handler for the "start" command. Starts the SSD1309 subsystem at runtime.
static ERR_te ssd1309_cmd_stop_handler (uint32_t argc, char **argv)
 CLI handler for the "stop" command. Stops the SSD1309 subsystem at runtime.
static ERR_te ssd1309_cmd_fillrect_handler (uint32_t argc, char **argv)
 CLI handler for the "fillrect" command. Fills a rectangle and updates the display.
static ERR_te ssd1309_cmd_clearrect_handler (uint32_t argc, char **argv)
 CLI handler for the "clearrect" command. Clears a rectangle and updates the display.
static ERR_te ssd1309_cmd_invertrect_handler (uint32_t argc, char **argv)
 CLI handler for the "invertrect" command. Inverts a rectangle and updates the display.
static ERR_te ssd1309_cmd_drawtext_handler (uint32_t argc, char **argv)
 CLI handler for the "drawtext" command. Draws text on a line and updates the display.
static ERR_te ssd1309_cmd_clearline_handler (uint32_t argc, char **argv)
 CLI handler for the "clearline" command. Clears a line and updates the display.
static ERR_te ssd1309_cmd_invertline_handler (uint32_t argc, char **argv)
 CLI handler for the "invertline" command. Inverts a line and updates the display.
ERR_te ssd1309_init_subsys (void)
 Initializes the SSD1309 subsystem.
ERR_te ssd1309_deinit_subsys (void)
 Deinitializes the SSD1309 subsystem.
ERR_te ssd1309_start_subsys (void)
 Starts the SSD1309 subsystem.
ERR_te ssd1309_stop_subsys (void)
 Stops the SSD1309 subsystem.
ERR_te ssd1309_get_def_cfg (SSD1309_CFG_ts *ssd1309_cfg_o)
 Populates a configuration structure with sensible default values.
ERR_te ssd1309_init_handle (SSD1309_CFG_ts *ssd1309_cfg, SSD1309_HANDLE_ts **ssd1309_handle_o)
 Initializes the SSD1309 display handle and sends the configuration sequence.
ERR_te ssd1309_draw_text (char const *text, uint8_t text_len, uint8_t line, bool force)
 Draws a text string into the framebuffer at the specified line.
ERR_te ssd1309_draw_rect (uint8_t x_src, uint8_t y_src, uint8_t x_dest, uint8_t y_dest, bool force)
 Draws a filled rectangle into the framebuffer.
ERR_te ssd1309_clear_line (uint8_t line, bool force)
 Clears a single display line in the framebuffer.
ERR_te ssd1309_invert_line (uint8_t line, bool force)
 Inverts all pixels in a single display line in the framebuffer.
ERR_te ssd1309_clear_rect (uint8_t x_src, uint8_t y_src, uint8_t x_dest, uint8_t y_dest, bool force)
 Clears a rectangular region in the framebuffer.
ERR_te ssd1309_invert_rect (uint8_t x_src, uint8_t y_src, uint8_t x_dest, uint8_t y_dest, bool force)
 Inverts all pixels in a rectangular region of the framebuffer.
ERR_te ssd1309_update (bool force)
 Flushes the internal framebuffer to the display over I2C.

Variables

const uint8_t fonts8x8 [95][8]
 8×8 pixel font table for printable ASCII characters (0x20–0x7E).
static struct internal_state_s internal_state
 Singleton instance of the SSD1309 subsystem internal state.
static CMD_INFO_ts ssd1309_cmds []
 Table of CLI commands registered by the SSD1309 subsystem.
static CMD_CLIENT_INFO_ts ssd1309_cmd_client_info
 Registration descriptor passed to the command subsystem.

Detailed Description

SSD1309 display driver implementation file.

Author
github.com/Baksi675
Version
0.1
Date
2025-11-28

Definition in file ssd1309.c.

Macro Definition Documentation

◆ SSD1309_ADDR_W

#define SSD1309_ADDR_W   0x3C

I2C write address for the SSD1309 (7-bit address 0x3C, write mode).

Definition at line 26 of file ssd1309.c.

◆ SSD1309_ADDR_R

#define SSD1309_ADDR_R   0x3D

I2C read address for the SSD1309 (7-bit address 0x3D, read mode).

Definition at line 28 of file ssd1309.c.

◆ SSD1309_PAGE_NUM

#define SSD1309_PAGE_NUM   8

Number of pages in the SSD1309 display (8 pages × 8 rows = 64 rows).

Definition at line 30 of file ssd1309.c.

◆ SSD1309_BITS_IN_PAGE

#define SSD1309_BITS_IN_PAGE   8

Number of pixel rows per page.

Definition at line 32 of file ssd1309.c.

◆ SSD1309_COL_NUM

#define SSD1309_COL_NUM   128

Number of columns in the display.

Definition at line 34 of file ssd1309.c.

◆ SSD1309_MAX_LINES

#define SSD1309_MAX_LINES   8

Maximum number of text lines on the display (one per page).

Definition at line 36 of file ssd1309.c.

Variable Documentation

◆ fonts8x8

const uint8_t fonts8x8[95][8]

8×8 pixel font table for printable ASCII characters (0x20–0x7E).

Each entry contains 8 bytes representing one character glyph, where each byte is a column of 8 pixels (bit 0 = top row, bit 7 = bottom row). Index into the table as fonts8x8[char - 32]. Covers 95 characters: space (0x20) through tilde (0x7E).

Definition at line 48 of file ssd1309.c.

48 {
49
50/* 0x20 ' ' */
51{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
52
53/* 0x21 '!' */
54{0x00,0x00,0x00,0x5F,0x00,0x00,0x00,0x00},
55
56/* 0x22 '"' */
57{0x00,0x07,0x00,0x07,0x00,0x00,0x00,0x00},
58
59/* 0x23 '#' */
60{0x14,0x7F,0x14,0x7F,0x14,0x00,0x00,0x00},
61
62/* 0x24 '$' */
63{0x24,0x2A,0x7F,0x2A,0x12,0x00,0x00,0x00},
64
65/* 0x25 '%' */
66{0x23,0x13,0x08,0x64,0x62,0x00,0x00,0x00},
67
68/* 0x26 '&' */
69{0x36,0x49,0x55,0x22,0x50,0x00,0x00,0x00},
70
71/* 0x27 ''' */
72{0x00,0x05,0x03,0x00,0x00,0x00,0x00,0x00},
73
74/* 0x28 '(' */
75{0x00,0x1C,0x22,0x41,0x00,0x00,0x00,0x00},
76
77/* 0x29 ')' */
78{0x00,0x41,0x22,0x1C,0x00,0x00,0x00,0x00},
79
80/* 0x2A '*' */
81{0x14,0x08,0x3E,0x08,0x14,0x00,0x00,0x00},
82
83/* 0x2B '+' */
84{0x08,0x08,0x3E,0x08,0x08,0x00,0x00,0x00},
85
86/* 0x2C ',' */
87{0x00,0x50,0x30,0x00,0x00,0x00,0x00,0x00},
88
89/* 0x2D '-' */
90{0x08,0x08,0x08,0x08,0x08,0x00,0x00,0x00},
91
92/* 0x2E '.' */
93{0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00},
94
95/* 0x2F '/' */
96{0x20,0x10,0x08,0x04,0x02,0x00,0x00,0x00},
97
98/* 0x30 '0' */
99{0x3E,0x51,0x49,0x45,0x3E,0x00,0x00,0x00},
100
101/* 0x31 '1' */
102{0x00,0x42,0x7F,0x40,0x00,0x00,0x00,0x00},
103
104/* 0x32 '2' */
105{0x62,0x51,0x49,0x49,0x46,0x00,0x00,0x00},
106
107/* 0x33 '3' */
108{0x22,0x41,0x49,0x49,0x36,0x00,0x00,0x00},
109
110/* 0x34 '4' */
111{0x18,0x14,0x12,0x7F,0x10,0x00,0x00,0x00},
112
113/* 0x35 '5' */
114{0x2F,0x49,0x49,0x49,0x31,0x00,0x00,0x00},
115
116/* 0x36 '6' */
117{0x3E,0x49,0x49,0x49,0x32,0x00,0x00,0x00},
118
119/* 0x37 '7' */
120{0x01,0x71,0x09,0x05,0x03,0x00,0x00,0x00},
121
122/* 0x38 '8' */
123{0x36,0x49,0x49,0x49,0x36,0x00,0x00,0x00},
124
125/* 0x39 '9' */
126{0x26,0x49,0x49,0x49,0x3E,0x00,0x00,0x00},
127
128/* 0x3A ':' */
129{0x00,0x36,0x36,0x00,0x00,0x00,0x00,0x00},
130
131/* 0x3B ';' */
132{0x00,0x56,0x36,0x00,0x00,0x00,0x00,0x00},
133
134/* 0x3C '<' */
135{0x08,0x14,0x22,0x41,0x00,0x00,0x00,0x00},
136
137/* 0x3D '=' */
138{0x14,0x14,0x14,0x14,0x14,0x00,0x00,0x00},
139
140/* 0x3E '>' */
141{0x41,0x22,0x14,0x08,0x00,0x00,0x00,0x00},
142
143/* 0x3F '?' */
144{0x02,0x01,0x51,0x09,0x06,0x00,0x00,0x00},
145
146/* 0x40 '@' */
147{0x32,0x49,0x79,0x41,0x3E,0x00,0x00,0x00},
148
149/* 0x41 'A' */
150{0x00,0x7E,0x09,0x09,0x09,0x09,0x7E,0x00},
151
152/* 0x42 'B' */
153{0x00,0x7F,0x49,0x49,0x49,0x49,0x36,0x00},
154
155/* 0x43 'C' */
156{0x00,0x3E,0x41,0x41,0x41,0x41,0x22,0x00},
157
158/* 0x44 'D' */
159{0x00,0x7F,0x41,0x41,0x41,0x22,0x1C,0x00},
160
161/* 0x45 'E' */
162{0x00,0x7F,0x49,0x49,0x49,0x49,0x41,0x00},
163
164/* 0x46 'F' */
165{0x00,0x7F,0x09,0x09,0x09,0x09,0x01,0x00},
166
167/* 0x47 'G' */
168{0x00,0x3E,0x41,0x41,0x49,0x49,0x7A,0x00},
169
170/* 0x48 'H' */
171{0x00,0x7F,0x08,0x08,0x08,0x08,0x7F,0x00},
172
173/* 0x49 'I' */
174{0x00,0x41,0x41,0x7F,0x41,0x41,0x00,0x00},
175
176/* 0x4A 'J' */
177{0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00},
178
179/* 0x4B 'K' */
180{0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00},
181
182/* 0x4C 'L' */
183{0x00,0x7F,0x40,0x40,0x40,0x40,0x40,0x00},
184
185/* 0x4D 'M' */
186{0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00},
187
188/* 0x4E 'N' */
189{0x00,0x7F,0x04,0x08,0x10,0x7F,0x00,0x00},
190
191/* 0x4F 'O' */
192{0x00,0x3E,0x41,0x41,0x41,0x41,0x3E,0x00},
193
194/* 0x50 'P' */
195{0x00,0x7F,0x09,0x09,0x09,0x09,0x06,0x00},
196
197/* 0x51 'Q' */
198{0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00},
199
200/* 0x52 'R' */
201{0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00},
202
203/* 0x53 'S' */
204{0x00,0x26,0x49,0x49,0x49,0x49,0x32,0x00},
205
206/* 0x54 'T' */
207{0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00},
208
209/* 0x55 'U' */
210{0x00,0x3F,0x40,0x40,0x40,0x40,0x3F,0x00},
211
212/* 0x56 'V' */
213{0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00},
214
215/* 0x57 'W' */
216{0x00,0x7F,0x20,0x18,0x20,0x7F,0x00,0x00},
217
218/* 0x58 'X' */
219{0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00},
220
221/* 0x59 'Y' */
222{0x00,0x03,0x04,0x78,0x04,0x03,0x00,0x00},
223
224/* 0x5A 'Z' */
225{0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00},
226
227/* 0x5B '[' */
228{0x00,0x7F,0x41,0x41,0x00,0x00,0x00,0x00},
229
230/* 0x5C '\' */
231{0x02,0x04,0x08,0x10,0x20,0x00,0x00,0x00},
232
233/* 0x5D ']' */
234{0x00,0x41,0x41,0x7F,0x00,0x00,0x00,0x00},
235
236/* 0x5E '^' */
237{0x04,0x02,0x01,0x02,0x04,0x00,0x00,0x00},
238
239/* 0x5F '_' */
240{0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00},
241
242/* 0x60 '`' */
243{0x00,0x01,0x02,0x04,0x00,0x00,0x00,0x00},
244
245/* 0x61 'a' */
246{0x00,0x20,0x54,0x54,0x54,0x54,0x78,0x00},
247
248/* 0x62 'b' */
249{0x00,0x7F,0x48,0x48,0x48,0x48,0x30,0x00},
250
251/* 0x63 'c' */
252{0x00,0x38,0x44,0x44,0x44,0x44,0x28,0x00},
253
254/* 0x64 'd' */
255{0x00,0x30,0x48,0x48,0x48,0x48,0x7F,0x00},
256
257/* 0x65 'e' */
258{0x00,0x38,0x54,0x54,0x54,0x54,0x18,0x00},
259
260/* 0x66 'f' */
261{0x00,0x08,0x7E,0x09,0x01,0x02,0x00,0x00},
262
263/* 0x67 'g' */
264{0x00,0x0C,0x52,0x52,0x52,0x52,0x3E,0x00},
265
266/* 0x68 'h' */
267{0x00,0x7F,0x08,0x08,0x08,0x08,0x70,0x00},
268
269/* 0x69 'i' */
270{0x00,0x00,0x48,0x7A,0x40,0x00,0x00,0x00},
271
272/* 0x6A 'j' */
273{0x00,0x20,0x40,0x48,0x3A,0x00,0x00,0x00},
274
275/* 0x6B 'k' */
276{0x00,0x7F,0x10,0x28,0x44,0x00,0x00,0x00},
277
278/* 0x6C 'l' */
279{0x00,0x41,0x7F,0x40,0x00,0x00,0x00,0x00},
280
281/* 0x6D 'm' */
282{0x00,0x7C,0x04,0x18,0x04,0x78,0x00,0x00},
283
284/* 0x6E 'n' */
285{0x00,0x7C,0x08,0x04,0x04,0x78,0x00,0x00},
286
287/* 0x6F 'o' */
288{0x00,0x38,0x44,0x44,0x44,0x44,0x38,0x00},
289
290/* 0x70 'p' */
291{0x00,0x7E,0x12,0x12,0x12,0x12,0x0C,0x00},
292
293/* 0x71 'q' */
294{0x00,0x0C,0x12,0x12,0x12,0x12,0x7E,0x00},
295
296/* 0x72 'r' */
297{0x00,0x7C,0x08,0x04,0x04,0x08,0x00,0x00},
298
299/* 0x73 's' */
300{0x00,0x48,0x54,0x54,0x54,0x54,0x20,0x00},
301
302/* 0x74 't' */
303{0x00,0x04,0x3F,0x44,0x40,0x20,0x00,0x00},
304
305/* 0x75 'u' */
306{0x00,0x3C,0x40,0x40,0x40,0x20,0x7C,0x00},
307
308/* 0x76 'v' */
309{0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00},
310
311/* 0x77 'w' */
312{0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00},
313
314/* 0x78 'x' */
315{0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00},
316
317/* 0x79 'y' */
318{0x00,0x0C,0x50,0x50,0x50,0x50,0x3C,0x00},
319
320/* 0x7A 'z' */
321{0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00},
322
323/* 0x7B '{' */
324{0x00,0x08,0x36,0x41,0x00,0x00,0x00,0x00},
325
326/* 0x7C '|' */
327{0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00},
328
329/* 0x7D '}' */
330{0x00,0x41,0x36,0x08,0x00,0x00,0x00,0x00},
331
332/* 0x7E '~' */
333{0x10,0x08,0x08,0x10,0x08,0x08,0x00,0x00}
334
335};

◆ internal_state

struct internal_state_s internal_state
static

Singleton instance of the SSD1309 subsystem internal state.

Definition at line 406 of file ssd1309.c.

◆ ssd1309_cmds

CMD_INFO_ts ssd1309_cmds[]
static

Table of CLI commands registered by the SSD1309 subsystem.

Registered with the command subsystem via ssd1309_cmd_client_info during ssd1309_init_subsys.

Definition at line 425 of file ssd1309.c.

425 {
426 {
427 .name = "start",
428 .help = "Starts the module, usage: ssd1309 start",
430 },
431 {
432 .name = "stop",
433 .help = "Stops the module, usage: ssd1309 stop",
434 .handler = ssd1309_cmd_stop_handler
435 },
436 {
437 .name = "fillrect",
438 .help = "Fills a rectangle, usage: ssd1309 fillrect <x1,y1,x2,y2>",
440 },
441 {
442 .name = "clearrect",
443 .help = "Clears a rectangle, usage: ssd1309 clearrect <x1,y1,x2,y2>",
445 },
446 {
447 .name = "invertrect",
448 .help = "Inverts the pixels of a rectangle, usage: ssd1309 invertrect <x1,y1,x2,y2>",
450 },
451 {
452 .name = "drawtext",
453 .help = "Draws text in a line, usage: ssd1309 drawtext <text> <line>",
455 },
456 {
457 .name = "clearline",
458 .help = "Clears a line, usage: ssd1309 clearline <line>",
460 },
461 {
462 .name = "invertline",
463 .help = "Inverts a line, usage: ssd1309 invertline <line>",
465 }
466};
static ERR_te ssd1309_cmd_clearline_handler(uint32_t argc, char **argv)
CLI handler for the "clearline" command. Clears a line and updates the display.
Definition ssd1309.c:1407
static ERR_te ssd1309_cmd_fillrect_handler(uint32_t argc, char **argv)
CLI handler for the "fillrect" command. Fills a rectangle and updates the display.
Definition ssd1309.c:1172
static ERR_te ssd1309_cmd_start_handler(uint32_t argc, char **argv)
CLI handler for the "start" command. Starts the SSD1309 subsystem at runtime.
Definition ssd1309.c:1111
static ERR_te ssd1309_cmd_invertline_handler(uint32_t argc, char **argv)
CLI handler for the "invertline" command. Inverts a line and updates the display.
Definition ssd1309.c:1455
static ERR_te ssd1309_cmd_drawtext_handler(uint32_t argc, char **argv)
CLI handler for the "drawtext" command. Draws text on a line and updates the display.
Definition ssd1309.c:1359
static ERR_te ssd1309_cmd_invertrect_handler(uint32_t argc, char **argv)
CLI handler for the "invertrect" command. Inverts a rectangle and updates the display.
Definition ssd1309.c:1296
static ERR_te ssd1309_cmd_stop_handler(uint32_t argc, char **argv)
CLI handler for the "stop" command. Stops the SSD1309 subsystem at runtime.
Definition ssd1309.c:1140
static ERR_te ssd1309_cmd_clearrect_handler(uint32_t argc, char **argv)
CLI handler for the "clearrect" command. Clears a rectangle and updates the display.
Definition ssd1309.c:1234

◆ ssd1309_cmd_client_info

CMD_CLIENT_INFO_ts ssd1309_cmd_client_info
static
Initial value:
= {
.cmds_ptr = ssd1309_cmds,
.num_cmds = sizeof(ssd1309_cmds) / sizeof(ssd1309_cmds[0]),
.name = "ssd1309",
.log_level_ptr = &internal_state.log_level
}
static struct internal_state_s internal_state
Singleton instance of the SysTick driver internal state.
static CMD_INFO_ts ssd1309_cmds[]
Table of CLI commands registered by the SSD1309 subsystem.
Definition ssd1309.c:425

Registration descriptor passed to the command subsystem.

Bundles the command table, its size, the subsystem name prefix used on the CLI, and a pointer to the runtime log-level variable.

Definition at line 475 of file ssd1309.c.

475 {
476 .cmds_ptr = ssd1309_cmds,
477 .num_cmds = sizeof(ssd1309_cmds) / sizeof(ssd1309_cmds[0]),
478 .name = "ssd1309",
479 .log_level_ptr = &internal_state.log_level
480};