2424 * THE SOFTWARE.
2525 */
2626
27- #include <stdio.h>
28- #include <stdint.h>
29- #include <string.h>
30- #include <stdlib.h>
31- #include <stdbool.h>
32-
33- #include "py/obj.h"
34- #include "py/runtime.h"
35- #include "py/misc.h"
27+ // This file is never compiled standalone, it's included directly from
28+ // extmod/machine_i2s.c via MICROPY_PY_MACHINE_I2S_INCLUDEFILE.
29+
30+ #include "py/mphal.h"
3631#include "py/stream.h"
37- #include "py/objstr.h"
38- #include "modmachine.h"
39- #include "mphalport.h"
4032
4133#if MICROPY_PY_MACHINE_I2S
4234
@@ -360,7 +352,7 @@ STATIC void task_for_non_blocking_mode(void *self_in) {
360352 }
361353}
362354
363- STATIC void machine_i2s_init_helper (machine_i2s_obj_t * self , size_t n_pos_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
355+ STATIC void mp_machine_i2s_init_helper (machine_i2s_obj_t * self , size_t n_pos_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
364356
365357 enum {
366358 ARG_sck ,
@@ -501,10 +493,8 @@ STATIC void machine_i2s_print(const mp_print_t *print, mp_obj_t self_in, mp_prin
501493 );
502494}
503495
504- STATIC mp_obj_t machine_i2s_make_new (const mp_obj_type_t * type , size_t n_pos_args , size_t n_kw_args , const mp_obj_t * args ) {
505- mp_arg_check_num (n_pos_args , n_kw_args , 1 , MP_OBJ_FUN_ARGS_MAX , true);
506-
507- i2s_port_t port = mp_obj_get_int (args [0 ]);
496+ STATIC machine_i2s_obj_t * mp_machine_i2s_make_new_instance (mp_int_t i2s_id ) {
497+ i2s_port_t port = i2s_id ;
508498 if (port < 0 || port >= I2S_NUM_AUTO ) {
509499 mp_raise_ValueError (MP_ERROR_TEXT ("invalid id" ));
510500 }
@@ -520,23 +510,10 @@ STATIC mp_obj_t machine_i2s_make_new(const mp_obj_type_t *type, size_t n_pos_arg
520510 machine_i2s_deinit (self );
521511 }
522512
523- mp_map_t kw_args ;
524- mp_map_init_fixed_table (& kw_args , n_kw_args , args + n_pos_args );
525- machine_i2s_init_helper (self , n_pos_args - 1 , args + 1 , & kw_args );
526-
527- return MP_OBJ_FROM_PTR (self );
513+ return self ;
528514}
529515
530- STATIC mp_obj_t machine_i2s_obj_init (size_t n_pos_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
531- machine_i2s_obj_t * self = pos_args [0 ];
532- machine_i2s_deinit (self );
533- machine_i2s_init_helper (self , n_pos_args - 1 , pos_args + 1 , kw_args );
534- return mp_const_none ;
535- }
536- STATIC MP_DEFINE_CONST_FUN_OBJ_KW (machine_i2s_init_obj , 1 , machine_i2s_obj_init );
537-
538- STATIC mp_obj_t machine_i2s_deinit (mp_obj_t self_in ) {
539- machine_i2s_obj_t * self = MP_OBJ_TO_PTR (self_in );
516+ STATIC void mp_machine_i2s_deinit (machine_i2s_obj_t * self ) {
540517 i2s_driver_uninstall (self -> port );
541518
542519 if (self -> non_blocking_mode_task != NULL ) {
@@ -550,9 +527,7 @@ STATIC mp_obj_t machine_i2s_deinit(mp_obj_t self_in) {
550527 }
551528
552529 self -> i2s_event_queue = NULL ;
553- return mp_const_none ;
554530}
555- STATIC MP_DEFINE_CONST_FUN_OBJ_1 (machine_i2s_deinit_obj , machine_i2s_deinit );
556531
557532STATIC mp_obj_t machine_i2s_irq (mp_obj_t self_in , mp_obj_t handler ) {
558533 machine_i2s_obj_t * self = MP_OBJ_TO_PTR (self_in );
@@ -660,26 +635,6 @@ STATIC mp_obj_t machine_i2s_shift(size_t n_args, const mp_obj_t *pos_args, mp_ma
660635STATIC MP_DEFINE_CONST_FUN_OBJ_KW (machine_i2s_shift_fun_obj , 0 , machine_i2s_shift );
661636STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ (machine_i2s_shift_obj , MP_ROM_PTR (& machine_i2s_shift_fun_obj ));
662637
663- STATIC const mp_rom_map_elem_t machine_i2s_locals_dict_table [] = {
664- // Methods
665- { MP_ROM_QSTR (MP_QSTR_init ), MP_ROM_PTR (& machine_i2s_init_obj ) },
666- { MP_ROM_QSTR (MP_QSTR_readinto ), MP_ROM_PTR (& mp_stream_readinto_obj ) },
667- { MP_ROM_QSTR (MP_QSTR_write ), MP_ROM_PTR (& mp_stream_write_obj ) },
668- { MP_ROM_QSTR (MP_QSTR_deinit ), MP_ROM_PTR (& machine_i2s_deinit_obj ) },
669- { MP_ROM_QSTR (MP_QSTR_irq ), MP_ROM_PTR (& machine_i2s_irq_obj ) },
670- { MP_ROM_QSTR (MP_QSTR___del__ ), MP_ROM_PTR (& machine_i2s_deinit_obj ) },
671-
672- // Static method
673- { MP_ROM_QSTR (MP_QSTR_shift ), MP_ROM_PTR (& machine_i2s_shift_obj ) },
674-
675- // Constants
676- { MP_ROM_QSTR (MP_QSTR_RX ), MP_ROM_INT (I2S_MODE_MASTER | I2S_MODE_RX ) },
677- { MP_ROM_QSTR (MP_QSTR_TX ), MP_ROM_INT (I2S_MODE_MASTER | I2S_MODE_TX ) },
678- { MP_ROM_QSTR (MP_QSTR_STEREO ), MP_ROM_INT (STEREO ) },
679- { MP_ROM_QSTR (MP_QSTR_MONO ), MP_ROM_INT (MONO ) },
680- };
681- MP_DEFINE_CONST_DICT (machine_i2s_locals_dict , machine_i2s_locals_dict_table );
682-
683638STATIC mp_uint_t machine_i2s_stream_read (mp_obj_t self_in , void * buf_in , mp_uint_t size , int * errcode ) {
684639 machine_i2s_obj_t * self = MP_OBJ_TO_PTR (self_in );
685640
@@ -802,23 +757,6 @@ STATIC mp_uint_t machine_i2s_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
802757 return ret ;
803758}
804759
805- STATIC const mp_stream_p_t i2s_stream_p = {
806- .read = machine_i2s_stream_read ,
807- .write = machine_i2s_stream_write ,
808- .ioctl = machine_i2s_ioctl ,
809- .is_text = false,
810- };
811-
812- MP_DEFINE_CONST_OBJ_TYPE (
813- machine_i2s_type ,
814- MP_QSTR_I2S ,
815- MP_TYPE_FLAG_ITER_IS_STREAM ,
816- make_new , machine_i2s_make_new ,
817- print , machine_i2s_print ,
818- protocol , & i2s_stream_p ,
819- locals_dict , & machine_i2s_locals_dict
820- );
821-
822760MP_REGISTER_ROOT_POINTER (struct _machine_i2s_obj_t * machine_i2s_obj [I2S_NUM_AUTO ]);
823761
824762#endif // MICROPY_PY_MACHINE_I2S
0 commit comments