8000 Merge pull request #2242 from theacodes/fix-1563 · tannewt/circuitpython@0192268 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0192268

Browse files
authored
Merge pull request micropython#2242 from theacodes/fix-1563
Improve documentation for `rtc`.
2 parents 855de94 + 4a55c48 commit 0192268

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

shared-bindings/rtc/RTC.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,23 @@ STATIC mp_obj_t rtc_rtc_make_new(const mp_obj_type_t *type, size_t n_args, const
5757

5858
//| .. attribute:: datetime
5959
//|
60-
//| The date and time of the RTC.
60+
//| The current date and time of the RTC as a `time.struct_time`.
61+
//|
62+
//| This must be set to the current date and time whenever the board loses power::
63+
//|
64+
//| import rtc
65+
//| import time
66+
//|
67+
//| r = rtc.RTC()
68+
//| r.datetime = rtctime.struct_time((2019, 5, 29, 15, 14, 15, 0, -1, -1))
69+
//|
70+
//|
71+
//| Once set, the RTC will automatically update this value as time passes. You can read this
72+
//| property to get a snapshot of the current time::
73+
//|
74+
//| current_time = r.datetime
75+
//| print(current_time)
76+
//| # struct_time(tm_year=2019, tm_month=5, ...)
6177
//|
6278
STATIC mp_obj_t rtc_rtc_obj_get_datetime(mp_obj_t self_in) {
6379
timeutils_struct_time_t tm;
@@ -83,9 +99,10 @@ const mp_obj_property_t rtc_rtc_datetime_obj = {
8399

84100
//| .. attribute:: calibration
85101
//|
86-
//| The RTC calibration value.
102+
//| The RTC calibration value as an `int`.
103+
//|
87104
//| A positive value speeds up the clock and a negative value slows it down.
88-
//| Range and value is hardware specific, but one step is often approx. 1 ppm.
105+
//| Range and value is hardware specific, but one step is often approximately 1 ppm.
89106
//|
90107
STATIC mp_obj_t rtc_rtc_obj_get_calibration(mp_obj_t self_in) {
91108
int calibration = common_hal_rtc_get_calibration();

shared-bindings/rtc/__init__.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@
3636
//|
3737
//| .. module:: rtc
3838
//| :synopsis: Real Time Clock
39-
//| :platform: SAMD21
39+
//| :platform: SAMD21, SAMD51, nRF52
4040
//|
41-
//| The `rtc` module provides support for a Real Time Clock.
42-
//| It also backs the `time.time()` and `time.localtime()` functions using the onboard RTC if present.
41+
//| The `rtc` module provides support for a Real Time Clock. You can access and manage the
42+
//| RTC using :class:`rtc.RTC`. It also backs the :func:`time.time` and :func:`time.localtime`
43+
//| functions using the onboard RTC if present.
4344
//|
44-
//| Libraries
45+
//| Classes
4546
//|
4647
//| .. toctree::
4748
//| :maxdepth: 3
@@ -63,10 +64,9 @@ mp_obj_t rtc_get_time_source_time(void) {
6364

6465
//| .. function:: set_time_source(rtc)
6566
//|
66-
//| Sets the rtc time source used by time.localtime().
67-
//| The default is `rtc.RTC()`.
68-
//|
69-
//| Example usage::
67+
//| Sets the RTC time source used by :func:`time.localtime`.
68+
//| The default is :class:`rtc.RTC`, but it's useful to use this to override the
69+
//| time source for testing purposes. For example::
7070
//|
7171
//| import rtc
7272
//| import time

0 commit comments

Comments
 (0)
0