From 7ded8116d90081851e0ddb1b4bdd77b645f6535c Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Wed, 1 Dec 2021 01:20:10 +0100 Subject: i2c added 16 bit register read/write --- fw/fe310/eos/i2c/bq25895.c | 22 +++++++++++++++------- fw/fe310/eos/i2c/ov2640.c | 4 ++-- 2 files changed, 17 insertions(+), 9 deletions(-) (limited to 'fw/fe310/eos/i2c') diff --git a/fw/fe310/eos/i2c/bq25895.c b/fw/fe310/eos/i2c/bq25895.c index ab2268b..f8923c6 100644 --- a/fw/fe310/eos/i2c/bq25895.c +++ b/fw/fe310/eos/i2c/bq25895.c @@ -7,29 +7,37 @@ #include "i2c.h" #include "i2c/bq25895.h" +static int reg_read(uint8_t reg, uint8_t *data) { + return eos_i2c_read8(BQ25895_ADDR, reg, data, 1); +} + +static int reg_write(uint8_t reg, uint8_t data) { + return eos_i2c_write8(BQ25895_ADDR, reg, &data, 1); +} + int eos_bq25895_init(uint8_t wakeup_cause) { int rst = (wakeup_cause == EOS_PWR_WAKE_RST); int i, rv = EOS_OK; uint8_t data = 0; - rv = eos_i2c_start(100000); + rv = eos_i2c_start(); if (rv) return rv; if (rst) { - rv = eos_i2c_write8(BQ25895_ADDR, 0x14, 0x80); // reset + rv = reg_write(0x14, 0x80); // reset if (rv) printf("I2C ERROR 0x14\n"); - rv = eos_i2c_write8(BQ25895_ADDR, 0x14, 0x00); // disable watchdog + rv = reg_write(0x14, 0x00); // disable watchdog if (rv) printf("I2C ERROR 0x14\n"); - rv = eos_i2c_write8(BQ25895_ADDR, 0x07, 0x8d); // disable watchdog + rv = reg_write(0x07, 0x8d); // disable watchdog if (rv) printf("I2C ERROR 0x07\n"); - rv = eos_i2c_write8(BQ25895_ADDR, 0x00, 0x28); // 2.1A input current + rv = reg_write(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- + rv = reg_write(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++) { - rv = eos_i2c_read8(BQ25895_ADDR, i, &data); + rv = reg_read(i, &data); if (!rv) printf("REG%02x: %02x\n", i, data); } eos_i2c_stop(); diff --git a/fw/fe310/eos/i2c/ov2640.c b/fw/fe310/eos/i2c/ov2640.c index 1a29463..6e54f10 100644 --- a/fw/fe310/eos/i2c/ov2640.c +++ b/fw/fe310/eos/i2c/ov2640.c @@ -339,11 +339,11 @@ static const uint8_t saturation_regs[NUM_SATURATION_LEVELS + 1][5] = { }; static int reg_read(int8_t reg, uint8_t *data) { - return eos_i2c_read8(OV2640_ADDR, reg, data); + return eos_i2c_read8(OV2640_ADDR, reg, data, 1); } static int reg_write(uint8_t reg, uint8_t data) { - return eos_i2c_write8(OV2640_ADDR, reg, data); + return eos_i2c_write8(OV2640_ADDR, reg, &data, 1); } static int regarr_write(const uint8_t (*regs)[2]) { -- cgit v1.2.3