ISSDK  1.8
IoT Sensing Software Development Kit
fxls8962_motion_detection.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_motion_detection.c
11  * @brief The fxls8962_motion_detection.c file implements the ISSDK FXLS8962 sensor
12  * driver example demonstration for Motion Detection.
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 
35 //-----------------------------------------------------------------------
36 // Macros
37 //-----------------------------------------------------------------------
38 #define MD_SDCD_WT_DBCNT 0x00 /* Debounce count value. */
39 #define SDCD_LTHS_LSB 0xC0 /* Lower Threshold LSB value. */
40 #define SDCD_LTHS_MSB 0x0F /* Lower Threshold MSB value. */
41 #define SDCD_UTHS_LSB 0x40 /* Upper Threshold LSB value. */
42 #define SDCD_UTHS_MSB 0x00 /* Upper Threshold MSB value. */
43 
44 //-----------------------------------------------------------------------
45 // Constants
46 //-----------------------------------------------------------------------
47 /*! @brief Register Start Motion Detect Mode Register Write List. */
66 
67 //-----------------------------------------------------------------------
68 // Global Variables
69 //-----------------------------------------------------------------------
70 volatile bool gFxls8962EventReady = false;
71 
72 //-----------------------------------------------------------------------
73 // Functions
74 //-----------------------------------------------------------------------
75 /*! -----------------------------------------------------------------------
76  * @brief This is the Sensor Data Ready ISR implementation.
77  * @details This function sets the flag which indicates if a new sample(s) is available for reading.
78  * @param[in] pUserData This is a void pointer to the instance of the user specific data structure for the ISR.
79  * @return void There is no return value.
80  * @constraints None
81  * @reeentrant Yes
82  * -----------------------------------------------------------------------*/
83 void fxls8962_int_callback(void *pUserData)
84 { /*! @brief Set flag to indicate Sensor has signalled data ready. */
85  gFxls8962EventReady = true;
86 }
87 
88 /*! -----------------------------------------------------------------------
89  * @brief This is the The main function implementation.
90  * @details This function invokes board initializes routines, then then brings up the sensor and
91  * finally enters an endless loop to continuously read available samples.
92  * @param[in] void This is no input parameter.
93  * @return void There is no return value.
94  * @constraints None
95  * @reeentrant No
96  * -----------------------------------------------------------------------*/
97 int main(void)
98 {
100 
101  ARM_DRIVER_I2C *I2Cdrv = &I2C_S_DRIVER; // Now using the shield.h value!!!
104 
105  /*! Initialize the MCU hardware. */
106  BOARD_InitPins();
109 
110  PRINTF("\r\n ISSDK FXLS8962 sensor driver example for Orientation and Motion Detection.\r\n");
111 
112  /*! Initialize FXLS8962 pin used by FRDM board */
113  pGpioDriver->pin_init(&FXLS8962_INT1, GPIO_DIRECTION_IN, NULL, &fxls8962_int_callback, NULL);
114 
115  /*! Initialize the I2C driver. */
116  status = I2Cdrv->Initialize(I2C_S_SIGNAL_EVENT);
117  if (ARM_DRIVER_OK != status)
118  {
119  PRINTF("\r\n I2C Initialization Failed\r\n");
120  return -1;
121  }
122 
123  /*! Set the I2C Power mode. */
124  status = I2Cdrv->PowerControl(ARM_POWER_FULL);
125  if (ARM_DRIVER_OK != status)
126  {
127  PRINTF("\r\n I2C Power Mode setting Failed\r\n");
128  return -1;
129  }
130 
131  /*! Set the I2C bus speed. */
132  status = I2Cdrv->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
133  if (ARM_DRIVER_OK != status)
134  {
135  PRINTF("\r\n I2C Control Mode setting Failed\r\n");
136  return -1;
137  }
138 
139  /*! Initialize FXLS8962 sensor driver. */
142  if (SENSOR_ERROR_NONE != status)
143  {
144  PRINTF("\r\n Sensor Initialization Failed\r\n");
145  return -1;
146  }
147  PRINTF("\r\n Successfully Initiliazed Sensor\r\n");
148 
149  /*! Set the task to be executed while waiting for I2C transactions to complete. */
151 
152  /* Apply FXLS8962 Configuration for Motion Detection. */
153  status = FXLS8962_I2C_Configure(&fxls8962Driver, cFxls8962ConfigMotionDetect);
154  if (SENSOR_ERROR_NONE != status)
155  {
156  PRINTF("\r\n Write FXLS8962 Motion Configuration Failed!\r\n");
157  return -1;
158  }
159  PRINTF("\r\n Successfully Applied FXLS8962 Sensor Configuration\r\n");
160 
161  for (;;)
162  {
163  PRINTF("\r\n");
164  PRINTF("\r\n Waiting for Motion | MCU going to Deep Sleep Mode ...\r\n");
165  while (false == gFxls8962EventReady)
166  { /* Sleep, until Motion detection Interrupt is received. */
168  }
169 
170  gFxls8962EventReady = false;
171  PRINTF("\r\n Motion detected | MCU Wake-up ...\r\n");
172  }
173 }
#define FXLS8962_SDCD_CONFIG1_Z_OT_EN_MASK
Definition: fxls8962.h:1520
#define FXLS8962_SENS_CONFIG4_DRDY_PUL_DIS
Definition: fxls8962.h:664
This structure defines the Write command List.
Definition: sensor_drv.h:68
int32_t status
#define FXLS8962_SENS_CONFIG3_WAKE_ODR_0_781HZ
Definition: fxls8962.h:569
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 FXLS8962_INT_EN_SDCD_OT_EN_EN
Definition: fxls8962.h:861
#define FXLS8962_SDCD_CONFIG2_OT_DBCTM_MASK
Definition: fxls8962.h:1615
The fxls8962_drv.h file describes the FXLS8962AF driver interface and structures. ...
#define FXLS8962_INT1
volatile bool gFxls8962EventReady
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
#define FXLS8962_SDCD_CONFIG2_OT_DBCTM_CLEARED
Definition: fxls8962.h:1642
Access structure of the GPIO Driver.
Definition: Driver_GPIO.h:38
#define SMC
Definition: lpc54114.h:118
#define FXLS8962_SDCD_CONFIG2_SDCD_EN_MASK
Definition: fxls8962.h:1621
const registerwritelist_t cFxls8962ConfigMotionDetect[]
Register Start Motion Detect Mode Register Write List.
#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 MD_SDCD_WT_DBCNT
#define FXLS8962_SENS_CONFIG3_WAKE_ODR_MASK
Definition: fxls8962.h:551
#define FXLS8962_SENS_CONFIG4_DRDY_PUL_MASK
Definition: fxls8962.h:627
This defines the sensor specific information for I2C.
Definition: fxls8962_drv.h:44
#define FXLS8962_ORIENT_CONFIG_ORIENT_ENABLE_MASK
Definition: fxls8962.h:1190
#define FXLS8962_SDCD_CONFIG2_SDCD_EN_EN
Definition: fxls8962.h:1628
#define I2C_S_SIGNAL_EVENT
Definition: issdk_hal.h:34
#define I2C_S_DRIVER
Definition: issdk_hal.h:33
void fxls8962_int_callback(void *pUserData)
This is the Sensor Data Ready ISR implementation.
#define BOARD_BootClockRUN
Definition: clock_config.h:19
#define FXLS8962_SDCD_CONFIG2_REF_UPDM_MASK
Definition: fxls8962.h:1618
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
#define SDCD_UTHS_LSB
#define FXLS8962_INT_EN_SDCD_OT_EN_MASK
Definition: fxls8962.h:844
#define FXLS8962_SDCD_CONFIG1_Y_OT_EN_MASK
Definition: fxls8962.h:1523
ARM_DRIVER_I2C * I2Cdrv
#define FXLS8962_SDCD_CONFIG1_X_OT_EN_EN
Definition: fxls8962.h:1548
#define SDCD_LTHS_MSB
#define FXLS8962_SDCD_CONFIG2_WT_DBCTM_MASK
Definition: fxls8962.h:1612
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
#define FXLS8962_SDCD_CONFIG2_WT_DBCTM_CLEARED
Definition: fxls8962.h:1648
#define FXLS8962_SDCD_CONFIG1_X_OT_EN_MASK
Definition: fxls8962.h:1526
#define FXLS8962_SDCD_CONFIG1_Z_OT_EN_EN
Definition: fxls8962.h:1556
#define SDCD_UTHS_MSB
#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
#define FXLS8962_SDCD_CONFIG2_REF_UPDM_SDCD_REF
Definition: fxls8962.h:1633
int main(void)
This is the The main function implementation.
#define SDCD_LTHS_LSB
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 FXLS8962_ORIENT_CONFIG_ORIENT_ENABLE_DIS
Definition: fxls8962.h:1205
#define FXLS8962_SDCD_CONFIG1_Y_OT_EN_EN
Definition: fxls8962.h:1552