@@ -230,13 +230,17 @@ MP_DEFINE_CONST_FUN_OBJ_2(bitbangio_spi_write_obj, bitbangio_spi_write);
230
230
//| The SPI object must be locked.
231
231
//| If the number of bytes to read is 0, nothing happens.
232
232
//|
233
- //| :param bytearray buffer: Read data into this buffer
234
- //| :param int start: Start of the slice of ``buffer`` to read into: ``buffer[start:end]``
235
- //| :param int end: End of the slice; this index is not included. If not specified, use ``len(buffer)``
236
- //| :param int write_value: Value to write while reading."""
233
+ //| If ``start`` or ``end`` is provided, then the buffer will be sliced
234
+ //| as if ``buffer[start:end]`` were passed.
235
+ //| The number of bytes read will be the length of ``buffer[start:end]``
236
+ //|
237
+ //| :param WriteableBuffer buffer: read bytes into this buffer
238
+ //| :param int start: beginning of buffer slice
239
+ //| :param int end: end of buffer slice; if not specified, use ``len(buffer)``
240
+ //| :param int write_value: value to write while reading
241
+ //| """
237
242
//| ...
238
243
//|
239
-
240
244
STATIC mp_obj_t bitbangio_spi_readinto (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
241
245
enum { ARG_buffer , ARG_start , ARG_end , ARG_write_value };
242
246
static const mp_arg_t allowed_args [] = {
@@ -270,26 +274,36 @@ STATIC mp_obj_t bitbangio_spi_readinto(size_t n_args, const mp_obj_t *pos_args,
270
274
MP_DEFINE_CONST_FUN_OBJ_KW (bitbangio_spi_readinto_obj , 1 , bitbangio_spi_readinto );
271
275
272
276
//| import sys
273
- //| def write_readinto(self, buffer_out : ReadableBuffer, buffer_in: ReadableBuffer , *, out_start: int = 0, out_end: int = sys.maxsize, in_start: int = 0, in_end: int = sys.maxsize) -> None:
274
- //| """Write out the data in ``buffer_out `` while simultaneously reading data into ``buffer_in ``.
277
+ //| def write_readinto(self, out_buffer : ReadableBuffer, in_buffer: WriteableBuffer , *, out_start: int = 0, out_end: int = sys.maxsize, in_start: int = 0, in_end: int = sys.maxsize) -> None:
278
+ //| """Write out the data in ``out_buffer `` while simultaneously reading data into ``in_buffer ``.
275
279
//| The SPI object must be locked.
276
- //| The lengths of the slices defined by ``buffer_out[out_start:out_end]`` and ``buffer_in[in_start:in_end]``
277
- //| must be equal.
280
+ //|
281
+ //| If ``out_start`` or ``out_end`` is provided, then the buffer will be sliced
282
+ //| as if ``out_buffer[out_start:out_end]`` were passed, but without copying the data.
283
+ //| The number of bytes written will be the length of ``out_buffer[out_start:out_end]``
284
+ //|
285
+ //| If ``in_start`` or ``in_end`` is provided, then the input buffer will be sliced
286
+ //| as if ``in_buffer[in_start:in_end]`` were passed,
287
+ //| The number of bytes read will be the length of ``out_buffer[in_start:in_end]``
288
+ //|
289
+ //| The lengths of the slices defined by ``out_buffer[out_start:out_end]``
290
+ //| and ``in_buffer[in_start:in_end]`` must be equal.
278
291
//| If buffer slice lengths are both 0, nothing happens.
279
292
//|
280
- //| :param ~_typing.ReadableBuffer buffer_out: Write out the data in this buffer
281
- //| :param ~_typing.WriteableBuffer buffer_in: Read data into this buffer
282
- //| :param int out_start: Start of the slice of buffer_out to write out: ``buffer_out[out_start:out_end]``
283
- //| :param int out_end: End of the slice; this index is not included. If not specified, use ``len(buffer_out)``
284
- //| :param int in_start: Start of the slice of ``buffer_in`` to read into: ``buffer_in[in_start:in_end]``
285
- //| :param int in_end: End of the slice; this index is not included. If not specified, use ``len(buffer_in)``"""
293
+ //| :param ReadableBuffer out_buffer: write out bytes from this buffer
294
+ //| :param WriteableBuffer in_buffer: read bytes into this buffer
295
+ //| :param int out_start: beginning of ``out_buffer`` slice
296
+ //| :param int out_end: end of ``out_buffer`` slice; if not specified, use ``len(out_buffer)``
297
+ //| :param int in_start: beginning of ``in_buffer`` slice
298
+ //| :param int in_end: end of ``in_buffer slice``; if not specified, use ``len(in_buffer)``
299
+ //| """
286
300
//| ...
287
301
//|
288
302
STATIC mp_obj_t bitbangio_spi_write_readinto (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
289
- enum { ARG_buffer_out , ARG_buffer_in , ARG_out_start , ARG_out_end , ARG_in_start , ARG_in_end };
303
+ enum { ARG_out_buffer , ARG_in_buffer , ARG_out_start , ARG_out_end , ARG_in_start , ARG_in_end };
290
304
static const mp_arg_t allowed_args [] = {
291
- { MP_QSTR_buffer_out , MP_ARG_REQUIRED | MP_ARG_OBJ , {.u_obj = MP_OBJ_NULL } },
292
- { MP_QSTR_buffer_in , MP_ARG_REQUIRED | MP_ARG_OBJ , {.u_obj = MP_OBJ_NULL } },
305
+ { MP_QSTR_out_buffer , MP_ARG_REQUIRED | MP_ARG_OBJ , {.u_obj = MP_OBJ_NULL } },
306
+ { MP_QSTR_in_buffer , MP_ARG_REQUIRED | MP_ARG_OBJ , {.u_obj = MP_OBJ_NULL } },
293
307
{ MP_QSTR_out_start , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 0 } },
294
308
{ MP_QSTR_out_end , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = INT_MAX } },
295
309
{ MP_QSTR_in_start , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 0 } },
@@ -303,13 +317,13 @@ STATIC mp_obj_t bitbangio_spi_write_readinto(size_t n_args, const mp_obj_t *pos_
303
317
mp_arg_parse_all (n_args - 1 , pos_args + 1 , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
304
318
305
319
mp_buffer_info_t buf_out_info ;
306
- mp_get_buffer_raise (args [ARG_buffer_out ].u_obj , & buf_out_info , MP_BUFFER_READ );
320
+ mp_get_buffer_raise (args [ARG_out_buffer ].u_obj , & buf_out_info , MP_BUFFER_READ );
307
321
int32_t out_start = args [ARG_out_start ].u_int ;
308
322
size_t out_length = buf_out_info .len ;
309
323
normalize_buffer_bounds (& out_start , args [ARG_out_end ].u_int , & out_length );
310
324
311
325
mp_buffer_info_t buf_in_info ;
312
- mp_get_buffer_raise (args [ARG_buffer_in ].u_obj , & buf_in_info , MP_BUFFER_WRITE );
326
+ mp_get_buffer_raise (args [ARG_in_buffer ].u_obj , & buf_in_info , MP_BUFFER_WRITE );
313
327
int32_t in_start = args [ARG_in_start ].u_int ;
314
328
size_t in_length = buf_in_info .len ;
315
329
normalize_buffer_bounds (& in_start , args [ARG_in_end ].u_int , & in_length );
0 commit comments