console patch (thanks to inmarket for helping)

ugfx_release_2.6
Tectu 2012-08-24 11:37:47 +02:00
parent a0162b98c8
commit 580c00b8f8
1 changed files with 180 additions and 175 deletions

View File

@ -1,175 +1,180 @@
/* /*
ChibiOS/RT - Copyright (C) 2012 ChibiOS/RT - Copyright (C) 2012
Joel Bodenmann aka Tectu <joel@unormal.org> Joel Bodenmann aka Tectu <joel@unormal.org>
This file is part of ChibiOS-LCD-Driver. This file is part of ChibiOS-LCD-Driver.
ChibiOS-LCD-Driver is free software; you can redistribute it and/or modify ChibiOS-LCD-Driver is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or the Free Software Foundation; either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
ChibiOS-LCD-Driver is distributed in the hope that it will be useful, ChibiOS-LCD-Driver is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "ch.h" #include "ch.h"
#include "hal.h" #include "hal.h"
#include "gdisp.h" #include "gdisp.h"
#include "gdisp_fonts.h" #include "console.h"
#include "console.h"
/*
#if defined(GDISP_NEED_SCROLL) * Interface implementation. The interface is write only
*/
/* static size_t writes(void *ip, const uint8_t *bp, size_t n) {
* Interface implementation. The interface is write only return lcdConsoleWrite((GLCDConsole *)ip, bp, n);
*/ }
static size_t writes(void *ip, const uint8_t *bp, size_t n) {
return lcdConsoleWrite((GLCDConsole *)ip, bp, n); static size_t reads(void *ip, uint8_t *bp, size_t n) {
} (void)ip;
(void)bp;
static size_t reads(void *ip, uint8_t *bp, size_t n) { (void)n;
(void)ip;
(void)bp; return 0;
(void)n; }
return 0; static msg_t put(void *ip, uint8_t b) {
} return lcdConsolePut((GLCDConsole *)ip, (char)b);
}
static msg_t put(void *ip, uint8_t b) {
return lcdConsolePut((GLCDConsole *)ip, (char)b); static msg_t get(void *ip) {
} (void)ip;
static msg_t get(void *ip) { return RDY_OK;
(void)ip; }
return RDY_OK; static msg_t putt(void *ip, uint8_t b, systime_t timeout) {
} (void)timeout;
static msg_t putt(void *ip, uint8_t b, systime_t timeout) { /* TODO: handle timeout */
(void)timeout;
return lcdConsolePut((GLCDConsole *)ip, (char)b);
/* TODO: handle timeout */ }
return lcdConsolePut((GLCDConsole *)ip, (char)b); static msg_t gett(void *ip, systime_t timeout) {
} (void)ip;
(void)timeout;
static msg_t gett(void *ip, systime_t timeout) {
(void)ip; return RDY_OK;
(void)timeout; }
return RDY_OK; static size_t writet(void *ip, const uint8_t *bp, size_t n, systime_t time) {
} (void)time;
static size_t writet(void *ip, const uint8_t *bp, size_t n, systime_t time) { return lcdConsoleWrite((GLCDConsole *)ip, bp, n);
(void)time; }
return lcdConsoleWrite((GLCDConsole *)ip, bp, n); static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) {
} (void)ip;
(void)bp;
static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) { (void)n;
(void)ip; (void)time;
(void)bp;
(void)n; return 0;
(void)time; }
return 0; static uint16_t getflags(void *ip) {
} _chn_get_and_clear_flags_impl(ip);
}
static uint16_t getflags(void *ip) {
_chn_get_and_clear_flags_impl(ip); static const struct GLCDConsoleVMT vmt = {
} writes, reads, put, get,
putt, gett, writet, readt,
static const struct GLCDConsoleVMT vmt = { getflags
writes, reads, put, get, };
putt, gett, writet, readt,
getflags
}; msg_t lcdConsoleInit(GLCDConsole *console, coord_t x0, coord_t y0, coord_t width, coord_t height, font_t font, pixel_t bkcolor, pixel_t color) {
const uint8_t* ptr;
uint16_t chi;
msg_t lcdConsoleInit(GLCDConsole *console, coord_t x0, coord_t y0, coord_t width, coord_t height, font_t font, pixel_t bkcolor, pixel_t color) { uint16_t x,y;
const uint8_t* ptr;
uint16_t chi; console->vmt = &vmt;
uint16_t x,y; /* read font, get height */
console->fy = gdispGetFontMetric(font, fontHeight);
console->vmt = &vmt;
/* read font, get height */ /* calculate the size of the console as an integer multiple of characters height*/
console->fy = font->height; console->sx = width;
console->sy = (((int16_t)(height/console->fy))-1)*console->fy;
/* calculate the size of the console as an integer multiple of characters height*/
console->sx = width; console->cx = 0;
console->sy = (((int16_t)(height/console->fy))-1)*console->fy; console->cy = 0;
console->x0 = x0;
console->cx = 0; console->y0 = y0;
console->cy = 0;
console->x0 = x0; console->bkcolor = bkcolor;
console->y0 = y0; console->color = color;
console->bkcolor = bkcolor; console->font = font;
console->color = color;
gdispFillArea(x0, y0, x0 + width, y0 + height, console->bkcolor);
console->font = font; return RDY_OK;
}
gdispFillArea(x0, y0, x0 + width, y0 + height, console->bkcolor);
return RDY_OK; msg_t lcdConsolePut(GLCDConsole *console, char c) {
} uint8_t width;
msg_t lcdConsolePut(GLCDConsole *console, char c) { if(c == '\n') {
uint8_t width; /* clear the text at the end of the line */
if(console->cx < console->sx)
if(c == '\n') { gdispFillArea(console->x0 + console->cx, console->y0 + console->cy,
/* clear the text at the end of the line */ console->sx - console->cx, console->fy,
if(console->cx < console->sx) console->bkcolor);
gdispFillArea(console->x0 + console->cx, console->y0 + console->cy, console->cx = 0;
console->x0 + console->sx, console->y0 + console->cy + console->fy, console->cy += console->fy;
console->bkcolor); } else if(c == '\r') {
console->cx = 0; /* TODO: work backwards through the buffer to the start of the current line */
console->cy += console->fy; //console->cx = 0;
} else if(c == '\r') { } else {
/* TODO: work backwards through the buffer to the start of the current line */ width = gdispGetCharWidth(c, console->font) + gdispGetFontMetric(console->font, fontCharPadding);
//console->cx = 0; if((console->cx + width) >= console->sx) {
} else { /* clear the text at the end of the line */
width = _getCharWidth(console->font, c); if (console->cy <= console->sy)
if((console->cx + width) >= console->sx) { gdispFillArea(console->x0 + console->cx, console->y0 + console->cy,
/* clear the text at the end of the line */ console->sx - (console->cx + width), console->fy,
gdispFillArea(console->x0 + console->cx, console->y0 + console->cy, console->bkcolor);
console->x0 + console->cx + width, console->y0 + console->cy + console->fy, console->cx = 0;
console->bkcolor); console->cy += console->fy;
console->cx = 0; }
console->cy += console->fy;
} if((console->cy > console->sy)) {
#if GDISP_NEED_SCROLL
if((console->cy > console->sy)) { /* scroll the console */
/* scroll the screen */ gdispVerticalScroll(console->x0, console->y0, console->sx,
gdispVerticalScroll(console->x0, console->y0, console->x0 + console->sx, console->sy + console->fy, console->fy, console->bkcolor);
console->y0 + console->sy + console->fy, console->fy, console->bkcolor); /* reset the cursor to the start of the line */
/* reset the cursor */ console->cx = 0;
console->cx = 0; console->cy = console->sy;
console->cy = console->sy; #else
} /* clear the console */
gdispFillArea(console->x0, console->y0,
gdispDrawChar(console->x0 + console->cx, console->y0 + console->cy, c, console->sx, console->sy + console->fy,
console->font, console->color); console->bkcolor);
/* reset the cursor to the top of the console */
/* update cursor */ console->cx = 0;
console->cx += width; console->cy = 0;
} #endif
return RDY_OK; }
}
gdispDrawChar(console->x0 + console->cx, console->y0 + console->cy, c,
msg_t lcdConsoleWrite(GLCDConsole *console, char *bp, size_t n) { console->font, console->color);
size_t i;
for(i = 0; i < n; i++) /* update cursor */
lcdConsolePut(console, bp[i]); console->cx += width;
}
return RDY_OK; return RDY_OK;
} }
msg_t lcdConsoleWrite(GLCDConsole *console, char *bp, size_t n) {
#endif /* GDISP_NEED_SCROLL */ size_t i;
for(i = 0; i < n; i++)
lcdConsolePut(console, bp[i]);
return RDY_OK;
}