ST7789/PicoDisplay: Update C++ examples. Rename GenericST7789 -> PicoDisplayST7789.

driver/sh1107
Phil Howard 2022-05-29 14:42:31 +01:00
rodzic 65788ae6bf
commit b66da12c1b
45 zmienionych plików z 646 dodań i 782 usunięć

Wyświetl plik

@ -1 +1,2 @@
include(pimoroni_i2c.cmake) include(pimoroni_i2c.cmake)
include(pimoroni_bus.cmake)

Wyświetl plik

@ -108,8 +108,8 @@ namespace pimoroni {
uint8_t enable; uint8_t enable;
}; };
pin_pair() : first(0), second(0) {} constexpr pin_pair() : first(0), second(0) {}
pin_pair(uint8_t first, uint8_t second) : first(first), second(second) {} constexpr pin_pair(uint8_t first, uint8_t second) : first(first), second(second) {}
}; };
struct bool_pair { struct bool_pair {

Wyświetl plik

@ -10,7 +10,7 @@ pico_enable_stdio_usb(${OUTPUT_NAME} 1)
pico_enable_stdio_uart(${OUTPUT_NAME} 1) pico_enable_stdio_uart(${OUTPUT_NAME} 1)
# Pull in pico libraries that we need # Pull in pico libraries that we need
target_link_libraries(${OUTPUT_NAME} pico_stdlib breakout_as7262 pico_explorer) target_link_libraries(${OUTPUT_NAME} pico_stdlib breakout_as7262 pico_explorer picographics_st7789)
# create map/bin/hex file etc. # create map/bin/hex file etc.
pico_add_extra_outputs(${OUTPUT_NAME}) pico_add_extra_outputs(${OUTPUT_NAME})

Wyświetl plik

@ -4,14 +4,16 @@
#include "breakout_as7262.hpp" #include "breakout_as7262.hpp"
#include "pico_explorer.hpp" #include "pico_explorer.hpp"
#include "picographics_st7789.hpp"
using namespace pimoroni; using namespace pimoroni;
constexpr float INTEGRATION_TIME = 10.0f; constexpr float INTEGRATION_TIME = 10.0f;
I2C i2c(BOARD::PICO_EXPLORER); I2C i2c(BOARD::PICO_EXPLORER);
BreakoutAS7262 as7262(&i2c); BreakoutAS7262 as7262(&i2c);
uint16_t buffer[PicoExplorer::WIDTH * PicoExplorer::HEIGHT];
PicoExplorer pico_explorer(buffer); PicoGraphicsST7789 display(PicoExplorer::WIDTH, PicoExplorer::HEIGHT, ROTATE_0, false, nullptr, get_spi_pins(BG_SPI_FRONT));
uint8_t bar_width = PicoExplorer::WIDTH / 6; uint8_t bar_width = PicoExplorer::WIDTH / 6;
uint8_t bar_height = PicoExplorer::HEIGHT; uint8_t bar_height = PicoExplorer::HEIGHT;
@ -20,13 +22,12 @@ void draw_bar(float scale, uint16_t channel) {
int16_t bar_top = bar_height - (bar_height * scale); int16_t bar_top = bar_height - (bar_height * scale);
bar_top = std::max((int16_t)0, bar_top); bar_top = std::max((int16_t)0, bar_top);
int16_t current_bar_height = bar_height - bar_top; int16_t current_bar_height = bar_height - bar_top;
pico_explorer.rectangle(Rect(channel * bar_width, bar_top, bar_width, current_bar_height - 1)); display.rectangle(Rect(channel * bar_width, bar_top, bar_width, current_bar_height - 1));
} }
int main() { int main() {
stdio_init_all(); stdio_init_all();
pico_explorer.init();
as7262.init(); as7262.init();
uint8_t dev_type = as7262.device_type(); uint8_t dev_type = as7262.device_type();
@ -43,9 +44,17 @@ int main() {
as7262.set_indicator_current(AS7262::indicator_current::ma4); as7262.set_indicator_current(AS7262::indicator_current::ma4);
as7262.set_leds(true, true); 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);
while(true) { while(true) {
pico_explorer.set_pen(0, 0, 0); display.set_pen(BLACK);
pico_explorer.clear(); display.clear();
AS7262::reading reading = as7262.read(); AS7262::reading reading = as7262.read();
printf("R: %f O: %f Y: %f G: %f B: %f V: %f \n", printf("R: %f O: %f Y: %f G: %f B: %f V: %f \n",
@ -64,34 +73,34 @@ int main() {
if(reading.blue > m) m = reading.blue; if(reading.blue > m) m = reading.blue;
if(reading.violet > m) m = reading.violet; if(reading.violet > m) m = reading.violet;
pico_explorer.set_pen(0, 0, 0); display.set_pen(BLACK);
pico_explorer.clear(); display.clear();
// Red // Red
pico_explorer.set_pen(255, 0, 0); display.set_pen(RED);
draw_bar(reading.red / m, 0); draw_bar(reading.red / m, 0);
// Orange // Orange
pico_explorer.set_pen(255, 128, 0); display.set_pen(ORANGE);
draw_bar(reading.orange / m, 1); draw_bar(reading.orange / m, 1);
// Yellow // Yellow
pico_explorer.set_pen(255, 255, 0); display.set_pen(YELLOW);
draw_bar(reading.yellow / m, 2); draw_bar(reading.yellow / m, 2);
// Green // Green
pico_explorer.set_pen(0, 255, 0); display.set_pen(GREEN);
draw_bar(reading.green / m, 3); draw_bar(reading.green / m, 3);
// Blue // Blue
pico_explorer.set_pen(0, 0, 255); display.set_pen(BLUE);
draw_bar(reading.blue / m, 4); draw_bar(reading.blue / m, 4);
// Violet // Violet
pico_explorer.set_pen(255, 0, 255); display.set_pen(VIOLET);
draw_bar(reading.violet / m, 5); draw_bar(reading.violet / m, 5);
pico_explorer.update(); display.update();
sleep_ms(INTEGRATION_TIME); sleep_ms(INTEGRATION_TIME);
} }

Wyświetl plik

@ -6,7 +6,7 @@ add_executable(
) )
# Pull in pico libraries that we need # Pull in pico libraries that we need
target_link_libraries(${OUTPUT_NAME} pico_stdlib generic_st7789) target_link_libraries(${OUTPUT_NAME} pico_stdlib picographics_st7789)
# create map/bin/hex file etc. # create map/bin/hex file etc.
pico_add_extra_outputs(${OUTPUT_NAME}) pico_add_extra_outputs(${OUTPUT_NAME})

Wyświetl plik

@ -1,21 +1,20 @@
#include <math.h> #include <math.h>
#include <vector> #include <vector>
#include "generic_st7789.hpp" #include "picographics_st7789.hpp"
using namespace pimoroni; using namespace pimoroni;
const int WIDTH = 240; const int WIDTH = 240;
const int HEIGHT = 240; const int HEIGHT = 240;
ST7789Generic display(WIDTH, HEIGHT, ROTATE_0, false, nullptr, get_spi_pins(BG_SPI_FRONT)); PicoGraphicsST7789 display(WIDTH, HEIGHT, ROTATE_0, false, nullptr, get_spi_pins(BG_SPI_FRONT));
int main() { int main() {
//lcd.configure_display(false); display.set_backlight(255);
lcd.set_backlight(255);
// Delete the default palette and allow us to create up to 256 of our own RGB565 colours // Delete the default palette and allow us to create up to 256 of our own RGB565 colours
lcd.set_palette_mode(ST7789Generic::PaletteModeUSER); display.set_palette_mode(PicoGraphicsST7789::PaletteModeUSER);
struct pt { struct pt {
float x; float x;
@ -30,40 +29,40 @@ int main() {
for(int i = 0; i < 100; i++) { for(int i = 0; i < 100; i++) {
pt shape; pt shape;
shape.r = (rand() % 10) + 3; shape.r = (rand() % 10) + 3;
shape.x = rand() % (lcd.bounds.w - (shape.r * 2)); shape.x = rand() % (display.bounds.w - (shape.r * 2));
shape.y = rand() % (lcd.bounds.h - (shape.r * 2)); shape.y = rand() % (display.bounds.h - (shape.r * 2));
shape.x += shape.r; shape.x += shape.r;
shape.y += shape.r; shape.y += shape.r;
shape.dx = float(rand() % 255) / 64.0f; shape.dx = float(rand() % 255) / 64.0f;
shape.dy = float(rand() % 255) / 64.0f; shape.dy = float(rand() % 255) / 64.0f;
shape.pen = lcd.create_pen(rand() % 255, rand() % 255, rand() % 255); shape.pen = display.create_pen(rand() % 255, rand() % 255, rand() % 255);
shapes.push_back(shape); shapes.push_back(shape);
} }
Pen BG = lcd.create_pen(120, 40, 60); Pen BG = display.create_pen(120, 40, 60);
Pen WHITE = lcd.create_pen(255, 255, 255); Pen WHITE = display.create_pen(255, 255, 255);
while(true) { while(true) {
lcd.set_pen(BG); display.set_pen(BG);
lcd.clear(); display.clear();
for(auto &shape : shapes) { for(auto &shape : shapes) {
shape.x += shape.dx; shape.x += shape.dx;
shape.y += shape.dy; shape.y += shape.dy;
if(shape.x < shape.r) shape.dx *= -1; if(shape.x < shape.r) shape.dx *= -1;
if(shape.x >= lcd.bounds.w - 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 < shape.r) shape.dy *= -1;
if(shape.y >= lcd.bounds.h - shape.r) shape.dy *= -1; if(shape.y >= display.bounds.h - shape.r) shape.dy *= -1;
lcd.set_pen(shape.pen); display.set_pen(shape.pen);
lcd.circle(Point(shape.x, shape.y), shape.r); display.circle(Point(shape.x, shape.y), shape.r);
} }
lcd.set_pen(WHITE); display.set_pen(WHITE);
lcd.text("Hello World", Point(0, 0), 240); display.text("Hello World", Point(0, 0), 240);
// update screen // update screen
lcd.update(); display.update();
} }
return 0; return 0;

Wyświetl plik

@ -2,11 +2,11 @@ set(OUTPUT_NAME roundlcd_demo)
add_executable( add_executable(
${OUTPUT_NAME} ${OUTPUT_NAME}
demo.cpp roundlcd_demo.cpp
) )
# Pull in pico libraries that we need # Pull in pico libraries that we need
target_link_libraries(${OUTPUT_NAME} pico_stdlib generic_st7789) target_link_libraries(${OUTPUT_NAME} pico_stdlib picographics_st7789)
# create map/bin/hex file etc. # create map/bin/hex file etc.
pico_add_extra_outputs(${OUTPUT_NAME}) pico_add_extra_outputs(${OUTPUT_NAME})

Wyświetl plik

@ -3,7 +3,7 @@
#include <vector> #include <vector>
#include <cstdlib> #include <cstdlib>
#include "generic_st7789.hpp" #include "picographics_st7789.hpp"
#include "time.h" #include "time.h"
// Place a 1.3 Round SPI LCD in the *front* slot of breakout garden. // Place a 1.3 Round SPI LCD in the *front* slot of breakout garden.
@ -14,7 +14,7 @@ using namespace pimoroni;
const int WIDTH = 240; const int WIDTH = 240;
const int HEIGHT = 240; const int HEIGHT = 240;
ST7789Generic display(WIDTH, HEIGHT, ROTATE_0, true, nullptr, get_spi_pins(BG_SPI_FRONT)); PicoGraphicsST7789 display(WIDTH, HEIGHT, ROTATE_0, true, nullptr, get_spi_pins(BG_SPI_FRONT));
constexpr float RADIUS = WIDTH / 2; constexpr float RADIUS = WIDTH / 2;
@ -44,7 +44,7 @@ int main() {
display.set_backlight(255); display.set_backlight(255);
// Delete the default palette and allow us to create up to 256 of our own RGB565 colours // Delete the default palette and allow us to create up to 256 of our own RGB565 colours
// display.set_palette_mode(ST7789Generic::PaletteModeUSER); // display.set_palette_mode(PicoGraphicsST7789::PaletteModeUSER);
uint32_t steps = 70; uint32_t steps = 70;
float angle_step = 0.5f; float angle_step = 0.5f;

Wyświetl plik

@ -5,7 +5,7 @@ add_executable(
) )
# Pull in pico libraries that we need # Pull in pico libraries that we need
target_link_libraries(pico_display_demo pico_stdlib hardware_spi hardware_pwm hardware_dma rgbled pico_display generic_st7789) target_link_libraries(pico_display_demo pico_stdlib hardware_spi hardware_pwm hardware_dma rgbled pico_display picographics_st7789)
# create map/bin/hex file etc. # create map/bin/hex file etc.
pico_add_extra_outputs(pico_display_demo) pico_add_extra_outputs(pico_display_demo)

Wyświetl plik

@ -4,12 +4,12 @@
#include <cstdlib> #include <cstdlib>
#include "pico_display.hpp" #include "pico_display.hpp"
#include "generic_st7789.hpp" #include "picographics_st7789.hpp"
#include "rgbled.hpp" #include "rgbled.hpp"
using namespace pimoroni; using namespace pimoroni;
ST7789Generic pico_display(PicoDisplay::WIDTH, PicoDisplay::HEIGHT, ROTATE_0); PicoGraphicsST7789 pico_display(PicoDisplay::WIDTH, PicoDisplay::HEIGHT, ROTATE_0);
RGBLED led(PicoDisplay::LED_R, PicoDisplay::LED_G, PicoDisplay::LED_B); RGBLED led(PicoDisplay::LED_R, PicoDisplay::LED_G, PicoDisplay::LED_B);

Wyświetl plik

@ -6,7 +6,7 @@ add_executable(
) )
# Pull in pico libraries that we need # 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 generic_st7789) target_link_libraries(${OUTPUT_NAME} pico_stdlib hardware_spi hardware_pwm hardware_dma rgbled button pico_display_2 picographics_st7789)
# create map/bin/hex file etc. # create map/bin/hex file etc.
pico_add_extra_outputs(${OUTPUT_NAME}) pico_add_extra_outputs(${OUTPUT_NAME})

Wyświetl plik

@ -4,13 +4,13 @@
#include <cstdlib> #include <cstdlib>
#include "pico_display_2.hpp" #include "pico_display_2.hpp"
#include "generic_st7789.hpp" #include "picographics_st7789.hpp"
#include "rgbled.hpp" #include "rgbled.hpp"
#include "button.hpp" #include "button.hpp"
using namespace pimoroni; using namespace pimoroni;
ST7789Generic pico_display(240, 240, ROTATE_0); PicoGraphicsST7789 pico_display(240, 240, ROTATE_0);
RGBLED led(PicoDisplay2::LED_R, PicoDisplay2::LED_G, PicoDisplay2::LED_B); RGBLED led(PicoDisplay2::LED_R, PicoDisplay2::LED_G, PicoDisplay2::LED_B);

Wyświetl plik

@ -2,11 +2,11 @@ set(OUTPUT_NAME encoder_explorer)
add_executable( add_executable(
${OUTPUT_NAME} ${OUTPUT_NAME}
demo.cpp pico_enc_explorer.cpp
) )
# Pull in pico libraries that we need # Pull in pico libraries that we need
target_link_libraries(${OUTPUT_NAME} pico_stdlib breakout_encoder pico_explorer) target_link_libraries(${OUTPUT_NAME} pico_stdlib breakout_encoder pico_explorer picographics_st7789)
# create map/bin/hex file etc. # create map/bin/hex file etc.
pico_add_extra_outputs(${OUTPUT_NAME}) pico_add_extra_outputs(${OUTPUT_NAME})

Wyświetl plik

@ -6,11 +6,23 @@
#include "pico_explorer.hpp" #include "pico_explorer.hpp"
#include "breakout_encoder.hpp" #include "breakout_encoder.hpp"
#include "picographics_st7789.hpp"
using namespace pimoroni; using namespace pimoroni;
uint16_t buffer[PicoExplorer::WIDTH * PicoExplorer::HEIGHT]; PicoGraphicsST7789 display(
PicoExplorer pico_explorer(buffer); PicoExplorer::WIDTH,
PicoExplorer::HEIGHT,
ROTATE_0, // Rotation
false, // Is it round!?
nullptr, // Buffer
get_spi_pins(BG_SPI_FRONT)
);
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);
static const uint8_t STEPS_PER_REV = 24; static const uint8_t STEPS_PER_REV = 24;
@ -44,47 +56,49 @@ void count_changed(int16_t count) {
from_hsv(h, 1.0f, 1.0f, r, g, b); from_hsv(h, 1.0f, 1.0f, r, g, b);
enc.set_led(r, g, b); enc.set_led(r, g, b);
pico_explorer.set_pen(0, 0, 0); display.set_pen(BLACK);
pico_explorer.clear(); display.clear();
{ {
pico_explorer.set_pen(255, 0, 0); display.set_pen(RED);
std::ostringstream ss; std::ostringstream ss;
ss << "R = "; ss << "R = ";
ss << (int)r; ss << (int)r;
std::string s(ss.str()); std::string s(ss.str());
pico_explorer.text(s, Point(10, 10), 220, 6); display.text(s, Point(10, 10), 220, 6);
} }
{ {
pico_explorer.set_pen(0, 255, 0); display.set_pen(GREEN);
std::ostringstream ss; std::ostringstream ss;
ss << "G = "; ss << "G = ";
ss << (int)g; ss << (int)g;
std::string s(ss.str()); std::string s(ss.str());
pico_explorer.text(s, Point(10, 70), 220, 6); display.text(s, Point(10, 70), 220, 6);
} }
{ {
pico_explorer.set_pen(0, 0, 255); display.set_pen(BLUE);
std::ostringstream ss; std::ostringstream ss;
ss << "B = "; ss << "B = ";
ss << (int)b; ss << (int)b;
std::string s(ss.str()); std::string s(ss.str());
pico_explorer.text(s, Point(10, 130), 220, 6); display.text(s, Point(10, 130), 220, 6);
} }
{ {
pico_explorer.set_pen(r, g, b); // 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));
std::ostringstream ss; std::ostringstream ss;
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)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)g;
ss << std::uppercase << std::hex << std::setfill('0') << std::setw(2) << (int)b; ss << std::uppercase << std::hex << std::setfill('0') << std::setw(2) << (int)b;
std::string s(ss.str()); std::string s(ss.str());
pico_explorer.text(s, Point(10, 190), 220, 5); display.text(s, Point(10, 190), 220, 5);
} }
pico_explorer.update(); display.update();
} }
int main() { int main() {
@ -93,9 +107,6 @@ int main() {
stdio_init_all(); stdio_init_all();
pico_explorer.init();
pico_explorer.update();
int16_t count = 0; int16_t count = 0;
if(enc.init()) { if(enc.init()) {
printf("Encoder found...\n"); printf("Encoder found...\n");

Wyświetl plik

@ -1,21 +1,21 @@
add_executable( add_executable(
explorer pico_explorer_demo
demo.cpp pico_explorer_demo.cpp
) )
add_resource(explorer fox.tga) add_resource(pico_explorer_demo fox.tga)
# Pull in pico libraries that we need # Pull in pico libraries that we need
target_link_libraries(explorer pico_stdlib pico_explorer msa301) target_link_libraries(pico_explorer_demo pico_stdlib pico_explorer msa301 picographics_st7789 button motor analog)
# create map/bin/hex file etc. # create map/bin/hex file etc.
pico_add_extra_outputs(explorer) pico_add_extra_outputs(pico_explorer_demo)
add_executable( add_executable(
text_demo text_demo
text_demo.cpp text_demo.cpp
) )
target_link_libraries(text_demo pico_stdlib pico_explorer msa301) target_link_libraries(text_demo pico_stdlib pico_explorer msa301 picographics_st7789)
pico_add_extra_outputs(text_demo) pico_add_extra_outputs(text_demo)

Wyświetl plik

@ -1,227 +0,0 @@
#include <string.h>
#include <math.h>
#include <vector>
#include <cstdlib>
#include "pico_explorer.hpp"
#include "msa301.hpp"
using namespace pimoroni;
extern unsigned char _binary_fox_tga_start[];
uint16_t buffer[PicoExplorer::WIDTH * PicoExplorer::HEIGHT];
PicoExplorer pico_explorer(buffer);
MSA301 msa301;
uint8_t arrow[] = {
0b00010000,
0b00110000,
0b01110000,
0b11111111,
0b11111111,
0b01110000,
0b00110000,
0b00010000
};
uint8_t tick[] = {
0b00000000,
0b00000010,
0b00000111,
0b01001110,
0b11111100,
0b00111000,
0b00010000,
0b00000000,
};
/*
void sprite(uint8_t *p, int x, int y, bool flip, uint16_t c) {
for(int ay = 0; ay < 8; ay++) {
uint8_t sl = p[ay];
for(int ax = 0; ax < 8; ax++) {
if(flip) {
if((0b10000000 >> ax) & sl) {
pixel(ax + x, ay + y, c);
}
}else{
if((0b1 << ax) & sl) {
pixel(ax + x, ay + y, c);
}
}
}
}
}*/
int main() {
pico_explorer.init();
msa301.init();
struct pt {
float x;
float y;
uint8_t r;
float dx;
float dy;
uint16_t pen;
};
std::vector<pt> shapes;
for(int i = 0; i < 100; i++) {
pt shape;
shape.x = rand() % 240;
shape.y = rand() % 135;
shape.r = (rand() % 10) + 3;
shape.dx = float(rand() % 255) / 128.0f;
shape.dy = float(rand() % 255) / 128.0f;
shape.pen = pico_explorer.create_pen(rand() % 255, rand() % 255, rand() % 255);
shapes.push_back(shape);
}
pico_explorer.set_audio_pin(pico_explorer.GP0);
Pen BG = pico_explorer.create_pen(120, 40, 60);
Pen WHITE = pico_explorer.create_pen(255, 255, 255);
Pen BOX = pico_explorer.create_pen(55, 65, 75);
Pen PURPLE = pico_explorer.create_pen(255, 0, 255);
uint32_t i = 0;
while(true) {
pico_explorer.set_pen(BG);
pico_explorer.clear();
for(auto &shape : shapes) {
shape.x += shape.dx;
shape.y += shape.dy;
if(shape.x < 0) shape.dx *= -1;
if(shape.x >= pico_explorer.bounds.w) shape.dx *= -1;
if(shape.y < 0) shape.dy *= -1;
if(shape.y >= pico_explorer.bounds.h) shape.dy *= -1;
pico_explorer.set_pen(shape.pen);
pico_explorer.circle(Point(shape.x, shape.y), shape.r);
}
float rv = pico_explorer.get_adc(pico_explorer.ADC0);
pico_explorer.set_pen(WHITE);
pico_explorer.circle(Point(rv * 140 + 50, 110), 20);
pico_explorer.set_pen(pico_explorer.create_pen(rv * 255, 0, 0));
pico_explorer.circle(Point(rv * 140 + 50, 110), 15);
float gv = pico_explorer.get_adc(pico_explorer.ADC1);
pico_explorer.set_pen(WHITE);
pico_explorer.circle(Point(gv * 140 + 50, 160), 20);
pico_explorer.set_pen(pico_explorer.create_pen(0, gv * 255, 0));
pico_explorer.circle(Point(gv * 140 + 50, 160), 15);
float bv = pico_explorer.get_adc(pico_explorer.ADC2);
pico_explorer.set_pen(WHITE);
pico_explorer.circle(Point(bv * 140 + 50, 210), 20);
pico_explorer.set_pen(pico_explorer.create_pen(0, 0, bv * 255));
pico_explorer.circle(Point(bv * 140 + 50, 210), 15);
pico_explorer.set_motor(pico_explorer.MOTOR1, pico_explorer.FORWARD, bv);
pico_explorer.set_motor(pico_explorer.MOTOR2, pico_explorer.FORWARD, rv);
pico_explorer.set_tone(440, 0.5);
if(pico_explorer.is_pressed(pico_explorer.A)) {
pico_explorer.set_pen(WHITE);
pico_explorer.character('A', Point(120, 180), 5);
}
if(pico_explorer.is_pressed(pico_explorer.B)) {
pico_explorer.set_pen(WHITE);
pico_explorer.character('B', Point(120, 180), 5);
}
if(pico_explorer.is_pressed(pico_explorer.X)) {
pico_explorer.set_pen(WHITE);
pico_explorer.character('X', Point(120, 180), 5);
}
if(pico_explorer.is_pressed(pico_explorer.Y)) {
pico_explorer.set_pen(WHITE);
pico_explorer.character('Y', Point(120, 180), 5);
}
float tyoff = cos(i / 20.0f) * 50.0f - 50.0f;
Rect text_box(10, 10, 150, 150);
pico_explorer.set_pen(BOX);
pico_explorer.rectangle(text_box);
text_box.deflate(10);
pico_explorer.set_clip(text_box);
pico_explorer.set_pen(WHITE);
pico_explorer.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 = pico_explorer.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++;
pico_explorer.set_pen(r, g, b);
pico_explorer.pixel(Point(x + xoff, 68 - y + yoff));
}
}
pico_explorer.remove_clip();
pico_explorer.set_pen(WHITE);
pico_explorer.text("x: " + std::to_string(int(msa301.get_axis(msa301.X, 16) * 100)), Point(10, 190), 100);
pico_explorer.text("y: " + std::to_string(int(msa301.get_axis(msa301.Y, 16) * 100)), Point(10, 205), 100);
pico_explorer.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;
pico_explorer.set_pen(WHITE);
pico_explorer.circle(Point(xpos, ypos), 20);
pico_explorer.set_pen(PURPLE);
pico_explorer.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
pico_explorer.update();
i++;
}
return 0;
}

Wyświetl plik

@ -0,0 +1,251 @@
#include <string.h>
#include <math.h>
#include <vector>
#include <cstdlib>
#include "pico_explorer.hpp"
#include "picographics_st7789.hpp"
#include "button.hpp"
#include "motor.hpp"
#include "msa301.hpp"
#include "analog.hpp"
using namespace pimoroni;
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)
);
// Buttons
Button button_a(PicoExplorer::A);
Button button_b(PicoExplorer::B);
Button button_x(PicoExplorer::X);
Button button_y(PicoExplorer::Y);
Motor motor1(PicoExplorer::MOTOR1_PINS);
Motor motor2(PicoExplorer::MOTOR2_PINS);
Analog adc0(PicoExplorer::ADC0_PIN);
Analog adc1(PicoExplorer::ADC1_PIN);
Analog adc2(PicoExplorer::ADC2_PIN);
MSA301 msa301;
uint8_t arrow[] = {
0b00010000,
0b00110000,
0b01110000,
0b11111111,
0b11111111,
0b01110000,
0b00110000,
0b00010000
};
uint8_t tick[] = {
0b00000000,
0b00000010,
0b00000111,
0b01001110,
0b11111100,
0b00111000,
0b00010000,
0b00000000,
};
/*
void sprite(uint8_t *p, int x, int y, bool flip, uint16_t c) {
for(int ay = 0; ay < 8; ay++) {
uint8_t sl = p[ay];
for(int ax = 0; ax < 8; ax++) {
if(flip) {
if((0b10000000 >> ax) & sl) {
pixel(ax + x, ay + y, c);
}
}else{
if((0b1 << ax) & sl) {
pixel(ax + x, ay + y, c);
}
}
}
}
}*/
int main() {
msa301.init();
struct pt {
float x;
float y;
uint8_t r;
float dx;
float dy;
uint16_t pen;
};
std::vector<pt> shapes;
for(int i = 0; i < 100; i++) {
pt shape;
shape.x = rand() % 240;
shape.y = rand() % 135;
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);
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);
uint32_t i = 0;
while(true) {
display.set_pen(BG);
display.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.y < 0) shape.dy *= -1;
if(shape.y >= display.bounds.h) shape.dy *= -1;
display.set_pen(shape.pen);
display.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);
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);
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);
// TODO Find the correct way to translate these in terms of motor
// display.set_motor(display.MOTOR1, display.FORWARD, bv);
// display.set_motor(display.MOTOR2, display.FORWARD, rv);
// TODO make this work
// display.set_tone(440, 0.5);
if(button_a.read()) {
display.set_pen(WHITE);
display.character('A', Point(120, 180), 5);
}
if(button_b.read()) {
display.set_pen(WHITE);
display.character('B', Point(120, 180), 5);
}
if(button_x.read()) {
display.set_pen(WHITE);
display.character('X', Point(120, 180), 5);
}
if(button_y.read()) {
display.set_pen(WHITE);
display.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);
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);
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));
}
}
display.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);
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);
/*
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();
i++;
}
return 0;
}

Wyświetl plik

@ -1,12 +1,12 @@
add_executable( add_executable(
explorerencoder pico_explorer_encoder
demo.cpp pico_explorer_encoder.cpp
) )
pico_generate_pio_header(explorerencoder ${CMAKE_CURRENT_LIST_DIR}/quadrature_out.pio) pico_generate_pio_header(pico_explorer_encoder ${CMAKE_CURRENT_LIST_DIR}/quadrature_out.pio)
# Pull in pico libraries that we need # Pull in pico libraries that we need
target_link_libraries(explorerencoder pico_stdlib pico_explorer encoder) target_link_libraries(pico_explorer_encoder pico_stdlib pico_explorer encoder button motor picographics_st7789)
# create map/bin/hex file etc. # create map/bin/hex file etc.
pico_add_extra_outputs(explorerencoder) pico_add_extra_outputs(pico_explorer_encoder)

Wyświetl plik

@ -4,6 +4,8 @@
#include "pico/stdlib.h" #include "pico/stdlib.h"
#include "encoder.hpp" #include "encoder.hpp"
#include "quadrature_out.pio.h" #include "quadrature_out.pio.h"
#include "picographics_st7789.hpp"
#include "button.hpp"
/* /*
An interactive demo of how rotary encoders work. An interactive demo of how rotary encoders work.
@ -31,6 +33,7 @@ be used by jumping GP0 to GP6 and GP1 to GP7.
using namespace pimoroni; using namespace pimoroni;
using namespace encoder; using namespace encoder;
using namespace motor;
//-------------------------------------------------- //--------------------------------------------------
// Constants // Constants
@ -90,8 +93,22 @@ enum DrawState {
//-------------------------------------------------- //--------------------------------------------------
// Variables // Variables
//-------------------------------------------------- //--------------------------------------------------
uint16_t buffer[PicoExplorer::WIDTH * PicoExplorer::HEIGHT]; PicoGraphicsST7789 display(
PicoExplorer pico_explorer(buffer); PicoExplorer::WIDTH,
PicoExplorer::HEIGHT,
ROTATE_0, // Rotation
false, // Is it round!?
nullptr, // Buffer
get_spi_pins(BG_SPI_FRONT)
);
Button button_a(PicoExplorer::A);
Button button_b(PicoExplorer::B);
Button button_x(PicoExplorer::X);
Button button_y(PicoExplorer::Y);
Motor motor1(PicoExplorer::MOTOR1_PINS);
Motor motor2(PicoExplorer::MOTOR2_PINS);
Encoder enc(pio0, 0, ENCODER_PINS, ENCODER_COMMON_PIN, NORMAL_DIR, COUNTS_PER_REV, COUNT_MICROSTEPS, FREQ_DIVIDER); Encoder enc(pio0, 0, ENCODER_PINS, ENCODER_COMMON_PIN, NORMAL_DIR, COUNTS_PER_REV, COUNT_MICROSTEPS, FREQ_DIVIDER);
@ -166,13 +183,13 @@ uint32_t draw_plot(Point p1, Point p2, volatile bool (&readings)[READINGS_SIZE],
switch(draw_state) { switch(draw_state) {
case DRAW_TRANSITION: case DRAW_TRANSITION:
for(uint8_t y = p1.y; y < p2.y; y++) for(uint8_t y = p1.y; y < p2.y; y++)
pico_explorer.pixel(Point(x + p1.x, y)); display.pixel(Point(x + p1.x, y));
break; break;
case DRAW_HIGH: case DRAW_HIGH:
pico_explorer.pixel(Point(x + p1.x, p1.y)); display.pixel(Point(x + p1.x, p1.y));
break; break;
case DRAW_LOW: case DRAW_LOW:
pico_explorer.pixel(Point(x + p1.x, p2.y - 1)); display.pixel(Point(x + p1.x, p2.y - 1));
break; break;
} }
} }
@ -215,11 +232,6 @@ void setup() {
gpio_pull_down(ENCODER_SWITCH_PIN); gpio_pull_down(ENCODER_SWITCH_PIN);
} }
pico_explorer.init();
pico_explorer.set_pen(0);
pico_explorer.clear();
pico_explorer.update();
enc.init(); enc.init();
bool_pair state = enc.state(); bool_pair state = enc.state();
@ -243,6 +255,7 @@ void setup() {
// MAIN // MAIN
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
int main() { int main() {
Pen WHITE = display.create_pen(255, 255, 255);
// Perform the main setup for the demo // Perform the main setup for the demo
setup(); setup();
@ -273,18 +286,21 @@ int main() {
Encoder::Capture capture = enc.capture(); Encoder::Capture capture = enc.capture();
// Spin Motor 1 either clockwise or counterclockwise depending on if B or Y are pressed // Spin Motor 1 either clockwise or counterclockwise depending on if B or Y are pressed
if(pico_explorer.is_pressed(PicoExplorer::B) && !pico_explorer.is_pressed(PicoExplorer::Y)) { if(button_b.read() && !button_y.read()) {
pico_explorer.set_motor(PicoExplorer::MOTOR1, PicoExplorer::FORWARD, 1.0f); // TODO Fix motors
//display.set_motor(PicoExplorer::MOTOR1, PicoExplorer::FORWARD, 1.0f);
} }
else if(pico_explorer.is_pressed(PicoExplorer::Y) && !pico_explorer.is_pressed(PicoExplorer::B)) { else if(button_y.read() && !button_b.read()) {
pico_explorer.set_motor(PicoExplorer::MOTOR1, PicoExplorer::REVERSE, 0.2f); // TODO Fix motors
//display.set_motor(PicoExplorer::MOTOR1, PicoExplorer::REVERSE, 0.2f);
} }
else { else {
pico_explorer.set_motor(PicoExplorer::MOTOR1, PicoExplorer::STOP); // TODO Fix motors
//display.set_motor(PicoExplorer::MOTOR1, PicoExplorer::STOP);
} }
// If A has been pressed, zoom the view out to a min of x1 // If A has been pressed, zoom the view out to a min of x1
if(pico_explorer.is_pressed(PicoExplorer::A)) { if(button_a.read()) {
if(!button_latch_a) { if(!button_latch_a) {
button_latch_a = true; button_latch_a = true;
current_zoom_level = std::max(current_zoom_level / 2, 1); current_zoom_level = std::max(current_zoom_level / 2, 1);
@ -295,7 +311,7 @@ int main() {
} }
// If X has been pressed, zoom the view in to the max of x512 // If X has been pressed, zoom the view in to the max of x512
if(pico_explorer.is_pressed(PicoExplorer::X)) { if(button_x.read()) {
if(!button_latch_x) { if(!button_latch_x) {
button_latch_x = true; button_latch_x = true;
current_zoom_level = std::min(current_zoom_level * 2, 512); current_zoom_level = std::min(current_zoom_level * 2, 512);
@ -308,16 +324,16 @@ int main() {
//-------------------------------------------------- //--------------------------------------------------
// Draw the encoder readings to the screen as a signal plot // Draw the encoder readings to the screen as a signal plot
pico_explorer.set_pen(0, 0, 0); display.set_pen(display.create_pen(0, 0, 0));
pico_explorer.clear(); display.clear();
drawing_to_screen = true; drawing_to_screen = true;
pico_explorer.set_pen(255, 255, 0); display.set_pen(display.create_pen(255, 255, 0));
uint32_t local_pos = next_reading_index; 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); 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);
pico_explorer.set_pen(0, 255, 255); display.set_pen(display.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); 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 // Copy values that may have been stored in the scratch buffers, back into the main buffers
@ -333,49 +349,49 @@ int main() {
drawing_to_screen = false; drawing_to_screen = false;
next_scratch_index = 0; next_scratch_index = 0;
pico_explorer.set_pen(255, 255, 255); display.set_pen(WHITE);
pico_explorer.character('A', Point(5, 10 + 15), 3); display.character('A', Point(5, 10 + 15), 3);
pico_explorer.character('B', Point(5, 80 + 15), 3); display.character('B', Point(5, 80 + 15), 3);
if(current_zoom_level < 10) if(current_zoom_level < 10)
pico_explorer.text("x" + std::to_string(current_zoom_level), Point(220, 62), 200, 2); display.text("x" + std::to_string(current_zoom_level), Point(220, 62), 200, 2);
else if(current_zoom_level < 100) else if(current_zoom_level < 100)
pico_explorer.text("x" + std::to_string(current_zoom_level), Point(210, 62), 200, 2); display.text("x" + std::to_string(current_zoom_level), Point(210, 62), 200, 2);
else else
pico_explorer.text("x" + std::to_string(current_zoom_level), Point(200, 62), 200, 2); display.text("x" + std::to_string(current_zoom_level), Point(200, 62), 200, 2);
//-------------------------------------------------- //--------------------------------------------------
// Write out the count, frequency and rpm of the encoder // Write out the count, frequency and rpm of the encoder
pico_explorer.set_pen(8, 8, 8); display.set_pen(display.create_pen(8, 8, 8));
pico_explorer.rectangle(Rect(0, 140, PicoExplorer::WIDTH, PicoExplorer::HEIGHT - 140)); display.rectangle(Rect(0, 140, PicoExplorer::WIDTH, PicoExplorer::HEIGHT - 140));
pico_explorer.set_pen(64, 64, 64); display.set_pen(display.create_pen(64, 64, 64));
pico_explorer.rectangle(Rect(0, 140, PicoExplorer::WIDTH, 2)); display.rectangle(Rect(0, 140, PicoExplorer::WIDTH, 2));
{ {
std::stringstream sstream; std::stringstream sstream;
sstream << capture.count(); sstream << capture.count();
pico_explorer.set_pen(255, 255, 255); pico_explorer.text("Count:", Point(10, 150), 200, 3); display.set_pen(WHITE); display.text("Count:", Point(10, 150), 200, 3);
pico_explorer.set_pen(255, 128, 255); pico_explorer.text(sstream.str(), Point(110, 150), 200, 3); display.set_pen(display.create_pen(255, 128, 255)); display.text(sstream.str(), Point(110, 150), 200, 3);
} }
{ {
std::stringstream sstream; std::stringstream sstream;
sstream << std::fixed << std::setprecision(1) << capture.frequency() << "hz"; sstream << std::fixed << std::setprecision(1) << capture.frequency() << "hz";
pico_explorer.set_pen(255, 255, 255); pico_explorer.text("Freq: ", Point(10, 180), 220, 3); display.set_pen(WHITE); display.text("Freq: ", Point(10, 180), 220, 3);
pico_explorer.set_pen(128, 255, 255); pico_explorer.text(sstream.str(), Point(90, 180), 220, 3); display.set_pen(display.create_pen(128, 255, 255)); display.text(sstream.str(), Point(90, 180), 220, 3);
} }
{ {
std::stringstream sstream; std::stringstream sstream;
sstream << std::fixed << std::setprecision(1) << capture.revolutions_per_minute(); sstream << std::fixed << std::setprecision(1) << capture.revolutions_per_minute();
pico_explorer.set_pen(255, 255, 255); pico_explorer.text("RPM: ", Point(10, 210), 220, 3); display.set_pen(WHITE); display.text("RPM: ", Point(10, 210), 220, 3);
pico_explorer.set_pen(255, 255, 128); pico_explorer.text(sstream.str(), Point(80, 210), 220, 3); display.set_pen(display.create_pen(255, 255, 128)); display.text(sstream.str(), Point(80, 210), 220, 3);
} }
pico_explorer.update(); // Refresh the screen display.update(); // Refresh the screen
gpio_put(PICO_DEFAULT_LED_PIN, false); // Show the screen refresh has ended gpio_put(PICO_DEFAULT_LED_PIN, false); // Show the screen refresh has ended
} }
} }

Wyświetl plik

@ -2,11 +2,11 @@ set(OUTPUT_NAME potentiometer_explorer)
add_executable( add_executable(
${OUTPUT_NAME} ${OUTPUT_NAME}
demo.cpp pico_pot_explorer.cpp
) )
# Pull in pico libraries that we need # Pull in pico libraries that we need
target_link_libraries(${OUTPUT_NAME} pico_stdlib breakout_potentiometer pico_explorer) target_link_libraries(${OUTPUT_NAME} pico_stdlib breakout_potentiometer pico_explorer picographics_st7789)
# create map/bin/hex file etc. # create map/bin/hex file etc.
pico_add_extra_outputs(${OUTPUT_NAME}) pico_add_extra_outputs(${OUTPUT_NAME})

Wyświetl plik

@ -7,11 +7,23 @@
#include "common/pimoroni_i2c.hpp" #include "common/pimoroni_i2c.hpp"
#include "pico_explorer.hpp" #include "pico_explorer.hpp"
#include "breakout_potentiometer.hpp" #include "breakout_potentiometer.hpp"
#include "picographics_st7789.hpp"
using namespace pimoroni; using namespace pimoroni;
uint16_t buffer[PicoExplorer::WIDTH * PicoExplorer::HEIGHT]; PicoGraphicsST7789 display(
PicoExplorer pico_explorer(buffer); PicoExplorer::WIDTH,
PicoExplorer::HEIGHT,
ROTATE_0, // Rotation
false, // Is it round!?
nullptr, // Buffer
get_spi_pins(BG_SPI_FRONT)
);
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);
I2C i2c(PICO_EXPLORER); I2C i2c(PICO_EXPLORER);
BreakoutPotentiometer pot(&i2c); BreakoutPotentiometer pot(&i2c);
@ -43,9 +55,6 @@ int main() {
stdio_init_all(); stdio_init_all();
pico_explorer.init();
pico_explorer.update();
printf("Starting...\n"); printf("Starting...\n");
if(pot.init()) { if(pot.init()) {
@ -62,47 +71,49 @@ int main() {
from_hsv(percent, 1.0f, 1.0f, r, g, b); from_hsv(percent, 1.0f, 1.0f, r, g, b);
pot.set_led(r, g, b); pot.set_led(r, g, b);
pico_explorer.set_pen(0, 0, 0); display.set_pen(BLACK);
pico_explorer.clear(); display.clear();
{ {
pico_explorer.set_pen(255, 0, 0); display.set_pen(RED);
std::ostringstream ss; std::ostringstream ss;
ss << "R = "; ss << "R = ";
ss << (int)r; ss << (int)r;
std::string s(ss.str()); std::string s(ss.str());
pico_explorer.text(s, Point(10, 10), 220, 6); display.text(s, Point(10, 10), 220, 6);
} }
{ {
pico_explorer.set_pen(0, 255, 0); display.set_pen(GREEN);
std::ostringstream ss; std::ostringstream ss;
ss << "G = "; ss << "G = ";
ss << (int)g; ss << (int)g;
std::string s(ss.str()); std::string s(ss.str());
pico_explorer.text(s, Point(10, 70), 220, 6); display.text(s, Point(10, 70), 220, 6);
} }
{ {
pico_explorer.set_pen(0, 0, 255); display.set_pen(BLUE);
std::ostringstream ss; std::ostringstream ss;
ss << "B = "; ss << "B = ";
ss << (int)b; ss << (int)b;
std::string s(ss.str()); std::string s(ss.str());
pico_explorer.text(s, Point(10, 130), 220, 6); display.text(s, Point(10, 130), 220, 6);
} }
{ {
pico_explorer.set_pen(r, g, b); // 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));
std::ostringstream ss; std::ostringstream ss;
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)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)g;
ss << std::uppercase << std::hex << std::setfill('0') << std::setw(2) << (int)b; ss << std::uppercase << std::hex << std::setfill('0') << std::setw(2) << (int)b;
std::string s(ss.str()); std::string s(ss.str());
pico_explorer.text(s, Point(10, 190), 220, 5); display.text(s, Point(10, 190), 220, 5);
} }
pico_explorer.update(); display.update();
} }
} }
else { else {

Wyświetl plik

@ -2,11 +2,11 @@ set(OUTPUT_NAME rtc_display)
add_executable( add_executable(
${OUTPUT_NAME} ${OUTPUT_NAME}
demo.cpp pico_rtc_display.cpp
) )
# Pull in pico libraries that we need # Pull in pico libraries that we need
target_link_libraries(${OUTPUT_NAME} pico_stdlib pico_explorer pico_display breakout_rtc) target_link_libraries(${OUTPUT_NAME} pico_stdlib pico_explorer pico_display breakout_rtc picographics_st7789 button rgbled)
# create map/bin/hex file etc. # create map/bin/hex file etc.
pico_add_extra_outputs(${OUTPUT_NAME}) pico_add_extra_outputs(${OUTPUT_NAME})

Wyświetl plik

@ -17,7 +17,7 @@
// To use PicoExplorer rather than PicoDisplay, uncomment the following line // To use PicoExplorer rather than PicoDisplay, uncomment the following line
// #define USE_PICO_EXPLORER 1 // #define USE_PICO_EXPLORER 1
// This: // This:
// - Includes pico_explorer.hpp rather than pico_display.hpp // - Includes pico_explorer.hpp rather than display.hpp
// - Replaces all PicoDisplay references with PicoExplorer // - Replaces all PicoDisplay references with PicoExplorer
// - Leaves out the .set_led() calls in flash_led() // - Leaves out the .set_led() calls in flash_led()
#ifdef USE_PICO_EXPLORER #ifdef USE_PICO_EXPLORER
@ -27,6 +27,10 @@
#endif #endif
#include "breakout_rtc.hpp" #include "breakout_rtc.hpp"
#include "picographics_st7789.hpp"
#include "drivers/button/button.hpp"
#include "drivers/rgbled/rgbled.hpp"
#define MODE_DISP_CLOCK 0 #define MODE_DISP_CLOCK 0
#define MODE_DISP_TIMER 1 #define MODE_DISP_TIMER 1
#define MODE_SET_TIMER 2 #define MODE_SET_TIMER 2
@ -36,17 +40,28 @@
using namespace pimoroni; using namespace pimoroni;
#ifdef USE_PICO_EXPLORER #ifdef USE_PICO_EXPLORER
uint16_t buffer[PicoExplorer::WIDTH * PicoExplorer::HEIGHT];
PicoExplorer pico_display(buffer);
uint16_t screen_width = PicoExplorer::WIDTH; uint16_t screen_width = PicoExplorer::WIDTH;
uint16_t screen_height = PicoExplorer::HEIGHT; uint16_t screen_height = PicoExplorer::HEIGHT;
Button button_a(PicoExplorer::A);
Button button_b(PicoExplorer::B);
Button button_x(PicoExplorer::X);
Button button_y(PicoExplorer::Y);
#else #else
uint16_t buffer[PicoDisplay::WIDTH * PicoDisplay::HEIGHT];
PicoDisplay pico_display(buffer);
uint16_t screen_width = PicoDisplay::WIDTH; uint16_t screen_width = PicoDisplay::WIDTH;
uint16_t screen_height = PicoDisplay::HEIGHT; uint16_t screen_height = PicoDisplay::HEIGHT;
Button button_a(PicoDisplay::A);
Button button_b(PicoDisplay::B);
Button button_x(PicoDisplay::X);
Button button_y(PicoDisplay::Y);
RGBLED led(PicoDisplay::LED_R, PicoDisplay::LED_G, PicoDisplay::LED_B);
#endif #endif
PicoGraphicsST7789 display(screen_width, screen_height, ROTATE_0, false, nullptr, get_spi_pins(BG_SPI_FRONT));
BreakoutRTC rtc; BreakoutRTC rtc;
#define LOW_COUNT_MOD 40 #define LOW_COUNT_MOD 40
@ -69,17 +84,20 @@ void flash_led(uint32_t curr_count) {
#ifndef USE_PICO_EXPLORER #ifndef USE_PICO_EXPLORER
if((curr_count % FLASH_MOD) < (FLASH_MOD / 2)) { if((curr_count % FLASH_MOD) < (FLASH_MOD / 2)) {
// value less than half modded number - LED off // value less than half modded number - LED off
pico_display.set_led(0, 0, 0); led.set_rgb(0, 0, 0);
} }
else { else {
// value more than half modded number - LED on // value more than half modded number - LED on
pico_display.set_led(128, 128, 128); led.set_rgb(128, 128, 128);
} }
#endif #endif
} }
int main() { int main() {
pico_display.init(); 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);
rtc.init(); rtc.init();
// rtc.setup(false); // rtc.setup(false);
@ -112,7 +130,7 @@ int main() {
while(true) { while(true) {
if(a_pressed == 0 && pico_display.is_pressed(pico_display.A)) { if(a_pressed == 0 && button_a.read()) {
a_pressed = 1; a_pressed = 1;
if(display_mode == MODE_DISP_CLOCK) { if(display_mode == MODE_DISP_CLOCK) {
// We were displaying clock = set up timer // We were displaying clock = set up timer
@ -134,11 +152,11 @@ int main() {
display_mode = MODE_SET_TIMER; display_mode = MODE_SET_TIMER;
} }
} }
else if(a_pressed >= 1 && !pico_display.is_pressed(pico_display.A)) { else if(a_pressed >= 1 && !button_a.read()) {
a_pressed = 0; a_pressed = 0;
} }
if(b_pressed == 0 && pico_display.is_pressed(pico_display.B)) { if(b_pressed == 0 && button_b.read()) {
b_pressed = 1; b_pressed = 1;
if((display_mode == MODE_DISP_TIMER) if((display_mode == MODE_DISP_TIMER)
|| (display_mode == MODE_SET_TIMER)) { || (display_mode == MODE_SET_TIMER)) {
@ -150,117 +168,117 @@ int main() {
timer_count = DEFAULT_TIMER_COUNT; timer_count = DEFAULT_TIMER_COUNT;
} }
} }
else if(b_pressed >= 1 && !pico_display.is_pressed(pico_display.B)) { else if(b_pressed >= 1 && !button_b.read()) {
b_pressed = 0; b_pressed = 0;
} }
if(x_pressed == 0 && pico_display.is_pressed(pico_display.X)) { if(x_pressed == 0 && button_x.read()) {
x_pressed = 1; x_pressed = 1;
if(display_mode == MODE_SET_TIMER) { if(display_mode == MODE_SET_TIMER) {
// Setting timer - Increment count // Setting timer - Increment count
timer_count++; timer_count++;
} }
} }
else if(x_pressed >= 1 && pico_display.is_pressed(pico_display.X)) { else if(x_pressed >= 1 && button_x.read()) {
// Button still pressed - check if has reached repeat count // Button still pressed - check if has reached repeat count
if(repeat_count_reached(x_pressed++)) { if(repeat_count_reached(x_pressed++)) {
timer_count++; timer_count++;
} }
} }
else if(x_pressed >= 1 && !pico_display.is_pressed(pico_display.X)) { else if(x_pressed >= 1 && !button_x.read()) {
x_pressed = 0; x_pressed = 0;
} }
if(y_pressed == 0 && pico_display.is_pressed(pico_display.Y)) { if(y_pressed == 0 && button_y.read()) {
y_pressed = 1; y_pressed = 1;
if(display_mode == MODE_SET_TIMER) { if(display_mode == MODE_SET_TIMER) {
// Setting timer - Decrement count // Setting timer - Decrement count
if (timer_count >= 1) timer_count--; if (timer_count >= 1) timer_count--;
} }
} }
else if(y_pressed >= 1 && pico_display.is_pressed(pico_display.Y)) { else if(y_pressed >= 1 && button_y.read()) {
// Button still pressed - check if has reached repeat count // Button still pressed - check if has reached repeat count
if(repeat_count_reached(y_pressed++)) { if(repeat_count_reached(y_pressed++)) {
if(timer_count >= 1) if(timer_count >= 1)
timer_count--; timer_count--;
} }
} }
else if(y_pressed >= 1 && !pico_display.is_pressed(pico_display.Y)) { else if(y_pressed >= 1 && !button_y.read()) {
y_pressed = 0; y_pressed = 0;
} }
Rect text_box(5, 5, screen_width-10, screen_height-10); Rect text_box(5, 5, screen_width-10, screen_height-10);
pico_display.set_pen(55, 65, 75); display.set_pen(BG);
pico_display.rectangle(text_box); display.rectangle(text_box);
// text_box.deflate(10); // text_box.deflate(10);
pico_display.set_clip(text_box); display.set_clip(text_box);
pico_display.set_pen(255, 255, 255); display.set_pen(WHITE);
switch(display_mode) { switch(display_mode) {
case MODE_DISP_CLOCK: case MODE_DISP_CLOCK:
// Show the clock face // Show the clock face
flash_led(0); flash_led(0);
if(rtc.update_time()) { if(rtc.update_time()) {
pico_display.text("Set Timer", display.text("Set Timer",
Point(text_box.x, text_box.y+2), 230, 1); Point(text_box.x, text_box.y+2), 230, 1);
pico_display.set_pen(0, 255, 0); display.set_pen(GREEN);
pico_display.text(rtc.string_date(), display.text(rtc.string_date(),
Point(text_box.x, text_box.y+20), 230, 4); Point(text_box.x, text_box.y+20), 230, 4);
pico_display.set_pen(255, 0, 0); display.set_pen(RED);
pico_display.text(rtc.string_time(), display.text(rtc.string_time(),
Point(text_box.x, text_box.y+60), 230, 6); Point(text_box.x, text_box.y+60), 230, 6);
pico_display.set_pen(255, 255, 255); display.set_pen(WHITE);
pico_display.text("Clock", display.text("Clock",
Point(text_box.x, text_box.y+screen_height-20), 230, 1); Point(text_box.x, text_box.y+screen_height-20), 230, 1);
} }
else { else {
sprintf(buf, "Time: rtc.updateTime() ret err"); sprintf(buf, "Time: rtc.updateTime() ret err");
pico_display.text(buf, display.text(buf,
Point(text_box.x, text_box.y), 30, 2); Point(text_box.x, text_box.y), 30, 2);
} }
break; break;
case MODE_DISP_TIMER: case MODE_DISP_TIMER:
pico_display.text("Set Timer", display.text("Set Timer",
Point(text_box.x, text_box.y+2), 230, 1); Point(text_box.x, text_box.y+2), 230, 1);
if(rtc.read_timer_interrupt_flag()) { if(rtc.read_timer_interrupt_flag()) {
// Go periodic time interupt - say loop ended // Go periodic time interupt - say loop ended
pico_display.set_pen(255, 0, 0); display.set_pen(RED);
sprintf(buf, "%s", "Timer complete"); sprintf(buf, "%s", "Timer complete");
pico_display.text(buf, display.text(buf,
Point(text_box.x, text_box.y+30), 230, 4); Point(text_box.x, text_box.y+30), 230, 4);
pico_display.set_pen(255, 255, 255); display.set_pen(WHITE);
flash_led(i); flash_led(i);
} }
else { else {
sprintf(buf, "%s %d", "Timer running", rtc.get_timer_count()); sprintf(buf, "%s %d", "Timer running", rtc.get_timer_count());
pico_display.text(buf, display.text(buf,
Point(text_box.x, text_box.y+30), 230, 3); Point(text_box.x, text_box.y+30), 230, 3);
} }
pico_display.text("Clock", display.text("Clock",
Point(text_box.x, text_box.y+screen_height-20), 230, 1); Point(text_box.x, text_box.y+screen_height-20), 230, 1);
break; break;
case MODE_SET_TIMER: case MODE_SET_TIMER:
flash_led(0); flash_led(0);
pico_display.text("Run Timer", display.text("Run Timer",
Point(text_box.x, text_box.y+2), 230, 1); Point(text_box.x, text_box.y+2), 230, 1);
pico_display.text("+ Time", display.text("+ Time",
Point(text_box.x+screen_width-42, text_box.y+2), 230, 1); Point(text_box.x+screen_width-42, text_box.y+2), 230, 1);
sprintf(buf, "Time %d secs", timer_count); sprintf(buf, "Time %d secs", timer_count);
pico_display.text(buf, display.text(buf,
Point(text_box.x, text_box.y+30), 230, 3); Point(text_box.x, text_box.y+30), 230, 3);
pico_display.text("Clock", display.text("Clock",
Point(text_box.x, text_box.y+screen_height-20), 230, 1); Point(text_box.x, text_box.y+screen_height-20), 230, 1);
pico_display.text("- Time", display.text("- Time",
Point(text_box.x+screen_width-42, Point(text_box.x+screen_width-42,
text_box.y+screen_height-20), 230, 1); text_box.y+screen_height-20), 230, 1);
break; break;
} }
pico_display.remove_clip(); display.remove_clip();
// update screen // update screen
pico_display.update(); display.update();
i++; i++;
} }

Wyświetl plik

@ -1,10 +1,10 @@
add_executable( add_executable(
tof_display tof_display
demo.cpp pico_tof_display.cpp
) )
# Pull in pico libraries that we need # Pull in pico libraries that we need
target_link_libraries(tof_display pico_stdlib pico_explorer pico_display vl53l1x) target_link_libraries(tof_display pico_stdlib pico_explorer pico_display vl53l1x picographics_st7789 button)
pico_enable_stdio_uart(tof_display 1) pico_enable_stdio_uart(tof_display 1)

Wyświetl plik

@ -24,62 +24,27 @@
#include "pico_display.hpp" #include "pico_display.hpp"
#endif #endif
#include "vl53l1x.hpp" #include "vl53l1x.hpp"
#include "drivers/button/button.hpp"
#include "picographics_st7789.hpp"
using namespace pimoroni; using namespace pimoroni;
class AutoRepeat {
public:
AutoRepeat(uint32_t repeat_time=200, uint32_t hold_time=1000) {
this->repeat_time = repeat_time;
this->hold_time = hold_time;
}
bool next(uint32_t time, bool state) {
bool changed = state != last_state;
last_state = state;
if(changed) {
if(state) {
pressed_time = time;
pressed = true;
last_time = time;
return true;
}
else {
pressed_time = 0;
pressed = false;
last_time = 0;
}
}
// Shortcut for no auto-repeat
if(repeat_time == 0) return false;
if(pressed) {
uint32_t repeat_rate = repeat_time;
if(hold_time > 0 && time - pressed_time > hold_time) {
repeat_rate /= 3;
}
if(time - last_time > repeat_rate) {
last_time = time;
return true;
}
}
return false;
}
private:
uint32_t repeat_time;
uint32_t hold_time;
bool pressed = false;
bool last_state = false;
uint32_t pressed_time = 0;
uint32_t last_time = 0;
};
#ifdef USE_PICO_EXPLORER #ifdef USE_PICO_EXPLORER
uint16_t buffer[PicoExplorer::WIDTH * PicoExplorer::HEIGHT]; PicoGraphicsST7789 pico_display(
PicoExplorer pico_display(buffer); PicoExplorer::WIDTH,
uint16_t screen_width = PicoExplorer::WIDTH; PicoExplorer::HEIGHT,
uint16_t screen_height = PicoExplorer::HEIGHT; ROTATE_0, // Rotation
false, // Is it round!?
nullptr, // Buffer
get_spi_pins(BG_SPI_FRONT)
);
Button button_a(PicoExplorer::A);
Button button_b(PicoExplorer::B);
Button button_x(PicoExplorer::X);
Button button_y(PicoExplorer::Y);
uint16_t disptext_reminder_size = 2; uint16_t disptext_reminder_size = 2;
uint16_t disptext_b_reminder_xoff = 5; uint16_t disptext_b_reminder_xoff = 5;
uint16_t disptext_b_reminder_yoff = 210; uint16_t disptext_b_reminder_yoff = 210;
@ -94,10 +59,20 @@ uint16_t disptext_dist_xoff = 10;
uint16_t disptext_dist_yoff = 90; uint16_t disptext_dist_yoff = 90;
uint16_t disptext_dist_size = 6; uint16_t disptext_dist_size = 6;
#else #else
uint16_t buffer[PicoDisplay::WIDTH * PicoDisplay::HEIGHT]; PicoGraphicsST7789 pico_display(
PicoDisplay pico_display(buffer); PicoDisplay::WIDTH,
uint16_t screen_width = PicoDisplay::WIDTH; PicoDisplay::HEIGHT,
uint16_t screen_height = PicoDisplay::HEIGHT; ROTATE_0, // Rotation
false, // Is it round!?
nullptr, // Buffer
get_spi_pins(BG_SPI_FRONT)
);
Button button_a(PicoDisplay::A);
Button button_b(PicoDisplay::B);
Button button_x(PicoDisplay::X);
Button button_y(PicoDisplay::Y);
uint16_t disptext_reminder_size = 2; uint16_t disptext_reminder_size = 2;
uint16_t disptext_b_reminder_xoff = 2; uint16_t disptext_b_reminder_xoff = 2;
uint16_t disptext_b_reminder_yoff = 110; uint16_t disptext_b_reminder_yoff = 110;
@ -113,6 +88,10 @@ uint16_t disptext_dist_yoff = 45;
uint16_t disptext_dist_size = 4; uint16_t disptext_dist_size = 4;
#endif #endif
uint16_t screen_width = pico_display.bounds.w;
uint16_t screen_height = pico_display.bounds.h;
#define MM_TO_INCH 25.4 #define MM_TO_INCH 25.4
VL53L1X vl53l1x; VL53L1X vl53l1x;
@ -124,11 +103,6 @@ const char mode_to_text[4][7] = {
"Long" "Long"
}; };
AutoRepeat ar_button_a;
AutoRepeat ar_button_b;
AutoRepeat ar_button_x;
AutoRepeat ar_button_y;
#define FLASH_MOD 20 #define FLASH_MOD 20
void flash_led(uint32_t curr_count) { void flash_led(uint32_t curr_count) {
// Flash the LED based on the current loop counter // Flash the LED based on the current loop counter
@ -148,8 +122,6 @@ int main() {
bool vl53_present = false; bool vl53_present = false;
uint16_t vl53_mode = 1; uint16_t vl53_mode = 1;
pico_display.init();
vl53_present = vl53l1x.init(); vl53_present = vl53l1x.init();
uint32_t i = 0; uint32_t i = 0;
@ -169,11 +141,15 @@ int main() {
// Whether the display is being held // Whether the display is being held
bool dist_held = false; 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);
while(true) { while(true) {
// bool a_pressed = ar_button_a.next(i, pico_display.is_pressed(pico_display.A)); // bool a_pressed = button_a.read();
bool b_pressed = ar_button_b.next(i, pico_display.is_pressed(pico_display.B)); bool b_pressed = button_b.read();
bool x_pressed = ar_button_x.next(i, pico_display.is_pressed(pico_display.X)); bool x_pressed = button_x.read();
bool y_pressed = ar_button_y.next(i, pico_display.is_pressed(pico_display.Y)); bool y_pressed = button_y.read();
if (b_pressed) { if (b_pressed) {
dist_held = !dist_held; dist_held = !dist_held;
@ -192,11 +168,11 @@ int main() {
} }
Rect text_box(5, 5, screen_width-10, screen_height-10); Rect text_box(5, 5, screen_width-10, screen_height-10);
pico_display.set_pen(55, 65, 75); pico_display.set_pen(BG);
pico_display.rectangle(text_box); pico_display.rectangle(text_box);
// text_box.deflate(10); // text_box.deflate(10);
pico_display.set_clip(text_box); pico_display.set_clip(text_box);
pico_display.set_pen(255, 255, 255); pico_display.set_pen(WHITE);
// Show the current distance // Show the current distance
flash_led(0); flash_led(0);
if (vl53_present) { if (vl53_present) {
@ -207,12 +183,12 @@ int main() {
Point(text_box.x+disptext_y_reminder_xoff, Point(text_box.x+disptext_y_reminder_xoff,
text_box.y+disptext_y_reminder_yoff), 230, disptext_reminder_size); text_box.y+disptext_y_reminder_yoff), 230, disptext_reminder_size);
if(dist_held) { if(dist_held) {
pico_display.set_pen(255, 64, 64); pico_display.set_pen(REDDISH);
} }
pico_display.text("Hold", pico_display.text("Hold",
Point(text_box.x+disptext_b_reminder_xoff, Point(text_box.x+disptext_b_reminder_xoff,
text_box.y+disptext_b_reminder_yoff), 230, disptext_reminder_size); text_box.y+disptext_b_reminder_yoff), 230, disptext_reminder_size);
pico_display.set_pen(255, 255, 255); pico_display.set_pen(WHITE);
sprintf(buf, "Mode: %s", mode_to_text[vl53_mode]); sprintf(buf, "Mode: %s", mode_to_text[vl53_mode]);
pico_display.text(buf, pico_display.text(buf,

Wyświetl plik

@ -2,11 +2,11 @@ set(OUTPUT_NAME trackball_display)
add_executable( add_executable(
${OUTPUT_NAME} ${OUTPUT_NAME}
demo.cpp pico_trackball_display.cpp
) )
# Pull in pico libraries that we need # Pull in pico libraries that we need
target_link_libraries(${OUTPUT_NAME} pico_stdlib pico_explorer pico_display breakout_trackball) target_link_libraries(${OUTPUT_NAME} pico_stdlib pico_explorer pico_display breakout_trackball picographics_st7789)
pico_enable_stdio_uart(${OUTPUT_NAME} 1) pico_enable_stdio_uart(${OUTPUT_NAME} 1)

Wyświetl plik

@ -16,15 +16,17 @@
// To use PicoExplorer rather than PicoDisplay, uncomment the following line // To use PicoExplorer rather than PicoDisplay, uncomment the following line
#define USE_PICO_EXPLORER 1 #define USE_PICO_EXPLORER 1
// This: // This:
// - Includes pico_explorer.hpp rather than pico_display.hpp // - Includes pico_explorer.hpp rather than display.hpp
// - Replaces all PicoDisplay references with PicoExplorer // - Replaces all PicoDisplay references with PicoExplorer
#ifdef USE_PICO_EXPLORER #ifdef USE_PICO_EXPLORER
#include "pico_explorer.hpp" #include "pico_explorer.hpp"
#else #else
#include "pico_display.hpp" #include "display.hpp"
#endif #endif
#include "breakout_trackball.hpp" #include "breakout_trackball.hpp"
#include "picographics_st7789.hpp"
using namespace pimoroni; using namespace pimoroni;
struct TrackballColour { struct TrackballColour {
@ -35,16 +37,15 @@ struct TrackballColour {
}; };
#ifdef USE_PICO_EXPLORER #ifdef USE_PICO_EXPLORER
uint16_t buffer[PicoExplorer::WIDTH * PicoExplorer::HEIGHT];
PicoExplorer pico_display(buffer);
const uint16_t screen_width = PicoExplorer::WIDTH; const uint16_t screen_width = PicoExplorer::WIDTH;
const uint16_t screen_height = PicoExplorer::HEIGHT; const uint16_t screen_height = PicoExplorer::HEIGHT;
#else #else
uint16_t buffer[PicoDisplay::WIDTH * PicoDisplay::HEIGHT];
PicoDisplay pico_display(buffer);
const uint16_t screen_width = PicoDisplay::WIDTH; const uint16_t screen_width = PicoDisplay::WIDTH;
const uint16_t screen_height = PicoDisplay::HEIGHT; const uint16_t screen_height = PicoDisplay::HEIGHT;
#endif #endif
PicoGraphicsST7789 display(screen_width, screen_height, ROTATE_0, false, nullptr, get_spi_pins(BG_SPI_FRONT));
const Point screen_centre(screen_width / 2, screen_height / 2); const Point screen_centre(screen_width / 2, screen_height / 2);
const uint16_t circle_radius = std::min(screen_centre.x, screen_centre.y) / 4; const uint16_t circle_radius = std::min(screen_centre.x, screen_centre.y) / 4;
const float ring_radius_mult = 0.7f; const float ring_radius_mult = 0.7f;
@ -71,7 +72,6 @@ bool centre_circle_state = false;
int main() { int main() {
int16_t x = screen_centre.x; int16_t x = screen_centre.x;
int16_t y = screen_centre.y; int16_t y = screen_centre.y;
pico_display.init();
trackball.init(); trackball.init();
@ -84,52 +84,57 @@ int main() {
positions[i] = pos; 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);
while(true) { while(true) {
Trackball::State state = trackball.read(); Trackball::State state = trackball.read();
x = std::min(std::max(x - state.left + state.right, 0), (int)screen_width); x = std::min(std::max(x - state.left + state.right, 0), (int)screen_width);
y = std::min(std::max(y - state.up + state.down, 0), (int)screen_height); y = std::min(std::max(y - state.up + state.down, 0), (int)screen_height);
Point cursor_pos(x, y); Point cursor_pos(x, y);
pico_display.set_pen(0, 0, 0); display.set_pen(BLACK);
pico_display.clear(); display.clear();
//Draw a set of circles in a ring around the screen centre //Draw a set of circles in a ring around the screen centre
for(uint8_t i = 0; i < NUM_CIRCLES; i++) { for(uint8_t i = 0; i < NUM_CIRCLES; i++) {
TrackballColour col = colour_circles[i]; TrackballColour col = colour_circles[i];
if(circle_states[i]) { if(circle_states[i]) {
pico_display.set_pen(col.r, col.g, col.b); display.set_pen(display.create_pen(col.r, col.g, col.b));
pico_display.circle(positions[i], circle_radius + circle_border); display.circle(positions[i], circle_radius + circle_border);
pico_display.set_pen(col.r >> 1, col.g >> 1, col.b >> 1); display.set_pen(display.create_pen(col.r >> 1, col.g >> 1, col.b >> 1));
pico_display.circle(positions[i], circle_radius); display.circle(positions[i], circle_radius);
} }
else { else {
pico_display.set_pen(col.r >> 1, col.g >> 1, col.b >> 1); display.set_pen(display.create_pen(col.r >> 1, col.g >> 1, col.b >> 1));
pico_display.circle(positions[i], circle_radius + circle_border); display.circle(positions[i], circle_radius + circle_border);
pico_display.set_pen(col.r, col.g, col.b); display.set_pen(display.create_pen(col.r, col.g, col.b));
pico_display.circle(positions[i], circle_radius); display.circle(positions[i], circle_radius);
} }
} }
//Draw a centre circle //Draw a centre circle
if(centre_circle_state) { if(centre_circle_state) {
pico_display.set_pen(255, 255, 255); display.set_pen(WHITE);
pico_display.circle(screen_centre, circle_radius + circle_border); display.circle(screen_centre, circle_radius + circle_border);
pico_display.set_pen(128, 128, 128); display.set_pen(MID_GREY);
pico_display.circle(screen_centre, circle_radius); display.circle(screen_centre, circle_radius);
} }
else { else {
pico_display.set_pen(128, 128, 128); display.set_pen(MID_GREY);
pico_display.circle(screen_centre, circle_radius + circle_border); display.circle(screen_centre, circle_radius + circle_border);
pico_display.set_pen(255, 255, 255); display.set_pen(WHITE);
pico_display.circle(screen_centre, circle_radius); display.circle(screen_centre, circle_radius);
} }
//Draw the cursor //Draw the cursor
pico_display.set_pen(0, 0, 0); display.set_pen(BLACK);
pico_display.circle(cursor_pos, cursor_radius + cursor_border); display.circle(cursor_pos, cursor_radius + cursor_border);
pico_display.set_pen(212, 212, 212); display.set_pen(LIGHT_GREY);
pico_display.circle(cursor_pos, cursor_radius); display.circle(cursor_pos, cursor_radius);
int16_t x_diff = cursor_pos.x - screen_centre.x; int16_t x_diff = cursor_pos.x - screen_centre.x;
int16_t y_diff = cursor_pos.y - screen_centre.y; int16_t y_diff = cursor_pos.y - screen_centre.y;
@ -161,7 +166,7 @@ int main() {
} }
// update screen // update screen
pico_display.update(); display.update();
} }
return 0; return 0;

Wyświetl plik

@ -4,7 +4,7 @@ add_executable(${OUTPUT_NAME} tufty2040_drawing.cpp)
target_link_libraries(${OUTPUT_NAME} target_link_libraries(${OUTPUT_NAME}
tufty2040 tufty2040
hardware_spi hardware_spi
generic_st7789 picographics_st7789
button button
) )

Wyświetl plik

@ -7,7 +7,7 @@
#include "pico/platform.h" #include "pico/platform.h"
#include "common/pimoroni_common.hpp" #include "common/pimoroni_common.hpp"
#include "generic_st7789.hpp" #include "picographics_st7789.hpp"
#include "tufty2040.hpp" #include "tufty2040.hpp"
#include "button.hpp" #include "button.hpp"
@ -15,8 +15,7 @@ using namespace pimoroni;
Tufty2040 tufty; Tufty2040 tufty;
// Swap WIDTH and HEIGHT to rotate 90 degrees PicoGraphicsST7789 display(
ST7789Generic pico_display(
Tufty2040::WIDTH, Tufty2040::HEIGHT, ROTATE_0, nullptr, Tufty2040::WIDTH, Tufty2040::HEIGHT, ROTATE_0, nullptr,
ParallelPins{ ParallelPins{
Tufty2040::LCD_CS, Tufty2040::LCD_CS,
@ -60,8 +59,10 @@ void from_hsv(float h, float s, float v, uint8_t &r, uint8_t &g, uint8_t &b) {
} }
int main() { int main() {
pico_display.set_backlight(255); display.set_backlight(255);
pico_display.configure_display(true); // Rotate 180
Pen WHITE = display.create_pen(255, 255, 255);
Pen BG = display.create_pen(120, 40, 60);
struct pt { struct pt {
float x; float x;
@ -75,12 +76,12 @@ int main() {
std::vector<pt> shapes; std::vector<pt> shapes;
for(int i = 0; i < 100; i++) { for(int i = 0; i < 100; i++) {
pt shape; pt shape;
shape.x = rand() % pico_display.bounds.w; shape.x = rand() % display.bounds.w;
shape.y = rand() % pico_display.bounds.h; shape.y = rand() % display.bounds.h;
shape.r = (rand() % 10) + 3; shape.r = (rand() % 10) + 3;
shape.dx = float(rand() % 255) / 64.0f; shape.dx = float(rand() % 255) / 64.0f;
shape.dy = float(rand() % 255) / 64.0f; shape.dy = float(rand() % 255) / 64.0f;
shape.pen = pico_display.create_pen(rand() % 255, rand() % 255, rand() % 255); shape.pen = display.create_pen(rand() % 255, rand() % 255, rand() % 255);
shapes.push_back(shape); shapes.push_back(shape);
} }
@ -89,8 +90,8 @@ int main() {
while(true) { while(true) {
pico_display.set_pen(120, 40, 60); display.set_pen(BG);
pico_display.clear(); display.clear();
for(auto &shape : shapes) { for(auto &shape : shapes) {
shape.x += shape.dx; shape.x += shape.dx;
@ -99,30 +100,30 @@ int main() {
shape.dx *= -1; shape.dx *= -1;
shape.x = shape.r; shape.x = shape.r;
} }
if((shape.x + shape.r) >= pico_display.bounds.w) { if((shape.x + shape.r) >= display.bounds.w) {
shape.dx *= -1; shape.dx *= -1;
shape.x = pico_display.bounds.w - shape.r; shape.x = display.bounds.w - shape.r;
} }
if((shape.y - shape.r) < 0) { if((shape.y - shape.r) < 0) {
shape.dy *= -1; shape.dy *= -1;
shape.y = shape.r; shape.y = shape.r;
} }
if((shape.y + shape.r) >= pico_display.bounds.h) { if((shape.y + shape.r) >= display.bounds.h) {
shape.dy *= -1; shape.dy *= -1;
shape.y = pico_display.bounds.h - shape.r; shape.y = display.bounds.h - shape.r;
} }
pico_display.set_pen(shape.pen); display.set_pen(shape.pen);
pico_display.circle(Point(shape.x, shape.y), shape.r); display.circle(Point(shape.x, shape.y), shape.r);
} }
pico_display.set_pen(255, 255, 255); display.set_pen(WHITE);
pico_display.text("Hello World", text_location, 320); display.text("Hello World", text_location, 320);
// update screen // update screen
pico_display.update(); display.update();
i+=10; i+=10;
tufty.led(i); tufty.led(i);

Wyświetl plik

@ -17,7 +17,7 @@ add_subdirectory(breakout_sgp30)
add_subdirectory(breakout_as7262) add_subdirectory(breakout_as7262)
add_subdirectory(breakout_msa301) add_subdirectory(breakout_msa301)
add_subdirectory(breakout_bh1745) add_subdirectory(breakout_bh1745)
add_subdirectory(generic_st7789) add_subdirectory(picographics_st7789)
add_subdirectory(pico_graphics) add_subdirectory(pico_graphics)
add_subdirectory(pico_display) add_subdirectory(pico_display)
add_subdirectory(pico_display_2) add_subdirectory(pico_display_2)

Wyświetl plik

@ -1 +0,0 @@
include(generic_st7789.cmake)

Wyświetl plik

@ -1,6 +1,3 @@
include(${CMAKE_CURRENT_LIST_DIR}/../../drivers/st7789/st7789.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/../pico_graphics/pico_graphics.cmake)
add_library(pico_display INTERFACE) add_library(pico_display INTERFACE)
target_sources(pico_display INTERFACE target_sources(pico_display INTERFACE
@ -10,4 +7,4 @@ target_sources(pico_display INTERFACE
target_include_directories(pico_display INTERFACE ${CMAKE_CURRENT_LIST_DIR}) target_include_directories(pico_display INTERFACE ${CMAKE_CURRENT_LIST_DIR})
# Pull in pico libraries that we need # Pull in pico libraries that we need
target_link_libraries(pico_display INTERFACE pico_stdlib hardware_spi hardware_pwm hardware_dma st7789 pico_graphics) target_link_libraries(pico_display INTERFACE pico_stdlib)

Wyświetl plik

@ -1,85 +1 @@
#include <math.h> #include "pico_display.hpp"
#include <string.h>
#include "hardware/gpio.h" // Workaround SDK bug - https://github.com/raspberrypi/pico-sdk/issues/3
#include "hardware/pwm.h"
#include "pico_display.hpp"
namespace pimoroni {
PicoDisplay::PicoDisplay(void *buf)
: PicoGraphics(WIDTH, HEIGHT, buf),
screen(WIDTH, HEIGHT, ROTATE_0, false, buf, get_spi_pins(BG_SPI_FRONT)) {
__fb = buf;
}
PicoDisplay::PicoDisplay(void *buf, int width, int height)
: PicoGraphics(width, height, buf),
screen(width, height, ROTATE_0, false, buf, get_spi_pins(BG_SPI_FRONT)) {
__fb = buf;
}
void PicoDisplay::init() {
// setup the rgb led for pwm control
pwm_config cfg = pwm_get_default_config();
pwm_config_set_output_polarity(&cfg, true, true);
// red
pwm_set_wrap(pwm_gpio_to_slice_num(LED_R), 65535);
pwm_init(pwm_gpio_to_slice_num(LED_R), &cfg, true);
gpio_set_function(LED_R, GPIO_FUNC_PWM);
// green
pwm_set_wrap(pwm_gpio_to_slice_num(LED_G), 65535);
pwm_init(pwm_gpio_to_slice_num(LED_G), &cfg, true);
gpio_set_function(LED_G, GPIO_FUNC_PWM);
// blue
pwm_set_wrap(pwm_gpio_to_slice_num(LED_B), 65535);
pwm_init(pwm_gpio_to_slice_num(LED_B), &cfg, true);
gpio_set_function(LED_B, GPIO_FUNC_PWM);
// 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);
}
void PicoDisplay::update() {
screen.update();
}
void PicoDisplay::set_backlight(uint8_t brightness) {
screen.set_backlight(brightness);
}
void PicoDisplay::set_led(uint8_t r, uint8_t g, uint8_t b) {
// gamma correct the provided 0-255 brightness value onto a
// 0-65535 range for the pwm counter
static const float gamma = 2.8;
uint16_t value;
// red
value = (uint16_t)(pow((float)(r) / 255.0f, gamma) * 65535.0f + 0.5f);
pwm_set_gpio_level(LED_R, value);
// green
value = (uint16_t)(pow((float)(g) / 255.0f, gamma) * 65535.0f + 0.5f);
pwm_set_gpio_level(LED_G, value);
// blue
value = (uint16_t)(pow((float)(b) / 255.0f, gamma) * 65535.0f + 0.5f);
pwm_set_gpio_level(LED_B, value);
}
bool PicoDisplay::is_pressed(uint8_t button) {
return !gpio_get(button);
}
void PicoDisplay::flip() {
screen.flip();
}
}

Wyświetl plik

@ -1,16 +1,12 @@
#pragma once #pragma once
#include "drivers/st7789/st7789.hpp" #include "pico/stdlib.h"
#include "libraries/pico_graphics/pico_graphics.hpp"
namespace pimoroni { namespace pimoroni {
class PicoDisplay {
class PicoDisplay : public PicoGraphics {
public: public:
static const int WIDTH = 240; static const int WIDTH = 240;
static const int HEIGHT = 135; static const int HEIGHT = 135;
static const int PORTRAIT_WIDTH = 135;
static const int PORTRAIT_HEIGHT = 240;
static const uint8_t A = 12; static const uint8_t A = 12;
static const uint8_t B = 13; static const uint8_t B = 13;
static const uint8_t X = 14; static const uint8_t X = 14;
@ -18,21 +14,5 @@ namespace pimoroni {
static const uint8_t LED_R = 6; static const uint8_t LED_R = 6;
static const uint8_t LED_G = 7; static const uint8_t LED_G = 7;
static const uint8_t LED_B = 8; static const uint8_t LED_B = 8;
void *__fb;
private:
ST7789 screen;
public:
PicoDisplay(void *buf);
PicoDisplay(void *buf, int width, int height);
void init();
void update();
void set_backlight(uint8_t brightness);
void set_led(uint8_t r, uint8_t g, uint8_t b);
bool is_pressed(uint8_t button);
void flip();
}; };
} }

Wyświetl plik

@ -1,14 +1,10 @@
include(${CMAKE_CURRENT_LIST_DIR}/../../drivers/st7789/st7789.cmake) add_library(pico_display_2 INTERFACE)
include(${CMAKE_CURRENT_LIST_DIR}/../pico_graphics/pico_graphics.cmake)
set(LIB_NAME pico_display_2) target_sources(pico_display_2 INTERFACE
add_library(${LIB_NAME} INTERFACE) ${CMAKE_CURRENT_LIST_DIR}/pico_display_2.cpp
target_sources(${LIB_NAME} INTERFACE
${CMAKE_CURRENT_LIST_DIR}/${LIB_NAME}.cpp
) )
target_include_directories(${LIB_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR}) target_include_directories(pico_display_2 INTERFACE ${CMAKE_CURRENT_LIST_DIR})
# Pull in pico libraries that we need # Pull in pico libraries that we need
target_link_libraries(${LIB_NAME} INTERFACE pico_stdlib hardware_spi hardware_pwm hardware_dma st7789 pico_graphics) target_link_libraries(pico_display_2 INTERFACE pico_stdlib)

Wyświetl plik

@ -1,85 +1 @@
#include <math.h> #include "pico_display_2.hpp"
#include <string.h>
#include "hardware/gpio.h" // Workaround SDK bug - https://github.com/raspberrypi/pico-sdk/issues/3
#include "hardware/pwm.h"
#include "pico_display_2.hpp"
namespace pimoroni {
PicoDisplay2::PicoDisplay2(void *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;
}
PicoDisplay2::PicoDisplay2(void *buf, int width, int height)
: 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;
}
void PicoDisplay2::init() {
// setup the rgb led for pwm control
pwm_config cfg = pwm_get_default_config();
pwm_config_set_output_polarity(&cfg, true, true);
// red
pwm_set_wrap(pwm_gpio_to_slice_num(LED_R), 65535);
pwm_init(pwm_gpio_to_slice_num(LED_R), &cfg, true);
gpio_set_function(LED_R, GPIO_FUNC_PWM);
// green
pwm_set_wrap(pwm_gpio_to_slice_num(LED_G), 65535);
pwm_init(pwm_gpio_to_slice_num(LED_G), &cfg, true);
gpio_set_function(LED_G, GPIO_FUNC_PWM);
// blue
pwm_set_wrap(pwm_gpio_to_slice_num(LED_B), 65535);
pwm_init(pwm_gpio_to_slice_num(LED_B), &cfg, true);
gpio_set_function(LED_B, GPIO_FUNC_PWM);
// 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);
}
void PicoDisplay2::update() {
screen.update();
}
void PicoDisplay2::set_backlight(uint8_t brightness) {
screen.set_backlight(brightness);
}
void PicoDisplay2::set_led(uint8_t r, uint8_t g, uint8_t b) {
// gamma correct the provided 0-255 brightness value onto a
// 0-65535 range for the pwm counter
static const float gamma = 2.8;
uint16_t value;
// red
value = (uint16_t)(pow((float)(r) / 255.0f, gamma) * 65535.0f + 0.5f);
pwm_set_gpio_level(LED_R, value);
// green
value = (uint16_t)(pow((float)(g) / 255.0f, gamma) * 65535.0f + 0.5f);
pwm_set_gpio_level(LED_G, value);
// blue
value = (uint16_t)(pow((float)(b) / 255.0f, gamma) * 65535.0f + 0.5f);
pwm_set_gpio_level(LED_B, value);
}
bool PicoDisplay2::is_pressed(uint8_t button) {
return !gpio_get(button);
}
void PicoDisplay2::flip() {
screen.flip();
}
}

Wyświetl plik

@ -1,16 +1,12 @@
#pragma once #pragma once
#include "drivers/st7789/st7789.hpp" #include "pico/stdlib.h"
#include "libraries/pico_graphics/pico_graphics.hpp"
namespace pimoroni { namespace pimoroni {
class PicoDisplay2 {
class PicoDisplay2 : public PicoGraphics {
public: public:
static const int WIDTH = 320; static const int WIDTH = 320;
static const int HEIGHT = 240; static const int HEIGHT = 240;
static const int PORTRAIT_WIDTH = 240;
static const int PORTRAIT_HEIGHT = 320;
static const uint8_t A = 12; static const uint8_t A = 12;
static const uint8_t B = 13; static const uint8_t B = 13;
static const uint8_t X = 14; static const uint8_t X = 14;
@ -18,21 +14,5 @@ namespace pimoroni {
static const uint8_t LED_R = 6; static const uint8_t LED_R = 6;
static const uint8_t LED_G = 7; static const uint8_t LED_G = 7;
static const uint8_t LED_B = 8; static const uint8_t LED_B = 8;
void *__fb;
private:
ST7789 screen;
public:
PicoDisplay2(void *buf);
PicoDisplay2(void *buf, int width, int height);
void init();
void update();
void set_backlight(uint8_t brightness);
void set_led(uint8_t r, uint8_t g, uint8_t b);
bool is_pressed(uint8_t button);
void flip();
}; };
} }

Wyświetl plik

@ -2,6 +2,7 @@
#include "drivers/st7789/st7789.hpp" #include "drivers/st7789/st7789.hpp"
#include "libraries/pico_graphics/pico_graphics.hpp" #include "libraries/pico_graphics/pico_graphics.hpp"
#include "drivers/motor/motor.hpp"
namespace pimoroni { namespace pimoroni {
@ -18,6 +19,13 @@ namespace pimoroni {
static const uint8_t ADC1 = 1; static const uint8_t ADC1 = 1;
static const uint8_t ADC2 = 2; static const uint8_t ADC2 = 2;
static const uint ADC0_PIN = 26;
static const uint ADC1_PIN = 27;
static const uint ADC2_PIN = 28;
static constexpr pin_pair MOTOR1_PINS{9, 8};
static constexpr pin_pair MOTOR2_PINS{11, 10};
static const uint8_t MOTOR1 = 0; static const uint8_t MOTOR1 = 0;
static const uint8_t MOTOR2 = 1; static const uint8_t MOTOR2 = 1;

Wyświetl plik

@ -0,0 +1 @@
include(picographics_st7789.cmake)

Wyświetl plik

@ -1,4 +1,4 @@
# Genereic ST7789 - Pico Display Pack & Pico Display Pack 2.0" and 240x240 Square & Round LCD Breakouts <!-- omit in toc --> # Pico Graphics ST7789 - Pico Display Pack & Pico Display Pack 2.0" and 240x240 Square & Round LCD Breakouts <!-- omit in toc -->
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! 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!
@ -16,14 +16,14 @@ The following example sets up Pico Display, displays some basic demo text and gr
```c++ ```c++
#include "pico_display.hpp" #include "pico_display.hpp"
#include "generic_st7789.hpp" #include "picographics_st7789.hpp"
#include "rgbled.hpp" #include "rgbled.hpp"
#include "button.hpp" #include "button.hpp"
using namespace pimoroni; using namespace pimoroni;
// Swap WIDTH and HEIGHT to rotate 90 degrees // Swap WIDTH and HEIGHT to rotate 90 degrees
ST7789Generic pico_display(PicoDisplay::WIDTH, PicoDisplay::HEIGHT, ROTATE_0); PicoGraphicsST7789 pico_display(PicoDisplay::WIDTH, PicoDisplay::HEIGHT, ROTATE_0);
// RGB LED controller // RGB LED controller
RGBLED led(PicoDisplay::LED_R, PicoDisplay::LED_G, PicoDisplay::LED_B); RGBLED led(PicoDisplay::LED_R, PicoDisplay::LED_G, PicoDisplay::LED_B);
@ -83,7 +83,7 @@ int main() {
### PicoGraphics ### PicoGraphics
The generic 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). 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. You will also need to use the RGBLED library to drive the RGB LED, and the Button library for the four buttons.

Wyświetl plik

@ -1,4 +1,4 @@
set(LIB_NAME generic_st7789) set(LIB_NAME picographics_st7789)
add_library(${LIB_NAME} INTERFACE) add_library(${LIB_NAME} INTERFACE)
target_sources(${LIB_NAME} INTERFACE target_sources(${LIB_NAME} INTERFACE

Wyświetl plik

@ -1,15 +1,15 @@
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
#include "generic_st7789.hpp" #include "picographics_st7789.hpp"
namespace pimoroni { namespace pimoroni {
void ST7789Generic::update() { void PicoGraphicsST7789::update() {
st7789.update(palette); st7789.update(palette);
} }
void ST7789Generic::set_backlight(uint8_t brightness) { void PicoGraphicsST7789::set_backlight(uint8_t brightness) {
st7789.set_backlight(brightness); st7789.set_backlight(brightness);
} }
} }

Wyświetl plik

@ -6,24 +6,24 @@
namespace pimoroni { namespace pimoroni {
class ST7789Generic : public PicoGraphics { class PicoGraphicsST7789 : public PicoGraphics {
private: private:
ST7789 st7789; ST7789 st7789;
public: public:
ST7789Generic(uint16_t width, uint16_t height, Rotation rotation, bool round=false, void *frame_buffer=nullptr) : PicoGraphicsST7789(uint16_t width, uint16_t height, Rotation rotation, bool round=false, void *frame_buffer=nullptr) :
PicoGraphics(width, height, frame_buffer), PicoGraphics(width, height, frame_buffer),
st7789(width, height, rotation, round, frame_buffer, get_spi_pins(BG_SPI_FRONT)) { st7789(width, height, rotation, round, frame_buffer, get_spi_pins(BG_SPI_FRONT)) {
common_init(); common_init();
}; };
ST7789Generic(uint16_t width, uint16_t height, Rotation rotation, bool round, void *frame_buffer, SPIPins bus_pins) : PicoGraphicsST7789(uint16_t width, uint16_t height, Rotation rotation, bool round, void *frame_buffer, SPIPins bus_pins) :
PicoGraphics(width, height, frame_buffer), PicoGraphics(width, height, frame_buffer),
st7789(width, height, rotation, round, frame_buffer, bus_pins) { st7789(width, height, rotation, round, frame_buffer, bus_pins) {
common_init(); common_init();
}; };
ST7789Generic(uint16_t width, uint16_t height, Rotation rotation, void *frame_buffer, ParallelPins bus_pins) : PicoGraphicsST7789(uint16_t width, uint16_t height, Rotation rotation, void *frame_buffer, ParallelPins bus_pins) :
PicoGraphics(width, height, frame_buffer), PicoGraphics(width, height, frame_buffer),
st7789(width, height, rotation, frame_buffer, bus_pins) { st7789(width, height, rotation, frame_buffer, bus_pins) {
common_init(); common_init();

Wyświetl plik

@ -5,7 +5,7 @@ add_library(usermod_${MOD_NAME} INTERFACE)
target_sources(usermod_${MOD_NAME} INTERFACE target_sources(usermod_${MOD_NAME} INTERFACE
${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.c ${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.c
${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.cpp ${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.cpp
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/generic_st7789/generic_st7789.cpp ${CMAKE_CURRENT_LIST_DIR}/../../../libraries/picographics_st7789/picographics_st7789.cpp
${CMAKE_CURRENT_LIST_DIR}/../../../drivers/st7789/st7789.cpp ${CMAKE_CURRENT_LIST_DIR}/../../../drivers/st7789/st7789.cpp
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/pico_graphics/pico_graphics.cpp ${CMAKE_CURRENT_LIST_DIR}/../../../libraries/pico_graphics/pico_graphics.cpp
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/pico_graphics/types.cpp ${CMAKE_CURRENT_LIST_DIR}/../../../libraries/pico_graphics/types.cpp

Wyświetl plik

@ -1,4 +1,4 @@
#include "libraries/generic_st7789/generic_st7789.hpp" #include "libraries/picographics_st7789/picographics_st7789.hpp"
#include "common/pimoroni_common.hpp" #include "common/pimoroni_common.hpp"
#include "common/pimoroni_bus.hpp" #include "common/pimoroni_bus.hpp"
@ -24,7 +24,7 @@ enum ST7789Display {
typedef struct _GenericST7789_obj_t { typedef struct _GenericST7789_obj_t {
mp_obj_base_t base; mp_obj_base_t base;
ST7789Generic *st7789; PicoGraphicsST7789 *st7789;
void *buffer; void *buffer;
} GenericST7789_obj_t; } GenericST7789_obj_t;
@ -89,19 +89,19 @@ mp_obj_t GenericST7789_make_new(const mp_obj_type_t *type, size_t n_args, size_t
if (display == DISPLAY_TUFTY_2040) { if (display == DISPLAY_TUFTY_2040) {
if (args[ARG_bus].u_obj == mp_const_none) { if (args[ARG_bus].u_obj == mp_const_none) {
self->st7789 = m_new_class(ST7789Generic, width, height, rotate, self->buffer, {10, 11, 12, 13, 14, 2}); self->st7789 = m_new_class(PicoGraphicsST7789, width, height, rotate, self->buffer, {10, 11, 12, 13, 14, 2});
} else if (mp_obj_is_type(args[ARG_bus].u_obj, &ParallelPins_type)) { } else if (mp_obj_is_type(args[ARG_bus].u_obj, &ParallelPins_type)) {
_PimoroniBus_obj_t *bus = (_PimoroniBus_obj_t *)MP_OBJ_TO_PTR(args[ARG_bus].u_obj); _PimoroniBus_obj_t *bus = (_PimoroniBus_obj_t *)MP_OBJ_TO_PTR(args[ARG_bus].u_obj);
self->st7789 = m_new_class(ST7789Generic, width, height, rotate, self->buffer, *(ParallelPins *)(bus->pins)); self->st7789 = m_new_class(PicoGraphicsST7789, width, height, rotate, self->buffer, *(ParallelPins *)(bus->pins));
} else { } else {
mp_raise_ValueError("ParallelBus expected!"); mp_raise_ValueError("ParallelBus expected!");
} }
} else { } else {
if (args[ARG_bus].u_obj == mp_const_none) { if (args[ARG_bus].u_obj == mp_const_none) {
self->st7789 = m_new_class(ST7789Generic, width, height, rotate, round, self->buffer, get_spi_pins(BG_SPI_FRONT)); self->st7789 = m_new_class(PicoGraphicsST7789, width, height, rotate, round, self->buffer, get_spi_pins(BG_SPI_FRONT));
} else if (mp_obj_is_type(args[ARG_bus].u_obj, &SPIPins_type)) { } else if (mp_obj_is_type(args[ARG_bus].u_obj, &SPIPins_type)) {
_PimoroniBus_obj_t *bus = (_PimoroniBus_obj_t *)MP_OBJ_TO_PTR(args[ARG_bus].u_obj); _PimoroniBus_obj_t *bus = (_PimoroniBus_obj_t *)MP_OBJ_TO_PTR(args[ARG_bus].u_obj);
self->st7789 = m_new_class(ST7789Generic, width, height, rotate, round, self->buffer, *(SPIPins *)(bus->pins)); self->st7789 = m_new_class(PicoGraphicsST7789, width, height, rotate, round, self->buffer, *(SPIPins *)(bus->pins));
} else { } else {
mp_raise_ValueError("SPIBus expected!"); mp_raise_ValueError("SPIBus expected!");
} }
@ -157,7 +157,7 @@ mp_obj_t GenericST7789_set_backlight(mp_obj_t self_in, mp_obj_t brightness) {
} }
mp_obj_t GenericST7789_module_RGB332(mp_obj_t r, mp_obj_t g, mp_obj_t b) { mp_obj_t GenericST7789_module_RGB332(mp_obj_t r, mp_obj_t g, mp_obj_t b) {
return mp_obj_new_int(ST7789Generic::create_pen_rgb332( return mp_obj_new_int(PicoGraphicsST7789::create_pen_rgb332(
mp_obj_get_int(r), mp_obj_get_int(r),
mp_obj_get_int(g), mp_obj_get_int(g),
mp_obj_get_int(b) mp_obj_get_int(b)
@ -165,7 +165,7 @@ mp_obj_t GenericST7789_module_RGB332(mp_obj_t r, mp_obj_t g, mp_obj_t b) {
} }
mp_obj_t GenericST7789_module_RGB565(mp_obj_t r, mp_obj_t g, mp_obj_t b) { mp_obj_t GenericST7789_module_RGB565(mp_obj_t r, mp_obj_t g, mp_obj_t b) {
return mp_obj_new_int(ST7789Generic::create_pen_rgb565( return mp_obj_new_int(PicoGraphicsST7789::create_pen_rgb565(
mp_obj_get_int(r), mp_obj_get_int(r),
mp_obj_get_int(g), mp_obj_get_int(g),
mp_obj_get_int(b) mp_obj_get_int(b)
@ -183,7 +183,7 @@ mp_obj_t GenericST7789_set_pen(mp_obj_t self_in, mp_obj_t pen) {
mp_obj_t GenericST7789_set_palette_mode(mp_obj_t self_in, mp_obj_t mode) { mp_obj_t GenericST7789_set_palette_mode(mp_obj_t self_in, mp_obj_t mode) {
GenericST7789_obj_t *self = MP_OBJ_TO_PTR2(self_in, GenericST7789_obj_t); GenericST7789_obj_t *self = MP_OBJ_TO_PTR2(self_in, GenericST7789_obj_t);
self->st7789->set_palette_mode((ST7789Generic::PaletteMode)mp_obj_get_int(mode)); self->st7789->set_palette_mode((PicoGraphicsST7789::PaletteMode)mp_obj_get_int(mode));
return mp_const_none; return mp_const_none;
} }