From 9bdb9d1436c9da92f5e2eff7635105309620e675 Mon Sep 17 00:00:00 2001 From: beardyw <50048990+beardyw@users.noreply.github.com> Date: Wed, 22 May 2019 08:01:09 +0100 Subject: [PATCH] Add files via upload --- main.c | 20 ++++++++++++++++++++ st7735.c | 26 ++++++++++++++++---------- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/main.c b/main.c index 938d4e3..bf29bc1 100644 --- a/main.c +++ b/main.c @@ -13,6 +13,26 @@ int main(void) { spi_init(); st7735_init(); + st7735_set_orientation(ST7735_LANDSCAPE); + st7735_fill_rect(0, 0, 160, 128, ST7735_COLOR_RED); + + _delay_ms(1000); + + st7735_set_orientation(ST7735_PORTRAIT); + st7735_fill_rect(0, 0, 128, 160, ST7735_COLOR_BLUE); + + _delay_ms(1000); + + st7735_set_orientation(ST7735_LANDSCAPE_INV); + st7735_fill_rect(0, 0, 160, 128, ST7735_COLOR_YELLOW); + + _delay_ms(1000); + + st7735_set_orientation(ST7735_PORTRAIT_INV); + st7735_fill_rect(0, 0, 128, 160, ST7735_COLOR_GREEN); + + _delay_ms(1000); + st7735_set_orientation(ST7735_LANDSCAPE); st7735_fill_rect(0, 0, 160, 128, ST7735_COLOR_BLACK); diff --git a/st7735.c b/st7735.c index 6dfc37f..2312d85 100644 --- a/st7735.c +++ b/st7735.c @@ -6,6 +6,8 @@ #include "spi.h" #include "st7735initcmds.h" +uint8_t st7735_screen_row_start = 0; +uint8_t st7735_screen_column_start = 0; uint8_t st7735_row_start = 0; uint8_t st7735_column_start = 0; uint8_t st7735_width = 0; @@ -106,8 +108,8 @@ void st7735_init() { st7735_run_command_list(st7735_red_init1); st7735_run_command_list(st7735_red_init_green2); st7735_run_command_list(st7735_red_init3); - st7735_column_start = 2; - st7735_row_start = 1; + st7735_column_start = st7735_screen_column_start = 2; + st7735_row_start = st7735_screen_row_start = 1; st7735_width = st7735_default_width; st7735_height = st7735_default_height_18; break; @@ -133,8 +135,8 @@ void st7735_init() { case ST7735_RED144_GREENTAB: st7735_height = st7735_default_height_144; - st7735_column_start = 2; - st7735_row_start = 3; + st7735_column_start = st7735_screen_column_start = 2; + st7735_row_start = st7735_screen_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); @@ -143,8 +145,8 @@ void st7735_init() { break; case ST7735_RED144_JAYCAR: st7735_height = st7735_default_height_144; - st7735_column_start = 32; - st7735_row_start = 0; + st7735_column_start = st7735_screen_column_start = 0; + st7735_row_start = st7735_screen_row_start = 32; st7735_run_command_list(st7735_red_init1); st7735_run_command_list(st7735_red_init_green1442); st7735_run_command_list(st7735_red_init3); @@ -187,10 +189,8 @@ void st7735_set_orientation(enum ST7735_ORIENTATION orientation) { st7735_height = st7735_default_height_18; } - if(st7735_type == ST7735_RED144_JAYCAR) { - st7735_column_start = 0; - st7735_row_start = 32; - } + st7735_column_start = st7735_screen_column_start; + st7735_row_start = st7735_screen_row_start; break; @@ -216,6 +216,8 @@ void st7735_set_orientation(enum ST7735_ORIENTATION orientation) { } st7735_height = st7735_default_width; + st7735_column_start = st7735_screen_row_start; + st7735_row_start = st7735_screen_column_start; break; case ST7735_PORTRAIT_INV: @@ -239,6 +241,8 @@ void st7735_set_orientation(enum ST7735_ORIENTATION orientation) { if(st7735_type == ST7735_RED144_JAYCAR) { st7735_column_start = 0; } + st7735_column_start = st7735_screen_column_start; + st7735_row_start = st7735_screen_row_start; break; @@ -263,6 +267,8 @@ void st7735_set_orientation(enum ST7735_ORIENTATION orientation) { } st7735_height = st7735_default_width; + st7735_column_start = st7735_screen_row_start; + st7735_row_start = st7735_screen_column_start; break; } }