/* Reads a buffer of data from the emulated EEPROM memory space. 
Reads a buffer of data from a section of emulated EEPROM memory space. The destination buffer may be of any size, and the source may lie outside of an emulated EEPROM page boundary. */
enum status_code eeprom_emulator_read_buffer(const uint16_t offset, uint8_t *const data, const uint16_t length)
/* Reads a buffer of data from the emulated EEPROM memory space. 
Reads a buffer of data from a section of emulated EEPROM memory space. The destination buffer may be of any size, and the source may lie outside of an emulated EEPROM page boundary. */
enum status_code eeprom_emulator_read_buffer(const uint16_t offset, uint8_t *const data, const uint16_t length)
{
	enum status_code error_code;
	uint8_t buffer[EEPROM_PAGE_SIZE];
	uint8_t logical_page = offset / EEPROM_PAGE_SIZE;
	uint16_t c = offset;
	error_code = eeprom_emulator_read_page(logical_page, buffer);
	if (error_code != STATUS_OK) {
		return error_code;
	}
	if ((offset % EEPROM_PAGE_SIZE) == 0) {
		data[0] = buffer[0];
		c=c+1;
	}
	for (; c < (length + offset); c++) {
		if ((c % EEPROM_PAGE_SIZE) == 0) {
			logical_page++;
			error_code = eeprom_emulator_read_page(logical_page, buffer);
			if (error_code != STATUS_OK) {
				return error_code;
			}
		}
		data[c - offset] = buffer[c % EEPROM_PAGE_SIZE];
	}
	return error_code;
}