c0ff8e16e774c153d139e9ec7d634be640a2153c
[aversive.git] / projects / microb2010 / common / i2c_commands.h
1 /*
2  *  Copyright Droids Corporation (2007)
3  * 
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  *
18  *  Revision : $Id: i2c_commands.h,v 1.9 2009-05-27 20:04:06 zer0 Exp $
19  *
20  */
21
22 #ifndef _I2C_COMMANDS_H_
23 #define _I2C_COMMANDS_H_
24
25 #define I2C_OPPONENT_NOT_THERE -1000
26
27 #define I2C_MAINBOARD_ADDR   1
28 #define I2C_COBBOARD_ADDR    2
29 #define I2C_BALLBOARD_ADDR   3
30
31 #define I2C_LEFT_SIDE    0
32 #define I2C_RIGHT_SIDE   1
33 #define I2C_AUTO_SIDE    2
34 #define I2C_CENTER_SIDE  3
35
36 #define I2C_COLOR_YELLOW 0
37 #define I2C_COLOR_BLUE   1
38
39 #define I2C_COB_BLACK   0
40 #define I2C_COB_WHITE   1
41 #define I2C_COB_UNKNOWN 2
42 #define I2C_COB_REMOVED 3
43
44 struct i2c_cmd_hdr {
45         uint8_t cmd;
46 };
47
48 /****/
49 /* commands that do not need and answer */
50 /****/
51
52 #define I2C_CMD_GENERIC_LED_CONTROL 0x00
53
54 struct i2c_cmd_led_control {
55         struct i2c_cmd_hdr hdr;
56         uint8_t led_num:7;
57         uint8_t state:1;
58 };
59
60 /****/
61
62 #define I2C_CMD_GENERIC_SET_COLOR 0x01
63
64 struct i2c_cmd_generic_color {
65         struct i2c_cmd_hdr hdr;
66         uint8_t color;
67 };
68
69 /****/
70
71 #define I2C_CMD_COBBOARD_SET_MODE 0x02
72
73 /* XXX disabled, use memory sync instead */
74 struct i2c_cmd_cobboard_set_mode {
75         struct i2c_cmd_hdr hdr;
76
77 #define I2C_COBBOARD_MODE_L_DEPLOY     0x01 /* deploy the spickle */
78 #define I2C_COBBOARD_MODE_L_HARVEST    0x02 /* auto harvest withe cobs */
79 #define I2C_COBBOARD_MODE_R_DEPLOY     0x04 /* deploy the spickle */
80 #define I2C_COBBOARD_MODE_R_HARVEST    0x08 /* auto harvest withe cobs */
81 #define I2C_COBBOARD_MODE_EJECT        0x10 /* eject cobs */
82 #define I2C_COBBOARD_MODE_INIT         0x20 /* init state machine */
83         //uint8_t mode;
84 };
85
86 #define I2C_CMD_BALLBOARD_SET_MODE 0x10
87
88 struct i2c_cmd_ballboard_set_mode {
89         struct i2c_cmd_hdr hdr;
90
91 #define I2C_BALLBOARD_MODE_INIT        0x00
92 #define I2C_BALLBOARD_MODE_OFF         0x01
93 #define I2C_BALLBOARD_MODE_HARVEST     0x02
94 #define I2C_BALLBOARD_MODE_EJECT       0x03
95 #define I2C_BALLBOARD_MODE_PREP_L_FORK 0x04
96 #define I2C_BALLBOARD_MODE_TAKE_L_FORK 0x05
97 #define I2C_BALLBOARD_MODE_PREP_R_FORK 0x06
98 #define I2C_BALLBOARD_MODE_TAKE_R_FORK 0x07
99         uint8_t mode;
100 };
101
102 /****/
103 /* requests and their answers */
104 /****/
105
106
107 #define I2C_REQ_COBBOARD_STATUS 0x80
108
109 struct i2c_req_cobboard_status {
110         struct i2c_cmd_hdr hdr;
111         uint8_t mode;
112 };
113
114 #define I2C_ANS_COBBOARD_STATUS 0x81
115
116 struct i2c_ans_cobboard_status {
117         struct i2c_cmd_hdr hdr;
118         /* mode type are defined above: I2C_COBBOARD_MODE_xxx */
119         uint8_t mode;
120
121 #define I2C_COBBOARD_STATUS_READY         0x00
122 #define I2C_COBBOARD_STATUS_LBUSY         0x01
123 #define I2C_COBBOARD_STATUS_RBUSY         0x02
124 #define I2C_COBBOARD_STATUS_EJECT         0x03
125         uint8_t status;
126
127         uint8_t cob_count;
128
129         int16_t left_cobroller_speed;
130         int16_t right_cobroller_speed;
131 };
132
133 #define I2C_REQ_BALLBOARD_STATUS 0x82
134
135 struct i2c_req_ballboard_status {
136         struct i2c_cmd_hdr hdr;
137 };
138
139 #define I2C_ANS_BALLBOARD_STATUS 0x83
140
141 struct i2c_ans_ballboard_status {
142         struct i2c_cmd_hdr hdr;
143
144         uint8_t mode;
145
146 #define I2C_BALLBOARD_STATUS_F_READY         0x00
147 #define I2C_BALLBOARD_STATUS_F_BUSY          0x01
148 #define I2C_BALLBOARD_STATUS_F_EXCPT         0x02
149         uint8_t status;
150
151         uint8_t ball_count;
152 };
153
154 #endif /* _I2C_PROTOCOL_H_ */