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,
|
msg_t lcdConsoleInit(GLCDConsole *console, uint16_t x0, uint16_t y0, uint16_t width, uint16_t height,
|
||||||
uint16_t y1, font_t font, uint8_t *buffer, uint16_t bkcolor, uint16_t color) {
|
font_t font, uint16_t bkcolor, uint16_t color) {
|
||||||
const uint8_t* ptr;
|
const uint8_t* ptr;
|
||||||
uint16_t chi;
|
uint16_t chi;
|
||||||
uint16_t x,y;
|
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 */
|
/* read font, get height */
|
||||||
console->fy = font[FONT_TABLE_HEIGHT_IDX];
|
console->fy = font[FONT_TABLE_HEIGHT_IDX];
|
||||||
|
|
||||||
|
/* calculate the size of the console as an integer multiple of characters */
|
||||||
/* calculate the size of the console in characters */
|
console->sx = width;
|
||||||
console->sx = (x1-x0);
|
console->sy = (((int16_t)(height/console->fy))-1)*console->fy;
|
||||||
console->sy = (((int16_t)((y1-y0)/console->fy))-1)*console->fy;
|
|
||||||
|
|
||||||
console->cx = 0;
|
console->cx = 0;
|
||||||
console->cy = 0;
|
console->cy = 0;
|
||||||
console->x0 = x0;
|
console->x0 = x0;
|
||||||
console->y0 = y0;
|
console->y0 = y0;
|
||||||
|
|
||||||
console->buf = buffer;
|
|
||||||
console->wptr = 0;
|
|
||||||
console->blen = console->sx*console->sy;
|
|
||||||
console->bstrt = 0;
|
|
||||||
|
|
||||||
console->bkcolor = bkcolor;
|
console->bkcolor = bkcolor;
|
||||||
console->color = color;
|
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) {
|
msg_t lcdConsolePut(GLCDConsole *console, char c) {
|
||||||
uint8_t width;
|
uint8_t width;
|
||||||
bool_t newline = FALSE;
|
|
||||||
|
|
||||||
|
|
||||||
if(c == '\n') {
|
if(c == '\n') {
|
||||||
/* clear the text at the end of the line */
|
/* clear the text at the end of the line */
|
||||||
|
@ -120,26 +112,19 @@ msg_t lcdConsolePut(GLCDConsole *console, char c) {
|
||||||
} else {
|
} else {
|
||||||
width = lcdMeasureChar(c, console->font);
|
width = lcdMeasureChar(c, console->font);
|
||||||
if((console->cx + width) >= console->sx) {
|
if((console->cx + width) >= console->sx) {
|
||||||
chprintf(&SD1, "[1] ");
|
|
||||||
console->cx = 0;
|
console->cx = 0;
|
||||||
console->cy += console->fy;
|
console->cy += console->fy;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(
|
if((console->cy > console->sy)) {
|
||||||
(console->cy > console->sy)) {
|
|
||||||
chprintf(&SD1, "[2] ");
|
|
||||||
if(newline)
|
|
||||||
chprintf(&SD1, "* ");
|
|
||||||
lcdVerticalScroll(console->x0, console->y0, console->x0 + console->sx,
|
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 */
|
/* reset the cursor */
|
||||||
console->cx = 0;
|
console->cx = 0;
|
||||||
console->cy = console->sy;
|
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,
|
lcdDrawChar(console->x0 + console->cx, console->y0 + console->cy, c,
|
||||||
console->font, console->color, console->bkcolor, solid);
|
console->font, console->color, console->bkcolor, solid);
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,6 @@ struct GLCDConsole {
|
||||||
const struct GLCDConsoleVMT *vmt;
|
const struct GLCDConsoleVMT *vmt;
|
||||||
_base_asynchronous_channel_data
|
_base_asynchronous_channel_data
|
||||||
/* WARNING: Do not add any data to this struct above this comment, only below */
|
/* WARNING: Do not add any data to this struct above this comment, only below */
|
||||||
/* text buffer */
|
|
||||||
uint8_t *buf;
|
|
||||||
/* font */
|
/* font */
|
||||||
font_t font;
|
font_t font;
|
||||||
/* lcd area to use */
|
/* lcd area to use */
|
||||||
|
@ -49,16 +47,14 @@ struct GLCDConsole {
|
||||||
uint16_t bkcolor, color;
|
uint16_t bkcolor, color;
|
||||||
/* font size in pixels */
|
/* font size in pixels */
|
||||||
uint8_t fy;
|
uint8_t fy;
|
||||||
/* buffer index */
|
|
||||||
uint16_t wptr, blen, bstrt;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
msg_t lcdConsoleInit(GLCDConsole *console, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
|
msg_t lcdConsoleInit(GLCDConsole *console, uint16_t x0, uint16_t y0, uint16_t width, uint16_t height,
|
||||||
font_t font, uint8_t *buffer, uint16_t bkcolor, uint16_t color);
|
font_t font, uint16_t bkcolor, uint16_t color);
|
||||||
|
|
||||||
msg_t lcdConsolePut(GLCDConsole *console, char c);
|
msg_t lcdConsolePut(GLCDConsole *console, char c);
|
||||||
msg_t lcdConsoleWrite(GLCDConsole *console, uint8_t *bp, size_t n);
|
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
|
#endif
|
||||||
|
|
||||||
#ifdef LCD_USE_FSMC
|
#ifdef LCD_USE_FSMC
|
||||||
|
@ -118,6 +137,7 @@ static __inline uint16_t lld_lcdReadData(void) {
|
||||||
|
|
||||||
static __inline uint16_t lld_lcdReadReg(uint16_t lcdReg) {
|
static __inline uint16_t lld_lcdReadReg(uint16_t lcdReg) {
|
||||||
LCD_REG = lcdReg;
|
LCD_REG = lcdReg;
|
||||||
|
volatile uint16_t dummy = LCD_RAM;
|
||||||
return (LCD_RAM);
|
return (LCD_RAM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,6 +165,9 @@ __inline void lld_lcdReadStreamStop(void) {
|
||||||
|
|
||||||
__inline void lld_lcdReadStream(uint16_t *buffer, size_t size) {
|
__inline void lld_lcdReadStream(uint16_t *buffer, size_t size) {
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
|
/* throw away first value read */
|
||||||
|
volatile uint16_t dummy = LCD_RAM;
|
||||||
|
|
||||||
for(i = 0; i < size; i++) {
|
for(i = 0; i < size; i++) {
|
||||||
buffer[i] = LCD_RAM;
|
buffer[i] = LCD_RAM;
|
||||||
}
|
}
|
||||||
|
@ -162,13 +185,25 @@ static __inline void lcdDelay(uint16_t us) {
|
||||||
|
|
||||||
|
|
||||||
void lld_lcdSetCursor(uint16_t x, uint16_t y) {
|
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) {
|
if(PORTRAIT) {
|
||||||
lld_lcdWriteReg(0x004e, x);
|
lld_lcdWriteReg(0x004e, x);
|
||||||
lld_lcdWriteReg(0x004f, y);
|
lld_lcdWriteReg(0x004f, y);
|
||||||
} else if(LANDSCAPE) {
|
} else if(LANDSCAPE) {
|
||||||
lld_lcdWriteReg(0x004e, y);
|
lld_lcdWriteReg(0x004e, y);
|
||||||
lld_lcdWriteReg(0x004f, x);
|
lld_lcdWriteReg(0x004f, x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lld_lcdSetOrientation(uint8_t newOrientation) {
|
void lld_lcdSetOrientation(uint8_t newOrientation) {
|
||||||
|
@ -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) {
|
void lld_lcdSetWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
|
||||||
lld_lcdSetCursor(x0, y0);
|
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()) {
|
switch(lcdGetOrientation()) {
|
||||||
case portrait:
|
case portrait:
|
||||||
lld_lcdWriteReg(0x44, ((x1-1) << 8) | x0);
|
lld_lcdWriteReg(0x44, (((x1-1) << 8) ) | (x0 ));
|
||||||
lld_lcdWriteReg(0x45, y0);
|
lld_lcdWriteReg(0x45, y0);
|
||||||
lld_lcdWriteReg(0x46, y1-1);
|
lld_lcdWriteReg(0x46, (y1-1));
|
||||||
break;
|
break;
|
||||||
case landscape:
|
case landscape:
|
||||||
lld_lcdWriteReg(0x44, ((y1-1) << 8) | y1);
|
lld_lcdWriteReg(0x44, (((y1-1) << 8) & 0xFF00) | (y1 & 0x00FF));
|
||||||
lld_lcdWriteReg(0x45, x0);
|
lld_lcdWriteReg(0x45, x0 & 0x01FF);
|
||||||
lld_lcdWriteReg(0x46, x1-1);
|
lld_lcdWriteReg(0x46, (x1-1) & 0x01FF);
|
||||||
break;
|
break;
|
||||||
case portraitInv:
|
case portraitInv:
|
||||||
lld_lcdWriteReg(0x44, ((x1-1) << 8) | x0);
|
lld_lcdWriteReg(0x44, (((x1-1) << 8) & 0xFF00) | (x0 & 0x00FF));
|
||||||
lld_lcdWriteReg(0x45, y0);
|
lld_lcdWriteReg(0x45, y0 & 0x01FF);
|
||||||
lld_lcdWriteReg(0x46, y1-1);
|
lld_lcdWriteReg(0x46, (y1-1) & 0x01FF);
|
||||||
break;
|
break;
|
||||||
case landscapeInv:
|
case landscapeInv:
|
||||||
lld_lcdWriteReg(0x44, ((y1-1) << 8) | y1);
|
lld_lcdWriteReg(0x44, (((y1-1) << 8) & 0xFF00) | (y1 & 0x00FF));
|
||||||
lld_lcdWriteReg(0x45, x0);
|
lld_lcdWriteReg(0x45, x0 & 0x01FF);
|
||||||
lld_lcdWriteReg(0x46, x1-1);
|
lld_lcdWriteReg(0x46, (x1-1) & 0x01FF);
|
||||||
break;
|
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;
|
row0 = (y1 - i - 1) + lines;
|
||||||
row1 = (y1 - i - 1);
|
row1 = (y1 - i - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read row0 into the buffer and then write at row1*/
|
/* read row0 into the buffer and then write at row1*/
|
||||||
lld_lcdSetWindow(x0, row0, x1, row0);
|
lld_lcdSetWindow(x0, row0, x1, row0);
|
||||||
lld_lcdReadStreamStart();
|
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
|
/* Return the width of the character, we need it so that lcdDrawString may work
|
||||||
* We don't have a static address counter */
|
* We don't have a static address counter */
|
||||||
|
return charWidth + padAfterChar;
|
||||||
/* Abhishek: what should padAfter be?
|
|
||||||
* return charWidth+padAfter;
|
|
||||||
*/
|
|
||||||
return charWidth;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* WARNING: No boundary checks! Unpredictable behaviour if text exceeds boundary */
|
/* WARNING: No boundary checks! Unpredictable behaviour if text exceeds boundary */
|
||||||
|
|
Loading…
Add table
Reference in a new issue