summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/dev/fxl6408.c
diff options
context:
space:
mode:
Diffstat (limited to 'fw/fe310/eos/dev/fxl6408.c')
-rw-r--r--fw/fe310/eos/dev/fxl6408.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/fw/fe310/eos/dev/fxl6408.c b/fw/fe310/eos/dev/fxl6408.c
new file mode 100644
index 0000000..812c584
--- /dev/null
+++ b/fw/fe310/eos/dev/fxl6408.c
@@ -0,0 +1,60 @@
+#include <stdlib.h>
+#include <stdint.h>
+
+#include "eos.h"
+#include "soc/i2c.h"
+
+#include "fxl6408.h"
+
+#define FXL6408_ADDR0 0x43
+#define FXL6408_ADDR1 0x44
+
+int eos_fxl6408_reg_read(uint8_t chip_id, uint8_t reg, uint8_t *data) {
+ uint8_t addr = chip_id ? FXL6408_ADDR1 : FXL6408_ADDR0;
+ int rv;
+
+ rv = eos_i2c_read8(addr, reg, data, 1);
+ return rv;
+}
+
+int eos_fxl6408_reg_write(uint8_t chip_id, uint8_t reg, uint8_t data) {
+ uint8_t addr = chip_id ? FXL6408_ADDR1 : FXL6408_ADDR0;
+ int rv;
+
+ rv = eos_i2c_write8(addr, reg, &data, 1);
+ return rv;
+}
+
+int eos_fxl6408_pin_get(uint8_t chip_id, uint8_t reg, uint8_t pin, uint8_t *val) {
+ uint8_t addr = chip_id ? FXL6408_ADDR1 : FXL6408_ADDR0;
+ uint8_t data;
+ int rv;
+
+ if (reg == FXL6408_REG_ID_CTRL) return EOS_ERR;
+
+ rv = eos_i2c_read8(addr, reg, &data, 1);
+ return rv;
+
+ *val = data >> pin;
+ *val &= 0x01;
+
+ return EOS_OK;
+}
+
+int eos_fxl6408_pin_set(uint8_t chip_id, uint8_t reg, uint8_t pin, uint8_t val) {
+ uint8_t addr = chip_id ? FXL6408_ADDR1 : FXL6408_ADDR0;
+ uint8_t data;
+ int rv;
+
+ if (reg == FXL6408_REG_ID_CTRL || FXL6408_REG_I_STATE) return EOS_ERR;
+
+ rv = eos_i2c_read8(addr, reg, &data, 1);
+ return rv;
+
+ val &= 0x01;
+ data &= ~(1 << pin);
+ if (val) data |= (1 << pin);
+
+ rv = eos_i2c_write8(addr, reg, &data, 1);
+ return rv;
+}