summaryrefslogtreecommitdiff
path: root/src/driver/eeprom24lc64.cc
blob: 1c8158a348ada8ec43a40d3eaba6eee0619e9e1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
 * Copyright 2020 Daniel Friesel
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */
#include <stdlib.h>
#include "driver/eeprom24lc64.h"
#if defined(MULTIPASS_ARCH_HAS_I2C) && !defined(CONFIG_driver_softi2c)
#include "driver/i2c.h"
#else
#include "driver/soft_i2c.h"
#endif

void EEPROM24LC64::readPage(unsigned short addr, char *data)
{
	txbuf[0] = addr >> 8;
	txbuf[1] = addr & 0x00ff;
	i2c.xmit(address, 2, txbuf, 32, (unsigned char *)data);
}

void EEPROM24LC64::writePage(unsigned short addr, char *data)
{
	txbuf[0] = addr >> 8;
	txbuf[1] = addr & 0x00ff;
	for (unsigned char i = 0; i < 32; i++) {
		txbuf[i+2] = data[i];
	}
	i2c.xmit(address, 34, txbuf, 0, NULL);
}

EEPROM24LC64 eeprom24lc64(0x50);