-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspi_oled_dac.c
1628 lines (1334 loc) · 42.4 KB
/
spi_oled_dac.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
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
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* spi_oled_dac --- SPI OLED SSD1351 on Black Pill STM32 2023-05-07 */
#include <stm32f4xx.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <ctype.h>
// Size of 128x128 OLED screen
#define MAXX 128
#define MAXY 128
#define DIGIT_WIDTH (21)
#define DIGIT_HEIGHT (32)
#define DIGIT_STRIDE (210)
// Co-ord of centre of screen
#define CENX (MAXX / 2)
#define CENY (MAXY / 2)
// SSD1351 command bytes
#define SSD1351_SETCOLUMN (0x15)
#define SSD1351_SETROW (0x75)
#define SSD1351_WRITERAM (0x5C)
#define SSD1351_READRAM (0x5D)
#define SSD1351_SETREMAP (0xA0)
#define SSD1351_STARTLINE (0xA1)
#define SSD1351_DISPLAYOFFSET (0xA2)
#define SSD1351_DISPLAYALLOFF (0xA4)
#define SSD1351_DISPLAYALLON (0xA5)
#define SSD1351_NORMALDISPLAY (0xA6)
#define SSD1351_INVERTDISPLAY (0xA7)
#define SSD1351_FUNCTIONSELECT (0xAB)
#define SSD1351_DISPLAYOFF (0xAE)
#define SSD1351_DISPLAYON (0xAF)
#define SSD1351_PRECHARGE (0xB1)
#define SSD1351_DISPLAYENHANCE (0xB2)
#define SSD1351_CLOCKDIV (0xB3)
#define SSD1351_SETVSL (0xB4)
#define SSD1351_SETGPIO (0xB5)
#define SSD1351_PRECHARGE2 (0xB6)
#define SSD1351_SETGRAY (0xB8)
#define SSD1351_USELUT (0xB9)
#define SSD1351_PRECHARGELEVEL (0xBB)
#define SSD1351_VCOMH (0xBE)
#define SSD1351_CONTRASTABC (0xC1)
#define SSD1351_CONTRASTMASTER (0xC7)
#define SSD1351_MUXRATIO (0xCA)
#define SSD1351_COMMANDLOCK (0xFD)
#define SSD1351_HORIZSCROLL (0x96)
#define SSD1351_STOPSCROLL (0x9E)
#define SSD1351_STARTSCROLL (0x9F)
// SSD1351 16-bit 5/6/5 colours
#define SSD1351_BLACK (0x0000)
#define SSD1351_RED (0x001f)
#define SSD1351_GREEN (0x07e0)
#define SSD1351_BLUE (0xf800)
#define SSD1351_CYAN (SSD1351_BLUE | SSD1351_GREEN)
#define SSD1351_MAGENTA (SSD1351_RED | SSD1351_BLUE)
#define SSD1351_YELLOW (SSD1351_RED | SSD1351_GREEN)
#define SSD1351_WHITE (SSD1351_RED | SSD1351_GREEN | SSD1351_BLUE)
#define SSD1351_GREY50 (0x000f | 0x03e0 | 0x7800)
#define SSD1351_GREY25 (0x0007 | 0x01e0 | 0x3800)
#define VFD_COLOUR SSD1351_CYAN
#define LED_COLOUR SSD1351_RED
#define PANAPLEX_COLOUR (SSD1351_RED | 0x03e0)
#define UART_RX_BUFFER_SIZE (128)
#define UART_RX_BUFFER_MASK (UART_RX_BUFFER_SIZE - 1)
#if (UART_RX_BUFFER_SIZE & UART_RX_BUFFER_MASK) != 0
#error UART_RX_BUFFER_SIZE must be a power of two and <= 256
#endif
#define UART_TX_BUFFER_SIZE (128)
#define UART_TX_BUFFER_MASK (UART_TX_BUFFER_SIZE - 1)
#if (UART_TX_BUFFER_SIZE & UART_TX_BUFFER_MASK) != 0
#error UART_TX_BUFFER_SIZE must be a power of two and <= 256
#endif
struct UART_RX_BUFFER
{
volatile uint8_t head;
volatile uint8_t tail;
uint8_t buf[UART_RX_BUFFER_SIZE];
};
struct UART_TX_BUFFER
{
volatile uint8_t head;
volatile uint8_t tail;
uint8_t buf[UART_TX_BUFFER_SIZE];
};
struct UART_BUFFER
{
struct UART_TX_BUFFER tx;
struct UART_RX_BUFFER rx;
};
// What style digits would we prefer?
enum STYLE {
PANAPLEX_STYLE,
LED_BAR_STYLE,
LED_DOT_STYLE,
VFD_STYLE
};
// What mode should the display operate in?
enum MODE {
MANUAL_MODE,
AUTO_HMS_MODE,
AUTO_HEX_MODE
};
// What state is the command parser operating in?
enum STATE {
NOT_SETTING_TIME,
SETTING_TIME_1,
SETTING_TIME_2,
SETTING_TIME_3,
SETTING_TIME_4,
SETTING_TIME_5,
SETTING_TIME_6
};
// UART buffers
struct UART_BUFFER U1Buf;
// The colour frame buffer, 32k bytes
uint16_t Frame[MAXY][MAXX];
volatile uint32_t Milliseconds = 0;
volatile uint8_t Tick = 0;
volatile uint8_t RtcTick = 0;
/* USART1_IRQHandler --- ISR for USART1, used for Rx and Tx */
void USART1_IRQHandler(void)
{
if (USART1->SR & USART_SR_RXNE) {
const uint8_t tmphead = (U1Buf.rx.head + 1) & UART_RX_BUFFER_MASK;
const uint8_t ch = USART1->DR; // Read received byte from UART
if (tmphead == U1Buf.rx.tail) // Is receive buffer full?
{
// Buffer is full; discard new byte
}
else
{
U1Buf.rx.head = tmphead;
U1Buf.rx.buf[tmphead] = ch; // Store byte in buffer
}
}
if (USART1->SR & USART_SR_TXE) {
if (U1Buf.tx.head != U1Buf.tx.tail) // Is there anything to send?
{
const uint8_t tmptail = (U1Buf.tx.tail + 1) & UART_TX_BUFFER_MASK;
U1Buf.tx.tail = tmptail;
USART1->DR = U1Buf.tx.buf[tmptail]; // Transmit one byte
}
else
{
USART1->CR1 &= ~USART_CR1_TXEIE; // Nothing left to send; disable Tx Empty interrupt
}
}
}
/* TIM4_IRQHandler --- ISR for TIM4, used for one-second real-time clock */
void TIM4_IRQHandler(void)
{
TIM4->SR &= ~TIM_SR_UIF; // Clear timer interrupt flag
RtcTick = 1;
}
/* millis --- return milliseconds since reset */
uint32_t millis(void)
{
return (Milliseconds);
}
/* SysTick_Handler --- ISR for System Timer overflow, used for 1ms ticker */
void SysTick_Handler(void)
{
static uint8_t flag = 0;
Milliseconds++;
Tick = 1;
// DEBUG: 500Hz on PC14 pin
if (flag)
GPIOC->BSRR = GPIO_BSRR_BR14; // GPIO pin PC14 LOW
else
GPIOC->BSRR = GPIO_BSRR_BS14; // GPIO pin PC14 HIGH
flag = !flag;
}
/* UART1RxByte --- read one character from UART1 via the circular buffer */
uint8_t UART1RxByte(void)
{
const uint8_t tmptail = (U1Buf.rx.tail + 1) & UART_RX_BUFFER_MASK;
while (U1Buf.rx.head == U1Buf.rx.tail) // Wait, if buffer is empty
;
U1Buf.rx.tail = tmptail;
return (U1Buf.rx.buf[tmptail]);
}
/* UART1RxAvailable --- return true if a byte is available in UART1 circular buffer */
int UART1RxAvailable(void)
{
return (U1Buf.rx.head != U1Buf.rx.tail);
}
/* UART1TxByte --- send one character to UART1 via the circular buffer */
void UART1TxByte(const uint8_t data)
{
const uint8_t tmphead = (U1Buf.tx.head + 1) & UART_TX_BUFFER_MASK;
while (tmphead == U1Buf.tx.tail) // Wait, if buffer is full
;
U1Buf.tx.buf[tmphead] = data;
U1Buf.tx.head = tmphead;
USART1->CR1 |= USART_CR1_TXEIE; // Enable UART1 Tx Empty interrupt
}
/* dac_cs --- set MCP4822 DAC CS pin HIGH or LOW */
static void dac_cs(const int cs)
{
if (cs)
GPIOA->BSRR = GPIO_BSRR_BS8; // GPIO pin PA8 HIGH
else
GPIOA->BSRR = GPIO_BSRR_BR8; // GPIO pin PA8 LOW
}
/* spi_cs --- set OLED CS pin HIGH or LOW */
static void spi_cs(const int cs)
{
if (cs)
GPIOA->BSRR = GPIO_BSRR_BS4; // GPIO pin PA4 HIGH
else
GPIOA->BSRR = GPIO_BSRR_BR4; // GPIO pin PA4 LOW
}
static void spi_dc(const int dc)
{
if (dc)
GPIOA->BSRR = GPIO_BSRR_BS3; // GPIO pin PA3 HIGH
else
GPIOA->BSRR = GPIO_BSRR_BR3; // GPIO pin PA3 LOW
}
static uint8_t spi_txd(const uint8_t data)
{
SPI1->DR = data;
while ((SPI1->SR & SPI_SR_TXE) == 0)
;
while ((SPI1->SR & SPI_SR_RXNE) == 0)
;
return (SPI1->DR);
}
/* dac_txd --- transmit data to MCP4822 DAC via SPI2 */
static uint16_t dac_txd(const uint16_t data)
{
SPI2->DR = data;
while ((SPI2->SR & SPI_SR_TXE) == 0)
;
while ((SPI2->SR & SPI_SR_RXNE) == 0)
;
return (SPI2->DR);
}
/* dac_a --- set DAC A output register */
static void dac_a(const int dac)
{
const uint16_t w = 0x3000 | (dac & 0x0fff);
dac_cs(0);
dac_txd(w);
dac_cs(1);
}
/* dac_b --- set DAC B output register */
static void dac_b(const int dac)
{
const uint16_t w = 0xb000 | (dac & 0x0fff);
dac_cs(0);
dac_txd(w);
dac_cs(1);
}
/* oledCmd --- send a command byte to the OLED by SPI */
static void oledCmd(const uint8_t c)
{
spi_dc(0);
spi_cs(0);
spi_txd(c);
spi_cs(1);
spi_dc(1);
}
/* oledCmd1b --- send two command bytes to the OLED by SPI */
static void oledCmd1b(const uint8_t c, const uint8_t b)
{
spi_dc(0);
spi_cs(0);
spi_txd(c);
spi_dc(1);
spi_txd(b);
spi_cs(1);
}
/* oledCmd2b --- send three command bytes to the OLED by SPI */
static void oledCmd2b(const uint8_t c, const uint8_t b1, const uint8_t b2)
{
spi_dc(0);
spi_cs(0);
spi_txd(c);
spi_dc(1);
spi_txd(b1);
spi_txd(b2);
spi_cs(1);
}
/* oledCmd3b --- send four command bytes to the OLED by SPI */
static void oledCmd3b(const uint8_t c, const uint8_t b1, const uint8_t b2, const uint8_t b3)
{
spi_dc(0);
spi_cs(0);
spi_txd(c);
spi_dc(1);
spi_txd(b1);
spi_txd(b2);
spi_txd(b3);
spi_cs(1);
}
/* updscreen --- update the physical screen from the buffer */
static void __attribute__((optimize("O3"))) updscreen(const uint8_t y1, const uint8_t y2)
{
int x, y;
volatile uint16_t __attribute__((unused)) junk;
oledCmd2b(SSD1351_SETCOLUMN, 0, MAXX - 1);
oledCmd2b(SSD1351_SETROW, y1, y2);
oledCmd(SSD1351_WRITERAM);
SPI1->CR1 |= SPI_CR1_DFF; // 16-bit mode for just a bit more speed
spi_cs(0);
for (y = y1; y <= y2; y++)
for (x = 0; x < MAXX; x++) {
SPI1->DR = Frame[y][x];
while ((SPI1->SR & SPI_SR_TXE) == 0)
;
while ((SPI1->SR & SPI_SR_RXNE) == 0)
;
junk = SPI1->DR;
}
spi_cs(1);
SPI1->CR1 &= ~SPI_CR1_DFF; // Back to 8-bit mode
}
/* OLED_begin --- initialise the SSD1351 OLED */
void OLED_begin(const int wd, const int ht)
{
uint8_t remap = 0x60;
// Init sequence for SSD1351 128x128 colour OLED module
oledCmd1b(SSD1351_COMMANDLOCK, 0x12);
oledCmd1b(SSD1351_COMMANDLOCK, 0xB1);
oledCmd(SSD1351_DISPLAYOFF);
oledCmd1b(SSD1351_CLOCKDIV, 0xF1);
oledCmd1b(SSD1351_MUXRATIO, 127);
oledCmd1b(SSD1351_DISPLAYOFFSET, 0x0);
oledCmd1b(SSD1351_SETGPIO, 0x00);
oledCmd1b(SSD1351_FUNCTIONSELECT, 0x01);
oledCmd1b(SSD1351_PRECHARGE, 0x32);
oledCmd1b(SSD1351_VCOMH, 0x05);
oledCmd(SSD1351_NORMALDISPLAY);
oledCmd3b(SSD1351_CONTRASTABC, 0xC8, 0x80, 0xC8);
oledCmd1b(SSD1351_CONTRASTMASTER, 0x0F);
oledCmd3b(SSD1351_SETVSL, 0xA0, 0xB5, 0x55);
oledCmd1b(SSD1351_PRECHARGE2, 0x01);
remap |= 0x10; // Flip display vertically
oledCmd1b(SSD1351_SETREMAP, remap);
oledCmd(SSD1351_DISPLAYON); // Turn on OLED panel
}
/* greyFrame --- clear entire frame to checkerboard pattern */
void greyFrame(void)
{
int r, c;
for (r = 0; r < MAXY; r += 2)
{
for (c = 0; c < MAXX; c += 2)
{
Frame[r][c] = SSD1351_BLACK;
Frame[r][c + 1] = SSD1351_WHITE;
}
for (c = 0; c < MAXX; c += 2)
{
Frame[r + 1][c] = SSD1351_WHITE;
Frame[r + 1][c + 1] = SSD1351_BLACK;
}
}
}
/* setPixel --- set a single pixel */
void setPixel(const unsigned int x, const unsigned int y, const uint16_t c)
{
if ((x < MAXX) && (y < MAXY))
Frame[y][x] = c;
else
{
// Serial.print("setPixel(");
// Serial.print(x);
// Serial.print(",");
// Serial.print(y);
// Serial.println(")");
}
}
/* setVline --- draw vertical line */
void setVline(const unsigned int x, const unsigned int y1, const unsigned int y2, const uint16_t c)
{
unsigned int y;
for (y = y1; y <= y2; y++)
Frame[y][x] = c;
}
/* setHline --- set pixels in a horizontal line */
void setHline(const unsigned int x1, const unsigned int x2, const unsigned int y, const uint16_t c)
{
unsigned int x;
for (x = x1; x <= x2; x++)
Frame[y][x] = c;
}
/* setRect --- set pixels in a (non-filled) rectangle */
void setRect(const int x1, const int y1, const int x2, const int y2, const uint16_t c)
{
setHline(x1, x2, y1, c);
setVline(x2, y1, y2, c);
setHline(x1, x2, y2, c);
setVline(x1, y1, y2, c);
}
/* fillRect --- set pixels in a filled rectangle */
void fillRect(const int x1, const int y1, const int x2, const int y2, const uint16_t ec, const uint16_t fc)
{
int y;
for (y = y1; y <= y2; y++)
setHline(x1, x2, y, fc);
setHline(x1, x2, y1, ec);
setVline(x2, y1, y2, ec);
setHline(x1, x2, y2, ec);
setVline(x1, y1, y2, ec);
}
/* renderBitmap --- render pixels into the framebuffer according to a bitmap */
void renderBitmap(const int x1, const int y1, const int wd, const int ht, const uint8_t *bitmap, const int stride, const uint16_t fg, const uint16_t bg)
{
int x, y;
int i, j;
const uint8_t *row;
const int x2 = x1 + wd - 1;
const int y2 = y1 + ht - 1;
for (y = y1, i = 0; y <= y2; y++, i++) {
row = bitmap + (stride * (i / 8));
for (x = x1, j = 0; x <= x2; x++, j++)
if (row[j] & (1 << (i % 8)))
Frame[y][x] = fg;
else
Frame[y][x] = bg;
}
}
#define WD (15) // Width of digit (X-coord of rightmost pixel of segments 'b' and 'c')
#define GY (13) // Y-coord of 'g' segment of Panaplex (slightly above half-way)
void drawLed(const int x0, int x, int y, const uint16_t c)
{
x *= 4;
y *= 4;
x += x0;
y += 3;
setHline(x, x + 2, y + 0, c);
setHline(x, x + 2, y + 1, c);
setHline(x, x + 2, y + 2, c);
}
void drawSegA(const int x, const int style, const uint16_t c)
{
switch (style) {
case PANAPLEX_STYLE:
setHline(x, x + WD, 0, c);
setHline(x, x + WD, 1, c);
break;
case LED_DOT_STYLE:
drawLed(x, 1, 0, c);
drawLed(x, 2, 0, c);
break;
case LED_BAR_STYLE:
setHline(x + 3, x + WD - 3, 0, c);
setHline(x + 3, x + WD - 3, 1, c);
setHline(x + 3, x + WD - 3, 2, c);
break;
case VFD_STYLE:
setHline(x + 1, x + WD - 1, 0, c);
setHline(x + 2, x + WD - 2, 1, c);
setHline(x + 3, x + WD - 3, 2, c);
break;
}
}
void drawSegB(const int x, const int style, const uint16_t c)
{
switch (style) {
case PANAPLEX_STYLE:
setVline(x + WD, 0, GY, c);
setVline(x + WD - 1, 0, GY, c);
break;
case LED_DOT_STYLE:
drawLed(x, 3, 1, c);
drawLed(x, 3, 2, c);
break;
case LED_BAR_STYLE:
setVline(x + WD, 3, 14, c);
setVline(x + WD - 1, 3, 14, c);
setVline(x + WD - 2, 3, 14, c);
break;
case VFD_STYLE:
setVline(x + WD, 1, 13, c);
setVline(x + WD - 1, 2, 14, c);
setVline(x + WD - 2, 3, 13, c);
break;
}
}
void drawSegC(const int x, const int style, const uint16_t c)
{
switch (style) {
case PANAPLEX_STYLE:
setVline(x + WD, GY, 31, c);
setVline(x + WD - 1, GY, 31, c);
break;
case LED_DOT_STYLE:
drawLed(x, 3, 4, c);
drawLed(x, 3, 5, c);
break;
case LED_BAR_STYLE:
setVline(x + WD, 18, 28, c);
setVline(x + WD - 1, 18, 28, c);
setVline(x + WD - 2, 18, 28, c);
break;
case VFD_STYLE:
setVline(x + WD, 19, 30, c);
setVline(x + WD - 1, 18, 29, c);
setVline(x + WD - 2, 19, 28, c);
break;
}
}
void drawSegD(const int x, const int style, const uint16_t c)
{
switch (style) {
case PANAPLEX_STYLE:
setHline(x, x + WD, 31, c);
setHline(x, x + WD, 30, c);
break;
case LED_DOT_STYLE:
drawLed(x, 1, 6, c);
drawLed(x, 2, 6, c);
break;
case LED_BAR_STYLE:
setHline(x + 3, x + WD - 3, 31, c);
setHline(x + 3, x + WD - 3, 30, c);
setHline(x + 3, x + WD - 3, 29, c);
break;
case VFD_STYLE:
setHline(x + 1, x + WD - 1, 31, c);
setHline(x + 2, x + WD - 2, 30, c);
setHline(x + 3, x + WD - 3, 29, c);
break;
}
}
void drawSegE(const int x, const int style, const uint16_t c)
{
switch (style) {
case PANAPLEX_STYLE:
setVline(x + 0, GY, 31, c);
setVline(x + 1, GY, 31, c);
break;
case LED_DOT_STYLE:
drawLed(x, 0, 4, c);
drawLed(x, 0, 5, c);
break;
case LED_BAR_STYLE:
setVline(x + 0, 18, 28, c);
setVline(x + 1, 18, 28, c);
setVline(x + 2, 18, 28, c);
break;
case VFD_STYLE:
setVline(x + 0, 17, 30, c);
setVline(x + 1, 18, 29, c);
setVline(x + 2, 19, 28, c);
break;
}
}
void drawSegF(const int x, const int style, const uint16_t c)
{
switch (style) {
case PANAPLEX_STYLE:
setVline(x + 0, 0, GY, c);
setVline(x + 1, 0, GY, c);
break;
case LED_DOT_STYLE:
drawLed(x, 0, 1, c);
drawLed(x, 0, 2, c);
break;
case LED_BAR_STYLE:
setVline(x + 0, 3, 14, c);
setVline(x + 1, 3, 14, c);
setVline(x + 2, 3, 14, c);
break;
case VFD_STYLE:
setVline(x + 0, 1, 15, c);
setVline(x + 1, 2, 14, c);
setVline(x + 2, 3, 13, c);
break;
}
}
void drawSegG(const int x, const int style, const uint16_t c)
{
switch (style) {
case PANAPLEX_STYLE:
setHline(x, x + WD, GY, c);
setHline(x, x + WD, GY + 1, c);
break;
case LED_DOT_STYLE:
drawLed(x, 1, 3, c);
drawLed(x, 2, 3, c);
break;
case LED_BAR_STYLE:
setHline(x + 3, x + WD - 3, 15, c);
setHline(x + 3, x + WD - 3, 16, c);
setHline(x + 3, x + WD - 3, 17, c);
break;
case VFD_STYLE:
setHline(x + 2, x + WD - 2, 15, c);
setHline(x + 1, x + WD - 1, 16, c);
setHline(x + 2, x + WD - 2, 17, c);
break;
}
}
void drawSegH(const int x, const int style, const uint16_t c)
{
switch (style) {
case PANAPLEX_STYLE:
setHline(x + WD, x + WD + 3, GY, c);
setHline(x + WD, x + WD + 3, GY + 1, c);
break;
case LED_DOT_STYLE:
drawLed(x, 4, 3, c);
break;
case LED_BAR_STYLE:
setHline(x + WD + 1, x + WD + 3, 15, c);
setHline(x + WD + 1, x + WD + 3, 16, c);
setHline(x + WD + 1, x + WD + 3, 17, c);
break;
case VFD_STYLE:
setHline(x + WD, x + WD + 3, 15, c);
setHline(x + WD - 1, x + WD + 3, 16, c);
setHline(x + WD, x + WD + 3, 17, c);
break;
}
}
void drawSegI(const int x, const int style, const uint16_t c)
{
switch (style) {
case LED_DOT_STYLE:
drawLed(x, 0, 0, c);
break;
}
}
void drawSegJ(const int x, const int style, const uint16_t c)
{
switch (style) {
case LED_DOT_STYLE:
drawLed(x, 3, 0, c);
break;
}
}
void drawSegK(const int x, const int style, const uint16_t c)
{
switch (style) {
case LED_DOT_STYLE:
drawLed(x, 3, 3, c);
break;
}
}
void drawSegL(const int x, const int style, const uint16_t c)
{
switch (style) {
case LED_DOT_STYLE:
drawLed(x, 3, 6, c);
break;
}
}
void drawSegM(const int x, const int style, const uint16_t c)
{
switch (style) {
case LED_DOT_STYLE:
drawLed(x, 0, 6, c);
break;
}
}
void drawSegN(const int x, const int style, const uint16_t c)
{
switch (style) {
case LED_DOT_STYLE:
drawLed(x, 0, 3, c);
break;
}
}
void drawSegDP(const int x, const int style, const uint16_t c)
{
switch (style) {
case PANAPLEX_STYLE:
setHline(x + WD + 2, x + WD + 4, 29, c);
setHline(x + WD + 2, x + WD + 4, 30, c);
setHline(x + WD + 2, x + WD + 4, 31, c);
break;
case LED_DOT_STYLE:
drawLed(x, 4, 6, c);
break;
case LED_BAR_STYLE:
case VFD_STYLE:
setHline(x + WD + 2, x + WD + 4, 29, c);
setHline(x + WD + 2, x + WD + 4, 30, c);
setHline(x + WD + 2, x + WD + 4, 31, c);
break;
}
}
void drawSegCN(const int x, const int style, const uint16_t c)
{
switch (style) {
case PANAPLEX_STYLE:
setHline(x + WD + 2, x + WD + 3, 9, c);
setHline(x + WD + 2, x + WD + 3, 10, c);
setHline(x + WD + 2, x + WD + 3, 17, c);
setHline(x + WD + 2, x + WD + 3, 18, c);
break;
case LED_DOT_STYLE:
drawLed(x, 4, 2, c);
drawLed(x, 4, 4, c);
break;
case LED_BAR_STYLE:
case VFD_STYLE:
setHline(x + WD + 2, x + WD + 4, 11, c);
setHline(x + WD + 2, x + WD + 4, 12, c);
setHline(x + WD + 2, x + WD + 4, 13, c);
setHline(x + WD + 2, x + WD + 4, 19, c);
setHline(x + WD + 2, x + WD + 4, 20, c);
setHline(x + WD + 2, x + WD + 4, 21, c);
break;
}
}
/* renderHexDigit --- draw a single digit into the frame buffer in a given style */
void renderHexDigit(const int x, const int digit, const int style, const uint16_t c)
{
if (0) {
;
}
else {
switch (digit) {
case 0:
drawSegA(x, style, c);
drawSegB(x, style, c);
drawSegC(x, style, c);
drawSegD(x, style, c);
drawSegE(x, style, c);
drawSegF(x, style, c);
drawSegK(x, style, c);
drawSegN(x, style, c);
break;
case 1:
drawSegB(x, style, c);
drawSegC(x, style, c);
drawSegJ(x, style, c);
drawSegK(x, style, c);
drawSegL(x, style, c);
break;
case 2:
drawSegA(x, style, c);
drawSegB(x, style, c);
drawSegD(x, style, c);
drawSegE(x, style, c);
drawSegG(x, style, c);
drawSegI(x, style, c);
drawSegL(x, style, c);
drawSegM(x, style, c);
break;
case 3:
drawSegA(x, style, c);
drawSegB(x, style, c);
drawSegC(x, style, c);
drawSegD(x, style, c);
drawSegG(x, style, c);
drawSegI(x, style, c);
drawSegM(x, style, c);
break;
case 4:
drawSegB(x, style, c);
drawSegC(x, style, c);
drawSegF(x, style, c);
drawSegG(x, style, c);
drawSegH(x, style, c); // Special segment just for 4
drawSegI(x, style, c);
drawSegJ(x, style, c);
drawSegK(x, style, c);
drawSegL(x, style, c);
break;
case 5:
drawSegA(x, style, c);
drawSegC(x, style, c);
drawSegD(x, style, c);
drawSegF(x, style, c);
drawSegG(x, style, c);
drawSegI(x, style, c);
drawSegJ(x, style, c);
drawSegM(x, style, c);
break;
case 6:
drawSegA(x, style, c);
drawSegC(x, style, c);
drawSegD(x, style, c);
drawSegE(x, style, c);
drawSegF(x, style, c);
drawSegG(x, style, c);
drawSegJ(x, style, c);
drawSegN(x, style, c);
break;
case 7:
drawSegA(x, style, c);
drawSegB(x, style, c);
drawSegC(x, style, c);
drawSegF(x, style, c); // Hooked 7
drawSegI(x, style, c);
drawSegJ(x, style, c);
drawSegK(x, style, c);
drawSegL(x, style, c);
break;
case 8:
drawSegA(x, style, c);
drawSegB(x, style, c);
drawSegC(x, style, c);
drawSegD(x, style, c);
drawSegE(x, style, c);
drawSegF(x, style, c);
drawSegG(x, style, c);
break;
case 9:
drawSegA(x, style, c);
drawSegB(x, style, c);
drawSegC(x, style, c);
drawSegD(x, style, c);
drawSegF(x, style, c);
drawSegG(x, style, c);
drawSegK(x, style, c);
drawSegM(x, style, c);
break;