more console work
This commit is contained in:
parent
7f306bab76
commit
c10f54e5af
4 changed files with 71 additions and 49 deletions
33
console.c
33
console.c
|
@ -71,8 +71,8 @@ static const struct GLCDConsoleVMT vmt = {
|
|||
};
|
||||
|
||||
|
||||
msg_t lcdConsoleInit(GLCDConsole *console, uint16_t x0, uint16_t y0, uint16_t x1,
|
||||
uint16_t y1, font_t font, uint8_t *buffer, uint16_t bkcolor, uint16_t color) {
|
||||
msg_t lcdConsoleInit(GLCDConsole *console, uint16_t x0, uint16_t y0, uint16_t width, uint16_t height,
|
||||
font_t font, uint16_t bkcolor, uint16_t color) {
|
||||
const uint8_t* ptr;
|
||||
uint16_t chi;
|
||||
uint16_t x,y;
|
||||
|
@ -81,21 +81,15 @@ msg_t lcdConsoleInit(GLCDConsole *console, uint16_t x0, uint16_t y0, uint16_t x1
|
|||
/* read font, get height */
|
||||
console->fy = font[FONT_TABLE_HEIGHT_IDX];
|
||||
|
||||
|
||||
/* calculate the size of the console in characters */
|
||||
console->sx = (x1-x0);
|
||||
console->sy = (((int16_t)((y1-y0)/console->fy))-1)*console->fy;
|
||||
/* calculate the size of the console as an integer multiple of characters */
|
||||
console->sx = width;
|
||||
console->sy = (((int16_t)(height/console->fy))-1)*console->fy;
|
||||
|
||||
console->cx = 0;
|
||||
console->cy = 0;
|
||||
console->x0 = x0;
|
||||
console->y0 = y0;
|
||||
|
||||
console->buf = buffer;
|
||||
console->wptr = 0;
|
||||
console->blen = console->sx*console->sy;
|
||||
console->bstrt = 0;
|
||||
|
||||
console->bkcolor = bkcolor;
|
||||
console->color = color;
|
||||
|
||||
|
@ -104,8 +98,6 @@ msg_t lcdConsoleInit(GLCDConsole *console, uint16_t x0, uint16_t y0, uint16_t x1
|
|||
|
||||
msg_t lcdConsolePut(GLCDConsole *console, char c) {
|
||||
uint8_t width;
|
||||
bool_t newline = FALSE;
|
||||
|
||||
|
||||
if(c == '\n') {
|
||||
/* clear the text at the end of the line */
|
||||
|
@ -120,26 +112,19 @@ msg_t lcdConsolePut(GLCDConsole *console, char c) {
|
|||
} else {
|
||||
width = lcdMeasureChar(c, console->font);
|
||||
if((console->cx + width) >= console->sx) {
|
||||
chprintf(&SD1, "[1] ");
|
||||
console->cx = 0;
|
||||
console->cy += console->fy;
|
||||
}
|
||||
|
||||
if(
|
||||
(console->cy > console->sy)) {
|
||||
chprintf(&SD1, "[2] ");
|
||||
if(newline)
|
||||
chprintf(&SD1, "* ");
|
||||
if((console->cy > console->sy)) {
|
||||
|
||||
lcdVerticalScroll(console->x0, console->y0, console->x0 + console->sx,
|
||||
console->y0 + console->sy, console->fy);
|
||||
console->y0 + console->sy + console->fy, console->fy);
|
||||
/* reset the cursor */
|
||||
console->cx = 0;
|
||||
console->cy = console->sy;
|
||||
} else if(newline) {
|
||||
chprintf(&SD1, "[3] ");
|
||||
console->cy += console->fy;
|
||||
}
|
||||
//chprintf(&SD1, "'%c' at [%d, %d]\r\n", c, console->x0 + console->cx, console->y0 + console->cy);
|
||||
|
||||
lcdDrawChar(console->x0 + console->cx, console->y0 + console->cy, c,
|
||||
console->font, console->color, console->bkcolor, solid);
|
||||
|
||||
|
|
|
@ -35,8 +35,6 @@ struct GLCDConsole {
|
|||
const struct GLCDConsoleVMT *vmt;
|
||||
_base_asynchronous_channel_data
|
||||
/* WARNING: Do not add any data to this struct above this comment, only below */
|
||||
/* text buffer */
|
||||
uint8_t *buf;
|
||||
/* font */
|
||||
font_t font;
|
||||
/* lcd area to use */
|
||||
|
@ -49,16 +47,14 @@ struct GLCDConsole {
|
|||
uint16_t bkcolor, color;
|
||||
/* font size in pixels */
|
||||
uint8_t fy;
|
||||
/* buffer index */
|
||||
uint16_t wptr, blen, bstrt;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
msg_t lcdConsoleInit(GLCDConsole *console, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
|
||||
font_t font, uint8_t *buffer, uint16_t bkcolor, uint16_t color);
|
||||
msg_t lcdConsoleInit(GLCDConsole *console, uint16_t x0, uint16_t y0, uint16_t width, uint16_t height,
|
||||
font_t font, uint16_t bkcolor, uint16_t color);
|
||||
|
||||
msg_t lcdConsolePut(GLCDConsole *console, char c);
|
||||
msg_t lcdConsoleWrite(GLCDConsole *console, uint8_t *bp, size_t n);
|
||||
|
|
|
@ -92,6 +92,25 @@ __inline void lld_lcdWriteStream(uint16_t *buffer, uint16_t size) {
|
|||
}
|
||||
}
|
||||
|
||||
__inline void lld_lcdReadStreamStart(void) {
|
||||
Clr_CS
|
||||
lld_lcdWriteIndex(0x0022);
|
||||
}
|
||||
|
||||
__inline void lld_lcdReadStreamStop(void) {
|
||||
Set_CS;
|
||||
}
|
||||
|
||||
__inline void lld_lcdReadStream(uint16_t *buffer, size_t size) {
|
||||
uint16_t i;
|
||||
/* throw away first value read */
|
||||
volatile uint16_t dummy = LCD_RAM;
|
||||
|
||||
for(i = 0; i < size; i++) {
|
||||
buffer[i] = LCD_RAM;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef LCD_USE_FSMC
|
||||
|
@ -118,6 +137,7 @@ static __inline uint16_t lld_lcdReadData(void) {
|
|||
|
||||
static __inline uint16_t lld_lcdReadReg(uint16_t lcdReg) {
|
||||
LCD_REG = lcdReg;
|
||||
volatile uint16_t dummy = LCD_RAM;
|
||||
return (LCD_RAM);
|
||||
}
|
||||
|
||||
|
@ -145,6 +165,9 @@ __inline void lld_lcdReadStreamStop(void) {
|
|||
|
||||
__inline void lld_lcdReadStream(uint16_t *buffer, size_t size) {
|
||||
uint16_t i;
|
||||
/* throw away first value read */
|
||||
volatile uint16_t dummy = LCD_RAM;
|
||||
|
||||
for(i = 0; i < size; i++) {
|
||||
buffer[i] = LCD_RAM;
|
||||
}
|
||||
|
@ -162,6 +185,18 @@ static __inline void lcdDelay(uint16_t us) {
|
|||
|
||||
|
||||
void lld_lcdSetCursor(uint16_t x, uint16_t y) {
|
||||
/* Reg 0x004E is an 8 bit value
|
||||
* Reg 0x004F is 8 bit
|
||||
*/
|
||||
/*
|
||||
* if(PORTRAIT) {
|
||||
lld_lcdWriteReg(0x004e, x & 0x00FF);
|
||||
lld_lcdWriteReg(0x004f, y & 0x01FF);
|
||||
} else if(LANDSCAPE) {
|
||||
lld_lcdWriteReg(0x004e, y & 0x00FF);
|
||||
lld_lcdWriteReg(0x004f, x & 0x01FF);
|
||||
}
|
||||
*/
|
||||
if(PORTRAIT) {
|
||||
lld_lcdWriteReg(0x004e, x);
|
||||
lld_lcdWriteReg(0x004f, y);
|
||||
|
@ -205,26 +240,35 @@ void lld_lcdSetOrientation(uint8_t newOrientation) {
|
|||
void lld_lcdSetWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
|
||||
lld_lcdSetCursor(x0, y0);
|
||||
|
||||
/* Reg 0x44 - Horizontal RAM address position
|
||||
* Upper Byte - HEA
|
||||
* Lower Byte - HSA
|
||||
* 0 <= HSA <= HEA <= 0xEF
|
||||
* Reg 0x45,0x46 - Vertical RAM address position
|
||||
* Lower 9 bits gives 0-511 range in each value
|
||||
* 0 <= Reg(0x45) <= Reg(0x46) <= 0x13F
|
||||
*/
|
||||
|
||||
switch(lcdGetOrientation()) {
|
||||
case portrait:
|
||||
lld_lcdWriteReg(0x44, ((x1-1) << 8) | x0);
|
||||
lld_lcdWriteReg(0x44, (((x1-1) << 8) ) | (x0 ));
|
||||
lld_lcdWriteReg(0x45, y0);
|
||||
lld_lcdWriteReg(0x46, y1-1);
|
||||
lld_lcdWriteReg(0x46, (y1-1));
|
||||
break;
|
||||
case landscape:
|
||||
lld_lcdWriteReg(0x44, ((y1-1) << 8) | y1);
|
||||
lld_lcdWriteReg(0x45, x0);
|
||||
lld_lcdWriteReg(0x46, x1-1);
|
||||
lld_lcdWriteReg(0x44, (((y1-1) << 8) & 0xFF00) | (y1 & 0x00FF));
|
||||
lld_lcdWriteReg(0x45, x0 & 0x01FF);
|
||||
lld_lcdWriteReg(0x46, (x1-1) & 0x01FF);
|
||||
break;
|
||||
case portraitInv:
|
||||
lld_lcdWriteReg(0x44, ((x1-1) << 8) | x0);
|
||||
lld_lcdWriteReg(0x45, y0);
|
||||
lld_lcdWriteReg(0x46, y1-1);
|
||||
lld_lcdWriteReg(0x44, (((x1-1) << 8) & 0xFF00) | (x0 & 0x00FF));
|
||||
lld_lcdWriteReg(0x45, y0 & 0x01FF);
|
||||
lld_lcdWriteReg(0x46, (y1-1) & 0x01FF);
|
||||
break;
|
||||
case landscapeInv:
|
||||
lld_lcdWriteReg(0x44, ((y1-1) << 8) | y1);
|
||||
lld_lcdWriteReg(0x45, x0);
|
||||
lld_lcdWriteReg(0x46, x1-1);
|
||||
lld_lcdWriteReg(0x44, (((y1-1) << 8) & 0xFF00) | (y1 & 0x00FF));
|
||||
lld_lcdWriteReg(0x45, x0 & 0x01FF);
|
||||
lld_lcdWriteReg(0x46, (x1-1) & 0x01FF);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -366,6 +410,7 @@ void lld_lcdVerticalScroll(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, i
|
|||
row0 = (y1 - i - 1) + lines;
|
||||
row1 = (y1 - i - 1);
|
||||
}
|
||||
|
||||
/* read row0 into the buffer and then write at row1*/
|
||||
lld_lcdSetWindow(x0, row0, x1, row0);
|
||||
lld_lcdReadStreamStart();
|
||||
|
|
6
glcd.c
6
glcd.c
|
@ -191,11 +191,7 @@ int lcdDrawChar(uint16_t cx, uint16_t cy, char c, font_t font, uint16_t color, u
|
|||
|
||||
/* Return the width of the character, we need it so that lcdDrawString may work
|
||||
* We don't have a static address counter */
|
||||
|
||||
/* Abhishek: what should padAfter be?
|
||||
* return charWidth+padAfter;
|
||||
*/
|
||||
return charWidth;
|
||||
return charWidth + padAfterChar;
|
||||
}
|
||||
|
||||
/* WARNING: No boundary checks! Unpredictable behaviour if text exceeds boundary */
|
||||
|
|
Loading…
Add table
Reference in a new issue