ISSDK  1.8
IoT Sensing Software Development Kit
fxas21002_fifo.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 /**
10  * @file fxas21002_fifo.c
11  * @brief The fxas21002_fifo.c file implements the ISSDK FXAS21002 sensor driver
12  * example demonstration with FIFO mode.
13  */
14 
15 /* SDK Includes */
16 #include "pin_mux.h"
17 #include "clock_config.h"
18 #include "board.h"
19 #include "fsl_debug_console.h"
20 
21 /* CMSIS Includes */
22 #include "Driver_I2C.h"
23 
24 /* ISSDK Includes */
25 #include "issdk_hal.h"
26 #include "fxas21002_drv.h"
27 
28 /*******************************************************************************
29  * Macro Definitions
30  ******************************************************************************/
31 /*---------------------------------------------------------------------------*/
32 /*! @def FIFO_SIZE
33  * @brief The watermark value configured for FXAS21002 FIFO Buffer.
34  */
35 #define FIFO_SIZE 4
36 
37 /*******************************************************************************
38  * Constants
39  ******************************************************************************/
40 /*! Prepare the register write list to configure FXAS21002 in FIFO mode. */
42  /*! Configure CTRL_REG1 register to put FXAS21002 to 12.5Hz sampling rate. */
44  /*! Configure F_SETUP register to set FIFO in Stop mode, Watermark of 16. */
49 
50 /*! Prepare the register read list to read FXAS21002 FIFO event. */
52 
53 /*! Prepare the register read list to read the raw gyro data from the FXAS21002. */
56 
57 /*******************************************************************************
58  * Code
59  ******************************************************************************/
60 /*!
61  * @brief Main function
62  */
63 int main(void)
64 {
66  uint8_t fifoEvent;
69 
70  ARM_DRIVER_I2C *I2Cdrv = &I2C_S_DRIVER; // Now using the shield.h value!!!
71  fxas21002_i2c_sensorhandle_t FXAS21002drv;
72 
73  /*! Initialize the MCU hardware. */
77 
78  PRINTF("\r\n ISSDK FXAS21002 sensor driver example demonstration with fifo mode\r\n");
79 
80  /*! Initialize the I2C driver. */
81  status = I2Cdrv->Initialize(I2C_S_SIGNAL_EVENT);
82  if (ARM_DRIVER_OK != status)
83  {
84  PRINTF("\r\n I2C Initialization Failed\r\n");
85  return -1;
86  }
87 
88  /*! Set the I2C Power mode. */
89  status = I2Cdrv->PowerControl(ARM_POWER_FULL);
90  if (ARM_DRIVER_OK != status)
91  {
92  PRINTF("\r\n I2C Power Mode setting Failed\r\n");
93  return -1;
94  }
95 
96  /*! Set the I2C bus speed. */
97  status = I2Cdrv->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
98  if (ARM_DRIVER_OK != status)
99  {
100  PRINTF("\r\n I2C Control Mode setting Failed\r\n");
101  return -1;
102  }
103 
104  /*! Initialize the FXAS21002 sensor driver. */
107  if (SENSOR_ERROR_NONE != status)
108  {
109  PRINTF("\r\n Sensor Initialization Failed\r\n");
110  return -1;
111  }
112  PRINTF("\r\n Successfully Initiliazed Sensor\r\n");
113 
114  /*! Set the task to be executed while waiting for I2C transactions to complete. */
115  //FXAS21002_I2C_SetIdleTask(&FXAS21002drv, (registeridlefunction_t)SMC_SetPowerModeVlpr, SMC);
116 
117  /*! Configure the FXAS21002 sensor driver. */
118  status = FXAS21002_I2C_Configure(&FXAS21002drv, fxas21002_Config_with_Fifo);
119  if (SENSOR_ERROR_NONE != status)
120  {
121  PRINTF("\r\n FXAS21002 Sensor Configuration Failed, Err = %d\r\n", status);
122  return -1;
123  }
124  PRINTF("\r\n Successfully Applied FXAS21002 Sensor Configuration\r\n");
125 
126  for (;;) /* Forever loop */
127  {
128  /*! Wait for the FIFO watermark event. */
129  status = FXAS21002_I2C_ReadData(&FXAS21002drv, fxas21002_Fifo_Event, &fifoEvent);
130  if (0 == (fifoEvent & FXAS21002_F_EVENT_F_EVENT_MASK))
131  {
132  continue;
133  }
134 
135  /*! Read the raw sensor data from the FXAS21002. */
136  status = FXAS21002_I2C_ReadData(&FXAS21002drv, fxas21002_Output_Values, data);
137  if (ARM_DRIVER_OK != status)
138  {
139  PRINTF("\r\n Read Failed. \r\n");
140  return -1;
141  }
142 
143  for (uint8_t i = 0; i < FIFO_SIZE; i++)
144  {
145  /*! Convert the raw sensor data to signed 16-bit container for display to the debug port. */
146  rawData.gyro[0] =
147  ((int16_t)data[i * FXAS21002_GYRO_DATA_SIZE + 0] << 8) | data[i * FXAS21002_GYRO_DATA_SIZE + 1];
148  rawData.gyro[1] =
149  ((int16_t)data[i * FXAS21002_GYRO_DATA_SIZE + 2] << 8) | data[i * FXAS21002_GYRO_DATA_SIZE + 3];
150  rawData.gyro[2] =
151  ((int16_t)data[i * FXAS21002_GYRO_DATA_SIZE + 4] << 8) | data[i * FXAS21002_GYRO_DATA_SIZE + 5];
152  }
153  /* NOTE: PRINTF is relatively expensive in terms of CPU time, specially when used with-in execution loop. */
154  PRINTF("\r\n Gyro X = %d Y = %d Z = %d\r\n", rawData.gyro[0], rawData.gyro[1], rawData.gyro[2]);
155  ASK_USER_TO_RESUME(100 / FIFO_SIZE); /* Ask for user input after processing 100 samples. */
156  }
157 }
#define FXAS21002_WHO_AM_I_WHOAMI_PROD_VALUE
Definition: fxas21002.h:402
const registerwritelist_t fxas21002_Config_with_Fifo[]
This structure defines the Write command List.
Definition: sensor_drv.h:68
#define FXAS21002_F_EVENT_F_EVENT_MASK
Definition: fxas21002.h:311
#define ASK_USER_TO_RESUME(x)
Definition: frdm_k64f.h:106
int32_t status
int32_t FXAS21002_I2C_Initialize(fxas21002_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t whoAmi)
The interface function to initialize the sensor.
#define FIFO_SIZE
The watermark value configured for FXAS21002 FIFO Buffer.
This structure defines the fxas21002 raw data buffer.
Definition: fxas21002_drv.h:53
#define FXAS21002_F_SETUP_F_MODE_STOP_MODE
Definition: fxas21002.h:282
#define FXAS21002_CTRL_REG3_WRAPTOONE_ROLL_DATA
Definition: fxas21002.h:848
#define __END_WRITE_DATA__
Definition: sensor_drv.h:45
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
int main(void)
Main function.
#define I2C_S_SIGNAL_EVENT
Definition: issdk_hal.h:34
int32_t FXAS21002_I2C_Configure(fxas21002_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
#define I2C_S_DRIVER
Definition: issdk_hal.h:33
This defines the sensor specific information for I2C.
Definition: fxas21002_drv.h:44
#define BOARD_BootClockRUN
Definition: clock_config.h:19
#define FXAS21002_CTRL_REG3_WRAPTOONE_MASK
Definition: fxas21002.h:829
#define FXAS21002_I2C_ADDR
uint8_t data[FXLS8962_DATA_SIZE]
#define __END_READ_DATA__
Definition: sensor_drv.h:51
#define FXAS21002_F_SETUP_F_WMRK_SHIFT
Definition: fxas21002.h:271
The fxas21002_drv.h file describes the fxas21002 driver interface and structures. ...
int32_t FXAS21002_I2C_ReadData(fxas21002_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
ARM_DRIVER_I2C * I2Cdrv
fxos8700_accelmagdata_t rawData
const registerreadlist_t fxas21002_Output_Values[]
uint16_t readFrom
Definition: sensor_drv.h:80
#define FXAS21002_F_SETUP_F_WMRK_MASK
Definition: fxas21002.h:270
#define FXAS21002_GYRO_DATA_SIZE
The size of the FXAS21002 gyro data.
Definition: fxas21002_drv.h:61
#define FXAS21002_CTRL_REG1_DR_MASK
Definition: fxas21002.h:684
This structure defines the Read command List.
Definition: sensor_drv.h:78
#define I2C_S_DEVICE_INDEX
Definition: issdk_hal.h:35
#define FXAS21002_CTRL_REG1_DR_12_5HZ
Definition: fxas21002.h:710
void BOARD_InitDebugConsole(void)
Definition: board.c:15
const registerreadlist_t fxas21002_Fifo_Event[]
void BOARD_InitPins(void)
Configures pin routing and optionally pin electrical features.
Definition: pin_mux.c:47
#define FXAS21002_F_SETUP_F_MODE_MASK
Definition: fxas21002.h:273