@@ -318,7 +318,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(machine_i2c_init_obj, 1, machine_i2c_obj_init);
318318
319319STATIC mp_obj_t machine_i2c_scan (mp_obj_t self_in ) {
320320 mp_obj_base_t * self = MP_OBJ_TO_PTR (self_in );
321- mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )self -> type -> protocol ;
321+ mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )mp_proto_get ( self , QSTR_protocol_i2c ) ;
322322 mp_obj_t list = mp_obj_new_list (0 , NULL );
323323 // 7-bit addresses 0b0000xxx and 0b1111xxx are reserved
324324 for (int addr = 0x08 ; addr < 0x78 ; ++ addr ) {
@@ -333,7 +333,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(machine_i2c_scan_obj, machine_i2c_scan);
333333
334334STATIC mp_obj_t machine_i2c_start (mp_obj_t self_in ) {
335335 mp_obj_base_t * self = (mp_obj_base_t * )MP_OBJ_TO_PTR (self_in );
336- mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )self -> type -> protocol ;
336+ mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )mp_proto_get ( self , QSTR_protocol_i2c ) ;
337337 if (i2c_p -> start == NULL ) {
338338 mp_raise_msg (& mp_type_OSError , translate ("I2C operation not supported" ));
339339 }
@@ -347,7 +347,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(machine_i2c_start_obj, machine_i2c_start);
347347
348348STATIC mp_obj_t machine_i2c_stop (mp_obj_t self_in ) {
349349 mp_obj_base_t * self = (mp_obj_base_t * )MP_OBJ_TO_PTR (self_in );
350- mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )self -> type -> protocol ;
350+ mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )mp_proto_get ( self , QSTR_protocol_i2c ) ;
351351 if (i2c_p -> stop == NULL ) {
352352 mp_raise_msg (& mp_type_OSError , translate ("I2C operation not supported" ));
353353 }
@@ -361,7 +361,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(machine_i2c_stop_obj, machine_i2c_stop);
361361
362362STATIC mp_obj_t machine_i2c_readinto (size_t n_args , const mp_obj_t * args ) {
363363 mp_obj_base_t * self = (mp_obj_base_t * )MP_OBJ_TO_PTR (args [0 ]);
364- mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )self -> type -> protocol ;
364+ mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )mp_proto_get ( self , QSTR_protocol_i2c ) ;
365365 if (i2c_p -> read == NULL ) {
366366 mp_raise_msg (& mp_type_OSError , translate ("I2C operation not supported" ));
367367 }
@@ -385,7 +385,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_i2c_readinto_obj, 2, 3, machine_i2c_
385385
386386STATIC mp_obj_t machine_i2c_write (mp_obj_t self_in , mp_obj_t buf_in ) {
387387 mp_obj_base_t * self = (mp_obj_base_t * )MP_OBJ_TO_PTR (self_in );
388- mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )self -> type -> protocol ;
388+ mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )mp_proto_get ( self , QSTR_protocol_i2c ) ;
389389 if (i2c_p -> write == NULL ) {
390390 mp_raise_msg (& mp_type_OSError , translate ("I2C operation not supported" ));
391391 }
@@ -407,7 +407,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(machine_i2c_write_obj, machine_i2c_write);
407407
408408STATIC mp_obj_t machine_i2c_readfrom (size_t n_args , const mp_obj_t * args ) {
409409 mp_obj_base_t * self = (mp_obj_base_t * )MP_OBJ_TO_PTR (args [0 ]);
410- mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )self -> type -> protocol ;
410+ mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )mp_proto_get ( self , QSTR_protocol_i2c ) ;
411411 mp_int_t addr = mp_obj_get_int (args [1 ]);
412412 vstr_t vstr ;
413413 vstr_init_len (& vstr , mp_obj_get_int (args [2 ]));
@@ -422,7 +422,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_i2c_readfrom_obj, 3, 4, machine_i2c_
422422
423423STATIC mp_obj_t machine_i2c_readfrom_into (size_t n_args , const mp_obj_t * args ) {
424424 mp_obj_base_t * self = (mp_obj_base_t * )MP_OBJ_TO_PTR (args [0 ]);
425- mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )self -> type -> protocol ;
425+ mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )mp_proto_get ( self , QSTR_protocol_i2c ) ;
426426 mp_int_t addr = mp_obj_get_int (args [1 ]);
427427 mp_buffer_info_t bufinfo ;
428428 mp_get_buffer_raise (args [2 ], & bufinfo , MP_BUFFER_WRITE );
@@ -437,7 +437,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_i2c_readfrom_into_obj, 3, 4, machine
437437
438438STATIC mp_obj_t machine_i2c_writeto (size_t n_args , const mp_obj_t * args ) {
439439 mp_obj_base_t * self = (mp_obj_base_t * )MP_OBJ_TO_PTR (args [0 ]);
440- mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )self -> type -> protocol ;
440+ mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )mp_proto_get ( self , QSTR_protocol_i2c ) ;
441441 mp_int_t addr = mp_obj_get_int (args [1 ]);
442442 mp_buffer_info_t bufinfo ;
443443 mp_get_buffer_raise (args [2 ], & bufinfo , MP_BUFFER_READ );
@@ -453,7 +453,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_i2c_writeto_obj, 3, 4, machin
453453
454454STATIC int read_mem (mp_obj_t self_in , uint16_t addr , uint32_t memaddr , uint8_t addrsize , uint8_t * buf , size_t len ) {
455455 mp_obj_base_t * self = (mp_obj_base_t * )MP_OBJ_TO_PTR (self_in );
456- mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )self -> type -> protocol ;
456+ mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )mp_proto_get ( self , QSTR_protocol_i2c ) ;
457457 uint8_t memaddr_buf [4 ];
458458 size_t memaddr_len = 0 ;
459459 for (int16_t i = addrsize - 8 ; i >= 0 ; i -= 8 ) {
@@ -473,7 +473,7 @@ STATIC int read_mem(mp_obj_t self_in, uint16_t addr, uint32_t memaddr, uint8_t a
473473
474474STATIC int write_mem (mp_obj_t self_in , uint16_t addr , uint32_t memaddr , uint8_t addrsize , const uint8_t * buf , size_t len ) {
475475 mp_obj_base_t * self = (mp_obj_base_t * )MP_OBJ_TO_PTR (self_in );
476- mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )self -> type -> protocol ;
476+ mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )mp_proto_get ( self , QSTR_protocol_i2c ) ;
477477
478478 // need some memory to create the buffer to send; try to use stack if possible
479479 uint8_t buf2_stack [MAX_MEMADDR_SIZE + BUF_STACK_SIZE ];
@@ -621,6 +621,7 @@ int mp_machine_soft_i2c_write(mp_obj_base_t *self_in, const uint8_t *src, size_t
621621}
622622
623623STATIC const mp_machine_i2c_p_t mp_machine_soft_i2c_p = {
624+ MP_PROTO_IMPLEMENT (MP_QSTR_protocol_i2c )
624625 .start = (int (* )(mp_obj_base_t * ))mp_hal_i2c_start ,
625626 .stop = (int (* )(mp_obj_base_t * ))mp_hal_i2c_stop ,
626627 .read = mp_machine_soft_i2c_read ,
0 commit comments