@@ -183,7 +183,7 @@ STATIC int mp_hal_i2c_read_byte(machine_i2c_obj_t *self, uint8_t *val, int nack)
183
183
// >=0 - number of acks received
184
184
// <0 - error, with errno being the negative of the return value
185
185
int 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 ;
187
187
188
188
// start the I2C transaction
189
189
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
229
229
// 0 - success
230
230
// <0 - error, with errno being the negative of the return value
231
231
int 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 ;
233
233
234
234
// start the I2C transaction
235
235
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);
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 * )self -> type -> protocol ;
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 ) {
@@ -332,8 +332,8 @@ STATIC mp_obj_t machine_i2c_scan(mp_obj_t self_in) {
332
332
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
- 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 ;
337
337
if (i2c_p -> start == NULL ) {
338
338
mp_raise_msg (& mp_type_OSError , "I2C operation not supported" );
339
339
}
@@ -346,8 +346,8 @@ STATIC mp_obj_t machine_i2c_start(mp_obj_t self_in) {
346
346
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
- 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 ;
351
351
if (i2c_p -> stop == NULL ) {
352
352
mp_raise_msg (& mp_type_OSError , "I2C operation not supported" );
353
353
}
@@ -360,8 +360,8 @@ STATIC mp_obj_t machine_i2c_stop(mp_obj_t self_in) {
360
360
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
- 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 ;
365
365
if (i2c_p -> read == NULL ) {
366
366
mp_raise_msg (& mp_type_OSError , "I2C operation not supported" );
367
367
}
@@ -384,8 +384,8 @@ STATIC mp_obj_t machine_i2c_readinto(size_t n_args, const mp_obj_t *args) {
384
384
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (machine_i2c_readinto_obj , 2 , 3 , machine_i2c_readinto );
385
385
386
386
STATIC 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 ;
389
389
if (i2c_p -> write == NULL ) {
390
390
mp_raise_msg (& mp_type_OSError , "I2C operation not supported" );
391
391
}
@@ -406,13 +406,13 @@ STATIC mp_obj_t machine_i2c_write(mp_obj_t self_in, mp_obj_t buf_in) {
406
406
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
- 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 ;
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 ]));
414
414
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 );
416
416
if (ret < 0 ) {
417
417
mp_raise_OSError (- ret );
418
418
}
@@ -421,8 +421,8 @@ STATIC mp_obj_t machine_i2c_readfrom(size_t n_args, const mp_obj_t *args) {
421
421
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (machine_i2c_readfrom_obj , 3 , 4 , machine_i2c_readfrom );
422
422
423
423
STATIC 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 ;
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 );
@@ -436,8 +436,8 @@ STATIC mp_obj_t machine_i2c_readfrom_into(size_t n_args, const mp_obj_t *args) {
436
436
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (machine_i2c_readfrom_into_obj , 3 , 4 , machine_i2c_readfrom_into );
437
437
438
438
STATIC 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 ;
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 );
@@ -452,8 +452,8 @@ STATIC mp_obj_t machine_i2c_writeto(size_t n_args, const mp_obj_t *args) {
452
452
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (machine_i2c_writeto_obj , 3 , 4 , machine_i2c_writeto );
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
- 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 ;
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 ) {
@@ -472,8 +472,8 @@ STATIC int read_mem(mp_obj_t self_in, uint16_t addr, uint32_t memaddr, uint8_t a
472
472
#define BUF_STACK_SIZE (12)
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
- 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 ;
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 ];
@@ -519,7 +519,7 @@ STATIC mp_obj_t machine_i2c_readfrom_mem(size_t n_args, const mp_obj_t *pos_args
519
519
520
520
// do the transfer
521
521
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 );
523
523
if (ret < 0 ) {
524
524
mp_raise_OSError (- ret );
525
525
}
@@ -594,7 +594,7 @@ STATIC const mp_rom_map_elem_t machine_i2c_locals_dict_table[] = {
594
594
MP_DEFINE_CONST_DICT (mp_machine_soft_i2c_locals_dict , machine_i2c_locals_dict_table );
595
595
596
596
int 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 ;
598
598
while (len -- ) {
599
599
int ret = mp_hal_i2c_read_byte (self , dest ++ , nack && (len == 0 ));
600
600
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,
605
605
}
606
606
607
607
int 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 ;
609
609
int num_acks = 0 ;
610
610
while (len -- ) {
611
611
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
621
621
}
622
622
623
623
STATIC 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 ,
626
626
.read = mp_machine_soft_i2c_read ,
627
627
.write = mp_machine_soft_i2c_write ,
628
628
.readfrom = mp_machine_soft_i2c_readfrom ,
@@ -634,7 +634,7 @@ const mp_obj_type_t machine_i2c_type = {
634
634
.name = MP_QSTR_I2C ,
635
635
.make_new = machine_i2c_make_new ,
636
636
.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 ,
638
638
};
639
639
640
640
#endif // MICROPY_PY_MACHINE_I2C
0 commit comments