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