Subversion Repositories NaviCtrl

Rev

Rev 146 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
41 ingob 1
#ifndef __I2C_H
2
#define __I2C_H
1 ingob 3
 
4
 
41 ingob 5
#define I2C_SLAVE_ADDRESS               0x50
1 ingob 6
 
41 ingob 7
#define I2C_CMD_VERSION                 0x01
8
#define I2C_CMD_READ_MAG        0x02
9
#define I2C_CMD_READ_HEADING    0x03
10
#define I2C_CMD_WRITE_CAL       0x04
1 ingob 11
 
41 ingob 12
 
13
typedef struct
1 ingob 14
{
41 ingob 15
  u8 Major;
16
  u8 Minor;
17
  u8 Patch;
18
  u8 Compatible;
19
} __attribute__((packed)) I2C_Version_t;
1 ingob 20
 
41 ingob 21
typedef struct
1 ingob 22
{
41 ingob 23
  s16 MagX;
24
  s16 MagY;
25
  s16 MagZ;
26
} __attribute__((packed)) I2C_Mag_t;
1 ingob 27
 
41 ingob 28
 
29
typedef struct
1 ingob 30
{
31
  s16 Nick;
32
  s16 Roll;
41 ingob 33
} __attribute__((packed)) I2C_WriteAttitude_t;
1 ingob 34
 
41 ingob 35
 
36
typedef struct
1 ingob 37
{
38
  u8 CalByte;
39
  u8 Dummy1;
40
  u8 Dummy2;
41 ingob 41
} __attribute__((packed)) I2C_Cal_t;
1 ingob 42
 
41 ingob 43
typedef struct
1 ingob 44
{
41 ingob 45
  s16 Heading;
46
} __attribute__((packed)) I2C_Heading_t;
1 ingob 47
 
41 ingob 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;
1 ingob 57
 
41 ingob 58
extern volatile I2C_State_t I2C_State;
59
extern volatile u8 I2C_Direction;
60
extern volatile u32 I2C1_Timeout;
1 ingob 61
 
41 ingob 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;
1 ingob 68
 
41 ingob 69
void I2C1_Init(void);
70
void I2C1_Deinit(void);
71
void I2C1_SendCommand(u8 command);
72
void I2C1_GetMK3MagVersion(void);
146 killagreg 73
void I2C1_UpdateCompass(void);
1 ingob 74
 
41 ingob 75
#endif // I2C_H
1 ingob 76