Skip to content

Commit 01f252d

Browse files
authored
Merge pull request #6698 from tannewt/title_execution_status
Turn on title bar everywhere and enhance it
2 parents 8c10e09 + 207311b commit 01f252d

File tree

19 files changed

+437
-224
lines changed

19 files changed

+437
-224
lines changed

locale/circuitpython.pot

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,10 @@ msgstr ""
863863
msgid "Display rotation must be in 90 degree increments"
864864
msgstr ""
865865

866+
#: main.c
867+
msgid "Done"
868+
msgstr ""
869+
866870
#: shared-bindings/digitalio/DigitalInOut.c
867871
msgid "Drive mode not used when direction is input."
868872
msgstr ""
@@ -1535,6 +1539,14 @@ msgstr ""
15351539
msgid "Odd parity is not supported"
15361540
msgstr ""
15371541

1542+
#: supervisor/shared/bluetooth/bluetooth.c
1543+
msgid "Off"
1544+
msgstr ""
1545+
1546+
#: supervisor/shared/bluetooth/bluetooth.c
1547+
msgid "Ok"
1548+
msgstr ""
1549+
15381550
#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c
15391551
#: ports/raspberrypi/common-hal/audiobusio/PDMIn.c
15401552
msgid "Only 8 or 16 bit mono with "
@@ -1787,6 +1799,10 @@ msgstr ""
17871799
msgid "Received response was invalid"
17881800
msgstr ""
17891801

1802+
#: supervisor/shared/bluetooth/bluetooth.c
1803+
msgid "Reconnecting"
1804+
msgstr ""
1805+
17901806
#: shared-bindings/displayio/EPaperDisplay.c
17911807
msgid "Refresh too soon"
17921808
msgstr ""

main.c

Lines changed: 65 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,22 @@ STATIC void stop_mp(void) {
204204
gc_deinit();
205205
}
206206

207+
STATIC const char *_current_executing_filename = NULL;
208+
209+
STATIC pyexec_result_t _exec_result = {0, MP_OBJ_NULL, 0};
210+
211+
void supervisor_execution_status(void) {
212+
mp_obj_exception_t *exception = MP_OBJ_TO_PTR(_exec_result.exception);
213+
if (_current_executing_filename != NULL) {
214+
serial_write(_current_executing_filename);
215+
} else if ((_exec_result.return_code & PYEXEC_EXCEPTION) != 0 &&
216+
exception != NULL) {
217+
mp_printf(&mp_plat_print, "@%d %q", _exec_result.exception_line, exception->base.type->name);
218+
} else {
219+
serial_write_compressed(translate("Done"));
220+
}
221+
}
222+
207223
#define STRING_LIST(...) {__VA_ARGS__, ""}
208224

209225
// Look for the first file that exists in the list of filenames, using mp_import_stat().
@@ -218,17 +234,23 @@ STATIC const char *first_existing_file_in_list(const char *const *filenames) {
218234
return NULL;
219235
}
220236

