prepare cobboard and ballboard
[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_COBBOARD_ADDR    2
27 #define I2C_BALLBOARD_ADDR   3
28
29 #define I2C_LEFT_SIDE   0
30 #define I2C_RIGHT_SIDE  1
31 #define I2C_AUTO_SIDE   2
32 #define I2C_CENTER_SIDE 3
33
34 #define I2C_COLOR_RED   0
35 #define I2C_COLOR_GREEN 1
36
37 struct i2c_cmd_hdr {
38         uint8_t cmd;
39 };
40
41 /****/
42 /* commands that do not need and answer */
43 /****/
44
45 #define I2C_CMD_GENERIC_LED_CONTROL 0x00
46
47 struct i2c_cmd_led_control {
48         struct i2c_cmd_hdr hdr;
49         uint8_t led_num:7;
50         uint8_t state:1;        
51 };
52
53 /****/
54
55 #define I2C_CMD_GENERIC_SET_COLOR 0x01
56
57 struct i2c_cmd_generic_color {
58         struct i2c_cmd_hdr hdr;
59         uint8_t color;
60 };
61
62 /****/
63
64 #define I2C_CMD_COBBOARD_SET_MODE 0x02
65
66 struct i2c_cmd_cobboard_set_mode {
67         struct i2c_cmd_hdr hdr;
68 #define I2C_COBBOARD_MODE_INIT               0x00
69 #define I2C_COBBOARD_MODE_MANUAL             0x01
70 #define I2C_COBBOARD_MODE_HARVEST            0x02
71 #define I2C_COBBOARD_MODE_EXIT               0xFF
72         uint8_t mode;
73         union {
74                 struct {
75                 } manual;
76
77                 struct {
78                 } harvest;
79         };
80 };
81
82 /****/
83 /* requests and their answers */
84 /****/
85
86
87 #define I2C_REQ_COBBOARD_STATUS 0x80
88
89 struct i2c_req_cobboard_status {
90         struct i2c_cmd_hdr hdr;
91         int16_t sickle_left1_current;
92 };
93
94 #define I2C_ANS_COBBOARD_STATUS 0x81
95
96 struct i2c_ans_cobboard_status {
97         struct i2c_cmd_hdr hdr;
98         /* mode type are defined above: I2C_COBBOARD_MODE_xxx */
99         uint8_t mode;
100
101 #define I2C_COBBOARD_STATUS_F_READY         0x00
102 #define I2C_COBBOARD_STATUS_F_BUSY          0x01
103 #define I2C_COBBOARD_STATUS_F_EXCPT         0x02
104         uint8_t status;
105
106         uint8_t cob_count;
107 };
108
109 #define I2C_REQ_BALLBOARD_STATUS 0x82
110
111 struct i2c_req_ballboard_status {
112         struct i2c_cmd_hdr hdr;
113 };
114
115 #define I2C_ANS_BALLBOARD_STATUS 0x83
116
117 struct i2c_ans_ballboard_status {
118         struct i2c_cmd_hdr hdr;
119
120
121 #define I2C_BALLBOARD_STATUS_F_READY         0x00
122 #define I2C_BALLBOARD_STATUS_F_BUSY          0x01
123 #define I2C_BALLBOARD_STATUS_F_EXCPT         0x02
124         uint8_t status;
125
126         uint8_t ball_count;
127 };
128
129 #endif /* _I2C_PROTOCOL_H_ */