-
Notifications
You must be signed in to change notification settings - Fork 1
/
v5_apitypes.h
445 lines (384 loc) · 16.1 KB
/
v5_apitypes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
/*----------------------------------------------------------------------------*/
/* */
/* Copyright (c) Innovation First 2016, All rights reserved. */
/* */
/* Module: v5_apitypes.h */
/* Author: James Pearman */
/* Created: 8 Nov 2016 */
/* */
/* Revisions: V0.1 */
/* */
/*----------------------------------------------------------------------------*/
#ifndef V5_APITYPES_H_
#define V5_APITYPES_H_
#include "stdint.h"
#include "stdbool.h"
/*-----------------------------------------------------------------------------*/
/** @file v5_apitypes.h
* @brief Header for V5 API - type definitions
*//*---------------------------------------------------------------------------*/
#ifdef __cplusplus
extern "C" {
#endif
/*----------------------------------------------------------------------------*/
/** @brief Code signature */
/*----------------------------------------------------------------------------*/
/** @details
* The first 16 bytes of a user code binary should contain the user code
* signature. For simple user code programs this will be created by the
* startup code in the runtime library, certain types of user code,
* for example a virtual machine, may override the default settings to cause
* the V5 system code to enable custom functionality yet TBD.
*
* to override the default use a definition like this in one of the user
* code source files.
*
* __attribute__ ((section (".boot_data"))) vcodesig vexCodeSig =
* { V5_SIG_MAGIC,
* V5_SIG_TYPE_USER,
* V5_SIG_OWNER_VEX,
* V5_SIG_OPTIONS_NONE
* };
*
* V5_SIG_MAGIC must be set, other fields and their behavior are TBD
*
* vexCodeSig is defined as "weak" and this definition will override it.
*/
typedef struct __attribute__ ((packed)) _vcodesig {
uint32_t magic; // Magic, must be 'VXV5' 0x35565856 le
uint32_t type; // program type
uint32_t owner; // program originator
uint32_t options; // program options
} vcodesig ;
//
#define V5_SIG_MAGIC 0x35585658
#define V5_SIG_TYPE_USER 0
#define V5_SIG_OWNER_SYS 0
#define V5_SIG_OWNER_VEX 1
#define V5_SIG_OWNER_PARTNER 2
#define V5_SIG_OPTIONS_NONE 0
#define V5_SIG_OPTIONS_INDG (1 << 0) // Invert default graphics colors
#define V5_SIG_OPTIONS_EXIT (1 << 1) // Kill threads when main exits
#define V5_SIG_OPTIONS_THDG (1 << 2) // Invert graphics based on theme
#define V5_CODE_SIG( type, owner, options ) \
vcodesig vexCodeSig __attribute__ ((section (".boot_data"))) = \
{ V5_SIG_MAGIC, type, owner, options };
/*----------------------------------------------------------------------------*/
/** @brief Structures used by system time functions */
/*----------------------------------------------------------------------------*/
// Time
struct time {
uint8_t ti_hour; /// Hours
uint8_t ti_min; /// Minutes
uint8_t ti_sec; /// Seconds
uint8_t ti_hund; /// Hundredths of seconds
};
// Time
struct date {
uint16_t da_year; /// Year - 1980
uint8_t da_day; /// Day of the month
uint8_t da_mon; /// Month (1 = Jan)
};
// DEVICE IDs
/*----------------------------------------------------------------------------*/
/** @brief V5 Device type definitions */
/*----------------------------------------------------------------------------*/
// TODO
// Do we really want to include the declare.h file ??
typedef enum {
kDeviceTypeNoSensor = 0,
kDeviceTypeMotorSensor = 2,
kDeviceTypeLedSensor = 3,
kDeviceTypeAbsEncSensor = 4,
kDeviceTypeBumperSensor = 5,
kDeviceTypeImuSensor = 6,
kDeviceTypeRangeSensor = 7,
kDeviceTypeRadioSensor = 8,
kDeviceTypeTetherSensor = 9,
kDeviceTypeBrainSensor = 10,
kDeviceTypeVisionSensor = 11,
kDeviceTypeAdiSensor = 12,
kDeviceTypeGyroSensor = 0x46,
kDeviceTypeSonarSensor = 0x47,
kDeviceTypeGenericSensor = 128,
kDeviceTypeGenericSerial = 129,
kDeviceTypeUndefinedSensor = 255
} V5_DeviceType;
// Opaque pointer to V5 device type structure
typedef struct _V5_Device * V5_DeviceT;
// Some ports will be virtual, some physical
#define V5_MAX_DEVICE_PORTS 32
typedef V5_DeviceType V5_DeviceTypeBuffer[V5_MAX_DEVICE_PORTS];
/*----------------------------------------------------------------------------*/
/** @brief V5 Controller definitions */
/*----------------------------------------------------------------------------*/
//
// March 2018, obsolete types now removed
// additional enum for final V5 controller labels added
//
typedef enum _V5_ControllerIndex {
AnaLeftX = 0,
AnaLeftY,
AnaRightX,
AnaRightY,
AnaSpare1,
AnaSpare2,
Button5U,
Button5D,
Button6U,
Button6D,
Button7U,
Button7D,
Button7L,
Button7R,
Button8U,
Button8D,
Button8L,
Button8R,
ButtonSEL,
BatteryLevel,
ButtonAll,
Flags,
BatteryCapacity,
// Final V5 names
Axis1 = AnaRightX,
Axis2 = AnaRightY,
Axis3 = AnaLeftY,
Axis4 = AnaLeftX,
ButtonL1 = Button5U,
ButtonL2 = Button5D,
ButtonR1 = Button6U,
ButtonR2 = Button6D,
ButtonUp = Button7U,
ButtonDown = Button7D,
ButtonLeft = Button7L,
ButtonRight = Button7R,
ButtonX = Button8U,
ButtonB = Button8D,
ButtonY = Button8L,
ButtonA = Button8R
} V5_ControllerIndex;
typedef enum _V5_ControllerStatus {
kV5ControllerOffline = 0,
kV5ControllerTethered,
kV5ControllerVexnet
} V5_ControllerStatus;
typedef enum _V5_ControllerId {
kControllerMaster = 0,
kControllerPartner
} V5_ControllerId;
/*----------------------------------------------------------------------------*/
/** @brief V5 LED device definitions */
/*----------------------------------------------------------------------------*/
// The LED is an obsolete sensor but we will leave as it's available on the Dev
// systems
typedef enum _V5_DeviceLedColor {
kLedColorBlack = 0,
kLedColorRed = 0xFF0000,
kLedColorGreen = 0x00FF00,
kLedColorBlue = 0x0000FF,
kLedColorYellow = 0xFFFF00,
kLedColorCyan = 0x00FFFF,
kLedColorMagenta = 0xFF00FF,
kLedColorWhite = 0xFFFFFF
} V5_DeviceLedColor;
/*----------------------------------------------------------------------------*/
/** @brief V5 ADI device definitions */
/*----------------------------------------------------------------------------*/
typedef enum _V5_AdiPortConfiguration {
kAdiPortTypeAnalogIn = 0,
kAdiPortTypeAnalogOut,
kAdiPortTypeDigitalIn,
kAdiPortTypeDigitalOut,
kAdiPortTypeSmartButton,
kAdiPortTypeSmartPot,
kAdiPortTypeLegacyButton,
kAdiPortTypeLegacyPotentiometer,
kAdiPortTypeLegacyLineSensor,
kAdiPortTypeLegacyLightSensor,
kAdiPortTypeLegacyGyro,
kAdiPortTypeLegacyAccelerometer,
kAdiPortTypeLegacyServo,
kAdiPortTypeLegacyPwm,
kAdiPortTypeQuadEncoder,
kAdiPortTypeSonar,
kAdiPortTypeLegacyPwmSlew,
kAdiPortTypeUndefined = 255
} V5_AdiPortConfiguration;
// ADI sensor has 8 ports
#define V5_ADI_PORT_NUM 8
/*----------------------------------------------------------------------------*/
/** @brief V5 Bumper switch device definitions */
/*----------------------------------------------------------------------------*/
typedef enum _V5_DeviceBumperState {
kBumperReleased = 0, /// Switch pressed
kBumperPressed = 1 /// Switch released
} V5_DeviceBumperState;
/*----------------------------------------------------------------------------*/
/** @brief V5 Motor definitions */
/*----------------------------------------------------------------------------*/
// Most of this is still TBD and is currently based on the IQ implementation
typedef enum {
kMotorControlModeOFF = 0, /// Motor is off and in coast mode
kMotorControlModeBRAKE = 1, /// Motor is off and in brake mode
kMotorControlModeHOLD = 2, /// Motor is holding at current position
kMotorControlModeSERVO = 3, /// Motor is in "Servo" mode. Move to position and hold at that position
kMotorControlModePROFILE = 4, /// Motor moves to set position and stops.
kMotorControlModeVELOCITY = 5, /// Motor is unlimited movement at set 'velocity'
kMotorControlModeUNDEFINED = 6 ///
} V5MotorControlMode;
typedef enum _V5_MotorBrakeMode {
kV5MotorBrakeModeCoast = 0, /// Motor will coast when stopped
kV5MotorBrakeModeBrake = 1, /// Motor will brake when stopped
kV5MotorBrakeModeHold = 2 /// Motor will hold position when stopped
} V5MotorBrakeMode;
typedef enum {
kMotorEncoderDegrees = 0, /// degrees Encoder Count Mode
kMotorEncoderRotations = 1, /// rotations Encoder Count Mode
kMotorEncoderCounts = 2 /// Raw Encoder Count Mode
} V5MotorEncoderUnits;
typedef enum _V5MotorGearset {
kMotorGearSet_36 = 0, /// 36:1 gear set, torque
kMotorGearSet_18 = 1, /// 18:1 gear set, speed
kMotorGearSet_06 = 2 /// 6:1 gear set, high speed
} V5MotorGearset;
// This is for 36:1 gear set
#define V5_MOTOR_COUNTS_PER_ROT 1800.0
//
// preliminary, used for position and velocity
//
typedef struct __attribute__ ((packed)) _V5_DeviceMotorPid {
uint8_t kf;
uint8_t kp;
uint8_t ki;
uint8_t kd;
uint8_t filter;
uint8_t pad1;
uint16_t limit;
uint8_t threshold;
uint8_t loopspeed;
uint8_t pad2[2];
} V5_DeviceMotorPid;
/*----------------------------------------------------------------------------*/
/** @brief V5 Vision sensor definitions */
/*----------------------------------------------------------------------------*/
// subject to change
typedef enum {
kVisionModeNormal = 0,
kVisionModeLineDetect = 2,
kVisionTypeTest = 3
} V5VisionMode;
typedef enum {
kVisionTypeNormal = 0,
kVisionTypeColorCode = 1,
kVisionTypeLineDetect = 2
} V5VisionBlockType;
// White balance
typedef enum {
kVisionWBNormal = 0,
kVisionWBStart = 1,
kVisionWBManual = 2
} V5VisionWBMode;
// LED control, from V5 or by the vision sensor
typedef enum {
kVisionLedModeAuto = 0,
kVisionLedModeManual = 1
} V5VisionLedMode;
// Wifi mode
typedef enum {
kVisionWifiModeOff = 0,
kVisionWifiModeOn = 1
} V5VisionWifiMode;
// signature should be 40 bytes and is the same data
// as sent to the vision sensor
// if bit0 is now set you know signature is read back
#define VISION_SIG_FLAG_STATUS (1<<0)
typedef struct __attribute__ ((__packed__)) {
uint8_t id;
uint8_t flags;
uint8_t pad[2];
float range;
int32_t uMin;
int32_t uMax;
int32_t uMean;
int32_t vMin;
int32_t vMax;
int32_t vMean;
uint32_t mRgb;
uint32_t mType;
} V5_DeviceVisionSignature;
typedef struct __attribute(( packed )) _V5_DeviceVisionObject {
uint16_t signature; /// block signature
V5VisionBlockType type; /// block type
uint16_t xoffset; /// left side of block
uint16_t yoffset; /// top of block
uint16_t width; /// width of block
uint16_t height; /// height of block
uint16_t angle; /// angle of CC block in 0.1 deg units
} V5_DeviceVisionObject;
// Color structure, used for LED and white balance
typedef struct __attribute(( packed )) _V5_DeviceVisionRgb {
uint8_t red;
uint8_t green;
uint8_t blue;
uint8_t brightness; /// not used yet
} V5_DeviceVisionRgb;
/*----------------------------------------------------------------------------*/
/** @brief V5 SD File system definitions */
/*----------------------------------------------------------------------------*/
// Opaque pointer (FIL *) to file structure
typedef void FIL;
// seek flags
// changed, Mar 6 2018 to be more consistent with stdio.h
#define FS_SEEK_SET 0
#define FS_SEEK_CUR 1
#define FS_SEEK_END 2
// File function return code (FRESULT)
typedef enum {
FR_OK = 0U, /// (0) Succeeded
FR_DISK_ERR, /// (1) A hard error occurred in the low level disk I/O layer
FR_INT_ERR, /// (2) Assertion failed
FR_NOT_READY, /// (3) The physical drive cannot work
FR_NO_FILE, /// (4) Could not find the file
FR_NO_PATH, /// (5) Could not find the path
FR_INVALID_NAME, /// (6) The path name format is invalid
FR_DENIED, /// (7) Access denied due to prohibited access or directory full
FR_EXIST, /// (8) Access denied due to prohibited access
FR_INVALID_OBJECT, /// (9) The file/directory object is invalid
FR_WRITE_PROTECTED, /// (10) The physical drive is write protected
FR_INVALID_DRIVE, /// (11) The logical drive number is invalid
FR_NOT_ENABLED, /// (12) The volume has no work area
FR_NO_FILESYSTEM, /// (13) There is no valid FAT volume
FR_MKFS_ABORTED, /// (14) The f_mkfs() aborted due to any parameter error
FR_TIMEOUT, /// (15) Could not get a grant to access the volume within defined period
FR_LOCKED, /// (16) The operation is rejected according to the file sharing policy
FR_NOT_ENOUGH_CORE, /// (17) LFN working buffer could not be allocated
FR_TOO_MANY_OPEN_FILES, /// (18) Number of open files > _FS_SHARE
FR_INVALID_PARAMETER /// (19) Given parameter is invalid
} FRESULT;
/*----------------------------------------------------------------------------*/
/** @brief V5 touch events */
/*----------------------------------------------------------------------------*/
typedef enum _touchEvent {
kTouchEventRelease,
kTouchEventPress,
kTouchEventPressAuto
} V5_TouchEvent;
typedef struct _V5_TouchStatus {
V5_TouchEvent lastEvent;
int16_t lastXpos;
int16_t lastYpos;
int32_t pressCount;
int32_t releaseCount;
} V5_TouchStatus;
/*----------------------------------------------------------------------------*/
/** @brief V5 competition status bits */
/*----------------------------------------------------------------------------*/
#define V5_COMP_BIT_EBL 1 // if set then robot disabled
#define V5_COMP_BIT_MODE 2 // if set then robot in autonomous
#define V5_COMP_BIT_COMP 4 // if set then either comp switch or field control connected
#define V5_COMP_BIT_GAME 8 // if set then field control connected
#ifdef __cplusplus
}
#endif
#endif /* V5_APITYPES_H_*/