From b4ecd612f7184cbf23d83ef78b0ccb5ed2c318e3 Mon Sep 17 00:00:00 2001 From: Tomasz Moń Date: Sat, 10 Jul 2021 08:56:32 +0200 Subject: 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 --- firmware/drivers/generic_i2c.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'firmware/drivers/generic_i2c.c') 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) { -- cgit v1.2.3