Hardware Reference
In-Depth Information
41 unsigned long i2c_funcs = 0; /
Support flags
/
42 int rc;
43
44 i2c_fd = open(node,O_RDWR); /
Open driver/dev/i2s−1
/
45 if ( i2c_fd < 0 ) {
46 perror("Opening/dev/i2s−1");
47 puts("Check that the i2c−dev & i2c−bcm2708 kernel modules"
48 "are loaded.");
49 abort();
50 }
51
52 /
53
Make sure the driver supports plain I2C I/O:
54
/
55 rc = ioctl(i2c_fd,I2C_FUNCS,&i2c_funcs);
56 assert(rc >= 0);
57 assert(i2c_funcs & I2C_FUNC_I2C);
58 }
59
60 /
61
Configure the nunchuk for no encryption:
62
/
63 static void
64 nunchuk_init(void) {
65 static char init_msg1[] = {0xF0, 0x55};
66 static char init_msg2[] = {0xFB, 0x00};
67 struct i2c_rdwr_ioctl_data msgset;
68 struct i2c_msg iomsgs[1];
69 int rc;
70
71 iomsgs[0].addr = 0x52; /
Address of Nunchuk
/
72 iomsgs[0].flags = 0; /
Write
/
73 iomsgs[0].buf = init_msg1; /
Nunchuk 2 byte sequence
/
74 iomsgs[0].len = 2; /
2 bytes
/
75
76 msgset.msgs = iomsgs;
77 msgset.nmsgs = 1;
78
79 rc = ioctl(i2c_fd,I2C_RDWR,&msgset);
80 assert(rc == 1);
81
82 timed_wait(0,200,0); /
Nunchuk needs time
/
83
84 iomsgs[0].addr = 0x52; /
Address of Nunchuk
/
85 iomsgs[0].flags = 0; /
Write
/
86 iomsgs[0].buf = init_msg2; /
Nunchuk 2 byte sequence
/
87 iomsgs[0].len = 2; /
2 bytes
/
88
Search WWH ::




Custom Search