Main Page
Related Pages
Data Structures
Files
Examples
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
vexspi.h
Go to the documentation of this file.
1
/*-----------------------------------------------------------------------------*/
2
/* */
3
/* Copyright (c) James Pearman */
4
/* 2013 */
5
/* All Rights Reserved */
6
/* */
7
/*-----------------------------------------------------------------------------*/
8
/* */
9
/* Module: vexspi.h */
10
/* Author: James Pearman */
11
/* Created: 7 May 2013 */
12
/* */
13
/* Revisions: */
14
/* V1.00 4 July 2013 - Initial release */
15
/* */
16
/*-----------------------------------------------------------------------------*/
17
/* */
18
/* This file is part of ConVEX. */
19
/* */
20
/* The author is supplying this software for use with the VEX cortex */
21
/* control system. ConVEX is free software; you can redistribute it */
22
/* and/or modify it under the terms of the GNU General Public License */
23
/* as published by the Free Software Foundation; either version 3 of */
24
/* the License, or (at your option) any later version. */
25
/* */
26
/* ConVEX is distributed in the hope that it will be useful, */
27
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
28
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
29
/* GNU General Public License for more details. */
30
/* */
31
/* You should have received a copy of the GNU General Public License */
32
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
33
/* */
34
/* A special exception to the GPL can be applied should you wish to */
35
/* distribute a combined work that includes ConVEX, without being obliged */
36
/* to provide the source code for any proprietary components. */
37
/* See the file exception.txt for full details of how and when the */
38
/* exception can be applied. */
39
/* */
40
/* The author can be contacted on the vex forums as jpearman */
41
/* or electronic mail using jbpearman_at_mac_dot_com */
42
/* Mentor for team 8888 RoboLancers, Pasadena CA. */
43
/* */
44
/*-----------------------------------------------------------------------------*/
45
46
#ifndef __VEXSPI__
47
#define __VEXSPI__
48
49
/*-----------------------------------------------------------------------------*/
50
/** @file vexspi.h
51
* @brief SPI communication to the master processor, macros and prototypes
52
*/
/*---------------------------------------------------------------------------*/
53
54
/** @cond */
55
#ifdef BOARD_OLIMEX_STM32_P103
56
// On the eval card
57
#define VEX_SPI_ENABLE_PORT GPIOA
58
#define VEX_SPI_ENABLE_PIN 8
59
#define VEX_SPI_CS_PORT GPIOA
60
#define VEX_SPI_CS_PIN 4
61
62
#else
63
// On the real cortex
64
#define VEX_SPI_ENABLE_PORT GPIOA
65
#define VEX_SPI_ENABLE_PIN 11
66
#define VEX_SPI_CS_PORT GPIOE
67
#define VEX_SPI_CS_PIN 0
68
69
#endif
70
/** @endcond */
71
72
/*-----------------------------------------------------------------------------*/
73
/** @brief default team name */
74
/*-----------------------------------------------------------------------------*/
75
#if !defined(CONVEX_TEAM_NAME)
76
#define CONVEX_TEAM_NAME "CONVEX ";
77
#endif
78
79
/*-----------------------------------------------------------------------------*/
80
/** @brief joystick data structure */
81
/*-----------------------------------------------------------------------------*/
82
/** @details
83
* Format of the joystick component of the SPI receive packet
84
* The reserved bytes are really used for other purposes
85
* but we keep them here in V1.00
86
*/
87
typedef
struct
_jsdata
{
88
char
Ch1
;
///< Analog control channel 1
89
char
Ch2
;
///< Analog control channel 2
90
char
Ch3
;
///< Analog control channel 3
91
char
Ch4
;
///< Analog control channel 4
92
char
acc_y
;
///< Accelerometer y data
93
char
acc_x
;
///< Accelerometer x data
94
char
acc_z
;
///< Accelerometer z data - not used
95
unsigned
char
btns
[2];
///< data for the 12 buttons
96
unsigned
char
res
[2];
///< reserved
97
}
jsdata
;
98
99
/*-----------------------------------------------------------------------------*/
100
/** @brief SPI transmit data packet */
101
/*-----------------------------------------------------------------------------*/
102
/** @details
103
* Format of a SPI transmit packet - 16 words
104
*/
105
typedef
union
_spiTxPacket
{
106
struct
_spiTxPak
{
107
unsigned
char
h1
;
///< Header byte one
108
unsigned
char
h2
;
///< Header byte two
109
unsigned
char
state
;
///< Control state
110
unsigned
char
reserved
[2];
///< unknown data
111
unsigned
char
type
;
///< data type
112
unsigned
char
motor
[8];
///< motor pwm data
113
unsigned
char
pad
[15];
///< not used
114
unsigned
char
rev_lsb
;
///< revision of user code lsb
115
unsigned
char
rev_msb
;
///< revision of user code msb
116
unsigned
char
id
;
///< message id
117
}
pak
;
///< access spiTxPacket as named variables
118
119
unsigned
char
data
[32];
///< access spiTxPacket as an array of char
120
}
spiTxPacket
;
121
122
/*-----------------------------------------------------------------------------*/
123
/** @brief SPI receive data packet */
124
/*-----------------------------------------------------------------------------*/
125
/** @details
126
* Format of a SPI receive packet - 16 words
127
*/
128
typedef
union
_spiRxPacket
{
129
struct
_spiRxPak
{
130
unsigned
char
h1
;
///< Header byte one
131
unsigned
char
h2
;
///< Header byte two
132
unsigned
char
status
;
///< status
133
unsigned
char
ctl
;
///< status and control byte
134
unsigned
char
batt1
;
///< main battery level, 59mV per bit
135
unsigned
char
batt2
;
///< backup battery level, 59mV per bit
136
jsdata
js_1
;
///< data for main joystick
137
unsigned
char
pad
;
///< 1 byte padding
138
jsdata
js_2
;
///< data for partner joystick
139
unsigned
char
rev_lsb
;
///< revision of master code lsb
140
unsigned
char
rev_msb
;
///< revision of master code msb
141
unsigned
char
id
;
///< message id
142
}
pak
;
///< access spiRxPacke as named variables
143
144
unsigned
char
data
[32];
///< access spiRxPacket as an array of char
145
}
spiRxPacket
;
146
147
/*-----------------------------------------------------------------------------*/
148
/** @brief SPI data */
149
/*-----------------------------------------------------------------------------*/
150
/** @details
151
* All SPI related data collected in this structure
152
*/
153
typedef
struct
_SpiData
{
154
spiTxPacket
txdata
;
///< tx data packet
155
spiRxPacket
rxdata
;
///< valid rx data packet
156
spiRxPacket
rxdata_t
;
///< receive data packet, may have errors
157
uint16_t
online
;
///< online status
158
uint32_t
errors
;
///< number of packets received with error
159
}
SpiData
;
160
161
162
#ifdef __cplusplus
163
extern
"C"
{
164
#endif
165
166
#define vexTeamnameSet(name) vexSpiTeamnameSet( name )
167
168
void
vexSpiInit
(
void
);
169
void
vexSpiTeamnameSet
(
char
*name );
170
short
vexSpiGetOnlineStatus
(
void
);
171
void
vexSpiSetMotor
( int16_t index, int16_t data, bool_t reversed );
172
void
vexSpiSend
(
void
);
173
void
vexSpiTickDelay
( int16_t tick);
174
jsdata
*
vexSpiGetJoystickDataPtr
( int16_t index );
175
uint16_t
vexSpiGetControl
(
void
);
176
uint16_t
vexSpiGetMainBattery
(
void
);
177
uint16_t
vexSpiGetBackupBattery
(
void
);
178
179
void
vexSpiDebug
(
vexStream
*chp,
int
argc,
char
*argv[]);
180
181
182
#ifdef __cplusplus
183
}
184
#endif
185
186
#endif // __VEXSPI__
convex
cortex
fw
vexspi.h
Generated on Sun Jan 5 2014 15:43:37 for Convex by
1.8.4