Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/environment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ Whether to configure the display at board initialization time, one of the follow
CIRCUITPY_PICODVI_ENABLE="never"

A display configured in this manner is available at ``supervisor.runtime.display``
until it is released by ``displayio.release_displays()``. It does not appear at
until it is released by ``supervisor.runtime.display.deinit()``. It does not appear at
``board.DISPLAY``.

`Adafruit Feather RP2350 <https://circuitpython.org/board/adafruit_feather_rp2350/>`_
Expand Down Expand Up @@ -284,7 +284,7 @@ next to a 640x480 display. Set this to false to keep that RAM free, for
example on a monitor without speakers.

``supervisor.runtime.audio`` is a :py:class:`picodvi.AudioOut`. It becomes ``None`` when
the display is released by ``displayio.release_displays()`` or when it is
the display is released, such as by ``supervisor.runtime.display.deinit()``, or when it is
deinitialized, and stays ``None`` until the next reset.

`Adafruit Feather RP2350 <https://circuitpython.org/board/adafruit_feather_rp2350/>`_
Expand Down
5 changes: 2 additions & 3 deletions locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2583,8 +2583,7 @@ msgid "%q must be >= %d"
msgstr ""

#: py/argcheck.c shared-bindings/gifio/GifWriter.c
#: shared-module/_airlift/__init__.c shared-module/gifio/OnDiskGif.c
#: shared-module/videogif/GifDecoder.c
#: shared-module/_airlift/__init__.c
msgid "%q must be <= %d"
msgstr ""

Expand Down Expand Up @@ -4656,7 +4655,7 @@ msgid "Too many displays"
msgstr ""

#: shared-module/displayio/legacy/__init__.c
msgid "Too many display busses; forgot displayio.release_displays() ?"
msgid "Too many display buses; deinit() unused displays"
msgstr ""

#: shared-module/displayio/lvgl/Group.c
Expand Down
3 changes: 3 additions & 0 deletions ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ LONGINT_IMPL = MPZ

CIRCUITPY_BITBANG_APA102 = 1

CIRCUITPY_CODEOP = 0
CIRCUITPY_ERRNO = 0
CIRCUITPY_PULSEIO = 0
CIRCUITPY_RAINBOWIO = 0
2 changes: 2 additions & 0 deletions ports/atmel-samd/boards/qtpy_m0_haxpress/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ LONGINT_IMPL = MPZ
SPI_FLASH_FILESYSTEM = 1
EXTERNAL_FLASH_DEVICES = "GD25Q16C,W25Q16JVxQ,W25Q32FV"

CIRCUITPY_CODEOP = 0
CIRCUITPY_ERRNO = 0
CIRCUITPY_RAINBOWIO = 0
1 change: 1 addition & 0 deletions ports/atmel-samd/boards/snekboard/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ EXTERNAL_FLASH_DEVICES = "W25Q16JVxQ"
LONGINT_IMPL = MPZ

CIRCUITPY_CODEOP = 0
CIRCUITPY_ERRNO = 0
CIRCUITPY_RAINBOWIO = 0
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ USB_MANUFACTURER = "Switch Science, Inc."
MCU_CHIP = nrf52840

INTERNAL_FLASH_FILESYSTEM = 1

CIRCUITPY_CODEOP = 0
CIRCUITPY_RAINBOWIO = 0
3 changes: 3 additions & 0 deletions ports/nordic/boards/bluemicro840/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ USB_MANUFACTURER = "nrf52.jpconstantineau.com"
MCU_CHIP = nrf52840

INTERNAL_FLASH_FILESYSTEM = 1

CIRCUITPY_CODEOP = 0
CIRCUITPY_RAINBOWIO = 0
32 changes: 31 additions & 1 deletion ports/zephyr-cp/bindings/zephyr_display/Display.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#include "py/objproperty.h"
#include "py/objtype.h"
#include "py/runtime.h"
#include "shared-bindings/displayio/__init__.h"
#include "shared-bindings/displayio/Group.h"
#include "shared-bindings/util.h"
#include "shared-module/displayio/__init__.h"

//| class Display:
Expand Down Expand Up @@ -69,11 +71,38 @@ static mp_obj_t zephyr_display_display_make_new(const mp_obj_type_t *type,
return MP_OBJ_FROM_PTR(self);
}

