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
SSInterface.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 _SSINTERFACE_H_ 00035 #define _SSINTERFACE_H_ 00036 00037 #include "mbed.h" 00038 #include "MaximSensor.h" 00039 #include "EventStats.h" 00040 00041 #define SS_PLATFORM_MAX3263X "SmartSensor_MAX3263X" 00042 #define SS_PLATFORM_MAX32660 "SmartSensor_MAX32660" 00043 #define SS_BOOTLOADER_PLATFORM_MAX3263X "Bootloader_MAX3263X" 00044 #define SS_BOOTLOADER_PLATFORM_MAX32660 "Bootloader_MAX32660" 00045 00046 00047 #define SS_I2C_8BIT_SLAVE_ADDR 0xAA 00048 #define SS_DEFAULT_CMD_SLEEP_MS 2 00049 #define SS_DEFAULT2_CMD_SLEEP_MS 4 00050 #define SS_DEFAULT3_CMD_SLEEP_MS 30 00051 #define SS_DUMP_REG_SLEEP_MS 100 00052 #define SS_ENABLE_SENSOR_SLEEP_MS 20 00053 00054 #define SH_INPUT_DATA_DIRECT_SENSOR 0x00 // Default 00055 #define SH_INPUT_DATA_FROM_HOST 0x01 00056 00057 #define SS_SENSORIDX_MAX86140 0x00 00058 #define SS_SENSORIDX_MAX30205 0x01 00059 #define SS_SENSORIDX_MAX30001 0x02 00060 #define SS_SENSORIDX_MAX30101 0x03 00061 #define SS_SENSORIDX_ACCEL 0x04 00062 00063 #define SS_ALGOIDX_AGC 0x00 00064 #define SS_ALGOIDX_AEC 0x01 00065 #define SS_ALGOIDX_WHRM 0x02 00066 #define SS_ALGOIDX_ECG 0x03 00067 #define SS_ALGOIDX_BPT 0x04 00068 #define SS_ALGOIDX_WSPO2 0x05 /// additional index 00069 00070 00071 #define SS_FAM_R_STATUS 0x00 00072 #define SS_CMDIDX_STATUS 0x00 00073 #define SS_SHIFT_STATUS_ERR 0 00074 #define SS_MASK_STATUS_ERR (0x07 << SS_SHIFT_STATUS_ERR) 00075 #define SS_SHIFT_STATUS_DATA_RDY 3 00076 #define SS_MASK_STATUS_DATA_RDY (1 << SS_SHIFT_STATUS_DATA_RDY) 00077 #define SS_SHIFT_STATUS_FIFO_OUT_OVR 4 00078 #define SS_MASK_STATUS_FIFO_OUT_OVR (1 << SS_SHIFT_STATUS_FIFO_OUT_OVR) 00079 #define SS_SHIFT_STATUS_FIFO_IN_OVR 5 00080 #define SS_MASK_STATUS_FIFO_IN_OVR (1 << SS_SHIFT_STATUS_FIFO_IN_OVR) 00081 00082 #define SS_SHIFT_STATUS_LOG_OVR 6 00083 #define SS_MASK_STATUS_LOG_OVR (1 << SS_SHIFT_STATUS_LOG_OVR) 00084 00085 #define SS_SHIFT_STATUS_LOG_RDY 7 00086 #define SS_MASK_STATUS_LOG_RDY (1 << SS_SHIFT_STATUS_LOG_RDY) 00087 00088 00089 #define SS_FAM_W_MODE 0x01 00090 #define SS_FAM_R_MODE 0x02 00091 #define SS_CMDIDX_MODE 0x00 00092 #define SS_SHIFT_MODE_SHDN 0 00093 #define SS_MASK_MODE_SHDN (1 << SS_SHIFT_MODE_SHDN) 00094 #define SS_SHIFT_MODE_RESET 1 00095 #define SS_MASK_MODE_RESET (1 << SS_SHIFT_MODE_RESET) 00096 #define SS_SHIFT_MODE_FIFORESET 2 00097 #define SS_MASK_MODE_FIFORESET (1 << SS_SHIFT_MODE_FIFORESET) 00098 #define SS_SHIFT_MODE_BOOTLDR 3 00099 #define SS_MASK_MODE_BOOTLDR (1 << SS_SHIFT_MODE_BOOTLDR) 00100 00101 #define SS_I2C_READ 0x03 00102 00103 #define SS_FAM_W_COMMCHAN 0x10 00104 #define SS_FAM_R_COMMCHAN 0x11 00105 #define SS_CMDIDX_OUTPUTMODE 0x00 00106 #define SS_SHIFT_OUTPUTMODE_DATATYPE 0 00107 #define SS_MASK_OUTPUTMODE_DATATYPE (0x03 << SS_SHIFT_OUTPUTMODE_DATATYPE) 00108 #define SS_DATATYPE_PAUSE 0 00109 #define SS_DATATYPE_RAW 1 00110 #define SS_DATATYPE_ALGO 2 00111 #define SS_DATATYPE_BOTH 3 00112 #define SS_SHIFT_OUTPUTMODE_SC_EN 2 00113 #define SS_MASK_OUTPUTMODE_SC_EN (1 << SS_SHIFT_OUTPUTMODE_SC_EN) 00114 #define SS_CMDIDX_FIFOAFULL 0x01 00115 00116 #define SS_FAM_R_OUTPUTFIFO 0x12 00117 #define SS_CMDIDX_OUT_NUMSAMPLES 0x00 00118 #define SS_CMDIDX_READFIFO 0x01 00119 00120 #define SS_FAM_R_INPUTFIFO 0x13 00121 #define SS_CMDIDX_SAMPLE_SIZE 0x00 00122 #define SS_CMDIDX_INPUT_FIFO_SIZE 0x01 00123 #define SS_CMDIDX_SENSOR_FIFO_SIZE 0x02 00124 #define SS_CMDIDX_NUM_SAMPLES_SENSOR_FIFO 0x03 00125 #define SS_CMDIDX_NUM_SAMPLES_INPUT_FIFO 0x04 00126 00127 #define SS_FAM_W_INPUTFIFO 0x14 00128 #define SS_CMDIDX_WRITE_FIFO 0x00 00129 00130 #define SS_FAM_W_WRITEREG 0x40 00131 #define SS_FAM_R_READREG 0x41 00132 #define SS_FAM_R_REGATTRIBS 0x42 00133 #define SS_FAM_R_DUMPREG 0x43 00134 00135 #define SS_FAM_W_SENSORMODE 0x44 00136 #define SS_FAM_R_SENSORMODE 0x45 00137 00138 #define SS_FAM_W_ALGOCONFIG 0x50 00139 #define SS_FAM_R_ALGOCONFIG 0x51 00140 #define SS_CFGIDX_AGC_TARGET 0x00 00141 #define SS_CFGIDX_AGC_CORR_COEFF 0x01 00142 #define SS_CFGIDX_AGC_SENSITIVITY 0x02 00143 #define SS_CFGIDX_AGC_SMP_AVG 0x03 00144 00145 #define SS_CFGIDX_WHRM_SR 0x00 00146 #define SS_CFGIDX_WHRM_MAX_HEIGHT 0x01 00147 #define SS_CFGIDX_WHRM_MAX_WEIGHT 0x02 00148 #define SS_CFGIDX_WHRM_MAX_AGE 0x03 00149 #define SS_CFGIDX_WHRM_MIN_HEIGHT 0x04 00150 #define SS_CFGIDX_WHRM_MIN_WEIGHT 0x05 00151 #define SS_CFGIDX_WHRM_MIN_AGE 0x06 00152 #define SS_CFGIDX_WHRM_DEF_HEIGHT 0x07 00153 #define SS_CFGIDX_WHRM_DEF_WEIGHT 0x08 00154 #define SS_CFGIDX_WHRM_DEF_AGE 0x09 00155 #define SS_CFGIDX_WHRM_INIT_HR 0x0A 00156 00157 // additional for WHRM_AEC_SCD 00158 #define SS_CFGIDX_WHRM_AEC_ENABLE 0x0B 00159 #define SS_CFGIDX_WHRM_SCD_ENABLE 0x0C 00160 #define SS_CFGIDX_WHRM_ADJ_TARGET_PD_CURRENT_PERIOD 0x0D 00161 #define SS_CFGIDX_WHRM_SCD_DEBOUNCE_WINDOW 0x0E 00162 #define SS_CFGIDX_WHRM_MOTION_MAG_THRESHOLD 0x0F 00163 #define SS_CFGIDX_WHRM_MIN_PD_CURRENT 0x10 00164 #define SS_CFGIDX_WHRM_PD_CONFIG 0x11 00165 #define SS_CFGIDX_WHRM_LED_CONFIG 0x12 00166 00167 // config for WSPO2 00168 #define SS_CFGIDX_WSPO2_CAL 0x00 00169 #define SS_CFGIDX_WSPO2_SR 0x01 00170 #define SS_CFGIDX_WSPO2_ALGO_MODE 0x02 00171 #define SS_CFGIDX_WSPO2_AGC_MODE 0x03 00172 #define SS_CFGIDX_WSPO2_MOTION_DET 0x04 00173 #define SS_CFGIDX_WSPO2_MOTION_PERIOD 0x05 00174 #define SS_CFGIDX_WSPO2_MOTION_THRESHOLD 0x06 00175 #define SS_CFGIDX_WSPO2_AGC_TIMEOUT 0x07 00176 #define SS_CFGIDX_WSPO2_TIMEOUT 0x08 00177 #define SS_CFGIDX_WSPO2_PD_CONFIG 0x09 00178 00179 00180 #define SS_CFGIDX_BP_USE_MED 0x00 00181 #define SS_CFGIDX_BP_SYS_BP_CAL 0x01 00182 #define SS_CFGIDX_BP_DIA_BP_CAL 0x02 00183 #define SS_CFGIDX_BP_CAL_DATA 0x03 00184 #define SS_CFGIDX_BP_EST_DATE 0x04 00185 #define SS_CFGIDX_BP_EST_NONREST 0x05 00186 #define SS_CFGIDX_BP_SPO2_COEFS 0x06 00187 00188 #define SS_FAM_W_ALGOMODE 0x52 00189 #define SS_FAM_R_ALGOMODE 0x53 00190 00191 #define SS_FAM_W_EXTERNSENSORMODE 0x60 00192 #define SS_W_EXT_SENSOR_MODE 0x00 00193 #define SS_FAM_R_EXTERNSENSORMODE 0x61 00194 #define SS_R_EXT_SENSOR_MODE 0x00 00195 00196 #define SS_FAM_R_SELFTEST 0x70 00197 00198 #define SS_FAM_W_BOOTLOADER 0x80 00199 #define SS_CMDIDX_SETIV 0x00 00200 #define SS_CMDIDX_SETAUTH 0x01 00201 #define SS_CMDIDX_SETNUMPAGES 0x02 00202 #define SS_CMDIDX_ERASE 0x03 00203 #define SS_CMDIDX_SENDPAGE 0x04 00204 #define SS_CMDIDX_ERASE_PAGE 0x05 00205 #define SS_FAM_R_BOOTLOADER 0x81 00206 #define SS_CMDIDX_BOOTFWVERSION 0x00 00207 #define SS_CMDIDX_PAGESIZE 0x01 00208 00209 #define SS_FAM_W_BOOTLOADER_CFG 0x82 00210 #define SS_FAM_R_BOOTLOADER_CFG 0x83 00211 #define SS_CMDIDX_BL_SAVE 0x00 00212 #define SS_CMDIDX_BL_ENTRY 0x01 00213 #define SS_BL_CFG_ENTER_BL_MODE 0x00 00214 #define SS_BL_CFG_EBL_PIN 0x01 00215 #define SS_BL_CFG_EBL_POL 0x02 00216 #define SS_CMDIDX_BL_EXIT 0x02 00217 #define SS_BL_CFG_EXIT_BL_MODE 0x00 00218 #define SS_BL_CFG_TIMEOUT 0x01 00219 00220 /* Enable logging/debugging */ 00221 #define SS_FAM_R_LOG 0x90 00222 #define SS_CMDIDX_R_LOG_DATA 0x00 00223 #define SS_CMDIDX_R_LOG_LEN 0x01 00224 00225 #define SS_CMDIDX_R_LOG_LEVEL 0x02 00226 #define SS_LOG_DISABLE 0x00 00227 #define SS_LOG_CRITICAL 0x01 00228 #define SS_LOG_ERROR 0x02 00229 #define SS_LOG_INFO 0x04 00230 #define SS_LOG_DEBUG 0x08 00231 00232 #define SS_FAM_W_LOG_CFG 0x91 00233 #define SS_CMDIDX_LOG_GET_LEVEL 0x00 00234 #define SS_CMDIDX_LOG_SET_LEVEL 0x01 00235 00236 #define SS_FAM_R_IDENTITY 0xFF 00237 #define SS_CMDIDX_PLATTYPE 0x00 00238 #define SS_CMDIDX_PARTID 0x01 00239 #define SS_CMDIDX_REVID 0x02 00240 #define SS_CMDIDX_FWVERSION 0x03 00241 #define SS_CMDIDX_AVAILSENSORS 0x04 00242 #define SS_CMDIDX_DRIVERVER 0x05 00243 #define SS_CMDIDX_AVAILALGOS 0x06 00244 #define SS_CMDIDX_ALGOVER 0x07 00245 00246 00247 typedef enum { 00248 SS_SUCCESS=0x00, 00249 00250 SS_ERR_COMMAND=0x01, 00251 SS_ERR_UNAVAILABLE=0x02, 00252 SS_ERR_DATA_FORMAT=0x03, 00253 SS_ERR_INPUT_VALUE=0x04, 00254 00255 SS_ERR_BTLDR_GENERAL=0x80, 00256 SS_ERR_BTLDR_CHECKSUM=0x81, 00257 00258 SS_ERR_TRY_AGAIN=0xFE, 00259 SS_ERR_UNKNOWN=0xFF, 00260 } SS_STATUS; 00261 00262 typedef enum { 00263 SS_PLAT_MAX3263X=0, 00264 SS_PLAT_MAX32660=1, 00265 } SS_PLAT_TYPE; 00266 00267 //self test result masks 00268 #define FAILURE_COMM 0x01 00269 #define FAILURE_INTERRUPT 0x02 00270 00271 #define SS_SMALL_BUF_SIZE 32 00272 #define SS_MED_BUF_SIZE 512 00273 #define SS_LARGE_BUF_SIZE 8224 00274 00275 #define SS_RESET_TIME 10 00276 #define SS_STARTUP_TO_BTLDR_TIME 50 00277 #define SS_STARTUP_TO_MAIN_APP_TIME 1000 00278 00279 #define SS_MAX_SUPPORTED_SENSOR_NUM 0xFE 00280 #define SS_MAX_SUPPORTED_ALGO_NUM 0xFE 00281 #define SS_MAX_SUPPORTED_ALGO_CFG_NUM 0xFE 00282 #define SS_MAX_SUPPORTED_MODE_NUM 0xFF 00283 00284 /* BOOTLOADER HOST */ 00285 #define EBL_CMD_TRIGGER_MODE 0 00286 #define EBL_GPIO_TRIGGER_MODE 1 00287 00288 00289 typedef struct { 00290 int data_size; 00291 Callback<void(uint8_t*)> callback; 00292 } ss_data_req; 00293 00294 typedef union { 00295 struct { 00296 uint16_t whrm_enabled :1; 00297 uint16_t wspo2_enabled :1; /// added 00298 uint16_t bpt_enabled :1; 00299 uint16_t agc_enabled :1; 00300 uint16_t max8614x_enabled:1; 00301 uint16_t max3010x_enabled:1; 00302 uint16_t accel_enabled :1; 00303 00304 uint16_t sensorhub_accel :1; // added to specify if sensor hub accel is used or host (default) 00305 uint16_t placeholder :8; // 00306 }; 00307 uint16_t status_vals; 00308 } status_algo_sensors_st; 00309 00310 00311 /** 00312 * @brief SSInterface is Maxim's SmartSensor Interface class 00313 */ 00314 class SSInterface 00315 { 00316 public: 00317 00318 /* PUBLIC FUNCTION DECLARATIONS */ 00319 /** 00320 * @brief SSInterface constructor. 00321 * 00322 * @param[in] i2cBus - reference to the I2C bus for the SmartSensor 00323 * @param[in] ss_mfio - name of SmartSensor multi-function IO pin 00324 * @param[in] ss_reset - name of SmartSensor Reset pin 00325 * 00326 */ 00327 SSInterface(I2C &i2cBus, PinName ss_mfio, PinName ss_reset); 00328 00329 /** 00330 * @brief SSInterface constructor. 00331 * 00332 * @param[in] spiBus - reference to the SPI bus for the SmartSensor 00333 * @param[in] ss_mfio - name of SmartSensor multi-function IO pin 00334 * @param[in] ss_reset - name of SmartSensor Reset pin 00335 * 00336 */ 00337 SSInterface(SPI &spiBus, PinName ss_mfio, PinName ss_reset); 00338 00339 /** 00340 * @brief DSInterface destructor. 00341 * 00342 */ 00343 ~SSInterface(); 00344 00345 /** 00346 * @brief Write a command to the SmartSensor and get status response 00347 * 00348 * @param[in] cmd_bytes - Pointer to the command's family and index bytes 00349 * @param[in] cmd_idx_len - The number of bytes in the command 00350 * @param[in] data - Pointer to the command's data bytes 00351 * @param[in] data_len - The number data bytes 00352 * 00353 * @return SS_STATUS byte 00354 */ 00355 SS_STATUS write_cmd(uint8_t *cmd_bytes, int cmd_bytes_len, 00356 uint8_t *data, int data_len, 00357 int sleep_ms = SS_DEFAULT_CMD_SLEEP_MS); 00358 00359 00360 /** 00361 * @brief Write a command to the SmartSensor and get status response 00362 * 00363 * @param[in] tx_buf - Pointer to the command's family, index bytes and data bytes 00364 * @param[in] tx_len - Total transaction lenght to send 00365 * 00366 * @return SS_STATUS byte 00367 */ 00368 SS_STATUS write_cmd(uint8_t *tx_buf, int tx_len, 00369 int sleep_ms = SS_DEFAULT_CMD_SLEEP_MS); 00370 00371 /** 00372 * @brief Write a command to the SmartSensor and get status response 00373 * 00374 * @param[in] cmd_bytes - Pointer to the command's family and index bytes 00375 * @param[in] cmd_idx_len - The number of bytes in the command 00376 * @param[in] data - Pointer to the command's data bytes 00377 * @param[in] data_len - The number data bytes 00378 * @param[in] rxbuf - Buffer to fill in with read data (including status byte) 00379 * @param[in] rxbuf_sz - Size of the rx buffer (to prevent overflow) 00380 * 00381 * @return SS_STATUS byte 00382 */ 00383 SS_STATUS read_cmd( uint8_t *cmd_bytes, int cmd_bytes_len, 00384 uint8_t *data, int data_len, 00385 uint8_t *rxbuf, int rxbuf_sz, 00386 int sleep_ms = SS_DEFAULT_CMD_SLEEP_MS); 00387 00388 /** 00389 * @brief Get a string representing the SmartSensor firmware version 00390 * @details If in bootloader mode, returns bootloader version 00391 * 00392 * @return Pointer to firmware version string 00393 */ 00394 const char* get_ss_fw_version(); 00395 00396 /** 00397 * @brief Get a string representing the SmartSensor algo version 00398 * @details If in bootloader mode, returns bootloader version 00399 * 00400 * @return Pointer to algo version string 00401 */ 00402 const char* get_ss_algo_version(); 00403 00404 /** 00405 * @brief Get a string representing the SmartSensor platform type 00406 * 00407 * @return Pointer to platform type string 00408 */ 00409 const char* get_ss_platform_name(); 00410 00411 /** 00412 * @brief Reset the SmartSensor and jump to main application 00413 * 00414 * @return SS_STATUS code indicating success 00415 */ 00416 SS_STATUS reset_to_main_app(); 00417 00418 /** 00419 * @brief Reset the SmartSensor and jump to bootloader 00420 * 00421 * @return SS_STATUS code indicating success 00422 */ 00423 SS_STATUS reset_to_bootloader(); 00424 00425 /** 00426 * @brief Reset the SmartSensor 00427 * @details If the SmartSensor was in bootloader, it will jump back into bootloader 00428 * If the SmartSensor was in main app, it will jump back into main app 00429 * 00430 * @return SS_STATUS code indicating success 00431 */ 00432 SS_STATUS reset(); 00433 00434 /** 00435 * @brief run the self test commands 00436 * param[in] idx - the id of the sensor for the self test 00437 * param[in] result - self-test response 00438 * param[in] sleep_ms - duration of wait for read command 00439 * @return SS_STATUS code indicating success 00440 */ 00441 SS_STATUS self_test(int idx, uint8_t *result, int sleep_ms = SS_DEFAULT_CMD_SLEEP_MS); 00442 00443 /** 00444 * @brief Check if SmartSensor is in bootloader mode 00445 * 00446 * @return 1 if in bootloader mode, 0 if in main app, -1 if comm error 00447 */ 00448 int in_bootldr_mode(); 00449 00450 00451 /** 00452 * @brief Read register from a device onboard SmartSensor 00453 * 00454 * @param[in] idx - Index of device to read 00455 * @param[in] addr - Register address 00456 * @param[out] val - Register value 00457 * 00458 * @return SS_SUCCESS on success 00459 */ 00460 SS_STATUS get_reg(int idx, uint8_t addr, uint32_t *val); 00461 00462 /** 00463 * @brief Set register of a device onboard SmartSensor 00464 * 00465 * @param[in] idx - Index of device to read 00466 * @param[in] addr - Register address 00467 * @param[in] val - Register value 00468 * @param[in] byte_size - Size of IC register in bytes 00469 * 00470 * @return SS_SUCCESS on success 00471 */ 00472 SS_STATUS set_reg(int idx, uint8_t addr, uint32_t val, int byte_size); 00473 00474 /** 00475 * @brief Dump registers of a device onboard SmartSensor 00476 * 00477 * @param[in] idx - Index of device 00478 * @param[in] reg_vals - Array of addr_val_pairs 00479 * @param[in] reg_vals_sz - Number of items reg_vals can hold 00480 * @param[out] num_regs - Number of registers returned by command 00481 * 00482 * @return SS_SUCCESS on success 00483 */ 00484 SS_STATUS dump_reg(int idx, addr_val_pair* reg_vals, int reg_vals_sz, int* num_regs); 00485 00486 00487 /** 00488 * @brief Enable a device on the SmartSensor 00489 * 00490 * @param[in] idx - Index of device 00491 * @param[in] mode - Mode to set the device to 00492 * @param[in] data_req - Data request 00493 * @param[in] ext_ - Data request 00494 * 00495 * @return SS_SUCCESS on success 00496 */ 00497 SS_STATUS enable_sensor(int idx, int mode, ss_data_req* data_req, uint8_t ext_mode = SH_INPUT_DATA_DIRECT_SENSOR); 00498 00499 /** 00500 * @brief Disable a device on the SmartSensor 00501 * 00502 * @param[in] idx - Index of device 00503 * 00504 * @return SS_SUCCESS on success 00505 */ 00506 SS_STATUS disable_sensor(int idx); 00507 00508 /** 00509 * @brief Enable an algorithm on the SmartSensor 00510 * 00511 * @param[in] idx - Index of device 00512 * @param[in] mode - Mode to set the device to 00513 * @param[in] data_req - Data request 00514 * 00515 * @return SS_SUCCESS on success 00516 */ 00517 SS_STATUS enable_algo(int idx, int mode, ss_data_req* data_req); 00518 00519 /** 00520 * @brief Disable an algorithm on the SmartSensor 00521 * 00522 * @param[in] idx - Index of device 00523 * 00524 * @return SS_SUCCESS on success 00525 */ 00526 SS_STATUS disable_algo(int idx); 00527 00528 /** 00529 * @brief Set the value of an algorithm configuration parameter 00530 * 00531 * @param[in] algo_idx Index of algorithm 00532 * @param[in] cfg_idx Index of configuration parameter 00533 * @param[in] cfg Array of configuration bytes 00534 * @param[in] cfg_sz Size of cfg array 00535 * 00536 * @return SS_SUCCESS on success 00537 */ 00538 SS_STATUS set_algo_cfg(int algo_idx, int cfg_idx, uint8_t *cfg, int cfg_sz); 00539 00540 /** 00541 * @brief Get the value of an algorithm configuration parameter 00542 * 00543 * @param[in] algo_idx Index of algorithm 00544 * @param[in] cfg_idx Index of configuration parameter 00545 * @param[in] cfg Array of configuration bytes to be filled in 00546 * @param[in] cfg_sz Number of bytes to be read 00547 * 00548 * @return SS_SUCCESS on success 00549 */ 00550 SS_STATUS get_algo_cfg(int algo_idx, int cfg_idx, uint8_t *cfg, int cfg_sz); 00551 00552 /** 00553 * @brief Set the CommChannel Output Mode options 00554 * 00555 * @param[in] data_type - Set to 0 for only algorithm data 00556 * Set to 1 for only raw sensor data 00557 * Set to 2 for algo + raw sensor data 00558 * Set to 3 for no data 00559 * @param[in] sc_en - Set to true to receive 1 byte sample count from SmartSensor 00560 * 00561 * @return SS_SUCCESS on success 00562 */ 00563 SS_STATUS set_data_type(int data_type, bool sc_en); 00564 00565 /** 00566 * @brief Get the CommChannel Output Mode options 00567 * 00568 * @param[out] data_type - 0 for only algorithm data 00569 * 1 for only raw sensor data 00570 * 2 for algo + raw sensor data 00571 * 3 for no data 00572 * @param[in] sc_en - If true, SmartSensor prepends data with 1 byte sample count 00573 * 00574 * @return SS_SUCCESS on success 00575 */ 00576 SS_STATUS get_data_type(int* data_type, bool *sc_en); 00577 00578 /** 00579 * @brief Set the number of samples for the SmartSensor to collect 00580 * before issuing an interrupt 00581 * 00582 * @param[in] thresh - Number of samples (1-255) to collect before interrupt 00583 * 00584 * @return SS_SUCCESS on success 00585 */ 00586 SS_STATUS set_fifo_thresh(int thresh); 00587 00588 /** 00589 * @brief Get the number of samples the SmartSensor will collect 00590 * before issuing an interrupt 00591 * 00592 * @param[out] thresh - Number of samples (1-255) collected before interrupt 00593 * 00594 * @return SS_SUCCESS on success 00595 */ 00596 SS_STATUS get_fifo_thresh(int *thresh); 00597 00598 /** 00599 * @brief Pass external sensor data to sensor hub 00600 * 00601 * @param[in] num_samples in tx_buf 00602 * @param[in] tx_buf - Host sample data to send sensor hub 00603 * @param[in] tx_buf_sz - Number of bytes of tx_buf 00604 * @param[out] nb_written - Number of samples to sensor hub's input FIFO 00605 * 00606 * @return SS_SUCCESS on success 00607 */ 00608 SS_STATUS feed_to_input_fifo(uint8_t *tx_buf, int tx_buf_sz, int *nb_written); 00609 00610 /** 00611 * @brief Get the number of sambes in Sensor FIFO 00612 * 00613 * @param[in] sensor_id - Sensor id to read FIFO size 00614 * @param[out] fifo_size - Sensor's FIFO size 00615 * 00616 * @return SS_SUCCESS on success 00617 */ 00618 SS_STATUS get_num_samples_in_sensor_fifo(uint8_t sensor_id, int *fifo_size); 00619 00620 /** 00621 * @brief Get the total number of bytes in the Input FIFO 00622 * 00623 * @param[out] fifo_size - Input FIFO size 00624 * 00625 * @return SS_SUCCESS on success 00626 */ 00627 SS_STATUS get_num_bytes_in_input_fifo(int *fifo_size); 00628 00629 /** 00630 * @brief Get the total number of samples the Sensor's FIFO can hold 00631 * 00632 * @param[in] sensor_id - Sensor id to read FIFO size 00633 * @param[out] fifo_size - Sensor's FIFO size 00634 * 00635 * @return SS_SUCCESS on success 00636 */ 00637 SS_STATUS get_sensor_fifo_size(uint8_t sensor_id, int *fifo_size); 00638 00639 /** 00640 * @brief Get the total number of samples the input FIFO can hold 00641 * 00642 * @param[out] fifo_size - Input FIFO size 00643 * 00644 * @return SS_SUCCESS on success 00645 */ 00646 SS_STATUS get_input_fifo_size(int *fifo_size); 00647 00648 /** 00649 * @brief Get the number of bytes per sample of a sensor 00650 * 00651 * @param[in] sensor_id - Sensor id to read sample size 00652 * @param[out] sample_size - Sensor's sample size 00653 * 00654 * @return SS_SUCCESS on success 00655 */ 00656 SS_STATUS get_sensor_sample_size(uint8_t sensor_id, uint8_t *sample_size); 00657 00658 /** 00659 * @brief send raw string to I2C 00660 * 00661 * @param[in] *rawdata - Raw data string, after slave address 00662 * @param[out] rawdata_sz - Raw data size 00663 * 00664 * @return SS_SUCCESS on success 00665 */ 00666 SS_STATUS send_raw(uint8_t *rawdata, int rawdata_sz); 00667 00668 /** 00669 * @brief Check that the SmartSensor is connected 00670 */ 00671 SS_STATUS ss_comm_check(); 00672 00673 /** 00674 * @brief Set if GPIO or CMD is used to enter bootloader and App 00675 * before issuing an interrupt 00676 * 00677 * param[in] mode 00678 * - 0: use command to enter bootloader mode 00679 * - 1: use EBL GPIO to enter bootloader mode 00680 * 00681 * @return SS_SUCCESS on success 00682 */ 00683 SS_STATUS set_ebl_mode(uint8_t mode); 00684 00685 /** 00686 * @brief Get ebl_mode value 00687 * 00688 * @return ebl_mode value 00689 */ 00690 int get_ebl_mode(); 00691 00692 SS_STATUS stay_in_bootloader(); 00693 SS_STATUS exit_from_bootloader(); 00694 00695 void enable_irq(); 00696 void disable_irq(); 00697 00698 void mfio_selftest(); 00699 bool reset_mfio_irq(); 00700 00701 void ss_execute_once(); 00702 void ss_clear_interrupt_flag(); 00703 00704 private: 00705 00706 /* PRIVATE VARIABLES */ 00707 I2C *m_i2cBus; 00708 SPI *m_spiBus; 00709 DigitalInOut mfio_pin; 00710 DigitalInOut reset_pin; 00711 InterruptIn irq_pin; 00712 00713 char fw_version[128]; 00714 char algo_version[128]; 00715 const char* plat_name; 00716 00717 bool in_bootldr; 00718 bool sc_en; 00719 int data_type; 00720 00721 uint8_t ebl_mode; /* 0: Command bootloader, 1: No command, trigger GPIO */ 00722 00723 int sensor_enabled_mode[SS_MAX_SUPPORTED_SENSOR_NUM]; 00724 int algo_enabled_mode[SS_MAX_SUPPORTED_ALGO_NUM]; 00725 ss_data_req* sensor_data_reqs[SS_MAX_SUPPORTED_SENSOR_NUM]; 00726 ss_data_req* algo_data_reqs[SS_MAX_SUPPORTED_ALGO_NUM]; 00727 00728 /* PRIVATE METHODS */ 00729 SS_STATUS write_cmd_small(uint8_t *cmd_bytes, int cmd_bytes_len, 00730 uint8_t *data, int data_len, 00731 int sleep_ms = SS_DEFAULT_CMD_SLEEP_MS); 00732 SS_STATUS write_cmd_medium(uint8_t *cmd_bytes, int cmd_bytes_len, 00733 uint8_t *data, int data_len, 00734 int sleep_ms = SS_DEFAULT_CMD_SLEEP_MS); 00735 SS_STATUS write_cmd_large(uint8_t *cmd_bytes, int cmd_bytes_len, 00736 uint8_t *data, int data_len, 00737 int sleep_ms = SS_DEFAULT_CMD_SLEEP_MS); 00738 void cfg_mfio(PinDirection); 00739 00740 void irq_handler(); 00741 volatile bool m_irq_received_; 00742 00743 00744 void irq_handler_selftest(); 00745 volatile bool mfio_int_happened; 00746 00747 SS_STATUS read_fifo_data(int num_samples, int sample_size, uint8_t* databuf, int databuf_sz); 00748 SS_STATUS num_avail_samples(int* num_samples); 00749 SS_STATUS get_log_len(int *log_len); 00750 SS_STATUS read_ss_log(int num_bytes, uint8_t *log_buf, int log_buf_sz); 00751 void fifo_sample_size(int data_type, int* sample_size); 00752 00753 // EventStats irq_evt; 00754 }; 00755 00756 00757 #endif
Generated on Wed Jul 13 2022 22:33:03 by
 1.7.2
 1.7.2