ISSDK  1.8
IoT Sensing Software Development Kit
pedometer_stepcount_fxos8700.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 pedometer_stepcount_fxos8700.c
11  * @brief The pedometer_stepcount_fxos8700.c file implements the ISSDK prdometer
12  * example using FXOS8700 sensor as the acceleration source.
13  */
14 
15 /* SDK Includes */
16 #include "pin_mux.h"
17 #include "clock_config.h"
18 #include "board.h"
19 #include "fsl_debug_console.h"
20 
21 /* CMSIS Includes */
22 #include "Driver_I2C.h"
23 
24 /* ISSDK Includes */
25 #include "issdk_hal.h"
26 #include "pedometer.h"
27 #include "fxos8700_drv.h"
28 
29 /*******************************************************************************
30  * Macro Definitions
31  ******************************************************************************/
32 #define RAW_ACCEL_DATA_SIZE (6)
33 
34 /*******************************************************************************
35  * Constants
36  ******************************************************************************/
37 
38 /* Configure the fxos8700 to STANDBY and 50Hz sampling rate.
39  * fxos8700 is used as the acceleration source for the pedometer */
41  /*! System and Control registers. */
42  /*! Configure the fxos8700 to 50Hz sampling rate. */
44  /* Configure the fxos8700 as accel only mode.*/
47 /* Pedometer configuration. These configuration are algorithm and user dependent data. */
48 static const pedometer_config_t pedo_config = {
50  .bits = {.config = 1},
51  .keynetik =
52  {
53  .height = 175,
54  .weight = 80,
55  .filtersteps = PEDO_FILTER_STEPS_DEFAULT,
56  .bits =
57  {
58  .filtertime = PEDO_FILTER_TIME_DEFAULT,
59  },
60  .speedperiod = PEDO_SPEED_PERIOD_DEFAULT,
61  .stepthreshold = PEDO_STEP_THRESHOLD_DEFAULT,
62  },
63  .stepcoalesce = 1,
64  .oneG = PEDO_ONEG_2G, // It is the One G representation in 2G scale.
65  .frequency = PEDO_FREQHZ_DEFAULT, // It is 50 HZ
66 
67 };
68 
69 /*! Command definition to read the Data Ready Status */
71 
72 /*! Command definition to read the Accel Data */
75 
76 /*******************************************************************************
77  * Code
78  ******************************************************************************/
79 
80 /*!
81  * @brief Main function
82  */
83 
84 int main(void)
85 {
87  uint8_t readBuffer[RAW_ACCEL_DATA_SIZE];
89  FXOS8700_DR_STATUS_t drStatus;
90 
91  ARM_DRIVER_I2C *I2Cdrv = &I2C_S_DRIVER; // Now using the shield.h value!!!
92  fxos8700_i2c_sensorhandle_t FXOS8700drv;
93  pedometer_t pedometer; /* This handle holds the current configuration and status value for the pedometer.*/
94 
95  /*! Initialize the MCU hardware. */
99 
100  PRINTF("\r\n ISSDK Pedometer Example using FXOS8700 sensor as the acceleration source\r\n");
101 
102  /*! Initialize the I2C driver. */
103  status = I2Cdrv->Initialize(I2C_S_SIGNAL_EVENT);
104  if (ARM_DRIVER_OK != status)
105  {
106  PRINTF("\r\n I2C Initialization Failed\r\n");
107  return -1;
108  }
109 
110  /*! Set the I2C Power mode. */
111  status = I2Cdrv->PowerControl(ARM_POWER_FULL);
112  if (ARM_DRIVER_OK != status)
113  {
114  PRINTF("\r\n I2C Power Mode setting Failed\r\n");
115  return -1;
116  }
117 
118  /*! Set the I2C bus speed. */
119  status = I2Cdrv->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
120  if (ARM_DRIVER_OK != status)
121  {
122  PRINTF("\r\n I2C Control Mode setting Failed\r\n");
123  return -1;
124  }
125 
126  /*! Initialize the FXOS8700 sensor driver. */
129  if (SENSOR_ERROR_NONE != status)
130  {
131  PRINTF("\r\n Sensor Initialization Failed\r\n");
132  return -1;
133  }
134  PRINTF("\r\n Successfully Initialized Sensor\r\n");
135 
136  /*! Set the task to be executed while waiting for I2C transactions to complete. */
138 
139  /*! Configure the fxos8700 sensor driver. */
140  status = FXOS8700_I2C_Configure(&FXOS8700drv, fxos8700_Config);
141  if (SENSOR_ERROR_NONE != status)
142  {
143  PRINTF("\r\n FXOS8700 Sensor Configuration Failed, Err = %d\r\n", status);
144  return -1;
145  }
146  PRINTF("\r\n Successfully Applied FXOS8700 Sensor Configuration\r\n");
147 
148  /* Initialize the pedometer*/
149  pedometer_init(&pedometer);
150 
151  /*configure the pedometer*/
152  pedometer_configure(&pedometer, &pedo_config);
153 
154  for (;;)
155  {
156  /* Poll, waiting for the data ready event.*/
157  status = FXOS8700_I2C_ReadData(&FXOS8700drv, FXOS8700_STATUS_READ, (uint8_t *)&drStatus);
158  if (0 == (drStatus.b.zyxdr))
159  {
160  continue;
161  }
162 
163  /* Read the raw accel data from the fxos8700.*/
164  status = FXOS8700_I2C_ReadData(&FXOS8700drv, FXOS8700_ACCEL_READ, readBuffer);
165  if (ARM_DRIVER_OK != status)
166  {
167  continue;
168  }
169  rawData.accel[0] = ((int16_t)readBuffer[0] << 8) | readBuffer[1];
170  rawData.accel[1] = ((int16_t)readBuffer[2] << 8) | readBuffer[3];
171  rawData.accel[2] = ((int16_t)readBuffer[4] << 8) | readBuffer[5];
172 
173  /* Execute the pedometer Algorithm */
174  pedometer_run(&pedometer, (ped_accel_t *)&rawData.accel);
175 
176  PRINTF("\r\n StepCount = %d \r\n", pedometer.status.stepcount);
177  }
178 }
179 ////////////////////////////////////////////////////////////////////////////////
180 // EOF
181 ////////////////////////////////////////////////////////////////////////////////
struct pedometer_t::pedometer_status_tag status
int32_t FXOS8700_I2C_Initialize(fxos8700_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: fxos8700_drv.c:222
int main(void)
Main function.
void pedometer_configure(pedometer_t *pPedometer, const pedometer_config_t *pConfig)
The interface function to configure the pedometer.
Definition: pedometer.c:111
This structure defines the Write command List.
Definition: sensor_drv.h:68
int32_t status
The pedometer.h file contains the interface and structure definitions for pedometer application...
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 FXOS8700_WHO_AM_I_PROD_VALUE
Definition: fxos8700.h:146
#define PEDO_FILTER_STEPS_DEFAULT
Definition: pedometer.h:35
#define SMC
Definition: lpc54114.h:118
This defines the configuration structure of the pedometer.
Definition: pedometer.h:46
#define __END_WRITE_DATA__
Definition: sensor_drv.h:45
debounce_count_t sleepcount_threshold
Definition: pedometer.h:50
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
#define PEDO_FREQHZ_DEFAULT
Definition: pedometer.h:31
#define I2C_S_SIGNAL_EVENT
Definition: issdk_hal.h:34
This defines the sensor specific information for I2C.
Definition: fxos8700_drv.h:44
#define I2C_S_DRIVER
Definition: issdk_hal.h:33
int32_t FXOS8700_I2C_Configure(fxos8700_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
Definition: fxos8700_drv.c:260
#define RAW_ACCEL_DATA_SIZE
#define PEDO_ONEG_2G
Definition: pedometer.h:30
This defines the pedometer instance.
Definition: pedometer.h:73
int32_t FXOS8700_I2C_ReadData(fxos8700_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: fxos8700_drv.c:305
This defines the acceleration input data for the pedometer.
Definition: pedometer.h:39
const registerwritelist_t fxos8700_Config[]
#define BOARD_BootClockRUN
Definition: clock_config.h:19
#define FXOS8700_CTRL_REG1_DR_SINGLE_50_HZ
Definition: fxos8700.h:1522
#define PEDO_FILTER_TIME_DEFAULT
Definition: pedometer.h:34
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
Definition: sensor_drv.h:97
const registerreadlist_t FXOS8700_STATUS_READ[]
This structure defines the fxos8700 raw accel data buffer.
Definition: fxos8700_drv.h:61
const registerreadlist_t FXOS8700_ACCEL_READ[]
#define __END_READ_DATA__
Definition: sensor_drv.h:51
ARM_DRIVER_I2C * I2Cdrv
fxos8700_accelmagdata_t rawData
#define FXOS8700_M_CTRL_REG2_M_AUTOINC_ACCEL_ONLY_MODE
Definition: fxos8700.h:2653
uint16_t readFrom
Definition: sensor_drv.h:80
The fxos8700_drv.h file describes the fxos8700 driver interface and structures.
#define PEDO_SPEED_PERIOD_DEFAULT
Definition: pedometer.h:33
This structure defines the Read command List.
Definition: sensor_drv.h:78
int32_t pedometer_run(pedometer_t *pPedometer, ped_accel_t *pData)
The interface function excutes the pedometer algorithm.
Definition: pedometer.c:125
#define I2C_S_DEVICE_INDEX
Definition: issdk_hal.h:35
#define PEDO_STEP_THRESHOLD_DEFAULT
Definition: pedometer.h:32
void FXOS8700_I2C_SetIdleTask(fxos8700_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
Definition: fxos8700_drv.c:252
void BOARD_InitDebugConsole(void)
Definition: board.c:15
void pedometer_init(pedometer_t *pPedometer)
The interface function initialize the pedometer.
Definition: pedometer.c:97
#define FXOS8700_I2C_ADDR
void BOARD_InitPins(void)
Configures pin routing and optionally pin electrical features.
Definition: pin_mux.c:47