From 4566511371a8a80201c1adb0535cde722cbd9b48 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Mon, 29 Mar 2021 13:39:54 +0200 Subject: moved i2c from esp32 to fe310. added bq25895, drv2605 and lsm9ds1 i2c support --- fw/fe310/eos/eos.c | 2 ++ fw/fe310/eos/i2c/Makefile | 17 +++++++++++++++++ fw/fe310/eos/i2c/bq25895.c | 24 ++++++++++++++++++++++++ fw/fe310/eos/i2c/bq25895.h | 5 +++++ fw/fe310/eos/i2c/drv2605.h | 3 +++ fw/fe310/eos/i2c/lsm9ds1.h | 4 ++++ 6 files changed, 55 insertions(+) create mode 100644 fw/fe310/eos/i2c/Makefile create mode 100644 fw/fe310/eos/i2c/bq25895.c create mode 100644 fw/fe310/eos/i2c/bq25895.h create mode 100644 fw/fe310/eos/i2c/drv2605.h create mode 100644 fw/fe310/eos/i2c/lsm9ds1.h (limited to 'fw/fe310/eos') diff --git a/fw/fe310/eos/eos.c b/fw/fe310/eos/eos.c index 91115f6..2a7f992 100644 --- a/fw/fe310/eos/eos.c +++ b/fw/fe310/eos/eos.c @@ -11,6 +11,7 @@ #include "wifi.h" #include "cell.h" #include "sock.h" +#include "i2c/bq25895.h" #include "eve/eve.h" #include "eos.h" @@ -33,6 +34,7 @@ void eos_init(void) { eos_cell_init(); eos_sock_init(); eos_spi_dev_init(); + eos_bq25895_init(); eos_net_wake(wakeup_cause); diff --git a/fw/fe310/eos/i2c/Makefile b/fw/fe310/eos/i2c/Makefile new file mode 100644 index 0000000..694fbf8 --- /dev/null +++ b/fw/fe310/eos/i2c/Makefile @@ -0,0 +1,17 @@ +include ../../common.mk + +CFLAGS += -I.. + +obj = bq25895.o + + +%.o: %.c %.h + $(CC) $(CFLAGS) -c $< + +%.o: %.S + $(CC) $(CFLAGS) -c $< + +all: $(obj) + +clean: + rm -f *.o diff --git a/fw/fe310/eos/i2c/bq25895.c b/fw/fe310/eos/i2c/bq25895.c new file mode 100644 index 0000000..ab56904 --- /dev/null +++ b/fw/fe310/eos/i2c/bq25895.c @@ -0,0 +1,24 @@ +#include +#include +#include + +#include "eos.h" +#include "i2c.h" +#include "i2c/bq25895.h" + +void eos_bq25895_init(void) { + uint8_t data = 0; + int i, ret = EOS_OK; + + eos_i2c_start(400000); + eos_i2c_write8(BQ25895_ADDR, 0, 0x26); // input current: 2.0 A + eos_i2c_write8(BQ25895_ADDR, 2, 0x28); + eos_i2c_write8(BQ25895_ADDR, 7, 0x8d); + + 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); + } + eos_i2c_stop(); +} diff --git a/fw/fe310/eos/i2c/bq25895.h b/fw/fe310/eos/i2c/bq25895.h new file mode 100644 index 0000000..f61a46f --- /dev/null +++ b/fw/fe310/eos/i2c/bq25895.h @@ -0,0 +1,5 @@ +#include + +#define BQ25895_ADDR 0x6A + +void eos_bq25895_init(void); diff --git a/fw/fe310/eos/i2c/drv2605.h b/fw/fe310/eos/i2c/drv2605.h new file mode 100644 index 0000000..fe90a9b --- /dev/null +++ b/fw/fe310/eos/i2c/drv2605.h @@ -0,0 +1,3 @@ +#include + +#define DRV2605_ADDR 0x5A diff --git a/fw/fe310/eos/i2c/lsm9ds1.h b/fw/fe310/eos/i2c/lsm9ds1.h new file mode 100644 index 0000000..92220e7 --- /dev/null +++ b/fw/fe310/eos/i2c/lsm9ds1.h @@ -0,0 +1,4 @@ +#include + +#define LSM9DS1_ADDR_AG 0x1E +#define LSM9DS1_ADDR_M 0x6B -- cgit v1.2.3