Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pio/st7789_lcd/st7789_lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#define PIN_RESET 4
#define PIN_BL 5

#define SPI_POLARITY 0 // default to 0, some displays require polarity 1

#define SERIAL_CLK_DIV 1.f

#ifndef M_PI
Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be tabs vs 4 spaces?


gpio_init(PIN_CS);
gpio_init(PIN_DC);
Expand Down
7 changes: 6 additions & 1 deletion pio/st7789_lcd/st7789_lcd.pio
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be tabs vs 4 spaces?

// and this is a cheesy way to get CPOL=1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment states CPOL=1 whereas that is actually CPOL=cpol. Perhaps could change to

-and this is a cheesy way to get CPOL=1
+and this is a cheesy way to set CPOL

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. But I took that comment directly from code already in the repo. I think it means that it's a cheesy way to get inverted polarity (i.e. CPOL=1, vs. CPOL=0).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair

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);
}
Expand Down