Skip to content
Merged
34 changes: 22 additions & 12 deletions extmod/modframebuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <string.h>

#include "py/runtime.h"
#include "py/objtype.h"
#include "py/proto.h"

#if MICROPY_PY_FRAMEBUF
Expand Down Expand Up @@ -304,17 +305,26 @@ STATIC mp_obj_t framebuf_make_new(const mp_obj_type_t *type, size_t n_args, cons
return MP_OBJ_FROM_PTR(o);
}

STATIC const mp_obj_type_t mp_type_framebuf;

// Helper to ensure we have the native super class instead of a subclass.
static mp_obj_framebuf_t* native_framebuf(mp_obj_t framebuf_obj) {
mp_obj_t native_framebuf = mp_instance_cast_to_native_base(framebuf_obj, &mp_type_framebuf);
mp_obj_assert_native_inited(native_framebuf);
return MP_OBJ_TO_PTR(native_framebuf);
}

STATIC mp_int_t framebuf_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
(void)flags;
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_framebuf_t *self = native_framebuf(self_in);
bufinfo->buf = self->buf;
bufinfo->len = self->stride * self->height * (self->format == FRAMEBUF_RGB565 ? 2 : 1);
bufinfo->typecode = 'B'; // view framebuf as bytes
return 0;
}

