Skip to content

Commit cb259de

Browse files
committed
Did busio, fixed up analogio
1 parent 6fd6747 commit cb259de

6 files changed

Lines changed: 42 additions & 41 deletions

File tree

shared-bindings/analogio/AnalogIn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ STATIC void check_for_deinit(analogio_analogin_obj_t *self) {
8686
raise_deinited_error();
8787
}
8888
}
89-
//| def __enter__(self, ) -> None:
89+
//| def __enter__(self, ) -> AnalogIn:
9090
//| """No-op used by Context Managers."""
9191
//| ...
9292
//|

shared-bindings/analogio/AnalogOut.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ STATIC mp_obj_t analogio_analogout_deinit(mp_obj_t self_in) {
7979
}
8080
STATIC MP_DEFINE_CONST_FUN_OBJ_1(analogio_analogout_deinit_obj, analogio_analogout_deinit);
8181

82-
//| def __enter__(self, ) -> None:
82+
//| def __enter__(self, ) -> AnalogOut:
8383
//| """No-op used by Context Managers."""
8484
//| ...
8585
//|

shared-bindings/busio/I2C.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ STATIC mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, con
8383
return (mp_obj_t)self;
8484
}
8585

86-
//| def deinit(self, ) -> Any:
86+
//| def deinit(self, ) -> None:
8787
//| """Releases control of the underlying hardware so other classes can use it."""
8888
//| ...
8989
//|
@@ -100,13 +100,13 @@ STATIC void check_for_deinit(busio_i2c_obj_t *self) {
100100
}
101101
}
102102

103-
//| def __enter__(self, ) -> Any:
103+
//| def __enter__(self, ) -> I2C:
104104
//| """No-op used in Context Managers."""
105105
//| ...
106106
//|
107107
// Provided by context manager helper.
108108

109-
//| def __exit__(self, ) -> Any:
109+
//| def __exit__(self, ) -> None:
110110
//| """Automatically deinitializes the hardware on context exit. See
111111
//| :ref:`lifetime-and-contextmanagers` for more info."""
112112
//| ...
@@ -125,7 +125,7 @@ static void check_lock(busio_i2c_obj_t *self) {
125125
}
126126
}
127127

128-
//| def scan(self, ) -> Any:
128+
//| def scan(self, ) -> list:
129129
//|
130130
//| """Scan all I2C addresses between 0x08 and 0x77 inclusive and return a
131131
//| list of those that respond.
@@ -150,7 +150,7 @@ STATIC mp_obj_t busio_i2c_scan(mp_obj_t self_in) {
150150
}
151151
MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_scan_obj, busio_i2c_scan);
152152

153-
//| def try_lock(self, ) -> Any:
153+
//| def try_lock(self, ) -> bool:
154154
//| """Attempts to grab the I2C lock. Returns True on success.
155155
//|
156156
//| :return: True when lock has been grabbed
@@ -164,7 +164,7 @@ STATIC mp_obj_t busio_i2c_obj_try_lock(mp_obj_t self_in) {
164164
}
165165
MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_try_lock_obj, busio_i2c_obj_try_lock);
166166

167-
//| def unlock(self, ) -> Any:
167+
//| def unlock(self, ) -> none:
168168
//| """Releases the I2C lock."""
169169
//| ...
170170
//|
@@ -176,7 +176,7 @@ STATIC mp_obj_t busio_i2c_obj_unlock(mp_obj_t self_in) {
176176
}
177177
MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_unlock_obj, busio_i2c_obj_unlock);
178178

179-
//| def readfrom_into(self, address: int, buffer: bytearray, *, start: int = 0, end: int = None) -> Any:
179+
//| def readfrom_into(self, address: int, buffer: bytearray, *, start: int = 0, end: int = None) -> None:
180180
//| """Read into ``buffer`` from the device selected by ``address``.
181181
//| The number of bytes read will be the length of ``buffer``.
182182
//| At least one byte must be read.
@@ -228,7 +228,7 @@ STATIC mp_obj_t busio_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_args,
228228
}
229229
MP_DEFINE_CONST_FUN_OBJ_KW(busio_i2c_readfrom_into_obj, 3, busio_i2c_readfrom_into);
230230

231-
//| def writeto(self, address: int, buffer: bytearray, *, start: int = 0, end: int = None, stop: bool = True) -> Any:
231+
//| def writeto(self, address: int, buffer: bytearray, *, start: int = 0, end: int = None, stop: bool = True) -> None:
232232
//| """Write the bytes from ``buffer`` to the device selected by ``address``.
233233
//| Transmits a stop bit when stop is True. Setting stop=False is deprecated and stop will be
234234
//| removed in CircuitPython 6.x. Use `writeto_then_readfrom` when needing a write, no stop and
@@ -287,7 +287,7 @@ STATIC mp_obj_t busio_i2c_writeto(size_t n_args, const mp_obj_t *pos_args, mp_ma
287287
}
288288
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(busio_i2c_writeto_obj, 1, busio_i2c_writeto);
289289

