Skip to content

Commit 360b25a

Browse files
committed
stm: Add udelay (delay in microseconds).
1 parent cd00064 commit 360b25a

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

stm/main.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ mp_obj_t pyb_delay(mp_obj_t count) {
110110
return mp_const_none;
111111
}
112112

113+
mp_obj_t pyb_udelay(mp_obj_t usec) {
114+
uint32_t count = 0;
115+
const uint32_t utime = (168 * mp_obj_get_int(usec) / 5);
116+
for (;;) {
117+
if (++count > utime) {
118+
return mp_const_none;
119+
}
120+
}
121+
}
122+
113123
void fatality(void) {
114124
led_state(PYB_LED_R1, 1);
115125
led_state(PYB_LED_G1, 1);
@@ -415,6 +425,7 @@ int main(void) {
415425
rt_store_attr(m, MP_QSTR_main, rt_make_function_n(1, pyb_main));
416426
rt_store_attr(m, MP_QSTR_sync, rt_make_function_n(0, pyb_sync));
417427
rt_store_attr(m, MP_QSTR_delay, rt_make_function_n(1, pyb_delay));
428+
rt_store_attr(m, MP_QSTR_udelay, rt_make_function_n(1, pyb_udelay));
418429
#if MICROPY_HW_HAS_SWITCH
419430
rt_store_attr(m, MP_QSTR_switch, (mp_obj_t)&pyb_switch_obj);
420431
#endif

stm/qstrdefsport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Q(main)
1111
Q(sync)
1212
Q(gc)
1313
Q(delay)
14+
Q(udelay)
1415
Q(switch)
1516
Q(SW)
1617
Q(servo)

0 commit comments

Comments
 (0)