Rev 885 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 885 | Rev 886 | ||
---|---|---|---|
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 | 7 | ||
7 | #define USE_SPI_COMMUNICATION |
8 | #define USE_SPI_COMMUNICATION |
8 | 9 | ||
9 | #define SPI_PROTOCOL_COMP 1 |
10 | #define SPI_PROTOCOL_COMP 1 |
10 | 11 | ||
11 | //----------------------------------------- |
12 | //----------------------------------------- |
12 | #define DDR_SPI DDRB |
13 | #define DDR_SPI DDRB |
13 | #define DD_SS PB4 |
14 | #define DD_SS PB4 |
14 | #define DD_SCK PB7 |
15 | #define DD_SCK PB7 |
15 | #define DD_MOSI PB5 |
16 | #define DD_MOSI PB5 |
16 | #define DD_MISO PB6 |
17 | #define DD_MISO PB6 |
17 | 18 | ||
18 | // for compatibility reasons gcc3.x <-> gcc4.x |
19 | // for compatibility reasons gcc3.x <-> gcc4.x |
19 | #ifndef SPCR |
20 | #ifndef SPCR |
20 | #define SPCR SPCR0 |
21 | #define SPCR SPCR0 |
21 | #endif |
22 | #endif |
22 | #ifndef SPE |
23 | #ifndef SPE |
23 | #define SPE SPE0 |
24 | #define SPE SPE0 |
24 | #endif |
25 | #endif |
25 | #ifndef MSTR |
26 | #ifndef MSTR |
26 | #define MSTR MSTR0 |
27 | #define MSTR MSTR0 |
27 | #endif |
28 | #endif |
28 | #ifndef SPR1 |
29 | #ifndef SPR1 |
29 | #define SPR1 SPR01 |
30 | #define SPR1 SPR01 |
30 | #endif |
31 | #endif |
31 | #ifndef SPR0 |
32 | #ifndef SPR0 |
32 | #define SPR0 SPR00 |
33 | #define SPR0 SPR00 |
33 | #endif |
34 | #endif |
34 | #ifndef SPIE |
35 | #ifndef SPIE |
35 | #define SPIE SPIE0 |
36 | #define SPIE SPIE0 |
36 | #endif |
37 | #endif |
37 | #ifndef SPDR |
38 | #ifndef SPDR |
38 | #define SPDR SPDR0 |
39 | #define SPDR SPDR0 |
39 | #endif |
40 | #endif |
40 | #ifndef SPIF |
41 | #ifndef SPIF |
41 | #define SPIF SPIF0 |
42 | #define SPIF SPIF0 |
42 | #endif |
43 | #endif |
43 | #ifndef SPSR |
44 | #ifndef SPSR |
44 | #define SPSR SPSR0 |
45 | #define SPSR SPSR0 |
45 | #endif |
46 | #endif |
46 | // ------------------------- |
47 | // ------------------------- |
47 | 48 | ||
48 | #define SLAVE_SELECT_DDR_PORT DDRC |
49 | #define SLAVE_SELECT_DDR_PORT DDRC |
49 | #define SLAVE_SELECT_PORT PORTC |
50 | #define SLAVE_SELECT_PORT PORTC |
50 | #define SPI_SLAVE_SELECT PC5 |
51 | #define SPI_SLAVE_SELECT PC5 |
51 | 52 | ||
52 | 53 | ||
53 | #define SPI_CMD_USER 10 |
54 | #define SPI_CMD_USER 10 |
54 | #define SPI_CMD_STICK 11 |
55 | #define SPI_CMD_STICK 11 |
55 | #define SPI_CMD_CAL_COMPASS 12 |
56 | #define SPI_CMD_CAL_COMPASS 12 |
- | 57 | ||
56 | struct str_ToNaviCtrl |
58 | typedef struct |
57 | { |
59 | { |
- | 60 | uint8_t Sync1; |
|
58 | unsigned char Sync1, Sync2; |
61 | uint8_t Sync2; |
59 | unsigned char Command; |
62 | uint8_t Command; |
60 | signed int IntegralNick; |
63 | int16_t IntegralPitch; |
61 | signed int IntegralRoll; |
64 | int16_t IntegralRoll; |
62 | signed int AccNick; |
65 | int16_t AccPitch; |
63 | signed int AccRoll; |
66 | int16_t AccRoll; |
64 | signed int GyroCompass; |
67 | int16_t GyroHeading; |
65 | signed int GyroNick; |
68 | int16_t GyroPitch; |
66 | signed int GyroRoll; |
69 | int16_t GyroRoll; |
67 | signed int GyroGier; |
70 | int16_t GyroYaw; |
68 | union |
71 | union |
- | 72 | { |
|
- | 73 | int8_t sByte[12]; |
|
69 | { char Byte[12]; |
74 | uint8_t Byte[12]; |
70 | int Int[6]; |
75 | int16_t Int[6]; |
71 | long Long[3]; |
76 | int32_t Long[3]; |
72 | float Float[3]; |
77 | float Float[3]; |
73 | } Param; |
78 | } Param; |
74 | unsigned char Chksum; |
79 | uint8_t Chksum; |
- | 80 | } ToNaviCtrl_t; |
|
- | 81 | ||
75 | }; |
82 | |
76 | 83 | ||
77 | #define SPI_CMD_OSD_DATA 100 |
84 | #define SPI_CMD_OSD_DATA 100 |
78 | #define SPI_CMD_GPS_POS 101 |
85 | #define SPI_CMD_GPS_POS 101 |
79 | #define SPI_CMD_GPS_TARGET 102 |
86 | #define SPI_CMD_GPS_TARGET 102 |
80 | struct str_FromNaviCtrl |
- | |
81 | { |
- | |
82 | unsigned char Command; |
- | |
83 | signed int GPS_Nick; |
- | |
84 | signed int GPS_Roll; |
- | |
85 | signed int GPS_Gier; |
- | |
86 | signed int CompassValue; |
- | |
87 | signed int Status; |
- | |
88 | unsigned char BeepTime; |
- | |
89 | union |
- | |
90 | { char Byte[12]; |
- | |
91 | int Int[6]; |
- | |
92 | long Long[3]; |
- | |
93 | float Float[3]; |
- | |
94 | } Param; |
- | |
95 | unsigned char Chksum; |
- | |
96 | }; |
- | |
- | 87 | ||
- | 88 | typedef struct |
|
- | 89 | { |
|
- | 90 | uint8_t Command; |
|
- | 91 | int16_t GPS_Pitch; |
|
- | 92 | int16_t GPS_Roll; |
|
- | 93 | int16_t GPS_Yaw; |
|
- | 94 | int16_t CompassHeading; |
|
- | 95 | int16_t Status; |
|
- | 96 | uint8_t BeepTime; |
|
- | 97 | union |
|
- | 98 | { |
|
- | 99 | int8_t Byte[12]; |
|
- | 100 | int16_t Int[6]; |
|
- | 101 | int32_t Long[3]; |
|
- | 102 | float Float[3]; |
|
- | 103 | } Param; |
|
- | 104 | uint8_t Chksum; |
|
97 | 105 | } FromNaviCtrl_t; |
|
98 | 106 | ||
99 | #ifdef USE_SPI_COMMUNICATION |
107 | #ifdef USE_SPI_COMMUNICATION |
100 | 108 | ||
101 | extern struct str_ToNaviCtrl ToNaviCtrl; |
109 | extern ToNaviCtrl_t ToNaviCtrl; |
102 | extern struct str_FromNaviCtrl FromNaviCtrl; |
- | |
103 | - | ||
104 | //#define SPI_CMD_VALUE 0x03 |
110 | extern FromNaviCtrl_t FromNaviCtrl; |
105 | 111 | ||
106 | extern void SPI_MasterInit(void); |
112 | extern void SPI_MasterInit(void); |
107 | extern void SPI_StartTransmitPacket(void); |
113 | extern void SPI_StartTransmitPacket(void); |
108 | extern void UpdateSPI_Buffer(void); |
- | |
109 | extern void SPI_TransmitByte(void); |
114 | extern void SPI_TransmitByte(void); |
110 | #else |
115 | #else |
111 | 116 | ||
112 | 117 | ||
113 | // -------------------------------- Dummy ----------------------------------------- |
118 | // -------------------------------- Dummy ----------------------------------------- |
114 | #define SPI_MasterInit() ; |
119 | #define SPI_MasterInit() ; |
115 | #define SPI_StartTransmitPacket() ; |
120 | #define SPI_StartTransmitPacket() ; |
116 | #define UpdateSPI_Buffer() ; |
121 | #define UpdateSPI_Buffer() ; |
117 | #define SPI_TransmitByte() ; |
122 | #define SPI_TransmitByte() ; |
118 | #endif |
123 | #endif |
119 | 124 | ||
120 | 125 | ||
121 | #endif |
126 | #endif //_SPI_H |
122 | 127 |