Skip to content

Commit 9bd70d7

Browse files
committed
mp utime
1 parent d202a13 commit 9bd70d7

File tree

9 files changed

+98
-5
lines changed

9 files changed

+98
-5
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,10 +523,12 @@ endif()
523523

524524
set(src_third_party_micropython_extmod
525525
src/third_party/micropython/extmod/virtpin.c
526+
src/third_party/micropython/extmod/utime_mphal.c
526527
)
527528
list (APPEND src_files ${src_third_party_micropython_extmod})
528529
set(header_third_party_micropython_extmod
529530
src/third_party/micropython/extmod/virtpin.h
531+
src/third_party/micropython/extmod/utime_mphal.h
530532
)
531533
list (APPEND header_files ${header_third_party_micropython_extmod})
532534
source_group("third_party\\micropython\\extmod" FILES ${src_third_party_micropython_extmod} ${header_third_party_micropython_extmod})
@@ -564,6 +566,12 @@ set(header_third_party_micropython_ports_bb3_mod_eez
564566
list (APPEND header_files ${header_third_party_micropython_ports_bb3_mod_eez})
565567
source_group("third_party\\micropython\\ports\\bb3\\modeez" FILES ${src_third_party_micropython_ports_bb3_mod_eez} ${header_third_party_micropython_ports_bb3_mod_eez})
566568

569+
set(src_third_party_micropython_ports_bb3_mod_utime
570+
src/third_party/micropython/ports/bb3/mod/utime/modutime.c
571+
)
572+
list (APPEND src_files ${src_third_party_micropython_ports_bb3_mod_utime})
573+
source_group("third_party\\micropython\\ports\\bb3\\utime" FILES ${src_third_party_micropython_ports_bb3_mod_utime})
574+
567575
set(src_third_party_micropython_py
568576
src/third_party/micropython/py/argcheck.c
569577
src/third_party/micropython/py/asmarm.c

scripts/test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import ustruct
2+
import utime
3+
4+
print(ustruct.pack('hhl', 1, 2, 3))
5+
print(utime.ticks_ms())

src/third_party/micropython/ports/bare-arm/mpconfigport.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
4848
#define MICROPY_USE_INTERNAL_PRINTF (0)
4949

50-
#define MICROPY_PY_UTIME_MP_HAL (1)
50+
#define MICROPY_PY_UTIME (1)
51+
#define MICROPY_PY_UTIME_MP_HAL (1)
5152

5253
// type definitions for the specific machine
5354

src/third_party/micropython/ports/bb3/genhdr/moduledefs.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,16 @@
1414
#define MODULE_DEF_MP_QSTR_UARRAY
1515
#endif
1616

17+
#if (MICROPY_PY_UTIME)
18+
extern const struct _mp_obj_module_t mp_module_utime;
19+
#define MODULE_DEF_MP_QSTR_UTIME { MP_ROM_QSTR(MP_QSTR_utime), MP_ROM_PTR(&mp_module_utime) },
20+
#else
21+
#define MODULE_DEF_MP_QSTR_UTIME
22+
#endif
23+
1724

1825
#define MICROPY_REGISTERED_MODULES \
1926
MODULE_DEF_MP_QSTR_EEZ \
2027
MODULE_DEF_MP_QSTR_UARRAY \
28+
MODULE_DEF_MP_QSTR_UTIME \
2129
// MICROPY_REGISTERED_MODULES
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// This file was generated by py/makeversionhdr.py
2-
#define MICROPY_GIT_TAG "919ff07-dirty"
3-
#define MICROPY_GIT_HASH "919ff07-dirty"
4-
#define MICROPY_BUILD_DATE "2019-12-04"
2+
#define MICROPY_GIT_TAG "d202a13-dirty"
3+
#define MICROPY_GIT_HASH "d202a13-dirty"
4+
#define MICROPY_BUILD_DATE "2019-12-06"

src/third_party/micropython/ports/bb3/genhdr/qstrdefs.generated.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,15 @@ QDEF(MP_QSTR_pack_into, (const byte*)"\x1f\x09" "pack_into")
220220
QDEF(MP_QSTR_pend_throw, (const byte*)"\xf3\x0a" "pend_throw")
221221
QDEF(MP_QSTR_real, (const byte*)"\xbf\x04" "real")
222222
QDEF(MP_QSTR_scpi, (const byte*)"\xec\x04" "scpi")
223+
QDEF(MP_QSTR_sleep, (const byte*)"\xea\x05" "sleep")
224+
QDEF(MP_QSTR_sleep_ms, (const byte*)"\x0b\x08" "sleep_ms")
225+
QDEF(MP_QSTR_sleep_us, (const byte*)"\x13\x08" "sleep_us")
226+
QDEF(MP_QSTR_ticks_add, (const byte*)"\x9d\x09" "ticks_add")
227+
QDEF(MP_QSTR_ticks_cpu, (const byte*)"\x1a\x09" "ticks_cpu")
228+
QDEF(MP_QSTR_ticks_diff, (const byte*)"\xb1\x0a" "ticks_diff")
229+
QDEF(MP_QSTR_ticks_ms, (const byte*)"\x42\x08" "ticks_ms")
230+
QDEF(MP_QSTR_ticks_us, (const byte*)"\x5a\x08" "ticks_us")
223231
QDEF(MP_QSTR_unpack, (const byte*)"\x07\x06" "unpack")
224232
QDEF(MP_QSTR_unpack_from, (const byte*)"\x0e\x0b" "unpack_from")
225233
QDEF(MP_QSTR_ustruct, (const byte*)"\x47\x07" "ustruct")
234+
QDEF(MP_QSTR_utime, (const byte*)"\xe5\x05" "utime")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
EEZ_MOD_DIR := $(USERMOD_DIR)
2+
3+
# Add all C files to SRC_USERMOD.
4+
SRC_USERMOD += $(EEZ_MOD_DIR)/modutime.c
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2013, 2014 Damien P. George
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include <stdio.h>
28+
#include <string.h>
29+
30+
#include "py/runtime.h"
31+
#include "py/smallint.h"
32+
#include "py/obj.h"
33+
#include "extmod/utime_mphal.h"
34+
35+
36+
STATIC const mp_rom_map_elem_t time_module_globals_table[] = {
37+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) },
38+
39+
{ MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj) },
40+
{ MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) },
41+
{ MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) },
42+
{ MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_utime_ticks_ms_obj) },
43+
{ MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_utime_ticks_us_obj) },
44+
{ MP_ROM_QSTR(MP_QSTR_ticks_cpu), MP_ROM_PTR(&mp_utime_ticks_cpu_obj) },
45+
{ MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_utime_ticks_add_obj) },
46+
{ MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_utime_ticks_diff_obj) },
47+
};
48+
49+
STATIC MP_DEFINE_CONST_DICT(time_module_globals, time_module_globals_table);
50+
51+
const mp_obj_module_t mp_module_utime = {
52+
.base = { &mp_type_module },
53+
.globals = (mp_obj_dict_t*)&time_module_globals,
54+
};
55+
56+
// Register the module to make it available in Python
57+
MP_REGISTER_MODULE(MP_QSTR_utime, mp_module_utime, MICROPY_PY_UTIME);

src/third_party/micropython/ports/bb3/mpconfigport.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
4848
#define MICROPY_USE_INTERNAL_PRINTF (0)
4949

50-
#define MICROPY_PY_UTIME_MP_HAL (1)
50+
#define MICROPY_PY_UTIME (1)
51+
#define MICROPY_PY_UTIME_MP_HAL (1)
5152

5253
// type definitions for the specific machine
5354

0 commit comments

Comments
 (0)