Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
27 changes: 14 additions & 13 deletions locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ msgstr ""
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
#: ports/stm/common-hal/pulseio/PulseIn.c py/argcheck.c
#: shared-bindings/bitmaptools/__init__.c shared-bindings/canio/Match.c
#: shared-bindings/time/__init__.c
#: shared-bindings/time/__init__.c shared-module/displayio/lvgl/Group.c
msgid "%q out of range"
msgstr ""

Expand Down Expand Up @@ -1745,10 +1745,9 @@ msgstr ""
#: ports/raspberrypi/common-hal/usb_host/Port.c
#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/emmcio/EMMC.c
#: shared-bindings/i2cioexpander/IOPin.c shared-bindings/microcontroller/Pin.c
#: shared-module/_airlift/__init__.c
#: shared-module/epaperdisplay/EPaperDisplay.c
#: shared-module/max3421e/Max3421E.c shared-module/usb/core/Device.c
#: shared-module/usb_host_audio/USBIn.c
#: shared-module/_airlift/__init__.c shared-module/audiotap/LevelReader.c
#: shared-module/epaperdisplay/epaper_core.c shared-module/max3421e/Max3421E.c
#: shared-module/usb/core/Device.c shared-module/usb_host_audio/USBIn.c
msgid "%q in use"
msgstr ""

Expand Down Expand Up @@ -2051,8 +2050,8 @@ msgstr ""
#: shared-bindings/bitmapfilter/__init__.c shared-bindings/canio/CAN.c
#: shared-bindings/digitalio/Pull.c shared-bindings/picogame/Sprite.c
#: shared-bindings/supervisor/__init__.c shared-module/audiofilters/__init__.c
#: shared-module/displayio/legacy/__init__.c
#: shared-module/synthio/Synthesizer.c shared-module/videocore/VideoBuffer.c
#: shared-module/displayio/lifetime.c shared-module/synthio/Synthesizer.c
#: shared-module/videocore/VideoBuffer.c
msgid "%q must be of type %q or %q, not %q"
msgstr ""

Expand Down Expand Up @@ -4601,12 +4600,18 @@ msgstr ""
msgid "unsupported bitmap depth"
msgstr ""

#: shared-module/busdisplay/__init__.c
msgid "%q must be a DigitalInOut, PWMOut or None"
msgstr ""

#: shared-module/busdisplay/lvgl/BusDisplay.c
#: shared-module/epaperdisplay/lvgl/EPaperDisplay.c
#: shared-module/framebufferio/lvgl/FramebufferDisplay.c
msgid "LVGL display create failed"
msgstr ""

#: shared-module/busdisplay/lvgl/BusDisplay.c
#: shared-module/epaperdisplay/lvgl/EPaperDisplay.c
#: shared-module/framebufferio/lvgl/FramebufferDisplay.c
msgid "LVGL buffer alloc failed"
msgstr ""
Expand Down Expand Up @@ -4654,12 +4659,8 @@ msgstr ""
msgid "Unable to read color palette data"
msgstr ""

#: shared-module/displayio/legacy/__init__.c
msgid "Too many displays"
msgstr ""

#: shared-module/displayio/legacy/__init__.c
msgid "Too many display buses; deinit() unused displays"
#: shared-module/displayio/lifetime.c
msgid "expected %q"
msgstr ""

#: shared-module/displayio/lvgl/Group.c
Expand Down
28 changes: 9 additions & 19 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ static void start_mp(safe_mode_t safe_mode) {
common_hal_os_chdir("/");

_vm_is_running = true;
#if CIRCUITPY_DISPLAYIO
displayio_start_vm();
#endif
}

