diff --git a/lcd.c b/lcd.c index e3dbab3..fec1c97 100644 --- a/lcd.c +++ b/lcd.c @@ -155,8 +155,11 @@ void lcd_init(uint8_t dispAttr){ lcd_clrscr(); } void lcd_gotoxy(uint8_t x, uint8_t y){ - if( x > (DISPLAY_WIDTH/sizeof(FONT[0])) || y > (DISPLAY_HEIGHT/8-1)) return;// out of display x = x * sizeof(FONT[0]); + lcd_goto_xpix_y(x,y); +} +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) || defined (SSD1309) @@ -488,4 +491,21 @@ 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 (line > (DISPLAY_HEIGHT/8-1) || x > DISPLAY_WIDTH - 1){return;} + if (x + width > DISPLAY_WIDTH) { // no -1 here, x alone is width 1 + width = DISPLAY_WIDTH - x; + } + lcd_goto_xpix_y(x,line); + lcd_data(&displayBuffer[line][x], width); +} #endif diff --git a/lcd.h b/lcd.h index dc74d88..3fa6313 100644 --- a/lcd.h +++ b/lcd.h @@ -124,6 +124,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 void lcd_charMode(uint8_t mode); // set size of chars @@ -136,6 +138,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); // read a pixel value from the display buffer + void lcd_display_block(uint8_t x, uint8_t line, uint8_t width); // display (part of) a display line #endif #ifdef __cplusplus