Skip to content

Commit 5660599

Browse files
Kevin MatochaKevin Matocha
Kevin Matocha
authored and
Kevin Matocha
committed
add a root_group property to the display, reset the REPL position when display.show(None) is called.
1 parent db0140f commit 5660599

File tree

26 files changed

+138
-105
lines changed

26 files changed

+138
-105
lines changed

shared-bindings/displayio/Display.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,23 @@ const mp_obj_property_t displayio_display_bus_obj = {
444444
MP_ROM_NONE},
445445
};
446446

447+
//| root_group: _Group
448+
//| """The root group on the display."""
449+
//|
450+
//|
451+
STATIC mp_obj_t displayio_display_obj_get_root_group(mp_obj_t self_in) {
452+
displayio_display_obj_t *self = native_display(self_in);
453+
return common_hal_displayio_display_get_root_group(self);
454+
}
455+
MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_root_group_obj, displayio_display_obj_get_root_group);
456+
457+
const mp_obj_property_t displayio_display_root_group_obj = {
458+
.base.type = &mp_type_property,
459+
.proxy = {(mp_obj_t)&displayio_display_get_root_group_obj,
460+
MP_ROM_NONE,
461+
MP_ROM_NONE},
462+
};
463+
447464

448465
//| def fill_row(self, y: int, buffer: WriteableBuffer) -> WriteableBuffer:
449466
//| """Extract the pixels from a single row
@@ -517,6 +534,7 @@ STATIC const mp_rom_map_elem_t displayio_display_locals_dict_table[] = {
517534
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&displayio_display_height_obj) },
518535
{ MP_ROM_QSTR(MP_QSTR_rotation), MP_ROM_PTR(&displayio_display_rotation_obj) },
519536
{ MP_ROM_QSTR(MP_QSTR_bus), MP_ROM_PTR(&displayio_display_bus_obj) },
537+
{ MP_ROM_QSTR(MP_QSTR_root_group), MP_ROM_PTR(&displayio_display_root_group_obj) },
520538
};
521539
STATIC MP_DEFINE_CONST_DICT(displayio_display_locals_dict, displayio_display_locals_dict_table);
522540

shared-bindings/displayio/Display.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ mp_float_t common_hal_displayio_display_get_brightness(displayio_display_obj_t *
6969
bool common_hal_displayio_display_set_brightness(displayio_display_obj_t *self, mp_float_t brightness);
7070

7171
mp_obj_t common_hal_displayio_display_get_bus(displayio_display_obj_t *self);
72-
72+
mp_obj_t common_hal_displayio_display_get_root_group(displayio_display_obj_t *self);
7373

7474
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_DISPLAY_H

shared-bindings/supervisor/__init__.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ STATIC const mp_rom_map_elem_t supervisor_module_globals_table[] = {
324324
{ MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&supervisor_ticks_ms_obj) },
325325
{ MP_ROM_QSTR(MP_QSTR_get_previous_traceback), MP_ROM_PTR(&supervisor_get_previous_traceback_obj) },
326326
{ MP_ROM_QSTR(MP_QSTR_disable_ble_workflow), MP_ROM_PTR(&supervisor_disable_ble_workflow_obj) },
327-
{ MP_ROM_QSTR(MP_QSTR_splash), MP_ROM_PTR(&circuitpython_splash) },
328327
{ MP_ROM_QSTR(MP_QSTR_reset_terminal), MP_ROM_PTR(&supervisor_reset_terminal_obj) },
329328
};
330329

