diff options
Diffstat (limited to 'shared-bindings/rtc')
| -rw-r--r-- | shared-bindings/rtc/RTC.c | 57 | ||||
| -rw-r--r-- | shared-bindings/rtc/__init__.c | 46 |
2 files changed, 44 insertions, 59 deletions
diff --git a/shared-bindings/rtc/RTC.c b/shared-bindings/rtc/RTC.c index a0e9be302..58fe308f5 100644 --- a/shared-bindings/rtc/RTC.c +++ b/shared-bindings/rtc/RTC.c @@ -36,44 +36,41 @@ #include "shared-bindings/time/__init__.h" #include "supervisor/shared/translate.h" -void MP_WEAK common_hal_rtc_get_time(timeutils_struct_time_t *tm) { - mp_raise_NotImplementedError(translate("RTC is not supported on this board")); -} - -void MP_WEAK common_hal_rtc_set_time(timeutils_struct_time_t *tm) { - mp_raise_NotImplementedError(translate("RTC is not supported on this board")); -} - -int MP_WEAK common_hal_rtc_get_calibration(void) { - return 0; -} - -void MP_WEAK common_hal_rtc_set_calibration(int calibration) { - mp_raise_NotImplementedError(translate("RTC calibration is not supported on this board")); -} - const rtc_rtc_obj_t rtc_rtc_obj = {{&rtc_rtc_type}}; -//| .. currentmodule:: rtc +//| class RTC: +//| """Real Time Clock""" //| -//| :class:`RTC` --- Real Time Clock -//| -------------------------------- +//| def __init__(self, ): +//| """This class represents the onboard Real Time Clock. It is a singleton and will always return the same instance.""" +//| ... //| -//| .. class:: RTC() -//| -//| This class represents the onboard Real Time Clock. It is a singleton and will always return the same instance. -//| -STATIC mp_obj_t rtc_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t rtc_rtc_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { // No arguments - mp_arg_check_num(n_args, n_kw, 0, 0, false); + mp_arg_check_num(n_args, kw_args, 0, 0, false); // return constant object return (mp_obj_t)&rtc_rtc_obj; } -//| .. attribute:: datetime +//| datetime: time.struct_time = ... +//| """The current date and time of the RTC as a `time.struct_time`. +//| +//| This must be set to the current date and time whenever the board loses power:: +//| +//| import rtc +//| import time +//| +//| r = rtc.RTC() +//| r.datetime = time.struct_time((2019, 5, 29, 15, 14, 15, 0, -1, -1)) +//| +//| +//| Once set, the RTC will automatically update this value as time passes. You can read this +//| property to get a snapshot of the current time:: //| -//| The date and time of the RTC. +//| current_time = r.datetime +//| print(current_time) +//| # struct_time(tm_year=2019, tm_month=5, ...)""" //| STATIC mp_obj_t rtc_rtc_obj_get_datetime(mp_obj_t self_in) { timeutils_struct_time_t tm; @@ -97,11 +94,11 @@ const mp_obj_property_t rtc_rtc_datetime_obj = { (mp_obj_t)&mp_const_none_obj}, }; -//| .. attribute:: calibration +//| calibration: int = ... +//| """The RTC calibration value as an `int`. //| -//| The RTC calibration value. //| A positive value speeds up the clock and a negative value slows it down. -//| Range and value is hardware specific, but one step is often approx. 1 ppm. +//| Range and value is hardware specific, but one step is often approximately 1 ppm.""" //| STATIC mp_obj_t rtc_rtc_obj_get_calibration(mp_obj_t self_in) { int calibration = common_hal_rtc_get_calibration(); diff --git a/shared-bindings/rtc/__init__.c b/shared-bindings/rtc/__init__.c index ac67a7131..b204d511c 100644 --- a/shared-bindings/rtc/__init__.c +++ b/shared-bindings/rtc/__init__.c @@ -31,22 +31,11 @@ #include "shared-bindings/rtc/RTC.h" #include "shared-bindings/time/__init__.h" -//| :mod:`rtc` --- Real Time Clock -//| ======================================================== +//| """Real Time Clock //| -//| .. module:: rtc -//| :synopsis: Real Time Clock -//| :platform: SAMD21 -//| -//| The `rtc` module provides support for a Real Time Clock. -//| It also backs the `time.time()` and `time.localtime()` functions using the onboard RTC if present. -//| -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| RTC +//| The `rtc` module provides support for a Real Time Clock. You can access and manage the +//| RTC using :class:`rtc.RTC`. It also backs the :func:`time.time` and :func:`time.localtime` +//| functions using the onboard RTC if present.""" //| void rtc_reset(void) { @@ -61,23 +50,22 @@ mp_obj_t rtc_get_time_source_time(void) { return struct_time_from_tm(&tm); } -//| .. function:: set_time_source(rtc) -//| -//| Sets the rtc time source used by time.localtime(). -//| The default is `rtc.RTC()`. -//| -//| Example usage:: +//| def set_time_source(rtc: Any) -> Any: +//| """Sets the RTC time source used by :func:`time.localtime`. +//| The default is :class:`rtc.RTC`, but it's useful to use this to override the +//| time source for testing purposes. For example:: //| -//| import rtc -//| import time +//| import rtc +//| import time //| -//| class RTC(object): -//| @property -//| def datetime(self): -//| return time.struct_time((2018, 3, 17, 21, 1, 47, 0, 0, 0)) +//| class RTC(object): +//| @property +//| def datetime(self): +//| return time.struct_time((2018, 3, 17, 21, 1, 47, 0, 0, 0)) //| -//| r = RTC() -//| rtc.set_time_source(r) +//| r = RTC() +//| rtc.set_time_source(r)""" +//| ... //| STATIC mp_obj_t rtc_set_time_source(mp_obj_t time_source) { MP_STATE_VM(rtc_time_source) = time_source; |
