Skip to content

Commit e458954

Browse files
committed
Did time, touchio, uheap
1 parent 991045b commit e458954

File tree

4 files changed

+93
-94
lines changed

4 files changed

+93
-94
lines changed

shared-bindings/time/__init__.c

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include "shared-bindings/time/__init__.h"
3737
#include "supervisor/shared/translate.h"
3838

39-
//| :mod:`time` --- time and timing related functions
39+
//| """:mod:`time` --- time and timing related functions
4040
//| ========================================================
4141
//|
4242
//| .. module:: time
@@ -45,15 +45,15 @@
4545
//|
4646
//| The `time` module is a strict subset of the CPython `cpython:time` module. So, code
4747
//| written in MicroPython will work in CPython but not necessarily the other
48-
//| way around.
48+
//| way around."""
4949
//|
50-
//| .. function:: monotonic()
50+
//| def monotonic() -> Any:
51+
//| """Returns an always increasing value of time with an unknown reference
52+
//| point. Only use it to compare against other values from `monotonic`.
5153
//|
52-
//| Returns an always increasing value of time with an unknown reference
53-
//| point. Only use it to compare against other values from `monotonic`.
54-
//|
55-
//| :return: the current monotonic time
56-
//| :rtype: float
54+
//| :return: the current monotonic time
55+
//| :rtype: float"""
56+
//| ...
5757
//|
5858
STATIC mp_obj_t time_monotonic(void) {
5959
uint64_t time64 = common_hal_time_monotonic();
@@ -62,11 +62,11 @@ STATIC mp_obj_t time_monotonic(void) {
6262
}
6363
MP_DEFINE_CONST_FUN_OBJ_0(time_monotonic_obj, time_monotonic);
6464

65-
//| .. function:: sleep(seconds)
66-
//|
67-
//| Sleep for a given number of seconds.
65+
//| def sleep(seconds: float) -> Any:
66+
//| """Sleep for a given number of seconds.
6867
//|
69-
//| :param float seconds: the time to sleep in fractional seconds
68+
//| :param float seconds: the time to sleep in fractional seconds"""
69+
//| ...
7070
//|
7171
STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) {
7272
#if MICROPY_PY_BUILTINS_FLOAT
@@ -97,21 +97,22 @@ mp_obj_t struct_time_make_new(const mp_obj_type_t *type, size_t n_args, const mp
9797
return namedtuple_make_new(type, 9, tuple->items, NULL);
9898
}
9999

100-
//| .. class:: struct_time(time_tuple)
100+
//| class struct_time:
101+
//| def __init__(self, time_tuple: Any):
102+
//| """Structure used to capture a date and time. Note that it takes a tuple!
101103
//|
102-
//| Structure used to capture a date and time. Note that it takes a tuple!
104+
//| :param tuple time_tuple: Tuple of time info: ``(tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst)``
103105
//|
104-
//| :param tuple time_tuple: Tuple of time info: ``(tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst)``
105-
//|
106-
//| * ``tm_year``: the year, 2017 for example
107-
//| * ``tm_month``: the month, range [1, 12]
108-
//| * ``tm_mday``: the day of the month, range [1, 31]
109-
//| * ``tm_hour``: the hour, range [0, 23]
110-
//| * ``tm_minute``: the minute, range [0, 59]
111-
//| * ``tm_sec``: the second, range [0, 61]
112-
//| * ``tm_wday``: the day of the week, range [0, 6], Monday is 0
113-
//| * ``tm_yday``: the day of the year, range [1, 366], -1 indicates not known
114-
//| * ``tm_isdst``: 1 when in daylight savings, 0 when not, -1 if unknown.
106+
//| * ``tm_year``: the year, 2017 for example
107+
//| * ``tm_month``: the month, range [1, 12]
108+
//| * ``tm_mday``: the day of the month, range [1, 31]
109+
//| * ``tm_hour``: the hour, range [0, 23]
110+
//| * ``tm_minute``: the minute, range [0, 59]
111+
//| * ``tm_sec``: the second, range [0, 61]
112+
//| * ``tm_wday``: the day of the week, range [0, 6], Monday is 0
113+
//| * ``tm_yday``: the day of the year, range [1, 366], -1 indicates not known
114+
//| * ``tm_isdst``: 1 when in daylight savings, 0 when not, -1 if unknown."""
115+
//| ...
115116
//|
116117
const mp_obj_namedtuple_type_t struct_time_type_obj = {
117118
.base = {
@@ -194,12 +195,12 @@ mp_obj_t MP_WEAK rtc_get_time_source_time(void) {
194195
mp_raise_RuntimeError(translate("RTC is not supported on this board"));
195196
}
196197

197-
//| .. function:: time()
198-
//|
199-
//| Return the current time in seconds since since Jan 1, 1970.
198+
//| def time() -> Any:
199+
//| """Return the current time in seconds since since Jan 1, 1970.
200200
//|
201-
//| :return: the current time
202-
//| :rtype: int
201+
//| :return: the current time
202+
//| :rtype: int"""
203+
//| ...
203204
//|
204205
STATIC mp_obj_t time_time(void) {
205206
timeutils_struct_time_t tm;
@@ -210,28 +211,28 @@ STATIC mp_obj_t time_time(void) {
210211
}
211212
MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time);
212213

213-
//| .. function:: monotonic_ns()
214+
//| def monotonic_ns() -> Any:
215+
//| """Return the time of the specified clock clk_id in nanoseconds.
214216
//|
215-
//| Return the time of the specified clock clk_id in nanoseconds.
216-
//|
217-
//| :return: the current time
218-
//| :rtype: int
217+
//| :return: the current time
218+
//| :rtype: int"""
219+
//| ...
219220
//|
220221
STATIC mp_obj_t time_monotonic_ns(void) {
221222
uint64_t time64 = common_hal_time_monotonic_ns();
222223
return mp_obj_new_int_from_ll((long long) time64);
223224
}
224225
MP_DEFINE_CONST_FUN_OBJ_0(time_monotonic_ns_obj, time_monotonic_ns);
225226

226-
//| .. function:: localtime([secs])
227-
//|
228-
//| Convert a time expressed in seconds since Jan 1, 1970 to a struct_time in
229-
//| local time. If secs is not provided or None, the current time as returned
230-
//| by time() is used.
231-
//| The earliest date for which it can generate a time is Jan 1, 2000.
227+
//| def localtime(secs: Any) -> Any:
228+
//| """Convert a time expressed in seconds since Jan 1, 1970 to a struct_time in
229+
//| local time. If secs is not provided or None, the current time as returned
230+
//| by time() is used.
231+
//| The earliest date for which it can generate a time is Jan 1, 2000.
232232
//|
233-
//| :return: the current time
234-
//| :rtype: time.struct_time
233+
//| :return: the current time
234+
//| :rtype: time.struct_time"""
235+
//| ...
235236
//|
236237
STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) {
237238
if (n_args == 0 || args[0] == mp_const_none) {
@@ -256,15 +257,15 @@ STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) {
256257
}
257258
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(time_localtime_obj, 0, 1, time_localtime);
258259

259-
//| .. function:: mktime(t)
260-
//|
261-
//| This is the inverse function of localtime(). Its argument is the
262-
//| struct_time or full 9-tuple (since the dst flag is needed; use -1 as the
263-
//| dst flag if it is unknown) which expresses the time in local time, not UTC.
264-
//| The earliest date for which it can generate a time is Jan 1, 2000.
260+
//| def mktime(t: Any) -> Any:
261+
//| """This is the inverse function of localtime(). Its argument is the
262+
//| struct_time or full 9-tuple (since the dst flag is needed; use -1 as the
263+
//| dst flag if it is unknown) which expresses the time in local time, not UTC.
264+
//| The earliest date for which it can generate a time is Jan 1, 2000.
265265
//|
266-
//| :return: seconds
267-
//| :rtype: int
266+
//| :return: seconds
267+
//| :rtype: int"""
268+
//| ...
268269
//|
269270
STATIC mp_obj_t time_mktime(mp_obj_t t) {
270271
mp_obj_t *elem;

shared-bindings/touchio/TouchIn.c

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,28 @@
3838
#include "shared-bindings/util.h"
3939
#include "supervisor/shared/translate.h"
4040

41-
//| .. currentmodule:: touchio
41+
//| class TouchIn:
42+
//| """.. currentmodule:: touchio
4243
//|
43-
//| :class:`TouchIn` -- Read the state of a capacitive touch sensor
44-
//| ===================================================================
44+
//| :class:`TouchIn` -- Read the state of a capacitive touch sensor
45+
//| ===================================================================
4546
//|
46-
//| Usage::
47+
//| Usage::
4748
//|
48-
//| import touchio
49-
//| from board import *
49+
//| import touchio
50+
//| from board import *
5051
//|
51-
//| touch = touchio.TouchIn(A1)
52-
//| while True:
53-
//| if touch.value:
54-
//| print("touched!")
52+
//| touch = touchio.TouchIn(A1)
53+
//| while True:
54+
//| if touch.value:
55+
//| print("touched!")"""
5556
//|
5657

57-
//| .. class:: TouchIn(pin)
58+
//| def __init__(self, pin: microcontroller.Pin):
59+
//| """Use the TouchIn on the given pin.
5860
//|
59-
//| Use the TouchIn on the given pin.
60-
//|
61-
//| :param ~microcontroller.Pin pin: the pin to read from
61+
//| :param ~microcontroller.Pin pin: the pin to read from"""
62+
//| ...
6263
//|
6364
STATIC mp_obj_t touchio_touchin_make_new(const mp_obj_type_t *type,
6465
mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
@@ -75,9 +76,9 @@ STATIC mp_obj_t touchio_touchin_make_new(const mp_obj_type_t *type,
7576
return (mp_obj_t) self;
7677
}
7778

78-
//| .. method:: deinit()
79-
//|
80-
//| Deinitialises the TouchIn and releases any hardware resources for reuse.
79+
//| def deinit(self, ) -> Any:
80+
//| """Deinitialises the TouchIn and releases any hardware resources for reuse."""
81+
//| ...
8182
//|
8283
STATIC mp_obj_t touchio_touchin_deinit(mp_obj_t self_in) {
8384
touchio_touchin_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -92,16 +93,16 @@ STATIC void check_for_deinit(touchio_touchin_obj_t *self) {
9293
}
9394
}
9495

95-
//| .. method:: __enter__()
96-
//|
97-
//| No-op used by Context Managers.
96+
//| def __enter__(self, ) -> Any:
97+
//| """No-op used by Context Managers."""
98+
//| ...
9899
//|
99100
// Provided by context manager helper.
100101

101-
//| .. method:: __exit__()
102-
//|
103-
//| Automatically deinitializes the hardware when exiting a context. See
104-
//| :ref:`lifetime-and-contextmanagers` for more info.
102+
//| def __exit__(self, ) -> Any:
103+
//| """Automatically deinitializes the hardware when exiting a context. See
104+
//| :ref:`lifetime-and-contextmanagers` for more info."""
105+
//| ...
105106
//|
106107
STATIC mp_obj_t touchio_touchin_obj___exit__(size_t n_args, const mp_obj_t *args) {
107108
(void)n_args;
@@ -110,11 +111,10 @@ STATIC mp_obj_t touchio_touchin_obj___exit__(size_t n_args, const mp_obj_t *args
110111
}
111112
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(touchio_touchin___exit___obj, 4, 4, touchio_touchin_obj___exit__);
112113

113-
//| .. attribute:: value
114+
//| value: Any = ...
115+
//| """Whether the touch pad is being touched or not. (read-only)
114116
//|
115-
//| Whether the touch pad is being touched or not. (read-only)
116-
//|
117-
//| True when `raw_value` > `threshold`.
117+
//| True when `raw_value` > `threshold`."""
118118
//|
119119
STATIC mp_obj_t touchio_touchin_obj_get_value(mp_obj_t self_in) {
120120
touchio_touchin_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -131,9 +131,8 @@ const mp_obj_property_t touchio_touchin_value_obj = {
131131
};
132132

133133

134-
//| .. attribute:: raw_value
135-
//|
136-
//| The raw touch measurement as an `int`. (read-only)
134+
//| raw_value: Any = ...
135+
//| """The raw touch measurement as an `int`. (read-only)"""
137136
//|
138137
STATIC mp_obj_t touchio_touchin_obj_get_raw_value(mp_obj_t self_in) {
139138
touchio_touchin_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -151,14 +150,13 @@ const mp_obj_property_t touchio_touchin_raw_value_obj = {
151150
};
152151

153152

154-
//| .. attribute:: threshold
155-
//|
156-
//| Minimum `raw_value` needed to detect a touch (and for `value` to be `True`).
153+
//| threshold: Any = ...
154+
//| """Minimum `raw_value` needed to detect a touch (and for `value` to be `True`).
157155
//|
158156
//| When the **TouchIn** object is created, an initial `raw_value` is read from the pin,
159157
//| and then `threshold` is set to be 100 + that value.
160158
//|
161-
//| You can adjust `threshold` to make the pin more or less sensitive.
159+
//| You can adjust `threshold` to make the pin more or less sensitive."""
162160
//|
163161
STATIC mp_obj_t touchio_touchin_obj_get_threshold(mp_obj_t self_in) {
164162
touchio_touchin_obj_t *self = MP_OBJ_TO_PTR(self_in);

shared-bindings/touchio/__init__.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
#include "py/runtime.h"
3737

38-
//| :mod:`touchio` --- Touch related IO
38+
//| """:mod:`touchio` --- Touch related IO
3939
//| =================================================
4040
//|
4141
//| .. module:: touchio
@@ -66,7 +66,7 @@
6666
//| print(touch_pin.value)
6767
//|
6868
//| This example will initialize the the device, and print the
69-
//| :py:data:`~touchio.TouchIn.value`.
69+
//| :py:data:`~touchio.TouchIn.value`."""
7070
//|
7171

7272
STATIC const mp_rom_map_elem_t touchio_module_globals_table[] = {

shared-bindings/uheap/__init__.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@
3131

3232
#include "shared-bindings/uheap/__init__.h"
3333

34-
//| :mod:`uheap` --- Heap size analysis
34+
//| """:mod:`uheap` --- Heap size analysis
3535
//| ================================================================
3636
//|
3737
//| .. module:: uheap
38-
//| :synopsis: Heap size analysis
38+
//| :synopsis: Heap size analysis"""
3939
//|
4040

41-
//| .. function:: info(object)
42-
//|
43-
//| Prints memory debugging info for the given object and returns the
44-
//| estimated size.
41+
//| def info(object: Any) -> Any:
42+
//| """Prints memory debugging info for the given object and returns the
43+
//| estimated size."""
44+
//| ...
4545
//|
4646
STATIC mp_obj_t uheap_info(mp_obj_t obj) {
4747
uint32_t size = shared_module_uheap_info(obj);

0 commit comments

Comments
 (0)