ISSDK  1.8
IoT Sensing Software Development Kit
fxls8974cf_interrupt.c
Go to the documentation of this file.
1 /*
2  * Copyright 2022 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 /**
9  * @file fxls8974cf_interrupt.c
10  * @brief The fxls8974cf_interrupt.c file implements the ISSDK FXLS8974CF sensor
11  * driver example demonstration with interrupt mode.
12  */
13 
14 //-----------------------------------------------------------------------
15 // SDK Includes
16 //-----------------------------------------------------------------------
17 #include "pin_mux.h"
18 #include "clock_config.h"
19 #include "board.h"
20 #include "fsl_debug_console.h"
21 
22 //-----------------------------------------------------------------------
23 // CMSIS Includes
24 //-----------------------------------------------------------------------
25 #include "Driver_I2C.h"
26 
27 //-----------------------------------------------------------------------
28 // ISSDK Includes
29 //-----------------------------------------------------------------------
30 #include "issdk_hal.h"
31 #include "gpio_driver.h"
32 #include "fxls8974_drv.h"
33 #include "systick_utils.h"
34 
35 //-----------------------------------------------------------------------
36 // Macros
37 //-----------------------------------------------------------------------
38 #define FXLS8974_DATA_SIZE 6
39 
40 //-----------------------------------------------------------------------
41 // Constants
42 //-----------------------------------------------------------------------
43 /*! @brief Register settings for Interrupt (non buffered) mode. */
45  /* Set Full-scale range as 2G. */
47  /* Set Wake Mode ODR Rate as 6.25Hz. */
49  /* Enable Interrupts for Data Ready Events. */
52 
53 /*! @brief Address of Raw Accel Data in Normal Mode. */
56 
57 //-----------------------------------------------------------------------
58 // Global Variables
59 //-----------------------------------------------------------------------
60 volatile bool gFxls8974DataReady = false;
61 
62 //-----------------------------------------------------------------------
63 // Functions
64 //-----------------------------------------------------------------------
65 /*! -----------------------------------------------------------------------
66  * @brief This is the Sensor Data Ready ISR implementation.
67  * @details This function sets the flag which indicates if a new sample(s) is available for reading.
68  * @param[in] pUserData This is a void pointer to the instance of the user specific data structure for the ISR.
69  * @return void There is no return value.
70  * @constraints None
71  * @reeentrant Yes
72  * -----------------------------------------------------------------------*/
73 void fxls8974_int_data_ready_callback(void *pUserData)
74 { /*! @brief Set flag to indicate Sensor has signalled data ready. */
75  gFxls8974DataReady = true;
76 }
77 
78 /*! -----------------------------------------------------------------------
79  * @brief This is the The main function implementation.
80  * @details This function invokes board initializes routines, then then brings up the sensor and
81  * finally enters an endless loop to continuously read available samples.
82  * @param[in] void This is no input parameter.
83  * @return void There is no return value.
84  * @constraints None
85  * @reeentrant No
86  * -----------------------------------------------------------------------*/
87 int main(void)
88 {
90  uint8_t whoami;
91  uint8_t data[FXLS8974_DATA_SIZE];
93 
94  ARM_DRIVER_I2C *I2Cdrv = &I2C_S_DRIVER; // Now using the shield.h value!!!
97 
98  /*! Initialize the MCU hardware. */
103 
104  PRINTF("\r\n ISSDK FXLS8974 sensor driver example demonstration with interrupt mode.\r\n");
105 
106  /*! Initialize FXLS8974 pin used by FRDM board */
108 
109  /*! Initialize RGB LED pin used by FRDM board */
110  pGpioDriver->pin_init(&GREEN_LED, GPIO_DIRECTION_OUT, NULL, NULL, NULL);
111 
112  /*! Initialize the I2C driver. */
113  status = I2Cdrv->Initialize(I2C_S_SIGNAL_EVENT);
114  if (ARM_DRIVER_OK != status)
115  {
116  PRINTF("\r\n I2C Initialization Failed\r\n");
117  return -1;
118  }
119 
120  /*! Set the I2C Power mode. */
121  status = I2Cdrv->PowerControl(ARM_POWER_FULL);
122  if (ARM_DRIVER_OK != status)
123  {
124  PRINTF("\r\n I2C Power Mode setting Failed\r\n");
125  return -1;
126  }
127 
128  /*! Set the I2C bus speed. */
129  status = I2Cdrv->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
130  if (ARM_DRIVER_OK != status)
131  {
132  PRINTF("\r\n I2C Control Mode setting Failed\r\n");
133  return -1;
134  }
135 
136  /*! Initialize FXLS8974 sensor driver. */
138  &whoami);
139  if (SENSOR_ERROR_NONE != status)
140  {
141  PRINTF("\r\n Sensor Initialization Failed\r\n");
142  return -1;
143  }
144  if ((FXLS8964_WHOAMI_VALUE == whoami) || (FXLS8967_WHOAMI_VALUE == whoami))
145  {
146  PRINTF("\r\n Successfully Initialized Gemini with WHO_AM_I = 0x%X\r\n", whoami);
147  }
148  else if ((FXLS8974_WHOAMI_VALUE == whoami) || (FXLS8968_WHOAMI_VALUE == whoami))
149  {
150  PRINTF("\r\n Successfully Initialized Timandra with WHO_AM_I = 0x%X\r\n", whoami);
151  }
152  else if (FXLS8962_WHOAMI_VALUE == whoami)
153  {
154  PRINTF("\r\n Successfully Initialized Newstein with WHO_AM_I = 0x%X\r\n", whoami);
155  }
156  else
157  {
158  PRINTF("\r\n Bad WHO_AM_I = 0x%X\r\n", whoami);
159  }
160 
161  /*! Set the task to be executed while waiting for I2C transactions to complete. */
163 
164  /*! Configure the FXLS8974 sensor. */
165  status = FXLS8974_I2C_Configure(&fxls8974Driver, cFxls8974ConfigNormal);
166  if (SENSOR_ERROR_NONE != status)
167  {
168  PRINTF("\r\n FXLS8974 Sensor Configuration Failed, Err = %d\r\n", status);
169  return -1;
170  }
171  PRINTF("\r\n Successfully Applied FXLS8974 Sensor Configuration\r\n");
172 
173  for (;;) /* Forever loop */
174  { /* In ISR Mode we do not need to check Data Ready Register.
175  * The receipt of interrupt will indicate data is ready. */
176  if (false == gFxls8974DataReady)
177  { /* Loop, if new sample is not available. */
179  continue;
180  }
181  else
182  { /*! Clear the data ready flag, it will be set again by the ISR. */
183  gFxls8974DataReady = false;
184  pGpioDriver->toggle_pin(&GREEN_LED);
185  }
186 
187  /*! Read new raw sensor data from the FXLS8974. */
188  status = FXLS8974_I2C_ReadData(&fxls8974Driver, cFxls8974OutputNormal, data);
189  if (ARM_DRIVER_OK != status)
190  {
191  PRINTF("\r\n Read Failed. \r\n");
192  return -1;
193  }
194 
195  /*! Process the sample and convert the raw sensor data. */
196  rawData.accel[0] = ((int16_t)data[1] << 8) | data[0];
197  rawData.accel[1] = ((int16_t)data[3] << 8) | data[2];
198  rawData.accel[2] = ((int16_t)data[5] << 8) | data[4];
199 
200  /* NOTE: PRINTF is relatively expensive in terms of CPU time, specially when used with-in execution loop. */
201  PRINTF("\r\n X=%5d Y=%5d Z=%5d\r\n", rawData.accel[0], rawData.accel[1], rawData.accel[2]);
202  ASK_USER_TO_RESUME(50); /* Ask for user input after processing 50 samples. */
203  }
204 }
volatile bool gFxls8974DataReady
#define FXLS8974_INT_EN_DRDY_EN_MASK
Definition: fxls8974.h:850
This structure defines the Write command List.
Definition: sensor_drv.h:68
#define FXLS8974_SENS_CONFIG1_FSR_MASK
Definition: fxls8974.h:423
int32_t FXLS8974_I2C_Configure(fxls8974_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
Definition: fxls8974_drv.c:285
#define ASK_USER_TO_RESUME(x)
Definition: frdm_k64f.h:106
int32_t status
int32_t FXLS8974_I2C_Initialize(fxls8974_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: fxls8974_drv.c:239
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
#define FXLS8974_INT1
#define FXLS8974_INT_EN_DRDY_EN_EN
Definition: fxls8974.h:857
Access structure of the GPIO Driver.
Definition: Driver_GPIO.h:38
This defines the sensor specific information for I2C.
Definition: fxls8974_drv.h:43
#define SMC
Definition: lpc54114.h:118
void fxls8974_int_data_ready_callback(void *pUserData)
This is the Sensor Data Ready ISR implementation.
#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)
This is the The main function implementation.
#define FXLS8967_WHOAMI_VALUE
Definition: fxls8962.h:89
#define I2C_S_SIGNAL_EVENT
Definition: issdk_hal.h:34
#define FXLS8974_I2C_ADDR
#define I2C_S_DRIVER
Definition: issdk_hal.h:33
#define FXLS8974_DATA_SIZE
#define BOARD_BootClockRUN
Definition: clock_config.h:19
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
Definition: sensor_drv.h:97
int32_t FXLS8974_I2C_ReadData(fxls8974_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: fxls8974_drv.c:330
GENERIC_DRIVER_GPIO Driver_GPIO_KSDK
Definition: gpio_driver.c:177
GENERIC_DRIVER_GPIO * pGpioDriver
This structure defines the fxls8974 raw data buffer.
Definition: fxls8974_drv.h:52
uint8_t data[FXLS8962_DATA_SIZE]
#define __END_READ_DATA__
Definition: sensor_drv.h:51
#define FXLS8974_SENS_CONFIG3_WAKE_ODR_MASK
Definition: fxls8974.h:551
fxls8974_i2c_sensorhandle_t fxls8974Driver
ARM_DRIVER_I2C * I2Cdrv
fxos8700_accelmagdata_t rawData
void FXLS8974_I2C_SetIdleTask(fxls8974_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
Definition: fxls8974_drv.c:277
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
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
const registerreadlist_t cFxls8974OutputNormal[]
Address of Raw Accel Data in Normal Mode.
void(* pin_init)(pinID_t aPinId, gpio_direction_t dir, void *apPinConfig, gpio_isr_handler_t aIsrHandler, void *apUserData)
Definition: Driver_GPIO.h:41
#define FXLS8974_SENS_CONFIG1_FSR_2G
Definition: fxls8974.h:453
This structure defines the Read command List.
Definition: sensor_drv.h:78
ARM Systick Utilities.
gpioHandleKSDK_t GREEN_LED
Definition: frdm_k64f.c:188
#define FXLS8974_WHOAMI_VALUE
Definition: fxls8962.h:90
The fxls8974_drv.h file describes the FXLS8974CF driver interface and structures. ...
#define FXLS8968_WHOAMI_VALUE
Definition: fxls896x.h:89
#define I2C_S_DEVICE_INDEX
Definition: issdk_hal.h:35
void BOARD_InitDebugConsole(void)
Definition: board.c:15
#define FXLS8962_WHOAMI_VALUE
Definition: fxls8962.h:87
#define FXLS8974_SENS_CONFIG3_WAKE_ODR_6_25HZ
Definition: fxls8974.h:566
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
const registerwritelist_t cFxls8974ConfigNormal[]
Register settings for Interrupt (non buffered) mode.