2 * Copyright (c) 2014, Olivier MATZ <zer0@droids-corp.org>
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
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.
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.
31 #include <aversive/error.h>
35 #include "../common/i2c_commands.h"
36 #include "gps_venus.h"
39 void i2c_protocol_init(void)
44 void i2c_led_control(uint8_t l, uint8_t state)
48 state? LED1_ON():LED1_OFF();
51 state? LED2_ON():LED2_OFF();
59 static void i2c_test(uint16_t val)
61 static uint16_t prev=0;
63 if ( (val-prev) != 1 ) {
64 WARNING(E_USER_I2C_PROTO, "Duplicated msg %d", val);
71 static void i2c_send_status(void)
73 struct i2c_ans_imuboard_status ans;
74 struct gps_pos gps_pos;
78 ans.hdr.cmd = I2C_ANS_IMUBOARD_STATUS;
82 gps_get_pos(&gps_pos);
83 IRQ_UNLOCK(irq_flags);
86 if (gps_pos_valid(&gps_pos)) {
87 ans.flags |= I2C_IMUBOARD_STATUS_GPS_OK;
88 ans.latitude = gps_pos.latitude;
89 ans.longitude = gps_pos.longitude;
90 ans.altitude = gps_pos.altitude;
93 i2c_send(I2C_ADD_MASTER, (uint8_t *) &ans,
94 sizeof(ans), I2C_CTRL_GENERIC);
97 void i2c_recvevent(uint8_t * buf, int8_t size)
102 static uint8_t a = 0;
115 /* Commands (no answer needed) */
116 case I2C_CMD_GENERIC_LED_CONTROL:
118 struct i2c_cmd_led_control *cmd = void_cmd;
119 if (size != sizeof (*cmd))
121 i2c_led_control(cmd->led_num, cmd->state);
126 /* Add other commands here ...*/
128 case I2C_REQ_IMUBOARD_STATUS:
130 //struct i2c_req_imuboard_status *cmd = void_cmd;
131 if (size != sizeof (struct i2c_req_imuboard_status))
143 /* log error on a led ? */
147 void i2c_recvbyteevent(__attribute__((unused)) uint8_t hwstatus,
148 __attribute__((unused)) uint8_t i,
149 __attribute__((unused)) int8_t c)
153 void i2c_sendevent(__attribute__((unused)) int8_t size)