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