Subversion Repositories FlightCtrl

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
827 ingob 1
// ######################## SPI - FlightCtrl ###################
2
#ifndef _SPI_H
3
#define _SPI_H
4
 
886 killagreg 5
//#include <util/delay.h>
6
#include <inttypes.h>
827 ingob 7
 
8
 
9
#define SPI_PROTOCOL_COMP   1
10
 
11
//-----------------------------------------
12
#define DDR_SPI DDRB
13
#define DD_SS   PB4
14
#define DD_SCK  PB7
15
#define DD_MOSI PB5
886 killagreg 16
#define DD_MISO PB6
827 ingob 17
 
886 killagreg 18
// for compatibility reasons gcc3.x <-> gcc4.x
19
#ifndef SPCR
827 ingob 20
#define SPCR   SPCR0
886 killagreg 21
#endif
22
#ifndef SPE
827 ingob 23
#define SPE   SPE0
886 killagreg 24
#endif
25
#ifndef MSTR
827 ingob 26
#define MSTR   MSTR0
886 killagreg 27
#endif
28
#ifndef SPR1
827 ingob 29
#define SPR1   SPR01
886 killagreg 30
#endif
31
#ifndef SPR0
827 ingob 32
#define SPR0   SPR00
886 killagreg 33
#endif
34
#ifndef SPIE
827 ingob 35
#define SPIE   SPIE0
886 killagreg 36
#endif
37
#ifndef SPDR
827 ingob 38
#define SPDR   SPDR0
886 killagreg 39
#endif
40
#ifndef SPIF
827 ingob 41
#define SPIF   SPIF0
886 killagreg 42
#endif
43
#ifndef SPSR
827 ingob 44
#define SPSR   SPSR0
886 killagreg 45
#endif
827 ingob 46
// -------------------------
47
 
48
#define SLAVE_SELECT_DDR_PORT   DDRC
49
#define SLAVE_SELECT_PORT       PORTC
50
#define SPI_SLAVE_SELECT        PC5
51
 
52
 
53
#define SPI_CMD_USER        10
54
#define SPI_CMD_STICK       11
1078 killagreg 55
#define SPI_CMD_MISC            12
936 killagreg 56
#define SPI_CMD_PARAMETER1      13
1078 killagreg 57
#define SPI_CMD_VERSION         14
886 killagreg 58
 
59
typedef struct
827 ingob 60
{
886 killagreg 61
        uint8_t Sync1;
62
        uint8_t Sync2;
63
        uint8_t Command;
911 killagreg 64
        int16_t IntegralNick;
886 killagreg 65
        int16_t IntegralRoll;
911 killagreg 66
        int16_t AccNick;
886 killagreg 67
        int16_t AccRoll;
68
        int16_t GyroHeading;
911 killagreg 69
        int16_t GyroNick;
886 killagreg 70
        int16_t GyroRoll;
71
        int16_t GyroYaw;
72
        union
73
        {
74
                int8_t  sByte[12];
75
                uint8_t Byte[12];
76
                int16_t Int[6];
77
                int32_t Long[3];
78
                float   Float[3];
79
        } Param;
80
        uint8_t Chksum;
1078 killagreg 81
} __attribute__((packed)) ToNaviCtrl_t;
827 ingob 82
 
886 killagreg 83
 
84
 
1078 killagreg 85
#define SPI_CMD_OSD_DATA        100
86
#define SPI_CMD_GPS_POS         101
87
#define SPI_CMD_GPS_TARGET      102
88
#define SPI_KALMAN                      103
886 killagreg 89
 
90
typedef struct
827 ingob 91
{
886 killagreg 92
        uint8_t Command;
911 killagreg 93
        int16_t GPS_Nick;
886 killagreg 94
        int16_t GPS_Roll;
95
        int16_t GPS_Yaw;
96
        int16_t CompassHeading;
97
        int16_t Status;
936 killagreg 98
        uint16_t BeepTime;
886 killagreg 99
        union
100
        {
101
                int8_t  Byte[12];
102
                int16_t Int[6];
103
                int32_t Long[3];
104
                float   Float[3];
105
        } Param;
106
        uint8_t Chksum;
1078 killagreg 107
} __attribute__((packed)) FromNaviCtrl_t;
827 ingob 108
 
109
 
1078 killagreg 110
typedef struct
111
{
112
        uint8_t Major;
113
        uint8_t Minor;
114
        uint8_t Patch;
115
        uint8_t Compatible;
116
} __attribute__((packed)) SPI_VersionInfo_t;
117
 
118
 
119
extern ToNaviCtrl_t                     ToNaviCtrl;
120
extern FromNaviCtrl_t                   FromNaviCtrl;
121
 
936 killagreg 122
void SPI_MasterInit(void);
123
void SPI_StartTransmitPacket(void);
124
void SPI_TransmitByte(void);
827 ingob 125
 
126
 
127
 
886 killagreg 128
#endif //_SPI_H