diff --git a/drivers/st7567/st7567.cpp b/drivers/st7567/st7567.cpp index 06f12bd6..1a66de67 100644 --- a/drivers/st7567/st7567.cpp +++ b/drivers/st7567/st7567.cpp @@ -147,7 +147,7 @@ namespace pimoroni { for (uint8_t page=0; page < 8 ; page++){ //select page - for (uint16_t pixel_index=0 ; pixel_index < (PAGESIZE * 8) ; pixel_index++){ //cycle through a page worth of bits from the fb + for (uint16_t pixel_index=0 ; pixel_index < (PAGESIZE * 8) ; pixel_index++){ //cycle through a page worth of bits from the fb page_byte_selector = ((pixel_index % 128)); page_bit_selector = (pixel_index / 128); @@ -167,22 +167,21 @@ namespace pimoroni { if(graphics->pen_type == PicoGraphics::PEN_1BIT) { command(reg::ENTER_RMWMODE); - - command(reg::SETPAGESTART | page); - command(reg::SETCOLL); - command(reg::SETCOLH); - gpio_put(dc, 1); // data mode - gpio_put(cs, 0); - spi_write_blocking(spi, &page_buffer[0], PAGESIZE ); - gpio_put(cs, 1); - gpio_put(dc, 0); // Back to command mode + command(reg::SETPAGESTART | page); + command(reg::SETCOLL); + command(reg::SETCOLH); + gpio_put(dc, 1); // data mode + gpio_put(cs, 0); + spi_write_blocking(spi, &page_buffer[0], PAGESIZE ); + gpio_put(cs, 1); + gpio_put(dc, 0); // Back to command mode } else{ //other pen types incompatable return; } } gpio_put(cs, 1); - + } void ST7567::set_backlight(uint8_t brightness) { diff --git a/drivers/st7567/st7567.hpp b/drivers/st7567/st7567.hpp index de0956b3..001be289 100644 --- a/drivers/st7567/st7567.hpp +++ b/drivers/st7567/st7567.hpp @@ -34,7 +34,7 @@ namespace pimoroni { uint sck; uint mosi; uint bl; - uint reset_pin=21; + uint reset_pin; uint32_t spi_baud = 10000000; //10Mhz @@ -45,7 +45,6 @@ namespace pimoroni { // Constructors/Destructor //-------------------------------------------------- public: - SPIPins gfx_pack_pins = {PIMORONI_SPI_DEFAULT_INSTANCE, 17, SPI_DEFAULT_SCK, SPI_DEFAULT_MOSI, PIN_UNUSED, 16, SPI_BG_FRONT_PWM}; ST7567(uint16_t width, uint16_t height, SPIPins pins) : DisplayDriver(width, height, ROTATE_0), diff --git a/examples/gfx_pack/gfx_demo.cpp b/examples/gfx_pack/gfx_demo.cpp index 5b4258b1..6bd2d746 100644 --- a/examples/gfx_pack/gfx_demo.cpp +++ b/examples/gfx_pack/gfx_demo.cpp @@ -9,18 +9,19 @@ #include "libraries/gfx_pack/gfx_pack.hpp" #include "drivers/st7567/st7567.hpp" #include "drivers/button/button.hpp" +#include "drivers/rgbled/rgbled.hpp" using namespace pimoroni; -SPIPins pins = {PIMORONI_SPI_DEFAULT_INSTANCE, 17, SPI_DEFAULT_SCK, SPI_DEFAULT_MOSI, PIN_UNUSED, 16, SPI_BG_FRONT_PWM}; -ST7567 st7567(128, 64, pins); + +ST7567 st7567(128, 64, gfx_pack_pins); PicoGraphics_Pen1Bit graphics(st7567.width, st7567.height, nullptr); +RGBLED backlight_rgb(GfxPack::BL_R, GfxPack::BL_G, GfxPack::BL_B, Polarity::ACTIVE_HIGH); - - -Button button_a(gfx_pack::A); -Button button_b(gfx_pack::B); -Button button_x(gfx_pack::X); -Button button_y(gfx_pack::Y); +Button button_a(GfxPack::A); +Button button_b(GfxPack::B); +Button button_c(GfxPack::C); +Button button_d(GfxPack::D); +Button button_e(GfxPack::E); // HSV Conversion expects float inputs in the range of 0.00-1.00 for each channel // Outputs are rgb in the range 0-255 for each channel @@ -43,6 +44,7 @@ void from_hsv(float h, float s, float v, uint8_t &r, uint8_t &g, uint8_t &b) { } int main() { + st7567.set_backlight(255); struct pt { @@ -68,15 +70,17 @@ int main() { Point text_location(0, 0); - //Pen BG = graphics.create_pen(120, 40, 60); - //Pen WHITE = graphics.create_pen(255, 255, 255); - +float hue = 0.0; while(true) { if(button_a.raw()) text_location.x -= 1; if(button_b.raw()) text_location.x += 1; - if(button_x.raw()) text_location.y -= 1; - if(button_y.raw()) text_location.y += 1; + if(button_c.raw()) text_location.y -= 1; + if(button_d.raw()) text_location.y += 1; + + if(button_e.raw()){ + text_location.x = 0; + text_location.y = 0;} graphics.set_pen(0); graphics.clear(); @@ -110,6 +114,8 @@ int main() { graphics.text("Hello World", text_location, 320); // update screen + backlight_rgb.set_hsv(hue, 0.0f, 1.0f); + hue += 0.002; st7567.update(&graphics); sleep_ms(1000/15); } diff --git a/libraries/gfx_pack/gfx_pack.hpp b/libraries/gfx_pack/gfx_pack.hpp index 8a231874..9256e135 100644 --- a/libraries/gfx_pack/gfx_pack.hpp +++ b/libraries/gfx_pack/gfx_pack.hpp @@ -1,16 +1,22 @@ #pragma once #include "pico/stdlib.h" +#include "common/pimoroni_bus.hpp" namespace pimoroni { - class gfx_pack { + + SPIPins gfx_pack_pins= {PIMORONI_SPI_DEFAULT_INSTANCE, 17, SPI_DEFAULT_SCK, SPI_DEFAULT_MOSI, PIN_UNUSED, 20, 9}; + + class GfxPack{ + public: static const int WIDTH = 128; static const int HEIGHT = 64; static const uint8_t A = 12; static const uint8_t B = 13; - static const uint8_t X = 14; - static const uint8_t Y = 15; + static const uint8_t C = 14; + static const uint8_t D = 15; + static const uint8_t E = 22; static const uint8_t BL_R = 6; static const uint8_t BL_G = 7; static const uint8_t BL_B = 8;