@@ -634,9 +634,16 @@ void i2c_reset(i2c_t *obj) {
634
634
int i2c_read (i2c_t * obj , int address , char * data , int length , int stop ) {
635
635
struct i2c_s * obj_s = I2C_S (obj );
636
636
I2C_HandleTypeDef * handle = & (obj_s -> handle );
637
- int count = 0 , ret = 0 ;
637
+ int count = I2C_ERROR_BUS_BUSY , ret = 0 ;
638
638
uint32_t timeout = 0 ;
639
639
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
+
640
647
if ((obj_s -> XferOperation == I2C_FIRST_AND_LAST_FRAME ) ||
641
648
(obj_s -> XferOperation == I2C_LAST_FRAME )) {
642
649
if (stop )
@@ -686,9 +693,16 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
686
693
int i2c_write (i2c_t * obj , int address , const char * data , int length , int stop ) {
687
694
struct i2c_s * obj_s = I2C_S (obj );
688
695
I2C_HandleTypeDef * handle = & (obj_s -> handle );
689
- int count = 0 , ret = 0 ;
696
+ int count = I2C_ERROR_BUS_BUSY , ret = 0 ;
690
697
uint32_t timeout = 0 ;
691
698
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
+
692
706
if ((obj_s -> XferOperation == I2C_FIRST_AND_LAST_FRAME ) ||
693
707
(obj_s -> XferOperation == I2C_LAST_FRAME )) {
694
708
if (stop )
0 commit comments