shared-module/board/__init__.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ typedef struct {
5757

5858
static const board_i2c_pin_t i2c_pin[CIRCUITPY_BOARD_I2C] = CIRCUITPY_BOARD_I2C_PIN;
5959
static busio_i2c_obj_t i2c_obj[CIRCUITPY_BOARD_I2C];
60+
static bool i2c_obj_created[CIRCUITPY_BOARD_I2C];
6061

6162
bool common_hal_board_is_i2c(mp_obj_t obj) {
6263
for (uint8_t instance = 0; instance < CIRCUITPY_BOARD_I2C; instance++) {
@@ -68,7 +69,7 @@ bool common_hal_board_is_i2c(mp_obj_t obj) {
6869
}
6970

7071
mp_obj_t common_hal_board_get_i2c(const mp_int_t instance) {
71-
return &i2c_obj[instance];
72+
return i2c_obj_created[instance] ? &i2c_obj[instance] : NULL;
7273
}
7374

7475
mp_obj_t common_hal_board_create_i2c(const mp_int_t instance) {
@@ -85,6 +86,7 @@ mp_obj_t common_hal_board_create_i2c(const mp_int_t instance) {
8586

8687
common_hal_busio_i2c_construct(self, i2c_pin[instance].scl, i2c_pin[instance].sda, 100000, 255);
8788

89+
i2c_obj_created[instance] = true;
8890
return &i2c_obj[instance];
8991
}
9092
#endif
@@ -101,6 +103,7 @@ typedef struct {
101103

102104
static const board_spi_pin_t spi_pin[CIRCUITPY_BOARD_SPI] = CIRCUITPY_BOARD_SPI_PIN;
103105
static busio_spi_obj_t spi_obj[CIRCUITPY_BOARD_SPI];
106+
static bool spi_obj_created[CIRCUITPY_BOARD_SPI];
104107

105108
bool common_hal_board_is_spi(mp_obj_t obj) {
106109
for (uint8_t instance = 0; instance < CIRCUITPY_BOARD_SPI; instance++) {
@@ -112,7 +115,7 @@ bool common_hal_board_is_spi(mp_obj_t obj) {
112115
}
113116

114117
mp_obj_t common_hal_board_get_spi(const mp_int_t instance) {
115-
return &spi_obj[instance];
118+
return spi_obj_created[instance] ? &spi_obj[instance] : NULL;
116119
}
117120

118121
mp_obj_t common_hal_board_create_spi(const mp_int_t instance) {
@@ -130,6 +133,7 @@ mp_obj_t common_hal_board_create_spi(const mp_int_t instance) {
130133

131134
common_hal_busio_spi_construct(self, spi_pin[instance].clock, spi_pin[instance].mosi, spi_pin[instance].miso);
132135

136+
spi_obj_created[instance] = true;
133137
return &spi_obj[instance];
134138
}
135139
#endif
@@ -143,6 +147,7 @@ typedef struct {
143147

144148
static const board_uart_pin_t uart_pin[CIRCUITPY_BOARD_UART] = CIRCUITPY_BOARD_UART_PIN;
145149
static busio_uart_obj_t uart_obj[CIRCUITPY_BOARD_UART];
150+
static bool uart_obj_created[CIRCUITPY_BOARD_UART];
146151

147152
bool common_hal_board_is_uart(mp_obj_t obj) {
148153
for (uint8_t instance = 0; instance < CIRCUITPY_BOARD_UART; instance++) {
@@ -154,7 +159,7 @@ bool common_hal_board_is_uart(mp_obj_t obj) {
154159
}
155160

156161
mp_obj_t common_hal_board_get_uart(const mp_int_t instance) {
157-
return &uart_obj[instance];
162+
return uart_obj_created[instance] ? &uart_obj[instance] : NULL;
158163
}
159164

160165
mp_obj_t common_hal_board_create_uart(const mp_int_t instance) {
@@ -174,6 +179,7 @@ mp_obj_t common_hal_board_create_uart(const mp_int_t instance) {
174179
common_hal_busio_uart_construct(self, uart_pin[instance].tx, uart_pin[instance].rx,
175180
NULL, NULL, NULL, false, 9600, 8, BUSIO_UART_PARITY_NONE, 1, 1.0f, 64, NULL, false);
176181

182+
uart_obj_created[instance] = true;
177183
return &uart_obj[instance];
178184
}
179185
#endif
@@ -190,11 +196,12 @@ void reset_board_buses(void) {
190196
}
191197
}
192198
#endif
193-
if (!common_hal_busio_i2c_deinited(&i2c_obj[instance])) {
199+
if (i2c_obj_created[instance]) {
194200
// make sure I2C lock is not held over a soft reset
195201
common_hal_busio_i2c_unlock(&i2c_obj[instance]);
196202
if (!display_using_i2c) {
197203
common_hal_busio_i2c_deinit(&i2c_obj[instance]);
204+
i2c_obj_created[instance] = false;
198205
}
199206
}
200207
}
@@ -217,18 +224,22 @@ void reset_board_buses(void) {
217224
#endif
218225
}
219226
#endif
220-
if (!common_hal_busio_spi_deinited(&spi_obj[instance])) {
227+
if (spi_obj_created[instance]) {
221228
// make sure SPI lock is not held over a soft reset
222229
common_hal_busio_spi_unlock(&spi_obj[instance]);
223230
if (!display_using_spi) {
224231
common_hal_busio_spi_deinit(&spi_obj[instance]);
232+
spi_obj_created[instance] = false;
225233
}
226234
}
227235
}
228236
#endif
229237
#if CIRCUITPY_BOARD_UART
230238
for (uint8_t instance = 0; instance < CIRCUITPY_BOARD_UART; instance++) {
231-
common_hal_busio_uart_deinit(&uart_obj[instance]);
239+
if (uart_obj_created[instance]) {
240+
common_hal_busio_uart_deinit(&uart_obj[instance]);
241+
uart_obj_created[instance] = false;
242+
}
232243
}
233244
#endif
234245
}

shared-module/displayio/Display.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ mp_obj_t common_hal_displayio_display_get_bus(displayio_display_obj_t *self) {
220220
return self->core.bus;
221221
}
222222

223+
mp_obj_t common_hal_displayio_display_get_root_group(displayio_display_obj_t *self) {
224+
return self->core.current_group;
225+
}
226+
223227
STATIC const displayio_area_t *_get_refresh_areas(displayio_display_obj_t *self) {
224228
if (self->core.full_refresh) {
225229
self->core.area.next = NULL;

shared-module/displayio/display_core.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,15 @@ void displayio_display_core_set_rotation(displayio_display_core_t *self,
163163
}
164164

165165
bool displayio_display_core_show(displayio_display_core_t *self, displayio_group_t *root_group) {
166-
if (root_group == NULL) {
167-
if (!circuitpython_splash.in_group) {
168-
root_group = &circuitpython_splash;
169-
} else if (self->current_group == &circuitpython_splash) {
170-
return true;
171-
}
166+
167+
if (root_group == NULL) { // set the display to the REPL, reset REPL position and size
168+
circuitpython_splash.in_group = false;
169+
// force the circuit_python_splash out of any group (Note: could cause problems with the parent group)
170+
circuitpython_splash.x = 0; // reset position in case someone moved it.
171+
circuitpython_splash.y = 0;
172+
supervisor_stop_terminal();
173+
supervisor_start_terminal(self->width, self->height);
174+
root_group = &circuitpython_splash;
172175
}
173176
if (root_group == self->current_group) {
174177
return true;

supervisor/shared/display.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#if CIRCUITPY_TERMINALIO
3333

3434
#include "shared-bindings/displayio/Bitmap.h"
35-
#include "shared-bindings/displayio/Group.h"
3635
#include "shared-bindings/displayio/TileGrid.h"
3736
#include "shared-bindings/fontio/BuiltinFont.h"
3837
#include "shared-bindings/terminalio/Terminal.h"
@@ -46,7 +45,6 @@ extern const fontio_builtinfont_t supervisor_terminal_font;
4645
extern displayio_bitmap_t supervisor_terminal_font_bitmap;
4746
extern displayio_tilegrid_t supervisor_terminal_text_grid;
4847
extern terminalio_terminal_obj_t supervisor_terminal;
49-
extern displayio_group_t circuitpython_splash;
5048

5149
#endif
5250

tests/circuitpython-manual/audiobusio/i2s_sample_loop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# signed 16 bit
2020
s16 = array.array("h", [0] * length)
2121
for i in range(length):
22-
s16[i] = int(math.sin(math.pi * 2 * i / length) * (2**15))
22+
s16[i] = int(math.sin(math.pi * 2 * i / length) * (2 ** 15))
2323
print(s16[i])
2424

2525
sample = audiocore.RawSample(s16, sample_rate=8000)

tests/circuitpython-manual/audiopwmio/single_buffer_loop.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,29 @@
1919
# unsigned 8 bit
2020
u8 = array.array("B", [0] * length)
2121
for i in range(length):
22-
u8[i] = int(math.sin(math.pi * 2 * i / length) * (2**7) + 2**7)
22+
u8[i] = int(math.sin(math.pi * 2 * i / length) * (2 ** 7) + 2 ** 7)
2323

2424
samples.append(audiocore.RawSample(u8, sample_rate=4000))
2525

2626
# signed 8 bit
2727
s8 = array.array("b", [0] * length)
2828
for i in range(length):
29-
s8[i] = int(math.sin(math.pi * 2 * i / length) * (2**7))
29+
s8[i] = int(math.sin(math.pi * 2 * i / length) * (2 ** 7))
3030

3131
samples.append(audiocore.RawSample(s8, sample_rate=16000))
3232

3333
# unsigned 16 bit
3434
u16 = array.array("H", [0] * length)
3535
for i in range(length):
36-
u16[i] = int(math.sin(math.pi * 2 * i / length) * (2**15) + 2**15)
36+
u16[i] = int(math.sin(math.pi * 2 * i / length) * (2 ** 15) + 2 ** 15)
3737

3838
samples.append(audiocore.RawSample(u16, sample_rate=8000))
3939

4040

4141
# signed 16 bit
4242
s16 = array.array("h", [0] * length)
4343
for i in range(length):
44-
s16[i] = int(math.sin(math.pi * 2 * i / length) * (2**15))
44+
s16[i] = int(math.sin(math.pi * 2 * i / length) * (2 ** 15))
4545

4646
samples.append(audiocore.RawSample(s16, sample_rate=8000))
4747

tests/cpydiff/modules_random_randint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
import random
99

1010

11-
x = random.randint(2**128 - 1, 2**128)
11+
x = random.randint(2 ** 128 - 1, 2 ** 128)
1212
print("x={}".format(x))

tests/float/complex1.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727
print(1j / 2)
2828
print((1j / 2j).real)
2929
print(1j / (1 + 2j))
30-
ans = 0j**0
30+
ans = 0j ** 0
3131
print("%.5g %.5g" % (ans.real, ans.imag))
32-
ans = 0j**1
32+
ans = 0j ** 1
3333
print("%.5g %.5g" % (ans.real, ans.imag))
34-
ans = 0j**0j
34+
ans = 0j ** 0j
3535
print("%.5g %.5g" % (ans.real, ans.imag))
36-
ans = 1j**2.5
36+
ans = 1j ** 2.5
3737
print("%.5g %.5g" % (ans.real, ans.imag))
38-
ans = 1j**2.5j
38+
ans = 1j ** 2.5j
3939
print("%.5g %.5g" % (ans.real, ans.imag))
4040

4141
# comparison
@@ -116,10 +116,10 @@
116116

117117
# zero division via power
118118
try:
119-
0j**-1
119+
0j ** -1
120120
except ZeroDivisionError:
121121
print("ZeroDivisionError")
122122
try:
123-
0j**1j
123+
0j ** 1j
124124
except ZeroDivisionError:
125125
print("ZeroDivisionError")

tests/float/float1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
print("ZeroDivisionError")
8989

9090
try:
91-
0.0**-1
91+
0.0 ** -1
9292
except ZeroDivisionError:
9393
print("ZeroDivisionError")
9494

tests/float/float2int_doubleprec_intbig.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@
3535
print(int(1418774543.0))
3636
print("%d" % 1418774543.0)
3737
if ll_type == 3:
38-
print(int(2.0**100))
39-
print("%d" % 2.0**100)
38+
print(int(2.0 ** 100))
39+
print("%d" % 2.0 ** 100)
4040
else:
4141
print(int(1073741823.0))
4242
print("%d" % 1073741823.0)
4343

4444
testpass = True
4545
p2_rng = ((30, 63, 1024), (62, 63, 1024))[is_64bit][ll_type]
4646
for i in range(0, p2_rng):
47-
bitcnt = len(bin(int(2.0**i))) - 3
47+
bitcnt = len(bin(int(2.0 ** i))) - 3
4848
if i != bitcnt:
4949
print("fail: 2**%u was %u bits long" % (i, bitcnt))
5050
testpass = False
@@ -53,7 +53,7 @@
5353
testpass = True
5454
p10_rng = ((9, 18, 23), (18, 18, 23))[is_64bit][ll_type]
5555
for i in range(0, p10_rng):
56-
digcnt = len(str(int(10.0**i))) - 1
56+
digcnt = len(str(int(10.0 ** i))) - 1
5757
if i != digcnt:
5858
print("fail: 10**%u was %u digits long" % (i, digcnt))
5959
testpass = False
@@ -72,28 +72,28 @@ def fp2int_test(num, name, should_fail):
7272
if ll_type != 2:
7373
if ll_type == 0:
7474
if is_64bit:
75-
neg_bad_fp = -1.00000005 * 2.0**62.0
76-
pos_bad_fp = 2.0**62.0
77-
neg_good_fp = -(2.0**62.0)
78-
pos_good_fp = 0.99999993 * 2.0**62.0
75+
neg_bad_fp = -1.00000005 * 2.0 ** 62.0
76+
pos_bad_fp = 2.0 ** 62.0
77+
neg_good_fp = -(2.0 ** 62.0)
78+
pos_good_fp = 0.99999993 * 2.0 ** 62.0
7979
else:
80-
neg_bad_fp = -1.00000005 * 2.0**30.0
81-
pos_bad_fp = 2.0**30.0
82-
neg_good_fp = -(2.0**30.0)
83-
pos_good_fp = 0.9999999499 * 2.0**30.0
80+
neg_bad_fp = -1.00000005 * 2.0 ** 30.0
81+
pos_bad_fp = 2.0 ** 30.0
82+
neg_good_fp = -(2.0 ** 30.0)
83+
pos_good_fp = 0.9999999499 * 2.0 ** 30.0
8484
else:
85-
neg_bad_fp = -0.51 * 2.0**64.0
86-
pos_bad_fp = 2.0**63.0
87-
neg_good_fp = -(2.0**63.0)
88-
pos_good_fp = 1.9999998 * 2.0**62.0
85+
neg_bad_fp = -0.51 * 2.0 ** 64.0
86+
pos_bad_fp = 2.0 ** 63.0
87+
neg_good_fp = -(2.0 ** 63.0)
88+
pos_good_fp = 1.9999998 * 2.0 ** 62.0
8989

9090
fp2int_test(neg_bad_fp, "neg bad", True)
9191
fp2int_test(pos_bad_fp, "pos bad", True)
9292
fp2int_test(neg_good_fp, "neg good", False)
9393
fp2int_test(pos_good_fp, "pos good", False)
9494
else:
95-
fp2int_test(-1.9999999999999981 * 2.0**1023.0, "large neg", False)
96-
fp2int_test(1.9999999999999981 * 2.0**1023.0, "large pos", False)
95+
fp2int_test(-1.9999999999999981 * 2.0 ** 1023.0, "large neg", False)
96+
fp2int_test(1.9999999999999981 * 2.0 ** 1023.0, "large pos", False)
9797

9898
fp2int_test(float("inf"), "inf test", True)
9999
fp2int_test(float("-inf"), "inf test", True)

0 commit comments

Comments
 (0)