Subversion Repositories FlightCtrl

Rev

Rev 1180 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1180 Rev 1187
1
// ######################## SPI - FlightCtrl ###################
1
// ######################## SPI - FlightCtrl ###################
2
#ifndef _SPI_H
2
#ifndef _SPI_H
3
#define _SPI_H
3
#define _SPI_H
4
 
4
 
5
//#include <util/delay.h>
5
//#include <util/delay.h>
6
#include <inttypes.h>
6
#include <inttypes.h>
7
 
7
 
8
 
8
 
9
#define SPI_PROTOCOL_COMP   1
9
#define SPI_PROTOCOL_COMP   1
10
 
10
 
11
//-----------------------------------------
11
//-----------------------------------------
12
#define DDR_SPI DDRB
12
#define DDR_SPI DDRB
13
#define DD_SS   PB4
13
#define DD_SS   PB4
14
#define DD_SCK  PB7
14
#define DD_SCK  PB7
15
#define DD_MOSI PB5
15
#define DD_MOSI PB5
16
#define DD_MISO PB6
16
#define DD_MISO PB6
17
 
17
 
18
// for compatibility reasons gcc3.x <-> gcc4.x
18
// for compatibility reasons gcc3.x <-> gcc4.x
19
#ifndef SPCR
19
#ifndef SPCR
20
#define SPCR   SPCR0
20
#define SPCR   SPCR0
21
#endif
21
#endif
-
 
22
#ifndef SPIE
-
 
23
#define SPIE   SPIE0
-
 
24
#endif
22
#ifndef SPE
25
#ifndef SPE
23
#define SPE   SPE0
26
#define SPE    SPE0
-
 
27
#endif
-
 
28
#ifdef  DORD
-
 
29
#define DORD   DORD0
24
#endif
30
#endif
25
#ifndef MSTR
31
#ifndef MSTR
26
#define MSTR   MSTR0
32
#define MSTR   MSTR0
27
#endif
33
#endif
-
 
34
#ifndef CPOL
-
 
35
#define CPOL   CPOL0
-
 
36
#endif
-
 
37
#ifndef CPHA
-
 
38
#define CPHA   CPHA0
-
 
39
#endif
28
#ifndef SPR1
40
#ifndef SPR1
29
#define SPR1   SPR01
41
#define SPR1   SPR01
30
#endif
42
#endif
31
#ifndef SPR0
43
#ifndef SPR0
32
#define SPR0   SPR00
44
#define SPR0   SPR00
33
#endif
45
#endif
34
#ifndef SPIE
-
 
35
#define SPIE   SPIE0
-
 
36
#endif
46
 
37
#ifndef SPDR
47
#ifndef SPDR
38
#define SPDR   SPDR0
48
#define SPDR   SPDR0
39
#endif
49
#endif
-
 
50
 
-
 
51
#ifndef SPSR
-
 
52
#define SPSR   SPSR0
-
 
53
#endif
40
#ifndef SPIF
54
#ifndef SPIF
41
#define SPIF   SPIF0
55
#define SPIF   SPIF0
42
#endif
56
#endif
-
 
57
#ifndef WCOL
-
 
58
#define WCOL   WCOL0
-
 
59
#endif
43
#ifndef SPSR
60
#ifndef SPI2X
44
#define SPSR   SPSR0
61
#define SPI2X  SPI2X0
45
#endif
62
#endif
46
// -------------------------
63
// -------------------------
47
 
64
 
48
#define SLAVE_SELECT_DDR_PORT   DDRC
65
#define SLAVE_SELECT_DDR_PORT   DDRC
49
#define SLAVE_SELECT_PORT       PORTC
66
#define SLAVE_SELECT_PORT       PORTC
50
#define SPI_SLAVE_SELECT        PC5
67
#define SPI_SLAVE_SELECT        PC5
51
 
68
 
52
 
69
 
53
#define SPI_CMD_USER        10
70
#define SPI_CMD_USER        10
54
#define SPI_CMD_STICK       11
71
#define SPI_CMD_STICK       11
55
#define SPI_CMD_MISC            12
72
#define SPI_CMD_MISC            12
56
#define SPI_CMD_PARAMETER1      13
73
#define SPI_CMD_PARAMETER1      13
57
#define SPI_CMD_VERSION         14
74
#define SPI_CMD_VERSION         14
58
 
75
 
