at24c32 access library
at24c32.h
Go to the documentation of this file.
1 /* @file */
13 #ifndef AT23C32
14 #define AT23C32
15 
16 #include <stdio.h>
17 #include <sys/ioctl.h>
18 #include <string.h>
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <linux/i2c.h>
22 #include <linux/i2c-dev.h>
23 #include <linux/fs.h>
24 #include <fcntl.h>
25 #include <errno.h>
26 #include <smbus_access.h>
27 #include <stdbool.h>
28 
29 #define I2C_DRIVER "/dev/i2c-1"
30 #define AT24C32 0x50
31 #define AT24C32_SUCCESS 0
32 #define AT24C32_SIZE 4096
33 
34 /* at24c32Open:
35  * open the device driver, check if all necessary functions are available
36  * set the I2C slave address
37  */
38 int at24c32Open(void);
39 
40 /* at24c32Close:
41  * closes the device driver
42  */
43 int at24c32Close(int);
44 
45 /* at24c32ByteWrite:
46  * write a single byte to the at24c32
47  * parameters:
48  * int: fd: file descriptor returned by at24c32Open
49  * unsigned short: the address within the at24c32
50  * where the data must be written
51  * unsigned char: the data to be written
52  * returns: AT24C32_SUCCESS if everything is fine, errno otherwise
53  */
54 int at24c32ByteWrite(int, unsigned short, unsigned char);
55 
56 /* at24c32ByteRead:
57  * write a single byte to the at24c32
58 
59  * parameters:
60  * int: fd: file descriptor returned by at24c32Open
61  * unsigned short: the address within the at24c32
62  * where the data must be read from
63  * returns
64  * unsigned char: data read
65  */
66 unsigned char at24c32ByteRead(int, unsigned short);
67 
68 /* at24c32BlockRead:
69  * read a block of 32 bytes from the at24c32
70  * parameters:
71  * int: fd: file descriptor returned by at24c32Open
72  * unsigned short: the address within the at24c32
73  * where the data must be read from
74  * unsigned char: number of bytes to be read
75  * returns
76  * unsigned char*: a pointer to the 32 bytes of data
77  * The Linux i2c driver on the Raspberry does not implement
78  * block reads. Here we similate it by sequencially reading
79  * 32 bytes and saving it into a 32 byte buffer
80  */
81 int at24c32BlockWrite(int, unsigned short, unsigned short, unsigned char *);
82 
83 /* at24c32BlockRead:
84  * write a block of 32 bytes to the at24c32
85  * parameters:
86  * int: fd: file descriptor returned by at24c32Open
87  * unsigned short: the address within the at24c32
88  * where the data must be read from
89  * unsigned short: length of data buffer to be written
90  * char *: pointer to the data
91  * returns
92  * int: AT24C32_SUCCESS if everything went well
93  * errno otherwise
94  * The Linux i2c driver on the Raspberry does not implement
95  * block reads. Here we similate it by sequencially reading
96  * 32 bytes and saving it into a 32 byte buffer
97  */
98 unsigned char *at24c32BlockRead(int, unsigned short, unsigned short);
99 
100 unsigned char at24c32CurrentAddressRead(int);
101 /* at24c32SetDebug:
102  * switches debugging messages on or off
103  * parameters:
104  * bool: true: debugging on, false: debugging off
105  */
106 void at24c32SetDebug(bool);
107 #endif
void at24c32SetDebug(bool)
switches debug mode on or off
Definition: at24c32Debug.c:22
include file with inline access routines to talk to the i2c driver
int at24c32ByteWrite(int, unsigned short, unsigned char)
writes a byte to the EEPROM
Definition: at24c32Write.c:28
unsigned char * at24c32BlockRead(int, unsigned short, unsigned short)
reads a block of data from the EEPROM
Definition: at24c32Read.c:56
unsigned char at24c32ByteRead(int, unsigned short)
reads a byte from the EEPROM
Definition: at24c32Read.c:25
int at24c32BlockWrite(int, unsigned short, unsigned short, unsigned char *)
writes a block of data to the EEPROM
Definition: at24c32Write.c:66
int at24c32Open(void)
Definition: at24c32Open.c:23
int at24c32Close(int)
closes the i2c driver
Definition: at24c32Open.c:68