1 /* 2 * Copyright (c) 2015, 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.h 11 * @brief The pedometer.h file contains the interface and structure definitions for 12 * pedometer application. 13 */ 14 15 #ifndef PEDOMETER_H_ 16 #define PEDOMETER_H_ 17 18 #include <stddef.h> 19 #include <stdint.h> 20 #include <stdbool.h> 21 #include "KeynetikPedometer.h" 22 /****************************************************************************** 23 * Public Datatypes 24 *****************************************************************************/ 25 26 typedef KeynetikActivityLevel activitylevel_t; /* alias to a shorter name for readability */ 27 typedef uint16_t debounce_count_t; 28 #define PEDO_ONEG_8G 4096 /* One G value for 8G mode.*/ 29 #define PEDO_ONEG_4G 8192 /* One G value for 4G mode.*/ 30 #define PEDO_ONEG_2G 16384 /* One G value for 2G mode.*/ 31 #define PEDO_FREQHZ_DEFAULT 50 /* Default frequency*/ 32 #define PEDO_STEP_THRESHOLD_DEFAULT 130 33 #define PEDO_SPEED_PERIOD_DEFAULT 5 34 #define PEDO_FILTER_TIME_DEFAULT 3 35 #define PEDO_FILTER_STEPS_DEFAULT 4 36 /*! 37 * @brief This defines the acceleration input data for the pedometer. 38 */ 39 typedef struct 40 { 41 int16_t accel[3]; 42 } ped_accel_t; 43 /*! 44 * @brief This defines the configuration structure of the pedometer. 45 */ 46 typedef struct 47 { 48 uint16_t sleepminimum; /* Sleep vector magnitude minimum */ 49 uint16_t sleepmaximum; /* Sleep vector magnitude maximum */ 50 debounce_count_t sleepcount_threshold; /* Sleep debounce counter threshold */ 51 struct 52 { 53 uint8_t : 5; /* Reserved */ 54 bool sleep_dbcntm : 1; /* Sleep debounce counter mode. Set to 1 to clear the debounce counter when the test 55 condition fails, otherwise decrement. */ 56 bool activity_dbcntm : 1; /* Activity debounce counter mode. Set to 1 to clear the debounce counter when the 57 test condition fails, otherwise decrement. */ 58 bool config : 1; /* Set to 1 to initialize the pedometer and configure it with the other configuration 59 variables. */ 60 } bits; 61 KeynetikConfig keynetik; /* Keynetik parameters (step length, height, weight, etc) */ 62 debounce_count_t activitycount_threshold; /* Activity debounce counter threshold */ 63 uint8_t stepcoalesce; /* Number of steps to coalesce for step interrupt */ 64 uint16_t oneG; /* One G value for the range at accelerometer is running. refer the data sheet of the accelerometer 65 and compute this value. 66 eg. 2G Mode, 1G is 4096.*/ 67 uint16_t frequency; /* The frequency at which accelerometer runs in HZ. best set frequencies are 25HZ or 50HZ. It 68 can run at higher too.*/ 69 } pedometer_config_t; 70 /*! 71 * @brief This defines the pedometer instance. 72 */ 73 typedef struct 74 { 75 struct pedometer_status_tag 76 { 77 union 78 { 79 struct 80 { 81 activitylevel_t activity : 3; /* Activity level. */ 82 bool suspend : 1; /* Pedometer autonomously suspended. */ 83 bool activitychange : 1; /* Change in activity level. */ 84 bool stepchange : 1; /* Change in step count. */ 85 bool suspendchange : 1; /* Change in suspend state .*/ 86 bool mergedflags : 1; /* Merged status flags. */ 87 } bits; 88 uint8_t byte; 89 } status; 90 uint8_t version; /* Pedometer version number. */ 91 uint16_t stepcount; /* Step count. */ 92 uint16_t distance; /* Total distance in meters or activity state. */ 93 uint16_t speed; /* Average speed in meters per hour. The value is updated on the completion of each step. */ 94 uint16_t calories; /* Calorie count expended. */ 95 debounce_count_t sleepcount; /* Sleep debounce counter. */ 96 } status; 97 pedometer_config_t config; /* Pedometer configuration.*/ 98 struct pedometer_private_tag 99 { 100 debounce_count_t activitycount; /* Activity debounce counter. */ 101 uint16_t stepchg_stepcount; /* Step count at last stepchange interrupt (for step coalesing) */ 102 } private; 103 } pedometer_t; 104 105 /****************************************************************************** 106 * Public Function Declarations 107 ******************************************************************************/ 108 /******************************************************************************* 109 * API 110 ******************************************************************************/ 111 /*! @brief The interface function initialize the pedometer. 112 * @details This function initialize the pedometer structure and return the handle. 113 114 * @param[in] pPedometer handle to the pedometer. 115 * 116 * @return void. 117 * 118 * @Constraints None 119 * 120 * @Reentrant Yes 121 */ 122 void pedometer_init(pedometer_t *pPedometer); 123 124 /*! @brief The interface function to configure the pedometer. 125 * 126 * @param[in] pedometer_t handle to the pedometer. 127 * @param[in] config configuration value. 128 * 129 * @return void. 130 * 131 * @Constraints None 132 * 133 * @Reentrant Yes 134 */ 135 void pedometer_configure(pedometer_t *pPedometer, const pedometer_config_t *pConfig); 136 /*! @brief The interface function excutes the pedometer algorithm. 137 * @details Call this function the rate at which accelerometer runs. 138 139 * @param[in] pPedometer handle to the pedometer. 140 * @param[in] accel_data acceleration data. 141 * @return ::pedometer_run() returns the status . 142 * 143 * @Constraints None 144 * 145 * @Reentrant Yes 146 */ 147 int32_t pedometer_run(pedometer_t *pPedometer, ped_accel_t *pData); 148 149 #endif // PEDOMETER_H_ 150