]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_SAMV71_Xplained_IAR_Keil/libboard_samv7-ek/source/lcd_font.c
Final V8.2.1 release ready for tagging:
[freertos] / FreeRTOS / Demo / CORTEX_M7_SAMV71_Xplained_IAR_Keil / libboard_samv7-ek / source / lcd_font.c
1 /* ----------------------------------------------------------------------------\r
2  *     SAM Software Package License\r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2011, Atmel Corporation\r
5  *\r
6  * All rights reserved.\r
7  *\r
8  * Redistribution and use in source and binary forms, with or without\r
9  * modification, are permitted provided that the following conditions are met:\r
10  *\r
11  * - Redistributions of source code must retain the above copyright notice,\r
12  * this list of conditions and the disclaimer below.\r
13  *\r
14  * Atmel's name may not be used to endorse or promote products derived from\r
15  * this software without specific prior written permission.\r
16  *\r
17  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR\r
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE\r
20  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,\r
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\r
23  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
24  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
25  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
26  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
27  * ----------------------------------------------------------------------------\r
28  */\r
29 \r
30 /**\r
31  * \file\r
32  *\r
33  * Implementation of draw font on LCD.\r
34  *\r
35  */\r
36 \r
37 /*----------------------------------------------------------------------------\r
38  *        Headers\r
39  *----------------------------------------------------------------------------*/\r
40 \r
41 #include "board.h"\r
42 \r
43 #include <stdint.h>\r
44 #include <assert.h>\r
45 \r
46 /*----------------------------------------------------------------------------\r
47  *        Local variables\r
48  *----------------------------------------------------------------------------*/\r
49 \r
50 /** Global variable describing the font being instancied. */\r
51 const Font gFont = {10, 14};\r
52 \r
53 /*----------------------------------------------------------------------------\r
54  *        Exported functions\r
55  *----------------------------------------------------------------------------*/\r
56 \r
57 /**\r
58  * \brief Draws an ASCII character on LCD.\r
59  *\r
60  * \param x  X-coordinate of character upper-left corner.\r
61  * \param y  Y-coordinate of character upper-left corner.\r
62  * \param c  Character to output.\r
63  * \param color  Character color.\r
64  */\r
65 extern void LCDD_DrawChar( uint32_t x, uint32_t y, uint8_t c, uint32_t color )\r
66 {\r
67     uint32_t row, col ;\r
68 \r
69     assert( (c >= 0x20) && (c <= 0x7F) ) ;\r
70 \r
71     for ( col = 0 ; col < 10 ; col++ )\r
72     {\r
73         for ( row = 0 ; row < 8 ; row++ )\r
74         {\r
75             if ( (pCharset10x14[((c - 0x20) * 20) + col * 2] >> (7 - row)) & 0x1 )\r
76             {\r
77                 LCDD_DrawPixel( x+col, y+row, color ) ;\r
78             }\r
79         }\r
80 \r
81         for (row = 0; row < 6; row++ )\r
82         {\r
83             if ((pCharset10x14[((c - 0x20) * 20) + col * 2 + 1] >> (7 - row)) & 0x1)\r
84             {\r
85                 LCDD_DrawPixel( x+col, y+row+8, color ) ;\r
86             }\r
87         }\r
88     }\r
89 }\r
90 \r
91 /**\r
92  * \brief Draws a string inside a LCD buffer, at the given coordinates.\r
93  * Line breaks will be honored.\r
94  *\r
95  * \param dwX      X-coordinate of string top-left corner.\r
96  * \param dwY      Y-coordinate of string top-left corner.\r
97  * \param pString  String to display.\r
98  */\r
99 extern void LCD_DrawString( uint32_t dwX, uint32_t dwY, const uint8_t *pString, uint32_t color )\r
100 {\r
101     uint32_t dwXorg = dwX ;\r
102 \r
103     while ( *pString != 0 )\r
104     {\r
105         if ( *pString == '\n' )\r
106         {\r
107             dwY += gFont.height + 2 ;\r
108             dwX = dwXorg ;\r
109         }\r
110         else\r
111         {\r
112             LCDD_DrawChar( dwX, dwY, *pString, color ) ;\r
113             dwX += gFont.width + 2 ;\r
114         }\r
115 \r
116         pString++ ;\r
117     }\r
118 }\r
119 \r
120 /**\r
121  * \brief Draws an ASCII character on LCD with given background color.\r
122  *\r
123  * \param x          X-coordinate of character upper-left corner.\r
124  * \param y          Y-coordinate of character upper-left corner.\r
125  * \param c          Character to output.\r
126  * \param fontColor  Character color.\r
127  * \param bgColor    Background color.\r
128  */\r
129 extern void LCDD_DrawCharWithBGColor( uint32_t x, uint32_t y, uint8_t c, uint32_t fontColor, uint32_t bgColor )\r
130 {\r
131     uint32_t row, col ;\r
132 \r
133     assert( (c >= 0x20) && (c <= 0x7F) ) ;\r
134 \r
135     for (col = 0; col < 10; col++)\r
136     {\r
137         for (row = 0 ; row < 8 ; row++)\r
138         {\r
139             if ( (pCharset10x14[((c - 0x20) * 20) + col * 2] >> (7 - row)) & 0x1 )\r
140             {\r
141                 LCDD_DrawPixel( x+col, y+row, fontColor ) ;\r
142             }\r
143             else\r
144             {\r
145                 LCDD_DrawPixel( x+col, y+row, bgColor ) ;\r
146             }\r
147         }\r
148 \r
149         for ( row = 0 ; row < 6 ; row++ )\r
150         {\r
151             if ( (pCharset10x14[((c - 0x20) * 20) + col * 2 + 1] >> (7 - row)) & 0x1 )\r
152             {\r
153                 LCDD_DrawPixel( x+col, y+row+8, fontColor ) ;\r
154             }\r
155             else\r
156             {\r
157                 LCDD_DrawPixel( x+col, y+row+8, bgColor ) ;\r
158             }\r
159         }\r
160     }\r
161 }\r
162 \r