Example host software to display SpO2 or Heart Rate on wrist using the MAX32664GWEC or MAXREFDES101 with IR/Red LED board. It is recommended that the MAX32664 be loaded with the latest Maxim supplied algorithm (.msbl file).
Dependencies: Maxim_Sensor_Hub_Communications BMI160 demoUI max32630hsp3
Fork of Host_Software_MAX32664GWEC_SpO2_HR by
SH_Max8614x_BareMetal.cpp
00001 /******************************************************************************* 00002 * Copyright (C) 2018 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 #include "SH_Max8614x_BareMetal.h" 00034 #include "SHComm.h" 00035 #include "HostAccelHelper.h" 00036 #include <string.h> //for memset 00037 #include <stdint.h> 00038 00039 uint16_t HrmResult = 0; 00040 uint16_t SPO2Result = 0; 00041 uint8_t HrmConfidence = 0; 00042 uint8_t SPo2Confidence = 0; 00043 00044 00045 00046 #if defined(DEBUG_INFO) 00047 #define __DBGMESSAGE( str , val ) {printf(str, val);} 00048 #else 00049 #define __DBGMESSAGE( str , val ) 00050 #endif 00051 00052 00053 // Defines 00054 #define SSMAX8614X_REG_SIZE 1 00055 #define SSMAX8614X_MODE1_DATASIZE 18 //Taken from API doc 00056 #define SSWHRM_MODE1_DATASIZE 6 //Taken from API doc 00057 #define SSWSPO2_MODE1_DATASIZE 9 // added for wspo2 00058 #define SSACCEL_MODE1_DATASIZE 6 //Taken from API doc 00059 #define SSAGC_MODE1_DATASIZE 0 //Taken from API doc 00060 #define SSBPT_MODE1_2_DATASIZE 4 //Taken from API doc /* TODO */ 00061 00062 #define MIN_MACRO(a,b) ((a)<(b)?(a):(b)) 00063 00064 // sensor configuration 00065 //#define ENABLE_SENSOR_HUB_ACCEL 00066 #define USE_HOST_ACCEL 00067 // algorithm configuration 00068 #define ENABLE_WHRM_AND_SP02 00069 #define ENABLE_WSP02 00070 // end of senor and algorithm configuration 00071 #define MAX_NUM_WR_ACC_SAMPLES 5 00072 #define BMI160_SAMPLE_RATE 25 00073 // end of defines 00074 00075 //function pointer use to perform arithmetic operation 00076 typedef void (*rx_data_callback)(uint8_t *); 00077 typedef struct { 00078 int data_size; 00079 rx_data_callback rx_data_parser; 00080 } ss_data_req; 00081 00082 typedef struct { 00083 int16_t x; 00084 int16_t y; 00085 int16_t z; 00086 } accel_mode1_data; 00087 00088 typedef struct { 00089 uint32_t led1; 00090 uint32_t led2; 00091 uint32_t led3; 00092 uint32_t led4; 00093 uint32_t led5; 00094 uint32_t led6; 00095 } max8614x_mode1_data; 00096 00097 typedef struct { 00098 uint16_t hr; 00099 uint8_t hr_conf; 00100 uint16_t spo2; 00101 uint8_t status; 00102 } whrm_mode1_data; 00103 00104 00105 typedef struct { /// added for WSPO2 00106 uint16_t r; 00107 uint8_t spo2_conf; 00108 uint16_t spo2; 00109 uint8_t percentComplete; 00110 uint8_t lowSignalQualityFlag; 00111 uint8_t motionFlag; 00112 uint8_t status; //isSpo2Calculated; 00113 } wspo2_mode1_data; 00114 00115 typedef struct Max86140_SH_Status_Tracker { 00116 uint8_t sensor_data_from_host; 00117 uint8_t data_type_enabled; // what type of data is enabled 00118 uint8_t sample_count_enabled; // does me11 provide sample count 00119 uint32_t sample_count; 00120 uint8_t data_buf_storage[512]; // store data read from SH 00121 ss_data_req algo_callbacks[SH_NUM_CURRENT_ALGOS]; 00122 ss_data_req sensor_callbacks[SH_NUM_CURRENT_SENSORS]; 00123 uint8_t sensor_enabled_mode[SH_NUM_CURRENT_SENSORS]; 00124 uint8_t algo_enabled_mode[SH_NUM_CURRENT_ALGOS]; 00125 int input_fifo_size; 00126 } Max86140_SH_Status_Tracker_t; 00127 00128 // Max8614x Default Callbacks 00129 void max8614x_data_rx(uint8_t* data_ptr) 00130 { 00131 max8614x_mode1_data sample; 00132 sample.led1 = (data_ptr[0] << 16) | (data_ptr[1] << 8) | data_ptr[2]; 00133 sample.led2 = (data_ptr[3] << 16) | (data_ptr[4] << 8) | data_ptr[5]; 00134 sample.led3 = (data_ptr[6] << 16) | (data_ptr[7] << 8) | data_ptr[8]; 00135 sample.led4 = (data_ptr[9] << 16) | (data_ptr[10] << 8) | data_ptr[11]; 00136 sample.led5 = (data_ptr[12] << 16) | (data_ptr[13] << 8) | data_ptr[14]; 00137 sample.led6 = (data_ptr[15] << 16) | (data_ptr[16] << 8) | data_ptr[17]; 00138 00139 //printf("led1=%.6X led2=%.6X led3=%.6X led4=%.6X led5=%.6X led6=%.6X\r\n", 00140 // sample.led1, sample.led2, sample.led3, sample.led4, sample.led5, sample.led6); 00141 00142 //enqueue(&max8614x_queue, &sample); 00143 } 00144 void whrm_data_rx(uint8_t* data_ptr) { 00145 //See API doc for data format 00146 whrm_mode1_data sample; 00147 sample.hr = (data_ptr[0] << 8) | data_ptr[1]; 00148 sample.hr_conf = data_ptr[2]; 00149 sample.spo2 = (data_ptr[3] << 8) | data_ptr[4]; 00150 sample.status = data_ptr[5]; 00151 HrmResult = sample.hr / 10; 00152 HrmConfidence = sample.hr_conf; 00153 //printf("hr_c=%d\r\n", HrmResult); 00154 #if defined(DEBUG_INFO) 00155 printf("hr=%.1f conf=%d spo2=%d status=%d\r\n", (float)sample.hr / 10.0, sample.hr_conf, sample.spo2, sample.status); 00156 #endif 00157 //enqueue(&whrm_queue, &sample); 00158 } 00159 00160 void wspo2_data_rx(uint8_t* data_ptr) 00161 { 00162 //See API doc for data format 00163 wspo2_mode1_data sample; 00164 sample.r = (data_ptr[0] << 8) | data_ptr[1]; // already x10 00165 sample.spo2_conf = data_ptr[2]; 00166 sample.spo2 = (data_ptr[3] << 8) | data_ptr[4]; // already x10 00167 sample.percentComplete = data_ptr[5]; 00168 sample.lowSignalQualityFlag = data_ptr[6]; 00169 sample.motionFlag = data_ptr[7]; 00170 sample.status = data_ptr[8]; 00171 SPO2Result = sample.spo2 / 10; 00172 SPo2Confidence = sample.spo2_conf; 00173 #if defined(DEBUG_INFO) 00174 printf("r=%.1f SpO2Conf=%d SpO2=%.1f prcntComp=%d lowSig=%d motion=%d isCalc=%d\r\n", (float)sample.r / 10.0, sample.spo2_conf, (float)sample.spo2/10.0, sample.percentComplete, sample.lowSignalQualityFlag , sample.motionFlag, sample.status); 00175 #endif 00176 //enqueue(&wspo2_queue, &sample); 00177 } 00178 00179 void accel_data_rx(uint8_t* data_ptr) { 00180 //See API doc for data format 00181 accel_mode1_data sample; 00182 sample.x = (data_ptr[0] << 8) | data_ptr[1]; 00183 sample.y = (data_ptr[2] << 8) | data_ptr[3]; 00184 sample.z = (data_ptr[4] << 8) | data_ptr[5]; 00185 //printf("x:%d, y:%d, z:%d\r\n", sample.x, sample.y, sample.z); 00186 } 00187 00188 void agc_data_rx(uint8_t* data_ptr) { 00189 //NOP: AGC does not collect data 00190 } 00191 // end of Max8614x Default Callbacks 00192 00193 00194 static Max86140_SH_Status_Tracker * get_config_struct() { 00195 00196 /* assigns a static adress to configuration struct*/ 00197 static Max86140_SH_Status_Tracker glbl_max8614x_status_track; 00198 return &glbl_max8614x_status_track; 00199 } 00200 00201 void initialize_config_struct() { 00202 Max86140_SH_Status_Tracker *p_glbl_max8614x_status_track = get_config_struct(); 00203 /* 00204 * Desc: Configuration init flow, Perform this action at init stage of data acquisition. Raw sesnsor data buffer pointer is input to each 00205 * enabled sensor/algorithm,s funtion that is responsible to extract numeric data from data byte stream from sensor hub. 00206 * 00207 * - Append Sensor Raw Data structure with raw sensor data sample size and pointer to function of sensor that is reposible to parse 00208 * data byte stream from sesnor hub and extract sensor numeric data. 00209 * - Append accompanying sensors to main state of sensor. ie Accelerometer from Host with sensor data sample size and pointer to function of 00210 * sensor that is reposible to parse data byte stream from sesnor hub and extract sensor numeric data. 00211 * - Append algorithms to be enabled with algorithm data sample size and pointer to function of 00212 * algorithm that is reposible to parse data byte stream from sensor hub and extract sensor numeric data. 00213 * 00214 * */ 00215 00216 //set all the values to 0 00217 memset(p_glbl_max8614x_status_track, 0, sizeof(*p_glbl_max8614x_status_track)); 00218 // max8614x 00219 p_glbl_max8614x_status_track->sensor_callbacks[SH_SENSORIDX_MAX8614X].data_size = SSMAX8614X_MODE1_DATASIZE; 00220 p_glbl_max8614x_status_track->sensor_callbacks[SH_SENSORIDX_MAX8614X].rx_data_parser = &max8614x_data_rx; 00221 // accelerometer 00222 p_glbl_max8614x_status_track->sensor_callbacks[SH_SENSORIDX_ACCEL].data_size = SSACCEL_MODE1_DATASIZE; 00223 p_glbl_max8614x_status_track->sensor_callbacks[SH_SENSORIDX_ACCEL].rx_data_parser = &accel_data_rx; 00224 // agc 00225 p_glbl_max8614x_status_track->algo_callbacks[SH_ALGOIDX_AGC].data_size = SSAGC_MODE1_DATASIZE; 00226 p_glbl_max8614x_status_track->algo_callbacks[SH_ALGOIDX_AGC].rx_data_parser = &agc_data_rx; 00227 // whrm 00228 p_glbl_max8614x_status_track->algo_callbacks[SH_ALGOIDX_WHRM].data_size = SSWHRM_MODE1_DATASIZE; 00229 p_glbl_max8614x_status_track->algo_callbacks[SH_ALGOIDX_WHRM].rx_data_parser = &whrm_data_rx; 00230 // spo2 00231 p_glbl_max8614x_status_track->algo_callbacks[SH_ALGOIDX_WSPO2].data_size = SSWSPO2_MODE1_DATASIZE; 00232 p_glbl_max8614x_status_track->algo_callbacks[SH_ALGOIDX_WSPO2].rx_data_parser = &wspo2_data_rx; 00233 } 00234 00235 00236 void SH_Max8614x_get_reg(uint8_t addr, uint32_t *val) { 00237 int status = sh_get_reg(SH_SENSORIDX_MAX8614X, addr, val); 00238 00239 if (status == 0) { 00240 __DBGMESSAGE("\r\n reg_val=%02X err=0 \r\n", ((uint8_t)*val)) 00241 } else { 00242 __DBGMESSAGE("\r\n err=%d\r\n", -1) 00243 } 00244 00245 return; 00246 } 00247 00248 int CSTMR_SH_FeedAccDataIntoSH(Max86140_SH_Status_Tracker_t *p_max8614x_status_track) { 00249 static accel_data_t peek_buf[MAX_NUM_WR_ACC_SAMPLES]; 00250 static uint8_t tx_buf[MAX_NUM_WR_ACC_SAMPLES * sizeof(accel_mode1_data) + 2]; // 2 bytes for the command 00251 if(!p_max8614x_status_track->sensor_data_from_host) { 00252 return -1; 00253 } else { 00254 accel_data_t accel_data = {0}; 00255 accel_mode1_data acc_sample; 00256 int num_tx, num_samples, num_bytes = 0, num_wr_bytes = 0; 00257 int num_written_samples, nb_expected; 00258 int ret = 0; 00259 00260 // get accelerometer data 00261 ret = CSTMR_SH_HostAccelerometerGet_sensor_xyz(&accel_data); 00262 if (ret < 0) 00263 return ret; 00264 00265 if(CSTMR_SH_HostAccelerometerEnqueueData(&accel_data) != 0) { 00266 __DBGMESSAGE("Thrown an accel sample\n", NULL) 00267 } 00268 00269 if(CSTMR_SH_HostAccelerometerGetDataCount() < MAX_NUM_WR_ACC_SAMPLES) { 00270 return -1; 00271 } 00272 00273 ret = sh_get_num_bytes_in_input_fifo(&num_bytes); 00274 if (ret != 0) { 00275 __DBGMESSAGE("Unable to read num bytes in input fifo\r\n", NULL) 00276 return -1; 00277 } 00278 num_tx = p_max8614x_status_track->input_fifo_size - num_bytes; 00279 if (num_tx <= 0) { 00280 __DBGMESSAGE("num_tx can't be negative\r\n",NULL) 00281 return -1; 00282 } 00283 num_samples = num_tx / sizeof(accel_mode1_data); 00284 num_samples = MIN_MACRO(num_samples, MAX_NUM_WR_ACC_SAMPLES); 00285 num_tx = num_samples * sizeof(accel_mode1_data); 00286 if (num_samples == 0) { 00287 __DBGMESSAGE("Input FIFO is Full\r\n",NULL) 00288 return -1; 00289 } 00290 00291 for(int i = 0; i < num_samples; ++i) { 00292 ret |= CSTMR_SH_HostAccelerometerDequeuData(&peek_buf[i]); 00293 } 00294 if (ret != 0) { 00295 __DBGMESSAGE("CSTMR_SH_HostAccelerometerDequeuData failed\r\n",NULL) 00296 return -1; 00297 } 00298 00299 00300 for (int i = 2, j = 0; j < num_samples; i+= sizeof(accel_mode1_data), j++) { 00301 accel_data = peek_buf[j]; 00302 acc_sample.x = (int16_t)(accel_data.x*1000); 00303 acc_sample.y = (int16_t)(accel_data.y*1000); 00304 acc_sample.z = (int16_t)(accel_data.z*1000); 00305 tx_buf[i] = acc_sample.x; 00306 tx_buf[i + 1] = acc_sample.x >> 8; 00307 tx_buf[i + 2] = acc_sample.y; 00308 tx_buf[i + 3] = acc_sample.y >> 8; 00309 tx_buf[i + 4] = acc_sample.z; 00310 tx_buf[i + 5] = acc_sample.z >> 8; 00311 00312 } 00313 00314 ret = sh_feed_to_input_fifo(tx_buf, num_tx + 2, &num_wr_bytes); 00315 if(ret != 0) { 00316 __DBGMESSAGE("sh_feed_to_input_fifo\r\n",NULL) 00317 return -1; 00318 } 00319 num_written_samples = num_wr_bytes / sizeof(accel_mode1_data); 00320 if(num_written_samples != num_samples) { 00321 __DBGMESSAGE("num_written_samples failed\r\n",NULL) 00322 return -1; 00323 } 00324 } 00325 return 0; 00326 } 00327 00328 00329 void SH_Max8614x_set_reg(uint8_t addr, uint32_t val) { 00330 int status; 00331 status = sh_set_reg(SH_SENSORIDX_MAX8614X, addr, val, SSMAX8614X_REG_SIZE); 00332 __DBGMESSAGE("\r\n err=%d\r\n", status); 00333 } 00334 00335 00336 00337 int SH_Max8614x_data_report_execute(void) { 00338 00339 int num_samples, databufLen; 00340 uint8_t *databuf; 00341 00342 00343 Max86140_SH_Status_Tracker_t *p_glbl_max8614x_status_track = get_config_struct(); 00344 00345 // prepare the buffer to store the results 00346 databuf = p_glbl_max8614x_status_track->data_buf_storage; 00347 databufLen = sizeof(p_glbl_max8614x_status_track->data_buf_storage); 00348 00349 // poll SH 00350 sh_ss_execute_once(databuf, databufLen, &num_samples); 00351 00352 // feed accelerometer into me11 00353 CSTMR_SH_FeedAccDataIntoSH(p_glbl_max8614x_status_track); 00354 00355 if(num_samples) { 00356 //Skip status byte 00357 uint8_t *data_ptr = &databuf[1]; 00358 00359 int i = 0; 00360 for (i = 0; i < num_samples; i++) { 00361 int sh_data_type = p_glbl_max8614x_status_track->data_type_enabled; 00362 if (p_glbl_max8614x_status_track->sample_count_enabled) { 00363 p_glbl_max8614x_status_track->sample_count = *data_ptr++; 00364 } 00365 //Chop up data and send to modules with enabled sensors 00366 if (sh_data_type == SS_DATATYPE_RAW || sh_data_type == SS_DATATYPE_BOTH) { 00367 for (int i = 0; i < SH_NUM_CURRENT_SENSORS; i++) { 00368 if (p_glbl_max8614x_status_track->sensor_enabled_mode[i]) { 00369 p_glbl_max8614x_status_track->sensor_callbacks[i].rx_data_parser(data_ptr); 00370 data_ptr += p_glbl_max8614x_status_track->sensor_callbacks[i].data_size; 00371 } 00372 } 00373 } 00374 if (sh_data_type == SS_DATATYPE_ALGO || sh_data_type == SS_DATATYPE_BOTH) { 00375 for (int i = 0; i < SH_NUM_CURRENT_ALGOS; i++) { 00376 if (p_glbl_max8614x_status_track->algo_enabled_mode[i]) { 00377 p_glbl_max8614x_status_track->algo_callbacks[i].rx_data_parser(data_ptr); 00378 data_ptr += p_glbl_max8614x_status_track->algo_callbacks[i].data_size; 00379 } 00380 } 00381 } 00382 } 00383 } 00384 return num_samples; 00385 } 00386 00387 int SH_Max8614x_algo_init(enum enAlgoMode paramAlgoMode) { 00388 00389 /* 00390 * 00391 * */ 00392 int status; 00393 Max86140_SH_Status_Tracker_t *p_glbl_max8614x_status_track = get_config_struct(); 00394 if(p_glbl_max8614x_status_track->algo_enabled_mode[SH_ALGOIDX_WHRM] || 00395 p_glbl_max8614x_status_track->algo_enabled_mode[SH_ALGOIDX_WSPO2]) { 00396 __DBGMESSAGE("\r\n Algo already enabled\r\n",NULL) 00397 return -1; 00398 } 00399 00400 if(paramAlgoMode == kAlgoModeHeartRate) { 00401 status = sh_enable_algo(SH_ALGOIDX_WHRM, SSWHRM_MODE1_DATASIZE); 00402 if (status != SS_SUCCESS) { 00403 __DBGMESSAGE("\r\n err=%d\r\n", COMM_GENERAL_ERROR) 00404 __DBGMESSAGE("FAILED at line %d, enable whrm\n", __LINE__) 00405 return status; 00406 } 00407 p_glbl_max8614x_status_track->algo_enabled_mode[SH_ALGOIDX_WHRM] = 0x01; 00408 } else { 00409 status = sh_enable_algo(SH_ALGOIDX_WSPO2, SSWSPO2_MODE1_DATASIZE); 00410 if (status != SS_SUCCESS) { 00411 __DBGMESSAGE("\r\n err=%d\r\n", COMM_GENERAL_ERROR) 00412 __DBGMESSAGE("FAILED at line %d, enable whrm\n", __LINE__) 00413 return status; 00414 } 00415 p_glbl_max8614x_status_track->algo_enabled_mode[SH_ALGOIDX_WSPO2] = 0x01; 00416 } 00417 } 00418 00419 00420 int SH_Max8614x_default_init(enum enAlgoMode paramAlgoMode) { 00421 /* 00422 * Desc: Initialization flow to get algorithm estimation results: 00423 * 1. initialize algorithm config struct 00424 * 2. enable data type to both raw sensor and algorithm data 00425 * 3. get input fifo size to learn fifo capacity 00426 * 4. set fifo threshold for mfio event frequency 00427 * 5. enable sensor to acquire ppg data 00428 * 6. enable accompanying accel sensor 00429 * 7. enable algorithm 00430 * 8. Sensor Hub now starts to write raw sensor/algorithm data to its data report FIFO which 00431 * reports mfio event when data size determined by fifo threshold is written to report fifo 00432 * data can be read by SH_Max8614x_data_report_execute function. 00433 * 00434 * */ 00435 00436 int status; 00437 00438 // first initialize the global config struct 00439 initialize_config_struct(); 00440 Max86140_SH_Status_Tracker_t *p_glbl_max8614x_status_track = get_config_struct(); 00441 00442 // get input fifo size 00443 status = sh_get_input_fifo_size(&p_glbl_max8614x_status_track->input_fifo_size); 00444 if (status != SS_SUCCESS) { 00445 __DBGMESSAGE("\r\n err=%d\r\n", COMM_GENERAL_ERROR) 00446 __DBGMESSAGE("FAILED at line %d\n", __LINE__) 00447 return COMM_GENERAL_ERROR;; 00448 } 00449 00450 // enable both data stype 00451 p_glbl_max8614x_status_track->data_type_enabled = SS_DATATYPE_BOTH; 00452 p_glbl_max8614x_status_track->sample_count_enabled = false; 00453 status = sh_set_data_type(p_glbl_max8614x_status_track->data_type_enabled, 00454 p_glbl_max8614x_status_track->sample_count_enabled); 00455 if (status != 0) { 00456 __DBGMESSAGE("\r\n err=%d\r\n", COMM_GENERAL_ERROR) 00457 __DBGMESSAGE("FAILED at line %d\n", __LINE__) 00458 return COMM_GENERAL_ERROR; 00459 } 00460 00461 status = sh_set_fifo_thresh(15); 00462 if (status != 0) { 00463 __DBGMESSAGE("\r\n err=%d\r\n", COMM_GENERAL_ERROR) 00464 __DBGMESSAGE("FAILED at line %d\n", __LINE__) 00465 return COMM_GENERAL_ERROR; 00466 } 00467 00468 status = sh_sensor_enable(SH_SENSORIDX_MAX8614X, SSMAX8614X_MODE1_DATASIZE, SH_INPUT_DATA_DIRECT_SENSOR); 00469 if (status != 0) { 00470 __DBGMESSAGE("\r\n err=%d\r\n", COMM_GENERAL_ERROR) 00471 __DBGMESSAGE("FAILED at line %d\n", __LINE__) 00472 return COMM_GENERAL_ERROR; 00473 } 00474 p_glbl_max8614x_status_track->sensor_enabled_mode[SH_SENSORIDX_MAX8614X] = 0x01; 00475 00476 #ifdef ENABLE_SENSOR_HUB_ACCEL 00477 status = sh_sensor_enable(SH_SENSORIDX_ACCEL, SSACCEL_MODE1_DATASIZE, SH_INPUT_DATA_DIRECT_SENSOR); 00478 if (status != SS_SUCCESS) { 00479 __DBGMESSAGE("\r\n err=%d\r\n", COMM_GENERAL_ERROR) 00480 __DBGMESSAGE("FAILED at line %d\n", __LINE__) 00481 } 00482 p_glbl_max8614x_status_track->sensor_data_from_host = false; 00483 p_glbl_max8614x_status_track->sensor_enabled_mode[SH_SENSORIDX_ACCEL] = 0x01; 00484 #elif defined(USE_HOST_ACCEL) 00485 CSTMR_SH_HostAccelerometerInitialize(); 00486 CSTMR_SH_HostAccelerometerSetDefaults(); 00487 status = CSTMR_SH_HostAccelerometerSetSampleRate(BMI160_SAMPLE_RATE); 00488 if (status != 0) { 00489 __DBGMESSAGE("Unable to set BMI160's sample rate\n",NULL) 00490 __DBGMESSAGE("\r\n err=%d\r\n", COMM_GENERAL_ERROR) 00491 __DBGMESSAGE("FAILED at line %d\n", __LINE__) 00492 return status; 00493 } 00494 00495 status = CSTMR_SH_HostAccelerometerEnableDataReadyInterrupt(); 00496 if(status != 0){ 00497 __DBGMESSAGE("Unable to enable BMI160 Interrupt, ret: %d\n", status) 00498 return status; 00499 } 00500 00501 status = sh_sensor_enable(SH_SENSORIDX_ACCEL, SSACCEL_MODE1_DATASIZE, SH_INPUT_DATA_FROM_HOST); 00502 if (status != 0) { 00503 __DBGMESSAGE("\r\n err=%d\r\n", COMM_GENERAL_ERROR) 00504 __DBGMESSAGE("FAILED at line %d\n", __LINE__) 00505 return status; 00506 } 00507 p_glbl_max8614x_status_track->sensor_data_from_host = true; 00508 p_glbl_max8614x_status_track->sensor_enabled_mode[SH_SENSORIDX_ACCEL] = 0x01; 00509 #endif 00510 status = SH_Max8614x_algo_init(paramAlgoMode); 00511 if(status != 0) { 00512 __DBGMESSAGE("AlgoInitFailed\r\n",NULL) 00513 } 00514 00515 __DBGMESSAGE("\r\n err=%d\r\n", status) 00516 return status; 00517 } 00518 00519 void SH_Max8614x_stop() { 00520 sh_disable_irq_mfioevent(); 00521 Max86140_SH_Status_Tracker_t *p_glbl_max8614x_status_track = get_config_struct(); 00522 00523 for(int i = 0; i < SH_NUM_CURRENT_SENSORS; ++i) { 00524 if(p_glbl_max8614x_status_track->sensor_enabled_mode[i]) { 00525 p_glbl_max8614x_status_track->sensor_enabled_mode[i] = 0; 00526 sh_sensor_disable(i); 00527 } 00528 00529 } 00530 00531 for(int i = 0; i < SH_NUM_CURRENT_ALGOS; ++i) { 00532 if(p_glbl_max8614x_status_track->algo_enabled_mode[i]) { 00533 p_glbl_max8614x_status_track->algo_enabled_mode[i] = 0; 00534 sh_disable_algo(i); 00535 } 00536 } 00537 00538 if(p_glbl_max8614x_status_track->sensor_data_from_host) { 00539 CSTMR_SH_HostAccelerometerInitialize(); 00540 p_glbl_max8614x_status_track->sensor_data_from_host = 0; 00541 } 00542 00543 sh_clear_mfio_event_flag(); 00544 sh_enable_irq_mfioevent(); 00545 } 00546 00547
Generated on Fri Jul 15 2022 09:07:43 by
1.7.2
