-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathultralcd_implementation_ultiboard_v2.h
1101 lines (993 loc) · 40 KB
/
ultralcd_implementation_ultiboard_v2.h
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
#ifndef ULTRA_LCD_IMPLEMENTATION_ULTIBOARD_V2_H
#define ULTRA_LCD_IMPLEMENTATION_ULTIBOARD_V2_H
/**
* Implementation of the LCD display routines for a SSD1309 OLED graphical display connected with i2c.
**/
#define LCD_GFX_WIDTH 128
#define LCD_GFX_HEIGHT 64
// All Ultipanels might have an encoder - so this is always be mapped onto first two bits
#define BLEN_C 2
#define BLEN_B 1
#define BLEN_A 0
#define EN_C (1<<BLEN_C)
#define EN_B (1<<BLEN_B) // The two encoder pins are connected through BTN_EN1 and BTN_EN2
#define EN_A (1<<BLEN_A)
#define LCD_CLICKED (buttons&EN_C)
/* Custom characters defined in the first 8 characters of the LCD */
//#define LCD_STR_BEDTEMP "\x00"
//#define LCD_STR_DEGREE "\x01"
//#define LCD_STR_THERMOMETER "\x02"
#define LCD_STR_UPLEVEL "\x03"
#define LCD_STR_REFRESH "\x04"
#define LCD_STR_FOLDER "\x05"
//#define LCD_STR_FEEDRATE "\x06"
//#define LCD_STR_CLOCK "\x07"
#define LCD_STR_ARROW_RIGHT "\x7E" /* from the default character set */
#define LED_ADDRESS 0b1100000
#define LCD_ADDRESS 0b0111100
#define LCD_WRITE 0x00
#define LCD_READ 0x01
#define LCD_SEND_COMMAND 0x00
#define LCD_SEND_DATA 0x40
#define LCD_COMMAND_CONTRAST 0x81
#define LCD_COMMAND_FULL_DISPLAY_ON_DISABLE 0xA4
#define LCD_COMMAND_FULL_DISPLAY_ON_ENABLE 0xA5
#define LCD_COMMAND_INVERT_DISABLE 0xA6
#define LCD_COMMAND_INVERT_ENABLE 0xA7
#define LCD_COMMAND_DISPLAY_OFF 0xAE
#define LCD_COMMAND_DISPLAY_ON 0xAF
#define LCD_COMMAND_NOP 0xE3
#define LCD_COMMAND_LOCK_COMMANDS 0xDF
#define LCD_COMMAND_SET_ADDRESSING_MODE 0x20
#define LCD_RESET_PIN 5
#define LCD_CS_PIN 6
#define LCD_I2C_FREQ 200000
static const uint8_t lcd_font[] PROGMEM = {
// font data
0x00, 0x00, 0x00, 0x00, 0x00,// '\x00'
0x06, 0x09, 0x09, 0x06, 0x00,// '\x01'
0x60, 0x9E, 0x81, 0x9E, 0x60,// '\x02'
0x14, 0x16, 0x1F, 0x06, 0x04,// '\x03'
0x2C, 0x4C, 0x42, 0x32, 0x34,// '\x04'
0x3E, 0x26, 0x26, 0x24, 0x3C,// '\x05'
0x60, 0x00, 0x00, 0x00, 0x00,// '\x06'
0x70, 0x00, 0x00, 0x00, 0x00,// '\x07'
0x00, 0x00, 0x00, 0x00, 0x00,// '\x08'
0x00, 0x00, 0x00, 0x00, 0x00,// '\x09'
0x00, 0x00, 0x00, 0x00, 0x00,// '\x0A'
0x00, 0x00, 0x00, 0x00, 0x00,// '\x0B'
0x00, 0x00, 0x00, 0x00, 0x00,// '\x0C'
0x00, 0x00, 0x00, 0x00, 0x00,// '\x0D'
0x00, 0x00, 0x00, 0x00, 0x00,// '\x0E'
0x00, 0x00, 0x00, 0x00, 0x00,// '\x0F'
0x00, 0x00, 0x00, 0x00, 0x00,// '\x10'
0x00, 0x00, 0x00, 0x00, 0x00,// '\x11'
0x00, 0x00, 0x00, 0x00, 0x00,// '\x12'
0x00, 0x00, 0x00, 0x00, 0x00,// '\x13'
0x00, 0x00, 0x00, 0x00, 0x00,// '\x14'
0x00, 0x00, 0x00, 0x00, 0x00,// '\x15'
0x00, 0x00, 0x00, 0x00, 0x00,// '\x16'
0x00, 0x00, 0x00, 0x00, 0x00,// '\x17'
0x00, 0x00, 0x00, 0x00, 0x00,// '\x18'
0x00, 0x00, 0x00, 0x00, 0x00,// '\x19'
0x00, 0x00, 0x00, 0x00, 0x00,// '\x1A'
0x00, 0x00, 0x00, 0x00, 0x00,// '\x1B'
0x00, 0x00, 0x00, 0x00, 0x00,// '\x1C'
0x00, 0x00, 0x00, 0x00, 0x00,// '\x1D'
0x00, 0x00, 0x00, 0x00, 0x00,// '\x1E'
0x00, 0x00, 0x00, 0x00, 0x00,// '\x1F'
0x00, 0x00, 0x00, 0x00, 0x00,// (space)
0x00, 0x00, 0x5F, 0x00, 0x00,// !
0x00, 0x07, 0x00, 0x07, 0x00,// "
0x14, 0x7F, 0x14, 0x7F, 0x14,// #
0x24, 0x2A, 0x7F, 0x2A, 0x12,// $
0x23, 0x13, 0x08, 0x64, 0x62,// %
0x36, 0x49, 0x55, 0x22, 0x50,// &
0x00, 0x05, 0x03, 0x00, 0x00,// '
0x00, 0x1C, 0x22, 0x41, 0x00,// (
0x00, 0x41, 0x22, 0x1C, 0x00,// )
0x08, 0x2A, 0x1C, 0x2A, 0x08,// *
0x08, 0x08, 0x3E, 0x08, 0x08,// +
0x00, 0x50, 0x30, 0x00, 0x00,// ,
0x08, 0x08, 0x08, 0x08, 0x08,// -
0x00, 0x60, 0x60, 0x00, 0x00,// .
0x20, 0x10, 0x08, 0x04, 0x02,// /
0x3E, 0x51, 0x49, 0x45, 0x3E,// 0
0x00, 0x42, 0x7F, 0x40, 0x00,// 1
0x42, 0x61, 0x51, 0x49, 0x46,// 2
0x21, 0x41, 0x45, 0x4B, 0x31,// 3
0x18, 0x14, 0x12, 0x7F, 0x10,// 4
0x27, 0x45, 0x45, 0x45, 0x39,// 5
0x3C, 0x4A, 0x49, 0x49, 0x30,// 6
0x01, 0x71, 0x09, 0x05, 0x03,// 7
0x36, 0x49, 0x49, 0x49, 0x36,// 8
0x06, 0x49, 0x49, 0x29, 0x1E,// 9
0x00, 0x36, 0x36, 0x00, 0x00,// :
0x00, 0x56, 0x36, 0x00, 0x00,// ;
0x00, 0x08, 0x14, 0x22, 0x41,// <
0x14, 0x14, 0x14, 0x14, 0x14,// =
0x41, 0x22, 0x14, 0x08, 0x00,// >
0x02, 0x01, 0x51, 0x09, 0x06,// ?
0x32, 0x49, 0x79, 0x41, 0x3E,// @
0x7E, 0x11, 0x11, 0x11, 0x7E,// A
0x7F, 0x49, 0x49, 0x49, 0x36,// B
0x3E, 0x41, 0x41, 0x41, 0x22,// C
0x7F, 0x41, 0x41, 0x22, 0x1C,// D
0x7F, 0x49, 0x49, 0x49, 0x41,// E
0x7F, 0x09, 0x09, 0x01, 0x01,// F
0x3E, 0x41, 0x41, 0x51, 0x32,// G
0x7F, 0x08, 0x08, 0x08, 0x7F,// H
0x00, 0x41, 0x7F, 0x41, 0x00,// I
0x20, 0x40, 0x41, 0x3F, 0x01,// J
0x7F, 0x08, 0x14, 0x22, 0x41,// K
0x7F, 0x40, 0x40, 0x40, 0x40,// L
0x7F, 0x02, 0x04, 0x02, 0x7F,// M
0x7F, 0x04, 0x08, 0x10, 0x7F,// N
0x3E, 0x41, 0x41, 0x41, 0x3E,// O
0x7F, 0x09, 0x09, 0x09, 0x06,// P
0x3E, 0x41, 0x51, 0x21, 0x5E,// Q
0x7F, 0x09, 0x19, 0x29, 0x46,// R
0x46, 0x49, 0x49, 0x49, 0x31,// S
0x01, 0x01, 0x7F, 0x01, 0x01,// T
0x3F, 0x40, 0x40, 0x40, 0x3F,// U
0x1F, 0x20, 0x40, 0x20, 0x1F,// V
0x7F, 0x20, 0x18, 0x20, 0x7F,// W
0x63, 0x14, 0x08, 0x14, 0x63,// X
0x03, 0x04, 0x78, 0x04, 0x03,// Y
0x61, 0x51, 0x49, 0x45, 0x43,// Z
0x00, 0x00, 0x7F, 0x41, 0x41,// [
0x02, 0x04, 0x08, 0x10, 0x20,// "\"
0x41, 0x41, 0x7F, 0x00, 0x00,// ]
0x04, 0x02, 0x01, 0x02, 0x04,// ^
0x40, 0x40, 0x40, 0x40, 0x40,// _
0x00, 0x01, 0x02, 0x04, 0x00,// `
0x20, 0x54, 0x54, 0x54, 0x78,// a
0x7F, 0x48, 0x44, 0x44, 0x38,// b
0x38, 0x44, 0x44, 0x44, 0x20,// c
0x38, 0x44, 0x44, 0x48, 0x7F,// d
0x38, 0x54, 0x54, 0x54, 0x18,// e
0x08, 0x7E, 0x09, 0x01, 0x02,// f
0x08, 0x14, 0x54, 0x54, 0x3C,// g
0x7F, 0x08, 0x04, 0x04, 0x78,// h
0x00, 0x44, 0x7D, 0x40, 0x00,// i
0x20, 0x40, 0x44, 0x3D, 0x00,// j
0x00, 0x7F, 0x10, 0x28, 0x44,// k
0x00, 0x41, 0x7F, 0x40, 0x00,// l
0x7C, 0x04, 0x18, 0x04, 0x78,// m
0x7C, 0x08, 0x04, 0x04, 0x78,// n
0x38, 0x44, 0x44, 0x44, 0x38,// o
0x7C, 0x14, 0x14, 0x14, 0x08,// p
0x08, 0x14, 0x14, 0x18, 0x7C,// q
0x7C, 0x08, 0x04, 0x04, 0x08,// r
0x48, 0x54, 0x54, 0x54, 0x20,// s
0x04, 0x3F, 0x44, 0x40, 0x20,// t
0x3C, 0x40, 0x40, 0x20, 0x7C,// u
0x1C, 0x20, 0x40, 0x20, 0x1C,// v
0x3C, 0x40, 0x30, 0x40, 0x3C,// w
0x44, 0x28, 0x10, 0x28, 0x44,// x
0x0C, 0x50, 0x50, 0x50, 0x3C,// y
0x44, 0x64, 0x54, 0x4C, 0x44,// z
0x00, 0x08, 0x36, 0x41, 0x00,// {
0x00, 0x00, 0x7F, 0x00, 0x00,// |
0x00, 0x41, 0x36, 0x08, 0x00,// }
0x08, 0x08, 0x2A, 0x1C, 0x08,// ->
0x08, 0x1C, 0x2A, 0x08, 0x08 // <-
};
static const uint8_t large_number16[] PROGMEM = {
/* page 0 (lines 0-7) */
0x0,0xfc,0xfe,0x6,0x6,0x6,0x6,0xfe,0xfc,0x0,
/* page 1 (lines 8-15) */
0x0,0x3f,0x7f,0x60,0x60,0x60,0x60,0x7f,0x3f,0x0,
/* page 2 (lines 16-23) */
0x0,0x0,0x0,0x0,0xfe,0xfe,0x0,0x0,0x0,0x0,
/* page 3 (lines 24-31) */
0x0,0x0,0x0,0x0,0x7f,0x7f,0x0,0x0,0x0,0x0,
/* page 4 (lines 32-39) */
0x0,0x6,0x86,0x86,0x86,0x86,0x86,0xfe,0xfc,0x0,
/* page 5 (lines 40-47) */
0x0,0x3f,0x7f,0x61,0x61,0x61,0x61,0x61,0x60,0x0,
/* page 6 (lines 48-55) */
0x0,0x6,0x6,0x86,0x86,0x86,0x86,0xfe,0x7c,0x0,
/* page 7 (lines 56-63) */
0x0,0x60,0x60,0x61,0x61,0x61,0x61,0x7f,0x3f,0x0,
/* page 8 (lines 64-71) */
0x0,0x0,0x80,0xe0,0x78,0x1e,0xfe,0xfe,0x0,0x0,
/* page 9 (lines 72-79) */
0x0,0x6,0x7,0x7,0x6,0x6,0x7f,0x7f,0x6,0x0,
/* page 10 (lines 80-87) */
0x0,0xfc,0xfe,0x86,0x86,0x86,0x86,0x86,0x6,0x0,
/* page 11 (lines 88-95) */
0x0,0x60,0x61,0x61,0x61,0x61,0x61,0x7f,0x3f,0x0,
/* page 12 (lines 96-103) */
0x0,0xfc,0xfe,0x86,0x86,0x86,0x86,0x86,0x0,0x0,
/* page 13 (lines 104-111) */
0x0,0x3f,0x7f,0x61,0x61,0x61,0x61,0x7f,0x3f,0x0,
/* page 14 (lines 112-119) */
0x0,0x6,0x6,0x6,0x6,0x86,0xf6,0x7e,0xe,0x0,
/* page 15 (lines 120-127) */
0x0,0x0,0x0,0x60,0x7c,0x1f,0x3,0x0,0x0,0x0,
/* page 16 (lines 128-135) */
0x0,0x7c,0xfe,0x86,0x86,0x86,0x86,0xfe,0x7c,0x0,
/* page 17 (lines 136-143) */
0x0,0x3f,0x7f,0x61,0x61,0x61,0x61,0x7f,0x3f,0x0,
/* page 18 (lines 144-151) */
0x0,0xfc,0xfe,0x86,0x86,0x86,0x86,0xfe,0xfc,0x0,
/* page 19 (lines 152-159) */
0x0,0x0,0x61,0x61,0x61,0x61,0x61,0x7f,0x3f,0x0,
};
static const uint8_t large_number24[] PROGMEM = {
0x0,0x0,0xf8,0xfc,0xfe,0xe,0xe,0xe,0xe,0xe,0xe,0xe,0xfe,0xfc,0xf8,0x0,
0x0,0x0,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xff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0xf8,0xf0,0xe0,0x0,
0x0,0x0,0x0,0x70,0x70,0x70,0x70,0x70,0x70,0x70,0x70,0x70,0x7f,0x3f,0x1f,0x0,
0x0,0x0,0xf8,0xfc,0xfe,0xe,0xe,0xe,0xe,0xe,0xe,0xe,0xe,0xe,0x0,0x0,
0x0,0x0,0xef,0xff,0xff,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0xf8,0xf0,0xe0,0x0,
0x0,0x0,0x1f,0x3f,0x7f,0x70,0x70,0x70,0x70,0x70,0x70,0x70,0x7f,0x3f,0x1f,0x0,
0x0,0x0,0xe,0xe,0xe,0xe,0xe,0xe,0xe,0xe,0x8e,0xfe,0xfe,0x7e,0xe,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xe0,0xfc,0xff,0x1f,0x3,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x78,0x7f,0x7f,0x7,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0xf8,0xfc,0xfe,0xe,0xe,0xe,0xe,0xe,0xe,0xe,0xfe,0xfc,0xf8,0x0,
0x0,0x0,0xef,0xff,0xff,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0xff,0xff,0xef,0x0,
0x0,0x0,0x1f,0x3f,0x7f,0x70,0x70,0x70,0x70,0x70,0x70,0x70,0x7f,0x3f,0x1f,0x0,
0x0,0x0,0xf8,0xfc,0xfe,0xe,0xe,0xe,0xe,0xe,0xe,0xe,0xfe,0xfc,0xf8,0x0,
0x0,0x0,0xf,0x1f,0x3f,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0xff,0xff,0xef,0x0,
0x0,0x0,0x0,0x70,0x70,0x70,0x70,0x70,0x70,0x70,0x70,0x70,0x7f,0x3f,0x1f,0x0,
};
static uint8_t lcd_contrast = 0xDF;
static void lcd_implementation_init();
static inline void i2c_start();
static inline void i2c_send_raw(uint8_t data)
{
TWDR = data;
TWCR = (1<<TWINT) | (1<<TWEN);
// MSerial.print('|');
while (!(TWCR & (1<<TWINT))) {}
// MSerial.println(int(TWSR), HEX);
/* if ((TWSR & 0xF8) == 0x38)
{
WRITE(54, 0);
while(1) {}
//Arbitration lost. The atmel goes into slave mode...
// TWCR = 0;
// lcd_implementation_init();
// i2c_start();
}
*/
}
static inline void i2c_start_led()
{
TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN);
// MSerial.print('=');
while (!(TWCR & (1<<TWINT))) {}
// MSerial.println(int(TWSR), HEX);
i2c_send_raw(LED_ADDRESS << 1);
}
static inline void i2c_start()
{
TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN);
// MSerial.print('=');
while (!(TWCR & (1<<TWINT))) {}
// MSerial.println(int(TWSR), HEX);
i2c_send_raw(LCD_ADDRESS << 1 | LCD_WRITE);
}
static inline void i2c_start_data()
{
i2c_start();
i2c_send_raw(LCD_SEND_DATA);
}
static inline void i2c_start_command()
{
i2c_start();
i2c_send_raw(LCD_SEND_COMMAND);
}
static inline void i2c_end()
{
TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWSTO);
// MSerial.println('X');
}
static void led_write(uint8_t addr, uint8_t data)
{
i2c_start_led();
i2c_send_raw(addr);
i2c_send_raw(data);
i2c_end();
}
static void lcd_implementation_clear()
{
i2c_start_data();
for(uint16_t n=0;n<128*64/8;n++)
i2c_send_raw(0);
i2c_start_command();
i2c_send_raw(LCD_COMMAND_CONTRAST);
i2c_send_raw(0xDF);
lcd_contrast = 0xDF;
i2c_end();
}
static void lcd_implementation_init()
{
SET_OUTPUT(LCD_CS_PIN);
SET_OUTPUT(LCD_RESET_PIN);
SET_OUTPUT(20);
SET_OUTPUT(21);
SET_OUTPUT(54);
WRITE(54, 1);
WRITE(LCD_CS_PIN, 0);
WRITE(20, 1);
WRITE(21, 1);
WRITE(LCD_RESET_PIN, 0);
_delay_ms(1);
WRITE(LCD_RESET_PIN, 1);
_delay_ms(100);
SET_OUTPUT(15);
WRITE(15, 0);
//ClockFreq = (F_CPU) / (16 + 2*TWBR * 4^TWPS)
//TWBR = ((F_CPU / ClockFreq) - 16)/2*4^TWPS
TWBR = ((F_CPU / LCD_I2C_FREQ) - 16)/2*1;
TWSR = 0x00;
led_write(0, 0x80);//MODE1
led_write(1, 0x1C);//MODE2
led_write(2, 0x20);//PWM0
led_write(3, 0x20);//PWM1
led_write(4, 0x20);//PWM2
led_write(5, 0x20);//PWM3
led_write(6, 0xFF);//GRPPWM
led_write(7, 0x00);//GRPFREQ
led_write(8, 0xAA);//LEDOUT
i2c_start_command();
i2c_send_raw(LCD_COMMAND_LOCK_COMMANDS);
i2c_send_raw(0x12);
i2c_send_raw(LCD_COMMAND_DISPLAY_OFF);
i2c_send_raw(0xD5);//Display clock divider/freq
i2c_send_raw(0xA0);
i2c_send_raw(0xA8);//Multiplex ratio
i2c_send_raw(0x3F);
i2c_send_raw(0xD3);//Display offset
i2c_send_raw(0x00);
i2c_send_raw(0x40);//Set start line
i2c_send_raw(0xA1);//Segment remap
i2c_send_raw(0xC8);//COM scan output direction
i2c_send_raw(0xDA);//COM pins hardware configuration
i2c_send_raw(0x12);
i2c_send_raw(LCD_COMMAND_CONTRAST);
i2c_send_raw(0xDF);
i2c_send_raw(0xD9);//Pre charge period
i2c_send_raw(0x82);
i2c_send_raw(0xDB);//VCOMH Deslect level
i2c_send_raw(0x34);
i2c_send_raw(LCD_COMMAND_SET_ADDRESSING_MODE);
i2c_send_raw(LCD_COMMAND_FULL_DISPLAY_ON_DISABLE);
i2c_send_raw(LCD_COMMAND_DISPLAY_ON);
i2c_end();
lcd_implementation_clear();
}
static void lcd_draw_char(const char chr)
{
const uint8_t* c = lcd_font + chr * 5;
i2c_send_raw(pgm_read_byte(c++));
i2c_send_raw(pgm_read_byte(c++));
i2c_send_raw(pgm_read_byte(c++));
i2c_send_raw(pgm_read_byte(c++));
i2c_send_raw(pgm_read_byte(c++));
i2c_send_raw(0x00);
}
static void lcd_draw_char_inverted(const char chr)
{
const uint8_t* c = lcd_font + chr * 5;
i2c_send_raw(pgm_read_byte(c++) ^ 0xFF);
i2c_send_raw(pgm_read_byte(c++) ^ 0xFF);
i2c_send_raw(pgm_read_byte(c++) ^ 0xFF);
i2c_send_raw(pgm_read_byte(c++) ^ 0xFF);
i2c_send_raw(pgm_read_byte(c++) ^ 0xFF);
i2c_send_raw(0xFF);
}
static void lcd_draw_string(const char* str, uint8_t width)
{
char c;
while((c = *str++) != '\0' && width > 0)
{
lcd_draw_char(c);
width--;
}
while(width)
{
lcd_draw_char(' ');
width--;
}
}
static uint8_t lcd_printPGM(const char* str)
{
char c;
uint8_t n = 0;
while((c = pgm_read_byte(str++)) != '\0')
{
lcd_draw_char(c);
n++;
}
return n;
}
static uint8_t lcd_printPGMinverted(const char* str)
{
char c;
uint8_t n = 0;
while((c = pgm_read_byte(str++)) != '\0')
{
lcd_draw_char_inverted(c);
n++;
}
return n;
}
static void lcd_set_pos(uint8_t col, uint8_t row)
{
i2c_start_command();
i2c_send_raw(0x00 | (col & 0x0F));
i2c_send_raw(0x10 | (col >> 4));
i2c_send_raw(0xB0 | row);
}
static void lcd_draw_large_number16(uint8_t col, uint8_t row, uint8_t nr)
{
lcd_set_pos(col, row);
i2c_start_data();
const uint8_t* c = large_number16 + nr * 10 * 2;
for(uint8_t n=0;n<10;n++)
i2c_send_raw(pgm_read_byte(c++));
lcd_set_pos(col, row + 1);
i2c_start_data();
for(uint8_t n=0;n<10;n++)
i2c_send_raw(pgm_read_byte(c++));
}
static void lcd_draw_large_number24(uint8_t col, uint8_t row, uint8_t nr)
{
lcd_set_pos(col, row);
i2c_start_data();
const uint8_t* c = large_number24 + nr * 16 * 3;
for(uint8_t n=0;n<16;n++)
i2c_send_raw(pgm_read_byte(c++));
lcd_set_pos(col, row + 1);
i2c_start_data();
for(uint8_t n=0;n<16;n++)
i2c_send_raw(pgm_read_byte(c++));
lcd_set_pos(col, row + 2);
i2c_start_data();
for(uint8_t n=0;n<16;n++)
i2c_send_raw(pgm_read_byte(c++));
}
static const uint8_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0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
};
static uint8_t anim = LCD_GFX_HEIGHT - 20;
extern uint8_t lcd_status_update_delay;
extern uint8_t lcdDrawUpdate;
static void lcd_implementation_status_screen()
{
i2c_start_command();
if (anim > 0)
{
i2c_send_raw(0x00);
i2c_send_raw(0x10);
i2c_send_raw(0xB0);
i2c_start_data();
const uint8_t* ptr = ultimaker_logo;
for(uint8_t m=0;m<LCD_GFX_HEIGHT / 8; m++)
{
for(uint8_t n=0;n<LCD_GFX_WIDTH;n++)
{
char c = pgm_read_byte(ptr++);
if (m < anim / 8)
c = 0x00;
if (m == anim / 8)
c = (c & (0xFF << (anim % 8)));
i2c_send_raw(c);
}
}
i2c_end();
anim--;
lcd_status_update_delay = 0;
if (!anim)
lcdDrawUpdate = 2;
return;
}
if (lcd_contrast > 0x08)
lcd_contrast -= 0x08;
else
lcd_contrast = 0;
i2c_start_command();
i2c_send_raw(LCD_COMMAND_CONTRAST);
i2c_send_raw(lcd_contrast);
int tHotend = int(degHotend(0) + 0.5);
int tTarget = int(degTargetHotend(0) + 0.5);
lcd_draw_large_number16( 0, 0, tHotend / 100);
lcd_draw_large_number16(10, 0, (tHotend / 10) % 10);
lcd_draw_large_number16(20, 0, (tHotend) % 10);
lcd_draw_char('0' + tTarget / 100);
lcd_draw_char('0' + tTarget / 10 % 10);
lcd_draw_char('0' + tTarget % 10);
#if EXTRUDERS > 1
tHotend = int(degHotend(1) + 0.5);
tTarget = int(degTargetHotend(1) + 0.5);
lcd_draw_large_number16(64+ 0, 0, tHotend / 100);
lcd_draw_large_number16(64+10, 0, (tHotend / 10) % 10);
lcd_draw_large_number16(64+20, 0, (tHotend) % 10);
lcd_draw_char('0' + tTarget / 100);
lcd_draw_char('0' + tTarget / 10 % 10);
lcd_draw_char('0' + tTarget % 10);
#endif
#if TEMP_SENSOR_BED != 0
tHotend = int(degBed() + 0.5);
tTarget = int(degTargetBed() + 0.5);
lcd_draw_large_number16( 0, 2, tHotend / 100);
lcd_draw_large_number16(10, 2, (tHotend / 10) % 10);
lcd_draw_large_number16(20, 2, (tHotend) % 10);
lcd_draw_char('0' + tTarget / 100);
lcd_draw_char('0' + tTarget / 10 % 10);
lcd_draw_char('0' + tTarget % 10);
#endif
lcd_draw_large_number16( 0, 4, feedmultiply / 100);
lcd_draw_large_number16(10, 4, (feedmultiply / 10) % 10);
lcd_draw_large_number16(20, 4, (feedmultiply) % 10);
if (IS_SD_PRINTING)
{
uint8_t n = card.percentDone();
lcd_draw_large_number24(64+ 0, 3, n / 100);
lcd_draw_large_number24(64+16, 3, (n / 10) % 10);
lcd_draw_large_number24(64+32, 3, n % 10);
}
lcd_set_pos(0, LCD_HEIGHT - 1);
i2c_start_data();
lcd_draw_string(lcd_status_message, LCD_WIDTH);
i2c_end();
}
static void lcd_implementation_drawmenu_generic(uint8_t row, const char* pstr, char post_char)
{
i2c_start_command();
i2c_send_raw(0x00);
i2c_send_raw(0x10);
i2c_send_raw(0xB0 | row);
i2c_start_data();
i2c_send_raw(0x00);
uint8_t n = LCD_WIDTH - 1 - lcd_printPGM(pstr);
while(n--)
lcd_draw_char(' ');
lcd_draw_char(post_char);
i2c_end();
}
static void lcd_implementation_drawmenu_generic_selected(uint8_t row, const char* pstr, char post_char)
{
i2c_start_command();
i2c_send_raw(0x00);
i2c_send_raw(0x10);
i2c_send_raw(0xB0 | row);
i2c_start_data();
i2c_send_raw(0xFF);
uint8_t n = LCD_WIDTH - 1 - lcd_printPGMinverted(pstr);
while(n--)
lcd_draw_char_inverted(' ');
lcd_draw_char_inverted(post_char);
i2c_end();
}
static void lcd_implementation_drawmenu_setting_edit_generic(uint8_t row, const char* pstr, char* data)
{
char c;
uint8_t n = LCD_WIDTH - 1 - strlen(data);
i2c_start_command();
i2c_send_raw(0x00);
i2c_send_raw(0x10);
i2c_send_raw(0xB0 | row);
i2c_start_data();
i2c_send_raw(0x00);
while((c = pgm_read_byte(pstr)) != '\0')
{
lcd_draw_char(c);
pstr++;
n--;
}
lcd_draw_char(':');
while(n--)
lcd_draw_char(' ');
while((c = *data++))
lcd_draw_char(c);
i2c_end();
}
static void lcd_implementation_drawmenu_setting_edit_generic_selected(uint8_t row, const char* pstr, char* data)
{
char c;
uint8_t n = LCD_WIDTH - 1 - strlen(data);
i2c_start_command();
i2c_send_raw(0x00);
i2c_send_raw(0x10);
i2c_send_raw(0xB0 | row);
i2c_start_data();
i2c_send_raw(0xFF);
while((c = pgm_read_byte(pstr)) != '\0')
{
lcd_draw_char_inverted(c);
pstr++;
n--;
}
lcd_draw_char_inverted(':');
while(n--)
lcd_draw_char_inverted(' ');
while((c = *data++))
lcd_draw_char_inverted(c);
i2c_end();
}
static void lcd_implementation_drawmenu_setting_edit_generic_selected_P(uint8_t row, const char* pstr, const char* data)
{
char c;
uint8_t n = LCD_WIDTH - 1 - strlen_P(data);
i2c_start_command();
i2c_send_raw(0x00);
i2c_send_raw(0x10);
i2c_send_raw(0xB0 | row);
i2c_start_data();
i2c_send_raw(0xFF);
while((c = pgm_read_byte(pstr)) != '\0')
{
lcd_draw_char_inverted(c);
pstr++;
n--;
}
lcd_draw_char_inverted(':');
while(n--)
lcd_draw_char_inverted(' ');
while((c = pgm_read_byte(data++)))
lcd_draw_char_inverted(c);
i2c_end();
}
static void lcd_implementation_drawmenu_setting_edit_generic_P(uint8_t row, const char* pstr, const char* data)
{
char c;
uint8_t n = LCD_WIDTH - 1 - strlen_P(data);
i2c_start_command();
i2c_send_raw(0x00);
i2c_send_raw(0x10);
i2c_send_raw(0xB0 | row);
i2c_start_data();
i2c_send_raw(0x00);
while((c = pgm_read_byte(pstr)) != '\0')
{
lcd_draw_char(c);
pstr++;
n--;
}
lcd_draw_char(':');
while(n--)
lcd_draw_char(' ');
while((c = pgm_read_byte(data++)))
lcd_draw_char(c);
i2c_end();
}
#define lcd_implementation_drawmenu_setting_edit_byte_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic_selected(row, pstr, itostr3(*(data)))
#define lcd_implementation_drawmenu_setting_edit_byte(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, itostr3(*(data)))
#define lcd_implementation_drawmenu_setting_edit_int3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic_selected(row, pstr, itostr3(*(data)))
#define lcd_implementation_drawmenu_setting_edit_int3(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, itostr3(*(data)))
#define lcd_implementation_drawmenu_setting_edit_int4_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic_selected(row, pstr, itostr4(*(data)))
#define lcd_implementation_drawmenu_setting_edit_int4(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, itostr4(*(data)))
#define lcd_implementation_drawmenu_setting_edit_float3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic_selected(row, pstr, ftostr3(*(data)))
#define lcd_implementation_drawmenu_setting_edit_float3(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ftostr3(*(data)))
#define lcd_implementation_drawmenu_setting_edit_float32_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic_selected(row, pstr, ftostr32(*(data)))
#define lcd_implementation_drawmenu_setting_edit_float32(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ftostr32(*(data)))
#define lcd_implementation_drawmenu_setting_edit_float5_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic_selected(row, pstr, ftostr5(*(data)))
#define lcd_implementation_drawmenu_setting_edit_float5(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ftostr5(*(data)))
#define lcd_implementation_drawmenu_setting_edit_float52_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic_selected(row, pstr, ftostr52(*(data)))
#define lcd_implementation_drawmenu_setting_edit_float52(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ftostr52(*(data)))
#define lcd_implementation_drawmenu_setting_edit_float51_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic_selected(row, pstr, ftostr51(*(data)))
#define lcd_implementation_drawmenu_setting_edit_float51(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ftostr51(*(data)))
#define lcd_implementation_drawmenu_setting_edit_long5_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic_selected(row, pstr, ftostr5(*(data)))
#define lcd_implementation_drawmenu_setting_edit_long5(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ftostr5(*(data)))
#define lcd_implementation_drawmenu_setting_edit_bool_selected(row, pstr, pstr2, data) lcd_implementation_drawmenu_setting_edit_generic_selected_P(row, pstr, (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
#define lcd_implementation_drawmenu_setting_edit_bool(row, pstr, pstr2, data) lcd_implementation_drawmenu_setting_edit_generic_P(row, pstr, (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
#define lcd_implementation_drawmenu_setting_edit_callback_int3_selected(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic_selected(row, pstr, itostr3(*(data)))
#define lcd_implementation_drawmenu_setting_edit_callback_int3(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, itostr3(*(data)))
#define lcd_implementation_drawmenu_setting_edit_callback_int4_selected(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic_selected(row, pstr, itostr4(*(data)))
#define lcd_implementation_drawmenu_setting_edit_callback_int4(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, itostr4(*(data)))
#define lcd_implementation_drawmenu_setting_edit_callback_float3_selected(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic_selected(row, pstr, ftostr3(*(data)))
#define lcd_implementation_drawmenu_setting_edit_callback_float3(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ftostr3(*(data)))
#define lcd_implementation_drawmenu_setting_edit_callback_float32_selected(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic_selected(row, pstr, ftostr32(*(data)))
#define lcd_implementation_drawmenu_setting_edit_callback_float32(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ftostr32(*(data)))
#define lcd_implementation_drawmenu_setting_edit_callback_float5_selected(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic_selected(row, pstr, ftostr5(*(data)))
#define lcd_implementation_drawmenu_setting_edit_callback_float5(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ftostr5(*(data)))
#define lcd_implementation_drawmenu_setting_edit_callback_float52_selected(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic_selected(row, pstr, ftostr52(*(data)))
#define lcd_implementation_drawmenu_setting_edit_callback_float52(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ftostr52(*(data)))
#define lcd_implementation_drawmenu_setting_edit_callback_float51_selected(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic_selected(row, pstr, ftostr51(*(data)))
#define lcd_implementation_drawmenu_setting_edit_callback_float51(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ftostr51(*(data)))
#define lcd_implementation_drawmenu_setting_edit_callback_long5_selected(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic_selected(row, pstr, ftostr5(*(data)))
#define lcd_implementation_drawmenu_setting_edit_callback_long5(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ftostr5(*(data)))
#define lcd_implementation_drawmenu_setting_edit_callback_bool_selected(row, pstr, pstr2, data, callback) lcd_implementation_drawmenu_setting_edit_generic_selected_P(row, pstr, '>', (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
#define lcd_implementation_drawmenu_setting_edit_callback_bool(row, pstr, pstr2, data, callback) lcd_implementation_drawmenu_setting_edit_generic_P(row, pstr, ' ', (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
void lcd_implementation_drawedit(const char* pstr, char* value)
{
char c;
uint8_t n = LCD_WIDTH - 1 - 1 - strlen(value);
i2c_start_command();
i2c_send_raw(0x00);
i2c_send_raw(0x10);
i2c_send_raw(0xB0 | 2);
i2c_start_data();
i2c_send_raw(0x00);
while((c = pgm_read_byte(pstr)) != '\0')
{
lcd_draw_char(c);
pstr++;
n--;
}
lcd_draw_char(':');
while(n--)
lcd_draw_char(' ');
while((c = *value++))
lcd_draw_char(c);
i2c_end();
}
static void lcd_implementation_drawmenu_sdfile_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename)
{
(void)pstr;
if (longFilename[0] != '\0')
{
filename = longFilename;
longFilename[LCD_WIDTH] = '\0';
}
i2c_start_command();
i2c_send_raw(0x00);
i2c_send_raw(0x10);
i2c_send_raw(0xB0 | row);
i2c_start_data();
i2c_send_raw(0xFF);
uint8_t n = LCD_WIDTH;
char c;
while((c = *longFilename++))
{
lcd_draw_char_inverted(c);
n--;
}
while(n--)
lcd_draw_char_inverted(' ');
i2c_end();
}
static void lcd_implementation_drawmenu_sdfile(uint8_t row, const char* pstr, const char* filename, char* longFilename)
{
(void)pstr;
if (longFilename[0] != '\0')
{
filename = longFilename;
longFilename[LCD_WIDTH] = '\0';
}
i2c_start_command();
i2c_send_raw(0x00);
i2c_send_raw(0x10);
i2c_send_raw(0xB0 | row);
i2c_start_data();
i2c_send_raw(0x00);
uint8_t n = LCD_WIDTH;
char c;
while((c = *longFilename++))
{
lcd_draw_char(c);
n--;
}
while(n--)
lcd_draw_char(' ');
i2c_end();
}
static void lcd_implementation_drawmenu_sddirectory_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename)
{
(void)pstr;
if (longFilename[0] != '\0')
{
filename = longFilename;
longFilename[LCD_WIDTH-1] = '\0';
}
i2c_start_command();
i2c_send_raw(0x00);
i2c_send_raw(0x10);
i2c_send_raw(0xB0 | row);
i2c_start_data();
i2c_send_raw(0x00);
lcd_draw_char_inverted(LCD_STR_FOLDER[0]);
uint8_t n = LCD_WIDTH-1;
char c;
while((c = *longFilename++))
{
lcd_draw_char_inverted(c);
n--;
}
while(n--)
lcd_draw_char_inverted(' ');
i2c_end();
}
static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* pstr, const char* filename, char* longFilename)
{
(void)pstr;
if (longFilename[0] != '\0')
{
filename = longFilename;
longFilename[LCD_WIDTH-1] = '\0';
}
i2c_start_command();
i2c_send_raw(0x00);
i2c_send_raw(0x10);
i2c_send_raw(0xB0 | row);
i2c_start_data();
i2c_send_raw(0x00);
lcd_draw_char(LCD_STR_FOLDER[0]);
uint8_t n = LCD_WIDTH-1;
char c;
while((c = *longFilename++))
{
lcd_draw_char(c);