// Helper to ensure we have the native super class instead of a subclass.
// Raises if the display has been released.
static zephyr_display_display_obj_t *native_display(mp_obj_t display_obj) {
mp_obj_t native = mp_obj_cast_to_native_base(display_obj, &zephyr_display_display_type);
if (native == MP_OBJ_NULL) {
raise_deinited_error();
}
mp_obj_assert_native_inited(native);
return MP_OBJ_TO_PTR(native);
zephyr_display_display_obj_t *self = MP_OBJ_TO_PTR(native);
if (self->base.type != &zephyr_display_display_type) {
raise_deinited_error();
}
return self;
}

//| def deinit(self) -> None:
//| """Release the display. A new `Display` can then be created.
//|
//| To release the display built during startup, use
//| ``supervisor.runtime.display.deinit()``.
//| As of CircuitPython 11.0.0, this replaces `displayio.release_displays()`, which is deprecated.
//| """
//| ...
//|
static mp_obj_t zephyr_display_display_obj_deinit(mp_obj_t self_in) {
mp_obj_t native = mp_obj_cast_to_native_base(self_in, &zephyr_display_display_type);
if (native != MP_OBJ_NULL) {
common_hal_displayio_deinit_display(native);
}
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(zephyr_display_display_deinit_obj, zephyr_display_display_obj_deinit);

static mp_obj_t zephyr_display_display_obj_show(mp_obj_t self_in, mp_obj_t group_in) {
(void)self_in;
Expand Down Expand Up @@ -267,6 +296,7 @@ MP_PROPERTY_GETSET(zephyr_display_display_root_group_obj,
(mp_obj_t)&zephyr_display_display_set_root_group_obj);

static const mp_rom_map_elem_t zephyr_display_display_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&zephyr_display_display_deinit_obj) },
{ MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(&zephyr_display_display_show_obj) },
{ MP_ROM_QSTR(MP_QSTR_refresh), MP_ROM_PTR(&zephyr_display_display_refresh_obj) },

Expand Down
32 changes: 31 additions & 1 deletion shared-bindings/busdisplay/BusDisplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "py/objproperty.h"
#include "py/objtype.h"
#include "py/runtime.h"
#include "shared-bindings/displayio/__init__.h"
#include "shared-bindings/displayio/Group.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/util.h"
Expand Down Expand Up @@ -227,11 +228,39 @@ static mp_obj_t busdisplay_busdisplay_make_new(const mp_obj_type_t *type, size_t
}

// Helper to ensure we have the native super class instead of a subclass.
// Raises if the display has been released.
static busdisplay_busdisplay_obj_t *native_display(mp_obj_t display_obj) {
mp_obj_t native_display = mp_obj_cast_to_native_base(display_obj, &busdisplay_busdisplay_type);
if (native_display == MP_OBJ_NULL) {
raise_deinited_error();
}
mp_obj_assert_native_inited(native_display);
return MP_OBJ_TO_PTR(native_display);
busdisplay_busdisplay_obj_t *self = MP_OBJ_TO_PTR(native_display);
if (self->base.type != &busdisplay_busdisplay_type) {
raise_deinited_error();
}
return self;
}

