Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Woazboat
firmware
Commits
3efbab13
Verified
Commit
3efbab13
authored
5 years ago
by
fpletz
Browse files
Options
Downloads
Patches
Plain Diff
feat(utime.c): add python functions to set time
parent
38f83243
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Documentation/pycardium/utime.rst
+12
-1
12 additions, 1 deletion
Documentation/pycardium/utime.rst
pycardium/modules/qstrdefs.h
+2
-0
2 additions, 0 deletions
pycardium/modules/qstrdefs.h
pycardium/modules/utime.c
+20
-0
20 additions, 0 deletions
pycardium/modules/utime.c
with
34 additions
and
1 deletion
Documentation/pycardium/utime.rst
+
12
−
1
View file @
3efbab13
...
...
@@ -25,7 +25,18 @@ alarm.
.. py:function:: utime.time()
Return the current timestamp in seconds since 2000-01-01
Return the current timestamp in seconds since 2000-01-01 00:00.
.. py:function:: utime.set_time(secs)
Sets the time to ``secs`` seconds since 2000-01-01 00:00.
.. py:function:: utime.set_unix_time(secs)
Sets the time to ``secs`` seconds since 1970-01-01 00:00 UTC.
This corresponds a regular Unix timestamp which can be obtained
by running ``date +%s`` in a command line or ``int(time.time())``
in Python.
.. py:function:: utime.localtime([secs])
...
...
This diff is collapsed.
Click to expand it.
pycardium/modules/qstrdefs.h
+
2
−
0
View file @
3efbab13
...
...
@@ -47,6 +47,8 @@ Q(ticks_diff)
Q
(
localtime
)
Q
(
mktime
)
Q
(
time
)
Q
(
set_time
)
Q
(
set_unix_time
)
/* vibra */
Q
(
vibra
)
...
...
This diff is collapsed.
Click to expand it.
pycardium/modules/utime.c
+
20
−
0
View file @
3efbab13
...
...
@@ -16,6 +16,23 @@
/* MicroPython has its epoch at 2000-01-01. Our RTC is in UTC */
#define EPOCH_OFFSET 946684800UL
static
mp_obj_t
time_set_time
(
mp_obj_t
secs
)
{
uint64_t
timestamp
=
mp_obj_get_int
(
secs
)
*
1000ULL
+
EPOCH_OFFSET
*
1000ULL
;
epic_rtc_set_milliseconds
(
timestamp
);
return
mp_const_none
;
}
static
MP_DEFINE_CONST_FUN_OBJ_1
(
time_set_time_obj
,
time_set_time
);
static
mp_obj_t
time_set_unix_time
(
mp_obj_t
secs
)
{
uint64_t
timestamp
=
mp_obj_get_int
(
secs
)
*
1000ULL
;
epic_rtc_set_milliseconds
(
timestamp
);
return
mp_const_none
;
}
static
MP_DEFINE_CONST_FUN_OBJ_1
(
time_set_unix_time_obj
,
time_set_unix_time
);
static
mp_obj_t
time_time
(
void
)
{
mp_int_t
seconds
;
...
...
@@ -101,6 +118,9 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(time_alarm_obj, 1, 2, time_alarm);
static
const
mp_rom_map_elem_t
time_module_globals_table
[]
=
{
{
MP_ROM_QSTR
(
MP_QSTR___name__
),
MP_ROM_QSTR
(
MP_QSTR_utime
)
},
{
MP_ROM_QSTR
(
MP_QSTR_time
),
MP_ROM_PTR
(
&
time_time_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_set_time
),
MP_ROM_PTR
(
&
time_set_time_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_set_unix_time
),
MP_ROM_PTR
(
&
time_set_unix_time_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_localtime
),
MP_ROM_PTR
(
&
time_localtime_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_mktime
),
MP_ROM_PTR
(
&
time_mktime_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_sleep
),
MP_ROM_PTR
(
&
mp_utime_sleep_obj
)
},
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment