Skip to content

Commit 8eaa0aa

Browse files
committed
Fix ctrl-D safemode (Thanks to tannewt's CP10 comment)
1 parent 5b4f70d commit 8eaa0aa

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

shared-bindings/fourwire/FourWire.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ static mp_obj_t fourwire_fourwire_make_new(const mp_obj_type_t *type, size_t n_a
6969
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
7070
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
7171

72-
const mcu_pin_obj_t *command = validate_obj_is_free_pin_or_none(args[ARG_command].u_obj, MP_QSTR_command);
72+
// const mcu_pin_obj_t *command = validate_obj_is_free_pin_or_none(args[ARG_command].u_obj, MP_QSTR_command);
73+
const mcu_pin_obj_t *command = validate_obj_is_pin_or_none(args[ARG_command].u_obj, MP_QSTR_command);
7374
const mcu_pin_obj_t *chip_select = validate_obj_is_free_pin_or_none(args[ARG_chip_select].u_obj, MP_QSTR_chip_select);
7475
const mcu_pin_obj_t *reset = validate_obj_is_free_pin_or_none(args[ARG_reset].u_obj, MP_QSTR_reset);
7576

shared-module/displayio/__init__.c

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ static void common_hal_displayio_release_displays_impl(bool keep_primary) {
139139
if (!keep_primary) {
140140
primary_display_number = -1;
141141
}
142-
for (uint8_t i = 0; i < max_num_displays; i++) {
142+
for (uint8_t i = (keep_primary ? CIRCUITPY_DISPLAY_LIMIT: 0); i < max_num_displays; i++) {
143143
if (i == primary_display_number) {
144144
continue;
145145
}
@@ -169,7 +169,10 @@ static void common_hal_displayio_release_displays_impl(bool keep_primary) {
169169
displays[i].display_base.type = &mp_type_NoneType;
170170
#endif
171171
}
172-
for (uint8_t i = 0; i < max_num_displays; i++) {
172+
for (uint8_t i = (keep_primary ? CIRCUITPY_DISPLAY_LIMIT: 0); i < max_num_displays; i++) {
173+
if (i == primary_display_number) {
174+
continue;
175+
}
173176
mp_const_obj_t bus_type = DYN_DISPLAY_BUSES(i).bus_base.type;
174177
if (bus_type == NULL || bus_type == &mp_type_NoneType) {
175178
continue;
@@ -221,7 +224,9 @@ static void common_hal_displayio_release_displays_impl(bool keep_primary) {
221224
#endif
222225
}
223226

224-
supervisor_stop_terminal();
227+
if (!keep_primary) {
228+
supervisor_stop_terminal();
229+
}
225230
}
226231

227232
void common_hal_displayio_release_displays(void) {
@@ -247,18 +252,18 @@ void malloc_display_memory(void) {
247252

248253
void reset_displays(void) {
249254
// In CircuitPython 10, release secondary displays before doing anything else:
250-
// common_hal_displayio_release_displays_impl(true);
255+
common_hal_displayio_release_displays_impl(true);
251256

252257
// The SPI buses used by FourWires may be allocated on the heap so we need to move them inline.
253-
for (uint8_t i = 0; i < max_num_displays; i++) {
254-
mp_const_obj_t display_bus_type = DYN_DISPLAY_BUSES(i).bus_base.type;
258+
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
259+
mp_const_obj_t display_bus_type = display_buses[i].bus_base.type;
255260
if (display_bus_type == NULL || display_bus_type == &mp_type_NoneType) {
256261
continue;
257262
#if CIRCUITPY_FOURWIRE
258263
} else if (display_bus_type == &fourwire_fourwire_type) {
259-
fourwire_fourwire_obj_t *fourwire = DYN_DISPLAY_BUSES_ADR(i, fourwire_bus);
264+
fourwire_fourwire_obj_t *fourwire = &display_buses[i].fourwire_bus;
260265
if (((size_t)fourwire->bus) < ((size_t)&display_buses) ||
261-
((size_t)fourwire->bus) > ((size_t)&display_buses + max_num_displays * sizeof(primary_display_bus_t))) {
266+
((size_t)fourwire->bus) > ((size_t)&display_buses + CIRCUITPY_DISPLAY_LIMIT * sizeof(primary_display_bus_t))) {
262267
busio_spi_obj_t *original_spi = fourwire->bus;
263268
#if CIRCUITPY_BOARD_SPI
264269
// We don't need to move original_spi if it is a board.SPI object because it is
@@ -276,7 +281,7 @@ void reset_displays(void) {
276281
memcpy(&fourwire->inline_bus, original_spi, sizeof(busio_spi_obj_t));
277282
fourwire->bus = &fourwire->inline_bus;
278283
// Check for other display buses that use the same spi bus and swap them too.
279-
for (uint8_t j = i + 1; j < max_num_displays; j++) {
284+
for (uint8_t j = i + 1; j < CIRCUITPY_DISPLAY_LIMIT; j++) {
280285
if (display_buses[j].fourwire_bus.base.type == &fourwire_fourwire_type &&
281286
display_buses[j].fourwire_bus.bus == original_spi) {
282287
display_buses[j].fourwire_bus.bus = &fourwire->inline_bus;
@@ -286,10 +291,10 @@ void reset_displays(void) {
286291
#endif
287292
#if CIRCUITPY_I2CDISPLAYBUS
288293
} else if (display_bus_type == &i2cdisplaybus_i2cdisplaybus_type) {
289-
i2cdisplaybus_i2cdisplaybus_obj_t *i2c = DYN_DISPLAY_BUSES_ADR(i, i2cdisplay_bus);
294+
i2cdisplaybus_i2cdisplaybus_obj_t *i2c = &display_buses[i].i2cdisplay_bus;
290295
// Check to see if we need to inline the I2C bus.
291296
if (((size_t)i2c->bus) < ((size_t)&display_buses) ||
292-
((size_t)i2c->bus) > ((size_t)&display_buses + max_num_displays * sizeof(primary_display_bus_t))) {
297+
((size_t)i2c->bus) > ((size_t)&display_buses + CIRCUITPY_DISPLAY_LIMIT * sizeof(primary_display_bus_t))) {
293298
busio_i2c_obj_t *original_i2c = i2c->bus;
294299
#if CIRCUITPY_BOARD_I2C
295300
// We don't need to move original_i2c if it is a board.I2C object because it is
@@ -302,7 +307,7 @@ void reset_displays(void) {
302307
memcpy(&i2c->inline_bus, original_i2c, sizeof(busio_i2c_obj_t));
303308
i2c->bus = &i2c->inline_bus;
304309
// Check for other displays that use the same i2c bus and swap them too.
305-
for (uint8_t j = i + 1; j < max_num_displays; j++) {
310+
for (uint8_t j = i + 1; j < CIRCUITPY_DISPLAY_LIMIT; j++) {
306311
if (display_buses[j].i2cdisplay_bus.base.type == &i2cdisplaybus_i2cdisplaybus_type &&
307312
display_buses[j].i2cdisplay_bus.bus == original_i2c) {
308313
display_buses[j].i2cdisplay_bus.bus = &i2c->inline_bus;
@@ -314,7 +319,7 @@ void reset_displays(void) {
314319
#endif
315320
#if CIRCUITPY_RGBMATRIX
316321
} else if (display_bus_type == &rgbmatrix_RGBMatrix_type) {
317-
rgbmatrix_rgbmatrix_obj_t *pm = DYN_DISPLAY_BUSES_ADR(i, rgbmatrix);
322+
rgbmatrix_rgbmatrix_obj_t *pm = &display_buses[i].rgbmatrix;
318323
if (!any_display_uses_this_framebuffer(&pm->base)) {
319324
common_hal_rgbmatrix_rgbmatrix_deinit(pm);
320325
} else {
@@ -323,10 +328,10 @@ void reset_displays(void) {
323328
#endif
324329
#if CIRCUITPY_IS31FL3741
325330
} else if (display_bus_type == &is31fl3741_framebuffer_type) {
326-
is31fl3741_framebuffer_obj_t *is31fb = DYN_DISPLAY_BUSES_ADR(i, is31fl3741);
331+
is31fl3741_framebuffer_obj_t *is31fb = &display_buses[i].is31fl3741;
327332

328333
if (((uint32_t)is31fb->is31fl3741->i2c) < ((uint32_t)&display_buses) ||
329-
((uint32_t)is31fb->is31fl3741->i2c) > ((uint32_t)&display_buses + max_num_displays)) {
334+
((uint32_t)is31fb->is31fl3741->i2c) > ((uint32_t)&display_buses + CIRCUITPY_DISPLAY_LIMIT)) {
330335
#if CIRCUITPY_BOARD_I2C
331336
// We don't need to move original_i2c if it is the board.I2C object because it is
332337
// statically allocated already. (Doing so would also make it impossible to reference in
@@ -353,12 +358,12 @@ void reset_displays(void) {
353358
#endif
354359
#if CIRCUITPY_SHARPDISPLAY
355360
} else if (display_bus_type == &sharpdisplay_framebuffer_type) {
356-
sharpdisplay_framebuffer_obj_t *sharp = DYN_DISPLAY_BUSES_ADR(i, sharpdisplay);
361+
sharpdisplay_framebuffer_obj_t *sharp = &display_buses[i].sharpdisplay;
357362
common_hal_sharpdisplay_framebuffer_reset(sharp);
358363
#endif
359364
#if CIRCUITPY_VIDEOCORE
360365
} else if (display_bus_type == &videocore_framebuffer_type) {
361-
videocore_framebuffer_obj_t *vc = DYN_DISPLAY_BUSES_ADR(i, videocore);
366+
videocore_framebuffer_obj_t *vc = &display_buses[i].videocore;
362367
if (!any_display_uses_this_framebuffer(&vc->base)) {
363368
common_hal_videocore_framebuffer_deinit(vc);
364369
}
@@ -367,46 +372,46 @@ void reset_displays(void) {
367372
#endif
368373
#if CIRCUITPY_PICODVI
369374
} else if (display_bus_type == &picodvi_framebuffer_type) {
370-
picodvi_framebuffer_obj_t *vc = DYN_DISPLAY_BUSES_ADR(i, picodvi);
375+
picodvi_framebuffer_obj_t *vc = &display_buses[i].picodvi;
371376
if (!any_display_uses_this_framebuffer(&vc->base)) {
372377
common_hal_picodvi_framebuffer_deinit(vc);
373378
}
374379
#endif
375380
#if CIRCUITPY_AURORA_EPAPER
376381
} else if (display_bus_type == &aurora_framebuffer_type) {
377382
#if CIRCUITPY_BOARD_SPI
378-
aurora_epaper_framebuffer_obj_t *aurora = DYN_DISPLAY_BUSES_ADR(i, aurora_epaper);
383+
aurora_epaper_framebuffer_obj_t *aurora = &display_buses[i].aurora_epaper;
379384
if (common_hal_board_is_spi(aurora->bus)) {
380385
common_hal_aurora_epaper_framebuffer_set_free_bus(false);
381386
}
382387
#endif
383388
// Set to None, gets deinit'd up by display_base
384-
DYN_DISPLAY_BUSES(i).bus_base.type = &mp_type_NoneType;
389+
display_buses[i].bus_base.type = &mp_type_NoneType;
385390
#endif
386391
} else {
387392
// Not an active display bus.
388393
continue;
389394
}
390395
}
391396

392-
for (uint8_t i = 0; i < max_num_displays; i++) {
397+
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
393398
// Reset the displayed group. Only the first will get the terminal but
394399
// that's ok.
395-
mp_const_obj_t display_type = DYN_DISPLAYS(i).display_base.type;
400+
mp_const_obj_t display_type = displays[i].display_base.type;
396401
if (display_type == NULL || display_type == &mp_type_NoneType) {
397402
continue;
398403
#if CIRCUITPY_BUSDISPLAY
399404
} else if (display_type == &busdisplay_busdisplay_type) {
400-
reset_busdisplay(DYN_DISPLAYS_ADR(i, display));
405+
reset_busdisplay(&displays[i].display);
401406
#endif
402407
#if CIRCUITPY_EPAPERDISPLAY
403408
} else if (display_type == &epaperdisplay_epaperdisplay_type) {
404-
epaperdisplay_epaperdisplay_obj_t *display = DYN_DISPLAYS_ADR(i, epaper_display);
409+
epaperdisplay_epaperdisplay_obj_t *display = &displays[i].epaper_display;
405410
epaperdisplay_epaperdisplay_reset(display);
406411
#endif
407412
#if CIRCUITPY_FRAMEBUFFERIO
408413
} else if (display_type == &framebufferio_framebufferdisplay_type) {
409-
framebufferio_framebufferdisplay_reset(DYN_DISPLAYS_ADR(i, framebuffer_display));
414+
framebufferio_framebufferdisplay_reset(&displays[i].framebuffer_display);
410415
#endif
411416
}
412417
}

0 commit comments

Comments
 (0)