@@ -273,7 +273,7 @@ int mp_machine_i2c_transfer_adaptor(mp_obj_base_t *self, uint16_t addr, size_t n
273273 }
274274 }
275275
276- mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )self -> type -> protocol ;
276+ mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )MP_OBJ_TYPE_GET_SLOT ( self -> type , protocol ) ;
277277 int ret = i2c_p -> transfer_single (self , addr , len , buf , flags );
278278
279279 if (n > 1 ) {
@@ -292,14 +292,14 @@ int mp_machine_i2c_transfer_adaptor(mp_obj_base_t *self, uint16_t addr, size_t n
292292}
293293
294294STATIC int mp_machine_i2c_readfrom (mp_obj_base_t * self , uint16_t addr , uint8_t * dest , size_t len , bool stop ) {
295- mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )self -> type -> protocol ;
295+ mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )MP_OBJ_TYPE_GET_SLOT ( self -> type , protocol ) ;
296296 mp_machine_i2c_buf_t buf = {.len = len , .buf = dest };
297297 unsigned int flags = MP_MACHINE_I2C_FLAG_READ | (stop ? MP_MACHINE_I2C_FLAG_STOP : 0 );
298298 return i2c_p -> transfer (self , addr , 1 , & buf , flags );
299299}
300300
301301STATIC int mp_machine_i2c_writeto (mp_obj_base_t * self , uint16_t addr , const uint8_t * src , size_t len , bool stop ) {
302- mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )self -> type -> protocol ;
302+ mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )MP_OBJ_TYPE_GET_SLOT ( self -> type , protocol ) ;
303303 mp_machine_i2c_buf_t buf = {.len = len , .buf = (uint8_t * )src };
304304 unsigned int flags = stop ? MP_MACHINE_I2C_FLAG_STOP : 0 ;
305305 return i2c_p -> transfer (self , addr , 1 , & buf , flags );
@@ -310,7 +310,7 @@ STATIC int mp_machine_i2c_writeto(mp_obj_base_t *self, uint16_t addr, const uint
310310
311311STATIC mp_obj_t machine_i2c_init (size_t n_args , const mp_obj_t * args , mp_map_t * kw_args ) {
312312 mp_obj_base_t * self = (mp_obj_base_t * )MP_OBJ_TO_PTR (args [0 ]);
313- mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )self -> type -> protocol ;
313+ mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )MP_OBJ_TYPE_GET_SLOT ( self -> type , protocol ) ;
314314 if (i2c_p -> init == NULL ) {
315315 mp_raise_msg (& mp_type_OSError , MP_ERROR_TEXT ("I2C operation not supported" ));
316316 }
@@ -338,7 +338,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(machine_i2c_scan_obj, machine_i2c_scan);
338338
339339STATIC mp_obj_t machine_i2c_start (mp_obj_t self_in ) {
340340 mp_obj_base_t * self = (mp_obj_base_t * )MP_OBJ_TO_PTR (self_in );
341- mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )self -> type -> protocol ;
341+ mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )MP_OBJ_TYPE_GET_SLOT ( self -> type , protocol ) ;
342342 if (i2c_p -> start == NULL ) {
343343 mp_raise_msg (& mp_type_OSError , MP_ERROR_TEXT ("I2C operation not supported" ));
344344 }
@@ -352,7 +352,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(machine_i2c_start_obj, machine_i2c_start);
352352
353353STATIC mp_obj_t machine_i2c_stop (mp_obj_t self_in ) {
354354 mp_obj_base_t * self = (mp_obj_base_t * )MP_OBJ_TO_PTR (self_in );
355- mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )self -> type -> protocol ;
355+ mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )MP_OBJ_TYPE_GET_SLOT ( self -> type , protocol ) ;
356356 if (i2c_p -> stop == NULL ) {
357357 mp_raise_msg (& mp_type_OSError , MP_ERROR_TEXT ("I2C operation not supported" ));
358358 }
@@ -366,7 +366,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(machine_i2c_stop_obj, machine_i2c_stop);
366366
367367STATIC mp_obj_t machine_i2c_readinto (size_t n_args , const mp_obj_t * args ) {
368368 mp_obj_base_t * self = (mp_obj_base_t * )MP_OBJ_TO_PTR (args [0 ]);
369- mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )self -> type -> protocol ;
369+ mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )MP_OBJ_TYPE_GET_SLOT ( self -> type , protocol ) ;
370370 if (i2c_p -> read == NULL ) {
371371 mp_raise_msg (& mp_type_OSError , MP_ERROR_TEXT ("I2C operation not supported" ));
372372 }
@@ -390,7 +390,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_i2c_readinto_obj, 2, 3, machine_i2c_
390390
391391STATIC mp_obj_t machine_i2c_write (mp_obj_t self_in , mp_obj_t buf_in ) {
392392 mp_obj_base_t * self = (mp_obj_base_t * )MP_OBJ_TO_PTR (self_in );
393- mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )self -> type -> protocol ;
393+ mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )MP_OBJ_TYPE_GET_SLOT ( self -> type , protocol ) ;
394394 if (i2c_p -> write == NULL ) {
395395 mp_raise_msg (& mp_type_OSError , MP_ERROR_TEXT ("I2C operation not supported" ));
396396 }
@@ -486,7 +486,7 @@ STATIC mp_obj_t machine_i2c_writevto(size_t n_args, const mp_obj_t *args) {
486486 }
487487
488488 // Do the I2C transfer
489- mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )self -> type -> protocol ;
489+ mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )MP_OBJ_TYPE_GET_SLOT ( self -> type , protocol ) ;
490490 int ret = i2c_p -> transfer (self , addr , nbufs , bufs , stop ? MP_MACHINE_I2C_FLAG_STOP : 0 );
491491 mp_local_free (bufs );
492492
@@ -519,7 +519,7 @@ STATIC int read_mem(mp_obj_t self_in, uint16_t addr, uint32_t memaddr, uint8_t a
519519
520520 #if MICROPY_PY_MACHINE_I2C_TRANSFER_WRITE1
521521 // The I2C transfer function may support the MP_MACHINE_I2C_FLAG_WRITE1 option
522- mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )self -> type -> protocol ;
522+ mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )MP_OBJ_TYPE_GET_SLOT ( self -> type , protocol ) ;
523523 if (i2c_p -> transfer_supports_write1 ) {
524524 // Create partial write and read buffers
525525 mp_machine_i2c_buf_t bufs [2 ] = {
@@ -556,7 +556,7 @@ STATIC int write_mem(mp_obj_t self_in, uint16_t addr, uint32_t memaddr, uint8_t
556556 };
557557
558558 // Do I2C transfer
559- mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )self -> type -> protocol ;
559+ mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )MP_OBJ_TYPE_GET_SLOT ( self -> type , protocol ) ;
560560 return i2c_p -> transfer (self , addr , 2 , bufs , MP_MACHINE_I2C_FLAG_STOP );
561561}
562562
0 commit comments