@@ -634,9 +634,16 @@ void i2c_reset(i2c_t *obj) {
634634int i2c_read (i2c_t * obj , int address , char * data , int length , int stop ) {
635635 struct i2c_s * obj_s = I2C_S (obj );
636636 I2C_HandleTypeDef * handle = & (obj_s -> handle );
637- int count = 0 , ret = 0 ;
637+ int count = I2C_ERROR_BUS_BUSY , ret = 0 ;
638638 uint32_t timeout = 0 ;
639639
640+ if ((length == 0 ) || (data == 0 )) {
641+ if (HAL_I2C_IsDeviceReady (handle , address , 1 , 10 ) == HAL_OK )
642+ return 0 ;
643+ else
644+ return I2C_ERROR_BUS_BUSY ;
645+ }
646+
640647 if ((obj_s -> XferOperation == I2C_FIRST_AND_LAST_FRAME ) ||
641648 (obj_s -> XferOperation == I2C_LAST_FRAME )) {
642649 if (stop )
@@ -686,9 +693,16 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
686693int i2c_write (i2c_t * obj , int address , const char * data , int length , int stop ) {
687694 struct i2c_s * obj_s = I2C_S (obj );
688695 I2C_HandleTypeDef * handle = & (obj_s -> handle );
689- int count = 0 , ret = 0 ;
696+ int count = I2C_ERROR_BUS_BUSY , ret = 0 ;
690697 uint32_t timeout = 0 ;
691698
699+ if ((length == 0 ) || (data == 0 )) {
700+ if (HAL_I2C_IsDeviceReady (handle , address , 1 , 10 ) == HAL_OK )
701+ return 0 ;
702+ else
703+ return I2C_ERROR_BUS_BUSY ;
704+ }
705+
692706 if ((obj_s -> XferOperation == I2C_FIRST_AND_LAST_FRAME ) ||
693707 (obj_s -> XferOperation == I2C_LAST_FRAME )) {
694708 if (stop )
0 commit comments