root / trunk / code / projects / libdragonfly / purgatory / i2c.h @ 8
History | View | Annotate | Download (1.92 KB)
1 |
/**
|
---|---|
2 |
* @file i2c.h
|
3 |
* @brief Definitions for i2c.
|
4 |
*
|
5 |
* Definitions for i2c. KEVIN - what is i2c?
|
6 |
*
|
7 |
* @author CMU Robotics Club
|
8 |
**/
|
9 |
|
10 |
|
11 |
#ifndef _I2C_H_
|
12 |
#define _I2C_H_
|
13 |
|
14 |
#include <stddef.h> |
15 |
|
16 |
// for i2c_byte coming from charge board
|
17 |
//I2C Message Codes
|
18 |
#define I2C_MSG_ACKNOWLEDGE 'A' |
19 |
#define I2C_MSG_BATTERY_CHARGING 'C' |
20 |
#define I2C_MSG_DATA 'D' |
21 |
#define I2C_MSG_CONTACT_ERROR 'E' |
22 |
#define I2C_MSG_BATTERY_FULL 'F' |
23 |
#define I2C_MSG_NO_CONTACT 'N' |
24 |
#define I2C_MSG_REQUEST_DATA 'R' |
25 |
#define I2C_MSG_GO_TO_SLEEP 'Y' |
26 |
#define I2C_MSG_ENTERING_SLEEP 'Z' |
27 |
|
28 |
char i2c_prev_byte; //store first byte of i2c packet (255 if null) |
29 |
|
30 |
// for i2c_register (checked in charging FSM)
|
31 |
#define I2C_REG_DEFAULT 0 |
32 |
#define I2C_REG_CHARGING 1 |
33 |
#define I2C_REG_CONTACT_ERROR 2 |
34 |
#define I2C_REG_BATTERY_FULL 3 |
35 |
#define I2C_REG_NO_CONTACT 4 |
36 |
int i2c_register;
|
37 |
|
38 |
/** @brief KEVIN **/
|
39 |
typedef void (*fun_srecv_t)(char); |
40 |
|
41 |
/** @brief KEVIN **/
|
42 |
typedef int (*fun_mrecv_t)(char); |
43 |
|
44 |
/** @brief KEVIN **/
|
45 |
typedef char (*fun_send_t)(void); |
46 |
|
47 |
/** @brief KEVIN **/
|
48 |
int i2c_init(char addr, fun_mrecv_t master_recv, fun_srecv_t slave_recv, fun_send_t slave_send); |
49 |
|
50 |
/** @brief KEVIN **/
|
51 |
void i2c_clear(void); |
52 |
|
53 |
/** @brief A function for the master to send data to a slave. **/
|
54 |
int i2c_send(char dest, char* data, size_t bytes); |
55 |
|
56 |
/** @brief KEVIN **/
|
57 |
int i2c_request(char dest); |
58 |
|
59 |
/** @brief KEVIN **/
|
60 |
void i2c_packet_rec (char i2c_byte); |
61 |
/** @brief KEVIN **/
|
62 |
void i2c_packet_sniff(char data); |
63 |
|
64 |
|
65 |
|
66 |
unsigned char i2c_homing_sensor_data; |
67 |
unsigned char i2c_homing_sensor_data_dirty; |
68 |
//data dirty-ness
|
69 |
//data is dirty if the user decides so (generally, after it is used and new data is required).
|
70 |
//the bit set to 1 will mark the data with the same name as dirty.
|
71 |
//each time a new sensor value is read, the dirty bit is set to fresh, indicating that new data was available.
|
72 |
#define I2C_DATA_FRESH 0 //fresh = not dirty |
73 |
#define I2C_DATA_DIRTY 1 //dirty is true |
74 |
|
75 |
|
76 |
#endif
|