107#if (ACCEL_ODR_HZ <= 1)
109#elif (ACCEL_ODR_HZ <= 3)
111#elif (ACCEL_ODR_HZ <= 6)
113#elif (ACCEL_ODR_HZ <= 30)
115#elif (ACCEL_ODR_HZ <= 50)
117#elif (ACCEL_ODR_HZ <= 100)
119#elif (ACCEL_ODR_HZ <= 200)
127#define FXOS8700_COUNTSPERG 8192
128#define FXOS8700_COUNTSPERUT 10
138 return FXOS8700_Init(sensor, sfg);
144 return FXOS8700_Init(sensor, sfg);
150 return FXOS8700_Init(sensor, sfg);
159 if (status==SENSOR_ERROR_NONE) {
161 sfg->Accel.iWhoAmI = reg;
162 sfg->Accel.iCountsPerg = FXOS8700_COUNTSPERG;
163 sfg->Accel.fgPerCount = 1.0F / FXOS8700_COUNTSPERG;
171 if (reg != FXOS8700_WHO_AM_I_PROD_VALUE) {
172 return SENSOR_ERROR_INIT;
185 sfg->Accel.isEnabled =
true;
199 uint8_t fifo_packet_count;
203 return SENSOR_ERROR_INIT;
209 sensor->
addr, FXOS8700_F_STATUS_READ, I2C_Buffer);
210 if (status == SENSOR_ERROR_NONE) {
212 fifo_packet_count = 1;
214 fifo_packet_count = I2C_Buffer[0] & FXOS8700_F_STATUS_F_CNT_MASK;
219 if (fifo_packet_count == 0) {
220 return (SENSOR_ERROR_READ);
231#define MAX_FIFO_PACKETS_PER_READ 15
233 while ((fifo_packet_count > 0) && (status == SENSOR_ERROR_NONE)) {
234 if (MAX_FIFO_PACKETS_PER_READ < fifo_packet_count) {
235 FXOS8700_DATA_READ[0].numBytes = 6 * MAX_FIFO_PACKETS_PER_READ;
236 fifo_packet_count -= MAX_FIFO_PACKETS_PER_READ;
238 FXOS8700_DATA_READ[0].numBytes = 6 * fifo_packet_count;
239 fifo_packet_count = 0;
242 sensor->
addr, FXOS8700_DATA_READ, I2C_Buffer);
243 if (status == SENSOR_ERROR_NONE) {
244 for (j = 0; j < FXOS8700_DATA_READ[0].numBytes; j+=6) {
246 sample[
CHX] = (I2C_Buffer[j + 0] << 8) | (I2C_Buffer[j + 1]);
247 sample[
CHY] = (I2C_Buffer[j + 2] << 8) | (I2C_Buffer[j + 3]);
248 sample[
CHZ] = (I2C_Buffer[j + 4] << 8) | (I2C_Buffer[j + 5]);
262 uint8_t I2C_Buffer[6];
268 return SENSOR_ERROR_INIT;
273 FXOS8700_DATA_READ[0].numBytes = 6;
275 if (status==SENSOR_ERROR_NONE) {
277 sample[
CHX] = (I2C_Buffer[0] << 8) | I2C_Buffer[1];
278 sample[
CHY] = (I2C_Buffer[2] << 8) | I2C_Buffer[3];
279 sample[
CHZ] = (I2C_Buffer[4] << 8) | I2C_Buffer[5];
293 return SENSOR_ERROR_INIT;
298 FXOS8700_DATA_READ[0].numBytes = 1;
300 if (status==SENSOR_ERROR_NONE) {
302 sfg->Temp.temperatureC = (float)I2C_Buffer * 0.96;
314 sts1 = FXOS8700_Accel_Read(sensor, sfg);
318 sts2 = FXOS8700_Mag_Read(sensor, sfg);
319 sts3 = FXOS8700_Therm_Read(sensor, sfg);
322 return (sts1 + sts2 + sts3);
344 sfg->Accel.isEnabled =
false;
350 return SENSOR_ERROR_INIT;
#define ACCEL_FIFO_SIZE
FXOS8700 (accel), MMA8652, FXLS8952 all have 32 element FIFO.
#define MAG_FIFO_SIZE
FXOS8700 (mag) and MAG3110 have no FIFO so equivalent to 1 element FIFO. For.
#define F_USING_MAG
nominally 0x0002 if an magnetometer is to be used, 0x0000 otherwise
#define F_USING_ACCEL
nominally 0x0001 if an accelerometer is to be used, 0x0000 otherwise
Describes the fxos8700 driver interface and structures.
Contains the register definitions for FXOS8700.
Provides function prototypes for driver level interfaces It does not have a corresponding ....
int8_t Sensor_I2C_Write_List(registerDeviceInfo_t *devInfo, uint16_t peripheralAddress, const registerwritelist_t *pRegWriteList)
Write register data to a sensor.
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.
float fCountsPeruT
counts per uT
float fuTPerCount
uT per count
uint8_t iWhoAmI
sensor whoami
bool isEnabled
true if the device is sampling
int16_t iCountsPeruT
counts per uT
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.
struct MagSensor Mag
magnetometer storage
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...