add vertical scroll functions
This commit is contained in:
parent
08a70cc3ce
commit
79f7278f3d
93
console.c
93
console.c
@ -84,7 +84,7 @@ msg_t lcdConsoleInit(GLCDConsole *console, uint16_t x0, uint16_t y0, uint16_t x1
|
||||
|
||||
/* calculate the size of the console in characters */
|
||||
console->sx = (x1-x0);
|
||||
console->sy = (y1-y0);
|
||||
console->sy = ((int16_t)((y1-y0)/console->fy))*console->fy;
|
||||
|
||||
console->cx = 0;
|
||||
console->cy = 0;
|
||||
@ -107,80 +107,45 @@ msg_t lcdConsoleUpdate(GLCDConsole *console) {
|
||||
}
|
||||
|
||||
msg_t lcdConsolePut(GLCDConsole *console, char c) {
|
||||
uint16_t i;
|
||||
uint16_t s = console->wptr;
|
||||
uint8_t width;
|
||||
bool_t redraw = FALSE;
|
||||
|
||||
/* write character to current position in buffer and update wptr */
|
||||
console->buf[console->wptr] = c;
|
||||
|
||||
if(++console->wptr == console->blen) {
|
||||
/* wrap around to the beginning */
|
||||
console->wptr = 0;
|
||||
}
|
||||
|
||||
lcdSetFont(console->font);
|
||||
lcdSetFontTransparency(solid);
|
||||
/* keep looping until we've finished writing
|
||||
* we may write more than one character if the console needs to be re-drawn
|
||||
* at the end of the loop leave the cursor set to the position for the next character
|
||||
* checks to see if this is out of range will be performed at the start of that character
|
||||
*/
|
||||
do {
|
||||
width = lcdMeasureChar(console->buf[s]);
|
||||
if(console->buf[s] == '\n') {
|
||||
/* clear the text at the end of the line */
|
||||
if(console->cx < console->sx)
|
||||
lcdDrawRect(console->cx, console->cy, console->sx, console->cy + console->fy,
|
||||
1, console->bkcolor);
|
||||
|
||||
if(c == '\n') {
|
||||
/* clear the text at the end of the line */
|
||||
if(console->cx < console->sx)
|
||||
lcdDrawRect(console->cx, console->cy, console->sx, console->cy + console->fy,
|
||||
1, console->bkcolor);
|
||||
console->cx = 0;
|
||||
console->cy += console->fy;
|
||||
} else if(c == '\r') {
|
||||
/* TODO: work backwards through the buffer to the start of the current line */
|
||||
//console->cx = 0;
|
||||
} else {
|
||||
width = lcdMeasureChar(c);
|
||||
if((console->cx + width) >= console->sx) {
|
||||
console->cx = 0;
|
||||
console->cy += console->fy;
|
||||
} else if(console->buf[s] == '\r') {
|
||||
/* TODO: work backwards through the buffer to the start of the current line */
|
||||
//console->cx = 0;
|
||||
} else {
|
||||
if((console->cx + width) >= console->sx) {
|
||||
console->cx = 0;
|
||||
console->cy += console->fy;
|
||||
}
|
||||
|
||||
if((console->cy + console->fy) >= console->sy) {
|
||||
/* we've gone beyond the end of the console */
|
||||
/* start at beginning of buffer and remove the first line */
|
||||
|
||||
/* increment s from bstrt until it has been incremented more than
|
||||
* console->sx or finds a new line */
|
||||
s = console->bstrt;
|
||||
console->cx = 0;
|
||||
|
||||
while((console->cx <= console->sx) && (console->buf[s % console->blen] != '\n')) {
|
||||
s++;
|
||||
/* TODO: increment based on the width of the character at s */
|
||||
/* TODO: this doesn't handle carriage return */
|
||||
console->cx += lcdMeasureChar(console->buf[s % console->blen]);
|
||||
}
|
||||
|
||||
/* update bstrt to the new start point of the console */
|
||||
console->bstrt = s;
|
||||
|
||||
/* reset the cursor */
|
||||
console->cx = 0;
|
||||
console->cy = 0;
|
||||
}
|
||||
lcdMoveCursor(console->x0 + console->cx, console->y0 + console->cy,
|
||||
console->color, console->bkcolor);
|
||||
lcdDrawChar(console->buf[s]);
|
||||
|
||||
/* update cursor */
|
||||
console->cx += width;
|
||||
}
|
||||
|
||||
/* finally increment index */
|
||||
if(++s == console->blen)
|
||||
s = 0;
|
||||
if((console->cy + console->fy) >= console->sy) {
|
||||
lcdVerticalScroll(console->x0, console->y0, console->x0 + console->sx,
|
||||
console->y0 + console->sy, console->fy);
|
||||
/* reset the cursor */
|
||||
console->cx = 0;
|
||||
while((console->cy) >= console->sy)
|
||||
console->cy -= console->fy;
|
||||
}
|
||||
lcdMoveCursor(console->x0 + console->cx, console->y0 + console->cy,
|
||||
console->color, console->bkcolor);
|
||||
lcdDrawChar(c);
|
||||
|
||||
} while(s != console->wptr);
|
||||
/* update cursor */
|
||||
console->cx += width;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -350,5 +350,15 @@ uint16_t lld_lcdGetWidth(void) {
|
||||
return lcd_width;
|
||||
}
|
||||
|
||||
void lld_lcdVerticalScroll(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, int16_t lines) {
|
||||
lld_lcdSetWindow(x0, y0, x1, y1);
|
||||
|
||||
/* if negative shift, then subtract from the height of the area */
|
||||
lines = (lines < 0) ? ((y1-y0) + lines) : lines;
|
||||
|
||||
/* TODO: implement */
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -42,6 +42,7 @@ uint16_t lld_lcdGetPixelColor(uint16_t x, uint16_t y);
|
||||
uint16_t lld_lcdGetOrientation(void);
|
||||
uint16_t lld_lcdGetHeight(void);
|
||||
uint16_t lld_lcdGetWidth(void);
|
||||
void lld_lcdVerticalScroll(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, int16_t lines);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -334,5 +334,20 @@ uint16_t lld_lcdGetWidth(void) {
|
||||
return lcd_width;
|
||||
}
|
||||
|
||||
#include "chprintf.h"
|
||||
|
||||
void lld_lcdVerticalScroll(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, int16_t lines) {
|
||||
lld_lcdSetWindow(x0, y0, x1, y1);
|
||||
|
||||
/* if negative shift, then subtract from the height of the area */
|
||||
lines = (lines < 0) ? ((y1-y0) + lines) : lines;
|
||||
|
||||
/* driver accepts only 9 bit line value */
|
||||
lld_lcdWriteReg(0x0041, (uint16_t)lines & 0x01FF);
|
||||
|
||||
/* enable the scroll */
|
||||
lld_lcdWriteReg(0x0007, (0x0001 << 9) | 0x0133);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -146,6 +146,7 @@ uint16_t lld_lcdGetPixelColor(uint16_t x, uint16_t y);
|
||||
uint16_t lld_lcdGetOrientation(void);
|
||||
uint16_t lld_lcdGetHeight(void);
|
||||
uint16_t lld_lcdGetWidth(void);
|
||||
void lld_lcdVerticalScroll(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, int16_t lines);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
6
glcd.c
6
glcd.c
@ -330,3 +330,9 @@ void lcdDrawCircle(uint16_t x, uint16_t y, uint16_t radius, uint8_t filled, uint
|
||||
} while(a <= b);
|
||||
}
|
||||
|
||||
void lcdVerticalScroll(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, int16_t lines) {
|
||||
lld_lcdVerticalScroll(x0,y0,x1,y1,lines);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
7
glcd.h
7
glcd.h
@ -4,6 +4,11 @@
|
||||
#include "ch.h"
|
||||
#include "hal.h"
|
||||
#include "fonts.h"
|
||||
|
||||
#if !defined(LCD_USE_FSMC) | !defined(LCD_USE_GPIO) | !defined(LCD_USE_SPI)
|
||||
#include "glcdconf.h"
|
||||
#endif
|
||||
|
||||
#include "ssd1289_lld.h"
|
||||
#include "s6d1121_lld.h"
|
||||
|
||||
@ -87,6 +92,8 @@ uint16_t lcdGetOrientation(void);
|
||||
uint16_t lcdBGR2RGB(uint16_t color);
|
||||
uint16_t lcdGetPixelColor(uint16_t x, uint16_t y);
|
||||
|
||||
void lcdVerticalScroll(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, int16_t lines);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user