Skip to content

Commit 7070fe1

Browse files
committed
Added inline pyi to UART.c
1 parent 28430a9 commit 7070fe1

1 file changed

Lines changed: 88 additions & 93 deletions

File tree

shared-bindings/busio/UART.c

Lines changed: 88 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -40,33 +40,32 @@
4040
#include "supervisor/shared/translate.h"
4141

4242

43-
//| .. currentmodule:: busio
44-
//|
45-
//| :class:`UART` -- a bidirectional serial protocol
46-
//| =================================================
47-
//|
48-
//|
49-
//| .. class:: UART(tx, rx, *, baudrate=9600, bits=8, parity=None, stop=1, timeout=1, receiver_buffer_size=64)
50-
//|
51-
//| A common bidirectional serial protocol that uses an an agreed upon speed
52-
//| rather than a shared clock line.
53-
//|
54-
//| :param ~microcontroller.Pin tx: the pin to transmit with, or ``None`` if this ``UART`` is receive-only.
55-
//| :param ~microcontroller.Pin rx: the pin to receive on, or ``None`` if this ``UART`` is transmit-only.
56-
//| :param ~microcontroller.Pin rts: the pin for rts, or ``None`` if rts not in use.
57-
//| :param ~microcontroller.Pin cts: the pin for cts, or ``None`` if cts not in use.
58-
//| :param ~microcontroller.Pin rs485_dir: the pin for rs485 direction setting, or ``None`` if rs485 not in use.
59-
//| :param bool rs485_invert: set to invert the sense of the rs485_dir pin.
60-
//| :param int baudrate: the transmit and receive speed.
61-
//| :param int bits: the number of bits per byte, 7, 8 or 9.
62-
//| :param Parity parity: the parity used for error checking.
63-
//| :param int stop: the number of stop bits, 1 or 2.
64-
//| :param float timeout: the timeout in seconds to wait for the first character and between subsequent characters when reading. Raises ``ValueError`` if timeout >100 seconds.
65-
//| :param int receiver_buffer_size: the character length of the read buffer (0 to disable). (When a character is 9 bits the buffer will be 2 * receiver_buffer_size bytes.)
66-
//|
67-
//| *New in CircuitPython 4.0:* ``timeout`` has incompatibly changed units from milliseconds to seconds.
68-
//| The new upper limit on ``timeout`` is meant to catch mistaken use of milliseconds.
69-
//|
43+
44+
//|class UART:
45+
//| """.. currentmodule:: busio
46+
//|
47+
//| :class:`UART` -- a bidirectional serial protocol
48+
//| ================================================="""
49+
//| def __init__(self, tx: microcontroller.Pin, rx: microcontroller.Pin, *, baudrate: int = 9600, bits: int = 8, parity: Parity = None, stop: int = 1, timeout: float = 1, receiver_buffer_size: int = 64):
50+
//| """A common bidirectional serial protocol that uses an an agreed upon speed
51+
//| rather than a shared clock line.
52+
//|
53+
//| :param ~microcontroller.Pin tx: the pin to transmit with, or ``None`` if this ``UART`` is receive-only.
54+
//| :param ~microcontroller.Pin rx: the pin to receive on, or ``None`` if this ``UART`` is transmit-only.
55+
//| :param ~microcontroller.Pin rts: the pin for rts, or ``None`` if rts not in use.
56+
//| :param ~microcontroller.Pin cts: the pin for cts, or ``None`` if cts not in use.
57+
//| :param ~microcontroller.Pin rs485_dir: the pin for rs485 direction setting, or ``None`` if rs485 not in use.
58+
//| :param bool rs485_invert: set to invert the sense of the rs485_dir pin.
59+
//| :param int baudrate: the transmit and receive speed.
60+
//| :param int bits: the number of bits per byte, 7, 8 or 9.
61+
//| :param Parity parity: the parity used for error checking.
62+
//| :param int stop: the number of stop bits, 1 or 2.
63+
//| :param float timeout: the timeout in seconds to wait for the first character and between subsequent characters when reading. Raises ``ValueError`` if timeout >100 seconds.
64+
//| :param int receiver_buffer_size: the character length of the read buffer (0 to disable). (When a character is 9 bits the buffer will be 2 * receiver_buffer_size bytes.)
65+
//|
66+
//| *New in CircuitPython 4.0:* ``timeout`` has incompatibly changed units from milliseconds to seconds.
67+
//| The new upper limit on ``timeout`` is meant to catch mistaken use of milliseconds."""
68+
//| ...
7069
typedef struct {
7170
mp_obj_base_t base;
7271
} busio_uart_parity_obj_t;
@@ -144,10 +143,9 @@ STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, co
144143
return (mp_obj_t)self;
145144
}
146145

