Skip to content

Commit 1a6279b

Browse files
robert-hhdpgeorge
authored andcommitted
samd/mphalport: Simplify mp_hal_delay_ms().
Do NOT use `mp_hal_delay_us()` for short delays. This was initially done to make short delays precise, but it does not allow for scheduling. Leave using `mp_hal_delay_us()` to user code if needed. Signed-off-by: robert-hh <[email protected]>
1 parent ed86fdb commit 1a6279b

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

docs/samd/quickref.rst

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ Use the :mod:`time <time>` module::
6565
start = time.ticks_ms() # get millisecond counter
6666
delta = time.ticks_diff(time.ticks_ms(), start) # compute time difference
6767

68+
Note that :func:`time.sleep_us()` delays by busy waiting. During that time, other tasks are
69+
not scheduled.
6870

6971
Clock and time
7072
--------------

ports/samd/mphalport.c

+3-7
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,9 @@ void mp_hal_clr_pin_mux(mp_hal_pin_obj_t pin) {
6969
}
7070

7171
void mp_hal_delay_ms(mp_uint_t ms) {
72-
if (ms > 10) {
73-
uint32_t t0 = systick_ms;
74-
while (systick_ms - t0 < ms) {
75-
MICROPY_EVENT_POLL_HOOK
76-
}
77-
} else {
78-
mp_hal_delay_us(ms * 1000);
72+
uint32_t t0 = systick_ms;
73+
while (systick_ms - t0 < ms) {
74+
MICROPY_EVENT_POLL_HOOK
7975
}
8076
}
8177

0 commit comments

Comments
 (0)