File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -143,22 +143,26 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_millis_obj, pyb_millis);
143143
144144/// \function delay(ms)
145145/// Delay for the given number of milliseconds.
146- STATIC mp_obj_t pyb_delay (mp_obj_t count ) {
147- HAL_Delay (mp_obj_get_int (count ));
146+ STATIC mp_obj_t pyb_delay (mp_obj_t ms_in ) {
147+ machine_int_t ms = mp_obj_get_int (ms_in );
148+ if (ms >= 0 ) {
149+ HAL_Delay (ms );
150+ }
148151 return mp_const_none ;
149152}
150153STATIC MP_DEFINE_CONST_FUN_OBJ_1 (pyb_delay_obj , pyb_delay );
151154
152155/// \function udelay(us)
153156/// Delay for the given number of microseconds.
154- STATIC mp_obj_t pyb_udelay (mp_obj_t usec ) {
155- uint32_t count = 0 ;
156- const uint32_t utime = ( 168 * mp_obj_get_int ( usec ) / 5 );
157- for (;;) {
158- if ( ++ count > utime ) {
159- return mp_const_none ;
157+ STATIC mp_obj_t pyb_udelay (mp_obj_t usec_in ) {
158+ machine_int_t usec = mp_obj_get_int ( usec_in ) ;
159+ if ( usec > 0 ) {
160+ uint32_t count = 0 ;
161+ const uint32_t utime = ( 168 * usec / 4 );
162+ while ( ++ count <= utime ) {
160163 }
161164 }
165+ return mp_const_none ;
162166}
163167STATIC MP_DEFINE_CONST_FUN_OBJ_1 (pyb_udelay_obj , pyb_udelay );
164168
You can’t perform that action at this time.
0 commit comments