@@ -318,7 +318,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(machine_i2c_init_obj, 1, machine_i2c_obj_init);
318
318
319
319
STATIC mp_obj_t machine_i2c_scan (mp_obj_t self_in ) {
320
320
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 ) ;
322
322
mp_obj_t list = mp_obj_new_list (0 , NULL );
323
323
// 7-bit addresses 0b0000xxx and 0b1111xxx are reserved
324
324
for (int addr = 0x08 ; addr < 0x78 ; ++ addr ) {
@@ -333,7 +333,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(machine_i2c_scan_obj, machine_i2c_scan);
333
333
334
334
STATIC mp_obj_t machine_i2c_start (mp_obj_t self_in ) {
335
335
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 ) ;
337
337
if (i2c_p -> start == NULL ) {
338
338
mp_raise_msg (& mp_type_OSError , translate ("I2C operation not supported" ));
339
339
}
@@ -347,7 +347,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(machine_i2c_start_obj, machine_i2c_start);
347
347
348
348
STATIC mp_obj_t machine_i2c_stop (mp_obj_t self_in ) {
349
349
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 ) ;
351
351
if (i2c_p -> stop == NULL ) {
352
352
mp_raise_msg (& mp_type_OSError , translate ("I2C operation not supported" ));
353
353
}
@@ -361,7 +361,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(machine_i2c_stop_obj, machine_i2c_stop);
361
361
362
362
STATIC mp_obj_t machine_i2c_readinto (size_t n_args , const mp_obj_t * args ) {
363
363
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 ) ;
365
365
if (i2c_p -> read == NULL ) {
366
366
mp_raise_msg (& mp_type_OSError , translate ("I2C operation not supported" ));
367
367
}
@@ -385,7 +385,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_i2c_readinto_obj, 2, 3, machine_i2c_
385
385
386
386
STATIC mp_obj_t machine_i2c_write (mp_obj_t self_in , mp_obj_t buf_in ) {
387
387
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 ) ;
389
389
if (i2c_p -> write == NULL ) {
390
390
mp_raise_msg (& mp_type_OSError , translate ("I2C operation not supported" ));
391
391
}
@@ -407,7 +407,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(machine_i2c_write_obj, machine_i2c_write);
407
407
408
408
STATIC mp_obj_t machine_i2c_readfrom (size_t n_args , const mp_obj_t * args ) {
409
409
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 ) ;
411
411
mp_int_t addr = mp_obj_get_int (args [1 ]);
412
412
vstr_t vstr ;
413
413
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_
422
422
423
423
STATIC mp_obj_t machine_i2c_readfrom_into (size_t n_args , const mp_obj_t * args ) {
424
424
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 ) ;
426
426
mp_int_t addr = mp_obj_get_int (args [1 ]);
427
427
mp_buffer_info_t bufinfo ;
428
428
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
437
437
438
438
STATIC mp_obj_t machine_i2c_writeto (size_t n_args , const mp_obj_t * args ) {
439
439
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 ) ;
441
441
mp_int_t addr = mp_obj_get_int (args [1 ]);
442
442
mp_buffer_info_t bufinfo ;
443
443
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
453
453
454
454
STATIC int read_mem (mp_obj_t self_in , uint16_t addr , uint32_t memaddr , uint8_t addrsize , uint8_t * buf , size_t len ) {
455
455
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 ) ;
457
457
uint8_t memaddr_buf [4 ];
458
458
size_t memaddr_len = 0 ;
459
459
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
473
473
474
474
STATIC int write_mem (mp_obj_t self_in , uint16_t addr , uint32_t memaddr , uint8_t addrsize , const uint8_t * buf , size_t len ) {
475
475
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 ) ;
477
477
478
478
// need some memory to create the buffer to send; try to use stack if possible
479
479
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
621
621
}
622
622
623
623
STATIC const mp_machine_i2c_p_t mp_machine_soft_i2c_p = {
624
+ MP_PROTO_IMPLEMENT (MP_QSTR_protocol_i2c )
624
625
.start = (int (* )(mp_obj_base_t * ))mp_hal_i2c_start ,
625
626
.stop = (int (* )(mp_obj_base_t * ))mp_hal_i2c_stop ,
626
627
.read = mp_machine_soft_i2c_read ,
0 commit comments