-
Notifications
You must be signed in to change notification settings - Fork 1k
/
u8x8_cad.c
904 lines (836 loc) · 25.1 KB
/
u8x8_cad.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
/*
u8x8_cad.c
"command arg data" interface to the graphics controller
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
Copyright (c) 2016, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The following sequence must be used for any data, which is set to the display:
uint8_t u8x8_cad_StartTransfer(u8x8_t *u8x8)
any of the following calls
uint8_t u8x8_cad_SendCmd(u8x8_t *u8x8, uint8_t cmd)
uint8_t u8x8_cad_SendArg(u8x8_t *u8x8, uint8_t arg)
uint8_t u8x8_cad_SendData(u8x8_t *u8x8, uint8_t cnt, uint8_t *data)
uint8_t u8x8_cad_EndTransfer(u8x8_t *u8x8)
*/
/*
uint8_t u8x8_cad_template(u8x8_t *u8x8, uint8_t msg, uint16_t arg_int, void *arg_ptr)
{
uint8_t i;
switch(msg)
{
case U8X8_MSG_CAD_SEND_CMD:
u8x8_mcd_byte_SetDC(mcd->next, 1);
u8x8_mcd_byte_Send(mcd->next, arg_int);
break;
case U8X8_MSG_CAD_SEND_ARG:
u8x8_mcd_byte_SetDC(mcd->next, 1);
u8x8_mcd_byte_Send(mcd->next, arg_int);
break;
case U8X8_MSG_CAD_SEND_DATA:
u8x8_mcd_byte_SetDC(mcd->next, 0);
for( i = 0; i < 8; i++ )
u8x8_mcd_byte_Send(mcd->next, ((uint8_t *)arg_ptr)[i]);
break;
case U8X8_MSG_CAD_RESET:
return mcd->next->cb(mcd->next, msg, arg_int, arg_ptr);
case U8X8_MSG_CAD_START_TRANSFER:
return mcd->next->cb(mcd->next, msg, arg_int, arg_ptr);
case U8X8_MSG_CAD_END_TRANSFER:
return mcd->next->cb(mcd->next, msg, arg_int, arg_ptr);
default:
break;
}
return 1;
}
*/
#include "u8x8.h"
uint8_t u8x8_cad_SendCmd(u8x8_t *u8x8, uint8_t cmd)
{
return u8x8->cad_cb(u8x8, U8X8_MSG_CAD_SEND_CMD, cmd, NULL);
}
uint8_t u8x8_cad_SendArg(u8x8_t *u8x8, uint8_t arg)
{
return u8x8->cad_cb(u8x8, U8X8_MSG_CAD_SEND_ARG, arg, NULL);
}
uint8_t u8x8_cad_SendMultipleArg(u8x8_t *u8x8, uint8_t cnt, uint8_t arg)
{
while( cnt > 0 )
{
u8x8->cad_cb(u8x8, U8X8_MSG_CAD_SEND_ARG, arg, NULL);
cnt--;
}
return 1;
}
uint8_t u8x8_cad_SendData(u8x8_t *u8x8, uint8_t cnt, uint8_t *data)
{
return u8x8->cad_cb(u8x8, U8X8_MSG_CAD_SEND_DATA, cnt, data);
}
uint8_t u8x8_cad_StartTransfer(u8x8_t *u8x8)
{
return u8x8->cad_cb(u8x8, U8X8_MSG_CAD_START_TRANSFER, 0, NULL);
}
uint8_t u8x8_cad_EndTransfer(u8x8_t *u8x8)
{
return u8x8->cad_cb(u8x8, U8X8_MSG_CAD_END_TRANSFER, 0, NULL);
}
void u8x8_cad_vsendf(u8x8_t * u8x8, const char *fmt, va_list va)
{
uint8_t d;
u8x8_cad_StartTransfer(u8x8);
while( *fmt != '\0' )
{
d = (uint8_t)va_arg(va, int);
switch(*fmt)
{
case 'a': u8x8_cad_SendArg(u8x8, d); break;
case 'c': u8x8_cad_SendCmd(u8x8, d); break;
case 'd': u8x8_cad_SendData(u8x8, 1, &d); break;
}
fmt++;
}
u8x8_cad_EndTransfer(u8x8);
}
void u8x8_SendF(u8x8_t * u8x8, const char *fmt, ...)
{
va_list va;
va_start(va, fmt);
u8x8_cad_vsendf(u8x8, fmt, va);
va_end(va);
}
/*
21 c send command c
22 a send arg a
23 d send data d
24 CS on
25 CS off
254 milli delay by milliseconds
255 end of sequence
*/
void u8x8_cad_SendSequence(u8x8_t *u8x8, uint8_t const *data)
{
uint8_t cmd;
uint8_t v;
for(;;)
{
cmd = *data;
data++;
switch( cmd )
{
case U8X8_MSG_CAD_SEND_CMD:
case U8X8_MSG_CAD_SEND_ARG:
v = *data;
u8x8->cad_cb(u8x8, cmd, v, NULL);
data++;
break;
case U8X8_MSG_CAD_SEND_DATA:
v = *data;
u8x8_cad_SendData(u8x8, 1, &v);
data++;
break;
case U8X8_MSG_CAD_START_TRANSFER:
case U8X8_MSG_CAD_END_TRANSFER:
u8x8->cad_cb(u8x8, cmd, 0, NULL);
break;
case 0x0fe:
v = *data;
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_MILLI, v);
data++;
break;
default:
return;
}
}
}
uint8_t u8x8_cad_empty(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
switch(msg)
{
case U8X8_MSG_CAD_SEND_CMD:
u8x8_byte_SendByte(u8x8, arg_int);
break;
case U8X8_MSG_CAD_SEND_ARG:
u8x8_byte_SendByte(u8x8, arg_int);
break;
case U8X8_MSG_CAD_SEND_DATA:
case U8X8_MSG_CAD_INIT:
case U8X8_MSG_CAD_START_TRANSFER:
case U8X8_MSG_CAD_END_TRANSFER:
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
default:
return 0;
}
return 1;
}
/*
convert to bytes by using
dc = 1 for commands and args and
dc = 0 for data
*/
uint8_t u8x8_cad_110(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
switch(msg)
{
case U8X8_MSG_CAD_SEND_CMD:
u8x8_byte_SetDC(u8x8, 1);
u8x8_byte_SendByte(u8x8, arg_int);
break;
case U8X8_MSG_CAD_SEND_ARG:
u8x8_byte_SetDC(u8x8, 1);
u8x8_byte_SendByte(u8x8, arg_int);
break;
case U8X8_MSG_CAD_SEND_DATA:
u8x8_byte_SetDC(u8x8, 0);
//u8x8_byte_SendBytes(u8x8, arg_int, arg_ptr);
//break;
/* fall through */
case U8X8_MSG_CAD_INIT:
case U8X8_MSG_CAD_START_TRANSFER:
case U8X8_MSG_CAD_END_TRANSFER:
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
default:
return 0;
}
return 1;
}
/*
convert to bytes by using
dc = 1 for commands and args and
dc = 0 for data
*/
uint8_t u8x8_gu800_cad_110(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
uint8_t *data;
switch(msg)
{
case U8X8_MSG_CAD_SEND_CMD:
u8x8_byte_SetDC(u8x8, 1);
u8x8_byte_StartTransfer(u8x8);
u8x8_byte_SendByte(u8x8, arg_int);
u8x8_byte_EndTransfer(u8x8);
break;
case U8X8_MSG_CAD_SEND_ARG:
u8x8_byte_SetDC(u8x8, 1);
u8x8_byte_StartTransfer(u8x8);
u8x8_byte_SendByte(u8x8, arg_int);
u8x8_byte_EndTransfer(u8x8);
break;
case U8X8_MSG_CAD_SEND_DATA:
u8x8_byte_SetDC(u8x8, 0);
data = (uint8_t *)arg_ptr;
while( arg_int > 0 )
{
u8x8_byte_StartTransfer(u8x8);
u8x8_byte_SendByte(u8x8, *data);
u8x8_byte_EndTransfer(u8x8);
data++;
arg_int--;
}
break;
case U8X8_MSG_CAD_INIT:
u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
break;
case U8X8_MSG_CAD_START_TRANSFER:
case U8X8_MSG_CAD_END_TRANSFER:
break;
default:
return 0;
}
return 1;
}
/*
convert to bytes by using
dc = 1 for commands and args and
dc = 0 for data
t6963
*/
uint8_t u8x8_cad_100(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
switch(msg)
{
case U8X8_MSG_CAD_SEND_CMD:
u8x8_byte_SetDC(u8x8, 1);
u8x8_byte_SendByte(u8x8, arg_int);
break;
case U8X8_MSG_CAD_SEND_ARG:
u8x8_byte_SetDC(u8x8, 0);
u8x8_byte_SendByte(u8x8, arg_int);
break;
case U8X8_MSG_CAD_SEND_DATA:
u8x8_byte_SetDC(u8x8, 0);
//u8x8_byte_SendBytes(u8x8, arg_int, arg_ptr);
//break;
/* fall through */
case U8X8_MSG_CAD_INIT:
case U8X8_MSG_CAD_START_TRANSFER:
case U8X8_MSG_CAD_END_TRANSFER:
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
default:
return 0;
}
return 1;
}
/*
convert to bytes by using
dc = 0 for commands and args and
dc = 1 for data
*/
uint8_t u8x8_cad_001(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
switch(msg)
{
case U8X8_MSG_CAD_SEND_CMD:
u8x8_byte_SetDC(u8x8, 0);
u8x8_byte_SendByte(u8x8, arg_int);
break;
case U8X8_MSG_CAD_SEND_ARG:
u8x8_byte_SetDC(u8x8, 0);
u8x8_byte_SendByte(u8x8, arg_int);
break;
case U8X8_MSG_CAD_SEND_DATA:
u8x8_byte_SetDC(u8x8, 1);
//u8x8_byte_SendBytes(u8x8, arg_int, arg_ptr);
//break;
/* fall through */
case U8X8_MSG_CAD_INIT:
case U8X8_MSG_CAD_START_TRANSFER:
case U8X8_MSG_CAD_END_TRANSFER:
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
default:
return 0;
}
return 1;
}
/*
convert to bytes by using
dc = 0 for commands
dc = 1 for args and data
*/
uint8_t u8x8_cad_011(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
switch(msg)
{
case U8X8_MSG_CAD_SEND_CMD:
u8x8_byte_SetDC(u8x8, 0);
u8x8_byte_SendByte(u8x8, arg_int);
break;
case U8X8_MSG_CAD_SEND_ARG:
u8x8_byte_SetDC(u8x8, 1);
u8x8_byte_SendByte(u8x8, arg_int);
break;
case U8X8_MSG_CAD_SEND_DATA:
u8x8_byte_SetDC(u8x8, 1);
//u8x8_byte_SendBytes(u8x8, arg_int, arg_ptr);
//break;
/* fall through */
case U8X8_MSG_CAD_INIT:
case U8X8_MSG_CAD_START_TRANSFER:
case U8X8_MSG_CAD_END_TRANSFER:
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
default:
return 0;
}
return 1;
}
/* cad procedure for the ST7920 in SPI mode */
/* u8x8_byte_SetDC is not used */
uint8_t u8x8_cad_st7920_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
uint8_t *data;
uint8_t b;
uint8_t i;
static uint8_t buf[16];
uint8_t *ptr;
switch(msg)
{
case U8X8_MSG_CAD_SEND_CMD:
u8x8_byte_SendByte(u8x8, 0x0f8);
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, 1);
u8x8_byte_SendByte(u8x8, arg_int & 0x0f0);
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, 1);
u8x8_byte_SendByte(u8x8, arg_int << 4);
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, 1);
break;
case U8X8_MSG_CAD_SEND_ARG:
u8x8_byte_SendByte(u8x8, 0x0f8);
u8x8_byte_SendByte(u8x8, arg_int & 0x0f0);
u8x8_byte_SendByte(u8x8, arg_int << 4);
break;
case U8X8_MSG_CAD_SEND_DATA:
u8x8_byte_SendByte(u8x8, 0x0fa);
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, 1);
/* this loop should be optimized: multiple bytes should be sent */
/* u8x8_byte_SendBytes(u8x8, arg_int, arg_ptr); */
data = (uint8_t *)arg_ptr;
/* the following loop increases speed by 20% */
while( arg_int >= 8 )
{
i = 8;
ptr = buf;
do
{
b = *data++;
*ptr++= b & 0x0f0;
b <<= 4;
*ptr++= b;
i--;
} while( i > 0 );
arg_int -= 8;
u8x8_byte_SendBytes(u8x8, 16, buf);
}
while( arg_int > 0 )
{
b = *data;
u8x8_byte_SendByte(u8x8, b & 0x0f0);
u8x8_byte_SendByte(u8x8, b << 4);
data++;
arg_int--;
}
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, 1);
break;
case U8X8_MSG_CAD_INIT:
case U8X8_MSG_CAD_START_TRANSFER:
case U8X8_MSG_CAD_END_TRANSFER:
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
default:
return 0;
}
return 1;
}
/* cad procedure for the SSD13xx family in I2C mode */
/* this procedure is also used by the ST7588 */
/* u8x8_byte_SetDC is not used */
/* U8X8_MSG_BYTE_START_TRANSFER starts i2c transfer, U8X8_MSG_BYTE_END_TRANSFER stops transfer */
/* After transfer start, a full byte indicates command or data mode */
static void u8x8_i2c_data_transfer(u8x8_t *u8x8, uint8_t arg_int, void *arg_ptr) U8X8_NOINLINE;
static void u8x8_i2c_data_transfer(u8x8_t *u8x8, uint8_t arg_int, void *arg_ptr)
{
u8x8_byte_StartTransfer(u8x8);
u8x8_byte_SendByte(u8x8, 0x040);
u8x8->byte_cb(u8x8, U8X8_MSG_CAD_SEND_DATA, arg_int, arg_ptr);
u8x8_byte_EndTransfer(u8x8);
}
/* classic version: will put a start/stop condition around each command and arg */
uint8_t u8x8_cad_ssd13xx_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
uint8_t *p;
switch(msg)
{
case U8X8_MSG_CAD_SEND_CMD:
case U8X8_MSG_CAD_SEND_ARG:
/* 7 Nov 2016: Can this be improved? */
//u8x8_byte_SetDC(u8x8, 0);
u8x8_byte_StartTransfer(u8x8);
//u8x8_byte_SendByte(u8x8, u8x8_GetI2CAddress(u8x8));
u8x8_byte_SendByte(u8x8, 0x000);
u8x8_byte_SendByte(u8x8, arg_int);
u8x8_byte_EndTransfer(u8x8);
break;
case U8X8_MSG_CAD_SEND_DATA:
//u8x8_byte_SetDC(u8x8, 1);
/* the FeatherWing OLED with the 32u4 transfer of long byte */
/* streams was not possible. This is broken down to */
/* smaller streams, 32 seems to be the limit... */
/* I guess this is related to the size of the Wire buffers in Arduino */
/* Unfortunately, this can not be handled in the byte level drivers, */
/* so this is done here. Even further, only 24 bytes will be sent, */
/* because there will be another byte (DC) required during the transfer */
p = (uint8_t *)arg_ptr;
while( arg_int > 24 )
{
u8x8_i2c_data_transfer(u8x8, 24, p);
arg_int-=24;
p+=24;
}
u8x8_i2c_data_transfer(u8x8, arg_int, p);
break;
case U8X8_MSG_CAD_INIT:
/* apply default i2c adr if required so that the start transfer msg can use this */
if ( u8x8->i2c_address == 255 )
u8x8->i2c_address = 0x078;
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
case U8X8_MSG_CAD_START_TRANSFER:
case U8X8_MSG_CAD_END_TRANSFER:
/* cad transfer commands are ignored */
break;
default:
return 0;
}
return 1;
}
/* fast version with reduced data start/stops, issue 735 */
uint8_t u8x8_cad_ssd13xx_fast_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
static uint8_t in_transfer = 0;
uint8_t *p;
switch(msg)
{
case U8X8_MSG_CAD_SEND_CMD:
/* improved version, takeover from ld7032 */
/* assumes, that the args of a command is not longer than 31 bytes */
/* speed improvement is about 4% compared to the classic version */
if ( in_transfer != 0 )
u8x8_byte_EndTransfer(u8x8);
u8x8_byte_StartTransfer(u8x8);
u8x8_byte_SendByte(u8x8, 0x000); /* cmd byte for ssd13xx controller */
u8x8_byte_SendByte(u8x8, arg_int);
in_transfer = 1;
/* lightning version: can replace the improved version from above */
/* the drawback of the lightning version is this: The complete init sequence */
/* must fit into the 32 byte Arduino Wire buffer, which might not always be the case */
/* speed improvement is about 6% compared to the classic version */
// if ( in_transfer == 0 )
// {
// u8x8_byte_StartTransfer(u8x8);
// u8x8_byte_SendByte(u8x8, 0x000); /* cmd byte for ssd13xx controller */
// in_transfer = 1;
// }
//u8x8_byte_SendByte(u8x8, arg_int);
break;
case U8X8_MSG_CAD_SEND_ARG:
u8x8_byte_SendByte(u8x8, arg_int);
break;
case U8X8_MSG_CAD_SEND_DATA:
if ( in_transfer != 0 )
u8x8_byte_EndTransfer(u8x8);
/* the FeatherWing OLED with the 32u4 transfer of long byte */
/* streams was not possible. This is broken down to */
/* smaller streams, 32 seems to be the limit... */
/* I guess this is related to the size of the Wire buffers in Arduino */
/* Unfortunately, this can not be handled in the byte level drivers, */
/* so this is done here. Even further, only 24 bytes will be sent, */
/* because there will be another byte (DC) required during the transfer */
p = (uint8_t *)arg_ptr;
while( arg_int > 24 )
{
u8x8_i2c_data_transfer(u8x8, 24, p);
arg_int-=24;
p+=24;
}
u8x8_i2c_data_transfer(u8x8, arg_int, p);
in_transfer = 0;
break;
case U8X8_MSG_CAD_INIT:
/* apply default i2c adr if required so that the start transfer msg can use this */
if ( u8x8->i2c_address == 255 )
u8x8->i2c_address = 0x078;
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
case U8X8_MSG_CAD_START_TRANSFER:
in_transfer = 0;
break;
case U8X8_MSG_CAD_END_TRANSFER:
if ( in_transfer != 0 )
u8x8_byte_EndTransfer(u8x8);
in_transfer = 0;
break;
default:
return 0;
}
return 1;
}
/* the st75256 i2c driver is a copy of the ssd13xx driver, but with arg=1 */
/* modified from cad001 (ssd13xx) to cad011 */
uint8_t u8x8_cad_st75256_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
uint8_t *p;
switch(msg)
{
case U8X8_MSG_CAD_SEND_CMD:
u8x8_byte_StartTransfer(u8x8);
u8x8_byte_SendByte(u8x8, 0x000);
u8x8_byte_SendByte(u8x8, arg_int);
u8x8_byte_EndTransfer(u8x8);
break;
case U8X8_MSG_CAD_SEND_ARG:
u8x8_byte_StartTransfer(u8x8);
u8x8_byte_SendByte(u8x8, 0x040);
u8x8_byte_SendByte(u8x8, arg_int);
u8x8_byte_EndTransfer(u8x8);
break;
case U8X8_MSG_CAD_SEND_DATA:
/* see ssd13xx driver */
p = (uint8_t *)arg_ptr;
while( arg_int > 24 )
{
u8x8_i2c_data_transfer(u8x8, 24, p);
arg_int-=24;
p+=24;
}
u8x8_i2c_data_transfer(u8x8, arg_int, p);
break;
case U8X8_MSG_CAD_INIT:
/* apply default i2c adr if required so that the start transfer msg can use this */
if ( u8x8->i2c_address == 255 )
u8x8->i2c_address = 0x078; /* ST75256, often this is 0x07e */
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
case U8X8_MSG_CAD_START_TRANSFER:
case U8X8_MSG_CAD_END_TRANSFER:
/* cad transfer commands are ignored */
break;
default:
return 0;
}
return 1;
}
/* cad i2c procedure for the ld7032 controller */
/* Issue https://github.com/olikraus/u8g2/issues/865 mentiones, that I2C does not work */
/* Workaround is to remove the while loop (or increase the value in the condition) */
uint8_t u8x8_cad_ld7032_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
static uint8_t in_transfer = 0;
uint8_t *p;
switch(msg)
{
case U8X8_MSG_CAD_SEND_CMD:
if ( in_transfer != 0 )
u8x8_byte_EndTransfer(u8x8);
u8x8_byte_StartTransfer(u8x8);
u8x8_byte_SendByte(u8x8, arg_int);
in_transfer = 1;
break;
case U8X8_MSG_CAD_SEND_ARG:
u8x8_byte_SendByte(u8x8, arg_int);
break;
case U8X8_MSG_CAD_SEND_DATA:
//u8x8_byte_SetDC(u8x8, 1);
/* the FeatherWing OLED with the 32u4 transfer of long byte */
/* streams was not possible. This is broken down to */
/* smaller streams, 32 seems to be the limit... */
/* I guess this is related to the size of the Wire buffers in Arduino */
/* Unfortunately, this can not be handled in the byte level drivers, */
/* so this is done here. Even further, only 24 bytes will be sent, */
/* because there will be another byte (DC) required during the transfer */
p = (uint8_t *)arg_ptr;
while( arg_int > 24 )
{
u8x8->byte_cb(u8x8, U8X8_MSG_CAD_SEND_DATA, 24, p);
arg_int-=24;
p+=24;
u8x8_byte_EndTransfer(u8x8);
u8x8_byte_StartTransfer(u8x8);
u8x8_byte_SendByte(u8x8, 0x08); /* data write for LD7032 */
}
u8x8->byte_cb(u8x8, U8X8_MSG_CAD_SEND_DATA, arg_int, p);
break;
case U8X8_MSG_CAD_INIT:
/* apply default i2c adr if required so that the start transfer msg can use this */
if ( u8x8->i2c_address == 255 )
u8x8->i2c_address = 0x060;
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
case U8X8_MSG_CAD_START_TRANSFER:
in_transfer = 0;
break;
case U8X8_MSG_CAD_END_TRANSFER:
if ( in_transfer != 0 )
u8x8_byte_EndTransfer(u8x8);
break;
default:
return 0;
}
return 1;
}
/* cad procedure for the UC16xx family in I2C mode */
/* u8x8_byte_SetDC is not used */
/* DC bit is encoded into the adr byte, structure is CAD001 */
uint8_t u8x8_cad_uc16xx_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
static uint8_t in_transfer = 0;
static uint8_t is_data = 0;
uint8_t *p;
switch(msg)
{
case U8X8_MSG_CAD_SEND_CMD:
case U8X8_MSG_CAD_SEND_ARG:
if ( in_transfer != 0 )
{
if ( is_data != 0 )
{
/* transfer mode is active, but data transfer */
u8x8_byte_EndTransfer(u8x8);
/* clear the lowest two bits of the adr */
u8x8_SetI2CAddress( u8x8, u8x8_GetI2CAddress(u8x8)&0x0fc );
u8x8_byte_StartTransfer(u8x8);
}
}
else
{
/* clear the lowest two bits of the adr */
u8x8_SetI2CAddress( u8x8, u8x8_GetI2CAddress(u8x8)&0x0fc );
u8x8_byte_StartTransfer(u8x8);
}
u8x8_byte_SendByte(u8x8, arg_int);
in_transfer = 1;
// is_data = 0; // 20 Jun 2021: I assume that this is missing here
break;
case U8X8_MSG_CAD_SEND_DATA:
if ( in_transfer != 0 )
{
if ( is_data == 0 )
{
/* transfer mode is active, but data transfer */
u8x8_byte_EndTransfer(u8x8);
/* clear the lowest two bits of the adr */
u8x8_SetI2CAddress( u8x8, (u8x8_GetI2CAddress(u8x8)&0x0fc)|2 );
u8x8_byte_StartTransfer(u8x8);
}
}
else
{
/* clear the lowest two bits of the adr */
u8x8_SetI2CAddress( u8x8, (u8x8_GetI2CAddress(u8x8)&0x0fc)|2 );
u8x8_byte_StartTransfer(u8x8);
}
in_transfer = 1;
// is_data = 1; // 20 Jun 2021: I assume that this is missing here
p = (uint8_t *)arg_ptr;
while( arg_int > 24 )
{
u8x8->byte_cb(u8x8, U8X8_MSG_CAD_SEND_DATA, 24, p);
arg_int-=24;
p+=24;
u8x8_byte_EndTransfer(u8x8);
u8x8_byte_StartTransfer(u8x8);
}
u8x8->byte_cb(u8x8, U8X8_MSG_CAD_SEND_DATA, arg_int, p);
break;
case U8X8_MSG_CAD_INIT:
/* apply default i2c adr if required so that the start transfer msg can use this */
if ( u8x8->i2c_address == 255 )
u8x8->i2c_address = 0x070;
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
case U8X8_MSG_CAD_START_TRANSFER:
in_transfer = 0;
/* actual start is delayed, because we do not whether this is data or cmd transfer */
break;
case U8X8_MSG_CAD_END_TRANSFER:
if ( in_transfer != 0 )
u8x8_byte_EndTransfer(u8x8);
in_transfer = 0;
break;
default:
return 0;
}
return 1;
}
/* cad procedure for the UC1638 in I2C mode */
/* same as u8x8_cad_uc16xx_i2c but CAD structure is CAD011 */
uint8_t u8x8_cad_uc1638_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
static uint8_t in_transfer = 0;
static uint8_t is_data = 0;
uint8_t *p;
switch(msg)
{
case U8X8_MSG_CAD_SEND_CMD:
if ( in_transfer != 0 )
{
if ( is_data != 0 )
{
/* transfer mode is active, but data transfer */
u8x8_byte_EndTransfer(u8x8);
/* clear the lowest two bits of the adr */
u8x8_SetI2CAddress( u8x8, u8x8_GetI2CAddress(u8x8)&0x0fc );
u8x8_byte_StartTransfer(u8x8);
}
}
else
{
/* clear the lowest two bits of the adr */
u8x8_SetI2CAddress( u8x8, u8x8_GetI2CAddress(u8x8)&0x0fc );
u8x8_byte_StartTransfer(u8x8);
}
u8x8_byte_SendByte(u8x8, arg_int);
in_transfer = 1;
is_data = 0;
break;
case U8X8_MSG_CAD_SEND_ARG:
if ( in_transfer != 0 )
{
if ( is_data == 0 )
{
/* transfer mode is active, but data transfer */
u8x8_byte_EndTransfer(u8x8);
/* clear the lowest two bits of the adr */
u8x8_SetI2CAddress( u8x8, (u8x8_GetI2CAddress(u8x8)&0x0fc)|2 );
u8x8_byte_StartTransfer(u8x8);
}
}
else
{
/* clear the lowest two bits of the adr */
u8x8_SetI2CAddress( u8x8, (u8x8_GetI2CAddress(u8x8)&0x0fc)|2 );
u8x8_byte_StartTransfer(u8x8);
}
u8x8_byte_SendByte(u8x8, arg_int);
in_transfer = 1;
is_data = 1;
break;
case U8X8_MSG_CAD_SEND_DATA:
if ( in_transfer != 0 )
{
if ( is_data == 0 )
{
/* transfer mode is active, but data transfer */
u8x8_byte_EndTransfer(u8x8);
/* clear the lowest two bits of the adr */
u8x8_SetI2CAddress( u8x8, (u8x8_GetI2CAddress(u8x8)&0x0fc)|2 );
u8x8_byte_StartTransfer(u8x8);
}
}
else
{
/* clear the lowest two bits of the adr */
u8x8_SetI2CAddress( u8x8, (u8x8_GetI2CAddress(u8x8)&0x0fc)|2 );
u8x8_byte_StartTransfer(u8x8);
}
in_transfer = 1;
is_data = 1;
p = (uint8_t *)arg_ptr;
while( arg_int > 24 )
{
u8x8->byte_cb(u8x8, U8X8_MSG_CAD_SEND_DATA, 24, p);
arg_int-=24;
p+=24;
u8x8_byte_EndTransfer(u8x8);
u8x8_byte_StartTransfer(u8x8);
}
u8x8->byte_cb(u8x8, U8X8_MSG_CAD_SEND_DATA, arg_int, p);
break;
case U8X8_MSG_CAD_INIT:
/* apply default i2c adr if required so that the start transfer msg can use this */
if ( u8x8->i2c_address == 255 )
u8x8->i2c_address = 0x078; /* see also https://github.com/olikraus/u8g2/issues/371 for a discussion on this value */
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
case U8X8_MSG_CAD_START_TRANSFER:
in_transfer = 0;
/* actual start is delayed, because we do not whether this is data or cmd transfer */
break;
case U8X8_MSG_CAD_END_TRANSFER:
if ( in_transfer != 0 )
u8x8_byte_EndTransfer(u8x8);
in_transfer = 0;
break;
default:
return 0;
}
return 1;
}