290-
//| def writeto_then_readfrom(self, address: int, out_buffer: bytearray, in_buffer: bytearray, *, out_start: int = 0, out_end: int = None, in_start: int = 0, in_end: int = None) -> Any:
290+
//| def writeto_then_readfrom(self, address: int, out_buffer: bytearray, in_buffer: bytearray, *, out_start: int = 0, out_end: int = None, in_start: int = 0, in_end: int = None) -> None:
291291
//| """Write the bytes from ``out_buffer`` to the device selected by ``address``, generate no stop
292292
//| bit, generate a repeated start and read into ``in_buffer``. ``out_buffer`` and
293293
//| ``in_buffer`` can be the same buffer because they are used sequentially.

shared-bindings/busio/OneWire.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ STATIC mp_obj_t busio_onewire_make_new(const mp_obj_type_t *type, size_t n_args,
7777
return MP_OBJ_FROM_PTR(self);
7878
}
7979

80-
//| def deinit(self, ) -> Any:
80+
//| def deinit(self, ) -> None:
8181
//| """Deinitialize the OneWire bus and release any hardware resources for reuse."""
8282
//| ...
8383
//|
@@ -94,13 +94,13 @@ STATIC void check_for_deinit(busio_onewire_obj_t *self) {
9494
}
9595
}
9696

97-
//| def __enter__(self, ) -> Any:
97+
//| def __enter__(self, ) -> OneWire:
9898
//| """No-op used by Context Managers."""
9999
//| ...
100100
//|
101101
// Provided by context manager helper.
102102

103-
//| def __exit__(self, ) -> Any:
103+
//| def __exit__(self, ) -> None:
104104
//| """Automatically deinitializes the hardware when exiting a context. See
105105
//| :ref:`lifetime-and-contextmanagers` for more info."""
106106
//| ...
@@ -112,7 +112,7 @@ STATIC mp_obj_t busio_onewire_obj___exit__(size_t n_args, const mp_obj_t *args)
112112
}
113113
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_onewire___exit___obj, 4, 4, busio_onewire_obj___exit__);
114114

115-
//| def reset(self, ) -> Any:
115+
//| def reset(self, ) -> bool:
116116
//| """Reset the OneWire bus and read presence
117117
//|
118118
//| :returns: False when at least one device is present
@@ -127,7 +127,7 @@ STATIC mp_obj_t busio_onewire_obj_reset(mp_obj_t self_in) {
127127
}
128128
MP_DEFINE_CONST_FUN_OBJ_1(busio_onewire_reset_obj, busio_onewire_obj_reset);
129129

130-
//| def read_bit(self, ) -> Any:
130+
//| def read_bit(self, ) -> bool:
131131
//| """Read in a bit
132132
//|
133133
//| :returns: bit state read
@@ -142,7 +142,7 @@ STATIC mp_obj_t busio_onewire_obj_read_bit(mp_obj_t self_in) {
142142
}
143143
MP_DEFINE_CONST_FUN_OBJ_1(busio_onewire_read_bit_obj, busio_onewire_obj_read_bit);
144144

145-
//| def write_bit(self, value: Any) -> Any:
145+
//| def write_bit(self, value: bool) -> None:
146146
//| """Write out a bit based on value."""
147147
//| ...
148148
//|

shared-bindings/busio/SPI.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ STATIC mp_obj_t busio_spi_make_new(const mp_obj_type_t *type, size_t n_args, con
100100
return MP_OBJ_FROM_PTR(self);
101101
}
102102

103-
//| def deinit(self, ) -> Any:
103+
//| def deinit(self, ) -> None:
104104
//| """Turn off the SPI bus."""
105105
//| ...
106106
//|
@@ -111,13 +111,13 @@ STATIC mp_obj_t busio_spi_obj_deinit(mp_obj_t self_in) {
111111
}
112112
MP_DEFINE_CONST_FUN_OBJ_1(busio_spi_deinit_obj, busio_spi_obj_deinit);
113113

114-
//| def __enter__(self, ) -> Any:
114+
//| def __enter__(self, ) -> SPI:
115115
//| """No-op used by Context Managers.
116116
//| Provided by context manager helper."""
117117
//| ...
118118
//|
119119

120-
//| def __exit__(self, ) -> Any:
120+
//| def __exit__(self, ) -> None:
121121
//| """Automatically deinitializes the hardware when exiting a context. See
122122
//| :ref:`lifetime-and-contextmanagers` for more info."""
123123
//| ...
@@ -142,7 +142,7 @@ STATIC void check_for_deinit(busio_spi_obj_t *self) {
142142
}
143143
}
144144

