From d591379befb9461eec2a01cf294683899176dd99 Mon Sep 17 00:00:00 2001 From: Jack Massey Date: Mon, 25 Feb 2019 21:08:58 +1000 Subject: [PATCH 01/12] Fix c99 compile issues This software depends on c99 despite the fact that it's not present in the compile flags. This has been fixed. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1a09ae0..f375fc6 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ SIZE = avr-size SRC_TMP = $(subst ../,,$(SRC)) OBJ = $(SRC_TMP:%.c=$(OBJDIR)/$(AVRMCU)/%.o) -CFLAGS = -I include -I images -I fonts -Os -Wall -Wstrict-prototypes +CFLAGS = -I include -I images -I fonts -Os -Wall -Wstrict-prototypes --std=c99 CFLAGS += -ffunction-sections -fdata-sections CFLAGS += -fshort-enums -fpack-struct -funsigned-char -funsigned-bitfields CFLAGS += -mmcu=$(AVRMCU) -DF_CPU=$(F_CPU)UL -DVERSION=$(VERSION) From 81b9762c4b55db48a4fcb6034387e49679b7f7fb Mon Sep 17 00:00:00 2001 From: Jack Massey Date: Mon, 25 Feb 2019 21:32:11 +1000 Subject: [PATCH 02/12] Fix issues with bad logo pointer The logo pointer being used was just incorrect and throwing a warning. --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index 57f1ee4..998d01d 100644 --- a/main.c +++ b/main.c @@ -19,7 +19,7 @@ int main(void) { st7735_set_orientation(ST7735_LANDSCAPE); st7735_fill_rect(0, 0, 160, 128, ST7735_COLOR_BLACK); - st7735_draw_mono_bitmap(16, 4, &logo_bw, ST7735_COLOR_WHITE, ST7735_COLOR_BLACK); + st7735_draw_mono_bitmap(16, 4, (PGM_P) logo_bw, ST7735_COLOR_WHITE, ST7735_COLOR_BLACK); //st7735_draw_bitmap(10, 10, &logo); From 7a7b030e2ad0242606d452f1af04d7e67eb5c7c9 Mon Sep 17 00:00:00 2001 From: Jack Massey Date: Mon, 25 Feb 2019 21:33:14 +1000 Subject: [PATCH 03/12] Removed commented out code --- main.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/main.c b/main.c index 998d01d..938d4e3 100644 --- a/main.c +++ b/main.c @@ -6,10 +6,7 @@ #include "st7735_gfx.h" #include "st7735_font.h" -//#include "logo.h" #include "logo_bw.h" - -//#include "tom_thumb.h" #include "free_sans.h" int main(void) { @@ -21,8 +18,6 @@ int main(void) { st7735_draw_mono_bitmap(16, 4, (PGM_P) logo_bw, ST7735_COLOR_WHITE, ST7735_COLOR_BLACK); - //st7735_draw_bitmap(10, 10, &logo); - for(uint8_t x = 8; x <= 160; x += 8) { st7735_draw_line(0, 0, x, 128, ST7735_COLOR_GREEN); From cbc18d15e90ecae4acfd522ed480e109499bec1d Mon Sep 17 00:00:00 2001 From: Jack Massey Date: Thu, 28 Feb 2019 09:04:33 +1000 Subject: [PATCH 04/12] Added ST7735_RED144_JAYCAR screen --- include/st7735.h | 5 +++-- spi.c | 4 ++-- st7735.c | 39 ++++++++++++++++++++++++++++++--------- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/include/st7735.h b/include/st7735.h index 275db83..66704a5 100644 --- a/include/st7735.h +++ b/include/st7735.h @@ -16,10 +16,11 @@ enum ST7735_DISPLAY_TYPE { ST7735_RED_18_GREENTAB, ST7735_RED_18_REDTAB, ST7735_RED_18_BLACKTAB, - ST7735_RED144_GREENTAB + ST7735_RED144_GREENTAB, + ST7735_RED144_JAYCAR }; -static const enum ST7735_DISPLAY_TYPE st7735_type = ST7735_RED_18_BLACKTAB; +static const enum ST7735_DISPLAY_TYPE st7735_type = ST7735_RED144_JAYCAR; // ST7735 commands diff --git a/spi.c b/spi.c index 3c0813d..ff3f25e 100644 --- a/spi.c +++ b/spi.c @@ -2,10 +2,10 @@ void spi_init(void) { // Set MOSI and SCK, SS/CS output, all others input - DDRB = (1< Date: Thu, 28 Feb 2019 09:07:22 +1000 Subject: [PATCH 05/12] Added support for cut off bitmaps --- st7735.c | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/st7735.c b/st7735.c index e864e97..9b51bbd 100644 --- a/st7735.c +++ b/st7735.c @@ -308,29 +308,36 @@ void st7735_fill_rect(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint16_t color void st7735_draw_bitmap(uint8_t x, uint8_t y, PGM_P bitmap) { - if(x >= st7735_width || y >= st7735_height) { - return; - } - uint8_t w = pgm_read_word(bitmap); bitmap += 2; uint8_t h = pgm_read_word(bitmap); bitmap += 2; + uint8_t max_x = x + w - 1; + uint8_t max_y = y + h - 1; - if((x + w - 1) >= st7735_width) { - return; - } - if((y + h - 1) >= st7735_height) { + if(x >= st7735_width || y >= st7735_height) { return; } - st7735_set_addr_win(x, y, x + w - 1, y + h - 1); + if(max_x >= st7735_width) { + max_x = st7735_width - 1; + } + + if(max_y >= st7735_height) { + max_y = st7735_height - 1; + } + + st7735_set_addr_win(x, y, max_x, max_y); st7735_set_rs(); spi_unset_cs(); for(uint8_t i = 0; i < h; i++) { for(uint8_t j = 0; j < w; j++) { + if((x + j) >= st7735_width || (y + i) >= st7735_height) { + bitmap += 2; + continue; + } uint16_t color = pgm_read_word(bitmap); st7735_write_color(color); bitmap += 2; @@ -343,19 +350,22 @@ void st7735_draw_bitmap(uint8_t x, uint8_t y, PGM_P bitmap) { void st7735_draw_mono_bitmap(uint8_t x, uint8_t y, PGM_P bitmap, uint16_t color_set, uint16_t color_unset) { uint8_t w = pgm_read_byte(bitmap++); uint8_t h = pgm_read_byte(bitmap++); + uint8_t max_x = x + w - 1; + uint8_t max_y = y + h - 1; if(x >= st7735_width || y >= st7735_height) { return; } - if((x + w - 1) >= st7735_width) { - return; - } - if((y + h - 1) >= st7735_height) { - return; + if(max_x >= st7735_width) { + max_x = st7735_width - 1; } - st7735_set_addr_win(x, y, x + w - 1, y + h - 1); + if(max_y >= st7735_height) { + max_y = st7735_height - 1; + } + + st7735_set_addr_win(x, y, max_x, max_y); st7735_set_rs(); spi_unset_cs(); @@ -365,9 +375,13 @@ void st7735_draw_mono_bitmap(uint8_t x, uint8_t y, PGM_P bitmap, uint16_t color_ for(uint8_t i = 0; i < h; i++) { for(uint8_t j = 0; j < w; j++) { if(bit_pos % 8 == 0) { - byte = pgm_read_byte(bitmap++); + byte = pgm_read_byte(bitmap++); } + if((x + j) >= st7735_width || (y + i) >= st7735_height) { + bit_pos++; + continue; + } if(byte & (1 << (bit_pos % 8))) { st7735_write_color(color_set); } @@ -379,5 +393,4 @@ void st7735_draw_mono_bitmap(uint8_t x, uint8_t y, PGM_P bitmap, uint16_t color_ } spi_set_cs(); - } From 5b1ee1361cbd8b254edd21217bb56240e451aac5 Mon Sep 17 00:00:00 2001 From: Jack Massey Date: Thu, 28 Feb 2019 10:42:38 +1000 Subject: [PATCH 06/12] Bumped version --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f375fc6..0766b42 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ AVRMCU ?= atmega8 F_CPU ?= 16000000 ISPPORT ?= /dev/kaboard -VERSION = 0.1 +VERSION = 0.2 HEADERS = include/spi.h include/st7735.h include/st7735initcmds.h HEADERS += images/logo_bw.h images/logo.h include/st7735_gfx.h From c6e0fc69923a9023e1e3aa7ebba5fb4e1575549e Mon Sep 17 00:00:00 2001 From: Jack Massey Date: Thu, 28 Feb 2019 21:31:38 +1000 Subject: [PATCH 07/12] Fixed init for the JAYCAR screen The ini for the JAYCAR screen didn't correctly set the column and row start. This has been corrected so it matches the default landscape mode. --- st7735.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/st7735.c b/st7735.c index 9b51bbd..b291600 100644 --- a/st7735.c +++ b/st7735.c @@ -135,7 +135,16 @@ void st7735_init() { st7735_height = st7735_default_height_144; st7735_column_start = 2; st7735_row_start = 3; + st7735_run_command_list(st7735_red_init1); + st7735_run_command_list(st7735_red_init_green1442); + st7735_run_command_list(st7735_red_init3); + st7735_width = st7735_default_width; + st7735_height = st7735_default_height_144; + break; case ST7735_RED144_JAYCAR: + st7735_height = st7735_default_height_144; + st7735_column_start = 32; + st7735_row_start = 0; st7735_run_command_list(st7735_red_init1); st7735_run_command_list(st7735_red_init_green1442); st7735_run_command_list(st7735_red_init3); From a3766f41e906685e90b4d751cdb1a477ada92a65 Mon Sep 17 00:00:00 2001 From: Jack Massey Date: Thu, 28 Feb 2019 21:37:40 +1000 Subject: [PATCH 08/12] Fixed mixing of tabs and spaces --- include/st7735.h | 2 +- st7735.c | 96 ++++++++++++++++++++++++------------------------ 2 files changed, 49 insertions(+), 49 deletions(-) diff --git a/include/st7735.h b/include/st7735.h index 66704a5..d94cafd 100644 --- a/include/st7735.h +++ b/include/st7735.h @@ -17,7 +17,7 @@ enum ST7735_DISPLAY_TYPE { ST7735_RED_18_REDTAB, ST7735_RED_18_BLACKTAB, ST7735_RED144_GREENTAB, - ST7735_RED144_JAYCAR + ST7735_RED144_JAYCAR }; static const enum ST7735_DISPLAY_TYPE st7735_type = ST7735_RED144_JAYCAR; diff --git a/st7735.c b/st7735.c index b291600..3e8089b 100644 --- a/st7735.c +++ b/st7735.c @@ -132,19 +132,19 @@ void st7735_init() { break; case ST7735_RED144_GREENTAB: - st7735_height = st7735_default_height_144; - st7735_column_start = 2; - st7735_row_start = 3; + st7735_height = st7735_default_height_144; + st7735_column_start = 2; + st7735_row_start = 3; st7735_run_command_list(st7735_red_init1); st7735_run_command_list(st7735_red_init_green1442); st7735_run_command_list(st7735_red_init3); st7735_width = st7735_default_width; st7735_height = st7735_default_height_144; break; - case ST7735_RED144_JAYCAR: - st7735_height = st7735_default_height_144; - st7735_column_start = 32; - st7735_row_start = 0; + case ST7735_RED144_JAYCAR: + st7735_height = st7735_default_height_144; + st7735_column_start = 32; + st7735_row_start = 0; st7735_run_command_list(st7735_red_init1); st7735_run_command_list(st7735_red_init_green1442); st7735_run_command_list(st7735_red_init3); @@ -179,17 +179,17 @@ void st7735_set_orientation(enum ST7735_ORIENTATION orientation) { st7735_width = st7735_default_width; if( - st7735_type == ST7735_RED144_GREENTAB || - st7735_type == ST7735_RED144_JAYCAR - ) { - st7735_height = st7735_default_height_144; + st7735_type == ST7735_RED144_GREENTAB || + st7735_type == ST7735_RED144_JAYCAR + ) { + st7735_height = st7735_default_height_144; } else { - st7735_height = st7735_default_height_18; - } + st7735_height = st7735_default_height_18; + } - if(st7735_type == ST7735_RED144_JAYCAR) { - st7735_row_start = 32; - } + if(st7735_type == ST7735_RED144_JAYCAR) { + st7735_row_start = 32; + } break; @@ -200,19 +200,19 @@ void st7735_set_orientation(enum ST7735_ORIENTATION orientation) { st7735_write_data(MADCTL_MY | MADCTL_MV | MADCTL_BGR); } - if( - st7735_type == ST7735_RED144_GREENTAB || - st7735_type == ST7735_RED144_JAYCAR - ) { + if( + st7735_type == ST7735_RED144_GREENTAB || + st7735_type == ST7735_RED144_JAYCAR + ) { st7735_width = st7735_default_height_144; } else { st7735_width = st7735_default_height_18; } - if(st7735_type == ST7735_RED144_JAYCAR) { - st7735_column_start = 32; - } + if(st7735_type == ST7735_RED144_JAYCAR) { + st7735_column_start = 32; + } st7735_height = st7735_default_width; break; @@ -226,10 +226,10 @@ void st7735_set_orientation(enum ST7735_ORIENTATION orientation) { st7735_width = st7735_default_width; - if( - st7735_type == ST7735_RED144_GREENTAB || - st7735_type == ST7735_RED144_JAYCAR - ) { + if( + st7735_type == ST7735_RED144_GREENTAB || + st7735_type == ST7735_RED144_JAYCAR + ) { st7735_height = st7735_default_height_144; } else { st7735_height = st7735_default_height_18; @@ -243,10 +243,10 @@ void st7735_set_orientation(enum ST7735_ORIENTATION orientation) { st7735_write_data(MADCTL_MX | MADCTL_MV | MADCTL_BGR); } - if( - st7735_type == ST7735_RED144_GREENTAB || - st7735_type == ST7735_RED144_JAYCAR - ) { + if( + st7735_type == ST7735_RED144_GREENTAB || + st7735_type == ST7735_RED144_JAYCAR + ) { st7735_width = st7735_default_height_144; } else { st7735_width = st7735_default_height_18; @@ -321,19 +321,19 @@ void st7735_draw_bitmap(uint8_t x, uint8_t y, PGM_P bitmap) { bitmap += 2; uint8_t h = pgm_read_word(bitmap); bitmap += 2; - uint8_t max_x = x + w - 1; - uint8_t max_y = y + h - 1; + uint8_t max_x = x + w - 1; + uint8_t max_y = y + h - 1; if(x >= st7735_width || y >= st7735_height) { return; } if(max_x >= st7735_width) { - max_x = st7735_width - 1; + max_x = st7735_width - 1; } if(max_y >= st7735_height) { - max_y = st7735_height - 1; + max_y = st7735_height - 1; } st7735_set_addr_win(x, y, max_x, max_y); @@ -343,10 +343,10 @@ void st7735_draw_bitmap(uint8_t x, uint8_t y, PGM_P bitmap) { for(uint8_t i = 0; i < h; i++) { for(uint8_t j = 0; j < w; j++) { - if((x + j) >= st7735_width || (y + i) >= st7735_height) { - bitmap += 2; - continue; - } + if((x + j) >= st7735_width || (y + i) >= st7735_height) { + bitmap += 2; + continue; + } uint16_t color = pgm_read_word(bitmap); st7735_write_color(color); bitmap += 2; @@ -359,19 +359,19 @@ void st7735_draw_bitmap(uint8_t x, uint8_t y, PGM_P bitmap) { void st7735_draw_mono_bitmap(uint8_t x, uint8_t y, PGM_P bitmap, uint16_t color_set, uint16_t color_unset) { uint8_t w = pgm_read_byte(bitmap++); uint8_t h = pgm_read_byte(bitmap++); - uint8_t max_x = x + w - 1; - uint8_t max_y = y + h - 1; + uint8_t max_x = x + w - 1; + uint8_t max_y = y + h - 1; if(x >= st7735_width || y >= st7735_height) { return; } if(max_x >= st7735_width) { - max_x = st7735_width - 1; + max_x = st7735_width - 1; } if(max_y >= st7735_height) { - max_y = st7735_height - 1; + max_y = st7735_height - 1; } st7735_set_addr_win(x, y, max_x, max_y); @@ -384,13 +384,13 @@ void st7735_draw_mono_bitmap(uint8_t x, uint8_t y, PGM_P bitmap, uint16_t color_ for(uint8_t i = 0; i < h; i++) { for(uint8_t j = 0; j < w; j++) { if(bit_pos % 8 == 0) { - byte = pgm_read_byte(bitmap++); + byte = pgm_read_byte(bitmap++); } - if((x + j) >= st7735_width || (y + i) >= st7735_height) { - bit_pos++; - continue; - } + if((x + j) >= st7735_width || (y + i) >= st7735_height) { + bit_pos++; + continue; + } if(byte & (1 << (bit_pos % 8))) { st7735_write_color(color_set); } From d9531564619023415d566b814a1f3166b1515dee Mon Sep 17 00:00:00 2001 From: Jack Massey Date: Thu, 28 Feb 2019 22:05:21 +1000 Subject: [PATCH 09/12] Fix rotation offsets for JAYCAR display The JAYCAR display was not having its offsets set correctly now that they were being set by default. --- st7735.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/st7735.c b/st7735.c index 3e8089b..3c19e7c 100644 --- a/st7735.c +++ b/st7735.c @@ -188,6 +188,7 @@ void st7735_set_orientation(enum ST7735_ORIENTATION orientation) { } if(st7735_type == ST7735_RED144_JAYCAR) { + st7735_column_start = 32; st7735_row_start = 32; } break; @@ -234,6 +235,11 @@ void st7735_set_orientation(enum ST7735_ORIENTATION orientation) { } else { st7735_height = st7735_default_height_18; } + + if(st7735_type == ST7735_RED144_JAYCAR) { + st7735_column_start = 0; + } + break; case ST7735_LANDSCAPE_INV: @@ -252,6 +258,10 @@ void st7735_set_orientation(enum ST7735_ORIENTATION orientation) { st7735_width = st7735_default_height_18; } + if(st7735_type == ST7735_RED144_JAYCAR) { + st7735_column_start = 0; + } + st7735_height = st7735_default_width; break; } From e35c9ae2e53e47cb459819d0b3e4cf5e299f88c8 Mon Sep 17 00:00:00 2001 From: Jack Massey Date: Thu, 28 Feb 2019 22:22:43 +1000 Subject: [PATCH 10/12] Fix portrait mode on JAYCAR display This was due to a simple typo when rebasing. --- st7735.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/st7735.c b/st7735.c index 3c19e7c..6dfc37f 100644 --- a/st7735.c +++ b/st7735.c @@ -188,7 +188,7 @@ void st7735_set_orientation(enum ST7735_ORIENTATION orientation) { } if(st7735_type == ST7735_RED144_JAYCAR) { - st7735_column_start = 32; + st7735_column_start = 0; st7735_row_start = 32; } break; From 8fecfbff0009dfcd2a6915b99d0cce14bb72ebec Mon Sep 17 00:00:00 2001 From: Jack Massey Date: Thu, 14 Mar 2019 11:32:31 +1000 Subject: [PATCH 11/12] Fix unused pin PB0 being used in init This pin is unused and shouldn't be set by the library. --- spi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spi.c b/spi.c index ff3f25e..3c0813d 100644 --- a/spi.c +++ b/spi.c @@ -2,10 +2,10 @@ void spi_init(void) { // Set MOSI and SCK, SS/CS output, all others input - DDRB = (1< Date: Thu, 14 Mar 2019 11:34:21 +1000 Subject: [PATCH 12/12] Updated README with usage This library has the pins hardcoded and so they are recorded in the README. Also added the additional tweaks done by Massey101. --- README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/README.md b/README.md index 5d9220e..aa406db 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,50 @@ and parts of https://github.com/adafruit/Adafruit-GFX-Library/ Tweaks ------ +By LongHairedHacker: + * Uses my own bitmap format for fullcolor and monochrome bitmaps * Faster line drawing based on: https://github.com/adafruit/Adafruit-GFX-Library/pull/36 * Faster font rendering based on https://github.com/adafruit/Adafruit-GFX-Library/issues/69 * Refactored draw_char function that does not load glyph struct twice + +By Massey101: + +* Added support for bitmap clipping +* Added JAYCAR screen for XC4629 support + + +Usage +----- + +Connect the display to the following PINS: + +JAYCAR screen and ATMEGA328: ++--------+--------+ +| Screen | AVR | ++--------+--------+ +| VCC | 5V | ++--------+--------+ +| GND | GND | ++--------+--------+ +| CS | PB2 | ++--------+--------+ +| RESET | PD7 | ++--------+--------+ +| A0 | PD6 | ++--------+--------+ +| SDA | PB3 | ++--------+--------+ +| SCK | PB5 | ++--------+--------+ +| LED | 3.3V | ++--------+--------+ + + +1. Set the environment variables for: + - `AVRMCU` - Your avr chip + - `F_CPU` - Your clock speed + - `ISPPORT` - programming device +2. Modify `include/st7735.h:st7735_type` to your screen. (I have no idea how to + figure out which is which) +3. Run `make flash`