Hardware Reference
In-Depth Information
25
/
26 rc = ioctl(i2c_fd,I2C_FUNCS,&i2c_funcs);
27 assert(rc >= 0);
28 assert(i2c_funcs & I2C_FUNC_I2C);
29 }
30
31 /
32
Close the I2C driver :
33
/
34 static void
35 i2c_close(void) {
36 close(i2c_fd);
37 i2c_fd = −1;
38 }
39
40 /
End i2c_common.c
/
1 /
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
2
ds1307set.c : Set real−time DS1307 clock on I2C bus
3
/
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <ctype.h>
8 #include <time.h>
9 #include <fcntl.h>
10 #include <unistd . h>
11 #include <string . h>
12 #include <errno . h>
13 #include <assert . h>
14 #include <sys / i octl . h>
15 #include <l inux / i2c−dev . h>
16
17 #include "i2c_common.c" /
I2C routines
/
18 #include "ds1307.h" /
DS1307 types
/
19
20 /
Change to i2c−0 if using early Raspberry Pi
/
21 static const char
node = "/dev/i2c−1";
22
23 /
24
Write [ S ] 0xB0 <regaddr> <rtcbuf[0]> . . . <rtcbuf[n−1]> [P]
25
/
26 static int
27 i2c_wr_rtc(ds1307_rtc_regs
rtc) {
28 struct i2c_rdwr_ioctl_data msgset;
29 struct i2c_msg iomsgs[1];
30 char buf[sizeof
rtc+1]; /
Work buffer
/
31
Search WWH ::




Custom Search