Skip to content

Commit 085d5ac

Browse files
authored
Fix ssd1306 font in ssd1306_i2c example (#404)
* Fix ssd1306 font in ssd1306_i2c example * Remove comment
1 parent eca13ac commit 085d5ac

File tree

2 files changed

+42
-59
lines changed

2 files changed

+42
-59
lines changed

i2c/ssd1306_i2c/ssd1306_font.h

+37-37
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,41 @@
88
// Theses are defined vertically to make them quick to copy to FB
99

1010
static uint8_t font[] = {
11-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Nothing
12-
0x1e, 0x28, 0x48, 0x88, 0x48, 0x28, 0x1e, 0x00, //A
13-
0xfe, 0x92, 0x92, 0x92, 0x92, 0x92, 0xfe, 0x00, //B
14-
0x7e, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x00, //C
15-
0xfe, 0x82, 0x82, 0x82, 0x82, 0x82, 0x7e, 0x00, //D
16-
0xfe, 0x92, 0x92, 0x92, 0x92, 0x92, 0x92, 0x00, //E
17-
0xfe, 0x90, 0x90, 0x90, 0x90, 0x80, 0x80, 0x00, //F
18-
0xfe, 0x82, 0x82, 0x82, 0x8a, 0x8a, 0xce, 0x00, //G
19-
0xfe, 0x10, 0x10, 0x10, 0x10, 0x10, 0xfe, 0x00, //H
20-
0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, //I
21-
0x84, 0x82, 0x82, 0xfc, 0x80, 0x80, 0x80, 0x00, //J
22-
0x00, 0xfe, 0x10, 0x10, 0x28, 0x44, 0x82, 0x00, //K
23-
0xfe, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, //L
24-
0xfe, 0x40, 0x20, 0x10, 0x20, 0x40, 0xfe, 0x00, //M
25-
0xfe, 0x40, 0x20, 0x10, 0x08, 0x04, 0xfe, 0x00, //N
26-
0x7c, 0x82, 0x82, 0x82, 0x82, 0x82, 0x7c, 0x00, //O
27-
0xfe, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, //P
28-
0x7c, 0x82, 0x82, 0x92, 0x8a, 0x86, 0x7e, 0x00, //Q
29-
0xfe, 0x88, 0x88, 0x88, 0x8c, 0x8a, 0x70, 0x00, //R
30-
0x62, 0x92, 0x92, 0x92, 0x92, 0x0c, 0x00, 0x00, //S
31-
0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x00, //T
32-
0xfc, 0x02, 0x02, 0x02, 0x02, 0x02, 0xfc, 0x00, //U
33-
0xf0, 0x08, 0x04, 0x02, 0x04, 0x08, 0xf0, 0x00, //V
34-
0xfe, 0x04, 0x08, 0x10, 0x08, 0x04, 0xfe, 0x00, //W
35-
0x00, 0x82, 0x44, 0x28, 0x28, 0x44, 0x82, 0x00, //X
36-
0x80, 0x40, 0x20, 0x1e, 0x20, 0x40, 0x80, 0x00, //Y
37-
0x82, 0x86, 0x9a, 0xa2, 0xc2, 0x82, 0x00, 0x00, //Z
38-
0x7c, 0x82, 0x82, 0x92, 0x82, 0x82, 0x7c, 0x00, //0
39-
0x00, 0x00, 0x42, 0xfe, 0x02, 0x00, 0x00, 0x00, //1
40-
0x0c, 0x92, 0x92, 0x92, 0x92, 0x62, 0x00, 0x00, //2
41-
0x92, 0x92, 0x92, 0x92, 0x92, 0x92, 0x6c, 0x00, //3
42-
0xfc, 0x04, 0x04, 0x1e, 0x04, 0x04, 0x00, 0x00, //4
43-
0xf2, 0x92, 0x92, 0x92, 0x92, 0x0c, 0x00, 0x00, //5
44-
0xfc, 0x12, 0x12, 0x12, 0x12, 0x12, 0x0c, 0x00, //6
45-
0x80, 0x80, 0x80, 0x86, 0x8c, 0xb0, 0xc0, 0x00, //7
46-
0x6c, 0x92, 0x92, 0x92, 0x92, 0x92, 0x6c, 0x00, //8
47-
0x60, 0x90, 0x90, 0x90, 0x90, 0x90, 0xfe, 0x00, //9
11+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Nothing
12+
0x78, 0x14, 0x12, 0x11, 0x12, 0x14, 0x78, 0x00, //A
13+
0x7f, 0x49, 0x49, 0x49, 0x49, 0x49, 0x7f, 0x00, //B
14+
0x7e, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x00, //C
15+
0x7f, 0x41, 0x41, 0x41, 0x41, 0x41, 0x7e, 0x00, //D
16+
0x7f, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x00, //E
17+
0x7f, 0x09, 0x09, 0x09, 0x09, 0x01, 0x01, 0x00, //F
18+
0x7f, 0x41, 0x41, 0x41, 0x51, 0x51, 0x73, 0x00, //G
19+
0x7f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x7f, 0x00, //H
20+
0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, //I
21+
0x21, 0x41, 0x41, 0x3f, 0x01, 0x01, 0x01, 0x00, //J
22+
0x00, 0x7f, 0x08, 0x08, 0x14, 0x22, 0x41, 0x00, //K
23+
0x7f, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, //L
24+
0x7f, 0x02, 0x04, 0x08, 0x04, 0x02, 0x7f, 0x00, //M
25+
0x7f, 0x02, 0x04, 0x08, 0x10, 0x20, 0x7f, 0x00, //N
26+
0x3e, 0x41, 0x41, 0x41, 0x41, 0x41, 0x3e, 0x00, //O
27+
0x7f, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0e, 0x00, //P
28+
0x3e, 0x41, 0x41, 0x49, 0x51, 0x61, 0x7e, 0x00, //Q
29+
0x7f, 0x11, 0x11, 0x11, 0x31, 0x51, 0x0e, 0x00, //R
30+
0x46, 0x49, 0x49, 0x49, 0x49, 0x30, 0x00, 0x00, //S
31+
0x01, 0x01, 0x01, 0x7f, 0x01, 0x01, 0x01, 0x00, //T
32+
0x3f, 0x40, 0x40, 0x40, 0x40, 0x40, 0x3f, 0x00, //U
33+
0x0f, 0x10, 0x20, 0x40, 0x20, 0x10, 0x0f, 0x00, //V
34+
0x7f, 0x20, 0x10, 0x08, 0x10, 0x20, 0x7f, 0x00, //W
35+
0x00, 0x41, 0x22, 0x14, 0x14, 0x22, 0x41, 0x00, //X
36+
0x01, 0x02, 0x04, 0x78, 0x04, 0x02, 0x01, 0x00, //Y
37+
0x41, 0x61, 0x59, 0x45, 0x43, 0x41, 0x00, 0x00, //Z
38+
0x3e, 0x41, 0x41, 0x49, 0x41, 0x41, 0x3e, 0x00, //0
39+
0x00, 0x00, 0x42, 0x7f, 0x40, 0x00, 0x00, 0x00, //1
40+
0x30, 0x49, 0x49, 0x49, 0x49, 0x46, 0x00, 0x00, //2
41+
0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x36, 0x00, //3
42+
0x3f, 0x20, 0x20, 0x78, 0x20, 0x20, 0x00, 0x00, //4
43+
0x4f, 0x49, 0x49, 0x49, 0x49, 0x30, 0x00, 0x00, //5
44+
0x3f, 0x48, 0x48, 0x48, 0x48, 0x48, 0x30, 0x00, //6
45+
0x01, 0x01, 0x01, 0x61, 0x31, 0x0d, 0x03, 0x00, //7
46+
0x36, 0x49, 0x49, 0x49, 0x49, 0x49, 0x36, 0x00, //8
47+
0x06, 0x09, 0x09, 0x09, 0x09, 0x09, 0x7f, 0x00, //9
4848
};

i2c/ssd1306_i2c/ssd1306_i2c.c

+5-22
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ void SSD1306_init() {
151151
SSD1306_SET_COM_OUT_DIR | 0x08, // set COM (common) output scan direction. Scan from bottom up, COM[N-1] to COM0
152152
SSD1306_SET_DISP_OFFSET, // set display offset
153153
0x00, // no offset
154-
SSD1306_SET_COM_PIN_CFG, // set COM (common) pins hardware configuration. Board specific magic number.
154+
SSD1306_SET_COM_PIN_CFG, // set COM (common) pins hardware configuration. Board specific magic number.
155155
// 0x02 Works for 128x32, 0x12 Possibly works for 128x64. Other options 0x22, 0x32
156156
#if ((SSD1306_WIDTH == 128) && (SSD1306_HEIGHT == 32))
157-
0x02,
157+
0x02,
158158
#elif ((SSD1306_WIDTH == 128) && (SSD1306_HEIGHT == 64))
159159
0x12,
160160
#else
@@ -207,7 +207,7 @@ void render(uint8_t *buf, struct render_area *area) {
207207
area->start_page,
208208
area->end_page
209209
};
210-
210+
211211
SSD1306_send_cmd_list(cmds, count_of(cmds));
212212
SSD1306_send_buf(buf, area->buflen);
213213
}
@@ -274,24 +274,7 @@ static inline int GetFontIndex(uint8_t ch) {
274274
else return 0; // Not got that char so space.
275275
}
276276

277-
static uint8_t reversed[sizeof(font)] = {0};
278-
279-
static uint8_t reverse(uint8_t b) {
280-
b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
281-
b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
282-
b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
283-
return b;
284-
}
285-
static void FillReversedCache() {
286-
// calculate and cache a reversed version of fhe font, because I defined it upside down...doh!
287-
for (int i=0;i<sizeof(font);i++)
288-
reversed[i] = reverse(font[i]);
289-
}
290-
291277
static void WriteChar(uint8_t *buf, int16_t x, int16_t y, uint8_t ch) {
292-
if (reversed[0] == 0)
293-
FillReversedCache();
294-
295278
if (x > SSD1306_WIDTH - 8 || y > SSD1306_HEIGHT - 8)
296279
return;
297280

@@ -303,7 +286,7 @@ static void WriteChar(uint8_t *buf, int16_t x, int16_t y, uint8_t ch) {
303286
int fb_idx = y * 128 + x;
304287

305288
for (int i=0;i<8;i++) {
306-
buf[fb_idx++] = reversed[idx * 8 + i];
289+
buf[fb_idx++] = font[idx * 8 + i];
307290
}
308291
}
309292

@@ -381,7 +364,7 @@ int main() {
381364
area.end_col = IMG_WIDTH - 1;
382365

383366
calc_render_area_buflen(&area);
384-
367+
385368
uint8_t offset = 5 + IMG_WIDTH; // 5px padding
386369

387370
for (int i = 0; i < 3; i++) {

0 commit comments

Comments
 (0)