poppy_com  0.1
Poppy2.0 communication library
 All Classes Files Functions Variables Enumerations Enumerator Pages
i2c_master.c
1 #include "poppy-com/inc/i2c_master.h"
2 #include HAL
3 
4 // I2C Master mode
5 
6 // Global variables
7 extern context_t ctx;
8 
9 unsigned char set_extern_id(unsigned char addr, unsigned char newid) {
10  if (i2cAddr(addr, TX)) {
11  i2c_transmit(STOP);
12  return 1;
13  }
14  if (i2cWrite(WRITE_ID)) {
15  i2c_transmit(STOP);
16  return 1;
17  }
18  if (i2cWrite(newid)) {
19  i2c_transmit(STOP);
20  return 1;
21  }
22  i2cWrite(crc(&newid, 1));
23  i2c_transmit(STOP);
24  return 0;
25 }
26 
27 unsigned char get_extern_module_type(unsigned char addr,
28  unsigned char *module_type) {
29  if (i2cAddr(addr, TX)) {
30  i2c_transmit(STOP);
31  return 1;
32  }
33  if (i2cWrite(GET_MODULE_TYPE)) {
34  i2c_transmit(STOP);
35  return 1;
36  }
37  if (i2cAddr(addr, RX)) {
38  i2c_transmit(STOP);
39  return 1;
40  }
41  if (i2cRead(FALSE, module_type)) {
42  i2c_transmit(STOP);
43  return 1;
44  }
45  i2c_transmit(STOP);
46  return 0;
47 }
48 
49 
50  // // Reply with ID
51  // SET_ID,
52  // ping(unsigned char addr);
53  // // Reply with module_type number
54  // GET_MODULE_TYPE,
55  // // Reply with a status register
56  // GET_STATUS,
57  // // Reply with the actual firmware revision number
58  // GET_FIRM_REVISION,