Rev 1 | Rev 146 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1 | Rev 41 | ||
---|---|---|---|
1 | #ifndef __I2C |
1 | #ifndef __I2C_H |
2 | #define __I2C |
2 | #define __I2C_H |
3 | 3 | ||
- | 4 | ||
- | 5 | #define I2C_SLAVE_ADDRESS 0x50 |
|
- | 6 | ||
- | 7 | #define I2C_CMD_VERSION 0x01 |
|
- | 8 | #define I2C_CMD_READ_MAG 0x02 |
|
4 | - | ||
5 | #define I2C_SLAVE_ADDRESS 0x50 |
- | |
6 | - | ||
7 | #define I2C_CMD_VERSION 0x01 |
- | |
8 | struct str_I2C_Version |
- | |
9 | { |
- | |
10 | u8 Hauptversion; |
- | |
11 | u8 Nebenversion; |
- | |
12 | u8 Comp; |
- | |
13 | } __attribute__((packed)); |
9 | #define I2C_CMD_READ_HEADING 0x03 |
14 | 10 | #define I2C_CMD_WRITE_CAL 0x04 |
|
15 | #define I2C_CMD_WRITE_EEPROM 0x0A |
11 | |
16 | #define I2C_CMD_READ_EEPROM 0x0B |
12 | |
- | 13 | typedef struct |
|
- | 14 | { |
|
17 | struct str_I2C_EEPROM |
15 | u8 Major; |
18 | { |
- | |
19 | u8 Adresse; |
16 | u8 Minor; |
20 | u16 Inhalt; |
17 | u8 Patch; |
21 | } __attribute__((packed)); |
18 | u8 Compatible; |
22 | 19 | } __attribute__((packed)) I2C_Version_t; |
|
23 | #define I2C_CMD_READ_MAG 0x02 |
20 | |
24 | struct str_I2C_Mag |
21 | typedef struct |
25 | { |
- | |
- | 22 | { |
|
26 | u16 MagX; |
23 | s16 MagX; |
27 | u16 MagY; |
24 | s16 MagY; |
28 | u16 MagZ; |
25 | s16 MagZ; |
29 | } __attribute__((packed)); |
26 | } __attribute__((packed)) I2C_Mag_t; |
30 | 27 | ||
31 | #define I2C_CMD_READ_HEADING 0x03 |
28 | |
32 | struct str_I2C_WriteNickRoll |
29 | typedef struct |
33 | { |
30 | { |
34 | s16 Nick; |
31 | s16 Nick; |
35 | s16 Roll; |
32 | s16 Roll; |
36 | } __attribute__((packed)); |
33 | } __attribute__((packed)) I2C_WriteAttitude_t; |
- | 34 | ||
37 | - | ||
38 | #define I2C_CMD_WRITE_CAL 0x04 |
35 | |
39 | struct str_I2C_WriteCal |
36 | typedef struct |
40 | { |
37 | { |
41 | u8 CalByte; |
38 | u8 CalByte; |
42 | u8 Dummy1; |
39 | u8 Dummy1; |
43 | u8 Dummy2; |
40 | u8 Dummy2; |
44 | } __attribute__((packed)); |
41 | } __attribute__((packed)) I2C_Cal_t; |
45 | 42 | ||
46 | struct str_I2C_Heading |
43 | typedef struct |
47 | { |
44 | { |
48 | u16 Heading; |
45 | s16 Heading; |
49 | } __attribute__((packed)); |
- | |
50 | - | ||
51 | - | ||
52 | extern u8 Tx_Idx, Rx_Idx, I2C_Direction; |
- | |
53 | - | ||
54 | extern struct str_I2C_Heading I2C_Heading; |
- | |
55 | extern struct str_I2C_WriteNickRoll I2C_WriteNickRoll; |
- | |
56 | extern struct str_I2C_Mag I2C_Mag; |
- | |
57 | extern struct str_I2C_EEPROM I2C_ReadEEPROM, I2C_WriteEEPROM; |
- | |
58 | extern struct str_I2C_Version I2C_Version; |
- | |
59 | extern struct str_I2C_WriteCal I2C_WriteCal; |
- | |
60 | extern void I2C1_Init(void); |
- | |
61 | extern void SendI2C_Command(u8 command); |
- | |
62 | extern u8 CompassUpdateActiv; |
- | |
63 | extern volatile u8 I2C_ReadRequest; |
- | |
- | 46 | } __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; |
|
- | 60 | extern volatile u32 I2C1_Timeout; |
|
- | 61 | ||
- | 62 | extern volatile I2C_Heading_t I2C_Heading; |
|
- | 63 | extern volatile I2C_WriteAttitude_t I2C_WriteAttitude; |
|
- | 64 | extern volatile I2C_Mag_t I2C_Mag; |
|
- | 65 | extern volatile I2C_Version_t MK3MAG_Version; |
|
- | 66 | extern volatile I2C_Cal_t I2C_WriteCal; |
|
- | 67 | extern volatile I2C_Cal_t I2C_ReadCal; |
|
- | 68 | extern volatile u32 CheckI2COkay; |
|
- | 69 | ||
- | 70 | void I2C1_Init(void); |
|
- | 71 | void I2C1_Deinit(void); |
|
64 | extern u8 CompassCalState; |
72 | void I2C1_SendCommand(u8 command); |
65 | 73 | void I2C1_GetMK3MagVersion(void); |
|
66 | 74 | ||
67 | #endif |
75 | #endif // I2C_H |
68 | 76 | ||
69 | 77 |