45 #include "clock_config.h" 46 #include "fsl_debug_console.h" 51 #include "Driver_I2C.h" 56 #include "issdk_hal.h" 58 #include "gpio_driver.h" 64 #define SDCD_LTHS_LSB 0xA0 65 #define SDCD_LTHS_MSB 0x0F 66 #define SDCD_UTHS_LSB 0x40 67 #define SDCD_UTHS_MSB 0x00 68 #define ASLP_COUNT_LSB 0xFA 69 #define ASLP_COUNT_MSB 0x00 70 #define FXLS8962_DATA_SIZE 6 124 const char *
pActivity[5] = {
"Unknown ",
"Rest ",
"Walking ",
"Jogging ",
"Running "};
135 .bits = {.config = 1},
144 .filtertime = 2, .male = 1,
157 .portPinConfig = {.pullSelect = kPORT_PullUp, .mux = kPORT_MuxAsGpio},
158 .interruptMode = kPORT_InterruptFallingEdge,
190 uint16_t lastReportedSteps;
205 PRINTF(
"\r\n ISSDK FXLS8962 sensor driver example for Motion Activated Pedometer.\r\n");
215 if (ARM_DRIVER_OK != status)
217 PRINTF(
"\r\n I2C Initialization Failed\r\n");
222 status = I2Cdrv->PowerControl(ARM_POWER_FULL);
223 if (ARM_DRIVER_OK != status)
225 PRINTF(
"\r\n I2C Power Mode setting Failed\r\n");
230 status = I2Cdrv->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
231 if (ARM_DRIVER_OK != status)
233 PRINTF(
"\r\n I2C Control Mode setting Failed\r\n");
242 PRINTF(
"\r\n Sensor Initialization Failed\r\n");
251 fxls8962Driver.
slaveAddress, cFxls8962ConfigInitialize);
254 PRINTF(
"\r\n Write FXLS8962 Initialization Failed.\r\n");
260 PRINTF(
"\r\n Pedometer successfully Initialized and Ready for measurements.");
271 PRINTF(
"\r\n Write FXLS8962 Motion Configuration Failed!\r\n");
277 PRINTF(
"\r\n\r\n Waiting for Motion | MCU switching to Sleep Mode ...\r\n");
294 if (ARM_DRIVER_OK != status)
296 PRINTF(
"\r\n Read INT Status Failed!\r\n");
305 PRINTF(
" Motion detected...\r\n");
311 PRINTF(
"\r\n Write FXLS8962 DRDY Configuration Failed.\r\n");
314 motionDetect =
false;
322 if (ARM_DRIVER_OK != status)
324 PRINTF(
"\r\n ERROR : Read Data Failed!\r\n");
329 rawData.
accel[0] = ((int16_t)data[1] << 8) | data[0];
330 rawData.
accel[0] *= 16;
331 rawData.
accel[1] = ((int16_t)data[3] << 8) | data[2];
332 rawData.
accel[1] *= 16;
333 rawData.
accel[2] = ((int16_t)data[5] << 8) | data[4];
334 rawData.
accel[2] *= 16;
346 PRINTF(
"\r\n | Steps | Distance | Speed | Calories | Activity |\r\n");
348 PRINTF(
"\033[K | %5d | %4dm | %2dkmph | %3d | %s |\r",
const registerwritelist_t cFxls8962ConfigInitialize[]
FXLS8962 Motion based Pedometer Register Write List.
void fxls8962_int_callback(void *pUserData)
This is the Sensor Event Ready ISR implementation.
void pedometer_init(pedometer_t *pPedometer)
The interface function initialize the pedometer.
This defines the configuration structure of the pedometer.
#define FXLS8962_SENS_CONFIG4_WK_SDCD_OT_MASK
The pedometer.h file contains the interface and structure definitions for pedometer application...
This structure defines the fxls8962 raw data buffer.
#define FXLS8962_SDCD_CONFIG1_Z_OT_EN_EN
#define __END_WRITE_DATA__
const registerreadlist_t cFxls8962INTStatus[]
Address of INT Status Register.
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.
#define FXLS8962_SENS_CONFIG3_WAKE_ODR_50HZ
void(* pin_init)(pinID_t aPinId, gpio_direction_t dir, void *apPinConfig, gpio_isr_handler_t aIsrHandler, void *apUserData)
const char * pActivity[5]
Pedometer Mode Name Strings.
#define BOARD_BootClockRUN
const registerwritelist_t cFxls8962ConfigDataReady[]
FXLS8962 DRDY and ASLP Detect Mode Register Write List.
#define FXLS8962_SDCD_CONFIG1_Y_OT_EN_EN
This defines the sensor specific information for I2C.
const registerreadlist_t cFxls8962Output[]
Address of Data Output Registers.
uint8_t data[FXLS8962_DATA_SIZE]
int32_t FXLS8962_I2C_Configure(fxls8962_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
#define FXLS8962_SDCD_CONFIG2_SDCD_EN_EN
void(* toggle_pin)(pinID_t aPinId)
This defines the acceleration input data for the pedometer.
volatile bool gFxls8962EventReady
The GPIO Configuration KSDK.
void FXLS8962_I2C_SetIdleTask(fxls8962_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
#define FXLS8962_SENS_CONFIG3_SLEEP_ODR_MASK
void BOARD_InitDebugConsole(void)
#define FXLS8962_SDCD_CONFIG1_X_OT_EN_EN
#define FXLS8962_SENS_CONFIG4_INT_POL_ACT_LOW
registerDeviceInfo_t deviceInfo
#define FXLS8962_SDCD_CONFIG2_WT_DBCTM_CLEARED
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
fxls8962_i2c_sensorhandle_t fxls8962Driver
#define __END_READ_DATA__
This defines the pedometer instance.
GENERIC_DRIVER_GPIO * pGpioDriver
#define FXLS8962_SDCD_CONFIG2_OT_DBCTM_CLEARED
#define FXLS8962_INT_EN_SDCD_OT_EN_EN
#define FXLS8962_I2C_ADDR
pedometer_config_t cPedoConfig
#define FXLS8962_SENS_CONFIG4_INT_POL_MASK
gpioHandleKSDK_t GREEN_LED
#define FXLS8962_SENS_CONFIG3_WAKE_ODR_MASK
debounce_count_t sleepcount_threshold
union pedometer_t::pedometer_status_tag::@292 status
gpio_pin_config_t pinConfig
const registerwritelist_t cFxls8962ConfigMotionDetect[]
FXLS8962 Motion Detect Mode Register Write List.
void(* set_pin)(pinID_t aPinId)
void(* clr_pin)(pinID_t aPinId)
void pedometer_configure(pedometer_t *pPedometer, const pedometer_config_t *pConfig)
The interface function to configure the pedometer.
#define FXLS8962_SDCD_CONFIG2_REF_UPDM_SDCD_REF
The fxls8962_drv.h file describes the FXLS8962AF driver interface and structures. ...
int32_t pedometer_run(pedometer_t *pPedometer, ped_accel_t *pData)
The interface function excutes the pedometer algorithm.
#define I2C_S_DEVICE_INDEX
#define FXLS8962_INT_STATUS_SRC_ASLP_MASK
gpioConfigKSDK_t gpioConfigINT1
GENERIC_DRIVER_GPIO Driver_GPIO_KSDK
#define FXLS8962_WHOAMI_VALUE
#define FXLS8962_DATA_SIZE
ARM_DRIVER_I2C * pCommDrv
struct pedometer_t::pedometer_status_tag status
Access structure of the GPIO Driver.
int main(void)
This is the The main function implementation.
#define FXLS8962_INT_STATUS_SRC_SDCD_OT_MASK
fxls8962_acceldataUser_t rawData
This structure defines the Write command List.
This structure defines the Read command List.
struct pedometer_t::pedometer_status_tag::@292::@293 bits
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.
status_t SMC_SetPowerModeWait(void *arg)
Configures the system to WAIT power mode. API name used from Kinetis family to maintain compatibility...
void BOARD_InitPins(void)
Configures pin routing and optionally pin electrical features.
#define FXLS8962_INT_EN_DRDY_EN_EN
#define FXLS8962_INT_EN_ASLP_EN_EN
#define FXLS8962_SENS_CONFIG3_SLEEP_ODR_0_781HZ
#define I2C_S_SIGNAL_EVENT
int32_t Sensor_I2C_Write(ARM_DRIVER_I2C *pCommDrv, registerDeviceInfo_t *devInfo, uint16_t slaveAddress, const registerwritelist_t *pRegWriteList)
Write register data to a sensor.
#define FXLS8962_SENS_CONFIG4_WK_SDCD_OT_EN