Skip to content
This repository was archived by the owner on Aug 23, 2024. It is now read-only.

Commit b0c179e

Browse files
committed
Fixed bug in utime.sleep & utime.sleep_ms
1 parent aed6e63 commit b0c179e

21 files changed

Lines changed: 31 additions & 29 deletions

File tree

MicroPython_BUILD/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ build/
2222

2323
patches/
2424

25+
partitions_mpy.csv
2526
sdkconfig
2627
sdkconfig.old
2728
_sdkconfig.saved

MicroPython_BUILD/components/micropython/extmod/utime_mphal.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,34 @@
3636
#include "py/runtime.h"
3737
#include "extmod/utime_mphal.h"
3838

39-
//----------------------------------------------
40-
STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) {
39+
//------------------------------------------------------------------
40+
STATIC mp_obj_t time_sleep(mp_uint_t n_args, const mp_obj_t *args) {
4141
#if MICROPY_PY_BUILTINS_FLOAT
42-
uint32_t t = mp_hal_delay_ms((mp_uint_t)(1000 * mp_obj_get_float(seconds_o)));
42+
uint32_t t = mp_hal_delay_ms((mp_uint_t)(1000 * mp_obj_get_float(args[0])));
4343
#else
44-
uint32_t t = mp_hal_delay_ms(1000 * mp_obj_get_int(seconds_o));
44+
uint32_t t = mp_hal_delay_ms(1000 * mp_obj_get_int(args[0]));
4545
#endif
46-
return MP_OBJ_NEW_SMALL_INT(t);
46+
if ((n_args > 1) && (mp_obj_is_true(args[1]))) {
47+
#if MICROPY_PY_BUILTINS_FLOAT
48+
return mp_obj_new_float((float)t / 1000.0);
49+
#else
50+
return MP_OBJ_NEW_SMALL_INT(t);
51+
#endif
52+
}
53+
return mp_const_none;
4754
}
48-
MP_DEFINE_CONST_FUN_OBJ_1(mp_utime_sleep_obj, time_sleep);
55+
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_utime_sleep_obj, 1, 2, time_sleep);
4956

50-
//-------------------------------------------
51-
STATIC mp_obj_t time_sleep_ms(mp_obj_t arg) {
52-
mp_int_t ms = mp_obj_get_int(arg);
57+
//---------------------------------------------------------------------
58+
STATIC mp_obj_t time_sleep_ms(mp_uint_t n_args, const mp_obj_t *args) {
59+
mp_int_t ms = mp_obj_get_int(args[0]);
5360
uint32_t t = mp_hal_delay_ms(ms);
54-
return MP_OBJ_NEW_SMALL_INT(t);
61+
if ((n_args > 1) && (mp_obj_is_true(args[1]))) {
62+
return MP_OBJ_NEW_SMALL_INT(t);
63+
}
64+
return mp_const_none;
5565
}
56-
MP_DEFINE_CONST_FUN_OBJ_1(mp_utime_sleep_ms_obj, time_sleep_ms);
66+
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_utime_sleep_ms_obj, 1, 2, time_sleep_ms);
5767

5868
//-------------------------------------------
5969
STATIC mp_obj_t time_sleep_us(mp_obj_t arg) {

MicroPython_BUILD/components/micropython/extmod/utime_mphal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929

3030
#include "py/obj.h"
3131

32-
MP_DECLARE_CONST_FUN_OBJ_1(mp_utime_sleep_obj);
33-
MP_DECLARE_CONST_FUN_OBJ_1(mp_utime_sleep_ms_obj);
32+
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_utime_sleep_obj);
33+
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_utime_sleep_ms_obj);
3434
MP_DECLARE_CONST_FUN_OBJ_1(mp_utime_sleep_us_obj);
3535
MP_DECLARE_CONST_FUN_OBJ_0(mp_utime_ticks_ms_obj);
3636
MP_DECLARE_CONST_FUN_OBJ_0(mp_utime_ticks_us_obj);
309 Bytes
Binary file not shown.
64 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/bash
2-
esptool.py --chip esp32 --port /dev/ttyUSB1 --baud 921600 --before default_reset --after no_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 bootloader/bootloader.bin 0xf000 phy_init_data.bin 0x10000 MicroPython.bin 0x8000 partitions_mpy.bin
2+
esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after no_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 bootloader/bootloader.bin 0xf000 phy_init_data.bin 0x10000 MicroPython.bin 0x8000 partitions_mpy.bin
80 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/bash
2-
esptool.py --chip esp32 --port /dev/ttyUSB1 --baud 921600 --before default_reset --after no_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 bootloader/bootloader.bin 0xf000 phy_init_data.bin 0x10000 MicroPython.bin 0x8000 partitions_mpy.bin
2+
esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after no_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 bootloader/bootloader.bin 0xf000 phy_init_data.bin 0x10000 MicroPython.bin 0x8000 partitions_mpy.bin

0 commit comments

Comments
 (0)