147-
//| .. method:: deinit()
148-
//|
149-
//| Deinitialises the UART and releases any hardware resources for reuse.
150-
//|
146+
//| def deinit(self, ) -> Any:
147+
//| """Deinitialises the UART and releases any hardware resources for reuse."""
148+
//| ...
151149
STATIC mp_obj_t busio_uart_obj_deinit(mp_obj_t self_in) {
152150
busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
153151
common_hal_busio_uart_deinit(self);
@@ -161,17 +159,15 @@ STATIC void check_for_deinit(busio_uart_obj_t *self) {
161159
}
162160
}
163161

164-
//| .. method:: __enter__()
165-
//|
166-
//| No-op used by Context Managers.
167-
//|
162+
//| def __enter__(self, ) -> Any:
163+
//| """No-op used by Context Managers."""
164+
//| ...
168165
// Provided by context manager helper.
169166

170-
//| .. method:: __exit__()
171-
//|
172-
//| Automatically deinitializes the hardware when exiting a context. See
173-
//| :ref:`lifetime-and-contextmanagers` for more info.
174-
//|
167+
//| def __exit__(self, ) -> Any:
168+
//| """Automatically deinitializes the hardware when exiting a context. See
169+
//| :ref:`lifetime-and-contextmanagers` for more info."""
170+
//| ...
175171
STATIC mp_obj_t busio_uart_obj___exit__(size_t n_args, const mp_obj_t *args) {
176172
(void)n_args;
177173
common_hal_busio_uart_deinit(args[0]);
@@ -181,41 +177,46 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_uart___exit___obj, 4, 4, busio_
181177

182178
// These are standard stream methods. Code is in py/stream.c.
183179
//
184-
//| .. method:: read(nbytes=None)
185-
//|
186-
//| Read characters. If ``nbytes`` is specified then read at most that many
187-
//| bytes. Otherwise, read everything that arrives until the connection
188-
//| times out. Providing the number of bytes expected is highly recommended
189-
//| because it will be faster.
180+
//| def read(self, nbytes: Any = None) -> Any:
181+
//| """Read characters. If ``nbytes`` is specified then read at most that many
182+
//| bytes. Otherwise, read everything that arrives until the connection
183+
//| times out. Providing the number of bytes expected is highly recommended
184+
//| because it will be faster.
190185
//|
191-
//| :return: Data read
192-
//| :rtype: bytes or None
193-
//|
194-
//| .. method:: readinto(buf)
186+
//| :return: Data read
187+
//| :rtype: bytes or None"""
188+
//| ...
189+
190+
//| def readinto(self, buf: Any) -> Any:
191+
//| """.. method:: readinto(buf)
195192
//|
196-
//| Read bytes into the ``buf``. Read at most ``len(buf)`` bytes.
193+
//| Read bytes into the ``buf``. Read at most ``len(buf)`` bytes.
197194
//|
198-
//| :return: number of bytes read and stored into ``buf``
199-
//| :rtype: int or None (on a non-blocking error)
195+
//| :return: number of bytes read and stored into ``buf``
196+
//| :rtype: int or None (on a non-blocking error)
200197
//|
201-
//| *New in CircuitPython 4.0:* No length parameter is permitted.
198+
//| *New in CircuitPython 4.0:* No length parameter is permitted."""
199+
//| ...
202200

203-
//| .. method:: readline()
201+
//| def readline(self, ) -> Any:
202+
//| """.. method:: readline()
204203
//|
205-
//| Read a line, ending in a newline character.
204+
//| Read a line, ending in a newline character.
206205
//|
207-
//| :return: the line read
208-
//| :rtype: int or None
209-
//|
210-
//| .. method:: write(buf)
211-
//|
212-
//| Write the buffer of bytes to the bus.
206+
//| :return: the line read
207+
//| :rtype: int or None"""
208+
//| ...
209+
210+
//| def write(self, buf: Any) -> Any:
211+
//| """.. method:: write(buf)
213212
//|
214-
//| *New in CircuitPython 4.0:* ``buf`` must be bytes, not a string.
213+
//| Write the buffer of bytes to the bus.
215214
//|
216-
//| :return: the number of bytes written
217-
//| :rtype: int or None
215+
//| *New in CircuitPython 4.0:* ``buf`` must be bytes, not a string.
218216
//|
217+
//| :return: the number of bytes written
218+
//| :rtype: int or None"""
219+
//| ...
219220

220221
// These three methods are used by the shared stream methods.
221222
STATIC mp_uint_t busio_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) {
@@ -259,10 +260,9 @@ STATIC mp_uint_t busio_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t
259260
return ret;
260261
}
261262

