Rev 1077 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1077 | Rev 1078 | ||
---|---|---|---|
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 SPE |
22 | #ifndef SPE |
23 | #define SPE SPE0 |
23 | #define SPE SPE0 |
24 | #endif |
24 | #endif |
25 | #ifndef MSTR |
25 | #ifndef MSTR |
26 | #define MSTR MSTR0 |
26 | #define MSTR MSTR0 |
27 | #endif |
27 | #endif |
28 | #ifndef SPR1 |
28 | #ifndef SPR1 |
29 | #define SPR1 SPR01 |
29 | #define SPR1 SPR01 |
30 | #endif |
30 | #endif |
31 | #ifndef SPR0 |
31 | #ifndef SPR0 |
32 | #define SPR0 SPR00 |
32 | #define SPR0 SPR00 |
33 | #endif |
33 | #endif |
34 | #ifndef SPIE |
34 | #ifndef SPIE |
35 | #define SPIE SPIE0 |
35 | #define SPIE SPIE0 |
36 | #endif |
36 | #endif |
37 | #ifndef SPDR |
37 | #ifndef SPDR |
38 | #define SPDR SPDR0 |
38 | #define SPDR SPDR0 |
39 | #endif |
39 | #endif |
40 | #ifndef SPIF |
40 | #ifndef SPIF |
41 | #define SPIF SPIF0 |
41 | #define SPIF SPIF0 |
42 | #endif |
42 | #endif |
43 | #ifndef SPSR |
43 | #ifndef SPSR |
44 | #define SPSR SPSR0 |
44 | #define SPSR SPSR0 |
45 | #endif |
45 | #endif |
46 | // ------------------------- |
46 | // ------------------------- |
47 | 47 | ||
48 | #define SLAVE_SELECT_DDR_PORT DDRC |
48 | #define SLAVE_SELECT_DDR_PORT DDRC |
49 | #define SLAVE_SELECT_PORT PORTC |
49 | #define SLAVE_SELECT_PORT PORTC |
50 | #define SPI_SLAVE_SELECT PC5 |
50 | #define SPI_SLAVE_SELECT PC5 |
51 | 51 | ||
52 | 52 | ||
53 | #define SPI_CMD_USER 10 |
53 | #define SPI_CMD_USER 10 |
54 | #define SPI_CMD_STICK 11 |
54 | #define SPI_CMD_STICK 11 |
55 | #define SPI_CMD_CAL_COMPASS 12 |
55 | #define SPI_CMD_MISC 12 |
56 | #define SPI_CMD_PARAMETER1 13 |
56 | #define SPI_CMD_PARAMETER1 13 |
- | 57 | #define SPI_CMD_VERSION 14 |
|
57 | 58 | ||
58 | typedef struct |
59 | typedef struct |
59 | { |
60 | { |
60 | uint8_t Sync1; |
61 | uint8_t Sync1; |
61 | uint8_t Sync2; |
62 | uint8_t Sync2; |
62 | uint8_t Command; |
63 | uint8_t Command; |
63 | int16_t IntegralNick; |
64 | int16_t IntegralNick; |
64 | int16_t IntegralRoll; |
65 | int16_t IntegralRoll; |
65 | int16_t AccNick; |
66 | int16_t AccNick; |
66 | int16_t AccRoll; |
67 | int16_t AccRoll; |
67 | int16_t GyroHeading; |
68 | int16_t GyroHeading; |
68 | int16_t GyroNick; |
69 | int16_t GyroNick; |
69 | int16_t GyroRoll; |
70 | int16_t GyroRoll; |
70 | int16_t GyroYaw; |
71 | int16_t GyroYaw; |
71 | union |
72 | union |
72 | { |
73 | { |
73 | int8_t sByte[12]; |
74 | int8_t sByte[12]; |
74 | uint8_t Byte[12]; |
75 | uint8_t Byte[12]; |
75 | int16_t Int[6]; |
76 | int16_t Int[6]; |
76 | int32_t Long[3]; |
77 | int32_t Long[3]; |
77 | float Float[3]; |
78 | float Float[3]; |
78 | } Param; |
79 | } Param; |
79 | uint8_t Chksum; |
80 | uint8_t Chksum; |
80 | } ToNaviCtrl_t; |
81 | } __attribute__((packed)) ToNaviCtrl_t; |
81 | 82 | ||
82 | 83 | ||
83 | 84 | ||
84 | #define SPI_CMD_OSD_DATA 100 |
85 | #define SPI_CMD_OSD_DATA 100 |
85 | #define SPI_CMD_GPS_POS 101 |
86 | #define SPI_CMD_GPS_POS 101 |
- | 87 | #define SPI_CMD_GPS_TARGET 102 |
|
86 | #define SPI_CMD_GPS_TARGET 102 |
88 | #define SPI_KALMAN 103 |
87 | 89 | ||
88 | typedef struct |
90 | typedef struct |
89 | { |
91 | { |
90 | uint8_t Command; |
92 | uint8_t Command; |
91 | int16_t GPS_Nick; |
93 | int16_t GPS_Nick; |
92 | int16_t GPS_Roll; |
94 | int16_t GPS_Roll; |
93 | int16_t GPS_Yaw; |
95 | int16_t GPS_Yaw; |
94 | int16_t CompassHeading; |
96 | int16_t CompassHeading; |
95 | int16_t Status; |
97 | int16_t Status; |
96 | uint16_t BeepTime; |
98 | uint16_t BeepTime; |
97 | union |
99 | union |
98 | { |
100 | { |
99 | int8_t Byte[12]; |
101 | int8_t Byte[12]; |
100 | int16_t Int[6]; |
102 | int16_t Int[6]; |
101 | int32_t Long[3]; |
103 | int32_t Long[3]; |
102 | float Float[3]; |
104 | float Float[3]; |
103 | } Param; |
105 | } Param; |
104 | uint8_t Chksum; |
106 | uint8_t Chksum; |
- | 107 | } __attribute__((packed)) FromNaviCtrl_t; |
|
- | 108 | ||
- | 109 | typedef struct |
|
- | 110 | { |
|
- | 111 | int16_t OsdBar; |
|
105 | } FromNaviCtrl_t; |
112 | int16_t Distance; |
- | 113 | int8_t Kalman_K; |
|
- | 114 | int8_t Kalman_MaxDrift; |
|
- | 115 | int8_t Kalman_MaxFusion; |
|
- | 116 | } __attribute__((packed)) FromNaviCtrl_Value_t; |
|
- | 117 | ||
- | 118 | ||
- | 119 | typedef struct |
|
- | 120 | { |
|
- | 121 | uint8_t Major; |
|
- | 122 | uint8_t Minor; |
|
- | 123 | uint8_t Patch; |
|
- | 124 | uint8_t Compatible; |
|
- | 125 | } __attribute__((packed)) SPI_VersionInfo_t; |
|
106 | 126 | ||
107 | 127 | ||
- | 128 | extern ToNaviCtrl_t ToNaviCtrl; |
|
108 | extern ToNaviCtrl_t ToNaviCtrl; |
129 | extern FromNaviCtrl_t FromNaviCtrl; |
109 | extern FromNaviCtrl_t FromNaviCtrl; |
130 | extern FromNaviCtrl_Value_t FromNaviCtrl_Value; |
110 | 131 | ||
111 | void SPI_MasterInit(void); |
132 | void SPI_MasterInit(void); |
112 | void SPI_StartTransmitPacket(void); |
133 | void SPI_StartTransmitPacket(void); |
113 | void SPI_TransmitByte(void); |
134 | void SPI_TransmitByte(void); |
114 | 135 | ||
115 | 136 | ||
116 | 137 | ||
117 | #endif //_SPI_H |
138 | #endif //_SPI_H |
118 | 139 |