summaryrefstree
path: root/HDMI/bridge/358870xbg/shooter-vr/主进程-修改已有资源/src/main.c
blob: 0a3bd5b1d0aac83277cf00bcca46127d8f73413d (plain)
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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
/**
 ******************************************************************************
 * @file    main.c
 * @author  YFL
 * @version V0.4
 * @date    11.5.2014
 * @brief   Main program body
 ******************************************************************************
 */

// The "Foculus Rift" tracker
//------------------------------------------------------------------
// A USB HID device, sending Accelerometer, Gyroscope and Magnetometer data over USB in an
// Oculus Rift compatible format.
// This project comes in useful, if you are building your own DIY Head Mounted Display.
// It solves the problem of finding a motion tracker.
// The firmware runs on the STM32F3DISCOVERY board and should be compatible with all Oculus Rift games.

// development blog:   http://yetifrisstlama.blogspot.fr/2014/03/the-foculus-rift-part-2-reverse.html

// Organization:
//------------------------------------------------------------------
// main.c   		main logic of the tracker,
//                  handling and reformating the sensor data stream and packing it into 62 byte packets to be sent over USB,
//                  Assign the coordinate system directions
//                  keeping track of the configuration data structures which the libOVR might send and request
// peripherals.c    setup and request data from the 3 sensor chips over SPI and I2C
//                  Handle the scaling and calibration factors, so the headtracker moves in the right way
//                  Zero-level calibration routine for the gyroscope
//                  Save calibration factors to flash
//                  PWM-patterns for the 8 status LEDs
// usb_desc.c       USB - HID descriptors, which fool the PC into thinking that there is an Oculus RIft corrected
// usb_endp.c       STM USB driver endpoint1 callbacks, just sets some global flags to inform the main routine when there is new data
// usb_prop.c       Customization of the STM USB driver, so feature reports can be sent and received
//                  received data is copied in the global array featureReportData[] and then processed by the main loop


// THings to implement
//------------------------------------------------------------------
// * Evaluate the flags, I still do not have a clue what they are used for
// * What is this mysterious 16 bit command field in the Oculus packets for?
// * FixMe: There is this strange synchronization issue, where featureReportData[] sometimes contains invalid data when evaluated in main()


// Changelog
//--------------------------------
// 09.03.2014:	Fixed bug in handleConfigPacketEvent() by adding break; statements (data rate was always 1 ms before)
// 10.03.2014:  Changed wMaxPacketSize from 62 to 64
// 19.03.2014:  Changed I2C Bus speed to 400 kHz, which allows to read all 3 sensors in 0.65 ms  (before it was > 2 ms)
// 20.03.2014:  Now evaluating the "new data ready" pins of all 3 sensors (improves timing a lot, reduces jitter)
//              Enabled FIFO in Streaming mode of Accelerometer and Gyro (no samples will be lost!)
//              Fixed Glitches in Magnetometer output by setting it to 75 Hz measurement rate (was 220 Hz before)
// 23.03.2014:  Fixed a problem with the USB interrupt and atomic access, not allowing the tracker to change sensor scale
//				Changed sensor scaling to floating point numbers and scaled to values as expected from the SDK
// 29.03.2014:  Added gyroscope "set to zero" calibration routine (Press the user button on the STM board and keep it very still)
//				Added temperature readout from gyro
//				Added some nice LED animations for IDLE mode, Tracker running mode and Calibration mode
// 01.04.2014:	Gyro offset calibration is now saved to Flash at address 0x08006000 and hence retained after power off
// 08.05.2014:	Fixed bug in readSensorAcc(): an array was accessed outside its boundaries.
//				also included the .hex file and switched on compiler optimizations
// 11.05.2014:	Experimental: Setting of board orientation ...
//				Push the user button for > 1 s to choose between 8 preconfigured orientation settings
//				Push the user button again for > 1 s to save the setting to FLASH memory

