/* Read any number of bytes from EEPROM memory. The read can be any number of bytes. Before the read is done the memory index must be placed at the desired location using a write with a repead start then a read. */
int32_t memory_read(struct memory_desc *dev, uint16_t address, uint8_t *data, uint32_t size)
/* Read any number of bytes from EEPROM memory. The read can be any number of bytes. Before the read is done the memory index must be placed at the desired location using a write with a repead start then a read. */
int32_t memory_read(struct memory_desc *dev, uint16_t address, uint8_t *data, uint32_t size)
{
	int32_t ret = 0;
	uint8_t *transmit_array;
	uint16_t shifted_address;
	shifted_address = MEMORY_PROTECTED_SIZE + address;
	if((shifted_address + size) > MEMORY_SIZE_BYTES)
		size = MEMORY_SIZE_BYTES - shifted_address;
	transmit_array = calloc(2, sizeof *transmit_array);
	if (!transmit_array)
		return -1;
	transmit_array[0] = (shifted_address & 0xff00) >> 8;
	transmit_array[1] = (shifted_address & 0x00ff) >> 0;
	ret = i2c_write(dev->i2c_dev, transmit_array, 2, false);
	if(ret < 0)
		goto finish;
	ret = i2c_read(dev->i2c_dev, data, size, true);
finish:
	free(transmit_array);
	return ret;
}