ISSDK  1.8
IoT Sensing Software Development Kit
fxas21002_interrupt.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_interrupt.c
11  * @brief The fxas21002_interrupt.c file implements the ISSDK FXAS21002 sensor
12  * driver example demonstration with interrupt mode.
13  */
14 
15 //-----------------------------------------------------------------------
16 // SDK Includes
17 //-----------------------------------------------------------------------
18 #include "pin_mux.h"
19 #include "clock_config.h"
20 #include "board.h"
21 #include "fsl_debug_console.h"
22 
23 //-----------------------------------------------------------------------
24 // CMSIS Includes
25 //-----------------------------------------------------------------------
26 #include "Driver_I2C.h"
27 
28 //-----------------------------------------------------------------------
29 // ISSDK Includes
30 //-----------------------------------------------------------------------
31 #include "issdk_hal.h"
32 #include "gpio_driver.h"
33 #include "fxas21002_drv.h"
34 
35 //-----------------------------------------------------------------------
36 // Constants
37 //-----------------------------------------------------------------------
38 /*! Prepare the register write list to configure FXAS21002 in non-FIFO mode. */
40  /*! Configure CTRL_REG1 register to put FXAS21002 to 12.5Hz sampling rate. */
42  /*! Configure CTRL_REG2 register to set interrupt configuration settings. */
47 
48 /*! Prepare the register read list to read FXAS21002 DataReady status. */
50 
51 /*! Prepare the register read list to read the raw gyro data from the FXAS21002. */
54 //-----------------------------------------------------------------------
55 // Global Variables
56 //-----------------------------------------------------------------------
57 volatile bool fxas21002Interrupt = false;
58 
59 //-----------------------------------------------------------------------
60 // Functions
61 //-----------------------------------------------------------------------
62 /*! -----------------------------------------------------------------------
63  * @brief This is the Sensor Data Ready ISR implementation.
64  * @details This function sets the flag which indicates if a new sample(s) is available for reading.
65  * @param[in] pUserData This is a void pointer to the instance of the user specific data structure for the ISR.
66  * @return void There is no return value.
67  * @constraints None
68  * @reeentrant Yes
69  * -----------------------------------------------------------------------*/
70 void fxas21002_isr(void *pUserData)
71 { /*! @brief Set flag to indicate Sensor has signalled data ready. */
72  fxas21002Interrupt = true;
73 }
74 
75 /*! -----------------------------------------------------------------------
76  * @brief This is the The main function implementation.
77  * @details This function invokes board initializes routines, then then brings up the sensor and
78  * finally enters an endless loop to continuously read available samples.
79  * @param[in] void This is no input parameter.
80  * @return void There is no return value.
81  * @constraints None
82  * @reeentrant No
83  * -----------------------------------------------------------------------*/
84 int main(void)
85 {
89 
90  ARM_DRIVER_I2C *I2Cdrv = &I2C_S_DRIVER; // Now using the shield.h value!!!
91  fxas21002_i2c_sensorhandle_t FXAS21002drv;
93 
94  /*! Initialize the MCU hardware. */
98 
99  PRINTF("\r\n ISSDK FXAS21002 sensor driver example demonstration with interrupt mode.\r\n");
100 
101  /*! Initialize INT1_FXAS21002 pin used by FRDM board */
102  gpioDriver->pin_init(&FXAS21002_INT1, GPIO_DIRECTION_IN, NULL, &fxas21002_isr, NULL);
103 
104  /*! Initialize RGB LED pin used by FRDM board */
105  gpioDriver->pin_init(&GREEN_LED, GPIO_DIRECTION_OUT, NULL, NULL, NULL);
106 
107  /*! Initialize the I2C driver. */
108  status = I2Cdrv->Initialize(I2C_S_SIGNAL_EVENT);
109  if (ARM_DRIVER_OK != status)
110  {
111  PRINTF("\r\n I2C Initialization Failed\r\n");
112  return -1;
113  }
114 
115  /*! Set the I2C Power mode. */
116  status = I2Cdrv->PowerControl(ARM_POWER_FULL);
117  if (ARM_DRIVER_OK != status)
118  {
119  PRINTF("\r\n I2C Power Mode setting Failed\r\n");
120  return -1;
121  }
122 
123  /*! Set the I2C bus speed. */
124  status = I2Cdrv->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
125  if (ARM_DRIVER_OK != status)
126  {
127  PRINTF("\r\n I2C Control Mode setting Failed\r\n");
128  return -1;
129  }
130 
131  /*! Initialize the FXAS21002 sensor driver. */
134  if (SENSOR_ERROR_NONE != status)
135  {
136  PRINTF("\r\n Sensor Initialization Failed\r\n");
137  return -1;
138  }
139  PRINTF("\r\n Successfully Initiliazed Sensor\r\n");
140 
141  /*! Set the task to be executed while waiting for I2C transactions to complete. */
143 
144  /*! Configure the FXAS21002 sensor driver. */
145  status = FXAS21002_I2C_Configure(&FXAS21002drv, fxas21002_Config_Isr);
146  if (SENSOR_ERROR_NONE != status)
147  {
148  PRINTF("\r\n FXAS21002 Sensor Configuration Failed, Err = %d\r\n", status);
149  return -1;
150  }
151  PRINTF("\r\n Successfully Applied FXAS21002 Sensor Configuration\r\n");
152 
153  for (;;) /* Forever loop */
154  { /* In ISR Mode we do not need to check Data Ready Register.
155  * The receipt of interrupt will indicate data is ready. */
156  if (false == fxas21002Interrupt)
157  { /* Loop, if new sample is not available. */
159  continue;
160  }
161  else
162  { /*! Clear the data ready flag, it will be set again by the ISR. */
163  fxas21002Interrupt = false;
164  gpioDriver->toggle_pin(&GREEN_LED);
165  }
166 
167  /*! Read the raw sensor data from the FXAS21002. */
168  status = FXAS21002_I2C_ReadData(&FXAS21002drv, fxas21002_Output_Values, data);
169  if (ARM_DRIVER_OK != status)
170  {
171  PRINTF("\r\n Read Failed. \r\n");
172  return -1;
173  }
174 
175  /*! Convert the raw sensor data to signed 16-bit container for display to the debug port. */
176  rawData.gyro[0] = ((int16_t)data[0] << 8) | data[1];
177  rawData.gyro[1] = ((int16_t)data[2] << 8) | data[3];
178  rawData.gyro[2] = ((int16_t)data[4] << 8) | data[5];
179 
180  /* NOTE: PRINTF is relatively expensive in terms of CPU time, specially when used with-in execution loop. */
181  PRINTF("\r\n Gyro X = %d Y = %d Z = %d\r\n", rawData.gyro[0], rawData.gyro[1], rawData.gyro[2]);
182  ASK_USER_TO_RESUME(100); /* Ask for user input after processing 100 samples. */
183  }
184 }
int main(void)
This is the The main function implementation.
#define FXAS21002_WHO_AM_I_WHOAMI_PROD_VALUE
Definition: fxas21002.h:402
#define FXAS21002_INT1
#define FXAS21002_CTRL_REG2_INT_EN_DRDY_ENABLE
Definition: fxas21002.h:783
This structure defines the Write command List.
Definition: sensor_drv.h:68
#define ASK_USER_TO_RESUME(x)
Definition: frdm_k64f.h:106
int32_t status
#define FXAS21002_CTRL_REG2_INT_CFG_DRDY_INT1
Definition: fxas21002.h:786
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.
status_t SMC_SetPowerModeVlpr(void *arg)
Configures the system to VLPR power mode. API name used from Kinetis family to maintain compatibility...
Definition: lpc54114.c:169
void FXAS21002_I2C_SetIdleTask(fxas21002_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
This structure defines the fxas21002 raw data buffer.
Definition: fxas21002_drv.h:53
Access structure of the GPIO Driver.
Definition: Driver_GPIO.h:38
#define SMC
Definition: lpc54114.h:118
#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.
#define FXAS21002_CTRL_REG2_INT_EN_DRDY_MASK
Definition: fxas21002.h:757
#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 FXAS21002_CTRL_REG2_IPOL_MASK
Definition: fxas21002.h:754
#define BOARD_BootClockRUN
Definition: clock_config.h:19
#define FXAS21002_CTRL_REG2_IPOL_ACTIVE_HIGH
Definition: fxas21002.h:782
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
Definition: sensor_drv.h:97
const registerreadlist_t fxas21002_DRDY[]
const registerreadlist_t fxas21002_Output_Values[]
GENERIC_DRIVER_GPIO Driver_GPIO_KSDK
Definition: gpio_driver.c:177
#define FXAS21002_I2C_ADDR
volatile bool fxas21002Interrupt
uint8_t data[FXLS8962_DATA_SIZE]
#define __END_READ_DATA__
Definition: sensor_drv.h:51
const registerwritelist_t fxas21002_Config_Isr[]
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
uint16_t readFrom
Definition: sensor_drv.h:80
void(* toggle_pin)(pinID_t aPinId)
Definition: Driver_GPIO.h:48
#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
status_t SMC_SetPowerModeWait(void *arg)
Configures the system to WAIT power mode. API name used from Kinetis family to maintain compatibility...
Definition: lpc54114.c:155
void(* pin_init)(pinID_t aPinId, gpio_direction_t dir, void *apPinConfig, gpio_isr_handler_t aIsrHandler, void *apUserData)
Definition: Driver_GPIO.h:41
This structure defines the Read command List.
Definition: sensor_drv.h:78
#define FXAS21002_CTRL_REG2_INT_CFG_DRDY_MASK
Definition: fxas21002.h:760
gpioHandleKSDK_t GREEN_LED
Definition: frdm_k64f.c:188
#define I2C_S_DEVICE_INDEX
Definition: issdk_hal.h:35
void fxas21002_isr(void *pUserData)
This is the Sensor Data Ready ISR implementation.
#define FXAS21002_CTRL_REG1_DR_12_5HZ
Definition: fxas21002.h:710
void BOARD_InitDebugConsole(void)
Definition: board.c:15
void BOARD_InitPins(void)
Configures pin routing and optionally pin electrical features.
Definition: pin_mux.c:47