#pragma pack(1)		//If this is not defined, GCC Will use padding bytes and mess up the union structs

/* Includes ------------------------------------------------------------------*/
#include "string.h"
#include "main.h"
#include "stm32f30x.h"
#include "stm32f3_discovery.h"
#include "globalVariables.h"
#include "peripherals.h"
#include "bsp.h"
#include <stdio.h>

/* Init global variables -----------------------------------------------------*/
RiftDisplayInfoFrameSep dataDisplayInfo;
RiftKeepAliveFrameSep dataKeepAlive;
RiftConfigFrameSep dataConfig;
RiftScaleFrameSep dataScale;
RiftSensorFrameSep dataToBeSent;
__IO uint8_t EP1flagTXcomplete = 1;
__IO uint8_t EP1flagRXcomplete = 0;
uint8_t orientationIndex=0;						//Holds the current orientation setting of the coordinate system (0-7)
												//This variable is saved to flash and restored on power up
												//Setup the corresponding orientations in packFoculusdataBlock()

/* Private variables ---------------------------------------------------------*/
RCC_ClocksTypeDef RCC_Clocks;
// Timer compare values are buffered locally and updated in the configFrame received event
uint32_t currentKeepAliveTimeout = 10000;		//[ms]
uint16_t currentDelayBetweenPackets = 100;		//[ms]
uint8_t  EP1debugBuffer[128];					//Not really used at the moment
int32_t gyroBuffer[3];							//[X,Y,Z] Will hold the scaled and ready to send sensor data
int32_t accBuffer[3];							//[X,Y,Z]
int16_t magBuffer[3];							//[X,Z,Y]
int16_t tempBuffer;								//Holds temperature as read from Magnetometer

/* Private function prototypes -----------------------------------------------*/
void initDefaultRiftSettings(void);
void packFoculusdataBlock(void);
void packSensorDataBlock(int32_t Xin, int32_t Yin, int32_t Zin, uint8_t *sensorDataOut);
void handleConfigPacketEvent(void);

enum FoculusStates {
    FocSt_Init,			// Pause sending data (keep alive timeout for example)
    FocSt_SendData		// Send data
};
uint8_t focState = FocSt_Init;


//Implement the user interface in one big ugly blocking function.
//I'm fully aware that this does stall the USB communications, which might cause trouble!
void handleButton(){
	uint8_t i;
	LED_out_byte( 0x00 );						//See how long ...
	i = getShortLongButtonPress();
	if( i==1 ){									//Short button press
		for (i=0; i<=5; i++){					//Blink LEDs 5 times to indicate gyro bias calibration
			delayms( 100 );
			LED_out_byte( 0xFF );
			delayms( 100 );
			LED_out_byte( 0x00 );
		}
		doGyroBiasCalibration();				//Start calibration measurement
	} else if( i==2 ){							//Long button press, do selection of orientation
		STM_EVAL_LEDOn( (Led_TypeDef)orientationIndex );
		while( STM_EVAL_PBGetState( BUTTON_USER ) ); //Wait for button release
		while( 1 ){
			STM_EVAL_LEDOn( (Led_TypeDef)orientationIndex );	//Indicate current orientation index
			i = getShortLongButtonPress();
			if( i==1 ){							//If short press, increment orientation index
				orientationIndex++;
				if( orientationIndex >= 8 ){
					orientationIndex = 0;
				}
				LED_out_byte( 0x00 );
			} else if ( i==2 ){					//If long press, save and exit orientation mode
				saveCalibrationToFlash();		//Experimental and potentially dangerous: save calibration values and orientation to FLASH memory
				for (i=0; i<=5; i++){			//Blink LEDs 5 times to indicate save
					delayms( 100 );
					STM_EVAL_LEDOn( (Led_TypeDef)orientationIndex );
					delayms( 100 );
					LED_out_byte( 0x00 );
				}
				break;
			}
		}
	}
}

