ISSDK  1.8
IoT Sensing Software Development Kit
fxls8962_interrupt.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 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 fxls8962_interrupt.c
11  * @brief The fxls8962_interrupt.c file implements the ISSDK FXLS8962 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 "fxls8962_drv.h"
34 #include "systick_utils.h"
35 
36 //-----------------------------------------------------------------------
37 // Macros
38 //-----------------------------------------------------------------------
39 #define FXLS8962_DATA_SIZE 6
40 
41 //-----------------------------------------------------------------------
42 // Constants
43 //-----------------------------------------------------------------------
44 /*! @brief Register settings for Interrupt (non buffered) mode. */
46  /* Set Full-scale range as 2G. */
48  /* Set Wake Mode ODR Rate as 6.25Hz. */
50  /* Enable Interrupts for Data Ready Events. */
53 
54 /*! @brief Address of Raw Accel Data in Normal Mode. */
57 
58 //-----------------------------------------------------------------------
59 // Global Variables
60 //-----------------------------------------------------------------------
61 volatile bool gFxls8962DataReady = false;
62 
63 //-----------------------------------------------------------------------
64 // Functions
65 //-----------------------------------------------------------------------
66 /*! -----------------------------------------------------------------------
67  * @brief This is the Sensor Data Ready ISR implementation.
68  * @details This function sets the flag which indicates if a new sample(s) is available for reading.
69  * @param[in] pUserData This is a void pointer to the instance of the user specific data structure for the ISR.
70  * @return void There is no return value.
71  * @constraints None
72  * @reeentrant Yes
73  * -----------------------------------------------------------------------*/
74 void fxls8962_int_data_ready_callback(void *pUserData)
75 { /*! @brief Set flag to indicate Sensor has signalled data ready. */
76  gFxls8962DataReady = true;
77 }
78 
79 /*! -----------------------------------------------------------------------
80  * @brief This is the The main function implementation.
81  * @details This function invokes board initializes routines, then then brings up the sensor and
82  * finally enters an endless loop to continuously read available samples.
83  * @param[in] void This is no input parameter.
84  * @return void There is no return value.
85  * @constraints None
86  * @reeentrant No
87  * -----------------------------------------------------------------------*/
88 int main(void)
89 {
91  uint8_t whoami;
92  uint8_t data[FXLS8962_DATA_SIZE];
94 
95  ARM_DRIVER_I2C *I2Cdrv = &I2C_S_DRIVER; // Now using the shield.h value!!!
98 
99  /*! Initialize the MCU hardware. */
100  BOARD_InitPins();
104 
105  PRINTF("\r\n ISSDK FXLS8962 sensor driver example demonstration with interrupt mode.\r\n");
106 
107  /*! Initialize FXLS8962 pin used by FRDM board */
109 
110  /*! Initialize RGB LED pin used by FRDM board */
111  pGpioDriver->pin_init(&GREEN_LED, GPIO_DIRECTION_OUT, NULL, NULL, NULL);
112 
113  /*! Initialize the I2C driver. */
114  status = I2Cdrv->Initialize(I2C_S_SIGNAL_EVENT);
115  if (ARM_DRIVER_OK != status)
116  {
117  PRINTF("\r\n I2C Initialization Failed\r\n");
118  return -1;
119  }
120 
121  /*! Set the I2C Power mode. */
122  status = I2Cdrv->PowerControl(ARM_POWER_FULL);
123  if (ARM_DRIVER_OK != status)
124  {
125  PRINTF("\r\n I2C Power Mode setting Failed\r\n");
126  return -1;
127  }
128 
129  /*! Set the I2C bus speed. */
130  status = I2Cdrv->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
131  if (ARM_DRIVER_OK != status)
132  {
133  PRINTF("\r\n I2C Control Mode setting Failed\r\n");
134  return -1;
135  }
136 
137  /*! Initialize FXLS8962 sensor driver. */
139  &whoami);
140  if (SENSOR_ERROR_NONE != status)
141  {
142  PRINTF("\r\n Sensor Initialization Failed\r\n");
143  return -1;
144  }
145  if ((FXLS8964_WHOAMI_VALUE == whoami) || (FXLS8967_WHOAMI_VALUE == whoami))
146  {
147  PRINTF("\r\n Successfully Initialized Gemini with WHO_AM_I = 0x%X\r\n", whoami);
148  }
149  else if (FXLS8974_WHOAMI_VALUE == whoami)
150  {
151  PRINTF("\r\n Successfully Initialized Timandra with WHO_AM_I = 0x%X\r\n", whoami);
152  }
153  else if (FXLS8962_WHOAMI_VALUE == whoami)
154  {
155  PRINTF("\r\n Successfully Initialized Newstein with WHO_AM_I = 0x%X\r\n", whoami);
156  }
157  else
158  {
159  PRINTF("\r\n Bad WHO_AM_I = 0x%X\r\n", whoami);
160  }
161 
162  /*! Set the task to be executed while waiting for I2C transactions to complete. */
164 
165  /*! Configure the FXLS8962 sensor. */
166  status = FXLS8962_I2C_Configure(&fxls8962Driver, cFxls8962ConfigNormal);
167  if (SENSOR_ERROR_NONE != status)
168  {
169  PRINTF("\r\n FXLS8962 Sensor Configuration Failed, Err = %d\r\n", status);
170  return -1;
171  }
172  PRINTF("\r\n Successfully Applied FXLS8962 Sensor Configuration\r\n");
173 
174  for (;;) /* Forever loop */
175  { /* In ISR Mode we do not need to check Data Ready Register.
176  * The receipt of interrupt will indicate data is ready. */
177  if (false == gFxls8962DataReady)
178  { /* Loop, if new sample is not available. */
180  continue;
181  }
182  else
183  { /*! Clear the data ready flag, it will be set again by the ISR. */
184  gFxls8962DataReady = false;
185  pGpioDriver->toggle_pin(&GREEN_LED);
186  }
187 
188  /*! Read new raw sensor data from the FXLS8962. */
189  status = FXLS8962_I2C_ReadData(&fxls8962Driver, cFxls8962OutputNormal, data);
190  if (ARM_DRIVER_OK != status)
191  {
192  PRINTF("\r\n Read Failed. \r\n");
193  return -1;
194  }
195 
196  /*! Process the sample and convert the raw sensor data. */
197  rawData.accel[0] = ((int16_t)data[1] << 8) | data[0];
198  rawData.accel[1] = ((int16_t)data[3] << 8) | data[2];
199  rawData.accel[2] = ((int16_t)data[5] << 8) | data[4];
200 
201  /* NOTE: PRINTF is relatively expensive in terms of CPU time, specially when used with-in execution loop. */
202  PRINTF("\r\n X=%5d Y=%5d Z=%5d\r\n", rawData.accel[0], rawData.accel[1], rawData.accel[2]);
203  ASK_USER_TO_RESUME(50); /* Ask for user input after processing 50 samples. */
204  }
205 }
#define FXLS8962_INT_EN_DRDY_EN_EN
Definition: fxls8962.h:857
This structure defines the fxls8962 raw data buffer.
Definition: fxls8962_drv.h:53
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
const registerwritelist_t cFxls8962ConfigNormal[]
Register settings for Interrupt (non buffered) mode.
#define FXLS8962_SENS_CONFIG1_FSR_2G
Definition: fxls8962.h:453
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
The fxls8962_drv.h file describes the FXLS8962AF driver interface and structures. ...
#define FXLS8962_INT1
#define FXLS8962_INT_EN_DRDY_EN_MASK
Definition: fxls8962.h:850
#define FXLS8962_DATA_SIZE
int32_t FXLS8962_I2C_Initialize(fxls8962_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t *whoami)
The interface function to initialize the sensor.
Definition: fxls8962_drv.c:240
Access structure of the GPIO Driver.
Definition: Driver_GPIO.h:38
#define SMC
Definition: lpc54114.h:118
volatile bool gFxls8962DataReady
#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 FXLS8962_SENS_CONFIG3_WAKE_ODR_MASK
Definition: fxls8962.h:551
This defines the sensor specific information for I2C.
Definition: fxls8962_drv.h:44
#define FXLS8967_WHOAMI_VALUE
Definition: fxls8962.h:89
#define I2C_S_SIGNAL_EVENT
Definition: issdk_hal.h:34
#define I2C_S_DRIVER
Definition: issdk_hal.h:33
#define BOARD_BootClockRUN
Definition: clock_config.h:19
fxls8962_i2c_sensorhandle_t fxls8962Driver
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
Definition: sensor_drv.h:97
GENERIC_DRIVER_GPIO Driver_GPIO_KSDK
Definition: gpio_driver.c:177
GENERIC_DRIVER_GPIO * pGpioDriver
void fxls8962_int_data_ready_callback(void *pUserData)
This is the Sensor Data Ready ISR implementation.
uint8_t data[FXLS8962_DATA_SIZE]
#define __END_READ_DATA__
Definition: sensor_drv.h:51
int32_t FXLS8962_I2C_ReadData(fxls8962_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: fxls8962_drv.c:331
#define FXLS8962_SENS_CONFIG3_WAKE_ODR_6_25HZ
Definition: fxls8962.h:566
ARM_DRIVER_I2C * I2Cdrv
int main(void)
This is the The main function implementation.
fxos8700_accelmagdata_t rawData
const registerreadlist_t cFxls8962OutputNormal[]
Address of Raw Accel Data in Normal Mode.
uint16_t readFrom
Definition: sensor_drv.h:80
void(* toggle_pin)(pinID_t aPinId)
Definition: Driver_GPIO.h:48
void BOARD_SystickEnable(void)
Function to enable systicks framework.
Definition: systick_utils.c:35
int32_t FXLS8962_I2C_Configure(fxls8962_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
Definition: fxls8962_drv.c:286
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
ARM Systick Utilities.
#define FXLS8962_SENS_CONFIG1_FSR_MASK
Definition: fxls8962.h:423
gpioHandleKSDK_t GREEN_LED
Definition: frdm_k64f.c:188
#define FXLS8974_WHOAMI_VALUE
Definition: fxls8962.h:90
#define I2C_S_DEVICE_INDEX
Definition: issdk_hal.h:35
void FXLS8962_I2C_SetIdleTask(fxls8962_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
Definition: fxls8962_drv.c:278
#define FXLS8962_I2C_ADDR
void BOARD_InitDebugConsole(void)
Definition: board.c:15
#define FXLS8962_WHOAMI_VALUE
Definition: fxls8962.h:87
void BOARD_InitPins(void)
Configures pin routing and optionally pin electrical features.
Definition: pin_mux.c:47
#define FXLS8964_WHOAMI_VALUE
Definition: fxls8962.h:88