TEST
Dependencies: max32630fthr Adafruit_FeatherOLED USBDevice
Interfaces/SmartSensor/SSInterface.h@1:f60eafbf009a, 2019-04-10 (annotated)
- Committer:
- gmehmet
- Date:
- Wed Apr 10 14:56:25 2019 +0300
- Revision:
- 1:f60eafbf009a
upload from local
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gmehmet | 1:f60eafbf009a | 1 | /*************************************************************************** |
gmehmet | 1:f60eafbf009a | 2 | * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved. |
gmehmet | 1:f60eafbf009a | 3 | * |
gmehmet | 1:f60eafbf009a | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
gmehmet | 1:f60eafbf009a | 5 | * copy of this software and associated documentation files (the "Software"), |
gmehmet | 1:f60eafbf009a | 6 | * to deal in the Software without restriction, including without limitation |
gmehmet | 1:f60eafbf009a | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
gmehmet | 1:f60eafbf009a | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
gmehmet | 1:f60eafbf009a | 9 | * Software is furnished to do so, subject to the following conditions: |
gmehmet | 1:f60eafbf009a | 10 | * |
gmehmet | 1:f60eafbf009a | 11 | * The above copyright notice and this permission notice shall be included |
gmehmet | 1:f60eafbf009a | 12 | * in all copies or substantial portions of the Software. |
gmehmet | 1:f60eafbf009a | 13 | * |
gmehmet | 1:f60eafbf009a | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
gmehmet | 1:f60eafbf009a | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
gmehmet | 1:f60eafbf009a | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
gmehmet | 1:f60eafbf009a | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
gmehmet | 1:f60eafbf009a | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
gmehmet | 1:f60eafbf009a | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
gmehmet | 1:f60eafbf009a | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
gmehmet | 1:f60eafbf009a | 21 | * |
gmehmet | 1:f60eafbf009a | 22 | * Except as contained in this notice, the name of Maxim Integrated |
gmehmet | 1:f60eafbf009a | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
gmehmet | 1:f60eafbf009a | 24 | * Products, Inc. Branding Policy. |
gmehmet | 1:f60eafbf009a | 25 | * |
gmehmet | 1:f60eafbf009a | 26 | * The mere transfer of this software does not imply any licenses |
gmehmet | 1:f60eafbf009a | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
gmehmet | 1:f60eafbf009a | 28 | * trademarks, maskwork rights, or any other form of intellectual |
gmehmet | 1:f60eafbf009a | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
gmehmet | 1:f60eafbf009a | 30 | * ownership rights. |
gmehmet | 1:f60eafbf009a | 31 | **************************************************************************** |
gmehmet | 1:f60eafbf009a | 32 | */ |
gmehmet | 1:f60eafbf009a | 33 | |
gmehmet | 1:f60eafbf009a | 34 | #ifndef _SSINTERFACE_H_ |
gmehmet | 1:f60eafbf009a | 35 | #define _SSINTERFACE_H_ |
gmehmet | 1:f60eafbf009a | 36 | |
gmehmet | 1:f60eafbf009a | 37 | #include "mbed.h" |
gmehmet | 1:f60eafbf009a | 38 | #include "MaximSensor.h" |
gmehmet | 1:f60eafbf009a | 39 | #include "EventStats.h" |
gmehmet | 1:f60eafbf009a | 40 | |
gmehmet | 1:f60eafbf009a | 41 | #define SS_PLATFORM_MAX3263X "SmartSensor_MAX3263X" |
gmehmet | 1:f60eafbf009a | 42 | #define SS_PLATFORM_MAX32660 "SmartSensor_MAX32660" |
gmehmet | 1:f60eafbf009a | 43 | #define SS_BOOTLOADER_PLATFORM_MAX3263X "Bootloader_MAX3263X" |
gmehmet | 1:f60eafbf009a | 44 | #define SS_BOOTLOADER_PLATFORM_MAX32660 "Bootloader_MAX32660" |
gmehmet | 1:f60eafbf009a | 45 | |
gmehmet | 1:f60eafbf009a | 46 | |
gmehmet | 1:f60eafbf009a | 47 | #define SS_I2C_8BIT_SLAVE_ADDR 0xAA |
gmehmet | 1:f60eafbf009a | 48 | #define SS_DEFAULT_CMD_SLEEP_MS 2 |
gmehmet | 1:f60eafbf009a | 49 | #define SS_DEFAULT2_CMD_SLEEP_MS 4 |
gmehmet | 1:f60eafbf009a | 50 | #define SS_DEFAULT3_CMD_SLEEP_MS 30 |
gmehmet | 1:f60eafbf009a | 51 | #define SS_DUMP_REG_SLEEP_MS 100 |
gmehmet | 1:f60eafbf009a | 52 | #define SS_ENABLE_SENSOR_SLEEP_MS 20 |
gmehmet | 1:f60eafbf009a | 53 | |
gmehmet | 1:f60eafbf009a | 54 | #define SH_INPUT_DATA_DIRECT_SENSOR 0x00 // Default |
gmehmet | 1:f60eafbf009a | 55 | #define SH_INPUT_DATA_FROM_HOST 0x01 |
gmehmet | 1:f60eafbf009a | 56 | |
gmehmet | 1:f60eafbf009a | 57 | #define SS_SENSORIDX_MAX86140 0x00 |
gmehmet | 1:f60eafbf009a | 58 | #define SS_SENSORIDX_MAX30205 0x01 |
gmehmet | 1:f60eafbf009a | 59 | #define SS_SENSORIDX_MAX30001 0x02 |
gmehmet | 1:f60eafbf009a | 60 | #define SS_SENSORIDX_MAX30101 0x03 |
gmehmet | 1:f60eafbf009a | 61 | #define SS_SENSORIDX_ACCEL 0x04 |
gmehmet | 1:f60eafbf009a | 62 | |
gmehmet | 1:f60eafbf009a | 63 | #define SS_ALGOIDX_AGC 0x00 |
gmehmet | 1:f60eafbf009a | 64 | #define SS_ALGOIDX_AEC 0x01 |
gmehmet | 1:f60eafbf009a | 65 | #define SS_ALGOIDX_WHRM 0x02 |
gmehmet | 1:f60eafbf009a | 66 | #define SS_ALGOIDX_ECG 0x03 |
gmehmet | 1:f60eafbf009a | 67 | #define SS_ALGOIDX_BPT 0x04 |
gmehmet | 1:f60eafbf009a | 68 | #define SS_ALGOIDX_WSPO2 0x05 /// additional index |
gmehmet | 1:f60eafbf009a | 69 | |
gmehmet | 1:f60eafbf009a | 70 | |
gmehmet | 1:f60eafbf009a | 71 | #define SS_FAM_R_STATUS 0x00 |
gmehmet | 1:f60eafbf009a | 72 | #define SS_CMDIDX_STATUS 0x00 |
gmehmet | 1:f60eafbf009a | 73 | #define SS_SHIFT_STATUS_ERR 0 |
gmehmet | 1:f60eafbf009a | 74 | #define SS_MASK_STATUS_ERR (0x07 << SS_SHIFT_STATUS_ERR) |
gmehmet | 1:f60eafbf009a | 75 | #define SS_SHIFT_STATUS_DATA_RDY 3 |
gmehmet | 1:f60eafbf009a | 76 | #define SS_MASK_STATUS_DATA_RDY (1 << SS_SHIFT_STATUS_DATA_RDY) |
gmehmet | 1:f60eafbf009a | 77 | #define SS_SHIFT_STATUS_FIFO_OUT_OVR 4 |
gmehmet | 1:f60eafbf009a | 78 | #define SS_MASK_STATUS_FIFO_OUT_OVR (1 << SS_SHIFT_STATUS_FIFO_OUT_OVR) |
gmehmet | 1:f60eafbf009a | 79 | #define SS_SHIFT_STATUS_FIFO_IN_OVR 5 |
gmehmet | 1:f60eafbf009a | 80 | #define SS_MASK_STATUS_FIFO_IN_OVR (1 << SS_SHIFT_STATUS_FIFO_IN_OVR) |
gmehmet | 1:f60eafbf009a | 81 | |
gmehmet | 1:f60eafbf009a | 82 | #define SS_SHIFT_STATUS_LOG_OVR 6 |
gmehmet | 1:f60eafbf009a | 83 | #define SS_MASK_STATUS_LOG_OVR (1 << SS_SHIFT_STATUS_LOG_OVR) |
gmehmet | 1:f60eafbf009a | 84 | |
gmehmet | 1:f60eafbf009a | 85 | #define SS_SHIFT_STATUS_LOG_RDY 7 |
gmehmet | 1:f60eafbf009a | 86 | #define SS_MASK_STATUS_LOG_RDY (1 << SS_SHIFT_STATUS_LOG_RDY) |
gmehmet | 1:f60eafbf009a | 87 | |
gmehmet | 1:f60eafbf009a | 88 | |
gmehmet | 1:f60eafbf009a | 89 | #define SS_FAM_W_MODE 0x01 |
gmehmet | 1:f60eafbf009a | 90 | #define SS_FAM_R_MODE 0x02 |
gmehmet | 1:f60eafbf009a | 91 | #define SS_CMDIDX_MODE 0x00 |
gmehmet | 1:f60eafbf009a | 92 | #define SS_SHIFT_MODE_SHDN 0 |
gmehmet | 1:f60eafbf009a | 93 | #define SS_MASK_MODE_SHDN (1 << SS_SHIFT_MODE_SHDN) |
gmehmet | 1:f60eafbf009a | 94 | #define SS_SHIFT_MODE_RESET 1 |
gmehmet | 1:f60eafbf009a | 95 | #define SS_MASK_MODE_RESET (1 << SS_SHIFT_MODE_RESET) |
gmehmet | 1:f60eafbf009a | 96 | #define SS_SHIFT_MODE_FIFORESET 2 |
gmehmet | 1:f60eafbf009a | 97 | #define SS_MASK_MODE_FIFORESET (1 << SS_SHIFT_MODE_FIFORESET) |
gmehmet | 1:f60eafbf009a | 98 | #define SS_SHIFT_MODE_BOOTLDR 3 |
gmehmet | 1:f60eafbf009a | 99 | #define SS_MASK_MODE_BOOTLDR (1 << SS_SHIFT_MODE_BOOTLDR) |
gmehmet | 1:f60eafbf009a | 100 | |
gmehmet | 1:f60eafbf009a | 101 | #define SS_I2C_READ 0x03 |
gmehmet | 1:f60eafbf009a | 102 | |
gmehmet | 1:f60eafbf009a | 103 | #define SS_FAM_W_COMMCHAN 0x10 |
gmehmet | 1:f60eafbf009a | 104 | #define SS_FAM_R_COMMCHAN 0x11 |
gmehmet | 1:f60eafbf009a | 105 | #define SS_CMDIDX_OUTPUTMODE 0x00 |
gmehmet | 1:f60eafbf009a | 106 | #define SS_SHIFT_OUTPUTMODE_DATATYPE 0 |
gmehmet | 1:f60eafbf009a | 107 | #define SS_MASK_OUTPUTMODE_DATATYPE (0x03 << SS_SHIFT_OUTPUTMODE_DATATYPE) |
gmehmet | 1:f60eafbf009a | 108 | #define SS_DATATYPE_PAUSE 0 |
gmehmet | 1:f60eafbf009a | 109 | #define SS_DATATYPE_RAW 1 |
gmehmet | 1:f60eafbf009a | 110 | #define SS_DATATYPE_ALGO 2 |
gmehmet | 1:f60eafbf009a | 111 | #define SS_DATATYPE_BOTH 3 |
gmehmet | 1:f60eafbf009a | 112 | #define SS_SHIFT_OUTPUTMODE_SC_EN 2 |
gmehmet | 1:f60eafbf009a | 113 | #define SS_MASK_OUTPUTMODE_SC_EN (1 << SS_SHIFT_OUTPUTMODE_SC_EN) |
gmehmet | 1:f60eafbf009a | 114 | #define SS_CMDIDX_FIFOAFULL 0x01 |
gmehmet | 1:f60eafbf009a | 115 | |
gmehmet | 1:f60eafbf009a | 116 | #define SS_FAM_R_OUTPUTFIFO 0x12 |
gmehmet | 1:f60eafbf009a | 117 | #define SS_CMDIDX_OUT_NUMSAMPLES 0x00 |
gmehmet | 1:f60eafbf009a | 118 | #define SS_CMDIDX_READFIFO 0x01 |
gmehmet | 1:f60eafbf009a | 119 | |
gmehmet | 1:f60eafbf009a | 120 | #define SS_FAM_R_INPUTFIFO 0x13 |
gmehmet | 1:f60eafbf009a | 121 | #define SS_CMDIDX_SAMPLE_SIZE 0x00 |
gmehmet | 1:f60eafbf009a | 122 | #define SS_CMDIDX_INPUT_FIFO_SIZE 0x01 |
gmehmet | 1:f60eafbf009a | 123 | #define SS_CMDIDX_SENSOR_FIFO_SIZE 0x02 |
gmehmet | 1:f60eafbf009a | 124 | #define SS_CMDIDX_NUM_SAMPLES_SENSOR_FIFO 0x03 |
gmehmet | 1:f60eafbf009a | 125 | #define SS_CMDIDX_NUM_SAMPLES_INPUT_FIFO 0x04 |
gmehmet | 1:f60eafbf009a | 126 | |
gmehmet | 1:f60eafbf009a | 127 | #define SS_FAM_W_INPUTFIFO 0x14 |
gmehmet | 1:f60eafbf009a | 128 | #define SS_CMDIDX_WRITE_FIFO 0x00 |
gmehmet | 1:f60eafbf009a | 129 | |
gmehmet | 1:f60eafbf009a | 130 | #define SS_FAM_W_WRITEREG 0x40 |
gmehmet | 1:f60eafbf009a | 131 | #define SS_FAM_R_READREG 0x41 |
gmehmet | 1:f60eafbf009a | 132 | #define SS_FAM_R_REGATTRIBS 0x42 |
gmehmet | 1:f60eafbf009a | 133 | #define SS_FAM_R_DUMPREG 0x43 |
gmehmet | 1:f60eafbf009a | 134 | |
gmehmet | 1:f60eafbf009a | 135 | #define SS_FAM_W_SENSORMODE 0x44 |
gmehmet | 1:f60eafbf009a | 136 | #define SS_FAM_R_SENSORMODE 0x45 |
gmehmet | 1:f60eafbf009a | 137 | |
gmehmet | 1:f60eafbf009a | 138 | #define SS_FAM_W_ALGOCONFIG 0x50 |
gmehmet | 1:f60eafbf009a | 139 | #define SS_FAM_R_ALGOCONFIG 0x51 |
gmehmet | 1:f60eafbf009a | 140 | #define SS_CFGIDX_AGC_TARGET 0x00 |
gmehmet | 1:f60eafbf009a | 141 | #define SS_CFGIDX_AGC_CORR_COEFF 0x01 |
gmehmet | 1:f60eafbf009a | 142 | #define SS_CFGIDX_AGC_SENSITIVITY 0x02 |
gmehmet | 1:f60eafbf009a | 143 | #define SS_CFGIDX_AGC_SMP_AVG 0x03 |
gmehmet | 1:f60eafbf009a | 144 | |
gmehmet | 1:f60eafbf009a | 145 | #define SS_CFGIDX_WHRM_SR 0x00 |
gmehmet | 1:f60eafbf009a | 146 | #define SS_CFGIDX_WHRM_MAX_HEIGHT 0x01 |
gmehmet | 1:f60eafbf009a | 147 | #define SS_CFGIDX_WHRM_MAX_WEIGHT 0x02 |
gmehmet | 1:f60eafbf009a | 148 | #define SS_CFGIDX_WHRM_MAX_AGE 0x03 |
gmehmet | 1:f60eafbf009a | 149 | #define SS_CFGIDX_WHRM_MIN_HEIGHT 0x04 |
gmehmet | 1:f60eafbf009a | 150 | #define SS_CFGIDX_WHRM_MIN_WEIGHT 0x05 |
gmehmet | 1:f60eafbf009a | 151 | #define SS_CFGIDX_WHRM_MIN_AGE 0x06 |
gmehmet | 1:f60eafbf009a | 152 | #define SS_CFGIDX_WHRM_DEF_HEIGHT 0x07 |
gmehmet | 1:f60eafbf009a | 153 | #define SS_CFGIDX_WHRM_DEF_WEIGHT 0x08 |
gmehmet | 1:f60eafbf009a | 154 | #define SS_CFGIDX_WHRM_DEF_AGE 0x09 |
gmehmet | 1:f60eafbf009a | 155 | #define SS_CFGIDX_WHRM_INIT_HR 0x0A |
gmehmet | 1:f60eafbf009a | 156 | |
gmehmet | 1:f60eafbf009a | 157 | // additional for WHRM_AEC_SCD |
gmehmet | 1:f60eafbf009a | 158 | #define SS_CFGIDX_WHRM_AEC_ENABLE 0x0B |
gmehmet | 1:f60eafbf009a | 159 | #define SS_CFGIDX_WHRM_SCD_ENABLE 0x0C |
gmehmet | 1:f60eafbf009a | 160 | #define SS_CFGIDX_WHRM_ADJ_TARGET_PD_CURRENT_PERIOD 0x0D |
gmehmet | 1:f60eafbf009a | 161 | #define SS_CFGIDX_WHRM_SCD_DEBOUNCE_WINDOW 0x0E |
gmehmet | 1:f60eafbf009a | 162 | #define SS_CFGIDX_WHRM_MOTION_MAG_THRESHOLD 0x0F |
gmehmet | 1:f60eafbf009a | 163 | #define SS_CFGIDX_WHRM_MIN_PD_CURRENT 0x10 |
gmehmet | 1:f60eafbf009a | 164 | #define SS_CFGIDX_WHRM_PD_CONFIG 0x11 |
gmehmet | 1:f60eafbf009a | 165 | #define SS_CFGIDX_WHRM_LED_CONFIG 0x12 |
gmehmet | 1:f60eafbf009a | 166 | |
gmehmet | 1:f60eafbf009a | 167 | // config for WSPO2 |
gmehmet | 1:f60eafbf009a | 168 | #define SS_CFGIDX_WSPO2_CAL 0x00 |
gmehmet | 1:f60eafbf009a | 169 | #define SS_CFGIDX_WSPO2_SR 0x01 |
gmehmet | 1:f60eafbf009a | 170 | #define SS_CFGIDX_WSPO2_ALGO_MODE 0x02 |
gmehmet | 1:f60eafbf009a | 171 | #define SS_CFGIDX_WSPO2_AGC_MODE 0x03 |
gmehmet | 1:f60eafbf009a | 172 | #define SS_CFGIDX_WSPO2_MOTION_DET 0x04 |
gmehmet | 1:f60eafbf009a | 173 | #define SS_CFGIDX_WSPO2_MOTION_PERIOD 0x05 |
gmehmet | 1:f60eafbf009a | 174 | #define SS_CFGIDX_WSPO2_MOTION_THRESHOLD 0x06 |
gmehmet | 1:f60eafbf009a | 175 | #define SS_CFGIDX_WSPO2_AGC_TIMEOUT 0x07 |
gmehmet | 1:f60eafbf009a | 176 | #define SS_CFGIDX_WSPO2_TIMEOUT 0x08 |
gmehmet | 1:f60eafbf009a | 177 | #define SS_CFGIDX_WSPO2_PD_CONFIG 0x09 |
gmehmet | 1:f60eafbf009a | 178 | |
gmehmet | 1:f60eafbf009a | 179 | |
gmehmet | 1:f60eafbf009a | 180 | #define SS_CFGIDX_BP_USE_MED 0x00 |
gmehmet | 1:f60eafbf009a | 181 | #define SS_CFGIDX_BP_SYS_BP_CAL 0x01 |
gmehmet | 1:f60eafbf009a | 182 | #define SS_CFGIDX_BP_DIA_BP_CAL 0x02 |
gmehmet | 1:f60eafbf009a | 183 | #define SS_CFGIDX_BP_CAL_DATA 0x03 |
gmehmet | 1:f60eafbf009a | 184 | #define SS_CFGIDX_BP_EST_DATE 0x04 |
gmehmet | 1:f60eafbf009a | 185 | #define SS_CFGIDX_BP_EST_NONREST 0x05 |
gmehmet | 1:f60eafbf009a | 186 | #define SS_CFGIDX_BP_SPO2_COEFS 0x06 |
gmehmet | 1:f60eafbf009a | 187 | |
gmehmet | 1:f60eafbf009a | 188 | #define SS_FAM_W_ALGOMODE 0x52 |
gmehmet | 1:f60eafbf009a | 189 | #define SS_FAM_R_ALGOMODE 0x53 |
gmehmet | 1:f60eafbf009a | 190 | |
gmehmet | 1:f60eafbf009a | 191 | #define SS_FAM_W_EXTERNSENSORMODE 0x60 |
gmehmet | 1:f60eafbf009a | 192 | #define SS_W_EXT_SENSOR_MODE 0x00 |
gmehmet | 1:f60eafbf009a | 193 | #define SS_FAM_R_EXTERNSENSORMODE 0x61 |
gmehmet | 1:f60eafbf009a | 194 | #define SS_R_EXT_SENSOR_MODE 0x00 |
gmehmet | 1:f60eafbf009a | 195 | |
gmehmet | 1:f60eafbf009a | 196 | #define SS_FAM_R_SELFTEST 0x70 |
gmehmet | 1:f60eafbf009a | 197 | |
gmehmet | 1:f60eafbf009a | 198 | #define SS_FAM_W_BOOTLOADER 0x80 |
gmehmet | 1:f60eafbf009a | 199 | #define SS_CMDIDX_SETIV 0x00 |
gmehmet | 1:f60eafbf009a | 200 | #define SS_CMDIDX_SETAUTH 0x01 |
gmehmet | 1:f60eafbf009a | 201 | #define SS_CMDIDX_SETNUMPAGES 0x02 |
gmehmet | 1:f60eafbf009a | 202 | #define SS_CMDIDX_ERASE 0x03 |
gmehmet | 1:f60eafbf009a | 203 | #define SS_CMDIDX_SENDPAGE 0x04 |
gmehmet | 1:f60eafbf009a | 204 | #define SS_CMDIDX_ERASE_PAGE 0x05 |
gmehmet | 1:f60eafbf009a | 205 | #define SS_FAM_R_BOOTLOADER 0x81 |
gmehmet | 1:f60eafbf009a | 206 | #define SS_CMDIDX_BOOTFWVERSION 0x00 |
gmehmet | 1:f60eafbf009a | 207 | #define SS_CMDIDX_PAGESIZE 0x01 |
gmehmet | 1:f60eafbf009a | 208 | |
gmehmet | 1:f60eafbf009a | 209 | #define SS_FAM_W_BOOTLOADER_CFG 0x82 |
gmehmet | 1:f60eafbf009a | 210 | #define SS_FAM_R_BOOTLOADER_CFG 0x83 |
gmehmet | 1:f60eafbf009a | 211 | #define SS_CMDIDX_BL_SAVE 0x00 |
gmehmet | 1:f60eafbf009a | 212 | #define SS_CMDIDX_BL_ENTRY 0x01 |
gmehmet | 1:f60eafbf009a | 213 | #define SS_BL_CFG_ENTER_BL_MODE 0x00 |
gmehmet | 1:f60eafbf009a | 214 | #define SS_BL_CFG_EBL_PIN 0x01 |
gmehmet | 1:f60eafbf009a | 215 | #define SS_BL_CFG_EBL_POL 0x02 |
gmehmet | 1:f60eafbf009a | 216 | #define SS_CMDIDX_BL_EXIT 0x02 |
gmehmet | 1:f60eafbf009a | 217 | #define SS_BL_CFG_EXIT_BL_MODE 0x00 |
gmehmet | 1:f60eafbf009a | 218 | #define SS_BL_CFG_TIMEOUT 0x01 |
gmehmet | 1:f60eafbf009a | 219 | |
gmehmet | 1:f60eafbf009a | 220 | /* Enable logging/debugging */ |
gmehmet | 1:f60eafbf009a | 221 | #define SS_FAM_R_LOG 0x90 |
gmehmet | 1:f60eafbf009a | 222 | #define SS_CMDIDX_R_LOG_DATA 0x00 |
gmehmet | 1:f60eafbf009a | 223 | #define SS_CMDIDX_R_LOG_LEN 0x01 |
gmehmet | 1:f60eafbf009a | 224 | |
gmehmet | 1:f60eafbf009a | 225 | #define SS_CMDIDX_R_LOG_LEVEL 0x02 |
gmehmet | 1:f60eafbf009a | 226 | #define SS_LOG_DISABLE 0x00 |
gmehmet | 1:f60eafbf009a | 227 | #define SS_LOG_CRITICAL 0x01 |
gmehmet | 1:f60eafbf009a | 228 | #define SS_LOG_ERROR 0x02 |
gmehmet | 1:f60eafbf009a | 229 | #define SS_LOG_INFO 0x04 |
gmehmet | 1:f60eafbf009a | 230 | #define SS_LOG_DEBUG 0x08 |
gmehmet | 1:f60eafbf009a | 231 | |
gmehmet | 1:f60eafbf009a | 232 | #define SS_FAM_W_LOG_CFG 0x91 |
gmehmet | 1:f60eafbf009a | 233 | #define SS_CMDIDX_LOG_GET_LEVEL 0x00 |
gmehmet | 1:f60eafbf009a | 234 | #define SS_CMDIDX_LOG_SET_LEVEL 0x01 |
gmehmet | 1:f60eafbf009a | 235 | |
gmehmet | 1:f60eafbf009a | 236 | #define SS_FAM_R_IDENTITY 0xFF |
gmehmet | 1:f60eafbf009a | 237 | #define SS_CMDIDX_PLATTYPE 0x00 |
gmehmet | 1:f60eafbf009a | 238 | #define SS_CMDIDX_PARTID 0x01 |
gmehmet | 1:f60eafbf009a | 239 | #define SS_CMDIDX_REVID 0x02 |
gmehmet | 1:f60eafbf009a | 240 | #define SS_CMDIDX_FWVERSION 0x03 |
gmehmet | 1:f60eafbf009a | 241 | #define SS_CMDIDX_AVAILSENSORS 0x04 |
gmehmet | 1:f60eafbf009a | 242 | #define SS_CMDIDX_DRIVERVER 0x05 |
gmehmet | 1:f60eafbf009a | 243 | #define SS_CMDIDX_AVAILALGOS 0x06 |
gmehmet | 1:f60eafbf009a | 244 | #define SS_CMDIDX_ALGOVER 0x07 |
gmehmet | 1:f60eafbf009a | 245 | |
gmehmet | 1:f60eafbf009a | 246 | |
gmehmet | 1:f60eafbf009a | 247 | typedef enum { |
gmehmet | 1:f60eafbf009a | 248 | SS_SUCCESS=0x00, |
gmehmet | 1:f60eafbf009a | 249 | |
gmehmet | 1:f60eafbf009a | 250 | SS_ERR_COMMAND=0x01, |
gmehmet | 1:f60eafbf009a | 251 | SS_ERR_UNAVAILABLE=0x02, |
gmehmet | 1:f60eafbf009a | 252 | SS_ERR_DATA_FORMAT=0x03, |
gmehmet | 1:f60eafbf009a | 253 | SS_ERR_INPUT_VALUE=0x04, |
gmehmet | 1:f60eafbf009a | 254 | |
gmehmet | 1:f60eafbf009a | 255 | SS_ERR_BTLDR_GENERAL=0x80, |
gmehmet | 1:f60eafbf009a | 256 | SS_ERR_BTLDR_CHECKSUM=0x81, |
gmehmet | 1:f60eafbf009a | 257 | |
gmehmet | 1:f60eafbf009a | 258 | SS_ERR_TRY_AGAIN=0xFE, |
gmehmet | 1:f60eafbf009a | 259 | SS_ERR_UNKNOWN=0xFF, |
gmehmet | 1:f60eafbf009a | 260 | } SS_STATUS; |
gmehmet | 1:f60eafbf009a | 261 | |
gmehmet | 1:f60eafbf009a | 262 | typedef enum { |
gmehmet | 1:f60eafbf009a | 263 | SS_PLAT_MAX3263X=0, |
gmehmet | 1:f60eafbf009a | 264 | SS_PLAT_MAX32660=1, |
gmehmet | 1:f60eafbf009a | 265 | } SS_PLAT_TYPE; |
gmehmet | 1:f60eafbf009a | 266 | |
gmehmet | 1:f60eafbf009a | 267 | //self test result masks |
gmehmet | 1:f60eafbf009a | 268 | #define FAILURE_COMM 0x01 |
gmehmet | 1:f60eafbf009a | 269 | #define FAILURE_INTERRUPT 0x02 |
gmehmet | 1:f60eafbf009a | 270 | |
gmehmet | 1:f60eafbf009a | 271 | #define SS_SMALL_BUF_SIZE 32 |
gmehmet | 1:f60eafbf009a | 272 | #define SS_MED_BUF_SIZE 512 |
gmehmet | 1:f60eafbf009a | 273 | #define SS_LARGE_BUF_SIZE 8224 |
gmehmet | 1:f60eafbf009a | 274 | |
gmehmet | 1:f60eafbf009a | 275 | #define SS_RESET_TIME 10 |
gmehmet | 1:f60eafbf009a | 276 | #define SS_STARTUP_TO_BTLDR_TIME 50 |
gmehmet | 1:f60eafbf009a | 277 | #define SS_STARTUP_TO_MAIN_APP_TIME 1000 |
gmehmet | 1:f60eafbf009a | 278 | |
gmehmet | 1:f60eafbf009a | 279 | #define SS_MAX_SUPPORTED_SENSOR_NUM 0xFE |
gmehmet | 1:f60eafbf009a | 280 | #define SS_MAX_SUPPORTED_ALGO_NUM 0xFE |
gmehmet | 1:f60eafbf009a | 281 | #define SS_MAX_SUPPORTED_ALGO_CFG_NUM 0xFE |
gmehmet | 1:f60eafbf009a | 282 | #define SS_MAX_SUPPORTED_MODE_NUM 0xFF |
gmehmet | 1:f60eafbf009a | 283 | |
gmehmet | 1:f60eafbf009a | 284 | /* BOOTLOADER HOST */ |
gmehmet | 1:f60eafbf009a | 285 | #define EBL_CMD_TRIGGER_MODE 0 |
gmehmet | 1:f60eafbf009a | 286 | #define EBL_GPIO_TRIGGER_MODE 1 |
gmehmet | 1:f60eafbf009a | 287 | |
gmehmet | 1:f60eafbf009a | 288 | |
gmehmet | 1:f60eafbf009a | 289 | typedef struct { |
gmehmet | 1:f60eafbf009a | 290 | int data_size; |
gmehmet | 1:f60eafbf009a | 291 | Callback<void(uint8_t*)> callback; |
gmehmet | 1:f60eafbf009a | 292 | } ss_data_req; |
gmehmet | 1:f60eafbf009a | 293 | |
gmehmet | 1:f60eafbf009a | 294 | typedef union { |
gmehmet | 1:f60eafbf009a | 295 | struct { |
gmehmet | 1:f60eafbf009a | 296 | uint16_t whrm_enabled :1; |
gmehmet | 1:f60eafbf009a | 297 | uint16_t wspo2_enabled :1; /// added |
gmehmet | 1:f60eafbf009a | 298 | uint16_t bpt_enabled :1; |
gmehmet | 1:f60eafbf009a | 299 | uint16_t agc_enabled :1; |
gmehmet | 1:f60eafbf009a | 300 | uint16_t max8614x_enabled:1; |
gmehmet | 1:f60eafbf009a | 301 | uint16_t max3010x_enabled:1; |
gmehmet | 1:f60eafbf009a | 302 | uint16_t accel_enabled :1; |
gmehmet | 1:f60eafbf009a | 303 | |
gmehmet | 1:f60eafbf009a | 304 | uint16_t sensorhub_accel :1; // added to specify if sensor hub accel is used or host (default) |
gmehmet | 1:f60eafbf009a | 305 | uint16_t placeholder :8; // |
gmehmet | 1:f60eafbf009a | 306 | }; |
gmehmet | 1:f60eafbf009a | 307 | uint16_t status_vals; |
gmehmet | 1:f60eafbf009a | 308 | } status_algo_sensors_st; |
gmehmet | 1:f60eafbf009a | 309 | |
gmehmet | 1:f60eafbf009a | 310 | |
gmehmet | 1:f60eafbf009a | 311 | /** |
gmehmet | 1:f60eafbf009a | 312 | * @brief SSInterface is Maxim's SmartSensor Interface class |
gmehmet | 1:f60eafbf009a | 313 | */ |
gmehmet | 1:f60eafbf009a | 314 | class SSInterface |
gmehmet | 1:f60eafbf009a | 315 | { |
gmehmet | 1:f60eafbf009a | 316 | public: |
gmehmet | 1:f60eafbf009a | 317 | |
gmehmet | 1:f60eafbf009a | 318 | /* PUBLIC FUNCTION DECLARATIONS */ |
gmehmet | 1:f60eafbf009a | 319 | /** |
gmehmet | 1:f60eafbf009a | 320 | * @brief SSInterface constructor. |
gmehmet | 1:f60eafbf009a | 321 | * |
gmehmet | 1:f60eafbf009a | 322 | * @param[in] i2cBus - reference to the I2C bus for the SmartSensor |
gmehmet | 1:f60eafbf009a | 323 | * @param[in] ss_mfio - name of SmartSensor multi-function IO pin |
gmehmet | 1:f60eafbf009a | 324 | * @param[in] ss_reset - name of SmartSensor Reset pin |
gmehmet | 1:f60eafbf009a | 325 | * |
gmehmet | 1:f60eafbf009a | 326 | */ |
gmehmet | 1:f60eafbf009a | 327 | SSInterface(I2C &i2cBus, PinName ss_mfio, PinName ss_reset); |
gmehmet | 1:f60eafbf009a | 328 | |
gmehmet | 1:f60eafbf009a | 329 | /** |
gmehmet | 1:f60eafbf009a | 330 | * @brief SSInterface constructor. |
gmehmet | 1:f60eafbf009a | 331 | * |
gmehmet | 1:f60eafbf009a | 332 | * @param[in] spiBus - reference to the SPI bus for the SmartSensor |
gmehmet | 1:f60eafbf009a | 333 | * @param[in] ss_mfio - name of SmartSensor multi-function IO pin |
gmehmet | 1:f60eafbf009a | 334 | * @param[in] ss_reset - name of SmartSensor Reset pin |
gmehmet | 1:f60eafbf009a | 335 | * |
gmehmet | 1:f60eafbf009a | 336 | */ |
gmehmet | 1:f60eafbf009a | 337 | SSInterface(SPI &spiBus, PinName ss_mfio, PinName ss_reset); |
gmehmet | 1:f60eafbf009a | 338 | |
gmehmet | 1:f60eafbf009a | 339 | /** |
gmehmet | 1:f60eafbf009a | 340 | * @brief DSInterface destructor. |
gmehmet | 1:f60eafbf009a | 341 | * |
gmehmet | 1:f60eafbf009a | 342 | */ |
gmehmet | 1:f60eafbf009a | 343 | ~SSInterface(); |
gmehmet | 1:f60eafbf009a | 344 | |
gmehmet | 1:f60eafbf009a | 345 | /** |
gmehmet | 1:f60eafbf009a | 346 | * @brief Write a command to the SmartSensor and get status response |
gmehmet | 1:f60eafbf009a | 347 | * |
gmehmet | 1:f60eafbf009a | 348 | * @param[in] cmd_bytes - Pointer to the command's family and index bytes |
gmehmet | 1:f60eafbf009a | 349 | * @param[in] cmd_idx_len - The number of bytes in the command |
gmehmet | 1:f60eafbf009a | 350 | * @param[in] data - Pointer to the command's data bytes |
gmehmet | 1:f60eafbf009a | 351 | * @param[in] data_len - The number data bytes |
gmehmet | 1:f60eafbf009a | 352 | * |
gmehmet | 1:f60eafbf009a | 353 | * @return SS_STATUS byte |
gmehmet | 1:f60eafbf009a | 354 | */ |
gmehmet | 1:f60eafbf009a | 355 | SS_STATUS write_cmd(uint8_t *cmd_bytes, int cmd_bytes_len, |
gmehmet | 1:f60eafbf009a | 356 | uint8_t *data, int data_len, |
gmehmet | 1:f60eafbf009a | 357 | int sleep_ms = SS_DEFAULT_CMD_SLEEP_MS); |
gmehmet | 1:f60eafbf009a | 358 | |
gmehmet | 1:f60eafbf009a | 359 | |
gmehmet | 1:f60eafbf009a | 360 | /** |
gmehmet | 1:f60eafbf009a | 361 | * @brief Write a command to the SmartSensor and get status response |
gmehmet | 1:f60eafbf009a | 362 | * |
gmehmet | 1:f60eafbf009a | 363 | * @param[in] tx_buf - Pointer to the command's family, index bytes and data bytes |
gmehmet | 1:f60eafbf009a | 364 | * @param[in] tx_len - Total transaction lenght to send |
gmehmet | 1:f60eafbf009a | 365 | * |
gmehmet | 1:f60eafbf009a | 366 | * @return SS_STATUS byte |
gmehmet | 1:f60eafbf009a | 367 | */ |
gmehmet | 1:f60eafbf009a | 368 | SS_STATUS write_cmd(uint8_t *tx_buf, int tx_len, |
gmehmet | 1:f60eafbf009a | 369 | int sleep_ms = SS_DEFAULT_CMD_SLEEP_MS); |
gmehmet | 1:f60eafbf009a | 370 | |
gmehmet | 1:f60eafbf009a | 371 | /** |
gmehmet | 1:f60eafbf009a | 372 | * @brief Write a command to the SmartSensor and get status response |
gmehmet | 1:f60eafbf009a | 373 | * |
gmehmet | 1:f60eafbf009a | 374 | * @param[in] cmd_bytes - Pointer to the command's family and index bytes |
gmehmet | 1:f60eafbf009a | 375 | * @param[in] cmd_idx_len - The number of bytes in the command |
gmehmet | 1:f60eafbf009a | 376 | * @param[in] data - Pointer to the command's data bytes |
gmehmet | 1:f60eafbf009a | 377 | * @param[in] data_len - The number data bytes |
gmehmet | 1:f60eafbf009a | 378 | * @param[in] rxbuf - Buffer to fill in with read data (including status byte) |
gmehmet | 1:f60eafbf009a | 379 | * @param[in] rxbuf_sz - Size of the rx buffer (to prevent overflow) |
gmehmet | 1:f60eafbf009a | 380 | * |
gmehmet | 1:f60eafbf009a | 381 | * @return SS_STATUS byte |
gmehmet | 1:f60eafbf009a | 382 | */ |
gmehmet | 1:f60eafbf009a | 383 | SS_STATUS read_cmd( uint8_t *cmd_bytes, int cmd_bytes_len, |
gmehmet | 1:f60eafbf009a | 384 | uint8_t *data, int data_len, |
gmehmet | 1:f60eafbf009a | 385 | uint8_t *rxbuf, int rxbuf_sz, |
gmehmet | 1:f60eafbf009a | 386 | int sleep_ms = SS_DEFAULT_CMD_SLEEP_MS); |
gmehmet | 1:f60eafbf009a | 387 | |
gmehmet | 1:f60eafbf009a | 388 | /** |
gmehmet | 1:f60eafbf009a | 389 | * @brief Get a string representing the SmartSensor firmware version |
gmehmet | 1:f60eafbf009a | 390 | * @details If in bootloader mode, returns bootloader version |
gmehmet | 1:f60eafbf009a | 391 | * |
gmehmet | 1:f60eafbf009a | 392 | * @return Pointer to firmware version string |
gmehmet | 1:f60eafbf009a | 393 | */ |
gmehmet | 1:f60eafbf009a | 394 | const char* get_ss_fw_version(); |
gmehmet | 1:f60eafbf009a | 395 | |
gmehmet | 1:f60eafbf009a | 396 | /** |
gmehmet | 1:f60eafbf009a | 397 | * @brief Get a string representing the SmartSensor algo version |
gmehmet | 1:f60eafbf009a | 398 | * @details If in bootloader mode, returns bootloader version |
gmehmet | 1:f60eafbf009a | 399 | * |
gmehmet | 1:f60eafbf009a | 400 | * @return Pointer to algo version string |
gmehmet | 1:f60eafbf009a | 401 | */ |
gmehmet | 1:f60eafbf009a | 402 | const char* get_ss_algo_version(); |
gmehmet | 1:f60eafbf009a | 403 | |
gmehmet | 1:f60eafbf009a | 404 | /** |
gmehmet | 1:f60eafbf009a | 405 | * @brief Get a string representing the SmartSensor platform type |
gmehmet | 1:f60eafbf009a | 406 | * |
gmehmet | 1:f60eafbf009a | 407 | * @return Pointer to platform type string |
gmehmet | 1:f60eafbf009a | 408 | */ |
gmehmet | 1:f60eafbf009a | 409 | const char* get_ss_platform_name(); |
gmehmet | 1:f60eafbf009a | 410 | |
gmehmet | 1:f60eafbf009a | 411 | /** |
gmehmet | 1:f60eafbf009a | 412 | * @brief Reset the SmartSensor and jump to main application |
gmehmet | 1:f60eafbf009a | 413 | * |
gmehmet | 1:f60eafbf009a | 414 | * @return SS_STATUS code indicating success |
gmehmet | 1:f60eafbf009a | 415 | */ |
gmehmet | 1:f60eafbf009a | 416 | SS_STATUS reset_to_main_app(); |
gmehmet | 1:f60eafbf009a | 417 | |
gmehmet | 1:f60eafbf009a | 418 | /** |
gmehmet | 1:f60eafbf009a | 419 | * @brief Reset the SmartSensor and jump to bootloader |
gmehmet | 1:f60eafbf009a | 420 | * |
gmehmet | 1:f60eafbf009a | 421 | * @return SS_STATUS code indicating success |
gmehmet | 1:f60eafbf009a | 422 | */ |
gmehmet | 1:f60eafbf009a | 423 | SS_STATUS reset_to_bootloader(); |
gmehmet | 1:f60eafbf009a | 424 | |
gmehmet | 1:f60eafbf009a | 425 | /** |
gmehmet | 1:f60eafbf009a | 426 | * @brief Reset the SmartSensor |
gmehmet | 1:f60eafbf009a | 427 | * @details If the SmartSensor was in bootloader, it will jump back into bootloader |
gmehmet | 1:f60eafbf009a | 428 | * If the SmartSensor was in main app, it will jump back into main app |
gmehmet | 1:f60eafbf009a | 429 | * |
gmehmet | 1:f60eafbf009a | 430 | * @return SS_STATUS code indicating success |
gmehmet | 1:f60eafbf009a | 431 | */ |
gmehmet | 1:f60eafbf009a | 432 | SS_STATUS reset(); |
gmehmet | 1:f60eafbf009a | 433 | |
gmehmet | 1:f60eafbf009a | 434 | /** |
gmehmet | 1:f60eafbf009a | 435 | * @brief run the self test commands |
gmehmet | 1:f60eafbf009a | 436 | * param[in] idx - the id of the sensor for the self test |
gmehmet | 1:f60eafbf009a | 437 | * param[in] result - self-test response |
gmehmet | 1:f60eafbf009a | 438 | * param[in] sleep_ms - duration of wait for read command |
gmehmet | 1:f60eafbf009a | 439 | * @return SS_STATUS code indicating success |
gmehmet | 1:f60eafbf009a | 440 | */ |
gmehmet | 1:f60eafbf009a | 441 | SS_STATUS self_test(int idx, uint8_t *result, int sleep_ms = SS_DEFAULT_CMD_SLEEP_MS); |
gmehmet | 1:f60eafbf009a | 442 | |
gmehmet | 1:f60eafbf009a | 443 | /** |
gmehmet | 1:f60eafbf009a | 444 | * @brief Check if SmartSensor is in bootloader mode |
gmehmet | 1:f60eafbf009a | 445 | * |
gmehmet | 1:f60eafbf009a | 446 | * @return 1 if in bootloader mode, 0 if in main app, -1 if comm error |
gmehmet | 1:f60eafbf009a | 447 | */ |
gmehmet | 1:f60eafbf009a | 448 | int in_bootldr_mode(); |
gmehmet | 1:f60eafbf009a | 449 | |
gmehmet | 1:f60eafbf009a | 450 | |
gmehmet | 1:f60eafbf009a | 451 | /** |
gmehmet | 1:f60eafbf009a | 452 | * @brief Read register from a device onboard SmartSensor |
gmehmet | 1:f60eafbf009a | 453 | * |
gmehmet | 1:f60eafbf009a | 454 | * @param[in] idx - Index of device to read |
gmehmet | 1:f60eafbf009a | 455 | * @param[in] addr - Register address |
gmehmet | 1:f60eafbf009a | 456 | * @param[out] val - Register value |
gmehmet | 1:f60eafbf009a | 457 | * |
gmehmet | 1:f60eafbf009a | 458 | * @return SS_SUCCESS on success |
gmehmet | 1:f60eafbf009a | 459 | */ |
gmehmet | 1:f60eafbf009a | 460 | SS_STATUS get_reg(int idx, uint8_t addr, uint32_t *val); |
gmehmet | 1:f60eafbf009a | 461 | |
gmehmet | 1:f60eafbf009a | 462 | /** |
gmehmet | 1:f60eafbf009a | 463 | * @brief Set register of a device onboard SmartSensor |
gmehmet | 1:f60eafbf009a | 464 | * |
gmehmet | 1:f60eafbf009a | 465 | * @param[in] idx - Index of device to read |
gmehmet | 1:f60eafbf009a | 466 | * @param[in] addr - Register address |
gmehmet | 1:f60eafbf009a | 467 | * @param[in] val - Register value |
gmehmet | 1:f60eafbf009a | 468 | * @param[in] byte_size - Size of IC register in bytes |
gmehmet | 1:f60eafbf009a | 469 | * |
gmehmet | 1:f60eafbf009a | 470 | * @return SS_SUCCESS on success |
gmehmet | 1:f60eafbf009a | 471 | */ |
gmehmet | 1:f60eafbf009a | 472 | SS_STATUS set_reg(int idx, uint8_t addr, uint32_t val, int byte_size); |
gmehmet | 1:f60eafbf009a | 473 | |
gmehmet | 1:f60eafbf009a | 474 | /** |
gmehmet | 1:f60eafbf009a | 475 | * @brief Dump registers of a device onboard SmartSensor |
gmehmet | 1:f60eafbf009a | 476 | * |
gmehmet | 1:f60eafbf009a | 477 | * @param[in] idx - Index of device |
gmehmet | 1:f60eafbf009a | 478 | * @param[in] reg_vals - Array of addr_val_pairs |
gmehmet | 1:f60eafbf009a | 479 | * @param[in] reg_vals_sz - Number of items reg_vals can hold |
gmehmet | 1:f60eafbf009a | 480 | * @param[out] num_regs - Number of registers returned by command |
gmehmet | 1:f60eafbf009a | 481 | * |
gmehmet | 1:f60eafbf009a | 482 | * @return SS_SUCCESS on success |
gmehmet | 1:f60eafbf009a | 483 | */ |
gmehmet | 1:f60eafbf009a | 484 | SS_STATUS dump_reg(int idx, addr_val_pair* reg_vals, int reg_vals_sz, int* num_regs); |
gmehmet | 1:f60eafbf009a | 485 | |
gmehmet | 1:f60eafbf009a | 486 | |
gmehmet | 1:f60eafbf009a | 487 | /** |
gmehmet | 1:f60eafbf009a | 488 | * @brief Enable a device on the SmartSensor |
gmehmet | 1:f60eafbf009a | 489 | * |
gmehmet | 1:f60eafbf009a | 490 | * @param[in] idx - Index of device |
gmehmet | 1:f60eafbf009a | 491 | * @param[in] mode - Mode to set the device to |
gmehmet | 1:f60eafbf009a | 492 | * @param[in] data_req - Data request |
gmehmet | 1:f60eafbf009a | 493 | * @param[in] ext_ - Data request |
gmehmet | 1:f60eafbf009a | 494 | * |
gmehmet | 1:f60eafbf009a | 495 | * @return SS_SUCCESS on success |
gmehmet | 1:f60eafbf009a | 496 | */ |
gmehmet | 1:f60eafbf009a | 497 | SS_STATUS enable_sensor(int idx, int mode, ss_data_req* data_req, uint8_t ext_mode = SH_INPUT_DATA_DIRECT_SENSOR); |
gmehmet | 1:f60eafbf009a | 498 | |
gmehmet | 1:f60eafbf009a | 499 | /** |
gmehmet | 1:f60eafbf009a | 500 | * @brief Disable a device on the SmartSensor |
gmehmet | 1:f60eafbf009a | 501 | * |
gmehmet | 1:f60eafbf009a | 502 | * @param[in] idx - Index of device |
gmehmet | 1:f60eafbf009a | 503 | * |
gmehmet | 1:f60eafbf009a | 504 | * @return SS_SUCCESS on success |
gmehmet | 1:f60eafbf009a | 505 | */ |
gmehmet | 1:f60eafbf009a | 506 | SS_STATUS disable_sensor(int idx); |
gmehmet | 1:f60eafbf009a | 507 | |
gmehmet | 1:f60eafbf009a | 508 | /** |
gmehmet | 1:f60eafbf009a | 509 | * @brief Enable an algorithm on the SmartSensor |
gmehmet | 1:f60eafbf009a | 510 | * |
gmehmet | 1:f60eafbf009a | 511 | * @param[in] idx - Index of device |
gmehmet | 1:f60eafbf009a | 512 | * @param[in] mode - Mode to set the device to |
gmehmet | 1:f60eafbf009a | 513 | * @param[in] data_req - Data request |
gmehmet | 1:f60eafbf009a | 514 | * |
gmehmet | 1:f60eafbf009a | 515 | * @return SS_SUCCESS on success |
gmehmet | 1:f60eafbf009a | 516 | */ |
gmehmet | 1:f60eafbf009a | 517 | SS_STATUS enable_algo(int idx, int mode, ss_data_req* data_req); |
gmehmet | 1:f60eafbf009a | 518 | |
gmehmet | 1:f60eafbf009a | 519 | /** |
gmehmet | 1:f60eafbf009a | 520 | * @brief Disable an algorithm on the SmartSensor |
gmehmet | 1:f60eafbf009a | 521 | * |
gmehmet | 1:f60eafbf009a | 522 | * @param[in] idx - Index of device |
gmehmet | 1:f60eafbf009a | 523 | * |
gmehmet | 1:f60eafbf009a | 524 | * @return SS_SUCCESS on success |
gmehmet | 1:f60eafbf009a | 525 | */ |
gmehmet | 1:f60eafbf009a | 526 | SS_STATUS disable_algo(int idx); |
gmehmet | 1:f60eafbf009a | 527 | |
gmehmet | 1:f60eafbf009a | 528 | /** |
gmehmet | 1:f60eafbf009a | 529 | * @brief Set the value of an algorithm configuration parameter |
gmehmet | 1:f60eafbf009a | 530 | * |
gmehmet | 1:f60eafbf009a | 531 | * @param[in] algo_idx Index of algorithm |
gmehmet | 1:f60eafbf009a | 532 | * @param[in] cfg_idx Index of configuration parameter |
gmehmet | 1:f60eafbf009a | 533 | * @param[in] cfg Array of configuration bytes |
gmehmet | 1:f60eafbf009a | 534 | * @param[in] cfg_sz Size of cfg array |
gmehmet | 1:f60eafbf009a | 535 | * |
gmehmet | 1:f60eafbf009a | 536 | * @return SS_SUCCESS on success |
gmehmet | 1:f60eafbf009a | 537 | */ |
gmehmet | 1:f60eafbf009a | 538 | SS_STATUS set_algo_cfg(int algo_idx, int cfg_idx, uint8_t *cfg, int cfg_sz); |
gmehmet | 1:f60eafbf009a | 539 | |
gmehmet | 1:f60eafbf009a | 540 | /** |
gmehmet | 1:f60eafbf009a | 541 | * @brief Get the value of an algorithm configuration parameter |
gmehmet | 1:f60eafbf009a | 542 | * |
gmehmet | 1:f60eafbf009a | 543 | * @param[in] algo_idx Index of algorithm |
gmehmet | 1:f60eafbf009a | 544 | * @param[in] cfg_idx Index of configuration parameter |
gmehmet | 1:f60eafbf009a | 545 | * @param[in] cfg Array of configuration bytes to be filled in |
gmehmet | 1:f60eafbf009a | 546 | * @param[in] cfg_sz Number of bytes to be read |
gmehmet | 1:f60eafbf009a | 547 | * |
gmehmet | 1:f60eafbf009a | 548 | * @return SS_SUCCESS on success |
gmehmet | 1:f60eafbf009a | 549 | */ |
gmehmet | 1:f60eafbf009a | 550 | SS_STATUS get_algo_cfg(int algo_idx, int cfg_idx, uint8_t *cfg, int cfg_sz); |
gmehmet | 1:f60eafbf009a | 551 | |
gmehmet | 1:f60eafbf009a | 552 | /** |
gmehmet | 1:f60eafbf009a | 553 | * @brief Set the CommChannel Output Mode options |
gmehmet | 1:f60eafbf009a | 554 | * |
gmehmet | 1:f60eafbf009a | 555 | * @param[in] data_type - Set to 0 for only algorithm data |
gmehmet | 1:f60eafbf009a | 556 | * Set to 1 for only raw sensor data |
gmehmet | 1:f60eafbf009a | 557 | * Set to 2 for algo + raw sensor data |
gmehmet | 1:f60eafbf009a | 558 | * Set to 3 for no data |
gmehmet | 1:f60eafbf009a | 559 | * @param[in] sc_en - Set to true to receive 1 byte sample count from SmartSensor |
gmehmet | 1:f60eafbf009a | 560 | * |
gmehmet | 1:f60eafbf009a | 561 | * @return SS_SUCCESS on success |
gmehmet | 1:f60eafbf009a | 562 | */ |
gmehmet | 1:f60eafbf009a | 563 | SS_STATUS set_data_type(int data_type, bool sc_en); |
gmehmet | 1:f60eafbf009a | 564 | |
gmehmet | 1:f60eafbf009a | 565 | /** |
gmehmet | 1:f60eafbf009a | 566 | * @brief Get the CommChannel Output Mode options |
gmehmet | 1:f60eafbf009a | 567 | * |
gmehmet | 1:f60eafbf009a | 568 | * @param[out] data_type - 0 for only algorithm data |
gmehmet | 1:f60eafbf009a | 569 | * 1 for only raw sensor data |
gmehmet | 1:f60eafbf009a | 570 | * 2 for algo + raw sensor data |
gmehmet | 1:f60eafbf009a | 571 | * 3 for no data |
gmehmet | 1:f60eafbf009a | 572 | * @param[in] sc_en - If true, SmartSensor prepends data with 1 byte sample count |
gmehmet | 1:f60eafbf009a | 573 | * |
gmehmet | 1:f60eafbf009a | 574 | * @return SS_SUCCESS on success |
gmehmet | 1:f60eafbf009a | 575 | */ |
gmehmet | 1:f60eafbf009a | 576 | SS_STATUS get_data_type(int* data_type, bool *sc_en); |
gmehmet | 1:f60eafbf009a | 577 | |
gmehmet | 1:f60eafbf009a | 578 | /** |
gmehmet | 1:f60eafbf009a | 579 | * @brief Set the number of samples for the SmartSensor to collect |
gmehmet | 1:f60eafbf009a | 580 | * before issuing an interrupt |
gmehmet | 1:f60eafbf009a | 581 | * |
gmehmet | 1:f60eafbf009a | 582 | * @param[in] thresh - Number of samples (1-255) to collect before interrupt |
gmehmet | 1:f60eafbf009a | 583 | * |
gmehmet | 1:f60eafbf009a | 584 | * @return SS_SUCCESS on success |
gmehmet | 1:f60eafbf009a | 585 | */ |
gmehmet | 1:f60eafbf009a | 586 | SS_STATUS set_fifo_thresh(int thresh); |
gmehmet | 1:f60eafbf009a | 587 | |
gmehmet | 1:f60eafbf009a | 588 | /** |
gmehmet | 1:f60eafbf009a | 589 | * @brief Get the number of samples the SmartSensor will collect |
gmehmet | 1:f60eafbf009a | 590 | * before issuing an interrupt |
gmehmet | 1:f60eafbf009a | 591 | * |
gmehmet | 1:f60eafbf009a | 592 | * @param[out] thresh - Number of samples (1-255) collected before interrupt |
gmehmet | 1:f60eafbf009a | 593 | * |
gmehmet | 1:f60eafbf009a | 594 | * @return SS_SUCCESS on success |
gmehmet | 1:f60eafbf009a | 595 | */ |
gmehmet | 1:f60eafbf009a | 596 | SS_STATUS get_fifo_thresh(int *thresh); |
gmehmet | 1:f60eafbf009a | 597 | |
gmehmet | 1:f60eafbf009a | 598 | /** |
gmehmet | 1:f60eafbf009a | 599 | * @brief Pass external sensor data to sensor hub |
gmehmet | 1:f60eafbf009a | 600 | * |
gmehmet | 1:f60eafbf009a | 601 | * @param[in] num_samples in tx_buf |
gmehmet | 1:f60eafbf009a | 602 | * @param[in] tx_buf - Host sample data to send sensor hub |
gmehmet | 1:f60eafbf009a | 603 | * @param[in] tx_buf_sz - Number of bytes of tx_buf |
gmehmet | 1:f60eafbf009a | 604 | * @param[out] nb_written - Number of samples to sensor hub's input FIFO |
gmehmet | 1:f60eafbf009a | 605 | * |
gmehmet | 1:f60eafbf009a | 606 | * @return SS_SUCCESS on success |
gmehmet | 1:f60eafbf009a | 607 | */ |
gmehmet | 1:f60eafbf009a | 608 | SS_STATUS feed_to_input_fifo(uint8_t *tx_buf, int tx_buf_sz, int *nb_written); |
gmehmet | 1:f60eafbf009a | 609 | |
gmehmet | 1:f60eafbf009a | 610 | /** |
gmehmet | 1:f60eafbf009a | 611 | * @brief Get the number of sambes in Sensor FIFO |
gmehmet | 1:f60eafbf009a | 612 | * |
gmehmet | 1:f60eafbf009a | 613 | * @param[in] sensor_id - Sensor id to read FIFO size |
gmehmet | 1:f60eafbf009a | 614 | * @param[out] fifo_size - Sensor's FIFO size |
gmehmet | 1:f60eafbf009a | 615 | * |
gmehmet | 1:f60eafbf009a | 616 | * @return SS_SUCCESS on success |
gmehmet | 1:f60eafbf009a | 617 | */ |
gmehmet | 1:f60eafbf009a | 618 | SS_STATUS get_num_samples_in_sensor_fifo(uint8_t sensor_id, int *fifo_size); |
gmehmet | 1:f60eafbf009a | 619 | |
gmehmet | 1:f60eafbf009a | 620 | /** |
gmehmet | 1:f60eafbf009a | 621 | * @brief Get the total number of bytes in the Input FIFO |
gmehmet | 1:f60eafbf009a | 622 | * |
gmehmet | 1:f60eafbf009a | 623 | * @param[out] fifo_size - Input FIFO size |
gmehmet | 1:f60eafbf009a | 624 | * |
gmehmet | 1:f60eafbf009a | 625 | * @return SS_SUCCESS on success |
gmehmet | 1:f60eafbf009a | 626 | */ |
gmehmet | 1:f60eafbf009a | 627 | SS_STATUS get_num_bytes_in_input_fifo(int *fifo_size); |
gmehmet | 1:f60eafbf009a | 628 | |
gmehmet | 1:f60eafbf009a | 629 | /** |
gmehmet | 1:f60eafbf009a | 630 | * @brief Get the total number of samples the Sensor's FIFO can hold |
gmehmet | 1:f60eafbf009a | 631 | * |
gmehmet | 1:f60eafbf009a | 632 | * @param[in] sensor_id - Sensor id to read FIFO size |
gmehmet | 1:f60eafbf009a | 633 | * @param[out] fifo_size - Sensor's FIFO size |
gmehmet | 1:f60eafbf009a | 634 | * |
gmehmet | 1:f60eafbf009a | 635 | * @return SS_SUCCESS on success |
gmehmet | 1:f60eafbf009a | 636 | */ |
gmehmet | 1:f60eafbf009a | 637 | SS_STATUS get_sensor_fifo_size(uint8_t sensor_id, int *fifo_size); |
gmehmet | 1:f60eafbf009a | 638 | |
gmehmet | 1:f60eafbf009a | 639 | /** |
gmehmet | 1:f60eafbf009a | 640 | * @brief Get the total number of samples the input FIFO can hold |
gmehmet | 1:f60eafbf009a | 641 | * |
gmehmet | 1:f60eafbf009a | 642 | * @param[out] fifo_size - Input FIFO size |
gmehmet | 1:f60eafbf009a | 643 | * |
gmehmet | 1:f60eafbf009a | 644 | * @return SS_SUCCESS on success |
gmehmet | 1:f60eafbf009a | 645 | */ |
gmehmet | 1:f60eafbf009a | 646 | SS_STATUS get_input_fifo_size(int *fifo_size); |
gmehmet | 1:f60eafbf009a | 647 | |
gmehmet | 1:f60eafbf009a | 648 | /** |
gmehmet | 1:f60eafbf009a | 649 | * @brief Get the number of bytes per sample of a sensor |
gmehmet | 1:f60eafbf009a | 650 | * |
gmehmet | 1:f60eafbf009a | 651 | * @param[in] sensor_id - Sensor id to read sample size |
gmehmet | 1:f60eafbf009a | 652 | * @param[out] sample_size - Sensor's sample size |
gmehmet | 1:f60eafbf009a | 653 | * |
gmehmet | 1:f60eafbf009a | 654 | * @return SS_SUCCESS on success |
gmehmet | 1:f60eafbf009a | 655 | */ |
gmehmet | 1:f60eafbf009a | 656 | SS_STATUS get_sensor_sample_size(uint8_t sensor_id, uint8_t *sample_size); |
gmehmet | 1:f60eafbf009a | 657 | |
gmehmet | 1:f60eafbf009a | 658 | /** |
gmehmet | 1:f60eafbf009a | 659 | * @brief send raw string to I2C |
gmehmet | 1:f60eafbf009a | 660 | * |
gmehmet | 1:f60eafbf009a | 661 | * @param[in] *rawdata - Raw data string, after slave address |
gmehmet | 1:f60eafbf009a | 662 | * @param[out] rawdata_sz - Raw data size |
gmehmet | 1:f60eafbf009a | 663 | * |
gmehmet | 1:f60eafbf009a | 664 | * @return SS_SUCCESS on success |
gmehmet | 1:f60eafbf009a | 665 | */ |
gmehmet | 1:f60eafbf009a | 666 | SS_STATUS send_raw(uint8_t *rawdata, int rawdata_sz); |
gmehmet | 1:f60eafbf009a | 667 | |
gmehmet | 1:f60eafbf009a | 668 | /** |
gmehmet | 1:f60eafbf009a | 669 | * @brief Check that the SmartSensor is connected |
gmehmet | 1:f60eafbf009a | 670 | */ |
gmehmet | 1:f60eafbf009a | 671 | SS_STATUS ss_comm_check(); |
gmehmet | 1:f60eafbf009a | 672 | |
gmehmet | 1:f60eafbf009a | 673 | /** |
gmehmet | 1:f60eafbf009a | 674 | * @brief Set if GPIO or CMD is used to enter bootloader and App |
gmehmet | 1:f60eafbf009a | 675 | * before issuing an interrupt |
gmehmet | 1:f60eafbf009a | 676 | * |
gmehmet | 1:f60eafbf009a | 677 | * param[in] mode |
gmehmet | 1:f60eafbf009a | 678 | * - 0: use command to enter bootloader mode |
gmehmet | 1:f60eafbf009a | 679 | * - 1: use EBL GPIO to enter bootloader mode |
gmehmet | 1:f60eafbf009a | 680 | * |
gmehmet | 1:f60eafbf009a | 681 | * @return SS_SUCCESS on success |
gmehmet | 1:f60eafbf009a | 682 | */ |
gmehmet | 1:f60eafbf009a | 683 | SS_STATUS set_ebl_mode(uint8_t mode); |
gmehmet | 1:f60eafbf009a | 684 | |
gmehmet | 1:f60eafbf009a | 685 | /** |
gmehmet | 1:f60eafbf009a | 686 | * @brief Get ebl_mode value |
gmehmet | 1:f60eafbf009a | 687 | * |
gmehmet | 1:f60eafbf009a | 688 | * @return ebl_mode value |
gmehmet | 1:f60eafbf009a | 689 | */ |
gmehmet | 1:f60eafbf009a | 690 | int get_ebl_mode(); |
gmehmet | 1:f60eafbf009a | 691 | |
gmehmet | 1:f60eafbf009a | 692 | SS_STATUS stay_in_bootloader(); |
gmehmet | 1:f60eafbf009a | 693 | SS_STATUS exit_from_bootloader(); |
gmehmet | 1:f60eafbf009a | 694 | |
gmehmet | 1:f60eafbf009a | 695 | void enable_irq(); |
gmehmet | 1:f60eafbf009a | 696 | void disable_irq(); |
gmehmet | 1:f60eafbf009a | 697 | |
gmehmet | 1:f60eafbf009a | 698 | void mfio_selftest(); |
gmehmet | 1:f60eafbf009a | 699 | bool reset_mfio_irq(); |
gmehmet | 1:f60eafbf009a | 700 | |
gmehmet | 1:f60eafbf009a | 701 | void ss_execute_once(); |
gmehmet | 1:f60eafbf009a | 702 | void ss_clear_interrupt_flag(); |
gmehmet | 1:f60eafbf009a | 703 | |
gmehmet | 1:f60eafbf009a | 704 | private: |
gmehmet | 1:f60eafbf009a | 705 | |
gmehmet | 1:f60eafbf009a | 706 | /* PRIVATE VARIABLES */ |
gmehmet | 1:f60eafbf009a | 707 | I2C *m_i2cBus; |
gmehmet | 1:f60eafbf009a | 708 | SPI *m_spiBus; |
gmehmet | 1:f60eafbf009a | 709 | DigitalInOut mfio_pin; |
gmehmet | 1:f60eafbf009a | 710 | DigitalInOut reset_pin; |
gmehmet | 1:f60eafbf009a | 711 | InterruptIn irq_pin; |
gmehmet | 1:f60eafbf009a | 712 | |
gmehmet | 1:f60eafbf009a | 713 | char fw_version[128]; |
gmehmet | 1:f60eafbf009a | 714 | char algo_version[128]; |
gmehmet | 1:f60eafbf009a | 715 | const char* plat_name; |
gmehmet | 1:f60eafbf009a | 716 | |
gmehmet | 1:f60eafbf009a | 717 | bool in_bootldr; |
gmehmet | 1:f60eafbf009a | 718 | bool sc_en; |
gmehmet | 1:f60eafbf009a | 719 | int data_type; |
gmehmet | 1:f60eafbf009a | 720 | |
gmehmet | 1:f60eafbf009a | 721 | uint8_t ebl_mode; /* 0: Command bootloader, 1: No command, trigger GPIO */ |
gmehmet | 1:f60eafbf009a | 722 | |
gmehmet | 1:f60eafbf009a | 723 | int sensor_enabled_mode[SS_MAX_SUPPORTED_SENSOR_NUM]; |
gmehmet | 1:f60eafbf009a | 724 | int algo_enabled_mode[SS_MAX_SUPPORTED_ALGO_NUM]; |
gmehmet | 1:f60eafbf009a | 725 | ss_data_req* sensor_data_reqs[SS_MAX_SUPPORTED_SENSOR_NUM]; |
gmehmet | 1:f60eafbf009a | 726 | ss_data_req* algo_data_reqs[SS_MAX_SUPPORTED_ALGO_NUM]; |
gmehmet | 1:f60eafbf009a | 727 | |
gmehmet | 1:f60eafbf009a | 728 | /* PRIVATE METHODS */ |
gmehmet | 1:f60eafbf009a | 729 | SS_STATUS write_cmd_small(uint8_t *cmd_bytes, int cmd_bytes_len, |
gmehmet | 1:f60eafbf009a | 730 | uint8_t *data, int data_len, |
gmehmet | 1:f60eafbf009a | 731 | int sleep_ms = SS_DEFAULT_CMD_SLEEP_MS); |
gmehmet | 1:f60eafbf009a | 732 | SS_STATUS write_cmd_medium(uint8_t *cmd_bytes, int cmd_bytes_len, |
gmehmet | 1:f60eafbf009a | 733 | uint8_t *data, int data_len, |
gmehmet | 1:f60eafbf009a | 734 | int sleep_ms = SS_DEFAULT_CMD_SLEEP_MS); |
gmehmet | 1:f60eafbf009a | 735 | SS_STATUS write_cmd_large(uint8_t *cmd_bytes, int cmd_bytes_len, |
gmehmet | 1:f60eafbf009a | 736 | uint8_t *data, int data_len, |
gmehmet | 1:f60eafbf009a | 737 | int sleep_ms = SS_DEFAULT_CMD_SLEEP_MS); |
gmehmet | 1:f60eafbf009a | 738 | void cfg_mfio(PinDirection); |
gmehmet | 1:f60eafbf009a | 739 | |
gmehmet | 1:f60eafbf009a | 740 | void irq_handler(); |
gmehmet | 1:f60eafbf009a | 741 | volatile bool m_irq_received_; |
gmehmet | 1:f60eafbf009a | 742 | |
gmehmet | 1:f60eafbf009a | 743 | |
gmehmet | 1:f60eafbf009a | 744 | void irq_handler_selftest(); |
gmehmet | 1:f60eafbf009a | 745 | volatile bool mfio_int_happened; |
gmehmet | 1:f60eafbf009a | 746 | |
gmehmet | 1:f60eafbf009a | 747 | SS_STATUS read_fifo_data(int num_samples, int sample_size, uint8_t* databuf, int databuf_sz); |
gmehmet | 1:f60eafbf009a | 748 | SS_STATUS num_avail_samples(int* num_samples); |
gmehmet | 1:f60eafbf009a | 749 | SS_STATUS get_log_len(int *log_len); |
gmehmet | 1:f60eafbf009a | 750 | SS_STATUS read_ss_log(int num_bytes, uint8_t *log_buf, int log_buf_sz); |
gmehmet | 1:f60eafbf009a | 751 | void fifo_sample_size(int data_type, int* sample_size); |
gmehmet | 1:f60eafbf009a | 752 | |
gmehmet | 1:f60eafbf009a | 753 | // EventStats irq_evt; |
gmehmet | 1:f60eafbf009a | 754 | }; |
gmehmet | 1:f60eafbf009a | 755 | |
gmehmet | 1:f60eafbf009a | 756 | |
gmehmet | 1:f60eafbf009a | 757 | #endif |