Skip to content

Commit 3ffa560

Browse files
committed
Update countio to python stub docs
1 parent 7546d47 commit 3ffa560

File tree

3 files changed

+38
-58
lines changed

3 files changed

+38
-58
lines changed

shared-bindings/busio/UART.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(busio_uart_reset_input_buffer_obj, busio_uart_o
346346
//| class Parity:
347347
//| """Enum-like class to define the parity used to verify correct data transfer."""
348348
//|
349-
//| def __init__(self, ):
350-
//| ODD: Any = ...
351-
//| """Total number of ones should be odd."""
349+
//| ODD: Any = ...
350+
//| """Total number of ones should be odd."""
352351
//|
353-
//| EVEN: Any = ...
354-
//| """Total number of ones should be even."""
355-
//| ...
352+
//| EVEN: Any = ...
353+
//| """Total number of ones should be even."""
356354
//|
357355
const mp_obj_type_t busio_uart_parity_type;
358356

shared-bindings/countio/Counter.c

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,41 @@
99
#include "shared-bindings/countio/Counter.h"
1010
#include "shared-bindings/util.h"
1111

12-
//| .. currentmodule:: countio
12+
//| class Counter:
13+
//| """Counter will keep track of the number of falling edge transistions (pulses) on a
14+
//| given pin"""
1315
//|
14-
//| :class:`Counter` -- Track the count of falling edge transistions (pulses) on a given pin
15-
//| ========================================================================================
16+
//| def __init__(self, pin_a):
17+
//| """Create a Counter object associated with the given pin. It tracks the number of
18+
//| falling pulses relative when the object is constructed.
1619
//|
17-
//| Counter will keep track of the number of falling edge transistions (pulses) on a given pin
20+
//| :param ~microcontroller.Pin pin_a: Pin to read pulses from.
1821
//|
19-
//| .. class:: Counter(pin_a)
2022
//|
21-
//| Create a Counter object associated with the given pin. It tracks the number of
22-
//| falling pulses relative when the object is constructed.
23+
//| For example::
2324
//|
24-
//| :param ~microcontroller.Pin pin_a: Pin to read pulses from.
25-
//|
25+
//| import countio
26+
//| import time
27+
//| from board import *
2628
//|
27-
//| For example::
28-
//|
29-
//| import countio
30-
//| import time
31-
//| from board import *
32-
//|
33-
//| pin_counter = countio.Counter(board.D1)
34-
//| #reset the count after 100 counts
35-
//| while True:
36-
//| if pin_counter.count == 100:
37-
//| pin_counter.reset()
38-
//| print(pin_counter.count)
29+
//| pin_counter = countio.Counter(board.D1)
30+
//| #reset the count after 100 counts
31+
//| while True:
32+
//| if pin_counter.count == 100:
33+
//| pin_counter.reset()
34+
//| print(pin_counter.count)"""
3935
//|
4036
STATIC mp_obj_t countio_counter_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
4137
enum { ARG_pin_a };
4238
static const mp_arg_t allowed_args[] = {
4339
{ MP_QSTR_pin_a, MP_ARG_REQUIRED | MP_ARG_OBJ }
44-
40+
4541
};
4642
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
4743
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
4844

4945
const mcu_pin_obj_t* pin_a = validate_obj_is_free_pin(args[ARG_pin_a].u_obj);
50-
46+
5147

5248
countio_counter_obj_t *self = m_new_obj(countio_counter_obj_t);
5349
self->base.type = &countio_counter_type;
@@ -57,9 +53,8 @@ STATIC mp_obj_t countio_counter_make_new(const mp_obj_type_t *type, size_t n_arg
5753
return MP_OBJ_FROM_PTR(self);
5854
}
5955

60-
//| .. method:: deinit()
61-
//|
62-
//| Deinitializes the Counter and releases any hardware resources for reuse.
56+
//| def deinit(self):
57+
//| """Deinitializes the Counter and releases any hardware resources for reuse."""
6358
//|
6459
STATIC mp_obj_t countio_counter_deinit(mp_obj_t self_in) {
6560
countio_counter_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -74,16 +69,14 @@ STATIC void check_for_deinit(countio_counter_obj_t *self) {
7469
}
7570
}
7671

77-
//| .. method:: __enter__()
78-
//|
79-
//| No-op used by Context Managers.
72+
//| def __enter__(self):
73+
//| """No-op used by Context Managers."""
8074
//|
8175
// Provided by context manager helper.
8276

83-
//| .. method:: __exit__()
84-
//|
85-
//| Automatically deinitializes the hardware when exiting a context. See
86-
//| :ref:`lifetime-and-contextmanagers` for more info.
77+
//| def __exit__(self):
78+
//| """Automatically deinitializes the hardware when exiting a context. See
79+
//| :ref:`lifetime-and-contextmanagers` for more info."""
8780
//|
8881
STATIC mp_obj_t countio_counter_obj___exit__(size_t n_args, const mp_obj_t *args) {
8982
(void)n_args;
@@ -93,10 +86,8 @@ STATIC mp_obj_t countio_counter_obj___exit__(size_t n_args, const mp_obj_t *args
9386
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(countio_counter___exit___obj, 4, 4, countio_counter_obj___exit__);
9487

9588

96-
//| .. attribute:: count
97-
//|
98-
//| The current count in terms of pulses.
99-
//|
89+
//| count: int = ...
90+
//| """The current count in terms of pulses."""
10091
//|
10192
STATIC mp_obj_t countio_counter_obj_get_count(mp_obj_t self_in) {
10293
countio_counter_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -122,14 +113,17 @@ const mp_obj_property_t countio_counter_count_obj = {
122113
(mp_obj_t)&mp_const_none_obj},
123114
};
124115

116+
//| def reset(self):
117+
//| """Resets the count back to 0."""
118+
//|
125119
STATIC mp_obj_t countio_counter_reset(mp_obj_t self_in){
126120
countio_counter_obj_t *self = MP_OBJ_TO_PTR(self_in);
127121
check_for_deinit(self);
128122
//set the position to zero for reset
129123
common_hal_countio_counter_reset(self);
130124
return mp_const_none;
131125
}
132-
126+
133127

134128
MP_DEFINE_CONST_FUN_OBJ_1(countio_counter_reset_obj, countio_counter_reset);
135129

shared-bindings/countio/__init__.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,10 @@
88
#include "shared-bindings/countio/__init__.h"
99
#include "shared-bindings/countio/Counter.h"
1010

11-
//| :mod:`countio` --- Support for edge counting
12-
//| ========================================================
13-
//|
14-
//| .. module:: countio
15-
//| :synopsis: Support for edge counting
16-
//| :platform: SAMD
11+
//| """Support for edge counting
1712
//|
1813
//| The `countio` module contains logic to read and count edge transistions
1914
//|
20-
//| Libraries
21-
//|
22-
//| .. toctree::
23-
//| :maxdepth: 3
24-
//|
25-
//| Counter
26-
//|
2715

2816
//| .. warning:: This module is not available in some SAMD21 (aka M0) builds. See the
2917
//| :ref:`module-support-matrix` for more info.
@@ -32,7 +20,7 @@
3220
//| All classes change hardware state and should be deinitialized when they
3321
//| are no longer needed if the program continues after use. To do so, either
3422
//| call :py:meth:`!deinit` or use a context manager. See
35-
//| :ref:`lifetime-and-contextmanagers` for more info.
23+
//| :ref:`lifetime-and-contextmanagers` for more info."""
3624
//|
3725

3826
STATIC const mp_rom_map_elem_t countio_module_globals_table[] = {

0 commit comments

Comments
 (0)