i2c: handle errors at i2ccmds
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
This commit is contained in:
committed by
KevinOConnor
parent
08a85ba869
commit
a4aa2a9002
@@ -11,6 +11,7 @@
|
||||
#include "internal.h" // GPIO
|
||||
#include "sched.h" // sched_shutdown
|
||||
#include "board/irq.h" //irq_disable
|
||||
#include "i2ccmds.h" // I2C_BUS_SUCCESS
|
||||
|
||||
struct i2c_info {
|
||||
I2C_TypeDef *i2c;
|
||||
@@ -149,7 +150,7 @@ i2c_stop(I2C_TypeDef *i2c, uint32_t timeout)
|
||||
i2c_wait(i2c, 0, I2C_SR1_TXE, timeout);
|
||||
}
|
||||
|
||||
void
|
||||
int
|
||||
i2c_write(struct i2c_config config, uint8_t write_len, uint8_t *write)
|
||||
{
|
||||
I2C_TypeDef *i2c = config.i2c;
|
||||
@@ -159,9 +160,11 @@ i2c_write(struct i2c_config config, uint8_t write_len, uint8_t *write)
|
||||
while (write_len--)
|
||||
i2c_send_byte(i2c, *write++, timeout);
|
||||
i2c_stop(i2c, timeout);
|
||||
|
||||
return I2C_BUS_SUCCESS;
|
||||
}
|
||||
|
||||
void
|
||||
int
|
||||
i2c_read(struct i2c_config config, uint8_t reg_len, uint8_t *reg
|
||||
, uint8_t read_len, uint8_t *read)
|
||||
{
|
||||
@@ -182,4 +185,6 @@ i2c_read(struct i2c_config config, uint8_t reg_len, uint8_t *reg
|
||||
read++;
|
||||
}
|
||||
i2c_wait(i2c, 0, I2C_SR1_RXNE, timeout);
|
||||
|
||||
return I2C_BUS_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user