Pegasus implementation of SmartSensor Host

Dependencies:   USBDevice max32630fthr

Fork of MAXREFDES220# by Maxim Integrated

Finger Heart Rate Monitor and SpO2 Monitor

The MAXREFDES220 Smart Sensor FeatherWing board is a integrated solution for providing finger-based heart rate measurements and SpO2 (blood oxygen saturation). This evaluation board interfaces to the host computer using the I2C interface. Heart rate outpu is available in beats per minute (BPM) and SpO2 is reported in percentages.; the PPG (photoplethysmography) raw data is also available. The board has an MAX30101 chip which is a low power heart rate monitor with adjustable sample rates and adjustable LED currents. The low cost MAX32664 microcontroller is pre-flashed with C code for finger-based pulse rate and SpO2 monitoring. Bootloader software is included to allow for future algorithms or updates to the algorithm from Maxim Integrated.

Ordering information will be available soon.

Note: SpO2 values are not calibrated. Calibration should be performed using the final end product.

MAXREFDES220 FeatherWing Pinout Connections

/media/uploads/phonemacro/maxrefdes220_pinouts_heart_rate_monitor3.jpg

Committer:
Shaun Kelsey
Date:
Wed Apr 11 16:55:26 2018 -0700
Revision:
3:28fb38fe73c4
Parent:
0:da5f5b56060a
Define MAXIM_PLATFORM_NAME

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Shaun Kelsey 0:da5f5b56060a 1 /***************************************************************************
Shaun Kelsey 0:da5f5b56060a 2 * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
Shaun Kelsey 0:da5f5b56060a 3 *
Shaun Kelsey 0:da5f5b56060a 4 * Permission is hereby granted, free of charge, to any person obtaining a
Shaun Kelsey 0:da5f5b56060a 5 * copy of this software and associated documentation files (the "Software"),
Shaun Kelsey 0:da5f5b56060a 6 * to deal in the Software without restriction, including without limitation
Shaun Kelsey 0:da5f5b56060a 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
Shaun Kelsey 0:da5f5b56060a 8 * and/or sell copies of the Software, and to permit persons to whom the
Shaun Kelsey 0:da5f5b56060a 9 * Software is furnished to do so, subject to the following conditions:
Shaun Kelsey 0:da5f5b56060a 10 *
Shaun Kelsey 0:da5f5b56060a 11 * The above copyright notice and this permission notice shall be included
Shaun Kelsey 0:da5f5b56060a 12 * in all copies or substantial portions of the Software.
Shaun Kelsey 0:da5f5b56060a 13 *
Shaun Kelsey 0:da5f5b56060a 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
Shaun Kelsey 0:da5f5b56060a 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Shaun Kelsey 0:da5f5b56060a 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Shaun Kelsey 0:da5f5b56060a 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
Shaun Kelsey 0:da5f5b56060a 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
Shaun Kelsey 0:da5f5b56060a 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
Shaun Kelsey 0:da5f5b56060a 20 * OTHER DEALINGS IN THE SOFTWARE.
Shaun Kelsey 0:da5f5b56060a 21 *
Shaun Kelsey 0:da5f5b56060a 22 * Except as contained in this notice, the name of Maxim Integrated
Shaun Kelsey 0:da5f5b56060a 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
Shaun Kelsey 0:da5f5b56060a 24 * Products, Inc. Branding Policy.
Shaun Kelsey 0:da5f5b56060a 25 *
Shaun Kelsey 0:da5f5b56060a 26 * The mere transfer of this software does not imply any licenses
Shaun Kelsey 0:da5f5b56060a 27 * of trade secrets, proprietary technology, copyrights, patents,
Shaun Kelsey 0:da5f5b56060a 28 * trademarks, maskwork rights, or any other form of intellectual
Shaun Kelsey 0:da5f5b56060a 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
Shaun Kelsey 0:da5f5b56060a 30 * ownership rights.
Shaun Kelsey 0:da5f5b56060a 31 ****************************************************************************
Shaun Kelsey 0:da5f5b56060a 32 */
Shaun Kelsey 0:da5f5b56060a 33
Shaun Kelsey 0:da5f5b56060a 34 #ifndef _SSINTERFACE_H_
Shaun Kelsey 0:da5f5b56060a 35 #define _SSINTERFACE_H_
Shaun Kelsey 0:da5f5b56060a 36
Shaun Kelsey 0:da5f5b56060a 37 #include "mbed.h"
Shaun Kelsey 0:da5f5b56060a 38 #include "MaximSensor.h"
Shaun Kelsey 0:da5f5b56060a 39
Shaun Kelsey 0:da5f5b56060a 40 #define SS_PLATFORM_MAX3263X "SmartSensor_MAX3263X"
Shaun Kelsey 0:da5f5b56060a 41 #define SS_PLATFORM_MAX32660 "SmartSensor_MAX32660"
Shaun Kelsey 0:da5f5b56060a 42 #define SS_BOOTLOADER_PLATFORM_MAX3263X "Bootloader_MAX3263X"
Shaun Kelsey 0:da5f5b56060a 43 #define SS_BOOTLOADER_PLATFORM_MAX32660 "Bootloader_MAX32660"
Shaun Kelsey 0:da5f5b56060a 44
Shaun Kelsey 0:da5f5b56060a 45
Shaun Kelsey 0:da5f5b56060a 46 #define SS_I2C_8BIT_SLAVE_ADDR 0xAA
Shaun Kelsey 0:da5f5b56060a 47 #define SS_DEFAULT_CMD_SLEEP_MS 2
Shaun Kelsey 0:da5f5b56060a 48 #define SS_DUMP_REG_SLEEP_MS 100
Shaun Kelsey 0:da5f5b56060a 49 #define SS_ENABLE_SENSOR_SLEEP_MS 20
Shaun Kelsey 0:da5f5b56060a 50
Shaun Kelsey 0:da5f5b56060a 51 #define SS_SENSORIDX_OS58 0x00
Shaun Kelsey 0:da5f5b56060a 52 #define SS_SENSORIDX_DT07 0x01
Shaun Kelsey 0:da5f5b56060a 53 #define SS_SENSORIDX_OT02 0x02
Shaun Kelsey 0:da5f5b56060a 54 #define SS_SENSORIDX_OS24 0x03
Shaun Kelsey 0:da5f5b56060a 55 #define SS_SENSORIDX_ACCEL 0x04
Shaun Kelsey 0:da5f5b56060a 56
Shaun Kelsey 0:da5f5b56060a 57 #define SS_ALGOIDX_AGC 0x00
Shaun Kelsey 0:da5f5b56060a 58 #define SS_ALGOIDX_AEC 0x01
Shaun Kelsey 0:da5f5b56060a 59 #define SS_ALGOIDX_WHRM 0x02
Shaun Kelsey 0:da5f5b56060a 60 #define SS_ALGOIDX_ECG 0x03
Shaun Kelsey 0:da5f5b56060a 61
Shaun Kelsey 0:da5f5b56060a 62
Shaun Kelsey 0:da5f5b56060a 63 #define SS_FAM_R_STATUS 0x00
Shaun Kelsey 0:da5f5b56060a 64 #define SS_CMDIDX_STATUS 0x00
Shaun Kelsey 0:da5f5b56060a 65 #define SS_SHIFT_STATUS_ERR 0
Shaun Kelsey 0:da5f5b56060a 66 #define SS_MASK_STATUS_ERR (0x07 << SS_SHIFT_STATUS_ERR)
Shaun Kelsey 0:da5f5b56060a 67 #define SS_SHIFT_STATUS_DATA_RDY 3
Shaun Kelsey 0:da5f5b56060a 68 #define SS_MASK_STATUS_DATA_RDY (1 << SS_SHIFT_STATUS_DATA_RDY)
Shaun Kelsey 0:da5f5b56060a 69 #define SS_SHIFT_STATUS_FIFO_OUT_OVR 4
Shaun Kelsey 0:da5f5b56060a 70 #define SS_MASK_STATUS_FIFO_OUT_OVR (1 << SS_SHIFT_STATUS_FIFO_OUT_OVR)
Shaun Kelsey 0:da5f5b56060a 71 #define SS_SHIFT_STATUS_FIFO_IN_OVR 5
Shaun Kelsey 0:da5f5b56060a 72 #define SS_MASK_STATUS_FIFO_IN_OVR (1 << SS_SHIFT_STATUS_FIFO_IN_OVR)
Shaun Kelsey 0:da5f5b56060a 73
Shaun Kelsey 0:da5f5b56060a 74 #define SS_FAM_W_MODE 0x01
Shaun Kelsey 0:da5f5b56060a 75 #define SS_FAM_R_MODE 0x02
Shaun Kelsey 0:da5f5b56060a 76 #define SS_CMDIDX_MODE 0x00
Shaun Kelsey 0:da5f5b56060a 77 #define SS_SHIFT_MODE_SHDN 0
Shaun Kelsey 0:da5f5b56060a 78 #define SS_MASK_MODE_SHDN (1 << SS_SHIFT_MODE_SHDN)
Shaun Kelsey 0:da5f5b56060a 79 #define SS_SHIFT_MODE_RESET 1
Shaun Kelsey 0:da5f5b56060a 80 #define SS_MASK_MODE_RESET (1 << SS_SHIFT_MODE_RESET)
Shaun Kelsey 0:da5f5b56060a 81 #define SS_SHIFT_MODE_FIFORESET 2
Shaun Kelsey 0:da5f5b56060a 82 #define SS_MASK_MODE_FIFORESET (1 << SS_SHIFT_MODE_FIFORESET)
Shaun Kelsey 0:da5f5b56060a 83 #define SS_SHIFT_MODE_BOOTLDR 3
Shaun Kelsey 0:da5f5b56060a 84 #define SS_MASK_MODE_BOOTLDR (1 << SS_SHIFT_MODE_BOOTLDR)
Shaun Kelsey 0:da5f5b56060a 85
Shaun Kelsey 0:da5f5b56060a 86 #define SS_I2C_READ 0x03
Shaun Kelsey 0:da5f5b56060a 87
Shaun Kelsey 0:da5f5b56060a 88 #define SS_FAM_W_COMMCHAN 0x10
Shaun Kelsey 0:da5f5b56060a 89 #define SS_FAM_R_COMMCHAN 0x11
Shaun Kelsey 0:da5f5b56060a 90 #define SS_CMDIDX_OUTPUTMODE 0x00
Shaun Kelsey 0:da5f5b56060a 91 #define SS_SHIFT_OUTPUTMODE_DATATYPE 0
Shaun Kelsey 0:da5f5b56060a 92 #define SS_MASK_OUTPUTMODE_DATATYPE (0x03 << SS_SHIFT_OUTPUTMODE_DATATYPE)
Shaun Kelsey 0:da5f5b56060a 93 #define SS_DATATYPE_PAUSE 0
Shaun Kelsey 0:da5f5b56060a 94 #define SS_DATATYPE_RAW 1
Shaun Kelsey 0:da5f5b56060a 95 #define SS_DATATYPE_ALGO 2
Shaun Kelsey 0:da5f5b56060a 96 #define SS_DATATYPE_BOTH 3
Shaun Kelsey 0:da5f5b56060a 97 #define SS_SHIFT_OUTPUTMODE_SC_EN 2
Shaun Kelsey 0:da5f5b56060a 98 #define SS_MASK_OUTPUTMODE_SC_EN (1 << SS_SHIFT_OUTPUTMODE_SC_EN)
Shaun Kelsey 0:da5f5b56060a 99 #define SS_CMDIDX_FIFOAFULL 0x01
Shaun Kelsey 0:da5f5b56060a 100
Shaun Kelsey 0:da5f5b56060a 101 #define SS_FAM_R_OUTPUTFIFO 0x12
Shaun Kelsey 0:da5f5b56060a 102 #define SS_CMDIDX_OUT_NUMSAMPLES 0x00
Shaun Kelsey 0:da5f5b56060a 103 #define SS_CMDIDX_READFIFO 0x01
Shaun Kelsey 0:da5f5b56060a 104
Shaun Kelsey 0:da5f5b56060a 105 #define SS_FAM_R_INPUTFIFO 0x13
Shaun Kelsey 0:da5f5b56060a 106 #define SS_CMDIDX_SAMPLESIZE 0x00
Shaun Kelsey 0:da5f5b56060a 107 #define SS_CMDIDX_FIFOSIZE 0x01
Shaun Kelsey 0:da5f5b56060a 108 #define SS_CMDIDX_IN_NUMSAMPLES 0x02
Shaun Kelsey 0:da5f5b56060a 109 #define SS_FAM_W_INPUTFIFO 0x14
Shaun Kelsey 0:da5f5b56060a 110 #define SS_CMDIDN_WRITEFIFO 0x00
Shaun Kelsey 0:da5f5b56060a 111
Shaun Kelsey 0:da5f5b56060a 112 #define SS_FAM_W_WRITEREG 0x40
Shaun Kelsey 0:da5f5b56060a 113 #define SS_FAM_R_READREG 0x41
Shaun Kelsey 0:da5f5b56060a 114 #define SS_FAM_R_REGATTRIBS 0x42
Shaun Kelsey 0:da5f5b56060a 115 #define SS_FAM_R_DUMPREG 0x43
Shaun Kelsey 0:da5f5b56060a 116
Shaun Kelsey 0:da5f5b56060a 117 #define SS_FAM_W_SENSORMODE 0x44
Shaun Kelsey 0:da5f5b56060a 118 #define SS_FAM_R_SENSORMODE 0x45
Shaun Kelsey 0:da5f5b56060a 119
Shaun Kelsey 0:da5f5b56060a 120 //TODO: Fill in known configuration parameters
Shaun Kelsey 0:da5f5b56060a 121 #define SS_FAM_W_ALGOCONFIG 0x50
Shaun Kelsey 0:da5f5b56060a 122 #define SS_FAM_R_ALGOCONFIG 0x51
Shaun Kelsey 0:da5f5b56060a 123
Shaun Kelsey 0:da5f5b56060a 124 #define SS_FAM_W_ALGOMODE 0x52
Shaun Kelsey 0:da5f5b56060a 125 #define SS_FAM_R_ALGOMODE 0x53
Shaun Kelsey 0:da5f5b56060a 126
Shaun Kelsey 0:da5f5b56060a 127 #define SS_FAM_W_EXTERNSENSORMODE 0x60
Shaun Kelsey 0:da5f5b56060a 128 #define SS_FAM_R_EXTERNSENSORMODE 0x61
Shaun Kelsey 0:da5f5b56060a 129
Shaun Kelsey 0:da5f5b56060a 130 #define SS_FAM_R_SELFTEST 0x70
Shaun Kelsey 0:da5f5b56060a 131
Shaun Kelsey 0:da5f5b56060a 132 #define SS_FAM_W_BOOTLOADER 0x80
Shaun Kelsey 0:da5f5b56060a 133 #define SS_CMDIDX_SETIV 0x00
Shaun Kelsey 0:da5f5b56060a 134 #define SS_CMDIDX_SETAUTH 0x01
Shaun Kelsey 0:da5f5b56060a 135 #define SS_CMDIDX_SETNUMPAGES 0x02
Shaun Kelsey 0:da5f5b56060a 136 #define SS_CMDIDX_ERASE 0x03
Shaun Kelsey 0:da5f5b56060a 137 #define SS_CMDIDX_SENDPAGE 0x04
Shaun Kelsey 0:da5f5b56060a 138 #define SS_FAM_R_BOOTLOADER 0x81
Shaun Kelsey 0:da5f5b56060a 139 #define SS_CMDIDX_BOOTFWVERSION 0x00
Shaun Kelsey 0:da5f5b56060a 140 #define SS_CMDIDX_PAGESIZE 0x01
Shaun Kelsey 0:da5f5b56060a 141
Shaun Kelsey 0:da5f5b56060a 142 #define SS_FAM_R_IDENTITY 0xFF
Shaun Kelsey 0:da5f5b56060a 143 #define SS_CMDIDX_PLATTYPE 0x00
Shaun Kelsey 0:da5f5b56060a 144 #define SS_CMDIDX_PARTID 0x01
Shaun Kelsey 0:da5f5b56060a 145 #define SS_CMDIDX_REVID 0x02
Shaun Kelsey 0:da5f5b56060a 146 #define SS_CMDIDX_FWVERSION 0x03
Shaun Kelsey 0:da5f5b56060a 147 #define SS_CMDIDX_AVAILSENSORS 0x04
Shaun Kelsey 0:da5f5b56060a 148 #define SS_CMDIDX_DRIVERVER 0x05
Shaun Kelsey 0:da5f5b56060a 149 #define SS_CMDIDX_AVAILALGOS 0x06
Shaun Kelsey 0:da5f5b56060a 150 #define SS_CMDIDX_ALGOVER 0x07
Shaun Kelsey 0:da5f5b56060a 151
Shaun Kelsey 0:da5f5b56060a 152
Shaun Kelsey 0:da5f5b56060a 153
Shaun Kelsey 0:da5f5b56060a 154 typedef enum {
Shaun Kelsey 0:da5f5b56060a 155 SS_SUCCESS=0x00,
Shaun Kelsey 0:da5f5b56060a 156
Shaun Kelsey 0:da5f5b56060a 157 SS_ERR_COMMAND=0x01,
Shaun Kelsey 0:da5f5b56060a 158 SS_ERR_UNAVAILABLE=0x02,
Shaun Kelsey 0:da5f5b56060a 159 SS_ERR_DATA_FORMAT=0x03,
Shaun Kelsey 0:da5f5b56060a 160 SS_ERR_INPUT_VALUE=0x04,
Shaun Kelsey 0:da5f5b56060a 161
Shaun Kelsey 0:da5f5b56060a 162 SS_ERR_BTLDR_GENERAL=0x80,
Shaun Kelsey 0:da5f5b56060a 163 SS_ERR_BTLDR_CHECKSUM=0x81,
Shaun Kelsey 0:da5f5b56060a 164
Shaun Kelsey 0:da5f5b56060a 165 SS_ERR_UNKNOWN=0xFF
Shaun Kelsey 0:da5f5b56060a 166 } SS_STATUS;
Shaun Kelsey 0:da5f5b56060a 167
Shaun Kelsey 0:da5f5b56060a 168 typedef enum {
Shaun Kelsey 0:da5f5b56060a 169 SS_PLAT_MAX3263X=0,
Shaun Kelsey 0:da5f5b56060a 170 SS_PLAT_MAX32660=1,
Shaun Kelsey 0:da5f5b56060a 171 } SS_PLAT_TYPE;
Shaun Kelsey 0:da5f5b56060a 172
Shaun Kelsey 0:da5f5b56060a 173 //self test result masks
Shaun Kelsey 0:da5f5b56060a 174 #define FAILURE_COMM 0x01
Shaun Kelsey 0:da5f5b56060a 175 #define FAILURE_INTERRUPT 0x02
Shaun Kelsey 0:da5f5b56060a 176
Shaun Kelsey 0:da5f5b56060a 177 #define SS_SMALL_BUF_SIZE 32
Shaun Kelsey 0:da5f5b56060a 178 #define SS_LARGE_BUF_SIZE 8224
Shaun Kelsey 0:da5f5b56060a 179
Shaun Kelsey 0:da5f5b56060a 180 #define SS_RESET_TIME 10
Shaun Kelsey 0:da5f5b56060a 181 #define SS_STARTUP_TIME 1000
Shaun Kelsey 0:da5f5b56060a 182
Shaun Kelsey 0:da5f5b56060a 183 #define SS_MAX_SUPPORTED_SENSOR_NUM 0xFE
Shaun Kelsey 0:da5f5b56060a 184 #define SS_MAX_SUPPORTED_ALGO_NUM 0xFE
Shaun Kelsey 0:da5f5b56060a 185 #define SS_MAX_SUPPORTED_MODE_NUM 0xFF
Shaun Kelsey 0:da5f5b56060a 186
Shaun Kelsey 0:da5f5b56060a 187 typedef struct {
Shaun Kelsey 0:da5f5b56060a 188 int data_size;
Shaun Kelsey 0:da5f5b56060a 189 Callback<void(uint8_t*)> callback;
Shaun Kelsey 0:da5f5b56060a 190 } ss_data_req;
Shaun Kelsey 0:da5f5b56060a 191
Shaun Kelsey 0:da5f5b56060a 192
Shaun Kelsey 0:da5f5b56060a 193 /**
Shaun Kelsey 0:da5f5b56060a 194 * @brief SSInterface is Maxim's SmartSensor Interface class
Shaun Kelsey 0:da5f5b56060a 195 */
Shaun Kelsey 0:da5f5b56060a 196 class SSInterface
Shaun Kelsey 0:da5f5b56060a 197 {
Shaun Kelsey 0:da5f5b56060a 198 public:
Shaun Kelsey 0:da5f5b56060a 199
Shaun Kelsey 0:da5f5b56060a 200 /* PUBLIC FUNCTION DECLARATIONS */
Shaun Kelsey 0:da5f5b56060a 201 /**
Shaun Kelsey 0:da5f5b56060a 202 * @brief SSInterface constructor.
Shaun Kelsey 0:da5f5b56060a 203 *
Shaun Kelsey 0:da5f5b56060a 204 * @param[in] i2cBus - reference to the I2C bus for the SmartSensor
Shaun Kelsey 0:da5f5b56060a 205 * @param[in] ss_mfio - name of SmartSensor multi-function IO pin
Shaun Kelsey 0:da5f5b56060a 206 * @param[in] ss_reset - name of SmartSensor Reset pin
Shaun Kelsey 0:da5f5b56060a 207 *
Shaun Kelsey 0:da5f5b56060a 208 */
Shaun Kelsey 0:da5f5b56060a 209 SSInterface(I2C &i2cBus, PinName ss_mfio, PinName ss_reset);
Shaun Kelsey 0:da5f5b56060a 210
Shaun Kelsey 0:da5f5b56060a 211 /**
Shaun Kelsey 0:da5f5b56060a 212 * @brief SSInterface constructor.
Shaun Kelsey 0:da5f5b56060a 213 *
Shaun Kelsey 0:da5f5b56060a 214 * @param[in] spiBus - reference to the SPI bus for the SmartSensor
Shaun Kelsey 0:da5f5b56060a 215 * @param[in] ss_mfio - name of SmartSensor multi-function IO pin
Shaun Kelsey 0:da5f5b56060a 216 * @param[in] ss_reset - name of SmartSensor Reset pin
Shaun Kelsey 0:da5f5b56060a 217 *
Shaun Kelsey 0:da5f5b56060a 218 */
Shaun Kelsey 0:da5f5b56060a 219 SSInterface(SPI &spiBus, PinName ss_mfio, PinName ss_reset);
Shaun Kelsey 0:da5f5b56060a 220
Shaun Kelsey 0:da5f5b56060a 221 /**
Shaun Kelsey 0:da5f5b56060a 222 * @brief DSInterface destructor.
Shaun Kelsey 0:da5f5b56060a 223 *
Shaun Kelsey 0:da5f5b56060a 224 */
Shaun Kelsey 0:da5f5b56060a 225 ~SSInterface();
Shaun Kelsey 0:da5f5b56060a 226
Shaun Kelsey 0:da5f5b56060a 227 /**
Shaun Kelsey 0:da5f5b56060a 228 * @brief Write a command to the SmartSensor and get status response
Shaun Kelsey 0:da5f5b56060a 229 *
Shaun Kelsey 0:da5f5b56060a 230 * @param[in] cmd_bytes - Pointer to the command's family and index bytes
Shaun Kelsey 0:da5f5b56060a 231 * @param[in] cmd_idx_len - The number of bytes in the command
Shaun Kelsey 0:da5f5b56060a 232 * @param[in] data - Pointer to the command's data bytes
Shaun Kelsey 0:da5f5b56060a 233 * @param[in] data_len - The number data bytes
Shaun Kelsey 0:da5f5b56060a 234 *
Shaun Kelsey 0:da5f5b56060a 235 * @return SS_STATUS byte
Shaun Kelsey 0:da5f5b56060a 236 */
Shaun Kelsey 0:da5f5b56060a 237 SS_STATUS write_cmd(uint8_t *cmd_bytes, int cmd_bytes_len,
Shaun Kelsey 0:da5f5b56060a 238 uint8_t *data, int data_len,
Shaun Kelsey 0:da5f5b56060a 239 int sleep_ms = SS_DEFAULT_CMD_SLEEP_MS);
Shaun Kelsey 0:da5f5b56060a 240
Shaun Kelsey 0:da5f5b56060a 241
Shaun Kelsey 0:da5f5b56060a 242 /**
Shaun Kelsey 0:da5f5b56060a 243 * @brief Write a command to the SmartSensor and get status response
Shaun Kelsey 0:da5f5b56060a 244 *
Shaun Kelsey 0:da5f5b56060a 245 * @param[in] tx_buf - Pointer to the command's family, index bytes and data bytes
Shaun Kelsey 0:da5f5b56060a 246 * @param[in] tx_len - Total transaction lenght to send
Shaun Kelsey 0:da5f5b56060a 247 *
Shaun Kelsey 0:da5f5b56060a 248 * @return SS_STATUS byte
Shaun Kelsey 0:da5f5b56060a 249 */
Shaun Kelsey 0:da5f5b56060a 250 SS_STATUS write_cmd(uint8_t *tx_buf, int tx_len,
Shaun Kelsey 0:da5f5b56060a 251 int sleep_ms = SS_DEFAULT_CMD_SLEEP_MS);
Shaun Kelsey 0:da5f5b56060a 252
Shaun Kelsey 0:da5f5b56060a 253 /**
Shaun Kelsey 0:da5f5b56060a 254 * @brief Write a command to the SmartSensor and get status response
Shaun Kelsey 0:da5f5b56060a 255 *
Shaun Kelsey 0:da5f5b56060a 256 * @param[in] cmd_bytes - Pointer to the command's family and index bytes
Shaun Kelsey 0:da5f5b56060a 257 * @param[in] cmd_idx_len - The number of bytes in the command
Shaun Kelsey 0:da5f5b56060a 258 * @param[in] data - Pointer to the command's data bytes
Shaun Kelsey 0:da5f5b56060a 259 * @param[in] data_len - The number data bytes
Shaun Kelsey 0:da5f5b56060a 260 * @param[in] rxbuf - Buffer to fill in with read data (including status byte)
Shaun Kelsey 0:da5f5b56060a 261 * @param[in] rxbuf_sz - Size of the rx buffer (to prevent overflow)
Shaun Kelsey 0:da5f5b56060a 262 *
Shaun Kelsey 0:da5f5b56060a 263 * @return SS_STATUS byte
Shaun Kelsey 0:da5f5b56060a 264 */
Shaun Kelsey 0:da5f5b56060a 265 SS_STATUS read_cmd( uint8_t *cmd_bytes, int cmd_bytes_len,
Shaun Kelsey 0:da5f5b56060a 266 uint8_t *data, int data_len,
Shaun Kelsey 0:da5f5b56060a 267 uint8_t *rxbuf, int rxbuf_sz,
Shaun Kelsey 0:da5f5b56060a 268 int sleep_ms = SS_DEFAULT_CMD_SLEEP_MS);
Shaun Kelsey 0:da5f5b56060a 269
Shaun Kelsey 0:da5f5b56060a 270 /**
Shaun Kelsey 0:da5f5b56060a 271 * @brief Get a string representing the SmartSensor firmware version
Shaun Kelsey 0:da5f5b56060a 272 * @details If in bootloader mode, returns bootloader version
Shaun Kelsey 0:da5f5b56060a 273 *
Shaun Kelsey 0:da5f5b56060a 274 * @return Pointer to firmware version string
Shaun Kelsey 0:da5f5b56060a 275 */
Shaun Kelsey 0:da5f5b56060a 276 const char* get_ss_fw_version();
Shaun Kelsey 0:da5f5b56060a 277
Shaun Kelsey 0:da5f5b56060a 278 /**
Shaun Kelsey 0:da5f5b56060a 279 * @brief Get a string representing the SmartSensor platform type
Shaun Kelsey 0:da5f5b56060a 280 *
Shaun Kelsey 0:da5f5b56060a 281 * @return Pointer to platform type string
Shaun Kelsey 0:da5f5b56060a 282 */
Shaun Kelsey 0:da5f5b56060a 283 const char* get_ss_platform_name();
Shaun Kelsey 0:da5f5b56060a 284
Shaun Kelsey 0:da5f5b56060a 285 /**
Shaun Kelsey 0:da5f5b56060a 286 * @brief Reset the SmartSensor and jump to main application
Shaun Kelsey 0:da5f5b56060a 287 *
Shaun Kelsey 0:da5f5b56060a 288 * @return SS_STATUS code indicating success
Shaun Kelsey 0:da5f5b56060a 289 */
Shaun Kelsey 0:da5f5b56060a 290 SS_STATUS reset_to_main_app();
Shaun Kelsey 0:da5f5b56060a 291
Shaun Kelsey 0:da5f5b56060a 292 /**
Shaun Kelsey 0:da5f5b56060a 293 * @brief Reset the SmartSensor and jump to bootloader
Shaun Kelsey 0:da5f5b56060a 294 *
Shaun Kelsey 0:da5f5b56060a 295 * @return SS_STATUS code indicating success
Shaun Kelsey 0:da5f5b56060a 296 */
Shaun Kelsey 0:da5f5b56060a 297 SS_STATUS reset_to_bootloader();
Shaun Kelsey 0:da5f5b56060a 298
Shaun Kelsey 0:da5f5b56060a 299 /**
Shaun Kelsey 0:da5f5b56060a 300 * @brief Reset the SmartSensor
Shaun Kelsey 0:da5f5b56060a 301 * @details If the SmartSensor was in bootloader, it will jump back into bootloader
Shaun Kelsey 0:da5f5b56060a 302 * If the SmartSensor was in main app, it will jump back into main app
Shaun Kelsey 0:da5f5b56060a 303 *
Shaun Kelsey 0:da5f5b56060a 304 * @return SS_STATUS code indicating success
Shaun Kelsey 0:da5f5b56060a 305 */
Shaun Kelsey 0:da5f5b56060a 306 SS_STATUS reset();
Shaun Kelsey 0:da5f5b56060a 307
Shaun Kelsey 0:da5f5b56060a 308 /**
Shaun Kelsey 0:da5f5b56060a 309 * @brief run the self test commands
Shaun Kelsey 0:da5f5b56060a 310 * param[in] idx - the id of the sensor for the self test
Shaun Kelsey 0:da5f5b56060a 311 * param[in] result - self-test response
Shaun Kelsey 0:da5f5b56060a 312 * param[in] sleep_ms - duration of wait for read command
Shaun Kelsey 0:da5f5b56060a 313 * @return SS_STATUS code indicating success
Shaun Kelsey 0:da5f5b56060a 314 */
Shaun Kelsey 0:da5f5b56060a 315 SS_STATUS self_test(int idx, uint8_t *result, int sleep_ms = SS_DEFAULT_CMD_SLEEP_MS);
Shaun Kelsey 0:da5f5b56060a 316
Shaun Kelsey 0:da5f5b56060a 317 /**
Shaun Kelsey 0:da5f5b56060a 318 * @brief Check if SmartSensor is in bootloader mode
Shaun Kelsey 0:da5f5b56060a 319 *
Shaun Kelsey 0:da5f5b56060a 320 * @return 1 if in bootloader mode, 0 if in main app, -1 if comm error
Shaun Kelsey 0:da5f5b56060a 321 */
Shaun Kelsey 0:da5f5b56060a 322 int in_bootldr_mode();
Shaun Kelsey 0:da5f5b56060a 323
Shaun Kelsey 0:da5f5b56060a 324
Shaun Kelsey 0:da5f5b56060a 325 /**
Shaun Kelsey 0:da5f5b56060a 326 * @brief Read register from a device onboard SmartSensor
Shaun Kelsey 0:da5f5b56060a 327 *
Shaun Kelsey 0:da5f5b56060a 328 * @param[in] idx - Index of device to read
Shaun Kelsey 0:da5f5b56060a 329 * @param[in] addr - Register address
Shaun Kelsey 0:da5f5b56060a 330 * @param[out] val - Register value
Shaun Kelsey 0:da5f5b56060a 331 *
Shaun Kelsey 0:da5f5b56060a 332 * @return SS_SUCCESS on success
Shaun Kelsey 0:da5f5b56060a 333 */
Shaun Kelsey 0:da5f5b56060a 334 SS_STATUS get_reg(int idx, uint8_t addr, uint32_t *val);
Shaun Kelsey 0:da5f5b56060a 335
Shaun Kelsey 0:da5f5b56060a 336 /**
Shaun Kelsey 0:da5f5b56060a 337 * @brief Set register of a device onboard SmartSensor
Shaun Kelsey 0:da5f5b56060a 338 *
Shaun Kelsey 0:da5f5b56060a 339 * @param[in] idx - Index of device to read
Shaun Kelsey 0:da5f5b56060a 340 * @param[in] addr - Register address
Shaun Kelsey 0:da5f5b56060a 341 * @param[in] val - Register value
Shaun Kelsey 0:da5f5b56060a 342 * @param[in] byte_size - Size of IC register in bytes
Shaun Kelsey 0:da5f5b56060a 343 *
Shaun Kelsey 0:da5f5b56060a 344 * @return SS_SUCCESS on success
Shaun Kelsey 0:da5f5b56060a 345 */
Shaun Kelsey 0:da5f5b56060a 346 SS_STATUS set_reg(int idx, uint8_t addr, uint32_t val, int byte_size);
Shaun Kelsey 0:da5f5b56060a 347
Shaun Kelsey 0:da5f5b56060a 348 /**
Shaun Kelsey 0:da5f5b56060a 349 * @brief Dump registers of a device onboard SmartSensor
Shaun Kelsey 0:da5f5b56060a 350 *
Shaun Kelsey 0:da5f5b56060a 351 * @param[in] idx - Index of device
Shaun Kelsey 0:da5f5b56060a 352 * @param[in] reg_vals - Array of addr_val_pairs
Shaun Kelsey 0:da5f5b56060a 353 * @param[in] reg_vals_sz - Number of items reg_vals can hold
Shaun Kelsey 0:da5f5b56060a 354 * @param[out] num_regs - Number of registers returned by command
Shaun Kelsey 0:da5f5b56060a 355 *
Shaun Kelsey 0:da5f5b56060a 356 * @return SS_SUCCESS on success
Shaun Kelsey 0:da5f5b56060a 357 */
Shaun Kelsey 0:da5f5b56060a 358 SS_STATUS dump_reg(int idx, addr_val_pair* reg_vals, int reg_vals_sz, int* num_regs);
Shaun Kelsey 0:da5f5b56060a 359
Shaun Kelsey 0:da5f5b56060a 360
Shaun Kelsey 0:da5f5b56060a 361 /**
Shaun Kelsey 0:da5f5b56060a 362 * @brief Enable a device on the SmartSensor
Shaun Kelsey 0:da5f5b56060a 363 *
Shaun Kelsey 0:da5f5b56060a 364 * @param[in] idx - Index of device
Shaun Kelsey 0:da5f5b56060a 365 * @param[in] mode - Mode to set the device to
Shaun Kelsey 0:da5f5b56060a 366 * @param[in] data_req - Data request
Shaun Kelsey 0:da5f5b56060a 367 *
Shaun Kelsey 0:da5f5b56060a 368 * @return SS_SUCCESS on success
Shaun Kelsey 0:da5f5b56060a 369 */
Shaun Kelsey 0:da5f5b56060a 370 SS_STATUS enable_sensor(int idx, int mode, ss_data_req* data_req);
Shaun Kelsey 0:da5f5b56060a 371
Shaun Kelsey 0:da5f5b56060a 372 /**
Shaun Kelsey 0:da5f5b56060a 373 * @brief Disable a device on the SmartSensor
Shaun Kelsey 0:da5f5b56060a 374 *
Shaun Kelsey 0:da5f5b56060a 375 * @param[in] idx - Index of device
Shaun Kelsey 0:da5f5b56060a 376 *
Shaun Kelsey 0:da5f5b56060a 377 * @return SS_SUCCESS on success
Shaun Kelsey 0:da5f5b56060a 378 */
Shaun Kelsey 0:da5f5b56060a 379 SS_STATUS disable_sensor(int idx);
Shaun Kelsey 0:da5f5b56060a 380
Shaun Kelsey 0:da5f5b56060a 381 /**
Shaun Kelsey 0:da5f5b56060a 382 * @brief Enable an algorithm on the SmartSensor
Shaun Kelsey 0:da5f5b56060a 383 *
Shaun Kelsey 0:da5f5b56060a 384 * @param[in] idx - Index of device
Shaun Kelsey 0:da5f5b56060a 385 * @param[in] mode - Mode to set the device to
Shaun Kelsey 0:da5f5b56060a 386 * @param[in] data_req - Data request
Shaun Kelsey 0:da5f5b56060a 387 *
Shaun Kelsey 0:da5f5b56060a 388 * @return SS_SUCCESS on success
Shaun Kelsey 0:da5f5b56060a 389 */
Shaun Kelsey 0:da5f5b56060a 390 SS_STATUS enable_algo(int idx, int mode, ss_data_req* data_req);
Shaun Kelsey 0:da5f5b56060a 391
Shaun Kelsey 0:da5f5b56060a 392 /**
Shaun Kelsey 0:da5f5b56060a 393 * @brief Disable an algorithm on the SmartSensor
Shaun Kelsey 0:da5f5b56060a 394 *
Shaun Kelsey 0:da5f5b56060a 395 * @param[in] idx - Index of device
Shaun Kelsey 0:da5f5b56060a 396 *
Shaun Kelsey 0:da5f5b56060a 397 * @return SS_SUCCESS on success
Shaun Kelsey 0:da5f5b56060a 398 */
Shaun Kelsey 0:da5f5b56060a 399 SS_STATUS disable_algo(int idx);
Shaun Kelsey 0:da5f5b56060a 400
Shaun Kelsey 0:da5f5b56060a 401
Shaun Kelsey 0:da5f5b56060a 402 /**
Shaun Kelsey 0:da5f5b56060a 403 * @brief Set the CommChannel Output Mode options
Shaun Kelsey 0:da5f5b56060a 404 *
Shaun Kelsey 0:da5f5b56060a 405 * @param[in] data_type - Set to 0 for only algorithm data
Shaun Kelsey 0:da5f5b56060a 406 * Set to 1 for only raw sensor data
Shaun Kelsey 0:da5f5b56060a 407 * Set to 2 for algo + raw sensor data
Shaun Kelsey 0:da5f5b56060a 408 * Set to 3 for no data
Shaun Kelsey 0:da5f5b56060a 409 * @param[in] sc_en - Set to true to receive 1 byte sample count from SmartSensor
Shaun Kelsey 0:da5f5b56060a 410 *
Shaun Kelsey 0:da5f5b56060a 411 * @return SS_SUCCESS on success
Shaun Kelsey 0:da5f5b56060a 412 */
Shaun Kelsey 0:da5f5b56060a 413 SS_STATUS set_data_type(int data_type, bool sc_en);
Shaun Kelsey 0:da5f5b56060a 414
Shaun Kelsey 0:da5f5b56060a 415 /**
Shaun Kelsey 0:da5f5b56060a 416 * @brief Get the CommChannel Output Mode options
Shaun Kelsey 0:da5f5b56060a 417 *
Shaun Kelsey 0:da5f5b56060a 418 * @param[out] data_type - 0 for only algorithm data
Shaun Kelsey 0:da5f5b56060a 419 * 1 for only raw sensor data
Shaun Kelsey 0:da5f5b56060a 420 * 2 for algo + raw sensor data
Shaun Kelsey 0:da5f5b56060a 421 * 3 for no data
Shaun Kelsey 0:da5f5b56060a 422 * @param[in] sc_en - If true, SmartSensor prepends data with 1 byte sample count
Shaun Kelsey 0:da5f5b56060a 423 *
Shaun Kelsey 0:da5f5b56060a 424 * @return SS_SUCCESS on success
Shaun Kelsey 0:da5f5b56060a 425 */
Shaun Kelsey 0:da5f5b56060a 426 SS_STATUS get_data_type(int* data_type, bool *sc_en);
Shaun Kelsey 0:da5f5b56060a 427
Shaun Kelsey 0:da5f5b56060a 428 void enable_irq();
Shaun Kelsey 0:da5f5b56060a 429 void disable_irq();
Shaun Kelsey 0:da5f5b56060a 430
Shaun Kelsey 0:da5f5b56060a 431 void mfio_selftest();
Shaun Kelsey 0:da5f5b56060a 432 bool reset_mfio_irq();
Shaun Kelsey 0:da5f5b56060a 433
Shaun Kelsey 0:da5f5b56060a 434 private:
Shaun Kelsey 0:da5f5b56060a 435
Shaun Kelsey 0:da5f5b56060a 436 /* PRIVATE VARIABLES */
Shaun Kelsey 0:da5f5b56060a 437 I2C *m_i2cBus;
Shaun Kelsey 0:da5f5b56060a 438 SPI *m_spiBus;
Shaun Kelsey 0:da5f5b56060a 439 DigitalInOut mfio_pin;
Shaun Kelsey 0:da5f5b56060a 440 DigitalInOut reset_pin;
Shaun Kelsey 0:da5f5b56060a 441 InterruptIn irq_pin;
Shaun Kelsey 0:da5f5b56060a 442
Shaun Kelsey 0:da5f5b56060a 443 char fw_version[128];
Shaun Kelsey 0:da5f5b56060a 444 const char* plat_name;
Shaun Kelsey 0:da5f5b56060a 445
Shaun Kelsey 0:da5f5b56060a 446 bool sc_en;
Shaun Kelsey 0:da5f5b56060a 447 int data_type;
Shaun Kelsey 0:da5f5b56060a 448
Shaun Kelsey 0:da5f5b56060a 449 int sensor_enabled_mode[SS_MAX_SUPPORTED_SENSOR_NUM];
Shaun Kelsey 0:da5f5b56060a 450 int algo_enabled_mode[SS_MAX_SUPPORTED_ALGO_NUM];
Shaun Kelsey 0:da5f5b56060a 451 ss_data_req* sensor_data_reqs[SS_MAX_SUPPORTED_SENSOR_NUM];
Shaun Kelsey 0:da5f5b56060a 452 ss_data_req* algo_data_reqs[SS_MAX_SUPPORTED_ALGO_NUM];
Shaun Kelsey 0:da5f5b56060a 453
Shaun Kelsey 0:da5f5b56060a 454 /* PRIVATE METHODS */
Shaun Kelsey 0:da5f5b56060a 455 SS_STATUS write_cmd_small(uint8_t *cmd_bytes, int cmd_bytes_len,
Shaun Kelsey 0:da5f5b56060a 456 uint8_t *data, int data_len,
Shaun Kelsey 0:da5f5b56060a 457 int sleep_ms = SS_DEFAULT_CMD_SLEEP_MS);
Shaun Kelsey 0:da5f5b56060a 458 SS_STATUS write_cmd_large(uint8_t *cmd_bytes, int cmd_bytes_len,
Shaun Kelsey 0:da5f5b56060a 459 uint8_t *data, int data_len,
Shaun Kelsey 0:da5f5b56060a 460 int sleep_ms = SS_DEFAULT_CMD_SLEEP_MS);
Shaun Kelsey 0:da5f5b56060a 461 void cfg_mfio(PinDirection);
Shaun Kelsey 0:da5f5b56060a 462
Shaun Kelsey 0:da5f5b56060a 463 void irq_handler();
Shaun Kelsey 0:da5f5b56060a 464
Shaun Kelsey 0:da5f5b56060a 465 void irq_handler_selftest();
Shaun Kelsey 0:da5f5b56060a 466 volatile bool mfio_int_happened;
Shaun Kelsey 0:da5f5b56060a 467
Shaun Kelsey 0:da5f5b56060a 468 SS_STATUS read_fifo_data(int num_samples, int sample_size, uint8_t* databuf, int databuf_sz);
Shaun Kelsey 0:da5f5b56060a 469 SS_STATUS num_avail_samples(int* num_samples);
Shaun Kelsey 0:da5f5b56060a 470 void fifo_sample_size(int data_type, int* sample_size);
Shaun Kelsey 0:da5f5b56060a 471 };
Shaun Kelsey 0:da5f5b56060a 472
Shaun Kelsey 0:da5f5b56060a 473
Shaun Kelsey 0:da5f5b56060a 474 #endif