Rev 54 | Rev 61 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 54 | Rev 57 | ||
---|---|---|---|
1 | #ifndef _SPI_SLAVE_H |
1 | #ifndef _SPI_SLAVE_H |
2 | #define _SPI_SLAVE_H |
2 | #define _SPI_SLAVE_H |
3 | 3 | ||
4 | #include "fifo.h" |
4 | #include "fifo.h" |
5 | 5 | ||
6 | 6 | ||
7 | #define SS_PIN GPIO_ReadBit(GPIO2, GPIO_Pin_7) |
7 | #define SS_PIN GPIO_ReadBit(GPIO2, GPIO_Pin_7) |
8 | - | ||
9 | #define SPI_PROTOCOL_COMP 2 |
- | |
10 | 8 | ||
11 | #define SPI_CMD_USER 10 |
9 | #define SPI_CMD_USER 10 |
12 | #define SPI_CMD_STICK 11 |
10 | #define SPI_CMD_STICK 11 |
13 | #define SPI_CMD_MISC 12 |
11 | #define SPI_CMD_MISC 12 |
14 | #define SPI_CMD_PARAMETER1 13 |
12 | #define SPI_CMD_PARAMETER1 13 |
15 | #define SPI_CMD_VERSION 14 |
13 | #define SPI_CMD_VERSION 14 |
16 | 14 | ||
17 | extern s32 FC_Kalman_K; |
15 | extern s32 FC_Kalman_K; |
18 | extern s32 Kalman_MaxDrift; |
16 | extern s32 Kalman_MaxDrift; |
19 | extern s32 Kalman_MaxFusion; |
17 | extern s32 Kalman_MaxFusion; |
20 | typedef struct |
18 | typedef struct |
21 | { |
19 | { |
22 | u8 Command; |
20 | u8 Command; |
23 | s16 IntegralNick; |
21 | s16 IntegralNick; |
24 | s16 IntegralRoll; |
22 | s16 IntegralRoll; |
25 | s16 AccNick; |
23 | s16 AccNick; |
26 | s16 AccRoll; |
24 | s16 AccRoll; |
27 | s16 GyroHeading; |
25 | s16 GyroHeading; |
28 | s16 GyroNick; |
26 | s16 GyroNick; |
29 | s16 GyroRoll; |
27 | s16 GyroRoll; |
30 | s16 GyroYaw; |
28 | s16 GyroYaw; |
31 | union |
29 | union |
32 | { |
30 | { |
33 | s8 sByte[12]; |
31 | s8 sByte[12]; |
34 | u8 Byte[12]; |
32 | u8 Byte[12]; |
35 | s16 Int[6]; |
33 | s16 Int[6]; |
36 | s32 Long[3]; |
34 | s32 Long[3]; |
37 | float Float[3]; |
35 | float Float[3]; |
38 | } Param; |
36 | } Param; |
39 | u8 Chksum; |
37 | u8 Chksum; |
40 | } __attribute__((packed)) FromFlightCtrl_t; |
38 | } __attribute__((packed)) FromFlightCtrl_t; |
41 | 39 | ||
42 | #define SPI_KALMAN 103 |
40 | #define SPI_KALMAN 103 |
43 | 41 | ||
44 | typedef struct |
42 | typedef struct |
45 | { |
43 | { |
46 | u8 Command; |
44 | u8 Command; |
47 | s16 GPS_Nick; |
45 | s16 GPS_Nick; |
48 | s16 GPS_Roll; |
46 | s16 GPS_Roll; |
49 | s16 GPS_Yaw; |
47 | s16 GPS_Yaw; |
50 | s16 CompassHeading; |
48 | s16 CompassHeading; |
51 | s16 Status; |
49 | s16 Status; |
52 | u16 BeepTime; |
50 | u16 BeepTime; |
53 | union |
51 | union |
54 | { |
52 | { |
55 | s8 sByte[12]; |
53 | s8 sByte[12]; |
56 | u8 Byte[12]; |
54 | u8 Byte[12]; |
57 | s16 Int[6]; |
55 | s16 Int[6]; |
58 | s32 Long[3]; |
56 | s32 Long[3]; |
59 | float Float[3]; |
57 | float Float[3]; |
60 | }Param; |
58 | }Param; |
61 | u8 Chksum; |
59 | u8 Chksum; |
62 | } __attribute__((packed)) ToFlightCtrl_t; |
60 | } __attribute__((packed)) ToFlightCtrl_t; |
63 | 61 | ||
64 | 62 | ||
65 | typedef struct |
63 | typedef struct |
66 | { |
64 | { |
67 | u8 Major; |
65 | u8 Major; |
68 | u8 Minor; |
66 | u8 Minor; |
69 | u8 Patch; |
67 | u8 Patch; |
70 | u8 Compatible; |
68 | u8 Compatible; |
71 | } __attribute__((packed)) SPI_Version_t; |
69 | } __attribute__((packed)) SPI_Version_t; |
72 | 70 | ||
73 | extern volatile FromFlightCtrl_t FromFlightCtrl; |
71 | extern volatile FromFlightCtrl_t FromFlightCtrl; |
74 | extern volatile ToFlightCtrl_t ToFlightCtrl; |
72 | extern volatile ToFlightCtrl_t ToFlightCtrl; |
75 | extern SPI_Version_t FC_Version; |
73 | extern SPI_Version_t FC_Version; |
76 | extern fifo_t CompassCalcStateFiFo; |
74 | extern fifo_t CompassCalcStateFiFo; |
77 | extern u32 CheckSPIOkay; |
75 | extern u32 CheckSPIOkay; |
78 | 76 | ||
79 | void SPI0_Init(void); |
77 | void SPI0_Init(void); |
80 | void SPI0_GetFlightCtrlVersion(void); |
78 | void SPI0_GetFlightCtrlVersion(void); |
81 | void SPI0_UpdateBuffer(void); |
79 | void SPI0_UpdateBuffer(void); |
82 | 80 | ||
83 | 81 | ||
84 | 82 | ||
85 | #endif //_SPI_SLAVE_H |
83 | #endif //_SPI_SLAVE_H |
86 | 84 |