@@ -183,7 +183,7 @@ STATIC int mp_hal_i2c_read_byte(machine_i2c_obj_t *self, uint8_t *val, int nack)
183183// >=0 - number of acks received
184184// <0 - error, with errno being the negative of the return value
185185int mp_machine_soft_i2c_writeto (mp_obj_base_t * self_in , uint16_t addr , const uint8_t * src , size_t len , bool stop ) {
186- machine_i2c_obj_t * self = (machine_i2c_obj_t * )self_in ;
186+ machine_i2c_obj_t * self = (machine_i2c_obj_t * )self_in ;
187187
188188 // start the I2C transaction
189189 int ret = mp_hal_i2c_start (self );
@@ -229,7 +229,7 @@ int mp_machine_soft_i2c_writeto(mp_obj_base_t *self_in, uint16_t addr, const uin
229229// 0 - success
230230// <0 - error, with errno being the negative of the return value
231231int mp_machine_soft_i2c_readfrom (mp_obj_base_t * self_in , uint16_t addr , uint8_t * dest , size_t len , bool stop ) {
232- machine_i2c_obj_t * self = (machine_i2c_obj_t * )self_in ;
232+ machine_i2c_obj_t * self = (machine_i2c_obj_t * )self_in ;
233233
234234 // start the I2C transaction
235235 int ret = mp_hal_i2c_start (self );
@@ -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 * )self -> type -> protocol ;
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 ) {
@@ -332,8 +332,8 @@ STATIC mp_obj_t machine_i2c_scan(mp_obj_t self_in) {
332332MP_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 ) {
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 ;
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 ;
337337 if (i2c_p -> start == NULL ) {
338338 mp_raise_msg (& mp_type_OSError , "I2C operation not supported" );
339339 }
@@ -346,8 +346,8 @@ STATIC mp_obj_t machine_i2c_start(mp_obj_t self_in) {
346346MP_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 ) {
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 ;
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 ;
351351 if (i2c_p -> stop == NULL ) {
352352 mp_raise_msg (& mp_type_OSError , "I2C operation not supported" );
353353 }
@@ -360,8 +360,8 @@ STATIC mp_obj_t machine_i2c_stop(mp_obj_t self_in) {
360360MP_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 ) {
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 ;
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 ;
365365 if (i2c_p -> read == NULL ) {
366366 mp_raise_msg (& mp_type_OSError , "I2C operation not supported" );
367367 }
@@ -384,8 +384,8 @@ STATIC mp_obj_t machine_i2c_readinto(size_t n_args, const mp_obj_t *args) {
384384MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (machine_i2c_readinto_obj , 2 , 3 , machine_i2c_readinto );
385385
386386STATIC mp_obj_t machine_i2c_write (mp_obj_t self_in , mp_obj_t buf_in ) {
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 ;
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 ;
389389 if (i2c_p -> write == NULL ) {
390390 mp_raise_msg (& mp_type_OSError , "I2C operation not supported" );
391391 }
@@ -406,13 +406,13 @@ STATIC mp_obj_t machine_i2c_write(mp_obj_t self_in, mp_obj_t buf_in) {
406406MP_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 ) {
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 ;
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 ;
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 ]));
414414 bool stop = (n_args == 3 ) ? true : mp_obj_is_true (args [3 ]);
415- int ret = i2c_p -> readfrom (self , addr , (uint8_t * )vstr .buf , vstr .len , stop );
415+ int ret = i2c_p -> readfrom (self , addr , (uint8_t * )vstr .buf , vstr .len , stop );
416416 if (ret < 0 ) {
417417 mp_raise_OSError (- ret );
418418 }
@@ -421,8 +421,8 @@ STATIC mp_obj_t machine_i2c_readfrom(size_t n_args, const mp_obj_t *args) {
421421MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (machine_i2c_readfrom_obj , 3 , 4 , machine_i2c_readfrom );
422422
423423STATIC mp_obj_t machine_i2c_readfrom_into (size_t n_args , const mp_obj_t * args ) {
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 ;
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 ;
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 );
@@ -436,8 +436,8 @@ STATIC mp_obj_t machine_i2c_readfrom_into(size_t n_args, const mp_obj_t *args) {
436436MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (machine_i2c_readfrom_into_obj , 3 , 4 , machine_i2c_readfrom_into );
437437
438438STATIC mp_obj_t machine_i2c_writeto (size_t n_args , const mp_obj_t * args ) {
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 ;
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 ;
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 );
@@ -452,8 +452,8 @@ STATIC mp_obj_t machine_i2c_writeto(size_t n_args, const mp_obj_t *args) {
452452STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (machine_i2c_writeto_obj , 3 , 4 , machine_i2c_writeto );
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 ) {
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 ;
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 ;
457457 uint8_t memaddr_buf [4 ];
458458 size_t memaddr_len = 0 ;
459459 for (int16_t i = addrsize - 8 ; i >= 0 ; i -= 8 ) {
@@ -472,8 +472,8 @@ STATIC int read_mem(mp_obj_t self_in, uint16_t addr, uint32_t memaddr, uint8_t a
472472#define BUF_STACK_SIZE (12)
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 ) {
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 ;
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 ;
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 ];
@@ -519,7 +519,7 @@ STATIC mp_obj_t machine_i2c_readfrom_mem(size_t n_args, const mp_obj_t *pos_args
519519
520520 // do the transfer
521521 int ret = read_mem (pos_args [0 ], args [ARG_addr ].u_int , args [ARG_memaddr ].u_int ,
522- args [ARG_addrsize ].u_int , (uint8_t * )vstr .buf , vstr .len );
522+ args [ARG_addrsize ].u_int , (uint8_t * )vstr .buf , vstr .len );
523523 if (ret < 0 ) {
524524 mp_raise_OSError (- ret );
525525 }
@@ -594,7 +594,7 @@ STATIC const mp_rom_map_elem_t machine_i2c_locals_dict_table[] = {
594594MP_DEFINE_CONST_DICT (mp_machine_soft_i2c_locals_dict , machine_i2c_locals_dict_table );
595595
596596int mp_machine_soft_i2c_read (mp_obj_base_t * self_in , uint8_t * dest , size_t len , bool nack ) {
597- machine_i2c_obj_t * self = (machine_i2c_obj_t * )self_in ;
597+ machine_i2c_obj_t * self = (machine_i2c_obj_t * )self_in ;
598598 while (len -- ) {
599599 int ret = mp_hal_i2c_read_byte (self , dest ++ , nack && (len == 0 ));
600600 if (ret != 0 ) {
@@ -605,7 +605,7 @@ int mp_machine_soft_i2c_read(mp_obj_base_t *self_in, uint8_t *dest, size_t len,
605605}
606606
607607int mp_machine_soft_i2c_write (mp_obj_base_t * self_in , const uint8_t * src , size_t len ) {
608- machine_i2c_obj_t * self = (machine_i2c_obj_t * )self_in ;
608+ machine_i2c_obj_t * self = (machine_i2c_obj_t * )self_in ;
609609 int num_acks = 0 ;
610610 while (len -- ) {
611611 int ret = mp_hal_i2c_write_byte (self , * src ++ );
@@ -621,8 +621,8 @@ 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- .start = (int (* )(mp_obj_base_t * ))mp_hal_i2c_start ,
625- .stop = (int (* )(mp_obj_base_t * ))mp_hal_i2c_stop ,
624+ .start = (int (* )(mp_obj_base_t * ))mp_hal_i2c_start ,
625+ .stop = (int (* )(mp_obj_base_t * ))mp_hal_i2c_stop ,
626626 .read = mp_machine_soft_i2c_read ,
627627 .write = mp_machine_soft_i2c_write ,
628628 .readfrom = mp_machine_soft_i2c_readfrom ,
@@ -634,7 +634,7 @@ const mp_obj_type_t machine_i2c_type = {
634634 .name = MP_QSTR_I2C ,
635635 .make_new = machine_i2c_make_new ,
636636 .protocol = & mp_machine_soft_i2c_p ,
637- .locals_dict = (mp_obj_dict_t * )& mp_machine_soft_i2c_locals_dict ,
637+ .locals_dict = (mp_obj_dict_t * )& mp_machine_soft_i2c_locals_dict ,
638638};
639639
640640#endif // MICROPY_PY_MACHINE_I2C
0 commit comments