-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssd1306.c
589 lines (495 loc) · 16.4 KB
/
ssd1306.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
#include "ssd1306.h"
#include <math.h>
#include <stdlib.h>
#include <string.h> // For memcpy
#if defined(SSD1306_USE_I2C)
void ssd1306_InitPheripheral(void) {
// TODO
}
void ssd1306_Reset(void) {
/* for I2C - do nothing */
}
// Send a byte to the command register
void ssd1306_WriteCommand(uint8_t byte) {
// TODO
}
// Send data
void ssd1306_WriteData(uint8_t* buffer, size_t buff_size) {
// TODO
}
#elif defined(SSD1306_USE_SPI)
void ssd1306_InitPheripheral(void) {
// initialize GPIO
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pin = OLED_CS_Pin;
LL_GPIO_Init(OLED_CS_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = OLED_DC_Pin;
LL_GPIO_Init(OLED_DC_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = OLED_RES_Pin;
LL_GPIO_Init(OLED_RES_GPIO_Port, &GPIO_InitStruct);
// initialize GPIO for SPI
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pin = OLED_CLK_Pin;
LL_GPIO_Init(OLED_CLK_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = OLED_MOSI_Pin;
LL_GPIO_Init(OLED_MOSI_GPIO_Port, &GPIO_InitStruct);
// initialize SPI
LL_SPI_InitTypeDef SPI_InitStruct = {0};
SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX;
SPI_InitStruct.Mode = LL_SPI_MODE_MASTER;
SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT;
SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW;
SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE;
SPI_InitStruct.NSS = LL_SPI_NSS_SOFT;
SPI_InitStruct.BaudRate = SSD1306_SPI_BAUDRATEPRESCALER;
SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST;
SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
LL_SPI_Init(SSD1306_SPI_PORT, &SPI_InitStruct);
// enable SPI
LL_SPI_Enable(SSD1306_SPI_PORT);
}
void ssd1306_Reset(void) {
// CS = High (not selected)
LL_GPIO_SetOutputPin(SSD1306_CS_Port, SSD1306_CS_Pin);
// Reset the OLED
LL_GPIO_ResetOutputPin(SSD1306_RES_Port, SSD1306_RES_Pin);
LL_mDelay(10);
LL_GPIO_SetOutputPin(SSD1306_RES_Port, SSD1306_RES_Pin);
LL_mDelay(10);
}
// Send a byte to the command register
void ssd1306_WriteCommand(uint8_t byte) {
LL_GPIO_ResetOutputPin(SSD1306_CS_Port, SSD1306_CS_Pin); // select OLED
LL_GPIO_ResetOutputPin(SSD1306_DC_Port, SSD1306_DC_Pin); // command
LL_SPI_TransmitData8(SSD1306_SPI_PORT, byte);
while (!LL_SPI_IsActiveFlag_TXE(SSD1306_SPI_PORT)) {
}
while (LL_SPI_IsActiveFlag_BSY(SSD1306_SPI_PORT)) {
}
LL_GPIO_SetOutputPin(SSD1306_CS_Port, SSD1306_CS_Pin); // un-select OLED
}
// Send data
void ssd1306_WriteData(uint8_t* buffer, size_t buff_size) {
LL_GPIO_ResetOutputPin(SSD1306_CS_Port, SSD1306_CS_Pin); // select OLED
LL_GPIO_SetOutputPin(SSD1306_DC_Port, SSD1306_DC_Pin); // data
for (size_t i = 0; i < buff_size; i++) {
LL_SPI_TransmitData8(SSD1306_SPI_PORT, buffer[i]);
while (!LL_SPI_IsActiveFlag_TXE(SSD1306_SPI_PORT)) {
}
}
while (LL_SPI_IsActiveFlag_BSY(SSD1306_SPI_PORT)) {
}
LL_GPIO_SetOutputPin(SSD1306_CS_Port, SSD1306_CS_Pin); // un-select OLED
}
#elif defined(SSD1306_USE_EMULATED_SPI)
void ssd1306_InitPheripheral(void) {
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pin = OLED_CLK_Pin;
LL_GPIO_Init(OLED_CLK_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = OLED_MOSI_Pin;
LL_GPIO_Init(OLED_MOSI_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = OLED_CS_Pin;
LL_GPIO_Init(OLED_CS_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = OLED_DC_Pin;
LL_GPIO_Init(OLED_DC_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = OLED_RES_Pin;
LL_GPIO_Init(OLED_RES_GPIO_Port, &GPIO_InitStruct);
}
void ssd1306_Reset(void) {
// CLK = High (idle)
LL_GPIO_SetOutputPin(SSD1306_CLK_Port, SSD1306_CLK_Pin);
// CS = High (not selected)
LL_GPIO_SetOutputPin(SSD1306_CS_Port, SSD1306_CS_Pin);
// Reset the OLED
LL_GPIO_ResetOutputPin(SSD1306_RES_Port, SSD1306_RES_Pin);
LL_mDelay(10);
LL_GPIO_SetOutputPin(SSD1306_RES_Port, SSD1306_RES_Pin);
LL_mDelay(10);
}
static void spi_emulate_transmit(uint8_t byte) {
for (uint8_t i = 0; i < 8; i++) {
LL_GPIO_ResetOutputPin(SSD1306_CLK_Port, SSD1306_CLK_Pin);
if (byte & 0x80)
LL_GPIO_SetOutputPin(SSD1306_MOSI_Port, SSD1306_MOSI_Pin);
else
LL_GPIO_ResetOutputPin(SSD1306_MOSI_Port, SSD1306_MOSI_Pin);
LL_GPIO_SetOutputPin(SSD1306_CLK_Port, SSD1306_CLK_Pin);
byte <<= 1;
}
}
// Send a byte to the command register
void ssd1306_WriteCommand(uint8_t byte) {
LL_GPIO_ResetOutputPin(SSD1306_CS_Port, SSD1306_CS_Pin); // select OLED
LL_GPIO_ResetOutputPin(SSD1306_DC_Port, SSD1306_DC_Pin); // command
spi_emulate_transmit(byte);
LL_GPIO_SetOutputPin(SSD1306_CS_Port, SSD1306_CS_Pin); // un-select OLED
}
// Send data
void ssd1306_WriteData(uint8_t* buffer, size_t buff_size) {
LL_GPIO_ResetOutputPin(SSD1306_CS_Port, SSD1306_CS_Pin); // select OLED
LL_GPIO_SetOutputPin(SSD1306_DC_Port, SSD1306_DC_Pin); // data
for (size_t i = 0; i < buff_size; i++)
spi_emulate_transmit(buffer[i]);
LL_GPIO_SetOutputPin(SSD1306_CS_Port, SSD1306_CS_Pin); // un-select OLED
}
#else
#error "You should define SSD1306_USE_SPI or SSD1306_USE_I2C or SSD1306_USE_EMULATED_I2C macro"
#endif
// Screenbuffer
static uint8_t SSD1306_Buffer[SSD1306_BUFFER_SIZE];
// Screen object
static SSD1306_t SSD1306;
/* Fills the Screenbuffer with values from a given buffer of a fixed length */
SSD1306_Error_t ssd1306_FillBuffer(uint8_t* buf, uint32_t len) {
SSD1306_Error_t ret = SSD1306_ERR;
if (len <= SSD1306_BUFFER_SIZE) {
memcpy(SSD1306_Buffer, buf, len);
ret = SSD1306_OK;
}
return ret;
}
// Initialize the oled screen
void ssd1306_Init(void) {
// Init peripheral
ssd1306_InitPheripheral();
// Reset OLED
ssd1306_Reset();
// Wait for the screen to boot
LL_mDelay(100);
// Init OLED
ssd1306_SetDisplayOn(0); // display off
ssd1306_WriteCommand(0x20); // Set Memory Addressing Mode
ssd1306_WriteCommand(0x00); // 00b,Horizontal Addressing Mode; 01b,Vertical Addressing Mode;
// 10b,Page Addressing Mode (RESET); 11b,Invalid
ssd1306_WriteCommand(0xB0); // Set Page Start Address for Page Addressing Mode,0-7
#ifdef SSD1306_MIRROR_VERT
ssd1306_WriteCommand(0xC0); // Mirror vertically
#else
ssd1306_WriteCommand(0xC8); // Set COM Output Scan Direction
#endif
ssd1306_WriteCommand(0x00); //---set low column address
ssd1306_WriteCommand(0x10); //---set high column address
ssd1306_WriteCommand(0x40); //--set start line address - CHECK
ssd1306_SetContrast(0xFF);
#ifdef SSD1306_MIRROR_HORIZ
ssd1306_WriteCommand(0xA0); // Mirror horizontally
#else
ssd1306_WriteCommand(0xA1); //--set segment re-map 0 to 127 - CHECK
#endif
#ifdef SSD1306_INVERSE_COLOR
ssd1306_WriteCommand(0xA7); //--set inverse color
#else
ssd1306_WriteCommand(0xA6); //--set normal color
#endif
// Set multiplex ratio.
#if (SSD1306_HEIGHT == 128)
// Found in the Luma Python lib for SH1106.
ssd1306_WriteCommand(0xFF);
#else
ssd1306_WriteCommand(0xA8); //--set multiplex ratio(1 to 64) - CHECK
#endif
#if (SSD1306_HEIGHT == 32)
ssd1306_WriteCommand(0x1F); //
#elif (SSD1306_HEIGHT == 64)
ssd1306_WriteCommand(0x3F); //
#elif (SSD1306_HEIGHT == 128)
ssd1306_WriteCommand(0x3F); // Seems to work for 128px high displays too.
#else
#error "Only 32, 64, or 128 lines of height are supported!"
#endif
ssd1306_WriteCommand(0xA4); // 0xa4,Output follows RAM content;0xa5,Output ignores RAM content
ssd1306_WriteCommand(0xD3); //-set display offset - CHECK
ssd1306_WriteCommand(0x00); //-not offset
ssd1306_WriteCommand(0xD5); //--set display clock divide ratio/oscillator frequency
ssd1306_WriteCommand(0xF0); //--set divide ratio
ssd1306_WriteCommand(0xD9); //--set pre-charge period
ssd1306_WriteCommand(0x22); //
ssd1306_WriteCommand(0xDA); //--set com pins hardware configuration - CHECK
#if (SSD1306_HEIGHT == 32)
ssd1306_WriteCommand(0x02);
#elif (SSD1306_HEIGHT == 64)
ssd1306_WriteCommand(0x12);
#elif (SSD1306_HEIGHT == 128)
ssd1306_WriteCommand(0x12);
#else
#error "Only 32, 64, or 128 lines of height are supported!"
#endif
ssd1306_WriteCommand(0xDB); //--set vcomh
ssd1306_WriteCommand(0x20); // 0x20,0.77xVcc
ssd1306_WriteCommand(0x8D); //--set DC-DC enable
ssd1306_WriteCommand(0x14); //
ssd1306_SetDisplayOn(1); //--turn on SSD1306 panel
// Clear screen
ssd1306_Fill(Black);
// Flush buffer to screen
ssd1306_UpdateScreen();
// Set default values for screen object
SSD1306.CurrentX = 0;
SSD1306.CurrentY = 0;
SSD1306.Initialized = 1;
}
// Fill the whole screen with the given color
void ssd1306_Fill(SSD1306_COLOR color) {
/* Set memory */
uint32_t i;
for (i = 0; i < sizeof(SSD1306_Buffer); i++) {
SSD1306_Buffer[i] = (color == Black) ? 0x00 : 0xFF;
}
}
// Write the screenbuffer with changed to the screen
void ssd1306_UpdateScreen(void) {
// Write data to each page of RAM. Number of pages
// depends on the screen height:
//
// * 32px == 4 pages
// * 64px == 8 pages
// * 128px == 16 pages
for (uint8_t i = 0; i < SSD1306_HEIGHT / 8; i++) {
ssd1306_WriteCommand(0xB0 + i); // Set the current RAM page address.
ssd1306_WriteCommand(0x00 + SSD1306_X_OFFSET_LOWER);
ssd1306_WriteCommand(0x10 + SSD1306_X_OFFSET_UPPER);
ssd1306_WriteData(&SSD1306_Buffer[SSD1306_WIDTH * i], SSD1306_WIDTH);
}
}
// Draw one pixel in the screenbuffer
// X => X Coordinate
// Y => Y Coordinate
// color => Pixel color
void ssd1306_DrawPixel(uint8_t x, uint8_t y, SSD1306_COLOR color) {
if (x >= SSD1306_WIDTH || y >= SSD1306_HEIGHT) {
// Don't write outside the buffer
return;
}
// Draw in the right color
if (color == White) {
SSD1306_Buffer[x + (y / 8) * SSD1306_WIDTH] |= 1 << (y % 8);
} else {
SSD1306_Buffer[x + (y / 8) * SSD1306_WIDTH] &= ~(1 << (y % 8));
}
}
// Draw 1 char to the screen buffer
// ch => char om weg te schrijven
// Font => Font waarmee we gaan schrijven
// color => Black or White
char ssd1306_WriteChar(char ch, FontDef Font, SSD1306_COLOR color) {
uint32_t i, b, j;
// Check if character is valid
if (ch < 32 || ch > 126)
return 0;
// Check remaining space on current line
if (SSD1306_WIDTH < (SSD1306.CurrentX + Font.FontWidth) ||
SSD1306_HEIGHT < (SSD1306.CurrentY + Font.FontHeight)) {
// Not enough space on current line
return 0;
}
// Use the font to write
for (i = 0; i < Font.FontHeight; i++) {
b = Font.data[(ch - 32) * Font.FontHeight + i];
for (j = 0; j < Font.FontWidth; j++) {
if ((b << j) & 0x8000) {
ssd1306_DrawPixel(SSD1306.CurrentX + j, (SSD1306.CurrentY + i), (SSD1306_COLOR)color);
} else {
ssd1306_DrawPixel(SSD1306.CurrentX + j, (SSD1306.CurrentY + i), (SSD1306_COLOR)!color);
}
}
}
// The current space is now taken
SSD1306.CurrentX += Font.FontWidth;
// Return written char for validation
return ch;
}
// Write full string to screenbuffer
char ssd1306_WriteString(char* str, FontDef Font, SSD1306_COLOR color) {
// Write until null-byte
while (*str) {
if (ssd1306_WriteChar(*str, Font, color) != *str) {
// Char could not be written
return *str;
}
// Next char
str++;
}
// Everything ok
return *str;
}
// Position the cursor
void ssd1306_SetCursor(uint8_t x, uint8_t y) {
SSD1306.CurrentX = x;
SSD1306.CurrentY = y;
}
// Draw line by Bresenhem's algorithm
void ssd1306_Line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, SSD1306_COLOR color) {
int32_t deltaX = abs(x2 - x1);
int32_t deltaY = abs(y2 - y1);
int32_t signX = ((x1 < x2) ? 1 : -1);
int32_t signY = ((y1 < y2) ? 1 : -1);
int32_t error = deltaX - deltaY;
int32_t error2;
ssd1306_DrawPixel(x2, y2, color);
while ((x1 != x2) || (y1 != y2)) {
ssd1306_DrawPixel(x1, y1, color);
error2 = error * 2;
if (error2 > -deltaY) {
error -= deltaY;
x1 += signX;
} else {
/*nothing to do*/
}
if (error2 < deltaX) {
error += deltaX;
y1 += signY;
} else {
/*nothing to do*/
}
}
return;
}
// Draw polyline
void ssd1306_Polyline(const SSD1306_VERTEX* par_vertex, uint16_t par_size, SSD1306_COLOR color) {
uint16_t i;
if (par_vertex != 0) {
for (i = 1; i < par_size; i++) {
ssd1306_Line(par_vertex[i - 1].x, par_vertex[i - 1].y, par_vertex[i].x, par_vertex[i].y, color);
}
} else {
/*nothing to do*/
}
return;
}
/*Convert Degrees to Radians*/
static float ssd1306_DegToRad(float par_deg) {
return par_deg * 3.14 / 180.0;
}
/*Normalize degree to [0;360]*/
static uint16_t ssd1306_NormalizeTo0_360(uint16_t par_deg) {
uint16_t loc_angle;
if (par_deg <= 360) {
loc_angle = par_deg;
} else {
loc_angle = par_deg % 360;
loc_angle = ((par_deg != 0) ? par_deg : 360);
}
return loc_angle;
}
/*DrawArc. Draw angle is beginning from 4 quart of trigonometric circle (3pi/2)
* start_angle in degree
* sweep in degree
*/
void ssd1306_DrawArc(uint8_t x, uint8_t y, uint8_t radius, uint16_t start_angle, uint16_t sweep, SSD1306_COLOR color) {
#define CIRCLE_APPROXIMATION_SEGMENTS 36
float approx_degree;
uint32_t approx_segments;
uint8_t xp1, xp2;
uint8_t yp1, yp2;
uint32_t count = 0;
uint32_t loc_sweep = 0;
float rad;
loc_sweep = ssd1306_NormalizeTo0_360(sweep);
count = (ssd1306_NormalizeTo0_360(start_angle) * CIRCLE_APPROXIMATION_SEGMENTS) / 360;
approx_segments = (loc_sweep * CIRCLE_APPROXIMATION_SEGMENTS) / 360;
approx_degree = loc_sweep / (float)approx_segments;
while (count < approx_segments) {
rad = ssd1306_DegToRad(count * approx_degree);
xp1 = x + (int8_t)(sin(rad) * radius);
yp1 = y + (int8_t)(cos(rad) * radius);
count++;
if (count != approx_segments) {
rad = ssd1306_DegToRad(count * approx_degree);
} else {
rad = ssd1306_DegToRad(loc_sweep);
}
xp2 = x + (int8_t)(sin(rad) * radius);
yp2 = y + (int8_t)(cos(rad) * radius);
ssd1306_Line(xp1, yp1, xp2, yp2, color);
}
return;
}
// Draw circle by Bresenhem's algorithm
void ssd1306_DrawCircle(uint8_t par_x, uint8_t par_y, uint8_t par_r, SSD1306_COLOR par_color) {
int32_t x = -par_r;
int32_t y = 0;
int32_t err = 2 - 2 * par_r;
int32_t e2;
if (par_x >= SSD1306_WIDTH || par_y >= SSD1306_HEIGHT) {
return;
}
do {
ssd1306_DrawPixel(par_x - x, par_y + y, par_color);
ssd1306_DrawPixel(par_x + x, par_y + y, par_color);
ssd1306_DrawPixel(par_x + x, par_y - y, par_color);
ssd1306_DrawPixel(par_x - x, par_y - y, par_color);
e2 = err;
if (e2 <= y) {
y++;
err = err + (y * 2 + 1);
if (-x == y && e2 <= x) {
e2 = 0;
} else {
/*nothing to do*/
}
} else {
/*nothing to do*/
}
if (e2 > x) {
x++;
err = err + (x * 2 + 1);
} else {
/*nothing to do*/
}
} while (x <= 0);
return;
}
// Draw rectangle
void ssd1306_DrawRectangle(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, SSD1306_COLOR color) {
ssd1306_Line(x1, y1, x2, y1, color);
ssd1306_Line(x2, y1, x2, y2, color);
ssd1306_Line(x2, y2, x1, y2, color);
ssd1306_Line(x1, y2, x1, y1, color);
return;
}
// Draw bitmap - ported from the ADAFruit GFX library
void ssd1306_DrawBitmap(uint8_t x, uint8_t y, const unsigned char* bitmap, uint8_t w, uint8_t h, SSD1306_COLOR color) {
int16_t byteWidth = (w + 7) / 8; // Bitmap scanline pad = whole byte
uint8_t byte = 0;
if (x >= SSD1306_WIDTH || y >= SSD1306_HEIGHT) {
return;
}
for (uint8_t j = 0; j < h; j++, y++) {
for (uint8_t i = 0; i < w; i++) {
if (i & 7)
byte <<= 1;
else
byte = (*(const unsigned char*)(&bitmap[j * byteWidth + i / 8]));
if (byte & 0x80)
ssd1306_DrawPixel(x + i, y, color);
}
}
return;
}
void ssd1306_SetContrast(const uint8_t value) {
const uint8_t kSetContrastControlRegister = 0x81;
ssd1306_WriteCommand(kSetContrastControlRegister);
ssd1306_WriteCommand(value);
}
void ssd1306_SetDisplayOn(const uint8_t on) {
uint8_t value;
if (on) {
value = 0xAF; // Display on
SSD1306.DisplayOn = 1;
} else {
value = 0xAE; // Display off
SSD1306.DisplayOn = 0;
}
ssd1306_WriteCommand(value);
}
uint8_t ssd1306_GetDisplayOn() {
return SSD1306.DisplayOn;
}