kopia lustrzana https://github.com/pimoroni/pimoroni-pico
ST7789: Port C++ examples to generic driver.
rodzic
8db8ad3140
commit
65fb478b6e
|
@ -1,11 +1,11 @@
|
|||
add_executable(
|
||||
display
|
||||
pico_display_demo
|
||||
demo.cpp
|
||||
image_data.cpp
|
||||
)
|
||||
|
||||
# Pull in pico libraries that we need
|
||||
target_link_libraries(display pico_stdlib hardware_spi hardware_pwm hardware_dma pico_display)
|
||||
target_link_libraries(pico_display_demo pico_stdlib hardware_spi hardware_pwm hardware_dma rgbled pico_display generic_st7789)
|
||||
|
||||
# create map/bin/hex file etc.
|
||||
pico_add_extra_outputs(display)
|
||||
pico_add_extra_outputs(pico_display_demo)
|
|
@ -4,84 +4,25 @@
|
|||
#include <cstdlib>
|
||||
|
||||
#include "pico_display.hpp"
|
||||
#include "generic_st7789.hpp"
|
||||
#include "rgbled.hpp"
|
||||
|
||||
using namespace pimoroni;
|
||||
|
||||
extern unsigned char image_tif[];
|
||||
extern unsigned int image_tif_len;
|
||||
const bool ROTATE_180 = false;
|
||||
|
||||
uint16_t buffer[PicoDisplay::WIDTH * PicoDisplay::HEIGHT];
|
||||
PicoDisplay pico_display(buffer);
|
||||
/*
|
||||
void pixel(int x, int y, uint16_t c) {
|
||||
x *= 2;
|
||||
y *= 2;
|
||||
pico_display.frame_buffer[x + y * 240] = c;
|
||||
pico_display.frame_buffer[x + 1 + y * 240] = c;
|
||||
pico_display.frame_buffer[x + 1 + (y + 1) * 240] = c;
|
||||
pico_display.frame_buffer[x + (y + 1) * 240] = c;
|
||||
}
|
||||
|
||||
void rect(int x, int y, int w, int h, uint16_t c) {
|
||||
for(int rx = x; rx < x + w; rx++) {
|
||||
for(int ry = y; ry < y + h; ry++) {
|
||||
pixel(rx, ry, c);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
// Swap WIDTH and HEIGHT to rotate 90 degrees
|
||||
ST7789Generic pico_display(PicoDisplay::WIDTH, PicoDisplay::HEIGHT, buffer);
|
||||
|
||||
uint8_t arrow[] = {
|
||||
0b00010000,
|
||||
0b00110000,
|
||||
0b01110000,
|
||||
0b11111111,
|
||||
0b11111111,
|
||||
0b01110000,
|
||||
0b00110000,
|
||||
0b00010000
|
||||
};
|
||||
RGBLED led(PicoDisplay::LED_R, PicoDisplay::LED_G, PicoDisplay::LED_B);
|
||||
|
||||
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_display.init();
|
||||
pico_display.configure_display(ROTATE_180);
|
||||
pico_display.set_backlight(100);
|
||||
|
||||
// uint16_t white = pico_display.create_pen(255, 255, 255);
|
||||
// uint16_t black = pico_display.create_pen(0, 0, 0);
|
||||
// uint16_t red = pico_display.create_pen(255, 0, 0);
|
||||
// uint16_t green = pico_display.create_pen(0, 255, 0);
|
||||
// uint16_t dark_grey = pico_display.create_pen(20, 40, 60);
|
||||
// uint16_t dark_green = pico_display.create_pen(10, 100, 10);
|
||||
// uint16_t blue = pico_display.create_pen(0, 0, 255);
|
||||
|
||||
struct pt {
|
||||
float x;
|
||||
float y;
|
||||
|
@ -92,7 +33,7 @@ int main() {
|
|||
};
|
||||
|
||||
std::vector<pt> shapes;
|
||||
for(int i = 0; i < 1000; i++) {
|
||||
for(int i = 0; i < 100; i++) {
|
||||
pt shape;
|
||||
shape.x = rand() % 240;
|
||||
shape.y = rand() % 135;
|
||||
|
@ -121,8 +62,8 @@ int main() {
|
|||
}
|
||||
|
||||
float led_step = fmod(i / 20.0f, M_PI * 2.0f);
|
||||
int r = (sin(led_step) * 25.0f) + 25.0f;
|
||||
pico_display.set_led(r, r / 1.2f, r);
|
||||
int r = (sin(led_step) * 32.0f) + 32.0f;
|
||||
led.set_rgb(r, r / 1.2f, r);
|
||||
|
||||
|
||||
std::vector<Point> poly;
|
||||
|
@ -134,9 +75,9 @@ int main() {
|
|||
poly.push_back(Point(30, 45));
|
||||
|
||||
pico_display.set_pen(255, 255, 0);
|
||||
//pico_display.pixel(Point(0, 0));
|
||||
pico_display.polygon(poly);
|
||||
|
||||
|
||||
pico_display.set_pen(0, 255, 255);
|
||||
pico_display.triangle(Point(50, 50), Point(130, 80), Point(80, 110));
|
||||
|
||||
|
@ -155,39 +96,10 @@ int main() {
|
|||
pico_display.line(Point(120, 67), Point(cx + 120, cy + 67));
|
||||
}
|
||||
}
|
||||
/*
|
||||
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_display.update();
|
||||
|
||||
sleep_ms(1000 / 60);
|
||||
i++;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
set(OUTPUT_NAME display_2)
|
||||
set(OUTPUT_NAME pico_display2_demo)
|
||||
|
||||
add_executable(
|
||||
${OUTPUT_NAME}
|
||||
|
@ -6,7 +6,7 @@ add_executable(
|
|||
)
|
||||
|
||||
# Pull in pico libraries that we need
|
||||
target_link_libraries( ${OUTPUT_NAME} pico_stdlib hardware_spi hardware_pwm hardware_dma pico_display_2)
|
||||
target_link_libraries(${OUTPUT_NAME} pico_stdlib hardware_spi hardware_pwm hardware_dma rgbled button pico_display_2 generic_st7789)
|
||||
|
||||
# create map/bin/hex file etc.
|
||||
pico_add_extra_outputs( ${OUTPUT_NAME})
|
||||
pico_add_extra_outputs(${OUTPUT_NAME})
|
|
@ -4,11 +4,25 @@
|
|||
#include <cstdlib>
|
||||
|
||||
#include "pico_display_2.hpp"
|
||||
#include "generic_st7789.hpp"
|
||||
#include "rgbled.hpp"
|
||||
#include "button.hpp"
|
||||
|
||||
using namespace pimoroni;
|
||||
|
||||
const bool ROTATE_180 = false;
|
||||
|
||||
uint16_t buffer[PicoDisplay2::WIDTH * PicoDisplay2::HEIGHT];
|
||||
PicoDisplay2 pico_display(buffer);
|
||||
|
||||
// Swap WIDTH and HEIGHT to rotate 90 degrees
|
||||
ST7789Generic pico_display(PicoDisplay2::WIDTH, PicoDisplay2::HEIGHT, buffer);
|
||||
|
||||
RGBLED led(PicoDisplay2::LED_R, PicoDisplay2::LED_G, PicoDisplay2::LED_B);
|
||||
|
||||
Button button_a(PicoDisplay2::A);
|
||||
Button button_b(PicoDisplay2::B);
|
||||
Button button_x(PicoDisplay2::X);
|
||||
Button button_y(PicoDisplay2::Y);
|
||||
|
||||
// HSV Conversion expects float inputs in the range of 0.00-1.00 for each channel
|
||||
// Outputs are rgb in the range 0-255 for each channel
|
||||
|
@ -31,7 +45,7 @@ void from_hsv(float h, float s, float v, uint8_t &r, uint8_t &g, uint8_t &b) {
|
|||
}
|
||||
|
||||
int main() {
|
||||
pico_display.init();
|
||||
pico_display.configure_display(ROTATE_180);
|
||||
pico_display.set_backlight(255);
|
||||
|
||||
struct pt {
|
||||
|
@ -58,11 +72,11 @@ int main() {
|
|||
Point text_location(0, 0);
|
||||
|
||||
while(true) {
|
||||
if(pico_display.is_pressed(pico_display.A)) text_location.x -= 1;
|
||||
if(pico_display.is_pressed(pico_display.B)) text_location.x += 1;
|
||||
if(button_a.raw()) text_location.x -= 1;
|
||||
if(button_b.raw()) text_location.x += 1;
|
||||
|
||||
if(pico_display.is_pressed(pico_display.X)) text_location.y -= 1;
|
||||
if(pico_display.is_pressed(pico_display.Y)) text_location.y += 1;
|
||||
if(button_x.raw()) text_location.y -= 1;
|
||||
if(button_y.raw()) text_location.y += 1;
|
||||
|
||||
pico_display.set_pen(120, 40, 60);
|
||||
pico_display.clear();
|
||||
|
@ -97,7 +111,7 @@ int main() {
|
|||
// we want a full colour cycle to take. 5000 = 5 sec.
|
||||
uint8_t r = 0, g = 0, b = 0;
|
||||
from_hsv((float)millis() / 5000.0f, 1.0f, 0.5f + sinf(millis() / 100.0f / 3.14159f) * 0.5f, r, g, b);
|
||||
pico_display.set_led(r, g, b);
|
||||
led.set_rgb(r, g, b);
|
||||
|
||||
|
||||
pico_display.set_pen(255, 255, 255);
|
||||
|
|
|
@ -12,6 +12,12 @@ namespace pimoroni {
|
|||
this->st7789.init(true, false);
|
||||
}
|
||||
|
||||
ST7789Generic::ST7789Generic(int width, int height, uint16_t *frame_buffer)
|
||||
: PicoGraphics(width, height, frame_buffer), st7789(width, height, frame_buffer, BG_SPI_FRONT) {
|
||||
this->frame_buffer = st7789.frame_buffer;
|
||||
this->st7789.init(true, false);
|
||||
}
|
||||
|
||||
ST7789Generic::ST7789Generic(uint16_t width, uint16_t height, spi_inst_t *spi,
|
||||
uint cs, uint dc, uint sck, uint mosi, uint miso, uint bl,
|
||||
uint16_t *frame_buffer) :
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace pimoroni {
|
|||
|
||||
public:
|
||||
ST7789Generic(int width, int height, BG_SPI_SLOT slot, uint16_t *frame_buffer = nullptr);
|
||||
ST7789Generic(int width, int height, uint16_t *frame_buffer = nullptr);
|
||||
ST7789Generic(uint16_t width, uint16_t height, spi_inst_t *spi,
|
||||
uint cs, uint dc, uint sck, uint mosi, uint miso = PIN_UNUSED, uint bl = PIN_UNUSED,
|
||||
uint16_t *frame_buffer = nullptr);
|
||||
|
|
|
@ -6,10 +6,6 @@
|
|||
|
||||
#include "pico_display.hpp"
|
||||
|
||||
const uint8_t LED_R = 6;
|
||||
const uint8_t LED_G = 7;
|
||||
const uint8_t LED_B = 8;
|
||||
|
||||
namespace pimoroni {
|
||||
|
||||
PicoDisplay::PicoDisplay(uint16_t *buf)
|
||||
|
|
|
@ -15,6 +15,9 @@ namespace pimoroni {
|
|||
static const uint8_t B = 13;
|
||||
static const uint8_t X = 14;
|
||||
static const uint8_t Y = 15;
|
||||
static const uint8_t LED_R = 6;
|
||||
static const uint8_t LED_G = 7;
|
||||
static const uint8_t LED_B = 8;
|
||||
|
||||
uint16_t *__fb;
|
||||
private:
|
||||
|
|
|
@ -6,10 +6,6 @@
|
|||
|
||||
#include "pico_display_2.hpp"
|
||||
|
||||
const uint8_t LED_R = 6;
|
||||
const uint8_t LED_G = 7;
|
||||
const uint8_t LED_B = 8;
|
||||
|
||||
namespace pimoroni {
|
||||
|
||||
PicoDisplay2::PicoDisplay2(uint16_t *buf)
|
||||
|
|
|
@ -15,6 +15,9 @@ namespace pimoroni {
|
|||
static const uint8_t B = 13;
|
||||
static const uint8_t X = 14;
|
||||
static const uint8_t Y = 15;
|
||||
static const uint8_t LED_R = 6;
|
||||
static const uint8_t LED_G = 7;
|
||||
static const uint8_t LED_B = 8;
|
||||
|
||||
uint16_t *__fb;
|
||||
private:
|
||||
|
|
Ładowanie…
Reference in New Issue