From 4848e7ba596f94d1b2a129657bbac5bb9656568c Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Tue, 7 Jun 2022 19:02:30 +0100 Subject: [PATCH] PicoGraphics/ST7789/ST3375: Fixup C++ examples and libraries. --- drivers/st7735/st7735.cmake | 2 +- .../breakout_as7262/explorer_bargraph.cmake | 2 +- .../breakout_as7262/explorer_bargraph.cpp | 49 +++--- .../breakout_colourlcd160x80/CMakeLists.txt | 4 +- .../colorlcd_160x80_demo.cpp | 59 ++++++++ examples/breakout_colourlcd160x80/demo.cpp | 62 -------- .../breakout_colourlcd240x240/CMakeLists.txt | 4 +- .../colorlcd_240x240_demo.cpp | 68 +++++++++ examples/breakout_colourlcd240x240/demo.cpp | 69 --------- examples/breakout_roundlcd/CMakeLists.txt | 2 +- examples/breakout_roundlcd/roundlcd_demo.cpp | 29 ++-- examples/pico_display/CMakeLists.txt | 4 +- .../{demo.cpp => pico_display_demo.cpp} | 50 ++++--- examples/pico_display_2/CMakeLists.txt | 4 +- .../{demo.cpp => pico_display_2_demo.cpp} | 44 +++--- examples/pico_enc_explorer/CMakeLists.txt | 2 +- .../pico_enc_explorer/pico_enc_explorer.cpp | 43 +++--- examples/pico_explorer/CMakeLists.txt | 4 +- examples/pico_explorer/pico_explorer_demo.cpp | 141 +++++++----------- examples/pico_explorer/text_demo.cpp | 35 +++-- examples/pico_explorer_encoder/CMakeLists.txt | 2 +- .../pico_explorer_encoder.cpp | 63 ++++---- examples/pico_pot_explorer/CMakeLists.txt | 2 +- .../pico_pot_explorer/pico_pot_explorer.cpp | 43 +++--- examples/pico_rtc_display/CMakeLists.txt | 2 +- .../pico_rtc_display/pico_rtc_display.cpp | 64 ++++---- examples/pico_tof_display/CMakeLists.txt | 2 +- .../pico_tof_display/pico_tof_display.cpp | 64 ++++---- .../pico_trackball_display/CMakeLists.txt | 2 +- .../pico_trackball_display.cpp | 62 ++++---- examples/tufty2040/tufty2040_drawing.cmake | 3 +- examples/tufty2040/tufty2040_drawing.cpp | 45 +++--- libraries/CMakeLists.txt | 2 - .../breakout_colourlcd160x80/CMakeLists.txt | 1 - .../breakout_colourlcd160x80.cmake | 11 -- .../breakout_colourlcd160x80.cpp | 6 - .../breakout_colourlcd160x80.hpp | 47 ------ .../breakout_colourlcd240x240/CMakeLists.txt | 11 -- .../breakout_colourlcd240x240.cmake | 14 -- .../breakout_colourlcd240x240.cpp | 58 ------- .../breakout_colourlcd240x240.hpp | 53 ------- libraries/breakout_roundlcd/CMakeLists.txt | 11 -- .../breakout_roundlcd/breakout_roundlcd.cmake | 14 -- .../breakout_roundlcd/breakout_roundlcd.cpp | 59 -------- .../breakout_roundlcd/breakout_roundlcd.hpp | 55 ------- libraries/pico_explorer/pico_explorer.cpp | 123 +-------------- libraries/pico_explorer/pico_explorer.hpp | 23 +-- libraries/pico_graphics/pico_graphics.cmake | 2 +- libraries/pico_graphics/pico_graphics.hpp | 4 +- libraries/picographics_st7789/CMakeLists.txt | 1 - libraries/picographics_st7789/README.md | 106 ------------- .../picographics_st7789.cmake | 11 -- .../picographics_st7789.cpp | 9 -- .../picographics_st7789.hpp | 50 ------- 54 files changed, 492 insertions(+), 1210 deletions(-) create mode 100644 examples/breakout_colourlcd160x80/colorlcd_160x80_demo.cpp delete mode 100644 examples/breakout_colourlcd160x80/demo.cpp create mode 100644 examples/breakout_colourlcd240x240/colorlcd_240x240_demo.cpp delete mode 100644 examples/breakout_colourlcd240x240/demo.cpp rename examples/pico_display/{demo.cpp => pico_display_demo.cpp} (56%) rename examples/pico_display_2/{demo.cpp => pico_display_2_demo.cpp} (70%) delete mode 100644 libraries/breakout_colourlcd160x80/CMakeLists.txt delete mode 100644 libraries/breakout_colourlcd160x80/breakout_colourlcd160x80.cmake delete mode 100644 libraries/breakout_colourlcd160x80/breakout_colourlcd160x80.cpp delete mode 100644 libraries/breakout_colourlcd160x80/breakout_colourlcd160x80.hpp delete mode 100644 libraries/breakout_colourlcd240x240/CMakeLists.txt delete mode 100644 libraries/breakout_colourlcd240x240/breakout_colourlcd240x240.cmake delete mode 100644 libraries/breakout_colourlcd240x240/breakout_colourlcd240x240.cpp delete mode 100644 libraries/breakout_colourlcd240x240/breakout_colourlcd240x240.hpp delete mode 100644 libraries/breakout_roundlcd/CMakeLists.txt delete mode 100644 libraries/breakout_roundlcd/breakout_roundlcd.cmake delete mode 100644 libraries/breakout_roundlcd/breakout_roundlcd.cpp delete mode 100644 libraries/breakout_roundlcd/breakout_roundlcd.hpp delete mode 100644 libraries/picographics_st7789/CMakeLists.txt delete mode 100644 libraries/picographics_st7789/README.md delete mode 100644 libraries/picographics_st7789/picographics_st7789.cmake delete mode 100644 libraries/picographics_st7789/picographics_st7789.cpp delete mode 100644 libraries/picographics_st7789/picographics_st7789.hpp diff --git a/drivers/st7735/st7735.cmake b/drivers/st7735/st7735.cmake index 3a44ee58..85c8ae60 100644 --- a/drivers/st7735/st7735.cmake +++ b/drivers/st7735/st7735.cmake @@ -7,4 +7,4 @@ target_sources(${DRIVER_NAME} INTERFACE target_include_directories(${DRIVER_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR}) # Pull in pico libraries that we need -target_link_libraries(${DRIVER_NAME} INTERFACE pico_stdlib hardware_spi hardware_pwm hardware_dma) +target_link_libraries(${DRIVER_NAME} INTERFACE pico_stdlib pimoroni_bus hardware_spi hardware_pwm hardware_dma) diff --git a/examples/breakout_as7262/explorer_bargraph.cmake b/examples/breakout_as7262/explorer_bargraph.cmake index 48b8b989..2972e1a0 100644 --- a/examples/breakout_as7262/explorer_bargraph.cmake +++ b/examples/breakout_as7262/explorer_bargraph.cmake @@ -10,7 +10,7 @@ pico_enable_stdio_usb(${OUTPUT_NAME} 1) pico_enable_stdio_uart(${OUTPUT_NAME} 1) # Pull in pico libraries that we need -target_link_libraries(${OUTPUT_NAME} pico_stdlib breakout_as7262 pico_explorer picographics_st7789) +target_link_libraries(${OUTPUT_NAME} pico_stdlib breakout_as7262 pico_explorer pico_graphics st7789) # create map/bin/hex file etc. pico_add_extra_outputs(${OUTPUT_NAME}) diff --git a/examples/breakout_as7262/explorer_bargraph.cpp b/examples/breakout_as7262/explorer_bargraph.cpp index 130c51a7..35ba9c6f 100644 --- a/examples/breakout_as7262/explorer_bargraph.cpp +++ b/examples/breakout_as7262/explorer_bargraph.cpp @@ -4,7 +4,8 @@ #include "breakout_as7262.hpp" #include "pico_explorer.hpp" -#include "picographics_st7789.hpp" +#include "drivers/st7789/st7789.hpp" +#include "libraries/pico_graphics/pico_graphics.hpp" using namespace pimoroni; @@ -13,16 +14,18 @@ constexpr float INTEGRATION_TIME = 10.0f; I2C i2c(BOARD::PICO_EXPLORER); BreakoutAS7262 as7262(&i2c); -PicoGraphicsST7789 display(PicoExplorer::WIDTH, PicoExplorer::HEIGHT, ROTATE_0, false, nullptr, get_spi_pins(BG_SPI_FRONT)); +ST7789 st7789(PicoExplorer::WIDTH, PicoExplorer::HEIGHT, ROTATE_0, false, get_spi_pins(BG_SPI_FRONT)); +PicoGraphics_PenRGB332 graphics(st7789.width, st7789.height, nullptr); -uint8_t bar_width = PicoExplorer::WIDTH / 6; -uint8_t bar_height = PicoExplorer::HEIGHT; void draw_bar(float scale, uint16_t channel) { + static uint8_t bar_width = st7789.width / 6; + static uint8_t bar_height = st7789.height; + int16_t bar_top = bar_height - (bar_height * scale); bar_top = std::max((int16_t)0, bar_top); int16_t current_bar_height = bar_height - bar_top; - display.rectangle(Rect(channel * bar_width, bar_top, bar_width, current_bar_height - 1)); + graphics.rectangle(Rect(channel * bar_width, bar_top, bar_width, current_bar_height - 1)); } int main() { @@ -44,17 +47,17 @@ int main() { as7262.set_indicator_current(AS7262::indicator_current::ma4); as7262.set_leds(true, true); - Pen BLACK = display.create_pen(0, 0, 0); - Pen RED = display.create_pen(255, 0, 0); - Pen ORANGE = display.create_pen(255, 128, 0); - Pen YELLOW = display.create_pen(255, 255, 0); - Pen GREEN = display.create_pen(0, 255, 0); - Pen BLUE = display.create_pen(0, 0, 255); - Pen VIOLET = display.create_pen(255, 0, 255); + Pen BLACK = graphics.create_pen(0, 0, 0); + Pen RED = graphics.create_pen(255, 0, 0); + Pen ORANGE = graphics.create_pen(255, 128, 0); + Pen YELLOW = graphics.create_pen(255, 255, 0); + Pen GREEN = graphics.create_pen(0, 255, 0); + Pen BLUE = graphics.create_pen(0, 0, 255); + Pen VIOLET = graphics.create_pen(255, 0, 255); while(true) { - display.set_pen(BLACK); - display.clear(); + graphics.set_pen(BLACK); + graphics.clear(); AS7262::reading reading = as7262.read(); printf("R: %f O: %f Y: %f G: %f B: %f V: %f \n", @@ -73,34 +76,34 @@ int main() { if(reading.blue > m) m = reading.blue; if(reading.violet > m) m = reading.violet; - display.set_pen(BLACK); - display.clear(); + graphics.set_pen(BLACK); + graphics.clear(); // Red - display.set_pen(RED); + graphics.set_pen(RED); draw_bar(reading.red / m, 0); // Orange - display.set_pen(ORANGE); + graphics.set_pen(ORANGE); draw_bar(reading.orange / m, 1); // Yellow - display.set_pen(YELLOW); + graphics.set_pen(YELLOW); draw_bar(reading.yellow / m, 2); // Green - display.set_pen(GREEN); + graphics.set_pen(GREEN); draw_bar(reading.green / m, 3); // Blue - display.set_pen(BLUE); + graphics.set_pen(BLUE); draw_bar(reading.blue / m, 4); // Violet - display.set_pen(VIOLET); + graphics.set_pen(VIOLET); draw_bar(reading.violet / m, 5); - display.update(); + st7789.update(&graphics); sleep_ms(INTEGRATION_TIME); } diff --git a/examples/breakout_colourlcd160x80/CMakeLists.txt b/examples/breakout_colourlcd160x80/CMakeLists.txt index c54ee549..93f98791 100644 --- a/examples/breakout_colourlcd160x80/CMakeLists.txt +++ b/examples/breakout_colourlcd160x80/CMakeLists.txt @@ -2,11 +2,11 @@ set(OUTPUT_NAME colourlcd160x80_demo) add_executable( ${OUTPUT_NAME} - demo.cpp + colorlcd_160x80_demo.cpp ) # Pull in pico libraries that we need -target_link_libraries(${OUTPUT_NAME} pico_stdlib breakout_colourlcd160x80) +target_link_libraries(${OUTPUT_NAME} pico_stdlib pico_graphics st7735 hardware_spi) # create map/bin/hex file etc. pico_add_extra_outputs(${OUTPUT_NAME}) diff --git a/examples/breakout_colourlcd160x80/colorlcd_160x80_demo.cpp b/examples/breakout_colourlcd160x80/colorlcd_160x80_demo.cpp new file mode 100644 index 00000000..e94c985c --- /dev/null +++ b/examples/breakout_colourlcd160x80/colorlcd_160x80_demo.cpp @@ -0,0 +1,59 @@ +#include +#include + +#include "drivers/st7735/st7735.hpp" +#include "libraries/pico_graphics/pico_graphics.hpp" + +using namespace pimoroni; + +ST7735 st7735(160, 80, get_spi_pins(BG_SPI_FRONT)); +PicoGraphics_PenP8 graphics(st7735.width, st7735.height, nullptr); + +int main() { + st7735.set_backlight(255); + + struct pt { + float x; + float y; + uint8_t r; + float dx; + float dy; + Pen pen; + }; + + std::vector shapes; + for(int i = 0; i < 1000; i++) { + pt shape; + shape.x = rand() % graphics.bounds.w; + shape.y = rand() % graphics.bounds.h; + shape.r = (rand() % 10) + 3; + shape.dx = float(rand() % 255) / 128.0f; + shape.dy = float(rand() % 255) / 128.0f; + shape.pen = graphics.create_pen(rand() % 255, rand() % 255, rand() % 255); + shapes.push_back(shape); + } + + uint8_t bg = graphics.create_pen(120, 40, 60); + + while(true) { + graphics.set_pen(bg); + graphics.clear(); + + for(auto &shape : shapes) { + shape.x += shape.dx; + shape.y += shape.dy; + if(shape.x < 0) shape.dx *= -1; + if(shape.x >= graphics.bounds.w) shape.dx *= -1; + if(shape.y < 0) shape.dy *= -1; + if(shape.y >= graphics.bounds.h) shape.dy *= -1; + + graphics.set_pen(shape.pen); + graphics.circle(Point(shape.x, shape.y), shape.r); + } + + // update screen + st7735.update(&graphics); + } + + return 0; +} diff --git a/examples/breakout_colourlcd160x80/demo.cpp b/examples/breakout_colourlcd160x80/demo.cpp deleted file mode 100644 index f2757536..00000000 --- a/examples/breakout_colourlcd160x80/demo.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include -#include - -#include "breakout_colourlcd160x80.hpp" - -using namespace pimoroni; - -uint8_t buffer[BreakoutColourLCD160x80::WIDTH * BreakoutColourLCD160x80::HEIGHT]; -BreakoutColourLCD160x80 lcd((void *)buffer); - -int main() { - lcd.init(); - lcd.set_backlight(255); - - // Delete the default palette and allow us to create up to 256 of our own RGB565 colours - lcd.set_palette_mode(BreakoutColourLCD160x80::PaletteModeUSER); - - struct pt { - float x; - float y; - uint8_t r; - float dx; - float dy; - Pen pen; - }; - - std::vector shapes; - for(int i = 0; i < 1000; i++) { - pt shape; - shape.x = rand() % lcd.bounds.w; - shape.y = rand() % lcd.bounds.h; - shape.r = (rand() % 10) + 3; - shape.dx = float(rand() % 255) / 128.0f; - shape.dy = float(rand() % 255) / 128.0f; - shape.pen = lcd.create_pen(rand() % 255, rand() % 255, rand() % 255); - shapes.push_back(shape); - } - - uint8_t bg = lcd.create_pen(120, 40, 60); - - while(true) { - lcd.set_pen(bg); - lcd.clear(); - - for(auto &shape : shapes) { - shape.x += shape.dx; - shape.y += shape.dy; - if(shape.x < 0) shape.dx *= -1; - if(shape.x >= lcd.bounds.w) shape.dx *= -1; - if(shape.y < 0) shape.dy *= -1; - if(shape.y >= lcd.bounds.h) shape.dy *= -1; - - lcd.set_pen(shape.pen); - lcd.circle(Point(shape.x, shape.y), shape.r); - } - - // update screen - lcd.update(); - } - - return 0; -} diff --git a/examples/breakout_colourlcd240x240/CMakeLists.txt b/examples/breakout_colourlcd240x240/CMakeLists.txt index 26ca71e0..bcb4b533 100644 --- a/examples/breakout_colourlcd240x240/CMakeLists.txt +++ b/examples/breakout_colourlcd240x240/CMakeLists.txt @@ -2,11 +2,11 @@ set(OUTPUT_NAME colourlcd240x240_demo) add_executable( ${OUTPUT_NAME} - demo.cpp + colorlcd_240x240_demo.cpp ) # Pull in pico libraries that we need -target_link_libraries(${OUTPUT_NAME} pico_stdlib picographics_st7789) +target_link_libraries(${OUTPUT_NAME} pico_stdlib pico_graphics st7789) # create map/bin/hex file etc. pico_add_extra_outputs(${OUTPUT_NAME}) diff --git a/examples/breakout_colourlcd240x240/colorlcd_240x240_demo.cpp b/examples/breakout_colourlcd240x240/colorlcd_240x240_demo.cpp new file mode 100644 index 00000000..e4fb9f4b --- /dev/null +++ b/examples/breakout_colourlcd240x240/colorlcd_240x240_demo.cpp @@ -0,0 +1,68 @@ +#include +#include + +#include "drivers/st7789/st7789.hpp" +#include "libraries/pico_graphics/pico_graphics.hpp" + +using namespace pimoroni; + +const int WIDTH = 240; +const int HEIGHT = 240; + +ST7789 st7789(WIDTH, HEIGHT, ROTATE_0, false, get_spi_pins(BG_SPI_FRONT)); +PicoGraphics_PenRGB332 graphics(st7789.width, st7789.height, nullptr); + +int main() { + st7789.set_backlight(255); + + struct pt { + float x; + float y; + uint8_t r; + float dx; + float dy; + Pen pen; + }; + + std::vector shapes; + for(int i = 0; i < 100; i++) { + pt shape; + shape.r = (rand() % 10) + 3; + shape.x = rand() % (graphics.bounds.w - (shape.r * 2)); + shape.y = rand() % (graphics.bounds.h - (shape.r * 2)); + shape.x += shape.r; + shape.y += shape.r; + shape.dx = float(rand() % 255) / 64.0f; + shape.dy = float(rand() % 255) / 64.0f; + shape.pen = graphics.create_pen(rand() % 255, rand() % 255, rand() % 255); + shapes.push_back(shape); + } + + Pen BG = graphics.create_pen(120, 40, 60); + Pen WHITE = graphics.create_pen(255, 255, 255); + + while(true) { + graphics.set_pen(BG); + graphics.clear(); + + for(auto &shape : shapes) { + shape.x += shape.dx; + shape.y += shape.dy; + if(shape.x < shape.r) shape.dx *= -1; + if(shape.x >= graphics.bounds.w - shape.r) shape.dx *= -1; + if(shape.y < shape.r) shape.dy *= -1; + if(shape.y >= graphics.bounds.h - shape.r) shape.dy *= -1; + + graphics.set_pen(shape.pen); + graphics.circle(Point(shape.x, shape.y), shape.r); + } + + graphics.set_pen(WHITE); + graphics.text("Hello World", Point(0, 0), 240); + + // update screen + st7789.update(&graphics); + } + + return 0; +} diff --git a/examples/breakout_colourlcd240x240/demo.cpp b/examples/breakout_colourlcd240x240/demo.cpp deleted file mode 100644 index dce1156d..00000000 --- a/examples/breakout_colourlcd240x240/demo.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include -#include - -#include "picographics_st7789.hpp" - -using namespace pimoroni; - -const int WIDTH = 240; -const int HEIGHT = 240; - -PicoGraphicsST7789 display(WIDTH, HEIGHT, ROTATE_0, false, nullptr, get_spi_pins(BG_SPI_FRONT)); - -int main() { - display.set_backlight(255); - - // Delete the default palette and allow us to create up to 256 of our own RGB565 colours - display.set_palette_mode(PicoGraphicsST7789::PaletteModeUSER); - - struct pt { - float x; - float y; - uint8_t r; - float dx; - float dy; - Pen pen; - }; - - std::vector shapes; - for(int i = 0; i < 100; i++) { - pt shape; - shape.r = (rand() % 10) + 3; - shape.x = rand() % (display.bounds.w - (shape.r * 2)); - shape.y = rand() % (display.bounds.h - (shape.r * 2)); - shape.x += shape.r; - shape.y += shape.r; - shape.dx = float(rand() % 255) / 64.0f; - shape.dy = float(rand() % 255) / 64.0f; - shape.pen = display.create_pen(rand() % 255, rand() % 255, rand() % 255); - shapes.push_back(shape); - } - - Pen BG = display.create_pen(120, 40, 60); - Pen WHITE = display.create_pen(255, 255, 255); - - while(true) { - display.set_pen(BG); - display.clear(); - - for(auto &shape : shapes) { - shape.x += shape.dx; - shape.y += shape.dy; - if(shape.x < shape.r) shape.dx *= -1; - if(shape.x >= display.bounds.w - shape.r) shape.dx *= -1; - if(shape.y < shape.r) shape.dy *= -1; - if(shape.y >= display.bounds.h - shape.r) shape.dy *= -1; - - display.set_pen(shape.pen); - display.circle(Point(shape.x, shape.y), shape.r); - } - - display.set_pen(WHITE); - display.text("Hello World", Point(0, 0), 240); - - // update screen - display.update(); - } - - return 0; -} diff --git a/examples/breakout_roundlcd/CMakeLists.txt b/examples/breakout_roundlcd/CMakeLists.txt index daac9779..abf05124 100644 --- a/examples/breakout_roundlcd/CMakeLists.txt +++ b/examples/breakout_roundlcd/CMakeLists.txt @@ -6,7 +6,7 @@ add_executable( ) # Pull in pico libraries that we need -target_link_libraries(${OUTPUT_NAME} pico_stdlib picographics_st7789) +target_link_libraries(${OUTPUT_NAME} pico_stdlib pico_graphics st7789) # create map/bin/hex file etc. pico_add_extra_outputs(${OUTPUT_NAME}) \ No newline at end of file diff --git a/examples/breakout_roundlcd/roundlcd_demo.cpp b/examples/breakout_roundlcd/roundlcd_demo.cpp index aed2862e..54b7fcc8 100644 --- a/examples/breakout_roundlcd/roundlcd_demo.cpp +++ b/examples/breakout_roundlcd/roundlcd_demo.cpp @@ -3,7 +3,8 @@ #include #include -#include "picographics_st7789.hpp" +#include "drivers/st7789/st7789.hpp" +#include "libraries/pico_graphics/pico_graphics.hpp" #include "time.h" // Place a 1.3 Round SPI LCD in the *front* slot of breakout garden. @@ -14,7 +15,8 @@ using namespace pimoroni; const int WIDTH = 240; const int HEIGHT = 240; -PicoGraphicsST7789 display(WIDTH, HEIGHT, ROTATE_0, true, nullptr, get_spi_pins(BG_SPI_FRONT)); +ST7789 st7789(WIDTH, HEIGHT, ROTATE_0, false, get_spi_pins(BG_SPI_FRONT)); +PicoGraphics_PenRGB332 graphics(st7789.width, st7789.height, nullptr); constexpr float RADIUS = WIDTH / 2; @@ -37,29 +39,26 @@ Pen from_hsv(float h, float s, float v) { case 5: r = v; g = p; b = q; break; } - return display.create_pen(r, g, b); + return graphics.create_pen(r, g, b); } int main() { - display.set_backlight(255); - - // Delete the default palette and allow us to create up to 256 of our own RGB565 colours - // display.set_palette_mode(PicoGraphicsST7789::PaletteModeUSER); + st7789.set_backlight(255); uint32_t steps = 70; float angle_step = 0.5f; - Pen BLACK = display.create_pen(0, 0, 0); - Pen WHITE = display.create_pen(255, 255, 255); + Pen BLACK = graphics.create_pen(0, 0, 0); + Pen WHITE = graphics.create_pen(255, 255, 255); while(1) { absolute_time_t at = get_absolute_time(); uint64_t t = to_us_since_boot(at) / 100000; float angle = (t % 360) * M_PI / 180.0f; - display.set_pen(BLACK); - display.clear(); - display.set_pen(WHITE); + graphics.set_pen(BLACK); + graphics.clear(); + graphics.set_pen(WHITE); for(auto step = 0u; step < steps; step++) { auto distance = RADIUS / steps * step; @@ -74,11 +73,11 @@ int main() { auto p = from_hsv((t / 10.0f) + distance / 120.0f, 1.0, 1.0); - display.set_pen(p); - display.circle(Point(x, y), l); + graphics.set_pen(p); + graphics.circle(Point(x, y), l); } - display.update(); + st7789.update(&graphics); sleep_ms(10); } } \ No newline at end of file diff --git a/examples/pico_display/CMakeLists.txt b/examples/pico_display/CMakeLists.txt index c857d624..d6f1847a 100644 --- a/examples/pico_display/CMakeLists.txt +++ b/examples/pico_display/CMakeLists.txt @@ -1,11 +1,11 @@ add_executable( pico_display_demo - demo.cpp + pico_display_demo.cpp image_data.cpp ) # Pull in pico libraries that we need -target_link_libraries(pico_display_demo pico_stdlib hardware_spi hardware_pwm hardware_dma rgbled pico_display picographics_st7789) +target_link_libraries(pico_display_demo pico_stdlib hardware_spi hardware_pwm hardware_dma rgbled pico_display pico_graphics st7789) # create map/bin/hex file etc. pico_add_extra_outputs(pico_display_demo) \ No newline at end of file diff --git a/examples/pico_display/demo.cpp b/examples/pico_display/pico_display_demo.cpp similarity index 56% rename from examples/pico_display/demo.cpp rename to examples/pico_display/pico_display_demo.cpp index 18508bc9..6cc55122 100644 --- a/examples/pico_display/demo.cpp +++ b/examples/pico_display/pico_display_demo.cpp @@ -4,18 +4,20 @@ #include #include "pico_display.hpp" -#include "picographics_st7789.hpp" +#include "drivers/st7789/st7789.hpp" +#include "libraries/pico_graphics/pico_graphics.hpp" #include "rgbled.hpp" using namespace pimoroni; -PicoGraphicsST7789 pico_display(PicoDisplay::WIDTH, PicoDisplay::HEIGHT, ROTATE_0); +ST7789 st7789(PicoDisplay::WIDTH, PicoDisplay::HEIGHT, ROTATE_0, false, get_spi_pins(BG_SPI_FRONT)); +PicoGraphics_PenRGB332 graphics(st7789.width, st7789.height, nullptr); RGBLED led(PicoDisplay::LED_R, PicoDisplay::LED_G, PicoDisplay::LED_B); int main() { - pico_display.set_backlight(100); + st7789.set_backlight(100); struct pt { float x; @@ -34,30 +36,30 @@ int main() { shape.r = (rand() % 10) + 3; shape.dx = float(rand() % 255) / 128.0f; shape.dy = float(rand() % 255) / 128.0f; - shape.pen = pico_display.create_pen(rand() % 255, rand() % 255, rand() % 255); + shape.pen = graphics.create_pen(rand() % 255, rand() % 255, rand() % 255); shapes.push_back(shape); } uint32_t i = 0; - Pen BG = pico_display.create_pen(120, 40, 60); - Pen YELLOW = pico_display.create_pen(255, 255, 0); - Pen TEAL = pico_display.create_pen(0, 255, 255); - Pen WHITE = pico_display.create_pen(255, 255, 255); + Pen BG = graphics.create_pen(120, 40, 60); + Pen YELLOW = graphics.create_pen(255, 255, 0); + Pen TEAL = graphics.create_pen(0, 255, 255); + Pen WHITE = graphics.create_pen(255, 255, 255); while(true) { - pico_display.set_pen(BG); - pico_display.clear(); + graphics.set_pen(BG); + graphics.clear(); for(auto &shape : shapes) { shape.x += shape.dx; shape.y += shape.dy; if(shape.x < 0) shape.dx *= -1; - if(shape.x >= pico_display.bounds.w) shape.dx *= -1; + if(shape.x >= graphics.bounds.w) shape.dx *= -1; if(shape.y < 0) shape.dy *= -1; - if(shape.y >= pico_display.bounds.h) shape.dy *= -1; + if(shape.y >= graphics.bounds.h) shape.dy *= -1; - pico_display.set_pen(shape.pen); - pico_display.circle(Point(shape.x, shape.y), shape.r); + graphics.set_pen(shape.pen); + graphics.circle(Point(shape.x, shape.y), shape.r); } float led_step = fmod(i / 20.0f, M_PI * 2.0f); @@ -73,17 +75,17 @@ int main() { poly.push_back(Point(50, 85)); poly.push_back(Point(30, 45)); - pico_display.set_pen(YELLOW); + graphics.set_pen(YELLOW); //pico_display.pixel(Point(0, 0)); - pico_display.polygon(poly); + graphics.polygon(poly); - pico_display.set_pen(TEAL); - pico_display.triangle(Point(50, 50), Point(130, 80), Point(80, 110)); + graphics.set_pen(TEAL); + graphics.triangle(Point(50, 50), Point(130, 80), Point(80, 110)); - pico_display.set_pen(WHITE); - pico_display.line(Point(50, 50), Point(120, 80)); - pico_display.line(Point(20, 20), Point(120, 20)); - pico_display.line(Point(20, 20), Point(20, 120)); + graphics.set_pen(WHITE); + graphics.line(Point(50, 50), Point(120, 80)); + graphics.line(Point(20, 20), Point(120, 20)); + graphics.line(Point(20, 20), Point(20, 120)); for(int r = 0; r < 30; r++) { for(int j = 0; j < 10; j++) { @@ -92,12 +94,12 @@ int main() { rads += (float(j) / 100.0f); float cx = sin(rads) * 300.0f; float cy = cos(rads) * 300.0f; - pico_display.line(Point(120, 67), Point(cx + 120, cy + 67)); + graphics.line(Point(120, 67), Point(cx + 120, cy + 67)); } } // update screen - pico_display.update(); + st7789.update(&graphics); sleep_ms(1000 / 60); i++; } diff --git a/examples/pico_display_2/CMakeLists.txt b/examples/pico_display_2/CMakeLists.txt index 51a60e45..0dfd3438 100644 --- a/examples/pico_display_2/CMakeLists.txt +++ b/examples/pico_display_2/CMakeLists.txt @@ -2,11 +2,11 @@ set(OUTPUT_NAME pico_display2_demo) add_executable( ${OUTPUT_NAME} - demo.cpp + pico_display_2_demo.cpp ) # Pull in pico libraries that we need -target_link_libraries(${OUTPUT_NAME} pico_stdlib hardware_spi hardware_pwm hardware_dma rgbled button pico_display_2 picographics_st7789) +target_link_libraries(${OUTPUT_NAME} pico_stdlib hardware_spi hardware_pwm hardware_dma rgbled button pico_display_2 st7789 pico_graphics) # create map/bin/hex file etc. pico_add_extra_outputs(${OUTPUT_NAME}) \ No newline at end of file diff --git a/examples/pico_display_2/demo.cpp b/examples/pico_display_2/pico_display_2_demo.cpp similarity index 70% rename from examples/pico_display_2/demo.cpp rename to examples/pico_display_2/pico_display_2_demo.cpp index 65968e78..ad9d9bdf 100644 --- a/examples/pico_display_2/demo.cpp +++ b/examples/pico_display_2/pico_display_2_demo.cpp @@ -3,16 +3,16 @@ #include #include -#include "graphics_2.hpp" +#include "libraries/pico_display_2/pico_display_2.hpp" #include "drivers/st7789/st7789.hpp" -#include "libraries/pico_graphics/pico_graphics->hpp" +#include "libraries/pico_graphics/pico_graphics.hpp" #include "rgbled.hpp" #include "button.hpp" using namespace pimoroni; ST7789 st7789(320, 240, ROTATE_0, false, get_spi_pins(BG_SPI_FRONT)); -PicoGraphics graphics; +PicoGraphics_PenRGB332 graphics(st7789.width, st7789.height, nullptr); RGBLED led(PicoDisplay2::LED_R, PicoDisplay2::LED_G, PicoDisplay2::LED_B); @@ -44,12 +44,6 @@ void from_hsv(float h, float s, float v, uint8_t &r, uint8_t &g, uint8_t &b) { int main() { st7789.set_backlight(255); - // 150k RAM, 65K colours - // graphics = new PicoGraphics_PenRGB565(st7789.width, st7789.height, nullptr); - - // 75k RAM, 256 colours - graphics = new PicoGraphics_PenRGB332(st7789.width, st7789.height, nullptr); - struct pt { float x; float y; @@ -62,19 +56,19 @@ int main() { std::vector shapes; for(int i = 0; i < 100; i++) { pt shape; - shape.x = rand() % graphics->bounds.w; - shape.y = rand() % graphics->bounds.h; + shape.x = rand() % graphics.bounds.w; + shape.y = rand() % graphics.bounds.h; shape.r = (rand() % 10) + 3; shape.dx = float(rand() % 255) / 64.0f; shape.dy = float(rand() % 255) / 64.0f; - shape.pen = graphics->create_pen(rand() % 255, rand() % 255, rand() % 255); + shape.pen = graphics.create_pen(rand() % 255, rand() % 255, rand() % 255); shapes.push_back(shape); } Point text_location(0, 0); - Pen BG = graphics->create_pen(120, 40, 60); - Pen WHITE = graphics->create_pen(255, 255, 255); + Pen BG = graphics.create_pen(120, 40, 60); + Pen WHITE = graphics.create_pen(255, 255, 255); while(true) { if(button_a.raw()) text_location.x -= 1; @@ -83,8 +77,8 @@ int main() { if(button_x.raw()) text_location.y -= 1; if(button_y.raw()) text_location.y += 1; - graphics->set_pen(BG); - graphics->clear(); + graphics.set_pen(BG); + graphics.clear(); for(auto &shape : shapes) { shape.x += shape.dx; @@ -93,21 +87,21 @@ int main() { shape.dx *= -1; shape.x = shape.r; } - if((shape.x + shape.r) >= graphics->bounds.w) { + if((shape.x + shape.r) >= graphics.bounds.w) { shape.dx *= -1; - shape.x = graphics->bounds.w - shape.r; + shape.x = graphics.bounds.w - shape.r; } if((shape.y - shape.r) < 0) { shape.dy *= -1; shape.y = shape.r; } - if((shape.y + shape.r) >= graphics->bounds.h) { + if((shape.y + shape.r) >= graphics.bounds.h) { shape.dy *= -1; - shape.y = graphics->bounds.h - shape.r; + shape.y = graphics.bounds.h - shape.r; } - graphics->set_pen(shape.pen); - graphics->circle(Point(shape.x, shape.y), shape.r); + graphics.set_pen(shape.pen); + graphics.circle(Point(shape.x, shape.y), shape.r); } @@ -119,11 +113,11 @@ int main() { led.set_rgb(r, g, b); - graphics->set_pen(WHITE); - graphics->text("Hello World", text_location, 320); + graphics.set_pen(WHITE); + graphics.text("Hello World", text_location, 320); // update screen - st7789.update(graphics); + st7789.update(&graphics); } return 0; diff --git a/examples/pico_enc_explorer/CMakeLists.txt b/examples/pico_enc_explorer/CMakeLists.txt index 5dac8e43..0a6b4195 100644 --- a/examples/pico_enc_explorer/CMakeLists.txt +++ b/examples/pico_enc_explorer/CMakeLists.txt @@ -6,7 +6,7 @@ add_executable( ) # Pull in pico libraries that we need -target_link_libraries(${OUTPUT_NAME} pico_stdlib breakout_encoder pico_explorer picographics_st7789) +target_link_libraries(${OUTPUT_NAME} pico_stdlib breakout_encoder pico_explorer pico_graphics st7789) # create map/bin/hex file etc. pico_add_extra_outputs(${OUTPUT_NAME}) diff --git a/examples/pico_enc_explorer/pico_enc_explorer.cpp b/examples/pico_enc_explorer/pico_enc_explorer.cpp index 4a7b93b9..d2e79507 100644 --- a/examples/pico_enc_explorer/pico_enc_explorer.cpp +++ b/examples/pico_enc_explorer/pico_enc_explorer.cpp @@ -6,23 +6,18 @@ #include "pico_explorer.hpp" #include "breakout_encoder.hpp" -#include "picographics_st7789.hpp" +#include "drivers/st7789/st7789.hpp" +#include "libraries/pico_graphics/pico_graphics.hpp" using namespace pimoroni; -PicoGraphicsST7789 display( - PicoExplorer::WIDTH, - PicoExplorer::HEIGHT, - ROTATE_0, // Rotation - false, // Is it round!? - nullptr, // Buffer - get_spi_pins(BG_SPI_FRONT) -); +ST7789 st7789(PicoExplorer::WIDTH, PicoExplorer::HEIGHT, ROTATE_0, false, get_spi_pins(BG_SPI_FRONT)); +PicoGraphics_PenRGB332 graphics(st7789.width, st7789.height, nullptr); -Pen BLACK = display.create_pen(0, 0, 0); -Pen RED = display.create_pen(255, 0, 0); -Pen GREEN = display.create_pen(0, 255, 0); -Pen BLUE = display.create_pen(0, 0, 255); +Pen BLACK = graphics.create_pen(0, 0, 0); +Pen RED = graphics.create_pen(255, 0, 0); +Pen GREEN = graphics.create_pen(0, 255, 0); +Pen BLUE = graphics.create_pen(0, 0, 255); static const uint8_t STEPS_PER_REV = 24; @@ -56,49 +51,49 @@ void count_changed(int16_t count) { from_hsv(h, 1.0f, 1.0f, r, g, b); enc.set_led(r, g, b); - display.set_pen(BLACK); - display.clear(); + graphics.set_pen(BLACK); + graphics.clear(); { - display.set_pen(RED); + graphics.set_pen(RED); std::ostringstream ss; ss << "R = "; ss << (int)r; std::string s(ss.str()); - display.text(s, Point(10, 10), 220, 6); + graphics.text(s, Point(10, 10), 220, 6); } { - display.set_pen(GREEN); + graphics.set_pen(GREEN); std::ostringstream ss; ss << "G = "; ss << (int)g; std::string s(ss.str()); - display.text(s, Point(10, 70), 220, 6); + graphics.text(s, Point(10, 70), 220, 6); } { - display.set_pen(BLUE); + graphics.set_pen(BLUE); std::ostringstream ss; ss << "B = "; ss << (int)b; std::string s(ss.str()); - display.text(s, Point(10, 130), 220, 6); + graphics.text(s, Point(10, 130), 220, 6); } { // Shouldn't really use create_pen in-line. // In default (RGB332) palette mode this will lookup the nearest 8-bit colour - display.set_pen(display.create_pen(r, g, b)); + graphics.set_pen(graphics.create_pen(r, g, b)); std::ostringstream ss; ss << "#"; ss << std::uppercase << std::hex << std::setfill('0') << std::setw(2) << (int)r; ss << std::uppercase << std::hex << std::setfill('0') << std::setw(2) << (int)g; ss << std::uppercase << std::hex << std::setfill('0') << std::setw(2) << (int)b; std::string s(ss.str()); - display.text(s, Point(10, 190), 220, 5); + graphics.text(s, Point(10, 190), 220, 5); } - display.update(); + st7789.update(&graphics); } int main() { diff --git a/examples/pico_explorer/CMakeLists.txt b/examples/pico_explorer/CMakeLists.txt index 669c2b1f..0f44144a 100644 --- a/examples/pico_explorer/CMakeLists.txt +++ b/examples/pico_explorer/CMakeLists.txt @@ -6,7 +6,7 @@ add_executable( add_resource(pico_explorer_demo fox.tga) # Pull in pico libraries that we need -target_link_libraries(pico_explorer_demo pico_stdlib pico_explorer msa301 picographics_st7789 button motor analog) +target_link_libraries(pico_explorer_demo pico_stdlib pico_explorer msa301 pico_graphics st7789 button motor analog) # create map/bin/hex file etc. pico_add_extra_outputs(pico_explorer_demo) @@ -16,6 +16,6 @@ add_executable( text_demo.cpp ) -target_link_libraries(text_demo pico_stdlib pico_explorer msa301 picographics_st7789) +target_link_libraries(text_demo pico_stdlib pico_explorer msa301 pico_graphics st7789) pico_add_extra_outputs(text_demo) \ No newline at end of file diff --git a/examples/pico_explorer/pico_explorer_demo.cpp b/examples/pico_explorer/pico_explorer_demo.cpp index ea88ae2a..963d021f 100644 --- a/examples/pico_explorer/pico_explorer_demo.cpp +++ b/examples/pico_explorer/pico_explorer_demo.cpp @@ -4,7 +4,8 @@ #include #include "pico_explorer.hpp" -#include "picographics_st7789.hpp" +#include "drivers/st7789/st7789.hpp" +#include "libraries/pico_graphics/pico_graphics.hpp" #include "button.hpp" #include "motor.hpp" #include "msa301.hpp" @@ -15,14 +16,8 @@ using namespace motor; extern unsigned char _binary_fox_tga_start[]; -PicoGraphicsST7789 display( - PicoExplorer::WIDTH, - PicoExplorer::HEIGHT, - ROTATE_0, // Rotation - false, // Is it round!? - nullptr, // Buffer - get_spi_pins(BG_SPI_FRONT) -); +ST7789 st7789(PicoExplorer::WIDTH, PicoExplorer::HEIGHT, ROTATE_0, false, get_spi_pins(BG_SPI_FRONT)); +PicoGraphics_PenRGB332 graphics(st7789.width, st7789.height, nullptr); // Buttons Button button_a(PicoExplorer::A); @@ -101,49 +96,49 @@ int main() { shape.r = (rand() % 10) + 3; shape.dx = float(rand() % 255) / 128.0f; shape.dy = float(rand() % 255) / 128.0f; - shape.pen = display.create_pen(rand() % 255, rand() % 255, rand() % 255); + shape.pen = graphics.create_pen(rand() % 255, rand() % 255, rand() % 255); shapes.push_back(shape); } - Pen BG = display.create_pen(120, 40, 60); - Pen WHITE = display.create_pen(255, 255, 255); - Pen BOX = display.create_pen(55, 65, 75); - Pen PURPLE = display.create_pen(255, 0, 255); + Pen BG = graphics.create_pen(120, 40, 60); + Pen WHITE = graphics.create_pen(255, 255, 255); + Pen BOX = graphics.create_pen(55, 65, 75); + Pen PURPLE = graphics.create_pen(255, 0, 255); uint32_t i = 0; while(true) { - display.set_pen(BG); - display.clear(); + graphics.set_pen(BG); + graphics.clear(); for(auto &shape : shapes) { shape.x += shape.dx; shape.y += shape.dy; if(shape.x < 0) shape.dx *= -1; - if(shape.x >= display.bounds.w) shape.dx *= -1; + if(shape.x >= graphics.bounds.w) shape.dx *= -1; if(shape.y < 0) shape.dy *= -1; - if(shape.y >= display.bounds.h) shape.dy *= -1; + if(shape.y >= graphics.bounds.h) shape.dy *= -1; - display.set_pen(shape.pen); - display.circle(Point(shape.x, shape.y), shape.r); + graphics.set_pen(shape.pen); + graphics.circle(Point(shape.x, shape.y), shape.r); } float rv = adc0.read_voltage() / 3.3f; - display.set_pen(WHITE); - display.circle(Point(rv * 140 + 50, 110), 20); - display.set_pen(display.create_pen(rv * 255, 0, 0)); - display.circle(Point(rv * 140 + 50, 110), 15); + graphics.set_pen(WHITE); + graphics.circle(Point(rv * 140 + 50, 110), 20); + graphics.set_pen(graphics.create_pen(rv * 255, 0, 0)); + graphics.circle(Point(rv * 140 + 50, 110), 15); float gv = adc1.read_voltage() / 3.3f; - display.set_pen(WHITE); - display.circle(Point(gv * 140 + 50, 160), 20); - display.set_pen(display.create_pen(0, gv * 255, 0)); - display.circle(Point(gv * 140 + 50, 160), 15); + graphics.set_pen(WHITE); + graphics.circle(Point(gv * 140 + 50, 160), 20); + graphics.set_pen(graphics.create_pen(0, gv * 255, 0)); + graphics.circle(Point(gv * 140 + 50, 160), 15); float bv = adc2.read_voltage() / 3.3f; - display.set_pen(WHITE); - display.circle(Point(bv * 140 + 50, 210), 20); - display.set_pen(display.create_pen(0, 0, bv * 255)); - display.circle(Point(bv * 140 + 50, 210), 15); + graphics.set_pen(WHITE); + graphics.circle(Point(bv * 140 + 50, 210), 20); + graphics.set_pen(graphics.create_pen(0, 0, bv * 255)); + graphics.circle(Point(bv * 140 + 50, 210), 15); motor1.speed(bv); motor2.speed(rv); @@ -152,98 +147,66 @@ int main() { // display.set_tone(440, 0.5); if(button_a.read()) { - display.set_pen(WHITE); - display.character('A', Point(120, 180), 5); + graphics.set_pen(WHITE); + graphics.character('A', Point(120, 180), 5); } if(button_b.read()) { - display.set_pen(WHITE); - display.character('B', Point(120, 180), 5); + graphics.set_pen(WHITE); + graphics.character('B', Point(120, 180), 5); } if(button_x.read()) { - display.set_pen(WHITE); - display.character('X', Point(120, 180), 5); + graphics.set_pen(WHITE); + graphics.character('X', Point(120, 180), 5); } if(button_y.read()) { - display.set_pen(WHITE); - display.character('Y', Point(120, 180), 5); + graphics.set_pen(WHITE); + graphics.character('Y', Point(120, 180), 5); } float tyoff = cos(i / 20.0f) * 50.0f - 50.0f; Rect text_box(10, 10, 150, 150); - display.set_pen(BOX); - display.rectangle(text_box); + graphics.set_pen(BOX); + graphics.rectangle(text_box); text_box.deflate(10); - display.set_clip(text_box); - display.set_pen(WHITE); - display.text("This is a test of some text data that should wrap nicely onto multiple lines which is dead useful like.", Point(text_box.x, text_box.y + tyoff), 100); + graphics.set_clip(text_box); + graphics.set_pen(WHITE); + graphics.text("This is a test of some text data that should wrap nicely onto multiple lines which is dead useful like.", Point(text_box.x, text_box.y + tyoff), 100); float xoff = sin(i / 20.0f) * 50.0f; xoff += 120 - (81 / 2); float yoff = cos(i / 20.0f) * 50.0f; yoff += 120 - (68 / 2); for(int y = 0; y < 68; y++) { - // uint16_t *dest = display.frame_buffer + (y * 240); uint8_t *src = _binary_fox_tga_start + 18 + (y * 81 * 3); for(int x = 0; x < 81; x++) { uint8_t b = *src++; uint8_t g = *src++; uint8_t r = *src++; - display.set_pen(display.create_pen(r, g, b)); - display.pixel(Point(x + xoff, 68 - y + yoff)); + graphics.set_pen(graphics.create_pen(r, g, b)); + graphics.pixel(Point(x + xoff, 68 - y + yoff)); } } - display.remove_clip(); + graphics.remove_clip(); - display.set_pen(WHITE); - display.text("x: " + std::to_string(int(msa301.get_axis(msa301.X, 16) * 100)), Point(10, 190), 100); - display.text("y: " + std::to_string(int(msa301.get_axis(msa301.Y, 16) * 100)), Point(10, 205), 100); - display.text("z: " + std::to_string(int(msa301.get_axis(msa301.Z, 16) * 100)), Point(10, 220), 100); + graphics.set_pen(WHITE); + graphics.text("x: " + std::to_string(int(msa301.get_axis(msa301.X, 16) * 100)), Point(10, 190), 100); + graphics.text("y: " + std::to_string(int(msa301.get_axis(msa301.Y, 16) * 100)), Point(10, 205), 100); + graphics.text("z: " + std::to_string(int(msa301.get_axis(msa301.Z, 16) * 100)), Point(10, 220), 100); uint16_t xpos = (msa301.get_axis(msa301.X, 16) * 120) + 120; uint16_t ypos = (msa301.get_axis(msa301.Z, 16) * 120) + 120; - display.set_pen(WHITE); - display.circle(Point(xpos, ypos), 20); - display.set_pen(PURPLE); - display.circle(Point(xpos, ypos), 15); + graphics.set_pen(WHITE); + graphics.circle(Point(xpos, ypos), 20); + graphics.set_pen(PURPLE); + graphics.circle(Point(xpos, ypos), 15); - -/* - if(pico_display.is_pressed(pico_display.A)) { - pico_display.rectangle(0, 0, 18, 18); - //sprite(tick, 5, 5, true, green); - }else{ - //sprite(arrow, 10 + bounce, 10, true, white); - } - - if(pico_display.is_pressed(pico_display.B)) { - pico_display.rectangle(0, 49, 18, 18); - //sprite(tick, 5, 54, true, green); - }else{ - //sprite(arrow, 10 - bounce, 50, true, white); - } - - - if(pico_display.is_pressed(pico_display.X)) { - pico_display.rectangle(102, 0, 18, 18); - //sprite(tick, 107, 5, true, green); - }else{ - //sprite(arrow, 102 - bounce, 10, false, white); - } - - if(pico_display.is_pressed(pico_display.Y)) { - pico_display.rectangle(102, 49, 18, 18); - //sprite(tick, 107, 54, true, green); - }else{ - //sprite(arrow, 102 + bounce, 50, false, white); - } -*/ // update screen - display.update(); + st7789.update(&graphics); i++; } diff --git a/examples/pico_explorer/text_demo.cpp b/examples/pico_explorer/text_demo.cpp index 6aa0ff79..e5f63da7 100644 --- a/examples/pico_explorer/text_demo.cpp +++ b/examples/pico_explorer/text_demo.cpp @@ -4,6 +4,9 @@ #include #include "pico_explorer.hpp" +#include "drivers/st7789/st7789.hpp" +#include "libraries/pico_graphics/pico_graphics.hpp" + #include "font6_data.hpp" #include "font8_data.hpp" #include "msa301.hpp" @@ -12,32 +15,32 @@ using namespace pimoroni; extern unsigned char _binary_fox_tga_start[]; -uint16_t buffer[PicoExplorer::WIDTH * PicoExplorer::HEIGHT]; -PicoExplorer pico_explorer(buffer); +ST7789 st7789(PicoExplorer::WIDTH, PicoExplorer::HEIGHT, ROTATE_0, false, get_spi_pins(BG_SPI_FRONT)); +PicoGraphics_PenRGB332 graphics(st7789.width, st7789.height, nullptr); + MSA301 msa301; int main() { - pico_explorer.init(); - pico_explorer.set_font(&font8); + graphics.set_font(&font8); msa301.init(); - Pen BG = pico_explorer.create_pen(120, 40, 60); - Pen WHITE = pico_explorer.create_pen(255, 255, 255); + Pen BG = graphics.create_pen(120, 40, 60); + Pen WHITE = graphics.create_pen(255, 255, 255); uint32_t i = 0; while(true) { - pico_explorer.set_pen(BG); - pico_explorer.clear(); + graphics.set_pen(BG); + graphics.clear(); - pico_explorer.set_pen(WHITE); - pico_explorer.set_font(&font6); - pico_explorer.text("6x6: The quick, brown fox jumps over the lazy dog! UPPER. lower.", Point(10, 10), 220); - pico_explorer.text("0123456789 !$%^&*()", Point(10, 70), 220); - pico_explorer.set_font(&font8); - pico_explorer.text("6x8: The quick, brown fox jumps over the lazy dog! UPPER. lower.", Point(10, 120), 220); - pico_explorer.text("0123456789 !$%^&*()", Point(10, 180), 220); + graphics.set_pen(WHITE); + graphics.set_font(&font6); + graphics.text("6x6: The quick, brown fox jumps over the lazy dog! UPPER. lower.", Point(10, 10), 220); + graphics.text("0123456789 !$%^&*()", Point(10, 70), 220); + graphics.set_font(&font8); + graphics.text("6x8: The quick, brown fox jumps over the lazy dog! UPPER. lower.", Point(10, 120), 220); + graphics.text("0123456789 !$%^&*()", Point(10, 180), 220); - pico_explorer.update(); + st7789.update(&graphics); i++; } diff --git a/examples/pico_explorer_encoder/CMakeLists.txt b/examples/pico_explorer_encoder/CMakeLists.txt index bfc53d45..dba74a85 100644 --- a/examples/pico_explorer_encoder/CMakeLists.txt +++ b/examples/pico_explorer_encoder/CMakeLists.txt @@ -6,7 +6,7 @@ add_executable( pico_generate_pio_header(pico_explorer_encoder ${CMAKE_CURRENT_LIST_DIR}/quadrature_out.pio) # Pull in pico libraries that we need -target_link_libraries(pico_explorer_encoder pico_stdlib pico_explorer encoder button motor picographics_st7789) +target_link_libraries(pico_explorer_encoder pico_stdlib pico_explorer encoder button motor pico_graphics st7789) # create map/bin/hex file etc. pico_add_extra_outputs(pico_explorer_encoder) \ No newline at end of file diff --git a/examples/pico_explorer_encoder/pico_explorer_encoder.cpp b/examples/pico_explorer_encoder/pico_explorer_encoder.cpp index d95afb68..61cafc02 100644 --- a/examples/pico_explorer_encoder/pico_explorer_encoder.cpp +++ b/examples/pico_explorer_encoder/pico_explorer_encoder.cpp @@ -4,7 +4,8 @@ #include "pico/stdlib.h" #include "encoder.hpp" #include "quadrature_out.pio.h" -#include "picographics_st7789.hpp" +#include "drivers/st7789/st7789.hpp" +#include "libraries/pico_graphics/pico_graphics.hpp" #include "button.hpp" /* @@ -93,14 +94,8 @@ enum DrawState { //-------------------------------------------------- // Variables //-------------------------------------------------- -PicoGraphicsST7789 display( - PicoExplorer::WIDTH, - PicoExplorer::HEIGHT, - ROTATE_0, // Rotation - false, // Is it round!? - nullptr, // Buffer - get_spi_pins(BG_SPI_FRONT) -); +ST7789 st7789(PicoExplorer::WIDTH, PicoExplorer::HEIGHT, ROTATE_0, false, get_spi_pins(BG_SPI_FRONT)); +PicoGraphics_PenRGB332 graphics(st7789.width, st7789.height, nullptr); Button button_a(PicoExplorer::A); Button button_b(PicoExplorer::B); @@ -182,13 +177,13 @@ uint32_t draw_plot(Point p1, Point p2, volatile bool (&readings)[READINGS_SIZE], switch(draw_state) { case DRAW_TRANSITION: for(uint8_t y = p1.y; y < p2.y; y++) - display.pixel(Point(x + p1.x, y)); + graphics.pixel(Point(x + p1.x, y)); break; case DRAW_HIGH: - display.pixel(Point(x + p1.x, p1.y)); + graphics.pixel(Point(x + p1.x, p1.y)); break; case DRAW_LOW: - display.pixel(Point(x + p1.x, p2.y - 1)); + graphics.pixel(Point(x + p1.x, p2.y - 1)); break; } } @@ -255,7 +250,7 @@ void setup() { // MAIN //////////////////////////////////////////////////////////////////////////////////////////////////// int main() { - Pen WHITE = display.create_pen(255, 255, 255); + Pen WHITE = graphics.create_pen(255, 255, 255); // Perform the main setup for the demo setup(); @@ -321,16 +316,16 @@ int main() { //-------------------------------------------------- // Draw the encoder readings to the screen as a signal plot - display.set_pen(display.create_pen(0, 0, 0)); - display.clear(); + graphics.set_pen(graphics.create_pen(0, 0, 0)); + graphics.clear(); drawing_to_screen = true; - display.set_pen(display.create_pen(255, 255, 0)); + graphics.set_pen(graphics.create_pen(255, 255, 0)); uint32_t local_pos = next_reading_index; uint32_t alignment_offset = draw_plot(Point(0, 10), Point(PicoExplorer::WIDTH, 10 + 50), enc_a_readings, local_pos, current_zoom_level > EDGE_ALIGN_ABOVE_ZOOM); - display.set_pen(display.create_pen(0, 255, 255)); + graphics.set_pen(graphics.create_pen(0, 255, 255)); draw_plot(Point(0, 80), Point(PicoExplorer::WIDTH, 80 + 50), enc_b_readings, (local_pos + (READINGS_SIZE - alignment_offset)) % READINGS_SIZE, false); // Copy values that may have been stored in the scratch buffers, back into the main buffers @@ -346,49 +341,49 @@ int main() { drawing_to_screen = false; next_scratch_index = 0; - display.set_pen(WHITE); - display.character('A', Point(5, 10 + 15), 3); - display.character('B', Point(5, 80 + 15), 3); + graphics.set_pen(WHITE); + graphics.character('A', Point(5, 10 + 15), 3); + graphics.character('B', Point(5, 80 + 15), 3); if(current_zoom_level < 10) - display.text("x" + std::to_string(current_zoom_level), Point(220, 62), 200, 2); + graphics.text("x" + std::to_string(current_zoom_level), Point(220, 62), 200, 2); else if(current_zoom_level < 100) - display.text("x" + std::to_string(current_zoom_level), Point(210, 62), 200, 2); + graphics.text("x" + std::to_string(current_zoom_level), Point(210, 62), 200, 2); else - display.text("x" + std::to_string(current_zoom_level), Point(200, 62), 200, 2); + graphics.text("x" + std::to_string(current_zoom_level), Point(200, 62), 200, 2); //-------------------------------------------------- // Write out the count, frequency and rpm of the encoder - display.set_pen(display.create_pen(8, 8, 8)); - display.rectangle(Rect(0, 140, PicoExplorer::WIDTH, PicoExplorer::HEIGHT - 140)); + graphics.set_pen(graphics.create_pen(8, 8, 8)); + graphics.rectangle(Rect(0, 140, PicoExplorer::WIDTH, PicoExplorer::HEIGHT - 140)); - display.set_pen(display.create_pen(64, 64, 64)); - display.rectangle(Rect(0, 140, PicoExplorer::WIDTH, 2)); + graphics.set_pen(graphics.create_pen(64, 64, 64)); + graphics.rectangle(Rect(0, 140, PicoExplorer::WIDTH, 2)); { std::stringstream sstream; sstream << capture.count(); - display.set_pen(WHITE); display.text("Count:", Point(10, 150), 200, 3); - display.set_pen(display.create_pen(255, 128, 255)); display.text(sstream.str(), Point(110, 150), 200, 3); + graphics.set_pen(WHITE); graphics.text("Count:", Point(10, 150), 200, 3); + graphics.set_pen(graphics.create_pen(255, 128, 255)); graphics.text(sstream.str(), Point(110, 150), 200, 3); } { std::stringstream sstream; sstream << std::fixed << std::setprecision(1) << capture.frequency() << "hz"; - display.set_pen(WHITE); display.text("Freq: ", Point(10, 180), 220, 3); - display.set_pen(display.create_pen(128, 255, 255)); display.text(sstream.str(), Point(90, 180), 220, 3); + graphics.set_pen(WHITE); graphics.text("Freq: ", Point(10, 180), 220, 3); + graphics.set_pen(graphics.create_pen(128, 255, 255)); graphics.text(sstream.str(), Point(90, 180), 220, 3); } { std::stringstream sstream; sstream << std::fixed << std::setprecision(1) << capture.revolutions_per_minute(); - display.set_pen(WHITE); display.text("RPM: ", Point(10, 210), 220, 3); - display.set_pen(display.create_pen(255, 255, 128)); display.text(sstream.str(), Point(80, 210), 220, 3); + graphics.set_pen(WHITE); graphics.text("RPM: ", Point(10, 210), 220, 3); + graphics.set_pen(graphics.create_pen(255, 255, 128)); graphics.text(sstream.str(), Point(80, 210), 220, 3); } - display.update(); // Refresh the screen + st7789.update(&graphics); // Refresh the screen gpio_put(PICO_DEFAULT_LED_PIN, false); // Show the screen refresh has ended } } diff --git a/examples/pico_pot_explorer/CMakeLists.txt b/examples/pico_pot_explorer/CMakeLists.txt index f2b47485..433e6096 100644 --- a/examples/pico_pot_explorer/CMakeLists.txt +++ b/examples/pico_pot_explorer/CMakeLists.txt @@ -6,7 +6,7 @@ add_executable( ) # Pull in pico libraries that we need -target_link_libraries(${OUTPUT_NAME} pico_stdlib breakout_potentiometer pico_explorer picographics_st7789) +target_link_libraries(${OUTPUT_NAME} pico_stdlib breakout_potentiometer pico_explorer pico_graphics st7789) # create map/bin/hex file etc. pico_add_extra_outputs(${OUTPUT_NAME}) diff --git a/examples/pico_pot_explorer/pico_pot_explorer.cpp b/examples/pico_pot_explorer/pico_pot_explorer.cpp index 49f4f067..a375b8f0 100644 --- a/examples/pico_pot_explorer/pico_pot_explorer.cpp +++ b/examples/pico_pot_explorer/pico_pot_explorer.cpp @@ -7,23 +7,18 @@ #include "common/pimoroni_i2c.hpp" #include "pico_explorer.hpp" #include "breakout_potentiometer.hpp" -#include "picographics_st7789.hpp" +#include "drivers/st7789/st7789.hpp" +#include "libraries/pico_graphics/pico_graphics.hpp" using namespace pimoroni; -PicoGraphicsST7789 display( - PicoExplorer::WIDTH, - PicoExplorer::HEIGHT, - ROTATE_0, // Rotation - false, // Is it round!? - nullptr, // Buffer - get_spi_pins(BG_SPI_FRONT) -); +ST7789 st7789(PicoExplorer::WIDTH, PicoExplorer::HEIGHT, ROTATE_0, false, get_spi_pins(BG_SPI_FRONT)); +PicoGraphics_PenRGB332 graphics(st7789.width, st7789.height, nullptr); -Pen BLACK = display.create_pen(0, 0, 0); -Pen RED = display.create_pen(255, 0, 0); -Pen GREEN = display.create_pen(0, 255, 0); -Pen BLUE = display.create_pen(0, 0, 255); +Pen BLACK = graphics.create_pen(0, 0, 0); +Pen RED = graphics.create_pen(255, 0, 0); +Pen GREEN = graphics.create_pen(0, 255, 0); +Pen BLUE = graphics.create_pen(0, 0, 255); I2C i2c(PICO_EXPLORER); BreakoutPotentiometer pot(&i2c); @@ -71,49 +66,49 @@ int main() { from_hsv(percent, 1.0f, 1.0f, r, g, b); pot.set_led(r, g, b); - display.set_pen(BLACK); - display.clear(); + graphics.set_pen(BLACK); + graphics.clear(); { - display.set_pen(RED); + graphics.set_pen(RED); std::ostringstream ss; ss << "R = "; ss << (int)r; std::string s(ss.str()); - display.text(s, Point(10, 10), 220, 6); + graphics.text(s, Point(10, 10), 220, 6); } { - display.set_pen(GREEN); + graphics.set_pen(GREEN); std::ostringstream ss; ss << "G = "; ss << (int)g; std::string s(ss.str()); - display.text(s, Point(10, 70), 220, 6); + graphics.text(s, Point(10, 70), 220, 6); } { - display.set_pen(BLUE); + graphics.set_pen(BLUE); std::ostringstream ss; ss << "B = "; ss << (int)b; std::string s(ss.str()); - display.text(s, Point(10, 130), 220, 6); + graphics.text(s, Point(10, 130), 220, 6); } { // Shouldn't really use create_pen in-line. // In default (RGB332) palette mode this will lookup the nearest 8-bit colour - display.set_pen(display.create_pen(r, g, b)); + graphics.set_pen(graphics.create_pen(r, g, b)); std::ostringstream ss; ss << "#"; ss << std::uppercase << std::hex << std::setfill('0') << std::setw(2) << (int)r; ss << std::uppercase << std::hex << std::setfill('0') << std::setw(2) << (int)g; ss << std::uppercase << std::hex << std::setfill('0') << std::setw(2) << (int)b; std::string s(ss.str()); - display.text(s, Point(10, 190), 220, 5); + graphics.text(s, Point(10, 190), 220, 5); } - display.update(); + st7789.update(&graphics); } } else { diff --git a/examples/pico_rtc_display/CMakeLists.txt b/examples/pico_rtc_display/CMakeLists.txt index 7b2f6207..df7cba8c 100644 --- a/examples/pico_rtc_display/CMakeLists.txt +++ b/examples/pico_rtc_display/CMakeLists.txt @@ -6,7 +6,7 @@ add_executable( ) # Pull in pico libraries that we need -target_link_libraries(${OUTPUT_NAME} pico_stdlib pico_explorer pico_display breakout_rtc picographics_st7789 button rgbled) +target_link_libraries(${OUTPUT_NAME} pico_stdlib pico_explorer pico_display breakout_rtc pico_graphics st7789 button rgbled) # create map/bin/hex file etc. pico_add_extra_outputs(${OUTPUT_NAME}) diff --git a/examples/pico_rtc_display/pico_rtc_display.cpp b/examples/pico_rtc_display/pico_rtc_display.cpp index eee36499..2a3db860 100644 --- a/examples/pico_rtc_display/pico_rtc_display.cpp +++ b/examples/pico_rtc_display/pico_rtc_display.cpp @@ -27,7 +27,8 @@ #endif #include "breakout_rtc.hpp" -#include "picographics_st7789.hpp" +#include "drivers/st7789/st7789.hpp" +#include "libraries/pico_graphics/pico_graphics.hpp" #include "drivers/button/button.hpp" #include "drivers/rgbled/rgbled.hpp" @@ -60,7 +61,8 @@ Button button_y(PicoDisplay::Y); RGBLED led(PicoDisplay::LED_R, PicoDisplay::LED_G, PicoDisplay::LED_B); #endif -PicoGraphicsST7789 display(screen_width, screen_height, ROTATE_0, false, nullptr, get_spi_pins(BG_SPI_FRONT)); +ST7789 st7789(screen_width, screen_height, ROTATE_0, false, get_spi_pins(BG_SPI_FRONT)); +PicoGraphics_PenRGB332 graphics(st7789.width, st7789.height, nullptr); BreakoutRTC rtc; @@ -94,10 +96,10 @@ void flash_led(uint32_t curr_count) { } int main() { - Pen WHITE = display.create_pen(255, 255, 255); - Pen BG = display.create_pen(55, 65, 75); - Pen RED = display.create_pen(255, 0, 0); - Pen GREEN = display.create_pen(0, 255, 0); + Pen WHITE = graphics.create_pen(255, 255, 255); + Pen BG = graphics.create_pen(55, 65, 75); + Pen RED = graphics.create_pen(255, 0, 0); + Pen GREEN = graphics.create_pen(0, 255, 0); rtc.init(); // rtc.setup(false); @@ -208,77 +210,77 @@ int main() { } Rect text_box(5, 5, screen_width-10, screen_height-10); - display.set_pen(BG); - display.rectangle(text_box); + graphics.set_pen(BG); + graphics.rectangle(text_box); // text_box.deflate(10); - display.set_clip(text_box); - display.set_pen(WHITE); + graphics.set_clip(text_box); + graphics.set_pen(WHITE); switch(display_mode) { case MODE_DISP_CLOCK: // Show the clock face flash_led(0); if(rtc.update_time()) { - display.text("Set Timer", + graphics.text("Set Timer", Point(text_box.x, text_box.y+2), 230, 1); - display.set_pen(GREEN); - display.text(rtc.string_date(), + graphics.set_pen(GREEN); + graphics.text(rtc.string_date(), Point(text_box.x, text_box.y+20), 230, 4); - display.set_pen(RED); - display.text(rtc.string_time(), + graphics.set_pen(RED); + graphics.text(rtc.string_time(), Point(text_box.x, text_box.y+60), 230, 6); - display.set_pen(WHITE); - display.text("Clock", + graphics.set_pen(WHITE); + graphics.text("Clock", Point(text_box.x, text_box.y+screen_height-20), 230, 1); } else { sprintf(buf, "Time: rtc.updateTime() ret err"); - display.text(buf, + graphics.text(buf, Point(text_box.x, text_box.y), 30, 2); } break; case MODE_DISP_TIMER: - display.text("Set Timer", + graphics.text("Set Timer", Point(text_box.x, text_box.y+2), 230, 1); if(rtc.read_timer_interrupt_flag()) { // Go periodic time interupt - say loop ended - display.set_pen(RED); + graphics.set_pen(RED); sprintf(buf, "%s", "Timer complete"); - display.text(buf, + graphics.text(buf, Point(text_box.x, text_box.y+30), 230, 4); - display.set_pen(WHITE); + graphics.set_pen(WHITE); flash_led(i); } else { sprintf(buf, "%s %d", "Timer running", rtc.get_timer_count()); - display.text(buf, + graphics.text(buf, Point(text_box.x, text_box.y+30), 230, 3); } - display.text("Clock", + graphics.text("Clock", Point(text_box.x, text_box.y+screen_height-20), 230, 1); break; case MODE_SET_TIMER: flash_led(0); - display.text("Run Timer", + graphics.text("Run Timer", Point(text_box.x, text_box.y+2), 230, 1); - display.text("+ Time", + graphics.text("+ Time", Point(text_box.x+screen_width-42, text_box.y+2), 230, 1); sprintf(buf, "Time %d secs", timer_count); - display.text(buf, + graphics.text(buf, Point(text_box.x, text_box.y+30), 230, 3); - display.text("Clock", + graphics.text("Clock", Point(text_box.x, text_box.y+screen_height-20), 230, 1); - display.text("- Time", + graphics.text("- Time", Point(text_box.x+screen_width-42, text_box.y+screen_height-20), 230, 1); break; } - display.remove_clip(); + graphics.remove_clip(); // update screen - display.update(); + st7789.update(&graphics); i++; } diff --git a/examples/pico_tof_display/CMakeLists.txt b/examples/pico_tof_display/CMakeLists.txt index 06a8417a..16b4c9b4 100644 --- a/examples/pico_tof_display/CMakeLists.txt +++ b/examples/pico_tof_display/CMakeLists.txt @@ -4,7 +4,7 @@ add_executable( ) # Pull in pico libraries that we need -target_link_libraries(tof_display pico_stdlib pico_explorer pico_display vl53l1x picographics_st7789 button) +target_link_libraries(tof_display pico_stdlib pico_explorer pico_display vl53l1x pico_graphics st7789 button) pico_enable_stdio_uart(tof_display 1) diff --git a/examples/pico_tof_display/pico_tof_display.cpp b/examples/pico_tof_display/pico_tof_display.cpp index 86bacb2f..4b60b93e 100644 --- a/examples/pico_tof_display/pico_tof_display.cpp +++ b/examples/pico_tof_display/pico_tof_display.cpp @@ -26,19 +26,13 @@ #include "vl53l1x.hpp" #include "drivers/button/button.hpp" -#include "picographics_st7789.hpp" +#include "drivers/st7789/st7789.hpp" +#include "libraries/pico_graphics/pico_graphics.hpp" using namespace pimoroni; #ifdef USE_PICO_EXPLORER -PicoGraphicsST7789 pico_display( - PicoExplorer::WIDTH, - PicoExplorer::HEIGHT, - ROTATE_0, // Rotation - false, // Is it round!? - nullptr, // Buffer - get_spi_pins(BG_SPI_FRONT) -); +ST7789 st7789(PicoExplorer::WIDTH, PicoExplorer::HEIGHT, ROTATE_0, false, get_spi_pins(BG_SPI_FRONT)); Button button_a(PicoExplorer::A); Button button_b(PicoExplorer::B); @@ -59,14 +53,7 @@ uint16_t disptext_dist_xoff = 10; uint16_t disptext_dist_yoff = 90; uint16_t disptext_dist_size = 6; #else -PicoGraphicsST7789 pico_display( - PicoDisplay::WIDTH, - PicoDisplay::HEIGHT, - ROTATE_0, // Rotation - false, // Is it round!? - nullptr, // Buffer - get_spi_pins(BG_SPI_FRONT) -); +ST7789 st7789(PicoDisplay::WIDTH, PicoDisplay::HEIGHT, ROTATE_0, false, get_spi_pins(BG_SPI_FRONT)); Button button_a(PicoDisplay::A); Button button_b(PicoDisplay::B); @@ -88,9 +75,10 @@ uint16_t disptext_dist_yoff = 45; uint16_t disptext_dist_size = 4; #endif +PicoGraphics_PenRGB332 graphics(st7789.width, st7789.height, nullptr); -uint16_t screen_width = pico_display.bounds.w; -uint16_t screen_height = pico_display.bounds.h; +uint16_t screen_width = graphics.bounds.w; +uint16_t screen_height = graphics.bounds.h; #define MM_TO_INCH 25.4 @@ -110,10 +98,10 @@ void flash_led(uint32_t curr_count) { #ifndef USE_PICO_EXPLORER if ((curr_count % FLASH_MOD) < (FLASH_MOD / 2)) { // value less than half modded number - LED off - pico_display.set_led(0, 0, 0); + //pico_display.set_led(0, 0, 0); // TODO use RGBLED } else { // value more than half modded number - LED on - pico_display.set_led(128, 128, 128); + //pico_display.set_led(128, 128, 128); // TODO use RGBLED } #endif } @@ -141,9 +129,9 @@ int main() { // Whether the display is being held bool dist_held = false; - Pen WHITE = pico_display.create_pen(255, 255, 255); - Pen REDDISH = pico_display.create_pen(255, 64, 64); - Pen BG = pico_display.create_pen(55, 65, 75); + Pen WHITE = graphics.create_pen(255, 255, 255); + Pen REDDISH = graphics.create_pen(255, 64, 64); + Pen BG = graphics.create_pen(55, 65, 75); while(true) { // bool a_pressed = button_a.read(); @@ -168,30 +156,30 @@ int main() { } Rect text_box(5, 5, screen_width-10, screen_height-10); - pico_display.set_pen(BG); - pico_display.rectangle(text_box); + graphics.set_pen(BG); + graphics.rectangle(text_box); // text_box.deflate(10); - pico_display.set_clip(text_box); - pico_display.set_pen(WHITE); + graphics.set_clip(text_box); + graphics.set_pen(WHITE); // Show the current distance flash_led(0); if (vl53_present) { - pico_display.text("Units", + graphics.text("Units", Point(text_box.x+disptext_x_reminder_xoff, text_box.y+disptext_x_reminder_yoff), 230, disptext_reminder_size); - pico_display.text("+Mode", + graphics.text("+Mode", Point(text_box.x+disptext_y_reminder_xoff, text_box.y+disptext_y_reminder_yoff), 230, disptext_reminder_size); if(dist_held) { - pico_display.set_pen(REDDISH); + graphics.set_pen(REDDISH); } - pico_display.text("Hold", + graphics.text("Hold", Point(text_box.x+disptext_b_reminder_xoff, text_box.y+disptext_b_reminder_yoff), 230, disptext_reminder_size); - pico_display.set_pen(WHITE); + graphics.set_pen(WHITE); sprintf(buf, "Mode: %s", mode_to_text[vl53_mode]); - pico_display.text(buf, + graphics.text(buf, Point(text_box.x+disptext_mode_xoff, text_box.y+disptext_mode_yoff), 230, disptext_mode_size); @@ -204,19 +192,19 @@ int main() { sprintf(buf, "%dft %.1fin", ft, ((float)dist/MM_TO_INCH)-ft*12.0); } - pico_display.text(buf, + graphics.text(buf, Point(text_box.x+disptext_dist_xoff, text_box.y+disptext_dist_yoff), 120, disptext_dist_size); } else { - pico_display.text("VL53L1X Missing", + graphics.text("VL53L1X Missing", Point(text_box.x+disptext_dist_xoff, text_box.y+disptext_dist_yoff), 230, disptext_dist_size); } - pico_display.remove_clip(); + graphics.remove_clip(); // update screen - pico_display.update(); + st7789.update(&graphics); i++; } diff --git a/examples/pico_trackball_display/CMakeLists.txt b/examples/pico_trackball_display/CMakeLists.txt index dc065c5e..ac18ef67 100644 --- a/examples/pico_trackball_display/CMakeLists.txt +++ b/examples/pico_trackball_display/CMakeLists.txt @@ -6,7 +6,7 @@ add_executable( ) # Pull in pico libraries that we need -target_link_libraries(${OUTPUT_NAME} pico_stdlib pico_explorer pico_display breakout_trackball picographics_st7789) +target_link_libraries(${OUTPUT_NAME} pico_stdlib pico_explorer pico_display breakout_trackball pico_graphics st7789) pico_enable_stdio_uart(${OUTPUT_NAME} 1) diff --git a/examples/pico_trackball_display/pico_trackball_display.cpp b/examples/pico_trackball_display/pico_trackball_display.cpp index b045b899..bdb5e27d 100644 --- a/examples/pico_trackball_display/pico_trackball_display.cpp +++ b/examples/pico_trackball_display/pico_trackball_display.cpp @@ -21,11 +21,12 @@ #ifdef USE_PICO_EXPLORER #include "pico_explorer.hpp" #else -#include "display.hpp" +#include "pico_display.hpp" #endif #include "breakout_trackball.hpp" -#include "picographics_st7789.hpp" +#include "drivers/st7789/st7789.hpp" +#include "libraries/pico_graphics/pico_graphics.hpp" using namespace pimoroni; @@ -44,7 +45,8 @@ const uint16_t screen_width = PicoDisplay::WIDTH; const uint16_t screen_height = PicoDisplay::HEIGHT; #endif -PicoGraphicsST7789 display(screen_width, screen_height, ROTATE_0, false, nullptr, get_spi_pins(BG_SPI_FRONT)); +ST7789 st7789(screen_width, screen_height, ROTATE_0, false, get_spi_pins(BG_SPI_FRONT)); +PicoGraphics_PenRGB332 graphics(st7789.width, st7789.height, nullptr); const Point screen_centre(screen_width / 2, screen_height / 2); const uint16_t circle_radius = std::min(screen_centre.x, screen_centre.y) / 4; @@ -84,10 +86,10 @@ int main() { positions[i] = pos; } - Pen WHITE = display.create_pen(255, 255, 255); - Pen BLACK = display.create_pen(0, 0, 0); - Pen LIGHT_GREY = display.create_pen(212, 212, 212); - Pen MID_GREY = display.create_pen(128, 128, 128); + Pen WHITE = graphics.create_pen(255, 255, 255); + Pen BLACK = graphics.create_pen(0, 0, 0); + Pen LIGHT_GREY = graphics.create_pen(212, 212, 212); + Pen MID_GREY = graphics.create_pen(128, 128, 128); while(true) { Trackball::State state = trackball.read(); @@ -95,46 +97,46 @@ int main() { y = std::min(std::max(y - state.up + state.down, 0), (int)screen_height); Point cursor_pos(x, y); - display.set_pen(BLACK); - display.clear(); + graphics.set_pen(BLACK); + graphics.clear(); //Draw a set of circles in a ring around the screen centre for(uint8_t i = 0; i < NUM_CIRCLES; i++) { TrackballColour col = colour_circles[i]; if(circle_states[i]) { - display.set_pen(display.create_pen(col.r, col.g, col.b)); - display.circle(positions[i], circle_radius + circle_border); - display.set_pen(display.create_pen(col.r >> 1, col.g >> 1, col.b >> 1)); - display.circle(positions[i], circle_radius); + graphics.set_pen(graphics.create_pen(col.r, col.g, col.b)); + graphics.circle(positions[i], circle_radius + circle_border); + graphics.set_pen(graphics.create_pen(col.r >> 1, col.g >> 1, col.b >> 1)); + graphics.circle(positions[i], circle_radius); } else { - display.set_pen(display.create_pen(col.r >> 1, col.g >> 1, col.b >> 1)); - display.circle(positions[i], circle_radius + circle_border); - display.set_pen(display.create_pen(col.r, col.g, col.b)); - display.circle(positions[i], circle_radius); + graphics.set_pen(graphics.create_pen(col.r >> 1, col.g >> 1, col.b >> 1)); + graphics.circle(positions[i], circle_radius + circle_border); + graphics.set_pen(graphics.create_pen(col.r, col.g, col.b)); + graphics.circle(positions[i], circle_radius); } } //Draw a centre circle if(centre_circle_state) { - display.set_pen(WHITE); - display.circle(screen_centre, circle_radius + circle_border); - display.set_pen(MID_GREY); - display.circle(screen_centre, circle_radius); + graphics.set_pen(WHITE); + graphics.circle(screen_centre, circle_radius + circle_border); + graphics.set_pen(MID_GREY); + graphics.circle(screen_centre, circle_radius); } else { - display.set_pen(MID_GREY); - display.circle(screen_centre, circle_radius + circle_border); - display.set_pen(WHITE); - display.circle(screen_centre, circle_radius); + graphics.set_pen(MID_GREY); + graphics.circle(screen_centre, circle_radius + circle_border); + graphics.set_pen(WHITE); + graphics.circle(screen_centre, circle_radius); } //Draw the cursor - display.set_pen(BLACK); - display.circle(cursor_pos, cursor_radius + cursor_border); - display.set_pen(LIGHT_GREY); - display.circle(cursor_pos, cursor_radius); + graphics.set_pen(BLACK); + graphics.circle(cursor_pos, cursor_radius + cursor_border); + graphics.set_pen(LIGHT_GREY); + graphics.circle(cursor_pos, cursor_radius); int16_t x_diff = cursor_pos.x - screen_centre.x; int16_t y_diff = cursor_pos.y - screen_centre.y; @@ -166,7 +168,7 @@ int main() { } // update screen - display.update(); + st7789.update(&graphics); } return 0; diff --git a/examples/tufty2040/tufty2040_drawing.cmake b/examples/tufty2040/tufty2040_drawing.cmake index ff63d762..17dee086 100644 --- a/examples/tufty2040/tufty2040_drawing.cmake +++ b/examples/tufty2040/tufty2040_drawing.cmake @@ -4,7 +4,8 @@ add_executable(${OUTPUT_NAME} tufty2040_drawing.cpp) target_link_libraries(${OUTPUT_NAME} tufty2040 hardware_spi - picographics_st7789 + pico_graphics + st7789 button ) diff --git a/examples/tufty2040/tufty2040_drawing.cpp b/examples/tufty2040/tufty2040_drawing.cpp index 63ced2c4..48f68e2b 100644 --- a/examples/tufty2040/tufty2040_drawing.cpp +++ b/examples/tufty2040/tufty2040_drawing.cpp @@ -7,7 +7,8 @@ #include "pico/platform.h" #include "common/pimoroni_common.hpp" -#include "picographics_st7789.hpp" +#include "drivers/st7789/st7789.hpp" +#include "libraries/pico_graphics/pico_graphics.hpp" #include "tufty2040.hpp" #include "button.hpp" @@ -15,8 +16,10 @@ using namespace pimoroni; Tufty2040 tufty; -PicoGraphicsST7789 display( - Tufty2040::WIDTH, Tufty2040::HEIGHT, ROTATE_0, nullptr, +ST7789 st7789( + Tufty2040::WIDTH, + Tufty2040::HEIGHT, + ROTATE_0, ParallelPins{ Tufty2040::LCD_CS, Tufty2040::LCD_DC, @@ -27,6 +30,8 @@ PicoGraphicsST7789 display( } ); +PicoGraphics_PenRGB332 graphics(st7789.width, st7789.height, nullptr); + Button button_a(Tufty2040::A); Button button_b(Tufty2040::B); Button button_c(Tufty2040::C); @@ -59,10 +64,10 @@ void from_hsv(float h, float s, float v, uint8_t &r, uint8_t &g, uint8_t &b) { } int main() { - display.set_backlight(255); + st7789.set_backlight(255); - Pen WHITE = display.create_pen(255, 255, 255); - Pen BG = display.create_pen(120, 40, 60); + Pen WHITE = graphics.create_pen(255, 255, 255); + Pen BG = graphics.create_pen(120, 40, 60); struct pt { float x; @@ -76,12 +81,12 @@ int main() { std::vector shapes; for(int i = 0; i < 100; i++) { pt shape; - shape.x = rand() % display.bounds.w; - shape.y = rand() % display.bounds.h; + shape.x = rand() % graphics.bounds.w; + shape.y = rand() % graphics.bounds.h; shape.r = (rand() % 10) + 3; shape.dx = float(rand() % 255) / 64.0f; shape.dy = float(rand() % 255) / 64.0f; - shape.pen = display.create_pen(rand() % 255, rand() % 255, rand() % 255); + shape.pen = graphics.create_pen(rand() % 255, rand() % 255, rand() % 255); shapes.push_back(shape); } @@ -90,8 +95,8 @@ int main() { while(true) { - display.set_pen(BG); - display.clear(); + graphics.set_pen(BG); + graphics.clear(); for(auto &shape : shapes) { shape.x += shape.dx; @@ -100,30 +105,30 @@ int main() { shape.dx *= -1; shape.x = shape.r; } - if((shape.x + shape.r) >= display.bounds.w) { + if((shape.x + shape.r) >= graphics.bounds.w) { shape.dx *= -1; - shape.x = display.bounds.w - shape.r; + shape.x = graphics.bounds.w - shape.r; } if((shape.y - shape.r) < 0) { shape.dy *= -1; shape.y = shape.r; } - if((shape.y + shape.r) >= display.bounds.h) { + if((shape.y + shape.r) >= graphics.bounds.h) { shape.dy *= -1; - shape.y = display.bounds.h - shape.r; + shape.y = graphics.bounds.h - shape.r; } - display.set_pen(shape.pen); - display.circle(Point(shape.x, shape.y), shape.r); + graphics.set_pen(shape.pen); + graphics.circle(Point(shape.x, shape.y), shape.r); } - display.set_pen(WHITE); - display.text("Hello World", text_location, 320); + graphics.set_pen(WHITE); + graphics.text("Hello World", text_location, 320); // update screen - display.update(); + st7789.update(&graphics); i+=10; tufty.led(i); diff --git a/libraries/CMakeLists.txt b/libraries/CMakeLists.txt index 4eb2dcd8..a7498a1a 100644 --- a/libraries/CMakeLists.txt +++ b/libraries/CMakeLists.txt @@ -4,7 +4,6 @@ add_subdirectory(breakout_dotmatrix) add_subdirectory(breakout_encoder) add_subdirectory(breakout_ioexpander) add_subdirectory(breakout_ltr559) -add_subdirectory(breakout_colourlcd160x80) add_subdirectory(breakout_rgbmatrix5x5) add_subdirectory(breakout_matrix11x7) add_subdirectory(breakout_mics6814) @@ -17,7 +16,6 @@ add_subdirectory(breakout_sgp30) add_subdirectory(breakout_as7262) add_subdirectory(breakout_msa301) add_subdirectory(breakout_bh1745) -add_subdirectory(picographics_st7789) add_subdirectory(pico_graphics) add_subdirectory(pico_display) add_subdirectory(pico_display_2) diff --git a/libraries/breakout_colourlcd160x80/CMakeLists.txt b/libraries/breakout_colourlcd160x80/CMakeLists.txt deleted file mode 100644 index d855c97b..00000000 --- a/libraries/breakout_colourlcd160x80/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -include(breakout_colourlcd160x80.cmake) diff --git a/libraries/breakout_colourlcd160x80/breakout_colourlcd160x80.cmake b/libraries/breakout_colourlcd160x80/breakout_colourlcd160x80.cmake deleted file mode 100644 index ece9be90..00000000 --- a/libraries/breakout_colourlcd160x80/breakout_colourlcd160x80.cmake +++ /dev/null @@ -1,11 +0,0 @@ -set(LIB_NAME breakout_colourlcd160x80) -add_library(${LIB_NAME} INTERFACE) - -target_sources(${LIB_NAME} INTERFACE - ${CMAKE_CURRENT_LIST_DIR}/${LIB_NAME}.cpp -) - -target_include_directories(${LIB_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR}) - -# Pull in pico libraries that we need -target_link_libraries(${LIB_NAME} INTERFACE pico_stdlib st7735 pico_graphics hardware_spi) diff --git a/libraries/breakout_colourlcd160x80/breakout_colourlcd160x80.cpp b/libraries/breakout_colourlcd160x80/breakout_colourlcd160x80.cpp deleted file mode 100644 index d35e831e..00000000 --- a/libraries/breakout_colourlcd160x80/breakout_colourlcd160x80.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "breakout_colourlcd160x80.hpp" - -namespace pimoroni { - - -} \ No newline at end of file diff --git a/libraries/breakout_colourlcd160x80/breakout_colourlcd160x80.hpp b/libraries/breakout_colourlcd160x80/breakout_colourlcd160x80.hpp deleted file mode 100644 index b2eadd27..00000000 --- a/libraries/breakout_colourlcd160x80/breakout_colourlcd160x80.hpp +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include "drivers/st7735/st7735.hpp" -#include "libraries/pico_graphics/pico_graphics.hpp" -#include "common/pimoroni_common.hpp" -#include "common/pimoroni_bus.hpp" - -namespace pimoroni { - - class BreakoutColourLCD160x80 : public PicoGraphics_PenRGB565 { - //-------------------------------------------------- - // Constants - //-------------------------------------------------- - public: - static const int WIDTH = 160; - static const int HEIGHT = 80; - - //-------------------------------------------------- - // Variables - //-------------------------------------------------- - private: - ST7735 screen; - - - //-------------------------------------------------- - // Constructors/Destructor - //-------------------------------------------------- - public: - - BreakoutColourLCD160x80(void *frame_buffer) - : BreakoutColourLCD160x80(frame_buffer, get_spi_pins(BG_SPI_FRONT)) { - } - - BreakoutColourLCD160x80(void *frame_buffer, SPIPins bus_pins) - : PicoGraphics_PenRGB565(WIDTH, HEIGHT, frame_buffer), screen(WIDTH, HEIGHT, bus_pins){ - } - - void update() { - screen.update(this); - } - - void set_backlight(uint8_t brightness) { - screen.set_backlight(brightness); - } - }; - -} diff --git a/libraries/breakout_colourlcd240x240/CMakeLists.txt b/libraries/breakout_colourlcd240x240/CMakeLists.txt deleted file mode 100644 index 2c234a7d..00000000 --- a/libraries/breakout_colourlcd240x240/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -set(LIB_NAME breakout_colourlcd240x240) -add_library(${LIB_NAME} INTERFACE) - -target_sources(${LIB_NAME} INTERFACE - ${CMAKE_CURRENT_LIST_DIR}/${LIB_NAME}.cpp -) - -target_include_directories(${LIB_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR}) - -# Pull in pico libraries that we need -target_link_libraries(${LIB_NAME} INTERFACE pico_stdlib st7789 pico_graphics) \ No newline at end of file diff --git a/libraries/breakout_colourlcd240x240/breakout_colourlcd240x240.cmake b/libraries/breakout_colourlcd240x240/breakout_colourlcd240x240.cmake deleted file mode 100644 index cf2f3148..00000000 --- a/libraries/breakout_colourlcd240x240/breakout_colourlcd240x240.cmake +++ /dev/null @@ -1,14 +0,0 @@ -include(${CMAKE_CURRENT_LIST_DIR}/../../drivers/st7789/st7789.cmake) -include(${CMAKE_CURRENT_LIST_DIR}/../pico_graphics/pico_graphics.cmake) - -set(LIB_NAME breakout_colourlcd240x240) -add_library(${LIB_NAME} INTERFACE) - -target_sources(${LIB_NAME} INTERFACE - ${CMAKE_CURRENT_LIST_DIR}/${LIB_NAME}.cpp -) - -target_include_directories(${LIB_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR}) - -# Pull in pico libraries that we need -target_link_libraries(${LIB_NAME} INTERFACE pico_stdlib st7789 pico_graphics) diff --git a/libraries/breakout_colourlcd240x240/breakout_colourlcd240x240.cpp b/libraries/breakout_colourlcd240x240/breakout_colourlcd240x240.cpp deleted file mode 100644 index f24f0e70..00000000 --- a/libraries/breakout_colourlcd240x240/breakout_colourlcd240x240.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "breakout_colourlcd240x240.hpp" - -namespace pimoroni { - - BreakoutColourLCD240x240::BreakoutColourLCD240x240(uint16_t *buf) - : PicoGraphics(WIDTH, HEIGHT, buf), screen(WIDTH, HEIGHT, false, buf, - PIMORONI_SPI_DEFAULT_INSTANCE, SPI_BG_FRONT_CS, SPI_DEFAULT_MISO, SPI_DEFAULT_SCK, SPI_DEFAULT_MOSI, SPI_BG_FRONT_PWM) { - __fb = buf; - } - - BreakoutColourLCD240x240::BreakoutColourLCD240x240(uint16_t *buf, spi_inst_t *spi, - uint cs, uint dc, uint sck, uint mosi, uint bl) - : PicoGraphics(WIDTH, HEIGHT, buf), screen(WIDTH, HEIGHT, false, buf, spi, cs, dc, sck, mosi, bl) { - __fb = buf; - } - - BreakoutColourLCD240x240::BreakoutColourLCD240x240(uint16_t *buf, BG_SPI_SLOT slot) - : PicoGraphics(WIDTH, HEIGHT, buf), screen(WIDTH, HEIGHT, false, buf, - PIMORONI_SPI_DEFAULT_INSTANCE, screen.get_slot_cs(slot), SPI_DEFAULT_MISO, SPI_DEFAULT_SCK, SPI_DEFAULT_MOSI, screen.get_slot_bl(slot)) { - __fb = buf; - } - - void BreakoutColourLCD240x240::init() { - } - - spi_inst_t* BreakoutColourLCD240x240::get_spi() const { - return screen.get_spi(); - } - - int BreakoutColourLCD240x240::get_cs() const { - return screen.get_cs(); - } - - int BreakoutColourLCD240x240::get_dc() const { - return screen.get_dc(); - } - - int BreakoutColourLCD240x240::get_sck() const { - return screen.get_sck(); - } - - int BreakoutColourLCD240x240::get_mosi() const { - return screen.get_mosi(); - } - - int BreakoutColourLCD240x240::get_bl() const { - return screen.get_bl(); - } - - void BreakoutColourLCD240x240::update() { - screen.update(); - } - - void BreakoutColourLCD240x240::set_backlight(uint8_t brightness) { - screen.set_backlight(brightness); - } - -} \ No newline at end of file diff --git a/libraries/breakout_colourlcd240x240/breakout_colourlcd240x240.hpp b/libraries/breakout_colourlcd240x240/breakout_colourlcd240x240.hpp deleted file mode 100644 index 67588696..00000000 --- a/libraries/breakout_colourlcd240x240/breakout_colourlcd240x240.hpp +++ /dev/null @@ -1,53 +0,0 @@ -#pragma once - -#include "drivers/st7789/st7789.hpp" -#include "libraries/pico_graphics/pico_graphics.hpp" -#include "common/pimoroni_common.hpp" - -namespace pimoroni { - - class BreakoutColourLCD240x240 : public PicoGraphics { - //-------------------------------------------------- - // Constants - //-------------------------------------------------- - public: - static const int WIDTH = 240; - static const int HEIGHT = 240; - - //-------------------------------------------------- - // Variables - //-------------------------------------------------- - public: - uint16_t *__fb; - private: - ST7789 screen; - - - //-------------------------------------------------- - // Constructors/Destructor - //-------------------------------------------------- - public: - BreakoutColourLCD240x240(uint16_t *buf); - BreakoutColourLCD240x240(uint16_t *buf, spi_inst_t *spi, - uint cs, uint dc, uint sck, uint mosi, uint bl = PIN_UNUSED); - BreakoutColourLCD240x240(uint16_t *buf, BG_SPI_SLOT slot); - - - //-------------------------------------------------- - // Methods - //-------------------------------------------------- - public: - void init(); - - spi_inst_t* get_spi() const; - int get_cs() const; - int get_dc() const; - int get_sck() const; - int get_mosi() const; - int get_bl() const; - - void update(); - void set_backlight(uint8_t brightness); - }; - -} diff --git a/libraries/breakout_roundlcd/CMakeLists.txt b/libraries/breakout_roundlcd/CMakeLists.txt deleted file mode 100644 index 46e19eb2..00000000 --- a/libraries/breakout_roundlcd/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -set(LIB_NAME breakout_roundlcd) -add_library(${LIB_NAME} INTERFACE) - -target_sources(${LIB_NAME} INTERFACE - ${CMAKE_CURRENT_LIST_DIR}/${LIB_NAME}.cpp -) - -target_include_directories(${LIB_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR}) - -# Pull in pico libraries that we need -target_link_libraries(${LIB_NAME} INTERFACE pico_stdlib st7789 pico_graphics) \ No newline at end of file diff --git a/libraries/breakout_roundlcd/breakout_roundlcd.cmake b/libraries/breakout_roundlcd/breakout_roundlcd.cmake deleted file mode 100644 index b4a2c5ec..00000000 --- a/libraries/breakout_roundlcd/breakout_roundlcd.cmake +++ /dev/null @@ -1,14 +0,0 @@ -include(${CMAKE_CURRENT_LIST_DIR}/../../drivers/st7789/st7789.cmake) -include(${CMAKE_CURRENT_LIST_DIR}/../pico_graphics/pico_graphics.cmake) - -set(LIB_NAME breakout_roundlcd) -add_library(${LIB_NAME} INTERFACE) - -target_sources(${LIB_NAME} INTERFACE - ${CMAKE_CURRENT_LIST_DIR}/${LIB_NAME}.cpp -) - -target_include_directories(${LIB_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR}) - -# Pull in pico libraries that we need -target_link_libraries(${LIB_NAME} INTERFACE pico_stdlib st7789 pimoroni_bus pico_graphics) \ No newline at end of file diff --git a/libraries/breakout_roundlcd/breakout_roundlcd.cpp b/libraries/breakout_roundlcd/breakout_roundlcd.cpp deleted file mode 100644 index c46f8cbb..00000000 --- a/libraries/breakout_roundlcd/breakout_roundlcd.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include "breakout_roundlcd.hpp" - -namespace pimoroni { - - BreakoutRoundLCD::BreakoutRoundLCD(uint16_t *buf) - : PicoGraphics(WIDTH, HEIGHT, buf), - screen(WIDTH, HEIGHT, ROTATE_0, true, buf, get_spi_pins(BG_SPI_FRONT)) { - __fb = buf; - } - - BreakoutRoundLCD::BreakoutRoundLCD(uint16_t *buf, spi_inst_t *spi, - uint cs, uint dc, uint sck, uint mosi, uint bl) - : PicoGraphics(WIDTH, HEIGHT, buf), - screen(WIDTH, HEIGHT, ROTATE_0, true, buf, SPIPins{spi, cs sck, mosi, PIN_UNUSED, dc, bl}) { - __fb = buf; - } - - BreakoutRoundLCD::BreakoutRoundLCD(uint16_t *buf, BG_SPI_SLOT slot) - : PicoGraphics(WIDTH, HEIGHT, buf), - screen(WIDTH, HEIGHT, ROTATE_0, true, buf, get_spi_pins(slot)) { { - __fb = buf; - } - - void BreakoutRoundLCD::init() { - } - - spi_inst_t* BreakoutRoundLCD::get_spi() const { - return screen.get_spi(); - } - - int BreakoutRoundLCD::get_cs() const { - return screen.get_cs(); - } - - int BreakoutRoundLCD::get_dc() const { - return screen.get_dc(); - } - - int BreakoutRoundLCD::get_sck() const { - return screen.get_sck(); - } - - int BreakoutRoundLCD::get_mosi() const { - return screen.get_mosi(); - } - - int BreakoutRoundLCD::get_bl() const { - return screen.get_bl(); - } - - void BreakoutRoundLCD::update() { - screen.update(); - } - - void BreakoutRoundLCD::set_backlight(uint8_t brightness) { - screen.set_backlight(brightness); - } - -} \ No newline at end of file diff --git a/libraries/breakout_roundlcd/breakout_roundlcd.hpp b/libraries/breakout_roundlcd/breakout_roundlcd.hpp deleted file mode 100644 index 8c990b05..00000000 --- a/libraries/breakout_roundlcd/breakout_roundlcd.hpp +++ /dev/null @@ -1,55 +0,0 @@ -#pragma once - -#include "drivers/st7789/st7789.hpp" -#include "libraries/pico_graphics/pico_graphics.hpp" - -namespace pimoroni { - - class BreakoutRoundLCD : public PicoGraphics { - //-------------------------------------------------- - // Constants - //-------------------------------------------------- - public: - static const int WIDTH = 240; - static const int HEIGHT = 240; - - static const uint8_t PIN_UNUSED = UINT8_MAX; - - - //-------------------------------------------------- - // Variables - //-------------------------------------------------- - public: - uint16_t *__fb; - private: - ST7789 screen; - - - //-------------------------------------------------- - // Constructors/Destructor - //-------------------------------------------------- - public: - BreakoutRoundLCD(uint16_t *buf); - BreakoutRoundLCD(uint16_t *buf, spi_inst_t *spi, - uint cs, uint dc, uint sck, uint mosi, uint bl = PIN_UNUSED); - BreakoutRoundLCD(uint16_t *buf, BG_SPI_SLOT slot); - - - //-------------------------------------------------- - // Methods - //-------------------------------------------------- - public: - void init(); - - spi_inst_t* get_spi() const; - int get_cs() const; - int get_dc() const; - int get_sck() const; - int get_mosi() const; - int get_bl() const; - - void update(); - void set_backlight(uint8_t brightness); - }; - -} diff --git a/libraries/pico_explorer/pico_explorer.cpp b/libraries/pico_explorer/pico_explorer.cpp index ccd07c69..be8dfc6b 100644 --- a/libraries/pico_explorer/pico_explorer.cpp +++ b/libraries/pico_explorer/pico_explorer.cpp @@ -1,122 +1 @@ -#include -#include - -#include "hardware/gpio.h" -#include "hardware/pwm.h" -#include "hardware/adc.h" - -#include "pico_explorer.hpp" - -const uint8_t MOTOR1N = 8; -const uint8_t MOTOR1P = 9; -const uint8_t MOTOR2N = 10; -const uint8_t MOTOR2P = 11; - -namespace pimoroni { - - PicoExplorer::PicoExplorer(void *buf) - : PicoGraphics(WIDTH, HEIGHT, buf), - screen(WIDTH, HEIGHT, ROTATE_0, false, buf, get_spi_pins(PICO_EXPLORER_ONBOARD)) { - __fb = buf; - } - - void PicoExplorer::init() { - // setup button inputs - gpio_set_function(A, GPIO_FUNC_SIO); gpio_set_dir(A, GPIO_IN); gpio_pull_up(A); - gpio_set_function(B, GPIO_FUNC_SIO); gpio_set_dir(B, GPIO_IN); gpio_pull_up(B); - gpio_set_function(X, GPIO_FUNC_SIO); gpio_set_dir(X, GPIO_IN); gpio_pull_up(X); - gpio_set_function(Y, GPIO_FUNC_SIO); gpio_set_dir(Y, GPIO_IN); gpio_pull_up(Y); - - // setup ADC channels - adc_init(); - const uint8_t ADC_BASE_PIN = 26; - adc_gpio_init(ADC0 + ADC_BASE_PIN); - adc_gpio_init(ADC1 + ADC_BASE_PIN); - adc_gpio_init(ADC2 + ADC_BASE_PIN); - - // setup motor pins - pwm_config motor_pwm_cfg = pwm_get_default_config(); - pwm_config_set_wrap(&motor_pwm_cfg, 5500); - - pwm_init(pwm_gpio_to_slice_num(MOTOR1N), &motor_pwm_cfg, true); - gpio_set_function(MOTOR1N, GPIO_FUNC_PWM); - - pwm_init(pwm_gpio_to_slice_num(MOTOR1P), &motor_pwm_cfg, true); - gpio_set_function(MOTOR1P, GPIO_FUNC_PWM); - - pwm_init(pwm_gpio_to_slice_num(MOTOR2N), &motor_pwm_cfg, true); - gpio_set_function(MOTOR2N, GPIO_FUNC_PWM); - - pwm_init(pwm_gpio_to_slice_num(MOTOR2P), &motor_pwm_cfg, true); - gpio_set_function(MOTOR2P, GPIO_FUNC_PWM); - } - - void PicoExplorer::update() { - screen.update(palette); - } - - [[deprecated("Use Button(uint pin).")]] - bool PicoExplorer::is_pressed(uint8_t button) { - return !gpio_get(button); - } - - [[deprecated("Use Analog(uint pin).")]] - float PicoExplorer::get_adc(uint8_t channel) { - adc_select_input(channel); - // scale raw 12-bit adc value to 0 .. 1 float - float result = float(adc_read()) / (1 << 12); - // clamp result to 0 .. 1 - result = std::min(1.0f, std::max(0.0f, result)); - return result; - } - - [[deprecated("Use Motor(pin_pair pins).")]] - void PicoExplorer::set_motor(uint8_t channel, uint8_t action, float speed) { - uint8_t p = channel == MOTOR1 ? MOTOR1P : MOTOR2P; - uint8_t n = channel == MOTOR1 ? MOTOR1N : MOTOR2N; - - switch(action) { - case FORWARD: { - pwm_set_gpio_level(n, (1 - speed) * 5500); - pwm_set_gpio_level(p, 5500); - break; - } - - case REVERSE: { - pwm_set_gpio_level(n, 5500); - pwm_set_gpio_level(p, (1 - speed) * 5500); - break; - } - - case STOP: { - pwm_set_gpio_level(p, 5500); - pwm_set_gpio_level(n, 5500); - break; - } - } - } - - [[deprecated("Use Buzzer(uint pin).")]] - void PicoExplorer::set_audio_pin(uint pin) { - pwm_config tone_pwm_cfg = pwm_get_default_config(); - - // calculate the pwm wrap value for this frequency - // first we set the clock divider to give us exactly - // ten thousand cycles per second - pwm_config_set_clkdiv(&tone_pwm_cfg, 255); - pwm_init(pwm_gpio_to_slice_num(pin), &tone_pwm_cfg, true); - gpio_set_function(pin, GPIO_FUNC_PWM); - audio_pin = pin; - } - - [[deprecated("Use Buzzer(uint pin).set_tone().")]] - void PicoExplorer::set_tone(uint16_t frequency, float duty) { - // output a square wave, so 50% duty cycle - if(audio_pin != -1) { - uint16_t pwm_wrap = 490196 / frequency; - pwm_set_wrap(audio_pin, pwm_wrap); - pwm_set_gpio_level(audio_pin, pwm_wrap * duty); - } - } - -} +#include "pico_explorer.hpp" \ No newline at end of file diff --git a/libraries/pico_explorer/pico_explorer.hpp b/libraries/pico_explorer/pico_explorer.hpp index b1d0d51b..3468831a 100644 --- a/libraries/pico_explorer/pico_explorer.hpp +++ b/libraries/pico_explorer/pico_explorer.hpp @@ -1,12 +1,10 @@ #pragma once -#include "drivers/st7789/st7789.hpp" -#include "libraries/pico_graphics/pico_graphics.hpp" #include "drivers/motor/motor.hpp" namespace pimoroni { - class PicoExplorer : public PicoGraphics { + class PicoExplorer { public: static const int WIDTH = 240; static const int HEIGHT = 240; @@ -41,25 +39,6 @@ namespace pimoroni { static const uint GP5 = 5; static const uint GP6 = 6; static const uint GP7 = 7; - - void *__fb; - private: - ST7789 screen; - int8_t audio_pin = -1; - - public: - PicoExplorer(void *buf); - - void init(); - void update(); - bool is_pressed(uint8_t button); - - float get_adc(uint8_t channel); - - void set_motor(uint8_t channel, uint8_t action, float speed = 0.0f); - - void set_audio_pin(uint pin); - void set_tone(uint16_t frequency, float duty = 0.2f); }; } \ No newline at end of file diff --git a/libraries/pico_graphics/pico_graphics.cmake b/libraries/pico_graphics/pico_graphics.cmake index a77cd83f..e5320dd2 100644 --- a/libraries/pico_graphics/pico_graphics.cmake +++ b/libraries/pico_graphics/pico_graphics.cmake @@ -5,4 +5,4 @@ add_library(pico_graphics target_include_directories(pico_graphics INTERFACE ${CMAKE_CURRENT_LIST_DIR}) -target_link_libraries(pico_graphics bitmap_fonts) \ No newline at end of file +target_link_libraries(pico_graphics bitmap_fonts pico_stdlib) \ No newline at end of file diff --git a/libraries/pico_graphics/pico_graphics.hpp b/libraries/pico_graphics/pico_graphics.hpp index b4462748..954d7733 100644 --- a/libraries/pico_graphics/pico_graphics.hpp +++ b/libraries/pico_graphics/pico_graphics.hpp @@ -320,8 +320,8 @@ namespace pimoroni { DisplayDriver(uint16_t width, uint16_t height, Rotation rotation) : width(width), height(height), rotation(rotation) {}; - virtual void update(PicoGraphics *display); - virtual void set_backlight(uint8_t brightness); + virtual void update(PicoGraphics *display) {}; + virtual void set_backlight(uint8_t brightness) {}; }; } diff --git a/libraries/picographics_st7789/CMakeLists.txt b/libraries/picographics_st7789/CMakeLists.txt deleted file mode 100644 index 89a60659..00000000 --- a/libraries/picographics_st7789/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -include(picographics_st7789.cmake) \ No newline at end of file diff --git a/libraries/picographics_st7789/README.md b/libraries/picographics_st7789/README.md deleted file mode 100644 index 98d1bb82..00000000 --- a/libraries/picographics_st7789/README.md +++ /dev/null @@ -1,106 +0,0 @@ -# Pico Graphics ST7789 - Pico Display Pack & Pico Display Pack 2.0" and 240x240 Square & Round LCD Breakouts - -Our Pico Display Packs offers a vibrant 1.14" (240x135) or 2.0" (320x240) IPS LCD screen for your Raspberry Pi Pico it also includes four switches and and an RGB LED! - -We've included helper functions to handle every aspect of drawing to the screen and interfacing with the buttons and LED. See the [function reference](#function-reference) for details. - -- [Example Program](#example-program) -- [Function Reference](#function-reference) - - [PicoGraphics](#picographics) - - [set_backlight](#set_backlight) - - [update](#update) - -## Example Program - -The following example sets up Pico Display, displays some basic demo text and graphics and will illuminate the RGB LED green if the A button is pressed. - -```c++ -#include "pico_display.hpp" -#include "picographics_st7789.hpp" -#include "rgbled.hpp" -#include "button.hpp" - -using namespace pimoroni; - -// Swap WIDTH and HEIGHT to rotate 90 degrees -PicoGraphicsST7789 pico_display(PicoDisplay::WIDTH, PicoDisplay::HEIGHT, ROTATE_0); - -// RGB LED controller -RGBLED led(PicoDisplay::LED_R, PicoDisplay::LED_G, PicoDisplay::LED_B); - -// Buttons -Button button_a(PicoDisplay::A); -Button button_b(PicoDisplay::B); -Button button_x(PicoDisplay::X); -Button button_y(PicoDisplay::Y); - -int main() { - // set the backlight to a value between 0 and 255 - // the backlight is driven via PWM and is gamma corrected by our - // library to give a gorgeous linear brightness range. - pico_display.set_backlight(100); - - // Create pens for the colours we want to use - // parameters are red, green, blue all between 0 and 255 - // By default these are crushed to RGB332 so only the upper bits of each are used! - int BG_COLOR = pico_display.create_pen(30, 40, 50); - int BOX_COLOR = pico_display.create_pen(10, 20, 30); - int TEXT_COLOR = pico_display.create_pen(110, 120, 130); - - while(true) { - // detect if the A button is pressed (could be A, B, X, or Y) - if(button_a.raw()) { - // make the led glow green - // parameters are red, green, blue all between 0 and 255 - // these are also gamma corrected - led.set_rgb(0, 255, 0); - } - - // set the colour of the pen - pico_display.set_pen(BG_COLOR); - - // fill the screen with the current pen colour - pico_display.clear(); - - // draw a box to put some text in - pico_display.set_pen(BOX_COLOR); - Rect text_rect(10, 10, 150, 150); - pico_display.rectangle(text_rect); - - // write some text inside the box with 10 pixels of margin - // automatically word wrapping - text_rect.deflate(10); - pico_display.set_pen(TEXT_COLOR); - pico_display.text("This is a message", Point(text_rect.x, text_rect.y), text_rect.w); - - // now we've done our drawing let's update the screen - pico_display.update(); - } -} -``` - -## Function Reference - -### PicoGraphics - -The Pico Graphics ST7789 driver uses our Pico Graphics library to draw graphics and text. For more information [read the Pico Graphics function reference.](../pico_graphics/README.md#function-reference). - -You will also need to use the RGBLED library to drive the RGB LED, and the Button library for the four buttons. - -### set_backlight - -Set the display backlight from 0-255. - -```c++ -pico_display.set_backlight(brightness); -``` - -Uses hardware PWM to dim the display backlight, dimming values are gamma-corrected to provide smooth brightness transitions across the full range of intensity. This may result in some low values mapping as "off." - -### update - -To display your changes on Pico Display's screen you need to call `update`: - -```c++ -pico_display.update(); -``` diff --git a/libraries/picographics_st7789/picographics_st7789.cmake b/libraries/picographics_st7789/picographics_st7789.cmake deleted file mode 100644 index 1196c95c..00000000 --- a/libraries/picographics_st7789/picographics_st7789.cmake +++ /dev/null @@ -1,11 +0,0 @@ -set(LIB_NAME picographics_st7789) -add_library(${LIB_NAME} INTERFACE) - -target_sources(${LIB_NAME} INTERFACE - ${CMAKE_CURRENT_LIST_DIR}/${LIB_NAME}.cpp -) - -target_include_directories(${LIB_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR}) - -# Pull in pico libraries that we need -target_link_libraries(${LIB_NAME} INTERFACE pico_stdlib hardware_spi hardware_pwm hardware_dma pimoroni_bus st7789 pico_graphics) \ No newline at end of file diff --git a/libraries/picographics_st7789/picographics_st7789.cpp b/libraries/picographics_st7789/picographics_st7789.cpp deleted file mode 100644 index 5bd9bd69..00000000 --- a/libraries/picographics_st7789/picographics_st7789.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -#include "picographics_st7789.hpp" - - -namespace pimoroni { - -} diff --git a/libraries/picographics_st7789/picographics_st7789.hpp b/libraries/picographics_st7789/picographics_st7789.hpp deleted file mode 100644 index 96ec537f..00000000 --- a/libraries/picographics_st7789/picographics_st7789.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once - -#include "drivers/st7789/st7789.hpp" -#include "libraries/pico_graphics/pico_graphics.hpp" -#include "common/pimoroni_bus.hpp" - -namespace pimoroni { - - class PicoGraphicsST7789 : public PicoGraphics_PenRGB565 { - private: - ST7789 st7789; - - public: - PicoGraphicsST7789(uint16_t width, uint16_t height, Rotation rotation, bool round=false, void *frame_buffer=nullptr) : - PicoGraphics_PenRGB565(width, height, frame_buffer), - st7789(width, height, rotation, round, get_spi_pins(BG_SPI_FRONT)) { - common_init(); - }; - - PicoGraphicsST7789(uint16_t width, uint16_t height, Rotation rotation, bool round, void *frame_buffer, SPIPins bus_pins) : - PicoGraphics_PenRGB565(width, height, frame_buffer), - st7789(width, height, rotation, round, bus_pins) { - common_init(); - }; - - PicoGraphicsST7789(uint16_t width, uint16_t height, Rotation rotation, void *frame_buffer, ParallelPins bus_pins) : - PicoGraphics_PenRGB565(width, height, frame_buffer), - st7789(width, height, rotation, bus_pins) { - common_init(); - }; - - void common_init() { - this->set_dimensions(st7789.width, st7789.height); - st7789.update(this); - } - - void update() { - st7789.update(this); - } - - void set_backlight(uint8_t brightness) { - st7789.set_backlight(brightness); - } - - void set_framebuffer(void* frame_buffer) { - this->frame_buffer = frame_buffer; - } - }; - -}