@@ -43,16 +43,18 @@ void microbit_soft_timer_deinit(void) {
4343 microbit_soft_timer_paused = false;
4444}
4545
46- void microbit_soft_timer_handler_run (void ) {
46+ static void microbit_soft_timer_handler_run (bool run_callbacks ) {
4747 uint32_t ticks_ms = mp_hal_ticks_ms ();
4848 microbit_soft_timer_entry_t * heap = MP_STATE_PORT (soft_timer_heap );
4949 while (heap != NULL && TICKS_DIFF (heap -> expiry_ms , ticks_ms ) <= 0 ) {
5050 microbit_soft_timer_entry_t * entry = heap ;
5151 heap = (microbit_soft_timer_entry_t * )mp_pairheap_pop (microbit_soft_timer_lt , & heap -> pairheap );
52- if (entry -> flags & MICROBIT_SOFT_TIMER_FLAG_PY_CALLBACK ) {
53- mp_sched_schedule (entry -> py_callback , MP_OBJ_FROM_PTR (entry ));
54- } else {
55- entry -> c_callback (entry );
52+ if (run_callbacks ) {
53+ if (entry -> flags & MICROBIT_SOFT_TIMER_FLAG_PY_CALLBACK ) {
54+ mp_sched_schedule (entry -> py_callback , MP_OBJ_FROM_PTR (entry ));
55+ } else {
56+ entry -> c_callback (entry );
57+ }
5658 }
5759 if (entry -> mode == MICROBIT_SOFT_TIMER_MODE_PERIODIC ) {
5860 entry -> expiry_ms += entry -> delta_ms ;
@@ -65,7 +67,7 @@ void microbit_soft_timer_handler_run(void) {
6567// This function can be executed at interrupt priority.
6668void microbit_soft_timer_handler (void ) {
6769 if (!microbit_soft_timer_paused ) {
68- microbit_soft_timer_handler_run ();
70+ microbit_soft_timer_handler_run (true );
6971 }
7072}
7173
@@ -77,10 +79,10 @@ void microbit_soft_timer_insert(microbit_soft_timer_entry_t *entry, uint32_t ini
7779 MICROPY_END_ATOMIC_SECTION (atomic_state );
7880}
7981
80- void microbit_soft_timer_set_pause (bool paused ) {
82+ void microbit_soft_timer_set_pause (bool paused , bool run_callbacks ) {
8183 if (microbit_soft_timer_paused && !paused ) {
8284 // Explicitly run the soft timer before unpausing, to catch up on any queued events.
83- microbit_soft_timer_handler_run ();
85+ microbit_soft_timer_handler_run (run_callbacks );
8486 }
8587 microbit_soft_timer_paused = paused ;
8688}
0 commit comments