File tree Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Expand file tree Collapse file tree 1 file changed +12
-8
lines changed 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);
143
143
144
144
/// \function delay(ms)
145
145
/// 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
+ }
148
151
return mp_const_none ;
149
152
}
150
153
STATIC MP_DEFINE_CONST_FUN_OBJ_1 (pyb_delay_obj , pyb_delay );
151
154
152
155
/// \function udelay(us)
153
156
/// 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 ) {
160
163
}
161
164
}
165
+ return mp_const_none ;
162
166
}
163
167
STATIC MP_DEFINE_CONST_FUN_OBJ_1 (pyb_udelay_obj , pyb_udelay );
164
168
You can’t perform that action at this time.
0 commit comments