static void stop_mp(void) {
Expand Down Expand Up @@ -351,9 +354,6 @@ static void count_strn(void *data, const char *str, size_t len) {
}

static void cleanup_after_vm(mp_obj_t exception) {
// Do any port cleanup needed before anything else, including releasing board buses.
reset_port_early();

// Get the traceback of any exception from this run off the heap.
// MP_OBJ_SENTINEL means "this run does not contribute to traceback storage, don't touch it"
// MP_OBJ_NULL (=0) means "this run completed successfully, clear any stored traceback"
Expand Down Expand Up @@ -398,9 +398,9 @@ static void cleanup_after_vm(mp_obj_t exception) {
videogif_reset();
#endif

// Turn off the display and flush the filesystem before the heap disappears.
// Release or preserve displays while their drivers and the VM still exist.
#if CIRCUITPY_DISPLAYIO
reset_displays();
displayio_stop_vm();
#endif

#if CIRCUITPY_MEMORYMONITOR
Expand Down Expand Up @@ -445,10 +445,8 @@ static void cleanup_after_vm(mp_obj_t exception) {
reset_port();
reset_board();

// Free the heap last because other modules may reference heap memory and need to shut down.
// Free the heap last because other modules may reference heap memory.
filesystem_flush();

// Runs finalisers while shutting down the heap.
stop_mp();

// Let the workflows know we've reset in case they want to restart.
Expand Down Expand Up @@ -708,10 +706,9 @@ static bool __attribute__((noinline)) run_code_py(safe_mode_t safe_mode, bool *s
// OK to start sleeping, real or fake.
const bool true_deep_sleep = awoke_from_true_deep_sleep || !supervisor_workflow_active();
#if CIRCUITPY_DISPLAYIO
// A fake sleep doesn't run boot.py again, so keep a display set as
// supervisor.runtime.display. Also leave the board as a reload does, because
// board_init() can't make its own display if the kept one fills the slots.
keep_display_in_fake_sleep = !true_deep_sleep && common_hal_displayio_primary_display_set_by_user();
// A fake sleep doesn't run boot.py again, so preserve a user-selected
// display and leave the board initialized, as on soft reload.
keep_display_in_fake_sleep = !true_deep_sleep && common_hal_supervisor_runtime_display_set_by_user();
if (!keep_display_in_fake_sleep) {
common_hal_displayio_release_displays();
}
Expand Down Expand Up @@ -832,9 +829,6 @@ static bool __attribute__((noinline)) run_code_py(safe_mode_t safe_mode, bool *s
if (fake_sleeping) {
if (!keep_display_in_fake_sleep) {
board_init();
#if CIRCUITPY_DISPLAYIO
common_hal_displayio_auto_primary_display();
#endif
}
// Undo any preserve_dios.
#if CIRCUITPY_ALARM_PRESERVE_DIOS
Expand Down Expand Up @@ -1140,10 +1134,6 @@ int __attribute__((used)) main(void) {
// displays init after filesystem, since they could share the flash SPI
board_init();

#if CIRCUITPY_DISPLAYIO
common_hal_displayio_auto_primary_display();
#endif

mp_hal_stdout_tx_str(line_clear);

// This is first time we are running CircuitPython after a reset or power-up.
Expand Down
13 changes: 13 additions & 0 deletions ports/analog/common-hal/busio/I2C.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ bool common_hal_busio_i2c_deinited(busio_i2c_obj_t *self) {
return self->sda == NULL;
}

bool common_hal_busio_i2c_is_moveable(busio_i2c_obj_t *self) {
return !common_hal_busio_i2c_deinited(self) && !self->has_lock;
}

bool common_hal_busio_i2c_move(busio_i2c_obj_t *self, busio_i2c_obj_t *destination) {
if (!common_hal_busio_i2c_is_moveable(self)) {
return false;
}
*destination = *self;
self->sda = NULL;
return true;
}

// Deinit i2c obj, reset I2C pin
void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {
MXC_I2C_Shutdown(self->i2c_regs);
Expand Down
2 changes: 1 addition & 1 deletion ports/analog/common-hal/busio/I2C.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ typedef struct {
mxc_i2c_regs_t *i2c_regs;
const mcu_pin_obj_t *scl;
const mcu_pin_obj_t *sda;
const int frequency;
uint32_t frequency;

uint32_t timeout;
bool has_lock;
Expand Down
13 changes: 13 additions & 0 deletions ports/analog/common-hal/busio/SPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ void common_hal_busio_spi_mark_deinit(busio_spi_obj_t *self) {
self->sck = NULL;
}

bool common_hal_busio_spi_is_moveable(busio_spi_obj_t *self) {
return !common_hal_busio_spi_deinited(self) && !self->has_lock;
}

bool common_hal_busio_spi_move(busio_spi_obj_t *self, busio_spi_obj_t *destination) {
if (!common_hal_busio_spi_is_moveable(self)) {
return false;
}
*destination = *self;
common_hal_busio_spi_mark_deinit(self);
return true;
}

// Deinit SPI obj
void common_hal_busio_spi_deinit(busio_spi_obj_t *self) {

Expand Down
13 changes: 13 additions & 0 deletions ports/analog/common-hal/digitalio/DigitalInOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t *se
return self->pin == NULL;
}

bool common_hal_digitalio_digitalinout_is_moveable(digitalio_digitalinout_obj_t *self) {
return !common_hal_digitalio_digitalinout_deinited(self);
}

bool common_hal_digitalio_digitalinout_move(digitalio_digitalinout_obj_t *self, digitalio_digitalinout_obj_t *destination) {
if (!common_hal_digitalio_digitalinout_is_moveable(self)) {
return false;
}
*destination = *self;
self->pin = NULL;
return true;
}

digitalinout_result_t common_hal_digitalio_digitalinout_construct(
digitalio_digitalinout_obj_t *self, const mcu_pin_obj_t *pin) {

Expand Down
16 changes: 14 additions & 2 deletions ports/atmel-samd/boards/hallowing_m0_express/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,14 @@ uint8_t display_init_sequence[] = {
0x29, 0 | DELAY, 100, // _DISPON
};

static fourwire_fourwire_obj_t display_bus;
busdisplay_busdisplay_obj_t board_display;

void board_init(void) {
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
fourwire_fourwire_obj_t *bus = displayio_native_init(&display_bus, &fourwire_fourwire_type, 0, MP_OBJ_NULL, true);
if (bus == NULL) {
return;
}
bus->base.type = &fourwire_fourwire_type;
busio_spi_obj_t *spi = common_hal_board_create_spi(0);
common_hal_fourwire_fourwire_construct(bus,
Expand All @@ -60,7 +66,12 @@ void board_init(void) {
0, // Polarity
0); // Phase

busdisplay_busdisplay_obj_t *display = &allocate_display()->display;
busdisplay_busdisplay_obj_t *display = displayio_native_init(
&board_display, &busdisplay_busdisplay_type, 0, MP_OBJ_FROM_PTR(bus), true);

if (display == NULL) {
return;
}
display->base.type = &busdisplay_busdisplay_type;
common_hal_busdisplay_busdisplay_construct(display,
bus,
Expand Down Expand Up @@ -90,6 +101,7 @@ void board_init(void) {
true, // backlight_on_high
false, // not SH1107
50000); // backlight pwm frequency
common_hal_supervisor_runtime_set_display(MP_OBJ_FROM_PTR(display), false);
}

// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
11 changes: 11 additions & 0 deletions ports/atmel-samd/boards/hallowing_m0_express/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This file is part of the CircuitPython project: https://circuitpython.org
//
// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
//
// SPDX-License-Identifier: MIT

#pragma once

#include "shared-module/busdisplay/BusDisplay.h"

extern busdisplay_busdisplay_obj_t board_display;
4 changes: 3 additions & 1 deletion ports/atmel-samd/boards/hallowing_m0_express/pins.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "shared-bindings/board/__init__.h"

#include "board.h"

#include "supervisor/board.h"
#include "shared-module/displayio/__init__.h"

Expand Down Expand Up @@ -73,6 +75,6 @@ static const mp_rom_map_elem_t board_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },

{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)}
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&board_display) },
};
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
15 changes: 13 additions & 2 deletions ports/atmel-samd/boards/hallowing_m4_express/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ uint8_t display_init_sequence[] = {
0x29, 0 | DELAY, 255, // _DISPON
};

static fourwire_fourwire_obj_t board_display_bus;
busdisplay_busdisplay_obj_t board_display;

void board_init(void) {
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
fourwire_fourwire_obj_t *bus = displayio_native_init(&board_display_bus, &fourwire_fourwire_type, 0, MP_OBJ_NULL, true);
if (bus == NULL) {
return;
}
busio_spi_obj_t *spi = &bus->inline_bus;
common_hal_busio_spi_construct(spi, &pin_PA01, &pin_PA00, NULL, false);

Expand All @@ -41,7 +47,11 @@ void board_init(void) {
0, // Polarity
0); // Phase

busdisplay_busdisplay_obj_t *display = &allocate_display()->display;
busdisplay_busdisplay_obj_t *display = displayio_native_init(&board_display, &busdisplay_busdisplay_type, 0, MP_OBJ_FROM_PTR(bus), true);

if (display == NULL) {
return;
}
display->base.type = &busdisplay_busdisplay_type;
common_hal_busdisplay_busdisplay_construct(display,
bus,
Expand Down Expand Up @@ -71,6 +81,7 @@ void board_init(void) {
true, // backlight_on_high
false, // not SH1107
50000); // backlight pwm frequency
common_hal_supervisor_runtime_set_display(MP_OBJ_FROM_PTR(display), false);
}

// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
11 changes: 11 additions & 0 deletions ports/atmel-samd/boards/hallowing_m4_express/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This file is part of the CircuitPython project: https://circuitpython.org
//
// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
//
// SPDX-License-Identifier: MIT

#pragma once

#include "shared-module/busdisplay/BusDisplay.h"

extern busdisplay_busdisplay_obj_t board_display;
4 changes: 3 additions & 1 deletion ports/atmel-samd/boards/hallowing_m4_express/pins.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "shared-bindings/board/__init__.h"

#include "board.h"

#include "shared-module/displayio/__init__.h"

static const mp_rom_map_elem_t board_module_globals_table[] = {
Expand Down Expand Up @@ -77,6 +79,6 @@ static const mp_rom_map_elem_t board_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },

{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)}
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&board_display) },
};
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
Loading
Loading