ST7789 -> PicoGraphics
* Absorb ST7735 support into the generic ST7789 driver and rename to PicoGraphics * Delete obsolete MicroPython modules * Refactor PicoGraphics to inherited class for each pen type * Refactor ST7789 and ST7735 to derive from DisplayDriver * Allow user to set pen_type in MicroPython constructor for RGB565, RGB332, P8 and P4 modesdriver/sh1107
|
@ -164,23 +164,22 @@ namespace pimoroni {
|
|||
}
|
||||
|
||||
// Native 16-bit framebuffer update
|
||||
void ST7735::update(PicoGraphics<PenRGB565> *graphics) {
|
||||
command(reg::RAMWR, width * height * sizeof(uint16_t), (const char*)graphics->get_data());
|
||||
}
|
||||
void ST7735::update(PicoGraphics *graphics) {
|
||||
if(graphics->pen_type == PicoGraphics::PEN_RGB565) {
|
||||
command(reg::RAMWR, width * height * sizeof(uint16_t), (const char*)graphics->get_data());
|
||||
} else {
|
||||
command(reg::RAMWR);
|
||||
gpio_put(dc, 1); // data mode
|
||||
gpio_put(cs, 0);
|
||||
|
||||
// 8-bit framebuffer with palette conversion update
|
||||
void ST7735::update(PicoGraphics<PenRGB332> *graphics) {
|
||||
command(reg::RAMWR);
|
||||
gpio_put(dc, 1); // data mode
|
||||
gpio_put(cs, 0);
|
||||
|
||||
uint16_t row_buf[width];
|
||||
for(auto y = 0u; y < height; y++) {
|
||||
graphics->get_data(y, &row_buf);
|
||||
// TODO: Add DMA->SPI / PIO while we prep the next row
|
||||
spi_write_blocking(spi, (const uint8_t*)row_buf, width * sizeof(uint16_t));
|
||||
uint16_t row_buf[width];
|
||||
for(auto y = 0u; y < height; y++) {
|
||||
graphics->get_data(y, &row_buf);
|
||||
// TODO: Add DMA->SPI / PIO while we prep the next row
|
||||
spi_write_blocking(spi, (const uint8_t*)row_buf, width * sizeof(uint16_t));
|
||||
}
|
||||
gpio_put(cs, 1);
|
||||
}
|
||||
gpio_put(cs, 1);
|
||||
}
|
||||
|
||||
void ST7735::set_backlight(uint8_t brightness) {
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
namespace pimoroni {
|
||||
|
||||
class ST7735 {
|
||||
class ST7735 : public DisplayDriver {
|
||||
//--------------------------------------------------
|
||||
// Constants
|
||||
//--------------------------------------------------
|
||||
|
@ -20,9 +20,6 @@ namespace pimoroni {
|
|||
// Variables
|
||||
//--------------------------------------------------
|
||||
private:
|
||||
// screen properties
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
|
||||
spi_inst_t *spi = spi0;
|
||||
|
||||
|
@ -45,7 +42,7 @@ namespace pimoroni {
|
|||
//--------------------------------------------------
|
||||
public:
|
||||
ST7735(uint16_t width, uint16_t height, SPIPins pins) :
|
||||
width(width), height(height),
|
||||
DisplayDriver(width, height, ROTATE_0),
|
||||
spi(pins.spi), cs(pins.cs), dc(pins.dc), sck(pins.sck), mosi(pins.mosi), bl(pins.bl) {
|
||||
init();
|
||||
}
|
||||
|
@ -55,10 +52,8 @@ namespace pimoroni {
|
|||
// Methods
|
||||
//--------------------------------------------------
|
||||
public:
|
||||
// Update functions for supported Pen types
|
||||
void update(PicoGraphics<PenRGB565> *graphics);
|
||||
void update(PicoGraphics<PenRGB332> *graphics);
|
||||
void set_backlight(uint8_t brightness);
|
||||
void update(PicoGraphics *graphics) override;
|
||||
void set_backlight(uint8_t brightness) override;
|
||||
|
||||
private:
|
||||
void init(bool auto_init_sequence = true);
|
||||
|
|
|
@ -46,7 +46,23 @@ namespace pimoroni {
|
|||
PWMFRSEL = 0xCC
|
||||
};
|
||||
|
||||
void ST7789::init() {
|
||||
void ST7789::common_init() {
|
||||
gpio_set_function(dc, GPIO_FUNC_SIO);
|
||||
gpio_set_dir(dc, GPIO_OUT);
|
||||
|
||||
gpio_set_function(cs, GPIO_FUNC_SIO);
|
||||
gpio_set_dir(cs, GPIO_OUT);
|
||||
|
||||
// if a backlight pin is provided then set it up for
|
||||
// pwm control
|
||||
if(bl != PIN_UNUSED) {
|
||||
pwm_config cfg = pwm_get_default_config();
|
||||
pwm_set_wrap(pwm_gpio_to_slice_num(bl), 65535);
|
||||
pwm_init(pwm_gpio_to_slice_num(bl), &cfg, true);
|
||||
gpio_set_function(bl, GPIO_FUNC_PWM);
|
||||
set_backlight(0); // Turn backlight off initially to avoid nasty surprises
|
||||
}
|
||||
|
||||
command(reg::SWRESET);
|
||||
|
||||
sleep_ms(150);
|
||||
|
@ -201,140 +217,40 @@ namespace pimoroni {
|
|||
gpio_put(cs, 1);
|
||||
}
|
||||
|
||||
void ST7789::update(PicoGraphics<PenRGB565> *graphics) {
|
||||
command(reg::RAMWR, width * height * sizeof(uint16_t), (const char*)graphics->get_data());
|
||||
}
|
||||
|
||||
void ST7789::update(PicoGraphics<PenRGB332> *graphics) {
|
||||
uint8_t command = reg::RAMWR;
|
||||
|
||||
gpio_put(dc, 0); // command mode
|
||||
|
||||
gpio_put(cs, 0);
|
||||
|
||||
if(spi) {
|
||||
spi_write_blocking(spi, &command, 1);
|
||||
void ST7789::update(PicoGraphics *graphics) {
|
||||
if(graphics->pen_type == PicoGraphics::PEN_RGB565) {
|
||||
command(reg::RAMWR, width * height * sizeof(uint16_t), (const char*)graphics->get_data());
|
||||
} else {
|
||||
write_blocking_parallel(&command, 1);
|
||||
}
|
||||
uint8_t command = reg::RAMWR;
|
||||
|
||||
gpio_put(dc, 1); // data mode
|
||||
gpio_put(dc, 0); // command mode
|
||||
|
||||
uint16_t row_buf[width];
|
||||
gpio_put(cs, 0);
|
||||
|
||||
for(auto y = 0u; y < height; y++) {
|
||||
graphics->get_data(y, &row_buf);
|
||||
// TODO: Add DMA->SPI / PIO while we prep the next row
|
||||
if(spi) {
|
||||
spi_write_blocking(spi, (const uint8_t*)row_buf, width * sizeof(uint16_t));
|
||||
spi_write_blocking(spi, &command, 1);
|
||||
} else {
|
||||
write_blocking_parallel((const uint8_t*)row_buf, width * sizeof(uint16_t));
|
||||
write_blocking_parallel(&command, 1);
|
||||
}
|
||||
}
|
||||
|
||||
gpio_put(cs, 1);
|
||||
}
|
||||
gpio_put(dc, 1); // data mode
|
||||
|
||||
void ST7789::update(PicoGraphics<PenP8> *graphics) {
|
||||
uint8_t command = reg::RAMWR;
|
||||
uint16_t row_buf[width];
|
||||
|
||||
gpio_put(dc, 0); // command mode
|
||||
|
||||
gpio_put(cs, 0);
|
||||
|
||||
if(spi) {
|
||||
spi_write_blocking(spi, &command, 1);
|
||||
} else {
|
||||
write_blocking_parallel(&command, 1);
|
||||
}
|
||||
|
||||
gpio_put(dc, 1); // data mode
|
||||
|
||||
uint16_t row_buf[width];
|
||||
|
||||
for(auto y = 0u; y < height; y++) {
|
||||
graphics->get_data(y, &row_buf);
|
||||
// TODO: Add DMA->SPI / PIO while we prep the next row
|
||||
if(spi) {
|
||||
spi_write_blocking(spi, (const uint8_t*)row_buf, width * sizeof(uint16_t));
|
||||
} else {
|
||||
write_blocking_parallel((const uint8_t*)row_buf, width * sizeof(uint16_t));
|
||||
for(auto y = 0u; y < height; y++) {
|
||||
graphics->get_data(y, &row_buf);
|
||||
// TODO: Add DMA->SPI / PIO while we prep the next row
|
||||
if(spi) {
|
||||
spi_write_blocking(spi, (const uint8_t*)row_buf, width * sizeof(uint16_t));
|
||||
} else {
|
||||
write_blocking_parallel((const uint8_t*)row_buf, width * sizeof(uint16_t));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gpio_put(cs, 1);
|
||||
gpio_put(cs, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void ST7789::update(PicoGraphics<PenP4> *graphics) {
|
||||
uint8_t command = reg::RAMWR;
|
||||
|
||||
gpio_put(dc, 0); // command mode
|
||||
|
||||
gpio_put(cs, 0);
|
||||
|
||||
if(spi) {
|
||||
spi_write_blocking(spi, &command, 1);
|
||||
} else {
|
||||
write_blocking_parallel(&command, 1);
|
||||
}
|
||||
|
||||
gpio_put(dc, 1); // data mode
|
||||
|
||||
uint16_t row_buf[width];
|
||||
|
||||
for(auto y = 0u; y < height; y++) {
|
||||
graphics->get_data(y, &row_buf);
|
||||
// TODO: Add DMA->SPI / PIO while we prep the next row
|
||||
if(spi) {
|
||||
spi_write_blocking(spi, (const uint8_t*)row_buf, width * sizeof(uint16_t));
|
||||
} else {
|
||||
write_blocking_parallel((const uint8_t*)row_buf, width * sizeof(uint16_t));
|
||||
}
|
||||
}
|
||||
|
||||
gpio_put(cs, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
// Native 16-bit framebuffer update
|
||||
void ST7789::update() {
|
||||
command(reg::RAMWR, width * height * sizeof(uint16_t), (const char*)frame_buffer);
|
||||
}
|
||||
|
||||
// 8-bit framebuffer with palette conversion update
|
||||
void ST7789::update(uint16_t *palette) {
|
||||
uint8_t command = reg::RAMWR;
|
||||
uint16_t row[width];
|
||||
|
||||
gpio_put(dc, 0); // command mode
|
||||
|
||||
gpio_put(cs, 0);
|
||||
|
||||
if(spi) {
|
||||
spi_write_blocking(spi, &command, 1);
|
||||
} else {
|
||||
write_blocking_parallel(&command, 1);
|
||||
}
|
||||
|
||||
gpio_put(dc, 1); // data mode
|
||||
|
||||
for(auto y = 0u; y < height; y++) {
|
||||
for(auto x = 0u; x < width; x++) {
|
||||
auto i = y * width + x;
|
||||
row[x] = palette[((uint8_t *)frame_buffer)[i]];
|
||||
}
|
||||
// TODO: Add DMA->SPI / PIO while we prep the next row
|
||||
if(spi) {
|
||||
spi_write_blocking(spi, (const uint8_t*)row, width * sizeof(uint16_t));
|
||||
} else {
|
||||
write_blocking_parallel((const uint8_t*)row, width * sizeof(uint16_t));
|
||||
}
|
||||
}
|
||||
|
||||
gpio_put(cs, 1);
|
||||
}
|
||||
*/
|
||||
|
||||
void ST7789::set_backlight(uint8_t brightness) {
|
||||
// gamma correct the provided 0-255 brightness value onto a
|
||||
// 0-65535 range for the pwm counter
|
||||
|
|
|
@ -12,14 +12,10 @@
|
|||
|
||||
namespace pimoroni {
|
||||
|
||||
class ST7789 {
|
||||
class ST7789 : public DisplayDriver {
|
||||
spi_inst_t *spi = PIMORONI_SPI_DEFAULT_INSTANCE;
|
||||
|
||||
public:
|
||||
// screen properties
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
Rotation rotation;
|
||||
bool round;
|
||||
|
||||
//--------------------------------------------------
|
||||
|
@ -44,8 +40,8 @@ namespace pimoroni {
|
|||
public:
|
||||
// Parallel init
|
||||
ST7789(uint16_t width, uint16_t height, Rotation rotation, ParallelPins pins) :
|
||||
spi(nullptr),
|
||||
width(width), height(height), rotation(rotation), round(false),
|
||||
DisplayDriver(width, height, rotation),
|
||||
spi(nullptr), round(false),
|
||||
cs(pins.cs), dc(pins.dc), wr_sck(pins.wr_sck), rd_sck(pins.rd_sck), d0(pins.d0), bl(pins.bl) {
|
||||
|
||||
gpio_set_function(wr_sck, GPIO_FUNC_SIO);
|
||||
|
@ -66,8 +62,8 @@ namespace pimoroni {
|
|||
|
||||
// Serial init
|
||||
ST7789(uint16_t width, uint16_t height, Rotation rotation, bool round, SPIPins pins) :
|
||||
spi(pins.spi),
|
||||
width(width), height(height), rotation(rotation), round(round),
|
||||
DisplayDriver(width, height, rotation),
|
||||
spi(pins.spi), round(round),
|
||||
cs(pins.cs), dc(pins.dc), wr_sck(pins.sck), d0(pins.mosi), bl(pins.bl) {
|
||||
|
||||
// configure spi interface and pins
|
||||
|
@ -79,35 +75,15 @@ namespace pimoroni {
|
|||
common_init();
|
||||
}
|
||||
|
||||
void init();
|
||||
void command(uint8_t command, size_t len = 0, const char *data = NULL);
|
||||
void set_backlight(uint8_t brightness);
|
||||
|
||||
void update(PicoGraphics<PenRGB565> *graphics);
|
||||
void update(PicoGraphics<PenRGB332> *graphics);
|
||||
void update(PicoGraphics<PenP8> *graphics);
|
||||
void update(PicoGraphics<PenP4> *graphics);
|
||||
void update(PicoGraphics *graphics) override;
|
||||
void set_backlight(uint8_t brightness) override;
|
||||
|
||||
private:
|
||||
void common_init();
|
||||
void configure_display(Rotation rotate);
|
||||
void write_blocking_parallel(const uint8_t *src, size_t len);
|
||||
void common_init() {
|
||||
gpio_set_function(dc, GPIO_FUNC_SIO);
|
||||
gpio_set_dir(dc, GPIO_OUT);
|
||||
|
||||
gpio_set_function(cs, GPIO_FUNC_SIO);
|
||||
gpio_set_dir(cs, GPIO_OUT);
|
||||
|
||||
// if a backlight pin is provided then set it up for
|
||||
// pwm control
|
||||
if(bl != PIN_UNUSED) {
|
||||
pwm_config cfg = pwm_get_default_config();
|
||||
pwm_set_wrap(pwm_gpio_to_slice_num(bl), 65535);
|
||||
pwm_init(pwm_gpio_to_slice_num(bl), &cfg, true);
|
||||
gpio_set_function(bl, GPIO_FUNC_PWM);
|
||||
set_backlight(0); // Turn backlight off initially to avoid nasty surprises
|
||||
}
|
||||
}
|
||||
void command(uint8_t command, size_t len = 0, const char *data = NULL);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -3,14 +3,16 @@
|
|||
#include <vector>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "pico_display_2.hpp"
|
||||
#include "picographics_st7789.hpp"
|
||||
#include "graphics_2.hpp"
|
||||
#include "drivers/st7789/st7789.hpp"
|
||||
#include "libraries/pico_graphics/pico_graphics->hpp"
|
||||
#include "rgbled.hpp"
|
||||
#include "button.hpp"
|
||||
|
||||
using namespace pimoroni;
|
||||
|
||||
PicoGraphicsST7789 pico_display(240, 240, ROTATE_0);
|
||||
ST7789 st7789(320, 240, ROTATE_0, false, get_spi_pins(BG_SPI_FRONT));
|
||||
PicoGraphics graphics;
|
||||
|
||||
RGBLED led(PicoDisplay2::LED_R, PicoDisplay2::LED_G, PicoDisplay2::LED_B);
|
||||
|
||||
|
@ -40,7 +42,13 @@ void from_hsv(float h, float s, float v, uint8_t &r, uint8_t &g, uint8_t &b) {
|
|||
}
|
||||
|
||||
int main() {
|
||||
pico_display.set_backlight(255);
|
||||
st7789.set_backlight(255);
|
||||
|
||||
// 150k RAM, 65K colours
|
||||
// graphics = new PicoGraphics_PenRGB565(st7789.width, st7789.height, nullptr);
|
||||
|
||||
// 75k RAM, 256 colours
|
||||
graphics = new PicoGraphics_PenRGB332(st7789.width, st7789.height, nullptr);
|
||||
|
||||
struct pt {
|
||||
float x;
|
||||
|
@ -54,19 +62,19 @@ int main() {
|
|||
std::vector<pt> shapes;
|
||||
for(int i = 0; i < 100; i++) {
|
||||
pt shape;
|
||||
shape.x = rand() % pico_display.bounds.w;
|
||||
shape.y = rand() % pico_display.bounds.h;
|
||||
shape.x = rand() % graphics->bounds.w;
|
||||
shape.y = rand() % graphics->bounds.h;
|
||||
shape.r = (rand() % 10) + 3;
|
||||
shape.dx = float(rand() % 255) / 64.0f;
|
||||
shape.dy = float(rand() % 255) / 64.0f;
|
||||
shape.pen = pico_display.create_pen(rand() % 255, rand() % 255, rand() % 255);
|
||||
shape.pen = graphics->create_pen(rand() % 255, rand() % 255, rand() % 255);
|
||||
shapes.push_back(shape);
|
||||
}
|
||||
|
||||
Point text_location(0, 0);
|
||||
|
||||
Pen BG = pico_display.create_pen(120, 40, 60);
|
||||
Pen WHITE = pico_display.create_pen(255, 255, 255);
|
||||
Pen BG = graphics->create_pen(120, 40, 60);
|
||||
Pen WHITE = graphics->create_pen(255, 255, 255);
|
||||
|
||||
while(true) {
|
||||
if(button_a.raw()) text_location.x -= 1;
|
||||
|
@ -75,8 +83,8 @@ int main() {
|
|||
if(button_x.raw()) text_location.y -= 1;
|
||||
if(button_y.raw()) text_location.y += 1;
|
||||
|
||||
pico_display.set_pen(BG);
|
||||
pico_display.clear();
|
||||
graphics->set_pen(BG);
|
||||
graphics->clear();
|
||||
|
||||
for(auto &shape : shapes) {
|
||||
shape.x += shape.dx;
|
||||
|
@ -85,21 +93,21 @@ int main() {
|
|||
shape.dx *= -1;
|
||||
shape.x = shape.r;
|
||||
}
|
||||
if((shape.x + shape.r) >= pico_display.bounds.w) {
|
||||
if((shape.x + shape.r) >= graphics->bounds.w) {
|
||||
shape.dx *= -1;
|
||||
shape.x = pico_display.bounds.w - shape.r;
|
||||
shape.x = graphics->bounds.w - shape.r;
|
||||
}
|
||||
if((shape.y - shape.r) < 0) {
|
||||
shape.dy *= -1;
|
||||
shape.y = shape.r;
|
||||
}
|
||||
if((shape.y + shape.r) >= pico_display.bounds.h) {
|
||||
if((shape.y + shape.r) >= graphics->bounds.h) {
|
||||
shape.dy *= -1;
|
||||
shape.y = pico_display.bounds.h - shape.r;
|
||||
shape.y = graphics->bounds.h - shape.r;
|
||||
}
|
||||
|
||||
pico_display.set_pen(shape.pen);
|
||||
pico_display.circle(Point(shape.x, shape.y), shape.r);
|
||||
graphics->set_pen(shape.pen);
|
||||
graphics->circle(Point(shape.x, shape.y), shape.r);
|
||||
|
||||
}
|
||||
|
||||
|
@ -111,11 +119,11 @@ int main() {
|
|||
led.set_rgb(r, g, b);
|
||||
|
||||
|
||||
pico_display.set_pen(WHITE);
|
||||
pico_display.text("Hello World", text_location, 320);
|
||||
graphics->set_pen(WHITE);
|
||||
graphics->text("Hello World", text_location, 320);
|
||||
|
||||
// update screen
|
||||
pico_display.update();
|
||||
st7789.update(graphics);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace pimoroni {
|
||||
|
||||
class BreakoutColourLCD160x80 : public PicoGraphics<PenRGB565> {
|
||||
class BreakoutColourLCD160x80 : public PicoGraphics_PenRGB565 {
|
||||
//--------------------------------------------------
|
||||
// Constants
|
||||
//--------------------------------------------------
|
||||
|
@ -32,7 +32,7 @@ namespace pimoroni {
|
|||
}
|
||||
|
||||
BreakoutColourLCD160x80(void *frame_buffer, SPIPins bus_pins)
|
||||
: PicoGraphics<PenRGB565>(WIDTH, HEIGHT, frame_buffer), screen(WIDTH, HEIGHT, bus_pins){
|
||||
: PicoGraphics_PenRGB565(WIDTH, HEIGHT, frame_buffer), screen(WIDTH, HEIGHT, bus_pins){
|
||||
}
|
||||
|
||||
void update() {
|
||||
|
|
|
@ -2,39 +2,51 @@
|
|||
|
||||
namespace pimoroni {
|
||||
|
||||
template<class T>
|
||||
void PicoGraphics<T>::set_font(const bitmap::font_t *font){
|
||||
void PicoGraphics::set_pen(uint c) {};
|
||||
void PicoGraphics::set_pen(uint8_t r, uint8_t g, uint8_t b) {};
|
||||
void PicoGraphics::update_pen(uint8_t i, uint8_t r, uint8_t g, uint8_t b) {};
|
||||
void PicoGraphics::reset_pen(uint8_t i) {};
|
||||
int PicoGraphics::create_pen(uint8_t r, uint8_t g, uint8_t b) {return -1;};
|
||||
void PicoGraphics::set_pixel(void *frame_buffer, uint x, uint y, uint stride) {};
|
||||
void PicoGraphics::palette_lookup(void *frame_buffer, void *result, uint offset, uint length) {};
|
||||
|
||||
void PicoGraphics::set_dimensions(int width, int height) {
|
||||
bounds.w = width;
|
||||
bounds.h = height;
|
||||
clip.w = width;
|
||||
clip.h = height;
|
||||
}
|
||||
|
||||
void *PicoGraphics::get_data() {
|
||||
return frame_buffer;
|
||||
}
|
||||
|
||||
void PicoGraphics::get_data(uint y, void *row_buf) {
|
||||
palette_lookup(frame_buffer, row_buf, y * bounds.w, bounds.w);
|
||||
}
|
||||
|
||||
void PicoGraphics::set_font(const bitmap::font_t *font){
|
||||
this->font = font;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void PicoGraphics<T>::set_pen(uint16_t p) {
|
||||
pen.set_color(p);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void PicoGraphics<T>::set_clip(const Rect &r) {
|
||||
void PicoGraphics::set_clip(const Rect &r) {
|
||||
clip = bounds.intersection(r);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void PicoGraphics<T>::remove_clip() {
|
||||
void PicoGraphics::remove_clip() {
|
||||
clip = bounds;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void PicoGraphics<T>::clear() {
|
||||
void PicoGraphics::clear() {
|
||||
rectangle(clip);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void PicoGraphics<T>::pixel(const Point &p) {
|
||||
void PicoGraphics::pixel(const Point &p) {
|
||||
if(!clip.contains(p)) return;
|
||||
pen.set_pixel(frame_buffer, p.x, p.y, bounds.w);
|
||||
set_pixel(frame_buffer, p.x, p.y, bounds.w);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void PicoGraphics<T>::pixel_span(const Point &p, int32_t l) {
|
||||
void PicoGraphics::pixel_span(const Point &p, int32_t l) {
|
||||
// check if span in bounds
|
||||
if( p.x + l < clip.x || p.x >= clip.x + clip.w ||
|
||||
p.y < clip.y || p.y >= clip.y + clip.h) return;
|
||||
|
@ -46,13 +58,12 @@ namespace pimoroni {
|
|||
|
||||
Point dest(clipped.x, clipped.y);
|
||||
while(l--) {
|
||||
pen.set_pixel(frame_buffer, dest.x, dest.y, bounds.w);
|
||||
set_pixel(frame_buffer, dest.x, dest.y, bounds.w);
|
||||
dest.x++;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void PicoGraphics<T>::rectangle(const Rect &r) {
|
||||
void PicoGraphics::rectangle(const Rect &r) {
|
||||
// clip and/or discard depending on rectangle visibility
|
||||
Rect clipped = r.intersection(clip);
|
||||
|
||||
|
@ -62,18 +73,12 @@ namespace pimoroni {
|
|||
while(clipped.h--) {
|
||||
// draw span of pixels for this row
|
||||
pixel_span(dest, clipped.w);
|
||||
/*for(int32_t i = 0; i < clipped.w; i++) {
|
||||
pen.set_pixel(frame_buffer, dest.x, dest.y, bounds.w);
|
||||
dest.x++;
|
||||
}*/
|
||||
|
||||
// move to next scanline
|
||||
dest.y++;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void PicoGraphics<T>::circle(const Point &p, int32_t radius) {
|
||||
void PicoGraphics::circle(const Point &p, int32_t radius) {
|
||||
// circle in screen bounds?
|
||||
Rect bounds = Rect(p.x - radius, p.y - radius, radius * 2, radius * 2);
|
||||
if(!bounds.intersects(clip)) return;
|
||||
|
@ -101,22 +106,19 @@ namespace pimoroni {
|
|||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void PicoGraphics<T>::character(const char c, const Point &p, uint8_t scale) {
|
||||
void PicoGraphics::character(const char c, const Point &p, uint8_t scale) {
|
||||
bitmap::character(font, [this](int32_t x, int32_t y, int32_t w, int32_t h){
|
||||
rectangle(Rect(x, y, w, h));
|
||||
}, c, p.x, p.y, scale);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void PicoGraphics<T>::text(const std::string &t, const Point &p, int32_t wrap, uint8_t scale) {
|
||||
void PicoGraphics::text(const std::string &t, const Point &p, int32_t wrap, uint8_t scale) {
|
||||
bitmap::text(font, [this](int32_t x, int32_t y, int32_t w, int32_t h){
|
||||
rectangle(Rect(x, y, w, h));
|
||||
}, t, p.x, p.y, wrap, scale);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
int32_t PicoGraphics<T>::measure_text(const std::string &t, uint8_t scale) {
|
||||
int32_t PicoGraphics::measure_text(const std::string &t, uint8_t scale) {
|
||||
return bitmap::measure_text(font, t, scale);
|
||||
}
|
||||
|
||||
|
@ -128,8 +130,7 @@ namespace pimoroni {
|
|||
return (p1.y == p2.y && p1.x > p2.x) || (p1.y < p2.y);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void PicoGraphics<T>::triangle(Point p1, Point p2, Point p3) {
|
||||
void PicoGraphics::triangle(Point p1, Point p2, Point p3) {
|
||||
Rect triangle_bounds(
|
||||
Point(std::min(p1.x, std::min(p2.x, p3.x)), std::min(p1.y, std::min(p2.y, p3.y))),
|
||||
Point(std::max(p1.x, std::max(p2.x, p3.x)), std::max(p1.y, std::max(p2.y, p3.y))));
|
||||
|
@ -174,7 +175,7 @@ namespace pimoroni {
|
|||
Point dest = Point(triangle_bounds.x, triangle_bounds.y + y);
|
||||
for (int32_t x = 0; x < triangle_bounds.w; x++) {
|
||||
if ((w0 | w1 | w2) >= 0) {
|
||||
pen.set_pixel(frame_buffer, dest.x, dest.y, bounds.w);
|
||||
set_pixel(frame_buffer, dest.x, dest.y, bounds.w);
|
||||
}
|
||||
|
||||
dest.x++;
|
||||
|
@ -190,8 +191,7 @@ namespace pimoroni {
|
|||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void PicoGraphics<T>::polygon(const std::vector<Point> &points) {
|
||||
void PicoGraphics::polygon(const std::vector<Point> &points) {
|
||||
static int32_t nodes[64]; // maximum allowed number of nodes per scanline for polygon rendering
|
||||
|
||||
int32_t miny = points[0].y, maxy = points[0].y;
|
||||
|
@ -237,8 +237,7 @@ namespace pimoroni {
|
|||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void PicoGraphics<T>::line(Point p1, Point p2) {
|
||||
void PicoGraphics::line(Point p1, Point p2) {
|
||||
// fast horizontal line
|
||||
if(p1.y == p2.y) {
|
||||
int32_t start = std::max(clip.x, std::min(p1.x, p2.x));
|
||||
|
@ -253,7 +252,7 @@ namespace pimoroni {
|
|||
int32_t length = std::min(clip.y + clip.h, std::max(p1.y, p2.y)) - start;
|
||||
Point dest(p1.x, start);
|
||||
while(length--) {
|
||||
pen.set_pixel(frame_buffer, dest.x, dest.y, bounds.w);
|
||||
set_pixel(frame_buffer, dest.x, dest.y, bounds.w);
|
||||
dest.y++;
|
||||
}
|
||||
return;
|
||||
|
@ -273,7 +272,7 @@ namespace pimoroni {
|
|||
int32_t x = p1.x;
|
||||
int32_t y = p1.y << 16;
|
||||
while(s--) {
|
||||
pen.set_pixel(frame_buffer, x, y >> 16, bounds.w);
|
||||
set_pixel(frame_buffer, x, y >> 16, bounds.w);
|
||||
y += sy;
|
||||
x += sx;
|
||||
}
|
||||
|
@ -285,7 +284,7 @@ namespace pimoroni {
|
|||
int32_t y = p1.y;
|
||||
int32_t x = p1.x << 16;
|
||||
while(s--) {
|
||||
pen.set_pixel(frame_buffer, x >> 16, y, bounds.w);
|
||||
set_pixel(frame_buffer, x >> 16, y, bounds.w);
|
||||
y += sy;
|
||||
x += sx;
|
||||
}
|
||||
|
|
|
@ -5,9 +5,14 @@
|
|||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include "libraries/bitmap_fonts/font6_data.hpp"
|
||||
#include "common/pimoroni_common.hpp"
|
||||
|
||||
// a tiny little graphics library for our Pico products
|
||||
// supports only 16-bit (565) RGB framebuffers
|
||||
// A tiny graphics library for our Pico products
|
||||
// supports:
|
||||
// - 16-bit (565) RGB
|
||||
// - 8-bit (332) RGB
|
||||
// - 8-bit with 16-bit 256 entry palette
|
||||
// - 4-bit with 16-bit 8 entry palette
|
||||
namespace pimoroni {
|
||||
typedef uint8_t RGB332;
|
||||
typedef uint16_t RGB565;
|
||||
|
@ -44,48 +49,95 @@ namespace pimoroni {
|
|||
void deflate(int32_t v);
|
||||
};
|
||||
|
||||
class PicoGraphicsPenType {
|
||||
public:
|
||||
class PicoGraphics {
|
||||
public:
|
||||
struct PaletteEntry {
|
||||
RGB565 color;
|
||||
bool used;
|
||||
};
|
||||
|
||||
struct PaletteEntry {
|
||||
RGB565 color;
|
||||
bool used;
|
||||
};
|
||||
enum PenType {
|
||||
PEN_P2 = 0,
|
||||
PEN_P4,
|
||||
PEN_P8,
|
||||
PEN_RGB332,
|
||||
PEN_RGB565
|
||||
};
|
||||
|
||||
static constexpr RGB332 rgb_to_rgb332(uint8_t r, uint8_t g, uint8_t b) {
|
||||
return (r & 0b11100000) | ((g & 0b11100000) >> 3) | ((b & 0b11000000) >> 6);
|
||||
}
|
||||
void *frame_buffer;
|
||||
|
||||
static constexpr RGB565 rgb332_to_rgb565(RGB332 c) {
|
||||
uint16_t p = ((c & 0b11100000) << 8) |
|
||||
((c & 0b00011100) << 6) |
|
||||
((c & 0b00000011) << 3);
|
||||
return __builtin_bswap16(p);
|
||||
}
|
||||
PenType pen_type;
|
||||
Rect bounds;
|
||||
Rect clip;
|
||||
|
||||
static constexpr RGB565 rgb_to_rgb565(uint8_t r, uint8_t g, uint8_t b) {
|
||||
uint16_t p = ((r & 0b11111000) << 8) |
|
||||
((g & 0b11111100) << 3) |
|
||||
((b & 0b11111000) >> 3);
|
||||
const bitmap::font_t *font;
|
||||
|
||||
return __builtin_bswap16(p);
|
||||
}
|
||||
static constexpr RGB332 rgb_to_rgb332(uint8_t r, uint8_t g, uint8_t b) {
|
||||
return (r & 0b11100000) | ((g & 0b11100000) >> 3) | ((b & 0b11000000) >> 6);
|
||||
}
|
||||
|
||||
virtual void set_pixel(void *frame_buffer, uint x, uint y, uint stride);
|
||||
virtual int create(uint8_t r, uint8_t g, uint8_t b);
|
||||
virtual void set_color(uint c);
|
||||
virtual void set_color(uint8_t r, uint8_t g, uint8_t b);
|
||||
virtual void update_color(uint8_t i, uint8_t r, uint8_t g, uint8_t b);
|
||||
static constexpr RGB565 rgb332_to_rgb565(RGB332 c) {
|
||||
uint16_t p = ((c & 0b11100000) << 8) |
|
||||
((c & 0b00011100) << 6) |
|
||||
((c & 0b00000011) << 3);
|
||||
return __builtin_bswap16(p);
|
||||
}
|
||||
|
||||
virtual void palette_lookup(void *frame_buffer, void *result, uint offset, uint length);
|
||||
static size_t buffer_size(uint w, uint h); // Must be static, since user must know required size to alloc framebuffer
|
||||
static constexpr RGB565 rgb_to_rgb565(uint8_t r, uint8_t g, uint8_t b) {
|
||||
uint16_t p = ((r & 0b11111000) << 8) |
|
||||
((g & 0b11111100) << 3) |
|
||||
((b & 0b11111000) >> 3);
|
||||
|
||||
return __builtin_bswap16(p);
|
||||
}
|
||||
|
||||
PicoGraphics(uint16_t width, uint16_t height, void *frame_buffer)
|
||||
: frame_buffer(frame_buffer), bounds(0, 0, width, height), clip(0, 0, width, height) {
|
||||
set_font(&font6);
|
||||
};
|
||||
|
||||
virtual void set_pen(uint c);
|
||||
virtual void set_pen(uint8_t r, uint8_t g, uint8_t b);
|
||||
virtual void update_pen(uint8_t i, uint8_t r, uint8_t g, uint8_t b);
|
||||
virtual void reset_pen(uint8_t i);
|
||||
virtual int create_pen(uint8_t r, uint8_t g, uint8_t b);
|
||||
virtual void set_pixel(void *frame_buffer, uint x, uint y, uint stride);
|
||||
virtual void palette_lookup(void *frame_buffer, void *result, uint offset, uint length);
|
||||
|
||||
void set_font(const bitmap::font_t *font);
|
||||
|
||||
void set_dimensions(int width, int height);
|
||||
|
||||
void *get_data();
|
||||
void get_data(uint y, void *row_buf);
|
||||
|
||||
void set_clip(const Rect &r);
|
||||
void remove_clip();
|
||||
|
||||
void clear();
|
||||
void pixel(const Point &p);
|
||||
void pixel_span(const Point &p, int32_t l);
|
||||
void rectangle(const Rect &r);
|
||||
void circle(const Point &p, int32_t r);
|
||||
void character(const char c, const Point &p, uint8_t scale = 2);
|
||||
void text(const std::string &t, const Point &p, int32_t wrap, uint8_t scale = 2);
|
||||
int32_t measure_text(const std::string &t, uint8_t scale = 2);
|
||||
void polygon(const std::vector<Point> &points);
|
||||
void triangle(Point p1, Point p2, Point p3);
|
||||
void line(Point p1, Point p2);
|
||||
};
|
||||
|
||||
class PenP4 : public PicoGraphicsPenType {
|
||||
|
||||
class PicoGraphics_PenP4 : public PicoGraphics {
|
||||
public:
|
||||
uint8_t color;
|
||||
PaletteEntry palette[8];
|
||||
PenP4() {
|
||||
PicoGraphics_PenP4(uint16_t width, uint16_t height, void *frame_buffer)
|
||||
: PicoGraphics(width, height, frame_buffer) {
|
||||
this->pen_type = PEN_P4;
|
||||
if(this->frame_buffer == nullptr) {
|
||||
this->frame_buffer = (void *)(new uint8_t[buffer_size(width, height)]);
|
||||
}
|
||||
palette[0].color = rgb_to_rgb565(57, 48, 57); // Black
|
||||
palette[1].color = rgb_to_rgb565(255, 255, 255); // White
|
||||
palette[2].color = rgb_to_rgb565(58, 91, 70); // Green
|
||||
|
@ -95,17 +147,12 @@ namespace pimoroni {
|
|||
palette[6].color = rgb_to_rgb565(177, 106, 73); // Orange
|
||||
palette[7].color = rgb_to_rgb565(255, 255, 255); // Clear
|
||||
}
|
||||
void set_color(uint c) {
|
||||
void set_pen(uint c) {
|
||||
color = c & 0xf;
|
||||
}
|
||||
void set_color(uint8_t r, uint8_t g, uint8_t b) override {
|
||||
void set_pen(uint8_t r, uint8_t g, uint8_t b) override {
|
||||
// TODO look up closest palette colour, or just NOOP?
|
||||
}
|
||||
void update_color(uint8_t i, uint8_t r, uint8_t g, uint8_t b) {}
|
||||
void reset_color(uint8_t i) {}
|
||||
int create(uint8_t r, uint8_t g, uint8_t b) override {
|
||||
return -1; // Can never create new colours, fixed palette!
|
||||
}
|
||||
void set_pixel(void *frame_buffer, uint x, uint y, uint stride) override {
|
||||
// pointer to byte in framebuffer that contains this pixel
|
||||
uint8_t *buf = (uint8_t *)frame_buffer;
|
||||
|
@ -133,30 +180,35 @@ namespace pimoroni {
|
|||
}
|
||||
};
|
||||
|
||||
class PenP8 : public PicoGraphicsPenType {
|
||||
class PicoGraphics_PenP8 : public PicoGraphics {
|
||||
public:
|
||||
uint8_t color;
|
||||
PaletteEntry palette[256];
|
||||
PenP8() {
|
||||
PicoGraphics_PenP8(uint16_t width, uint16_t height, void *frame_buffer)
|
||||
: PicoGraphics(width, height, frame_buffer) {
|
||||
this->pen_type = PEN_P8;
|
||||
if(this->frame_buffer == nullptr) {
|
||||
this->frame_buffer = (void *)(new uint8_t[buffer_size(width, height)]);
|
||||
}
|
||||
for(auto i = 0u; i < 256; i++) {
|
||||
reset_color(i);
|
||||
reset_pen(i);
|
||||
}
|
||||
}
|
||||
void set_color(uint c) override {
|
||||
void set_pen(uint c) override {
|
||||
color = c;
|
||||
}
|
||||
void set_color(uint8_t r, uint8_t g, uint8_t b) override {
|
||||
void set_pen(uint8_t r, uint8_t g, uint8_t b) override {
|
||||
// TODO look up closest palette colour, or just NOOP?
|
||||
}
|
||||
void update_color(uint8_t i, uint8_t r, uint8_t g, uint8_t b) {
|
||||
void update_pen(uint8_t i, uint8_t r, uint8_t g, uint8_t b) override {
|
||||
palette[i].color = rgb_to_rgb565(r, g, b);
|
||||
palette[i].used = true;
|
||||
}
|
||||
void reset_color(uint8_t i) {
|
||||
void reset_pen(uint8_t i) override {
|
||||
palette[i].color = 0;
|
||||
palette[i].used = false;
|
||||
}
|
||||
int create(uint8_t r, uint8_t g, uint8_t b) override {
|
||||
int create_pen(uint8_t r, uint8_t g, uint8_t b) override {
|
||||
// Create a colour and place it in the palette if there's space
|
||||
RGB565 c = rgb_to_rgb565(r, g, b);
|
||||
for(auto i = 0u; i < 256u; i++) {
|
||||
|
@ -184,30 +236,35 @@ namespace pimoroni {
|
|||
}
|
||||
};
|
||||
|
||||
class PenRGB332 : public PicoGraphicsPenType {
|
||||
class PicoGraphics_PenRGB332 : public PicoGraphics {
|
||||
public:
|
||||
RGB332 color;
|
||||
PaletteEntry palette[256];
|
||||
PenRGB332() {
|
||||
PicoGraphics_PenRGB332(uint16_t width, uint16_t height, void *frame_buffer)
|
||||
: PicoGraphics(width, height, frame_buffer) {
|
||||
this->pen_type = PEN_RGB332;
|
||||
if(this->frame_buffer == nullptr) {
|
||||
this->frame_buffer = (void *)(new uint8_t[buffer_size(width, height)]);
|
||||
}
|
||||
for(auto i = 0u; i < 256; i++) {
|
||||
reset_color(i);
|
||||
reset_pen(i);
|
||||
}
|
||||
}
|
||||
void set_color(uint c) {
|
||||
void set_pen(uint c) override {
|
||||
color = c;
|
||||
}
|
||||
void set_color(uint8_t r, uint8_t g, uint8_t b) override {
|
||||
void set_pen(uint8_t r, uint8_t g, uint8_t b) override {
|
||||
color = rgb_to_rgb332(r, g, b);
|
||||
}
|
||||
void update_color(uint8_t i, uint8_t r, uint8_t g, uint8_t b) {
|
||||
void update_pen(uint8_t i, uint8_t r, uint8_t g, uint8_t b) override {
|
||||
palette[i].color = rgb_to_rgb565(r, g, b);
|
||||
palette[i].used = true;
|
||||
}
|
||||
void reset_color(uint8_t i) {
|
||||
void reset_pen(uint8_t i) override {
|
||||
palette[i].color = rgb332_to_rgb565(i);
|
||||
palette[i].used = true;
|
||||
}
|
||||
int create(uint8_t r, uint8_t g, uint8_t b) override {
|
||||
int create_pen(uint8_t r, uint8_t g, uint8_t b) override {
|
||||
return rgb_to_rgb332(r, g, b);
|
||||
}
|
||||
void set_pixel(void *frame_buffer, uint x, uint y, uint stride) override {
|
||||
|
@ -226,109 +283,45 @@ namespace pimoroni {
|
|||
}
|
||||
};
|
||||
|
||||
class PenRGB565 : public PicoGraphicsPenType {
|
||||
class PicoGraphics_PenRGB565 : public PicoGraphics {
|
||||
public:
|
||||
uint16_t color;
|
||||
void set_color(uint c) override {
|
||||
RGB565 color;
|
||||
PicoGraphics_PenRGB565(uint16_t width, uint16_t height, void *frame_buffer)
|
||||
: PicoGraphics(width, height, frame_buffer) {
|
||||
this->pen_type = PEN_RGB565;
|
||||
if(this->frame_buffer == nullptr) {
|
||||
this->frame_buffer = (void *)(new uint8_t[buffer_size(width, height)]);
|
||||
}
|
||||
}
|
||||
void set_pen(uint c) override {
|
||||
color = c;
|
||||
}
|
||||
void update_color(uint8_t i, uint8_t r, uint8_t g, uint8_t b) {
|
||||
// Palette only. Does nothing.
|
||||
}
|
||||
void reset_color(uint8_t i) {
|
||||
// Palette only. Does nothing.
|
||||
}
|
||||
void set_color(uint8_t r, uint8_t g, uint8_t b) override {
|
||||
void set_pen(uint8_t r, uint8_t g, uint8_t b) override {
|
||||
color = rgb_to_rgb565(r, g, b);
|
||||
}
|
||||
int create(uint8_t r, uint8_t g, uint8_t b) override {
|
||||
int create_pen(uint8_t r, uint8_t g, uint8_t b) override {
|
||||
return rgb_to_rgb565(r, g, b);
|
||||
}
|
||||
void set_pixel(void *frame_buffer, uint x, uint y, uint stride) override {
|
||||
uint16_t *buf = (uint16_t *)frame_buffer;
|
||||
buf[y * stride + x] = color;
|
||||
}
|
||||
void palette_lookup(void *frame_buffer, void *result, uint offset, uint length) override {
|
||||
}
|
||||
static size_t buffer_size(uint w, uint h) {
|
||||
return w * h * sizeof(RGB565);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T=PicoGraphicsPenType>
|
||||
class PicoGraphics {
|
||||
public:
|
||||
void *frame_buffer;
|
||||
class DisplayDriver {
|
||||
public:
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
Rotation rotation;
|
||||
|
||||
Rect bounds;
|
||||
Rect clip;
|
||||
DisplayDriver(uint16_t width, uint16_t height, Rotation rotation)
|
||||
: width(width), height(height), rotation(rotation) {};
|
||||
|
||||
const bitmap::font_t *font;
|
||||
|
||||
T pen;
|
||||
|
||||
public:
|
||||
PicoGraphics(uint16_t width, uint16_t height, void *frame_buffer)
|
||||
: frame_buffer(frame_buffer), bounds(0, 0, width, height), clip(0, 0, width, height) {
|
||||
set_font(&font6);
|
||||
if(this->frame_buffer == nullptr) {
|
||||
this->frame_buffer = (void *)(new uint8_t[pen.buffer_size(width, height)]);
|
||||
}
|
||||
};
|
||||
|
||||
void set_font(const bitmap::font_t *font);
|
||||
void set_pen(uint16_t p);
|
||||
|
||||
int create_pen(uint8_t r, uint8_t g, uint8_t b) {
|
||||
return pen.create(r, g, b);
|
||||
}
|
||||
|
||||
void set_pen(uint8_t r, uint8_t g, uint8_t b) {
|
||||
pen.set_color(r, g, b);
|
||||
}
|
||||
|
||||
void update_pen(uint8_t i, uint8_t r, uint8_t g, uint8_t b) {
|
||||
pen.update_color(i, r, g, b);
|
||||
}
|
||||
|
||||
void reset_pen(uint8_t i) {
|
||||
pen.reset_color(i);
|
||||
}
|
||||
|
||||
void set_dimensions(int width, int height) {
|
||||
bounds.w = width;
|
||||
bounds.h = height;
|
||||
clip.w = width;
|
||||
clip.h = height;
|
||||
}
|
||||
|
||||
void set_clip(const Rect &r);
|
||||
void remove_clip();
|
||||
|
||||
void *get_data() {
|
||||
return frame_buffer;
|
||||
}
|
||||
|
||||
void get_data(uint y, void *row_buf) {
|
||||
pen.palette_lookup(frame_buffer, row_buf, y * bounds.w, bounds.w);
|
||||
}
|
||||
|
||||
void clear();
|
||||
void pixel(const Point &p);
|
||||
void pixel_span(const Point &p, int32_t l);
|
||||
void rectangle(const Rect &r);
|
||||
void circle(const Point &p, int32_t r);
|
||||
void character(const char c, const Point &p, uint8_t scale = 2);
|
||||
void text(const std::string &t, const Point &p, int32_t wrap, uint8_t scale = 2);
|
||||
int32_t measure_text(const std::string &t, uint8_t scale = 2);
|
||||
void polygon(const std::vector<Point> &points);
|
||||
void triangle(Point p1, Point p2, Point p3);
|
||||
void line(Point p1, Point p2);
|
||||
virtual void update(PicoGraphics *display);
|
||||
virtual void set_backlight(uint8_t brightness);
|
||||
};
|
||||
|
||||
template class PicoGraphics<PenP4>;
|
||||
template class PicoGraphics<PenP8>;
|
||||
template class PicoGraphics<PenRGB332>;
|
||||
template class PicoGraphics<PenRGB565>;
|
||||
|
||||
}
|
||||
|
|
|
@ -6,32 +6,30 @@
|
|||
|
||||
namespace pimoroni {
|
||||
|
||||
template <class T=PicoGraphicsPenType>
|
||||
class PicoGraphicsST7789 : public PicoGraphics<T> {
|
||||
class PicoGraphicsST7789 : public PicoGraphics_PenRGB565 {
|
||||
private:
|
||||
ST7789 st7789;
|
||||
|
||||
public:
|
||||
PicoGraphicsST7789(uint16_t width, uint16_t height, Rotation rotation, bool round=false, void *frame_buffer=nullptr) :
|
||||
PicoGraphics<T>(width, height, frame_buffer),
|
||||
PicoGraphics_PenRGB565(width, height, frame_buffer),
|
||||
st7789(width, height, rotation, round, get_spi_pins(BG_SPI_FRONT)) {
|
||||
common_init();
|
||||
};
|
||||
|
||||
PicoGraphicsST7789(uint16_t width, uint16_t height, Rotation rotation, bool round, void *frame_buffer, SPIPins bus_pins) :
|
||||
PicoGraphics<T>(width, height, frame_buffer),
|
||||
PicoGraphics_PenRGB565(width, height, frame_buffer),
|
||||
st7789(width, height, rotation, round, bus_pins) {
|
||||
common_init();
|
||||
};
|
||||
|
||||
PicoGraphicsST7789(uint16_t width, uint16_t height, Rotation rotation, void *frame_buffer, ParallelPins bus_pins) :
|
||||
PicoGraphics<T>(width, height, frame_buffer),
|
||||
PicoGraphics_PenRGB565(width, height, frame_buffer),
|
||||
st7789(width, height, rotation, bus_pins) {
|
||||
common_init();
|
||||
};
|
||||
|
||||
void common_init() {
|
||||
st7789.init();
|
||||
this->set_dimensions(st7789.width, st7789.height);
|
||||
st7789.update(this);
|
||||
}
|
||||
|
|
|
@ -10,9 +10,7 @@ include(breakout_dotmatrix/micropython)
|
|||
include(breakout_encoder/micropython)
|
||||
include(breakout_ioexpander/micropython)
|
||||
include(breakout_ltr559/micropython)
|
||||
include(breakout_colourlcd160x80/micropython)
|
||||
include(breakout_as7262/micropython)
|
||||
#include(breakout_roundlcd/micropython) # replaced with Generic ST7789
|
||||
include(breakout_rgbmatrix5x5/micropython)
|
||||
include(breakout_matrix11x7/micropython)
|
||||
include(breakout_msa301/micropython)
|
||||
|
@ -22,7 +20,6 @@ include(breakout_potentiometer/micropython)
|
|||
include(breakout_rtc/micropython)
|
||||
include(breakout_trackball/micropython)
|
||||
include(breakout_sgp30/micropython)
|
||||
# include(breakout_colourlcd240x240/micropython) # replaced with Generic ST7789
|
||||
include(breakout_bh1745/micropython)
|
||||
include(breakout_bme68x/micropython)
|
||||
include(breakout_bme280/micropython)
|
||||
|
|
|
@ -1,95 +0,0 @@
|
|||
#include "breakout_colourlcd160x80.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// BreakoutColourLCD160x80 Class
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Module functions
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(BreakoutColourLCD160x80_module_RGB565_obj, BreakoutColourLCD160x80_module_RGB565);
|
||||
|
||||
// Class Methods
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(BreakoutColourLCD160x80_update_obj, BreakoutColourLCD160x80_update);
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(BreakoutColourLCD160x80_set_backlight_obj, BreakoutColourLCD160x80_set_backlight);
|
||||
|
||||
// Pen
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(BreakoutColourLCD160x80_set_pen_obj, BreakoutColourLCD160x80_set_pen);
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(BreakoutColourLCD160x80_create_pen_obj, 4, 4, BreakoutColourLCD160x80_create_pen);
|
||||
|
||||
// Primitives
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(BreakoutColourLCD160x80_set_clip_obj, 5, 5, BreakoutColourLCD160x80_set_clip);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(BreakoutColourLCD160x80_remove_clip_obj, BreakoutColourLCD160x80_remove_clip);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(BreakoutColourLCD160x80_clear_obj, BreakoutColourLCD160x80_clear);
|
||||
MP_DEFINE_CONST_FUN_OBJ_3(BreakoutColourLCD160x80_pixel_obj, BreakoutColourLCD160x80_pixel);
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(BreakoutColourLCD160x80_pixel_span_obj, 4, 4, BreakoutColourLCD160x80_pixel_span);
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(BreakoutColourLCD160x80_rectangle_obj, 5, 5, BreakoutColourLCD160x80_rectangle);
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(BreakoutColourLCD160x80_circle_obj, 4, 4, BreakoutColourLCD160x80_circle);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutColourLCD160x80_character_obj, 1, BreakoutColourLCD160x80_character);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutColourLCD160x80_text_obj, 1, BreakoutColourLCD160x80_text);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutColourLCD160x80_measure_text_obj, 1, BreakoutColourLCD160x80_measure_text);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutColourLCD160x80_polygon_obj, 2, BreakoutColourLCD160x80_polygon);
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(BreakoutColourLCD160x80_triangle_obj, 7, 7, BreakoutColourLCD160x80_triangle);
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(BreakoutColourLCD160x80_line_obj, 5, 5, BreakoutColourLCD160x80_line);
|
||||
|
||||
// Utility
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(BreakoutColourLCD160x80_get_bounds_obj, BreakoutColourLCD160x80_get_bounds);
|
||||
|
||||
/***** Binding of Methods *****/
|
||||
STATIC const mp_rom_map_elem_t BreakoutColourLCD160x80_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_pixel), MP_ROM_PTR(&BreakoutColourLCD160x80_pixel_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_pen), MP_ROM_PTR(&BreakoutColourLCD160x80_set_pen_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&BreakoutColourLCD160x80_update_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_backlight), MP_ROM_PTR(&BreakoutColourLCD160x80_set_backlight_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_create_pen), MP_ROM_PTR(&BreakoutColourLCD160x80_create_pen_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_clip), MP_ROM_PTR(&BreakoutColourLCD160x80_set_clip_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_remove_clip), MP_ROM_PTR(&BreakoutColourLCD160x80_remove_clip_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&BreakoutColourLCD160x80_clear_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_pixel_span), MP_ROM_PTR(&BreakoutColourLCD160x80_pixel_span_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_rectangle), MP_ROM_PTR(&BreakoutColourLCD160x80_rectangle_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_circle), MP_ROM_PTR(&BreakoutColourLCD160x80_circle_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_character), MP_ROM_PTR(&BreakoutColourLCD160x80_character_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_text), MP_ROM_PTR(&BreakoutColourLCD160x80_text_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_measure_text), MP_ROM_PTR(&BreakoutColourLCD160x80_measure_text_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_polygon), MP_ROM_PTR(&BreakoutColourLCD160x80_polygon_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_triangle), MP_ROM_PTR(&BreakoutColourLCD160x80_triangle_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_line), MP_ROM_PTR(&BreakoutColourLCD160x80_line_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_get_bounds), MP_ROM_PTR(&BreakoutColourLCD160x80_get_bounds_obj) }
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(BreakoutColourLCD160x80_locals_dict, BreakoutColourLCD160x80_locals_dict_table);
|
||||
|
||||
/***** Class Definition *****/
|
||||
const mp_obj_type_t BreakoutColourLCD160x80_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_breakout_colourlcd160x80,
|
||||
.make_new = BreakoutColourLCD160x80_make_new,
|
||||
.locals_dict = (mp_obj_dict_t*)&BreakoutColourLCD160x80_locals_dict,
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// breakout_colourlcd160x80 Module
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/***** Globals Table *****/
|
||||
STATIC const mp_map_elem_t breakout_colourlcd160x80_globals_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_breakout_colourlcd160x80) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_BreakoutColourLCD160x80), (mp_obj_t)&BreakoutColourLCD160x80_type },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_RGB565), MP_ROM_PTR(&BreakoutColourLCD160x80_module_RGB565_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_WIDTH), MP_ROM_INT(WIDTH) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_HEIGHT), MP_ROM_INT(HEIGHT) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(mp_module_breakout_colourlcd160x80_globals, breakout_colourlcd160x80_globals_table);
|
||||
|
||||
/***** Module Definition *****/
|
||||
const mp_obj_module_t breakout_colourlcd160x80_user_cmodule = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&mp_module_breakout_colourlcd160x80_globals,
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
MP_REGISTER_MODULE(MP_QSTR_breakout_colourlcd160x80, breakout_colourlcd160x80_user_cmodule, MODULE_BREAKOUT_COLOURLCD160X80_ENABLED);
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
@ -1,403 +0,0 @@
|
|||
#include "libraries/breakout_colourlcd160x80/breakout_colourlcd160x80.hpp"
|
||||
#include "common/pimoroni_common.hpp"
|
||||
#include "common/pimoroni_bus.hpp"
|
||||
|
||||
#include "micropython/modules/util.hpp"
|
||||
|
||||
|
||||
using namespace pimoroni;
|
||||
|
||||
extern "C" {
|
||||
#include "breakout_colourlcd160x80.h"
|
||||
#include "micropython/modules/pimoroni_bus/pimoroni_bus.h"
|
||||
|
||||
/***** Variables Struct *****/
|
||||
typedef struct _BreakoutColourLCD160x80_obj_t {
|
||||
mp_obj_base_t base;
|
||||
BreakoutColourLCD160x80 *breakout;
|
||||
void *buffer;
|
||||
} BreakoutColourLCD160x80_obj_t;
|
||||
|
||||
|
||||
/***** Constructor *****/
|
||||
mp_obj_t BreakoutColourLCD160x80_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
BreakoutColourLCD160x80_obj_t *self = nullptr;
|
||||
|
||||
enum { ARG_bus, ARG_buffer };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_bus, MP_ARG_OBJ, { .u_obj = mp_const_none } },
|
||||
{ MP_QSTR_buffer, MP_ARG_OBJ, { .u_obj = mp_const_none } },
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
self = m_new_obj(BreakoutColourLCD160x80_obj_t);
|
||||
self->base.type = &BreakoutColourLCD160x80_type;
|
||||
|
||||
// Get or create a suitable framebuffer
|
||||
// save a pointer onto the object so that GC can find it
|
||||
size_t required_size = PenRGB565::buffer_size(WIDTH, HEIGHT);
|
||||
|
||||
if (args[ARG_buffer].u_obj != mp_const_none) {
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_RW);
|
||||
self->buffer = bufinfo.buf;
|
||||
if(bufinfo.len < (size_t)(required_size)) {
|
||||
mp_raise_ValueError("Supplied buffer is too small!");
|
||||
}
|
||||
} else {
|
||||
self->buffer = m_new(uint8_t, required_size);
|
||||
}
|
||||
|
||||
// Check the bus argument for a valid SPIBus
|
||||
// or just build the class and accept the defaults.
|
||||
if (args[ARG_bus].u_obj == mp_const_none) {
|
||||
self->breakout = m_new_class(BreakoutColourLCD160x80, self->buffer);
|
||||
} 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);
|
||||
self->breakout = m_new_class(BreakoutColourLCD160x80, self->buffer, *(SPIPins *)(bus->pins));
|
||||
} else {
|
||||
mp_raise_ValueError("SPIBus expected!");
|
||||
}
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
/***** Methods *****/
|
||||
mp_obj_t BreakoutColourLCD160x80_get_bounds(mp_obj_t self_in) {
|
||||
BreakoutColourLCD160x80_obj_t *self = MP_OBJ_TO_PTR2(self_in, BreakoutColourLCD160x80_obj_t);
|
||||
mp_obj_t tuple[2] = {
|
||||
mp_obj_new_int(self->breakout->bounds.w),
|
||||
mp_obj_new_int(self->breakout->bounds.h)
|
||||
};
|
||||
return mp_obj_new_tuple(2, tuple);
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD160x80_update(mp_obj_t self_in) {
|
||||
BreakoutColourLCD160x80_obj_t *self = MP_OBJ_TO_PTR2(self_in, BreakoutColourLCD160x80_obj_t);
|
||||
self->breakout->update();
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD160x80_set_backlight(mp_obj_t self_in, mp_obj_t brightness) {
|
||||
BreakoutColourLCD160x80_obj_t *self = MP_OBJ_TO_PTR2(self_in, BreakoutColourLCD160x80_obj_t);
|
||||
|
||||
float b = mp_obj_get_float(brightness);
|
||||
|
||||
if(b < 0 || b > 1.0f) mp_raise_ValueError("brightness out of range. Expected 0.0 to 1.0");
|
||||
|
||||
self->breakout->set_backlight((uint8_t)(b * 255.0f));
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD160x80_module_RGB332(mp_obj_t r, mp_obj_t g, mp_obj_t b) {
|
||||
return mp_obj_new_int(PicoGraphicsPenType::rgb_to_rgb332(
|
||||
mp_obj_get_int(r),
|
||||
mp_obj_get_int(g),
|
||||
mp_obj_get_int(b)
|
||||
));
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD160x80_module_RGB565(mp_obj_t r, mp_obj_t g, mp_obj_t b) {
|
||||
return mp_obj_new_int(PicoGraphicsPenType::rgb_to_rgb565(
|
||||
mp_obj_get_int(r),
|
||||
mp_obj_get_int(g),
|
||||
mp_obj_get_int(b)
|
||||
));
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD160x80_set_pen(mp_obj_t self_in, mp_obj_t pen) {
|
||||
BreakoutColourLCD160x80_obj_t *self = MP_OBJ_TO_PTR2(self_in, BreakoutColourLCD160x80_obj_t);
|
||||
|
||||
self->breakout->set_pen(mp_obj_get_int(pen));
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD160x80_reset_pen(mp_obj_t self_in, mp_obj_t pen) {
|
||||
BreakoutColourLCD160x80_obj_t *self = MP_OBJ_TO_PTR2(self_in, BreakoutColourLCD160x80_obj_t);
|
||||
|
||||
self->breakout->reset_pen(mp_obj_get_int(pen));
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD160x80_update_pen(size_t n_args, const mp_obj_t *args) {
|
||||
enum { ARG_self, ARG_i, ARG_r, ARG_g, ARG_b };
|
||||
|
||||
BreakoutColourLCD160x80_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self], BreakoutColourLCD160x80_obj_t);
|
||||
|
||||
self->breakout->update_pen(
|
||||
mp_obj_get_int(args[ARG_i]) & 0xff,
|
||||
mp_obj_get_int(args[ARG_r]) & 0xff,
|
||||
mp_obj_get_int(args[ARG_g]) & 0xff,
|
||||
mp_obj_get_int(args[ARG_b]) & 0xff
|
||||
);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD160x80_create_pen(size_t n_args, const mp_obj_t *args) {
|
||||
enum { ARG_self, ARG_r, ARG_g, ARG_b };
|
||||
|
||||
BreakoutColourLCD160x80_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self], BreakoutColourLCD160x80_obj_t);
|
||||
|
||||
int result = self->breakout->create_pen(
|
||||
mp_obj_get_int(args[ARG_r]) & 0xff,
|
||||
mp_obj_get_int(args[ARG_g]) & 0xff,
|
||||
mp_obj_get_int(args[ARG_b]) & 0xff
|
||||
);
|
||||
|
||||
if (result == -1) mp_raise_ValueError("create_pen failed. No matching colour or space in palette!");
|
||||
|
||||
return mp_obj_new_int(result);
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD160x80_set_clip(size_t n_args, const mp_obj_t *args) {
|
||||
enum { ARG_self, ARG_x, ARG_y, ARG_w, ARG_h };
|
||||
|
||||
BreakoutColourLCD160x80_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self], BreakoutColourLCD160x80_obj_t);
|
||||
|
||||
self->breakout->set_clip({
|
||||
mp_obj_get_int(args[ARG_x]),
|
||||
mp_obj_get_int(args[ARG_y]),
|
||||
mp_obj_get_int(args[ARG_w]),
|
||||
mp_obj_get_int(args[ARG_h])
|
||||
});
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD160x80_remove_clip(mp_obj_t self_in) {
|
||||
BreakoutColourLCD160x80_obj_t *self = MP_OBJ_TO_PTR2(self_in, BreakoutColourLCD160x80_obj_t);
|
||||
|
||||
self->breakout->remove_clip();
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD160x80_clear(mp_obj_t self_in) {
|
||||
BreakoutColourLCD160x80_obj_t *self = MP_OBJ_TO_PTR2(self_in, BreakoutColourLCD160x80_obj_t);
|
||||
|
||||
self->breakout->clear();
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD160x80_pixel(mp_obj_t self_in, mp_obj_t x, mp_obj_t y) {
|
||||
BreakoutColourLCD160x80_obj_t *self = MP_OBJ_TO_PTR2(self_in, BreakoutColourLCD160x80_obj_t);
|
||||
|
||||
self->breakout->pixel({
|
||||
mp_obj_get_int(x),
|
||||
mp_obj_get_int(y)
|
||||
});
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD160x80_pixel_span(size_t n_args, const mp_obj_t *args) {
|
||||
enum { ARG_self, ARG_x, ARG_y, ARG_l };
|
||||
|
||||
BreakoutColourLCD160x80_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self], BreakoutColourLCD160x80_obj_t);
|
||||
|
||||
self->breakout->pixel_span({
|
||||
mp_obj_get_int(args[ARG_x]),
|
||||
mp_obj_get_int(args[ARG_y])
|
||||
}, mp_obj_get_int(args[ARG_l]));
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD160x80_rectangle(size_t n_args, const mp_obj_t *args) {
|
||||
enum { ARG_self, ARG_x, ARG_y, ARG_w, ARG_h };
|
||||
|
||||
BreakoutColourLCD160x80_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self], BreakoutColourLCD160x80_obj_t);
|
||||
|
||||
self->breakout->rectangle({
|
||||
mp_obj_get_int(args[ARG_x]),
|
||||
mp_obj_get_int(args[ARG_y]),
|
||||
mp_obj_get_int(args[ARG_w]),
|
||||
mp_obj_get_int(args[ARG_h])
|
||||
});
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD160x80_circle(size_t n_args, const mp_obj_t *args) {
|
||||
enum { ARG_self, ARG_x, ARG_y, ARG_r };
|
||||
|
||||
BreakoutColourLCD160x80_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self], BreakoutColourLCD160x80_obj_t);
|
||||
|
||||
self->breakout->circle({
|
||||
mp_obj_get_int(args[ARG_x]),
|
||||
mp_obj_get_int(args[ARG_y])
|
||||
}, mp_obj_get_int(args[ARG_r]));
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD160x80_character(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_self, ARG_char, ARG_x, ARG_y, ARG_scale };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_char, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_x, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_scale, MP_ARG_INT, {.u_int = 2} },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
BreakoutColourLCD160x80_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, BreakoutColourLCD160x80_obj_t);
|
||||
|
||||
int c = mp_obj_get_int(args[ARG_char].u_obj);
|
||||
int x = args[ARG_x].u_int;
|
||||
int y = args[ARG_y].u_int;
|
||||
int scale = args[ARG_scale].u_int;
|
||||
|
||||
self->breakout->character((char)c, Point(x, y), scale);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD160x80_text(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_self, ARG_text, ARG_x, ARG_y, ARG_wrap, ARG_scale };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_text, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_x1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_wordwrap, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_scale, MP_ARG_INT, {.u_int = 2} },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
BreakoutColourLCD160x80_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, BreakoutColourLCD160x80_obj_t);
|
||||
|
||||
mp_obj_t text_obj = args[ARG_text].u_obj;
|
||||
|
||||
if(!mp_obj_is_str_or_bytes(text_obj)) mp_raise_TypeError("text: string required");
|
||||
|
||||
GET_STR_DATA_LEN(text_obj, str, str_len);
|
||||
|
||||
std::string t((const char*)str);
|
||||
|
||||
int x = args[ARG_x].u_int;
|
||||
int y = args[ARG_y].u_int;
|
||||
int wrap = args[ARG_wrap].u_int;
|
||||
int scale = args[ARG_scale].u_int;
|
||||
|
||||
self->breakout->text(t, Point(x, y), wrap, scale);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD160x80_measure_text(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_self, ARG_text, ARG_scale };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_text, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_scale, MP_ARG_INT, {.u_int = 2} },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
BreakoutColourLCD160x80_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, BreakoutColourLCD160x80_obj_t);
|
||||
|
||||
mp_obj_t text_obj = args[ARG_text].u_obj;
|
||||
|
||||
if(!mp_obj_is_str_or_bytes(text_obj)) mp_raise_TypeError("text: string required");
|
||||
|
||||
GET_STR_DATA_LEN(text_obj, str, str_len);
|
||||
|
||||
std::string t((const char*)str);
|
||||
|
||||
int scale = args[ARG_scale].u_int;
|
||||
|
||||
int width = self->breakout->measure_text(t, scale);
|
||||
|
||||
return mp_obj_new_int(width);
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD160x80_polygon(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
size_t num_tuples = n_args - 1;
|
||||
const mp_obj_t *tuples = pos_args + 1;
|
||||
|
||||
BreakoutColourLCD160x80_obj_t *self = MP_OBJ_TO_PTR2(pos_args[0], BreakoutColourLCD160x80_obj_t);
|
||||
|
||||
// Check if there is only one argument, which might be a list
|
||||
if(n_args == 2) {
|
||||
if(mp_obj_is_type(pos_args[1], &mp_type_list)) {
|
||||
mp_obj_list_t *points = MP_OBJ_TO_PTR2(pos_args[1], mp_obj_list_t);
|
||||
|
||||
if(points->len <= 0) mp_raise_ValueError("poly(): cannot provide an empty list");
|
||||
|
||||
num_tuples = points->len;
|
||||
tuples = points->items;
|
||||
}
|
||||
else {
|
||||
mp_raise_TypeError("poly(): can't convert object to list");
|
||||
}
|
||||
}
|
||||
|
||||
if(num_tuples > 0) {
|
||||
std::vector<Point> points;
|
||||
for(size_t i = 0; i < num_tuples; i++) {
|
||||
mp_obj_t obj = tuples[i];
|
||||
if(!mp_obj_is_type(obj, &mp_type_tuple)) mp_raise_ValueError("poly(): can't convert object to tuple");
|
||||
|
||||
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR2(obj, mp_obj_tuple_t);
|
||||
|
||||
if(tuple->len != 2) mp_raise_ValueError("poly(): tuple must only contain two numbers");
|
||||
|
||||
points.push_back({
|
||||
mp_obj_get_int(tuple->items[0]),
|
||||
mp_obj_get_int(tuple->items[1])
|
||||
});
|
||||
}
|
||||
self->breakout->polygon(points);
|
||||
}
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD160x80_triangle(size_t n_args, const mp_obj_t *args) {
|
||||
enum { ARG_self, ARG_x1, ARG_y1, ARG_x2, ARG_y2, ARG_x3, ARG_y3 };
|
||||
|
||||
BreakoutColourLCD160x80_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self], BreakoutColourLCD160x80_obj_t);
|
||||
|
||||
self->breakout->triangle(
|
||||
{mp_obj_get_int(args[ARG_x1]),
|
||||
mp_obj_get_int(args[ARG_y1])},
|
||||
{mp_obj_get_int(args[ARG_x2]),
|
||||
mp_obj_get_int(args[ARG_y2])},
|
||||
{mp_obj_get_int(args[ARG_x3]),
|
||||
mp_obj_get_int(args[ARG_y3])}
|
||||
);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD160x80_line(size_t n_args, const mp_obj_t *args) {
|
||||
enum { ARG_self, ARG_x1, ARG_y1, ARG_x2, ARG_y2 };
|
||||
|
||||
BreakoutColourLCD160x80_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self], BreakoutColourLCD160x80_obj_t);
|
||||
|
||||
self->breakout->line(
|
||||
{mp_obj_get_int(args[ARG_x1]),
|
||||
mp_obj_get_int(args[ARG_y1])},
|
||||
{mp_obj_get_int(args[ARG_x2]),
|
||||
mp_obj_get_int(args[ARG_y2])}
|
||||
);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
// Include MicroPython API.
|
||||
#include "py/runtime.h"
|
||||
#include "py/objstr.h"
|
||||
|
||||
static const int WIDTH = 160;
|
||||
static const int HEIGHT = 80;
|
||||
|
||||
// Type
|
||||
extern const mp_obj_type_t BreakoutColourLCD160x80_type;
|
||||
|
||||
// Module functions
|
||||
extern mp_obj_t BreakoutColourLCD160x80_module_RGB565(mp_obj_t r, mp_obj_t g, mp_obj_t b);
|
||||
|
||||
// Class methods
|
||||
extern mp_obj_t BreakoutColourLCD160x80_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args);
|
||||
|
||||
extern mp_obj_t BreakoutColourLCD160x80_update(mp_obj_t self_in);
|
||||
extern mp_obj_t BreakoutColourLCD160x80_set_backlight(mp_obj_t self_in, mp_obj_t brightness);
|
||||
|
||||
// Pen
|
||||
extern mp_obj_t BreakoutColourLCD160x80_set_pen(mp_obj_t self_in, mp_obj_t pen);
|
||||
extern mp_obj_t BreakoutColourLCD160x80_create_pen(size_t n_args, const mp_obj_t *args);
|
||||
|
||||
// Primitives
|
||||
extern mp_obj_t BreakoutColourLCD160x80_set_clip(size_t n_args, const mp_obj_t *args);
|
||||
extern mp_obj_t BreakoutColourLCD160x80_remove_clip(mp_obj_t self_in);
|
||||
extern mp_obj_t BreakoutColourLCD160x80_clear(mp_obj_t self_in);
|
||||
extern mp_obj_t BreakoutColourLCD160x80_pixel(mp_obj_t self_in, mp_obj_t x, mp_obj_t y);
|
||||
extern mp_obj_t BreakoutColourLCD160x80_pixel_span(size_t n_args, const mp_obj_t *args);
|
||||
extern mp_obj_t BreakoutColourLCD160x80_rectangle(size_t n_args, const mp_obj_t *args);
|
||||
extern mp_obj_t BreakoutColourLCD160x80_circle(size_t n_args, const mp_obj_t *args);
|
||||
extern mp_obj_t BreakoutColourLCD160x80_character(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t BreakoutColourLCD160x80_text(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t BreakoutColourLCD160x80_measure_text(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t BreakoutColourLCD160x80_polygon(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t BreakoutColourLCD160x80_triangle(size_t n_args, const mp_obj_t *args);
|
||||
extern mp_obj_t BreakoutColourLCD160x80_line(size_t n_args, const mp_obj_t *args);
|
||||
|
||||
// Utility
|
||||
extern mp_obj_t BreakoutColourLCD160x80_get_bounds(mp_obj_t self_in);
|
|
@ -1,28 +0,0 @@
|
|||
set(MOD_NAME breakout_colourlcd160x80)
|
||||
string(TOUPPER ${MOD_NAME} MOD_NAME_UPPER)
|
||||
add_library(usermod_${MOD_NAME} INTERFACE)
|
||||
|
||||
target_sources(usermod_${MOD_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/${MOD_NAME}/${MOD_NAME}.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../drivers/st7735/st7735.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/pico_graphics/pico_graphics.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/pico_graphics/types.cpp
|
||||
)
|
||||
|
||||
target_include_directories(usermod_${MOD_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
target_compile_definitions(usermod_${MOD_NAME} INTERFACE
|
||||
-DMODULE_${MOD_NAME_UPPER}_ENABLED=1
|
||||
)
|
||||
|
||||
target_link_libraries(usermod INTERFACE usermod_${MOD_NAME})
|
||||
|
||||
set_source_files_properties(
|
||||
${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.c
|
||||
PROPERTIES COMPILE_FLAGS
|
||||
"-Wno-discarded-qualifiers"
|
||||
)
|
|
@ -1,78 +0,0 @@
|
|||
#include "breakout_colourlcd240x240.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// BreakoutColourLCD240x240 Class
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/***** Methods *****/
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(BreakoutColourLCD240x240_update_obj, BreakoutColourLCD240x240_update);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutColourLCD240x240_set_backlight_obj, 1, BreakoutColourLCD240x240_set_backlight);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutColourLCD240x240_set_pen_obj, 1, BreakoutColourLCD240x240_set_pen);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutColourLCD240x240_create_pen_obj, 1, BreakoutColourLCD240x240_create_pen);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutColourLCD240x240_set_clip_obj, 1, BreakoutColourLCD240x240_set_clip);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(BreakoutColourLCD240x240_remove_clip_obj, BreakoutColourLCD240x240_remove_clip);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(BreakoutColourLCD240x240_clear_obj, BreakoutColourLCD240x240_clear);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutColourLCD240x240_pixel_obj, 1, BreakoutColourLCD240x240_pixel);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutColourLCD240x240_pixel_span_obj, 1, BreakoutColourLCD240x240_pixel_span);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutColourLCD240x240_rectangle_obj, 1, BreakoutColourLCD240x240_rectangle);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutColourLCD240x240_circle_obj, 1, BreakoutColourLCD240x240_circle);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutColourLCD240x240_character_obj, 1, BreakoutColourLCD240x240_character);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutColourLCD240x240_text_obj, 1, BreakoutColourLCD240x240_text);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutColourLCD240x240_polygon_obj, 1, BreakoutColourLCD240x240_polygon);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutColourLCD240x240_triangle_obj, 1, BreakoutColourLCD240x240_triangle);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutColourLCD240x240_line_obj, 1, BreakoutColourLCD240x240_line);
|
||||
|
||||
/***** Binding of Methods *****/
|
||||
STATIC const mp_rom_map_elem_t BreakoutColourLCD240x240_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&BreakoutColourLCD240x240_update_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_backlight), MP_ROM_PTR(&BreakoutColourLCD240x240_set_backlight_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_pen), MP_ROM_PTR(&BreakoutColourLCD240x240_set_pen_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_create_pen), MP_ROM_PTR(&BreakoutColourLCD240x240_create_pen_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_clip), MP_ROM_PTR(&BreakoutColourLCD240x240_set_clip_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_remove_clip), MP_ROM_PTR(&BreakoutColourLCD240x240_remove_clip_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&BreakoutColourLCD240x240_clear_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_pixel), MP_ROM_PTR(&BreakoutColourLCD240x240_pixel_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_pixel_span), MP_ROM_PTR(&BreakoutColourLCD240x240_pixel_span_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_rectangle), MP_ROM_PTR(&BreakoutColourLCD240x240_rectangle_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_circle), MP_ROM_PTR(&BreakoutColourLCD240x240_circle_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_character), MP_ROM_PTR(&BreakoutColourLCD240x240_character_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_text), MP_ROM_PTR(&BreakoutColourLCD240x240_text_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_polygon), MP_ROM_PTR(&BreakoutColourLCD240x240_polygon_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_triangle), MP_ROM_PTR(&BreakoutColourLCD240x240_triangle_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_line), MP_ROM_PTR(&BreakoutColourLCD240x240_line_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_WIDTH), MP_ROM_INT(WIDTH) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_HEIGHT), MP_ROM_INT(HEIGHT) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(BreakoutColourLCD240x240_locals_dict, BreakoutColourLCD240x240_locals_dict_table);
|
||||
|
||||
/***** Class Definition *****/
|
||||
const mp_obj_type_t breakout_colourlcd240x240_BreakoutColourLCD240x240_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_breakout_colourlcd240x240,
|
||||
.print = BreakoutColourLCD240x240_print,
|
||||
.make_new = BreakoutColourLCD240x240_make_new,
|
||||
.locals_dict = (mp_obj_dict_t*)&BreakoutColourLCD240x240_locals_dict,
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// breakout_colourlcd240x240 Module
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/***** Globals Table *****/
|
||||
STATIC const mp_map_elem_t breakout_colourlcd240x240_globals_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_breakout_colourlcd240x240) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_BreakoutColourLCD240x240), (mp_obj_t)&breakout_colourlcd240x240_BreakoutColourLCD240x240_type },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(mp_module_breakout_colourlcd240x240_globals, breakout_colourlcd240x240_globals_table);
|
||||
|
||||
/***** Module Definition *****/
|
||||
const mp_obj_module_t breakout_colourlcd240x240_user_cmodule = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&mp_module_breakout_colourlcd240x240_globals,
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
MP_REGISTER_MODULE(MP_QSTR_breakout_colourlcd240x240, breakout_colourlcd240x240_user_cmodule, MODULE_BREAKOUT_COLOURLCD240X240_ENABLED);
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
@ -1,531 +0,0 @@
|
|||
#include "libraries/breakout_colourlcd240x240/breakout_colourlcd240x240.hpp"
|
||||
|
||||
#include "micropython/modules/util.hpp"
|
||||
|
||||
|
||||
|
||||
using namespace pimoroni;
|
||||
|
||||
extern "C" {
|
||||
#include "breakout_colourlcd240x240.h"
|
||||
|
||||
/***** Variables Struct *****/
|
||||
typedef struct _breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t {
|
||||
mp_obj_base_t base;
|
||||
BreakoutColourLCD240x240 *breakout;
|
||||
} breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t;
|
||||
|
||||
/***** Print *****/
|
||||
void BreakoutColourLCD240x240_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
(void)kind; //Unused input parameter
|
||||
breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t *self = MP_OBJ_TO_PTR2(self_in, breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t);
|
||||
BreakoutColourLCD240x240* breakout = self->breakout;
|
||||
mp_print_str(print, "BreakoutColourLCD240x240(");
|
||||
|
||||
mp_print_str(print, "spi = ");
|
||||
mp_obj_print_helper(print, mp_obj_new_int((breakout->get_spi() == spi0) ? 0 : 1), PRINT_REPR);
|
||||
|
||||
mp_print_str(print, ", cs = ");
|
||||
mp_obj_print_helper(print, mp_obj_new_int(breakout->get_cs()), PRINT_REPR);
|
||||
|
||||
mp_print_str(print, ", dc = ");
|
||||
mp_obj_print_helper(print, mp_obj_new_int(breakout->get_dc()), PRINT_REPR);
|
||||
|
||||
mp_print_str(print, ", sck = ");
|
||||
mp_obj_print_helper(print, mp_obj_new_int(breakout->get_sck()), PRINT_REPR);
|
||||
|
||||
mp_print_str(print, ", mosi = ");
|
||||
mp_obj_print_helper(print, mp_obj_new_int(breakout->get_mosi()), PRINT_REPR);
|
||||
|
||||
mp_print_str(print, ", bl = ");
|
||||
mp_obj_print_helper(print, mp_obj_new_int(breakout->get_bl()), PRINT_REPR);
|
||||
|
||||
mp_print_str(print, ")");
|
||||
}
|
||||
|
||||
/***** Constructor *****/
|
||||
mp_obj_t BreakoutColourLCD240x240_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t *self = nullptr;
|
||||
|
||||
if(n_args + n_kw == 2) {
|
||||
enum { ARG_buffer, ARG_slot };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_buffer, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_slot, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
int slot = args[ARG_slot].u_int;
|
||||
if(slot == BG_SPI_FRONT || slot == BG_SPI_BACK) {
|
||||
self = m_new_obj(breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t);
|
||||
self->base.type = &breakout_colourlcd240x240_BreakoutColourLCD240x240_type;
|
||||
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_RW);
|
||||
|
||||
self->breakout = new BreakoutColourLCD240x240((uint16_t *)bufinfo.buf, (BG_SPI_SLOT)slot);
|
||||
}
|
||||
else {
|
||||
mp_raise_ValueError("slot not a valid value. Expected 0 to 1");
|
||||
}
|
||||
}
|
||||
else {
|
||||
enum { ARG_buffer, ARG_spi, ARG_cs, ARG_dc, ARG_sck, ARG_mosi, ARG_bl };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_buffer, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_spi, MP_ARG_INT, {.u_int = -1} },
|
||||
{ MP_QSTR_cs, MP_ARG_INT, {.u_int = pimoroni::SPI_BG_FRONT_CS} },
|
||||
{ MP_QSTR_dc, MP_ARG_INT, {.u_int = pimoroni::SPI_DEFAULT_MISO} },
|
||||
{ MP_QSTR_sck, MP_ARG_INT, {.u_int = pimoroni::SPI_DEFAULT_SCK} },
|
||||
{ MP_QSTR_mosi, MP_ARG_INT, {.u_int = pimoroni::SPI_DEFAULT_MOSI} },
|
||||
{ MP_QSTR_bl, MP_ARG_INT, {.u_int = pimoroni::SPI_BG_FRONT_PWM} },
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_RW);
|
||||
|
||||
// Get SPI bus.
|
||||
int spi_id = args[ARG_spi].u_int;
|
||||
int sck = args[ARG_sck].u_int;
|
||||
int mosi = args[ARG_mosi].u_int;
|
||||
|
||||
if(spi_id == -1) {
|
||||
spi_id = (sck >> 3) & 0b1; // If no spi specified, choose the one for the given SCK pin
|
||||
}
|
||||
if(spi_id < 0 || spi_id > 1) {
|
||||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("SPI(%d) doesn't exist"), spi_id);
|
||||
}
|
||||
|
||||
if(!IS_VALID_SCK(spi_id, sck)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad SCK pin"));
|
||||
}
|
||||
|
||||
if(!IS_VALID_MOSI(spi_id, mosi)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad MOSI pin"));
|
||||
}
|
||||
|
||||
self = m_new_obj(breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t);
|
||||
self->base.type = &breakout_colourlcd240x240_BreakoutColourLCD240x240_type;
|
||||
|
||||
spi_inst_t *spi = (spi_id == 0) ? spi0 : spi1;
|
||||
self->breakout = new BreakoutColourLCD240x240((uint16_t *)bufinfo.buf, spi,
|
||||
args[ARG_cs].u_int, args[ARG_dc].u_int, sck, mosi, args[ARG_bl].u_int);
|
||||
}
|
||||
|
||||
self->breakout->init();
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
/***** Methods *****/
|
||||
mp_obj_t BreakoutColourLCD240x240_update(mp_obj_t self_in) {
|
||||
breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t *self = MP_OBJ_TO_PTR2(self_in, breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t);
|
||||
self->breakout->update();
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD240x240_set_backlight(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_self, ARG_brightness };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_brightness, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t);
|
||||
|
||||
float brightness = mp_obj_get_float(args[ARG_brightness].u_obj);
|
||||
|
||||
if(brightness < 0 || brightness > 1.0f)
|
||||
mp_raise_ValueError("brightness out of range. Expected 0.0 to 1.0");
|
||||
else
|
||||
self->breakout->set_backlight((uint8_t)(brightness * 255.0f));
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD240x240_set_pen(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
|
||||
if(n_args <= 2) {
|
||||
enum { ARG_self, ARG_pen };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_pen, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t);
|
||||
|
||||
int pen = args[ARG_pen].u_int;
|
||||
|
||||
if(pen < 0 || pen > 0xffff)
|
||||
mp_raise_ValueError("p is not a valid pen.");
|
||||
else
|
||||
self->breakout->set_pen(pen);
|
||||
}
|
||||
else {
|
||||
enum { ARG_self, ARG_r, ARG_g, ARG_b };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_r, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_g, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_b, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t);
|
||||
|
||||
int r = args[ARG_r].u_int;
|
||||
int g = args[ARG_g].u_int;
|
||||
int b = args[ARG_b].u_int;
|
||||
|
||||
if(r < 0 || r > 255)
|
||||
mp_raise_ValueError("r out of range. Expected 0 to 255");
|
||||
else if(g < 0 || g > 255)
|
||||
mp_raise_ValueError("g out of range. Expected 0 to 255");
|
||||
else if(b < 0 || b > 255)
|
||||
mp_raise_ValueError("b out of range. Expected 0 to 255");
|
||||
else
|
||||
self->breakout->set_pen(r, g, b);
|
||||
}
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD240x240_create_pen(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
int pen = 0;
|
||||
|
||||
enum { ARG_self, ARG_r, ARG_g, ARG_b };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_r, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_g, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_b, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t);
|
||||
|
||||
int r = args[ARG_r].u_int;
|
||||
int g = args[ARG_g].u_int;
|
||||
int b = args[ARG_b].u_int;
|
||||
|
||||
if(r < 0 || r > 255)
|
||||
mp_raise_ValueError("r out of range. Expected 0 to 255");
|
||||
else if(g < 0 || g > 255)
|
||||
mp_raise_ValueError("g out of range. Expected 0 to 255");
|
||||
else if(b < 0 || b > 255)
|
||||
mp_raise_ValueError("b out of range. Expected 0 to 255");
|
||||
else
|
||||
pen = self->breakout->create_pen(r, g, b);
|
||||
|
||||
return mp_obj_new_int(pen);
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD240x240_set_clip(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_self, ARG_x, ARG_y, ARG_w, ARG_h };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_x1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_w, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_h, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t);
|
||||
|
||||
int x = args[ARG_x].u_int;
|
||||
int y = args[ARG_y].u_int;
|
||||
int w = args[ARG_w].u_int;
|
||||
int h = args[ARG_h].u_int;
|
||||
|
||||
Rect r(x, y, w, h);
|
||||
self->breakout->set_clip(r);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD240x240_remove_clip(mp_obj_t self_in) {
|
||||
breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t *self = MP_OBJ_TO_PTR2(self_in, breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t);
|
||||
self->breakout->remove_clip();
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD240x240_clear(mp_obj_t self_in) {
|
||||
breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t *self = MP_OBJ_TO_PTR2(self_in, breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t);
|
||||
self->breakout->clear();
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD240x240_pixel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_self, ARG_x, ARG_y };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_x1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t);
|
||||
|
||||
int x = args[ARG_x].u_int;
|
||||
int y = args[ARG_y].u_int;
|
||||
|
||||
Point p(x, y);
|
||||
self->breakout->pixel(p);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD240x240_pixel_span(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_self, ARG_x, ARG_y, ARG_l };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_x1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_l, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t);
|
||||
|
||||
int x = args[ARG_x].u_int;
|
||||
int y = args[ARG_y].u_int;
|
||||
int l = args[ARG_l].u_int;
|
||||
|
||||
Point p(x, y);
|
||||
self->breakout->pixel_span(p, l);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD240x240_rectangle(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_self, ARG_x, ARG_y, ARG_w, ARG_h };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_x1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_w, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_h, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t);
|
||||
|
||||
int x = args[ARG_x].u_int;
|
||||
int y = args[ARG_y].u_int;
|
||||
int w = args[ARG_w].u_int;
|
||||
int h = args[ARG_h].u_int;
|
||||
|
||||
Rect r(x, y, w, h);
|
||||
self->breakout->rectangle(r);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD240x240_circle(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_self, ARG_x, ARG_y, ARG_r };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_x1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_r, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t);
|
||||
|
||||
int x = args[ARG_x].u_int;
|
||||
int y = args[ARG_y].u_int;
|
||||
int r = args[ARG_r].u_int;
|
||||
|
||||
Point p(x, y);
|
||||
self->breakout->circle(p, r);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD240x240_character(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_self, ARG_char, ARG_x, ARG_y, ARG_scale };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_char, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_x1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_scale, MP_ARG_INT, {.u_int = 2} },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t);
|
||||
|
||||
int c = mp_obj_get_int(args[ARG_char].u_obj);
|
||||
int x = args[ARG_x].u_int;
|
||||
int y = args[ARG_y].u_int;
|
||||
int scale = args[ARG_scale].u_int;
|
||||
|
||||
self->breakout->character((char)c, Point(x, y), scale);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD240x240_text(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_self, ARG_text, ARG_x, ARG_y, ARG_wrap, ARG_scale };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_text, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_x1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_wordwrap, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_scale, MP_ARG_INT, {.u_int = 2} },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t);
|
||||
|
||||
mp_obj_t text_obj = args[ARG_text].u_obj;
|
||||
if(mp_obj_is_str_or_bytes(text_obj)) {
|
||||
GET_STR_DATA_LEN(text_obj, str, str_len);
|
||||
|
||||
std::string t((const char*)str);
|
||||
|
||||
int x = args[ARG_x].u_int;
|
||||
int y = args[ARG_y].u_int;
|
||||
int wrap = args[ARG_wrap].u_int;
|
||||
int scale = args[ARG_scale].u_int;
|
||||
|
||||
self->breakout->text(t, Point(x, y), wrap, scale);
|
||||
}
|
||||
else if(mp_obj_is_float(text_obj)) {
|
||||
mp_raise_TypeError("can't convert 'float' object to str implicitly");
|
||||
}
|
||||
else if(mp_obj_is_int(text_obj)) {
|
||||
mp_raise_TypeError("can't convert 'int' object to str implicitly");
|
||||
}
|
||||
else if(mp_obj_is_bool(text_obj)) {
|
||||
mp_raise_TypeError("can't convert 'bool' object to str implicitly");
|
||||
}
|
||||
else {
|
||||
mp_raise_TypeError("can't convert object to str implicitly");
|
||||
}
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD240x240_polygon(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
// enum { ARG_self, ARG_x, ARG_y, ARG_r };
|
||||
// static const mp_arg_t allowed_args[] = {
|
||||
// { MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
// { MP_QSTR_x, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
// { MP_QSTR_y, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
// { MP_QSTR_r, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
// };
|
||||
|
||||
// mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
// mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
// breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t);
|
||||
|
||||
// int x = args[ARG_x].u_int;
|
||||
// int y = args[ARG_y].u_int;
|
||||
// int r = args[ARG_r].u_int;
|
||||
|
||||
// Point p(x, y);
|
||||
// self->breakout->circle(p, r);
|
||||
|
||||
mp_raise_NotImplementedError("polygon is not implemented. Please avoid using this function for now");
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD240x240_triangle(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_self, ARG_x1, ARG_y1, ARG_x2, ARG_y2, ARG_x3, ARG_y3 };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_x1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_x2, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y2, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_x3, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y3, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t);
|
||||
|
||||
int x1 = args[ARG_x1].u_int;
|
||||
int y1 = args[ARG_y1].u_int;
|
||||
int x2 = args[ARG_x2].u_int;
|
||||
int y2 = args[ARG_y2].u_int;
|
||||
int x3 = args[ARG_x3].u_int;
|
||||
int y3 = args[ARG_y3].u_int;
|
||||
|
||||
Point p1(x1, y1);
|
||||
Point p2(x2, y2);
|
||||
Point p3(x3, y3);
|
||||
self->breakout->triangle(p1, p2, p3);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutColourLCD240x240_line(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_self, ARG_x1, ARG_y1, ARG_x2, ARG_y2 };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_x1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_x2, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y2, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_colourlcd240x240_BreakoutColourLCD240x240_obj_t);
|
||||
|
||||
int x1 = args[ARG_x1].u_int;
|
||||
int y1 = args[ARG_y1].u_int;
|
||||
int x2 = args[ARG_x2].u_int;
|
||||
int y2 = args[ARG_y2].u_int;
|
||||
|
||||
Point p1(x1, y1);
|
||||
Point p2(x2, y2);
|
||||
self->breakout->line(p1, p2);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
// Include MicroPython API.
|
||||
#include "py/runtime.h"
|
||||
#include "py/objstr.h"
|
||||
|
||||
/***** Constants *****/
|
||||
static const int WIDTH = 240;
|
||||
static const int HEIGHT = 240;
|
||||
|
||||
|
||||
/***** Extern of Class Definition *****/
|
||||
extern const mp_obj_type_t breakout_colourlcd240x240_BreakoutColourLCD240x240_type;
|
||||
|
||||
/***** Extern of Class Methods *****/
|
||||
extern void BreakoutColourLCD240x240_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind);
|
||||
extern mp_obj_t BreakoutColourLCD240x240_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args);
|
||||
extern mp_obj_t BreakoutColourLCD240x240_update(mp_obj_t self_in);
|
||||
extern mp_obj_t BreakoutColourLCD240x240_set_backlight(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
|
||||
extern mp_obj_t BreakoutColourLCD240x240_set_pen(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t BreakoutColourLCD240x240_create_pen(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t BreakoutColourLCD240x240_set_clip(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t BreakoutColourLCD240x240_remove_clip(mp_obj_t self_in);
|
||||
extern mp_obj_t BreakoutColourLCD240x240_clear(mp_obj_t self_in);
|
||||
extern mp_obj_t BreakoutColourLCD240x240_pixel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t BreakoutColourLCD240x240_pixel_span(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t BreakoutColourLCD240x240_rectangle(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t BreakoutColourLCD240x240_circle(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t BreakoutColourLCD240x240_character(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t BreakoutColourLCD240x240_text(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t BreakoutColourLCD240x240_polygon(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t BreakoutColourLCD240x240_triangle(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t BreakoutColourLCD240x240_line(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
|
@ -1,22 +0,0 @@
|
|||
set(MOD_NAME breakout_colourlcd240x240)
|
||||
string(TOUPPER ${MOD_NAME} MOD_NAME_UPPER)
|
||||
add_library(usermod_${MOD_NAME} INTERFACE)
|
||||
|
||||
target_sources(usermod_${MOD_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/${MOD_NAME}/${MOD_NAME}.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/types.cpp
|
||||
)
|
||||
|
||||
target_include_directories(usermod_${MOD_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
target_compile_definitions(usermod_${MOD_NAME} INTERFACE
|
||||
-DMODULE_${MOD_NAME_UPPER}_ENABLED=1
|
||||
)
|
||||
|
||||
target_link_libraries(usermod INTERFACE usermod_${MOD_NAME})
|
|
@ -1,78 +0,0 @@
|
|||
#include "breakout_roundlcd.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// BreakoutRoundLCD Class
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/***** Methods *****/
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(BreakoutRoundLCD_update_obj, BreakoutRoundLCD_update);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutRoundLCD_set_backlight_obj, 1, BreakoutRoundLCD_set_backlight);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutRoundLCD_set_pen_obj, 1, BreakoutRoundLCD_set_pen);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutRoundLCD_create_pen_obj, 1, BreakoutRoundLCD_create_pen);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutRoundLCD_set_clip_obj, 1, BreakoutRoundLCD_set_clip);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(BreakoutRoundLCD_remove_clip_obj, BreakoutRoundLCD_remove_clip);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(BreakoutRoundLCD_clear_obj, BreakoutRoundLCD_clear);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutRoundLCD_pixel_obj, 1, BreakoutRoundLCD_pixel);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutRoundLCD_pixel_span_obj, 1, BreakoutRoundLCD_pixel_span);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutRoundLCD_rectangle_obj, 1, BreakoutRoundLCD_rectangle);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutRoundLCD_circle_obj, 1, BreakoutRoundLCD_circle);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutRoundLCD_character_obj, 1, BreakoutRoundLCD_character);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutRoundLCD_text_obj, 1, BreakoutRoundLCD_text);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutRoundLCD_polygon_obj, 1, BreakoutRoundLCD_polygon);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutRoundLCD_triangle_obj, 1, BreakoutRoundLCD_triangle);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutRoundLCD_line_obj, 1, BreakoutRoundLCD_line);
|
||||
|
||||
/***** Binding of Methods *****/
|
||||
STATIC const mp_rom_map_elem_t BreakoutRoundLCD_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&BreakoutRoundLCD_update_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_backlight), MP_ROM_PTR(&BreakoutRoundLCD_set_backlight_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_pen), MP_ROM_PTR(&BreakoutRoundLCD_set_pen_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_create_pen), MP_ROM_PTR(&BreakoutRoundLCD_create_pen_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_clip), MP_ROM_PTR(&BreakoutRoundLCD_set_clip_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_remove_clip), MP_ROM_PTR(&BreakoutRoundLCD_remove_clip_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&BreakoutRoundLCD_clear_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_pixel), MP_ROM_PTR(&BreakoutRoundLCD_pixel_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_pixel_span), MP_ROM_PTR(&BreakoutRoundLCD_pixel_span_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_rectangle), MP_ROM_PTR(&BreakoutRoundLCD_rectangle_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_circle), MP_ROM_PTR(&BreakoutRoundLCD_circle_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_character), MP_ROM_PTR(&BreakoutRoundLCD_character_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_text), MP_ROM_PTR(&BreakoutRoundLCD_text_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_polygon), MP_ROM_PTR(&BreakoutRoundLCD_polygon_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_triangle), MP_ROM_PTR(&BreakoutRoundLCD_triangle_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_line), MP_ROM_PTR(&BreakoutRoundLCD_line_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_WIDTH), MP_ROM_INT(WIDTH) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_HEIGHT), MP_ROM_INT(HEIGHT) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(BreakoutRoundLCD_locals_dict, BreakoutRoundLCD_locals_dict_table);
|
||||
|
||||
/***** Class Definition *****/
|
||||
const mp_obj_type_t breakout_roundlcd_BreakoutRoundLCD_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_BreakoutRoundLCD,
|
||||
.print = BreakoutRoundLCD_print,
|
||||
.make_new = BreakoutRoundLCD_make_new,
|
||||
.locals_dict = (mp_obj_dict_t*)&BreakoutRoundLCD_locals_dict,
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// breakout_roundlcd Module
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/***** Globals Table *****/
|
||||
STATIC const mp_map_elem_t breakout_roundlcd_globals_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_breakout_roundlcd) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_BreakoutRoundLCD), (mp_obj_t)&breakout_roundlcd_BreakoutRoundLCD_type },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(mp_module_breakout_roundlcd_globals, breakout_roundlcd_globals_table);
|
||||
|
||||
/***** Module Definition *****/
|
||||
const mp_obj_module_t breakout_roundlcd_user_cmodule = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&mp_module_breakout_roundlcd_globals,
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
MP_REGISTER_MODULE(MP_QSTR_breakout_roundlcd, breakout_roundlcd_user_cmodule, MODULE_BREAKOUT_ROUNDLCD_ENABLED);
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
@ -1,512 +0,0 @@
|
|||
#include "libraries/breakout_roundlcd/breakout_roundlcd.hpp"
|
||||
|
||||
#include "micropython/modules/util.hpp"
|
||||
|
||||
|
||||
|
||||
using namespace pimoroni;
|
||||
|
||||
extern "C" {
|
||||
#include "breakout_roundlcd.h"
|
||||
|
||||
/***** Variables Struct *****/
|
||||
typedef struct _breakout_roundlcd_BreakoutRoundLCD_obj_t {
|
||||
mp_obj_base_t base;
|
||||
BreakoutRoundLCD *breakout;
|
||||
} breakout_roundlcd_BreakoutRoundLCD_obj_t;
|
||||
|
||||
/***** Print *****/
|
||||
void BreakoutRoundLCD_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
(void)kind; //Unused input parameter
|
||||
breakout_roundlcd_BreakoutRoundLCD_obj_t *self = MP_OBJ_TO_PTR2(self_in, breakout_roundlcd_BreakoutRoundLCD_obj_t);
|
||||
BreakoutRoundLCD* breakout = self->breakout;
|
||||
mp_print_str(print, "BreakoutRoundLCD(");
|
||||
|
||||
mp_print_str(print, "spi = ");
|
||||
mp_obj_print_helper(print, mp_obj_new_int((breakout->get_spi() == spi0) ? 0 : 1), PRINT_REPR);
|
||||
|
||||
mp_print_str(print, ", cs = ");
|
||||
mp_obj_print_helper(print, mp_obj_new_int(breakout->get_cs()), PRINT_REPR);
|
||||
|
||||
mp_print_str(print, ", dc = ");
|
||||
mp_obj_print_helper(print, mp_obj_new_int(breakout->get_dc()), PRINT_REPR);
|
||||
|
||||
mp_print_str(print, ", sck = ");
|
||||
mp_obj_print_helper(print, mp_obj_new_int(breakout->get_sck()), PRINT_REPR);
|
||||
|
||||
mp_print_str(print, ", mosi = ");
|
||||
mp_obj_print_helper(print, mp_obj_new_int(breakout->get_mosi()), PRINT_REPR);
|
||||
|
||||
mp_print_str(print, ", bl = ");
|
||||
mp_obj_print_helper(print, mp_obj_new_int(breakout->get_bl()), PRINT_REPR);
|
||||
|
||||
mp_print_str(print, ")");
|
||||
}
|
||||
|
||||
/***** Constructor *****/
|
||||
mp_obj_t BreakoutRoundLCD_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
breakout_roundlcd_BreakoutRoundLCD_obj_t *self = nullptr;
|
||||
|
||||
if(n_args + n_kw == 2) {
|
||||
enum { ARG_buffer, ARG_slot };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_buffer, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_slot, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
int slot = args[ARG_slot].u_int;
|
||||
if(slot == BG_SPI_FRONT || slot == BG_SPI_BACK) {
|
||||
self = m_new_obj(breakout_roundlcd_BreakoutRoundLCD_obj_t);
|
||||
self->base.type = &breakout_roundlcd_BreakoutRoundLCD_type;
|
||||
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_RW);
|
||||
|
||||
self->breakout = new BreakoutRoundLCD((uint16_t *)bufinfo.buf, (BG_SPI_SLOT)slot);
|
||||
}
|
||||
else {
|
||||
mp_raise_ValueError("slot not a valid value. Expected 0 to 1");
|
||||
}
|
||||
}
|
||||
else {
|
||||
enum { ARG_buffer, ARG_spi, ARG_cs, ARG_dc, ARG_sck, ARG_mosi, ARG_bl };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_buffer, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_spi, MP_ARG_INT, {.u_int = -1} },
|
||||
{ MP_QSTR_cs, MP_ARG_INT, {.u_int = pimoroni::SPI_BG_FRONT_CS} },
|
||||
{ MP_QSTR_dc, MP_ARG_INT, {.u_int = pimoroni::SPI_DEFAULT_MISO} },
|
||||
{ MP_QSTR_sck, MP_ARG_INT, {.u_int = pimoroni::SPI_DEFAULT_SCK} },
|
||||
{ MP_QSTR_mosi, MP_ARG_INT, {.u_int = pimoroni::SPI_DEFAULT_MOSI} },
|
||||
{ MP_QSTR_bl, MP_ARG_INT, {.u_int = pimoroni::SPI_BG_FRONT_PWM} },
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_RW);
|
||||
|
||||
// Get SPI bus.
|
||||
int spi_id = args[ARG_spi].u_int;
|
||||
int sck = args[ARG_sck].u_int;
|
||||
int mosi = args[ARG_mosi].u_int;
|
||||
|
||||
if(spi_id == -1) {
|
||||
spi_id = (sck >> 3) & 0b1; // If no spi specified, choose the one for the given SCK pin
|
||||
}
|
||||
if(spi_id < 0 || spi_id > 1) {
|
||||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("SPI(%d) doesn't exist"), spi_id);
|
||||
}
|
||||
|
||||
if(!IS_VALID_SCK(spi_id, sck)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad SCK pin"));
|
||||
}
|
||||
|
||||
if(!IS_VALID_MOSI(spi_id, mosi)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad MOSI pin"));
|
||||
}
|
||||
|
||||
self = m_new_obj(breakout_roundlcd_BreakoutRoundLCD_obj_t);
|
||||
self->base.type = &breakout_roundlcd_BreakoutRoundLCD_type;
|
||||
|
||||
spi_inst_t *spi = (spi_id == 0) ? spi0 : spi1;
|
||||
self->breakout = new BreakoutRoundLCD((uint16_t *)bufinfo.buf, spi,
|
||||
args[ARG_cs].u_int, args[ARG_dc].u_int, sck, mosi, args[ARG_bl].u_int);
|
||||
}
|
||||
|
||||
self->breakout->init();
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
/***** Methods *****/
|
||||
mp_obj_t BreakoutRoundLCD_update(mp_obj_t self_in) {
|
||||
breakout_roundlcd_BreakoutRoundLCD_obj_t *self = MP_OBJ_TO_PTR2(self_in, breakout_roundlcd_BreakoutRoundLCD_obj_t);
|
||||
self->breakout->update();
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutRoundLCD_set_backlight(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_self, ARG_brightness };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_brightness, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
breakout_roundlcd_BreakoutRoundLCD_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_roundlcd_BreakoutRoundLCD_obj_t);
|
||||
|
||||
float brightness = mp_obj_get_float(args[ARG_brightness].u_obj);
|
||||
|
||||
if(brightness < 0 || brightness > 1.0f)
|
||||
mp_raise_ValueError("brightness out of range. Expected 0.0 to 1.0");
|
||||
else
|
||||
self->breakout->set_backlight((uint8_t)(brightness * 255.0f));
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutRoundLCD_set_pen(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
|
||||
if(n_args <= 2) {
|
||||
enum { ARG_self, ARG_pen };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_pen, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
breakout_roundlcd_BreakoutRoundLCD_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_roundlcd_BreakoutRoundLCD_obj_t);
|
||||
|
||||
int pen = args[ARG_pen].u_int;
|
||||
|
||||
if(pen < 0 || pen > 0xffff)
|
||||
mp_raise_ValueError("p is not a valid pen.");
|
||||
else
|
||||
self->breakout->set_pen(pen);
|
||||
}
|
||||
else {
|
||||
enum { ARG_self, ARG_r, ARG_g, ARG_b };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_r, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_g, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_b, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
breakout_roundlcd_BreakoutRoundLCD_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_roundlcd_BreakoutRoundLCD_obj_t);
|
||||
|
||||
int r = args[ARG_r].u_int;
|
||||
int g = args[ARG_g].u_int;
|
||||
int b = args[ARG_b].u_int;
|
||||
|
||||
if(r < 0 || r > 255)
|
||||
mp_raise_ValueError("r out of range. Expected 0 to 255");
|
||||
else if(g < 0 || g > 255)
|
||||
mp_raise_ValueError("g out of range. Expected 0 to 255");
|
||||
else if(b < 0 || b > 255)
|
||||
mp_raise_ValueError("b out of range. Expected 0 to 255");
|
||||
else
|
||||
self->breakout->set_pen(r, g, b);
|
||||
}
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutRoundLCD_create_pen(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
int pen = 0;
|
||||
|
||||
enum { ARG_self, ARG_r, ARG_g, ARG_b };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_r, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_g, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_b, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
breakout_roundlcd_BreakoutRoundLCD_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_roundlcd_BreakoutRoundLCD_obj_t);
|
||||
|
||||
int r = args[ARG_r].u_int;
|
||||
int g = args[ARG_g].u_int;
|
||||
int b = args[ARG_b].u_int;
|
||||
|
||||
if(r < 0 || r > 255)
|
||||
mp_raise_ValueError("r out of range. Expected 0 to 255");
|
||||
else if(g < 0 || g > 255)
|
||||
mp_raise_ValueError("g out of range. Expected 0 to 255");
|
||||
else if(b < 0 || b > 255)
|
||||
mp_raise_ValueError("b out of range. Expected 0 to 255");
|
||||
else
|
||||
pen = self->breakout->create_pen(r, g, b);
|
||||
|
||||
return mp_obj_new_int(pen);
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutRoundLCD_set_clip(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_self, ARG_x, ARG_y, ARG_w, ARG_h };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_x1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_w, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_h, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
breakout_roundlcd_BreakoutRoundLCD_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_roundlcd_BreakoutRoundLCD_obj_t);
|
||||
|
||||
int x = args[ARG_x].u_int;
|
||||
int y = args[ARG_y].u_int;
|
||||
int w = args[ARG_w].u_int;
|
||||
int h = args[ARG_h].u_int;
|
||||
|
||||
Rect r(x, y, w, h);
|
||||
self->breakout->set_clip(r);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutRoundLCD_remove_clip(mp_obj_t self_in) {
|
||||
breakout_roundlcd_BreakoutRoundLCD_obj_t *self = MP_OBJ_TO_PTR2(self_in, breakout_roundlcd_BreakoutRoundLCD_obj_t);
|
||||
self->breakout->remove_clip();
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutRoundLCD_clear(mp_obj_t self_in) {
|
||||
breakout_roundlcd_BreakoutRoundLCD_obj_t *self = MP_OBJ_TO_PTR2(self_in, breakout_roundlcd_BreakoutRoundLCD_obj_t);
|
||||
self->breakout->clear();
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutRoundLCD_pixel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_self, ARG_x, ARG_y };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_x1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
breakout_roundlcd_BreakoutRoundLCD_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_roundlcd_BreakoutRoundLCD_obj_t);
|
||||
|
||||
int x = args[ARG_x].u_int;
|
||||
int y = args[ARG_y].u_int;
|
||||
|
||||
Point p(x, y);
|
||||
self->breakout->pixel(p);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutRoundLCD_pixel_span(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_self, ARG_x, ARG_y, ARG_l };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_x1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_l, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
breakout_roundlcd_BreakoutRoundLCD_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_roundlcd_BreakoutRoundLCD_obj_t);
|
||||
|
||||
int x = args[ARG_x].u_int;
|
||||
int y = args[ARG_y].u_int;
|
||||
int l = args[ARG_l].u_int;
|
||||
|
||||
Point p(x, y);
|
||||
self->breakout->pixel_span(p, l);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutRoundLCD_rectangle(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_self, ARG_x, ARG_y, ARG_w, ARG_h };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_x1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_w, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_h, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
breakout_roundlcd_BreakoutRoundLCD_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_roundlcd_BreakoutRoundLCD_obj_t);
|
||||
|
||||
int x = args[ARG_x].u_int;
|
||||
int y = args[ARG_y].u_int;
|
||||
int w = args[ARG_w].u_int;
|
||||
int h = args[ARG_h].u_int;
|
||||
|
||||
Rect r(x, y, w, h);
|
||||
self->breakout->rectangle(r);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutRoundLCD_circle(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_self, ARG_x, ARG_y, ARG_r };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_x1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_r, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
breakout_roundlcd_BreakoutRoundLCD_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_roundlcd_BreakoutRoundLCD_obj_t);
|
||||
|
||||
int x = args[ARG_x].u_int;
|
||||
int y = args[ARG_y].u_int;
|
||||
int r = args[ARG_r].u_int;
|
||||
|
||||
Point p(x, y);
|
||||
self->breakout->circle(p, r);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutRoundLCD_character(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_self, ARG_char, ARG_x, ARG_y, ARG_scale };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_char, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_x1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_scale, MP_ARG_INT, {.u_int = 2} },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
breakout_roundlcd_BreakoutRoundLCD_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_roundlcd_BreakoutRoundLCD_obj_t);
|
||||
|
||||
int c = mp_obj_get_int(args[ARG_char].u_obj);
|
||||
int x = args[ARG_x].u_int;
|
||||
int y = args[ARG_y].u_int;
|
||||
int scale = args[ARG_scale].u_int;
|
||||
|
||||
self->breakout->character((char)c, Point(x, y), scale);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutRoundLCD_text(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_self, ARG_text, ARG_x, ARG_y, ARG_wrap, ARG_scale };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_text, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_x1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_wordwrap, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_scale, MP_ARG_INT, {.u_int = 2} },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
breakout_roundlcd_BreakoutRoundLCD_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_roundlcd_BreakoutRoundLCD_obj_t);
|
||||
|
||||
mp_obj_t text_obj = args[ARG_text].u_obj;
|
||||
if(mp_obj_is_str_or_bytes(text_obj)) {
|
||||
GET_STR_DATA_LEN(text_obj, str, str_len);
|
||||
|
||||
std::string t((const char*)str);
|
||||
|
||||
int x = args[ARG_x].u_int;
|
||||
int y = args[ARG_y].u_int;
|
||||
int wrap = args[ARG_wrap].u_int;
|
||||
int scale = args[ARG_scale].u_int;
|
||||
|
||||
self->breakout->text(t, Point(x, y), wrap, scale);
|
||||
}
|
||||
else if(mp_obj_is_float(text_obj)) {
|
||||
mp_raise_TypeError("can't convert 'float' object to str implicitly");
|
||||
}
|
||||
else if(mp_obj_is_int(text_obj)) {
|
||||
mp_raise_TypeError("can't convert 'int' object to str implicitly");
|
||||
}
|
||||
else if(mp_obj_is_bool(text_obj)) {
|
||||
mp_raise_TypeError("can't convert 'bool' object to str implicitly");
|
||||
}
|
||||
else {
|
||||
mp_raise_TypeError("can't convert object to str implicitly");
|
||||
}
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutRoundLCD_polygon(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
|
||||
mp_raise_NotImplementedError("polygon is not implemented. Please avoid using this function for now");
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutRoundLCD_triangle(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_self, ARG_x1, ARG_y1, ARG_x2, ARG_y2, ARG_x3, ARG_y3 };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_x1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_x2, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y2, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_x3, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y3, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
breakout_roundlcd_BreakoutRoundLCD_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_roundlcd_BreakoutRoundLCD_obj_t);
|
||||
|
||||
int x1 = args[ARG_x1].u_int;
|
||||
int y1 = args[ARG_y1].u_int;
|
||||
int x2 = args[ARG_x2].u_int;
|
||||
int y2 = args[ARG_y2].u_int;
|
||||
int x3 = args[ARG_x3].u_int;
|
||||
int y3 = args[ARG_y3].u_int;
|
||||
|
||||
Point p1(x1, y1);
|
||||
Point p2(x2, y2);
|
||||
Point p3(x3, y3);
|
||||
self->breakout->triangle(p1, p2, p3);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t BreakoutRoundLCD_line(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_self, ARG_x1, ARG_y1, ARG_x2, ARG_y2 };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_x1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y1, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_x2, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y2, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
breakout_roundlcd_BreakoutRoundLCD_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_roundlcd_BreakoutRoundLCD_obj_t);
|
||||
|
||||
int x1 = args[ARG_x1].u_int;
|
||||
int y1 = args[ARG_y1].u_int;
|
||||
int x2 = args[ARG_x2].u_int;
|
||||
int y2 = args[ARG_y2].u_int;
|
||||
|
||||
Point p1(x1, y1);
|
||||
Point p2(x2, y2);
|
||||
self->breakout->line(p1, p2);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
// Include MicroPython API.
|
||||
#include "py/runtime.h"
|
||||
#include "py/objstr.h"
|
||||
|
||||
/***** Constants *****/
|
||||
static const int WIDTH = 240;
|
||||
static const int HEIGHT = 240;
|
||||
|
||||
|
||||
/***** Extern of Class Definition *****/
|
||||
extern const mp_obj_type_t breakout_roundlcd_BreakoutRoundLCD_type;
|
||||
|
||||
/***** Extern of Class Methods *****/
|
||||
extern void BreakoutRoundLCD_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind);
|
||||
extern mp_obj_t BreakoutRoundLCD_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args);
|
||||
extern mp_obj_t BreakoutRoundLCD_update(mp_obj_t self_in);
|
||||
extern mp_obj_t BreakoutRoundLCD_set_backlight(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
|
||||
extern mp_obj_t BreakoutRoundLCD_set_pen(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t BreakoutRoundLCD_create_pen(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t BreakoutRoundLCD_set_clip(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t BreakoutRoundLCD_remove_clip(mp_obj_t self_in);
|
||||
extern mp_obj_t BreakoutRoundLCD_clear(mp_obj_t self_in);
|
||||
extern mp_obj_t BreakoutRoundLCD_pixel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t BreakoutRoundLCD_pixel_span(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t BreakoutRoundLCD_rectangle(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t BreakoutRoundLCD_circle(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t BreakoutRoundLCD_character(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t BreakoutRoundLCD_text(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t BreakoutRoundLCD_polygon(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t BreakoutRoundLCD_triangle(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t BreakoutRoundLCD_line(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
|
@ -1,20 +0,0 @@
|
|||
set(MOD_NAME breakout_roundlcd)
|
||||
string(TOUPPER ${MOD_NAME} MOD_NAME_UPPER)
|
||||
add_library(usermod_${MOD_NAME} INTERFACE)
|
||||
|
||||
target_sources(usermod_${MOD_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/${MOD_NAME}/${MOD_NAME}.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../drivers/st7789/st7789.cpp
|
||||
)
|
||||
|
||||
target_include_directories(usermod_${MOD_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
target_compile_definitions(usermod_${MOD_NAME} INTERFACE
|
||||
-DMODULE_${MOD_NAME_UPPER}_ENABLED=1
|
||||
)
|
||||
|
||||
target_link_libraries(usermod INTERFACE usermod_${MOD_NAME})
|
|
@ -5,7 +5,6 @@ include(breakout_dotmatrix/micropython)
|
|||
include(breakout_encoder/micropython)
|
||||
include(breakout_ioexpander/micropython)
|
||||
include(breakout_ltr559/micropython)
|
||||
include(breakout_colourlcd160x80/micropython)
|
||||
include(breakout_as7262/micropython)
|
||||
include(breakout_rgbmatrix5x5/micropython)
|
||||
include(breakout_matrix11x7/micropython)
|
||||
|
@ -42,7 +41,7 @@ include(qrcode/micropython/micropython)
|
|||
include(adcfft/micropython)
|
||||
include(pcf85063a/micropython)
|
||||
|
||||
include(st7789/micropython)
|
||||
include(picographics/micropython)
|
||||
include(jpegdec/micropython)
|
||||
|
||||
include(modules_py/modules_py)
|
||||
|
|
|
@ -1,211 +0,0 @@
|
|||
# Pico Display Pack - MicroPython <!-- omit in toc -->
|
||||
|
||||
Pico Display Pack is a vibrant 1.14", 240 x 135 pixel IPS LCD screen for your Raspberry Pi Pico, with four useful buttons and a RGB LED. [Buy one here!](https://shop.pimoroni.com/products/pico-display-pack)
|
||||
|
||||
We've included helper functions to handle every aspect of drawing to the screen and interfacing with the buttons and LED. See the [function reference](#function-reference) for details. Scroll down to the bottom for links to more resources!
|
||||
|
||||
- [Example Program](#example-program)
|
||||
- [Function Reference](#function-reference)
|
||||
- [init](#init)
|
||||
- [set_backlight](#set_backlight)
|
||||
- [set_led](#set_led)
|
||||
- [is_pressed](#is_pressed)
|
||||
- [update](#update)
|
||||
- [set_pen](#set_pen)
|
||||
- [create_pen](#create_pen)
|
||||
- [clear](#clear)
|
||||
- [pixel](#pixel)
|
||||
- [pixel_span](#pixel_span)
|
||||
- [rectangle](#rectangle)
|
||||
- [circle](#circle)
|
||||
- [character](#character)
|
||||
- [text](#text)
|
||||
- [set_clip](#set_clip)
|
||||
- [remove_clip](#remove_clip)
|
||||
- [More Resources](#more-resources)
|
||||
|
||||
## Example Program
|
||||
|
||||
The following example sets up Pico Display, displays some basic demo text and illuminates the RGB LED green when the A button is pressed.
|
||||
|
||||
```python
|
||||
import utime
|
||||
import picodisplay
|
||||
|
||||
# Initialise Picodisplay with a bytearray display buffer
|
||||
buf = bytearray(picodisplay.get_width() * picodisplay.get_height() * 2)
|
||||
picodisplay.init(buf)
|
||||
picodisplay.set_backlight(1.0)
|
||||
|
||||
picodisplay.set_pen(255, 0, 0) # Set a red pen
|
||||
picodisplay.clear() # Clear the display buffer
|
||||
picodisplay.set_pen(255, 255, 255) # Set a white pen
|
||||
picodisplay.text("pico display", 10, 10, 240, 6) # Add some text
|
||||
picodisplay.update() # Update the display with our changes
|
||||
|
||||
picodisplay.set_led(255, 0, 0) # Set the RGB LED to red
|
||||
utime.sleep(1) # Wait for a second
|
||||
picodisplay.set_led(0, 255, 0) # Set the RGB LED to green
|
||||
utime.sleep(1) # Wait for a second
|
||||
picodisplay.set_led(0, 0, 255) # Set the RGB LED to blue
|
||||
|
||||
while picodisplay.is_pressed(picodisplay.BUTTON_A) == False:
|
||||
pass
|
||||
|
||||
picodisplay.set_led(0, 255, 0) # Set the RGB LED to green
|
||||
```
|
||||
|
||||
## Function Reference
|
||||
|
||||
### init
|
||||
|
||||
Sets up Pico Display. `init` must be called before any other functions since it configures the required PWM and GPIO. `init()` needs a bytearray type display buffer that MicroPython's garbage collection isn't going to eat, make sure you create one and pass it in like so:
|
||||
|
||||
```python
|
||||
buf = bytearray(picodisplay.get_width() * picodisplay.get_height() * 2)
|
||||
picodisplay.init(buf)
|
||||
```
|
||||
|
||||
### set_backlight
|
||||
|
||||
Sets the display backlight from 0.0 to 1.0.
|
||||
|
||||
```python
|
||||
picodisplay.set_backlight(brightness)
|
||||
```
|
||||
|
||||
Uses hardware PWM to dim the display backlight, dimming values are gamma-corrected to provide smooth brightness transitions across the full range of intensity. This may result in some low values mapping as "off."
|
||||
|
||||
### set_led
|
||||
|
||||
Sets the RGB LED on Pico Display with an RGB triplet.
|
||||
|
||||
```python
|
||||
picodisplay.set_led(r, g, b)
|
||||
```
|
||||
|
||||
Uses hardware PWM to drive the LED. Values are automatically gamma-corrected to provide smooth brightness transitions and low values may map as "off."
|
||||
|
||||
### is_pressed
|
||||
|
||||
Reads the GPIO pin connected to one of Pico Display's buttons, returning `True` if it's pressed and `False` if it is released.
|
||||
|
||||
```python
|
||||
picodisplay.is_pressed(button)
|
||||
```
|
||||
|
||||
The button value should be a number denoting a pin, and constants `picodisplay.BUTTON_A`, `picodisplay.BUTTON_B`, `picodisplay.BUTTON_X` and `picodisplay.BUTTON_Y` are supplied to make it easier. e:
|
||||
|
||||
```python
|
||||
is_a_button_pressed = picodisplay.is_pressed(picodisplay.BUTTON_A)
|
||||
```
|
||||
|
||||
### update
|
||||
|
||||
To display your changes on Pico Display's screen you need to call `update`.
|
||||
|
||||
```python
|
||||
picodisplay.update()
|
||||
```
|
||||
|
||||
### set_pen
|
||||
|
||||
Sets the colour to be used by subsequent calls to drawing functions. The values for `r`, `g` and `b` should be from 0-255 inclusive.
|
||||
|
||||
```python
|
||||
picodisplay.set_pen(r, g, b)
|
||||
```
|
||||
|
||||
### create_pen
|
||||
|
||||
Creates a pen which can be stored as a variable for faster re-use of the same colour through calls to `set_pen`. The values for `r`, `g` and `b` should be from 0-255 inclusive.
|
||||
|
||||
```python
|
||||
pen_colour = picodisplay.create_pen(r, g, b)
|
||||
picodisplay.set_pen(penColour)
|
||||
```
|
||||
|
||||
### clear
|
||||
|
||||
Fills the display buffer with the currently set pen colour.
|
||||
|
||||
```python
|
||||
picodisplay.clear()
|
||||
```
|
||||
|
||||
### pixel
|
||||
|
||||
Sets a single pixel in the display buffer to the current pen colour. The `x` and `y` parameters determine the X and Y coordinates of the drawn pixel in the buffer.
|
||||
|
||||
```python
|
||||
picodisplay.pixel(x, y)
|
||||
```
|
||||
|
||||
### pixel_span
|
||||
|
||||
Draws a horizontal line of pixels to the buffer. The `x` and `y` parameters specify the coordinates of the first pixel of the line. The `l` parameter describes the length of the line in pixels. This function will only extend the line towards the end of the screen, i.e. the `x` coordinate should specify the left hand extreme of the line.
|
||||
|
||||
```python
|
||||
picodisplay.pixel_span(x, y, l)
|
||||
```
|
||||
|
||||
### rectangle
|
||||
|
||||
Draws a rectangle filled with the current pen colour to the buffer. The `x` and `y` parameters specify the upper left corner of the rectangle, `w` specifies the width in pixels, and `h` the height.
|
||||
|
||||
```python
|
||||
picodisplay.rectangle(x, y, w, h)
|
||||
```
|
||||
|
||||
![Rectangle function explanation image](/micropython/modules/pico_display/images/rectangle.png)
|
||||
|
||||
### circle
|
||||
|
||||
Draws a circle filled with the current pen colour to the buffer. The `x` and `y` parameters specify the centre of the circle, `r` specifies the radius in pixels.
|
||||
|
||||
```python
|
||||
picodisplay.circle(x, y, r)
|
||||
```
|
||||
|
||||
![Circle function explanation image](/micropython/modules/pico_display/images/circle.png)
|
||||
|
||||
### character
|
||||
|
||||
Draws a single character to the display buffer in the current pen colour. The `c` parameter should be the ASCII numerical representation of the character to be printed, `x` and `y` describe the top-left corner of the character's drawing field. The `character` function can also be given an optional 4th parameter, `scale`, describing the scale of the character to be drawn. Default value is 2.
|
||||
|
||||
```python
|
||||
char_a = ord('a')
|
||||
picodisplay.character(char_a, x, y)
|
||||
picodisplay.character(char_a, x, y, scale)
|
||||
```
|
||||
|
||||
### text
|
||||
|
||||
Draws a string of text to the display buffer in the current pen colour. The `string` parameter is the string of text to be drawn, and `x` and `y` specify the upper left corner of the drawing field. The `wrap` parameter describes the width, in pixels, after which the next word in the string will be drawn on a new line underneath the current text. This will wrap the string over multiple lines if required. This function also has an optional parameter, `scale`, which describes the size of the characters to be drawn. The default `scale` is 2.
|
||||
|
||||
```python
|
||||
picodisplay.text(string, x, y, wrap)
|
||||
picodisplay.text(string, x, y, wrap, scale)
|
||||
```
|
||||
|
||||
![Text scale explanation image](/micropython/modules/pico_display/images/text_scale.png)
|
||||
|
||||
### set_clip
|
||||
|
||||
This function defines a rectangular area outside which no drawing actions will take effect. If a drawing action crosses the boundary of the clip then only the pixels inside the clip will be drawn. Note that `clip` does not remove pixels which have already been drawn, it only prevents new pixels being drawn outside the described area. A more visual description of the function of clips can be found below. Only one clip can be active at a time, and defining a new clip replaces any previous clips. The `x` and `y` parameters describe the upper-left corner of the clip area, `w` and `h` describe the width and height in pixels.
|
||||
|
||||
```python
|
||||
picodisplay.set_clip(x, y, w, h)
|
||||
```
|
||||
|
||||
![Clip function explanation image](/micropython/modules/pico_display/images/clip.png)
|
||||
|
||||
### remove_clip
|
||||
|
||||
This function removes any currently implemented clip.
|
||||
|
||||
## More Resources
|
||||
|
||||
- [Display Pack Guide by UnfinishedStuff](https://github.com/UnfinishedStuff/Pimoroni_Pico_Display_Pack_documentation) - more detail on functions and code examples
|
||||
- [Display Pack Workout by tonygo2](https://www.instructables.com/Pimoroni-Pico-Display-Workout/) - a comprehensive demo
|
||||
- [picofont by Les Wright](https://github.com/leswright1977/picofont) - implementing custom fonts using pure MicroPython
|
Przed Szerokość: | Wysokość: | Rozmiar: 5.1 KiB |
Przed Szerokość: | Wysokość: | Rozmiar: 6.5 KiB |
Przed Szerokość: | Wysokość: | Rozmiar: 4.7 KiB |
Przed Szerokość: | Wysokość: | Rozmiar: 6.5 KiB |
|
@ -1,26 +0,0 @@
|
|||
add_library(usermod_pico_display INTERFACE)
|
||||
|
||||
target_sources(usermod_pico_display INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/pico_display.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/pico_display.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/pico_display/pico_display.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/types.cpp
|
||||
)
|
||||
|
||||
target_include_directories(usermod_pico_display INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
target_compile_definitions(usermod_pico_display INTERFACE
|
||||
MODULE_PICODISPLAY_ENABLED=1
|
||||
)
|
||||
|
||||
target_link_libraries(usermod INTERFACE usermod_pico_display)
|
||||
|
||||
set_source_files_properties(
|
||||
${CMAKE_CURRENT_LIST_DIR}/pico_display.c
|
||||
PROPERTIES COMPILE_FLAGS
|
||||
"-Wno-discarded-qualifiers -Wno-implicit-int"
|
||||
)
|
|
@ -1,74 +0,0 @@
|
|||
#include "pico_display.h"
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// picodisplay Module
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/***** Module Functions *****/
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(picodisplay_init_obj, picodisplay_init);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(picodisplay_get_width_obj, picodisplay_get_width);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(picodisplay_get_height_obj, picodisplay_get_height);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(picodisplay_update_obj, picodisplay_update);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(picodisplay_set_backlight_obj, picodisplay_set_backlight);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(picodisplay_set_led_obj, picodisplay_set_led);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(picodisplay_is_pressed_obj, picodisplay_is_pressed);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(picodisplay_flip_obj, picodisplay_flip);
|
||||
|
||||
//From PicoGraphics parent class
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(picodisplay_set_pen_obj, 1, 3, picodisplay_set_pen);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(picodisplay_create_pen_obj, picodisplay_create_pen);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(picodisplay_set_clip_obj, 4, 4, picodisplay_set_clip);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(picodisplay_remove_clip_obj, picodisplay_remove_clip);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(picodisplay_clear_obj, picodisplay_clear);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(picodisplay_pixel_obj, picodisplay_pixel);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(picodisplay_pixel_span_obj, picodisplay_pixel_span);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(picodisplay_rectangle_obj, 4, 4, picodisplay_rectangle);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(picodisplay_circle_obj, picodisplay_circle);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(picodisplay_character_obj, 3, 4, picodisplay_character);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(picodisplay_text_obj, 4, 5, picodisplay_text);
|
||||
|
||||
|
||||
/***** Globals Table *****/
|
||||
STATIC const mp_map_elem_t picodisplay_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_picodisplay) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&picodisplay_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_get_width), MP_ROM_PTR(&picodisplay_get_width_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_get_height), MP_ROM_PTR(&picodisplay_get_height_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&picodisplay_update_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_backlight), MP_ROM_PTR(&picodisplay_set_backlight_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_led), MP_ROM_PTR(&picodisplay_set_led_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_is_pressed), MP_ROM_PTR(&picodisplay_is_pressed_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_flip), MP_ROM_PTR(&picodisplay_flip_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_pen), MP_ROM_PTR(&picodisplay_set_pen_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_create_pen), MP_ROM_PTR(&picodisplay_create_pen_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_clip), MP_ROM_PTR(&picodisplay_set_clip_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_remove_clip), MP_ROM_PTR(&picodisplay_remove_clip_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&picodisplay_clear_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_pixel), MP_ROM_PTR(&picodisplay_pixel_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_pixel_span), MP_ROM_PTR(&picodisplay_pixel_span_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_rectangle), MP_ROM_PTR(&picodisplay_rectangle_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_circle), MP_ROM_PTR(&picodisplay_circle_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_character), MP_ROM_PTR(&picodisplay_character_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_text), MP_ROM_PTR(&picodisplay_text_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_BUTTON_A), MP_ROM_INT(12) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_BUTTON_B), MP_ROM_INT(13) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_BUTTON_X), MP_ROM_INT(14) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_BUTTON_Y), MP_ROM_INT(15) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_LED_R), MP_ROM_INT(6) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_LED_G), MP_ROM_INT(7) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_LED_B), MP_ROM_INT(8) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(mp_module_picodisplay_globals, picodisplay_globals_table);
|
||||
|
||||
/***** Module Definition *****/
|
||||
const mp_obj_module_t picodisplay_user_cmodule = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&mp_module_picodisplay_globals,
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
MP_REGISTER_MODULE(MP_QSTR_picodisplay, picodisplay_user_cmodule, MODULE_PICODISPLAY_ENABLED);
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
@ -1,323 +0,0 @@
|
|||
#include "hardware/spi.h"
|
||||
#include "hardware/sync.h"
|
||||
#include "pico/binary_info.h"
|
||||
|
||||
#include "libraries/pico_display/pico_display.hpp"zzz
|
||||
|
||||
using namespace pimoroni;
|
||||
|
||||
PicoDisplay *display = nullptr;
|
||||
|
||||
|
||||
extern "C" {
|
||||
#include "pico_display.h"
|
||||
|
||||
#define NOT_INITIALISED_MSG "Cannot call this function, as picodisplay is not initialised. Call picodisplay.init(<bytearray>) first."
|
||||
|
||||
mp_obj_t picodisplay_buf_obj;
|
||||
|
||||
mp_obj_t picodisplay_init(mp_obj_t buf_obj) {
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(buf_obj, &bufinfo, MP_BUFFER_RW);
|
||||
picodisplay_buf_obj = buf_obj;
|
||||
|
||||
// If a display already exists, delete it
|
||||
if(display != nullptr) {
|
||||
delete display;
|
||||
}
|
||||
|
||||
// Create a new display pointing to the newly provided buffer
|
||||
display = new PicoDisplay(bufinfo.buf);
|
||||
display->init();
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay_get_width() {
|
||||
return mp_obj_new_int(PicoDisplay::WIDTH);
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay_get_height() {
|
||||
return mp_obj_new_int(PicoDisplay::HEIGHT);
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay_update() {
|
||||
if(display != nullptr)
|
||||
display->update();
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay_flip() {
|
||||
if(display != nullptr)
|
||||
display->flip();
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay_set_backlight(mp_obj_t brightness_obj) {
|
||||
if(display != nullptr) {
|
||||
float brightness = mp_obj_get_float(brightness_obj);
|
||||
|
||||
if(brightness < 0 || brightness > 1.0f)
|
||||
mp_raise_ValueError("brightness out of range. Expected 0.0 to 1.0");
|
||||
else
|
||||
display->set_backlight((uint8_t)(brightness * 255.0f));
|
||||
}
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay_set_led(mp_obj_t r_obj, mp_obj_t g_obj, mp_obj_t b_obj) {
|
||||
if(display != nullptr) {
|
||||
int r = mp_obj_get_int(r_obj);
|
||||
int g = mp_obj_get_int(g_obj);
|
||||
int b = mp_obj_get_int(b_obj);
|
||||
|
||||
if(r < 0 || r > 255)
|
||||
mp_raise_ValueError("r out of range. Expected 0 to 255");
|
||||
else if(g < 0 || g > 255)
|
||||
mp_raise_ValueError("g out of range. Expected 0 to 255");
|
||||
else if(b < 0 || b > 255)
|
||||
mp_raise_ValueError("b out of range. Expected 0 to 255");
|
||||
else
|
||||
display->set_led(r, g, b);
|
||||
}
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay_is_pressed(mp_obj_t button_obj) {
|
||||
if(display != nullptr) {
|
||||
return display->is_pressed(mp_obj_get_int(button_obj)) ? mp_const_true : mp_const_false;
|
||||
}
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay_set_pen(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
if(display != nullptr) {
|
||||
switch(n_args) {
|
||||
case 1: {
|
||||
int p = mp_obj_get_int(args[0]);
|
||||
|
||||
if(p < 0 || p > 0xffff)
|
||||
mp_raise_ValueError("p is not a valid pen.");
|
||||
else
|
||||
display->set_pen(p);
|
||||
} break;
|
||||
|
||||
case 3: {
|
||||
int r = mp_obj_get_int(args[0]);
|
||||
int g = mp_obj_get_int(args[1]);
|
||||
int b = mp_obj_get_int(args[2]);
|
||||
|
||||
if(r < 0 || r > 255)
|
||||
mp_raise_ValueError("r out of range. Expected 0 to 255");
|
||||
else if(g < 0 || g > 255)
|
||||
mp_raise_ValueError("g out of range. Expected 0 to 255");
|
||||
else if(b < 0 || b > 255)
|
||||
mp_raise_ValueError("b out of range. Expected 0 to 255");
|
||||
else
|
||||
display->set_pen(r, g, b);
|
||||
} break;
|
||||
|
||||
default: {
|
||||
char *buffer;
|
||||
buffer = (char*)malloc(100);
|
||||
sprintf(buffer, "function takes 1 or 3 (r,g,b) positional arguments but %d were given", n_args);
|
||||
mp_raise_TypeError(buffer);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay_create_pen(mp_obj_t r_obj, mp_obj_t g_obj, mp_obj_t b_obj) {
|
||||
int pen = 0;
|
||||
|
||||
if(display != nullptr) {
|
||||
int r = mp_obj_get_int(r_obj);
|
||||
int g = mp_obj_get_int(g_obj);
|
||||
int b = mp_obj_get_int(b_obj);
|
||||
|
||||
if(r < 0 || r > 255)
|
||||
mp_raise_ValueError("r out of range. Expected 0 to 255");
|
||||
else if(g < 0 || g > 255)
|
||||
mp_raise_ValueError("g out of range. Expected 0 to 255");
|
||||
else if(b < 0 || b > 255)
|
||||
mp_raise_ValueError("b out of range. Expected 0 to 255");
|
||||
else
|
||||
pen = display->create_pen(r, g, b);
|
||||
}
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_obj_new_int(pen);
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay_set_clip(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
(void)n_args; //Unused input parameter, we know it's 4
|
||||
|
||||
if(display != nullptr) {
|
||||
int x = mp_obj_get_int(args[0]);
|
||||
int y = mp_obj_get_int(args[1]);
|
||||
int w = mp_obj_get_int(args[2]);
|
||||
int h = mp_obj_get_int(args[3]);
|
||||
|
||||
Rect r(x, y, w, h);
|
||||
display->set_clip(r);
|
||||
}
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay_remove_clip() {
|
||||
if(display != nullptr)
|
||||
display->remove_clip();
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay_clear() {
|
||||
if(display != nullptr)
|
||||
display->clear();
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay_pixel(mp_obj_t x_obj, mp_obj_t y_obj) {
|
||||
if(display != nullptr) {
|
||||
int x = mp_obj_get_int(x_obj);
|
||||
int y = mp_obj_get_int(y_obj);
|
||||
|
||||
Point p(x, y);
|
||||
display->pixel(p);
|
||||
}
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay_pixel_span(mp_obj_t x_obj, mp_obj_t y_obj, mp_obj_t l_obj) {
|
||||
if(display != nullptr) {
|
||||
int x = mp_obj_get_int(x_obj);
|
||||
int y = mp_obj_get_int(y_obj);
|
||||
int l = mp_obj_get_int(l_obj);
|
||||
|
||||
Point p(x, y);
|
||||
display->pixel_span(p, l);
|
||||
}
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay_rectangle(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
(void)n_args; //Unused input parameter, we know it's 4
|
||||
|
||||
if(display != nullptr) {
|
||||
int x = mp_obj_get_int(args[0]);
|
||||
int y = mp_obj_get_int(args[1]);
|
||||
int w = mp_obj_get_int(args[2]);
|
||||
int h = mp_obj_get_int(args[3]);
|
||||
|
||||
Rect r(x, y, w, h);
|
||||
display->rectangle(r);
|
||||
}
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay_circle(mp_obj_t x_obj, mp_obj_t y_obj, mp_obj_t r_obj) {
|
||||
if(display != nullptr) {
|
||||
int x = mp_obj_get_int(x_obj);
|
||||
int y = mp_obj_get_int(y_obj);
|
||||
int r = mp_obj_get_int(r_obj);
|
||||
|
||||
Point p(x, y);
|
||||
display->circle(p, r);
|
||||
}
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay_character(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
if(display != nullptr) {
|
||||
int c = mp_obj_get_int(args[0]);
|
||||
int x = mp_obj_get_int(args[1]);
|
||||
int y = mp_obj_get_int(args[2]);
|
||||
|
||||
Point p(x, y);
|
||||
if(n_args == 4) {
|
||||
int scale = mp_obj_get_int(args[3]);
|
||||
display->character((char)c, p, scale);
|
||||
}
|
||||
else
|
||||
display->character((char)c, p);
|
||||
}
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay_text(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
if(display != nullptr) {
|
||||
if(mp_obj_is_str_or_bytes(args[0])) {
|
||||
GET_STR_DATA_LEN(args[0], str, str_len);
|
||||
|
||||
std::string t((const char*)str);
|
||||
|
||||
int x = mp_obj_get_int(args[1]);
|
||||
int y = mp_obj_get_int(args[2]);
|
||||
int wrap = mp_obj_get_int(args[3]);
|
||||
|
||||
Point p(x, y);
|
||||
if(n_args == 5) {
|
||||
int scale = mp_obj_get_int(args[4]);
|
||||
display->text(t, p, wrap, scale);
|
||||
}
|
||||
else
|
||||
display->text(t, p, wrap);
|
||||
}
|
||||
else if(mp_obj_is_float(args[0])) {
|
||||
mp_raise_TypeError("can't convert 'float' object to str implicitly");
|
||||
}
|
||||
else if(mp_obj_is_int(args[0])) {
|
||||
mp_raise_TypeError("can't convert 'int' object to str implicitly");
|
||||
}
|
||||
else if(mp_obj_is_bool(args[0])) {
|
||||
mp_raise_TypeError("can't convert 'bool' object to str implicitly");
|
||||
}
|
||||
else {
|
||||
mp_raise_TypeError("can't convert object to str implicitly");
|
||||
}
|
||||
}
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
// Include MicroPython API.
|
||||
#include "py/runtime.h"
|
||||
#include "py/objstr.h"
|
||||
|
||||
// Declare the functions we'll make available in Python
|
||||
extern mp_obj_t picodisplay_init(mp_obj_t buf_obj);
|
||||
extern mp_obj_t picodisplay_get_width();
|
||||
extern mp_obj_t picodisplay_get_height();
|
||||
extern mp_obj_t picodisplay_set_backlight(mp_obj_t brightness_obj);
|
||||
extern mp_obj_t picodisplay_update();
|
||||
extern mp_obj_t picodisplay_set_led(mp_obj_t r_obj, mp_obj_t g_obj, mp_obj_t b_obj);
|
||||
extern mp_obj_t picodisplay_is_pressed(mp_obj_t button_obj);
|
||||
extern mp_obj_t picodisplay_flip();
|
||||
|
||||
// From PicoGraphics parent class
|
||||
extern mp_obj_t picodisplay_set_pen(mp_uint_t n_args, const mp_obj_t *args);
|
||||
extern mp_obj_t picodisplay_create_pen(mp_obj_t r_obj, mp_obj_t g_obj, mp_obj_t b_obj);
|
||||
extern mp_obj_t picodisplay_set_clip(mp_uint_t n_args, const mp_obj_t *args);
|
||||
extern mp_obj_t picodisplay_remove_clip();
|
||||
extern mp_obj_t picodisplay_clear();
|
||||
extern mp_obj_t picodisplay_pixel(mp_obj_t x_obj, mp_obj_t y_obj);
|
||||
extern mp_obj_t picodisplay_pixel_span(mp_obj_t x_obj, mp_obj_t y_obj, mp_obj_t l_obj);
|
||||
extern mp_obj_t picodisplay_rectangle(mp_uint_t n_args, const mp_obj_t *args);
|
||||
extern mp_obj_t picodisplay_circle(mp_obj_t x_obj, mp_obj_t y_obj, mp_obj_t r_obj);
|
||||
extern mp_obj_t picodisplay_character(mp_uint_t n_args, const mp_obj_t *args);
|
||||
extern mp_obj_t picodisplay_text(mp_uint_t n_args, const mp_obj_t *args);
|
|
@ -1,206 +0,0 @@
|
|||
# Pico Display Pack - MicroPython <!-- omit in toc -->
|
||||
|
||||
Pico Display 2.0" Pack is a vibrant 2.0", 320 x 240 pixel IPS LCD screen for your Raspberry Pi Pico, with four useful buttons and a RGB LED. [Click here](https://shop.pimoroni.com/products/pico-display-pack) to find out more!
|
||||
|
||||
We've included helper functions to handle every aspect of drawing to the screen and interfacing with the buttons and LED. See the [function reference](#function-reference) for details.
|
||||
|
||||
Check out [UnfinishedStuff's excellent Display Pack guide](https://github.com/UnfinishedStuff/Pimoroni_Pico_Display_Pack_documentation) for more detail on the functions and code examples, and [tonygo2's Display Pack Workout](https://www.instructables.com/Pimoroni-Pico-Display-Workout/) for a comprehensive demo!
|
||||
|
||||
- [Example Program](#example-program)
|
||||
- [Function Reference](#function-reference)
|
||||
- [init](#init)
|
||||
- [set_backlight](#set_backlight)
|
||||
- [set_led](#set_led)
|
||||
- [is_pressed](#is_pressed)
|
||||
- [update](#update)
|
||||
- [set_pen](#set_pen)
|
||||
- [create_pen](#create_pen)
|
||||
- [clear](#clear)
|
||||
- [pixel](#pixel)
|
||||
- [pixel_span](#pixel_span)
|
||||
- [rectangle](#rectangle)
|
||||
- [circle](#circle)
|
||||
- [character](#character)
|
||||
- [text](#text)
|
||||
- [set_clip](#set_clip)
|
||||
- [remove_clip](#remove_clip)
|
||||
|
||||
## Example Program
|
||||
|
||||
The following example sets up Pico Display, displays some basic demo text and illuminates the RGB LED green when the A button is pressed.
|
||||
|
||||
```python
|
||||
import utime
|
||||
import picodisplay2 as picodisplay
|
||||
|
||||
# Initialise Picodisplay with a bytearray display buffer
|
||||
buf = bytearray(picodisplay.get_width() * picodisplay.get_height() * 2)
|
||||
picodisplay.init(buf)
|
||||
picodisplay.set_backlight(1.0)
|
||||
|
||||
picodisplay.set_pen(255, 0, 0) # Set a red pen
|
||||
picodisplay.clear() # Clear the display buffer
|
||||
picodisplay.set_pen(255, 255, 255) # Set a white pen
|
||||
picodisplay.text("pico display", 10, 10, 240, 6) # Add some text
|
||||
picodisplay.update() # Update the display with our changes
|
||||
|
||||
picodisplay.set_led(255, 0, 0) # Set the RGB LED to red
|
||||
utime.sleep(1) # Wait for a second
|
||||
picodisplay.set_led(0, 255, 0) # Set the RGB LED to green
|
||||
utime.sleep(1) # Wait for a second
|
||||
picodisplay.set_led(0, 0, 255) # Set the RGB LED to blue
|
||||
|
||||
while picodisplay.is_pressed(picodisplay.BUTTON_A) == False:
|
||||
pass
|
||||
|
||||
picodisplay.set_led(0, 255, 0) # Set the RGB LED to green
|
||||
```
|
||||
|
||||
## Function Reference
|
||||
|
||||
### init
|
||||
|
||||
Sets up Pico Display. `init` must be called before any other functions since it configures the required PWM and GPIO. `init()` needs a bytearray type display buffer that MicroPython's garbage collection isn't going to eat, make sure you create one and pass it in like so:
|
||||
|
||||
```python
|
||||
buf = bytearray(picodisplay.get_width() * picodisplay.get_height() * 2)
|
||||
picodisplay.init(buf)
|
||||
```
|
||||
|
||||
### set_backlight
|
||||
|
||||
Sets the display backlight from 0.0 to 1.0.
|
||||
|
||||
```python
|
||||
picodisplay.set_backlight(brightness)
|
||||
```
|
||||
|
||||
Uses hardware PWM to dim the display backlight, dimming values are gamma-corrected to provide smooth brightness transitions across the full range of intensity. This may result in some low values mapping as "off."
|
||||
|
||||
### set_led
|
||||
|
||||
Sets the RGB LED on Pico Display with an RGB triplet.
|
||||
|
||||
```python
|
||||
picodisplay.set_led(r, g, b)
|
||||
```
|
||||
|
||||
Uses hardware PWM to drive the LED. Values are automatically gamma-corrected to provide smooth brightness transitions and low values may map as "off."
|
||||
|
||||
### is_pressed
|
||||
|
||||
Reads the GPIO pin connected to one of Pico Display's buttons, returning `True` if it's pressed and `False` if it is released.
|
||||
|
||||
```python
|
||||
picodisplay.is_pressed(button)
|
||||
```
|
||||
|
||||
The button value should be a number denoting a pin, and constants `picodisplay.BUTTON_A`, `picodisplay.BUTTON_B`, `picodisplay.BUTTON_X` and `picodisplay.BUTTON_Y` are supplied to make it easier. e:
|
||||
|
||||
```python
|
||||
is_a_button_pressed = picodisplay.is_pressed(picodisplay.BUTTON_A)
|
||||
```
|
||||
|
||||
### update
|
||||
|
||||
To display your changes on Pico Display's screen you need to call `update`.
|
||||
|
||||
```python
|
||||
picodisplay.update()
|
||||
```
|
||||
|
||||
### set_pen
|
||||
|
||||
Sets the colour to be used by subsequent calls to drawing functions. The values for `r`, `g` and `b` should be from 0-255 inclusive.
|
||||
|
||||
```python
|
||||
picodisplay.set_pen(r, g, b)
|
||||
```
|
||||
|
||||
### create_pen
|
||||
|
||||
Creates a pen which can be stored as a variable for faster re-use of the same colour through calls to `set_pen`. The values for `r`, `g` and `b` should be from 0-255 inclusive.
|
||||
|
||||
```python
|
||||
pen_colour = picodisplay.create_pen(r, g, b)
|
||||
picodisplay.set_pen(penColour)
|
||||
```
|
||||
|
||||
### clear
|
||||
|
||||
Fills the display buffer with the currently set pen colour.
|
||||
|
||||
```python
|
||||
picodisplay.clear()
|
||||
```
|
||||
|
||||
### pixel
|
||||
|
||||
Sets a single pixel in the display buffer to the current pen colour. The `x` and `y` parameters determine the X and Y coordinates of the drawn pixel in the buffer.
|
||||
|
||||
```python
|
||||
picodisplay.pixel(x, y)
|
||||
```
|
||||
|
||||
### pixel_span
|
||||
|
||||
Draws a horizontal line of pixels to the buffer. The `x` and `y` parameters specify the coordinates of the first pixel of the line. The `l` parameter describes the length of the line in pixels. This function will only extend the line towards the end of the screen, i.e. the `x` coordinate should specify the left hand extreme of the line.
|
||||
|
||||
```python
|
||||
picodisplay.pixel_span(x, y, l)
|
||||
```
|
||||
|
||||
### rectangle
|
||||
|
||||
Draws a rectangle filled with the current pen colour to the buffer. The `x` and `y` parameters specify the upper left corner of the rectangle, `w` specifies the width in pixels, and `h` the height.
|
||||
|
||||
```python
|
||||
picodisplay.rectangle(x, y, w, h)
|
||||
```
|
||||
|
||||
![Rectangle function explanation image](/micropython/modules/pico_display/images/rectangle.png)
|
||||
|
||||
### circle
|
||||
|
||||
Draws a circle filled with the current pen colour to the buffer. The `x` and `y` parameters specify the centre of the circle, `r` specifies the radius in pixels.
|
||||
|
||||
```python
|
||||
picodisplay.circle(x, y, r)
|
||||
```
|
||||
|
||||
![Circle function explanation image](/micropython/modules/pico_display/images/circle.png)
|
||||
|
||||
### character
|
||||
|
||||
Draws a single character to the display buffer in the current pen colour. The `c` parameter should be the ASCII numerical representation of the character to be printed, `x` and `y` describe the top-left corner of the character's drawing field. The `character` function can also be given an optional 4th parameter, `scale`, describing the scale of the character to be drawn. Default value is 2.
|
||||
|
||||
```python
|
||||
char_a = ord('a')
|
||||
picodisplay.character(char_a, x, y)
|
||||
picodisplay.character(char_a, x, y, scale)
|
||||
```
|
||||
|
||||
### text
|
||||
|
||||
Draws a string of text to the display buffer in the current pen colour. The `string` parameter is the string of text to be drawn, and `x` and `y` specify the upper left corner of the drawing field. The `wrap` parameter describes the width, in pixels, after which the next word in the string will be drawn on a new line underneath the current text. This will wrap the string over multiple lines if required. This function also has an optional parameter, `scale`, which describes the size of the characters to be drawn. The default `scale` is 2.
|
||||
|
||||
```python
|
||||
picodisplay.text(string, x, y, wrap)
|
||||
picodisplay.text(string, x, y, wrap, scale)
|
||||
```
|
||||
|
||||
![Text scale explanation image](/micropython/modules/pico_display/images/text_scale.png)
|
||||
|
||||
### set_clip
|
||||
|
||||
This function defines a rectangular area outside which no drawing actions will take effect. If a drawing action crosses the boundary of the clip then only the pixels inside the clip will be drawn. Note that `clip` does not remove pixels which have already been drawn, it only prevents new pixels being drawn outside the described area. A more visual description of the function of clips can be found below. Only one clip can be active at a time, and defining a new clip replaces any previous clips. The `x` and `y` parameters describe the upper-left corner of the clip area, `w` and `h` describe the width and height in pixels.
|
||||
|
||||
```python
|
||||
picodisplay.set_clip(x, y, w, h)
|
||||
```
|
||||
|
||||
![Clip function explanation image](/micropython/modules/pico_display/images/clip.png)
|
||||
|
||||
### remove_clip
|
||||
|
||||
This function removes any currently implemented clip.
|
Przed Szerokość: | Wysokość: | Rozmiar: 5.1 KiB |
Przed Szerokość: | Wysokość: | Rozmiar: 6.5 KiB |
Przed Szerokość: | Wysokość: | Rozmiar: 4.7 KiB |
Przed Szerokość: | Wysokość: | Rozmiar: 6.5 KiB |
|
@ -1,28 +0,0 @@
|
|||
set(MOD_NAME pico_display_2)
|
||||
string(TOUPPER ${MOD_NAME} MOD_NAME_UPPER)
|
||||
add_library(usermod_${MOD_NAME} INTERFACE)
|
||||
|
||||
target_sources(usermod_${MOD_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/${MOD_NAME}/${MOD_NAME}.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/types.cpp
|
||||
)
|
||||
|
||||
target_include_directories(usermod_${MOD_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
target_compile_definitions(usermod_${MOD_NAME} INTERFACE
|
||||
MODULE_${MOD_NAME_UPPER}_ENABLED=1
|
||||
)
|
||||
|
||||
target_link_libraries(usermod INTERFACE usermod_${MOD_NAME})
|
||||
|
||||
set_source_files_properties(
|
||||
${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.c
|
||||
PROPERTIES COMPILE_FLAGS
|
||||
"-Wno-discarded-qualifiers -Wno-implicit-int"
|
||||
)
|
|
@ -1,74 +0,0 @@
|
|||
#include "pico_display_2.h"
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// picodisplay2 Module
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/***** Module Functions *****/
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(picodisplay2_init_obj, picodisplay2_init);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(picodisplay2_get_width_obj, picodisplay2_get_width);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(picodisplay2_get_height_obj, picodisplay2_get_height);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(picodisplay2_update_obj, picodisplay2_update);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(picodisplay2_set_backlight_obj, picodisplay2_set_backlight);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(picodisplay2_set_led_obj, picodisplay2_set_led);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(picodisplay2_is_pressed_obj, picodisplay2_is_pressed);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(picodisplay2_flip_obj, picodisplay2_flip);
|
||||
|
||||
//From PicoGraphics parent class
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(picodisplay2_set_pen_obj, 1, 3, picodisplay2_set_pen);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(picodisplay2_create_pen_obj, picodisplay2_create_pen);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(picodisplay2_set_clip_obj, 4, 4, picodisplay2_set_clip);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(picodisplay2_remove_clip_obj, picodisplay2_remove_clip);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(picodisplay2_clear_obj, picodisplay2_clear);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(picodisplay2_pixel_obj, picodisplay2_pixel);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(picodisplay2_pixel_span_obj, picodisplay2_pixel_span);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(picodisplay2_rectangle_obj, 4, 4, picodisplay2_rectangle);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(picodisplay2_circle_obj, picodisplay2_circle);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(picodisplay2_character_obj, 3, 4, picodisplay2_character);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(picodisplay2_text_obj, 4, 5, picodisplay2_text);
|
||||
|
||||
|
||||
/***** Globals Table *****/
|
||||
STATIC const mp_map_elem_t picodisplay2_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_picodisplay2) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&picodisplay2_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_get_width), MP_ROM_PTR(&picodisplay2_get_width_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_get_height), MP_ROM_PTR(&picodisplay2_get_height_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&picodisplay2_update_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_backlight), MP_ROM_PTR(&picodisplay2_set_backlight_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_led), MP_ROM_PTR(&picodisplay2_set_led_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_is_pressed), MP_ROM_PTR(&picodisplay2_is_pressed_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_flip), MP_ROM_PTR(&picodisplay2_flip_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_pen), MP_ROM_PTR(&picodisplay2_set_pen_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_create_pen), MP_ROM_PTR(&picodisplay2_create_pen_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_clip), MP_ROM_PTR(&picodisplay2_set_clip_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_remove_clip), MP_ROM_PTR(&picodisplay2_remove_clip_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&picodisplay2_clear_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_pixel), MP_ROM_PTR(&picodisplay2_pixel_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_pixel_span), MP_ROM_PTR(&picodisplay2_pixel_span_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_rectangle), MP_ROM_PTR(&picodisplay2_rectangle_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_circle), MP_ROM_PTR(&picodisplay2_circle_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_character), MP_ROM_PTR(&picodisplay2_character_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_text), MP_ROM_PTR(&picodisplay2_text_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_BUTTON_A), MP_ROM_INT(12) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_BUTTON_B), MP_ROM_INT(13) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_BUTTON_X), MP_ROM_INT(14) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_BUTTON_Y), MP_ROM_INT(15) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_LED_R), MP_ROM_INT(6) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_LED_G), MP_ROM_INT(7) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_LED_B), MP_ROM_INT(8) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(mp_module_picodisplay2_globals, picodisplay2_globals_table);
|
||||
|
||||
/***** Module Definition *****/
|
||||
const mp_obj_module_t picodisplay2_user_cmodule = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&mp_module_picodisplay2_globals,
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
MP_REGISTER_MODULE(MP_QSTR_picodisplay2, picodisplay2_user_cmodule, MODULE_PICO_DISPLAY_2_ENABLED);
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
@ -1,323 +0,0 @@
|
|||
#include "hardware/spi.h"
|
||||
#include "hardware/sync.h"
|
||||
#include "pico/binary_info.h"
|
||||
|
||||
#include "libraries/pico_display_2/pico_display_2.hpp"
|
||||
|
||||
using namespace pimoroni;
|
||||
|
||||
PicoDisplay2 *display2 = nullptr;
|
||||
|
||||
|
||||
extern "C" {
|
||||
#include "pico_display_2.h"
|
||||
|
||||
#define NOT_INITIALISED_MSG "Cannot call this function, as picodisplay2 is not initialised. Call picodisplay2.init(<bytearray>) first."
|
||||
|
||||
mp_obj_t picodisplay2_buf_obj;
|
||||
|
||||
mp_obj_t picodisplay2_init(mp_obj_t buf_obj) {
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(buf_obj, &bufinfo, MP_BUFFER_RW);
|
||||
picodisplay2_buf_obj = buf_obj;
|
||||
|
||||
// If a display already exists, delete it
|
||||
if(display2 != nullptr) {
|
||||
delete display2;
|
||||
}
|
||||
|
||||
// Create a new display pointing to the newly provided buffer
|
||||
display2 = new PicoDisplay2(bufinfo.buf);
|
||||
display2->init();
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay2_get_width() {
|
||||
return mp_obj_new_int(PicoDisplay2::WIDTH);
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay2_get_height() {
|
||||
return mp_obj_new_int(PicoDisplay2::HEIGHT);
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay2_update() {
|
||||
if(display2 != nullptr)
|
||||
display2->update();
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay2_flip() {
|
||||
if(display2 != nullptr)
|
||||
display2->flip();
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay2_set_backlight(mp_obj_t brightness_obj) {
|
||||
if(display2 != nullptr) {
|
||||
float brightness = mp_obj_get_float(brightness_obj);
|
||||
|
||||
if(brightness < 0 || brightness > 1.0f)
|
||||
mp_raise_ValueError("brightness out of range. Expected 0.0 to 1.0");
|
||||
else
|
||||
display2->set_backlight((uint8_t)(brightness * 255.0f));
|
||||
}
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay2_set_led(mp_obj_t r_obj, mp_obj_t g_obj, mp_obj_t b_obj) {
|
||||
if(display2 != nullptr) {
|
||||
int r = mp_obj_get_int(r_obj);
|
||||
int g = mp_obj_get_int(g_obj);
|
||||
int b = mp_obj_get_int(b_obj);
|
||||
|
||||
if(r < 0 || r > 255)
|
||||
mp_raise_ValueError("r out of range. Expected 0 to 255");
|
||||
else if(g < 0 || g > 255)
|
||||
mp_raise_ValueError("g out of range. Expected 0 to 255");
|
||||
else if(b < 0 || b > 255)
|
||||
mp_raise_ValueError("b out of range. Expected 0 to 255");
|
||||
else
|
||||
display2->set_led(r, g, b);
|
||||
}
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay2_is_pressed(mp_obj_t button_obj) {
|
||||
if(display2 != nullptr) {
|
||||
return display2->is_pressed(mp_obj_get_int(button_obj)) ? mp_const_true : mp_const_false;
|
||||
}
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay2_set_pen(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
if(display2 != nullptr) {
|
||||
switch(n_args) {
|
||||
case 1: {
|
||||
int p = mp_obj_get_int(args[0]);
|
||||
|
||||
if(p < 0 || p > 0xffff)
|
||||
mp_raise_ValueError("p is not a valid pen.");
|
||||
else
|
||||
display2->set_pen(p);
|
||||
} break;
|
||||
|
||||
case 3: {
|
||||
int r = mp_obj_get_int(args[0]);
|
||||
int g = mp_obj_get_int(args[1]);
|
||||
int b = mp_obj_get_int(args[2]);
|
||||
|
||||
if(r < 0 || r > 255)
|
||||
mp_raise_ValueError("r out of range. Expected 0 to 255");
|
||||
else if(g < 0 || g > 255)
|
||||
mp_raise_ValueError("g out of range. Expected 0 to 255");
|
||||
else if(b < 0 || b > 255)
|
||||
mp_raise_ValueError("b out of range. Expected 0 to 255");
|
||||
else
|
||||
display2->set_pen(r, g, b);
|
||||
} break;
|
||||
|
||||
default: {
|
||||
char *buffer;
|
||||
buffer = (char*)malloc(100);
|
||||
sprintf(buffer, "function takes 1 or 3 (r,g,b) positional arguments but %d were given", n_args);
|
||||
mp_raise_TypeError(buffer);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay2_create_pen(mp_obj_t r_obj, mp_obj_t g_obj, mp_obj_t b_obj) {
|
||||
int pen = 0;
|
||||
|
||||
if(display2 != nullptr) {
|
||||
int r = mp_obj_get_int(r_obj);
|
||||
int g = mp_obj_get_int(g_obj);
|
||||
int b = mp_obj_get_int(b_obj);
|
||||
|
||||
if(r < 0 || r > 255)
|
||||
mp_raise_ValueError("r out of range. Expected 0 to 255");
|
||||
else if(g < 0 || g > 255)
|
||||
mp_raise_ValueError("g out of range. Expected 0 to 255");
|
||||
else if(b < 0 || b > 255)
|
||||
mp_raise_ValueError("b out of range. Expected 0 to 255");
|
||||
else
|
||||
pen = display2->create_pen(r, g, b);
|
||||
}
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_obj_new_int(pen);
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay2_set_clip(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
(void)n_args; //Unused input parameter, we know it's 4
|
||||
|
||||
if(display2 != nullptr) {
|
||||
int x = mp_obj_get_int(args[0]);
|
||||
int y = mp_obj_get_int(args[1]);
|
||||
int w = mp_obj_get_int(args[2]);
|
||||
int h = mp_obj_get_int(args[3]);
|
||||
|
||||
Rect r(x, y, w, h);
|
||||
display2->set_clip(r);
|
||||
}
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay2_remove_clip() {
|
||||
if(display2 != nullptr)
|
||||
display2->remove_clip();
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay2_clear() {
|
||||
if(display2 != nullptr)
|
||||
display2->clear();
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay2_pixel(mp_obj_t x_obj, mp_obj_t y_obj) {
|
||||
if(display2 != nullptr) {
|
||||
int x = mp_obj_get_int(x_obj);
|
||||
int y = mp_obj_get_int(y_obj);
|
||||
|
||||
Point p(x, y);
|
||||
display2->pixel(p);
|
||||
}
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay2_pixel_span(mp_obj_t x_obj, mp_obj_t y_obj, mp_obj_t l_obj) {
|
||||
if(display2 != nullptr) {
|
||||
int x = mp_obj_get_int(x_obj);
|
||||
int y = mp_obj_get_int(y_obj);
|
||||
int l = mp_obj_get_int(l_obj);
|
||||
|
||||
Point p(x, y);
|
||||
display2->pixel_span(p, l);
|
||||
}
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay2_rectangle(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
(void)n_args; //Unused input parameter, we know it's 4
|
||||
|
||||
if(display2 != nullptr) {
|
||||
int x = mp_obj_get_int(args[0]);
|
||||
int y = mp_obj_get_int(args[1]);
|
||||
int w = mp_obj_get_int(args[2]);
|
||||
int h = mp_obj_get_int(args[3]);
|
||||
|
||||
Rect r(x, y, w, h);
|
||||
display2->rectangle(r);
|
||||
}
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay2_circle(mp_obj_t x_obj, mp_obj_t y_obj, mp_obj_t r_obj) {
|
||||
if(display2 != nullptr) {
|
||||
int x = mp_obj_get_int(x_obj);
|
||||
int y = mp_obj_get_int(y_obj);
|
||||
int r = mp_obj_get_int(r_obj);
|
||||
|
||||
Point p(x, y);
|
||||
display2->circle(p, r);
|
||||
}
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay2_character(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
if(display2 != nullptr) {
|
||||
int c = mp_obj_get_int(args[0]);
|
||||
int x = mp_obj_get_int(args[1]);
|
||||
int y = mp_obj_get_int(args[2]);
|
||||
|
||||
Point p(x, y);
|
||||
if(n_args == 4) {
|
||||
int scale = mp_obj_get_int(args[3]);
|
||||
display2->character((char)c, p, scale);
|
||||
}
|
||||
else
|
||||
display2->character((char)c, p);
|
||||
}
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picodisplay2_text(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
if(display2 != nullptr) {
|
||||
if(mp_obj_is_str_or_bytes(args[0])) {
|
||||
GET_STR_DATA_LEN(args[0], str, str_len);
|
||||
|
||||
std::string t((const char*)str);
|
||||
|
||||
int x = mp_obj_get_int(args[1]);
|
||||
int y = mp_obj_get_int(args[2]);
|
||||
int wrap = mp_obj_get_int(args[3]);
|
||||
|
||||
Point p(x, y);
|
||||
if(n_args == 5) {
|
||||
int scale = mp_obj_get_int(args[4]);
|
||||
display2->text(t, p, wrap, scale);
|
||||
}
|
||||
else
|
||||
display2->text(t, p, wrap);
|
||||
}
|
||||
else if(mp_obj_is_float(args[0])) {
|
||||
mp_raise_TypeError("can't convert 'float' object to str implicitly");
|
||||
}
|
||||
else if(mp_obj_is_int(args[0])) {
|
||||
mp_raise_TypeError("can't convert 'int' object to str implicitly");
|
||||
}
|
||||
else if(mp_obj_is_bool(args[0])) {
|
||||
mp_raise_TypeError("can't convert 'bool' object to str implicitly");
|
||||
}
|
||||
else {
|
||||
mp_raise_TypeError("can't convert object to str implicitly");
|
||||
}
|
||||
}
|
||||
else
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
// Include MicroPython API.
|
||||
#include "py/runtime.h"
|
||||
#include "py/objstr.h"
|
||||
|
||||
// Declare the functions we'll make available in Python
|
||||
extern mp_obj_t picodisplay2_init(mp_obj_t buf_obj);
|
||||
extern mp_obj_t picodisplay2_get_width();
|
||||
extern mp_obj_t picodisplay2_get_height();
|
||||
extern mp_obj_t picodisplay2_set_backlight(mp_obj_t brightness_obj);
|
||||
extern mp_obj_t picodisplay2_update();
|
||||
extern mp_obj_t picodisplay2_set_led(mp_obj_t r_obj, mp_obj_t g_obj, mp_obj_t b_obj);
|
||||
extern mp_obj_t picodisplay2_is_pressed(mp_obj_t button_obj);
|
||||
extern mp_obj_t picodisplay2_flip();
|
||||
|
||||
// From PicoGraphics parent class
|
||||
extern mp_obj_t picodisplay2_set_pen(mp_uint_t n_args, const mp_obj_t *args);
|
||||
extern mp_obj_t picodisplay2_create_pen(mp_obj_t r_obj, mp_obj_t g_obj, mp_obj_t b_obj);
|
||||
extern mp_obj_t picodisplay2_set_clip(mp_uint_t n_args, const mp_obj_t *args);
|
||||
extern mp_obj_t picodisplay2_remove_clip();
|
||||
extern mp_obj_t picodisplay2_clear();
|
||||
extern mp_obj_t picodisplay2_pixel(mp_obj_t x_obj, mp_obj_t y_obj);
|
||||
extern mp_obj_t picodisplay2_pixel_span(mp_obj_t x_obj, mp_obj_t y_obj, mp_obj_t l_obj);
|
||||
extern mp_obj_t picodisplay2_rectangle(mp_uint_t n_args, const mp_obj_t *args);
|
||||
extern mp_obj_t picodisplay2_circle(mp_obj_t x_obj, mp_obj_t y_obj, mp_obj_t r_obj);
|
||||
extern mp_obj_t picodisplay2_character(mp_uint_t n_args, const mp_obj_t *args);
|
||||
extern mp_obj_t picodisplay2_text(mp_uint_t n_args, const mp_obj_t *args);
|
|
@ -1,12 +1,12 @@
|
|||
set(MOD_NAME st7789)
|
||||
set(MOD_NAME picographics)
|
||||
string(TOUPPER ${MOD_NAME} MOD_NAME_UPPER)
|
||||
add_library(usermod_${MOD_NAME} INTERFACE)
|
||||
|
||||
target_sources(usermod_${MOD_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/picographics_st7789/picographics_st7789.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../drivers/st7789/st7789.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../drivers/st7735/st7735.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/pico_graphics/pico_graphics.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/pico_graphics/types.cpp
|
||||
)
|
|
@ -0,0 +1,104 @@
|
|||
#include "picographics.h"
|
||||
|
||||
// Module functions
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(ModPicoGraphics_module_RGB332_obj, ModPicoGraphics_module_RGB332);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(ModPicoGraphics_module_RGB565_obj, ModPicoGraphics_module_RGB565);
|
||||
|
||||
// Class Methods
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(ModPicoGraphics_update_obj, ModPicoGraphics_update);
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(ModPicoGraphics_set_backlight_obj, ModPicoGraphics_set_backlight);
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(ModPicoGraphics_set_framebuffer_obj, ModPicoGraphics_set_framebuffer);
|
||||
|
||||
// Palette management
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ModPicoGraphics_update_pen_obj, 5, 5, ModPicoGraphics_update_pen);
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(ModPicoGraphics_reset_pen_obj, ModPicoGraphics_reset_pen);
|
||||
|
||||
// Pen
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(ModPicoGraphics_set_pen_obj, ModPicoGraphics_set_pen);
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ModPicoGraphics_create_pen_obj, 4, 4, ModPicoGraphics_create_pen);
|
||||
|
||||
// Primitives
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ModPicoGraphics_set_clip_obj, 5, 5, ModPicoGraphics_set_clip);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(ModPicoGraphics_remove_clip_obj, ModPicoGraphics_remove_clip);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(ModPicoGraphics_clear_obj, ModPicoGraphics_clear);
|
||||
MP_DEFINE_CONST_FUN_OBJ_3(ModPicoGraphics_pixel_obj, ModPicoGraphics_pixel);
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ModPicoGraphics_pixel_span_obj, 4, 4, ModPicoGraphics_pixel_span);
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ModPicoGraphics_rectangle_obj, 5, 5, ModPicoGraphics_rectangle);
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ModPicoGraphics_circle_obj, 4, 4, ModPicoGraphics_circle);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(ModPicoGraphics_character_obj, 1, ModPicoGraphics_character);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(ModPicoGraphics_text_obj, 1, ModPicoGraphics_text);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(ModPicoGraphics_measure_text_obj, 1, ModPicoGraphics_measure_text);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(ModPicoGraphics_polygon_obj, 2, ModPicoGraphics_polygon);
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ModPicoGraphics_triangle_obj, 7, 7, ModPicoGraphics_triangle);
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ModPicoGraphics_line_obj, 5, 5, ModPicoGraphics_line);
|
||||
|
||||
// Utility
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(ModPicoGraphics_get_bounds_obj, ModPicoGraphics_get_bounds);
|
||||
|
||||
STATIC const mp_rom_map_elem_t ModPicoGraphics_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_pixel), MP_ROM_PTR(&ModPicoGraphics_pixel_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_pen), MP_ROM_PTR(&ModPicoGraphics_set_pen_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&ModPicoGraphics_update_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_update_pen), MP_ROM_PTR(&ModPicoGraphics_update_pen_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_reset_pen), MP_ROM_PTR(&ModPicoGraphics_reset_pen_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_backlight), MP_ROM_PTR(&ModPicoGraphics_set_backlight_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_create_pen), MP_ROM_PTR(&ModPicoGraphics_create_pen_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_clip), MP_ROM_PTR(&ModPicoGraphics_set_clip_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_remove_clip), MP_ROM_PTR(&ModPicoGraphics_remove_clip_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&ModPicoGraphics_clear_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_pixel_span), MP_ROM_PTR(&ModPicoGraphics_pixel_span_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_rectangle), MP_ROM_PTR(&ModPicoGraphics_rectangle_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_circle), MP_ROM_PTR(&ModPicoGraphics_circle_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_character), MP_ROM_PTR(&ModPicoGraphics_character_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_text), MP_ROM_PTR(&ModPicoGraphics_text_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_measure_text), MP_ROM_PTR(&ModPicoGraphics_measure_text_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_polygon), MP_ROM_PTR(&ModPicoGraphics_polygon_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_triangle), MP_ROM_PTR(&ModPicoGraphics_triangle_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_line), MP_ROM_PTR(&ModPicoGraphics_line_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_get_bounds), MP_ROM_PTR(&ModPicoGraphics_get_bounds_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_framebuffer), MP_ROM_PTR(&ModPicoGraphics_set_framebuffer_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(ModPicoGraphics_locals_dict, ModPicoGraphics_locals_dict_table);
|
||||
|
||||
/***** Class Definition *****/
|
||||
const mp_obj_type_t ModPicoGraphics_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_picographics,
|
||||
.make_new = ModPicoGraphics_make_new,
|
||||
.locals_dict = (mp_obj_dict_t*)&ModPicoGraphics_locals_dict,
|
||||
};
|
||||
|
||||
/***** Module Globals *****/
|
||||
STATIC const mp_map_elem_t picographics_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_picographics) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PicoGraphics), (mp_obj_t)&ModPicoGraphics_type },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_RGB332), MP_ROM_PTR(&ModPicoGraphics_module_RGB332_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_RGB565), MP_ROM_PTR(&ModPicoGraphics_module_RGB565_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_LCD_240X240), MP_ROM_INT(DISPLAY_LCD_240X240) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_ROUND_LCD_240X240), MP_ROM_INT(DISPLAY_ROUND_LCD_240X240) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_PICO_DISPLAY), MP_ROM_INT(DISPLAY_PICO_DISPLAY) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_PICO_DISPLAY_2), MP_ROM_INT(DISPLAY_PICO_DISPLAY_2) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_PICO_EXPLORER), MP_ROM_INT(DISPLAY_PICO_EXPLORER) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_TUFTY_2040), MP_ROM_INT(DISPLAY_TUFTY_2040) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_ENVIRO_PLUS), MP_ROM_INT(DISPLAY_ENVIRO_PLUS) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_LCD_160X80), MP_ROM_INT(DISPLAY_LCD_160X80) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_PEN_P4), MP_ROM_INT(PEN_P4) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PEN_P8), MP_ROM_INT(PEN_P8) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PEN_RGB332), MP_ROM_INT(PEN_RGB332) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PEN_RGB565), MP_ROM_INT(PEN_RGB565) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(mp_module_picographics_globals, picographics_globals_table);
|
||||
|
||||
/***** Module Definition *****/
|
||||
const mp_obj_module_t picographics_user_cmodule = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&mp_module_picographics_globals,
|
||||
};
|
||||
|
||||
MP_REGISTER_MODULE(MP_QSTR_picographics, picographics_user_cmodule, MODULE_PICOGRAPHICS_ENABLED);
|
|
@ -1,49 +1,50 @@
|
|||
#include "libraries/picographics_st7789/picographics_st7789.hpp"
|
||||
#include "drivers/st7789/st7789.hpp"
|
||||
#include "drivers/st7735/st7735.hpp"
|
||||
#include "libraries/pico_graphics/pico_graphics.hpp"
|
||||
#include "common/pimoroni_common.hpp"
|
||||
#include "common/pimoroni_bus.hpp"
|
||||
|
||||
#include "micropython/modules/util.hpp"
|
||||
|
||||
#ifndef PICO_GRAPHICS_PEN_TYPE
|
||||
#define PICO_GRAPHICS_PEN_TYPE PenRGB332
|
||||
#endif
|
||||
|
||||
using namespace pimoroni;
|
||||
|
||||
extern "C" {
|
||||
#include "st7789.h"
|
||||
#include "picographics.h"
|
||||
#include "micropython/modules/pimoroni_bus/pimoroni_bus.h"
|
||||
|
||||
typedef struct _GenericST7789_obj_t {
|
||||
typedef struct _ModPicoGraphics_obj_t {
|
||||
mp_obj_base_t base;
|
||||
PicoGraphicsST7789<PICO_GRAPHICS_PEN_TYPE> *st7789;
|
||||
PicoGraphics *graphics;
|
||||
DisplayDriver *display;
|
||||
void *buffer;
|
||||
} GenericST7789_obj_t;
|
||||
} ModPicoGraphics_obj_t;
|
||||
|
||||
mp_obj_t GenericST7789_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
GenericST7789_obj_t *self = nullptr;
|
||||
mp_obj_t ModPicoGraphics_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
ModPicoGraphics_obj_t *self = nullptr;
|
||||
|
||||
enum { ARG_display, ARG_rotate, ARG_bus, ARG_buffer };
|
||||
enum { ARG_display, ARG_rotate, ARG_bus, ARG_buffer, ARG_pen_type };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_display, MP_ARG_INT | MP_ARG_REQUIRED },
|
||||
{ MP_QSTR_rotate, MP_ARG_INT, { .u_int = Rotation::ROTATE_0 } },
|
||||
{ MP_QSTR_bus, MP_ARG_OBJ, { .u_obj = mp_const_none } },
|
||||
{ MP_QSTR_buffer, MP_ARG_OBJ, { .u_obj = mp_const_none } },
|
||||
{ MP_QSTR_pen_type, MP_ARG_INT, { .u_int = PEN_RGB332 } },
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
self = m_new_obj(GenericST7789_obj_t);
|
||||
self->base.type = &GenericST7789_type;
|
||||
self = m_new_obj(ModPicoGraphics_obj_t);
|
||||
self->base.type = &ModPicoGraphics_type;
|
||||
|
||||
Rotation rotate = (Rotation)args[ARG_rotate].u_int;
|
||||
bool round = false;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
|
||||
ST7789Display display = (ST7789Display)args[ARG_display].u_int;
|
||||
PicoGraphicsPenType pen_type = (PicoGraphicsPenType)args[ARG_pen_type].u_int;
|
||||
PicoGraphicsDisplay display = (PicoGraphicsDisplay)args[ARG_display].u_int;
|
||||
|
||||
switch(display) {
|
||||
case DISPLAY_PICO_DISPLAY:
|
||||
|
@ -66,9 +67,64 @@ mp_obj_t GenericST7789_make_new(const mp_obj_type_t *type, size_t n_args, size_t
|
|||
height = 240;
|
||||
round = true;
|
||||
break;
|
||||
case DISPLAY_LCD_160X80:
|
||||
width = 160;
|
||||
height = 80;
|
||||
break;
|
||||
default:
|
||||
mp_raise_ValueError("Unsupported display!");
|
||||
break; // unreachable
|
||||
}
|
||||
|
||||
size_t required_size = PICO_GRAPHICS_PEN_TYPE::buffer_size(width, height);
|
||||
// Try to create an appropriate display driver
|
||||
if (display == DISPLAY_TUFTY_2040) {
|
||||
if (args[ARG_bus].u_obj == mp_const_none) {
|
||||
self->display = m_new_class(ST7789, width, height, rotate, {10, 11, 12, 13, 14, 2});
|
||||
} 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);
|
||||
self->display = m_new_class(ST7789, width, height, rotate, *(ParallelPins *)(bus->pins));
|
||||
} else {
|
||||
mp_raise_ValueError("ParallelBus expected!");
|
||||
}
|
||||
} else if (display == DISPLAY_LCD_160X80) {
|
||||
if (args[ARG_bus].u_obj == mp_const_none) {
|
||||
self->display = m_new_class(ST7735, width, height, get_spi_pins(BG_SPI_FRONT));
|
||||
} 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);
|
||||
self->display = m_new_class(ST7735, width, height, *(SPIPins *)(bus->pins));
|
||||
} else {
|
||||
mp_raise_ValueError("SPIBus expected!");
|
||||
}
|
||||
} else {
|
||||
if (args[ARG_bus].u_obj == mp_const_none) {
|
||||
self->display = m_new_class(ST7789, width, height, rotate, round, get_spi_pins(BG_SPI_FRONT));
|
||||
} 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);
|
||||
self->display = m_new_class(ST7789, width, height, rotate, round, *(SPIPins *)(bus->pins));
|
||||
} else {
|
||||
mp_raise_ValueError("SPIBus expected!");
|
||||
}
|
||||
}
|
||||
|
||||
// Create or fetch buffer
|
||||
size_t required_size = 0;
|
||||
switch(pen_type) {
|
||||
case PEN_P4:
|
||||
required_size = PicoGraphics_PenP4::buffer_size(width, height);
|
||||
break;
|
||||
case PEN_P8:
|
||||
required_size = PicoGraphics_PenP8::buffer_size(width, height);
|
||||
break;
|
||||
case PEN_RGB332:
|
||||
required_size = PicoGraphics_PenRGB332::buffer_size(width, height);
|
||||
break;
|
||||
case PEN_RGB565:
|
||||
required_size = PicoGraphics_PenRGB565::buffer_size(width, height);
|
||||
break;
|
||||
default:
|
||||
mp_raise_ValueError("Unsupported display!");
|
||||
break; // unreachable
|
||||
}
|
||||
|
||||
if (args[ARG_buffer].u_obj != mp_const_none) {
|
||||
mp_buffer_info_t bufinfo;
|
||||
|
@ -81,112 +137,121 @@ mp_obj_t GenericST7789_make_new(const mp_obj_type_t *type, size_t n_args, size_t
|
|||
self->buffer = m_new(uint8_t, required_size);
|
||||
}
|
||||
|
||||
if (display == DISPLAY_TUFTY_2040) {
|
||||
if (args[ARG_bus].u_obj == mp_const_none) {
|
||||
self->st7789 = m_new_class(PicoGraphicsST7789<PICO_GRAPHICS_PEN_TYPE>, width, height, rotate, self->buffer, {10, 11, 12, 13, 14, 2});
|
||||
} 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);
|
||||
self->st7789 = m_new_class(PicoGraphicsST7789<PICO_GRAPHICS_PEN_TYPE>, width, height, rotate, self->buffer, *(ParallelPins *)(bus->pins));
|
||||
} else {
|
||||
mp_raise_ValueError("ParallelBus expected!");
|
||||
}
|
||||
} else {
|
||||
if (args[ARG_bus].u_obj == mp_const_none) {
|
||||
self->st7789 = m_new_class(PicoGraphicsST7789<PICO_GRAPHICS_PEN_TYPE>, 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)) {
|
||||
_PimoroniBus_obj_t *bus = (_PimoroniBus_obj_t *)MP_OBJ_TO_PTR(args[ARG_bus].u_obj);
|
||||
self->st7789 = m_new_class(PicoGraphicsST7789<PICO_GRAPHICS_PEN_TYPE>, width, height, rotate, round, self->buffer, *(SPIPins *)(bus->pins));
|
||||
} else {
|
||||
mp_raise_ValueError("SPIBus expected!");
|
||||
}
|
||||
// Create an instance of the graphics library
|
||||
// use the *driver* width/height because they may have been swapped due to rotation
|
||||
switch(pen_type) {
|
||||
case PEN_P4:
|
||||
self->graphics = m_new_class(PicoGraphics_PenP4, self->display->width, self->display->height, self->buffer);
|
||||
break;
|
||||
case PEN_P8:
|
||||
self->graphics = m_new_class(PicoGraphics_PenP8, self->display->width, self->display->height, self->buffer);
|
||||
break;
|
||||
case PEN_RGB332:
|
||||
self->graphics = m_new_class(PicoGraphics_PenRGB332, self->display->width, self->display->height, self->buffer);
|
||||
break;
|
||||
case PEN_RGB565:
|
||||
self->graphics = m_new_class(PicoGraphics_PenRGB565, self->display->width, self->display->height, self->buffer);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Clear the buffer
|
||||
self->graphics->set_pen(0);
|
||||
self->graphics->clear();
|
||||
|
||||
// Update the LCD from the graphics library
|
||||
self->display->update(self->graphics);
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
mp_obj_t GenericST7789_set_framebuffer(mp_obj_t self_in, mp_obj_t framebuffer) {
|
||||
GenericST7789_obj_t *self = MP_OBJ_TO_PTR2(self_in, GenericST7789_obj_t);
|
||||
mp_obj_t ModPicoGraphics_set_framebuffer(mp_obj_t self_in, mp_obj_t framebuffer) {
|
||||
(void)self_in;
|
||||
(void)framebuffer;
|
||||
/*
|
||||
ModPicoGraphics_obj_t *self = MP_OBJ_TO_PTR2(self_in, ModPicoGraphics_obj_t);
|
||||
|
||||
if (framebuffer == mp_const_none) {
|
||||
m_del(uint8_t, self->buffer, self->st7789->bounds.w * self->st7789->bounds.h);
|
||||
m_del(uint8_t, self->buffer, self->graphics->bounds.w * self->graphics->bounds.h);
|
||||
self->buffer = nullptr;
|
||||
self->st7789->set_framebuffer(nullptr);
|
||||
self->graphics->set_framebuffer(nullptr);
|
||||
} else {
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(framebuffer, &bufinfo, MP_BUFFER_RW);
|
||||
self->buffer = bufinfo.buf;
|
||||
self->st7789->set_framebuffer(self->buffer);
|
||||
self->graphics->set_framebuffer(self->buffer);
|
||||
}
|
||||
|
||||
*/
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t GenericST7789_get_bounds(mp_obj_t self_in) {
|
||||
GenericST7789_obj_t *self = MP_OBJ_TO_PTR2(self_in, GenericST7789_obj_t);
|
||||
mp_obj_t ModPicoGraphics_get_bounds(mp_obj_t self_in) {
|
||||
ModPicoGraphics_obj_t *self = MP_OBJ_TO_PTR2(self_in, ModPicoGraphics_obj_t);
|
||||
mp_obj_t tuple[2] = {
|
||||
mp_obj_new_int(self->st7789->bounds.w),
|
||||
mp_obj_new_int(self->st7789->bounds.h)
|
||||
mp_obj_new_int(self->graphics->bounds.w),
|
||||
mp_obj_new_int(self->graphics->bounds.h)
|
||||
};
|
||||
return mp_obj_new_tuple(2, tuple);
|
||||
}
|
||||
|
||||
mp_obj_t GenericST7789_update(mp_obj_t self_in) {
|
||||
GenericST7789_obj_t *self = MP_OBJ_TO_PTR2(self_in, GenericST7789_obj_t);
|
||||
self->st7789->update();
|
||||
mp_obj_t ModPicoGraphics_update(mp_obj_t self_in) {
|
||||
ModPicoGraphics_obj_t *self = MP_OBJ_TO_PTR2(self_in, ModPicoGraphics_obj_t);
|
||||
self->display->update(self->graphics);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t GenericST7789_set_backlight(mp_obj_t self_in, mp_obj_t brightness) {
|
||||
GenericST7789_obj_t *self = MP_OBJ_TO_PTR2(self_in, GenericST7789_obj_t);
|
||||
mp_obj_t ModPicoGraphics_set_backlight(mp_obj_t self_in, mp_obj_t brightness) {
|
||||
ModPicoGraphics_obj_t *self = MP_OBJ_TO_PTR2(self_in, ModPicoGraphics_obj_t);
|
||||
|
||||
float b = mp_obj_get_float(brightness);
|
||||
|
||||
if(b < 0 || b > 1.0f) mp_raise_ValueError("brightness out of range. Expected 0.0 to 1.0");
|
||||
|
||||
self->st7789->set_backlight((uint8_t)(b * 255.0f));
|
||||
self->display->set_backlight((uint8_t)(b * 255.0f));
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t GenericST7789_module_RGB332(mp_obj_t r, mp_obj_t g, mp_obj_t b) {
|
||||
return mp_obj_new_int(PicoGraphicsPenType::rgb_to_rgb332(
|
||||
mp_obj_t ModPicoGraphics_module_RGB332(mp_obj_t r, mp_obj_t g, mp_obj_t b) {
|
||||
return mp_obj_new_int(PicoGraphics::rgb_to_rgb332(
|
||||
mp_obj_get_int(r),
|
||||
mp_obj_get_int(g),
|
||||
mp_obj_get_int(b)
|
||||
));
|
||||
}
|
||||
|
||||
mp_obj_t GenericST7789_module_RGB565(mp_obj_t r, mp_obj_t g, mp_obj_t b) {
|
||||
return mp_obj_new_int(PicoGraphicsPenType::rgb_to_rgb565(
|
||||
mp_obj_t ModPicoGraphics_module_RGB565(mp_obj_t r, mp_obj_t g, mp_obj_t b) {
|
||||
return mp_obj_new_int(PicoGraphics::rgb_to_rgb565(
|
||||
mp_obj_get_int(r),
|
||||
mp_obj_get_int(g),
|
||||
mp_obj_get_int(b)
|
||||
));
|
||||
}
|
||||
|
||||
mp_obj_t GenericST7789_set_pen(mp_obj_t self_in, mp_obj_t pen) {
|
||||
GenericST7789_obj_t *self = MP_OBJ_TO_PTR2(self_in, GenericST7789_obj_t);
|
||||
mp_obj_t ModPicoGraphics_set_pen(mp_obj_t self_in, mp_obj_t pen) {
|
||||
ModPicoGraphics_obj_t *self = MP_OBJ_TO_PTR2(self_in, ModPicoGraphics_obj_t);
|
||||
|
||||
self->st7789->set_pen(mp_obj_get_int(pen));
|
||||
self->graphics->set_pen(mp_obj_get_int(pen));
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t GenericST7789_reset_pen(mp_obj_t self_in, mp_obj_t pen) {
|
||||
GenericST7789_obj_t *self = MP_OBJ_TO_PTR2(self_in, GenericST7789_obj_t);
|
||||
mp_obj_t ModPicoGraphics_reset_pen(mp_obj_t self_in, mp_obj_t pen) {
|
||||
ModPicoGraphics_obj_t *self = MP_OBJ_TO_PTR2(self_in, ModPicoGraphics_obj_t);
|
||||
|
||||
self->st7789->reset_pen(mp_obj_get_int(pen));
|
||||
self->graphics->reset_pen(mp_obj_get_int(pen));
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t GenericST7789_update_pen(size_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_t ModPicoGraphics_update_pen(size_t n_args, const mp_obj_t *args) {
|
||||
enum { ARG_self, ARG_i, ARG_r, ARG_g, ARG_b };
|
||||
|
||||
GenericST7789_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self], GenericST7789_obj_t);
|
||||
ModPicoGraphics_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self], ModPicoGraphics_obj_t);
|
||||
|
||||
self->st7789->update_pen(
|
||||
self->graphics->update_pen(
|
||||
mp_obj_get_int(args[ARG_i]) & 0xff,
|
||||
mp_obj_get_int(args[ARG_r]) & 0xff,
|
||||
mp_obj_get_int(args[ARG_g]) & 0xff,
|
||||
|
@ -196,12 +261,12 @@ mp_obj_t GenericST7789_update_pen(size_t n_args, const mp_obj_t *args) {
|
|||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t GenericST7789_create_pen(size_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_t ModPicoGraphics_create_pen(size_t n_args, const mp_obj_t *args) {
|
||||
enum { ARG_self, ARG_r, ARG_g, ARG_b };
|
||||
|
||||
GenericST7789_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self], GenericST7789_obj_t);
|
||||
ModPicoGraphics_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self], ModPicoGraphics_obj_t);
|
||||
|
||||
int result = self->st7789->create_pen(
|
||||
int result = self->graphics->create_pen(
|
||||
mp_obj_get_int(args[ARG_r]) & 0xff,
|
||||
mp_obj_get_int(args[ARG_g]) & 0xff,
|
||||
mp_obj_get_int(args[ARG_b]) & 0xff
|
||||
|
@ -212,12 +277,12 @@ mp_obj_t GenericST7789_create_pen(size_t n_args, const mp_obj_t *args) {
|
|||
return mp_obj_new_int(result);
|
||||
}
|
||||
|
||||
mp_obj_t GenericST7789_set_clip(size_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_t ModPicoGraphics_set_clip(size_t n_args, const mp_obj_t *args) {
|
||||
enum { ARG_self, ARG_x, ARG_y, ARG_w, ARG_h };
|
||||
|
||||
GenericST7789_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self], GenericST7789_obj_t);
|
||||
ModPicoGraphics_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self], ModPicoGraphics_obj_t);
|
||||
|
||||
self->st7789->set_clip({
|
||||
self->graphics->set_clip({
|
||||
mp_obj_get_int(args[ARG_x]),
|
||||
mp_obj_get_int(args[ARG_y]),
|
||||
mp_obj_get_int(args[ARG_w]),
|
||||
|
@ -227,26 +292,26 @@ mp_obj_t GenericST7789_set_clip(size_t n_args, const mp_obj_t *args) {
|
|||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t GenericST7789_remove_clip(mp_obj_t self_in) {
|
||||
GenericST7789_obj_t *self = MP_OBJ_TO_PTR2(self_in, GenericST7789_obj_t);
|
||||
mp_obj_t ModPicoGraphics_remove_clip(mp_obj_t self_in) {
|
||||
ModPicoGraphics_obj_t *self = MP_OBJ_TO_PTR2(self_in, ModPicoGraphics_obj_t);
|
||||
|
||||
self->st7789->remove_clip();
|
||||
self->graphics->remove_clip();
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t GenericST7789_clear(mp_obj_t self_in) {
|
||||
GenericST7789_obj_t *self = MP_OBJ_TO_PTR2(self_in, GenericST7789_obj_t);
|
||||
mp_obj_t ModPicoGraphics_clear(mp_obj_t self_in) {
|
||||
ModPicoGraphics_obj_t *self = MP_OBJ_TO_PTR2(self_in, ModPicoGraphics_obj_t);
|
||||
|
||||
self->st7789->clear();
|
||||
self->graphics->clear();
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t GenericST7789_pixel(mp_obj_t self_in, mp_obj_t x, mp_obj_t y) {
|
||||
GenericST7789_obj_t *self = MP_OBJ_TO_PTR2(self_in, GenericST7789_obj_t);
|
||||
mp_obj_t ModPicoGraphics_pixel(mp_obj_t self_in, mp_obj_t x, mp_obj_t y) {
|
||||
ModPicoGraphics_obj_t *self = MP_OBJ_TO_PTR2(self_in, ModPicoGraphics_obj_t);
|
||||
|
||||
self->st7789->pixel({
|
||||
self->graphics->pixel({
|
||||
mp_obj_get_int(x),
|
||||
mp_obj_get_int(y)
|
||||
});
|
||||
|
@ -254,12 +319,12 @@ mp_obj_t GenericST7789_pixel(mp_obj_t self_in, mp_obj_t x, mp_obj_t y) {
|
|||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t GenericST7789_pixel_span(size_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_t ModPicoGraphics_pixel_span(size_t n_args, const mp_obj_t *args) {
|
||||
enum { ARG_self, ARG_x, ARG_y, ARG_l };
|
||||
|
||||
GenericST7789_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self], GenericST7789_obj_t);
|
||||
ModPicoGraphics_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self], ModPicoGraphics_obj_t);
|
||||
|
||||
self->st7789->pixel_span({
|
||||
self->graphics->pixel_span({
|
||||
mp_obj_get_int(args[ARG_x]),
|
||||
mp_obj_get_int(args[ARG_y])
|
||||
}, mp_obj_get_int(args[ARG_l]));
|
||||
|
@ -267,12 +332,12 @@ mp_obj_t GenericST7789_pixel_span(size_t n_args, const mp_obj_t *args) {
|
|||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t GenericST7789_rectangle(size_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_t ModPicoGraphics_rectangle(size_t n_args, const mp_obj_t *args) {
|
||||
enum { ARG_self, ARG_x, ARG_y, ARG_w, ARG_h };
|
||||
|
||||
GenericST7789_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self], GenericST7789_obj_t);
|
||||
ModPicoGraphics_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self], ModPicoGraphics_obj_t);
|
||||
|
||||
self->st7789->rectangle({
|
||||
self->graphics->rectangle({
|
||||
mp_obj_get_int(args[ARG_x]),
|
||||
mp_obj_get_int(args[ARG_y]),
|
||||
mp_obj_get_int(args[ARG_w]),
|
||||
|
@ -282,12 +347,12 @@ mp_obj_t GenericST7789_rectangle(size_t n_args, const mp_obj_t *args) {
|
|||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t GenericST7789_circle(size_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_t ModPicoGraphics_circle(size_t n_args, const mp_obj_t *args) {
|
||||
enum { ARG_self, ARG_x, ARG_y, ARG_r };
|
||||
|
||||
GenericST7789_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self], GenericST7789_obj_t);
|
||||
ModPicoGraphics_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self], ModPicoGraphics_obj_t);
|
||||
|
||||
self->st7789->circle({
|
||||
self->graphics->circle({
|
||||
mp_obj_get_int(args[ARG_x]),
|
||||
mp_obj_get_int(args[ARG_y])
|
||||
}, mp_obj_get_int(args[ARG_r]));
|
||||
|
@ -295,7 +360,7 @@ mp_obj_t GenericST7789_circle(size_t n_args, const mp_obj_t *args) {
|
|||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t GenericST7789_character(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
mp_obj_t ModPicoGraphics_character(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_self, ARG_char, ARG_x, ARG_y, ARG_scale };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
|
@ -308,19 +373,19 @@ mp_obj_t GenericST7789_character(size_t n_args, const mp_obj_t *pos_args, mp_map
|
|||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
GenericST7789_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, GenericST7789_obj_t);
|
||||
ModPicoGraphics_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, ModPicoGraphics_obj_t);
|
||||
|
||||
int c = mp_obj_get_int(args[ARG_char].u_obj);
|
||||
int x = args[ARG_x].u_int;
|
||||
int y = args[ARG_y].u_int;
|
||||
int scale = args[ARG_scale].u_int;
|
||||
|
||||
self->st7789->character((char)c, Point(x, y), scale);
|
||||
self->graphics->character((char)c, Point(x, y), scale);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t GenericST7789_text(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
mp_obj_t ModPicoGraphics_text(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_self, ARG_text, ARG_x, ARG_y, ARG_wrap, ARG_scale };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
|
@ -334,7 +399,7 @@ mp_obj_t GenericST7789_text(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
|
|||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
GenericST7789_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, GenericST7789_obj_t);
|
||||
ModPicoGraphics_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, ModPicoGraphics_obj_t);
|
||||
|
||||
mp_obj_t text_obj = args[ARG_text].u_obj;
|
||||
|
||||
|
@ -349,12 +414,12 @@ mp_obj_t GenericST7789_text(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
|
|||
int wrap = args[ARG_wrap].u_int;
|
||||
int scale = args[ARG_scale].u_int;
|
||||
|
||||
self->st7789->text(t, Point(x, y), wrap, scale);
|
||||
self->graphics->text(t, Point(x, y), wrap, scale);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t GenericST7789_measure_text(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
mp_obj_t ModPicoGraphics_measure_text(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_self, ARG_text, ARG_scale };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
|
@ -365,7 +430,7 @@ mp_obj_t GenericST7789_measure_text(size_t n_args, const mp_obj_t *pos_args, mp_
|
|||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
GenericST7789_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, GenericST7789_obj_t);
|
||||
ModPicoGraphics_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, ModPicoGraphics_obj_t);
|
||||
|
||||
mp_obj_t text_obj = args[ARG_text].u_obj;
|
||||
|
||||
|
@ -377,16 +442,16 @@ mp_obj_t GenericST7789_measure_text(size_t n_args, const mp_obj_t *pos_args, mp_
|
|||
|
||||
int scale = args[ARG_scale].u_int;
|
||||
|
||||
int width = self->st7789->measure_text(t, scale);
|
||||
int width = self->graphics->measure_text(t, scale);
|
||||
|
||||
return mp_obj_new_int(width);
|
||||
}
|
||||
|
||||
mp_obj_t GenericST7789_polygon(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
mp_obj_t ModPicoGraphics_polygon(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
size_t num_tuples = n_args - 1;
|
||||
const mp_obj_t *tuples = pos_args + 1;
|
||||
|
||||
GenericST7789_obj_t *self = MP_OBJ_TO_PTR2(pos_args[0], GenericST7789_obj_t);
|
||||
ModPicoGraphics_obj_t *self = MP_OBJ_TO_PTR2(pos_args[0], ModPicoGraphics_obj_t);
|
||||
|
||||
// Check if there is only one argument, which might be a list
|
||||
if(n_args == 2) {
|
||||
|
@ -418,18 +483,18 @@ mp_obj_t GenericST7789_polygon(size_t n_args, const mp_obj_t *pos_args, mp_map_t
|
|||
mp_obj_get_int(tuple->items[1])
|
||||
});
|
||||
}
|
||||
self->st7789->polygon(points);
|
||||
self->graphics->polygon(points);
|
||||
}
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t GenericST7789_triangle(size_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_t ModPicoGraphics_triangle(size_t n_args, const mp_obj_t *args) {
|
||||
enum { ARG_self, ARG_x1, ARG_y1, ARG_x2, ARG_y2, ARG_x3, ARG_y3 };
|
||||
|
||||
GenericST7789_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self], GenericST7789_obj_t);
|
||||
ModPicoGraphics_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self], ModPicoGraphics_obj_t);
|
||||
|
||||
self->st7789->triangle(
|
||||
self->graphics->triangle(
|
||||
{mp_obj_get_int(args[ARG_x1]),
|
||||
mp_obj_get_int(args[ARG_y1])},
|
||||
{mp_obj_get_int(args[ARG_x2]),
|
||||
|
@ -441,12 +506,12 @@ mp_obj_t GenericST7789_triangle(size_t n_args, const mp_obj_t *args) {
|
|||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t GenericST7789_line(size_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_t ModPicoGraphics_line(size_t n_args, const mp_obj_t *args) {
|
||||
enum { ARG_self, ARG_x1, ARG_y1, ARG_x2, ARG_y2 };
|
||||
|
||||
GenericST7789_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self], GenericST7789_obj_t);
|
||||
ModPicoGraphics_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self], ModPicoGraphics_obj_t);
|
||||
|
||||
self->st7789->line(
|
||||
self->graphics->line(
|
||||
{mp_obj_get_int(args[ARG_x1]),
|
||||
mp_obj_get_int(args[ARG_y1])},
|
||||
{mp_obj_get_int(args[ARG_x2]),
|
|
@ -0,0 +1,61 @@
|
|||
#include "py/runtime.h"
|
||||
#include "py/objstr.h"
|
||||
|
||||
enum PicoGraphicsDisplay {
|
||||
DISPLAY_LCD_240X240=0,
|
||||
DISPLAY_ROUND_LCD_240X240,
|
||||
DISPLAY_PICO_DISPLAY,
|
||||
DISPLAY_PICO_DISPLAY_2,
|
||||
DISPLAY_PICO_EXPLORER,
|
||||
DISPLAY_TUFTY_2040,
|
||||
DISPLAY_ENVIRO_PLUS,
|
||||
DISPLAY_LCD_160X80
|
||||
};
|
||||
|
||||
enum PicoGraphicsPenType {
|
||||
PEN_P2 = 0,
|
||||
PEN_P4,
|
||||
PEN_P8,
|
||||
PEN_RGB332,
|
||||
PEN_RGB565
|
||||
};
|
||||
|
||||
// Type
|
||||
extern const mp_obj_type_t ModPicoGraphics_type;
|
||||
|
||||
// Module functions
|
||||
extern mp_obj_t ModPicoGraphics_module_RGB332(mp_obj_t r, mp_obj_t g, mp_obj_t b);
|
||||
extern mp_obj_t ModPicoGraphics_module_RGB565(mp_obj_t r, mp_obj_t g, mp_obj_t b);
|
||||
|
||||
// Class methods
|
||||
extern mp_obj_t ModPicoGraphics_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args);
|
||||
|
||||
extern mp_obj_t ModPicoGraphics_update(mp_obj_t self_in);
|
||||
extern mp_obj_t ModPicoGraphics_set_backlight(mp_obj_t self_in, mp_obj_t brightness);
|
||||
|
||||
// Palette management
|
||||
extern mp_obj_t ModPicoGraphics_update_pen(size_t n_args, const mp_obj_t *args);
|
||||
extern mp_obj_t ModPicoGraphics_reset_pen(mp_obj_t self_in, mp_obj_t pen);
|
||||
|
||||
// Pen
|
||||
extern mp_obj_t ModPicoGraphics_set_pen(mp_obj_t self_in, mp_obj_t pen);
|
||||
extern mp_obj_t ModPicoGraphics_create_pen(size_t n_args, const mp_obj_t *args);
|
||||
|
||||
// Primitives
|
||||
extern mp_obj_t ModPicoGraphics_set_clip(size_t n_args, const mp_obj_t *args);
|
||||
extern mp_obj_t ModPicoGraphics_remove_clip(mp_obj_t self_in);
|
||||
extern mp_obj_t ModPicoGraphics_clear(mp_obj_t self_in);
|
||||
extern mp_obj_t ModPicoGraphics_pixel(mp_obj_t self_in, mp_obj_t x, mp_obj_t y);
|
||||
extern mp_obj_t ModPicoGraphics_pixel_span(size_t n_args, const mp_obj_t *args);
|
||||
extern mp_obj_t ModPicoGraphics_rectangle(size_t n_args, const mp_obj_t *args);
|
||||
extern mp_obj_t ModPicoGraphics_circle(size_t n_args, const mp_obj_t *args);
|
||||
extern mp_obj_t ModPicoGraphics_character(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t ModPicoGraphics_text(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t ModPicoGraphics_measure_text(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t ModPicoGraphics_polygon(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t ModPicoGraphics_triangle(size_t n_args, const mp_obj_t *args);
|
||||
extern mp_obj_t ModPicoGraphics_line(size_t n_args, const mp_obj_t *args);
|
||||
|
||||
// Utility
|
||||
extern mp_obj_t ModPicoGraphics_get_bounds(mp_obj_t self_in);
|
||||
extern mp_obj_t ModPicoGraphics_set_framebuffer(mp_obj_t self_in, mp_obj_t framebuffer);
|
|
@ -1,98 +0,0 @@
|
|||
#include "st7789.h"
|
||||
|
||||
// Module functions
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(GenericST7789_module_RGB332_obj, GenericST7789_module_RGB332);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(GenericST7789_module_RGB565_obj, GenericST7789_module_RGB565);
|
||||
|
||||
// Class Methods
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(GenericST7789_update_obj, GenericST7789_update);
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(GenericST7789_set_backlight_obj, GenericST7789_set_backlight);
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(GenericST7789_set_framebuffer_obj, GenericST7789_set_framebuffer);
|
||||
|
||||
// Palette management
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(GenericST7789_update_pen_obj, 5, 5, GenericST7789_update_pen);
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(GenericST7789_reset_pen_obj, GenericST7789_reset_pen);
|
||||
|
||||
// Pen
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(GenericST7789_set_pen_obj, GenericST7789_set_pen);
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(GenericST7789_create_pen_obj, 4, 4, GenericST7789_create_pen);
|
||||
|
||||
// Primitives
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(GenericST7789_set_clip_obj, 5, 5, GenericST7789_set_clip);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(GenericST7789_remove_clip_obj, GenericST7789_remove_clip);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(GenericST7789_clear_obj, GenericST7789_clear);
|
||||
MP_DEFINE_CONST_FUN_OBJ_3(GenericST7789_pixel_obj, GenericST7789_pixel);
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(GenericST7789_pixel_span_obj, 4, 4, GenericST7789_pixel_span);
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(GenericST7789_rectangle_obj, 5, 5, GenericST7789_rectangle);
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(GenericST7789_circle_obj, 4, 4, GenericST7789_circle);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(GenericST7789_character_obj, 1, GenericST7789_character);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(GenericST7789_text_obj, 1, GenericST7789_text);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(GenericST7789_measure_text_obj, 1, GenericST7789_measure_text);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(GenericST7789_polygon_obj, 2, GenericST7789_polygon);
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(GenericST7789_triangle_obj, 7, 7, GenericST7789_triangle);
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(GenericST7789_line_obj, 5, 5, GenericST7789_line);
|
||||
|
||||
// Utility
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(GenericST7789_get_bounds_obj, GenericST7789_get_bounds);
|
||||
|
||||
STATIC const mp_rom_map_elem_t GenericST7789_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_pixel), MP_ROM_PTR(&GenericST7789_pixel_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_pen), MP_ROM_PTR(&GenericST7789_set_pen_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&GenericST7789_update_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_update_pen), MP_ROM_PTR(&GenericST7789_update_pen_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_reset_pen), MP_ROM_PTR(&GenericST7789_reset_pen_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_backlight), MP_ROM_PTR(&GenericST7789_set_backlight_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_create_pen), MP_ROM_PTR(&GenericST7789_create_pen_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_clip), MP_ROM_PTR(&GenericST7789_set_clip_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_remove_clip), MP_ROM_PTR(&GenericST7789_remove_clip_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&GenericST7789_clear_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_pixel_span), MP_ROM_PTR(&GenericST7789_pixel_span_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_rectangle), MP_ROM_PTR(&GenericST7789_rectangle_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_circle), MP_ROM_PTR(&GenericST7789_circle_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_character), MP_ROM_PTR(&GenericST7789_character_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_text), MP_ROM_PTR(&GenericST7789_text_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_measure_text), MP_ROM_PTR(&GenericST7789_measure_text_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_polygon), MP_ROM_PTR(&GenericST7789_polygon_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_triangle), MP_ROM_PTR(&GenericST7789_triangle_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_line), MP_ROM_PTR(&GenericST7789_line_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_get_bounds), MP_ROM_PTR(&GenericST7789_get_bounds_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_framebuffer), MP_ROM_PTR(&GenericST7789_set_framebuffer_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(GenericST7789_locals_dict, GenericST7789_locals_dict_table);
|
||||
|
||||
/***** Class Definition *****/
|
||||
const mp_obj_type_t GenericST7789_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_st7789,
|
||||
.make_new = GenericST7789_make_new,
|
||||
.locals_dict = (mp_obj_dict_t*)&GenericST7789_locals_dict,
|
||||
};
|
||||
|
||||
/***** Module Globals *****/
|
||||
STATIC const mp_map_elem_t st7789_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_st7789) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_ST7789), (mp_obj_t)&GenericST7789_type },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_RGB332), MP_ROM_PTR(&GenericST7789_module_RGB332_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_RGB565), MP_ROM_PTR(&GenericST7789_module_RGB565_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_LCD_240X240), MP_ROM_INT(DISPLAY_LCD_240X240) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_ROUND_LCD_240X240), MP_ROM_INT(DISPLAY_ROUND_LCD_240X240) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_PICO_DISPLAY), MP_ROM_INT(DISPLAY_PICO_DISPLAY) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_PICO_DISPLAY_2), MP_ROM_INT(DISPLAY_PICO_DISPLAY_2) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_PICO_EXPLORER), MP_ROM_INT(DISPLAY_PICO_EXPLORER) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_TUFTY_2040), MP_ROM_INT(DISPLAY_TUFTY_2040) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_ENVIRO_PLUS), MP_ROM_INT(DISPLAY_ENVIRO_PLUS) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(mp_module_st7789_globals, st7789_globals_table);
|
||||
|
||||
/***** Module Definition *****/
|
||||
const mp_obj_module_t st7789_user_cmodule = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&mp_module_st7789_globals,
|
||||
};
|
||||
|
||||
MP_REGISTER_MODULE(MP_QSTR_st7789, st7789_user_cmodule, MODULE_ST7789_ENABLED);
|
|
@ -1,52 +0,0 @@
|
|||
#include "py/runtime.h"
|
||||
#include "py/objstr.h"
|
||||
|
||||
enum ST7789Display {
|
||||
DISPLAY_LCD_240X240=0,
|
||||
DISPLAY_ROUND_LCD_240X240,
|
||||
DISPLAY_PICO_DISPLAY,
|
||||
DISPLAY_PICO_DISPLAY_2,
|
||||
DISPLAY_PICO_EXPLORER,
|
||||
DISPLAY_TUFTY_2040,
|
||||
DISPLAY_ENVIRO_PLUS
|
||||
};
|
||||
|
||||
// Type
|
||||
extern const mp_obj_type_t GenericST7789_type;
|
||||
|
||||
// Module functions
|
||||
extern mp_obj_t GenericST7789_module_RGB332(mp_obj_t r, mp_obj_t g, mp_obj_t b);
|
||||
extern mp_obj_t GenericST7789_module_RGB565(mp_obj_t r, mp_obj_t g, mp_obj_t b);
|
||||
|
||||
// Class methods
|
||||
extern mp_obj_t GenericST7789_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args);
|
||||
|
||||
extern mp_obj_t GenericST7789_update(mp_obj_t self_in);
|
||||
extern mp_obj_t GenericST7789_set_backlight(mp_obj_t self_in, mp_obj_t brightness);
|
||||
|
||||
// Palette management
|
||||
extern mp_obj_t GenericST7789_update_pen(size_t n_args, const mp_obj_t *args);
|
||||
extern mp_obj_t GenericST7789_reset_pen(mp_obj_t self_in, mp_obj_t pen);
|
||||
|
||||
// Pen
|
||||
extern mp_obj_t GenericST7789_set_pen(mp_obj_t self_in, mp_obj_t pen);
|
||||
extern mp_obj_t GenericST7789_create_pen(size_t n_args, const mp_obj_t *args);
|
||||
|
||||
// Primitives
|
||||
extern mp_obj_t GenericST7789_set_clip(size_t n_args, const mp_obj_t *args);
|
||||
extern mp_obj_t GenericST7789_remove_clip(mp_obj_t self_in);
|
||||
extern mp_obj_t GenericST7789_clear(mp_obj_t self_in);
|
||||
extern mp_obj_t GenericST7789_pixel(mp_obj_t self_in, mp_obj_t x, mp_obj_t y);
|
||||
extern mp_obj_t GenericST7789_pixel_span(size_t n_args, const mp_obj_t *args);
|
||||
extern mp_obj_t GenericST7789_rectangle(size_t n_args, const mp_obj_t *args);
|
||||
extern mp_obj_t GenericST7789_circle(size_t n_args, const mp_obj_t *args);
|
||||
extern mp_obj_t GenericST7789_character(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t GenericST7789_text(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t GenericST7789_measure_text(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t GenericST7789_polygon(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t GenericST7789_triangle(size_t n_args, const mp_obj_t *args);
|
||||
extern mp_obj_t GenericST7789_line(size_t n_args, const mp_obj_t *args);
|
||||
|
||||
// Utility
|
||||
extern mp_obj_t GenericST7789_get_bounds(mp_obj_t self_in);
|
||||
extern mp_obj_t GenericST7789_set_framebuffer(mp_obj_t self_in, mp_obj_t framebuffer);
|
|
@ -1 +1 @@
|
|||
Subproject commit d438344943ab4383dae86b4620075ea877dec535
|
||||
Subproject commit 24caf74d90e88a62a030309d229155e210d897ac
|