kopia lustrzana https://github.com/pimoroni/pimoroni-pico
started on converting pico display demo
rodzic
3f24b442f1
commit
c48f81bc90
|
@ -38,3 +38,4 @@ add_subdirectory(vl53l5cx)
|
|||
add_subdirectory(pcf85063a)
|
||||
add_subdirectory(pms5003)
|
||||
add_subdirectory(sh1107)
|
||||
add_subdirectory(st7567)
|
|
@ -1 +1 @@
|
|||
include(st7735.cmake)
|
||||
include(st7567.cmake)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
set(DRIVER_NAME st7735)
|
||||
set(DRIVER_NAME st7567)
|
||||
add_library(${DRIVER_NAME} INTERFACE)
|
||||
|
||||
target_sources(${DRIVER_NAME} INTERFACE
|
||||
|
|
|
@ -55,3 +55,4 @@ add_subdirectory(servo2040)
|
|||
add_subdirectory(motor2040)
|
||||
add_subdirectory(inventor2040w)
|
||||
add_subdirectory(encoder)
|
||||
add_subdirectory(gfx_pack)
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
set(OUTPUT_NAME gfx_pack_demo)
|
||||
|
||||
add_executable(
|
||||
${OUTPUT_NAME}
|
||||
gfx_demo.cpp
|
||||
)
|
||||
|
||||
# Pull in pico libraries that we need
|
||||
target_link_libraries(${OUTPUT_NAME} pico_stdlib hardware_spi hardware_pwm hardware_dma rgbled button pico_display_2 st7568 pico_graphics)
|
||||
|
||||
# create map/bin/hex file etc.
|
||||
pico_add_extra_outputs(${OUTPUT_NAME})
|
|
@ -0,0 +1,124 @@
|
|||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "libraries/pico_display_2/pico_display_2.hpp"
|
||||
#include "drivers/st7789/st7789.hpp"
|
||||
#include "libraries/pico_graphics/pico_graphics.hpp"
|
||||
#include "rgbled.hpp"
|
||||
#include "button.hpp"
|
||||
|
||||
using namespace pimoroni;
|
||||
|
||||
ST7789 st7789(320, 240, ROTATE_0, false, get_spi_pins(BG_SPI_FRONT));
|
||||
PicoGraphics_PenRGB332 graphics(st7789.width, st7789.height, nullptr);
|
||||
|
||||
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
|
||||
void from_hsv(float h, float s, float v, uint8_t &r, uint8_t &g, uint8_t &b) {
|
||||
float i = floor(h * 6.0f);
|
||||
float f = h * 6.0f - i;
|
||||
v *= 255.0f;
|
||||
uint8_t p = v * (1.0f - s);
|
||||
uint8_t q = v * (1.0f - f * s);
|
||||
uint8_t t = v * (1.0f - (1.0f - f) * s);
|
||||
|
||||
switch (int(i) % 6) {
|
||||
case 0: r = v; g = t; b = p; break;
|
||||
case 1: r = q; g = v; b = p; break;
|
||||
case 2: r = p; g = v; b = t; break;
|
||||
case 3: r = p; g = q; b = v; break;
|
||||
case 4: r = t; g = p; b = v; break;
|
||||
case 5: r = v; g = p; b = q; break;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
st7789.set_backlight(255);
|
||||
|
||||
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() % graphics.bounds.w;
|
||||
shape.y = rand() % graphics.bounds.h;
|
||||
shape.r = (rand() % 10) + 3;
|
||||
shape.dx = float(rand() % 255) / 64.0f;
|
||||
shape.dy = float(rand() % 255) / 64.0f;
|
||||
shape.pen = graphics.create_pen(rand() % 255, rand() % 255, rand() % 255);
|
||||
shapes.push_back(shape);
|
||||
}
|
||||
|
||||
Point text_location(0, 0);
|
||||
|
||||
Pen BG = graphics.create_pen(120, 40, 60);
|
||||
Pen WHITE = graphics.create_pen(255, 255, 255);
|
||||
|
||||
while(true) {
|
||||
if(button_a.raw()) text_location.x -= 1;
|
||||
if(button_b.raw()) text_location.x += 1;
|
||||
|
||||
if(button_x.raw()) text_location.y -= 1;
|
||||
if(button_y.raw()) text_location.y += 1;
|
||||
|
||||
graphics.set_pen(BG);
|
||||
graphics.clear();
|
||||
|
||||
for(auto &shape : shapes) {
|
||||
shape.x += shape.dx;
|
||||
shape.y += shape.dy;
|
||||
if((shape.x - shape.r) < 0) {
|
||||
shape.dx *= -1;
|
||||
shape.x = shape.r;
|
||||
}
|
||||
if((shape.x + shape.r) >= graphics.bounds.w) {
|
||||
shape.dx *= -1;
|
||||
shape.x = graphics.bounds.w - shape.r;
|
||||
}
|
||||
if((shape.y - shape.r) < 0) {
|
||||
shape.dy *= -1;
|
||||
shape.y = shape.r;
|
||||
}
|
||||
if((shape.y + shape.r) >= graphics.bounds.h) {
|
||||
shape.dy *= -1;
|
||||
shape.y = graphics.bounds.h - shape.r;
|
||||
}
|
||||
|
||||
graphics.set_pen(shape.pen);
|
||||
graphics.circle(Point(shape.x, shape.y), shape.r);
|
||||
|
||||
}
|
||||
|
||||
// Since HSV takes a float from 0.0 to 1.0 indicating hue,
|
||||
// then we can divide millis by the number of milliseconds
|
||||
// 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);
|
||||
led.set_rgb(r, g, b);
|
||||
|
||||
|
||||
graphics.set_pen(WHITE);
|
||||
graphics.text("Hello World", text_location, 320);
|
||||
|
||||
// update screen
|
||||
st7789.update(&graphics);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -35,3 +35,4 @@ add_subdirectory(inventor2040w)
|
|||
add_subdirectory(adcfft)
|
||||
add_subdirectory(jpegdec)
|
||||
add_subdirectory(inky_frame)
|
||||
add_subdirectory(gfx_pack)
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
set(LIB_NAME gfx_pack)
|
||||
add_library(${LIB_NAME} INTERFACE)
|
||||
|
||||
target_sources(${LIB_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/${LIB_NAME}.cpp
|
||||
)
|
||||
|
||||
target_include_directories(${LIB_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
# Pull in pico libraries that we need
|
||||
target_link_libraries(${LIB_NAME} INTERFACE pico_stdlib hardware_spi hardware_pwm hardware_dma st7789 pico_graphics)
|
|
@ -0,0 +1,84 @@
|
|||
# Pico Display 2.0" Pack <!-- omit in toc -->
|
||||
|
||||
Our Pico Display Pack offers a vibrant 1.14" (240x135) IPS LCD screen for your Raspberry Pi Pico it also includes four switches and and an RGB LED!
|
||||
|
||||
- [Example Program](#example-program)
|
||||
- [Function Reference](#function-reference)
|
||||
- [PicoGraphics](#picographics)
|
||||
- [ST7789](#st7789)
|
||||
|
||||
## Example Program
|
||||
|
||||
The following example sets up Pico Display, displays some basic demo text and graphics and will illuminate the RGB LED green if the A button is pressed.
|
||||
|
||||
```c++
|
||||
#include "pico_display_2.hpp"
|
||||
#include "drivers/st7789/st7789.hpp"
|
||||
#include "libraries/pico_graphics/pico_graphics.hpp"
|
||||
#include "rgbled.hpp"
|
||||
#include "button.hpp"
|
||||
|
||||
// Display driver
|
||||
ST7789 st7789(PicoDisplay2::WIDTH, PicoDisplay2::HEIGHT, ROTATE_0, false, get_spi_pins(BG_SPI_FRONT));
|
||||
|
||||
// Graphics library - in RGB332 mode you get 256 colours and optional dithering for 75K RAM.
|
||||
PicoGraphics_PenRGB332 graphics(st7789.width, st7789.height, nullptr);
|
||||
|
||||
// RGB LED
|
||||
RGBLED led(PicoDisplay2::LED_R, PicoDisplay2::LED_G, PicoDisplay2::LED_B);
|
||||
|
||||
// And each button
|
||||
Button button_a(PicoDisplay2::A);
|
||||
Button button_b(PicoDisplay2::B);
|
||||
Button button_x(PicoDisplay2::X);
|
||||
Button button_y(PicoDisplay2::Y);
|
||||
|
||||
int main() {
|
||||
|
||||
// set the backlight to a value between 0 and 255
|
||||
// the backlight is driven via PWM and is gamma corrected by our
|
||||
// library to give a gorgeous linear brightness range.
|
||||
st7789.set_backlight(100);
|
||||
|
||||
while(true) {
|
||||
// detect if the A button is pressed (could be A, B, X, or Y)
|
||||
if(button_a.raw(display.A)) {
|
||||
// make the led glow green
|
||||
// parameters are red, green, blue all between 0 and 255
|
||||
// these are also gamma corrected
|
||||
led.set_rgb(0, 255, 0);
|
||||
}
|
||||
|
||||
// set the colour of the pen
|
||||
// parameters are red, green, blue all between 0 and 255
|
||||
graphics.set_pen(30, 40, 50);
|
||||
|
||||
// fill the screen with the current pen colour
|
||||
graphics.clear();
|
||||
|
||||
// draw a box to put some text in
|
||||
graphics.set_pen(10, 20, 30);
|
||||
Rect text_rect(10, 10, 150, 150);
|
||||
graphics.rectangle(text_rect);
|
||||
|
||||
// write some text inside the box with 10 pixels of margin
|
||||
// automatically word wrapping
|
||||
text_rect.deflate(10);
|
||||
graphics.set_pen(110, 120, 130);
|
||||
graphics.text("This is a message", Point(text_rect.x, text_rect.y), text_rect.w);
|
||||
|
||||
// now we've done our drawing let's update the screen
|
||||
st7789.update(&graphics);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Function Reference
|
||||
|
||||
### PicoGraphics
|
||||
|
||||
Pico Display 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).
|
||||
|
||||
### ST7789
|
||||
|
||||
Pico Display uses the ST7789 display driver to handle the LCD. For more information [read the ST7789 README.](../../drivers/st7789/README.md).
|
|
@ -0,0 +1,10 @@
|
|||
add_library(pico_display_2 INTERFACE)
|
||||
|
||||
target_sources(pico_display_2 INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/pico_display_2.cpp
|
||||
)
|
||||
|
||||
target_include_directories(pico_display_2 INTERFACE ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
# Pull in pico libraries that we need
|
||||
target_link_libraries(pico_display_2 INTERFACE pico_stdlib)
|
|
@ -0,0 +1 @@
|
|||
#include "gfx_pack.hpp"
|
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
#include "pico/stdlib.h"
|
||||
|
||||
namespace pimoroni {
|
||||
class gfx_pack {
|
||||
public:
|
||||
static const int WIDTH = 128;
|
||||
static const int HEIGHT = 64;
|
||||
static const uint8_t A = 12;
|
||||
static const uint8_t B = 13;
|
||||
static const uint8_t X = 14;
|
||||
static const uint8_t Y = 15;
|
||||
static const uint8_t BL_R = 6;
|
||||
static const uint8_t BL_G = 7;
|
||||
static const uint8_t BL_B = 8;
|
||||
static const uint8_t BL_W = 9;
|
||||
};
|
||||
}
|
Ładowanie…
Reference in New Issue