added some functions

Added functions to move to goto a specific x pixel, clear display buffer, read from display buffer, and transfer only a portion of the buffer to the display.
pull/5/head
Paul Klinger 5 years ago
parent fa446f6111
commit 834f7875a3

25
lcd.c

@ -130,6 +130,17 @@ void lcd_gotoxy(uint8_t x, uint8_t y){
#endif
lcd_command(commandSequence, sizeof(commandSequence));
}
void lcd_goto_xpix_y(uint8_t x, uint8_t y){
if( x > (DISPLAY_WIDTH) || y > (DISPLAY_HEIGHT/8-1)) return;// out of display
cursorPosition.x=x;
cursorPosition.y=y;
#if defined SSD1306
uint8_t commandSequence[] = {0xb0+y, 0x21, x, 0x7f};
#elif defined SH1106
uint8_t commandSequence[] = {0xb0+y, 0x21, 0x00+((2+x) & (0x0f)), 0x10+( ((2+x) & (0xf0)) >> 4 ), 0x7f};
#endif
lcd_command(commandSequence, sizeof(commandSequence));
}
void lcd_clrscr(void){
#ifdef GRAPHICMODE
for (uint8_t i = 0; i < DISPLAY_HEIGHT/8; i++){
@ -452,4 +463,18 @@ void lcd_display() {
}
#endif
}
void lcd_clear_buffer() {
for (uint8_t i = 0; i < DISPLAY_HEIGHT/8; i++){
memset(displayBuffer[i], 0x00, sizeof(displayBuffer[i]));
}
}
uint8_t lcd_check_buffer(uint8_t x, uint8_t y) {
if( x > DISPLAY_WIDTH-1 || y > (DISPLAY_HEIGHT-1)) return 0; // out of Display
return displayBuffer[(y / (DISPLAY_HEIGHT/8))][x] & (1 << (y % (DISPLAY_HEIGHT/8)));
}
void lcd_display_block(uint8_t x, uint8_t line, uint8_t width) {
if ( x+width > (DISPLAY_WIDTH) || line > (DISPLAY_HEIGHT/8-1)) return;
lcd_goto_xpix_y(x,line);
lcd_data(&displayBuffer[line][x], width);
}
#endif

@ -109,6 +109,8 @@ extern "C" {
void lcd_clrscr(void); // clear screen (and buffer at GRFAICMODE)
void lcd_gotoxy(uint8_t x, uint8_t y); // set curser at pos x, y. x means character,
// y means line (page, refer lcd manual)
void lcd_goto_xpix_y(uint8_t x, uint8_t y); // set curser at pos x, y. x means pixel,
// y means line (page, refer lcd manual)
void lcd_putc(char c); // print character on screen at TEXTMODE
// at GRAPHICMODE print character to buffer
@ -122,6 +124,9 @@ extern "C" {
void lcd_fillCircle(uint8_t center_x, uint8_t center_y, uint8_t radius, uint8_t color);
void lcd_drawBitmap(uint8_t x, uint8_t y, const uint8_t picture[], uint8_t width, uint8_t height, uint8_t color);
void lcd_display(void); // copy buffer to display RAM
void lcd_clear_buffer(void); // clear display buffer
uint8_t lcd_check_buffer(uint8_t x, uint8_t y);
void lcd_display_block(uint8_t x, uint8_t line, uint8_t width); // display (part of) a display line
#endif
#ifdef __cplusplus

Loading…
Cancel
Save