59
typedef struct
76
typedef struct
60
{
77
{
61
        uint8_t Sync1;
78
        uint8_t Sync1;
62
        uint8_t Sync2;
79
        uint8_t Sync2;
63
        uint8_t Command;
80
        uint8_t Command;
64
        int16_t IntegralNick;
81
        int16_t IntegralNick;
65
        int16_t IntegralRoll;
82
        int16_t IntegralRoll;
66
        int16_t AccNick;
83
        int16_t AccNick;
67
        int16_t AccRoll;
84
        int16_t AccRoll;
68
        int16_t GyroHeading;
85
        int16_t GyroHeading;
69
        int16_t GyroNick;
86
        int16_t GyroNick;
70
        int16_t GyroRoll;
87
        int16_t GyroRoll;
71
        int16_t GyroYaw;
88
        int16_t GyroYaw;
72
        union
89
        union
73
        {
90
        {
74
                int8_t  sByte[12];
91
                int8_t  sByte[12];
75
                uint8_t Byte[12];
92
                uint8_t Byte[12];
76
                int16_t Int[6];
93
                int16_t Int[6];
77
                int32_t Long[3];
94
                int32_t Long[3];
78
                float   Float[3];
95
                float   Float[3];
79
        } Param;
96
        } Param;
80
        uint8_t Chksum;
97
        uint8_t Chksum;
81
} __attribute__((packed)) ToNaviCtrl_t;
98
} __attribute__((packed)) ToNaviCtrl_t;
82
 
99
 
83
 
100
 
84
 
101
 
85
#define SPI_CMD_OSD_DATA        100
102
#define SPI_CMD_OSD_DATA        100
86
#define SPI_CMD_GPS_POS         101
103
#define SPI_CMD_GPS_POS         101
87
#define SPI_CMD_GPS_TARGET      102
104
#define SPI_CMD_GPS_TARGET      102
88
#define SPI_KALMAN                      103
105
#define SPI_KALMAN                      103
89
 
106
 
90
typedef struct
107
typedef struct
91
{
108
{
92
        uint8_t Command;
109
        uint8_t Command;
93
        int16_t GPSStickNick;
110
        int16_t GPSStickNick;
94
        int16_t GPSStickRoll;
111
        int16_t GPSStickRoll;
95
        int16_t GPS_Yaw;
112
        int16_t GPS_Yaw;
96
        int16_t CompassHeading;
113
        int16_t CompassHeading;
97
        int16_t Status;
114
        int16_t Status;
98
        uint16_t BeepTime;
115
        uint16_t BeepTime;
99
        union
116
        union
100
        {
117
        {
101
                int8_t  Byte[12];
118
                int8_t  Byte[12];
102
                int16_t Int[6];
119
                int16_t Int[6];
103
                int32_t Long[3];
120
                int32_t Long[3];
104
                float   Float[3];
121
                float   Float[3];
105
        } Param;
122
        } Param;
106
        uint8_t Chksum;
123
        uint8_t Chksum;
107
} __attribute__((packed)) FromNaviCtrl_t;
124
} __attribute__((packed)) FromNaviCtrl_t;
108
 
125
 
109
 
126
 
110
typedef struct
127
typedef struct
111
{
128
{
112
        uint8_t Major;
129
        uint8_t Major;
113
        uint8_t Minor;
130
        uint8_t Minor;
114
        uint8_t Patch;
131
        uint8_t Patch;
115
        uint8_t Compatible;
132
        uint8_t Compatible;
116
} __attribute__((packed)) SPI_VersionInfo_t;
133
} __attribute__((packed)) SPI_VersionInfo_t;
117
 
134
 
118
 
135
 
119
extern ToNaviCtrl_t                     ToNaviCtrl;
136
extern ToNaviCtrl_t                     ToNaviCtrl;
120
extern FromNaviCtrl_t                   FromNaviCtrl;
137
extern FromNaviCtrl_t                   FromNaviCtrl;
121
 
138
 
122
void SPI_MasterInit(void);
139
void SPI_MasterInit(void);
123
void SPI_StartTransmitPacket(void);
140
void SPI_StartTransmitPacket(void);
124
void SPI_TransmitByte(void);
141
void SPI_TransmitByte(void);
125
 
142
 
126
 
143
 
127
 
144
 
128
#endif //_SPI_H
145
#endif //_SPI_H
129
 
146