Rev 885 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 885 | Rev 886 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | // ######################## SPI - FlightCtrl ################### |
1 | // ######################## SPI - FlightCtrl ################### |
2 | #ifndef _SPI_H |
2 | #ifndef _SPI_H |
3 | #define _SPI_H |
3 | #define _SPI_H |
Line 4... | Line 4... | ||
4 | 4 | ||
- | 5 | //#include <util/delay.h> |
|
Line 5... | Line 6... | ||
5 | #include <util/delay.h> |
6 | #include <inttypes.h> |
Line 6... | Line 7... | ||
6 | 7 | ||
Line 7... | Line 8... | ||
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 |
Line 13... | Line 14... | ||
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 |
Line 42... | Line 43... | ||
42 | #endif |
43 | #endif |
43 | #ifndef SPSR |
44 | #ifndef SPSR |
44 | #define SPSR SPSR0 |
45 | #define SPSR SPSR0 |
Line 45... | Line 46... | ||
45 | #endif |
46 | #endif |
46 | // ------------------------- |
47 | // ------------------------- |
47 | 48 | ||
- | 49 | #define SLAVE_SELECT_DDR_PORT DDRC |
|
48 | #define SLAVE_SELECT_DDR_PORT DDRC |
50 | #define SLAVE_SELECT_PORT PORTC |
49 | #define SLAVE_SELECT_PORT PORTC |
51 | #define SPI_SLAVE_SELECT PC5 |
- | 52 | ||
50 | #define SPI_SLAVE_SELECT PC5 |
53 | |
51 | 54 | #define SPI_CMD_USER 10 |
|
52 | 55 | #define SPI_CMD_STICK 11 |
|
53 | #define SPI_CMD_USER 10 |
56 | #define SPI_CMD_CAL_COMPASS 12 |
54 | #define SPI_CMD_STICK 11 |
57 | |
55 | #define SPI_CMD_CAL_COMPASS 12 |
58 | typedef struct |
56 | struct str_ToNaviCtrl |
59 | { |
57 | { |
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; |
- | 64 | int16_t IntegralRoll; |
|
- | 65 | int16_t AccPitch; |
|
61 | signed int IntegralRoll; |
66 | int16_t AccRoll; |
62 | signed int AccNick; |
67 | int16_t GyroHeading; |
63 | signed int AccRoll; |
68 | int16_t GyroPitch; |
64 | signed int GyroCompass; |
69 | int16_t GyroRoll; |
65 | signed int GyroNick; |
70 | int16_t GyroYaw; |
66 | signed int GyroRoll; |
71 | union |
- | 72 | { |
|
- | 73 | int8_t sByte[12]; |
|
67 | signed int GyroGier; |
74 | uint8_t Byte[12]; |
Line 68... | Line 75... | ||
68 | union |
75 | int16_t Int[6]; |
69 | { char Byte[12]; |
76 | int32_t Long[3]; |
70 | int Int[6]; |
77 | float Float[3]; |
71 | long Long[3]; |
- | |
72 | float Float[3]; |
- | |
73 | } Param; |
- | |
74 | unsigned char Chksum; |
- | |
75 | }; |
- | |
76 | - | ||
77 | #define SPI_CMD_OSD_DATA 100 |
- | |
78 | #define SPI_CMD_GPS_POS 101 |
- | |
79 | #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; |
- | |
Line -... | Line 78... | ||
- | 78 | } Param; |
|
- | 79 | uint8_t Chksum; |
|
- | 80 | } ToNaviCtrl_t; |
|
- | 81 | ||
- | 82 | ||
- | 83 | ||
- | 84 | #define SPI_CMD_OSD_DATA 100 |
|
- | 85 | #define SPI_CMD_GPS_POS 101 |
|
- | 86 | #define SPI_CMD_GPS_TARGET 102 |
|
- | 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; |
|
Line 88... | Line 96... | ||
88 | unsigned char BeepTime; |
96 | uint8_t BeepTime; |
Line 89... | Line 97... | ||
89 | union |
97 | union |
90 | { char Byte[12]; |
98 | { |
91 | int Int[6]; |
- | |
92 | long Long[3]; |
- | |
Line 93... | Line 99... | ||
93 | float Float[3]; |
99 | int8_t Byte[12]; |
94 | } Param; |
100 | int16_t Int[6]; |
95 | unsigned char Chksum; |
- | |
96 | }; |
101 | int32_t Long[3]; |
97 | 102 | float Float[3]; |
|
Line 98... | Line 103... | ||
98 | 103 | } Param; |
|
99 | #ifdef USE_SPI_COMMUNICATION |
104 | uint8_t Chksum; |
100 | 105 | } FromNaviCtrl_t; |
|
101 | extern struct str_ToNaviCtrl ToNaviCtrl; |
106 | |
102 | extern struct str_FromNaviCtrl FromNaviCtrl; |
107 | #ifdef USE_SPI_COMMUNICATION |
103 | 108 | ||
Line 104... | Line 109... | ||
104 | //#define SPI_CMD_VALUE 0x03 |
109 | extern ToNaviCtrl_t ToNaviCtrl; |