add vertical scroll functions
This commit is contained in:
parent
08a70cc3ce
commit
79f7278f3d
7 changed files with 69 additions and 64 deletions
55
console.c
55
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 */
|
/* calculate the size of the console in characters */
|
||||||
console->sx = (x1-x0);
|
console->sx = (x1-x0);
|
||||||
console->sy = (y1-y0);
|
console->sy = ((int16_t)((y1-y0)/console->fy))*console->fy;
|
||||||
|
|
||||||
console->cx = 0;
|
console->cx = 0;
|
||||||
console->cy = 0;
|
console->cy = 0;
|
||||||
|
@ -107,81 +107,46 @@ msg_t lcdConsoleUpdate(GLCDConsole *console) {
|
||||||
}
|
}
|
||||||
|
|
||||||
msg_t lcdConsolePut(GLCDConsole *console, char c) {
|
msg_t lcdConsolePut(GLCDConsole *console, char c) {
|
||||||
uint16_t i;
|
|
||||||
uint16_t s = console->wptr;
|
|
||||||
uint8_t width;
|
uint8_t width;
|
||||||
bool_t redraw = FALSE;
|
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);
|
lcdSetFont(console->font);
|
||||||
lcdSetFontTransparency(solid);
|
lcdSetFontTransparency(solid);
|
||||||
/* keep looping until we've finished writing
|
|
||||||
* we may write more than one character if the console needs to be re-drawn
|
if(c == '\n') {
|
||||||
* 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 */
|
/* clear the text at the end of the line */
|
||||||
if(console->cx < console->sx)
|
if(console->cx < console->sx)
|
||||||
lcdDrawRect(console->cx, console->cy, console->sx, console->cy + console->fy,
|
lcdDrawRect(console->cx, console->cy, console->sx, console->cy + console->fy,
|
||||||
1, console->bkcolor);
|
1, console->bkcolor);
|
||||||
console->cx = 0;
|
console->cx = 0;
|
||||||
console->cy += console->fy;
|
console->cy += console->fy;
|
||||||
} else if(console->buf[s] == '\r') {
|
} else if(c == '\r') {
|
||||||
/* TODO: work backwards through the buffer to the start of the current line */
|
/* TODO: work backwards through the buffer to the start of the current line */
|
||||||
//console->cx = 0;
|
//console->cx = 0;
|
||||||
} else {
|
} else {
|
||||||
|
width = lcdMeasureChar(c);
|
||||||
if((console->cx + width) >= console->sx) {
|
if((console->cx + width) >= console->sx) {
|
||||||
console->cx = 0;
|
console->cx = 0;
|
||||||
console->cy += console->fy;
|
console->cy += console->fy;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((console->cy + console->fy) >= console->sy) {
|
if((console->cy + console->fy) >= console->sy) {
|
||||||
/* we've gone beyond the end of the console */
|
lcdVerticalScroll(console->x0, console->y0, console->x0 + console->sx,
|
||||||
/* start at beginning of buffer and remove the first line */
|
console->y0 + console->sy, console->fy);
|
||||||
|
|
||||||
/* 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 */
|
/* reset the cursor */
|
||||||
console->cx = 0;
|
console->cx = 0;
|
||||||
console->cy = 0;
|
while((console->cy) >= console->sy)
|
||||||
|
console->cy -= console->fy;
|
||||||
}
|
}
|
||||||
lcdMoveCursor(console->x0 + console->cx, console->y0 + console->cy,
|
lcdMoveCursor(console->x0 + console->cx, console->y0 + console->cy,
|
||||||
console->color, console->bkcolor);
|
console->color, console->bkcolor);
|
||||||
lcdDrawChar(console->buf[s]);
|
lcdDrawChar(c);
|
||||||
|
|
||||||
/* update cursor */
|
/* update cursor */
|
||||||
console->cx += width;
|
console->cx += width;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* finally increment index */
|
|
||||||
if(++s == console->blen)
|
|
||||||
s = 0;
|
|
||||||
|
|
||||||
} while(s != console->wptr);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
msg_t lcdConsoleWrite(GLCDConsole *console, uint8_t *bp, size_t n) {
|
msg_t lcdConsoleWrite(GLCDConsole *console, uint8_t *bp, size_t n) {
|
||||||
|
|
|
@ -350,5 +350,15 @@ uint16_t lld_lcdGetWidth(void) {
|
||||||
return lcd_width;
|
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
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ uint16_t lld_lcdGetPixelColor(uint16_t x, uint16_t y);
|
||||||
uint16_t lld_lcdGetOrientation(void);
|
uint16_t lld_lcdGetOrientation(void);
|
||||||
uint16_t lld_lcdGetHeight(void);
|
uint16_t lld_lcdGetHeight(void);
|
||||||
uint16_t lld_lcdGetWidth(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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -334,5 +334,20 @@ uint16_t lld_lcdGetWidth(void) {
|
||||||
return lcd_width;
|
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
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -146,6 +146,7 @@ uint16_t lld_lcdGetPixelColor(uint16_t x, uint16_t y);
|
||||||
uint16_t lld_lcdGetOrientation(void);
|
uint16_t lld_lcdGetOrientation(void);
|
||||||
uint16_t lld_lcdGetHeight(void);
|
uint16_t lld_lcdGetHeight(void);
|
||||||
uint16_t lld_lcdGetWidth(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
|
#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);
|
} 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 "ch.h"
|
||||||
#include "hal.h"
|
#include "hal.h"
|
||||||
#include "fonts.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 "ssd1289_lld.h"
|
||||||
#include "s6d1121_lld.h"
|
#include "s6d1121_lld.h"
|
||||||
|
|
||||||
|
@ -87,6 +92,8 @@ uint16_t lcdGetOrientation(void);
|
||||||
uint16_t lcdBGR2RGB(uint16_t color);
|
uint16_t lcdBGR2RGB(uint16_t color);
|
||||||
uint16_t lcdGetPixelColor(uint16_t x, uint16_t y);
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue