Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
d3116556
Commit
d3116556
authored
Mar 22, 2014
by
Damien George
Browse files
stmhal: Add time module with sleep function.
parent
ad7b84a7
Changes
5
Hide whitespace changes
Inline
Side-by-side
stmhal/Makefile
View file @
d3116556
...
...
@@ -74,6 +74,7 @@ SRC_C = \
pyexec.c
\
pybmodule.c
\
osmodule.c
\
timemodule.c
\
import.c
\
lexerfatfs.c
\
gpio.c
\
...
...
stmhal/main.c
View file @
d3116556
...
...
@@ -23,6 +23,7 @@
#include
"pyexec.h"
#include
"pybmodule.h"
#include
"osmodule.h"
#include
"timemodule.h"
#include
"usart.h"
#include
"led.h"
#include
"exti.h"
...
...
@@ -276,9 +277,10 @@ soft_reset:
// probably shouldn't do this, so we are compatible with CPython
rt_store_name
(
MP_QSTR_pyb
,
(
mp_obj_t
)
&
pyb_module
);
// pre-import the os module
// pre-import the os
and time
module
s
// TODO don't do this! (need a way of registering builtin modules...)
rt_store_name
(
MP_QSTR_os
,
(
mp_obj_t
)
&
os_module
);
rt_store_name
(
MP_QSTR_time
,
(
mp_obj_t
)
&
time_module
);
// check if user switch held (initiates reset of filesystem)
bool
reset_filesystem
=
false
;
...
...
stmhal/qstrdefsport.h
View file @
d3116556
...
...
@@ -66,3 +66,7 @@ Q(rmdir)
Q
(
unlink
)
Q
(
sep
)
Q
(
urandom
)
// for time module
Q
(
time
)
Q
(
sleep
)
stmhal/timemodule.c
0 → 100644
View file @
d3116556
#include
<stm32f4xx_hal.h>
#include
"nlr.h"
#include
"misc.h"
#include
"mpconfig.h"
#include
"qstr.h"
#include
"obj.h"
#include
"map.h"
#include
"timemodule.h"
STATIC
mp_obj_t
time_sleep
(
mp_obj_t
seconds_o
)
{
#if MICROPY_ENABLE_FLOAT
if
(
MP_OBJ_IS_INT
(
seconds_o
))
{
#endif
HAL_Delay
(
1000
*
mp_obj_get_int
(
seconds_o
));
#if MICROPY_ENABLE_FLOAT
}
else
{
HAL_Delay
((
uint32_t
)(
1000
*
mp_obj_get_float
(
seconds_o
)));
}
#endif
return
mp_const_none
;
}
MP_DEFINE_CONST_FUN_OBJ_1
(
time_sleep_obj
,
time_sleep
);
STATIC
const
mp_map_elem_t
time_module_globals_table
[]
=
{
{
MP_OBJ_NEW_QSTR
(
MP_QSTR___name__
),
MP_OBJ_NEW_QSTR
(
MP_QSTR_time
)
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_sleep
),
(
mp_obj_t
)
&
time_sleep_obj
},
};
STATIC
const
mp_map_t
time_module_globals
=
{
.
all_keys_are_qstrs
=
1
,
.
table_is_fixed_array
=
1
,
.
used
=
sizeof
(
time_module_globals_table
)
/
sizeof
(
mp_map_elem_t
),
.
alloc
=
sizeof
(
time_module_globals_table
)
/
sizeof
(
mp_map_elem_t
),
.
table
=
(
mp_map_elem_t
*
)
time_module_globals_table
,
};
const
mp_obj_module_t
time_module
=
{
.
base
=
{
&
mp_type_module
},
.
name
=
MP_QSTR_time
,
.
globals
=
(
mp_map_t
*
)
&
time_module_globals
,
};
stmhal/timemodule.h
0 → 100644
View file @
d3116556
extern
const
mp_obj_module_t
time_module
;
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment