summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2020-04-14 17:14:44 -0700
committerScott Shawcroft <scott@tannewt.org>2020-04-14 17:14:44 -0700
commitb580b34cbf1c48ef3de1dbeb5f44ec3d06b704af (patch)
tree9ec02ce5a6e78fb0383058972d09938813f39db3 /shared-bindings
parent7dfcae6067ee07ad644278a66aaa114759b181a8 (diff)
parent7ed1483b89d24bb4dd44f9c4c8271c438303b9fe (diff)
Merge remote-tracking branch 'adafruit/master' into lower_power
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/_protomatter/Protomatter.c376
-rw-r--r--shared-bindings/_protomatter/Protomatter.h59
-rw-r--r--shared-bindings/_protomatter/__init__.c55
-rw-r--r--shared-bindings/displayio/Bitmap.c19
-rw-r--r--shared-bindings/displayio/Bitmap.h1
-rw-r--r--shared-bindings/displayio/Display.c22
-rw-r--r--shared-bindings/displayio/Display.h2
-rw-r--r--shared-bindings/displayio/EPaperDisplay.c13
-rw-r--r--shared-bindings/displayio/FourWire.c13
-rw-r--r--shared-bindings/displayio/I2CDisplay.c13
-rw-r--r--shared-bindings/displayio/ParallelBus.c13
-rw-r--r--shared-bindings/framebufferio/FramebufferDisplay.c428
-rw-r--r--shared-bindings/framebufferio/FramebufferDisplay.h69
-rw-r--r--shared-bindings/framebufferio/__init__.c63
-rw-r--r--shared-bindings/framebufferio/__init__.h0
-rw-r--r--shared-bindings/microcontroller/Pin.h6
-rw-r--r--shared-bindings/ulab/__init__.rst38
17 files changed, 1115 insertions, 75 deletions
diff --git a/shared-bindings/_protomatter/Protomatter.c b/shared-bindings/_protomatter/Protomatter.c
new file mode 100644
index 000000000..bb4339079
--- /dev/null
+++ b/shared-bindings/_protomatter/Protomatter.c
@@ -0,0 +1,376 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 Jeff Epler for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "py/obj.h"
+#include "py/objproperty.h"
+#include "py/runtime.h"
+#include "py/objarray.h"
+
+#include "common-hal/_protomatter/Protomatter.h"
+#include "shared-bindings/_protomatter/Protomatter.h"
+#include "shared-bindings/microcontroller/Pin.h"
+#include "shared-bindings/microcontroller/__init__.h"
+#include "shared-bindings/util.h"
+#include "shared-module/displayio/__init__.h"
+#include "shared-module/framebufferio/__init__.h"
+#include "shared-module/framebufferio/FramebufferDisplay.h"
+
+//| .. currentmodule:: _protomatter
+//|
+//| :class:`protomatter` -- Driver for HUB75-style RGB LED matrices
+//| ================================================================
+//|
+
+extern Protomatter_core *_PM_protoPtr;
+
+STATIC uint8_t validate_pin(mp_obj_t obj) {
+ mcu_pin_obj_t *result = validate_obj_is_free_pin(obj);
+ return common_hal_mcu_pin_number(result);
+}
+
+STATIC void validate_pins(qstr what, uint8_t* pin_nos, mp_int_t max_pins, mp_obj_t seq, uint8_t *count_out) {
+ mp_int_t len = MP_OBJ_SMALL_INT_VALUE(mp_obj_len(seq));
+ if (len > max_pins) {
+ mp_raise_ValueError_varg(translate("At most %d %q may be specified (not %d)"), max_pins, what, len);
+ }
+ *count_out = len;
+ for (mp_int_t i=0; i<len; i++) {
+ pin_nos[i] = validate_pin(mp_obj_subscr(seq, MP_OBJ_NEW_SMALL_INT(i), MP_OBJ_SENTINEL));
+ }
+}
+
+STATIC void claim_and_never_reset_pin(mp_obj_t pin) {
+ common_hal_mcu_pin_claim(pin);
+ common_hal_never_reset_pin(pin);
+}
+
+STATIC void claim_and_never_reset_pins(mp_obj_t seq) {
+ mp_int_t len = MP_OBJ_SMALL_INT_VALUE(mp_obj_len(seq));
+ for (mp_int_t i=0; i<len; i++) {
+ claim_and_never_reset_pin(mp_obj_subscr(seq, MP_OBJ_NEW_SMALL_INT(i), MP_OBJ_SENTINEL));
+ }
+}
+
+STATIC void preflight_pins_or_throw(uint8_t clock_pin, uint8_t *rgb_pins, uint8_t rgb_pin_count, bool allow_inefficient) {
+ uint32_t port = clock_pin / 32;
+ uint32_t bit_mask = 1 << (clock_pin % 32);
+
+ for (uint8_t i = 0; i < rgb_pin_count; i++) {
+ uint32_t pin_port = rgb_pins[i] / 32;
+
+ if (pin_port != port) {
+ mp_raise_ValueError_varg(
+ translate("rgb_pins[%d] is not on the same port as clock"), i);
+ }
+
+ uint32_t pin_mask = 1 << (rgb_pins[i] % 32);
+ if (pin_mask & bit_mask) {
+ mp_raise_ValueError_varg(
+ translate("rgb_pins[%d] duplicates another pin assignment"), i);
+ }
+
+ bit_mask |= pin_mask;
+ }
+
+ if (allow_inefficient) {
+ return;
+ }
+
+ uint8_t byte_mask = 0;
+ if (bit_mask & 0x000000FF) byte_mask |= 0b0001;
+ if (bit_mask & 0x0000FF00) byte_mask |= 0b0010;
+ if (bit_mask & 0x00FF0000) byte_mask |= 0b0100;
+ if (bit_mask & 0xFF000000) byte_mask |= 0b1000;
+
+ uint8_t bytes_per_element = 0xff;
+ uint8_t ideal_bytes_per_element = (rgb_pin_count + 7) / 8;
+
+ switch(byte_mask) {
+ case 0b0001:
+ case 0b0010:
+ case 0b0100:
+ case 0b1000:
+ bytes_per_element = 1;
+ break;
+
+ case 0b0011:
+ case 0b1100:
+ bytes_per_element = 2;
+ break;
+
+ default:
+ bytes_per_element = 4;
+ break;
+ }
+
+ if (bytes_per_element != ideal_bytes_per_element) {
+ mp_raise_ValueError_varg(
+ translate("Pinout uses %d bytes per element, which consumes more than the ideal %d bytes. If this cannot be avoided, pass allow_inefficient=True to the constructor"),
+ bytes_per_element, ideal_bytes_per_element);
+ }
+}
+
+//| :class:`~_protomatter.Protomatter` displays an in-memory framebuffer to an LED matrix.
+//|
+//| .. class:: Protomatter(width, bit_depth, rgb_pins, addr_pins, clock_pin, latch_pin, output_enable_pin, *, doublebuffer=True, framebuffer=None)
+//|
+//| Create a Protomatter object with the given attributes. The height of
+//| the display is determined by the number of rgb and address pins:
+//| len(rgb_pins) // 3 * 2 ** len(address_pins). With 6 RGB pins and 4
+//| address lines, the display will be 32 pixels tall.
+//|
+//| Up to 30 RGB pins and 8 address pins are supported.
+//|
+//| The RGB pins must be within a single "port" and performance and memory
+//| usage are best when they are all within "close by" bits of the port.
+//| The clock pin must also be on the same port as the RGB pins. See the
+//| documentation of the underlying protomatter C library for more
+//| information. Generally, Adafruit's interface boards are designed so
+//| that these requirements are met when matched with the intended
+//| microcontroller board. For instance, the Feather M4 Express works
+//| together with the RGB Matrix Feather.
+//|
+//| The framebuffer is in "RGB565" format.
+//|
+//| "RGB565" means that it is organized as a series of 16-bit numbers
+//| where the highest 5 bits are interpreted as red, the next 6 as
+//| green, and the final 5 as blue. The object can be any buffer, but
+//| `array.array` and `ulab.array` objects are most often useful.
+//| To update the content, modify the framebuffer and call refresh.
+//|
+//| If a framebuffer is not passed in, one is allocated and initialized
+//| to all black. In any case, the framebuffer can be retrieved
+//| by passing the protomatter object to memoryview().
+//|
+//| If doublebuffer is False, some memory is saved, but the display may
+//| flicker during updates.
+//|
+//| If a framebuffer is not passed in, one is allocated internally. To
+//| retrieve it, pass the protomatter object to memoryview().
+//|
+//| A Protomatter framebuffer is often used in conjunction with a
+//| `framebufferio.FramebufferDisplay`.
+//|
+
+STATIC mp_obj_t protomatter_protomatter_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+ enum { ARG_width, ARG_bit_depth, ARG_rgb_list, ARG_addr_list,
+ ARG_clock_pin, ARG_latch_pin, ARG_output_enable_pin, ARG_doublebuffer, ARG_framebuffer, ARG_height };
+ static const mp_arg_t allowed_args[] = {
+ { MP_QSTR_width, MP_ARG_INT | MP_ARG_REQUIRED | MP_ARG_KW_ONLY },
+ { MP_QSTR_bit_depth, MP_ARG_INT | MP_ARG_REQUIRED | MP_ARG_KW_ONLY },
+ { MP_QSTR_rgb_pins, MP_ARG_OBJ | MP_ARG_REQUIRED | MP_ARG_KW_ONLY },
+ { MP_QSTR_addr_pins, MP_ARG_OBJ | MP_ARG_REQUIRED | MP_ARG_KW_ONLY },
+ { MP_QSTR_clock_pin, MP_ARG_OBJ | MP_ARG_REQUIRED | MP_ARG_KW_ONLY },
+ { MP_QSTR_latch_pin, MP_ARG_OBJ | MP_ARG_REQUIRED | MP_ARG_KW_ONLY },
+ { MP_QSTR_output_enable_pin, MP_ARG_OBJ | MP_ARG_REQUIRED | MP_ARG_KW_ONLY },
+ { MP_QSTR_doublebuffer, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = true } },
+ { MP_QSTR_framebuffer, MP_ARG_OBJ | MP_ARG_KW_ONLY, { .u_obj = mp_const_none } },
+ { MP_QSTR_height, MP_ARG_INT | MP_ARG_KW_ONLY, { .u_int = 0 } },
+ };
+ 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);
+
+ // Because interrupt handlers point directly at protomatter objects,
+ // it is NOT okay to move them to the long-lived pool later. Allocate
+ // them there to begin with, since generally they'll be long-lived anyway.
+ protomatter_protomatter_obj_t *self = &allocate_display_bus_or_raise()->protomatter;
+ self->base.type = &protomatter_Protomatter_type;
+
+ uint8_t rgb_count, addr_count;
+ uint8_t rgb_pins[MP_ARRAY_SIZE(self->rgb_pins)];
+ uint8_t addr_pins[MP_ARRAY_SIZE(self->addr_pins)];
+ uint8_t clock_pin = validate_pin(args[ARG_clock_pin].u_obj);
+ uint8_t latch_pin = validate_pin(args[ARG_latch_pin].u_obj);
+ uint8_t output_enable_pin = validate_pin(args[ARG_output_enable_pin].u_obj);
+
+ validate_pins(MP_QSTR_rgb_pins, rgb_pins, MP_ARRAY_SIZE(self->rgb_pins), args[ARG_rgb_list].u_obj, &rgb_count);
+ validate_pins(MP_QSTR_addr_pins, addr_pins, MP_ARRAY_SIZE(self->addr_pins), args[ARG_addr_list].u_obj, &addr_count);
+
+ if (rgb_count % 6) {
+ mp_raise_ValueError_varg(translate("Must use a multiple of 6 rgb pins, not %d"), rgb_count);
+ }
+
+ // TODO(@jepler) Use fewer than all rows of pixels if height < computed_height
+ if (args[ARG_height].u_int != 0) {
+ int computed_height = (rgb_count / 3) << (addr_count);
+ if (computed_height != args[ARG_height].u_int) {
+ mp_raise_ValueError_varg(
+ translate("%d address pins and %d rgb pins indicate a height of %d, not %d"), addr_count, rgb_count, computed_height, args[ARG_height].u_int);
+ }
+ }
+
+ preflight_pins_or_throw(clock_pin, rgb_pins, rgb_count, true);
+
+ mp_obj_t framebuffer = args[ARG_framebuffer].u_obj;
+ if (framebuffer == mp_const_none) {
+ int width = args[ARG_width].u_int;
+ int bufsize = 2 * width * rgb_count / 3 * (1 << addr_count);
+ framebuffer = mp_obj_new_bytearray_of_zeros(bufsize);
+ }
+
+ common_hal_protomatter_protomatter_construct(self,
+ args[ARG_width].u_int,
+ args[ARG_bit_depth].u_int,
+ rgb_count, rgb_pins,
+ addr_count, addr_pins,
+ clock_pin, latch_pin, output_enable_pin,
+ args[ARG_doublebuffer].u_bool,
+ framebuffer, NULL);
+
+ claim_and_never_reset_pins(args[ARG_rgb_list].u_obj);
+ claim_and_never_reset_pins(args[ARG_addr_list].u_obj);
+ claim_and_never_reset_pin(args[ARG_clock_pin].u_obj);
+ claim_and_never_reset_pin(args[ARG_output_enable_pin].u_obj);
+ claim_and_never_reset_pin(args[ARG_latch_pin].u_obj);
+
+ return MP_OBJ_FROM_PTR(self);
+}
+
+//| .. method:: deinit
+//|
+//| Free the resources (pins, timers, etc.) associated with this
+//| protomatter instance. After deinitialization, no further operations
+//| may be performed.
+//|
+STATIC mp_obj_t protomatter_protomatter_deinit(mp_obj_t self_in) {
+ protomatter_protomatter_obj_t *self = (protomatter_protomatter_obj_t*)self_in;
+ common_hal_protomatter_protomatter_deinit(self);
+ return mp_const_none;
+}
+
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(protomatter_protomatter_deinit_obj, protomatter_protomatter_deinit);
+
+static void check_for_deinit(protomatter_protomatter_obj_t *self) {
+ if (!self->core.rgbPins) {
+ raise_deinited_error();
+ }
+}
+
+//| .. attribute:: brightness
+//|
+//| In the current implementation, 0.0 turns the display off entirely
+//| and any other value up to 1.0 turns the display on fully.
+//|
+STATIC mp_obj_t protomatter_protomatter_get_brightness(mp_obj_t self_in) {
+ protomatter_protomatter_obj_t *self = (protomatter_protomatter_obj_t*)self_in;
+ check_for_deinit(self);
+ return mp_obj_new_float(common_hal_protomatter_protomatter_get_paused(self)? 0.0f : 1.0f);
+}
+MP_DEFINE_CONST_FUN_OBJ_1(protomatter_protomatter_get_brightness_obj, protomatter_protomatter_get_brightness);
+
+STATIC mp_obj_t protomatter_protomatter_set_brightness(mp_obj_t self_in, mp_obj_t value_in) {
+ protomatter_protomatter_obj_t *self = (protomatter_protomatter_obj_t*)self_in;
+ check_for_deinit(self);
+ mp_float_t brightness = mp_obj_get_float(value_in);
+ if (brightness < 0.0f || brightness > 1.0f) {
+ mp_raise_ValueError(translate("Brightness must be 0-1.0"));
+ }
+ common_hal_protomatter_protomatter_set_paused(self_in, brightness <= 0);
+
+ return mp_const_none;
+}
+MP_DEFINE_CONST_FUN_OBJ_2(protomatter_protomatter_set_brightness_obj, protomatter_protomatter_set_brightness);
+
+const mp_obj_property_t protomatter_protomatter_brightness_obj = {
+ .base.type = &mp_type_property,
+ .proxy = {(mp_obj_t)&protomatter_protomatter_get_brightness_obj,
+ (mp_obj_t)&protomatter_protomatter_set_brightness_obj,
+ (mp_obj_t)&mp_const_none_obj},
+};
+
+//| .. method:: refresh()
+//|
+//| Transmits the color data in the buffer to the pixels so that
+//| they are shown.
+//|
+STATIC mp_obj_t protomatter_protomatter_refresh(mp_obj_t self_in) {
+ protomatter_protomatter_obj_t *self = (protomatter_protomatter_obj_t*)self_in;
+ check_for_deinit(self);
+ common_hal_protomatter_protomatter_refresh(self);
+ return mp_const_none;
+}
+MP_DEFINE_CONST_FUN_OBJ_1(protomatter_protomatter_refresh_obj, protomatter_protomatter_refresh);
+
+STATIC const mp_rom_map_elem_t protomatter_protomatter_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&protomatter_protomatter_deinit_obj) },
+ { MP_ROM_QSTR(MP_QSTR_brightness), MP_ROM_PTR(&protomatter_protomatter_brightness_obj) },
+ { MP_ROM_QSTR(MP_QSTR_refresh), MP_ROM_PTR(&protomatter_protomatter_refresh_obj) },
+};
+STATIC MP_DEFINE_CONST_DICT(protomatter_protomatter_locals_dict, protomatter_protomatter_locals_dict_table);
+
+STATIC void protomatter_protomatter_get_bufinfo(mp_obj_t self_in, mp_buffer_info_t *bufinfo) {
+ protomatter_protomatter_obj_t *self = (protomatter_protomatter_obj_t*)self_in;
+ check_for_deinit(self);
+
+ *bufinfo = self->bufinfo;
+}
+
+// These version exists so that the prototype matches the protocol,
+// avoiding a type cast that can hide errors
+STATIC void protomatter_protomatter_swapbuffers(mp_obj_t self_in) {
+ common_hal_protomatter_protomatter_refresh(self_in);
+}
+
+STATIC void protomatter_protomatter_deinit_proto(mp_obj_t self_in) {
+ common_hal_protomatter_protomatter_deinit(self_in);
+}
+
+STATIC float protomatter_protomatter_get_brightness_proto(mp_obj_t self_in) {
+ return common_hal_protomatter_protomatter_get_paused(self_in) ? 0.0f : 1.0f;
+}
+
+STATIC bool protomatter_protomatter_set_brightness_proto(mp_obj_t self_in, mp_float_t value) {
+ common_hal_protomatter_protomatter_set_paused(self_in, value <= 0);
+ return true;
+}
+
+STATIC const framebuffer_p_t protomatter_protomatter_proto = {
+ MP_PROTO_IMPLEMENT(MP_QSTR_protocol_framebuffer)
+ .get_bufinfo = protomatter_protomatter_get_bufinfo,
+ .set_brightness = protomatter_protomatter_set_brightness_proto,
+ .get_brightness = protomatter_protomatter_get_brightness_proto,
+ .swapbuffers = protomatter_protomatter_swapbuffers,
+ .deinit = protomatter_protomatter_deinit_proto,
+};
+
+STATIC mp_int_t protomatter_protomatter_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
+ protomatter_protomatter_obj_t *self = (protomatter_protomatter_obj_t*)self_in;
+ // a readonly framebuffer would be unusual but not impossible
+ if ((flags & MP_BUFFER_WRITE) && !(self->bufinfo.typecode & MP_OBJ_ARRAY_TYPECODE_FLAG_RW)) {
+ return 1;
+ }
+ *bufinfo = self->bufinfo;
+ return 0;
+}
+
+const mp_obj_type_t protomatter_Protomatter_type = {
+ { &mp_type_type },
+ .name = MP_QSTR_Protomatter,
+ .buffer_p = { .get_buffer = protomatter_protomatter_get_buffer, },
+ .make_new = protomatter_protomatter_make_new,
+ .protocol = &protomatter_protomatter_proto,
+ .locals_dict = (mp_obj_dict_t*)&protomatter_protomatter_locals_dict,
+};
diff --git a/shared-bindings/_protomatter/Protomatter.h b/shared-bindings/_protomatter/Protomatter.h
new file mode 100644
index 000000000..9499da22c
--- /dev/null
+++ b/shared-bindings/_protomatter/Protomatter.h
@@ -0,0 +1,59 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 Jeff Epler for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_PROTOMATTER_PROTOMATTER_H
+#define MICROPY_INCLUDED_SHARED_BINDINGS_PROTOMATTER_PROTOMATTER_H
+
+#include "shared-module/_protomatter/Protomatter.h"
+#include "lib/protomatter/core.h"
+
+extern const mp_obj_type_t protomatter_Protomatter_type;
+typedef struct {
+ mp_obj_base_t base;
+ mp_obj_t framebuffer;
+ mp_buffer_info_t bufinfo;
+ Protomatter_core core;
+ void *timer;
+ uint16_t bufsize, width;
+ uint8_t rgb_pins[30];
+ uint8_t addr_pins[10];
+ uint8_t clock_pin, latch_pin, oe_pin;
+ uint8_t rgb_count, addr_count;
+ uint8_t bit_depth;
+ bool core_is_initialized;
+ bool paused;
+ bool doublebuffer;
+} protomatter_protomatter_obj_t;
+
+void common_hal_protomatter_protomatter_construct(protomatter_protomatter_obj_t* self, int width, int bit_depth, uint8_t rgb_count, uint8_t* rgb_pins, uint8_t addr_count, uint8_t* addr_pins, uint8_t clock_pin, uint8_t latch_pin, uint8_t oe_pin, bool doublebuffer, mp_obj_t framebuffer, void* timer);
+void common_hal_protomatter_protomatter_deinit(protomatter_protomatter_obj_t*);
+void protomatter_protomatter_collect_ptrs(protomatter_protomatter_obj_t*);
+void common_hal_protomatter_protomatter_reconstruct(protomatter_protomatter_obj_t* self, mp_obj_t framebuffer);
+void common_hal_protomatter_protomatter_set_paused(protomatter_protomatter_obj_t* self, bool paused);
+bool common_hal_protomatter_protomatter_get_paused(protomatter_protomatter_obj_t* self);
+void common_hal_protomatter_protomatter_refresh(protomatter_protomatter_obj_t* self);
+
+#endif
diff --git a/shared-bindings/_protomatter/__init__.c b/shared-bindings/_protomatter/__init__.c
new file mode 100644
index 000000000..2281b15f1
--- /dev/null
+++ b/shared-bindings/_protomatter/__init__.c
@@ -0,0 +1,55 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 Jeff Epler for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include <stdint.h>
+
+#include "py/obj.h"
+#include "py/runtime.h"
+
+#include "shared-bindings/_protomatter/Protomatter.h"
+
+//| :mod:`_protomatter` --- Low-level routines for bitbanged LED matrices
+//| =====================================================================
+//|
+//| .. module:: _protomatter
+//| :synopsis: Low-level routines for bitbanged LED matrices
+//|
+//| .. toctree::
+//| :maxdepth: 3
+//|
+//| Protomatter
+
+STATIC const mp_rom_map_elem_t protomatter_module_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__protomatter) },
+ { MP_ROM_QSTR(MP_QSTR_Protomatter), MP_ROM_PTR(&protomatter_Protomatter_type) },
+};
+
+STATIC MP_DEFINE_CONST_DICT(protomatter_module_globals, protomatter_module_globals_table);
+
+const mp_obj_module_t protomatter_module = {
+ .base = { &mp_type_module },
+ .globals = (mp_obj_dict_t*)&protomatter_module_globals,
+};
diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c
index 91c17f2d1..391f3e595 100644
--- a/shared-bindings/displayio/Bitmap.c
+++ b/shared-bindings/displayio/Bitmap.c
@@ -178,9 +178,28 @@ STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t val
return mp_const_none;
}
+//| .. method:: fill(value)
+//|
+//| Fills the bitmap with the supplied palette index value.
+//|
+STATIC mp_obj_t displayio_bitmap_obj_fill(mp_obj_t self_in, mp_obj_t value_obj) {
+ displayio_bitmap_t *self = MP_OBJ_TO_PTR(self_in);
+
+ mp_int_t value = mp_obj_get_int(value_obj);
+ if (value >= 1 << common_hal_displayio_bitmap_get_bits_per_value(self)) {
+ mp_raise_ValueError(translate("pixel value requires too many bits"));
+ }
+ common_hal_displayio_bitmap_fill(self, value);
+
+ return mp_const_none;
+}
+MP_DEFINE_CONST_FUN_OBJ_2(displayio_bitmap_fill_obj, displayio_bitmap_obj_fill);
+
STATIC const mp_rom_map_elem_t displayio_bitmap_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&displayio_bitmap_height_obj) },
{ MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&displayio_bitmap_width_obj) },
+ { MP_ROM_QSTR(MP_QSTR_fill), MP_ROM_PTR(&displayio_bitmap_fill_obj) },
+
};
STATIC MP_DEFINE_CONST_DICT(displayio_bitmap_locals_dict, displayio_bitmap_locals_dict_table);
diff --git a/shared-bindings/displayio/Bitmap.h b/shared-bindings/displayio/Bitmap.h
index 90694951f..46c337329 100644
--- a/shared-bindings/displayio/Bitmap.h
+++ b/shared-bindings/displayio/Bitmap.h
@@ -41,5 +41,6 @@ uint16_t common_hal_displayio_bitmap_get_width(displayio_bitmap_t *self);
uint32_t common_hal_displayio_bitmap_get_bits_per_value(displayio_bitmap_t *self);
void common_hal_displayio_bitmap_set_pixel(displayio_bitmap_t *bitmap, int16_t x, int16_t y, uint32_t value);
uint32_t common_hal_displayio_bitmap_get_pixel(displayio_bitmap_t *bitmap, int16_t x, int16_t y);
+void common_hal_displayio_bitmap_fill(displayio_bitmap_t *bitmap, uint32_t value);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_BITMAP_H
diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c
index 3ef7e74e9..a22b2add2 100644
--- a/shared-bindings/displayio/Display.c
+++ b/shared-bindings/displayio/Display.c
@@ -92,6 +92,7 @@
//| :param bool pixels_in_byte_share_row: True when pixels are less than a byte and a byte includes pixels from the same row of the display. When False, pixels share a column.
//| :param int bytes_per_cell: Number of bytes per addressable memory location when color_depth < 8. When greater than one, bytes share a row or column according to pixels_in_byte_share_row.
//| :param bool reverse_pixels_in_byte: Reverses the pixel order within each byte when color_depth < 8. Does not apply across multiple bytes even if there is more than one byte per cell (bytes_per_cell.)
+//| :param bool reverse_bytes_in_word: Reverses the order of bytes within a word when color_depth == 16
//| :param int set_column_command: Command used to set the start and end columns to update
//| :param int set_row_command: Command used so set the start and end rows to update
//| :param int write_ram_command: Command used to write pixels values into the update region. Ignored if data_as_commands is set.
@@ -107,7 +108,7 @@
//| :param bool backlight_on_high: If True, pulling the backlight pin high turns the backlight on.
//|
STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
- enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_grayscale, ARG_pixels_in_byte_share_row, ARG_bytes_per_cell, ARG_reverse_pixels_in_byte, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_brightness_command, ARG_brightness, ARG_auto_brightness, ARG_single_byte_bounds, ARG_data_as_commands, ARG_auto_refresh, ARG_native_frames_per_second, ARG_backlight_on_high };
+ enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_grayscale, ARG_pixels_in_byte_share_row, ARG_bytes_per_cell, ARG_reverse_pixels_in_byte, ARG_reverse_bytes_in_word, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_brightness_command, ARG_brightness, ARG_auto_brightness, ARG_single_byte_bounds, ARG_data_as_commands, ARG_auto_refresh, ARG_native_frames_per_second, ARG_backlight_on_high };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ },
{ MP_QSTR_init_sequence, MP_ARG_REQUIRED | MP_ARG_OBJ },
@@ -121,6 +122,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
{ MP_QSTR_pixels_in_byte_share_row, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} },
{ MP_QSTR_bytes_per_cell, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 1} },
{ MP_QSTR_reverse_pixels_in_byte, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
+ { MP_QSTR_reverse_bytes_in_word, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} },
{ MP_QSTR_set_column_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x2a} },
{ MP_QSTR_set_row_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x2b} },
{ MP_QSTR_write_ram_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x2c} },
@@ -152,23 +154,17 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
mp_raise_ValueError(translate("Display rotation must be in 90 degree increments"));
}
- displayio_display_obj_t *self = NULL;
- for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
- if (displays[i].display.base.type == NULL ||
- displays[i].display.base.type == &mp_type_NoneType) {
- self = &displays[i].display;
- break;
- }
- }
- if (self == NULL) {
- mp_raise_RuntimeError(translate("Too many displays"));
- }
+ primary_display_t *disp = allocate_display_or_raise();
+ displayio_display_obj_t *self = &disp->display;;
self->base.type = &displayio_display_type;
common_hal_displayio_display_construct(
self,
display_bus, args[ARG_width].u_int, args[ARG_height].u_int, args[ARG_colstart].u_int, args[ARG_rowstart].u_int, rotation,
args[ARG_color_depth].u_int, args[ARG_grayscale].u_bool,
- args[ARG_pixels_in_byte_share_row].u_bool, args[ARG_bytes_per_cell].u_bool, args[ARG_reverse_pixels_in_byte].u_bool,
+ args[ARG_pixels_in_byte_share_row].u_bool,
+ args[ARG_bytes_per_cell].u_bool,
+ args[ARG_reverse_pixels_in_byte].u_bool,
+ args[ARG_reverse_bytes_in_word].u_bool,
args[ARG_set_column_command].u_int, args[ARG_set_row_command].u_int,
args[ARG_write_ram_command].u_int,
args[ARG_set_vertical_scroll].u_int,
diff --git a/shared-bindings/displayio/Display.h b/shared-bindings/displayio/Display.h
index 8c2e20262..e69c5b6b5 100644
--- a/shared-bindings/displayio/Display.h
+++ b/shared-bindings/displayio/Display.h
@@ -41,7 +41,7 @@ extern const mp_obj_type_t displayio_display_type;
void common_hal_displayio_display_construct(displayio_display_obj_t* self,
mp_obj_t bus, uint16_t width, uint16_t height,
int16_t colstart, int16_t rowstart, uint16_t rotation, uint16_t color_depth, bool grayscale,
- bool pixels_in_byte_share_row, uint8_t bytes_per_cell, bool reverse_pixels_in_byte,
+ bool pixels_in_byte_share_row, uint8_t bytes_per_cell, bool reverse_pixels_in_byte, bool reverse_bytes_in_word,
uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll,
uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin, uint16_t brightness_command,
mp_float_t brightness, bool auto_brightness,
diff --git a/shared-bindings/displayio/EPaperDisplay.c b/shared-bindings/displayio/EPaperDisplay.c
index 25a4a41e9..1459c1680 100644
--- a/shared-bindings/displayio/EPaperDisplay.c
+++ b/shared-bindings/displayio/EPaperDisplay.c
@@ -136,17 +136,8 @@ STATIC mp_obj_t displayio_epaperdisplay_make_new(const mp_obj_type_t *type, size
mp_raise_ValueError(translate("Display rotation must be in 90 degree increments"));
}
- displayio_epaperdisplay_obj_t *self = NULL;
- for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
- if (displays[i].display.base.type == NULL ||
- displays[i].display.base.type == &mp_type_NoneType) {
- self = &displays[i].epaper_display;
- break;
- }
- }
- if (self == NULL) {
- mp_raise_RuntimeError(translate("Too many displays"));
- }
+ primary_display_t *disp = allocate_display_or_raise();
+ displayio_epaperdisplay_obj_t *self = &disp->epaper_display;;
mp_float_t refresh_time = mp_obj_get_float(args[ARG_refresh_time].u_obj);
mp_float_t seconds_per_frame = mp_obj_get_float(args[ARG_seconds_per_frame].u_obj);
diff --git a/shared-bindings/displayio/FourWire.c b/shared-bindings/displayio/FourWire.c
index 77329578a..1cd51b2e2 100644
--- a/shared-bindings/displayio/FourWire.c
+++ b/shared-bindings/displayio/FourWire.c
@@ -82,19 +82,8 @@ STATIC mp_obj_t displayio_fourwire_make_new(const mp_obj_type_t *type, size_t n_
mcu_pin_obj_t *chip_select = validate_obj_is_free_pin(args[ARG_chip_select].u_obj);
mcu_pin_obj_t *reset = validate_obj_is_free_pin_or_none(args[ARG_reset].u_obj);
- displayio_fourwire_obj_t* self = NULL;
mp_obj_t spi = args[ARG_spi_bus].u_obj;
- for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
- if (displays[i].fourwire_bus.base.type == NULL ||
- displays[i].fourwire_bus.base.type == &mp_type_NoneType) {
- self = &displays[i].fourwire_bus;
- self->base.type = &displayio_fourwire_type;
- break;
- }
- }
- if (self == NULL) {
- mp_raise_RuntimeError(translate("Too many display busses"));
- }
+ displayio_fourwire_obj_t* self = &allocate_display_bus_or_raise()->fourwire_bus;
uint8_t polarity = args[ARG_polarity].u_int;
if (polarity != 0 && polarity != 1) {
diff --git a/shared-bindings/displayio/I2CDisplay.c b/shared-bindings/displayio/I2CDisplay.c
index 2e312aa14..dd3333f6d 100644
--- a/shared-bindings/displayio/I2CDisplay.c
+++ b/shared-bindings/displayio/I2CDisplay.c
@@ -71,19 +71,8 @@ STATIC mp_obj_t displayio_i2cdisplay_make_new(const mp_obj_type_t *type, size_t
mcu_pin_obj_t *reset = validate_obj_is_free_pin_or_none(args[ARG_reset].u_obj);
- displayio_i2cdisplay_obj_t* self = NULL;
mp_obj_t i2c = args[ARG_i2c_bus].u_obj;
- for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
- if (displays[i].i2cdisplay_bus.base.type == NULL ||
- displays[i].i2cdisplay_bus.base.type == &mp_type_NoneType) {
- self = &displays[i].i2cdisplay_bus;
- self->base.type = &displayio_i2cdisplay_type;
- break;
- }
- }
- if (self == NULL) {
- mp_raise_RuntimeError(translate("Too many display busses"));
- }
+ displayio_i2cdisplay_obj_t* self = &allocate_display_bus_or_raise()->i2cdisplay_bus;
common_hal_displayio_i2cdisplay_construct(self,
MP_OBJ_TO_PTR(i2c), args[ARG_device_address].u_int, reset);
diff --git a/shared-bindings/displayio/ParallelBus.c b/shared-bindings/displayio/ParallelBus.c
index b3a876f90..4d9ffb0a1 100644
--- a/shared-bindings/displayio/ParallelBus.c
+++ b/shared-bindings/displayio/ParallelBus.c
@@ -83,18 +83,7 @@ STATIC mp_obj_t displayio_parallelbus_make_new(const mp_obj_type_t *type, size_t
mcu_pin_obj_t *read = validate_obj_is_free_pin(args[ARG_read].u_obj);
mcu_pin_obj_t *reset = validate_obj_is_free_pin(args[ARG_reset].u_obj);
- displayio_parallelbus_obj_t* self = NULL;
- for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
- if (displays[i].parallel_bus.base.type== NULL ||
- displays[i].parallel_bus.base.type == &mp_type_NoneType) {
- self = &displays[i].parallel_bus;
- self->base.type = &displayio_parallelbus_type;
- break;
- }
- }
- if (self == NULL) {
- mp_raise_RuntimeError(translate("Too many display busses"));
- }
+ displayio_parallelbus_obj_t* self = &allocate_display_bus_or_raise()->parallel_bus;
common_hal_displayio_parallelbus_construct(self, data0, command, chip_select, write, read, reset);
return self;
diff --git a/shared-bindings/framebufferio/FramebufferDisplay.c b/shared-bindings/framebufferio/FramebufferDisplay.c
new file mode 100644
index 000000000..aa8fc1a63
--- /dev/null
+++ b/shared-bindings/framebufferio/FramebufferDisplay.c
@@ -0,0 +1,428 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "shared-bindings/framebufferio/FramebufferDisplay.h"
+
+#include <stdint.h>
+
+#include "lib/utils/context_manager_helpers.h"
+#include "py/binary.h"
+#include "py/objproperty.h"
+#include "py/objtype.h"
+#include "py/runtime.h"
+#include "shared-bindings/displayio/Group.h"
+#include "shared-bindings/microcontroller/Pin.h"
+#include "shared-bindings/util.h"
+#include "shared-module/displayio/__init__.h"
+#include "supervisor/shared/translate.h"
+
+//| .. currentmodule:: framebufferio
+//|
+//| :class:`FramebufferDisplay` -- Manage updating a display with framebuffer in RAM
+//| ================================================================================
+//|
+//| This initializes a display and connects it into CircuitPython. Unlike other
+//| objects in CircuitPython, Display objects live until `displayio.release_displays()`
+//| is called. This is done so that CircuitPython can use the display itself.
+//|
+//| .. class:: FramebufferDisplay(framebuffer, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, grayscale=False, pixels_in_byte_share_row=True, bytes_per_cell=1, reverse_pixels_in_byte=False, backlight_pin=None, brightness=1.0, auto_brightness=False, auto_refresh=True, native_frames_per_second=60)
+//|
+//| Create a Display object with the given framebuffer (a buffer, array, ulab.array, etc)
+//|
+//| :param framebuffer: The framebuffer that the display is connected to
+//| :type framebuffer: any core object implementing the framebuffer protocol
+//| :param int width: Width in pixels
+//| :param int height: Height in pixels
+//| :param int rotation: The rotation of the display in degrees clockwise. Must be in 90 degree increments (0, 90, 180, 270)
+//| :param int color_depth: The number of bits of color per pixel transmitted. (Some displays
+//| support 18 bit but 16 is easier to transmit. The last bit is extrapolated.)
+//| :param int bytes_per_cell: Number of bytes per addressable memory location when color_depth < 8. When greater than one, bytes share a row or column according to pixels_in_byte_share_row.
+//| :param microcontroller.Pin backlight_pin: Pin connected to the display's backlight
+//| :param bool brightness: Initial display brightness. This value is ignored if auto_brightness is True.
+//| :param bool auto_brightness: If True, brightness is controlled via an ambient light sensor or other mechanism.
+//| :param bool auto_refresh: Automatically refresh the screen
+//| :param int native_frames_per_second: Number of display refreshes per second
+//|
+STATIC mp_obj_t framebufferio_framebufferdisplay_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+ enum { ARG_framebuffer, ARG_width, ARG_height, ARG_rotation, ARG_color_depth, ARG_bytes_per_cell, ARG_auto_refresh, ARG_native_frames_per_second, NUM_ARGS };
+ static const mp_arg_t allowed_args[] = {
+ { MP_QSTR_framebuffer, MP_ARG_REQUIRED | MP_ARG_OBJ },
+ { MP_QSTR_width, MP_ARG_INT | MP_ARG_KW_ONLY | MP_ARG_REQUIRED, },
+ { MP_QSTR_height, MP_ARG_INT | MP_ARG_KW_ONLY | MP_ARG_REQUIRED, },
+ { MP_QSTR_rotation, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
+ { MP_QSTR_color_depth, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 16} },
+ { MP_QSTR_bytes_per_cell, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 1} },
+ { MP_QSTR_auto_refresh, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} },
+ { MP_QSTR_native_frames_per_second, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 60} },
+ };
+ MP_STATIC_ASSERT( MP_ARRAY_SIZE(allowed_args) == NUM_ARGS );
+ 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);
+
+ mp_obj_t framebuffer = args[ARG_framebuffer].u_obj;
+
+ mp_int_t rotation = args[ARG_rotation].u_int;
+ if (rotation % 90 != 0) {
+ mp_raise_ValueError(translate("Display rotation must be in 90 degree increments"));
+ }
+
+ primary_display_t *disp = allocate_display_or_raise();
+ framebufferio_framebufferdisplay_obj_t *self = &disp->framebuffer_display;
+ self->base.type = &framebufferio_framebufferdisplay_type;
+ common_hal_framebufferio_framebufferdisplay_construct(
+ self,
+ framebuffer,
+ args[ARG_width].u_int, args[ARG_height].u_int,
+ rotation,
+ args[ARG_color_depth].u_int,
+ args[ARG_bytes_per_cell].u_int,
+ args[ARG_auto_refresh].u_bool,
+ args[ARG_native_frames_per_second].u_int
+ );
+
+ return self;
+}
+
+// Helper to ensure we have the native super class instead of a subclass.
+static framebufferio_framebufferdisplay_obj_t* native_display(mp_obj_t display_obj) {
+ mp_obj_t native_display = mp_instance_cast_to_native_base(display_obj, &framebufferio_framebufferdisplay_type);
+ mp_obj_assert_native_inited(native_display);
+ return MP_OBJ_TO_PTR(native_display);
+}
+
+//| .. method:: show(group)
+//|
+//| Switches to displaying the given group of layers. When group is None, the default
+//| CircuitPython terminal will be shown.
+//|
+//| :param Group group: The group to show.
+//|
+STATIC mp_obj_t framebufferio_framebufferdisplay_obj_show(mp_obj_t self_in, mp_obj_t group_in) {
+ framebufferio_framebufferdisplay_obj_t *self = native_display(self_in);
+ displayio_group_t* group = NULL;
+ if (group_in != mp_const_none) {
+ group = MP_OBJ_TO_PTR(native_group(group_in));
+ }
+
+ bool ok = common_hal_framebufferio_framebufferdisplay_show(self, group);
+ if (!ok) {
+ mp_raise_ValueError(translate("Group already used"));
+ }
+ return mp_const_none;
+}
+MP_DEFINE_CONST_FUN_OBJ_2(framebufferio_framebufferdisplay_show_obj, framebufferio_framebufferdisplay_obj_show);
+
+//| .. method:: refresh(*, target_frames_per_second=60, minimum_frames_per_second=1)
+//|
+//| When auto refresh is off, waits for the target frame rate and then refreshes the display,
+//| returning True. If the call has taken too long since the last refresh call for the given
+//| target frame rate, then the refresh returns False immediately without updating the screen to
+//| hopefully help getting caught up.
+//|
+//| If the time since the last successful refresh is below the minimum frame rate, then an
+//| exception will be raised. Set minimum_frames_per_second to 0 to disable.
+//|
+//| When auto refresh is on, updates the display immediately. (The display will also update
+//| without calls to this.)
+//|
+//| :param int target_frames_per_second: How many times a second `refresh` should be called and the screen updated.
+//| :param int minimum_frames_per_second: The minimum number of times the screen should be updated per second.
+//|
+STATIC mp_obj_t framebufferio_framebufferdisplay_obj_refresh(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+ enum { ARG_target_frames_per_second, ARG_minimum_frames_per_second };
+ static const mp_arg_t allowed_args[] = {
+ { MP_QSTR_target_frames_per_second, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 60} },
+ { MP_QSTR_minimum_frames_per_second, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} },
+ };
+ mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
+ mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
+
+ framebufferio_framebufferdisplay_obj_t *self = native_display(pos_args[0]);
+ uint32_t maximum_ms_per_real_frame = 0xffffffff;
+ mp_int_t minimum_frames_per_second = args[ARG_minimum_frames_per_second].u_int;
+ if (minimum_frames_per_second > 0) {
+ maximum_ms_per_real_frame = 1000 / minimum_frames_per_second;
+ }
+ return mp_obj_new_bool(common_hal_framebufferio_framebufferdisplay_refresh(self, 1000 / args[ARG_target_frames_per_second].u_int, maximum_ms_per_real_frame));
+}
+MP_DEFINE_CONST_FUN_OBJ_KW(framebufferio_framebufferdisplay_refresh_obj, 1, framebufferio_framebufferdisplay_obj_refresh);
+
+//| .. attribute:: auto_refresh
+//|
+//| True when the display is refreshed automatically.
+//|
+STATIC mp_obj_t framebufferio_framebufferdisplay_obj_get_auto_refresh(mp_obj_t self_in) {
+ framebufferio_framebufferdisplay_obj_t *self = native_display(self_in);
+ return mp_obj_new_bool(common_hal_framebufferio_framebufferdisplay_get_auto_refresh(self));
+}
+MP_DEFINE_CONST_FUN_OBJ_1(framebufferio_framebufferdisplay_get_auto_refresh_obj, framebufferio_framebufferdisplay_obj_get_auto_refresh);
+
+STATIC mp_obj_t framebufferio_framebufferdisplay_obj_set_auto_refresh(mp_obj_t self_in, mp_obj_t auto_refresh) {
+ framebufferio_framebufferdisplay_obj_t *self = native_display(self_in);
+
+ common_hal_framebufferio_framebufferdisplay_set_auto_refresh(self, mp_obj_is_true(auto_refresh));
+
+ return mp_const_none;
+}
+MP_DEFINE_CONST_FUN_OBJ_2(framebufferio_framebufferdisplay_set_auto_refresh_obj, framebufferio_framebufferdisplay_obj_set_auto_refresh);
+
+const mp_obj_property_t framebufferio_framebufferdisplay_auto_refresh_obj = {
+ .base.type = &mp_type_property,
+ .proxy = {(mp_obj_t)&framebufferio_framebufferdisplay_get_auto_refresh_obj,
+ (mp_obj_t)&framebufferio_framebufferdisplay_set_auto_refresh_obj,
+ (mp_obj_t)&mp_const_none_obj},
+};
+
+//| .. attribute:: brightness
+//|
+//| The brightness of the display as a float. 0.0 is off and 1.0 is full brightness. When
+//| `auto_brightness` is True, the value of `brightness` will change automatically.
+//| If `brightness` is set, `auto_brightness` will be disabled and will be set to False.
+//|
+STATIC mp_obj_t framebufferio_framebufferdisplay_obj_get_brightness(mp_obj_t self_in) {
+ framebufferio_framebufferdisplay_obj_t *self = native_display(self_in);
+ mp_float_t brightness = common_hal_framebufferio_framebufferdisplay_get_brightness(self);
+ if (brightness < 0) {
+ mp_raise_RuntimeError(translate("Brightness not adjustable"));
+ }
+ return mp_obj_new_float(brightness);
+}
+MP_DEFINE_CONST_FUN_OBJ_1(framebufferio_framebufferdisplay_get_brightness_obj, framebufferio_framebufferdisplay_obj_get_brightness);
+
+STATIC mp_obj_t framebufferio_framebufferdisplay_obj_set_brightness(mp_obj_t self_in, mp_obj_t brightness_obj) {
+ framebufferio_framebufferdisplay_obj_t *self = native_display(self_in);
+ common_hal_framebufferio_framebufferdisplay_set_auto_brightness(self, false);
+ mp_float_t brightness = mp_obj_get_float(brightness_obj);
+ if (brightness < 0.0f || brightness > 1.0f) {
+ mp_raise_ValueError(translate("Brightness must be 0-1.0"));
+ }
+ bool ok = common_hal_framebufferio_framebufferdisplay_set_brightness(self, brightness);
+ if (!ok) {
+ mp_raise_RuntimeError(translate("Brightness not adjustable"));
+ }
+ return mp_const_none;
+}
+MP_DEFINE_CONST_FUN_OBJ_2(framebufferio_framebufferdisplay_set_brightness_obj, framebufferio_framebufferdisplay_obj_set_brightness);
+
+const mp_obj_property_t framebufferio_framebufferdisplay_brightness_obj = {
+ .base.type = &mp_type_property,
+ .proxy = {(mp_obj_t)&framebufferio_framebufferdisplay_get_brightness_obj,
+ (mp_obj_t)&framebufferio_framebufferdisplay_set_brightness_obj,
+ (mp_obj_t)&mp_const_none_obj},
+};
+
+//| .. attribute:: auto_brightness
+//|
+//| True when the display brightness is adjusted automatically, based on an ambient
+//| light sensor or other method. Note that some displays may have this set to True by default,
+//| but not actually implement automatic brightness adjustment. `auto_brightness` is set to False
+//| if `brightness` is set manually.
+//|
+STATIC mp_obj_t framebufferio_framebufferdisplay_obj_get_auto_brightness(mp_obj_t self_in) {
+ framebufferio_framebufferdisplay_obj_t *self = native_display(self_in);
+ return mp_obj_new_bool(common_hal_framebufferio_framebufferdisplay_get_auto_brightness(self));
+}
+MP_DEFINE_CONST_FUN_OBJ_1(framebufferio_framebufferdisplay_get_auto_brightness_obj, framebufferio_framebufferdisplay_obj_get_auto_brightness);
+
+STATIC mp_obj_t framebufferio_framebufferdisplay_obj_set_auto_brightness(mp_obj_t self_in, mp_obj_t auto_brightness) {
+ framebufferio_framebufferdisplay_obj_t *self = native_display(self_in);
+
+ bool ok = common_hal_framebufferio_framebufferdisplay_set_auto_brightness(self, mp_obj_is_true(auto_brightness));
+ if (!ok) {
+ mp_raise_RuntimeError(translate("Brightness not adjustable"));
+ }
+
+ return mp_const_none;
+}
+MP_DEFINE_CONST_FUN_OBJ_2(framebufferio_framebufferdisplay_set_auto_brightness_obj, framebufferio_framebufferdisplay_obj_set_auto_brightness);
+
+const mp_obj_property_t framebufferio_framebufferdisplay_auto_brightness_obj = {
+ .base.type = &mp_type_property,
+ .proxy = {(mp_obj_t)&framebufferio_framebufferdisplay_get_auto_brightness_obj,
+ (mp_obj_t)&framebufferio_framebufferdisplay_set_auto_brightness_obj,
+ (mp_obj_t)&mp_const_none_obj},
+};
+
+//| .. attribute:: width
+//|
+//| Gets the width of the framebuffer
+//|
+STATIC mp_obj_t framebufferio_framebufferdisplay_obj_get_width(mp_obj_t self_in) {
+ framebufferio_framebufferdisplay_obj_t *self = native_display(self_in);
+ return MP_OBJ_NEW_SMALL_INT(common_hal_framebufferio_framebufferdisplay_get_width(self));
+}
+MP_DEFINE_CONST_FUN_OBJ_1(framebufferio_framebufferdisplay_get_width_obj, framebufferio_framebufferdisplay_obj_get_width);
+
+const mp_obj_property_t framebufferio_framebufferdisplay_width_obj = {
+ .base.type = &mp_type_property,
+ .proxy = {(mp_obj_t)&framebufferio_framebufferdisplay_get_width_obj,
+ (mp_obj_t)&mp_const_none_obj,
+ (mp_obj_t)&mp_const_none_obj},
+};
+
+//| .. attribute:: height
+//|
+//| Gets the height of the framebuffer
+//|
+STATIC mp_obj_t framebufferio_framebufferdisplay_obj_get_height(mp_obj_t self_in) {
+ framebufferio_framebufferdisplay_obj_t *self = native_display(self_in);
+ return MP_OBJ_NEW_SMALL_INT(common_hal_framebufferio_framebufferdisplay_get_height(self));
+}
+MP_DEFINE_CONST_FUN_OBJ_1(framebufferio_framebufferdisplay_get_height_obj, framebufferio_framebufferdisplay_obj_get_height);
+
+const mp_obj_property_t framebufferio_framebufferdisplay_height_obj = {
+ .base.type = &mp_type_property,
+ .proxy = {(mp_obj_t)&framebufferio_framebufferdisplay_get_height_obj,
+ (mp_obj_t)&mp_const_none_obj,
+ (mp_obj_t)&mp_const_none_obj},
+};
+
+//| .. attribute:: rotation
+//|
+//| The rotation of the display as an int in degrees.
+//|
+STATIC mp_obj_t framebufferio_framebufferdisplay_obj_get_rotation(mp_obj_t self_in) {
+ framebufferio_framebufferdisplay_obj_t *self = native_display(self_in);
+ return MP_OBJ_NEW_SMALL_INT(common_hal_framebufferio_framebufferdisplay_get_rotation(self));
+}
+MP_DEFINE_CONST_FUN_OBJ_1(framebufferio_framebufferdisplay_get_rotation_obj, framebufferio_framebufferdisplay_obj_get_rotation);
+STATIC mp_obj_t framebufferio_framebufferdisplay_obj_set_rotation(mp_obj_t self_in, mp_obj_t value) {
+ framebufferio_framebufferdisplay_obj_t *self = native_display(self_in);
+ common_hal_framebufferio_framebufferdisplay_set_rotation(self, mp_obj_get_int(value));
+ return mp_const_none;
+}
+MP_DEFINE_CONST_FUN_OBJ_2(framebufferio_framebufferdisplay_set_rotation_obj, framebufferio_framebufferdisplay_obj_set_rotation);
+
+
+const mp_obj_property_t framebufferio_framebufferdisplay_rotation_obj = {
+ .base.type = &mp_type_property,
+ .proxy = {(mp_obj_t)&framebufferio_framebufferdisplay_get_rotation_obj,
+ (mp_obj_t)&framebufferio_framebufferdisplay_set_rotation_obj,
+ (mp_obj_t)&mp_const_none_obj},
+};
+
+//| .. attribute:: framebuffer
+//|
+//| The framebuffer being used by the display
+//|
+//|
+STATIC mp_obj_t framebufferio_framebufferdisplay_obj_get_framebuffer(mp_obj_t self_in) {
+ framebufferio_framebufferdisplay_obj_t *self = native_display(self_in);
+ return common_hal_framebufferio_framebufferdisplay_get_framebuffer(self);
+}
+MP_DEFINE_CONST_FUN_OBJ_1(framebufferio_framebufferdisplay_get_framebuffer_obj, framebufferio_framebufferdisplay_obj_get_framebuffer);
+
+const mp_obj_property_t framebufferio_framebufferframebuffer_obj = {
+ .base.type = &mp_type_property,
+ .proxy = {(mp_obj_t)&framebufferio_framebufferdisplay_get_framebuffer_obj,
+ (mp_obj_t)&mp_const_none_obj,
+ (mp_obj_t)&mp_const_none_obj},
+};
+
+
+//| .. method:: fill_row(y, buffer)
+//|
+//| Extract the pixels from a single row
+//|
+//| :param int y: The top edge of the area
+//| :param bytearray buffer: The buffer in which to place the pixel data
+STATIC mp_obj_t framebufferio_framebufferdisplay_obj_fill_row(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+ enum { ARG_y, ARG_buffer };
+ static const mp_arg_t allowed_args[] = {
+ { MP_QSTR_y, MP_ARG_INT | MP_ARG_REQUIRED, {.u_int = -1} },
+ { MP_QSTR_buffer, MP_ARG_OBJ | MP_ARG_REQUIRED, {} },
+ };
+ mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
+ mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
+ framebufferio_framebufferdisplay_obj_t *self = native_display(pos_args[0]);
+ mp_int_t y = args[ARG_y].u_int;
+ mp_obj_t *result = args[ARG_buffer].u_obj;
+
+ mp_buffer_info_t bufinfo;
+ mp_get_buffer_raise(result, &bufinfo, MP_BUFFER_WRITE);
+
+ if (bufinfo.typecode != BYTEARRAY_TYPECODE) {
+ mp_raise_ValueError(translate("Buffer is not a bytearray."));
+ }
+ if (self->core.colorspace.depth != 16) {
+ mp_raise_ValueError(translate("Display must have a 16 bit colorspace."));
+ }
+
+ displayio_area_t area = {
+ .x1 = 0,
+ .y1 = y,
+ .x2 = self->core.width,
+ .y2 = y + 1
+ };
+ uint8_t pixels_per_word = (sizeof(uint32_t) * 8) / self->core.colorspace.depth;
+ uint16_t buffer_size = self->core.width / pixels_per_word;
+ uint16_t pixels_per_buffer = displayio_area_size(&area);
+ if (pixels_per_buffer % pixels_per_word) {
+ buffer_size += 1;
+ }
+
+ uint32_t *result_buffer = bufinfo.buf;
+ size_t result_buffer_size = bufinfo.len;
+
+ if (result_buffer_size >= (buffer_size * 4)) {
+ volatile uint32_t mask_length = (pixels_per_buffer / 32) + 1;
+ uint32_t mask[mask_length];
+
+ for (uint16_t k = 0; k < mask_length; k++) {
+ mask[k] = 0x00000000;
+ }
+
+ displayio_display_core_fill_area(&self->core, &area, mask, result_buffer);
+ return result;
+ } else {
+ mp_raise_ValueError(translate("Buffer is too small"));
+ }
+}
+MP_DEFINE_CONST_FUN_OBJ_KW(framebufferio_framebufferdisplay_fill_row_obj, 1, framebufferio_framebufferdisplay_obj_fill_row);
+
+STATIC const mp_rom_map_elem_t framebufferio_framebufferdisplay_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(&framebufferio_framebufferdisplay_show_obj) },
+ { MP_ROM_QSTR(MP_QSTR_refresh), MP_ROM_PTR(&framebufferio_framebufferdisplay_refresh_obj) },
+ { MP_ROM_QSTR(MP_QSTR_fill_row), MP_ROM_PTR(&framebufferio_framebufferdisplay_fill_row_obj) },
+
+ { MP_ROM_QSTR(MP_QSTR_auto_refresh), MP_ROM_PTR(&framebufferio_framebufferdisplay_auto_refresh_obj) },
+
+ { MP_ROM_QSTR(MP_QSTR_brightness), MP_ROM_PTR(&framebufferio_framebufferdisplay_brightness_obj) },
+ { MP_ROM_QSTR(MP_QSTR_auto_brightness), MP_ROM_PTR(&framebufferio_framebufferdisplay_auto_brightness_obj) },
+
+ { MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&framebufferio_framebufferdisplay_width_obj) },
+ { MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&framebufferio_framebufferdisplay_height_obj) },
+ { MP_ROM_QSTR(MP_QSTR_rotation), MP_ROM_PTR(&framebufferio_framebufferdisplay_rotation_obj) },
+ { MP_ROM_QSTR(MP_QSTR_framebuffer), MP_ROM_PTR(&framebufferio_framebufferframebuffer_obj) },
+};
+STATIC MP_DEFINE_CONST_DICT(framebufferio_framebufferdisplay_locals_dict, framebufferio_framebufferdisplay_locals_dict_table);
+
+const mp_obj_type_t framebufferio_framebufferdisplay_type = {
+ { &mp_type_type },
+ .name = MP_QSTR_FramebufferDisplay,
+ .make_new = framebufferio_framebufferdisplay_make_new,
+ .locals_dict = (mp_obj_dict_t*)&framebufferio_framebufferdisplay_locals_dict,
+};
diff --git a/shared-bindings/framebufferio/FramebufferDisplay.h b/shared-bindings/framebufferio/FramebufferDisplay.h
new file mode 100644
index 000000000..b472088d2
--- /dev/null
+++ b/shared-bindings/framebufferio/FramebufferDisplay.h
@@ -0,0 +1,69 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2017, 2018 Scott Shawcroft for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_FRAMEBUFFERDISPLAY_H
+#define MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_FRAMEBUFFERDISPLAY_H
+
+#include "common-hal/microcontroller/Pin.h"
+
+#include "shared-module/framebufferio/FramebufferDisplay.h"
+#include "shared-module/displayio/Group.h"
+
+extern const mp_obj_type_t framebufferio_framebufferdisplay_type;
+
+#define DELAY 0x80
+
+#define NO_BRIGHTNESS_COMMAND 0x100
+
+void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebufferdisplay_obj_t* self,
+ mp_obj_t framebuffer, uint16_t width, uint16_t height,
+ uint16_t rotation, uint16_t color_depth,
+ uint8_t bytes_per_cell,
+ bool auto_refresh, uint16_t native_frames_per_second);
+
+bool common_hal_framebufferio_framebufferdisplay_show(framebufferio_framebufferdisplay_obj_t* self,
+ displayio_group_t* root_group);
+
+bool common_hal_framebufferio_framebufferdisplay_refresh(framebufferio_framebufferdisplay_obj_t* self, uint32_t target_ms_per_frame, uint32_t maximum_ms_per_real_frame);
+
+bool common_hal_framebufferio_framebufferdisplay_get_auto_refresh(framebufferio_framebufferdisplay_obj_t* self);
+void common_hal_framebufferio_framebufferdisplay_set_auto_refresh(framebufferio_framebufferdisplay_obj_t* self, bool auto_refresh);
+
+uint16_t common_hal_framebufferio_framebufferdisplay_get_width(framebufferio_framebufferdisplay_obj_t* self);
+uint16_t common_hal_framebufferio_framebufferdisplay_get_height(framebufferio_framebufferdisplay_obj_t* self);
+uint16_t common_hal_framebufferio_framebufferdisplay_get_rotation(framebufferio_framebufferdisplay_obj_t* self);
+void common_hal_framebufferio_framebufferdisplay_set_rotation(framebufferio_framebufferdisplay_obj_t* self, int rotation);
+
+bool common_hal_framebufferio_framebufferdisplay_get_auto_brightness(framebufferio_framebufferdisplay_obj_t* self);
+bool common_hal_framebufferio_framebufferdisplay_set_auto_brightness(framebufferio_framebufferdisplay_obj_t* self, bool auto_brightness);
+
+mp_float_t common_hal_framebufferio_framebufferdisplay_get_brightness(framebufferio_framebufferdisplay_obj_t* self);
+bool common_hal_framebufferio_framebufferdisplay_set_brightness(framebufferio_framebufferdisplay_obj_t* self, mp_float_t brightness);
+
+mp_obj_t common_hal_framebufferio_framebufferdisplay_framebuffer(framebufferio_framebufferdisplay_obj_t* self);
+
+
+#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_FRAMEBUFFERDISPLAY_H
diff --git a/shared-bindings/framebufferio/__init__.c b/shared-bindings/framebufferio/__init__.c
new file mode 100644
index 000000000..0f0823a25
--- /dev/null
+++ b/shared-bindings/framebufferio/__init__.c
@@ -0,0 +1,63 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 Jeff Epler for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "py/obj.h"
+#include "shared-bindings/framebufferio/__init__.h"
+#include "shared-bindings/framebufferio/FramebufferDisplay.h"
+
+//| :mod:`framebufferio` --- Native framebuffer display driving
+//| =========================================================================
+//|
+//| .. module:: framebufferio
+//| :synopsis: Native helpers for driving displays
+//| :platform: SAMD51, nRF52
+//|
+//| The `framebufferio` module contains classes to manage display output
+//| including synchronizing with refresh rates and partial updating.
+//| It is used in conjunction with classes from `displayio` to actually
+//| place items on the display; and classes like `Protomatter` to actually
+//| drive the display.
+//|
+//| Libraries
+//|
+//| .. toctree::
+//| :maxdepth: 3
+//|
+//| FramebufferDisplay
+//|
+
+#if CIRCUITPY_FRAMEBUFFERIO
+static const mp_rom_map_elem_t framebufferio_module_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_framebufferio) },
+ { MP_ROM_QSTR(MP_QSTR_FramebufferDisplay), MP_ROM_PTR(&framebufferio_framebufferdisplay_type) },
+};
+STATIC MP_DEFINE_CONST_DICT(framebufferio_module_globals, framebufferio_module_globals_table);
+const mp_obj_module_t framebufferio_module = {
+ .base = { &mp_type_module },
+ .globals = (mp_obj_dict_t*)&framebufferio_module_globals,
+};
+#endif
+
diff --git a/shared-bindings/framebufferio/__init__.h b/shared-bindings/framebufferio/__init__.h
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/shared-bindings/framebufferio/__init__.h
diff --git a/shared-bindings/microcontroller/Pin.h b/shared-bindings/microcontroller/Pin.h
index 4f29322a0..bb5256b55 100644
--- a/shared-bindings/microcontroller/Pin.h
+++ b/shared-bindings/microcontroller/Pin.h
@@ -43,5 +43,11 @@ void assert_pin_free(const mcu_pin_obj_t* pin);
bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t* pin);
void common_hal_never_reset_pin(const mcu_pin_obj_t* pin);
void common_hal_reset_pin(const mcu_pin_obj_t* pin);
+uint8_t common_hal_mcu_pin_number(const mcu_pin_obj_t* pin);
+void common_hal_mcu_pin_claim(const mcu_pin_obj_t* pin);
+void common_hal_mcu_pin_claim_number(uint8_t pin_no);
+void common_hal_mcu_pin_reset_number(uint8_t pin_no);
+
+#define COMMON_HAL_MCU_NO_PIN ((uint8_t)0xff)
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_MICROCONTROLLER_PIN_H
diff --git a/shared-bindings/ulab/__init__.rst b/shared-bindings/ulab/__init__.rst
index 1379e56f3..c9f2617ff 100644
--- a/shared-bindings/ulab/__init__.rst
+++ b/shared-bindings/ulab/__init__.rst
@@ -79,26 +79,30 @@ ulab.array -- 1- and 2- dimensional array
.. method:: __add__()
Adds corresponding elements of the two arrays, or adds a number to all
- elements of the array. A number must be on the right hand side. If
- both arguments are arrays, their sizes must match.
+ elements of the array. If both arguments are arrays, their sizes must match.
.. method:: __sub__()
- Subtracts corresponding elements of the two arrays, or subtracts a
- number from all elements of the array. A number must be on the right
- hand side. If both arguments are arrays, their sizes must match.
+ Subtracts corresponding elements of the two arrays, or adds a number to all
+ elements of the array. If both arguments are arrays, their sizes must match.
.. method:: __mul__()
Multiplies corresponding elements of the two arrays, or multiplies
- all elements of the array by a number. A number must be on the right
- hand side. If both arguments are arrays, their sizes must match.
+ all elements of the array by a number. If both arguments are arrays,
+ their sizes must match.
.. method:: __div__()
Multiplies corresponding elements of the two arrays, or divides
- all elements of the array by a number. A number must be on the right
- hand side. If both arguments are arrays, their sizes must match.
+ all elements of the array by a number. If both arguments are arrays,
+ their sizes must match.
+
+ .. method:: __pow__()
+
+ Computes the power (x**y) of corresponding elements of the the two arrays,
+ or one number and one array. If both arguments are arrays, their sizes
+ must match.
.. method:: __getitem__()
@@ -126,7 +130,7 @@ Array type codes
Type code for unsigned integers in the range 0 .. 255 inclusive, like the 'H' typecode of `array.array`
-.. attribute:: uint8
+.. attribute:: uint16
Type code for unsigned integers in the range 0 .. 65535 inclusive, like the 'h' typecode of `array.array`
@@ -348,6 +352,12 @@ much more efficient than expressing the same operation as a Python loop.
Return the total number of elements in the array, as an integer.
+.. method:: trace(m)
+
+ :param m: a square matrix
+
+ Compute the trace of the matrix, the sum of its diagonal elements.
+
:mod:`ulab.filter` --- Filtering functions
==========================================
@@ -404,11 +414,11 @@ operate over the flattened array (None), rows (0), or columns (1).
.. method:: argmax(array, \*, axis=None)
- Return the index of the maximum element of the 1D array, as an array with 1 element
+ Return the index of the maximum element of the 1D array
.. method:: argmin(array, \*, axis=None)
- Return the index of the minimum element of the 1D array, as an array with 1 element
+ Return the index of the minimum element of the 1D array
.. method:: argsort(array, \*, axis=None)
@@ -426,7 +436,7 @@ operate over the flattened array (None), rows (0), or columns (1).
.. method:: max(array, \*, axis=None)
- Return the maximum element of the 1D array, as an array with 1 element
+ Return the maximum element of the 1D array
.. method:: mean(array, \*, axis=None)
@@ -434,7 +444,7 @@ operate over the flattened array (None), rows (0), or columns (1).
.. method:: min(array, \*, axis=None)
- Return the minimum element of the 1D array, as an array with 1 element
+ Return the minimum element of the 1D array
.. method:: roll(array, distance, \*, axis=None)