18#define FXAS21000_STATUS 0x00
19#define FXAS21000_F_STATUS 0x08
20#define FXAS21000_F_SETUP 0x09
21#define FXAS21000_WHO_AM_I 0x0C
22#define FXAS21000_CTRL_REG0 0x0D
23#define FXAS21000_CTRL_REG1 0x13
24#define FXAS21000_CTRL_REG2 0x14
25#define FXAS21000_WHO_AM_I_VALUE 0xD1
26#define FXAS21000_COUNTSPERDEGPERSEC 20
27#define FXAS21002_COUNTSPERDEGPERSEC 16
34 { .readFrom = FXAS21002_WHO_AM_I, .numBytes = 1 }, __END_READ_DATA__
40 { .readFrom = FXAS21002_STATUS, .numBytes = 1 }, __END_READ_DATA__
46 { .readFrom = FXAS21002_OUT_X_MSB, .numBytes = 6 }, __END_READ_DATA__
59 { FXAS21000_CTRL_REG1, 0x00, 0x00 },
63 { FXAS21000_F_SETUP, 0x40, 0x00 },
71 { FXAS21000_CTRL_REG0, 0x00, 0x00 },
88 { FXAS21000_CTRL_REG1, 0x1E, 0x00 },
89#elif (GYRO_ODR_HZ <= 3)
90 { FXAS21000_CTRL_REG1, 0x1A, 0x00 },
91#elif (GYRO_ODR_HZ <= 6)
92 { FXAS21000_CTRL_REG1, 0x16, 0x00 },
93#elif (GYRO_ODR_HZ <= 12)
94 { FXAS21000_CTRL_REG1, 0x12, 0x00 },
95#elif (GYRO_ODR_HZ <= 25)
96 { FXAS21000_CTRL_REG1, 0x0E, 0x00 },
97#elif (GYRO_ODR_HZ <= 50)
98 { FXAS21000_CTRL_REG1, 0x0A, 0x00 },
99#elif (GYRO_ODR_HZ <= 100)
100 { FXAS21000_CTRL_REG1, 0x06, 0x00 },
102 { FXAS21000_CTRL_REG1, 0x02, 0x00 },
117 { FXAS21002_CTRL_REG1, 0x00, 0x00 },
121 { FXAS21002_F_SETUP, 0x40, 0x00 },
129 { FXAS21002_CTRL_REG0, 0x00, 0x00 },
137 { FXAS21002_CTRL_REG3, 0x08, 0x00 },
154#if (GYRO_ODR_HZ <= 12)
155 { FXAS21002_CTRL_REG1, 0x1A, 0x00 },
156#elif (GYRO_ODR_HZ <= 25)
157 { FXAS21002_CTRL_REG1, 0x16, 0x00 },
158#elif (GYRO_ODR_HZ <= 50)
159 { FXAS21002_CTRL_REG1, 0x12, 0x00 },
160#elif (GYRO_ODR_HZ <= 100)
161 { FXAS21002_CTRL_REG1, 0x0E, 0x00 },
162#elif (GYRO_ODR_HZ <= 200)
163 { FXAS21002_CTRL_REG1, 0x0A, 0x00 },
164#elif (GYRO_ODR_HZ <= 400)
165 { FXAS21002_CTRL_REG1, 0x06, 0x00 },
167 { FXAS21002_CTRL_REG1, 0x02, 0x00 },
179 int8_t status = SENSOR_ERROR_NONE;
182 sfg->Gyro.iWhoAmI = reg;
184 case FXAS21002_WHO_AM_I_WHOAMI_PROD_VALUE:
185 case FXAS21002_WHO_AM_I_WHOAMI_PRE_VALUE:
186 case FXAS21002_WHO_AM_I_WHOAMI_OLD_VALUE:
190 return SENSOR_ERROR_INIT;
193 return SENSOR_ERROR_INIT;
197 switch (sfg->Gyro.iWhoAmI) {
198 case (FXAS21000_WHO_AM_I_VALUE):
202 sfg->Gyro.iCountsPerDegPerSec = FXAS21000_COUNTSPERDEGPERSEC;
203 sfg->Gyro.fDegPerSecPerCount = 1.0F / FXAS21000_COUNTSPERDEGPERSEC;
205 case (FXAS21002_WHO_AM_I_WHOAMI_PRE_VALUE):
206 case (FXAS21002_WHO_AM_I_WHOAMI_PROD_VALUE):
208 sfg->Gyro.iCountsPerDegPerSec = FXAS21002_COUNTSPERDEGPERSEC;
209 sfg->Gyro.fDegPerSecPerCount = 1.0F / FXAS21002_COUNTSPERDEGPERSEC;
212 sfg->Gyro.iFIFOCount=0;
214 sfg->Gyro.isEnabled =
true;
223 uint8_t fifo_packet_count = 1;
228 return SENSOR_ERROR_INIT;
234 if (status == SENSOR_ERROR_NONE) {
236 fifo_packet_count = 1;
238 fifo_packet_count = I2C_Buffer[0] & FXAS21002_F_STATUS_F_CNT_MASK ;
242 if (fifo_packet_count == 0)
return(SENSOR_ERROR_READ);
249 if (sfg->Gyro.iWhoAmI == FXAS21002_WHO_AM_I_WHOAMI_OLD_VALUE) {
252 FXAS21002_DATA_READ[0].readFrom = FXAS21002_OUT_X_MSB;
253 FXAS21002_DATA_READ[0].numBytes = 6;
256 for (j = 0; j < fifo_packet_count; j++) {
259 sensor->
addr, FXAS21002_DATA_READ,
262 if (status == SENSOR_ERROR_NONE) {
264 sample[
CHX] = (I2C_Buffer[0] << 8) | I2C_Buffer[1];
265 sample[
CHY] = (I2C_Buffer[2] << 8) | I2C_Buffer[3];
266 sample[
CHZ] = (I2C_Buffer[4] << 8) | I2C_Buffer[5];
276#define MAX_FIFO_PACKETS_PER_READ 11
277 FXAS21002_DATA_READ[0].readFrom = FXAS21002_OUT_X_MSB;
278 while( (fifo_packet_count > 0) && (status==SENSOR_ERROR_NONE)) {
279 if( MAX_FIFO_PACKETS_PER_READ < fifo_packet_count ) {
280 FXAS21002_DATA_READ[0].numBytes = MAX_FIFO_PACKETS_PER_READ * 6;
281 fifo_packet_count -= MAX_FIFO_PACKETS_PER_READ;
283 FXAS21002_DATA_READ[0].numBytes = fifo_packet_count * 6;
284 fifo_packet_count = 0;
287 sensor->
addr, FXAS21002_DATA_READ,
289 if (status==SENSOR_ERROR_NONE) {
290 for (j = 0; j < FXAS21002_DATA_READ[0].numBytes; j+=6) {
292 sample[
CHX] = (I2C_Buffer[j + 0] << 8) | I2C_Buffer[j + 1];
293 sample[
CHY] = (I2C_Buffer[j + 2] << 8) | I2C_Buffer[j + 3];
294 sample[
CHZ] = (I2C_Buffer[j + 4] << 8) | I2C_Buffer[j + 5];
309 { FXAS21000_CTRL_REG1, 0x00, 0x00 },
320 sfg->Gyro.isEnabled =
false;
322 return SENSOR_ERROR_INIT;
#define GYRO_FIFO_SIZE
FXAX21000, FXAS21002 have 32 element FIFO.
#define F_USING_GYRO
nominally 0x0004 if a gyro is to be used, 0x0000 otherwise
Contains the fxas21002 sensor register definitions and its bit mask.
int8_t Sensor_I2C_Write_List(registerDeviceInfo_t *devInfo, uint16_t peripheralAddress, const registerwritelist_t *pRegWriteList)
Write register data to a sensor.
bool I2CReadByte(byte address, byte reg, byte *destination)
Read single byte from address and place in destination Returns true if successful,...
int32_t Sensor_I2C_Read(registerDeviceInfo_t *devInfo, uint16_t peripheralAddress, const registerReadlist_t *pReadList, uint8_t *pOutBuffer)
Read register data from a sensor.
The hal_i2c.h file declares low-level interface functions for reading and writing sensor registers us...
void conditionSample(int16_t sample[3])
conditionSample ensures that we never encounter the maximum negative two's complement value for a 16-...
void addToFifo(union FifoSensor *sensor, uint16_t maxFifoSize, int16_t sample[3])
addToFifo is called from within sensor driver read functions
The sensor_fusion.h file implements the top level programming interface.
#define CHX
Used to access X-channel entries in various data data structures.
#define CHY
Used to access Y-channel entries in various data data structures.
#define CHZ
Used to access Z-channel entries in various data data structures.
An instance of PhysicalSensor structure type should be allocated for each physical sensors (combo dev...
registerDeviceInfo_t deviceInfo
I2C device context.
uint16_t addr
I2C address if applicable.
uint16_t isInitialized
Bitfields to indicate sensor is active (use SensorBitFields from build.h)
The top level fusion structure.
This structure defines the Read command List.
This structure defines the Write command List.
The FifoSensor union allows us to use common pointers for Accel, Mag & Gyro logical sensor structures...