262-
//| .. attribute:: baudrate
263-
//|
264-
//| The current baudrate.
265-
//|
263+
//| baudrate: Any =
264+
//| """The current baudrate."""
265+
//| ...
266266
STATIC mp_obj_t busio_uart_obj_get_baudrate(mp_obj_t self_in) {
267267
busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
268268
check_for_deinit(self);
@@ -286,10 +286,9 @@ const mp_obj_property_t busio_uart_baudrate_obj = {
286286
(mp_obj_t)&mp_const_none_obj},
287287
};
288288

289-
//| .. attribute:: in_waiting
290-
//|
291-
//| The number of bytes in the input buffer, available to be read
292-
//|
289+
//| in_waiting: Any =
290+
//| """The number of bytes in the input buffer, available to be read"""
291+
//| ...
293292
STATIC mp_obj_t busio_uart_obj_get_in_waiting(mp_obj_t self_in) {
294293
busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
295294
check_for_deinit(self);
@@ -304,10 +303,9 @@ const mp_obj_property_t busio_uart_in_waiting_obj = {
304303
(mp_obj_t)&mp_const_none_obj},
305304
};
306305

307-
//| .. attribute:: timeout
308-
//|
309-
//| The current timeout, in seconds (float).
310-
//|
306+
//| timeout: Any =
307+
//| """The current timeout, in seconds (float)."""
308+
//| ...
311309
STATIC mp_obj_t busio_uart_obj_get_timeout(mp_obj_t self_in) {
312310
busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
313311
check_for_deinit(self);
@@ -333,10 +331,9 @@ const mp_obj_property_t busio_uart_timeout_obj = {
333331
(mp_obj_t)&mp_const_none_obj},
334332
};
335333

336-
//| .. method:: reset_input_buffer()
337-
//|
338-
//| Discard any unread characters in the input buffer.
339-
//|
334+
//| def reset_input_buffer(self, ) -> Any:
335+
//| """Discard any unread characters in the input buffer."""
336+
//| ...
340337
STATIC mp_obj_t busio_uart_obj_reset_input_buffer(mp_obj_t self_in) {
341338
busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
342339
check_for_deinit(self);
@@ -345,18 +342,16 @@ STATIC mp_obj_t busio_uart_obj_reset_input_buffer(mp_obj_t self_in) {
345342
}
346343
STATIC MP_DEFINE_CONST_FUN_OBJ_1(busio_uart_reset_input_buffer_obj, busio_uart_obj_reset_input_buffer);
347344

348-
//| .. class:: busio.UART.Parity()
349-
//|
350-
//| Enum-like class to define the parity used to verify correct data transfer.
351-
//|
352-
//| .. data:: ODD
353-
//|
354-
//| Total number of ones should be odd.
355-
//|
356-
//| .. data:: EVEN
357-
//|
358-
//| Total number of ones should be even.
359-
//|
345+
//|class busio:
346+
//| def __init__(self, ):
347+
//| """Enum-like class to define the parity used to verify correct data transfer."""
348+
//| ODD: Any =
349+
//| """Total number of ones should be odd."""
350+
//| ...
351+
//| EVEN: Any =
352+
//| """Total number of ones should be even."""
353+
//| ...
354+
//| ...
360355
const mp_obj_type_t busio_uart_parity_type;
361356

362357
const busio_uart_parity_obj_t busio_uart_parity_odd_obj = {

0 commit comments

Comments
 (0)