//| def deinit(self) -> None:
//| """Release the display and its display bus, so their pins can be used again.
//| The display bus is not released if another display still uses it.
//| A `busio.SPI` or `busio.I2C` object that you passed to the display bus is not deinitialized.
//|
//| To release a built-in display, or a display kept from an earlier run,
//| use ``supervisor.runtime.display.deinit()``.
//| As of CircuitPython 11.0.0, this replaces `displayio.release_displays()`, which is deprecated.
//| """
//| ...
//|
static mp_obj_t busdisplay_busdisplay_obj_deinit(mp_obj_t self_in) {
mp_obj_t native_display = mp_obj_cast_to_native_base(self_in, &busdisplay_busdisplay_type);
if (native_display != MP_OBJ_NULL) {
common_hal_displayio_deinit_display(native_display);
}
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(busdisplay_busdisplay_deinit_obj, busdisplay_busdisplay_obj_deinit);

// Undocumented show() implementation with a friendly error message.
static mp_obj_t busdisplay_busdisplay_obj_show(mp_obj_t self_in, mp_obj_t group_in) {
Expand Down Expand Up @@ -505,6 +534,7 @@ static mp_obj_t busdisplay_busdisplay_obj_fill_row(size_t n_args, const mp_obj_t
MP_DEFINE_CONST_FUN_OBJ_KW(busdisplay_busdisplay_fill_row_obj, 1, busdisplay_busdisplay_obj_fill_row);

static const mp_rom_map_elem_t busdisplay_busdisplay_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&busdisplay_busdisplay_deinit_obj) },
{ MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(&busdisplay_busdisplay_show_obj) },
{ MP_ROM_QSTR(MP_QSTR_refresh), MP_ROM_PTR(&busdisplay_busdisplay_refresh_obj) },
{ MP_ROM_QSTR(MP_QSTR_fill_row), MP_ROM_PTR(&busdisplay_busdisplay_fill_row_obj) },
Expand Down
5 changes: 5 additions & 0 deletions shared-bindings/displayio/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@
//| release the builtin display on boards that have one. You will need to reinitialize it yourself
//| afterwards. This may take seconds to complete if an active EPaperDisplay is refreshing.
//|
//| .. deprecated:: 11.0.0
//| Call ``deinit()`` on the display instead. To release a built-in display or a display
//| kept from an earlier run, use ``supervisor.runtime.display.deinit()``.
//| ``release_displays()`` will be removed in a future major release.
//|
//| Displays that are not `supervisor.runtime.display <supervisor.Runtime.display>` are released automatically when your code
//| finishes. Use this before initializing a display if one may still be active, such as a builtin
//| display or a display from an earlier run.
Expand Down
12 changes: 12 additions & 0 deletions shared-bindings/displayio/__init__.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ typedef enum displayio_colorspace {
} displayio_colorspace_t;

void common_hal_displayio_release_displays(void);

// Release one display and its bus.
//
// display is the native display object (not a Python subclass instance).
// - Does nothing if display is not an active display.
// - The bus is not released if another display still uses it.
// - If display is the primary display, the primary display is cleared
// and the terminal is stopped.
//
// Raises RuntimeError, with nothing released, if an EPaperDisplay using
// lag_frames can't get its bus.
void common_hal_displayio_deinit_display(mp_obj_t display);
mp_obj_t common_hal_displayio_get_primary_display(void);
void common_hal_displayio_set_primary_display(mp_obj_t o);
void common_hal_displayio_auto_primary_display(void);
Expand Down
4 changes: 2 additions & 2 deletions shared-bindings/dotclockframebuffer/DotClockFramebuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
//| """Create a DotClockFramebuffer object associated with the given pins.
//|
//| The pins are then in use by the display until your code finishes or
//| `displayio.release_displays()` is called. If the display is
//| the display's ``deinit()`` is called. If the display is
//| `supervisor.runtime.display <supervisor.Runtime.display>`, they stay in use after your code finishes, so CircuitPython can
//| use the display. In that case, check `supervisor.runtime.display <supervisor.Runtime.display>` before creating the display
//| again, or call :py:func:`displayio.release_displays` first.
//| again, or call ``supervisor.runtime.display.deinit()`` first.
//|
//| When a board has dedicated dot clock framebuffer pins and/or timings, they are intended to be used in the constructor with ``**`` dictionary unpacking like so:
//| ``DotClockFramebuffer(**board.TFT_PINS, **board.TFT_TIMINGS)``
Expand Down
36 changes: 35 additions & 1 deletion shared-bindings/epaperdisplay/EPaperDisplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "py/objproperty.h"
#include "py/objtype.h"
#include "py/runtime.h"
#include "shared-bindings/displayio/__init__.h"
#include "shared-bindings/displayio/Group.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/util.h"
Expand Down Expand Up @@ -364,11 +365,43 @@ static mp_obj_t epaperdisplay_epaperdisplay_make_new(const mp_obj_type_t *type,
}

// Helper to ensure we have the native super class instead of a subclass.
// Raises if the display has been released.
static epaperdisplay_epaperdisplay_obj_t *native_display(mp_obj_t display_obj) {
mp_obj_t native_display = mp_obj_cast_to_native_base(display_obj, &epaperdisplay_epaperdisplay_type);
if (native_display == MP_OBJ_NULL) {
raise_deinited_error();
}
mp_obj_assert_native_inited(native_display);
return MP_OBJ_TO_PTR(native_display);
epaperdisplay_epaperdisplay_obj_t *self = MP_OBJ_TO_PTR(native_display);
if (self->base.type != &epaperdisplay_epaperdisplay_type) {
raise_deinited_error();
}
return self;
}

//| def deinit(self) -> None:
//| """Release the display and its display bus, so their pins can be used again.
//| The display bus is not released if another display still uses it.
//| A `busio.SPI` or `busio.I2C` object that you passed to the display bus is not deinitialized.
//|
//| If a refresh is in progress, this waits for it to finish, which may take seconds.
//| If the display uses ``lag_frames`` and can't get its bus, this waits up to 30 seconds.
//| It then raises `RuntimeError` and leaves the display as it was.
//|
//| To release a built-in display, or a display kept from an earlier run,
//| use ``supervisor.runtime.display.deinit()``.
//| As of CircuitPython 11.0.0, this replaces `displayio.release_displays()`, which is deprecated.
//| """
//| ...
//|
static mp_obj_t epaperdisplay_epaperdisplay_obj_deinit(mp_obj_t self_in) {
mp_obj_t native_display = mp_obj_cast_to_native_base(self_in, &epaperdisplay_epaperdisplay_type);
if (native_display != MP_OBJ_NULL) {
common_hal_displayio_deinit_display(native_display);
}
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(epaperdisplay_epaperdisplay_deinit_obj, epaperdisplay_epaperdisplay_obj_deinit);

// Undocumented show() implementation with a friendly error message.
static mp_obj_t epaperdisplay_epaperdisplay_obj_show(mp_obj_t self_in, mp_obj_t group_in) {
Expand Down Expand Up @@ -610,6 +643,7 @@ MP_PROPERTY_GETSET(epaperdisplay_epaperdisplay_root_group_obj,
(mp_obj_t)&epaperdisplay_epaperdisplay_set_root_group_obj);

static const mp_rom_map_elem_t epaperdisplay_epaperdisplay_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&epaperdisplay_epaperdisplay_deinit_obj) },
{ MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(&epaperdisplay_epaperdisplay_show_obj) },
{ MP_ROM_QSTR(MP_QSTR_update_refresh_mode), MP_ROM_PTR(&epaperdisplay_epaperdisplay_update_refresh_mode_obj) },
{ MP_ROM_QSTR(MP_QSTR_refresh), MP_ROM_PTR(&epaperdisplay_epaperdisplay_refresh_obj) },
Expand Down
4 changes: 2 additions & 2 deletions shared-bindings/fourwire/FourWire.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
//| """Create a FourWire object associated with the given pins.
//|
//| The SPI bus and pins are then in use by the display until your code finishes or
//| `displayio.release_displays()` is called. If the display is
//| the display's ``deinit()`` is called. If the display is
//| `supervisor.runtime.display <supervisor.Runtime.display>`, they stay in use after your code finishes, so CircuitPython can
//| use the display. In that case, check `supervisor.runtime.display <supervisor.Runtime.display>` before creating the display
//| again, or call :py:func:`displayio.release_displays` first.
//| again, or call ``supervisor.runtime.display.deinit()`` first.
//|
//| If the ``command`` pin is not specified, a 9-bit SPI mode will be simulated by adding a
//| data/command bit to every bit being transmitted, and splitting the resulting data back
Expand Down
30 changes: 29 additions & 1 deletion shared-bindings/framebufferio/FramebufferDisplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "py/objtype.h"
#include "py/proto.h"
#include "py/runtime.h"
#include "shared-bindings/displayio/__init__.h"
#include "shared-bindings/displayio/Group.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/util.h"
Expand Down Expand Up @@ -95,11 +96,37 @@ static mp_obj_t framebufferio_framebufferdisplay_make_new(const mp_obj_type_t *t
}

// Helper to ensure we have the native super class instead of a subclass.
// Raises if the display has been released.
static framebufferio_framebufferdisplay_obj_t *native_display(mp_obj_t display_obj) {
mp_obj_t native_display = mp_obj_cast_to_native_base(display_obj, &framebufferio_framebufferdisplay_type);
if (native_display == MP_OBJ_NULL) {
raise_deinited_error();
}
mp_obj_assert_native_inited(native_display);
return MP_OBJ_TO_PTR(native_display);
framebufferio_framebufferdisplay_obj_t *self = MP_OBJ_TO_PTR(native_display);
if (self->base.type != &framebufferio_framebufferdisplay_type) {
raise_deinited_error();
}
return self;
}

//| def deinit(self) -> None:
//| """Release the display and deinitialize its framebuffer, so their pins can be used again.
//|
//| To release a built-in display, or a display kept from an earlier run,
//| use ``supervisor.runtime.display.deinit()``.
//| As of CircuitPython 11.0.0, this replaces `displayio.release_displays()`, which is deprecated.
//| """
//| ...
//|
static mp_obj_t framebufferio_framebufferdisplay_obj_deinit(mp_obj_t self_in) {
mp_obj_t native_display = mp_obj_cast_to_native_base(self_in, &framebufferio_framebufferdisplay_type);
if (native_display != MP_OBJ_NULL) {
common_hal_displayio_deinit_display(native_display);
}
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(framebufferio_framebufferdisplay_deinit_obj, framebufferio_framebufferdisplay_obj_deinit);

// Undocumented show() implementation with a friendly error message.
static mp_obj_t framebufferio_framebufferdisplay_obj_show(mp_obj_t self_in, mp_obj_t group_in) {
Expand Down Expand Up @@ -378,6 +405,7 @@ MP_PROPERTY_GETSET(framebufferio_framebufferdisplay_root_group_obj,
(mp_obj_t)&framebufferio_framebufferdisplay_set_root_group_obj);

static const mp_rom_map_elem_t framebufferio_framebufferdisplay_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&framebufferio_framebufferdisplay_deinit_obj) },
{ 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) },
Expand Down
4 changes: 2 additions & 2 deletions shared-bindings/i2cdisplaybus/I2CDisplayBus.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
//| """Create a I2CDisplayBus object associated with the given I2C bus and reset pin.
//|
//| The I2C bus and pins are then in use by the display until your code finishes or
//| `displayio.release_displays()` is called. If the display is
//| the display's ``deinit()`` is called. If the display is
//| `supervisor.runtime.display <supervisor.Runtime.display>`, they stay in use after your code finishes, so CircuitPython can
//| use the display. In that case, check `supervisor.runtime.display <supervisor.Runtime.display>` before creating the display
//| again, or call :py:func:`displayio.release_displays` first.
//| again, or call ``supervisor.runtime.display.deinit()`` first.
//|
//| :param busio.I2C i2c_bus: The I2C bus that make up the clock and data lines
//| :param int device_address: The I2C address of the device
Expand Down
4 changes: 2 additions & 2 deletions shared-bindings/paralleldisplaybus/ParallelBus.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
//| by implying the next 7 additional pins on a given GPIO port.
//|
//| The parallel bus and pins are then in use by the display until your code finishes or
//| `displayio.release_displays()` is called. If the display is
//| the display's ``deinit()`` is called. If the display is
//| `supervisor.runtime.display <supervisor.Runtime.display>`, they stay in use after your code finishes, so CircuitPython can
//| use the display. In that case, check `supervisor.runtime.display <supervisor.Runtime.display>` before creating the display
//| again, or call :py:func:`displayio.release_displays` first.
//| again, or call ``supervisor.runtime.display.deinit()`` first.
//|
//| :param microcontroller.Pin data_pins: A list of data pins. Specify exactly one of ``data_pins`` or ``data0``.
//| :param microcontroller.Pin data0: The first data pin. The rest are implied
Expand Down
5 changes: 3 additions & 2 deletions shared-bindings/qspibus/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
//|
//| import board
//| import qspibus
//| import displayio
//| import supervisor
//|
//| displayio.release_displays()
//| if supervisor.runtime.display:
//| supervisor.runtime.display.deinit()
//|
//| bus = qspibus.QSPIBus(
//| clock=board.LCD_CLK,
Expand Down
Loading
Loading