Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: max32630fthr Adafruit_FeatherOLED USBDevice
SSMAX8614XComm.h
00001 /******************************************************************************* 00002 * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved. 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a 00005 * copy of this software and associated documentation files (the "Software"), 00006 * to deal in the Software without restriction, including without limitation 00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00008 * and/or sell copies of the Software, and to permit persons to whom the 00009 * Software is furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included 00012 * in all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00020 * OTHER DEALINGS IN THE SOFTWARE. 00021 * 00022 * Except as contained in this notice, the name of Maxim Integrated 00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated 00024 * Products, Inc. Branding Policy. 00025 * 00026 * The mere transfer of this software does not imply any licenses 00027 * of trade secrets, proprietary technology, copyrights, patents, 00028 * trademarks, maskwork rights, or any other form of intellectual 00029 * property whatsoever. Maxim Integrated Products, Inc. retains all 00030 * ownership rights. 00031 ******************************************************************************* 00032 */ 00033 00034 #ifndef _SSMAX8614XCOMM_H_ 00035 #define _SSMAX8614XCOMM_H_ 00036 00037 #include "mbed.h" 00038 #include "SensorComm.h" 00039 #include "USBSerial.h" 00040 #include "SSInterface.h" 00041 #include "queue.h" 00042 #include "bmi160.h" 00043 00044 #define SENSOR_ID_SSMAX8614X 0x04 00045 00046 #define PPG_CONF_LEVEL_FLASH_ADDRESS 0x0010F100 00047 #define PPG_EXPIRE_DURATION_FLASH_ADDRESS 0x0010F104 00048 00049 00050 /** 00051 * @brief SSMAX8614XComm Command handler class for communication with MAX30101 on SmartSensor board 00052 * @details 00053 */ 00054 class SSMAX8614XComm: public SensorComm 00055 { 00056 public: 00057 00058 /* PUBLIC FUNCTION DECLARATIONS */ 00059 /** 00060 * @brief SSMAX8614XComm constructor. 00061 * 00062 */ 00063 SSMAX8614XComm(USBSerial* USB, SSInterface* ssInterface, DSInterface* dsInterface); 00064 00065 /** 00066 * @brief Parses DeviceStudio-style commands. 00067 * @details Parses and executes commands. Prints return code to i/o device. 00068 * @returns true if sensor acted upon the command, false if command was unknown 00069 */ 00070 bool parse_command(const char* cmd); 00071 00072 /** 00073 * @brief Fill in buffer with sensor data 00074 * 00075 * @param[in] buf Buffer to fill data into 00076 * @param[in] size Maximum size of buffer 00077 * @param[out] Number of bytes written to buffer 00078 */ 00079 int data_report_execute(char* buf, int size); 00080 00081 /** 00082 * @brief Stop collecting data and disable sensor 00083 */ 00084 void stop(); 00085 00086 /** 00087 * @brief Get the maxim part number of the device 00088 */ 00089 const char* get_part_name() { return "max8614x"; } 00090 00091 /** 00092 * @brief Execute the smart sensor self test routine 00093 * 00094 * @return SS_SUCCESS or error code 00095 */ 00096 int selftest_max8614x(); 00097 00098 /** 00099 * @brief Execute the accelerometer self test routine 00100 * @return SS_SUCCESS or error code 00101 */ 00102 int selftest_accelerometer(); 00103 00104 /** 00105 * @brief Evaluate the accelerometer self test routine 00106 * 00107 * @param message - message to be printed in the failure cases 00108 * @param value - result of the self test passed as parameter 00109 * @return true if result is SUCCESSFULL false otherwise 00110 */ 00111 bool self_test_result_evaluate(const char *message, uint8_t value); 00112 00113 unsigned char get_sensor_id(); 00114 00115 void setBMI160(BMI160_I2C *pbmi160); 00116 00117 uint16_t instant_hr; 00118 uint16_t instant_hr_conf; 00119 uint8_t instant_hr_activityClass; 00120 00121 uint16_t instant_spo2; 00122 uint16_t instant_spo2_conf; 00123 uint8_t instant_spo2_percentage; 00124 uint8_t instant_lowSignalQualityFlag; 00125 00126 private: 00127 /* PRIVATE TYPE DEFINITIONS */ 00128 typedef enum _cmd_state_t { 00129 get_format_ppg_0, 00130 read_ppg_0, // moved here to match parser index "3" 00131 get_reg_ppg, 00132 set_reg_ppg, 00133 dump_reg_ppg, 00134 set_agc_dis, 00135 set_agc_en, 00136 self_test_ppg_os58, 00137 self_test_ppg_acc, 00138 //---------------------------WHRM_AEC_SCD ------- 00139 set_cfg_whrmaecscd_aecenable, 00140 get_cfg_whrmaecscd_aecenable, 00141 set_cfg_whrmaecscd_scdenable, 00142 get_cfg_whrmaecscd_scdenable, 00143 set_cfg_whrmaecscd_adjpdperiod, 00144 get_cfg_whrmaecscd_adjpdperiod, 00145 set_cfg_whrmaecscd_debouncewin, 00146 get_cfg_whrmaecscd_debouncewin, 00147 set_cfg_whrmaecscd_motionthreshold, 00148 get_cfg_whrmaecscd_motionthreshold, 00149 set_cfg_whrmaecscd_minpdcurrent, 00150 get_cfg_whrmaecscd_minpdcurrent, 00151 set_cfg_whrmaecscd_pdconfig, 00152 get_cfg_whrmaecscd_pdconfig, 00153 set_cfg_whrmaecscd_ledconfig, 00154 get_cfg_whrmaecscd_ledconfig, 00155 //------------------------------------------------ 00156 send_raw, 00157 set_cfg_accel_sh_dis, 00158 set_cfg_accel_sh_en, 00159 set_cfg_ppg_conf_level, 00160 set_cfg_ppg_expire_duration, 00161 NUM_CMDS, 00162 } cmd_state_t; 00163 00164 00165 typedef struct { 00166 uint32_t led1; 00167 uint32_t led2; 00168 uint32_t led3; 00169 uint32_t led4; 00170 uint32_t led5; 00171 uint32_t led6; 00172 } max8614x_mode1_data; 00173 00174 typedef struct __attribute__((packed)){ 00175 uint16_t hr; // mode 1 & 2 00176 uint8_t hr_conf; // mode 1 & 2 00177 uint16_t rr; // mode 1 & 2 00178 uint8_t activity_class; // mode 1 & 2 00179 uint8_t rr_conf; // mode 2 00180 uint32_t walk_steps; // mode 2 00181 uint32_t run_steps; // mode 2 00182 uint32_t kcal; // mode 2 00183 uint32_t cadence; // mode 2 00184 uint8_t is_led_cur_adj; // mode 2 00185 uint16_t adj_led_cur; // mode 2 00186 uint8_t is_t_int_cur_adj;// mode 2 00187 uint16_t adj_t_int_cur; // mode 2 00188 uint8_t is_f_smp_adj; // mode 2 00189 uint8_t adj_f_smp; // mode 2 00190 uint8_t smp_ave; // mode 2 00191 uint8_t state; // mode 2 00192 uint8_t is_high_motion; // mode 2 00193 uint8_t status; // mode 2 00194 } whrm_modeX_data; 00195 00196 typedef struct { 00197 int16_t x; 00198 int16_t y; 00199 int16_t z; 00200 } accel_mode1_data; 00201 00202 00203 typedef struct __attribute__((packed)) { 00204 uint32_t start_byte :8; 00205 00206 uint32_t sample_cnt :32; 00207 uint32_t led1 :20; 00208 uint32_t led2 :20; 00209 uint32_t led3 :20; 00210 uint32_t led4 :20; 00211 uint32_t led5 :20; 00212 uint32_t led6 :20; 00213 uint32_t x :14; //Represent values of 0.000 through 8.191 00214 uint32_t y :14; //Represent values of 0.000 through 8.191 00215 uint32_t z :14; //Represent values of 0.000 through 8.191 00216 uint32_t hr :12; //Represent values of 0.0 through 204.7 00217 uint32_t spo2 :11; //Represent values of 0.0 through 102.3 (only need up to 100.0) 00218 uint32_t status :8; 00219 00220 uint8_t :0; //Align CRC byte on byte boundary 00221 uint8_t crc8:8; 00222 } ds_pkt_data_mode1; 00223 00224 00225 typedef struct __attribute__((packed)) { 00226 uint32_t start_byte :8; 00227 uint32_t sample_cnt :16; 00228 uint32_t grnCnt :20; 00229 uint32_t grn2Cnt :20; 00230 uint32_t x :14; //Represent values of 0.000 through 8.191 00231 uint32_t y :14; //Represent values of 0.000 through 8.191 00232 uint32_t z :14; //Represent values of 0.000 through 8.191 00233 uint32_t hr :12; //Represent values of 0.0 through 204.7 00234 uint32_t hr_confidence :8; //Represent values of 0.0 through 100 00235 uint32_t rr :11; //Represent values of 0.0 through 102.3 (only need up to 100.0) 00236 uint32_t status :8; 00237 uint8_t :0; //Align CRC byte on byte boundary 00238 uint8_t crc8:8; 00239 } ds_pkt_data_mode2_compact; 00240 00241 typedef struct _accel_data_t { 00242 float x; 00243 float y; 00244 float z; 00245 int16_t x_raw; 00246 int16_t y_raw; 00247 int16_t z_raw; 00248 } accel_data_t; 00249 00250 /* PRIVATE VARIABLES */ 00251 int input_fifo_size; 00252 bool sensor_data_from_host; 00253 00254 BMI160_I2C *m_bmi160; 00255 00256 USBSerial *m_USB; 00257 SSInterface *ss_int; 00258 DSInterface *ds_int; 00259 00260 queue_t max8614x_queue; 00261 uint8_t max8614x_queue_buf[64 * sizeof(max8614x_mode1_data)]; 00262 00263 queue_t whrm_queue; 00264 uint8_t whrm_queue_buf[64 * sizeof(whrm_modeX_data)]; // use the bigger of model and 2 00265 00266 queue_t accel_output_queue; 00267 uint8_t accel_output_queue_buf[64 * sizeof(accel_mode1_data)]; 00268 00269 queue_t accel_input_queue; 00270 uint8_t accel_input_queue_buf[64 * sizeof(accel_mode1_data)]; 00271 00272 00273 ss_data_req max8614x_mode1_data_req; 00274 ss_data_req whrm_mode1_data_req; 00275 ss_data_req whrm_mode2_data_req; 00276 00277 ss_data_req accel_mode1_data_req; 00278 ss_data_req agc_mode1_data_req; 00279 00280 00281 bool agc_enabled; 00282 00283 // sensor and algo status 00284 status_algo_sensors_st sensor_algo_en_dis_; 00285 00286 /* PRIVATE CONST VARIABLES */ 00287 static const int SSMAX8614X_REG_SIZE = 1; 00288 static const int SSMAX8614X_MODE1_DATASIZE = 18; //Taken from API doc 00289 static const int SSWHRM_MODE1_DATASIZE = 6; //Taken from API doc 00290 static const int SSWHRM_MODEX_DATASIZE = 35; // For WHRM_AEC_SCD 00291 static const int SSACCEL_MODE1_DATASIZE = 6; //Taken from API doc 00292 static const int SSAGC_MODE1_DATASIZE = 0; //Taken from API doc 00293 00294 00295 /* PRIVATE METHODS */ 00296 void max8614x_data_rx(uint8_t *data_ptr); 00297 void whrm_data_rx_mode1(uint8_t *data_ptr); 00298 void whrm_data_rx_mode2(uint8_t *data_ptr); 00299 void accel_data_rx(uint8_t *data_ptr); 00300 void agc_data_rx(uint8_t *data_ptr); 00301 int get_sensor_xyz(accel_data_t&); 00302 int parse_cal_str(const char *ptr_ch, const char *cmd, uint8_t *cal_data, int cal_data_sz); 00303 int parse_str(const char *ptr_ch, const char *cmd, uint8_t *data, int data_sz); 00304 }; 00305 00306 #endif /* _SSMAX8614XCOMM_H_ */
Generated on Tue Jul 12 2022 20:09:29 by
