ISSDK  1.7
IoT Sensing Software Development Kit
hal_frdm_fxs_mult2_b.c
Go to the documentation of this file.
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
4  * Copyright 2016-2017 NXP
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without modification,
8  * are permitted (subject to the limitations in the disclaimer below) provided
9  * that the following conditions are met:
10  *
11  * o Redistributions of source code must retain the above copyright notice, this list
12  * of conditions and the following disclaimer.
13  *
14  * o Redistributions in binary form must reproduce the above copyright notice, this
15  * list of conditions and the following disclaimer in the documentation and/or
16  * other materials provided with the distribution.
17  *
18  * o Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from this
20  * software without specific prior written permission.
21  *
22  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
27  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
30  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 /*! \file hal_frdm_fxs_mult2_b.c
36  \brief Hardware Abstraction layer for the FRDM-FXS-MULT2-B sensor shield.
37 */
38 
39 #include "sensor_fusion.h" // top level magCal and sensor fusion interfaces
40 
41 // This HAL (Hardware Abstraction Layer) is applicable to:
42 // FRDM_K64F +
43 // FRDM_FXS_MULT2_B utilizing the FX0S8700 and FXAS21002 on the shield
44 // It also works for the FRDM-STBC_AGM01 board.
45 // It also works for the FRDM-STBC_AGM02 board (the driver_MAG3110.c inverts
46 // the MAG3110 Z-axis reading to enforce +Z = up, so compatibility is maintained)
47 
48 void ApplyAccelHAL(struct AccelSensor *Accel)
49 {
50  int8 i; // loop counter
51 
52  // apply HAL to all measurements read from FIFO buffer
53  for (i = 0; i < Accel->iFIFOCount; i++)
54  {
55  // apply HAL mapping to coordinate system used
56 #if THISCOORDSYSTEM == NED
57  int16 itmp16 = Accel->iGsFIFO[i][CHX];
58  Accel->iGsFIFO[i][CHX] = Accel->iGsFIFO[i][CHY];
59  Accel->iGsFIFO[i][CHY] = itmp16;
60 #endif // NED
61 #if THISCOORDSYSTEM == ANDROID
62  Accel->iGsFIFO[i][CHX] = -Accel->iGsFIFO[i][CHX];
63  Accel->iGsFIFO[i][CHY] = -Accel->iGsFIFO[i][CHY];
64 #endif // Android
65 #if (THISCOORDSYSTEM == WIN8)
66  Accel->iGsFIFO[i][CHZ] = -Accel->iGsFIFO[i][CHZ];
67 #endif // Win8
68 
69  } // end of loop over FIFO count
70 
71  return;
72 }
73 
74 // function applies the hardware abstraction layer to the magnetometer readings
75 void ApplyMagHAL(struct MagSensor *Mag)
76 {
77  int8 i; // loop counter
78 
79  // apply HAL to all measurements read from FIFO buffer
80  for (i = 0; i < Mag->iFIFOCount; i++)
81  {
82  // apply HAL mapping to coordinate system used
83 #if THISCOORDSYSTEM == NED
84  int16 itmp16 = Mag->iBsFIFO[i][CHX];
85  Mag->iBsFIFO[i][CHX] = -Mag->iBsFIFO[i][CHY];
86  Mag->iBsFIFO[i][CHY] = -itmp16;
87  Mag->iBsFIFO[i][CHZ] = -Mag->iBsFIFO[i][CHZ];
88 #endif // NED
89 #if THISCOORDSYSTEM == ANDROID
90  Mag->iBsFIFO[i][CHX] = -Mag->iBsFIFO[i][CHX];
91  Mag->iBsFIFO[i][CHY] = -Mag->iBsFIFO[i][CHY];
92 #endif // Android
93 #if THISCOORDSYSTEM == WIN8
94  Mag->iBsFIFO[i][CHX] = -Mag->iBsFIFO[i][CHX];
95  Mag->iBsFIFO[i][CHY] = -Mag->iBsFIFO[i][CHY];
96 #endif
97  } // end of loop over FIFO count
98 
99  return;
100 }
101 
102 // function applies the hardware abstraction layer to the gyro readings
103 void ApplyGyroHAL(struct GyroSensor *Gyro)
104 {
105  int8 i; // loop counter
106 
107  // apply HAL to all measurements read from FIFO buffer
108  for (i = 0; i < Gyro->iFIFOCount; i++)
109  {
110  // apply HAL mapping to coordinate system used
111 #if THISCOORDSYSTEM == NED
112  int16 itmp16 = Gyro->iYsFIFO[i][CHX];
113  Gyro->iYsFIFO[i][CHX] = -Gyro->iYsFIFO[i][CHY];
114  Gyro->iYsFIFO[i][CHY] = -itmp16;
115  Gyro->iYsFIFO[i][CHZ] = -Gyro->iYsFIFO[i][CHZ];
116 #endif // NED
117 #if THISCOORDSYSTEM == ANDROID
118  Gyro->iYsFIFO[i][CHX] = -Gyro->iYsFIFO[i][CHX];
119  Gyro->iYsFIFO[i][CHY] = -Gyro->iYsFIFO[i][CHY];
120 #endif // Android
121 #if THISCOORDSYSTEM == WIN8
122  Gyro->iYsFIFO[i][CHX] = -Gyro->iYsFIFO[i][CHX];
123  Gyro->iYsFIFO[i][CHY] = -Gyro->iYsFIFO[i][CHY];
124 #endif // Win8
125 
126  } // end of loop over FIFO count
127 
128  return;
129 }
130 
#define CHY
Used to access Y-channel entries in various data data structures.
Definition: sensor_fusion.h:87
void ApplyGyroHAL(struct GyroSensor *Gyro)
Apply the gyroscope Hardware Abstraction Layer.
int16_t iYsFIFO[GYRO_FIFO_SIZE][3]
FIFO measurements (counts)
The AccelSensor structure stores raw and processed measurements for a 3-axis accelerometer.
The MagSensor structure stores raw and processed measurements for a 3-axis magnetic sensor...
int16_t iBsFIFO[MAG_FIFO_SIZE][3]
FIFO measurements (counts)
uint8_t iFIFOCount
number of measurements read from FIFO
The sensor_fusion.h file implements the top level programming interface.
#define CHZ
Used to access Z-channel entries in various data data structures.
Definition: sensor_fusion.h:88
int16_t iGsFIFO[ACCEL_FIFO_SIZE][3]
FIFO measurements (counts)
uint8_t iFIFOCount
number of measurements read from FIFO
#define CHX
Used to access X-channel entries in various data data structures.
Definition: sensor_fusion.h:86
void ApplyMagHAL(struct MagSensor *Mag)
Apply the magnetometer Hardware Abstraction Layer.
void ApplyAccelHAL(struct AccelSensor *Accel)
Apply the accelerometer Hardware Abstraction Layer.
int16_t int16
Definition: sensor_fusion.h:66
int8_t int8
Definition: sensor_fusion.h:65
uint8_t iFIFOCount
number of measurements read from FIFO
The GyroSensor structure stores raw and processed measurements for a 3-axis gyroscope.