221-
STATIC bool maybe_run_list(const char *const *filenames, pyexec_result_t *exec_result) {
222-
const char *filename = first_existing_file_in_list(filenames);
223-
if (filename == NULL) {
237+
STATIC bool maybe_run_list(const char *const *filenames) {
238+
_exec_result.return_code = 0;
239+
_exec_result.exception = MP_OBJ_NULL;
240+
_exec_result.exception_line = 0;
241+
_current_executing_filename = first_existing_file_in_list(filenames);
242+
if (_current_executing_filename == NULL) {
224243
return false;
225244
}
226-
mp_hal_stdout_tx_str(filename);
245+
mp_hal_stdout_tx_str(_current_executing_filename);
227246
serial_write_compressed(translate(" output:\n"));
228-
pyexec_file(filename, exec_result);
247+
supervisor_title_bar_update();
248+
pyexec_file(_current_executing_filename, &_exec_result);
229249
#if CIRCUITPY_ATEXIT
230-
shared_module_atexit_execute(exec_result);
250+
shared_module_atexit_execute(&_exec_result);
231251
#endif
252+
_current_executing_filename = NULL;
253+
supervisor_title_bar_update();
232254
return true;
233255
}
234256

@@ -347,12 +369,6 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool first_run, bool *simulate_re
347369
}
348370
#endif
349371

350-
pyexec_result_t result;
351-
352-
result.return_code = 0;
353-
result.exception = MP_OBJ_NULL;
354-
result.exception_line = 0;
355-
356372
bool skip_repl = false;
357373
bool skip_wait = false;
358374
bool found_main = false;
@@ -391,7 +407,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool first_run, bool *simulate_re
391407
if (((next_code_info_t *)next_code_allocation->ptr)->filename[0] != '\0') {
392408
const char *next_list[] = {((next_code_info_t *)next_code_allocation->ptr)->filename, ""};
393409
// This is where the user's python code is actually executed:
394-
found_main = maybe_run_list(next_list, &result);
410+
found_main = maybe_run_list(next_list);
395411
if (!found_main) {
396412
serial_write(((next_code_info_t *)next_code_allocation->ptr)->filename);
397413
serial_write_compressed(translate(" not found.\n"));
@@ -401,11 +417,11 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool first_run, bool *simulate_re
401417
// Otherwise, default to the standard list of filenames
402418
if (!found_main) {
403419
// This is where the user's python code is actually executed:
404-
found_main = maybe_run_list(supported_filenames, &result);
420+
found_main = maybe_run_list(supported_filenames);
405421
// If that didn't work, double check the extensions
406422
#if CIRCUITPY_FULL_BUILD
407423
if (!found_main) {
408-
found_main = maybe_run_list(double_extension_filenames, &result);
424+
found_main = maybe_run_list(double_extension_filenames);
409425
if (found_main) {
410426
serial_write_compressed(translate("WARNING: Your code filename has two extensions\n"));
411427
}
@@ -417,15 +433,15 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool first_run, bool *simulate_re
417433

418434
// Print done before resetting everything so that we get the message over
419435
// BLE before it is reset and we have a delay before reconnect.
420-
if ((result.return_code & PYEXEC_RELOAD) && supervisor_get_run_reason() == RUN_REASON_AUTO_RELOAD) {
436+
if ((_exec_result.return_code & PYEXEC_RELOAD) && supervisor_get_run_reason() == RUN_REASON_AUTO_RELOAD) {
421437
serial_write_compressed(translate("\nCode stopped by auto-reload. Reloading soon.\n"));
422438
} else {
423439
serial_write_compressed(translate("\nCode done running.\n"));
424440
}
425441

426442

427443
// Finished executing python code. Cleanup includes filesystem flush and a board reset.
428-
cleanup_after_vm(heap, result.exception);
444+
cleanup_after_vm(heap, _exec_result.exception);
429445

430446
// If a new next code file was set, that is a reason to keep it (obviously). Stuff this into
431447
// the options because it can be treated like any other reason-for-stickiness bit. The
@@ -436,15 +452,15 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool first_run, bool *simulate_re
436452
next_code_options |= SUPERVISOR_NEXT_CODE_OPT_NEWLY_SET;
437453
}
438454

439-
if (result.return_code & PYEXEC_RELOAD) {
455+
if (_exec_result.return_code & PYEXEC_RELOAD) {
440456
next_code_stickiness_situation |= SUPERVISOR_NEXT_CODE_OPT_STICKY_ON_RELOAD;
441457
// Reload immediately unless the reload is due to autoreload. In that
442458
// case, we wait below to see if any other writes occur.
443459
if (supervisor_get_run_reason() != RUN_REASON_AUTO_RELOAD) {
444460
skip_repl = true;
445461
skip_wait = true;
446462
}
447-
} else if (result.return_code == 0) {
463+
} else if (_exec_result.return_code == 0) {
448464
next_code_stickiness_situation |= SUPERVISOR_NEXT_CODE_OPT_STICKY_ON_SUCCESS;
449465
if (next_code_options & SUPERVISOR_NEXT_CODE_OPT_RELOAD_ON_SUCCESS) {
450466
skip_repl = true;
@@ -455,12 +471,12 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool first_run, bool *simulate_re
455471
// Deep sleep cannot be skipped
456472
// TODO: settings in deep sleep should persist, using a new sleep memory API
457473
if (next_code_options & SUPERVISOR_NEXT_CODE_OPT_RELOAD_ON_ERROR
458-
&& !(result.return_code & PYEXEC_DEEP_SLEEP)) {
474+
&& !(_exec_result.return_code & PYEXEC_DEEP_SLEEP)) {
459475
skip_repl = true;
460476
skip_wait = true;
461477
}
462478
}
463-
if (result.return_code & PYEXEC_FORCED_EXIT) {
479+
if (_exec_result.return_code & PYEXEC_FORCED_EXIT) {
464480
skip_repl = false;
465481
skip_wait = true;
466482
}
@@ -478,12 +494,12 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool first_run, bool *simulate_re
478494
uint8_t blink_count;
479495
bool led_active = false;
480496
#if CIRCUITPY_ALARM
481-
if (result.return_code & PYEXEC_DEEP_SLEEP) {
497+
if (_exec_result.return_code & PYEXEC_DEEP_SLEEP) {
482498
color = BLACK;
483499
blink_count = 0;
484500
} else
485501
#endif
486-
if (result.return_code != PYEXEC_EXCEPTION) {
502+
if (_exec_result.return_code != PYEXEC_EXCEPTION) {
487503
if (safe_mode == NO_SAFE_MODE) {
488504
color = ALL_DONE;
489505
blink_count = ALL_DONE_BLINKS;
@@ -568,7 +584,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool first_run, bool *simulate_re
568584

569585
// Sleep until our next interrupt.
570586
#if CIRCUITPY_ALARM
571-
if (result.return_code & PYEXEC_DEEP_SLEEP) {
587+
if (_exec_result.return_code & PYEXEC_DEEP_SLEEP) {
572588
const bool awoke_from_true_deep_sleep =
573589
common_hal_mcu_processor_get_reset_reason() == RESET_REASON_DEEP_SLEEP_ALARM;
574590

@@ -730,19 +746,28 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
730746
usb_set_defaults();
731747
#endif
732748

733-
pyexec_result_t result = {0, MP_OBJ_NULL, 0};
734-
735749
if (ok_to_run) {
736750
#ifdef CIRCUITPY_BOOT_OUTPUT_FILE
751+
// Turn off title bar updates when writing out to boot_out.txt.
752+
supervisor_title_bar_suspend();
737753
vstr_t boot_text;
738754
vstr_init(&boot_text, 512);
739755
boot_output = &boot_text;
740756
#endif
741757

742758
// Write version info
743759
mp_printf(&mp_plat_print, "%s\nBoard ID:%s\n", MICROPY_FULL_VERSION_INFO, CIRCUITPY_BOARD_ID);
760+
#if CIRCUITPY_MICROCONTROLLER && COMMON_HAL_MCU_PROCESSOR_UID_LENGTH > 0
761+
uint8_t raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH];
762+
common_hal_mcu_processor_get_uid(raw_id);
763+
mp_printf(&mp_plat_print, "UID:");
764+
for (uint8_t i = 0; i < COMMON_HAL_MCU_PROCESSOR_UID_LENGTH; i++) {
765+
mp_printf(&mp_plat_print, "%02X", raw_id[i]);
766+
}
767+
mp_printf(&mp_plat_print, "\n");
768+
#endif
744769

745-
bool found_boot = maybe_run_list(boot_py_filenames, &result);
770+
bool found_boot = maybe_run_list(boot_py_filenames);
746771
(void)found_boot;
747772

748773

@@ -752,6 +777,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
752777
FATFS *fs = &vfs->fatfs;
753778

754779
boot_output = NULL;
780+
supervisor_title_bar_resume();
755781
bool write_boot_output = true;
756782
FIL boot_output_file;
757783
if (f_open(fs, &boot_output_file, CIRCUITPY_BOOT_OUTPUT_FILE, FA_READ) == FR_OK) {
@@ -794,7 +820,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
794820

795821
port_post_boot_py(true);
796822

797-
cleanup_after_vm(heap, result.exception);
823+
cleanup_after_vm(heap, _exec_result.exception);
798824

799825
port_post_boot_py(false);
800826

@@ -831,7 +857,11 @@ STATIC int run_repl(bool first_run) {
831857
exit_code = pyexec_raw_repl();
832858
supervisor_title_bar_resume();
833859
} else {
860+
_current_executing_filename = "REPL";
861+
supervisor_title_bar_update();
834862
exit_code = pyexec_friendly_repl();
863+
_current_executing_filename = NULL;
864+
supervisor_title_bar_update();
835865
}
836866
#if CIRCUITPY_ATEXIT
837867
pyexec_result_t result;
@@ -841,6 +871,13 @@ STATIC int run_repl(bool first_run) {
841871
}
842872
#endif
843873
cleanup_after_vm(heap, MP_OBJ_SENTINEL);
874+
875+
// Also reset bleio. The above call omits it in case workflows should continue. In this case,
876+
// we're switching straight to another VM so we want to reset.
877+
#if CIRCUITPY_BLEIO
878+
bleio_reset();
879+
#endif
880+
844881
#if CIRCUITPY_STATUS_LED
845882
status_led_init();
846883
new_status_color(BLACK);

ports/atmel-samd/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ CFLAGS += \
164164
-msoft-float \
165165
-mfloat-abi=soft \
166166
-DSAMD21
167+
LIBS := libs/libgcc-12.1.0-Os-v6-m-nofp.a -lc
168+
else
169+
LIBS := -lgcc -lc
167170
endif
168171
ifeq ($(CHIP_FAMILY), samd51)
169172
CFLAGS += \
@@ -200,7 +203,6 @@ endif
200203
CFLAGS += -Wno-stringop-overread -Wno-stringop-overflow
201204

202205
LDFLAGS = $(CFLAGS) -nostartfiles -Wl,-nostdlib -Wl,-T,$(GENERATED_LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
203-
LIBS := -lgcc -lc
204206

205207
# Use toolchain libm if we're not using our own.
206208
ifndef INTERNAL_LIBM
Binary file not shown.

ports/nrf/common-hal/_bleio/Adapter.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,15 +449,23 @@ bool common_hal_bleio_adapter_set_address(bleio_adapter_obj_t *self, bleio_addre
449449
return sd_ble_gap_addr_set(&local_address) == NRF_SUCCESS;
450450
}
451451

452+
uint16_t bleio_adapter_get_name(char *buf, uint16_t len) {
453+
uint16_t full_len = 0;
454+
sd_ble_gap_device_name_get(NULL, &full_len);
455+
456+
uint32_t err_code = sd_ble_gap_device_name_get((uint8_t *)buf, &len);
457+
if (err_code != NRF_SUCCESS) {
458+
return 0;
459+
}
460+
return full_len;
461+
}
462+
452463
mp_obj_str_t *common_hal_bleio_adapter_get_name(bleio_adapter_obj_t *self) {
453464
uint16_t len = 0;
454465
sd_ble_gap_device_name_get(NULL, &len);
455-
uint8_t buf[len];
456-
uint32_t err_code = sd_ble_gap_device_name_get(buf, &len);
457-
if (err_code != NRF_SUCCESS) {
458-
return NULL;
459-
}
460-
return mp_obj_new_str((char *)buf, len);
466+
char buf[len];
467+
bleio_adapter_get_name(buf, len);
468+
return mp_obj_new_str(buf, len);
461469
}
462470

463471
void common_hal_bleio_adapter_set_name(bleio_adapter_obj_t *self, const char *name) {

py/circuitpy_mpconfig.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ CFLAGS += -DCIRCUITPY_SSL=$(CIRCUITPY_SSL)
369369
CIRCUITPY_STAGE ?= 0
370370
CFLAGS += -DCIRCUITPY_STAGE=$(CIRCUITPY_STAGE)
371371

372-
CIRCUITPY_STATUS_BAR ?= $(CIRCUITPY_WEB_WORKFLOW)
372+
CIRCUITPY_STATUS_BAR ?= 1
373373
CFLAGS += -DCIRCUITPY_STATUS_BAR=$(CIRCUITPY_STATUS_BAR)
374374

375375
CIRCUITPY_STORAGE ?= 1

shared-bindings/_bleio/Adapter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ MP_PROPERTY_GETSET(bleio_adapter_address_obj,
158158
//| The name is "CIRCUITPY" + the last four hex digits of ``adapter.address``,
159159
//| to make it easy to distinguish multiple CircuitPython boards."""
160160
//|
161-
STATIC mp_obj_t bleio_adapter_get_name(mp_obj_t self) {
161+
STATIC mp_obj_t _bleio_adapter_get_name(mp_obj_t self) {
162162
return MP_OBJ_FROM_PTR(common_hal_bleio_adapter_get_name(self));
163163
}
164-
MP_DEFINE_CONST_FUN_OBJ_1(bleio_adapter_get_name_obj, bleio_adapter_get_name);
164+
MP_DEFINE_CONST_FUN_OBJ_1(bleio_adapter_get_name_obj, _bleio_adapter_get_name);
165165

166166

167167
STATIC mp_obj_t bleio_adapter_set_name(mp_obj_t self, mp_obj_t new_name) {

shared-bindings/_bleio/Adapter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ extern bool common_hal_bleio_adapter_get_connected(bleio_adapter_obj_t *self);
5050
extern bleio_address_obj_t *common_hal_bleio_adapter_get_address(bleio_adapter_obj_t *self);
5151
extern bool common_hal_bleio_adapter_set_address(bleio_adapter_obj_t *self, bleio_address_obj_t *address);
5252

53+
// Copies the adapter name into the given buffer up to len and returns the full length (may be more
54+
// than len if the buffer was too short.)
55+
uint16_t bleio_adapter_get_name(char *buf, uint16_t len);
5356
extern mp_obj_str_t *common_hal_bleio_adapter_get_name(bleio_adapter_obj_t *self);
5457
extern void common_hal_bleio_adapter_set_name(bleio_adapter_obj_t *self, const char *name);
5558

0 commit comments

Comments
 (0)