Slight efactor of st7789 driver, and addition of the flip function

This commit is contained in:
David Tillotson 2021-03-06 16:45:38 +00:00 committed by Phil Howard
parent 19a084f219
commit 237d59d1d1
4 changed files with 20 additions and 8 deletions

View File

@ -7,6 +7,7 @@
#include "hardware/pwm.h" #include "hardware/pwm.h"
namespace pimoroni { namespace pimoroni {
char madctl[2];
void ST7789::init(bool auto_init_sequence) { void ST7789::init(bool auto_init_sequence) {
// configure spi interface and pins // configure spi interface and pins
@ -50,15 +51,16 @@ namespace pimoroni {
sleep_ms(150); sleep_ms(150);
if(width == 240 && height == 240) { if(width == 240 && height == 240) {
command(reg::MADCTL, 1, "\x04"); // row/column addressing order - rgb pixel order madctl = 0x04;
command(reg::TEON, 1, "\x00"); // enable frame sync signal if used
command(reg::COLMOD, 1, "\x05"); // 16 bits per pixel
} }
if(width == 240 && height == 135) { if(width == 240 && height == 135) {
command(reg::MADCTL, 1, "\x70"); madctl = 0x70;
command(reg::COLMOD, 1, "\x05");
} }
command(reg::MADCTL, 1, madctl); // row/column addressing order - rgb pixel order
command(reg::TEON, 1, "\x00"); // enable frame sync signal if used
command(reg::COLMOD, 1, "\x05"); // 16 bits per pixel
command(reg::INVON); // set inversion mode command(reg::INVON); // set inversion mode
command(reg::SLPOUT); // leave sleep mode command(reg::SLPOUT); // leave sleep mode
@ -147,4 +149,9 @@ namespace pimoroni {
void ST7789::vsync_callback(gpio_irq_callback_t callback) { void ST7789::vsync_callback(gpio_irq_callback_t callback) {
gpio_set_irq_enabled_with_callback(vsync, GPIO_IRQ_EDGE_RISE, true, callback); gpio_set_irq_enabled_with_callback(vsync, GPIO_IRQ_EDGE_RISE, true, callback);
} }
}
void ST7789::flip(){
madctl[0] ^= 0xC0;
command(reg::MADCTL, 1, madctl);
}
}

View File

@ -47,6 +47,7 @@ namespace pimoroni {
void vsync_callback(gpio_irq_callback_t callback); void vsync_callback(gpio_irq_callback_t callback);
void update(bool dont_block = false); void update(bool dont_block = false);
void set_backlight(uint8_t brightness); void set_backlight(uint8_t brightness);
void flip();
enum reg { enum reg {
SWRESET = 0x01, SWRESET = 0x01,

View File

@ -79,4 +79,7 @@ namespace pimoroni {
return !gpio_get(button); return !gpio_get(button);
} }
} void flip() {
screen.flip();
}
}

View File

@ -26,6 +26,7 @@ namespace pimoroni {
void set_backlight(uint8_t brightness); void set_backlight(uint8_t brightness);
void set_led(uint8_t r, uint8_t g, uint8_t b); void set_led(uint8_t r, uint8_t g, uint8_t b);
bool is_pressed(uint8_t button); bool is_pressed(uint8_t button);
void flip();
}; };
} }