/**
 * @brief  Main program.
 * @param  None
 * @retval None
 */
u32 buf[10]={0};




int main(void) {
	int i;

	/* Setup SysTick event each 1 ms */
	RCC_GetClocksFreq( &RCC_Clocks );
	SysTick_Config( RCC_Clocks.HCLK_Frequency / 1000 );	  //Every 1 ms

	LED_Config();

	BSP_Usart1Init();
	
	EEPROM_Init();
	
	//EEPROM_WriteData(0x4,buf2,2);
	printf("start write to tc\n");

	Tc358Write();




	printf("write to tc complete\n");
	for(;;)
	{

		EEPROM_ReadData(0x0,buf,40);
		for(i=0; i<10; i++)
		{
			printf("Addr[0x%2x]:0x%8x\n",0x0+i*4,buf[i]);			
		}
		while(1);


	}

	
	/* Configure the USB (will get stuck here until USB is plugged in)*/
	USB_Config();

	/* Init peripherals */
	
	initDefaultRiftSettings();
	initSensorGyro( dataScale.rFrame.gScale );
	initSensorAccMag( dataScale.rFrame.aScale, dataScale.rFrame.mScale );	// Init combined accelerometer and magnetometer chip

	/* Infinite loop */
	while (1) {
//---------------------------------------------------------------------------------------------------------
//		Is the reception of a new packet on Endpoint 1 (EP1) finished? This is not used at the moment.
//---------------------------------------------------------------------------------------------------------
		if ( EP1flagRXcomplete ) {
			USB_SIL_Read( EP1_OUT, EP1debugBuffer );
			SetEPRxValid( ENDP1 );
			EP1flagRXcomplete = 0;
//			uint8_t command = EP1debugBuffer[0];
		}
//----------------------------------------------------------------------------------------------------
//		Check if some settings have been updated by the USB interrupt and fire an event to handle the setting change
//----------------------------------------------------------------------------------------------------
		if ( newConfigFrameReceived >= 0 ){
			if ( newConfigFrameReceived == featureReportData[0] ){	//Rudimentary check if featureReportData contains valid data (it does not always and I don't understand why)
				handleConfigPacketEvent();
			} else {
				newConfigFrameReceived = -1;						//Sometimes a glitch happens and no new data is written to featureReportData
			}
		}
//----------------------------------------------------------------------------------------------------
//		Check if user pushed the button to change the settings
//----------------------------------------------------------------------------------------------------
		if ( STM_EVAL_PBGetState( BUTTON_USER ) ){	//Check if button is pressed
			handleButton();							//ToDo: !!! Danger !!! This is blocking and will stall USB communications!
		}
//----------------------------------------------------------------------------------------------------
//		Handle sensor data statemachine
//----------------------------------------------------------------------------------------------------
		switch ( focState ){
		case FocSt_Init:									// Do not send sensor data while in init state, wait for keepALive packet
			LED_ani_idle();
			break;
		case FocSt_SendData:
			LED_ani_run();
			if ( isGyroNewData() ){
				tempBuffer = readSensorGyro( gyroBuffer );	//takes 0.05 ms, wow, SPI, such fast!
			}
			if ( isAccNewData() ){
				readSensorAcc( accBuffer );					//takes 0.23 ms
			}
			if ( isMagNewData() ){
				readSensorMag( magBuffer );					//takes 0.37 ms
			}
			// Check if a new packet shall be sent over USB
			// Do this only if: _last transmission finished_  and if _enough time passed_
			if ( EP1flagTXcomplete && (timerTimeSinceLastFrameSent >= currentDelayBetweenPackets) ) {
				EP1flagTXcomplete = 0;			//Yep, start new USB transmission ...
				timerTimeSinceLastFrameSent = 0;
				packFoculusdataBlock();			//Format the data from sensors as a SensorFrame
				USB_SIL_Write( EP1_IN, dataToBeSent.rawUSBdata, 62 );	//Hand data over to the USB driver
				SetEPTxValid( ENDP1 );
			}
			//  * SKD sends keep alive packets every 3 seconds or so, they contain keepALiveIntervalMs
			//	  this is a (10 s) timeout, if this time has passed and no keep alive packet received, then
			//    stop sending sensor data.
			// Check if a keepAlive timout occurred
			if ( timerTimeSinceLastKeepAlive > currentKeepAliveTimeout ){
				focState = FocSt_Init;			//Timeout occurred, back to init state
			}
			break;
		}
	}
}

