fix gps message when position is not correct
[protos/imu.git] / i2cm_sw.h
1 #ifndef I2CM_SW_H
2 #define I2CM_SW_H
3
4 /*
5 #define BIT(x) (1 << (x))
6 #define SETBITS(x,y) ((x) |= (y))
7 #define CLEARBITS(x,y) ((x) &= (~(y)))
8 #define SETBIT(x,y) SETBITS((x), (BIT((y))))
9 #define CLEARBIT(x,y) CLEARBITS((x), (BIT((y))))
10 #define BITSET(x,y) ((x) & (BIT(y)))
11 #define BITCLEAR(x,y) !BITSET((x), (y))
12 #define BITSSET(x,y) (((x) & (y)) == (y))
13 #define BITSCLEAR(x,y) (((x) & (y)) == 0)
14 #define BITVAL(x,y) (((x)>>(y)) & 1)
15 */
16
17 #define I2C_LOW(port, bit) sbi(DDR(port),bit)
18 #define I2C_HIGH(port, bit) cbi(DDR(port),bit)
19
20
21 typedef uint8_t i2cm_state;
22
23 #define NOT_INIT   0
24 #define I2CM_READY 1
25 #define I2CM_BUSY  2
26 #define I2CM_SENT  3
27 #define I2CM_SENT_NO_ACK 4
28 #define I2CM_SENT_START  5
29 #define I2CM_SENT_START_NO_ACK 6
30 #define I2CM_SENT_STOP 7
31 #define I2CM_RECEIVED_BYTE 8
32
33 #define I2CM_DELAY()  _delay_loop_2(4)
34 #define I2CM_BIT_DELAY() _delay_loop_2(4)
35
36 void i2cm_init(void);
37 void i2cm_manage(void);
38 uint8_t i2cm_get_state(void);
39 uint8_t i2cm_get_received_byte(void);
40 void i2cm_register_event(void (*func)(i2cm_state state));
41 uint8_t i2cm_send_start(uint8_t sla_w);
42 uint8_t i2cm_send_stop(void);
43 uint8_t i2cm_receive_byte(uint8_t last);
44
45 uint8_t i2cm_send(uint8_t addr, uint8_t* data, uint8_t len);
46 uint8_t i2cm_recv(uint8_t addr, uint8_t len);
47 uint8_t i2cm_get_recv_buffer(uint8_t* buf, uint8_t len);
48
49
50 #define I2C_ERR_SEND_START 1
51 #define I2C_ERR_SEND_BYTE 2
52 #define I2C_ERR_RECV_BYTE 3
53
54
55 #endif //I2CM_SW_H