summaryrefslogtreecommitdiff
path: root/firmware/drivers
diff options
context:
space:
mode:
authorTomasz Moń <desowin@gmail.com>2021-07-10 08:56:32 +0200
committerTomasz Moń <desowin@gmail.com>2021-07-10 08:56:32 +0200
commitb4ecd612f7184cbf23d83ef78b0ccb5ed2c318e3 (patch)
treed0c25f174efbfa49612b5bdb7d6f6adf3e146ed6 /firmware/drivers
parent663539619c05d9b429dfbea1e5d38d8bb043ee03 (diff)
Sansa Connect: Use deviceid in USB Serial Number
Atmel AT88SC6416C CryptoMemory is almost I2C compatible. The device is connected to bitbanged I2C bus shared with compliant I2C devices. Change-Id: Iec54702db1bdfb93c01291eef18ec60391c63b16
Diffstat (limited to 'firmware/drivers')
-rw-r--r--firmware/drivers/generic_i2c.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/firmware/drivers/generic_i2c.c b/firmware/drivers/generic_i2c.c
index effb5372b4..9fd90b5b2c 100644
--- a/firmware/drivers/generic_i2c.c
+++ b/firmware/drivers/generic_i2c.c
@@ -198,6 +198,40 @@ end:
return ret;
}
+int i2c_write_read_data(int bus_index, int bus_address,
+ const unsigned char* buf_write, int count_write,
+ unsigned char* buf_read, int count_read)
+{
+ int i;
+ int ret = 0;
+ const struct i2c_interface *iface = i2c_if[bus_index];
+
+ i2c_start(iface);
+ if (!i2c_outb(iface, bus_address))
+ {
+ ret = -2;
+ goto end;
+ }
+
+ for(i = 0;i < count_write;i++)
+ {
+ if (!i2c_outb(iface, buf_write[i]))
+ {
+ ret = -3;
+ goto end;
+ }
+ }
+
+ for(i = 0;i < count_read-1;i++)
+ buf_read[i] = i2c_inb(iface, true);
+
+ buf_read[i] = i2c_inb(iface, false);
+
+end:
+ i2c_stop(iface);
+ return ret;
+}
+
/* returns bus index which can be used as a handle, or <0 on error */
int i2c_add_node(const struct i2c_interface *iface)
{