summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/i2c
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2021-11-25 01:59:07 +0100
committerUros Majstorovic <majstor@majstor.org>2021-11-25 01:59:07 +0100
commit6a31936e80ae2743376dcbf9d39cd92461c4deca (patch)
treef6dedd2cbf3aee9bb8135c7a4ff874c066a6d072 /fw/fe310/eos/i2c
parentc44897fda572cf8837b4535a6d1aaad4605c14af (diff)
i2s init/start/running fixed; i2c start returns error if i2s is running
Diffstat (limited to 'fw/fe310/eos/i2c')
-rw-r--r--fw/fe310/eos/i2c/bq25895.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/fw/fe310/eos/i2c/bq25895.c b/fw/fe310/eos/i2c/bq25895.c
index 85b162b..db4a6ab 100644
--- a/fw/fe310/eos/i2c/bq25895.c
+++ b/fw/fe310/eos/i2c/bq25895.c
@@ -9,27 +9,31 @@
void eos_bq25895_init(uint8_t wakeup_cause) {
int rst = (wakeup_cause == EOS_PWR_WAKE_RST);
- int i, ret = EOS_OK;
+ int i, rv = EOS_OK;
uint8_t data = 0;
- eos_i2c_start(100000);
+ rv = eos_i2c_start(100000);
+ if (rv) {
+ printf("I2C BUSY\n");
+ return;
+ }
if (rst) {
- ret = eos_i2c_write8(BQ25895_ADDR, 0x14, 0x80); // reset
- if (ret) printf("I2C ERROR 0x14\n");
- ret = eos_i2c_write8(BQ25895_ADDR, 0x14, 0x00); // disable watchdog
- if (ret) printf("I2C ERROR 0x14\n");
- ret = eos_i2c_write8(BQ25895_ADDR, 0x07, 0x8d); // disable watchdog
- if (ret) printf("I2C ERROR 0x07\n");
- ret = eos_i2c_write8(BQ25895_ADDR, 0x00, 0x28); // 2.1A input current
- if (ret) printf("I2C ERROR 0x00\n");
- ret = eos_i2c_write8(BQ25895_ADDR, 0x02, 0x30); // enable ICO, disaable MaxCharge and D+/D-
- if (ret) printf("I2C ERROR 0x02\n");
+ rv = eos_i2c_write8(BQ25895_ADDR, 0x14, 0x80); // reset
+ if (rv) printf("I2C ERROR 0x14\n");
+ rv = eos_i2c_write8(BQ25895_ADDR, 0x14, 0x00); // disable watchdog
+ if (rv) printf("I2C ERROR 0x14\n");
+ rv = eos_i2c_write8(BQ25895_ADDR, 0x07, 0x8d); // disable watchdog
+ if (rv) printf("I2C ERROR 0x07\n");
+ rv = eos_i2c_write8(BQ25895_ADDR, 0x00, 0x28); // 2.1A input current
+ if (rv) printf("I2C ERROR 0x00\n");
+ rv = eos_i2c_write8(BQ25895_ADDR, 0x02, 0x30); // enable ICO, disaable MaxCharge and D+/D-
+ if (rv) printf("I2C ERROR 0x02\n");
}
printf("BQ25895:\n");
for (i=0; i<0x15; i++) {
- ret = eos_i2c_read8(BQ25895_ADDR, i, &data);
- if (!ret) printf("REG%02x: %02x\n", i, data);
+ rv = eos_i2c_read8(BQ25895_ADDR, i, &data);
+ if (!rv) printf("REG%02x: %02x\n", i, data);
}
eos_i2c_stop();
}