-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathssd1306.cc
786 lines (653 loc) · 18.7 KB
/
ssd1306.cc
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
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
//---------------------------------------------------------------------------
#include "ssd1306.h"
#include "javelin/button_script_manager.h"
#include "javelin/clock.h"
#include "javelin/console.h"
#include "javelin/font/monochrome/font.h"
#include "javelin/hal/display.h"
#include "javelin/utf8_pointer.h"
#include "rp2040_dma.h"
#include <hardware/gpio.h>
#include <hardware/i2c.h>
#include <string.h>
//---------------------------------------------------------------------------
#if JAVELIN_DISPLAY_DRIVER == 1306
//---------------------------------------------------------------------------
#if JAVELIN_SPLIT
Ssd1306::Ssd1306Data Ssd1306::instances[2];
#else
Ssd1306::Ssd1306Data Ssd1306::instances[1];
#endif
uint16_t Ssd1306::dmaBuffer[JAVELIN_OLED_WIDTH * JAVELIN_OLED_HEIGHT / 8 + 1];
//---------------------------------------------------------------------------
const uint32_t I2C_CLOCK = 400'000;
//---------------------------------------------------------------------------
struct Ssd1306Command {
enum Value : uint8_t {
SET_LOWER_COLUMN_START_ADDRESS = 0x00, // -> 0x0f
SET_HIGHER_COLUMN_START_ADDRESS = 0x10, // -> 0x1f
SET_MEMORY_ADDRESSING_MODE = 0x20,
SET_COLUMN_ADDRESS = 0x21,
SET_PAGE_ADDRESS = 0x22,
SET_DISPLAY_START_LINE = 0x40, // -> 0x7f
SET_CONTRAST = 0x81,
SET_CHARGE_PUMP = 0x8d,
SET_SEGMENT_REMAP_DISABLED = 0xa0,
SET_SEGMENT_REMAP_ENABLED = 0xa1,
SET_FORCE_WHITE_DISABLED = 0xa4,
SET_FORCE_WHITE_ENABLED = 0xa5,
SET_INVERT_DISABLED = 0xa6,
SET_INVERT_ENABLE = 0xa7,
SET_MULTIPLEX_RATIO = 0xa8,
SET_DISPLAY_OFF = 0xae,
SET_DISPLAY_ON = 0xaf,
SET_PAGE_START_ADDRESS = 0xb0, // -> 0xbf
SET_COM_SCAN_DIRECTION_TOP_DOWN = 0xc0,
SET_COM_SCAN_DIRECTION_BOTTOM_UP = 0xc8,
SET_DISPLAY_OFFSET = 0xd3, // Data: offset
SET_DISPLAY_OSCILLATOR_FREQUENCY_CLOCK_DIVIDE_RATIO = 0xd5,
SET_PRECHARGE_PERIOD = 0xd9,
SET_COM_PIN_CONFIGURATION = 0xda,
SET_VCOMH_DESELECT_LEVEL = 0xdb,
};
constexpr static uint8_t EnableDisplay(bool on) {
return on ? SET_DISPLAY_ON : SET_DISPLAY_OFF;
}
constexpr static uint8_t SetDisplayStartLine(uint8_t line) {
return SET_DISPLAY_START_LINE + line;
}
};
struct Ssd1306MemoryAddressingMode {
enum Value : uint8_t {
HORIZONTAL = 0,
VERTICAL = 1,
PAGE = 2,
};
};
//---------------------------------------------------------------------------
bool Ssd1306::SendCommand(uint8_t command) {
uint8_t buffer[2] = {0x80, command};
return i2c_write_blocking(JAVELIN_OLED_I2C, JAVELIN_OLED_I2C_ADDRESS, buffer,
2, false) == 2;
}
bool Ssd1306::SendCommandList(const uint8_t *commands, size_t length) {
for (size_t i = 0; i < length; ++i) {
if (!SendCommand(commands[i])) {
return false;
}
}
return true;
}
void Ssd1306::SendCommandListDma(const uint8_t *commands, size_t length) {
JAVELIN_OLED_I2C->hw->enable = 0;
JAVELIN_OLED_I2C->hw->tar = JAVELIN_OLED_I2C_ADDRESS;
JAVELIN_OLED_I2C->hw->enable = 1;
// Start of data.
uint16_t *d = dmaBuffer;
for (size_t i = 0; i < length; ++i) {
*d++ = 0x80;
*d++ = commands[i] | 0x200;
}
SendDmaBuffer(length * 2);
}
bool Ssd1306::IsI2cTxReady() {
return (JAVELIN_OLED_I2C->hw->raw_intr_stat &
I2C_IC_RAW_INTR_STAT_TX_EMPTY_BITS) != 0;
}
void Ssd1306::WaitForI2cTxReady() {
while (!IsI2cTxReady()) {
// Do nothing.
}
}
void Ssd1306::SendDmaBuffer(size_t count) {
dma4->count = count;
dma4->source = dmaBuffer;
dma4->destination = &JAVELIN_OLED_I2C->hw->data_cmd;
constexpr Rp2040DmaControl dmaControl = {
.enable = true,
.dataSize = Rp2040DmaControl::DataSize::HALF_WORD,
.incrementRead = true,
.incrementWrite = false,
.chainToDma = 4,
.transferRequest = Rp2040DmaTransferRequest::I2C1_TX,
.sniffEnable = false,
};
dma4->controlTrigger = dmaControl;
}
void Ssd1306::PrintInfo() {
#if JAVELIN_SPLIT
Console::Printf("Screen: %s, %s\n",
instances[0].available ? "present" : "not present",
instances[1].available ? "present" : "not present");
#else
Console::Printf("Screen: %s\n",
instances[0].available ? "present" : "not present");
#endif
}
//---------------------------------------------------------------------------
void Ssd1306::Ssd1306Data::SetPixel(uint32_t x, uint32_t y) {
if (x >= JAVELIN_DISPLAY_WIDTH || y >= JAVELIN_DISPLAY_HEIGHT) {
return;
}
const size_t bitIndex = x * JAVELIN_DISPLAY_HEIGHT + y;
uint8_t *p = &buffer8[bitIndex / 8];
if (drawColor) {
*p |= 1 << (bitIndex & 7);
} else {
*p &= ~(1 << (bitIndex & 7));
}
}
void Ssd1306::Ssd1306Data::Clear() {
if (!available) {
return;
}
dirty = true;
Mem::Clear(buffer32);
}
void Ssd1306::Ssd1306Data::DrawLine(int x0, int y0, int x1, int y1) {
if (!available) {
return;
}
dirty = true;
// Use balanced Bresenham's line algorithm:
// https://en.wikipedia.org/wiki/Bresenham's_line_algorithm
const int dx = abs(x1 - x0);
const int sx = x0 < x1 ? 1 : -1;
const int dy = -abs(y1 - y0);
const int sy = y0 < y1 ? 1 : -1;
int error = dx + dy;
while (true) {
SetPixel(x0, y0);
if (x0 == x1 && y0 == y1) {
return;
}
const int e2 = 2 * error;
if (e2 >= dy) {
error += dy;
x0 += sx;
}
if (e2 <= dx) {
error += dx;
y0 += sy;
}
}
}
void Ssd1306::Ssd1306Data::DrawRect(int left, int top, int right, int bottom) {
if (!available) {
return;
}
if (right < 0 || bottom < 0 || left >= JAVELIN_DISPLAY_WIDTH ||
top >= JAVELIN_DISPLAY_HEIGHT) {
return;
}
if (left < 0) {
left = 0;
}
if (right >= JAVELIN_DISPLAY_WIDTH) {
right = JAVELIN_DISPLAY_WIDTH;
}
int width = right - left;
if (top < 0) {
top = 0;
}
if (bottom >= JAVELIN_DISPLAY_HEIGHT) {
bottom = JAVELIN_DISPLAY_HEIGHT;
}
dirty = true;
uint8_t *p = &buffer8[left * (JAVELIN_DISPLAY_HEIGHT / 8) + (top >> 3)];
const int startY = top & -8;
const int endY = (bottom + 7) & -8;
for (int y = startY; y < endY; y += 8) {
int mask = 0xff;
if (y < top) {
mask &= mask << (top - y);
}
if (y + 8 > bottom) {
mask &= mask >> (y + 8 - bottom);
}
uint8_t *row = p;
for (int x = 0; x < width; ++x) {
int pixels = *row;
if (drawColor) {
pixels |= mask;
} else {
pixels &= ~mask;
}
*row = pixels;
row += JAVELIN_DISPLAY_HEIGHT / 8;
}
p++;
}
}
void Ssd1306::Ssd1306Data::DrawImage(int x, int y, int width, int height,
const uint8_t *data) {
if (!available) {
return;
}
// It's all off the screen.
if (x >= JAVELIN_DISPLAY_WIDTH || y >= JAVELIN_DISPLAY_HEIGHT) {
return;
}
if (y + height <= 0) {
return;
}
size_t bytesPerColumn = (height + 7) >> 3;
if (x < 0) {
width += x;
if (width <= 0) {
return;
}
data -= bytesPerColumn * x;
x = 0;
}
dirty = true;
const int startY = y >> 3;
const int yShift = y & 7;
const int endY = (y + height + 7) >> 3;
uint8_t *p = &buffer8[x * (JAVELIN_DISPLAY_HEIGHT / 8)];
const int endX = x + width;
if (endX > JAVELIN_DISPLAY_WIDTH) {
width = JAVELIN_DISPLAY_WIDTH - x;
}
while (width > 0) {
const uint8_t *column = data;
data += bytesPerColumn;
if (startY >= 0) {
const int bits = column[0] << yShift;
int pixels = p[startY];
if (drawColor) {
pixels |= bits;
} else {
pixels &= ~bits;
}
p[startY] = pixels;
}
for (int yy = startY + 1; yy < endY; ++yy) {
++column;
if (yy >= JAVELIN_DISPLAY_HEIGHT / 8) {
break;
}
if (yy < 0) {
continue;
}
int bits = (column[-1] >> (8 - yShift));
if (column < data) {
bits |= column[0] << yShift;
}
int pixels = p[yy];
if (drawColor) {
pixels |= bits;
} else {
pixels &= ~bits;
}
p[yy] = pixels;
}
p += JAVELIN_DISPLAY_HEIGHT / 8;
--width;
}
}
void Ssd1306::Ssd1306Data::DrawGrayscaleRange(int x, int y, int width,
int height, const uint8_t *data,
int min, int max) {
// It's all off the screen.
if (x >= JAVELIN_DISPLAY_WIDTH || y >= JAVELIN_DISPLAY_HEIGHT) {
return;
}
if (y < 0) {
height += y;
if (height <= 0) {
return;
}
data -= y;
y = 0;
}
const size_t bytesPerColumn = height;
if (x < 0) {
width += x;
if (width <= 0) {
return;
}
data -= bytesPerColumn * x;
x = 0;
}
dirty = true;
uint8_t *p = &buffer8[x * (JAVELIN_DISPLAY_HEIGHT / 8)];
const int endX = x + width;
if (endX > JAVELIN_DISPLAY_WIDTH) {
width = JAVELIN_DISPLAY_WIDTH - x;
}
const int endY = y + height;
if (endY > JAVELIN_DISPLAY_HEIGHT) {
height = JAVELIN_DISPLAY_HEIGHT - y;
}
while (width > 0) {
const uint8_t *column = data;
data += bytesPerColumn;
for (int yy = 0; yy < height; ++yy) {
if (min <= column[yy] && column[yy] < max) {
if (drawColor) {
p[(yy + y) >> 3] |= 1 << ((yy + y) & 7);
} else {
p[(yy + y) >> 3] &= ~(1 << ((yy + y) & 7));
}
}
}
p += JAVELIN_DISPLAY_HEIGHT / 8;
--width;
}
}
void Ssd1306::Ssd1306Data::DrawText(int x, int y, const Font *font,
TextAlignment alignment, const char *text) {
if (!available) {
return;
}
Utf8Pointer utf8p(text);
y -= font->baseline;
switch (alignment) {
case TextAlignment::LEFT:
break;
case TextAlignment::MIDDLE:
x -= font->GetStringWidth(text) >> 1;
break;
case TextAlignment::RIGHT:
x -= font->GetStringWidth(text);
break;
}
for (;;) {
const uint32_t c = *utf8p++;
if (c == 0) {
return;
}
const uint8_t *data = font->GetCharacterData(c);
if (data) {
uint32_t width = font->GetCharacterWidth(c);
DrawImage(x, y, width, font->height, data);
x += width;
}
x += font->spacing;
}
}
void Ssd1306::Ssd1306Data::Update() {
if (!available) {
return;
}
control.Update();
if (!dirty || dma4->IsBusy() || !IsI2cTxReady()) {
return;
}
ButtonScriptManager::GetInstance().ExecuteScript(
ButtonScriptId::DISPLAY_OVERLAY);
dirty = false;
JAVELIN_OLED_I2C->hw->enable = 0;
JAVELIN_OLED_I2C->hw->tar = JAVELIN_OLED_I2C_ADDRESS;
JAVELIN_OLED_I2C->hw->enable = 1;
// Start of data.
uint16_t *d = dmaBuffer;
*d++ = 0x40;
#if JAVELIN_OLED_ROTATION == 0 || JAVELIN_OLED_ROTATION == 180
const uint8_t *s = buffer8;
// Copy the frame buffer to DMA to the display.
for (size_t i = 0; i < JAVELIN_OLED_WIDTH * JAVELIN_OLED_HEIGHT / 8; ++i) {
*d++ = *s++;
}
#elif JAVELIN_OLED_ROTATION == 90 || JAVELIN_OLED_ROTATION == 270
for (int frameBufferY = JAVELIN_DISPLAY_HEIGHT - 1; frameBufferY >= 0;
--frameBufferY) {
const int shift = ~frameBufferY & 7;
const uint8_t *s = &buffer8[frameBufferY / 8];
for (size_t y = 0; y < JAVELIN_OLED_HEIGHT / 8; ++y) {
uint32_t pixelValue = 0;
for (size_t i = 0; i < 8; ++i) {
pixelValue = (pixelValue >> 1) | ((*s << shift) & 0x80);
s += JAVELIN_DISPLAY_HEIGHT / 8;
}
*d++ = pixelValue;
}
}
#else
#error Unhandled rotation
#endif
// Mark last byte as end of data.
d[-1] |= 0x200;
SendDmaBuffer(JAVELIN_OLED_WIDTH * JAVELIN_OLED_HEIGHT / 8 + 1);
}
bool Ssd1306::Ssd1306Data::InitializeSsd1306() {
static constexpr uint8_t COMMANDS[] = {
Ssd1306Command::EnableDisplay(false),
Ssd1306Command::SET_MEMORY_ADDRESSING_MODE,
Ssd1306MemoryAddressingMode::VERTICAL,
Ssd1306Command::SetDisplayStartLine(0),
#if !defined(JAVELIN_OLED_ROTATION) || JAVELIN_OLED_ROTATION == 0 || \
JAVELIN_OLED_ROTATION == 90
Ssd1306Command::SET_SEGMENT_REMAP_ENABLED,
Ssd1306Command::SET_COM_SCAN_DIRECTION_BOTTOM_UP,
#elif JAVELIN_OLED_ROTATION == 180 || JAVELIN_OLED_ROTATION == 270
Ssd1306Command::SET_SEGMENT_REMAP_DISABLED,
Ssd1306Command::SET_COM_SCAN_DIRECTION_TOP_DOWN,
#else
#error Unsupported OLED rotation
#endif
Ssd1306Command::SET_MULTIPLEX_RATIO,
JAVELIN_OLED_HEIGHT - 1, // Display height - 1
Ssd1306Command::SET_DISPLAY_OFFSET,
0x00,
Ssd1306Command::SET_COM_PIN_CONFIGURATION,
#if (JAVELIN_OLED_WIDTH == 128 && JAVELIN_OLED_HEIGHT == 32)
0x02,
#elif (JAVELIN_OLED_WIDTH == 128 && JAVELIN_OLED_HEIGHT == 64)
0x12,
#else
0x02,
#endif
Ssd1306Command::SET_DISPLAY_OSCILLATOR_FREQUENCY_CLOCK_DIVIDE_RATIO,
0x80, // Standard frequency, ClockDiv = 1.
Ssd1306Command::SET_PRECHARGE_PERIOD,
0xF1,
Ssd1306Command::SET_VCOMH_DESELECT_LEVEL,
0x30, // 0.83xVcc
Ssd1306Command::SET_CONTRAST,
0xFF,
Ssd1306Command::SET_FORCE_WHITE_DISABLED,
Ssd1306Command::SET_INVERT_DISABLED,
Ssd1306Command::SET_CHARGE_PUMP,
0x14, // Enable charge pump during display on.
Ssd1306Command::EnableDisplay(true),
Ssd1306Command::SET_COLUMN_ADDRESS,
0,
JAVELIN_OLED_WIDTH - 1,
Ssd1306Command::SET_PAGE_ADDRESS,
0,
(JAVELIN_OLED_HEIGHT - 1) / 8,
};
return SendCommandList(COMMANDS, sizeof(COMMANDS));
}
void Ssd1306::Ssd1306Data::Initialize() {
i2c_init(JAVELIN_OLED_I2C, I2C_CLOCK);
gpio_set_function(JAVELIN_OLED_SDA_PIN, GPIO_FUNC_I2C);
gpio_set_function(JAVELIN_OLED_SCL_PIN, GPIO_FUNC_I2C);
gpio_pull_up(JAVELIN_OLED_SDA_PIN);
gpio_pull_up(JAVELIN_OLED_SCL_PIN);
available = InitializeSsd1306();
if (!available) {
return;
}
// Update a black screen to avoid initial noise on the display.
WaitForI2cTxReady();
dirty = true;
Update();
}
//---------------------------------------------------------------------------
void Ssd1306::Ssd1306Control::Update() {
if (dirtyFlag == 0 || dma4->IsBusy() || !IsI2cTxReady()) {
return;
}
uint8_t commands[4];
uint8_t *p = commands;
if (dirtyFlag & DIRTY_FLAG_SCREEN_ON) {
*p++ = Ssd1306Command::EnableDisplay(data.screenOn);
}
if (dirtyFlag & DIRTY_FLAG_CONTRAST) {
*p++ = Ssd1306Command::SET_CONTRAST;
*p++ = data.contrast;
}
dirtyFlag = 0;
SendCommandListDma(commands, p - commands);
}
//---------------------------------------------------------------------------
void Ssd1306::Ssd1306Availability::UpdateBuffer(TxBuffer &buffer) {
if (!dirty) {
return;
}
dirty = false;
buffer.Add(SplitHandlerId::DISPLAY_AVAILABLE, &available, sizeof(bool));
}
void Ssd1306::Ssd1306Availability::OnDataReceived(const void *data,
size_t length) {
available = *(bool *)data;
}
void Ssd1306::Ssd1306Control::UpdateBuffer(TxBuffer &buffer) {
if (dirtyFlag == 0) {
return;
}
dirtyFlag = 0;
buffer.Add(SplitHandlerId::DISPLAY_CONTROL, &data, sizeof(data));
}
void Ssd1306::Ssd1306Control::OnDataReceived(const void *data, size_t length) {
const Ssd1306ControlTxRxData *controlData =
(const Ssd1306ControlTxRxData *)data;
if (this->data.screenOn != controlData->screenOn) {
this->data.screenOn = controlData->screenOn;
dirtyFlag |= DIRTY_FLAG_SCREEN_ON;
}
if (this->data.contrast != controlData->contrast) {
this->data.contrast = controlData->contrast;
dirtyFlag |= DIRTY_FLAG_CONTRAST;
}
}
void Ssd1306::Ssd1306Control::OnTransmitConnectionReset() {
dirtyFlag = DIRTY_FLAG_SCREEN_ON | DIRTY_FLAG_CONTRAST;
}
void Ssd1306::Ssd1306Data::UpdateBuffer(TxBuffer &buffer) {
if (!dirty || !available) {
return;
}
dirty = false;
buffer.Add(SplitHandlerId::DISPLAY_DATA, buffer8, sizeof(buffer8));
}
void Ssd1306::Ssd1306Data::OnDataReceived(const void *data, size_t length) {
dirty = true;
memcpy(buffer8, data, sizeof(buffer8));
}
//---------------------------------------------------------------------------
void Display::Clear(int displayId) {
#if JAVELIN_SPLIT
if (displayId < 0 || displayId >= 2) {
return;
}
#else
displayId = 0;
#endif
Ssd1306::instances[displayId].Clear();
}
void Display::SetScreenOn(int displayId, bool on) {
#if JAVELIN_SPLIT
if (displayId < 0 || displayId >= 2) {
return;
}
#else
displayId = 0;
#endif
Ssd1306::instances[displayId].control.SetScreenOn(on);
}
void Display::SetContrast(int displayId, int contrast) {
#if JAVELIN_SPLIT
if (displayId < 0 || displayId >= 2) {
return;
}
#else
displayId = 0;
#endif
Ssd1306::instances[displayId].control.SetContrast(contrast > 255 ? 255
: contrast);
}
void Display::DrawPixel(int displayId, int x, int y) {
#if JAVELIN_SPLIT
if (displayId < 0 || displayId >= 2) {
return;
}
#else
displayId = 0;
#endif
Ssd1306::instances[displayId].dirty = true;
Ssd1306::instances[displayId].SetPixel(x, y);
}
void Display::DrawLine(int displayId, int x1, int y1, int x2, int y2) {
#if JAVELIN_SPLIT
if (displayId < 0 || displayId >= 2) {
return;
}
#else
displayId = 0;
#endif
Ssd1306::instances[displayId].DrawLine(x1, y1, x2, y2);
}
void Display::DrawImage(int displayId, int x, int y, int width, int height,
const uint8_t *data) {
#if JAVELIN_SPLIT
if (displayId < 0 || displayId >= 2) {
return;
}
#else
displayId = 0;
#endif
Ssd1306::instances[displayId].DrawImage(x, y, width, height, data);
}
void Display::DrawGrayscaleRange(int displayId, int x, int y, int width,
int height, const uint8_t *data, int min,
int max) {
#if JAVELIN_SPLIT
if (displayId < 0 || displayId >= 2) {
return;
}
#else
displayId = 0;
#endif
Ssd1306::instances[displayId].DrawGrayscaleRange(x, y, width, height, data,
min, max);
}
void Display::DrawText(int displayId, int x, int y, FontId fontId,
TextAlignment alignment, const char *text) {
#if JAVELIN_SPLIT
if (displayId < 0 || displayId >= 2) {
return;
}
#else
displayId = 0;
#endif
const Font *font = Font::GetFont(fontId);
Ssd1306::instances[displayId].DrawText(x, y, font, alignment, text);
}
void Display::DrawRect(int displayId, int left, int top, int right,
int bottom) {
#if JAVELIN_SPLIT
if (displayId < 0 || displayId >= 2) {
return;
}
#else
displayId = 0;
#endif
Ssd1306::instances[displayId].DrawRect(left, top, right, bottom);
}
void Display::SetDrawColor(int displayId, int color) {
#if JAVELIN_SPLIT
if (displayId < 0 || displayId >= 2) {
return;
}
#else
displayId = 0;
#endif
Ssd1306::instances[displayId].drawColor = color != 0;
}
//---------------------------------------------------------------------------
#endif // JAVELIN_DISPLAY_DRIVER == 1306
//---------------------------------------------------------------------------