/* Write memory, this function manages writing data beyond a pages size (16 bytes)  */
uint8_t ts_write_memory(uint16_t address, uint16_t size, uint8_t *buf)
/* Write memory, this function manages writing data beyond a pages size (16 bytes)  */
uint8_t ts_write_memory(uint16_t address, uint16_t size, uint8_t *buf)
{
	uint8_t write_size              = 0;
	uint8_t n                       = 0;
	uint16_t end_page_addr          = 0;
	uint8_t *buf_ptr                = 0;
	buf_ptr = buf;
	do {
		n = (uint16_t)(address / PAGE_SIZE);
		end_page_addr = ((n + 1) * PAGE_SIZE);
		if ((address + size) > end_page_addr) {
			write_size = end_page_addr - address;
		} else {
			write_size = size;
		}
		at30ts_status = ts_write_eeprom(address, write_size, buf_ptr);
		if (at30ts_status != TWI_SUCCESS) {
			return at30ts_status;
		}
		size -= write_size;
		address += write_size;
		buf_ptr += write_size;
	} while (size);
	return TWI_SUCCESS;
}