remove unused vector.[ch]
[protos/imu.git] / i2c_protocol.c
1 /*
2  * Copyright (c) 2014, Olivier MATZ <zer0@droids-corp.org>
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  *     * Redistributions of source code must retain the above copyright
8  *       notice, this list of conditions and the following disclaimer.
9  *     * Redistributions in binary form must reproduce the above copyright
10  *       notice, this list of conditions and the following disclaimer in the
11  *       documentation and/or other materials provided with the distribution.
12  *     * Neither the name of the University of California, Berkeley nor the
13  *       names of its contributors may be used to endorse or promote products
14  *       derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 #include <string.h>
29
30 #include <aversive.h>
31 #include <aversive/error.h>
32
33 #include <i2c.h>
34
35 #include "../fpv-common/i2c_commands.h"
36 #include "main.h"
37
38 void i2c_protocol_init(void)
39 {
40 }
41
42 /*** LED CONTROL ***/
43 void i2c_led_control(uint8_t l, uint8_t state)
44 {
45         switch(l) {
46         case 1:
47                 state? LED1_ON():LED1_OFF();
48                 break;
49         case 2:
50                 state? LED2_ON():LED2_OFF();
51                 break;
52         default:
53                 break;
54         }
55 }
56
57 #ifdef notyet
58 static void i2c_test(uint16_t val)
59 {
60         static uint16_t prev=0;
61
62         if ( (val-prev) != 1 ) {
63                 WARNING(E_USER_I2C_PROTO, "Dupplicated msg %d", val);
64         }
65         prev = val;
66         ext.nb_test_cmd ++;
67 }
68 #endif
69
70 static void i2c_send_status(void)
71 {
72         struct i2c_ans_imuboard_status ans;
73         static uint8_t x;
74
75         i2c_flush();
76         ans.hdr.cmd =  I2C_ANS_IMUBOARD_STATUS;
77
78         /* status */
79         ans.test = x++; /* XXX */
80 #if 0
81         ans.mode = state_get_mode();
82         ans.status = state_get_status();
83
84         ans.left_cobroller_speed = imuboard.left_cobroller_speed;
85         ans.right_cobroller_speed = imuboard.right_cobroller_speed;
86
87         ans.cob_count = state_get_cob_count();
88 #endif
89
90         i2c_send(I2C_ADD_MASTER, (uint8_t *) &ans,
91                  sizeof(ans), I2C_CTRL_GENERIC);
92 }
93
94 void i2c_recvevent(uint8_t * buf, int8_t size)
95 {
96         void *void_cmd = buf;
97
98 #if 0 /* XXX */
99         static uint8_t a = 0;
100
101         a++;
102         if (a & 0x10)
103                 LED2_TOGGLE();
104
105         if (size <= 0) {
106                 goto error;
107         }
108 #endif
109
110         switch (buf[0]) {
111
112         /* Commands (no answer needed) */
113         case I2C_CMD_GENERIC_LED_CONTROL:
114                 {
115                         struct i2c_cmd_led_control *cmd = void_cmd;
116                         if (size != sizeof (*cmd))
117                                 goto error;
118                         i2c_led_control(cmd->led_num, cmd->state);
119                         break;
120                 }
121
122
123         /* Add other commands here ...*/
124
125         case I2C_REQ_IMUBOARD_STATUS:
126                 {
127                         //struct i2c_req_imuboard_status *cmd = void_cmd;
128                         if (size != sizeof (struct i2c_req_imuboard_status))
129                                 goto error;
130
131                         i2c_send_status();
132                         break;
133                 }
134
135         default:
136                 goto error;
137         }
138
139  error:
140         /* log error on a led ? */
141         return;
142 }
143
144 void i2c_recvbyteevent(__attribute__((unused)) uint8_t hwstatus,
145                        __attribute__((unused)) uint8_t i, 
146                        __attribute__((unused)) int8_t c)
147 {
148 }
149
150 void i2c_sendevent(__attribute__((unused)) int8_t size)
151 {
152 }
153
154