@@ -469,145 +469,6 @@ MP_DEFINE_CONST_FUN_OBJ_1(busio_spi_get_frequency_obj, busio_spi_obj_get_frequen
469469MP_PROPERTY_GETTER (busio_spi_frequency_obj ,
470470 (mp_obj_t )& busio_spi_get_frequency_obj );
471471
472- #if CIRCUITPY_SAMD
473-
474- //| import sys
475- //| def async_transfer_start(
476- //| self,
477- //| out_buffer: ReadableBuffer,
478- //| in_buffer: WriteableBuffer,
479- //| *,
480- //| out_start: int = 0,
481- //| out_end: int = sys.maxsize,
482- //| in_start: int = 0,
483- //| in_end: int = sys.maxsize
484- //| ) -> None:
485- //| """Write out the data in ``out_buffer`` while simultaneously reading data into ``in_buffer``.
486- //| The SPI object must be locked. Note: this method returns immediately, and the data will not
487- //| actually be transferred until some time has passed. Use `async_transfer_finished` and
488- //| `async_transfer_end` to check on the status of the transfer and close out its resources.
489- //|
490- //| If ``out_start`` or ``out_end`` is provided, then the buffer will be sliced
491- //| as if ``out_buffer[out_start:out_end]`` were passed, but without copying the data.
492- //| The number of bytes written will be the length of ``out_buffer[out_start:out_end]``.
493- //|
494- //| If ``in_start`` or ``in_end`` is provided, then the input buffer will be sliced
495- //| as if ``in_buffer[in_start:in_end]`` were passed,
496- //| The number of bytes read will be the length of ``out_buffer[in_start:in_end]``.
497- //|
498- //| The lengths of the slices defined by ``out_buffer[out_start:out_end]``
499- //| and ``in_buffer[in_start:in_end]`` must be equal.
500- //| If buffer slice lengths are both 0, nothing happens.
501- //|
502- //| Note: This method is currently only available on atmel-samd` ports of CircuitPython.
503- //|
504- //| :param ReadableBuffer out_buffer: write out bytes from this buffer
505- //| :param WriteableBuffer in_buffer: read bytes into this buffer
506- //| :param int out_start: beginning of ``out_buffer`` slice
507- //| :param int out_end: end of ``out_buffer`` slice; if not specified, use ``len(out_buffer)``
508- //| :param int in_start: beginning of ``in_buffer`` slice
509- //| :param int in_end: end of ``in_buffer slice``; if not specified, use ``len(in_buffer)``
510- //| """
511- //| ...
512-
513- STATIC mp_obj_t busio_spi_start_async_transfer (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
514- enum { ARG_out_buffer , ARG_in_buffer , ARG_out_start , ARG_out_end , ARG_in_start , ARG_in_end };
515- static const mp_arg_t allowed_args [] = {
516- { MP_QSTR_out_buffer , MP_ARG_REQUIRED | MP_ARG_OBJ , {.u_obj = MP_OBJ_NULL } },
517- { MP_QSTR_in_buffer , MP_ARG_REQUIRED | MP_ARG_OBJ , {.u_obj = MP_OBJ_NULL } },
518- { MP_QSTR_out_start , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 0 } },
519- { MP_QSTR_out_end , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = INT_MAX } },
520- { MP_QSTR_in_start , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 0 } },
521- { MP_QSTR_in_end , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = INT_MAX } },
522- };
523- busio_spi_obj_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
524- check_for_deinit (self );
525- check_lock (self );
526- mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
527- mp_arg_parse_all (n_args - 1 , pos_args + 1 , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
528-
529- mp_buffer_info_t buf_out_info ;
530- mp_get_buffer_raise (args [ARG_out_buffer ].u_obj , & buf_out_info , MP_BUFFER_READ );
531- int out_stride_in_bytes = mp_binary_get_size ('@' , buf_out_info .typecode , NULL );
532- int32_t out_start = args [ARG_out_start ].u_int ;
533- size_t out_length = buf_out_info .len / out_stride_in_bytes ;
534- normalize_buffer_bounds (& out_start , args [ARG_out_end ].u_int , & out_length );
535-
536- mp_buffer_info_t buf_in_info ;
537- mp_get_buffer_raise (args [ARG_in_buffer ].u_obj , & buf_in_info , MP_BUFFER_WRITE );
538- int in_stride_in_bytes = mp_binary_get_size ('@' , buf_in_info .typecode , NULL );
539- int32_t in_start = args [ARG_in_start ].u_int ;
540- size_t in_length = buf_in_info .len / in_stride_in_bytes ;
541- normalize_buffer_bounds (& in_start , args [ARG_in_end ].u_int , & in_length );
542-
543- // Treat start and length in terms of bytes from now on.
544- out_start *= out_stride_in_bytes ;
545- out_length *= out_stride_in_bytes ;
546- in_start *= in_stride_in_bytes ;
547- in_length *= in_stride_in_bytes ;
548-
549- if (out_length != in_length ) {
550- mp_raise_ValueError (MP_ERROR_TEXT ("buffer slices must be of equal length" ));
551- }
552-
553- common_hal_busio_spi_transfer_async_start (self ,
554- ((uint8_t * )buf_out_info .buf ) + out_start ,
555- ((uint8_t * )buf_in_info .buf ) + in_start ,
556- out_length );
557- return mp_const_none ;
558- }
559- MP_DEFINE_CONST_FUN_OBJ_KW (busio_spi_start_transfer_obj , 1 , busio_spi_start_async_transfer );
560-
561- //| import sys
562- //| def async_transfer_finished(
563- //| self
564- //| ) -> None:
565- //| """Check whether or not the last async transfer started on this SPI object has finished. If
566- //| no transfer was started, this method behaves as though the most recent transfer has finished
567- //| and returns `True`. Otherwise, it returns `False`.
568- //|
569- //| Note: This method is currently only available on atmel-samd` ports of CircuitPython.
570- //| """
571- //| ...
572- STATIC mp_obj_t busio_spi_obj_check_async_transfer (mp_obj_t self_in ) {
573- busio_spi_obj_t * self = MP_OBJ_TO_PTR (self_in );
574- check_for_deinit (self );
575- return common_hal_busio_spi_transfer_async_check (self ) ? mp_const_true : mp_const_false ;
576- }
577- MP_DEFINE_CONST_FUN_OBJ_1 (busio_spi_check_transfer_obj , busio_spi_obj_check_async_transfer );
578-
579- //| import sys
580- //| def async_transfer_end(
581- //| self
582- //| ) -> None:
583- //| """Return the status code with which the last async transfer on this SPI object completed. This
584- //| method MUST be called for all transfers, regardless of user interest in status code. The resources
585- //| for the transfer will be left open until this method is called. Once this method is called, the
586- //| peripheral resets and is ready for another transfer. The return code of this method also resets to
587- //| its pre-transfer state: repeated calls to this method may produce different codes.
588- //|
589- //| Return code 0: No transfer has occured, either because `start_async_transfer` was never called, or because
590- //| it was called with zero-length buffers.
591- //| Return code -1: The transfer failed because no DMA channels are available.
592- //| Return code -2: The transfer executed, but the DMA controller indicates that either some data is
593- //| untransferred, that a software issue prevented the data transfer from completing, or that some other error
594- //| has occured within the DMA controller.
595- //| Return code -3: An unaligned buffer was passed to the QSPI peripheral, which prevents the DMA controller from
596- //| appropriately chunking the transfer.
597- //| Return code n>0: A transfer of `n` bytes in each direction has succeeded.
598- //|
599- //| Note: This method is currently only available on atmel-samd` ports of CircuitPython.
600- //| """
601- //| ...
602- STATIC mp_obj_t busio_spi_obj_end_async_transfer (mp_obj_t self_in ) {
603- busio_spi_obj_t * self = MP_OBJ_TO_PTR (self_in );
604- check_for_deinit (self );
605- return MP_OBJ_NEW_SMALL_INT (common_hal_busio_spi_transfer_async_end (self ));
606- }
607- MP_DEFINE_CONST_FUN_OBJ_1 (busio_spi_end_transfer_obj , busio_spi_obj_end_async_transfer );
608-
609- #endif // CIRCUITPY_SAMD
610-
611472#endif // CIRCUITPY_BUSIO_SPI
612473
613474
@@ -626,13 +487,6 @@ STATIC const mp_rom_map_elem_t busio_spi_locals_dict_table[] = {
626487 { MP_ROM_QSTR (MP_QSTR_write_readinto ), MP_ROM_PTR (& busio_spi_write_readinto_obj ) },
627488 { MP_ROM_QSTR (MP_QSTR_frequency ), MP_ROM_PTR (& busio_spi_frequency_obj ) }
628489
629- #if CIRCUITPY_SAMD
630- ,
631- { MP_ROM_QSTR (MP_QSTR_async_transfer_start ), MP_ROM_PTR (& busio_spi_start_transfer_obj ) },
632- { MP_ROM_QSTR (MP_QSTR_async_transfer_finished ), MP_ROM_PTR (& busio_spi_check_transfer_obj ) },
633- { MP_ROM_QSTR (MP_QSTR_async_transfer_end ), MP_ROM_PTR (& busio_spi_end_transfer_obj ) }
634- #endif // CIRCUITPY_SAMD
635-
636490 #endif // CIRCUITPY_BUSIO_SPI
637491};
638492STATIC MP_DEFINE_CONST_DICT (busio_spi_locals_dict , busio_spi_locals_dict_table );
0 commit comments