145-
//| def configure(self, *, baudrate: int = 100000, polarity: int = 0, phase: int = 0, bits: int = 8) -> Any:
145+
//| def configure(self, *, baudrate: int = 100000, polarity: int = 0, phase: int = 0, bits: int = 8) -> None:
146146
//| """Configures the SPI bus. The SPI object must be locked.
147147
//|
148148
//| :param int baudrate: the desired clock rate in Hertz. The actual clock rate may be higher or lower
@@ -201,7 +201,7 @@ STATIC mp_obj_t busio_spi_configure(size_t n_args, const mp_obj_t *pos_args, mp_
201201
}
202202
MP_DEFINE_CONST_FUN_OBJ_KW(busio_spi_configure_obj, 1, busio_spi_configure);
203203

204-
//| def try_lock(self, ) -> Any:
204+
//| def try_lock(self, ) -> bool:
205205
//| """Attempts to grab the SPI lock. Returns True on success.
206206
//|
207207
//| :return: True when lock has been grabbed
@@ -215,7 +215,7 @@ STATIC mp_obj_t busio_spi_obj_try_lock(mp_obj_t self_in) {
215215
}
216216
MP_DEFINE_CONST_FUN_OBJ_1(busio_spi_try_lock_obj, busio_spi_obj_try_lock);
217217

218-
//| def unlock(self, ) -> Any:
218+
//| def unlock(self, ) -> None:
219219
//| """Releases the SPI lock."""
220220
//| ...
221221
//|
@@ -228,7 +228,7 @@ STATIC mp_obj_t busio_spi_obj_unlock(mp_obj_t self_in) {
228228
}
229229
MP_DEFINE_CONST_FUN_OBJ_1(busio_spi_unlock_obj, busio_spi_obj_unlock);
230230

231-
//| def write(self, buffer: bytearray, *, start: Any = 0, end: int = None) -> Any:
231+
//| def write(self, buffer: bytes, *, start: int = 0, end: int = None) -> None:
232232
//| """Write the data contained in ``buffer``. The SPI object must be locked.
233233
//| If the buffer is empty, nothing happens.
234234
//|
@@ -270,7 +270,7 @@ STATIC mp_obj_t busio_spi_write(size_t n_args, const mp_obj_t *pos_args, mp_map_
270270
MP_DEFINE_CONST_FUN_OBJ_KW(busio_spi_write_obj, 2, busio_spi_write);
271271

272272

273-
//| def readinto(self, buffer: bytearray, *, start: Any = 0, end: int = None, write_value: int = 0) -> Any:
273+
//| def readinto(self, buffer: bytearray, *, start: int = 0, end: int = None, write_value: int = 0) -> None:
274274
//| """Read into ``buffer`` while writing ``write_value`` for each byte read.
275275
//| The SPI object must be locked.
276276
//| If the number of bytes to read is 0, nothing happens.
@@ -314,7 +314,7 @@ STATIC mp_obj_t busio_spi_readinto(size_t n_args, const mp_obj_t *pos_args, mp_m
314314
}
315315
MP_DEFINE_CONST_FUN_OBJ_KW(busio_spi_readinto_obj, 2, busio_spi_readinto);
316316

317-
//| def write_readinto(self, buffer_out: bytearray, buffer_in: bytearray, *, out_start: Any = 0, out_end: int = None, in_start: Any = 0, in_end: int = None) -> Any:
317+
//| def write_readinto(self, buffer_out: bytearray, buffer_in: bytearray, *, out_start: int = 0, out_end: int = None, in_start: None = 0, in_end: int = None) -> None:
318318
//| """Write out the data in ``buffer_out`` while simultaneously reading data into ``buffer_in``.
319319
//| The SPI object must be locked.
320320
//| The lengths of the slices defined by ``buffer_out[out_start:out_end]`` and ``buffer_in[in_start:in_end]``
@@ -377,7 +377,7 @@ STATIC mp_obj_t busio_spi_write_readinto(size_t n_args, const mp_obj_t *pos_args
377377
}
378378
MP_DEFINE_CONST_FUN_OBJ_KW(busio_spi_write_readinto_obj, 2, busio_spi_write_readinto);
379379

380-
//| frequency: Any = ...
380+
//| frequency: int = ...
381381
//| """The actual SPI bus frequency. This may not match the frequency requested
382382
//| due to internal limitations."""
383383
//|

shared-bindings/busio/UART.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, co
142142
return (mp_obj_t)self;
143143
}
144144

145-
//| def deinit(self, ) -> Any:
145+
//| def deinit(self, ) -> None:
146146
//| """Deinitialises the UART and releases any hardware resources for reuse."""
147147
//| ...
148148
//|
@@ -159,13 +159,13 @@ STATIC void check_for_deinit(busio_uart_obj_t *self) {
159159
}
160160
}
161161

