other proto for circle
[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_MAINBOARD_ADDR   1
26 #define I2C_MECHBOARD_ADDR   2
27 #define I2C_SENSORBOARD_ADDR 3
28
29 #define I2C_LEFT_SIDE   0
30 #define I2C_RIGHT_SIDE  1
31 #define I2C_AUTO_SIDE   2 /* for prepare_pickup */
32 #define I2C_CENTER_SIDE 3 /* for prepare_pickup */
33
34 #define I2C_COLOR_RED   0
35 #define I2C_COLOR_GREEN 1
36
37 #define I2C_AUTOBUILD_DEFAULT_DIST 210
38
39 struct i2c_cmd_hdr {
40         uint8_t cmd;
41 };
42
43 /****/
44 /* commands that do not need and answer */
45 /****/
46
47 #define I2C_CMD_GENERIC_LED_CONTROL 0x00
48
49 struct i2c_cmd_led_control {
50         struct i2c_cmd_hdr hdr;
51         uint8_t led_num:7;
52         uint8_t state:1;        
53 };
54
55 /****/
56
57 #define I2C_CMD_GENERIC_SET_COLOR 0x01
58
59 struct i2c_cmd_generic_color {
60         struct i2c_cmd_hdr hdr;
61         uint8_t color;
62 };
63
64 /****/
65
66 #define I2C_CMD_MECHBOARD_SET_MODE 0x02
67
68 struct i2c_cmd_mechboard_set_mode {
69         struct i2c_cmd_hdr hdr;
70 #define I2C_MECHBOARD_MODE_MANUAL             0x00
71 #define I2C_MECHBOARD_MODE_HARVEST            0x01
72 #define I2C_MECHBOARD_MODE_PREPARE_PICKUP     0x02
73 #define I2C_MECHBOARD_MODE_PICKUP             0x03
74 #define I2C_MECHBOARD_MODE_PREPARE_BUILD      0x04
75 #define I2C_MECHBOARD_MODE_AUTOBUILD          0x05
76 #define I2C_MECHBOARD_MODE_WAIT               0x06
77 #define I2C_MECHBOARD_MODE_INIT               0x07
78 #define I2C_MECHBOARD_MODE_PREPARE_GET_LINTEL 0x08
79 #define I2C_MECHBOARD_MODE_GET_LINTEL         0x09
80 #define I2C_MECHBOARD_MODE_PUT_LINTEL         0x0A
81 #define I2C_MECHBOARD_MODE_PREPARE_EJECT      0x0B
82 #define I2C_MECHBOARD_MODE_EJECT              0x0C
83 #define I2C_MECHBOARD_MODE_CLEAR              0x0D
84 #define I2C_MECHBOARD_MODE_LAZY_HARVEST       0x0E
85 #define I2C_MECHBOARD_MODE_LOADED             0x0F
86 #define I2C_MECHBOARD_MODE_PREPARE_INSIDE     0x10
87 #define I2C_MECHBOARD_MODE_STORE              0x11
88 #define I2C_MECHBOARD_MODE_LAZY_PICKUP        0x12
89 #define I2C_MECHBOARD_MODE_MANIVELLE          0x13
90 #define I2C_MECHBOARD_MODE_PUSH_TEMPLE        0x14
91 #define I2C_MECHBOARD_MODE_PUSH_TEMPLE_DISC   0x15
92 #define I2C_MECHBOARD_MODE_EXIT               0xFF
93         uint8_t mode;
94         union {
95                 struct {
96
97                 } manual;
98
99                 struct {
100                         uint8_t side;
101                         uint8_t next_mode;
102                 } prep_pickup;
103
104                 struct {
105                         uint8_t level_l;
106                         uint8_t level_r;
107                 } prep_build;
108
109                 struct {
110                         uint8_t side;
111                 } push_temple_disc;
112
113                 struct {
114                         uint8_t level;
115                 } push_temple;
116
117                 struct {
118                         uint8_t level_left;
119                         uint8_t level_right;
120                         uint8_t count_left;
121                         uint8_t count_right;
122                         uint8_t distance_left;
123                         uint8_t distance_right;
124                         uint8_t do_lintel;
125                 } autobuild;
126
127                 struct {
128                         uint8_t level_l;
129                         uint8_t level_r;
130                 } prep_inside;
131         };
132 };
133
134 /****/
135
136 /* only valid in manual mode */
137 #define I2C_CMD_MECHBOARD_ARM_GOTO 0x03
138
139 struct i2c_cmd_mechboard_arm_goto {
140         struct i2c_cmd_hdr hdr;
141 #define I2C_MECHBOARD_ARM_LEFT     0
142 #define I2C_MECHBOARD_ARM_RIGHT    1
143 #define I2C_MECHBOARD_ARM_BOTH     2
144         uint8_t which;
145
146         uint8_t height; /* in cm */
147         uint8_t distance; /* in cm */
148 };
149
150 /****/
151
152 #define I2C_CMD_SENSORBOARD_SET_BEACON 0x04
153
154 struct i2c_cmd_sensorboard_start_beacon {
155         struct i2c_cmd_hdr hdr;
156         uint8_t enable;
157 };
158
159
160 /****/
161
162 #define I2C_CMD_SENSORBOARD_SET_SCANNER 0x05
163
164 struct i2c_cmd_sensorboard_scanner {
165         struct i2c_cmd_hdr hdr;
166
167 #define I2C_SENSORBOARD_SCANNER_STOP    0x00
168 #define I2C_SENSORBOARD_SCANNER_PREPARE 0x01
169 #define I2C_SENSORBOARD_SCANNER_START   0x02
170         uint8_t mode;
171 };
172
173 /*****/
174
175 #define I2C_CMD_SENSORBOARD_CALIB_SCANNER 0x06
176 struct i2c_cmd_sensorboard_calib_scanner {
177         struct i2c_cmd_hdr hdr;
178 };
179
180 /*****/
181
182 #define I2C_CMD_SENSORBOARD_SCANNER_ALGO 0x07
183 struct i2c_cmd_sensorboard_scanner_algo {
184         struct i2c_cmd_hdr hdr;
185
186 #define I2C_SCANNER_ALGO_COLUMN_DROPZONE 1
187 #define I2C_SCANNER_ALGO_CHECK_TEMPLE    2
188 #define I2C_SCANNER_ALGO_TEMPLE_DROPZONE 3
189         uint8_t algo;
190
191         union {
192                 struct {
193 #define I2C_SCANNER_ZONE_0     0
194 #define I2C_SCANNER_ZONE_1     1
195 #define I2C_SCANNER_ZONE_DISC  2
196                         uint8_t working_zone;
197                         int16_t center_x;
198                         int16_t center_y;
199                 } drop_zone;
200                 
201                 struct {
202                         uint8_t level;
203                         int16_t temple_x;
204                         int16_t temple_y;
205                 } check_temple;
206         };
207 };
208
209 /****/
210 /* requests and their answers */
211 /****/
212
213
214 #define I2C_REQ_MECHBOARD_STATUS 0x80
215
216 struct i2c_req_mechboard_status {
217         struct i2c_cmd_hdr hdr;
218
219         int16_t pump_left1_current;
220         int16_t pump_left2_current;
221 };
222
223 #define I2C_ANS_MECHBOARD_STATUS 0x81
224
225 struct i2c_ans_mechboard_status {
226         struct i2c_cmd_hdr hdr;
227         /* mode type are defined above: I2C_MECHBOARD_MODE_xxx */
228         uint8_t mode;
229
230 #define I2C_MECHBOARD_STATUS_F_READY         0x00
231 #define I2C_MECHBOARD_STATUS_F_BUSY          0x01
232 #define I2C_MECHBOARD_STATUS_F_EXCPT         0x02
233         uint8_t status;
234
235         uint8_t lintel_count;
236
237         /* flag is there if column was taken by this pump. Note that
238          * we should also check ADC (current) to see if the column is
239          * still there. */
240 #define I2C_MECHBOARD_COLUMN_L1              0x01
241 #define I2C_MECHBOARD_COLUMN_L2              0x02
242 #define I2C_MECHBOARD_COLUMN_R1              0x04
243 #define I2C_MECHBOARD_COLUMN_R2              0x08
244         uint8_t column_flags;
245         
246         int16_t pump_left1;
247         int16_t pump_right1;
248         int16_t pump_left2;
249         int16_t pump_right2;
250
251 #define I2C_MECHBOARD_CURRENT_COLUMN 85
252         int16_t pump_right1_current;
253         int16_t pump_right2_current;
254
255         uint16_t servo_lintel_left;
256         uint16_t servo_lintel_right;
257 };
258
259 #define I2C_REQ_SENSORBOARD_STATUS 0x82
260
261 struct i2c_req_sensorboard_status {
262         struct i2c_cmd_hdr hdr;
263
264         /* position sent by mainboard */
265         int16_t x;
266         int16_t y;
267         int16_t a;
268
269         /* PWM for pickup */
270         uint8_t enable_pickup_wheels;
271 };
272
273 #define I2C_ANS_SENSORBOARD_STATUS 0x83
274
275 struct i2c_ans_sensorboard_status {
276         struct i2c_cmd_hdr hdr;
277
278         uint8_t status;
279 #define I2C_OPPONENT_NOT_THERE -1000
280         int16_t opponent_x;
281         int16_t opponent_y;
282         int16_t opponent_a;
283         int16_t opponent_d;
284
285 #define I2C_SCAN_DONE 1
286 #define I2C_SCAN_MAX_COLUMN 2
287         uint8_t scan_status;
288
289 #define I2C_COLUMN_NO_DROPZONE -1
290         int8_t dropzone_h;
291         int16_t dropzone_x;
292         int16_t dropzone_y;
293 };
294
295 #endif /* _I2C_PROTOCOL_H_ */