1 // SPDX-License-Identifier: GPL-2.0+
4 * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
9 #include <video_font.h> /* Get font data, width and height */
11 static void lcd_putc_xy90(struct console_t *pcons, ushort x, ushort y, char c)
13 int fg_color = lcd_getfgcolor();
14 int bg_color = lcd_getbgcolor();
17 fbptr_t *dst = (fbptr_t *)pcons->fbbase +
18 (x+1) * pcons->lcdsizex -
22 uchar *pfont = video_fontdata + c * VIDEO_FONT_HEIGHT;
23 for (col = 0; col < VIDEO_FONT_WIDTH; ++col) {
24 for (i = 0; i < VIDEO_FONT_HEIGHT; ++i)
25 *dst-- = (*(pfont + i) & msk) ? fg_color : bg_color;
27 dst += (pcons->lcdsizex + VIDEO_FONT_HEIGHT);
31 static inline void console_setrow90(struct console_t *pcons, u32 row, int clr)
34 fbptr_t *dst = (fbptr_t *)pcons->fbbase +
36 row*VIDEO_FONT_HEIGHT+1;
38 for (j = 0; j < pcons->lcdsizey; j++) {
39 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
41 dst += (pcons->lcdsizex + VIDEO_FONT_HEIGHT);
45 static inline void console_moverow90(struct console_t *pcons,
46 u32 rowdst, u32 rowsrc)
49 fbptr_t *dst = (fbptr_t *)pcons->fbbase +
51 (rowdst*VIDEO_FONT_HEIGHT+1);
53 fbptr_t *src = (fbptr_t *)pcons->fbbase +
55 (rowsrc*VIDEO_FONT_HEIGHT+1);
57 for (j = 0; j < pcons->lcdsizey; j++) {
58 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
60 src += (pcons->lcdsizex + VIDEO_FONT_HEIGHT);
61 dst += (pcons->lcdsizex + VIDEO_FONT_HEIGHT);
64 static void lcd_putc_xy180(struct console_t *pcons, ushort x, ushort y, char c)
66 int fg_color = lcd_getfgcolor();
67 int bg_color = lcd_getbgcolor();
69 fbptr_t *dst = (fbptr_t *)pcons->fbbase +
71 pcons->lcdsizey * pcons->lcdsizex -
75 for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
76 uchar bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
78 for (i = 0; i < VIDEO_FONT_WIDTH; ++i) {
79 *dst-- = (bits & 0x80) ? fg_color : bg_color;
82 dst -= (pcons->lcdsizex - VIDEO_FONT_WIDTH);
86 static inline void console_setrow180(struct console_t *pcons, u32 row, int clr)
89 fbptr_t *dst = (fbptr_t *)pcons->fbbase +
90 (pcons->rows-row-1) * VIDEO_FONT_HEIGHT *
93 for (i = 0; i < (VIDEO_FONT_HEIGHT * pcons->lcdsizex); i++)
97 static inline void console_moverow180(struct console_t *pcons,
98 u32 rowdst, u32 rowsrc)
101 fbptr_t *dst = (fbptr_t *)pcons->fbbase +
102 (pcons->rows-rowdst-1) * VIDEO_FONT_HEIGHT *
105 fbptr_t *src = (fbptr_t *)pcons->fbbase +
106 (pcons->rows-rowsrc-1) * VIDEO_FONT_HEIGHT *
109 for (i = 0; i < (VIDEO_FONT_HEIGHT * pcons->lcdsizex); i++)
113 static void lcd_putc_xy270(struct console_t *pcons, ushort x, ushort y, char c)
115 int fg_color = lcd_getfgcolor();
116 int bg_color = lcd_getbgcolor();
118 fbptr_t *dst = (fbptr_t *)pcons->fbbase +
119 pcons->lcdsizey * pcons->lcdsizex -
120 (x+1) * pcons->lcdsizex +
124 uchar *pfont = video_fontdata + c * VIDEO_FONT_HEIGHT;
125 for (col = 0; col < VIDEO_FONT_WIDTH; ++col) {
126 for (i = 0; i < VIDEO_FONT_HEIGHT; ++i)
127 *dst++ = (*(pfont + i) & msk) ? fg_color : bg_color;
129 dst -= (pcons->lcdsizex + VIDEO_FONT_HEIGHT);
133 static inline void console_setrow270(struct console_t *pcons, u32 row, int clr)
136 fbptr_t *dst = (fbptr_t *)pcons->fbbase +
137 row*VIDEO_FONT_HEIGHT;
139 for (j = 0; j < pcons->lcdsizey; j++) {
140 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
142 dst += (pcons->lcdsizex - VIDEO_FONT_HEIGHT);
146 static inline void console_moverow270(struct console_t *pcons,
147 u32 rowdst, u32 rowsrc)
150 fbptr_t *dst = (fbptr_t *)pcons->fbbase +
151 rowdst*VIDEO_FONT_HEIGHT;
153 fbptr_t *src = (fbptr_t *)pcons->fbbase +
154 rowsrc*VIDEO_FONT_HEIGHT;
156 for (j = 0; j < pcons->lcdsizey; j++) {
157 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
159 src += (pcons->lcdsizex - VIDEO_FONT_HEIGHT);
160 dst += (pcons->lcdsizex - VIDEO_FONT_HEIGHT);
164 static void console_calc_rowcol_rot(struct console_t *pcons)
166 if (pcons->lcdrot == 1 || pcons->lcdrot == 3)
167 console_calc_rowcol(pcons, pcons->lcdsizey, pcons->lcdsizex);
169 console_calc_rowcol(pcons, pcons->lcdsizex, pcons->lcdsizey);
172 void lcd_init_console_rot(struct console_t *pcons)
174 if (pcons->lcdrot == 0) {
176 } else if (pcons->lcdrot == 1) {
177 pcons->fp_putc_xy = &lcd_putc_xy90;
178 pcons->fp_console_moverow = &console_moverow90;
179 pcons->fp_console_setrow = &console_setrow90;
180 } else if (pcons->lcdrot == 2) {
181 pcons->fp_putc_xy = &lcd_putc_xy180;
182 pcons->fp_console_moverow = &console_moverow180;
183 pcons->fp_console_setrow = &console_setrow180;
184 } else if (pcons->lcdrot == 3) {
185 pcons->fp_putc_xy = &lcd_putc_xy270;
186 pcons->fp_console_moverow = &console_moverow270;
187 pcons->fp_console_setrow = &console_setrow270;
189 printf("%s: invalid framebuffer rotation (%d)!\n",
190 __func__, pcons->lcdrot);
193 console_calc_rowcol_rot(pcons);