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
 
5
#include <util/delay.h>
6
 
7
#define USE_SPI_COMMUNICATION 
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
16
#define DD_MISO PB6 
17
 
18
// for compatibility reasons gcc3.x <-> gcc4.x 
19
#ifndef SPCR  
20
#define SPCR   SPCR0
21
#endif    
22
#ifndef SPE  
23
#define SPE   SPE0
24
#endif    
25
#ifndef MSTR  
26
#define MSTR   MSTR0
27
#endif    
28
#ifndef SPR1  
29
#define SPR1   SPR01
30
#endif    
31
#ifndef SPR0  
32
#define SPR0   SPR00
33
#endif    
34
#ifndef SPIE  
35
#define SPIE   SPIE0
36
#endif    
37
#ifndef SPDR  
38
#define SPDR   SPDR0
39
#endif    
40
#ifndef SPIF  
41
#define SPIF   SPIF0
42
#endif    
43
#ifndef SPSR  
44
#define SPSR   SPSR0
45
#endif    
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
55
#define SPI_CMD_CAL_COMPASS 12
56
struct str_ToNaviCtrl
57
{
58
 unsigned char Sync1, Sync2;
59
 unsigned char Command;
60
 signed int  IntegralNick;
61
 signed int  IntegralRoll;
62
 signed int  AccNick;
63
 signed int  AccRoll;
64
 signed int  GyroCompass;
65
 signed int  GyroNick;
66
 signed int  GyroRoll;
67
 signed int  GyroGier;
68
 union  
69
 { char Byte[12];
70
   int  Int[6];
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;
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
};
97
 
98
 
99
#ifdef USE_SPI_COMMUNICATION
100
 
101
extern struct str_ToNaviCtrl   ToNaviCtrl;
102
extern struct str_FromNaviCtrl FromNaviCtrl;
103
 
104
//#define SPI_CMD_VALUE   0x03
105
 
106
extern void SPI_MasterInit(void);
107
extern void SPI_StartTransmitPacket(void);
108
extern void UpdateSPI_Buffer(void);
109
extern void SPI_TransmitByte(void);
110
#else
111
 
112
 
113
// -------------------------------- Dummy -----------------------------------------
114
#define  SPI_MasterInit() ; 
115
#define  SPI_StartTransmitPacket() ;
116
#define  UpdateSPI_Buffer() ;
117
#define  SPI_TransmitByte() ;
118
#endif
119
 
120
 
121
#endif