This repository has been archived by the owner on Jan 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathi2c-at24.h
58 lines (49 loc) · 2.52 KB
/
i2c-at24.h
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// SPDX-License-Identifier: CC0-1.0
/*
* Written in 2021 by Noralf Trønnes <noralf@tronnes.org>
*
* To the extent possible under law, the author(s) have dedicated all copyright and related and
* neighboring rights to this software to the public domain worldwide. This software is
* distributed without any warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication along with this software.
* If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#ifndef _I2C_AT24_H_
#define _I2C_AT24_H_
#include "dln2-devices.h"
struct i2c_at24_device_data {
unsigned int offset;
};
struct i2c_at24_device {
struct dln2_i2c_device base;
struct i2c_at24_device_data *data;
size_t size;
size_t addr_size;
const void *initial_data;
size_t initial_data_size;
bool readonly;
};
#define DEFINE_I2C_AT24(_var, _addr, _idata, _isize, _name, _size, _addr_size) \
struct i2c_at24_device_data _var##_data; \
struct i2c_at24_device (_var) = { \
.base = { \
.name = _name, \
.address = (_addr), \
.read = i2c_at24_read, \
.write = i2c_at24_write, \
}, \
.data = &(_var##_data), \
.size = (_size), \
.addr_size = (_addr_size), \
.initial_data = _idata, \
.initial_data_size = _isize, \
}
#define DEFINE_I2C_AT24C32(_var, _addr, _idata, _isize) DEFINE_I2C_AT24(_var, _addr, _idata, _isize, "24c32", 4 * 1024, 2)
//#define DEFINE_I2C_AT24C256(_var, _addr) DEFINE_I2C_AT24(_var, _addr, "24c256", 32 * 1024, 2)
bool i2c_at24_read(const struct dln2_i2c_device *dev, uint16_t address, void *buf, size_t len);
bool i2c_at24_write(const struct dln2_i2c_device *dev, uint16_t address, const void *buf, size_t len);
void i2c_at24_memcpy(void *dst, const void *src, unsigned int offset, size_t len, size_t max_len);
int i2c_at24_flash_read(const struct i2c_at24_device *at24, uint16_t address, unsigned int offset, void *buf, size_t len);
bool i2c_at24_flash_write(const struct i2c_at24_device *at24, uint16_t address, unsigned int offset, const void *buf, size_t len);
#endif