Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "stm32_adafruit_lcd.h"
#include "../../../Utilities/Fonts/fonts.h"
#include "../../../Utilities/Fonts/font24.c"
#include "../../../Utilities/Fonts/font20.c"
#include "../../../Utilities/Fonts/font16.c"
#include "../../../Utilities/Fonts/font12.c"
#include "../../../Utilities/Fonts/font8.c"
#define POLY_X
#define POLY_Y
#define NULL
#define MAX_HEIGHT_FONT
#define MAX_WIDTH_FONT
#define OFFSET_BITMAP
#define ABS
DrawProp
lcd_drv
bitmap
BSP_LCD_Init()
BSP_LCD_GetXSize()
BSP_LCD_GetYSize()
BSP_LCD_GetTextColor()
BSP_LCD_GetBackColor()
BSP_LCD_SetTextColor(uint16_t)
BSP_LCD_SetBackColor(uint16_t)
BSP_LCD_SetFont(sFONT *)
BSP_LCD_GetFont()
BSP_LCD_Clear(uint16_t)
BSP_LCD_ClearStringLine(uint16_t)
BSP_LCD_DisplayChar(uint16_t, uint16_t, uint8_t)
BSP_LCD_DisplayStringAt(uint16_t, uint16_t, uint8_t *, Line_ModeTypdef)
BSP_LCD_DisplayStringAtLine(uint16_t, uint8_t *)
BSP_LCD_DrawPixel(uint16_t, uint16_t, uint16_t)
BSP_LCD_DrawHLine(uint16_t, uint16_t, uint16_t)
BSP_LCD_DrawVLine(uint16_t, uint16_t, uint16_t)
BSP_LCD_DrawLine(uint16_t, uint16_t, uint16_t, uint16_t)
BSP_LCD_DrawRect(uint16_t, uint16_t, uint16_t, uint16_t)
BSP_LCD_DrawCircle(uint16_t, uint16_t, uint16_t)
BSP_LCD_DrawPolygon(pPoint, uint16_t)
BSP_LCD_DrawEllipse(int, int, int, int)
BSP_LCD_DrawBitmap(uint16_t, uint16_t, uint8_t *)
BSP_LCD_FillRect(uint16_t, uint16_t, uint16_t, uint16_t)
BSP_LCD_FillCircle(uint16_t, uint16_t, uint16_t)
BSP_LCD_FillPolygon(pPoint, uint16_t)
BSP_LCD_FillEllipse(int, int, int, int)
BSP_LCD_DisplayOn()
BSP_LCD_DisplayOff()
DrawChar(uint16_t, uint16_t, const uint8_t *)
FillTriangle(uint16_t, uint16_t, uint16_t, uint16_t, uint16_t, uint16_t)
SetDisplayWindow(uint16_t, uint16_t, uint16_t, uint16_t)
Files
loading...
SourceVuSTM32 Libraries and SamplesAdafruit_Shieldstm32_adafruit_lcd.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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file stm32_adafruit_lcd.c * @author MCD Application Team * @brief This file includes the driver for Liquid Crystal Display (LCD) module * mounted on the Adafruit 1.8" TFT LCD shield (reference ID 802), * that is used with the STM32 Nucleo board through SPI interface. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* File Info : ----------------------------------------------------------------- User NOTES 1. How To use this driver: -------------------------- - The LCD st7735 component driver MUST be included with this driver. 2. Driver description: --------------------- + Initialization steps: o Initialize the LCD using the BSP_LCD_Init() function. + Display on LCD o Clear the whole LCD using the BSP_LCD_Clear() function or only one specified string line using the BSP_LCD_ClearStringLine() function. o Display a character on the specified line and column using the BSP_LCD_DisplayChar() function or a complete string line using the BSP_LCD_DisplayStringAtLine() function. o Display a string line on the specified position (x,y in pixel) and align mode using the BSP_LCD_DisplayStringAtLine() function. o Draw and fill a basic shapes (dot, line, rectangle, circle, ellipse, ..) on LCD using a set of functions. ------------------------------------------------------------------------------*//* ... */ /* Dependencies - st7735.c - fonts.h - font24.c - font20.c - font16.c - font12.c - font8.c" EndDependencies *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "stm32_adafruit_lcd.h" #include "../../../Utilities/Fonts/fonts.h" #include "../../../Utilities/Fonts/font24.c" #include "../../../Utilities/Fonts/font20.c" #include "../../../Utilities/Fonts/font16.c" #include "../../../Utilities/Fonts/font12.c" #include "../../../Utilities/Fonts/font8.c" 7 includes /** @addtogroup BSP * @{ *//* ... */ /** @addtogroup STM32_ADAFRUIT * @{ *//* ... */ /** @addtogroup STM32_ADAFRUIT_LCD * @{ *//* ... */ /** @defgroup STM32_ADAFRUIT_LCD_Private_TypesDefinitions * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup STM32_ADAFRUIT_LCD_Private_Defines * @{ *//* ... */ #define POLY_X(Z) ((int32_t)((Points + (Z))->X)) #define POLY_Y(Z) ((int32_t)((Points + (Z))->Y)) #define NULL (void *)0 #define MAX_HEIGHT_FONT 17 #define MAX_WIDTH_FONT 24 #define OFFSET_BITMAP 54 /** * @} *//* ... */ /** @defgroup STM32_ADAFRUIT_LCD_Private_Macros * @{ *//* ... */ #define ABS(X) ((X) > 0 ? (X) : -(X)) 7 defines /** * @} *//* ... */ /** @defgroup STM32_ADAFRUIT_LCD_Private_Variables * @{ *//* ... */ LCD_DrawPropTypeDef DrawProp; static LCD_DrvTypeDef *lcd_drv; /* Max size of bitmap will based on a font24 (17x24) */ static uint8_t bitmap[MAX_HEIGHT_FONT*MAX_WIDTH_FONT*2+OFFSET_BITMAP] = {0}; /** * @} *//* ... */ /** @defgroup STM32_ADAFRUIT_LCD_Private_FunctionPrototypes * @{ *//* ... */ static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c); static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3); static void SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height); /** * @} *//* ... */ /** @defgroup STM32_ADAFRUIT_LCD_Private_Functions * @{ *//* ... */ /** * @brief Initializes the LCD. * @param None * @retval LCD state *//* ... */ uint8_t BSP_LCD_Init(void) { uint8_t ret = LCD_ERROR; /* Default value for draw propriety */ DrawProp.BackColor = 0xFFFF; DrawProp.pFont = &Font24; DrawProp.TextColor = 0x0000; lcd_drv = &st7735_drv; /* LCD Init */ lcd_drv->Init(); /* Clear the LCD screen */ BSP_LCD_Clear(LCD_COLOR_WHITE); /* Initialize the font */ BSP_LCD_SetFont(&LCD_DEFAULT_FONT); ret = LCD_OK; return ret; }{ ... } /** * @brief Gets the LCD X size. * @param None * @retval Used LCD X size *//* ... */ uint32_t BSP_LCD_GetXSize(void) { return(lcd_drv->GetLcdPixelWidth()); }{ ... } /** * @brief Gets the LCD Y size. * @param None * @retval Used LCD Y size *//* ... */ uint32_t BSP_LCD_GetYSize(void) { return(lcd_drv->GetLcdPixelHeight()); }{ ... } /** * @brief Gets the LCD text color. * @param None * @retval Used text color. *//* ... */ uint16_t BSP_LCD_GetTextColor(void) { return DrawProp.TextColor; }{ ... } /** * @brief Gets the LCD background color. * @param None * @retval Used background color *//* ... */ uint16_t BSP_LCD_GetBackColor(void) { return DrawProp.BackColor; }{ ... } /** * @brief Sets the LCD text color. * @param Color: Text color code RGB(5-6-5) * @retval None *//* ... */ void BSP_LCD_SetTextColor(uint16_t Color) { DrawProp.TextColor = Color; }{ ... } /** * @brief Sets the LCD background color. * @param Color: Background color code RGB(5-6-5) * @retval None *//* ... */ void BSP_LCD_SetBackColor(uint16_t Color) { DrawProp.BackColor = Color; }{ ... } /** * @brief Sets the LCD text font. * @param fonts: Font to be used * @retval None *//* ... */ void BSP_LCD_SetFont(sFONT *pFonts) { DrawProp.pFont = pFonts; }{ ... } /** * @brief Gets the LCD text font. * @param None * @retval Used font *//* ... */ sFONT *BSP_LCD_GetFont(void) { return DrawProp.pFont; }{ ... } /** * @brief Clears the hole LCD. * @param Color: Color of the background * @retval None *//* ... */ void BSP_LCD_Clear(uint16_t Color) { uint32_t counter = 0; uint32_t color_backup = DrawProp.TextColor; DrawProp.TextColor = Color; for(counter = 0; counter < BSP_LCD_GetYSize(); counter++) { BSP_LCD_DrawHLine(0, counter, BSP_LCD_GetXSize()); }for (counter = 0; counter < BSP_LCD_GetYSize(); counter++) { ... } DrawProp.TextColor = color_backup; BSP_LCD_SetTextColor(DrawProp.TextColor); }{ ... } /** * @brief Clears the selected line. * @param Line: Line to be cleared * This parameter can be one of the following values: * @arg 0..9: if the Current fonts is Font16x24 * @arg 0..19: if the Current fonts is Font12x12 or Font8x12 * @arg 0..29: if the Current fonts is Font8x8 * @retval None *//* ... */ void BSP_LCD_ClearStringLine(uint16_t Line) { uint32_t color_backup = DrawProp.TextColor; DrawProp.TextColor = DrawProp.BackColor;; /* Draw a rectangle with background color */ BSP_LCD_FillRect(0, (Line * DrawProp.pFont->Height), BSP_LCD_GetXSize(), DrawProp.pFont->Height); DrawProp.TextColor = color_backup; BSP_LCD_SetTextColor(DrawProp.TextColor); }{ ... } /** * @brief Displays one character. * @param Xpos: Start column address * @param Ypos: Line where to display the character shape. * @param Ascii: Character ascii code * This parameter must be a number between Min_Data = 0x20 and Max_Data = 0x7E * @retval None *//* ... */ void BSP_LCD_DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii) { DrawChar(Xpos, Ypos, &DrawProp.pFont->table[(Ascii-' ') *\ DrawProp.pFont->Height * ((DrawProp.pFont->Width + 7) / 8)]); }{ ... } /** * @brief Displays characters on the LCD. * @param Xpos: X position (in pixel) * @param Ypos: Y position (in pixel) * @param Text: Pointer to string to display on LCD * @param Mode: Display mode * This parameter can be one of the following values: * @arg CENTER_MODE * @arg RIGHT_MODE * @arg LEFT_MODE * @retval None *//* ... */ void BSP_LCD_DisplayStringAt(uint16_t Xpos, uint16_t Ypos, uint8_t *Text, Line_ModeTypdef Mode) { uint16_t refcolumn = 1, i = 0; uint32_t size = 0, xsize = 0; uint8_t *ptr = Text; /* Get the text size */ while (*ptr++) size ++ ; /* Characters number per line */ xsize = (BSP_LCD_GetXSize()/DrawProp.pFont->Width); switch (Mode) { case CENTER_MODE: { refcolumn = Xpos + ((xsize - size)* DrawProp.pFont->Width) / 2; break; ...}case CENTER_MODE: case LEFT_MODE: { refcolumn = Xpos; break; ...}case LEFT_MODE: case RIGHT_MODE: { refcolumn = - Xpos + ((xsize - size)*DrawProp.pFont->Width); break; ...}case RIGHT_MODE: default: { refcolumn = Xpos; break; ...}default }switch (Mode) { ... } /* Send the string character by character on lCD */ while ((*Text != 0) && (((BSP_LCD_GetXSize() - (i*DrawProp.pFont->Width)) & 0xFFFF) >= DrawProp.pFont->Width)) { /* Display one character on LCD */ BSP_LCD_DisplayChar(refcolumn, Ypos, *Text); /* Decrement the column position by 16 */ refcolumn += DrawProp.pFont->Width; /* Point on the next character */ Text++; i++; }while ((*Text != 0) && (((BSP_LCD_GetXSize() - (i*DrawProp.pFont->Width)) & 0xFFFF) >= DrawProp.pFont->Width)) { ... } }{ ... } /** * @brief Displays a character on the LCD. * @param Line: Line where to display the character shape * This parameter can be one of the following values: * @arg 0..19: if the Current fonts is Font8 * @arg 0..12: if the Current fonts is Font12 * @arg 0...9: if the Current fonts is Font16 * @arg 0...7: if the Current fonts is Font20 * @arg 0...5: if the Current fonts is Font24 * @param ptr: Pointer to string to display on LCD * @retval None *//* ... */ void BSP_LCD_DisplayStringAtLine(uint16_t Line, uint8_t *ptr) { BSP_LCD_DisplayStringAt(0, LINE(Line), ptr, LEFT_MODE); }{ ... } /** * @brief Draws a pixel on LCD. * @param Xpos: X position * @param Ypos: Y position * @param RGB_Code: Pixel color in RGB mode (5-6-5) * @retval None *//* ... */ void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGB_Code) { if(lcd_drv->WritePixel != NULL) { lcd_drv->WritePixel(Xpos, Ypos, RGB_Code); }if (lcd_drv->WritePixel != NULL) { ... } }{ ... } /** * @brief Draws an horizontal line. * @param Xpos: X position * @param Ypos: Y position * @param Length: Line length * @retval None *//* ... */ void BSP_LCD_DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length) { uint32_t index = 0; if(lcd_drv->DrawHLine != NULL) { lcd_drv->DrawHLine(DrawProp.TextColor, Xpos, Ypos, Length); }if (lcd_drv->DrawHLine != NULL) { ... } else { for(index = 0; index < Length; index++) { BSP_LCD_DrawPixel((Xpos + index), Ypos, DrawProp.TextColor); }for (index = 0; index < Length; index++) { ... } }else { ... } }{ ... } /** * @brief Draws a vertical line. * @param Xpos: X position * @param Ypos: Y position * @param Length: Line length * @retval None *//* ... */ void BSP_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length) { uint32_t index = 0; if(lcd_drv->DrawVLine != NULL) { lcd_drv->DrawVLine(DrawProp.TextColor, Xpos, Ypos, Length); }if (lcd_drv->DrawVLine != NULL) { ... } else { for(index = 0; index < Length; index++) { BSP_LCD_DrawPixel(Xpos, Ypos + index, DrawProp.TextColor); }for (index = 0; index < Length; index++) { ... } }else { ... } }{ ... } /** * @brief Draws an uni-line (between two points). * @param x1: Point 1 X position * @param y1: Point 1 Y position * @param x2: Point 2 X position * @param y2: Point 2 Y position * @retval None *//* ... */ void BSP_LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) { int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0, yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0, curpixel = 0; deltax = ABS(x2 - x1); /* The difference between the x's */ deltay = ABS(y2 - y1); /* The difference between the y's */ x = x1; /* Start x off at the first pixel */ y = y1; /* Start y off at the first pixel */ if (x2 >= x1) /* The x-values are increasing */ { xinc1 = 1; xinc2 = 1; ...} else /* The x-values are decreasing */ { xinc1 = -1; xinc2 = -1; }else { ... } if (y2 >= y1) /* The y-values are increasing */ { yinc1 = 1; yinc2 = 1; ...} else /* The y-values are decreasing */ { yinc1 = -1; yinc2 = -1; }else { ... } if (deltax >= deltay) /* There is at least one x-value for every y-value */ { xinc1 = 0; /* Don't change the x when numerator >= denominator */ yinc2 = 0; /* Don't change the y for every iteration */ den = deltax; num = deltax / 2; numadd = deltay; numpixels = deltax; /* There are more x-values than y-values */ ...} else /* There is at least one y-value for every x-value */ { xinc2 = 0; /* Don't change the x for every iteration */ yinc1 = 0; /* Don't change the y when numerator >= denominator */ den = deltay; num = deltay / 2; numadd = deltax; numpixels = deltay; /* There are more y-values than x-values */ }else { ... } for (curpixel = 0; curpixel <= numpixels; curpixel++) { BSP_LCD_DrawPixel(x, y, DrawProp.TextColor); /* Draw the current pixel */ num += numadd; /* Increase the numerator by the top of the fraction */ if (num >= den) /* Check if numerator >= denominator */ { num -= den; /* Calculate the new numerator value */ x += xinc1; /* Change the x as appropriate */ y += yinc1; /* Change the y as appropriate */ ...} x += xinc2; /* Change the x as appropriate */ y += yinc2; /* Change the y as appropriate */ }for (curpixel = 0; curpixel <= numpixels; curpixel++) { ... } }{ ... } /** * @brief Draws a rectangle. * @param Xpos: X position * @param Ypos: Y position * @param Width: Rectangle width * @param Height: Rectangle height * @retval None *//* ... */ void BSP_LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) { /* Draw horizontal lines */ BSP_LCD_DrawHLine(Xpos, Ypos, Width); BSP_LCD_DrawHLine(Xpos, (Ypos+ Height), Width); /* Draw vertical lines */ BSP_LCD_DrawVLine(Xpos, Ypos, Height); BSP_LCD_DrawVLine((Xpos + Width), Ypos, Height); }{ ... } /** * @brief Draws a circle. * @param Xpos: X position * @param Ypos: Y position * @param Radius: Circle radius * @retval None *//* ... */ void BSP_LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius) { int32_t D; /* Decision Variable */ uint32_t CurX; /* Current X Value */ uint32_t CurY; /* Current Y Value */ D = 3 - (Radius << 1); CurX = 0; CurY = Radius; while (CurX <= CurY) { BSP_LCD_DrawPixel((Xpos + CurX), (Ypos - CurY), DrawProp.TextColor); BSP_LCD_DrawPixel((Xpos - CurX), (Ypos - CurY), DrawProp.TextColor); BSP_LCD_DrawPixel((Xpos + CurY), (Ypos - CurX), DrawProp.TextColor); BSP_LCD_DrawPixel((Xpos - CurY), (Ypos - CurX), DrawProp.TextColor); BSP_LCD_DrawPixel((Xpos + CurX), (Ypos + CurY), DrawProp.TextColor); BSP_LCD_DrawPixel((Xpos - CurX), (Ypos + CurY), DrawProp.TextColor); BSP_LCD_DrawPixel((Xpos + CurY), (Ypos + CurX), DrawProp.TextColor); BSP_LCD_DrawPixel((Xpos - CurY), (Ypos + CurX), DrawProp.TextColor); /* Initialize the font */ BSP_LCD_SetFont(&LCD_DEFAULT_FONT); if (D < 0) { D += (CurX << 2) + 6; }if (D < 0) { ... } else { D += ((CurX - CurY) << 2) + 10; CurY--; }else { ... } CurX++; }while (CurX <= CurY) { ... } }{ ... } /** * @brief Draws an poly-line (between many points). * @param Points: Pointer to the points array * @param PointCount: Number of points * @retval None *//* ... */ void BSP_LCD_DrawPolygon(pPoint Points, uint16_t PointCount) { int16_t X = 0, Y = 0; if(PointCount < 2) { return; }if (PointCount < 2) { ... } BSP_LCD_DrawLine(Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y); while(--PointCount) { X = Points->X; Y = Points->Y; Points++; BSP_LCD_DrawLine(X, Y, Points->X, Points->Y); }while (--PointCount) { ... } }{ ... } /** * @brief Draws an ellipse on LCD. * @param Xpos: X position * @param Ypos: Y position * @param XRadius: Ellipse X radius * @param YRadius: Ellipse Y radius * @retval None *//* ... */ void BSP_LCD_DrawEllipse(int Xpos, int Ypos, int XRadius, int YRadius) { int x = 0, y = -YRadius, err = 2-2*XRadius, e2; float K = 0, rad1 = 0, rad2 = 0; rad1 = XRadius; rad2 = YRadius; K = (float)(rad2/rad1); do { BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/K)), (Ypos+y), DrawProp.TextColor); BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/K)), (Ypos+y), DrawProp.TextColor); BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/K)), (Ypos-y), DrawProp.TextColor); BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/K)), (Ypos-y), DrawProp.TextColor); e2 = err; if (e2 <= x) { err += ++x*2+1; if (-y == x && e2 <= y) e2 = 0; }if (e2 <= x) { ... } if (e2 > y) err += ++y*2+1; ...} while (y <= 0); }{ ... } /** * @brief Draws a bitmap picture loaded in the STM32 MCU internal memory. * @param Xpos: Bmp X position in the LCD * @param Ypos: Bmp Y position in the LCD * @param pBmp: Pointer to Bmp picture address * @retval None *//* ... */ void BSP_LCD_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pBmp) { uint32_t height = 0; uint32_t width = 0; /* Read bitmap width */ width = pBmp[18] + (pBmp[19] << 8) + (pBmp[20] << 16) + (pBmp[21] << 24); /* Read bitmap height */ height = pBmp[22] + (pBmp[23] << 8) + (pBmp[24] << 16) + (pBmp[25] << 24); /* Remap Ypos, st7735 works with inverted X in case of bitmap */ /* X = 0, cursor is on Top corner */ if(lcd_drv == &st7735_drv) { Ypos = BSP_LCD_GetYSize() - Ypos - height; }if (lcd_drv == &st7735_drv) { ... } SetDisplayWindow(Xpos, Ypos, width, height); if(lcd_drv->DrawBitmap != NULL) { lcd_drv->DrawBitmap(Xpos, Ypos, pBmp); }if (lcd_drv->DrawBitmap != NULL) { ... } SetDisplayWindow(0, 0, BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); }{ ... } /** * @brief Draws a full rectangle. * @param Xpos: X position * @param Ypos: Y position * @param Width: Rectangle width * @param Height: Rectangle height * @retval None *//* ... */ void BSP_LCD_FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) { BSP_LCD_SetTextColor(DrawProp.TextColor); do { BSP_LCD_DrawHLine(Xpos, Ypos++, Width); ...} while(Height--); }{ ... } /** * @brief Draws a full circle. * @param Xpos: X position * @param Ypos: Y position * @param Radius: Circle radius * @retval None *//* ... */ void BSP_LCD_FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius) { int32_t D; /* Decision Variable */ uint32_t CurX; /* Current X Value */ uint32_t CurY; /* Current Y Value */ D = 3 - (Radius << 1); CurX = 0; CurY = Radius; BSP_LCD_SetTextColor(DrawProp.TextColor); while (CurX <= CurY) { if(CurY > 0) { BSP_LCD_DrawHLine(Xpos - CurY, Ypos + CurX, 2*CurY); BSP_LCD_DrawHLine(Xpos - CurY, Ypos - CurX, 2*CurY); }if (CurY > 0) { ... } if(CurX > 0) { BSP_LCD_DrawHLine(Xpos - CurX, Ypos - CurY, 2*CurX); BSP_LCD_DrawHLine(Xpos - CurX, Ypos + CurY, 2*CurX); }if (CurX > 0) { ... } if (D < 0) { D += (CurX << 2) + 6; }if (D < 0) { ... } else { D += ((CurX - CurY) << 2) + 10; CurY--; }else { ... } CurX++; }while (CurX <= CurY) { ... } BSP_LCD_SetTextColor(DrawProp.TextColor); BSP_LCD_DrawCircle(Xpos, Ypos, Radius); }{ ... } /** * @brief Draws a full poly-line (between many points). * @param Points: Pointer to the points array * @param PointCount: Number of points * @retval None *//* ... */ void BSP_LCD_FillPolygon(pPoint Points, uint16_t PointCount) { int16_t X = 0, Y = 0, X2 = 0, Y2 = 0, X_center = 0, Y_center = 0, X_first = 0, Y_first = 0, pixelX = 0, pixelY = 0, counter = 0; uint16_t IMAGE_LEFT = 0, IMAGE_RIGHT = 0, IMAGE_TOP = 0, IMAGE_BOTTOM = 0; IMAGE_LEFT = IMAGE_RIGHT = Points->X; IMAGE_TOP= IMAGE_BOTTOM = Points->Y; for(counter = 1; counter < PointCount; counter++) { pixelX = POLY_X(counter); if(pixelX < IMAGE_LEFT) { IMAGE_LEFT = pixelX; }if (pixelX < IMAGE_LEFT) { ... } if(pixelX > IMAGE_RIGHT) { IMAGE_RIGHT = pixelX; }if (pixelX > IMAGE_RIGHT) { ... } pixelY = POLY_Y(counter); if(pixelY < IMAGE_TOP) { IMAGE_TOP = pixelY; }if (pixelY < IMAGE_TOP) { ... } if(pixelY > IMAGE_BOTTOM) { IMAGE_BOTTOM = pixelY; }if (pixelY > IMAGE_BOTTOM) { ... } }for (counter = 1; counter < PointCount; counter++) { ... } if(PointCount < 2) { return; }if (PointCount < 2) { ... } X_center = (IMAGE_LEFT + IMAGE_RIGHT)/2; Y_center = (IMAGE_BOTTOM + IMAGE_TOP)/2; X_first = Points->X; Y_first = Points->Y; while(--PointCount) { X = Points->X; Y = Points->Y; Points++; X2 = Points->X; Y2 = Points->Y; FillTriangle(X, X2, X_center, Y, Y2, Y_center); FillTriangle(X, X_center, X2, Y, Y_center, Y2); FillTriangle(X_center, X2, X, Y_center, Y2, Y); }while (--PointCount) { ... } FillTriangle(X_first, X2, X_center, Y_first, Y2, Y_center); FillTriangle(X_first, X_center, X2, Y_first, Y_center, Y2); FillTriangle(X_center, X2, X_first, Y_center, Y2, Y_first); }{ ... } /** * @brief Draws a full ellipse. * @param Xpos: X position * @param Ypos: Y position * @param XRadius: Ellipse X radius * @param YRadius: Ellipse Y radius * @retval None *//* ... */ void BSP_LCD_FillEllipse(int Xpos, int Ypos, int XRadius, int YRadius) { int x = 0, y = -YRadius, err = 2-2*XRadius, e2; float K = 0, rad1 = 0, rad2 = 0; rad1 = XRadius; rad2 = YRadius; K = (float)(rad2/rad1); do { BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/K)), (Ypos+y), (2*(uint16_t)(x/K) + 1)); BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/K)), (Ypos-y), (2*(uint16_t)(x/K) + 1)); e2 = err; if (e2 <= x) { err += ++x*2+1; if (-y == x && e2 <= y) e2 = 0; }if (e2 <= x) { ... } if (e2 > y) err += ++y*2+1; ...} while (y <= 0); }{ ... } /** * @brief Enables the display. * @param None * @retval None *//* ... */ void BSP_LCD_DisplayOn(void) { lcd_drv->DisplayOn(); }{ ... } /** * @brief Disables the display. * @param None * @retval None *//* ... */ void BSP_LCD_DisplayOff(void) { lcd_drv->DisplayOff(); }{ ... } /******************************************************************************* Static Functions *******************************************************************************//* ... */ /** * @brief Draws a character on LCD. * @param Xpos: Line where to display the character shape * @param Ypos: Start column address * @param pChar: Pointer to the character data * @retval None *//* ... */ static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *pChar) { uint32_t counterh = 0, counterw = 0, index = 0; uint16_t height = 0, width = 0; uint8_t offset = 0; uint8_t *pchar = NULL; uint32_t line = 0; height = DrawProp.pFont->Height; width = DrawProp.pFont->Width; /* Fill bitmap header*/ *(uint16_t *) (bitmap + 2) = (uint16_t)(height*width*2+OFFSET_BITMAP); *(uint16_t *) (bitmap + 4) = (uint16_t)((height*width*2+OFFSET_BITMAP)>>16); *(uint16_t *) (bitmap + 10) = OFFSET_BITMAP; *(uint16_t *) (bitmap + 18) = (uint16_t)(width); *(uint16_t *) (bitmap + 20) = (uint16_t)((width)>>16); *(uint16_t *) (bitmap + 22) = (uint16_t)(height); *(uint16_t *) (bitmap + 24) = (uint16_t)((height)>>16); offset = 8 *((width + 7)/8) - width ; for(counterh = 0; counterh < height; counterh++) { pchar = ((uint8_t *)pChar + (width + 7)/8 * counterh); if(((width + 7)/8) == 3) { line = (pchar[0]<< 16) | (pchar[1]<< 8) | pchar[2]; }if (((width + 7)/8) == 3) { ... } if(((width + 7)/8) == 2) { line = (pchar[0]<< 8) | pchar[1]; }if (((width + 7)/8) == 2) { ... } if(((width + 7)/8) == 1) { line = pchar[0]; }if (((width + 7)/8) == 1) { ... } for (counterw = 0; counterw < width; counterw++) { /* Image in the bitmap is written from the bottom to the top */ /* Need to invert image in the bitmap */ index = (((height-counterh-1)*width)+(counterw))*2+OFFSET_BITMAP; if((line & (1 << (width- counterw + offset- 1))) != 0) { bitmap[index] = (uint8_t)DrawProp.TextColor; bitmap[index+1] = (uint8_t)(DrawProp.TextColor >> 8); }if ((line & (1 << (width- counterw + offset- 1))) != 0) { ... } else { bitmap[index] = (uint8_t)DrawProp.BackColor; bitmap[index+1] = (uint8_t)(DrawProp.BackColor >> 8); }else { ... } }for (counterw = 0; counterw < width; counterw++) { ... } }for (counterh = 0; counterh < height; counterh++) { ... } BSP_LCD_DrawBitmap(Xpos, Ypos, bitmap); }{ ... } /** * @brief Fills a triangle (between 3 points). * @param Points: Pointer to the points array * @param x1: Point 1 X position * @param y1: Point 1 Y position * @param x2: Point 2 X position * @param y2: Point 2 Y position * @param x3: Point 3 X position * @param y3: Point 3 Y position * @retval None *//* ... */ static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3) { int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0, yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0, curpixel = 0; deltax = ABS(x2 - x1); /* The difference between the x's */ deltay = ABS(y2 - y1); /* The difference between the y's */ x = x1; /* Start x off at the first pixel */ y = y1; /* Start y off at the first pixel */ if (x2 >= x1) /* The x-values are increasing */ { xinc1 = 1; xinc2 = 1; ...} else /* The x-values are decreasing */ { xinc1 = -1; xinc2 = -1; }else { ... } if (y2 >= y1) /* The y-values are increasing */ { yinc1 = 1; yinc2 = 1; ...} else /* The y-values are decreasing */ { yinc1 = -1; yinc2 = -1; }else { ... } if (deltax >= deltay) /* There is at least one x-value for every y-value */ { xinc1 = 0; /* Don't change the x when numerator >= denominator */ yinc2 = 0; /* Don't change the y for every iteration */ den = deltax; num = deltax / 2; numadd = deltay; numpixels = deltax; /* There are more x-values than y-values */ ...} else /* There is at least one y-value for every x-value */ { xinc2 = 0; /* Don't change the x for every iteration */ yinc1 = 0; /* Don't change the y when numerator >= denominator */ den = deltay; num = deltay / 2; numadd = deltax; numpixels = deltay; /* There are more y-values than x-values */ }else { ... } for (curpixel = 0; curpixel <= numpixels; curpixel++) { BSP_LCD_DrawLine(x, y, x3, y3); num += numadd; /* Increase the numerator by the top of the fraction */ if (num >= den) /* Check if numerator >= denominator */ { num -= den; /* Calculate the new numerator value */ x += xinc1; /* Change the x as appropriate */ y += yinc1; /* Change the y as appropriate */ ...} x += xinc2; /* Change the x as appropriate */ y += yinc2; /* Change the y as appropriate */ }for (curpixel = 0; curpixel <= numpixels; curpixel++) { ... } }{ ... } /** * @brief Sets display window. * @param LayerIndex: layer index * @param Xpos: LCD X position * @param Ypos: LCD Y position * @param Width: LCD window width * @param Height: LCD window height * @retval None *//* ... */ static void SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) { if(lcd_drv->SetDisplayWindow != NULL) { lcd_drv->SetDisplayWindow(Xpos, Ypos, Width, Height); }if (lcd_drv->SetDisplayWindow != NULL) { ... } }{ ... } /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */ Includes
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.