3 * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
5 * SPDX-License-Identifier: GPL-2.0+
10 #include <video_font.h> /* Get font data, width and height */
12 static void lcd_putc_xy90(struct console_t *pcons, ushort x, ushort y, char c)
14 int fg_color = lcd_getfgcolor();
15 int bg_color = lcd_getbgcolor();
18 fbptr_t *dst = (fbptr_t *)pcons->fbbase +
19 (x+1) * pcons->lcdsizex -
23 uchar *pfont = video_fontdata + c * VIDEO_FONT_HEIGHT;
24 for (col = 0; col < VIDEO_FONT_WIDTH; ++col) {
25 for (i = 0; i < VIDEO_FONT_HEIGHT; ++i)
26 *dst-- = (*(pfont + i) & msk) ? fg_color : bg_color;
28 dst += (pcons->lcdsizex + VIDEO_FONT_HEIGHT);
32 static inline void console_setrow90(struct console_t *pcons, u32 row, int clr)
35 fbptr_t *dst = (fbptr_t *)pcons->fbbase +
37 row*VIDEO_FONT_HEIGHT+1;
39 for (j = 0; j < pcons->lcdsizey; j++) {
40 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
42 dst += (pcons->lcdsizex + VIDEO_FONT_HEIGHT);
46 static inline void console_moverow90(struct console_t *pcons,
47 u32 rowdst, u32 rowsrc)
50 fbptr_t *dst = (fbptr_t *)pcons->fbbase +
52 (rowdst*VIDEO_FONT_HEIGHT+1);
54 fbptr_t *src = (fbptr_t *)pcons->fbbase +
56 (rowsrc*VIDEO_FONT_HEIGHT+1);
58 for (j = 0; j < pcons->lcdsizey; j++) {
59 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
61 src += (pcons->lcdsizex + VIDEO_FONT_HEIGHT);
62 dst += (pcons->lcdsizex + VIDEO_FONT_HEIGHT);
65 static void lcd_putc_xy180(struct console_t *pcons, ushort x, ushort y, char c)
67 int fg_color = lcd_getfgcolor();
68 int bg_color = lcd_getbgcolor();
70 fbptr_t *dst = (fbptr_t *)pcons->fbbase +
72 pcons->lcdsizey * pcons->lcdsizex -
76 for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
77 uchar bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
79 for (i = 0; i < VIDEO_FONT_WIDTH; ++i) {
80 *dst-- = (bits & 0x80) ? fg_color : bg_color;
83 dst -= (pcons->lcdsizex - VIDEO_FONT_WIDTH);
87 static inline void console_setrow180(struct console_t *pcons, u32 row, int clr)
90 fbptr_t *dst = (fbptr_t *)pcons->fbbase +
91 (pcons->rows-row-1) * VIDEO_FONT_HEIGHT *
94 for (i = 0; i < (VIDEO_FONT_HEIGHT * pcons->lcdsizex); i++)
98 static inline void console_moverow180(struct console_t *pcons,
99 u32 rowdst, u32 rowsrc)
102 fbptr_t *dst = (fbptr_t *)pcons->fbbase +
103 (pcons->rows-rowdst-1) * VIDEO_FONT_HEIGHT *
106 fbptr_t *src = (fbptr_t *)pcons->fbbase +
107 (pcons->rows-rowsrc-1) * VIDEO_FONT_HEIGHT *
110 for (i = 0; i < (VIDEO_FONT_HEIGHT * pcons->lcdsizex); i++)
114 static void lcd_putc_xy270(struct console_t *pcons, ushort x, ushort y, char c)
116 int fg_color = lcd_getfgcolor();
117 int bg_color = lcd_getbgcolor();
119 fbptr_t *dst = (fbptr_t *)pcons->fbbase +
120 pcons->lcdsizey * pcons->lcdsizex -
121 (x+1) * pcons->lcdsizex +
125 uchar *pfont = video_fontdata + c * VIDEO_FONT_HEIGHT;
126 for (col = 0; col < VIDEO_FONT_WIDTH; ++col) {
127 for (i = 0; i < VIDEO_FONT_HEIGHT; ++i)
128 *dst++ = (*(pfont + i) & msk) ? fg_color : bg_color;
130 dst -= (pcons->lcdsizex + VIDEO_FONT_HEIGHT);
134 static inline void console_setrow270(struct console_t *pcons, u32 row, int clr)
137 fbptr_t *dst = (fbptr_t *)pcons->fbbase +
138 row*VIDEO_FONT_HEIGHT;
140 for (j = 0; j < pcons->lcdsizey; j++) {
141 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
143 dst += (pcons->lcdsizex - VIDEO_FONT_HEIGHT);
147 static inline void console_moverow270(struct console_t *pcons,
148 u32 rowdst, u32 rowsrc)
151 fbptr_t *dst = (fbptr_t *)pcons->fbbase +
152 rowdst*VIDEO_FONT_HEIGHT;
154 fbptr_t *src = (fbptr_t *)pcons->fbbase +
155 rowsrc*VIDEO_FONT_HEIGHT;
157 for (j = 0; j < pcons->lcdsizey; j++) {
158 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
160 src += (pcons->lcdsizex - VIDEO_FONT_HEIGHT);
161 dst += (pcons->lcdsizex - VIDEO_FONT_HEIGHT);
165 static void console_calc_rowcol_rot(struct console_t *pcons)
167 if (pcons->lcdrot == 1 || pcons->lcdrot == 3)
168 console_calc_rowcol(pcons, pcons->lcdsizey, pcons->lcdsizex);
170 console_calc_rowcol(pcons, pcons->lcdsizex, pcons->lcdsizey);
173 void lcd_init_console_rot(struct console_t *pcons)
175 if (pcons->lcdrot == 0) {
177 } else if (pcons->lcdrot == 1) {
178 pcons->fp_putc_xy = &lcd_putc_xy90;
179 pcons->fp_console_moverow = &console_moverow90;
180 pcons->fp_console_setrow = &console_setrow90;
181 } else if (pcons->lcdrot == 2) {
182 pcons->fp_putc_xy = &lcd_putc_xy180;
183 pcons->fp_console_moverow = &console_moverow180;
184 pcons->fp_console_setrow = &console_setrow180;
185 } else if (pcons->lcdrot == 3) {
186 pcons->fp_putc_xy = &lcd_putc_xy270;
187 pcons->fp_console_moverow = &console_moverow270;
188 pcons->fp_console_setrow = &console_setrow270;
190 printf("%s: invalid framebuffer rotation (%d)!\n",
191 __func__, pcons->lcdrot);
194 console_calc_rowcol_rot(pcons);