ISSDK  1.8
IoT Sensing Software Development Kit
fxls8974cf_poll.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_poll.c
10  * @brief The fxls8974cf_poll.c file implements the ISSDK FXLS8974 sensor driver
11  * example demonstration with polling mode.
12  */
13 
14 /* SDK Includes */
15 #include "pin_mux.h"
16 #include "clock_config.h"
17 #include "board.h"
18 #include "fsl_debug_console.h"
19 
20 /* CMSIS Includes */
21 #include "Driver_I2C.h"
22 
23 /* ISSDK Includes */
24 #include "issdk_hal.h"
25 #include "fxls8974_drv.h"
26 #include "systick_utils.h"
27 
28 /*******************************************************************************
29  * Macros
30  ******************************************************************************/
31 #define FXLS8974_DATA_SIZE 6
32 
33 /*******************************************************************************
34  * Constants
35  ******************************************************************************/
36 /*! @brief Register settings for Normal (non buffered) mode. */
38  /* Set Full-scale range as 2G. */
40  /* Set Wake Mode ODR Rate as 6.25Hz. */
43 
44 /*! @brief Address of DATA Ready Status Register. */
46 
47 /*! @brief Address of Raw Accel Data in Normal Mode. */
50 
51 /*******************************************************************************
52  * Code
53  ******************************************************************************/
54 /*!
55  * @brief Main function
56  */
57 int main(void)
58 {
60  uint8_t whoami;
61  uint8_t dataReady;
62  uint8_t data[FXLS8974_DATA_SIZE];
64 
65  ARM_DRIVER_I2C *I2Cdrv = &I2C_S_DRIVER; // Now using the shield.h value!!!
67 
68  /*! Initialize the MCU hardware. */
73 
74  PRINTF("\r\n ISSDK FXLS8974 sensor driver example demonstration with poll mode\r\n");
75 
76  /*! Initialize the I2C driver. */
77  status = I2Cdrv->Initialize(I2C_S_SIGNAL_EVENT);
78  if (ARM_DRIVER_OK != status)
79  {
80  PRINTF("\r\n I2C Initialization Failed\r\n");
81  return -1;
82  }
83 
84  /*! Set the I2C Power mode. */
85  status = I2Cdrv->PowerControl(ARM_POWER_FULL);
86  if (ARM_DRIVER_OK != status)
87  {
88  PRINTF("\r\n I2C Power Mode setting Failed\r\n");
89  return -1;
90  }
91 
92  /*! Set the I2C bus speed. */
93  status = I2Cdrv->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
94  if (ARM_DRIVER_OK != status)
95  {
96  PRINTF("\r\n I2C Control Mode setting Failed\r\n");
97  return -1;
98  }
99 
100  /*! Initialize FXLS8974 sensor driver. */
102  &whoami);
103  if (ARM_DRIVER_OK != status)
104  {
105  PRINTF("\r\n Sensor Initialization Failed\r\n");
106  return -1;
107  }
108  if ((FXLS8964_WHOAMI_VALUE == whoami) || (FXLS8967_WHOAMI_VALUE == whoami))
109  {
110  PRINTF("\r\n Successfully Initialized Gemini with WHO_AM_I = 0x%X\r\n", whoami);
111  }
112  else if ((FXLS8974_WHOAMI_VALUE == whoami) || (FXLS8968_WHOAMI_VALUE == whoami))
113  {
114  PRINTF("\r\n Successfully Initialized Timandra with WHO_AM_I = 0x%X\r\n", whoami);
115  }
116  else if (FXLS8962_WHOAMI_VALUE == whoami)
117  {
118  PRINTF("\r\n Successfully Initialized Newstein with WHO_AM_I = 0x%X\r\n", whoami);
119  }
120  else
121  {
122  PRINTF("\r\n Bad WHO_AM_I = 0x%X\r\n", whoami);
123  return -1;
124  }
125 
126  /*! Set the task to be executed while waiting for I2C transactions to complete. */
128 
129  /*! Configure the FXLS8974 sensor. */
130  status = FXLS8974_I2C_Configure(&fxls8974Driver, cFxls8974ConfigNormal);
131  if (ARM_DRIVER_OK != status)
132  {
133  PRINTF("\r\n FXLS8974 Sensor Configuration Failed, Err = %d\r\n", status);
134  return -1;
135  }
136  PRINTF("\r\n Successfully Applied FXLS8974 Sensor Configuration\r\n");
137 
138  for (;;) /* Forever loop */
139  {
140  /*! Wait for data ready from the FXLS8974. */
141  status = FXLS8974_I2C_ReadData(&fxls8974Driver, cFxls8974DRDYEvent, &dataReady);
142  if (0 == (dataReady & FXLS8974_INT_STATUS_SRC_DRDY_MASK))
143  {
144  continue;
145  }
146 
147  /*! Read new raw sensor data from the FXLS8974. */
148  status = FXLS8974_I2C_ReadData(&fxls8974Driver, cFxls8974OutputNormal, data);
149  if (ARM_DRIVER_OK != status)
150  {
151  PRINTF("\r\n Read Failed. \r\n");
152  return -1;
153  }
154 
155  /*! Convert the raw sensor data to signed 16-bit container for display to the debug port. */
156  rawData.accel[0] = ((int16_t)data[1] << 8) | data[0];
157  rawData.accel[1] = ((int16_t)data[3] << 8) | data[2];
158  rawData.accel[2] = ((int16_t)data[5] << 8) | data[4];
159 
160  /* NOTE: PRINTF is relatively expensive in terms of CPU time, specially when used with-in execution loop. */
161  PRINTF("\r\nX=%5d Y=%5d Z=%5d\r\n", rawData.accel[0], rawData.accel[1], rawData.accel[2]);
162  ASK_USER_TO_RESUME(50); /* Ask for user input after processing 50 samples. */
163  }
164 }
This structure defines the Write command List.
Definition: sensor_drv.h:68
#define FXLS8974_SENS_CONFIG1_FSR_MASK
Definition: fxls8974.h:423
#define FXLS8974_INT_STATUS_SRC_DRDY_MASK
Definition: fxls8974.h:147
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
const registerwritelist_t cFxls8974ConfigNormal[]
Register settings for Normal (non buffered) mode.
This defines the sensor specific information for I2C.
Definition: fxls8974_drv.h:43
#define SMC
Definition: lpc54114.h:118
const registerreadlist_t cFxls8974DRDYEvent[]
Address of DATA Ready Status Register.
#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 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 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
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
#define FXLS8974_DATA_SIZE
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 BOARD_SystickEnable(void)
Function to enable systicks framework.
Definition: systick_utils.c:35
int main(void)
Main function.
#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.
#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 registerreadlist_t cFxls8974OutputNormal[]
Address of Raw Accel Data in Normal Mode.