From 834f7875a3326425bbeb7f4a04b62681f1e26da2 Mon Sep 17 00:00:00 2001 From: Paul Klinger Date: Fri, 8 Feb 2019 00:50:29 +0100 Subject: [PATCH 1/6] 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. --- lcd.c | 25 +++++++++++++++++++++++++ lcd.h | 5 +++++ 2 files changed, 30 insertions(+) diff --git a/lcd.c b/lcd.c index 97fe612..9a6805c 100644 --- a/lcd.c +++ b/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 diff --git a/lcd.h b/lcd.h index 873e41f..dfdf921 100644 --- a/lcd.h +++ b/lcd.h @@ -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 From 0e14c81df23641185e47cefc5a0d6daa7c722afc Mon Sep 17 00:00:00 2001 From: Paul Klinger Date: Fri, 8 Feb 2019 17:55:52 +0100 Subject: [PATCH 2/6] use lcd_goto_xpix_y for lcd_gotoxy --- lcd.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/lcd.c b/lcd.c index 9a6805c..f19c8e9 100644 --- a/lcd.c +++ b/lcd.c @@ -119,16 +119,8 @@ 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]); - 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)); + 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 From 4b49d467c9857e8db55d79ee05a4a6b5b6a16798 Mon Sep 17 00:00:00 2001 From: Paul Klinger Date: Fri, 8 Feb 2019 17:59:27 +0100 Subject: [PATCH 3/6] tabs/spaces --- lcd.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lcd.h b/lcd.h index dfdf921..74d0a3d 100644 --- a/lcd.h +++ b/lcd.h @@ -110,7 +110,7 @@ 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, + 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 @@ -124,7 +124,7 @@ 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 + 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 From 7f42d3f89a84427f812409264fd6965e4b54ef11 Mon Sep 17 00:00:00 2001 From: Paul Klinger Date: Fri, 8 Feb 2019 19:07:10 +0100 Subject: [PATCH 4/6] added comment --- lcd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lcd.h b/lcd.h index 74d0a3d..90907b9 100644 --- a/lcd.h +++ b/lcd.h @@ -125,7 +125,7 @@ extern "C" { 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); + 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 From 0dbd2a14d7ef39fba94fcf40e61fee9da32f7320 Mon Sep 17 00:00:00 2001 From: Paul Klinger Date: Tue, 12 Feb 2019 18:26:26 +0100 Subject: [PATCH 5/6] truncate display_block area if too large --- lcd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lcd.c b/lcd.c index f19c8e9..2c5460a 100644 --- a/lcd.c +++ b/lcd.c @@ -465,7 +465,10 @@ uint8_t lcd_check_buffer(uint8_t x, uint8_t y) { 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; + if (line > (DISPLAY_HEIGHT/8-1)) return; + if (x + width > DISPLAY_WIDTH - 1) { + width = DISPLAY_WIDTH - x - 1; + } lcd_goto_xpix_y(x,line); lcd_data(&displayBuffer[line][x], width); } From 6a4b62579df795903052f8ce3a5fa680afd02d9f Mon Sep 17 00:00:00 2001 From: Paul Klinger Date: Wed, 13 Feb 2019 01:21:19 +0100 Subject: [PATCH 6/6] truncate display_block area if too large --- lcd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lcd.c b/lcd.c index 2c5460a..6c91851 100644 --- a/lcd.c +++ b/lcd.c @@ -465,9 +465,9 @@ uint8_t lcd_check_buffer(uint8_t x, uint8_t y) { 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)) return; - if (x + width > DISPLAY_WIDTH - 1) { - width = DISPLAY_WIDTH - x - 1; + 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);