kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Very messy attempt at using a bytearray as the buffer
rodzic
84e98b7040
commit
4f6691be8b
|
@ -11,9 +11,9 @@ const uint8_t LED_B = 8;
|
||||||
|
|
||||||
namespace pimoroni {
|
namespace pimoroni {
|
||||||
|
|
||||||
PicoDisplay::PicoDisplay()
|
PicoDisplay::PicoDisplay(uint16_t *buf)
|
||||||
: PicoGraphics(WIDTH, HEIGHT, __fb), screen(WIDTH, HEIGHT, __fb) {
|
: PicoGraphics(WIDTH, HEIGHT, buf), screen(WIDTH, HEIGHT, buf) {
|
||||||
memset(__fb, 0, sizeof(__fb));
|
__fb = buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PicoDisplay::init() {
|
void PicoDisplay::init() {
|
||||||
|
|
|
@ -14,12 +14,12 @@ namespace pimoroni {
|
||||||
static const uint8_t X = 14;
|
static const uint8_t X = 14;
|
||||||
static const uint8_t Y = 15;
|
static const uint8_t Y = 15;
|
||||||
|
|
||||||
|
uint16_t *__fb;
|
||||||
private:
|
private:
|
||||||
uint16_t __fb[WIDTH * HEIGHT];
|
|
||||||
ST7789 screen;
|
ST7789 screen;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PicoDisplay();
|
PicoDisplay(uint16_t *buf);
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void update();
|
void update();
|
||||||
|
|
|
@ -18,8 +18,7 @@ namespace pimoroni {
|
||||||
((g & 0b11111100) << 3) |
|
((g & 0b11111100) << 3) |
|
||||||
((b & 0b11111000) >> 3);
|
((b & 0b11111000) >> 3);
|
||||||
|
|
||||||
// endian swap, this should be possible another way...
|
return __builtin_bswap16(p);
|
||||||
return ((p & 0xff00) >> 8) | ((p & 0xff) << 8);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PicoGraphics::set_clip(const rect &r) {
|
void PicoGraphics::set_clip(const rect &r) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ enum buttons
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/***** Module Functions *****/
|
/***** Module Functions *****/
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(picodisplay_init_obj, picodisplay_init);
|
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_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_get_height_obj, picodisplay_get_height);
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(picodisplay_update_obj, picodisplay_update);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_0(picodisplay_update_obj, picodisplay_update);
|
||||||
|
|
|
@ -6,14 +6,20 @@
|
||||||
|
|
||||||
using namespace pimoroni;
|
using namespace pimoroni;
|
||||||
|
|
||||||
PicoDisplay display;
|
PicoDisplay *display;
|
||||||
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "pico_display.h"
|
#include "pico_display.h"
|
||||||
|
|
||||||
mp_obj_t picodisplay_init() {
|
mp_obj_t buf_obj;
|
||||||
display.init();
|
|
||||||
|
mp_obj_t picodisplay_init(mp_obj_t buf) {
|
||||||
|
mp_buffer_info_t bufinfo;
|
||||||
|
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_RW);
|
||||||
|
buf_obj = buf;
|
||||||
|
display = new PicoDisplay((uint16_t *)bufinfo.buf);
|
||||||
|
display->init();
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +32,7 @@ mp_obj_t picodisplay_get_height() {
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t picodisplay_update() {
|
mp_obj_t picodisplay_update() {
|
||||||
display.update();
|
display->update();
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +42,7 @@ mp_obj_t picodisplay_set_backlight(mp_obj_t brightness_obj) {
|
||||||
if(brightness < 0 || brightness > 1.0f)
|
if(brightness < 0 || brightness > 1.0f)
|
||||||
mp_raise_ValueError("brightness out of range. Expected 0.0 to 1.0");
|
mp_raise_ValueError("brightness out of range. Expected 0.0 to 1.0");
|
||||||
else
|
else
|
||||||
display.set_backlight((uint8_t)(brightness * 255.0f));
|
display->set_backlight((uint8_t)(brightness * 255.0f));
|
||||||
|
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
@ -53,7 +59,7 @@ mp_obj_t picodisplay_set_led(mp_obj_t r_obj, mp_obj_t g_obj, mp_obj_t b_obj) {
|
||||||
else if(b < 0 || b > 255)
|
else if(b < 0 || b > 255)
|
||||||
mp_raise_ValueError("b out of range. Expected 0 to 255");
|
mp_raise_ValueError("b out of range. Expected 0 to 255");
|
||||||
else
|
else
|
||||||
display.set_led(r, g, b);
|
display->set_led(r, g, b);
|
||||||
|
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
@ -65,19 +71,19 @@ mp_obj_t picodisplay_is_pressed(mp_obj_t button_obj) {
|
||||||
switch(buttonID)
|
switch(buttonID)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
buttonPressed = display.is_pressed(PicoDisplay::A);
|
buttonPressed = display->is_pressed(PicoDisplay::A);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
buttonPressed = display.is_pressed(PicoDisplay::B);
|
buttonPressed = display->is_pressed(PicoDisplay::B);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
buttonPressed = display.is_pressed(PicoDisplay::X);
|
buttonPressed = display->is_pressed(PicoDisplay::X);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
buttonPressed = display.is_pressed(PicoDisplay::Y);
|
buttonPressed = display->is_pressed(PicoDisplay::Y);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -253,4 +259,4 @@ mp_obj_t picodisplay_text(mp_uint_t n_args, const mp_obj_t *args) {
|
||||||
|
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include "py/objstr.h"
|
#include "py/objstr.h"
|
||||||
|
|
||||||
// Declare the functions we'll make available in Python
|
// Declare the functions we'll make available in Python
|
||||||
extern mp_obj_t picodisplay_init();
|
extern mp_obj_t picodisplay_init(mp_obj_t buf);
|
||||||
extern mp_obj_t picodisplay_get_width();
|
extern mp_obj_t picodisplay_get_width();
|
||||||
extern mp_obj_t picodisplay_get_height();
|
extern mp_obj_t picodisplay_get_height();
|
||||||
extern mp_obj_t picodisplay_set_backlight(mp_obj_t brightness_obj);
|
extern mp_obj_t picodisplay_set_backlight(mp_obj_t brightness_obj);
|
||||||
|
|
Ładowanie…
Reference in New Issue