Rev 146 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 146 | Rev 189 | ||
---|---|---|---|
1 | #ifndef __I2C_H |
1 | #ifndef __I2C_H |
2 | #define __I2C_H |
2 | #define __I2C_H |
3 | - | ||
4 | - | ||
5 | #define I2C_SLAVE_ADDRESS 0x50 |
- | |
6 | 3 | ||
7 | #define I2C_CMD_VERSION 0x01 |
4 | #define I2C_CMD_VERSION 0x01 |
8 | #define I2C_CMD_READ_MAG 0x02 |
5 | #define I2C_CMD_READ_MAG 0x02 |
9 | #define I2C_CMD_READ_HEADING 0x03 |
6 | #define I2C_CMD_READ_HEADING 0x03 |
10 | #define I2C_CMD_WRITE_CAL 0x04 |
7 | #define I2C_CMD_WRITE_CAL 0x04 |
11 | 8 | ||
12 | 9 | ||
13 | typedef struct |
10 | typedef struct |
14 | { |
11 | { |
15 | u8 Major; |
12 | u8 Major; |
16 | u8 Minor; |
13 | u8 Minor; |
17 | u8 Patch; |
14 | u8 Patch; |
18 | u8 Compatible; |
15 | u8 Compatible; |
19 | } __attribute__((packed)) I2C_Version_t; |
16 | } __attribute__((packed)) I2C_Version_t; |
20 | 17 | ||
21 | typedef struct |
18 | typedef struct |
22 | { |
19 | { |
23 | s16 MagX; |
20 | s16 MagX; |
24 | s16 MagY; |
21 | s16 MagY; |
25 | s16 MagZ; |
22 | s16 MagZ; |
26 | } __attribute__((packed)) I2C_Mag_t; |
23 | } __attribute__((packed)) I2C_Mag_t; |
27 | 24 | ||
28 | 25 | ||
29 | typedef struct |
26 | typedef struct |
30 | { |
27 | { |
31 | s16 Nick; |
28 | s16 Nick; |
32 | s16 Roll; |
29 | s16 Roll; |
33 | } __attribute__((packed)) I2C_WriteAttitude_t; |
30 | } __attribute__((packed)) I2C_WriteAttitude_t; |
34 | 31 | ||
35 | 32 | ||
36 | typedef struct |
33 | typedef struct |
37 | { |
34 | { |
38 | u8 CalByte; |
35 | u8 CalByte; |
39 | u8 Dummy1; |
36 | u8 Dummy1; |
40 | u8 Dummy2; |
37 | u8 Dummy2; |
41 | } __attribute__((packed)) I2C_Cal_t; |
38 | } __attribute__((packed)) I2C_Cal_t; |
42 | 39 | ||
43 | typedef struct |
40 | typedef struct |
44 | { |
41 | { |
45 | s16 Heading; |
42 | s16 Heading; |
46 | } __attribute__((packed)) I2C_Heading_t; |
43 | } __attribute__((packed)) I2C_Heading_t; |
47 | - | ||
48 | typedef enum |
- | |
49 | { |
- | |
50 | I2C_UNDEF, |
- | |
51 | I2C_IDLE, |
- | |
52 | I2C_TX_PROGRESS, |
- | |
53 | I2C_RX_PENDING, |
- | |
54 | I2C_RX_PROGRESS, |
- | |
55 | I2C_OFF |
- | |
56 | } I2C_State_t; |
- | |
57 | - | ||
58 | extern volatile I2C_State_t I2C_State; |
- | |
59 | extern volatile u8 I2C_Direction; |
44 | |
60 | extern volatile u32 I2C1_Timeout; |
45 | extern volatile u32 I2C1_Timeout; |
61 | 46 | ||
62 | extern volatile I2C_Heading_t I2C_Heading; |
47 | extern volatile I2C_Heading_t I2C_Heading; |
63 | extern volatile I2C_WriteAttitude_t I2C_WriteAttitude; |
- | |
64 | extern volatile I2C_Mag_t I2C_Mag; |
48 | extern volatile I2C_Mag_t I2C_Mag; |
65 | extern volatile I2C_Version_t MK3MAG_Version; |
49 | extern volatile I2C_Version_t MK3MAG_Version; |
66 | extern volatile I2C_Cal_t I2C_WriteCal; |
- | |
67 | extern volatile I2C_Cal_t I2C_ReadCal; |
- | |
68 | 50 | ||
69 | void I2C1_Init(void); |
51 | void I2C1_Init(void); |
70 | void I2C1_Deinit(void); |
52 | void I2C1_Deinit(void); |
71 | void I2C1_SendCommand(u8 command); |
53 | void I2C1_SendCommand(u8 command); |
72 | void I2C1_GetMK3MagVersion(void); |
54 | void I2C1_GetMK3MagVersion(void); |
73 | void I2C1_UpdateCompass(void); |
55 | void I2C1_UpdateCompass(void); |
74 | 56 | ||
75 | #endif // I2C_H |
57 | #endif // I2C_H |
76 | 58 | ||
77 | 59 |