From de4ef55738612260c019ab03f1811292ce4a518e Mon Sep 17 00:00:00 2001 From: mkerna Date: Thu, 31 Aug 2023 14:58:48 -0400 Subject: [PATCH 1/7] Update st7789_lcd.c Fixes issue 370. Change #define SPI_POLARITY to 1 for displays that need it. --- pio/st7789_lcd/st7789_lcd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pio/st7789_lcd/st7789_lcd.c b/pio/st7789_lcd/st7789_lcd.c index 26862c5be..bfe153763 100644 --- a/pio/st7789_lcd/st7789_lcd.c +++ b/pio/st7789_lcd/st7789_lcd.c @@ -28,6 +28,8 @@ #define PIN_RESET 4 #define PIN_BL 5 +#define SPI_POLARITY 0 // default to 0, displays require polarity 1 + #define SERIAL_CLK_DIV 1.f #ifndef M_PI @@ -90,7 +92,7 @@ int main() { PIO pio = pio0; uint sm = 0; uint offset = pio_add_program(pio, &st7789_lcd_program); - st7789_lcd_program_init(pio, sm, offset, PIN_DIN, PIN_CLK, SERIAL_CLK_DIV); + st7789_lcd_program_init(pio, sm, offset, SPI_POLARITY, PIN_DIN, PIN_CLK, SERIAL_CLK_DIV); gpio_init(PIN_CS); gpio_init(PIN_DC); From 0fbb30ea08f7fb4e34762636ec704637c305a2df Mon Sep 17 00:00:00 2001 From: mkerna Date: Thu, 31 Aug 2023 15:00:30 -0400 Subject: [PATCH 2/7] Update st7789_lcd.pio Fixes issue 370. Allows change to polarity. --- pio/st7789_lcd/st7789_lcd.pio | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pio/st7789_lcd/st7789_lcd.pio b/pio/st7789_lcd/st7789_lcd.pio index aa35c683f..ece2a1a83 100644 --- a/pio/st7789_lcd/st7789_lcd.pio +++ b/pio/st7789_lcd/st7789_lcd.pio @@ -22,7 +22,7 @@ // but we are using a threshold of 8 here (consume 1 byte from each FIFO entry // and discard the remainder) to make things easier for software on the other side -static inline void st7789_lcd_program_init(PIO pio, uint sm, uint offset, uint data_pin, uint clk_pin, float clk_div) { +static inline void st7789_lcd_program_init(PIO pio, uint sm, uint offset, bool cpol, uint data_pin, uint clk_pin, float clk_div) { pio_gpio_init(pio, data_pin); pio_gpio_init(pio, clk_pin); pio_sm_set_consecutive_pindirs(pio, sm, data_pin, 1, true); @@ -33,6 +33,11 @@ static inline void st7789_lcd_program_init(PIO pio, uint sm, uint offset, uint d sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX); sm_config_set_clkdiv(&c, clk_div); sm_config_set_out_shift(&c, false, true, 8); + + // The pin muxes can be configured to invert the output (among other things + // and this is a cheesy way to get CPOL=1 + gpio_set_outover(clk_pin, cpol ? GPIO_OVERRIDE_INVERT : GPIO_OVERRIDE_NORMAL); + pio_sm_init(pio, sm, offset, &c); pio_sm_set_enabled(pio, sm, true); } From e6daba9ea28fe61d39433a4d9f355335d16ba5ed Mon Sep 17 00:00:00 2001 From: mkerna Date: Thu, 31 Aug 2023 15:07:20 -0400 Subject: [PATCH 3/7] Update st7789_lcd.c --- pio/st7789_lcd/st7789_lcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pio/st7789_lcd/st7789_lcd.c b/pio/st7789_lcd/st7789_lcd.c index bfe153763..caa0e55cb 100644 --- a/pio/st7789_lcd/st7789_lcd.c +++ b/pio/st7789_lcd/st7789_lcd.c @@ -28,7 +28,7 @@ #define PIN_RESET 4 #define PIN_BL 5 -#define SPI_POLARITY 0 // default to 0, displays require polarity 1 +#define SPI_POLARITY 0 // default to 0, some displays require polarity 1 #define SERIAL_CLK_DIV 1.f From ddb810eddede0bbd5ac05626539787d03d45fa5a Mon Sep 17 00:00:00 2001 From: mkerna Date: Fri, 1 Sep 2023 19:04:43 -0400 Subject: [PATCH 4/7] Update st7789_lcd.c --- pio/st7789_lcd/st7789_lcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pio/st7789_lcd/st7789_lcd.c b/pio/st7789_lcd/st7789_lcd.c index caa0e55cb..152963d6d 100644 --- a/pio/st7789_lcd/st7789_lcd.c +++ b/pio/st7789_lcd/st7789_lcd.c @@ -92,7 +92,7 @@ int main() { PIO pio = pio0; uint sm = 0; uint offset = pio_add_program(pio, &st7789_lcd_program); - st7789_lcd_program_init(pio, sm, offset, SPI_POLARITY, PIN_DIN, PIN_CLK, SERIAL_CLK_DIV); + st7789_lcd_program_init(pio, sm, offset, SPI_POLARITY, PIN_DIN, PIN_CLK, SERIAL_CLK_DIV); gpio_init(PIN_CS); gpio_init(PIN_DC); From 8e17b7baeeacac4c0b029d41f3def8e5e942bb97 Mon Sep 17 00:00:00 2001 From: mkerna Date: Fri, 1 Sep 2023 19:06:08 -0400 Subject: [PATCH 5/7] Update st7789_lcd.pio --- pio/st7789_lcd/st7789_lcd.pio | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pio/st7789_lcd/st7789_lcd.pio b/pio/st7789_lcd/st7789_lcd.pio index ece2a1a83..037d9ab13 100644 --- a/pio/st7789_lcd/st7789_lcd.pio +++ b/pio/st7789_lcd/st7789_lcd.pio @@ -34,8 +34,8 @@ static inline void st7789_lcd_program_init(PIO pio, uint sm, uint offset, bool c sm_config_set_clkdiv(&c, clk_div); sm_config_set_out_shift(&c, false, true, 8); - // The pin muxes can be configured to invert the output (among other things - // and this is a cheesy way to get CPOL=1 + // The pin muxes can be configured to invert the output (among other things + // and this is a cheesy way to allow changing polarity gpio_set_outover(clk_pin, cpol ? GPIO_OVERRIDE_INVERT : GPIO_OVERRIDE_NORMAL); pio_sm_init(pio, sm, offset, &c); From 5a72b25472f773a325753e7442f543dd2c542776 Mon Sep 17 00:00:00 2001 From: mkerna Date: Sat, 2 Sep 2023 07:15:32 -0400 Subject: [PATCH 6/7] Update st7789_lcd.c --- pio/st7789_lcd/st7789_lcd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pio/st7789_lcd/st7789_lcd.c b/pio/st7789_lcd/st7789_lcd.c index 152963d6d..f6724262b 100644 --- a/pio/st7789_lcd/st7789_lcd.c +++ b/pio/st7789_lcd/st7789_lcd.c @@ -28,7 +28,7 @@ #define PIN_RESET 4 #define PIN_BL 5 -#define SPI_POLARITY 0 // default to 0, some displays require polarity 1 +#define SPI_CLOCK_POLARITY 0 // default to 0, some displays require polarity 1 #define SERIAL_CLK_DIV 1.f @@ -92,7 +92,7 @@ int main() { PIO pio = pio0; uint sm = 0; uint offset = pio_add_program(pio, &st7789_lcd_program); - st7789_lcd_program_init(pio, sm, offset, SPI_POLARITY, PIN_DIN, PIN_CLK, SERIAL_CLK_DIV); + st7789_lcd_program_init(pio, sm, offset, SPI_CLOCK_POLARITY, PIN_DIN, PIN_CLK, SERIAL_CLK_DIV); gpio_init(PIN_CS); gpio_init(PIN_DC); From 2f088935f2e98368f5654fe1230c57ce546b3c8d Mon Sep 17 00:00:00 2001 From: mkerna Date: Tue, 19 Sep 2023 16:40:44 -0400 Subject: [PATCH 7/7] Update st7789_lcd.pio --- pio/st7789_lcd/st7789_lcd.pio | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pio/st7789_lcd/st7789_lcd.pio b/pio/st7789_lcd/st7789_lcd.pio index 037d9ab13..165fc4b5c 100644 --- a/pio/st7789_lcd/st7789_lcd.pio +++ b/pio/st7789_lcd/st7789_lcd.pio @@ -34,7 +34,7 @@ static inline void st7789_lcd_program_init(PIO pio, uint sm, uint offset, bool c sm_config_set_clkdiv(&c, clk_div); sm_config_set_out_shift(&c, false, true, 8); - // The pin muxes can be configured to invert the output (among other things + // The pin muxes can be configured to invert the output (among other things), // and this is a cheesy way to allow changing polarity gpio_set_outover(clk_pin, cpol ? GPIO_OVERRIDE_INVERT : GPIO_OVERRIDE_NORMAL);