// Copy data form the memory buffer used by the USB interrupt
// to the structs used by the main routine, which are useful for decoding purposes
// It is a bit tricky to access data from an interrupt routine, as it can change anytime!
void memcpy_atomic(uint8_t *to, __IO uint8_t *from, size_t size){
	size_t counter;
	for (counter=0; counter<size; counter++){
		*to = *from;
		to++;
		from++;
	}
//	memcpy(to, from, size);		//Not sure if the above (using volatile) is any better (or even worse) than this
}

void handleConfigPacketEvent(){
// This is called, after a new ConfigPacket has been received from the libOVR.
// At this point, the new configuration data needs to be copied in the relevant struct
// Then we react accordingly to the updated configuration
	uint16_t command;
	switch ( newConfigFrameReceived ){
	case Packet_KeepAlive:		//		Reset keepAlive Counter, set state to Run
		memcpy_atomic( dataKeepAlive.rawUSBdata, featureReportData, 5 );
		newConfigFrameReceived = -1;
		if ( dataKeepAlive.rFrame.keepAliveIntervalMs > 100 ){
			currentKeepAliveTimeout = dataKeepAlive.rFrame.keepAliveIntervalMs;
		}
		if ( focState==FocSt_Init ){
			focState = FocSt_SendData;
		}
		command = dataKeepAlive.rFrame.commandID;
		break;
	case Packet_Config:			//		Reset packet interval, keep ALive Interval and handle Flags
		memcpy_atomic( dataConfig.rawUSBdata, featureReportData, 7 );
		newConfigFrameReceived = -1;
		currentDelayBetweenPackets = dataConfig.rFrame.packetInterval;
		if ( dataConfig.rFrame.keepAliveIntervalMs > 100 ){
			currentKeepAliveTimeout = dataConfig.rFrame.keepAliveIntervalMs;
		}
		command = dataConfig.rFrame.commandID;
		break;
	case Packet_DisplayInfo:	//		Note, that at the moment this allows write access to the DisplayInfo data
		memcpy_atomic( dataDisplayInfo.rawUSBdata, featureReportData, 56 );
		newConfigFrameReceived = -1;
		command = dataDisplayInfo.rFrame.commandID;
		break;
	case Packet_Scale:			//		Reset Sensor chips and scaling factors to new scale
		memcpy_atomic( dataScale.rawUSBdata, featureReportData, 8 );
		newConfigFrameReceived = -1;
		initSensorGyro( dataScale.rFrame.gScale );
		initSensorAccMag( dataScale.rFrame.aScale, dataScale.rFrame.mScale );
		command = dataScale.rFrame.commandID;
		break;
	default:
		newConfigFrameReceived = -1;
	}
	timerTimeSinceLastKeepAlive = 0;
}

/**
 * @brief  Configure the USB.
 */
void USB_Config(void) {
	Set_System();
	Set_USBClock();
	USB_Interrupts_Config();
	USB_Init();
	while (bDeviceState != CONFIGURED) {
	}
}