STATIC mp_obj_t framebuf_fill(mp_obj_t self_in, mp_obj_t col_in) {
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_framebuf_t *self = native_framebuf(self_in);
mp_int_t col = mp_obj_get_int(col_in);
formats[self->format].fill_rect(self, 0, 0, self->width, self->height, col);
return mp_const_none;
Expand All @@ -324,7 +334,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(framebuf_fill_obj, framebuf_fill);
STATIC mp_obj_t framebuf_fill_rect(size_t n_args, const mp_obj_t *args) {
(void)n_args;

mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args[0]);
mp_obj_framebuf_t *self = native_framebuf(args[0]);
mp_int_t x = mp_obj_get_int(args[1]);
mp_int_t y = mp_obj_get_int(args[2]);
mp_int_t width = mp_obj_get_int(args[3]);
Expand All @@ -338,7 +348,7 @@ STATIC mp_obj_t framebuf_fill_rect(size_t n_args, const mp_obj_t *args) {
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_fill_rect_obj, 6, 6, framebuf_fill_rect);

STATIC mp_obj_t framebuf_pixel(size_t n_args, const mp_obj_t *args) {
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args[0]);
mp_obj_framebuf_t *self = native_framebuf(args[0]);
mp_int_t x = mp_obj_get_int(args[1]);
mp_int_t y = mp_obj_get_int(args[2]);
if (0 <= x && x < self->width && 0 <= y && y < self->height) {
Expand All @@ -357,7 +367,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_pixel_obj, 3, 4, framebuf_pi
STATIC mp_obj_t framebuf_hline(size_t n_args, const mp_obj_t *args) {
(void)n_args;

mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args[0]);
mp_obj_framebuf_t *self = native_framebuf(args[0]);
mp_int_t x = mp_obj_get_int(args[1]);
mp_int_t y = mp_obj_get_int(args[2]);
mp_int_t w = mp_obj_get_int(args[3]);
Expand All @@ -372,7 +382,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_hline_obj, 5, 5, framebuf_hl
STATIC mp_obj_t framebuf_vline(size_t n_args, const mp_obj_t *args) {
(void)n_args;

mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args[0]);
mp_obj_framebuf_t *self = native_framebuf(args[0]);
mp_int_t x = mp_obj_get_int(args[1]);
mp_int_t y = mp_obj_get_int(args[2]);
mp_int_t h = mp_obj_get_int(args[3]);
Expand All @@ -387,7 +397,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_vline_obj, 5, 5, framebuf_vl
STATIC mp_obj_t framebuf_rect(size_t n_args, const mp_obj_t *args) {
(void)n_args;

mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args[0]);
mp_obj_framebuf_t *self = native_framebuf(args[0]);
mp_int_t x = mp_obj_get_int(args[1]);
mp_int_t y = mp_obj_get_int(args[2]);
mp_int_t w = mp_obj_get_int(args[3]);
Expand All @@ -406,7 +416,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_rect_obj, 6, 6, framebuf_rec
STATIC mp_obj_t framebuf_line(size_t n_args, const mp_obj_t *args) {
(void)n_args;

mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args[0]);
mp_obj_framebuf_t *self = native_framebuf(args[0]);
mp_int_t x1 = mp_obj_get_int(args[1]);
mp_int_t y1 = mp_obj_get_int(args[2]);
mp_int_t x2 = mp_obj_get_int(args[3]);
Expand Down Expand Up @@ -470,8 +480,8 @@ STATIC mp_obj_t framebuf_line(size_t n_args, const mp_obj_t *args) {
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_line_obj, 6, 6, framebuf_line);

STATIC mp_obj_t framebuf_blit(size_t n_args, const mp_obj_t *args) {
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args[0]);
mp_obj_framebuf_t *source = MP_OBJ_TO_PTR(args[1]);
mp_obj_framebuf_t *self = native_framebuf(args[0]);
mp_obj_framebuf_t *source = native_framebuf(args[1]);
mp_int_t x = mp_obj_get_int(args[2]);
mp_int_t y = mp_obj_get_int(args[3]);
mp_int_t key = -1;
Expand Down Expand Up @@ -513,7 +523,7 @@ STATIC mp_obj_t framebuf_blit(size_t n_args, const mp_obj_t *args) {
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_blit_obj, 4, 5, framebuf_blit);

STATIC mp_obj_t framebuf_scroll(mp_obj_t self_in, mp_obj_t xstep_in, mp_obj_t ystep_in) {
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_framebuf_t *self = native_framebuf(self_in);
mp_int_t xstep = mp_obj_get_int(xstep_in);
mp_int_t ystep = mp_obj_get_int(ystep_in);
int sx, y, xend, yend, dx, dy;
Expand Down Expand Up @@ -546,7 +556,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(framebuf_scroll_obj, framebuf_scroll);

STATIC mp_obj_t framebuf_text(size_t n_args, const mp_obj_t *args) {
// extract arguments
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args[0]);
mp_obj_framebuf_t *self = native_framebuf(args[0]);
const char *str = mp_obj_str_get_str(args[1]);
mp_int_t x0 = mp_obj_get_int(args[2]);
mp_int_t y0 = mp_obj_get_int(args[3]);
Expand Down
42 changes: 4 additions & 38 deletions locale/ID.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-01-18 11:56-0800\n"
"POT-Creation-Date: 2020-01-29 17:27-0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -512,11 +512,8 @@ msgstr "Clock unit sedang digunakan"
msgid "Column entry must be digitalio.DigitalInOut"
msgstr ""

#: shared-bindings/displayio/I2CDisplay.c
msgid "Command must be 0-255"
msgstr ""

#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c
#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c
#: shared-bindings/displayio/ParallelBus.c
msgid "Command must be an int between 0 and 255"
msgstr ""

Expand Down Expand Up @@ -661,10 +658,6 @@ msgstr ""
msgid "Expected a Characteristic"
msgstr ""

#: shared-bindings/_pixelbuf/__init__.c
msgid "Expected a PixelBuf instance"
msgstr ""

#: shared-bindings/_bleio/Characteristic.c
msgid "Expected a Service"
msgstr ""
Expand Down Expand Up @@ -692,11 +685,11 @@ msgstr ""
msgid "Failed to acquire mutex, err 0x%04x"
msgstr "Gagal untuk mendapatkan mutex, status: 0x%08lX"

#: ports/atmel-samd/common-hal/busio/UART.c
#: ports/mimxrt10xx/common-hal/busio/UART.c ports/nrf/common-hal/busio/UART.c
msgid "Failed to allocate RX buffer"
msgstr "Gagal untuk mengalokasikan buffer RX"

#: ports/atmel-samd/common-hal/busio/UART.c
#: ports/atmel-samd/common-hal/pulseio/PulseIn.c
#: ports/cxd56/common-hal/pulseio/PulseIn.c
#: ports/nrf/common-hal/pulseio/PulseIn.c
Expand Down Expand Up @@ -1148,10 +1141,6 @@ msgstr ""
msgid "Pin does not have ADC capabilities"
msgstr "Pin tidak mempunya kemampuan untuk ADC (Analog Digital Converter)"

#: shared-bindings/_pixelbuf/PixelBuf.c
msgid "Pixel beyond bounds of buffer"
msgstr ""

#: py/builtinhelp.c
msgid "Plus any modules on the filesystem\n"
msgstr "Tambahkan module apapun pada filesystem\n"
Expand Down Expand Up @@ -1203,10 +1192,6 @@ msgstr ""
msgid "Random number generation error"
msgstr ""

#: shared-bindings/_pixelbuf/PixelBuf.c
msgid "Range out of bounds"
msgstr ""

#: shared-bindings/pulseio/PulseIn.c
msgid "Read-only"
msgstr ""
Expand Down Expand Up @@ -1632,11 +1617,6 @@ msgstr ""
msgid "branch not in range"
msgstr ""

#: shared-bindings/_pixelbuf/PixelBuf.c
#, c-format
msgid "buf is too small. need %d bytes"
msgstr ""

#: shared-bindings/audiocore/RawSample.c
msgid "buffer must be a bytes-like object"
msgstr ""
Expand Down Expand Up @@ -2528,10 +2508,6 @@ msgstr ""
msgid "queue overflow"
msgstr "antrian meluap (overflow)"

#: shared-bindings/_pixelbuf/PixelBuf.c
msgid "rawbuf is not the same size as buf"
msgstr ""

#: py/builtinimport.c
msgid "relative import"
msgstr "relative import"
Expand Down Expand Up @@ -2765,16 +2741,6 @@ msgstr ""
msgid "unknown format code '%c' for object of type '%s'"
msgstr ""

#: py/objstr.c
#, c-format
msgid "unknown format code '%c' for object of type 'float'"
msgstr ""

#: py/objstr.c
#, c-format
msgid "unknown format code '%c' for object of type 'str'"
msgstr ""

#: py/compile.c
msgid "unknown type"
msgstr "tipe tidak diketahui"
Expand Down
42 changes: 4 additions & 38 deletions locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-01-18 11:56-0800\n"
"POT-Creation-Date: 2020-01-29 17:27-0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -502,11 +502,8 @@ msgstr ""
msgid "Column entry must be digitalio.DigitalInOut"
msgstr ""

#: shared-bindings/displayio/I2CDisplay.c
msgid "Command must be 0-255"
msgstr ""

#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c
#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c
#: shared-bindings/displayio/ParallelBus.c
msgid "Command must be an int between 0 and 255"
msgstr ""

Expand Down Expand Up @@ -650,10 +647,6 @@ msgstr ""
msgid "Expected a Characteristic"
msgstr ""

#: shared-bindings/_pixelbuf/__init__.c
msgid "Expected a PixelBuf instance"
msgstr ""

#: shared-bindings/_bleio/Characteristic.c
msgid "Expected a Service"
msgstr ""
Expand Down Expand Up @@ -681,11 +674,11 @@ msgstr ""
msgid "Failed to acquire mutex, err 0x%04x"
msgstr ""

#: ports/atmel-samd/common-hal/busio/UART.c
#: ports/mimxrt10xx/common-hal/busio/UART.c ports/nrf/common-hal/busio/UART.c
msgid "Failed to allocate RX buffer"
msgstr ""

#: ports/atmel-samd/common-hal/busio/UART.c
#: ports/atmel-samd/common-hal/pulseio/PulseIn.c
#: ports/cxd56/common-hal/pulseio/PulseIn.c
#: ports/nrf/common-hal/pulseio/PulseIn.c
Expand Down Expand Up @@ -1136,10 +1129,6 @@ msgstr ""
msgid "Pin does not have ADC capabilities"
msgstr ""

#: shared-bindings/_pixelbuf/PixelBuf.c
msgid "Pixel beyond bounds of buffer"
msgstr ""

#: py/builtinhelp.c
msgid "Plus any modules on the filesystem\n"
msgstr ""
Expand Down Expand Up @@ -1189,10 +1178,6 @@ msgstr ""
msgid "Random number generation error"
msgstr ""

#: shared-bindings/_pixelbuf/PixelBuf.c
msgid "Range out of bounds"
msgstr ""

#: shared-bindings/pulseio/PulseIn.c
msgid "Read-only"
msgstr ""
Expand Down Expand Up @@ -1609,11 +1594,6 @@ msgstr ""
msgid "branch not in range"
msgstr ""

#: shared-bindings/_pixelbuf/PixelBuf.c
#, c-format
msgid "buf is too small. need %d bytes"
msgstr ""

#: shared-bindings/audiocore/RawSample.c
msgid "buffer must be a bytes-like object"
msgstr ""
Expand Down Expand Up @@ -2503,10 +2483,6 @@ msgstr ""
msgid "queue overflow"
msgstr ""

#: shared-bindings/_pixelbuf/PixelBuf.c
msgid "rawbuf is not the same size as buf"
msgstr ""

#: py/builtinimport.c
msgid "relative import"
msgstr ""
Expand Down Expand Up @@ -2739,16 +2715,6 @@ msgstr ""
msgid "unknown format code '%c' for object of type '%s'"
msgstr ""

#: py/objstr.c
#, c-format
msgid "unknown format code '%c' for object of type 'float'"
msgstr ""

#: py/objstr.c
#, c-format
msgid "unknown format code '%c' for object of type 'str'"
msgstr ""

#: py/compile.c
msgid "unknown type"
msgstr ""
Expand Down
Loading