39 #include <ti/drivers/GPIO.h>
40 #include <ti/drivers/I2C.h>
42 #include "ti_drivers_config.h"
75 #define WRITE_FIFO_INPUT_BYTE 0x04
81 #define BOOTLOADER_MODE 0x08
83 #define INCORR_PARAM 0xEE
85 #define CONFIGURATION_REGISTER 0x0A
86 #define PULSE_MASK 0xFC
87 #define READ_PULSE_MASK 0x03
88 #define SAMP_MASK 0xE3
89 #define READ_SAMP_MASK 0x1C
91 #define READ_ADC_MASK 0x60
93 #define ENABLE_CMD_DELAY 50
95 #define MAXFAST_ARRAY_SIZE 6
96 #define MAXFAST_EXTENDED_DATA 5
97 #define MAX30101_LED_ARRAY 12
99 #define SET_FORMAT 0x00
100 #define READ_FORMAT 0x01
101 #define WRITE_SET_THRESHOLD 0x01
102 #define WRITE_EXTERNAL_TO_FIFO 0x00
104 #define BIO_ADDRESS 0x55;
151 enum READ_STATUS_BYTE_VALUE {
154 ERR_UNAVAIL_CMD = 0x01,
158 ERR_INVALID_MODE = 0x05,
159 ERR_BTLDR_TRY_AGAIN = 0x05,
160 ERR_BTLDR_GENERAL = 0x80,
163 ERR_BTLDR_INVALID_APP,
164 ERR_TRY_AGAIN = 0xFE,
172 enum FAMILY_REGISTER_BYTES {
182 WRITE_REGISTER = 0x40,
188 CHANGE_ALGORITHM_CONFIG = 0x50,
189 READ_ALGORITHM_CONFIG,
191 BOOTLOADER_FLASH = 0x80,
203 enum DEVICE_MODE_WRITE_BYTES {
205 EXIT_BOOTLOADER = 0x00,
207 ENTER_BOOTLOADER = 0x08
213 enum OUTPUT_MODE_WRITE_BYTE {
218 SENSOR_AND_ALGORITHM,
227 enum FIFO_OUTPUT_INDEX_BYTE {
235 enum FIFO_EXTERNAL_INDEX_BYTE {
240 READ_NUM_SAMPLES_INPUT,
241 READ_NUM_SAMPLES_SENSOR
246 enum WRITE_REGISTER_INDEX_BYTE {
248 WRITE_MAX30101 = 0x03,
254 enum READ_REGISTER_INDEX_BYTE {
256 READ_MAX30101 = 0x03,
262 enum GET_AFE_INDEX_BYTE {
264 RETRIEVE_AFE_MAX30101 = 0x03,
265 RETRIEVE_AFE_ACCELEROMETER
270 enum DUMP_REGISTER_INDEX_BYTE {
272 DUMP_REGISTER_MAX30101 = 0x03,
273 DUMP_REGISTER_ACCELEROMETER
278 enum SENSOR_ENABLE_INDEX_BYTE {
280 ENABLE_MAX30101 = 0x03,
286 enum READ_SENSOR_ENABLE_INDEX_BYTE {
288 READ_ENABLE_MAX30101 = 0x03,
289 READ_ENABLE_ACCELEROMETER
294 enum ALGORITHM_CONFIG_INDEX_BYTE {
296 SET_TARG_PERC = 0x00,
297 SET_STEP_SIZE = 0x00,
298 SET_SENSITIVITY = 0x00,
299 SET_AVG_SAMPLES = 0x00,
300 SET_PULSE_OX_COEF = 0x02,
306 enum ALGO_AGC_WRITE_BYTE {
312 MAXIMFAST_COEF_ID = 0x0B
317 enum READ_ALGORITHM_INDEX_BYTE {
319 READ_AGC_PERCENTAGE = 0x00,
320 READ_AGC_STEP_SIZE = 0x00,
321 READ_AGC_SENSITIVITY = 0x00,
322 READ_AGC_NUM_SAMPLES = 0x00,
323 READ_MAX_FAST_COEF = 0x02
329 enum READ_AGC_ALGO_WRITE_BYTE {
331 READ_AGC_PERC_ID = 0x00,
332 READ_AGC_STEP_SIZE_ID,
333 READ_AGC_SENSITIVITY_ID,
334 READ_AGC_NUM_SAMPLES_ID,
335 READ_MAX_FAST_COEF_ID = 0x0B
340 enum ALGORITHM_MODE_ENABLE_INDEX_BYTE {
342 ENABLE_AGC_ALGO = 0x00,
343 ENABLE_WHRM_ALGO = 0x02
348 enum BOOTLOADER_FLASH_INDEX_BYTE {
350 SET_INIT_VECTOR_BYTES = 0x00,
359 enum BOOTLOADER_INFO_INDEX_BYTE {
361 BOOTLOADER_VERS = 0x00,
367 enum IDENTITY_INDEX_BYTES {
369 READ_MCU_TYPE = 0x00,
370 READ_SENSOR_HUB_VERS = 0x03,
371 READ_ALGO_VERS = 0x07
384 #define I2_READ_STATUS_BYTE_COUNT 0x01
386 #define MODE_REGISTER 0x09
387 #define MODE_MASK 0xF8
388 #define READ_MODE_MASK 0x07
389 #define RESET_MASK 0xBF
390 #define READ_RESET_MASK 0x40
391 #define SET_RESET_BIT 0x40
392 #define SHDN_MASK 0x7F
393 #define READ_SHDN_MASK 0x80
395 #define LEDOFFSET_REGISTER 0x0B
396 #define LED1_REGISTER 0x0C
397 #define LED2_REGISTER 0x0D
398 #define LED3_REGISTER 0x0E
399 #define LED4_REGISTER 0x0F
401 #define READ_MAX_FAST_RATE 0x02
402 #define READ_MAX_FAST_RATE_ID 0x00
404 #define NUM_MAXIM_FAST_COEF 0x03
424 uint8_t
beginI2C(I2C_Handle i2cHandle, uint8_t *statusByte);
449 uint8_t
configMAX32664(uint8_t outputFormat, uint8_t algoMode, uint8_t intThresh);
736 uint8_t
setDeviceMode(uint8_t operatingMode, uint8_t *statusByte);
990 uint8_t
readPulseAmp(uint8_t *ledArray, uint8_t *statusByte);
1131 uint8_t
I2CReadByte(uint8_t familyByte, uint8_t indexByte, uint8_t *statusByte);
1173 uint8_t
I2CReadFillArray(uint8_t familyByte, uint8_t indexByte, uint8_t arraySize, uint8_t *arraytoFill);
1193 uint16_t
I2CReadInt(uint8_t familyByte, uint8_t indexByte, uint8_t *statusByte);
1214 uint16_t
I2CReadIntWithWriteByte(uint8_t familyByte, uint8_t indexByte, uint8_t writeByte, uint8_t *statusByte);
1235 int32_t
I2CRead32BitValue(uint8_t familyByte, uint8_t indexByte, uint8_t dataByte, uint8_t *statusByte);
1257 uint8_t
I2CReadMultiple32BitValues(uint8_t familyByte, uint8_t indexByte, uint8_t dataByte, uint8_t numReads, int32_t *numArray);
1277 uint8_t
I2CWriteByte(uint8_t familyByte, uint8_t indexByte, uint8_t dataByte);
1297 uint8_t
I2CWrite2Bytes(uint8_t familyByte, uint8_t indexByte, uint8_t dataByte0, uint8_t dataByte1);
uint16_t I2CReadIntWithWriteByte(uint8_t familyByte, uint8_t indexByte, uint8_t writeByte, uint8_t *statusByte)
Performs a read transaction with a single write byte.
Definition: bio_sensor.c:1981
uint8_t numSamplesOutFifo(uint8_t *statusByte)
Reads number of samples available in the output FIFO.
Definition: bio_sensor.c:853
uint8_t readAlgoRange(uint8_t *statusByte)
Reads the percent of full scale ADC range that the AGC algorithm is using.
Definition: bio_sensor.c:1116
struct version readSensorHubVersion(uint8_t *statusByte)
Reads the current version of the sensor hub.
Definition: bio_sensor.c:1236
uint8_t I2CWriteByte(uint8_t familyByte, uint8_t indexByte, uint8_t dataByte)
Does an I2C write transaction with the MAX32664 that will write a single byte.
Definition: bio_sensor.c:2183
uint8_t readRegisterMAX30101(uint8_t regAddr, uint8_t *statusByte)
Reads the value in specific register in the MAX30101.
Definition: bio_sensor.c:1673
uint8_t I2CenableWriteByte(uint8_t familyByte, uint8_t indexByte, uint8_t dataByte)
Does an I2C write transaction with the MAX32664 that will write a single byte, with a longer delay be...
Definition: bio_sensor.c:2285
uint8_t agcAlgoControl(uint8_t enable)
Controls the AGC algorithm, enables or disables it.
Definition: bio_sensor.c:876
uint8_t setFifoThreshold(uint8_t intThresh)
Sets output FIFO threshold (# data samples extracted before MRIO output interrupt generated)
Definition: bio_sensor.c:825
uint16_t readPulseWidth(uint8_t *statusByte)
Reads the LED pulse width of the LEDs in the MAX30101.
Definition: bio_sensor.c:1438
uint8_t readPulseAmp(uint8_t *ledArray, uint8_t *statusByte)
Reads the LED pulse amplitude of the LEDs in the MAX30101.
Definition: bio_sensor.c:1467
uint8_t softwareResetMAX30101(void)
Performs a reset of MAX30101 by setting the Reset Control bit to 1.
Definition: bio_sensor.c:754
struct bioData readSensorData(uint8_t *statusByte)
Read sensor data from MAX32664 output FIFO.
Definition: bio_sensor.c:195
uint8_t readAlgoStepSize(uint8_t *statusByte)
Reads the step size towards the target for the AGC algorithm.
Definition: bio_sensor.c:1139
uint16_t I2CReadInt(uint8_t familyByte, uint8_t indexByte, uint8_t *statusByte)
Performs a read transaction with no write bytes.
Definition: bio_sensor.c:1917
struct sensorAttr getAfeAttributesAccelerometer(uint8_t *statusByte)
Gets the attributes for the accelerometer.
Definition: bio_sensor.c:1609
uint8_t setDeviceMode(uint8_t operatingMode, uint8_t *statusByte)
Sets the operating mode for the MAX32664.
Definition: bio_sensor.c:1028
uint8_t maximFastAlgoControl(uint8_t mode)
Controls the WHRM/Maxim Algorithm, disables it or sets the mode (mode 1 or mode 2)
Definition: bio_sensor.c:965
uint8_t getMcuType(uint8_t *statusByte)
Reads the MCU type of biometric sensor hub (expect MAX32660/MAX32664)
Definition: bio_sensor.c:1353
uint16_t readADCRange(uint8_t *statusByte)
Reads the internal ADC range of the MAX30101.
Definition: bio_sensor.c:1408
uint8_t I2CReadByte(uint8_t familyByte, uint8_t indexByte, uint8_t *statusByte)
Does an I2C read transaction with the MAX32664 that will read a single byte.
Definition: bio_sensor.c:1731
uint8_t softwareResetMAX32664(void)
Does a software reset of the device.
Definition: bio_sensor.c:715
uint8_t readAlgoSamples(uint8_t *statusByte)
Reads the number of samples available in the output FIFO.
Definition: bio_sensor.c:1093
struct sensorAttr getAfeAttributesMAX30101(uint8_t *statusByte)
Gets the attributes for the MAX30101 sensor.
Definition: bio_sensor.c:1570
uint8_t I2CWrite2Bytes(uint8_t familyByte, uint8_t indexByte, uint8_t dataByte0, uint8_t dataByte1)
Does an I2C write transaction with the MAX32664 that will write two bytes.
Definition: bio_sensor.c:2233
uint8_t readDeviceMode(uint8_t *statusByte)
Reads the current MAX32664 operating mode.
Definition: bio_sensor.c:1004
uint8_t I2CReadBytewithWriteByte(uint8_t familyByte, uint8_t indexByte, uint8_t dataByte, uint8_t *statusByte)
Does an I2C read transaction with the MAX32664 that requires a single write byte, that will read a si...
Definition: bio_sensor.c:1790
uint8_t readMAX30101State(uint8_t *statusByte)
Reads the MAX30101 pulse oximeter state.
Definition: bio_sensor.c:942
struct bioData readRawAndAlgoData(uint8_t *statusByte)
Reads the raw+algorithm data if that this is the output format.
Definition: bio_sensor.c:555
uint16_t readADCSampleRate(uint8_t *statusByte)
Reads the ADC sample rate of the MAX30101 internal ADC.
Definition: bio_sensor.c:1374
uint8_t max30101Control(uint8_t senSwitch)
Controls the MAX30101 pulse oximeter, enables or disables it.
Definition: bio_sensor.c:909
struct version readBootloaderVersion(uint8_t *statusByte)
Reads the current version of the bootloader.
Definition: bio_sensor.c:1316
struct version readAlgorithmVersion(uint8_t *statusByte)
Reads the current version of the algorithm.
Definition: bio_sensor.c:1276
uint8_t I2CReadMultiple32BitValues(uint8_t familyByte, uint8_t indexByte, uint8_t dataByte, uint8_t numReads, int32_t *numArray)
Does an I2C read transaction with the MAX32664 that reads multiple 32-bit variables.
Definition: bio_sensor.c:2111
struct bioData readRawData(uint8_t *statusByte)
Reads the raw sensor data, assuming only the raw sensor data is being output.
Definition: bio_sensor.c:337
uint8_t I2CReadFillArray(uint8_t familyByte, uint8_t indexByte, uint8_t arraySize, uint8_t *arraytoFill)
Does an I2C read transaction with the MAX32664 that will read an array of data back,...
Definition: bio_sensor.c:1850
uint8_t readSensorHubStatus(uint8_t *statusByte)
Reads the current sensor hub status.
Definition: bio_sensor.c:1070
uint8_t beginI2C(I2C_Handle i2cHandle, uint8_t *statusByte)
Takes the I2C handle object to read the current sensor hub mode.
Definition: bio_sensor.c:63
uint8_t setOutputMode(uint8_t outputType)
Sets the data output mode: raw, algorithm, raw+algorithm, etc.
Definition: bio_sensor.c:793
uint8_t configMAX32664(uint8_t outputFormat, uint8_t algoMode, uint8_t intThresh)
Configures the MAX32664.
Definition: bio_sensor.c:108
uint8_t readMAX30101Mode(uint8_t *statusByte)
Reads the operating mode of the MAX30101 PO sensor.
Definition: bio_sensor.c:1534
int32_t I2CRead32BitValue(uint8_t familyByte, uint8_t indexByte, uint8_t dataByte, uint8_t *statusByte)
Does an I2C read transaction with the MAX32664 that reads a single 32-bit variable.
Definition: bio_sensor.c:2045
struct bioData readAlgoData(uint8_t *statusByte)
Reads the algorithm data, assuming only the algorithm data is being output.
Definition: bio_sensor.c:414
uint8_t getExtAccelMode(uint8_t *statusByte)
Gets the current mode of the external accelerometer.
Definition: bio_sensor.c:1643
uint8_t writeRegisterMAX30101(uint8_t regAddr, uint8_t regVal)
Writes the given value to the given register address in the MAX30101.
Definition: bio_sensor.c:1697
uint16_t readAlgoSampleRate(uint8_t *statusByte)
Reads the WHRM algorithm sample rate.
Definition: bio_sensor.c:1185
uint8_t readAlgoSensitivity(uint8_t *statusByte)
Reads the sensitivity of the AGC algorithm.
Definition: bio_sensor.c:1162
uint8_t readMaximFastCoef(int32_t *coefArray)
Reads the 3 Maxim Fast algorithm coefficients, which are 32-bit signed values * 100,...
Definition: bio_sensor.c:1209
Struct of algorithm output data.
Definition: bio_sensor.h:112
int8_t extStatus
– Algorithm status. 0: Success, 1: Not Ready, -1: Something is on sensor, -2: Device excessive motion...
Definition: bio_sensor.h:121
uint16_t heartRate
Calculated WHRM algorithm heart rate. LSB = 0.1bpm.
Definition: bio_sensor.h:116
uint16_t oxygen
Calculated WHRM algorithm SpO2 level. 0-100% LSB = 1%.
Definition: bio_sensor.h:118
uint32_t irLed
IR LED ADC Count.
Definition: bio_sensor.h:114
float rValue
– Algorithm Mode 2 vv calculated R value
Definition: bio_sensor.h:120
uint8_t status
Algorithm current state. 0: No object detected, 1: Something on sensor, 2: Another object detected,...
Definition: bio_sensor.h:119
uint8_t confidence
Calculated WHRM algorithm confidence in heart rate. 0-100% LSB = 1%.
Definition: bio_sensor.h:117
uint32_t redLed
RED LED ADC Count.
Definition: bio_sensor.h:115
Struct of attributes for a sensor.
Definition: bio_sensor.h:142
uint8_t availRegisters
Number of registers available.
Definition: bio_sensor.h:145
uint8_t byteWord
Number of bytes in a word for this sensor.
Definition: bio_sensor.h:144
Struct of version data.
Definition: bio_sensor.h:130
uint8_t major
major part of version information
Definition: bio_sensor.h:132
uint8_t revision
revision part of version information
Definition: bio_sensor.h:134
uint8_t minor
minor part of version information
Definition: bio_sensor.h:133