Merge pull request #4 from pimoroni/revert-3-picodisplay-bytearray-buffer

Revert "Attempt to allocate a bytearray behind the sCenes"
pull/10/head
ZodiusInfuser 2021-01-21 00:36:23 +00:00 zatwierdzone przez GitHub
commit bf37a60fb7
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 7 dodań i 21 usunięć

Wyświetl plik

@ -1,6 +1,4 @@
#include "pico_display.h" #include "pico_display.h"
#include "py/binary.h"
#include "py/objarray.h"
/***** Constants *****/ /***** Constants *****/
enum buttons enum buttons
@ -11,25 +9,13 @@ enum buttons
BUTTON_Y, BUTTON_Y,
}; };
mp_obj_t alloc_new_bytearray(int len) {
int typecode_size = mp_binary_get_size('@', BYTEARRAY_TYPECODE, NULL);
mp_obj_array_t *o = m_new_obj(mp_obj_array_t);
o->base.type = &mp_type_bytearray;
o->typecode = BYTEARRAY_TYPECODE;
o->free = 0;
o->len = len;
o->items = m_new(byte, typecode_size * o->len);
memset(o->items, 0, len);
return MP_OBJ_FROM_PTR(o);
}
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
// picodisplay Module // picodisplay Module
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
/***** 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);

Wyświetl plik

@ -12,10 +12,12 @@ PicoDisplay *display;
extern "C" { extern "C" {
#include "pico_display.h" #include "pico_display.h"
mp_obj_t picodisplay_init() { mp_obj_t buf_obj;
mp_obj_t ba = alloc_new_bytearray(PicoDisplay::WIDTH * PicoDisplay::HEIGHT * sizeof(uint16_t));
mp_obj_t picodisplay_init(mp_obj_t buf) {
mp_buffer_info_t bufinfo; mp_buffer_info_t bufinfo;
mp_get_buffer_raise(ba, &bufinfo, MP_BUFFER_RW); mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_RW);
buf_obj = buf;
display = new PicoDisplay((uint16_t *)bufinfo.buf); display = new PicoDisplay((uint16_t *)bufinfo.buf);
display->init(); display->init();
return mp_const_none; return mp_const_none;

Wyświetl plik

@ -2,10 +2,8 @@
#include "py/runtime.h" #include "py/runtime.h"
#include "py/objstr.h" #include "py/objstr.h"
extern mp_obj_t alloc_new_bytearray(int len);
// 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);