//The SDK will request some configuration data from the tracker, here I set the default setting
//I tried to find sensible default settings, but especially for the displayInfo struct I'm not so sure if they are OK.
void initDefaultRiftSettings() {
	dataConfig.rFrame.commandID = 0;
	dataConfig.rFrame.flags = Flag_RawMode | Flag_SensorCoordinates;
	dataConfig.rFrame.keepAliveIntervalMs = currentKeepAliveTimeout;
	dataConfig.rFrame.packetInterval = currentDelayBetweenPackets;
	dataConfig.rFrame.two = 0x02;

	dataScale.rFrame.commandID = 0;
	dataScale.rFrame.aScale = 8;
	dataScale.rFrame.gScale = 1000;
	dataScale.rFrame.mScale = 2500;
	dataScale.rFrame.four = 0x04;

	dataKeepAlive.rFrame.commandID = 0;
	dataKeepAlive.rFrame.keepAliveIntervalMs = currentKeepAliveTimeout;
	dataKeepAlive.rFrame.eight = 0x08;

	dataDisplayInfo.rFrame.commandID = 0;
	dataDisplayInfo.rFrame.distortionType =  0x00;		//ToDo: Distortion Type Flags, What is possible here?
	dataDisplayInfo.rFrame.HResolution = 	 1280;
	dataDisplayInfo.rFrame.VResolution = 	  800;
	dataDisplayInfo.rFrame.HScreenSize =   149760;		//[um] ?
	dataDisplayInfo.rFrame.VScreenSize =  	93600;		//[um] ?
	dataDisplayInfo.rFrame.VCenter = 		46900;		//[um] ?
	dataDisplayInfo.rFrame.LensSeparation = 64000;		//[um] ?
	dataDisplayInfo.rFrame.eye2ScreenDistanceL = 41000; //[um] ?
	dataDisplayInfo.rFrame.eye2ScreenDistanceR = 41000; //[um] ?
	dataDisplayInfo.rFrame.k0 = 1.00;
	dataDisplayInfo.rFrame.k1 = 0.22;
	dataDisplayInfo.rFrame.k2 = 0.24;
	dataDisplayInfo.rFrame.k3 = 0.00;
	dataDisplayInfo.rFrame.k4 = 0.00;
	dataDisplayInfo.rFrame.k5 = 0.00;
	dataDisplayInfo.rFrame.nine = 0x09;

	dataToBeSent.rFrame.messageType = TrackerMessage_Sensors;	//This means we send sensor data
	dataToBeSent.rFrame.sampleCount = 0;
	dataToBeSent.rFrame.timeStamp = 0;
	dataToBeSent.rFrame.commandID = 0;
	dataToBeSent.rFrame.temp = 4711;
	dataToBeSent.rFrame.mX = 4;
	dataToBeSent.rFrame.mY = 5;
	dataToBeSent.rFrame.mZ = 6;

	restoreCalibrationFromFlash();						//Restore gyro offset calibration factors once at startup from flash
}

//**********************************************************************************
//* Functions for fetching data from the Sensors and formating them in RIFT format *
//**********************************************************************************
void packSensorDataBlock( int32_t Xin, int32_t Yin, int32_t Zin, uint8_t *sensorDataOut ) {
/*
 * Within the readSensor() functions:
 *  the 16 bit int sensor values from the Gyro and Acc are scaled to physical units and cast to int32_t
 * Here:
 *  The first 21 LSB bits are used in this routine and reformated to fit in the dataBlock as expected by the Oculus SDK
 *  21 bit effective input range:     -1 048 576 (0x100000)   ...    -1 (0x1FFFFF)   ...    +1 048 575  (0x0FFFFF)
 */
	//Arrange the bits in the right order within the buffer
	sensorDataOut[0] = (Xin >> 13) & 0xFF;							//Xin[13:20]  (bit index 13 - 20 of Xin)
	sensorDataOut[1] = (Xin >>  5) & 0xFF;							//Xin[5:12]
	sensorDataOut[2] = ((Xin & 0x1F) << 3) | ((Yin >> 18) & 0x07);	//Xin[0:4],Yin[18:20] (MSB, part of Xin, part of Yin, LSB)

	sensorDataOut[3] = (Yin >> 10) & 0xFF;							//Yin[10:17]
	sensorDataOut[4] = (Yin >>  2) & 0xFF;							//Yin[2:9]
	sensorDataOut[5] = ((Yin & 0x03) << 6) | ((Zin >> 15) & 0x3F);	//Yin[0:1],Zin[15:20]

	sensorDataOut[6] = (Zin >>  7) & 0xFF;							//Zin[7:14]
	sensorDataOut[7] = (Zin <<  1) & 0xFE;							//Zin[0:6],0
}

