lcd_console_rotation.c 5.19 KB
Newer Older
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
/*
 * (C) Copyright 2015
 * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

#include <common.h>
#include <lcd.h>
#include <video_font.h>		/* Get font data, width and height */

static void lcd_putc_xy90(struct console_t *pcons, ushort x, ushort y, char c)
{
	int fg_color = lcd_getfgcolor();
	int bg_color = lcd_getbgcolor();
	int col, i;

	fbptr_t *dst = (fbptr_t *)pcons->fbbase +
				  (x+1) * pcons->lcdsizex -
				  y;

	uchar msk = 0x80;
	uchar *pfont = video_fontdata + c * VIDEO_FONT_HEIGHT;
	for (col = 0; col < VIDEO_FONT_WIDTH; ++col) {
		for (i = 0; i < VIDEO_FONT_HEIGHT; ++i)
			*dst-- = (*(pfont + i) & msk) ? fg_color : bg_color;
		msk >>= 1;
		dst += (pcons->lcdsizex + VIDEO_FONT_HEIGHT);
	}
}

static inline void console_setrow90(struct console_t *pcons, u32 row, int clr)
{
	int i, j;
	fbptr_t *dst = (fbptr_t *)pcons->fbbase +
				  pcons->lcdsizex -
				  row*VIDEO_FONT_HEIGHT+1;

	for (j = 0; j < pcons->lcdsizey; j++) {
		for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
			*dst-- = clr;
		dst += (pcons->lcdsizex + VIDEO_FONT_HEIGHT);
	}
}

static inline void console_moverow90(struct console_t *pcons,
				      u32 rowdst, u32 rowsrc)
{
	int i, j;
	fbptr_t *dst = (fbptr_t *)pcons->fbbase +
				  pcons->lcdsizex -
				  (rowdst*VIDEO_FONT_HEIGHT+1);

	fbptr_t *src = (fbptr_t *)pcons->fbbase +
				  pcons->lcdsizex -
				  (rowsrc*VIDEO_FONT_HEIGHT+1);

	for (j = 0; j < pcons->lcdsizey; j++) {
		for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
			*dst-- = *src--;
		src += (pcons->lcdsizex + VIDEO_FONT_HEIGHT);
		dst += (pcons->lcdsizex + VIDEO_FONT_HEIGHT);
	}
}
static void lcd_putc_xy180(struct console_t *pcons, ushort x, ushort y, char c)
{
	int fg_color = lcd_getfgcolor();
	int bg_color = lcd_getbgcolor();
	int i, row;
	fbptr_t *dst = (fbptr_t *)pcons->fbbase +
				  pcons->lcdsizex +
				  pcons->lcdsizey * pcons->lcdsizex -
				  y * pcons->lcdsizex -
				  (x+1);

	for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
		uchar bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];

		for (i = 0; i < VIDEO_FONT_WIDTH; ++i) {
			*dst-- = (bits & 0x80) ? fg_color : bg_color;
			bits <<= 1;
		}
		dst -= (pcons->lcdsizex - VIDEO_FONT_WIDTH);
	}
}

static inline void console_setrow180(struct console_t *pcons, u32 row, int clr)
{
	int i;
	fbptr_t *dst = (fbptr_t *)pcons->fbbase +
				  (pcons->rows-row-1) * VIDEO_FONT_HEIGHT *
				  pcons->lcdsizex;

	for (i = 0; i < (VIDEO_FONT_HEIGHT * pcons->lcdsizex); i++)
		*dst++ = clr;
}

static inline void console_moverow180(struct console_t *pcons,
				      u32 rowdst, u32 rowsrc)
{
	int i;
	fbptr_t *dst = (fbptr_t *)pcons->fbbase +
				  (pcons->rows-rowdst-1) * VIDEO_FONT_HEIGHT *
				  pcons->lcdsizex;

	fbptr_t *src = (fbptr_t *)pcons->fbbase +
				  (pcons->rows-rowsrc-1) * VIDEO_FONT_HEIGHT *
				  pcons->lcdsizex;

	for (i = 0; i < (VIDEO_FONT_HEIGHT * pcons->lcdsizex); i++)
		*dst++ = *src++;
}

static void lcd_putc_xy270(struct console_t *pcons, ushort x, ushort y, char c)
{
	int fg_color = lcd_getfgcolor();
	int bg_color = lcd_getbgcolor();
	int i, col;
	fbptr_t *dst = (fbptr_t *)pcons->fbbase +
				  pcons->lcdsizey * pcons->lcdsizex -
				  (x+1) * pcons->lcdsizex +
				  y;

	uchar msk = 0x80;
	uchar *pfont = video_fontdata + c * VIDEO_FONT_HEIGHT;
	for (col = 0; col < VIDEO_FONT_WIDTH; ++col) {
		for (i = 0; i < VIDEO_FONT_HEIGHT; ++i)
			*dst++ = (*(pfont + i) & msk) ? fg_color : bg_color;
		msk >>= 1;
		dst -= (pcons->lcdsizex + VIDEO_FONT_HEIGHT);
	}
}

static inline void console_setrow270(struct console_t *pcons, u32 row, int clr)
{
	int i, j;
	fbptr_t *dst = (fbptr_t *)pcons->fbbase +
				  row*VIDEO_FONT_HEIGHT;

	for (j = 0; j < pcons->lcdsizey; j++) {
		for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
			*dst++ = clr;
		dst += (pcons->lcdsizex - VIDEO_FONT_HEIGHT);
	}
}

static inline void console_moverow270(struct console_t *pcons,
				     u32 rowdst, u32 rowsrc)
{
	int i, j;
	fbptr_t *dst = (fbptr_t *)pcons->fbbase +
				  rowdst*VIDEO_FONT_HEIGHT;

	fbptr_t *src = (fbptr_t *)pcons->fbbase +
				  rowsrc*VIDEO_FONT_HEIGHT;

	for (j = 0; j < pcons->lcdsizey; j++) {
		for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
			*dst++ = *src++;
		src += (pcons->lcdsizex - VIDEO_FONT_HEIGHT);
		dst += (pcons->lcdsizex - VIDEO_FONT_HEIGHT);
	}
}

static void console_calc_rowcol_rot(struct console_t *pcons)
{
	if (pcons->lcdrot == 1 || pcons->lcdrot == 3)
		console_calc_rowcol(pcons, pcons->lcdsizey, pcons->lcdsizex);
	else
		console_calc_rowcol(pcons, pcons->lcdsizex, pcons->lcdsizey);
}

void lcd_init_console_rot(struct console_t *pcons)
{
	if (pcons->lcdrot == 0) {
		return;
	} else if (pcons->lcdrot == 1) {
		pcons->fp_putc_xy = &lcd_putc_xy90;
		pcons->fp_console_moverow = &console_moverow90;
		pcons->fp_console_setrow = &console_setrow90;
	} else if (pcons->lcdrot == 2) {
		pcons->fp_putc_xy = &lcd_putc_xy180;
		pcons->fp_console_moverow = &console_moverow180;
		pcons->fp_console_setrow = &console_setrow180;
	} else if (pcons->lcdrot == 3) {
		pcons->fp_putc_xy = &lcd_putc_xy270;
		pcons->fp_console_moverow = &console_moverow270;
		pcons->fp_console_setrow = &console_setrow270;
	} else {
		printf("%s: invalid framebuffer rotation (%d)!\n",
		       __func__, pcons->lcdrot);
		return;
	}
	console_calc_rowcol_rot(pcons);
}