@@ -346,26 +346,29 @@ STATIC mp_obj_t machine_i2c_stop(mp_obj_t self_in) {
346346}
347347MP_DEFINE_CONST_FUN_OBJ_1 (machine_i2c_stop_obj , machine_i2c_stop );
348348
349- STATIC mp_obj_t machine_i2c_readinto (mp_obj_t self_in , mp_obj_t buf_in ) {
350- mp_obj_base_t * self = (mp_obj_base_t * )MP_OBJ_TO_PTR (self_in );
349+ STATIC mp_obj_t machine_i2c_readinto (size_t n_args , const mp_obj_t * args ) {
350+ mp_obj_base_t * self = (mp_obj_base_t * )MP_OBJ_TO_PTR (args [ 0 ] );
351351 mp_machine_i2c_p_t * i2c_p = (mp_machine_i2c_p_t * )self -> type -> protocol ;
352352 if (i2c_p -> read == NULL ) {
353353 mp_raise_msg (& mp_type_OSError , "I2C operation not supported" );
354354 }
355355
356356 // get the buffer to read into
357357 mp_buffer_info_t bufinfo ;
358- mp_get_buffer_raise (buf_in , & bufinfo , MP_BUFFER_WRITE );
358+ mp_get_buffer_raise (args [1 ], & bufinfo , MP_BUFFER_WRITE );
359+
360+ // work out if we want to send a nack at the end
361+ bool nack = (n_args == 2 ) ? true : mp_obj_is_true (args [2 ]);
359362
360363 // do the read
361- int ret = i2c_p -> read (self , bufinfo .buf , bufinfo .len );
364+ int ret = i2c_p -> read (self , bufinfo .buf , bufinfo .len , nack );
362365 if (ret != 0 ) {
363366 mp_raise_OSError (- ret );
364367 }
365368
366369 return mp_const_none ;
367370}
368- MP_DEFINE_CONST_FUN_OBJ_2 (machine_i2c_readinto_obj , machine_i2c_readinto );
371+ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (machine_i2c_readinto_obj , 2 , 3 , machine_i2c_readinto );
369372
370373STATIC mp_obj_t machine_i2c_write (mp_obj_t self_in , mp_obj_t buf_in ) {
371374 mp_obj_base_t * self = (mp_obj_base_t * )MP_OBJ_TO_PTR (self_in );
@@ -579,10 +582,10 @@ int mp_machine_soft_i2c_stop(mp_obj_base_t *self_in) {
579582 return mp_hal_i2c_stop (self );
580583}
581584
582- int mp_machine_soft_i2c_read (mp_obj_base_t * self_in , uint8_t * dest , size_t len ) {
585+ int mp_machine_soft_i2c_read (mp_obj_base_t * self_in , uint8_t * dest , size_t len , bool nack ) {
583586 machine_i2c_obj_t * self = (machine_i2c_obj_t * )self_in ;
584587 while (len -- ) {
585- int ret = mp_hal_i2c_read_byte (self , dest ++ , len == 0 );
588+ int ret = mp_hal_i2c_read_byte (self , dest ++ , nack && ( len == 0 ) );
586589 if (ret != 0 ) {
587590 return ret ;
588591 }
0 commit comments