void packFoculusdataBlock() {
//	Here we do the transformation from the two different sensor coordinate systems
//	to the libOVR coordinate system. We also allow 8 different mounting orientations
//	of the STM discovery board.
//  If the coordinate axes seem not right, here is the place to change it
	static uint16_t timeStamp = 0;
	dataToBeSent.rFrame.temp = tempBuffer;																		//Temperature
	dataToBeSent.rFrame.commandID = 0;
	dataToBeSent.rFrame.sampleCount = 1;
	dataToBeSent.rFrame.timeStamp = timeStamp++;
	switch( orientationIndex ){		//This allows the sensor board to be mounted in 8 different orientations (configurable by the Userbutton)
	default:
	case 0:	// These settings seem to fit for mounting the discovery board on the back of the HMD,
			// so that the LEDs point toward the face and the USB connectors point downwards
			// See also: riftCoord.png
		dataToBeSent.rFrame.mX = -magBuffer[ cmY ];
		dataToBeSent.rFrame.mY =  magBuffer[ cmX ];
		dataToBeSent.rFrame.mZ =  magBuffer[ cmZ ];
		packSensorDataBlock(  -accBuffer[ caY ],  accBuffer[ caX ],  accBuffer[ caZ ], dataToBeSent.rFrame.sensorData1 );		//Conv. Acc. data to Oculus format
		packSensorDataBlock(  -gyroBuffer[ cgX ], -gyroBuffer[ cgY ], gyroBuffer[ cgZ ], dataToBeSent.rFrame.sensorData1+8 );	//Conv. Gyro. data to Oculus format
		break;
	case 1:
		dataToBeSent.rFrame.mX = -magBuffer[ cmX ];
		dataToBeSent.rFrame.mY =  magBuffer[ cmY ];
		dataToBeSent.rFrame.mZ = -magBuffer[ cmZ ];
		packSensorDataBlock(  -accBuffer[ caX ],  accBuffer[ caY ],  -accBuffer[ caZ ], dataToBeSent.rFrame.sensorData1 );		//Conv. Acc. data to Oculus format
		packSensorDataBlock(  gyroBuffer[ cgY ], gyroBuffer[ cgX ], -gyroBuffer[ cgZ ], dataToBeSent.rFrame.sensorData1+8 );	//Conv. Gyro. data to Oculus format
		break;
	case 2:
		dataToBeSent.rFrame.mX =  magBuffer[ cmY ];
		dataToBeSent.rFrame.mY =  magBuffer[ cmX ];
		dataToBeSent.rFrame.mZ = -magBuffer[ cmZ ];
		packSensorDataBlock(  accBuffer[ caY ],  accBuffer[ caX ],  -accBuffer[ caZ ], dataToBeSent.rFrame.sensorData1 );		//Conv. Acc. data to Oculus format
		packSensorDataBlock(  gyroBuffer[ cgX ], -gyroBuffer[ cgY ], -gyroBuffer[ cgZ ], dataToBeSent.rFrame.sensorData1+8 );	//Conv. Gyro. data to Oculus format
		break;
	case 3:
		dataToBeSent.rFrame.mX = -magBuffer[ cmY ];
		dataToBeSent.rFrame.mY = -magBuffer[ cmX ];
		dataToBeSent.rFrame.mZ = -magBuffer[ cmZ ];
		packSensorDataBlock(  -accBuffer[ caY ],  -accBuffer[ caX ],  -accBuffer[ caZ ], dataToBeSent.rFrame.sensorData1 );		//Conv. Acc. data to Oculus format
		packSensorDataBlock(  -gyroBuffer[ cgX ], gyroBuffer[ cgY ], -gyroBuffer[ cgZ ], dataToBeSent.rFrame.sensorData1+8 );	//Conv. Gyro. data to Oculus format
		break;
	case 4:
		dataToBeSent.rFrame.mX = -magBuffer[ cmY ];
		dataToBeSent.rFrame.mY =  magBuffer[ cmZ ];
		dataToBeSent.rFrame.mZ = -magBuffer[ cmX ];
		packSensorDataBlock(  -accBuffer[ caY ],  accBuffer[ caZ ],  -accBuffer[ caX ], dataToBeSent.rFrame.sensorData1 );		//Conv. Acc. data to Oculus format
		packSensorDataBlock(  -gyroBuffer[ cgX ], gyroBuffer[ cgZ ], gyroBuffer[ cgY ], dataToBeSent.rFrame.sensorData1+8 );	//Conv. Gyro. data to Oculus format
		break;
	case 5:
		dataToBeSent.rFrame.mX = magBuffer[ cmY ];
		dataToBeSent.rFrame.mY = magBuffer[ cmZ ];
		dataToBeSent.rFrame.mZ = magBuffer[ cmX ];
		packSensorDataBlock(  accBuffer[ caY ],  accBuffer[ caZ ],  accBuffer[ caX ], dataToBeSent.rFrame.sensorData1 );		//Conv. Acc. data to Oculus format
		packSensorDataBlock(  gyroBuffer[ cgX ], gyroBuffer[ cgZ ], -gyroBuffer[ cgY ], dataToBeSent.rFrame.sensorData1+8 );	//Conv. Gyro. data to Oculus format
		break;
	case 6:
		dataToBeSent.rFrame.mX = -magBuffer[ cmX ];
		dataToBeSent.rFrame.mY =  magBuffer[ cmZ ];
		dataToBeSent.rFrame.mZ =  magBuffer[ cmY ];
		packSensorDataBlock(  -accBuffer[ caX ],  accBuffer[ caZ ],  accBuffer[ caY ], dataToBeSent.rFrame.sensorData1 );		//Conv. Acc. data to Oculus format
		packSensorDataBlock(  gyroBuffer[ cgY ], gyroBuffer[ cgZ ], gyroBuffer[ cgX ], dataToBeSent.rFrame.sensorData1+8 );	//Conv. Gyro. data to Oculus format
		break;
	case 7:
		dataToBeSent.rFrame.mX =  magBuffer[ cmX ];
		dataToBeSent.rFrame.mY =  magBuffer[ cmZ ];
		dataToBeSent.rFrame.mZ = -magBuffer[ cmY ];
		packSensorDataBlock(  accBuffer[ caX ],  accBuffer[ caZ ],  -accBuffer[ caY ], dataToBeSent.rFrame.sensorData1 );		//Conv. Acc. data to Oculus format
		packSensorDataBlock(  -gyroBuffer[ cgY ], gyroBuffer[ cgZ ], -gyroBuffer[ cgX ], dataToBeSent.rFrame.sensorData1+8 );	//Conv. Gyro. data to Oculus format
		break;
	}
}

/**
 * @brief  Basic management of the timeout situation.
 * @param  None.
 * @retval None.
 */

#ifdef  USE_FULL_ASSERT

/**
 * @brief  Reports the name of the source file and the source line number
 *         where the assert_param error has occurred.
 * @param  file: pointer to the source file name
 * @param  line: assert_param error line source number
 * @retval None
 */
void assert_failed(uint8_t* file, uint32_t line)
{
	/* User can add his own implementation to report the file name and line number,
	 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

	/* Infinite loop */
	while (1)
	{
	}
}
#endif

/**
 * @}
 */

/**
 * @}
 */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/