-
Notifications
You must be signed in to change notification settings - Fork 20
/
at24cxx.h
57 lines (48 loc) · 1.61 KB
/
at24cxx.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
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-04-13 XiaojieFan the first version
* 2019-12-04 RenMing Use PAGE WRITE instead of BYTE WRITE and input address can be selected
*/
#ifndef __AT24CXX_H__
#define __AT24CXX_H__
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#define AT24C01 0
#define AT24C02 1
#define AT24C04 2
#define AT24C08 3
#define AT24C16 4
#define AT24C32 5
#define AT24C64 6
#define AT24C128 7
#define AT24C256 8
#define AT24C512 9
#define AT24CTYPE 10 // Number of supported types
#define EE_TWR 5
#ifndef PKG_AT24CXX_EE_TYPE
#define PKG_AT24CXX_EE_TYPE AT24C02
#endif
#define AT24CXX_A0 (1 << 0)
#define AT24CXX_A1 (1 << 1)
#define AT24CXX_A2 (1 << 2)
struct at24cxx_device
{
struct rt_i2c_bus_device *i2c;
rt_mutex_t lock;
uint8_t AddrInput;
};
typedef struct at24cxx_device *at24cxx_device_t;
extern at24cxx_device_t at24cxx_init(const char *i2c_bus_name, uint8_t AddrInput);
extern rt_err_t at24cxx_check(at24cxx_device_t dev);
extern rt_err_t at24cxx_read(at24cxx_device_t dev, uint32_t ReadAddr, uint8_t *pBuffer, uint16_t NumToRead);
extern rt_err_t at24cxx_write(at24cxx_device_t dev, uint32_t WriteAddr, uint8_t *pBuffer, uint16_t NumToWrite);
extern rt_err_t at24cxx_page_read(at24cxx_device_t dev, uint32_t ReadAddr, uint8_t *pBuffer, uint16_t NumToRead);
extern rt_err_t at24cxx_page_write(at24cxx_device_t dev, uint32_t WriteAddr, uint8_t *pBuffer, uint16_t NumToWrite);
#endif