162-
//| def __enter__(self, ) -> Any:
162+
//| def __enter__(self, ) -> UART:
163163
//| """No-op used by Context Managers."""
164164
//| ...
165165
//|
166166
// Provided by context manager helper.
167167

168-
//| def __exit__(self, ) -> Any:
168+
//| def __exit__(self, ) -> None:
169169
//| """Automatically deinitializes the hardware when exiting a context. See
170170
//| :ref:`lifetime-and-contextmanagers` for more info."""
171171
//| ...
@@ -179,7 +179,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_uart___exit___obj, 4, 4, busio_
179179

180180
// These are standard stream methods. Code is in py/stream.c.
181181
//
182-
//| def read(self, nbytes: Any = None) -> Any:
182+
//| def read(self, nbytes: int = None) -> Optional[bytes]:
183183
//| """Read characters. If ``nbytes`` is specified then read at most that many
184184
//| bytes. Otherwise, read everything that arrives until the connection
185185
//| times out. Providing the number of bytes expected is highly recommended
@@ -190,7 +190,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_uart___exit___obj, 4, 4, busio_
190190
//| ...
191191
//|
192192

193-
//| def readinto(self, buf: Any) -> Any:
193+
//| def readinto(self, buf: bytes) -> Optional[int]:
194194
//| """Read bytes into the ``buf``. Read at most ``len(buf)`` bytes.
195195
//|
196196
//| :return: number of bytes read and stored into ``buf``
@@ -200,15 +200,15 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_uart___exit___obj, 4, 4, busio_
200200
//| ...
201201
//|
202202

203-
//| def readline(self, ) -> Any:
203+
//| def readline(self, ) -> Optional[int]:
204204
//| """Read a line, ending in a newline character.
205205
//|
206206
//| :return: the line read
207207
//| :rtype: int or None"""
208208
//| ...
209209
//|
210210

211-
//| def write(self, buf: Any) -> Any:
211+
//| def write(self, buf: bytearray) -> Optional[int]:
212212
//| """Write the buffer of bytes to the bus.
213213
//|
214214
//| *New in CircuitPython 4.0:* ``buf`` must be bytes, not a string.
@@ -261,7 +261,7 @@ STATIC mp_uint_t busio_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t
261261
return ret;
262262
}
263263

264-
//| baudrate: Any = ...
264+
//| baudrate: int = ...
265265
//| """The current baudrate."""
266266
//|
267267
STATIC mp_obj_t busio_uart_obj_get_baudrate(mp_obj_t self_in) {
@@ -287,7 +287,7 @@ const mp_obj_property_t busio_uart_baudrate_obj = {
287287
(mp_obj_t)&mp_const_none_obj},
288288
};
289289

290-
//| in_waiting: Any = ...
290+
//| in_waiting: int = ...
291291
//| """The number of bytes in the input buffer, available to be read"""
292292
//|
293293
STATIC mp_obj_t busio_uart_obj_get_in_waiting(mp_obj_t self_in) {
@@ -304,7 +304,7 @@ const mp_obj_property_t busio_uart_in_waiting_obj = {
304304
(mp_obj_t)&mp_const_none_obj},
305305
};
306306

307-
//| timeout: Any = ...
307+
//| timeout: float = ...
308308
//| """The current timeout, in seconds (float)."""
309309
//|
310310
STATIC mp_obj_t busio_uart_obj_get_timeout(mp_obj_t self_in) {
@@ -332,8 +332,9 @@ const mp_obj_property_t busio_uart_timeout_obj = {
332332
(mp_obj_t)&mp_const_none_obj},
333333
};
334334

335-
//| def reset_input_buffer(self, ) -> Any: ...
336-
//| """Discard any unread characters in the input buffer."""
335+
//| def reset_input_buffer(self, ) -> None:
336+
//| """Discard any unread characters in the input buffer."""
337+
//| ...
337338
//|
338339
STATIC mp_obj_t busio_uart_obj_reset_input_buffer(mp_obj_t self_in) {
339340
busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -346,10 +347,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(busio_uart_reset_input_buffer_obj, busio_uart_o
346347
//| class Parity:
347348
//| """Enum-like class to define the parity used to verify correct data transfer."""
348349
//|
349-
//| ODD: Any = ...
350+
//| ODD: int = ...
350351
//| """Total number of ones should be odd."""
351352
//|
352-
//| EVEN: Any = ...
353+
//| EVEN: int = ...
353354
//| """Total number of ones should be even."""
354355
//|
355356
const mp_obj_type_t busio_uart_parity_type;

0 commit comments

Comments
 (0)