summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2019-01-17 00:20:16 -0800
committerScott Shawcroft <scott@tannewt.org>2019-01-17 00:20:16 -0800
commit84292ad89070f1994ed09b59c8a693216a40cd89 (patch)
tree267e6ae05f87d95a432f6cd112c46189c9a70ce0 /shared-bindings
parent05d8885a1ab959fabdbb77f99408b2e7dc78b97c (diff)
External fourwire works and blinka splash after
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/displayio/Display.c23
-rw-r--r--shared-bindings/displayio/FourWire.c23
-rw-r--r--shared-bindings/displayio/FourWire.h2
-rw-r--r--shared-bindings/displayio/ParallelBus.h2
-rw-r--r--shared-bindings/displayio/__init__.c16
-rw-r--r--shared-bindings/displayio/__init__.h4
6 files changed, 48 insertions, 22 deletions
diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c
index 5db470417..21f44965e 100644
--- a/shared-bindings/displayio/Display.c
+++ b/shared-bindings/displayio/Display.c
@@ -40,18 +40,19 @@
//| .. currentmodule:: displayio
//|
-//| :class:`FourWire` -- Manage updating a display over SPI four wire protocol
+//| :class:`Display` -- Manage updating a display over a display bus
//| ==========================================================================
//|
-//| Manage updating a display over SPI four wire protocol in the background while Python code runs.
-//| It doesn't handle display initialization.
+//| 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.
//|
//| .. warning:: This will be changed before 4.0.0. Consider it very experimental.
//|
//| .. class:: Display(display_bus, *, width, height, colstart=0, rowstart=0, color_depth=16,
//| set_column_command=0x2a set_row_command=0x2b, write_ram_command=0x2c)
//|
-//| Create a FourWire object associated with the given pins.
+//| Create a Display object.
//|
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_color_depth, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command };
@@ -80,11 +81,15 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[ARG_init_sequence].u_obj, &bufinfo, MP_BUFFER_READ);
- displayio_display_obj_t *self;
- if (display_bus == &primary_display.fourwire_bus) {
- self = &primary_display.display;
- } else {
- self = m_new_obj(displayio_display_obj_t);
+ displayio_display_obj_t *self = NULL;
+ for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
+ if (displays[i].display.base.type == NULL) {
+ self = &displays[i].display;
+ break;
+ }
+ }
+ if (self == NULL) {
+ mp_raise_RuntimeError(translate("Display limit reached"));
}
self->base.type = &displayio_display_type;
common_hal_displayio_display_construct(self,
diff --git a/shared-bindings/displayio/FourWire.c b/shared-bindings/displayio/FourWire.c
index 674d1c900..9833fbc64 100644
--- a/shared-bindings/displayio/FourWire.c
+++ b/shared-bindings/displayio/FourWire.c
@@ -69,18 +69,21 @@ STATIC mp_obj_t displayio_fourwire_make_new(const mp_obj_type_t *type, size_t n_
if (command == mp_const_none || chip_select == mp_const_none) {
mp_raise_ValueError(translate("Command and chip_select required"));
}
+ assert_pin_free(command);
+ assert_pin_free(chip_select);
+ assert_pin_free(reset);
- displayio_fourwire_obj_t* self;
+ displayio_fourwire_obj_t* self = NULL;
mp_obj_t spi = args[ARG_spi_bus].u_obj;
- if (board_spi() == spi && primary_display.bus_type == NULL) {
- self = &primary_display.fourwire_bus;
- primary_display.bus_type = &displayio_fourwire_type;
- } else {
- // TODO(tannewt): Always check pin free. For now we ignore the primary display.
- assert_pin_free(command);
- assert_pin_free(chip_select);
- assert_pin_free(reset);
- self = m_new_obj(displayio_fourwire_obj_t);
+ for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
+ if (displays[i].fourwire_bus.base.type== NULL) {
+ self = &displays[i].fourwire_bus;
+ self->base.type = &displayio_fourwire_type;
+ break;
+ }
+ }
+ if (self == NULL) {
+ mp_raise_RuntimeError(translate("Display bus limit reached"));
}
common_hal_displayio_fourwire_construct(self,
diff --git a/shared-bindings/displayio/FourWire.h b/shared-bindings/displayio/FourWire.h
index a9e1bf566..3a9f66d4c 100644
--- a/shared-bindings/displayio/FourWire.h
+++ b/shared-bindings/displayio/FourWire.h
@@ -39,6 +39,8 @@ void common_hal_displayio_fourwire_construct(displayio_fourwire_obj_t* self,
busio_spi_obj_t* spi, const mcu_pin_obj_t* command,
const mcu_pin_obj_t* chip_select, const mcu_pin_obj_t* reset);
+void common_hal_displayio_fourwire_deinit(displayio_fourwire_obj_t* self);
+
bool common_hal_displayio_fourwire_begin_transaction(mp_obj_t self);
void common_hal_displayio_fourwire_send(mp_obj_t self, bool command, uint8_t *data, uint32_t data_length);
diff --git a/shared-bindings/displayio/ParallelBus.h b/shared-bindings/displayio/ParallelBus.h
index f1d1656b1..c73934838 100644
--- a/shared-bindings/displayio/ParallelBus.h
+++ b/shared-bindings/displayio/ParallelBus.h
@@ -38,6 +38,8 @@ void common_hal_displayio_parallelbus_construct(displayio_parallelbus_obj_t* sel
const mcu_pin_obj_t* data0, const mcu_pin_obj_t* command,
const mcu_pin_obj_t* chip_select, const mcu_pin_obj_t* reset, const mcu_pin_obj_t* write);
+void common_hal_displayio_parallelbus_deinit(displayio_parallelbus_obj_t* self);
+
bool common_hal_displayio_parallelbus_begin_transaction(mp_obj_t self);
void common_hal_displayio_parallelbus_send(mp_obj_t self, bool command, uint8_t *data, uint32_t data_length);
diff --git a/shared-bindings/displayio/__init__.c b/shared-bindings/displayio/__init__.c
index d485d8095..66cf4d63d 100644
--- a/shared-bindings/displayio/__init__.c
+++ b/shared-bindings/displayio/__init__.c
@@ -32,6 +32,7 @@
#include "shared-bindings/displayio/__init__.h"
#include "shared-bindings/displayio/Bitmap.h"
#include "shared-bindings/displayio/ColorConverter.h"
+#include "shared-bindings/displayio/Display.h"
#include "shared-bindings/displayio/FourWire.h"
#include "shared-bindings/displayio/Group.h"
#include "shared-bindings/displayio/OnDiskBitmap.h"
@@ -61,6 +62,7 @@
//|
//| Bitmap
//| ColorConverter
+//| Display
//| FourWire
//| Group
//| OnDiskBitmap
@@ -71,10 +73,22 @@
//| All libraries change hardware state but are never deinit
//|
+
+//| .. method:: release_displays()
+//|
+//| Releases any actively used displays so theis pins can be used again.
+//|
+STATIC mp_obj_t displayio_release_displays(void) {
+ common_hal_displayio_release_displays();
+ return mp_const_none;
+}
+MP_DEFINE_CONST_FUN_OBJ_0(displayio_release_displays_obj, displayio_release_displays);
+
STATIC const mp_rom_map_elem_t displayio_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_displayio) },
{ MP_ROM_QSTR(MP_QSTR_Bitmap), MP_ROM_PTR(&displayio_bitmap_type) },
{ MP_ROM_QSTR(MP_QSTR_ColorConverter), MP_ROM_PTR(&displayio_colorconverter_type) },
+ { MP_ROM_QSTR(MP_QSTR_Display), MP_ROM_PTR(&displayio_display_type) },
{ MP_ROM_QSTR(MP_QSTR_Group), MP_ROM_PTR(&displayio_group_type) },
{ MP_ROM_QSTR(MP_QSTR_OnDiskBitmap), MP_ROM_PTR(&displayio_ondiskbitmap_type) },
{ MP_ROM_QSTR(MP_QSTR_Palette), MP_ROM_PTR(&displayio_palette_type) },
@@ -82,6 +96,8 @@ STATIC const mp_rom_map_elem_t displayio_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_Sprite), MP_ROM_PTR(&displayio_sprite_type) },
{ MP_ROM_QSTR(MP_QSTR_FourWire), MP_ROM_PTR(&displayio_fourwire_type) },
+
+ { MP_ROM_QSTR(MP_QSTR_release_displays), MP_ROM_PTR(&displayio_release_displays_obj) },
};
STATIC MP_DEFINE_CONST_DICT(displayio_module_globals, displayio_module_globals_table);
diff --git a/shared-bindings/displayio/__init__.h b/shared-bindings/displayio/__init__.h
index a6663bf57..427ddb47d 100644
--- a/shared-bindings/displayio/__init__.h
+++ b/shared-bindings/displayio/__init__.h
@@ -27,8 +27,6 @@
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO___INIT___H
#define MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO___INIT___H
-#include "py/obj.h"
-
-// Nothing now.
+void common_hal_displayio_release_displays(void);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO___INIT___H