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.
Fork of mbed-os-test by
Revision 0:e4a10ed6eb92, committed 2016-10-25
- Comitter:
- jbradshaw
- Date:
- Tue Oct 25 15:22:11 2016 +0000
- Commit message:
- tewt
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.gitignore Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,4 @@ +.build +.mbed +projectfiles +*.py*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/BMP280/BMP280/BMP280.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,294 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + + +#include "mbed.h" +#include "BMP280.h" + +//****************************************************************************** +BMP280::BMP280(PinName sda, PinName scl, int slaveAddress) : + slaveAddress(slaveAddress) { + i2c = new I2C(sda, scl); + isOwner = true; +} +//****************************************************************************** +BMP280::BMP280(I2C *i2c, int slaveAddress) : + slaveAddress(slaveAddress) { + this->i2c = i2c; + isOwner = false; + + i2c->frequency(100000); + loggingEnabled = 0; + loggingSampleRate = 5; +} +//****************************************************************************** +BMP280::~BMP280(void) { + if (isOwner == true) { + delete i2c; + } +} + +//****************************************************************************** +int BMP280::init(BMP280::bmp280_osrs_P_t Osrs_p, BMP280::bmp280_osrs_T_t Osrs_t, + BMP280::bmp280_FILT_t Filter, BMP280::bmp280_MODE_t Mode, + BMP280::bmp280_TSB_t T_sb) + +{ + char reg; + char raw_Tn[6]; + char raw_Pn[20]; + + // Read all the temp coeffecients from the BMP280 memory. It will be used in + // calculation + reg = 0x88; + if (reg_read(reg, raw_Tn, 6) != 0) { + return -1; + } + + dig_T1 = (((uint16_t)raw_Tn[1]) << 8) | raw_Tn[0]; + dig_T2 = (((int16_t)raw_Tn[3]) << 8) | raw_Tn[2]; + dig_T3 = (((int16_t)raw_Tn[5]) << 8) | raw_Tn[4]; + + // Read all the press coeffecients from the BMP280 memory. It will be used in + // calculation + reg = 0x8E; + if (reg_read(reg, raw_Pn, 20) != 0) { + return -1; + } + + dig_P1 = (((uint16_t)raw_Pn[1]) << 8) | raw_Pn[0]; + dig_P2 = (((int16_t)raw_Pn[3]) << 8) | raw_Pn[2]; + dig_P3 = (((int16_t)raw_Pn[5]) << 8) | raw_Pn[4]; + dig_P4 = (((int16_t)raw_Pn[7]) << 8) | raw_Pn[6]; + dig_P5 = (((int16_t)raw_Pn[9]) << 8) | raw_Pn[8]; + dig_P6 = (((int16_t)raw_Pn[11]) << 8) | raw_Pn[10]; + dig_P7 = (((int16_t)raw_Pn[13]) << 8) | raw_Pn[12]; + dig_P8 = (((int16_t)raw_Pn[15]) << 8) | raw_Pn[14]; + dig_P9 = (((int16_t)raw_Pn[17]) << 8) | raw_Pn[16]; + + + wait(1.0 / 10.0); + + /****/ + if (reg_read(BMP280_CTRL_MEAS, &bmp280_ctrl_meas.all, 1) != 0) { + return -1; + } + + bmp280_ctrl_meas.bit.osrs_p = Osrs_p; + bmp280_ctrl_meas.bit.osrs_t = Osrs_t; + + bmp280_ctrl_meas.bit.mode = Mode; + + if (reg_write(BMP280_CTRL_MEAS, bmp280_ctrl_meas.all) != 0) { + return -1; + } + + /****/ + + if (reg_read(BMP280_CONFIG, &bmp280_config.all, 1) != 0) { + return -1; + } + + bmp280_config.bit.filter = Filter; + + if (Mode == 0b11) { + bmp280_config.bit.t_sb = T_sb; + } + + if (reg_write(BMP280_CONFIG, bmp280_config.all) != 0) { + return -1; + } + + return 0; +} + +//****************************************************************************** +float BMP280::ToFahrenheit(float temperature) { + return temperature * 9 / 5 + 32; +} + +//****************************************************************************** +int BMP280::ReadCompDataRaw2(char *bmp280_rawData) { + int i; + char data[6]; + float temp; + float pressure; + int iPressure; + char str[32]; + ReadCompDataRaw(data); + ToFloat(data, &temp, &pressure); + iPressure = (int)pressure; + sprintf(str, "%d ", iPressure); + for (i = 0; i < 6; i++) { + bmp280_rawData[i] = str[i]; + } + return 0; +} + +//****************************************************************************** +int BMP280::ReadCompDataRaw(char *bmp280_rawData) { + char reg; + char rxbytes; + + reg = BMP280_PRESS_MSB; + rxbytes = 6; + + if (reg_read(reg, bmp280_rawData, rxbytes) != 0) { + return -1; + } + return 0; +} + +//****************************************************************************** +void BMP280::ToFloat(char *bmp280_rawData, float *Temp_degC, float *Press_Pa) { + bmp280_rawPress = (uint32_t)(bmp280_rawData[0] << 12) | + (bmp280_rawData[1] << 4) | (bmp280_rawData[2] >> 4); + + bmp280_rawTemp = (uint32_t)(bmp280_rawData[3] << 12) | + (bmp280_rawData[4] << 4) | (bmp280_rawData[5] >> 4); + + *Temp_degC = compensate_T_float(bmp280_rawTemp); + *Press_Pa = compensate_P_float(bmp280_rawPress); +} + +//****************************************************************************** +int BMP280::ReadCompData(float *Temp_degC, float *Press_Pa) { + char bmp280_rawData[6]; + + if (ReadCompDataRaw(bmp280_rawData) != 0) { + return -1; + } + ToFloat(bmp280_rawData, Temp_degC, Press_Pa); + return 0; +} + +//****************************************************************************** +int BMP280::reg_write(char reg, char value) { + int result; + char cmdData[2] = {(char)reg, value}; + result = i2c->write(slaveAddress, cmdData, 2); + if (result != 0) + return -1; + return 0; +} + +//****************************************************************************** +int BMP280::reg_read(char reg, char *value, char number) { + int result; + char cmdData[1] = {(char)reg}; + + result = i2c->write(slaveAddress, cmdData, 1); + if (result != 0) + return -1; + result = i2c->read(slaveAddress, value, number); + if (result != 0) + return -1; + return 0; +} + +//****************************************************************************** +int BMP280::Sleep(void) { + // Configure the I2C interface + + if (reg_read(BMP280_CTRL_MEAS, &bmp280_ctrl_meas.all, 1) != 0) { + return -1; + } + bmp280_ctrl_meas.bit.mode = 0b00; // put everything to sleep mode... + + if (reg_write(BMP280_CTRL_MEAS, bmp280_ctrl_meas.all) != 0) { + return -1; + } + return 0; +} + +//****************************************************************************** +void BMP280::Reset(void) { + reg_write(BMP280_RESET, 0xB6); // Initiate a Soft Reset +} + +//****************************************************************************** +int BMP280::Detect(void) { + if (reg_read(BMP280_ID, &bmp280_id, 1) != 0) { + return -1; + } + + if (bmp280_id == 0x58) { + return 1; + } + return 0; +} + +//****************************************************************************** +int BMP280::ReadId(void) { + if (reg_read(BMP280_ID, &bmp280_id, 1) != 0) { + return -1; + } + return bmp280_id; +} + +//****************************************************************************** +float BMP280::compensate_T_float(int32_t adc_T) { + float var1, var2, T; + var1 = + (((float)adc_T) / 16384.0 - ((float)dig_T1) / 1024.0) * ((float)dig_T2); + + var2 = ((((float)adc_T) / 131072.0 - ((float)dig_T1) / 8192.0) * + (((float)adc_T) / 131072.0 - ((float)dig_T1) / 8192.0)) * + ((float)dig_T3); + + t_fine = (int32_t)(var1 + var2); + + T = (var1 + var2) / 5120.0; + + return T; +} + +//****************************************************************************** +float BMP280::compensate_P_float(int32_t adc_P) { + float var1, var2, p; + var1 = ((float)t_fine / 2.0) - 64000.0; + var2 = var1 * var1 * ((float)dig_P6) / 32768.0; + var2 = var2 + var1 * ((float)dig_P5) * 2.0; + var2 = (var2 / 4.0) + (((float)dig_P4) * 65536.0); + var1 = (((float)dig_P3) * var1 * var1 / 524288.0 + ((float)dig_P2) * var1) / 524288.0; + var1 = (1.0 + var1 / 32768.0) * ((float)dig_P1); + if (var1 == 0.0) { + return 0; // avoid exception caused by division by zero + } + p = 1048576.0 - (float)adc_P; + p = (p - (var2 / 4096.0)) * 6250.0 / var1; + var1 = ((float)dig_P9) * p * p / 2147483648.0; + var2 = p * ((float)dig_P8) / 32768.0; + p = p + (var1 + var2 + ((float)dig_P7)) / 16.0; + return p; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/BMP280/BMP280/BMP280.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,418 @@ +/******************************************************************************* +* Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES +* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Except as contained in this notice, the name of Maxim Integrated +* Products, Inc. shall not be used except as stated in the Maxim Integrated +* Products, Inc. Branding Policy. +* +* The mere transfer of this software does not imply any licenses +* of trade secrets, proprietary technology, copyrights, patents, +* trademarks, maskwork rights, or any other form of intellectual +* property whatsoever. Maxim Integrated Products, Inc. retains all +* ownership rights. +*******************************************************************************/ +/** + * Bosch BMP280 Digital Pressure Sensor + * + * @code + * #include <stdio.h> + * #include "mbed.h" + * #include "xxx.h" + * + * I2C i2c(I2C_SDA, I2C_SCL); + * xxx xxx(&i2c); + * + * int main(void) { + * printf("Initialized xxx\n"); + * while(1) { + * if (xxx.init() != 0) { + * printf("Error communicating with xxx\n"); + * } else { + * printf("Initialized xxx\n"); + * break; + * } + * wait(1); + * } + * + * while(1) { + * printf(""); + * wait(1); + * } + * } + * @endcode + */ + +#ifndef BMP280_H_ +#define BMP280_H_ + +#include "mbed.h" + +#define BMP280_READID (0x58) + +#define BMP280_TEMP_XLSB (0xFC) +#define BMP280_TEMP_LSB (0xFB) +#define BMP280_TEMP_MSB (0xFA) + +#define BMP280_PRESS_XLSB (0xF9) +#define BMP280_PRESS_LSB (0xF8) +#define BMP280_PRESS_MSB (0xF7) + +#define BMP280_CONFIG (0xF5) +#define BMP280_CTRL_MEAS (0xF4) +#define BMP280_STATUS (0xF3) +#define BMP280_RESET (0xE0) +#define BMP280_ID (0xD0) + +// calib25-calib00: 0xA1-0x88 +#define BMP280_CALIB25 (0xA1) // Beginning address +#define BMP280_CALIB00 (0x88) // Ending address + +#define BMP280_REGISTER_CHIPID (0xD0) +#define BMP280_REGISTER_VERSION (0xD1) +#define BMP280_REGISTER_SOFTRESET (0xE0) + +#define BMP280_REGISTER_CAL26 (0xE1) // R calibration stored in 0xE1-0xF0 + +#define BMP280_REGISTER_CONTROL (0xF4) +#define BMP280_REGISTER_CONFIG (0xF5) +#define BMP280_REGISTER_PRESSUREDATA (0xF7) +#define BMP280_REGISTER_TEMPDATA (0xFA) + +/** + * @brief Bosch BMP280 Digital Pressure Sensor + */ +class BMP280 { + +public: + /** + * BMP280 constructor. + * + * @param sda mbed pin to use for SDA line of I2C interface. + * @param scl mbed pin to use for SCL line of I2C interface. + * @param slaveAddress Slave Address of the device. + */ + BMP280(PinName sda, PinName scl, int slaveAddress); + + /** + * BMP280 constructor. + * + * @param i2c I2C object to use. + * @param slaveAddress Slave Address of the device. + */ + BMP280(I2C *i2c, int slaveAddress); + + char loggingEnabled; + char loggingSampleRate; + + /** + * Write a device register + */ + int writeReg(char reg, char value); + /** + * Read a device register + */ + int readReg(char reg, char *value); + + /// @brief TEMP_XLSB (0xFC) + char bmp280_temp_xlsb; // Lower 4-bits are all 0's + + /// @brief TEMP_LSB (0xFB) + char bmp280_temp_lsb; + + /// @brief TEMP_MSB (0xFA) + char bmp280_temp_msb; + + /// @brief PRESS_XLSB (0xF9) + char bmp280_press_xlsb; // Lower 4-bits are all 0's + + /// @brief PRESS_LSB (0xF8) + char bmp280_press_lsb; + + /// @brief PRESS_MSB (0xF7) + char bmp280_press_msb; + + /// @brief CONFIG_REG (0xF5) + union bmp280_config_reg { + char all; + struct { + char spi3w_en : 1; + char reserved : 1; + char filter : 3; + char t_sb : 3; + } bit; + } bmp280_config; + + /// @brief CTRL_MEAS (0xF4) + union bmp280_ctrl_meas { + char all; + struct { + char mode : 2; + char osrs_p : 3; + char osrs_t : 3; + } bit; + } bmp280_ctrl_meas; + + /// @brief STATUS (0xF3) + union bmp280_status { + char all; + struct { + char im_update : 1; + char reserved1 : 2; + char measuring : 1; + char reserved2 : 4; + } bit; + } bmp280_status; + + /// @brief RESET (0xE0) + char bmp280_reset; + + /// @brief ID (0xD0) + char bmp280_id; + + typedef enum { + SKIPPED_P = 0, + OVERSAMPLING_X1_P = 1, + OVERSAMPLING_X2_P = 2, + OVERSAMPLING_X4_P = 3, + OVERSAMPLING_X8_P = 4, + OVERSAMPLING_X16_P = 5 + } bmp280_osrs_P_t; + + typedef enum { + SKIPPED_T = 0, + OVERSAMPLING_X1_T = 1, + OVERSAMPLING_X2_T = 2, + OVERSAMPLING_X4_T = 3, + OVERSAMPLING_X8_T = 4, + OVERSAMPLING_X16_T = 5 + } bmp280_osrs_T_t; + + typedef enum { + FILT_OFF = 1, + FILT_2 = 2, + FILT_3 = 4, + FILT_4 = 8, + FILT_5 = 16 + } bmp280_FILT_t; + + typedef enum { + SLEEP_MODE = 0, + FORCED_MODE = 1, + NORMAL_MODE = 3 + } bmp280_MODE_t; + + typedef enum { + T_0_5 = 0, + T_62_5 = 1, + T_125 = 2, + T_250 = 3, + T_500 = 4, + T_1000 = 5, + T_2000 = 6, + T_4000 = 7 + } bmp280_TSB_t; + + /// @brief calib25... calib00 (0xA1...0x88) + char bmp280_Calib[26]; + + uint16_t dig_T1; + int16_t dig_T2; + int16_t dig_T3; + + uint16_t dig_P1; + int16_t dig_P2; + int16_t dig_P3; + int16_t dig_P4; + int16_t dig_P5; + int16_t dig_P6; + int16_t dig_P7; + int16_t dig_P8; + int16_t dig_P9; + + int32_t t_fine; // This is calculated int the temperature to be used by the + // pressure + + int32_t bmp280_rawPress; + int32_t bmp280_rawTemp; + + float Temp_degC; // Deg C. + float Press_Pa; // Pascal. + + /** + * BMP280 constructor. + * + * @param sda mbed pin to use for SDA line of I2C interface. + * @param scl mbed pin to use for SCL line of I2C interface. + */ + BMP280(PinName sda, PinName scl); + + /** + * BMP280 constructor. + * + * @param i2c I2C object to use. + */ + BMP280(I2C *i2c); + + /** + * BMP280 destructor. + */ + ~BMP280(void); + + // Function Prototypes + + /** + * @brief This initializes the BMP280 + * @brief The BMP280 has 2 modes. FORCED mode and NORMAL mode. FORCED Mode gives more + * @brief control to the processor as the processor sends out the Mode to initiate a conversion + * @brief and a data is sent out then. NORMAL mode is initialized once and it just runs and sends + * @brief out data at a programmed timed interval. (In this example the main() will set this to Normal + * @brief function) + * @param Osrs_p- Pressure oversampling + * @param Osrs_t- Temperature oversampling + * @param Filter- Filter Settings + * @param Mode- Power Modes + * @param T_sb- Standby time (used with Normal mode) + * @param dig_T1, dig_T2, dig_T3- Coeffs used for temp conversion - GLOBAL variables (output) + * @param dig_P1, .... , dig_P9- Coeffs used for press conversion - GLOBAL variables (output) + * @returns 0-if no error. A non-zero value indicates an error. + */ + int init(bmp280_osrs_P_t Osrs_p, bmp280_osrs_T_t Osrs_t, bmp280_FILT_t Filter, + bmp280_MODE_t Mode, bmp280_TSB_t T_sb); + + /** + * @brief The BMP280 has 2 modes. FORCED mode and NORMAL mode. FORCED Mode + * gives more + * @brief control to the processor as the processor sends out the Mode to + * initiate a conversion + * @brief and a data is sent out then. NORMAL mode is initialized once and it + * just runs and sends + * @brief out data at a programmed timed interval. (In this example the + * main() will set this to Normal + * @brief function) + * @param *Temp_degC - Pointer to temperature (result in deg C) + * @param *Press_Pa - Pointer to pressure (resul in Pascal) + * @returns 0-if no error. A non-zero value indicates an error. + */ + int ReadCompData(float *Temp_degC, float *Press_Pa); + + /** + * @brief This function allows writing to a register. + * @param reg- Address of the register to write to + * @param value- Data written to the register + * @returns 0-if no error. A non-zero value indicates an error. + */ + int reg_write(char reg, char value); + + /** + * @brief This function allows writing to a register. + * @params reg- Address of the register to read from (input) + * @params *value- Pointer to the value read from the register (output) + * @returns 0-if no error. A non-zero value indicates an error. + */ + int reg_read(char reg, char *value, char number); + + /** + * @brief Performs a soft reset on the BMP280 + * @param none + * @returns none + */ + void Reset(void); + + /** + * @brief Detects if the BMP280 is present + * @param none + * @returns 1 for found, 0 for not found, -1 for comm error + */ + int Detect(void); + + /** + * @brief Performs calculations on the raw temperature data to convert to + * @brief temperature in deg C, based on Bosch's algorithm + * @param Raw Temp ADC value, Global dig_T1, dig_T2, dig_T3 + * @returns The Temperature in deg C + */ + float compensate_T_float(int32_t adc_T); // returned value Deg C. + + /** + * @brief Performs calculations on the raw pressure data to convert to + * @brief pressure in Pascal, based on Bosch's algorithm + * @param adc_P Raw Press ADC value, Global dig_P1, dig_P2,..., dig_P9 + * @returns The Pressure in Pascals + */ + float compensate_P_float(int32_t adc_P); // returned value Pascal. + + /** + * @brief Puts the BMP280 in low power Sleep mode + * @param none + * @returns 0 if no errors, -1 if error. + */ + int Sleep(void); + + /** + * @brief This reads the raw BMP280 data + * @param *bmp280_rawData- array of raw output data + * @returns 0-if no error. A non-zero value indicates an error. + * + */ + int ReadCompDataRaw(char *bmp280_rawData); + /** + * @brief This reads the raw BMP280 data uses the Bosch algorithm to get the + * data + * @brief in float, then the float gets converted to an String + * @param *bmp280_rawData- array of raw output data + * @returns 0-if no error. A non-zero value indicates an error. + * + */ + int ReadCompDataRaw2(char *bmp280_rawData); + /** + * @brief This converts the raw BMP280 data to couble based on Bosch's + * algorithm + * @param *bmp280_rawData- array of raw input data + * @param *Temp_degC- pointer to output, Temp value in deg C + * @param *Press_Pa- pointer to output, Press value in Pascals + * @returns 0-if no error. A non-zero value indicates an error. + * + */ + void ToFloat(char *bmp280_rawData, float *Temp_degC, float *Press_Pa); + /** + * @brief converts to Farenhite from Centigrade + * @param temperature in Centigrade + * @returns temperature value in Farenhite + */ + float ToFahrenheit(float temperature); + + /** + * @brief Reads a unique ID from the register + * @param none + * @returns The correct id value which is 0x58 + */ + int ReadId(void); + +private: + /// I2C pointer + I2C *i2c; + /// Is this object the owner of the I2C object + bool isOwner; + /// Device slave address + int slaveAddress; +}; + +#endif // BMP280_H_
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/BMP280/BMP280_RPC.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include "BMP280_RPC.h" +#include "BMP280.h" +#include "StringHelper.h" +#include "Peripherals.h" +#include "Device_Logging.h" + +extern Device_Logging *bmp280_Logging; + + +int BMP280_InitStart(char argStrs[32][32], char replyStrs[32][32]) { + uint8_t args[1]; + uint8_t reply[1]; + + ProcessArgs(argStrs, args, sizeof(args)); + bmp280_Logging->initStart(args[0]); + reply[0] = 0x80; + FormatReply(reply, sizeof(reply), replyStrs); + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/BMP280/BMP280_RPC.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _BMP280_RPC_H_ +#define _BMP280_RPC_H_ + +#include "mbed.h" + +/** +* @brief Read the identification of the s25fs512 using quad spi +* @param argStrs incoming rpc argument strings +* OUTPUT: +* replyStrs: strings that get returned to the rpc caller +* @return 0 if successful, -1 if error +*/ +int BMP280_InitStart(char argStrs[32][32], char replyStrs[32][32]); + +#endif /* _BMP280_RPC_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/HspLed/HspLed/HspLed.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,143 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include "HspLed.h" +#include "Peripherals.h" + +void hspled_int_handler(void); + +//******************************************************************************* +HspLed::HspLed(PinName ledPin) : + redLed(LED_RED, 0), isStarted(false), timerIntervalLast(-1), timerInterval(500) { +} + + +//******************************************************************************* +void HspLed::state(int state) { + redLed.write(state); +} + + +//******************************************************************************* +void HspLed::toggle(void) { + state(!redLed.read()); +} + + +//******************************************************************************* +void HspLed::setMode(eMode mode) { + this->mode = mode; +} + +//******************************************************************************* +void HspLed::blink(uint32_t mSeconds) { + mode = eLedPeriod; + this->timerInterval = (float)mSeconds / 1000.0f; + start(); +} + +//******************************************************************************* +void HspLed::pattern(uint32_t bitPattern, uint32_t mSeconds) { + mode = eLedPattern; + this->bitPattern = bitPattern; + this->timerInterval = (float)mSeconds / 1000.0f; + start(); +} + +//******************************************************************************* +void HspLed::on(void) { + mode = eLedOn; + state(HSP_LED_ON); + start(); +} + + +//******************************************************************************* +void HspLed::off(void) { + mode = eLedOff; + state(HSP_LED_OFF); + start(); +} + + +//******************************************************************************* +void HspLed::patternToLed(void) { + uint32_t bit; + bit = bitPattern & 1; + state(bit); + // rotate the pattern + bitPattern = bitPattern >> 1; + bitPattern = bitPattern | (bit << 31); +} + + +//******************************************************************************* +void HspLed::service(void) { + switch (mode) { + case eLedOn: + state(HSP_LED_ON); + break; + case eLedOff: + state(HSP_LED_OFF); + break; + case eLedPeriod: + toggle(); + break; + case eLedPattern: + patternToLed(); + break; + } +} + +//******************************************************************************* +void HspLed::start(void) { + if (timerInterval != timerIntervalLast && isStarted == true) { + stop(); + } + ticker.attach(&hspled_int_handler, timerInterval); + timerIntervalLast = timerInterval; + + isStarted = true; +} + +//******************************************************************************* +void HspLed::stop(void) { + ticker.detach(); + isStarted = false; +} + +//******************************************************************************* +void hspled_int_handler(void) { + HspLed *hspLed = Peripherals::hspLed(); + hspLed->service(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/HspLed/HspLed/HspLed.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,169 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _LED_H_ +#define _LED_H_ + +#include "mbed.h" + +/** + * Driver for the HSP Led, supports different blink rates and patterns + * + * @code + * #include <stdio.h> + * #include "mbed.h" + * #include "xxx.h" + * + * I2C i2c(I2C_SDA, I2C_SCL); + * xxx xxx(&i2c); + * + * int main(void) { + * printf("Initialized xxx\n"); + * while(1) { + * if (xxx.init() != 0) { + * printf("Error communicating with xxx\n"); + * } else { + * printf("Initialized xxx\n"); + * break; + * } + * wait(1); + * } + * + * while(1) { + * printf(""); + * wait(1); + * } + * } + * @endcode + */ + +class HspLed { +public: + static const int LED_ON = 0; + static const int LED_OFF = 1; + + /// define all of the modes the LED can support + typedef enum eMode { + eLedOn, + eLedOff, + eLedPeriod, + eLedPattern + } eMode; + /// define the values that turn the LED on or off at the pin + #define HSP_LED_ON 0 + #define HSP_LED_OFF 1 + + /* + * @brief Constructor where you specify the LED pin name + */ + HspLed(PinName ledPin); + + /** + * Blink the HSP LED at a set time interval + * @param mSeconds Number of seconds to set the timer interval + */ + void blink(uint32_t mSeconds); + + /** + * @brief Start rotating the LED through a 32-bit pattern at a mS rate specified + * @param pattern 32-bit pattern to rotate through + * @param mSeconds the amount of time to take per bit in the pattern + */ + void pattern(uint32_t pattern, uint32_t mSeconds); + + /** + * @brief Turn the LED on + */ + void on(void); + + /** + * @brief Turn the LED off + */ + void off(void); + + /** + * @brief Update the LED + */ + void service(void); + +private: + + /** + * Set the mode of the LED, the mode include blinking at a set rate or blinking + * according to a pattern + * @param mode Mode to set the LED to + */ + void setMode(eMode state); + + /** + * Toggle the state of the LED + */ + void toggle(void); + + /** + * Start the LED blinking or rotating through a pattern + */ + void start(void); + + /** + * Stop blinking or rotating through a pattern + */ + void stop(void); + + /** + * Write the LED pin to a state + * @param state A one or zero value to write to the LED pin + */ + void state(int state); + + /* + * @brief Single step through the pattern and output to the LED + */ + void patternToLed(void); + + /// timer interval in mS + float timerInterval; + /// last timer interval set to... used to prevent resetting the timer to the same value + float timerIntervalLast; + /// local state of the pattern to rotate through + uint32_t bitPattern; + /// current mode of the LED + eMode mode; + /// the LED digital output + DigitalOut redLed; + /// Timer service used to update the LED + Ticker ticker; + /// Flag to indicate if the timer has been started + bool isStarted; +}; + +#endif /* _LED_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/HspLed/HspLed_RPC.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include "HspLed_RPC.h" +#include "HspLed.h" +#include "StringHelper.h" +#include "Peripherals.h" + +int Led_On(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + Peripherals::hspLed()->on(); + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +int Led_Off(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + Peripherals::hspLed()->off(); + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +int Led_BlinkHz(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t args[1]; + uint32_t reply[1]; + ProcessArgs32(argStrs, args, sizeof(args) / sizeof(uint32_t)); + Peripherals::hspLed()->blink(args[0]); + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +int Led_BlinkPattern(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t args[2]; + uint32_t reply[1]; + ProcessArgs32(argStrs, args, sizeof(args) / sizeof(uint32_t)); + Peripherals::hspLed()->pattern(args[0], args[1]); + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/HspLed/HspLed_RPC.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _LED_RPC_H_ +#define _LED_RPC_H_ + +#include "mbed.h" + +int Led_On(char argStrs[32][32], char replyStrs[32][32]); +int Led_Off(char argStrs[32][32], char replyStrs[32][32]); +int Led_BlinkHz(char argStrs[32][32], char replyStrs[32][32]); +int Led_BlinkPattern(char argStrs[32][32], char replyStrs[32][32]); + +#endif /* _LED_RPC_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/LIS2DH/LIS2DH/LIS2DH.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,278 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include "LIS2DH.h" +#include "Streaming.h" +#include "Peripherals.h" + +void lis2dh_int_handler(void); +/** buffer array to hold fifo contents for packetizing +*/ +uint32_t lis2dh_buffer[LIS2DH_MAX_DATA_SIZE]; + +static int debug_int_count = 0; +int16_t motion_cached[3]; +LIS2DH *LIS2DH::instance = NULL; + +//****************************************************************************** +LIS2DH::LIS2DH(PinName sda, PinName scl, int slaveAddress) : + slaveAddress(slaveAddress) { + i2c = new I2C(sda, scl); + i2c->frequency(400000); + isOwner = true; + instance = this; +} + +//****************************************************************************** +LIS2DH::LIS2DH(I2C *i2c, int slaveAddress) : + slaveAddress(slaveAddress) { + this->i2c = i2c; + i2c->frequency(400000); + isOwner = false; + instance = this; +} + +//****************************************************************************** +LIS2DH::~LIS2DH(void) { + if (isOwner == true) { + delete i2c; + } +} + +//****************************************************************************** +int LIS2DH::writeReg(char reg, char value) { + int result; + char cmdData[2] = {(char)reg, value}; + result = i2c->write(slaveAddress, cmdData, 2); + if (result != 0) + return -1; + return 0; +} + +//****************************************************************************** +int LIS2DH::readReg(char reg, char *value) { + int result; + char cmdData[1] = {(char)reg}; + + result = i2c->write(slaveAddress, cmdData, 1); + if (result != 0) + return -1; + result = i2c->read(slaveAddress, value, 1); + if (result != 0) + return -1; + return 0; +} + +//****************************************************************************** +static void I2c_Reset(uint8_t index, int speed) { + mxc_i2cm_regs_t *regs = MXC_I2CM_GET_I2CM(index); + /* reset module */ + regs->ctrl = MXC_F_I2CM_CTRL_MSTR_RESET_EN; + regs->ctrl = 0; + /* enable tx_fifo and rx_fifo */ + regs->ctrl |= (MXC_F_I2CM_CTRL_TX_FIFO_EN | MXC_F_I2CM_CTRL_RX_FIFO_EN); +} + +//****************************************************************************** +// Interrupt handler, this empties the hardware fifo and packetizes it for +// streaming +void LIS2DH::int_handler(void) { + char fifo_src; + int16_t valueX; + int16_t valueY; + int16_t valueZ; + int num; + int index; + + I2c_Reset(2, 1); + num = 0; + index = 0; + fifo_src = 0; + while ((fifo_src & 0x20) != 0x20) { + get_motion_fifo(&valueX, &valueY, &valueZ); + lis2dh_buffer[index++] = valueX; + lis2dh_buffer[index++] = valueY; + lis2dh_buffer[index++] = valueZ; + readReg(LIS2DH_FIFO_SRC_REG, &fifo_src); + num++; + if (num >= 32) + break; + } + motion_cached[0] = valueX; + motion_cached[1] = valueY; + motion_cached[2] = valueZ; + + StreamPacketUint32(PACKET_LIS2DH, lis2dh_buffer, index); +} + +//****************************************************************************** +void LIS2DH::init(void) { + stop(); + configure_interrupt(); +} + +//****************************************************************************** +void LIS2DH::configure_interrupt(void) { + // interrupt enabled on INT1, interrupt active low + lis2dh_ctrl_reg6.all = 0; + lis2dh_ctrl_reg6.bit.I2_INT1 = 1; // interrupt 1 function enabled on int1 pin + lis2dh_ctrl_reg6.bit.H_LACTIVE = 1; // interrupt active low + writeReg(LIS2DH_CTRL_REG6, lis2dh_ctrl_reg6.all); +} + +//****************************************************************************** +int LIS2DH::initStart(int dataRate, int fifoThreshold) { + __disable_irq(); + + configure_interrupt(); + + // enable FIFO + lis2dh_ctrl_reg5.all = 0x0; + lis2dh_ctrl_reg5.bit.FIFO_EN = 0x1; + if (writeReg(LIS2DH_CTRL_REG5, lis2dh_ctrl_reg5.all) == -1) { + __enable_irq(); + return -1; + } + + // set FIFO to stream mode, trigger select INT1 + lis2dh_fifo_ctrl_reg.all = 0x0; + lis2dh_fifo_ctrl_reg.bit.FTH = fifoThreshold; + lis2dh_fifo_ctrl_reg.bit.FM = LIS2DH_FIFOMODE_STREAM; + lis2dh_fifo_ctrl_reg.bit.TR = 0x0; + if (writeReg(LIS2DH_FIFO_CTRL_REG, lis2dh_fifo_ctrl_reg.all) == -1) { + __enable_irq(); + return -1; + } + + // set HR (high resolution) + if (writeReg(LIS2DH_CTRL_REG4, 0x8) == -1) { + __enable_irq(); + return -1; + } + + // set the data rate, enable all axis + dataRate = dataRate & 0xF; + if (dataRate > 0x9) dataRate = 0x9; + lis2dh_ctrl_reg1.bit.ODR = dataRate; // set the data rate + lis2dh_ctrl_reg1.bit.LPen = 0x0; // disable low power mode + lis2dh_ctrl_reg1.bit.Zen = 0x1; // enable z + lis2dh_ctrl_reg1.bit.Yen = 0x1; // enable y + lis2dh_ctrl_reg1.bit.Xen = 0x1; // enable x + if (writeReg(LIS2DH_CTRL_REG1, lis2dh_ctrl_reg1.all) == -1) { + __enable_irq(); + return -1; + } + + // enable watermark interrupt + lis2dh_ctrl_reg3.all = 0x00; + lis2dh_ctrl_reg3.bit.I1_WTM = 0x1; + if (writeReg(LIS2DH_CTRL_REG3, lis2dh_ctrl_reg3.all) == -1) { + __enable_irq(); + return -1; + } + __enable_irq(); + + return 0; +} + +//****************************************************************************** +int LIS2DH::detect(char *detected) { + char val; + *detected = 0; + if (readReg(LIS2DH_WHO_AM_I, &val) == -1) + return -1; + if (val == LIS2DH_ID) *detected = 1; + return 0; +} + +//****************************************************************************** +int LIS2DH::get_motion_cached(int16_t *valueX, int16_t *valueY, + int16_t *valueZ) { + *valueX = motion_cached[0]; + *valueY = motion_cached[1]; + *valueZ = motion_cached[2]; + return 0; +} + +//****************************************************************************** +int LIS2DH::get_motion_fifo(int16_t *valueX, int16_t *valueY, int16_t *valueZ) { + char reg = LIS2DH_OUT_X_L | 0x80; + char values[6]; + int i; + + reg = LIS2DH_OUT_X_L; + for (i = 0; i < 6; i++) { + if (readReg(reg, &values[i]) != 0) { + return -1; + } + reg++; + } + + *valueX = ((short)values[1] << 8) + values[0]; + *valueY = ((short)values[3] << 8) + values[2]; + *valueZ = ((short)values[5] << 8) + values[4]; + motion_cached[0] = *valueX; + motion_cached[1] = *valueY; + motion_cached[2] = *valueZ; + return 0; +} + +//****************************************************************************** +// 0x33 = read ID +char LIS2DH::readId(void) { + char val; + readReg(LIS2DH_WHO_AM_I, &val); + return val; +} + +//****************************************************************************** +void LIS2DH::stop(void) { + __disable_irq(); + writeReg(LIS2DH_CTRL_REG3, 0x00); // Disable watermark interrupt + writeReg(LIS2DH_CTRL_REG1, 0x00); // Data rate = 0Hz + writeReg(LIS2DH_FIFO_CTRL_REG, + 0x00); // set to bypass mode... clears FIFO_SRC_REG + __enable_irq(); +} + +//****************************************************************************** +void LIS2DHIntHandler(void) { + char value; + // read the data rate axis enable register, if this is zero then just return, + // we are not ready for interrupts + LIS2DH::instance->readReg(LIS2DH_CTRL_REG1, &value); + if (value == 0x0) { + return; + } + LIS2DH::instance->int_handler(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/LIS2DH/LIS2DH/LIS2DH.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,462 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#ifndef LIS2DH_H_ +#define LIS2DH_H_ + +#include "mbed.h" + +/** + * Driver for the LIS2DH on the HSP Platform + * + * @code + * #include <stdio.h> + * #include "mbed.h" + * #include "xxx.h" + * + * I2C i2c(I2C_SDA, I2C_SCL); + * xxx xxx(&i2c); + * + * int main(void) { + * printf("Initialized xxx\n"); + * while(1) { + * if (xxx.init() != 0) { + * printf("Error communicating with xxx\n"); + * } else { + * printf("Initialized xxx\n"); + * break; + * } + * wait(1); + * } + * + * while(1) { + * printf(""); + * wait(1); + * } + * } + * @endcode + */ + +void LIS2DHIntHandler(void); + +#define LIS2DH_READID 0x33 + +/// @brief LIS2DH Register addresses +#define LIS2DH_STATUS_REG_AUX 0x07 +#define LIS2DH_OUT_TEMP_L 0x0C +#define LIS2DH_OUT_TEMP_H 0x0D +#define LIS2DH_INT_COUNTER_REG 0x0E +#define LIS2DH_WHO_AM_I 0x0F +#define LIS2DH_TEMP_CFG_REG 0x1F +#define LIS2DH_CTRL_REG1 0x20 +#define LIS2DH_CTRL_REG2 0x21 +#define LIS2DH_CTRL_REG3 0x22 +#define LIS2DH_CTRL_REG4 0x23 +#define LIS2DH_CTRL_REG5 0x24 +#define LIS2DH_CTRL_REG6 0x25 +#define LIS2DH_REFERENCE 0x26 +#define LIS2DH_STATUS_REG2 0x27 +#define LIS2DH_OUT_X_L 0x28 +#define LIS2DH_OUT_X_H 0x29 +#define LIS2DH_OUT_Y_L 0x2A +#define LIS2DH_OUT_Y_H 0x2B +#define LIS2DH_OUT_Z_L 0x2C +#define LIS2DH_OUT_Z_H 0x2D +#define LIS2DH_FIFO_CTRL_REG 0x2E +#define LIS2DH_FIFO_SRC_REG 0x2F +#define LIS2DH_INT1_CFG 0x30 +#define LIS2DH_INT1_SRC 0x31 +#define LIS2DH_INT1_THS 0x32 +#define LIS2DH_INT1_DURATION 0x33 +#define LIS2DH_INT2_CFG 0x34 +#define LIS2DH_INT2_SRC 0x35 +#define LIS2DH_INT2_THS 0x36 +#define LIS2DH_INT2_DURATION 0x37 +#define LIS2DH_CLICK_CFG 0x38 +#define LIS2DH_CLICK_SRC 0x39 +#define LIS2DH_CLICK_THS 0x3A +#define LIS2DH_TIME_LIMIT 0x3B +#define LIS2DH_TIME_LATENCY 0x3C +#define LIS2DH_TIME_WINDOW 0x3D +#define LIS2DH_Act_THS 0x3E +#define LIS2DH_Act_DUR 0x3F + +#define LIS2DH_DATARATE_1HZ 0x1 +#define LIS2DH_DATARATE_10HZ 0x2 +#define LIS2DH_DATARATE_25HZ 0x3 +#define LIS2DH_DATARATE_50HZ 0x4 +#define LIS2DH_DATARATE_100HZ 0x5 +#define LIS2DH_DATARATE_200HZ 0x6 +#define LIS2DH_DATARATE_400HZ 0x7 + +#define LIS2DH_FIFOMODE_BYPASS 0x00 +#define LIS2DH_FIFOMODE_FIFO 0x01 +#define LIS2DH_FIFOMODE_STREAM 0x02 +#define LIS2DH_FIFOMODE_TRIGGER 0x03 + +#define LIS2DH_ID 0x33 +#define LIS2DH_FIFO_SIZE 32 + +#define LISD2DH_FIFO_MODE_BYPASS 0 +#define LISD2DH_FIFO_MODE_FIFO 1 +#define LISD2DH_FIFO_MODE_STREAM 2 +#define LISD2DH_FIFO_MODE_TRIGGER 3 + +#define LIS2DH_NUMBER_OF_AXIS 3 +#define LIS2DH_MAX_DATA_SIZE (LIS2DH_NUMBER_OF_AXIS * LIS2DH_FIFO_SIZE) + +class LIS2DH { +public: + /// @brief STATUS_AUX (07h) + union lis2dh_status_aux_reg { + char all; + struct { + char reserved3 : 2; + char TDA : 1; + char reserved2 : 3; + char TOR : 1; + char reserved1 : 1; + } bit; + } lis2dh_status_aux; + + /// @brief OUT_TEMP_L (0Ch) + union lis2dh_out_temp_l_reg { + char all; + } lis2dh_out_temp_l; + + /// @brief OUT_TEMP_H (0Dh) + union lis2dh_out_temp_h_reg { + char all; + } lis2dh_out_temp_h; + + /// @brief INT_COUNTER (0Eh) + union lis2dh_int_counter_reg { + char all; + } lis2dh_int_counter; + + /// @brief WHO_AM_I (0Fh) + union lis2dh_who_am_i_reg { + char all; + } lis2dh_who_am_i; + + /// @brief TEMP_CFG_REG (1Fh) + union lis2dh_temp_cfg_reg { + char all; + struct { + char reserved1 : 6; + char TEMP_EN0 : 1; + char TEMP_EN1 : 1; + } bit; + } lis2dh_temp_cfg; + + /// @brief CTRL_REG1 (20h) + union lis2dh_ctrl_reg1_reg { + char all; + struct { + char Xen : 1; + char Yen : 1; + char Zen : 1; + char LPen : 1; + char ODR : 4; + } bit; + } lis2dh_ctrl_reg1; + + /// @brief CTRL_REG1 (21h) + union lis2dh_ctrl_reg2_reg { + char all; + struct { + char HPIS : 3; + char HPCLICK : 1; + char FDS : 1; + char HPCF : 2; + char HPM : 2; + } bit; + } lis2dh_ctrl_reg2; + + /// @brief CTRL_REG3 (22h) + union lis2dh_ctrl_reg3_reg { + char all; + struct { + char reserved : 1; + char I1_OVERRUN : 1; + char I1_WTM : 1; + char I1_DRDY : 2; + char I1_AOI : 1; + char I1_CLICK : 1; + } bit; + } lis2dh_ctrl_reg3; + + /// @brief CTRL_REG4 (23h) + union lis2dh_ctrl_reg4_reg { + char all; + struct { + char SIM : 1; + char ST : 2; + char HR : 1; + char FS : 2; + char BLE : 1; + char BDU : 1; + } bit; + } lis2dh_ctrl_reg4; + + /// @brief CTRL_REG5 (24h) + union lis2dh_ctrl_reg5_reg { + char all; + struct { + char D4D_INT2 : 1; + char LIR_INT2 : 1; + char D4D_INT1 : 1; + char LIR_INT1 : 1; + char reserved : 2; + char FIFO_EN : 1; + char BOOT : 1; + } bit; + } lis2dh_ctrl_reg5; + + /// @brief CTRL_REG6 (25h) + union lis2dh_ctrl_reg6_reg { + char all; + struct { + char reserved1 : 1; + char H_LACTIVE : 1; + char reserved2 : 1; + char P2_ACT : 1; + char BOOT_I2 : 1; + char I2_INT2 : 2; + char I2_INT1 : 1; + char I2_CLICKen: 1; + } bit; + } lis2dh_ctrl_reg6; + + /// @brief REFERENCE (26h) + union lis2dh_reference_reg { + char all; + } lis2dh_reference; + + /// @brief STATUS_REG (27h) + union lis2dh_status_reg_ { + char all; + struct { + char XDA : 1; + char YDA : 1; + char ZDA : 1; + char ZYXDA : 1; + char XOR : 1; + char YOR : 1; + char ZOR : 1; + char ZYXOR : 1; + } bit; + } lis2dh_status_reg; + + /// @brief OUT_X_L (28h) + union lis2dh_out_x_l_ { + char all; + } lis2dh_out_x_l; + + /// @brief OUT_X_H (29h) + union lis2dh_out_x_h_ { + char all; + } lis2dh_out_x_h; + + /// @brief OUT_Y_L (2Ah) + union lis2dh_out_y_l_ { + char all; + } lis2dh_out_y_l; + + /// @brief OUT_Y_H (2Bh) + union lis2dh_out_y_h_ { + char all; + } lis2dh_out_y_h; + + /// @brief OUT_Z_L (2Ch) + union lis2dh_out_z_l_ { + char all; + } lis2dh_out_z_l; + + /// @brief OUT_Z_H (2Dh) + union lis2dh_out_z_h_ { + char all; + } lis2dh_out_z_h; + + /// @brief FIFO_CTRL_REG (2Eh) + union lis2dh_fifo_ctrl_reg_ { + char all; + struct { + char FTH : 5; + char TR : 1; + char FM : 2; + } bit; + } lis2dh_fifo_ctrl_reg; + + /// @brief FIFO_CTRL_REG (2Fh) + union lis2dh_fifo_src_reg_ { + char all; + struct { + char FSS : 5; + char EMPTY : 1; + char OVRN_FIFO : 1; + char WTM : 1; + } bit; + } lis2dh_fifo_src_reg; + + /// @brief INT1_CFG (30h) + union lis2dh_int1_cfg_reg_ { + char all; + struct { + char XLIE_XDOWNE : 1; + char XHIE_XUPE : 1; + char YLIE_YDOWNE : 1; + char YHIE_YUPE : 1; + char ZLIE_ZDOWNE : 1; + char ZHIE_ZUPE : 1; + char SIXD : 1; + char AOI : 1; + } bit; + } lis2dh_int1_cfg; + + /// @brief INT1_SRC (31h) + union lis2dh_int1_src_reg_ { + char all; + struct { + char XL : 1; + char XH : 1; + char YL : 1; + char YH : 1; + char ZL : 1; + char ZH : 1; + char IA : 1; + char reserved : 1; + } bit; + } lis2dh_int1_src; + + /// @brief INT1_THS (32h) + union lis2dh_int1_ths_reg_ { + char all; + } lis2dh_int1_ths; + + /// @brief INT1_DURATION (33h) + union lis2dh_int1_duration_reg_ { + char all; + } lis2dh_int1_duration; + + /// @brief INT2_CFG (34h) + union lis2dh_int2_cfg_reg_ { + char all; + struct { + char XLIE : 1; + char XHIE : 1; + char YLIE : 1; + char YHIE : 1; + char ZLIE : 1; + char ZHIE : 1; + char SIX6 : 1; + char AOI : 1; + } bit; + } lis2dh_int2_cfg; + + /// @brief INT2_SRC (35h) + union lis2dh_int2_src_reg_ { + char all; + struct { + char XL : 1; + char XH : 1; + char YL : 1; + char YH : 1; + char ZL : 1; + char ZH : 1; + char IA : 1; + char reserved : 1; + } bit; + } lis2dh_int2_src; + + /// @brief INT2_THS (36h) + union lis2dh_int2_ths_reg_ { + char all; + } lis2dh_int2_ths; + + /// @brief INT2_DURATION (37h) + union lis2dh_int2_duration_reg_ { + char all; + } lis2dh_int2_duration; + + LIS2DH(PinName sda, PinName scl, int slaveAddress); + LIS2DH(I2C *i2c, int slaveAddress); + ~LIS2DH(void); + + /** @brief Initialize the device + */ + void init(void); + /** @brief Interrupt handler + */ + void int_handler(void); + /** @brief Get motion data from the device fifo + */ + int get_motion_fifo(short *valueX, short *valueY, short *valueZ); + /** @brief Get the last cached motion values (cached from a previous interrupt + * event) + */ + int get_motion_cached(int16_t *valueX, int16_t *valueY, int16_t *valueZ); + /** @brief Star Interrupts + */ + int initStart(int dataRate, int fifoThreshold); + /** @brief Stop interrupts + */ + void stop(void); + /** @brief Read device register + */ + int readReg(char reg, char *value); + /** @brief Write device regsiter + */ + int writeReg(char reg, char value); + /** @brief Detect if device exists + */ + int detect(char *detected); + /** @brief Read the device ID + */ + char readId(void); + + static LIS2DH *instance; + +private: + /** @brief + */ + void configure_interrupt(void); + /// I2C pointer + I2C *i2c; + /// Is this object the owner of the I2C object + bool isOwner; + /// Device slave address + int slaveAddress; +}; + +#endif /* LIS2DH_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/LIS2DH/LIS2DH_RPC.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include "mbed.h" +#include "LIS2DH.h" +#include "StringInOut.h" +#include "StringHelper.h" +#include "Peripherals.h" + +#define LIS2DH_SLAVE_ADDRESS 0x32 +#define LIS2DH_REG_PART_ID 0x0F + +//****************************************************************************** +int LIS2DH_ReadReg(char argStrs[32][32], char replyStrs[32][32]) { + uint8_t args[1]; + uint8_t reply[1]; + ProcessArgs(argStrs, args, sizeof(args)); + LIS2DH *lis2dh = Peripherals::lis2dh(); + lis2dh->readReg(args[0], (char *)reply); + FormatReply(reply, sizeof(reply), replyStrs); + return 0; +} + +//****************************************************************************** +int LIS2DH_WriteReg(char argStrs[32][32], char replyStrs[32][32]) { + uint8_t args[2]; + uint8_t reply[1]; + ProcessArgs(argStrs, args, sizeof(args)); + LIS2DH *lis2dh = Peripherals::lis2dh(); + lis2dh->writeReg(args[0], args[1]); // pass in the register address + reply[0] = 0x80; + FormatReply(reply, sizeof(reply), replyStrs); + return 0; +} + +extern int highDataRate; +//****************************************************************************** +int LIS2DH_InitStart(char argStrs[32][32], char replyStrs[32][32]) { + uint8_t args[2]; + uint8_t reply[1]; + ProcessArgs(argStrs, args, sizeof(args)); + LIS2DH *lis2dh = Peripherals::lis2dh(); + if (args[0] >= LIS2DH_DATARATE_200HZ) + highDataRate = 1; + lis2dh->initStart(args[0], args[1]); + reply[0] = 0x80; + FormatReply(reply, sizeof(reply), replyStrs); + return 0; +} + +//****************************************************************************** +int LIS2DH_Stop(char argStrs[32][32], char replyStrs[32][32]) { + uint8_t reply[1]; + LIS2DH *lis2dh = Peripherals::lis2dh(); + lis2dh->stop(); + reply[0] = 0x80; + FormatReply(reply, sizeof(reply), replyStrs); + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/LIS2DH/LIS2DH_RPC.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _LIS2HD_H_ +#define _LIS2HD_H_ + +#include "mbed.h" + +int LIS2DH_ReadReg(char argStrs[32][32], char replyStrs[32][32]); +int LIS2DH_WriteReg(char argStrs[32][32], char replyStrs[32][32]); +int LIS2DH_InitStart(char argStrs[32][32], char replyStrs[32][32]); +int LIS2DH_Stop(char argStrs[32][32], char replyStrs[32][32]); + +#endif /* _LIS2HD_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/MAX14720/MAX14720/MAX14720.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,198 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include "MAX14720.h" + +//****************************************************************************** +MAX14720::MAX14720(PinName sda, PinName scl, int slaveAddress) : + slaveAddress(slaveAddress) { + i2c = new I2C(sda, scl); + isOwner = true; + clkDivEn = false; + clkDivSet = 0; + boostISet = BOOST_ISET_100mA; + boostMillivolts = 3300; + boostEn = BOOST_DISABLED; + boostEMI = false; + boostInd = false; + boostHysOff = false; + boostPasDsc = false; + boostActDsc = false; + buckMd = BUCK_BURST; + buckFst = false; + buckISet = BUCK_ISET_300mA; + buckCfg = false; + buckInd = false; + buckHysOff = true; + buckMinOT = true; + buckInteg = true; + buckPasDsc = false; + buckActDsc = false; + buckFScl = false; +} +//****************************************************************************** +MAX14720::MAX14720(I2C *i2c, int slaveAddress) : slaveAddress(slaveAddress) { + this->i2c = i2c; + isOwner = false; + clkDivEn = false; + clkDivSet = 0; + boostISet = BOOST_ISET_100mA; + boostMillivolts = 3300; + boostEn = BOOST_DISABLED; + boostEMI = false; + boostInd = false; + boostHysOff = false; + boostPasDsc = false; + boostActDsc = false; + buckMd = BUCK_BURST; + buckFst = false; + buckISet = BUCK_ISET_300mA; + buckCfg = false; + buckInd = false; + buckHysOff = true; + buckMinOT = true; + buckInteg = true; + buckPasDsc = false; + buckActDsc = false; + buckFScl = false; +} +//****************************************************************************** +MAX14720::~MAX14720() { + if (isOwner == true) { + delete i2c; + } +} + +//****************************************************************************** +int MAX14720::boostSetMode(boostEn_t mode) { + int result; + char data; + boostEn = mode; + data = (boostEn << 3) | (boostEMI << 1) | (boostInd); + result = writeReg(REG_BOOST_CFG, data); + if (result == MAX14720_ERROR) return result; + return 0; +} + +//****************************************************************************** +int MAX14720::boostSetVoltage(int mV) { + int result; + char data; + if ((MAX14720_BOOST_MIN_MV <= mV) && (mV <= MAX14720_BOOST_MAX_MV)) { + boostMillivolts = mV; + data = (mV - MAX14720_BOOST_MIN_MV) / MAX14720_BOOST_STEP_MV; + } else { + return MAX14720_ERROR; + } + if (boostEn == BOOST_ENABLED) { + result = writeReg(REG_BOOST_CFG, 0x00); + } + if (result == MAX14720_ERROR) return result; + result = writeReg(REG_BOOST_VSET, data); + if (result == MAX14720_ERROR) return result; + if (boostEn == BOOST_ENABLED) { + data = (boostEn << 3) | (boostEMI << 1) | (boostInd); + result = writeReg(REG_BOOST_CFG, data); + } + if (result == MAX14720_ERROR) return result; + return 0; +} + +//****************************************************************************** +int MAX14720::init() { + int result; + char data; + data = (clkDivEn << 7) | (clkDivSet); + result = writeReg(REG_BOOST_CDIV, data); + if (result == MAX14720_ERROR) return result; + data = (boostISet); + result = writeReg(REG_BOOST_ISET, data); + if (result == MAX14720_ERROR)return result; + if ((MAX14720_BOOST_MIN_MV <= boostMillivolts) && + (boostMillivolts <= MAX14720_BOOST_MAX_MV)) { + data = (boostMillivolts - MAX14720_BOOST_MIN_MV) / MAX14720_BOOST_STEP_MV; + } else { + return MAX14720_ERROR; + } + result = writeReg(REG_BOOST_VSET, data); + if (result == MAX14720_ERROR) return result; + data = (buckMd << 1) | (buckFst); + result = writeReg(REG_BUCK_CFG, data); + if (result == MAX14720_ERROR) return result; + data = (boostHysOff << 7) | (boostPasDsc << 6) | (boostActDsc << 5) | + (buckPasDsc << 2) | (buckActDsc << 1) | (buckFScl); + result = writeReg(REG_BBB_EXTRA, data); + if (result == MAX14720_ERROR) return result; + // Write Boost Enable Register Last + data = (boostEn << 3) | (boostEMI << 1) | (boostInd); + result = writeReg(REG_BOOST_CFG, data); + if (result == MAX14720_ERROR) return result; + return 0; +} + +//****************************************************************************** +int MAX14720::monSet(monCfg_t monCfg) { + int result; + result = writeReg(REG_MON_CFG, monCfg); + if (result == MAX14720_ERROR) return result; + return 0; +} + +//****************************************************************************** +int MAX14720::shutdown() { + int result; + result = writeReg(REG_PWR_OFF, 0xB2); + if (result == MAX14720_ERROR) return result; + return 0; +} + +//****************************************************************************** +int MAX14720::writeReg(registers_t reg, char value) { + int result; + char cmdData[2] = {(char)reg, value}; + result = i2c->write(slaveAddress, cmdData, 2); + if (result != 0) return MAX14720_ERROR; + return MAX14720_NO_ERROR; +} + +//****************************************************************************** +int MAX14720::readReg(registers_t reg, char *value) { + int result; + char cmdData[1] = {(char)reg}; + + result = i2c->write(slaveAddress, cmdData, 1); + if (result != 0) return MAX14720_ERROR; + result = i2c->read(slaveAddress, value, 1); + if (result != 0) return MAX14720_ERROR; + return MAX14720_NO_ERROR; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/MAX14720/MAX14720/MAX14720.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,317 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#ifndef _MAX14720_H_ +#define _MAX14720_H_ + +#include "mbed.h" + +#define MAX14720_NO_ERROR 0 +#define MAX14720_ERROR -1 + +#define MAX14720_BOOST_MIN_MV 2500 +#define MAX14720_BOOST_MAX_MV 5000 +#define MAX14720_BOOST_STEP_MV 100 + +/** + * MAX14720 PMIC Driver + * + * @code + * #include "mbed.h" + * #include "MAX14720.h" + * + * // I2C Master 2 + * I2C i2c2(I2C2_SDA, I2C2_SCL); + * + * #define I2C_ADDR_PMIC (0x54) + * MAX14720 max14720(&i2c2,I2C_ADDR_PMIC); + * + * DigitalOut led(LED1); + * InterruptIn button(SW1); + * + * void turnOff() + * { + * max14720.shutdown(); + * } + * + * int main() + * { + * int result; + * button.fall(&turnOff); + * led = 0; + * max14720.boostEn = MAX14720::BOOST_ENABLED; + * result = max14720.init(); + * if (result == MAX14720_ERROR) printf("Error initializing MAX14720"); + * wait(1); + * while(1) { + * max14720.boostSetMode(MAX14720::BOOST_DISABLED); + * max14720.boostEn = MAX14720::BOOST_ENABLED; + * wait(0.5); + * max14720.boostSetVoltage(2500); + * wait(0.5); + * max14720.boostSetVoltage(5000); + * wait(0.5); + * } + * } + * @endcode + */ +class MAX14720 { + +public: + /** + *@brief Register Addresses + *@details Enumerated MAX14720 register addresses + */ + typedef enum { + REG_CHIP_ID = 0x00, ///< Chip ID + REG_CHIP_REV = 0x01, ///< Chip Revision + REG_BOOST_CDIV = 0x03, ///< Boost Clock Divider + REG_BOOST_ISET = 0x04, ///< Boost Peak Current + REG_BOOST_VSET = 0x05, ///< Boost Voltage Setting + REG_BOOST_CFG = 0x06, ///< Boost Configuration + REG_BUCK_VSET = 0x07, ///< Buck Voltage Setting + REG_BUCK_CFG = 0x08, ///< Buck Configuration + REG_BUCK_ISET = 0x09, ///< Buck Peak Current and Settings + REG_LDO_VSET = 0x0A, ///< LDO Voltage Setting + REG_LDO_CFG = 0x0B, ///< LDO Configuration + REG_SWITCH_CFG = 0x0C, ///< Switch Configuration + REG_BAT_TIME = 0x0D, ///< Battery Impedance Timing + REG_BAT_CFG = 0x0E, ///< Battery Impedance Configuration + REG_BAT_BCV = 0x0F, ///< Battery Cell Voltage + REG_BAT_OCV = 0x10, ///< Open Cell Voltage + REG_BAT_LCV = 0x11, ///< Loaded Cell Voltage + REG_MON_CFG = 0x19, ///< Monitor Multiplexer Configuration + REG_BOOT_CFG = 0x1A, ///< Boot Configuration + REG_PIN_STAT = 0x1B, ///< Pin Status + REG_BBB_EXTRA = 0x1C, ///< Buck/Buck-Boost Extra + REG_HANDSHK = 0x1D, ///< Power-On Handshake + REG_UVLO_CFG = 0x1E, ///< Under-Voltage Lock Out + REG_PWR_OFF = 0x1F, ///< Power Off Command + } registers_t; + + /** + *@brief Boost Peak Current Settings + *@details Enumerated peak current settings for boost regulator + */ + typedef enum { + BOOST_ISET_MIN, ///< Minimum On-Time + BOOST_ISET_50mA, ///< 50mA Peak Current + BOOST_ISET_100mA, ///< 100mA Peak Current + BOOST_ISET_150mA, ///< 150mA Peak Current + BOOST_ISET_200mA, ///< 200mA Peak Current + BOOST_ISET_250mA, ///< 250mA Peak Current + BOOST_ISET_300mA, ///< 300mA Peak Current + BOOST_ISET_350mA, ///< 350mA Peak Current + } boostISet_t; + + /** + *@brief Boost Enable Mode + *@details Enumerated enable modes for boost regulator + */ + typedef enum { + BOOST_DISABLED, ///< Boost Disabled + BOOST_ENABLED, ///< Boost Enabled + BOOST_EN_MPC, ///< Boost Enabled by MPC pin + } boostEn_t; + + /** + *@brief Buck Operating Modes + *@details Enumerated operating modes for buck regulator + */ + typedef enum { + BUCK_BURST, ///< Burst Mode Operation + BUCK_FPWM, ///< Forced PWM Operation + BUCK_MPC_FPWM, ///< MPC activated Forced PWM + } buckMd_t; + + /** + *@brief Buck Peak Current Settings + *@details Enumerated peak current settings for buck regulator + */ + typedef enum { + BUCK_ISET_50mA, ///< 50mA Peak Current + BUCK_ISET_100mA, ///< 100mA Peak Current + BUCK_ISET_150mA, ///< 150mA Peak Current + BUCK_ISET_200mA, ///< 200mA Peak Current + BUCK_ISET_250mA, ///< 250mA Peak Current + BUCK_ISET_300mA, ///< 300mA Peak Current + BUCK_ISET_350mA, ///< 350mA Peak Current + BUCK_ISET_400mA, ///< 400mA Peak Current + } buckISet_t; + + /** + *@brief Monitor Configurations + *@details Enumerated configuration modes for monitor multiplexer + */ + typedef enum { + MON_PULLDOWN = 0x00, ///< Pulled down by 100k Ohm + MON_HI_Z = 0x08, ///< High Impedance + MON_SWIN = 0x80, ///< SWIN Selected + MON_SWOUT = 0x81, ///< SWOUT Selected + MON_BIN = 0x82, ///< BIN Selected + MON_BOUT = 0x83, ///< BOUT Selected + MON_HVIN = 0x84, ///< HVIN Selected + MON_HVOUT = 0x85, ///< HVOUT Selected + MON_LIN = 0x86, ///< LIN Selected + MON_LOUT = 0x87, ///< LOUT Selected + } monCfg_t; + + /** + *@brief Under-Voltage Lock Out Input + *@details Enumerated input selection options for UVLO + */ + typedef enum { + LIN_UVLO, ///< LIN used to determine UVLO condition + BIN_UVLO, ///< BIN used to determine UVLO condition + } uvloIn_t; + + /** + * @brief MAX14720 constructor. + * + * @param sda mbed pin to use for SDA line of I2C interface. + * @param scl mbed pin to use for SCL line of I2C interface. + * @param slaveAddress Slave Address of the device. + */ + MAX14720(PinName sda, PinName scl, int slaveAddress); + + /** + * @brief MAX14720 constructor. + * + * @param i2c I2C object to use. + * @param slaveAddress Slave Address of the device. + */ + MAX14720(I2C *i2c, int slaveAddress); + + /** + * @brief MAX14720 destructor. + */ + ~MAX14720(); + + /** + * @brief Initialize MAX14720 + * @details Applies settings to MAX14720. + * Settings are stored in public variables. + * The variables are pre-loaded with the most common configuation. + * Assign new values to the public variables before calling init. + * @returns 0 if no errors, -1 if error. + */ + int init(); + + /** + * @brief Set the Boost Voltage + * @details Sets the voltage for the boost regulator. + * The voltage is specified in millivoltst. + * The MAX14720 cannot update the voltage when enabled. + * This function checks the local boostEn variable and if the + * regualtor is enabled it will send the disable command before + * sending the new voltage and re-enable the boost regulator after + * the new voltage is written. + * @param mV voltage for boost regualtor in millivolts + * @returns 0 if no errors, -1 if error. + */ + int boostSetVoltage(int mV); + + /** + * @brief Set Boost Enable Mode + * @details Sets the enable mode for the boost regulator + * @param mode The enable mode for the boost regulator + * @returns 0 if no errors, -1 if error. + */ + int boostSetMode(boostEn_t mode); + + /** + * @brief Configure Mon Pin + * @details Configures the operating mode of the monitor multiplexer + * @param monCfg The configuration mode for the monitor pin + * @returns 0 if no errors, -1 if error. + */ + int monSet(monCfg_t monCfg); + + /** + * @brief Shutdown + * @details Sends the command to turn off all supplies and put the part + * in battery saving shelf mode. + * @returns 0 if no errors, -1 if error. + */ + int shutdown(); + + /** + * @brief Write Register + * @details Writes the given value to the specified register + * @param reg The register to be written + * @param value The data to be written + * @returns 0 if no errors, -1 if error. + */ + int writeReg(registers_t reg, char value); + + /** + * @brief Read Register + * @details Reads from the specified register + * @param reg The register to be read + * @param value Pointer for where to store the data + * @returns 0 if no errors, -1 if error. + */ + int readReg(registers_t reg, char *value); + + bool clkDivEn; /// Boost Clock Divider Enable + int clkDivSet; /// Boost Clock Divider Setting + boostISet_t boostISet; /// Boost Peak Current Setting + int boostMillivolts; /// Boost Voltage in millivolts + boostEn_t boostEn; /// Boost Enable Mode + bool boostEMI, /// Boost EMI Setting + boostInd, /// Boost Inductor Setting + boostHysOff, /// Boost Hysteresis Off + boostPasDsc, /// Boost Passive Discharge + boostActDsc; /// Boost Active Discharge + buckMd_t buckMd; /// Buck Operating Mode + bool buckFst; /// Buck Fast Start + buckISet_t buckISet; /// Buck Peak Current Setting + bool buckCfg, /// Buck Configuration (Set to 1 when using FPWM mode) + buckInd, /// Buck Inductor Setting + buckHysOff, /// Buck Hysteresis Off + buckMinOT, /// Buck Minimum On Time + buckInteg, /// Buck Integrate + buckPasDsc, /// Buck Passive Discharge + buckActDsc, /// Buck Active Discharge + buckFScl; /// Buck Fet Scaling + +private: + /// I2C pointer + I2C *i2c; + /// Is this object the owner of the I2C object + bool isOwner; + /// Device slave address + int slaveAddress; +}; + +#endif /* _MAX14720_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/MAX14720/MAX14720_RPC.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include "MAX14720_RPC.h" +#include "MAX14720.h" +#include "StringHelper.h" +#include "Peripherals.h" +#include "Device_Logging.h" + +/** +* @brief Read the identification of the s25fs512 using quad spi +* @param argStrs incoming rpc argument strings +* OUTPUT: +* replyStrs: strings that get returned to the rpc caller +* @return 0 if successful, -1 if error +*/ +int MAX14720_ReadBoostVSet(char argStrs[32][32], char replyStrs[32][32]) { + uint8_t args[1]; + uint8_t reply[1]; + //MAX14720::BoostVSet_Values value; + + ProcessArgs(argStrs, args, sizeof(args)); + //Peripherals::max14720()->readBoostVSet(&value); + //reply[0] = (char)value; + FormatReply(reply, sizeof(reply), replyStrs); + return 0; +} + +/** +* @brief Read the identification of the s25fs512 using quad spi +* @param argStrs incoming rpc argument strings +* OUTPUT: +* replyStrs: strings that get returned to the rpc caller +* @return 0 if successful, -1 if error +*/ +int MAX14720_WriteBoostVSet(char argStrs[32][32], char replyStrs[32][32]) { + uint8_t args[1]; + uint8_t reply[1]; + + ProcessArgs(argStrs, args, sizeof(args)); + // Peripherals::max14720()->boostEn(MAX14720::BoostEn_Disable); + // Peripherals::max14720()->boostVSet((MAX14720::BoostVSet_Values)args[0]); + // Peripherals::max14720()->boostEn(MAX14720::BoostEn_Enable); + reply[0] = 0x80; + FormatReply(reply, sizeof(reply), replyStrs); + return 0; +} + +/** +* @brief Read the identification of the s25fs512 using quad spi +* @param argStrs incoming rpc argument strings +* OUTPUT: +* replyStrs: strings that get returned to the rpc caller +* @return 0 if successful, -1 if error +*/ +int MAX14720_ReadReg(char argStrs[32][32], char replyStrs[32][32]) { + uint8_t args[1]; + uint8_t reply[1]; + char address; + char value; + + ProcessArgs(argStrs, args, sizeof(args)); + // Peripherals::max14720()->readReg((MAX14720::MAX14720_REG_map_t)address,&value); + reply[0] = (char)value; + FormatReply(reply, sizeof(reply), replyStrs); + return 0; +} + +/** +* @brief Read the identification of the s25fs512 using quad spi +* @param argStrs incoming rpc argument strings +* OUTPUT: +* replyStrs: strings that get returned to the rpc caller +* @return 0 if successful, -1 if error +*/ +int MAX14720_WriteReg(char argStrs[32][32], char replyStrs[32][32]) { + uint8_t args[2]; + uint8_t reply[1]; + + ProcessArgs(argStrs, args, sizeof(args)); + // Peripherals::max14720()->writeReg((MAX14720::MAX14720_REG_map_t)args[0],args[1]); + reply[0] = 0x80; + FormatReply(reply, sizeof(reply), replyStrs); + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/MAX14720/MAX14720_RPC.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _MAX14720_RPC_H_ +#define _MAX14720_RPC_H_ + +#include "mbed.h" + +int MAX14720_ReadBoostVSet(char argStrs[32][32], char replyStrs[32][32]); +int MAX14720_WriteBoostVSet(char argStrs[32][32], char replyStrs[32][32]); +int MAX14720_ReadReg(char argStrs[32][32], char replyStrs[32][32]); +int MAX14720_WriteReg(char argStrs[32][32], char replyStrs[32][32]); + +#endif /* _MAX14720_RPC_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/MAX30001/MAX30001/MAX30001.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,1317 @@ + +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include "mbed.h" +#include "MAX30001.h" + +MAX30001 *MAX30001::instance = NULL; + +//****************************************************************************** +MAX30001::MAX30001(PinName mosi, PinName miso, PinName sclk, PinName cs) { + spi = new SPI(mosi, miso, sclk, cs); + spi->frequency(3000000); + spi_owner = true; + functionpointer.attach(&spiHandler); + onDataAvailableCallback = NULL; + instance = this; +} + +//****************************************************************************** +MAX30001::MAX30001(SPI *_spi) { + spi = _spi; + spi->frequency(3000000); + spi_owner = false; + functionpointer.attach(&spiHandler); + onDataAvailableCallback = NULL; + instance = this; +} + +//****************************************************************************** +MAX30001::~MAX30001(void) { + if (spi_owner) { + delete spi; + } +} + +//****************************************************************************** +int MAX30001::max30001_Rbias_FMSTR_Init(uint8_t En_rbias, uint8_t Rbiasv, + uint8_t Rbiasp, uint8_t Rbiasn, + uint8_t Fmstr) { + if (max30001_reg_read(CNFG_GEN, &max30001_cnfg_gen.all) == -1) { + return -1; + } + + max30001_cnfg_gen.bit.en_rbias = En_rbias; + max30001_cnfg_gen.bit.rbiasv = Rbiasv; + max30001_cnfg_gen.bit.rbiasp = Rbiasp; + max30001_cnfg_gen.bit.rbiasn = Rbiasn; + max30001_cnfg_gen.bit.fmstr = Fmstr; + + if (max30001_reg_write(CNFG_GEN, max30001_cnfg_gen.all) == -1) { + return -1; + } + return 0; +} + +//****************************************************************************** +int MAX30001::max30001_CAL_InitStart(uint8_t En_Vcal, uint8_t Vmode, + uint8_t Vmag, uint8_t Fcal, uint16_t Thigh, + uint8_t Fifty) { + // CNFG_CAL + if (max30001_reg_read(CNFG_CAL, &max30001_cnfg_cal.all) == -1) { + return -1; + } + + max30001_cnfg_cal.bit.vmode = Vmode; + max30001_cnfg_cal.bit.vmag = Vmag; + max30001_cnfg_cal.bit.fcal = Fcal; + max30001_cnfg_cal.bit.thigh = Thigh; + max30001_cnfg_cal.bit.fifty = Fifty; + + if (max30001_reg_write(CNFG_CAL, max30001_cnfg_cal.all) == -1) { + return -1; + } + + // RTOS uses a 32768HZ clock. 32768ticks represents 1secs. 1sec/10 = + // 100msecs. + wait(1.0 / 10.0); + + if (max30001_reg_read(CNFG_CAL, &max30001_cnfg_cal.all) == -1) { + return -1; + } + + max30001_cnfg_cal.bit.en_vcal = En_Vcal; + + if (max30001_reg_write(CNFG_CAL, max30001_cnfg_cal.all) == -1) { + return -1; + } + + // RTOS uses a 32768HZ clock. 32768ticks represents 1secs. 1sec/10 = + // 100msecs. + wait(1.0 / 10.0); + + return 0; +} + +//****************************************************************************** +int MAX30001::max30001_CAL_Stop(void) { + + if (max30001_reg_read(CNFG_CAL, &max30001_cnfg_cal.all) == -1) { + return -1; + } + + max30001_cnfg_cal.bit.en_vcal = 0; // Disable VCAL, all other settings are left unaffected + + if (max30001_reg_write(CNFG_CAL, max30001_cnfg_cal.all) == -1) { + return -1; + } + + return 0; +} +//****************************************************************************** +//****************************************************************************** +int MAX30001::max30001_INT_assignment(max30001_intrpt_Location_t en_enint_loc, max30001_intrpt_Location_t en_eovf_loc, max30001_intrpt_Location_t en_fstint_loc, + max30001_intrpt_Location_t en_dcloffint_loc, max30001_intrpt_Location_t en_bint_loc, max30001_intrpt_Location_t en_bovf_loc, + max30001_intrpt_Location_t en_bover_loc, max30001_intrpt_Location_t en_bundr_loc, max30001_intrpt_Location_t en_bcgmon_loc, + max30001_intrpt_Location_t en_pint_loc, max30001_intrpt_Location_t en_povf_loc, max30001_intrpt_Location_t en_pedge_loc, + max30001_intrpt_Location_t en_lonint_loc, max30001_intrpt_Location_t en_rrint_loc, max30001_intrpt_Location_t en_samp_loc, + max30001_intrpt_type_t intb_Type, max30001_intrpt_type_t int2b_Type) + + +{ + // INT1 + + if (max30001_reg_read(EN_INT, &max30001_en_int.all) == -1) { + return -1; + } + + // max30001_en_int2.bit.en_pint = 0b1; // Keep this off... + + max30001_en_int.bit.en_eint = 0b1 & en_enint_loc; + max30001_en_int.bit.en_eovf = 0b1 & en_eovf_loc; + max30001_en_int.bit.en_fstint = 0b1 & en_fstint_loc; + + max30001_en_int.bit.en_dcloffint = 0b1 & en_dcloffint_loc; + max30001_en_int.bit.en_bint = 0b1 & en_bint_loc; + max30001_en_int.bit.en_bovf = 0b1 & en_bovf_loc; + + max30001_en_int.bit.en_bover = 0b1 & en_bover_loc; + max30001_en_int.bit.en_bundr = 0b1 & en_bundr_loc; + max30001_en_int.bit.en_bcgmon = 0b1 & en_bcgmon_loc; + + max30001_en_int.bit.en_pint = 0b1 & en_pint_loc; + max30001_en_int.bit.en_povf = 0b1 & en_povf_loc; + max30001_en_int.bit.en_pedge = 0b1 & en_pedge_loc; + + max30001_en_int.bit.en_lonint = 0b1 & en_lonint_loc; + max30001_en_int.bit.en_rrint = 0b1 & en_rrint_loc; + max30001_en_int.bit.en_samp = 0b1 & en_samp_loc; + + max30001_en_int.bit.intb_type = int2b_Type; + + if (max30001_reg_write(EN_INT, max30001_en_int.all) == -1) { + return -1; + } + + // INT2 + + if (max30001_reg_read(EN_INT2, &max30001_en_int2.all) == -1) { + return -1; + } + + max30001_en_int2.bit.en_eint = 0b1 & (en_enint_loc >> 1); + max30001_en_int2.bit.en_eovf = 0b1 & (en_eovf_loc >> 1); + max30001_en_int2.bit.en_fstint = 0b1 & (en_fstint_loc >> 1); + + max30001_en_int2.bit.en_dcloffint = 0b1 & (en_dcloffint_loc >> 1); + max30001_en_int2.bit.en_bint = 0b1 & (en_bint_loc >> 1); + max30001_en_int2.bit.en_bovf = 0b1 & (en_bovf_loc >> 1); + + max30001_en_int2.bit.en_bover = 0b1 & (en_bover_loc >> 1); + max30001_en_int2.bit.en_bundr = 0b1 & (en_bundr_loc >> 1); + max30001_en_int2.bit.en_bcgmon = 0b1 & (en_bcgmon_loc >> 1); + + max30001_en_int2.bit.en_pint = 0b1 & (en_pint_loc >> 1); + max30001_en_int2.bit.en_povf = 0b1 & (en_povf_loc >> 1); + max30001_en_int2.bit.en_pedge = 0b1 & (en_pedge_loc >> 1); + + max30001_en_int2.bit.en_lonint = 0b1 & (en_lonint_loc >> 1); + max30001_en_int2.bit.en_rrint = 0b1 & (en_rrint_loc >> 1); + max30001_en_int2.bit.en_samp = 0b1 & (en_samp_loc >> 1); + + max30001_en_int2.bit.intb_type = intb_Type; + + if (max30001_reg_write(EN_INT2, max30001_en_int2.all) == -1) { + return -1; + } + + return 0; +} + +//****************************************************************************** +int MAX30001::max30001_ECG_InitStart(uint8_t En_ecg, uint8_t Openp, + uint8_t Openn, uint8_t Pol, + uint8_t Calp_sel, uint8_t Caln_sel, + uint8_t E_fit, uint8_t Rate, uint8_t Gain, + uint8_t Dhpf, uint8_t Dlpf) { + + // CNFG_EMUX + + if (max30001_reg_read(CNFG_EMUX, &max30001_cnfg_emux.all) == -1) { + return -1; + } + + max30001_cnfg_emux.bit.openp = Openp; + max30001_cnfg_emux.bit.openn = Openn; + max30001_cnfg_emux.bit.pol = Pol; + max30001_cnfg_emux.bit.calp_sel = Calp_sel; + max30001_cnfg_emux.bit.caln_sel = Caln_sel; + + if (max30001_reg_write(CNFG_EMUX, max30001_cnfg_emux.all) == -1) { + return -1; + } + + /**** ENABLE CHANNELS ****/ + // CNFG_GEN + + if (max30001_reg_read(CNFG_GEN, &max30001_cnfg_gen.all) == -1) { + return -1; + } + + max30001_cnfg_gen.bit.en_ecg = En_ecg; // 0b1 + + // fmstr is default + + if (max30001_reg_write(CNFG_GEN, max30001_cnfg_gen.all) == -1) { + return -1; + } + + /**** Wait for PLL Lock & References to settle down ****/ + + max30001_timeout = 0; + + do { + if (max30001_reg_read(STATUS, &max30001_status.all) == -1) // Wait and spin for PLL to lock... + { + return -1; + } + } while (max30001_status.bit.pllint == 1 && max30001_timeout++ <= 1000); + + // MNGR_INT + + if (max30001_reg_read(MNGR_INT, &max30001_mngr_int.all) == -1) { + return -1; + } + + max30001_mngr_int.bit.e_fit = E_fit; // 31 + + if (max30001_reg_write(MNGR_INT, max30001_mngr_int.all) == -1) { + return -1; + } + + // CNFG_ECG + + if (max30001_reg_read(CNFG_ECG, &max30001_cnfg_ecg.all) == -1) { + return -1; + } + + max30001_cnfg_ecg.bit.rate = Rate; + max30001_cnfg_ecg.bit.gain = Gain; + max30001_cnfg_ecg.bit.dhpf = Dhpf; + max30001_cnfg_ecg.bit.dlpf = Dlpf; + + if (max30001_reg_write(CNFG_ECG, max30001_cnfg_ecg.all) == -1) { + return -1; + } + + return 0; +} + +//****************************************************************************** +int MAX30001::max30001_ECGFast_Init(uint8_t Clr_Fast, uint8_t Fast, uint8_t Fast_Th) { + if (max30001_reg_read(MNGR_INT, &max30001_mngr_int.all) == -1) { + return -1; + } + + max30001_mngr_int.bit.clr_fast = Clr_Fast; + + if (max30001_reg_write(MNGR_INT, max30001_mngr_int.all) == -1) { + return -1; + } + + if (max30001_reg_read(MNGR_DYN, &max30001_mngr_dyn.all) == -1) { + return -1; + } + + max30001_mngr_dyn.bit.fast = Fast; + max30001_mngr_dyn.bit.fast_th = Fast_Th; + + if (max30001_reg_write(MNGR_INT, max30001_mngr_int.all) == -1) { + return -1; + } + + return 0; +} + +//****************************************************************************** +int MAX30001::max30001_Stop_ECG(void) { + + if (max30001_reg_read(CNFG_GEN, &max30001_cnfg_gen.all) == -1) { + return -1; + } + + max30001_cnfg_gen.bit.en_ecg = 0; // Stop ECG + + // fmstr is default + + if (max30001_reg_write(CNFG_GEN, max30001_cnfg_gen.all) == -1) { + return -1; + } + + return 0; +} + +//****************************************************************************** +int MAX30001::max30001_PACE_InitStart(uint8_t En_pace, uint8_t Clr_pedge, + uint8_t Pol, uint8_t Gn_diff_off, + uint8_t Gain, uint8_t Aout_lbw, + uint8_t Aout, uint8_t Dacp, + uint8_t Dacn) { + + /**** SET MASTER FREQUENCY, ENABLE CHANNELS ****/ + + // CNFG_GEN + + if (max30001_reg_read(CNFG_GEN, &max30001_cnfg_gen.all) == -1) { + return -1; + } + + max30001_cnfg_gen.bit.en_pace = En_pace; // 0b1; + + if (max30001_reg_write(CNFG_GEN, max30001_cnfg_gen.all) == -1) { + return -1; + } + + /**** Wait for PLL Lock & References to settle down ****/ + max30001_timeout = 0; + + do { + if (max30001_reg_read(STATUS, &max30001_status.all) == + -1) // Wait and spin for PLL to lock... + { + return -1; + } + + } while (max30001_status.bit.pllint == 1 && max30001_timeout++ <= 1000); + + // MNGR_INT + + if (max30001_reg_read(MNGR_INT, &max30001_mngr_int.all) == -1) { + return -1; + } + + max30001_mngr_int.bit.clr_pedge = Clr_pedge; // 0b0; + + if (max30001_reg_write(MNGR_INT, max30001_mngr_int.all) == -1) { + return -1; + } + + /* Put: CNFG_PACE */ + + max30001_reg_read(CNFG_PACE, &max30001_cnfg_pace.all); + + max30001_cnfg_pace.bit.pol = Pol; + max30001_cnfg_pace.bit.gn_diff_off = Gn_diff_off; + max30001_cnfg_pace.bit.gain = Gain; + max30001_cnfg_pace.bit.aout_lbw = Aout_lbw; + max30001_cnfg_pace.bit.aout = Aout; + max30001_cnfg_pace.bit.dacp = Dacp; + max30001_cnfg_pace.bit.dacn = Dacn; + + max30001_reg_write(CNFG_PACE, max30001_cnfg_pace.all); + + return 0; +} +//****************************************************************************** +int MAX30001::max30001_Stop_PACE(void) { + + if (max30001_reg_read(CNFG_GEN, &max30001_cnfg_gen.all) == -1) { + return -1; + } + + max30001_cnfg_gen.bit.en_pace = 0; // Stop PACE + + if (max30001_reg_write(CNFG_GEN, max30001_cnfg_gen.all) == -1) { + return -1; + } + + return 0; +} + +//****************************************************************************** +int MAX30001::max30001_BIOZ_InitStart( + uint8_t En_bioz, uint8_t Openp, uint8_t Openn, uint8_t Calp_sel, + uint8_t Caln_sel, uint8_t CG_mode, uint8_t B_fit, uint8_t Rate, + uint8_t Ahpf, uint8_t Ext_rbias, uint8_t Gain, uint8_t Dhpf, uint8_t Dlpf, + uint8_t Fcgen, uint8_t Cgmon, uint8_t Cgmag, uint8_t Phoff) { + + // CNFG_BMUX + + if (max30001_reg_read(CNFG_BMUX, &max30001_cnfg_bmux.all) == -1) { + return -1; + } + + max30001_cnfg_bmux.bit.openp = Openp; // 0b1; + max30001_cnfg_bmux.bit.openn = Openn; // 0b1; + max30001_cnfg_bmux.bit.calp_sel = Calp_sel; // 0b10; + max30001_cnfg_bmux.bit.caln_sel = Caln_sel; // 0b11; + max30001_cnfg_bmux.bit.cg_mode = CG_mode; // 0b00; + + if (max30001_reg_write(CNFG_BMUX, max30001_cnfg_bmux.all) == -1) { + return -1; + } + + /**** SET MASTER FREQUENCY, ENABLE CHANNELS ****/ + + // CNFG_GEN + + if (max30001_reg_read(CNFG_GEN, &max30001_cnfg_gen.all) == -1) { + return -1; + } + + max30001_cnfg_gen.bit.en_bioz = En_bioz; + + // fmstr is default + + if (max30001_reg_write(CNFG_GEN, max30001_cnfg_gen.all) == -1) { + return -1; + } + + /**** Wait for PLL Lock & References to settle down ****/ + + max30001_timeout = 0; + + do { + if (max30001_reg_read(STATUS, &max30001_status.all) == + -1) // Wait and spin for PLL to lock... + { + return -1; + } + + } while (max30001_status.bit.pllint == 1 && max30001_timeout++ <= 1000); + + /**** Start of CNFG_BIOZ ****/ + + // MNGR_INT + + if (max30001_reg_read(MNGR_INT, &max30001_mngr_int.all) == -1) { + return -1; + } + + max30001_mngr_int.bit.b_fit = B_fit; //; + + if (max30001_reg_write(MNGR_INT, max30001_mngr_int.all) == -1) { + return -1; + } + + // CNFG_BIOZ + + if (max30001_reg_read(CNFG_BIOZ, &max30001_cnfg_bioz.all) == -1) { + return -1; + } + + max30001_cnfg_bioz.bit.rate = Rate; + max30001_cnfg_bioz.bit.ahpf = Ahpf; + max30001_cnfg_bioz.bit.ext_rbias = Ext_rbias; + max30001_cnfg_bioz.bit.gain = Gain; + max30001_cnfg_bioz.bit.dhpf = Dhpf; + max30001_cnfg_bioz.bit.dlpf = Dlpf; + max30001_cnfg_bioz.bit.fcgen = Fcgen; + max30001_cnfg_bioz.bit.cgmon = Cgmon; + max30001_cnfg_bioz.bit.cgmag = Cgmag; + max30001_cnfg_bioz.bit.phoff = Phoff; + + if (max30001_reg_write(CNFG_BIOZ, max30001_cnfg_bioz.all) == -1) { + return -1; + } + + return 0; +} + +//****************************************************************************** +int MAX30001::max30001_Stop_BIOZ(void) { + + if (max30001_reg_read(CNFG_GEN, &max30001_cnfg_gen.all) == -1) { + return -1; + } + + max30001_cnfg_gen.bit.en_bioz = 0; // Stop BIOZ + + if (max30001_reg_write(CNFG_GEN, max30001_cnfg_gen.all) == -1) { + return -1; + } + + return 0; +} + +//****************************************************************************** +int MAX30001::max30001_BIOZ_InitBist(uint8_t En_bist, uint8_t Rnom, + uint8_t Rmod, uint8_t Fbist) { + + // CNFG_BMUX + + if (max30001_reg_read(CNFG_BMUX, &max30001_cnfg_bmux.all) == -1) { + return -1; + } + + max30001_cnfg_bmux.bit.en_bist = En_bist; + max30001_cnfg_bmux.bit.rnom = Rnom; + max30001_cnfg_bmux.bit.rmod = Rmod; + max30001_cnfg_bmux.bit.fbist = Fbist; + + if (max30001_reg_write(CNFG_BMUX, max30001_cnfg_bmux.all) == -1) { + return -1; + } + + return 0; +} +//****************************************************************************** +int MAX30001::max30001_RtoR_InitStart(uint8_t En_rtor, uint8_t Wndw, + uint8_t Gain, uint8_t Pavg, uint8_t Ptsf, + uint8_t Hoff, uint8_t Ravg, uint8_t Rhsf, + uint8_t Clr_rrint) { + + // MNGR_INT + + if (max30001_reg_read(MNGR_INT, &max30001_mngr_int.all) == -1) { + return -1; + } + + max30001_mngr_int.bit.clr_rrint = + Clr_rrint; // 0b01 & 0b00 are for interrupt mode... + // 0b10 is for monitoring mode... it just overwrites the data... + + if (max30001_reg_write(MNGR_INT, max30001_mngr_int.all) == -1) { + return -1; + } + + // RTOR1 + if (max30001_reg_read(CNFG_RTOR1, &max30001_cnfg_rtor1.all) == -1) { + return -1; + } + + max30001_cnfg_rtor1.bit.wndw = Wndw; + max30001_cnfg_rtor1.bit.gain = Gain; + max30001_cnfg_rtor1.bit.en_rtor = En_rtor; + max30001_cnfg_rtor1.bit.pavg = Pavg; + max30001_cnfg_rtor1.bit.ptsf = Ptsf; + + if (max30001_reg_write(CNFG_RTOR1, max30001_cnfg_rtor1.all) == -1) { + return -1; + } + // RTOR2 + + if (max30001_reg_read(CNFG_RTOR2, &max30001_cnfg_rtor2.all) == -1) { + return -1; + } + max30001_cnfg_rtor2.bit.hoff = Hoff; + max30001_cnfg_rtor2.bit.ravg = Ravg; + max30001_cnfg_rtor2.bit.rhsf = Rhsf; + + if (max30001_reg_write(CNFG_RTOR2, max30001_cnfg_rtor2.all) == -1) { + return -1; + } + + return 0; +} + +//****************************************************************************** +int MAX30001::max30001_Stop_RtoR(void) { + + if (max30001_reg_read(CNFG_RTOR1, &max30001_cnfg_rtor1.all) == -1) { + return -1; + } + + max30001_cnfg_rtor1.bit.en_rtor = 0; // Stop RtoR + + if (max30001_reg_write(CNFG_RTOR1, max30001_cnfg_rtor1.all) == -1) { + return -1; + } + + return 0; +} + +//****************************************************************************** +int MAX30001::max30001_PLL_lock(void) { + // Spin to see PLLint become zero to indicate a lock. + + max30001_timeout = 0; + + do { + if (max30001_reg_read(STATUS, &max30001_status.all) == + -1) // Wait and spin for PLL to lock... + { + return -1; + } + + } while (max30001_status.bit.pllint == 1 && max30001_timeout++ <= 1000); + + return 0; +} + +//****************************************************************************** +int MAX30001::max30001_sw_rst(void) { + // SW reset for the MAX30001 chip + + if (max30001_reg_write(SW_RST, 0x000000) == -1) { + return -1; + } + + return 0; +} + +//****************************************************************************** +int MAX30001::max30001_synch(void) { // For synchronization + if (max30001_reg_write(SYNCH, 0x000000) == -1) { + return -1; + } + return 0; +} + +//****************************************************************************** +int MAX30001::max300001_fifo_rst(void) { // Resets the FIFO + if (max30001_reg_write(FIFO_RST, 0x000000) == -1) { + return -1; + } + return 0; +} + +//****************************************************************************** +// int MAX30001::max30001_reg_write(uint8_t addr, uint32_t data) +int MAX30001::max30001_reg_write(MAX30001_REG_map_t addr, uint32_t data) { + + uint8_t result[4]; + uint8_t data_array[4]; + int32_t success = 0; + + data_array[0] = (addr << 1) & 0xff; + + data_array[3] = data & 0xff; + data_array[2] = (data >> 8) & 0xff; + data_array[1] = (data >> 16) & 0xff; + + success = SPI_Transmit(&data_array[0], 4, &result[0], 4); + + if (success != 0) { + return -1; + } else { + return 0; + } +} + +//****************************************************************************** +// int MAX30001::max30001_reg_read(uint8_t addr, uint32_t *return_data) +int MAX30001::max30001_reg_read(MAX30001_REG_map_t addr, + uint32_t *return_data) { + uint8_t result[4]; + uint8_t data_array[1]; + int32_t success = 0; + + data_array[0] = ((addr << 1) & 0xff) | 1; // For Read, Or with 1 + success = SPI_Transmit(&data_array[0], 1, &result[0], 4); + *return_data = /*result[0] + */ (uint32_t)(result[1] << 16) + + (result[2] << 8) + result[3]; + if (success != 0) { + return -1; + } else { + return 0; + } +} + +//****************************************************************************** +int MAX30001::max30001_Enable_DcLeadOFF_Init(int8_t En_dcloff, int8_t Ipol, + int8_t Imag, int8_t Vth) { + // the leads are not touching the body + + // CNFG_EMUX, Set ECGP and ECGN for external hook up... + + if (max30001_reg_read(CNFG_GEN, &max30001_cnfg_gen.all) == -1) { + return -1; + } + + max30001_cnfg_gen.bit.en_dcloff = En_dcloff; + max30001_cnfg_gen.bit.ipol = Ipol; + max30001_cnfg_gen.bit.imag = Imag; + max30001_cnfg_gen.bit.vth = Vth; + + if (max30001_reg_write(CNFG_GEN, max30001_cnfg_gen.all) == -1) { + return -1; + } + + return 0; +} + +//****************************************************************************** +int MAX30001::max30001_Disable_DcLeadOFF(void) { + if (max30001_reg_read(CNFG_GEN, &max30001_cnfg_gen.all) == -1) { + return -1; + } + + max30001_cnfg_gen.bit.en_dcloff = 0; // Turned off the dc lead off. + + if (max30001_reg_write(CNFG_GEN, max30001_cnfg_gen.all) == -1) { + return -1; + } + + return 0; +} + +//****************************************************************************** +int MAX30001::max30001_BIOZ_Enable_ACLeadOFF_Init(uint8_t En_bloff, + uint8_t Bloff_hi_it, + uint8_t Bloff_lo_it) { + + // CNFG_GEN + if (max30001_reg_read(CNFG_GEN, &max30001_cnfg_gen.all) == -1) { + return -1; + } + + max30001_cnfg_gen.bit.en_bloff = En_bloff; + + if (max30001_reg_write(CNFG_GEN, max30001_cnfg_gen.all) == -1) { + return -1; + } + + // MNGR_DYN + if (max30001_reg_read(MNGR_DYN, &max30001_mngr_dyn.all) == -1) { + return -1; + } + + max30001_mngr_dyn.bit.bloff_hi_it = Bloff_hi_it; + max30001_mngr_dyn.bit.bloff_lo_it = Bloff_lo_it; + + if (max30001_reg_write(MNGR_DYN, max30001_mngr_dyn.all) == -1) { + return -1; + } + + return 0; +} + +//****************************************************************************** +int MAX30001::max30001_BIOZ_Disable_ACleadOFF(void) { + // CNFG_GEN + if (max30001_reg_read(CNFG_GEN, &max30001_cnfg_gen.all) == -1) { + return -1; + } + + max30001_cnfg_gen.bit.en_bloff = 0b0; // Turns of the BIOZ AC Lead OFF feature + + if (max30001_reg_write(CNFG_GEN, max30001_cnfg_gen.all) == -1) { + return -1; + } + + return 0; +} + +//****************************************************************************** +int MAX30001::max30001_BIOZ_Enable_BCGMON(void) { + // CNFG_BIOZ + if (max30001_reg_read(CNFG_BIOZ, &max30001_cnfg_bioz.all) == -1) { + return -1; + } + + max30001_cnfg_bioz.bit.cgmon = 1; + + if (max30001_reg_write(CNFG_BIOZ, max30001_cnfg_bioz.all) == -1) { + return -1; + } + + max30001_reg_read(CNFG_BIOZ, &max30001_cnfg_bioz.all); + + return 0; +} + +#if 1 +//****************************************************************************** +int MAX30001::max30001_Enable_LeadON(int8_t Channel) // Channel: ECG = 0b01, BIOZ = 0b10, Disable = 0b00 +{ + + if (max30001_reg_read(CNFG_GEN, &max30001_cnfg_gen.all) == -1) { + return -1; + } + + max30001_cnfg_gen.bit.en_ecg = 0b0; + max30001_cnfg_gen.bit.en_bioz = 0b0; + max30001_cnfg_gen.bit.en_pace = 0b0; + + max30001_cnfg_gen.bit.en_ulp_lon = Channel; // BIOZ ULP lead on detection... + + if (max30001_reg_write(CNFG_GEN, max30001_cnfg_gen.all) == -1) { + return -1; + } + + max30001_reg_read(CNFG_GEN, &max30001_cnfg_gen.all); + + max30001_reg_read(STATUS, &max30001_status.all); + + return 0; +} +//****************************************************************************** +int MAX30001::max30001_Disable_LeadON(void) { + + if (max30001_reg_read(CNFG_GEN, &max30001_cnfg_gen.all) == -1) { + return -1; + } + + max30001_cnfg_gen.bit.en_ulp_lon = 0b0; + + if (max30001_reg_write(CNFG_GEN, max30001_cnfg_gen.all) == -1) { + return -1; + } + + return 0; +} +#endif +//****************************************************************************** +#define LEADOFF_SERVICE_TIME 0x2000 // 0x1000 = 1 second +#define LEADOFF_NUMSTATES 2 +uint32_t leadoffState = 0; +uint32_t max30001_LeadOffoldTime = 0; +void MAX30001::max30001_ServiceLeadoff(uint32_t currentTime) { + + uint32_t delta_Time; + + delta_Time = currentTime - max30001_LeadOffoldTime; + + if (delta_Time > LEADOFF_SERVICE_TIME) { + switch (leadoffState) { + case 0: /* switch to ECG DC Lead OFF */ + max30001_Enable_DcLeadOFF_Init(0b01, 0b0, 0b001, 0b00); + break; + + case 1: /* switch to BIOZ DC Lead OFF */ + max30001_Enable_DcLeadOFF_Init(0b10, 0b0, 0b001, 0b00); + break; + } + + leadoffState++; + leadoffState %= LEADOFF_NUMSTATES; + + max30001_LeadOffoldTime = currentTime; + } +} +//****************************************************************************** +#define LEADON_SERVICE_TIME 0x2000 // 0x1000 = 1 second +#define LEADON_NUMSTATES 2 +uint32_t leadOnState = 0; +uint32_t max30001_LeadOnoldTime = 0; +void MAX30001::max30001_ServiceLeadON(uint32_t currentTime) { + + uint32_t delta_Time; + + delta_Time = currentTime - max30001_LeadOnoldTime; + + if (delta_Time > LEADON_SERVICE_TIME) { + switch (leadOnState) { + case 0: /* switch to ECG DC Lead ON */ + max30001_Enable_LeadON(0b01); + break; + + case 1: /* switch to BIOZ DC Lead ON */ + max30001_Enable_LeadON(0b10); + break; + } + + leadOnState++; + leadOnState %= LEADON_NUMSTATES; + + max30001_LeadOnoldTime = currentTime; + } +} + +//****************************************************************************** +int MAX30001::max30001_FIFO_LeadONOff_Read(void) { + + uint8_t result[32 * 3]; // 32words - 3bytes each + + uint8_t data_array[4]; + int32_t success = 0; + int i, j; + + uint32_t total_databytes; + uint8_t i_index; + uint8_t data_chunk; + uint8_t loop_logic; + + uint8_t etag, ptag, btag; + + uint8_t adr; + + int8_t ReadAllPaceOnce; + + static uint8_t dcloffint_OneShot = 0; + static uint8_t acloffint_OneShot = 0; + static uint8_t bcgmon_OneShot = 0; + static uint8_t acleadon_OneShot = 0; + + int8_t ret_val; + + if (max30001_status.bit.eint == 1 || max30001_status.bit.pint == 1) { + adr = ECG_FIFO_BURST; + data_array[0] = ((adr << 1) & 0xff) | 1; + + // The SPI routine only sends out data of 32 bytes in size. Therefore the + // data is being read in + // smaller chunks in this routine... + + total_databytes = (max30001_mngr_int.bit.e_fit + 1) * 3; + + i_index = 0; + loop_logic = 1; + + while (loop_logic) { + if (total_databytes > 30) { + data_chunk = 30; + total_databytes = total_databytes - 30; + } else { + data_chunk = total_databytes; + loop_logic = 0; + } + + /* The extra 1 byte is for the extra byte that comes out of the SPI */ + success = SPI_Transmit(&data_array[0], 1, &result[i_index], (data_chunk + 1)); // Make a copy of the FIFO over here... + + if (success != 0) { + return -1; + } + + /* This is important, because every transaction above creates an empty + * redundant data at result[0] */ + for (j = i_index; j < (data_chunk + i_index); j++) /* get rid of the 1 extra byte by moving the whole array up one */ + { + result[j] = result[j + 1]; + } + + i_index = i_index + 30; /* point to the next array location to put the data in */ + } + + ReadAllPaceOnce = 0; + + /* Put the content of the FIFO based on the EFIT value, We ignore the + * result[0] and start concatenating indexes: 1,2,3 - 4,5,6 - 7,8,9 - */ + for (i = 0, j = 0; i < max30001_mngr_int.bit.e_fit + 1; i++, j = j + 3) // index1=23-16 bit, index2=15-8 bit, index3=7-0 bit + { + max30001_ECG_FIFO_buffer[i] = ((uint32_t)result[j] << 16) + (result[j + 1] << 8) + result[j + 2]; + + etag = (0b00111000 & result[j + 2]) >> 3; + ptag = 0b00000111 & result[j + 2]; + + if (ptag != 0b111 && ReadAllPaceOnce == 0) { + + ReadAllPaceOnce = 1; // This will prevent extra read of PACE, once group + // 0-5 is read ONCE. + + adr = PACE0_FIFO_BURST; + + data_array[0] = ((adr << 1) & 0xff) | 1; // For Read Or with 1 + + success = SPI_Transmit(&data_array[0], 1, &result[0], 10); + + max30001_PACE[0] = (uint32_t)(result[1] << 16) + (result[2] << 8) + result[3]; + max30001_PACE[1] = (uint32_t)(result[4] << 16) + (result[5] << 8) + result[6]; + max30001_PACE[2] = (uint32_t)(result[7] << 16) + (result[8] << 8) + result[9]; + + adr = PACE1_FIFO_BURST; + + data_array[0] = ((adr << 1) & 0xff) | 1; // For Read Or with 1 + + success = SPI_Transmit(&data_array[0], 1, &result[0], 10); + + max30001_PACE[3] = (uint32_t)(result[1] << 16) + (result[2] << 8) + result[3]; + max30001_PACE[4] = (uint32_t)(result[4] << 16) + (result[5] << 8) + result[6]; + max30001_PACE[5] = (uint32_t)(result[7] << 16) + (result[8] << 8) + result[9]; + + adr = PACE2_FIFO_BURST; + + data_array[0] = ((adr << 1) & 0xff) | 1; // For Read Or with 1 + + success = SPI_Transmit(&data_array[0], 1, &result[0], 10); + + max30001_PACE[6] = (uint32_t)(result[1] << 16) + (result[2] << 8) + result[3]; + max30001_PACE[7] = (uint32_t)(result[4] << 16) + (result[5] << 8) + result[6]; + max30001_PACE[8] = (uint32_t)(result[7] << 16) + (result[8] << 8) + result[9]; + + adr = PACE3_FIFO_BURST; + + data_array[0] = ((adr << 1) & 0xff) | 1; // For Read Or with 1 + + success = SPI_Transmit(&data_array[0], 1, &result[0], 10); + + max30001_PACE[9] = (uint32_t)(result[1] << 16) + (result[2] << 8) + result[3]; + max30001_PACE[10] = (uint32_t)(result[4] << 16) + (result[5] << 8) + result[6]; + max30001_PACE[11] = (uint32_t)(result[7] << 16) + (result[8] << 8) + result[9]; + + adr = PACE4_FIFO_BURST; + + data_array[0] = ((adr << 1) & 0xff) | 1; // For Read Or with 1 + + success = SPI_Transmit(&data_array[0], 1, &result[0], 10); + + max30001_PACE[12] = (uint32_t)(result[1] << 16) + (result[2] << 8) + result[3]; + max30001_PACE[13] = (uint32_t)(result[4] << 16) + (result[5] << 8) + result[6]; + max30001_PACE[14] = (uint32_t)(result[7] << 16) + (result[8] << 8) + result[9]; + + adr = PACE5_FIFO_BURST; + + data_array[0] = ((adr << 1) & 0xff) | 1; // For Read Or with 1 + + success = SPI_Transmit(&data_array[0], 1, &result[0], 10); + + max30001_PACE[15] = (uint32_t)(result[1] << 16) + (result[2] << 8) + result[3]; + max30001_PACE[16] = (uint32_t)(result[4] << 16) + (result[5] << 8) + result[6]; + max30001_PACE[17] = (uint32_t)(result[7] << 16) + (result[8] << 8) + result[9]; + + dataAvailable(MAX30001_DATA_PACE, max30001_PACE, 18); // Send out the Pace data once only + } + } + + if (etag != 0b110) { + + dataAvailable(MAX30001_DATA_ECG, max30001_ECG_FIFO_buffer, (max30001_mngr_int.bit.e_fit + 1)); + } + + } /* End of ECG init */ + + /* RtoR */ + + if (max30001_status.bit.rrint == 1) { + if (max30001_reg_read(RTOR, &max30001_RtoR_data) == -1) { + return -1; + } + + max30001_RtoR_data = (0x00FFFFFF & max30001_RtoR_data) >> 10; + + hspValMax30001.R2R = (uint16_t)max30001_RtoR_data; + hspValMax30001.fmstr = (uint16_t)max30001_cnfg_gen.bit.fmstr; + + dataAvailable(MAX30001_DATA_RTOR, &max30001_RtoR_data, 1); + } + + // Handling BIOZ data... + + if (max30001_status.bit.bint == 1) { + adr = 0x22; + data_array[0] = ((adr << 1) & 0xff) | 1; + + /* [(BFIT+1)*3byte]+1extra byte due to the addr */ + + if (SPI_Transmit(&data_array[0], 1, &result[0],((max30001_mngr_int.bit.b_fit + 1) * 3) + 1) == -1) // Make a copy of the FIFO over here... + + { + return -1; + } + + btag = 0b00000111 & result[3]; + + /* Put the content of the FIFO based on the BFIT value, We ignore the + * result[0] and start concatenating indexes: 1,2,3 - 4,5,6 - 7,8,9 - */ + for (i = 0, j = 0; i < max30001_mngr_int.bit.b_fit + 1; i++, j = j + 3) // index1=23-16 bit, index2=15-8 bit, index3=7-0 bit + { + max30001_BIOZ_FIFO_buffer[i] = ((uint32_t)result[j + 1] << 16) + (result[j + 2] << 8) + result[j + 3]; + } + + if (btag != 0b110) { + dataAvailable(MAX30001_DATA_BIOZ, max30001_BIOZ_FIFO_buffer, 8); + } + } + + ret_val = 0; + + if (max30001_status.bit.dcloffint == 1) // ECG/BIOZ Lead Off + { + dcloffint_OneShot = 1; + max30001_DCLeadOff = 0; + max30001_DCLeadOff = max30001_DCLeadOff | (max30001_cnfg_gen.bit.en_dcloff << 8) | (max30001_status.all & 0x00000F); + dataAvailable(MAX30001_DATA_LEADOFF_DC, &max30001_DCLeadOff, 1); + // Do a FIFO Reset + max30001_reg_write(FIFO_RST, 0x000000); + + ret_val = 0b100; + + } else if (dcloffint_OneShot == 1 && max30001_status.bit.dcloffint == 0) // Just send once when it comes out of dc lead off + { + max30001_DCLeadOff = 0; + max30001_DCLeadOff = max30001_DCLeadOff | (max30001_cnfg_gen.bit.en_dcloff << 8) | (max30001_status.all & 0x00000F); + dataAvailable(MAX30001_DATA_LEADOFF_DC, &max30001_DCLeadOff, 1); + dcloffint_OneShot = 0; + } + + if (max30001_status.bit.bover == 1 || max30001_status.bit.bundr == 1) // BIOZ AC Lead Off + { + acloffint_OneShot = 1; + max30001_ACLeadOff = 0; + max30001_ACLeadOff = + max30001_ACLeadOff | ((max30001_status.all & 0x030000) >> 16); + dataAvailable(MAX30001_DATA_LEADOFF_AC, &max30001_ACLeadOff, 1); + // Do a FIFO Reset + max30001_reg_write(FIFO_RST, 0x000000); + + ret_val = 0b1000; + } else if (acloffint_OneShot == 1 && max30001_status.bit.bover == 0 && max30001_status.bit.bundr == 0) // Just send once when it comes out of ac lead off + { + max30001_ACLeadOff = 0; + max30001_ACLeadOff = max30001_ACLeadOff | ((max30001_status.all & 0x030000) >> 16); + dataAvailable(MAX30001_DATA_LEADOFF_AC, &max30001_ACLeadOff, 1); + acloffint_OneShot = 0; + } + + if (max30001_status.bit.bcgmon == 1) // BIOZ BCGMON check + { + bcgmon_OneShot = 1; + max30001_bcgmon = 0; + max30001_bcgmon = max30001_bcgmon | ((max30001_status.all & 0x000030) >> 4); + dataAvailable(MAX30001_DATA_BCGMON, &max30001_bcgmon, 1); + // Do a FIFO Reset + max30001_reg_write(FIFO_RST, 0x000000); + + ret_val = 0b10000; + } else if (bcgmon_OneShot == 1 && max30001_status.bit.bcgmon == 0) { + max30001_bcgmon = 0; + max30001_bcgmon = max30001_bcgmon | ((max30001_status.all & 0x000030) >> 4); + bcgmon_OneShot = 0; + dataAvailable(MAX30001_DATA_BCGMON, &max30001_bcgmon, 1); + } + +#if 0 +if(max30001_status.bit.lonint == 1) // AC LeadON Check +{ + max30001_LeadOn = 0; + max30001_reg_read(STATUS,&max30001_status.all); // Reading is important + max30001_LeadOn = max30001_LeadOn | (max30001_cnfg_gen.bit.en_ulp_lon << 8) | ((max30001_status.all & 0x000800) >> 11); // 0b01 will mean ECG Lead On, 0b10 will mean BIOZ Lead On + // LEAD ON has been detected... Now take actions +} +#endif + + if (max30001_status.bit.lonint == 1 && + acleadon_OneShot == 0) // AC LeadON Check, when lead is on + { + max30001_LeadOn = 0; + max30001_reg_read(STATUS, &max30001_status.all); // Reading is important + max30001_LeadOn = + max30001_LeadOn | (max30001_cnfg_gen.bit.en_ulp_lon << 8) | + ((max30001_status.all & 0x000800) >> + 11); // 0b01 will mean ECG Lead On, 0b10 will mean BIOZ Lead On + + // LEAD ON has been detected... Now take actions + acleadon_OneShot = 1; + dataAvailable(MAX30001_DATA_ACLEADON, &max30001_LeadOn, 1); // One shot data will be sent... + } else if (max30001_status.bit.lonint == 0 && acleadon_OneShot == 1) { + max30001_LeadOn = 0; + max30001_reg_read(STATUS, &max30001_status.all); + max30001_LeadOn = + max30001_LeadOn | (max30001_cnfg_gen.bit.en_ulp_lon << 8) | ((max30001_status.all & 0x000800) >> 11); // 0b01 will mean ECG Lead On, 0b10 will mean BIOZ Lead On + dataAvailable(MAX30001_DATA_ACLEADON, &max30001_LeadOn, 1); // One shot data will be sent... + acleadon_OneShot = 0; + } + + return ret_val; +} + +//****************************************************************************** + +int MAX30001::max30001_int_handler(void) { + + static uint32_t InitReset = 0; + + int8_t return_value; + + max30001_reg_read(STATUS, &max30001_status.all); + + // Inital Reset and any FIFO over flow invokes a FIFO reset + if (InitReset == 0 || max30001_status.bit.eovf == 1 || max30001_status.bit.bovf == 1 || max30001_status.bit.povf == 1) { + // Do a FIFO Reset + max30001_reg_write(FIFO_RST, 0x000000); + + InitReset++; + return 2; + } + + return_value = 0; + + // The four data handling goes on over here + if (max30001_status.bit.eint == 1 || max30001_status.bit.pint == 1 || max30001_status.bit.bint == 1 || max30001_status.bit.rrint == 1) { + return_value = return_value | max30001_FIFO_LeadONOff_Read(); + } + + // ECG/BIOZ DC Lead Off test + if (max30001_status.bit.dcloffint == 1) { + return_value = return_value | max30001_FIFO_LeadONOff_Read(); + } + + // BIOZ AC Lead Off test + if (max30001_status.bit.bover == 1 || max30001_status.bit.bundr == 1) { + return_value = return_value | max30001_FIFO_LeadONOff_Read(); + } + + // BIOZ DRVP/N test using BCGMON. + if (max30001_status.bit.bcgmon == 1) { + return_value = return_value | max30001_FIFO_LeadONOff_Read(); + } + + if (max30001_status.bit.lonint == 1) // ECG Lead ON test: i.e. the leads are touching the body... + { + + max30001_FIFO_LeadONOff_Read(); + } + + return return_value; +} + +/// function pointer to the async callback +static event_callback_t functionpointer; +/// flag used to indicate an async xfer has taken place +static volatile int xferFlag = 0; + +/** +* @brief Callback handler for SPI async events +* @param events description of event that occurred +*/ +static void spiHandler(int events) { xferFlag = 1; } + +/** +* @brief Transmit and recieve QUAD SPI data +* @param tx_buf pointer to transmit byte buffer +* @param tx_size number of bytes to transmit +* @param rx_buf pointer to the recieve buffer +* @param rx_size number of bytes to recieve +*/ +int MAX30001::SPI_Transmit(const uint8_t *tx_buf, uint32_t tx_size, uint8_t *rx_buf, uint32_t rx_size) { + xferFlag = 0; + int i; + for (i = 0; i < sizeof(buffer); i++) { + if (i < tx_size) + buffer[i] = tx_buf[i]; + else + buffer[i] = 0xFF; + } + spi->transfer<uint8_t>(buffer, (int)rx_size, rx_buf, (int)rx_size, spiHandler /* functionpointer */); + while (xferFlag == 0); + return 0; +} + +//****************************************************************************** +void MAX30001::max30001_ReadHeartrateData(max30001_t *_hspValMax30001) { + _hspValMax30001->R2R = hspValMax30001.R2R; + _hspValMax30001->fmstr = hspValMax30001.fmstr; +} + +//****************************************************************************** +void MAX30001::onDataAvailable(PtrFunction _onDataAvailable) { + onDataAvailableCallback = _onDataAvailable; +} + +/** +* @brief Used to notify an external function that interrupt data is available +* @param id type of data available +* @param buffer 32-bit buffer that points to the data +* @param length length of 32-bit elements available +*/ +void MAX30001::dataAvailable(uint32_t id, uint32_t *buffer, uint32_t length) { + if (onDataAvailableCallback != NULL) { + (*onDataAvailableCallback)(id, buffer, length); + } +} + +/** +* @brief Callback handler for SPI async events +* @param events description of event that occurred +*/ +void MAX30001::spiHandler(int events) { xferFlag = 1; } + +//****************************************************************************** +static int allowInterrupts = 0; + +void MAX30001Mid_IntB_Handler(void) { + if (allowInterrupts == 0) return; + MAX30001::instance->max30001_int_handler(); +} + +void MAX30001Mid_Int2B_Handler(void) { + if (allowInterrupts == 0) return; + MAX30001::instance->max30001_int_handler(); +} + +void MAX30001_AllowInterrupts(int state) { +allowInterrupts = state; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/MAX30001/MAX30001/MAX30001.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,1076 @@ +/******************************************************************************* +* Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES +* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Except as contained in this notice, the name of Maxim Integrated +* Products, Inc. shall not be used except as stated in the Maxim Integrated +* Products, Inc. Branding Policy. +* +* The mere transfer of this software does not imply any licenses +* of trade secrets, proprietary technology, copyrights, patents, +* trademarks, maskwork rights, or any other form of intellectual +* property whatsoever. Maxim Integrated Products, Inc. retains all +* ownership rights. +*******************************************************************************/ +/* + * max30001.h + * + * Created on: Oct 9, 2015 + * Author: faisal.tariq + */ + +#ifndef MAX30001_H_ +#define MAX30001_H_ + +#include "mbed.h" + +#define mbed_COMPLIANT // Uncomment to Use timer for MAX30001 FCLK (for mbed) + // Comment to use the RTC clock + +#define ASYNC_SPI_BUFFER_SIZE (32 * 3) // Maximimum buffer size for async byte transfers + +// Defines for data callbacks +#define MAX30001_DATA_ECG 0x30 +#define MAX30001_DATA_PACE 0x31 +#define MAX30001_DATA_RTOR 0x32 +#define MAX30001_DATA_BIOZ 0x33 +#define MAX30001_DATA_LEADOFF_DC 0x34 +#define MAX30001_DATA_LEADOFF_AC 0x35 +#define MAX30001_DATA_BCGMON 0x36 +#define MAX30001_DATA_ACLEADON 0x37 + +#define MAX30001_SPI_MASTER_PORT 0 +#define MAX30001_SPI_SS_INDEX 0 + +#define MAX30001_INT_PORT_B 3 +#define MAX30001_INT_PIN_B 6 + +#define MAX30001_INT_PORT_2B 4 +#define MAX30001_INT_PIN_2B 5 + +#define MAX30001_INT_PORT_FCLK 1 +#define MAX30001_INT_PIN_FCLK 7 + +#define MAX30001_FUNC_SEL_TMR 2 // 0=FW Control, 1= Pulse Train, 2=Timer + +#define MAX30001_INDEX 3 +#define MAX30001_POLARITY 0 +#define MAX30001_PERIOD 30518 +#define MAX30001_CYCLE 50 + +#define MAX30001_IOMUX_IO_ENABLE 1 + +#define MAX30001_SPI_PORT 0 +#define MAX30001_CS_PIN 0 +#define MAX30001_CS_POLARITY 0 +#define MAX30001_CS_ACTIVITY_DELAY 0 +#define MAX30001_CS_INACTIVITY_DELAY 0 +#define MAX30001_CLK_HI 1 +#define MAX30001_CLK_LOW 1 +#define MAX30001_ALT_CLK 0 +#define MAX30001_CLK_POLARITY 0 +#define MAX30001_CLK_PHASE 0 +#define MAX30001_WRITE 1 +#define MAX30001_READ 0 + +#define MAX30001_INT_PORT_B 3 +#define MAX30001INT_PIN_B 6 + +void MAX30001_AllowInterrupts(int state); + +/** +* Maxim Integrated MAX30001 ECG/BIOZ chip +*/ +class MAX30001 { + +public: + typedef enum { // MAX30001 Register addresses + STATUS = 0x01, + EN_INT = 0x02, + EN_INT2 = 0x03, + MNGR_INT = 0x04, + MNGR_DYN = 0x05, + SW_RST = 0x08, + SYNCH = 0x09, + FIFO_RST = 0x0A, + INFO = 0x0F, + CNFG_GEN = 0x10, + CNFG_CAL = 0x12, + CNFG_EMUX = 0x14, + CNFG_ECG = 0x15, + CNFG_BMUX = 0x17, + CNFG_BIOZ = 0x18, + CNFG_PACE = 0x1A, + CNFG_RTOR1 = 0x1D, + CNFG_RTOR2 = 0x1E, + + // Data locations + ECG_FIFO_BURST = 0x20, + ECG_FIFO = 0x21, + FIFO_BURST = 0x22, + BIOZ_FIFO = 0x23, + RTOR = 0x25, + + PACE0_FIFO_BURST = 0x30, + PACE0_A = 0x31, + PACE0_B = 0x32, + PACE0_C = 0x33, + + PACE1_FIFO_BURST = 0x34, + PACE1_A = 0x35, + PACE1_B = 0x36, + PACE1_C = 0x37, + + PACE2_FIFO_BURST = 0x38, + PACE2_A = 0x39, + PACE2_B = 0x3A, + PACE2_C = 0x3B, + + PACE3_FIFO_BURST = 0x3C, + PACE3_A = 0x3D, + PACE3_B = 0x3E, + PACE3_C = 0x3F, + + PACE4_FIFO_BURST = 0x40, + PACE4_A = 0x41, + PACE4_B = 0x42, + PACE4_C = 0x43, + + PACE5_FIFO_BURST = 0x44, + PACE5_A = 0x45, + PACE5_B = 0x46, + PACE5_C = 0x47, + + } MAX30001_REG_map_t; + + /** + * @brief STATUS (0x01) + */ + union max30001_status_reg { + uint32_t all; + + struct { + uint32_t loff_nl : 1; + uint32_t loff_nh : 1; + uint32_t loff_pl : 1; + uint32_t loff_ph : 1; + + uint32_t bcgmn : 1; + uint32_t bcgmp : 1; + uint32_t reserved1 : 1; + uint32_t reserved2 : 1; + + uint32_t pllint : 1; + uint32_t samp : 1; + uint32_t rrint : 1; + uint32_t lonint : 1; + + uint32_t pedge : 1; + uint32_t povf : 1; + uint32_t pint : 1; + uint32_t bcgmon : 1; + + uint32_t bundr : 1; + uint32_t bover : 1; + uint32_t bovf : 1; + uint32_t bint : 1; + + uint32_t dcloffint : 1; + uint32_t fstint : 1; + uint32_t eovf : 1; + uint32_t eint : 1; + + uint32_t reserved : 8; + + } bit; + + } max30001_status; + + + /** + * @brief EN_INT (0x02) + */ + + union max30001_en_int_reg { + uint32_t all; + + struct { + uint32_t intb_type : 2; + uint32_t reserved1 : 1; + uint32_t reserved2 : 1; + + uint32_t reserved3 : 1; + uint32_t reserved4 : 1; + uint32_t reserved5 : 1; + uint32_t reserved6 : 1; + + uint32_t en_pllint : 1; + uint32_t en_samp : 1; + uint32_t en_rrint : 1; + uint32_t en_lonint : 1; + + uint32_t en_pedge : 1; + uint32_t en_povf : 1; + uint32_t en_pint : 1; + uint32_t en_bcgmon : 1; + + uint32_t en_bundr : 1; + uint32_t en_bover : 1; + uint32_t en_bovf : 1; + uint32_t en_bint : 1; + + uint32_t en_dcloffint : 1; + uint32_t en_fstint : 1; + uint32_t en_eovf : 1; + uint32_t en_eint : 1; + + uint32_t reserved : 8; + + } bit; + + } max30001_en_int; + + + /** + * @brief EN_INT2 (0x03) + */ + union max30001_en_int2_reg { + uint32_t all; + + struct { + uint32_t intb_type : 2; + uint32_t reserved1 : 1; + uint32_t reserved2 : 1; + + uint32_t reserved3 : 1; + uint32_t reserved4 : 1; + uint32_t reserved5 : 1; + uint32_t reserved6 : 1; + + uint32_t en_pllint : 1; + uint32_t en_samp : 1; + uint32_t en_rrint : 1; + uint32_t en_lonint : 1; + + uint32_t en_pedge : 1; + uint32_t en_povf : 1; + uint32_t en_pint : 1; + uint32_t en_bcgmon : 1; + + uint32_t en_bundr : 1; + uint32_t en_bover : 1; + uint32_t en_bovf : 1; + uint32_t en_bint : 1; + + uint32_t en_dcloffint : 1; + uint32_t en_fstint : 1; + uint32_t en_eovf : 1; + uint32_t en_eint : 1; + + uint32_t reserved : 8; + + } bit; + + } max30001_en_int2; + + /** + * @brief MNGR_INT (0x04) + */ + union max30001_mngr_int_reg { + uint32_t all; + + struct { + uint32_t samp_it : 2; + uint32_t clr_samp : 1; + uint32_t clr_pedge : 1; + uint32_t clr_rrint : 2; + uint32_t clr_fast : 1; + uint32_t reserved1 : 1; + uint32_t reserved2 : 4; + uint32_t reserved3 : 4; + + uint32_t b_fit : 3; + uint32_t e_fit : 5; + + uint32_t reserved : 8; + + } bit; + + } max30001_mngr_int; + + /** + * @brief MNGR_DYN (0x05) + */ + union max30001_mngr_dyn_reg { + uint32_t all; + + struct { + uint32_t bloff_lo_it : 8; + uint32_t bloff_hi_it : 8; + uint32_t fast_th : 6; + uint32_t fast : 2; + uint32_t reserved : 8; + } bit; + + } max30001_mngr_dyn; + + // 0x08 + // uint32_t max30001_sw_rst; + + // 0x09 + // uint32_t max30001_synch; + + // 0x0A + // uint32_t max30001_fifo_rst; + + + /** + * @brief INFO (0x0F) + */ + union max30001_info_reg { + uint32_t all; + struct { + uint32_t serial : 12; + uint32_t part_id : 2; + uint32_t sample : 1; + uint32_t reserved1 : 1; + uint32_t rev_id : 4; + uint32_t pattern : 4; + uint32_t reserved : 8; + } bit; + + } max30001_info; + + /** + * @brief CNFG_GEN (0x10) + */ + union max30001_cnfg_gen_reg { + uint32_t all; + struct { + uint32_t rbiasn : 1; + uint32_t rbiasp : 1; + uint32_t rbiasv : 2; + uint32_t en_rbias : 2; + uint32_t vth : 2; + uint32_t imag : 3; + uint32_t ipol : 1; + uint32_t en_dcloff : 2; + uint32_t en_bloff : 2; + uint32_t reserved1 : 1; + uint32_t en_pace : 1; + uint32_t en_bioz : 1; + uint32_t en_ecg : 1; + uint32_t fmstr : 2; + uint32_t en_ulp_lon : 2; + uint32_t reserved : 8; + } bit; + + } max30001_cnfg_gen; + + + /** + * @brief CNFG_CAL (0x12) + */ + union max30001_cnfg_cal_reg { + uint32_t all; + struct { + uint32_t thigh : 11; + uint32_t fifty : 1; + uint32_t fcal : 3; + uint32_t reserved1 : 5; + uint32_t vmag : 1; + uint32_t vmode : 1; + uint32_t en_vcal : 1; + uint32_t reserved2 : 1; + uint32_t reserved : 8; + } bit; + + } max30001_cnfg_cal; + + /** + * @brief CNFG_EMUX (0x14) + */ + union max30001_cnfg_emux_reg { + uint32_t all; + struct { + uint32_t reserved1 : 16; + uint32_t caln_sel : 2; + uint32_t calp_sel : 2; + uint32_t openn : 1; + uint32_t openp : 1; + uint32_t reserved2 : 1; + uint32_t pol : 1; + uint32_t reserved : 8; + } bit; + + } max30001_cnfg_emux; + + + /** + * @brief CNFG_ECG (0x15) + */ + union max30001_cnfg_ecg_reg { + uint32_t all; + struct { + uint32_t reserved1 : 12; + uint32_t dlpf : 2; + uint32_t dhpf : 1; + uint32_t reserved2 : 1; + uint32_t gain : 2; + uint32_t reserved3 : 4; + uint32_t rate : 2; + + uint32_t reserved : 8; + } bit; + + } max30001_cnfg_ecg; + + /** + * @brief CNFG_BMUX (0x17) + */ + union max30001_cnfg_bmux_reg { + uint32_t all; + struct { + uint32_t fbist : 2; + uint32_t reserved1 : 2; + uint32_t rmod : 3; + uint32_t reserved2 : 1; + uint32_t rnom : 3; + uint32_t en_bist : 1; + uint32_t cg_mode : 2; + uint32_t reserved3 : 2; + uint32_t caln_sel : 2; + uint32_t calp_sel : 2; + uint32_t openn : 1; + uint32_t openp : 1; + uint32_t reserved4 : 2; + uint32_t reserved : 8; + } bit; + + } max30001_cnfg_bmux; + + /** + * @brief CNFG_BIOZ (0x18) + */ + union max30001_bioz_reg { + uint32_t all; + struct { + uint32_t phoff : 4; + uint32_t cgmag : 3; + uint32_t cgmon : 1; + uint32_t fcgen : 4; + uint32_t dlpf : 2; + uint32_t dhpf : 2; + uint32_t gain : 2; + uint32_t reserved1 : 1; + uint32_t ext_rbias : 1; + uint32_t ahpf : 3; + uint32_t rate : 1; + uint32_t reserved : 8; + } bit; + + } max30001_cnfg_bioz; + + + /** + * @brief CNFG_PACE (0x1A) + */ + union max30001_cnfg_pace_reg { + uint32_t all; + + struct { + uint32_t dacn : 4; + uint32_t dacp : 4; + uint32_t reserved1 : 4; + uint32_t aout : 2; + uint32_t aout_lbw : 1; + uint32_t reserved2 : 1; + uint32_t gain : 3; + uint32_t gn_diff_off : 1; + uint32_t reserved3 : 3; + uint32_t pol : 1; + uint32_t reserved : 8; + } bit; + + } max30001_cnfg_pace; + + /** + * @brief CNFG_RTOR1 (0x1D) + */ + union max30001_cnfg_rtor1_reg { + uint32_t all; + struct { + uint32_t reserved1 : 8; + uint32_t ptsf : 4; + uint32_t pavg : 2; + uint32_t reserved2 : 1; + uint32_t en_rtor : 1; + uint32_t gain : 4; + uint32_t wndw : 4; + uint32_t reserved : 8; + } bit; + + } max30001_cnfg_rtor1; + + /** + * @brief CNFG_RTOR2 (0x1E) + */ + union max30001_cnfg_rtor2_reg { + uint32_t all; + struct { + uint32_t reserved1 : 8; + uint32_t rhsf : 3; + uint32_t reserved2 : 1; + uint32_t ravg : 2; + uint32_t reserved3 : 2; + uint32_t hoff : 6; + uint32_t reserved4 : 2; + uint32_t reserved : 8; + } bit; + + } max30001_cnfg_rtor2; + + /*********************************************************************************/ + + typedef enum { + MAX30001_NO_INT = 0, // No interrupt + MAX30001_INT_B = 1, // INTB selected for interrupt + MAX30001_INT_2B = 2 // INT2B selected for interrupt + } max30001_intrpt_Location_t; + + typedef enum { + MAX30001_INT_DISABLED = 0b00, + MAX30001_INT_CMOS = 0b01, + MAX30001_INT_ODN = 0b10, + MAX30001_INT_ODNR = 0b11 + } max30001_intrpt_type_t; + + typedef enum { // Input Polarity selection + MAX30001_NON_INV = 0, // Non-Inverted + MAX30001_INV = 1 // Inverted + } max30001_emux_pol; + + typedef enum { // OPENP and OPENN setting + MAX30001_ECG_CON_AFE = 0, // ECGx is connected to AFE channel + MAX30001_ECG_ISO_AFE = 1 // ECGx is isolated from AFE channel + } max30001_emux_openx; + + typedef enum { // EMUX_CALP_SEL & EMUX_CALN_SEL + MAX30001_NO_CAL_SIG = 0b00, // No calibration signal is applied + MAX30001_INPT_VMID = 0b01, // Input is connected to VMID + MAX30001_INPT_VCALP = 0b10, // Input is connected to VCALP + MAX30001_INPT_VCALN = 0b11 // Input is connected to VCALN + } max30001_emux_calx_sel; + + typedef enum { // EN_ECG, EN_BIOZ, EN_PACE + MAX30001_CHANNEL_DISABLED = 0b0, // + MAX30001_CHANNEL_ENABLED = 0b1 + } max30001_en_feature; + + /*********************************************************************************/ + // Data + uint32_t max30001_ECG_FIFO_buffer[32]; // (303 for internal test) + uint32_t max30001_BIOZ_FIFO_buffer[8]; // (303 for internal test) + + uint32_t max30001_PACE[18]; // Pace Data 0-5 + + uint32_t max30001_RtoR_data; // This holds the RtoR data + + uint32_t max30001_DCLeadOff; // This holds the LeadOff data, Last 4 bits give + // the status, BIT3=LOFF_PH, BIT2=LOFF_PL, + // BIT1=LOFF_NH, BIT0=LOFF_NL + // 8th and 9th bits tell Lead off is due to ECG or BIOZ. + // 0b01 = ECG Lead Off and 0b10 = BIOZ Lead off + + uint32_t max30001_ACLeadOff; // This gives the state of the BIOZ AC Lead Off + // state. BIT 1 = BOVER, BIT 0 = BUNDR + + uint32_t max30001_bcgmon; // This holds the BCGMON data, BIT 1 = BCGMP, BIT0 = + // BCGMN + + uint32_t max30001_LeadOn; // This holds the LeadOn data, BIT1 = BIOZ Lead ON, + // BIT0 = ECG Lead ON, BIT8= Lead On Status Bit + + uint32_t max30001_timeout; // If the PLL does not respond, timeout and get out. + + typedef struct { // Creating a structure for BLE data + int16_t R2R; + int16_t fmstr; + } max30001_t; + + max30001_t hspValMax30001; // R2R, FMSTR + + /** + * @brief Constructor that accepts pin names for the SPI interface + * @param spi pointer to the mbed SPI object + */ + MAX30001(SPI *spi); + + /** + * @brief Constructor that accepts pin names for the SPI interface + * @param mosi master out slave in pin name + * @param miso master in slave out pin name + * @param sclk serial clock pin name + * @param cs chip select pin name + */ + MAX30001(PinName mosi, PinName miso, PinName sclk, PinName cs); + + /** + * MAX30001 destructor + */ + ~MAX30001(void); + + /** + * @brief This function sets up the Resistive Bias mode and also selects the master clock frequency. + * @brief Uses Register: CNFG_GEN-0x10 + * @param En_rbias: Enable and Select Resitive Lead Bias Mode + * @param Rbiasv: Resistive Bias Mode Value Selection + * @param Rbiasp: Enables Resistive Bias on Positive Input + * @param Rbiasn: Enables Resistive Bias on Negative Input + * @param Fmstr: Selects Master Clock Frequency + * @returns 0-if no error. A non-zero value indicates an error. + * + */ + int max30001_Rbias_FMSTR_Init(uint8_t En_rbias, uint8_t Rbiasv, + uint8_t Rbiasp, uint8_t Rbiasn, uint8_t Fmstr); + + /** + * @brief This function uses sets up the calibration signal internally. If it is desired to use the internal signal, then + * @brief this function must be called and the registers set, prior to setting the CALP_SEL and CALN_SEL in the ECG_InitStart + * @brief and BIOZ_InitStart functions. + * @brief Uses Register: CNFG_CAL-0x12 + * @param En_Vcal: Calibration Source (VCALP and VCALN) Enable + * @param Vmode: Calibration Source Mode Selection + * @param Vmag: Calibration Source Magnitude Selection (VMAG) + * @param Fcal: Calibration Source Frequency Selection (FCAL) + * @param Thigh: Calibration Source Time High Selection + * @param Fifty: Calibration Source Duty Cycle Mode Selection + * @returns 0-if no error. A non-zero value indicates an error. + * + */ + int max30001_CAL_InitStart(uint8_t En_Vcal, uint8_t Vmode, uint8_t Vmag, + uint8_t Fcal, uint16_t Thigh, uint8_t Fifty); + + /** + * @brief This function disables the VCAL signal + * @returns 0-if no error. A non-zero value indicates an error. + */ + int max30001_CAL_Stop(void); + + /** + * @brief This function handles the assignment of the two interrupt pins (INTB & INT2B) with various + * @brief functions/behaviors of the MAX30001. Also, each pin can be configured for different drive capability. + * @brief Uses Registers: EN_INT-0x02 and EN_INT2-0x03. + * @param max30001_intrpt_Locatio_t <argument>: All the arguments with the aforementioned enumeration essentially + * can be configured to generate an interrupt on either INTB or INT2B or NONE. + * @param max30001_intrpt_type_t intb_Type: INTB Port Type (EN_INT Selections). + * @param max30001_intrpt_type _t int2b_Type: INT2B Port Type (EN_INT2 Selections) + * @returns 0-if no error. A non-zero value indicates an error. + * + */ + int max30001_INT_assignment(max30001_intrpt_Location_t en_enint_loc, max30001_intrpt_Location_t en_eovf_loc, max30001_intrpt_Location_t en_fstint_loc, + max30001_intrpt_Location_t en_dcloffint_loc, max30001_intrpt_Location_t en_bint_loc, max30001_intrpt_Location_t en_bovf_loc, + max30001_intrpt_Location_t en_bover_loc, max30001_intrpt_Location_t en_bundr_loc, max30001_intrpt_Location_t en_bcgmon_loc, + max30001_intrpt_Location_t en_pint_loc, max30001_intrpt_Location_t en_povf_loc, max30001_intrpt_Location_t en_pedge_loc, + max30001_intrpt_Location_t en_lonint_loc, max30001_intrpt_Location_t en_rrint_loc, max30001_intrpt_Location_t en_samp_loc, + max30001_intrpt_type_t intb_Type, max30001_intrpt_type_t int2b_Type); + + + + /** + * @brief For MAX30001/3 ONLY + * @brief This function sets up the MAX30001 for the ECG measurements. + * @brief Registers used: CNFG_EMUX, CNFG_GEN, MNGR_INT, CNFG_ECG. + * @param En_ecg: ECG Channel Enable <CNFG_GEN register bits> + * @param Openp: Open the ECGN Input Switch (most often used for testing and calibration studies) <CNFG_EMUX register bits> + * @param Openn: Open the ECGN Input Switch (most often used for testing and calibration studies) <CNFG_EMUX register bits> + * @param Calp_sel: ECGP Calibration Selection <CNFG_EMUX register bits> + * @param Caln_sel: ECGN Calibration Selection <CNFG_EMUX register bits> + * @param E_fit: ECG FIFO Interrupt Threshold (issues EINT based on number of unread FIFO records) <CNFG_GEN register bits> + * @param Clr_rrint: RTOR R Detect Interrupt (RRINT) Clear Behavior <CNFG_GEN register bits> + * @param Rate: ECG Data Rate + * @param Gain: ECG Channel Gain Setting + * @param Dhpf: ECG Channel Digital High Pass Filter Cutoff Frequency + * @param Dlpf: ECG Channel Digital Low Pass Filter Cutoff Frequency + * @returns 0-if no error. A non-zero value indicates an error. + * + */ + int max30001_ECG_InitStart(uint8_t En_ecg, uint8_t Openp, uint8_t Openn, + uint8_t Pol, uint8_t Calp_sel, uint8_t Caln_sel, + uint8_t E_fit, uint8_t Rate, uint8_t Gain, + uint8_t Dhpf, uint8_t Dlpf); + + /** + * @brief For MAX30001/3 ONLY + * @brief This function enables the Fast mode feature of the ECG. + * @brief Registers used: MNGR_INT-0x04, MNGR_DYN-0x05 + * @param Clr_Fast: FAST MODE Interrupt Clear Behavior <MNGR_INT Register> + * @param Fast: ECG Channel Fast Recovery Mode Selection (ECG High Pass Filter Bypass) <MNGR_DYN Register> + * @param Fast_Th: Automatic Fast Recovery Threshold + * @returns 0-if no error. A non-zero value indicates an error. + * + */ + int max30001_ECGFast_Init(uint8_t Clr_Fast, uint8_t Fast, uint8_t Fast_Th); + + /** + * @brief For MAX30001/3 ONLY + * @brief This function disables the ECG. + * @brief Uses Register CNFG_GEN-0x10. + * @returns 0-if no error. A non-zero value indicates an error. + * + */ + int max30001_Stop_ECG(void); + + /** + * @brief For MAX30001 ONLY + * @brief This function sets up the MAX30001 for pace signal detection. + * @brief If both PACE and BIOZ are turned ON, then make sure Fcgen is set for 80K or 40K in the + * @brief max30001_BIOZ_InitStart() function. However, if Only PACE is on but BIOZ off, then Fcgen can be set + * @brief for 80K only, in the max30001_BIOZ_InitStart() function + * @brief Registers used: MNGR_INT-0x04, CNFG_GEN-0x37, CNFG_PACE-0x1A. + * @param En_pace : PACE Channel Enable <CNFG_GEN Register> + * @param Clr_pedge : PACE Edge Detect Interrupt (PEDGE) Clear Behavior <MNGR_INT Register> + * @param Pol: PACE Input Polarity Selection <CNFG_PACE Register> + * @param Gn_diff_off: PACE Differentiator Mode <CNFG_PACE Register> + * @param Gain: PACE Channel Gain Selection <CNFG_PACE Register> + * @param Aout_lbw: PACE Analog Output Buffer Bandwidth Mode <CNFG_PACE Register> + * @param Aout: PACE Single Ended Analog Output Buffer Signal Monitoring Selection <CNFG_PACE Register> + * @param Dacp (4bits): PACE Detector Positive Comparator Threshold <CNFG_PACE Register> + * @param Dacn(4bits): PACE Detector Negative Comparator Threshold <CNFG_PACE Register> + * @returns 0-if no error. A non-zero value indicates an error <CNFG_PACE Register> + * + */ + int max30001_PACE_InitStart(uint8_t En_pace, uint8_t Clr_pedge, uint8_t Pol, + uint8_t Gn_diff_off, uint8_t Gain, + uint8_t Aout_lbw, uint8_t Aout, uint8_t Dacp, + uint8_t Dacn); + + /** + *@brief For MAX30001 ONLY + *@param This function disables the PACE. Uses Register CNFG_GEN-0x10. + *@returns 0-if no error. A non-zero value indicates an error. + * + */ + int max30001_Stop_PACE(void); + + /** + * @brief For MAX30001/2 ONLY + * @brief This function sets up the MAX30001 for BIOZ measurement. + * @brief Registers used: MNGR_INT-0x04, CNFG_GEN-0X10, CNFG_BMUX-0x17,CNFG_BIOZ-0x18. + * @param En_bioz: BIOZ Channel Enable <CNFG_GEN Register> + * @param Openp: Open the BIP Input Switch <CNFG_BMUX Register> + * @param Openn: Open the BIN Input Switch <CNFG_BMUX Register> + * @param Calp_sel: BIP Calibration Selection <CNFG_BMUX Register> + * @param Caln_sel: BIN Calibration Selection <CNFG_BMUX Register> + * @param CG_mode: BIOZ Current Generator Mode Selection <CNFG_BMUX Register> + * @param B_fit: BIOZ FIFO Interrupt Threshold (issues BINT based on number of unread FIFO records) <MNGR_INT Register> + * @param Rate: BIOZ Data Rate <CNFG_BIOZ Register> + * @param Ahpf: BIOZ/PACE Channel Analog High Pass Filter Cutoff Frequency and Bypass <CNFG_BIOZ Register> + * @param Ext_rbias: External Resistor Bias Enable <CNFG_BIOZ Register> + * @param Gain: BIOZ Channel Gain Setting <CNFG_BIOZ Register> + * @param Dhpf: BIOZ Channel Digital High Pass Filter Cutoff Frequency <CNFG_BIOZ Register> + * @param Dlpf: BIOZ Channel Digital Low Pass Filter Cutoff Frequency <CNFG_BIOZ Register> + * @param Fcgen: BIOZ Current Generator Modulation Frequency <CNFG_BIOZ Register> + * @param Cgmon: BIOZ Current Generator Monitor <CNFG_BIOZ Register> + * @param Cgmag: BIOZ Current Generator Magnitude <CNFG_BIOZ Register> + * @param Phoff: BIOZ Current Generator Modulation Phase Offset <CNFG_BIOZ Register> + * @returns 0-if no error. A non-zero value indicates an error. + * + */ + int max30001_BIOZ_InitStart(uint8_t En_bioz, uint8_t Openp, uint8_t Openn, + uint8_t Calp_sel, uint8_t Caln_sel, + uint8_t CG_mode, + /* uint8_t En_bioz,*/ uint8_t B_fit, uint8_t Rate, + uint8_t Ahpf, uint8_t Ext_rbias, uint8_t Gain, + uint8_t Dhpf, uint8_t Dlpf, uint8_t Fcgen, + uint8_t Cgmon, uint8_t Cgmag, uint8_t Phoff); + + /** + * @brief For MAX30001/2 ONLY + * @brief This function disables the BIOZ. Uses Register CNFG_GEN-0x10. + * @returns 0-if no error. A non-zero value indicates an error. + * @returns 0-if no error. A non-zero value indicates an error. + * + */ + int max30001_Stop_BIOZ(void); + + /** + * @brief For MAX30001/2 ONLY + * @brief BIOZ modulated Resistance Built-in-Self-Test, Registers used: CNFG_BMUX-0x17 + * @param En_bist: Enable Modulated Resistance Built-in-Self-test <CNFG_BMUX Register> + * @param Rnom: BIOZ RMOD BIST Nominal Resistance Selection <CNFG_BMUX Register> + * @param Rmod: BIOZ RMOD BIST Modulated Resistance Selection <CNFG_BMUX Register> + * @param Fbist: BIOZ RMOD BIST Frequency Selection <CNFG_BMUX Register> + * @returns 0-if no error. A non-zero value indicates an error. + * + */ + int max30001_BIOZ_InitBist(uint8_t En_bist, uint8_t Rnom, uint8_t Rmod, + uint8_t Fbist); + + /** + * @brief For MAX30001/3/4 ONLY + * @brief Sets up the device for RtoR measurement + * @param EN_rtor: ECG RTOR Detection Enable <RTOR1 Register> + * @param Wndw: R to R Window Averaging (Window Width = RTOR_WNDW[3:0]*8mS) <RTOR1 Register> + * @param Gain: R to R Gain (where Gain = 2^RTOR_GAIN[3:0], plus an auto-scale option) <RTOR1 Register> + * @param Pavg: R to R Peak Averaging Weight Factor <RTOR1 Register> + * @param Ptsf: R to R Peak Threshold Scaling Factor <RTOR1 Register> + * @param Hoff: R to R minimum Hold Off <RTOR2 Register> + * @param Ravg: R to R Interval Averaging Weight Factor <RTOR2 Register> + * @param Rhsf: R to R Interval Hold Off Scaling Factor <RTOR2 Register> + * @param Clr_rrint: RTOR Detect Interrupt Clear behaviour <MNGR_INT Register> + * @returns 0-if no error. A non-zero value indicates an error. + * + */ + int max30001_RtoR_InitStart(uint8_t En_rtor, uint8_t Wndw, uint8_t Gain, + uint8_t Pavg, uint8_t Ptsf, uint8_t Hoff, + uint8_t Ravg, uint8_t Rhsf, uint8_t Clr_rrint); + + /** + * @brief For MAX30001/3/4 ONLY + * @brief This function disables the RtoR. Uses Register CNFG_RTOR1-0x1D + * @returns 0-if no error. A non-zero value indicates an error. + * + */ + int max30001_Stop_RtoR(void); + + /** + * @brief This is a function that waits for the PLL to lock; once a lock is achieved it exits out. (For convenience only) + * @returns 0-if no error. A non-zero value indicates an error. + * + */ + int max30001_PLL_lock(void); + + /** + * @brief This function causes the MAX30001 to reset. Uses Register SW_RST-0x08 + * @return 0-if no error. A non-zero value indicates an error. + * + */ + int max30001_sw_rst(void); + + /** + * @brief This function provides a SYNCH operation. Uses Register SYCNH-0x09. Please refer to the data sheet for + * @brief the details on how to use this. + * @returns 0-if no error. A non-zero value indicates an error. + * + */ + int max30001_synch(void); + + /** + * @brief This function performs a FIFO Reset. Uses Register FIFO_RST-0x0A. Please refer to the data sheet + * @brief for the details on how to use this. + * @returns 0-if no error. A non-zero value indicates an error. + */ + int max300001_fifo_rst(void); + + /** + * + * @brief This is a callback function which collects all the data from the ECG, BIOZ, PACE and RtoR. It also handles + * @brief Lead On/Off. This function is passed through the argument of max30001_COMMinit(). + * @returns 0-if no error. A non-zero value indicates an error. + * + */ + int max30001_int_handler(void); + + /** + * @brief This is function called from the max30001_int_handler() function and processes all the ECG, BIOZ, PACE + * @brief and the RtoR data and sticks them in appropriate arrays and variables each unsigned 32 bits. + * @param ECG data will be in the array (input): max30001_ECG_FIFO_buffer[] + * @param Pace data will be in the array (input): max30001_PACE[] + * @param RtoRdata will be in the variable (input): max30001_RtoR_data + * @param BIOZ data will be in the array (input): max30001_BIOZ_FIFO_buffer[] + * @param global max30001_ECG_FIFO_buffer[] + * @param global max30001_PACE[] + * @param global max30001_BIOZ_FIFO_buffer[] + * @param global max30001_RtoR_data + * @param global max30001_DCLeadOff + * @param global max30001_ACLeadOff + * @param global max30001_LeadON + * @returns 0-if no error. A non-zero value indicates an error. + * + */ + int max30001_FIFO_LeadONOff_Read(void); + + /** + * @brief This function allows writing to a register. + * @param addr: Address of the register to write to + * @param data: 24-bit data read from the register. + * @returns 0-if no error. A non-zero value indicates an error. + * + */ + int max30001_reg_write(MAX30001_REG_map_t addr, uint32_t data); + + /** + * @brief This function allows reading from a register + * @param addr: Address of the register to read from. + * @param *return_data: pointer to the value read from the register. + * @returns 0-if no error. A non-zero value indicates an error. + * + */ + int max30001_reg_read(MAX30001_REG_map_t addr, uint32_t *return_data); + + /** + * @brief This function enables the DC Lead Off detection. Either ECG or BIOZ can be detected, one at a time. + * @brief Registers Used: CNFG_GEN-0x10 + * @param En_dcloff: BIOZ Digital Lead Off Detection Enable + * @param Ipol: DC Lead Off Current Polarity (if current sources are enabled/connected) + * @param Imag: DC Lead off current Magnitude Selection + * @param Vth: DC Lead Off Voltage Threshold Selection + * @returns 0-if no error. A non-zero value indicates an error. + * + */ + int max30001_Enable_DcLeadOFF_Init(int8_t En_dcloff, int8_t Ipol, int8_t Imag, + int8_t Vth); + + /** + * @brief This function disables the DC Lead OFF feature, whichever is active. + * @returns 0-if no error. A non-zero value indicates an error. + * + */ + int max30001_Disable_DcLeadOFF(void); + + /** + * @brief This function sets up the BIOZ for AC Lead Off test. + * @brief Registers Used: CNFG_GEN-0x10, MNGR_DYN-0x05 + * @param En_bloff: BIOZ Digital Lead Off Detection Enable <CNFG_GEN register> + * @param Bloff_hi_it: DC Lead Off Current Polarity (if current sources are enabled/connected) <MNGR_DYN register> + * @param Bloff_lo_it: DC Lead off current Magnitude Selection <MNGR_DYN register> + * @returns 0-if no error. A non-zero value indicates an error. + * + */ + int max30001_BIOZ_Enable_ACLeadOFF_Init(uint8_t En_bloff, uint8_t Bloff_hi_it, + uint8_t Bloff_lo_it); + + /** + * @brief This function Turns of the BIOZ AC Lead OFF feature + * @brief Registers Used: CNFG_GEN-0x10 + * @returns 0-if no error. A non-zero value indicates an error. + * + */ + int max30001_BIOZ_Disable_ACleadOFF(void); + + /** + * @brief This function enables the Current Gnerator Monitor + * @brief Registers Used: CNFG_BIOZ-0x18 + * @returns 0-if no error. A non-zero value indicates an error. + * + */ + int max30001_BIOZ_Enable_BCGMON(void); + + /** + * + * @brief This function enables the Lead ON detection. Either ECG or BIOZ can be detected, one at a time. + * @brief Also, the en_bioz, en_ecg, en_pace setting is saved so that when this feature is disabled through the + * @brief max30001_Disable_LeadON() function (or otherwise) the enable/disable state of those features can be retrieved. + * @param Channel: ECG or BIOZ detection + * @returns 0-if everything is good. A non-zero value indicates an error. + * + */ + int max30001_Enable_LeadON(int8_t Channel); + + /** + * @brief This function turns off the Lead ON feature, whichever one is active. Also, retrieves the en_bioz, + * @brief en_ecg, en_pace and sets it back to as it was. + * @param 0-if everything is good. A non-zero value indicates an error. + * + */ + int max30001_Disable_LeadON(void); + + /** + * + * @brief This function is toggled every 2 seconds to switch between ECG Lead ON and BIOZ Lead ON detect + * @brief Adjust LEADOFF_SERVICE_TIME to determine the duration between the toggles. + * @param CurrentTime - This gets fed the time by RTC_GetValue function + * + */ + void max30001_ServiceLeadON(uint32_t currentTime); + + /** + * + * @brief This function is toggled every 2 seconds to switch between ECG DC Lead Off and BIOZ DC Lead Off + * @brief Adjust LEADOFF_SERVICE_TIME to determine the duration between the toggles. + * @param CurrentTime - This gets fed the time by RTC_GetValue function + * + */ + void max30001_ServiceLeadoff(uint32_t currentTime); + + /** + * + * @brief This function sets current RtoR values and fmstr values in a pointer structure + * @param hspValMax30001 - Pointer to a structure where to store the values + * + */ + void max30001_ReadHeartrateData(max30001_t *_hspValMax30001); + + /** + * @brief type definition for data interrupt + */ + typedef void (*PtrFunction)(uint32_t id, uint32_t *buffer, uint32_t length); + + /** + * @brief Used to connect a callback for when interrupt data is available + */ + void onDataAvailable(PtrFunction _onDataAvailable); + + static MAX30001 *instance; + +private: + void dataAvailable(uint32_t id, uint32_t *buffer, uint32_t length); + /// interrupt handler for async spi events + static void spiHandler(int events); + /// wrapper method to transmit and recieve SPI data + int SPI_Transmit(const uint8_t *tx_buf, uint32_t tx_size, uint8_t *rx_buf, + uint32_t rx_size); + + /// pointer to mbed SPI object + SPI *spi; + /// is this object the owner of the spi object + bool spi_owner; + /// buffer to use for async transfers + uint8_t buffer[ASYNC_SPI_BUFFER_SIZE]; + /// function pointer to the async callback + event_callback_t functionpointer; + /// callback function when interrupt data is available + PtrFunction onDataAvailableCallback; + +}; // End of MAX30001 Class + +/** + * @brief Preventive measure used to dismiss interrupts that fire too early during + * @brief initialization on INTB line + * + */ +void MAX30001Mid_IntB_Handler(void); + +/** + * @brief Preventive measure used to dismiss interrupts that fire too early during + * @brief initialization on INT2B line + * + */ +void MAX30001Mid_Int2B_Handler(void); + +/** + * @brief Allows Interrupts to be accepted as valid. + * @param state: 1-Allow interrupts, Any-Don't allow interrupts. + * + */ +void MAX30001_AllowInterrupts(int state); + +#endif /* MAX30001_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/MAX30001/MAX30001_RPC.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,477 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include <stdio.h> +#include "StringHelper.h" +#include "MAX30001.h" +#include "Streaming.h" +#include "StringInOut.h" +#include "MAX30001_helper.h" +#include "RpcFifo.h" +#include "RpcServer.h" +#include "Peripherals.h" +#include "DataLoggingService.h" + +/*static int startedEcg = 0; +static int startedBioz = 0; +static int startedCal = 0; +static int startedPace = 0; +static int startedRtor = 0; +static void StopAll(); +*/ + +extern int highDataRate; + +uint32_t max30001_RegRead(MAX30001::MAX30001_REG_map_t addr) { + uint32_t data; + Peripherals::max30001()->max30001_reg_read(addr, &data); + return data; +} + +void max30001_RegWrite(MAX30001::MAX30001_REG_map_t addr, uint32_t data) { + Peripherals::max30001()->max30001_reg_write(addr, data); +} + +int MAX30001_WriteReg(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t args[2]; + uint32_t reply[1]; + uint32_t value; + ProcessArgs32(argStrs, args, sizeof(args) / sizeof(uint32_t)); + + max30001_RegWrite((MAX30001::MAX30001_REG_map_t)args[0], args[1]); + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +int MAX30001_ReadReg(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t args[1]; + uint32_t reply[1]; + uint32_t value; + ProcessArgs32(argStrs, args, sizeof(args) / sizeof(uint32_t)); + value = max30001_RegRead((MAX30001::MAX30001_REG_map_t)args[0]); + reply[0] = value; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +int MAX30001_Rbias_FMSTR_Init(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t args[5]; + uint32_t reply[1]; + uint32_t value; + ProcessArgs32(argStrs, args, sizeof(args) / sizeof(uint32_t)); + + value = Peripherals::max30001()->max30001_Rbias_FMSTR_Init(args[0], // En_rbias + args[1], // Rbiasv + args[2], // Rbiasp + args[3], // Rbiasn + args[4]); // Fmstr + + reply[0] = value; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +int MAX30001_CAL_InitStart(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t args[6]; + uint32_t reply[1]; + uint32_t value; + ProcessArgs32(argStrs, args, sizeof(args) / sizeof(uint32_t)); + + // Peripherals::serial()->printf("MAX30001_CAL_InitStart 0 "); + value = Peripherals::max30001()->max30001_CAL_InitStart(args[0], // En_Vcal + args[1], // Vmag + args[2], // Fcal + args[3], // Thigh + args[4], // Fifty + args[5]); // Vmode + + reply[0] = value; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +int MAX30001_ECG_InitStart(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t args[11]; + uint32_t reply[1]; + uint32_t value; + ProcessArgs32(argStrs, args, sizeof(args) / sizeof(uint32_t)); + + // Peripherals::serial()->printf("MAX30001_ECG_InitStart 0 "); + value = Peripherals::max30001()->max30001_ECG_InitStart(args[0], // En_ecg + args[1], // Openp + args[2], // Openn + args[3], // Pol + args[4], // Calp_sel + args[5], // Caln_sel + args[6], // E_fit + args[7], // Rate + args[8], // Gain + args[9], // Dhpf + args[10]); // Dlpf + // Peripherals::serial()->printf("MAX30001_ECG_InitStart 1 "); + MAX30001_Helper_SetStreamingFlag(eStreaming_ECG, 1); + reply[0] = value; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +int MAX30001_ECGFast_Init(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t args[3]; + uint32_t reply[1]; + uint32_t value; + ProcessArgs32(argStrs, args, sizeof(args) / sizeof(uint32_t)); + + value = Peripherals::max30001()->max30001_ECGFast_Init(args[0], // Clr_Fast + args[1], // Fast + args[2]); // Fast_Th + + reply[0] = value; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +int MAX30001_PACE_InitStart(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t args[9]; + uint32_t reply[1]; + uint32_t value; + ProcessArgs32(argStrs, args, sizeof(args) / sizeof(uint32_t)); + + value = + Peripherals::max30001()->max30001_PACE_InitStart(args[0], // En_pace + args[1], // Clr_pedge + args[2], // Pol + args[3], // Gn_diff_off + args[4], // Gain + args[5], // Aout_lbw + args[6], // Aout + args[7], // Dacp + args[8]); // Dacn + + MAX30001_Helper_SetStreamingFlag(eStreaming_PACE, 1); + reply[0] = value; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +int MAX30001_BIOZ_InitStart(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t args[17]; + uint32_t reply[1]; + uint32_t value; + ProcessArgs32(argStrs, args, sizeof(args) / sizeof(uint32_t)); + + value = Peripherals::max30001()->max30001_BIOZ_InitStart(args[0], // En_bioz + args[1], // Openp + args[2], // Openn + args[3], // Calp_sel + args[4], // Caln_sel + args[5], // CG_mode + args[6], // B_fit + args[7], // Rate + args[8], // Ahpf + args[9], // Ext_rbias + args[10], // Gain + args[11], // Dhpf + args[12], // Dlpf + args[13], // Fcgen + args[14], // Cgmon + args[15], // Cgmag + args[16]); // Phoff + + MAX30001_Helper_SetStreamingFlag(eStreaming_BIOZ, 1); + reply[0] = value; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +int MAX30001_RtoR_InitStart(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t args[9]; + uint32_t reply[1]; + uint32_t value; + ProcessArgs32(argStrs, args, sizeof(args) / sizeof(uint32_t)); + + value = Peripherals::max30001()->max30001_RtoR_InitStart(args[0], // En_rtor + args[1], // Wndw + args[2], // Gain + args[3], // Pavg + args[4], // Ptsf + args[5], // Hoff + args[6], // Ravg + args[7], // Rhsf + args[8]); // Clr_rrint + + MAX30001_Helper_SetStreamingFlag(eStreaming_RtoR, 1); + reply[0] = value; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +int MAX30001_Stop_ECG(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + Peripherals::max30001()->max30001_Stop_ECG(); + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} +int MAX30001_Stop_PACE(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + Peripherals::max30001()->max30001_Stop_PACE(); + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} +int MAX30001_Stop_BIOZ(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + Peripherals::max30001()->max30001_Stop_BIOZ(); + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} +int MAX30001_Stop_RtoR(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + Peripherals::max30001()->max30001_Stop_RtoR(); + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} +int MAX30001_Stop_Cal(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + // max30001_Stop_Cal(); + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +void max30001_ServiceStreaming() { + char ch; + uint32_t val; + USBSerial *usbSerial = Peripherals::usbSerial(); + + fifo_clear(GetStreamOutFifo()); + + SetStreaming(TRUE); + clearOutReadFifo(); + while (IsStreaming() == TRUE) { + + if (fifo_empty(GetStreamOutFifo()) == 0) { + fifo_get32(GetStreamOutFifo(), &val); + + usbSerial->printf("%02X ", val); + + } + if (usbSerial->available()) { + ch = usbSerial->_getc(); + + MAX30001_Helper_Stop(); + SetStreaming(FALSE); + fifo_clear(GetUSBIncomingFifo()); // clear USB serial incoming fifo + fifo_clear(GetStreamOutFifo()); + } + + } +} + +int MAX30001_Start(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + uint32_t all; + fifo_clear(GetUSBIncomingFifo()); + Peripherals::max30001()->max30001_synch(); + // max30001_ServiceStreaming(); + highDataRate = 0; + Peripherals::max30001()->max30001_reg_read(MAX30001::STATUS, &all); + LoggingService_StartLoggingUsb(); + + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +int MAX30001_Stop(char argStrs[32][32], char replyStrs[32][32]) { + /* uint32_t args[1]; + uint32_t reply[1]; + uint32_t value; + //ProcessArgs32(argStrs, args, sizeof(args) / sizeof(uint32_t)); + max30001_StopTest(); + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs);*/ + return 0; +} + +int MAX30001_INT_assignment(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t args[17]; + uint32_t reply[1]; + ProcessArgs32(argStrs, args, sizeof(args) / sizeof(uint32_t)); + /* + printf("MAX30001_INT_assignment "); + printf("%d ",args[0]); + printf("%d ",args[1]); + printf("%d ",args[2]); + printf("%d ",args[3]); + printf("%d ",args[4]); + printf("%d ",args[5]); + printf("%d ",args[6]); + printf("%d ",args[7]); + printf("%d ",args[8]); + printf("%d ",args[9]); + printf("%d ",args[10]); + printf("%d ",args[11]); + printf("%d ",args[12]); + printf("%d ",args[13]); + printf("%d ",args[14]); + printf("%d ",args[15]); + printf("%d ",args[16]); + printf("\n"); + fflush(stdout); + */ + + Peripherals::max30001()->max30001_INT_assignment( + (MAX30001::max30001_intrpt_Location_t)args[0], + (MAX30001::max30001_intrpt_Location_t)args[1], + (MAX30001::max30001_intrpt_Location_t)args[2], + (MAX30001::max30001_intrpt_Location_t)args[3], + (MAX30001::max30001_intrpt_Location_t)args[4], + (MAX30001::max30001_intrpt_Location_t)args[5], + (MAX30001::max30001_intrpt_Location_t)args[6], + (MAX30001::max30001_intrpt_Location_t)args[7], + (MAX30001::max30001_intrpt_Location_t)args[8], + (MAX30001::max30001_intrpt_Location_t)args[9], + (MAX30001::max30001_intrpt_Location_t)args[10], + (MAX30001::max30001_intrpt_Location_t)args[11], + (MAX30001::max30001_intrpt_Location_t)args[12], + (MAX30001::max30001_intrpt_Location_t)args[13], + (MAX30001::max30001_intrpt_Location_t)args[14], + (MAX30001::max30001_intrpt_type_t)args[15], + (MAX30001::max30001_intrpt_type_t)args[16]); + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +int MAX30001_StartTest(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + // ProcessArgs32(argStrs, args, sizeof(args) / sizeof(uint32_t)); + + /*** Set FMSTR over here ****/ + + /*** Set and Start the VCAL input ***/ + /* NOTE VCAL must be set first if VCAL is to be used */ + Peripherals::max30001()->max30001_CAL_InitStart(0b1, 0b1, 0b1, 0b011, 0x7FF, 0b0); + + /**** ECG Initialization ****/ + Peripherals::max30001()->max30001_ECG_InitStart(0b1, 0b1, 0b1, 0b0, 0b10, 0b11, 31, 0b00, 0b00, 0b0, 0b01); + + /***** PACE Initialization ***/ + Peripherals::max30001()->max30001_PACE_InitStart(0b1, 0b0, 0b0, 0b1, 0b000, 0b0, 0b00, 0b0, 0b0); + + /**** BIOZ Initialization ****/ + Peripherals::max30001()->max30001_BIOZ_InitStart( + 0b1, 0b1, 0b1, 0b10, 0b11, 0b00, 7, 0b0, 0b111, 0b0, 0b10, 0b00, 0b00, 0b0001, 0b0, 0b111, 0b0000); + + /*** Set RtoR registers ***/ + Peripherals::max30001()->max30001_RtoR_InitStart( + 0b1, 0b0011, 0b1111, 0b00, 0b0011, 0b000001, 0b00, 0b000, 0b01); + + /*** Set Rbias & FMSTR over here ****/ + Peripherals::max30001()->max30001_Rbias_FMSTR_Init(0b01, 0b10, 0b1, 0b1, 0b00); + + /**** Interrupt Setting ****/ + + /*** Set ECG Lead ON/OFF ***/ + // max30001_ECG_LeadOnOff(); + + /*** Set BIOZ Lead ON/OFF ***/ + // max30001_BIOZ_LeadOnOff(); Does not work yet... + + /**** Do a Synch ****/ + Peripherals::max30001()->max30001_synch(); + + fifo_clear(GetUSBIncomingFifo()); + max30001_ServiceStreaming(); + + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} +/* +static void StopAll() { + if (startedEcg == 1) { + max30001_Stop_ECG(); + } + if (startedCal == 1) { + } + if (startedBioz == 1) { + max30001_Stop_BIOZ(); + } + if (startedPace == 1) { + max30001_Stop_PACE(); + } + if (startedRtor == 1) { + max30001_Stop_RtoR(); + } + startedEcg = 0; + startedBioz = 0; + startedCal = 0; + startedPace = 0; + startedRtor = 0; +} +*/ +/* +// switch to ECG DC Lead ON +max30001_Enable_LeadON(0b01); +// switch to BIOZ DC Lead ON +max30001_Enable_LeadON(0b10); +*/ +int MAX30001_Enable_ECG_LeadON(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + // switch to ECG DC Lead ON + Peripherals::max30001()->max30001_Enable_LeadON(0b01); + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} +int MAX30001_Enable_BIOZ_LeadON(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + // switch to BIOZ DC Lead ON + Peripherals::max30001()->max30001_Enable_LeadON(0b10); + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} +// uint32_t max30001_LeadOn; // This holds the LeadOn data, BIT1 = BIOZ Lead ON, BIT0 = ECG Lead ON +int MAX30001_Read_LeadON(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + // return the max30001_LeadOn var from the MAX30001 driver + reply[0] = Peripherals::max30001()->max30001_LeadOn; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/MAX30001/MAX30001_RPC.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef __MAX300001_RPC_H +#define __MAX300001_RPC_H + +int MAX30001_WriteReg(char argStrs[32][32], char replyStrs[32][32]); +int MAX30001_ReadReg(char argStrs[32][32], char replyStrs[32][32]); +int MAX30001_Start(char argStrs[32][32], char replyStrs[32][32]); +int MAX30001_Stop(char argStrs[32][32], char replyStrs[32][32]); +int MAX30001_Rbias_FMSTR_Init(char argStrs[32][32], char replyStrs[32][32]); +int MAX30001_CAL_InitStart(char argStrs[32][32], char replyStrs[32][32]); +int MAX30001_ECG_InitStart(char argStrs[32][32], char replyStrs[32][32]); +int MAX30001_ECGFast_Init(char argStrs[32][32], char replyStrs[32][32]); +int MAX30001_PACE_InitStart(char argStrs[32][32], char replyStrs[32][32]); +int MAX30001_BIOZ_InitStart(char argStrs[32][32], char replyStrs[32][32]); +int MAX30001_RtoR_InitStart(char argStrs[32][32], char replyStrs[32][32]); +int MAX30001_Stop_ECG(char argStrs[32][32], char replyStrs[32][32]); +int MAX30001_Stop_PACE(char argStrs[32][32], char replyStrs[32][32]); +int MAX30001_Stop_BIOZ(char argStrs[32][32], char replyStrs[32][32]); +int MAX30001_Stop_RtoR(char argStrs[32][32], char replyStrs[32][32]); +int MAX30001_Stop_Cal(char argStrs[32][32], char replyStrs[32][32]); +int MAX30001_Enable_ECG_LeadON(char argStrs[32][32], char replyStrs[32][32]); +int MAX30001_Enable_BIOZ_LeadON(char argStrs[32][32], char replyStrs[32][32]); +int MAX30001_Read_LeadON(char argStrs[32][32], char replyStrs[32][32]); + +int MAX30001_StartTest(char argStrs[32][32], char replyStrs[32][32]); +int MAX30001_INT_assignment(char argStrs[32][32], char replyStrs[32][32]); + +#endif /* __MAX300001_RPC_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/MAX30001/MAX30001_helper.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,122 @@ + +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include "MAX30001_helper.h" +#include "MAX30001.h" +#include "StringInOut.h" +#include "Peripherals.h" + +static uint8_t flags[4]; + +int MAX30001_Helper_IsStreaming(eFlags flag) { + return flags[(uint32_t)flag]; +} + +void MAX30001_Helper_SetStreamingFlag(eFlags flag, uint8_t state) { + flags[(uint32_t)flag] = state; +} + +void MAX30001_Helper_Stop(void) { + if (flags[(uint32_t)eStreaming_ECG] == 1) { + Peripherals::max30001()->max30001_Stop_ECG(); + } + if (flags[(uint32_t)eStreaming_PACE] == 1) { + Peripherals::max30001()->max30001_Stop_PACE(); + } + if (flags[(uint32_t)eStreaming_BIOZ] == 1) { + Peripherals::max30001()->max30001_Stop_BIOZ(); + } + if (flags[(uint32_t)eStreaming_RtoR] == 1) { + Peripherals::max30001()->max30001_Stop_RtoR(); + } + MAX30001_Helper_ClearStreamingFlags(); +} + +int MAX30001_AnyStreamingSet(void) { + uint32_t i; + for (i = 0; i < 4; i++) { + if (flags[i] == 1) return 1; + } + return 0; +} + +void MAX30001_Helper_StartSync(void) { + if (MAX30001_AnyStreamingSet() == 1) { + Peripherals::max30001()->max30001_synch(); + } +} + +void MAX30001_Helper_ClearStreamingFlags(void) { + uint32_t i; + for (i = 0; i < 4; i++) { + flags[i] = 0; + } +} + +void MAX30001_Helper_Debug_ShowStreamFlags(void) { + putStr("\r\n"); + if (flags[(uint32_t)eStreaming_ECG] == 1) { + putStr("eStreaming_ECG, "); + } + if (flags[(uint32_t)eStreaming_PACE] == 1) { + putStr("eStreaming_PACE, "); + } + if (flags[(uint32_t)eStreaming_BIOZ] == 1) { + putStr("eStreaming_BIOZ, "); + } + if (flags[(uint32_t)eStreaming_RtoR] == 1) { + putStr("eStreaming_RtoR, "); + } + putStr("\r\n"); +} + +void MAX30001_Helper_SetupInterrupts() { + Peripherals::max30001()->max30001_INT_assignment(MAX30001::MAX30001_INT_B, MAX30001::MAX30001_NO_INT, MAX30001::MAX30001_NO_INT, // en_enint_loc, en_eovf_loc, en_fstint_loc, + MAX30001::MAX30001_INT_2B, MAX30001::MAX30001_INT_2B, MAX30001::MAX30001_NO_INT, // en_dcloffint_loc, en_bint_loc, en_bovf_loc, + MAX30001::MAX30001_INT_2B, MAX30001::MAX30001_INT_2B, MAX30001::MAX30001_NO_INT, // en_bover_loc, en_bundr_loc, en_bcgmon_loc, + MAX30001::MAX30001_INT_B, MAX30001::MAX30001_NO_INT, MAX30001::MAX30001_NO_INT, // en_pint_loc, en_povf_loc, en_pedge_loc, + MAX30001::MAX30001_INT_2B, MAX30001::MAX30001_INT_B, MAX30001::MAX30001_NO_INT, // en_lonint_loc, en_rrint_loc, en_samp_loc, + MAX30001::MAX30001_INT_ODNR, MAX30001::MAX30001_INT_ODNR); // intb_Type, int2b_Type) +} + + + +static uint8_t serialNumber[6]; +uint8_t *MAX30001_Helper_getVersion(void) { + // read the id + Peripherals::max30001()->max30001_reg_read(MAX30001::INFO, (uint32_t *)serialNumber); + // read id twice because it needs to be read twice + Peripherals::max30001()->max30001_reg_read(MAX30001::INFO, (uint32_t *)serialNumber); + return serialNumber; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/MAX30001/MAX30001_helper.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef MAX30001_HELPER_H_ +#define MAX30001_HELPER_H_ + +#include "mbed.h" + +typedef enum eFlags { + eStreaming_ECG, + eStreaming_PACE, + eStreaming_BIOZ, + eStreaming_RtoR +} eFlags; + +int MAX30001_Helper_IsStreaming(eFlags flag); +void MAX30001_Helper_SetStreamingFlag(eFlags flag, uint8_t state); +void MAX30001_Helper_Stop(void); +void MAX30001_Helper_ClearStreamingFlags(void); +int MAX30001_AnyStreamingSet(void); +void MAX30001_Helper_Debug_ShowStreamFlags(void); +void MAX30001_Helper_StartSync(void); +void MAX30001_Helper_SetupInterrupts(void); +uint8_t *MAX30001_Helper_getVersion(void); + +#endif /* MAX30001_HELPER_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/MAX30101/MAX30101/MAX30101.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,703 @@ + +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include "mbed.h" +#include "MAX30101.h" + +MAX30101 *MAX30101::instance = NULL; + +//****************************************************************************** +MAX30101::MAX30101(PinName sda, PinName scl, int slaveAddress): + slaveAddress(slaveAddress) { + i2c = new I2C(sda, scl); + i2c_owner = true; + i2c->frequency(400000); + onInterruptCallback = NULL; + onDataAvailableCallback = NULL; + instance = this; +} + +//****************************************************************************** +MAX30101::MAX30101(I2C *_i2c, int slaveAddress) : + slaveAddress(slaveAddress) { + i2c = _i2c; + i2c_owner = false; + i2c->frequency(400000); + onInterruptCallback = NULL; + onDataAvailableCallback = NULL; + instance = this; +} + +//****************************************************************************** +MAX30101::~MAX30101(void) { + if (i2c_owner) { + delete i2c; + } +} + +//****************************************************************************** +int MAX30101::int_handler(void) { + uint16_t index, i; + uint16_t rx_bytes, second_rx_bytes; + char temp_int; + char temp_frac; + uint16_t num_active_led; + uint32_t sample; + int loop = 1; + static uint8_t cntr_int = 0; + + + cntr_int++; + + while (loop) { + if (i2c_reg_read(REG_INT_STAT_1, &max30101_Interrupt_Status_1.all) != 0) // Read Interrupt flag bits + { + return -1; + } + + if (i2c_reg_read(REG_INT_STAT_2, &max30101_Interrupt_Status_2.all) != 0) // Read Interrupt flag bits + { + return -1; + } + + if (max30101_Interrupt_Status_1.bit.a_full) { + /* Read the sample(s) */ + char reg = REG_FIFO_DATA; + + num_active_led = 0; + + if (max30101_mode_configuration.bit.mode == 0x02) // Heart Rate mode, i.e. 1 led + { + num_active_led = 1; + } else if (max30101_mode_configuration.bit.mode == 0x03) // SpO2 mode, i.e. 2 led + { + num_active_led = 2; + } else if (max30101_mode_configuration.bit.mode == 0x07) // Multi-LED mode, i.e. 1-4 led + { + if (max30101_multiLED_mode_ctrl_1.bit.slot1 != 0) { + num_active_led++; + } + + if (max30101_multiLED_mode_ctrl_1.bit.slot2 != 0) { + num_active_led++; + } + + if (max30101_multiLED_mode_ctrl_2.bit.slot3 != 0) { + num_active_led++; + } + + if (max30101_multiLED_mode_ctrl_2.bit.slot4 != 0) { + num_active_led++; + } + } + // 3bytes/LED x Number of Active LED x FIFO level selected + rx_bytes = 3 * num_active_led * (32-max30101_fifo_configuration.bit.fifo_a_full); + + second_rx_bytes = rx_bytes; + + /* The FIFO Size is determined by the Sample size. The number of bytes + * in a Sample is dictated by number of LED's + * + * #LED Selected Bytes in "1" sample + * 1 3 + * 2 6 + * 3 9 + * 4 12 + * + * The I2C API function limits the number of bytes to read to 256 (i.e. + * char). Therefore, when set for + * Multiple LED's and the FIFO size is set to 32. It would mean there is + * more than 256 bytes. + * In that case two I2C reads have to be made. However It is important + * to not that each "Sample" + * must be read completely and reading only partial number of bytes from + * a sample will result in erroneous data. + * + * For example: + * Num of LED selected = 3 and FIFO size is set to 32 (i.e. 0 value in + * register), then the number of bytes + * will be 3bytes/Led * 3led's * 32 = 288 bytes in all. Since there are + * 3 LED's each sample will contain (3 * 3) + * 9bytes. Therefore Sample 1 = 9bytes, Sample 2 = 18,... Sample 28 = + * 252. Therefore the first + * I2C read should be 252 bytes and the second read should be 288-252 = + * 36. + * + * It turns out that this size issue comes up only when number of LED + * selected is 3 or 4 and choosing 252bytes + * for the first I2C read would work for both Number of LED selection. + */ + + if (rx_bytes <= CHUNK_SIZE) { + I2CM_Read(slaveAddress, ®, 1, &max30101_rawData[0], + (char)rx_bytes /*total_databytes_1*/); + } else { + I2CM_Read(slaveAddress, ®, 1, &max30101_rawData[0], CHUNK_SIZE); + + second_rx_bytes = second_rx_bytes - CHUNK_SIZE; + I2CM_Read(slaveAddress, ®, 1, &max30101_rawData[CHUNK_SIZE], + (char)second_rx_bytes); + } + + index = 0; + + for (i = 0; i < rx_bytes; i += 3) { + sample = ((uint32_t)(max30101_rawData[i] & 0x03) << 16) | (max30101_rawData[i + 1] << 8) | max30101_rawData[i + 2]; + + // Right shift the data based on the LED_PW setting + sample = sample >> + (3 - + max30101_spo2_configuration.bit.led_pw); // 0=shift 3, 1=shift 2, 2=shift 1, 3=no shift + + max30101_buffer[index++] = sample; + } + + onDataAvailableCallback(MAX30101_OXIMETER_DATA + num_active_led, max30101_buffer, index); + } + +// This interrupt handles the proximity interrupt, for future enhancements +#if 0 + if(max30101_Interrupt_Status_1.bit.prox_int) + { + max30101_mode_configuration.full=0; + max30101_mode_configuration.bit.mode=0x03; // SpO2 mode + i2c_reg_write(REG_MODE_CFG, max30101_mode_configuration.full); + + } +#endif + + // This interrupt handles the temperature interrupt + if (max30101_Interrupt_Status_2.bit.die_temp_rdy) { + char reg; + + reg = REG_TINT; + if (I2CM_Read(slaveAddress, ®, 1, &temp_int, 1) != 0) { + return -1; + } + + reg = REG_TFRAC; + if (I2CM_Read(slaveAddress, ®, 1, &temp_frac, 1) != 0) { + return -1; + } + + max30101_final_temp = (int8_t)temp_int + 0.0625 * temp_frac; + + if (i2c_reg_write(REG_TEMP_EN, 0x00) != 0) // Die Temperature Config, Temp disable... after one read... + { + return -1; + } + } + + if (i2c_reg_read(REG_INT_STAT_1, &max30101_Interrupt_Status_1.all) != 0) // Read Interrupt flag bits + { + return -1; + } + if (max30101_Interrupt_Status_1.bit.a_full != 1) { + loop = 0; + } + } + + interruptPostCallback(); + + + return 0; +} + +//****************************************************************************** +int MAX30101::SpO2mode_init(uint8_t fifo_waterlevel_mark, uint8_t sample_avg, + uint8_t sample_rate, uint8_t pulse_width, + uint8_t red_led_current, uint8_t ir_led_current) { + + char status; + + max30101_mode_configuration.all = 0; + max30101_mode_configuration.bit.reset = 1; + if (i2c_reg_write(REG_MODE_CFG, max30101_mode_configuration.all) != 0) // Reset the device, Mode = don't use... + { + return -1; + } + + /* Give it some settle time (100ms) */ + wait(1.0 / 10.0); // Let things settle down a bit + + max30101_fifo_configuration.all = 0; + max30101_fifo_configuration.bit.smp_ave = sample_avg; // Sample averaging; + max30101_fifo_configuration.bit.fifo_roll_over_en = 1; // FIFO Roll over enabled + max30101_fifo_configuration.bit.fifo_a_full = fifo_waterlevel_mark; // Interrupt when certain level is filled + if (i2c_reg_write(REG_FIFO_CFG, max30101_fifo_configuration.all) != 0) { + return -1; + } + + max30101_spo2_configuration.bit.spo2_adc_rge = 0x2; // ADC Range 8192 fullscale + max30101_spo2_configuration.bit.spo2_sr = sample_rate; // 100 Samp/sec. + max30101_spo2_configuration.bit.led_pw = pulse_width; // Pulse Width=411us and ADC Resolution=18 + if (i2c_reg_write(REG_SPO2_CFG, max30101_spo2_configuration.all) != 0) { + return -1; + } + + max30101_led1_pa = red_led_current; // RED LED current + if (i2c_reg_write(REG_LED1_PA, max30101_led1_pa) != 0) { + return -1; + } + + max30101_led2_pa = ir_led_current; // IR LED current + if (i2c_reg_write(REG_LED2_PA, max30101_led2_pa) != 0) { + return -1; + } + + /************/ + + if (i2c_reg_read(REG_INT_STAT_1, &status) != 0) // Clear INT1 by reading the status + { + return -1; + } + + if (i2c_reg_read(REG_INT_STAT_2, &status) != 0) // Clear INT2 by reading the status + { + return -1; + } + + if (i2c_reg_write(REG_FIFO_W_PTR, 0x00) != 0) // Clear FIFO ptr + { + return -1; + } + + if (i2c_reg_write(REG_FIFO_OVF_CNT, 0x00) != 0) // Clear FIFO ptr + { + return -1; + } + + if (i2c_reg_write(REG_FIFO_R_PTR, 0x00) != 0) // Clear FIFO ptr + { + return -1; + } + + max30101_Interrupt_Enable_1.all = 0; + max30101_Interrupt_Enable_1.bit.a_full_en = 1; // Enable FIFO almost full interrupt + if (i2c_reg_write(REG_INT_EN_1, max30101_Interrupt_Enable_1.all) != 0) { + return -1; + } + + max30101_mode_configuration.all = 0; + max30101_mode_configuration.bit.mode = 0x03; // SpO2 mode + if (i2c_reg_write(REG_MODE_CFG, max30101_mode_configuration.all) != 0) { + return -1; + } + + return 0; +} + +//****************************************************************************** +int MAX30101::SpO2mode_stop(void) { + + max30101_Interrupt_Enable_1.all = 0; + max30101_Interrupt_Enable_1.bit.a_full_en = 0; // Disable FIFO almost full interrupt + if (i2c_reg_write(REG_INT_EN_1, max30101_Interrupt_Enable_1.all) != 0) { + return -1; + } + + max30101_mode_configuration.all = 0; + max30101_mode_configuration.bit.mode = 0x00; // SpO2 mode off + if (i2c_reg_write(REG_MODE_CFG, max30101_mode_configuration.all) != 0) { + return -1; + } + + max30101_led1_pa = 0; // RED LED current, 0.0 + if (i2c_reg_write(REG_LED1_PA, max30101_led1_pa) != 0) { + return -1; + } + + max30101_led2_pa = 0; // IR LED current, 0.0 + if (i2c_reg_write(REG_LED2_PA, max30101_led2_pa) != 0) { + return -1; + } + + return 0; +} + +//****************************************************************************** +int MAX30101::HRmode_init(uint8_t fifo_waterlevel_mark, uint8_t sample_avg, + uint8_t sample_rate, uint8_t pulse_width, + uint8_t red_led_current) { + + /*uint8_t*/ char status; + + max30101_mode_configuration.all = 0; + max30101_mode_configuration.bit.reset = 1; + if (i2c_reg_write(REG_MODE_CFG, max30101_mode_configuration.all) != 0) // Reset the device, Mode = don't use... + { + return -1; + } + + /* Give it some settle time (100ms) */ + wait(1.0 / 10.0); // Let things settle down a bit + + max30101_fifo_configuration.all = 0; + max30101_fifo_configuration.bit.smp_ave = sample_avg; // Sample averaging; + max30101_fifo_configuration.bit.fifo_roll_over_en = 1; // FIFO Roll over enabled + max30101_fifo_configuration.bit.fifo_a_full = fifo_waterlevel_mark; // Interrupt when certain level is filled + if (i2c_reg_write(REG_FIFO_CFG, max30101_fifo_configuration.all) != 0) { + return -1; + } + + max30101_spo2_configuration.bit.spo2_adc_rge = 0x2; // ADC Range 8192 fullscale + max30101_spo2_configuration.bit.spo2_sr = sample_rate; // 100 Samp/sec. + max30101_spo2_configuration.bit.led_pw = pulse_width; // Pulse Width=411us and ADC Resolution=18 + if (i2c_reg_write(REG_SPO2_CFG, max30101_spo2_configuration.all) != 0) { + return -1; + } + + max30101_led1_pa = red_led_current; // RED LED current, 0.0 + if (i2c_reg_write(REG_LED1_PA, max30101_led1_pa) != 0) { + return -1; + } + + /************/ + + if (i2c_reg_read(REG_INT_STAT_1, &status) != 0) // Clear INT1 by reading the status + { + return -1; + } + + if (i2c_reg_read(REG_INT_STAT_2, &status) != 0) // Clear INT2 by reading the status + { + return -1; + } + + if (i2c_reg_write(REG_FIFO_W_PTR, 0x00) != 0) // Clear FIFO ptr + { + return -1; + } + + if (i2c_reg_write(REG_FIFO_OVF_CNT, 0x00) != 0) // Clear FIFO ptr + { + return -1; + } + + if (i2c_reg_write(REG_FIFO_R_PTR, 0x00) != 0) // Clear FIFO ptr + { + return -1; + } + + max30101_Interrupt_Enable_1.all = 0; + max30101_Interrupt_Enable_1.bit.a_full_en = 1; + // max30101_Interrupt_Enable_1.bit.prox_int_en=0; // Enable Proximity + // Interrupt + if (i2c_reg_write(REG_INT_EN_1, max30101_Interrupt_Enable_1.all) != 0) { + return -1; + } + + max30101_mode_configuration.all = 0; + max30101_mode_configuration.bit.mode = 0x02; // HR mode + if (i2c_reg_write(REG_MODE_CFG, max30101_mode_configuration.all) != 0) { + return -1; + } + + return 0; +} + +//****************************************************************************** +int MAX30101::HRmode_stop(void) { + + max30101_Interrupt_Enable_1.all = 0; + max30101_Interrupt_Enable_1.bit.a_full_en = 0; // Disable FIFO almost full interrupt + if (i2c_reg_write(REG_INT_EN_1, max30101_Interrupt_Enable_1.all) != 0) { + return -1; + } + + max30101_mode_configuration.all = 0; + max30101_mode_configuration.bit.mode = 0x00; // HR mode off + if (i2c_reg_write(REG_MODE_CFG, max30101_mode_configuration.all) != 0) { + return -1; + } + + max30101_led1_pa = 0; // RED LED current, 0.0 + if (i2c_reg_write(REG_LED1_PA, max30101_led1_pa) != 0) { + return -1; + } + + return 0; +} + +//****************************************************************************** +int MAX30101::Multimode_init(uint8_t fifo_waterlevel_mark, uint8_t sample_avg, + uint8_t sample_rate, uint8_t pulse_width, + uint8_t red_led_current, uint8_t ir_led_current, + uint8_t green_led_current, uint8_t slot_1, + uint8_t slot_2, uint8_t slot_3, uint8_t slot_4) { + char status; + max30101_mode_configuration.all = 0; + max30101_mode_configuration.bit.reset = 1; + if (i2c_reg_write(REG_MODE_CFG, max30101_mode_configuration.all) != 0) // Reset the device, Mode = don't use... + { + return -1; + } + + /* Give it some settle time (100ms) */ // Let things settle down a bit + wait(1.0 / 10.0); + + max30101_fifo_configuration.all = 0; + max30101_fifo_configuration.bit.smp_ave = sample_avg; // Sample averaging; + max30101_fifo_configuration.bit.fifo_roll_over_en = 1; // FIFO Roll over enabled + max30101_fifo_configuration.bit.fifo_a_full = + fifo_waterlevel_mark; // Interrupt when certain level is filled + if (i2c_reg_write(REG_FIFO_CFG, max30101_fifo_configuration.all) != 0) { + return -1; + } + + max30101_spo2_configuration.bit.spo2_adc_rge = 0x2; // ADC Range 8192 fullscale + max30101_spo2_configuration.bit.spo2_sr = sample_rate; // 100 Samp/sec. + max30101_spo2_configuration.bit.led_pw = pulse_width; // Pulse Width=411us and ADC Resolution=18 + if (i2c_reg_write(REG_SPO2_CFG, max30101_spo2_configuration.all) != 0) { + return -1; + } + + max30101_led1_pa = red_led_current; // RED LED current + if (i2c_reg_write(REG_LED1_PA, max30101_led1_pa) != 0) { + return -1; + } + + max30101_led2_pa = ir_led_current; // IR LED current + if (i2c_reg_write(REG_LED2_PA, max30101_led2_pa) != 0) { + return -1; + } + + max30101_led3_pa = green_led_current; // Green LED current + if (i2c_reg_write(REG_LED3_PA, max30101_led3_pa) != 0) { + return -1; + } + + // 0x01=Red(LED1), 0x02=IR(LED2), 0x03=Green(LED3) : Use LEDn_PA to adjust the intensity + // 0x05=Red , 0x06=IR , 0x07=Green : Use PILOT_PA to adjust the intensity DO NOT USE THIS ROW... + + max30101_multiLED_mode_ctrl_1.bit.slot1 = slot_1; + max30101_multiLED_mode_ctrl_1.bit.slot2 = slot_2; + if (i2c_reg_write(REG_SLT2_SLT1, max30101_multiLED_mode_ctrl_1.all)) { + return -1; + } + + max30101_multiLED_mode_ctrl_2.all = 0; + max30101_multiLED_mode_ctrl_2.bit.slot3 = slot_3; + max30101_multiLED_mode_ctrl_2.bit.slot4 = slot_4; + if (i2c_reg_write(REG_SLT4_SLT3, max30101_multiLED_mode_ctrl_2.all)) { + return -1; + } + + /************/ + + if (i2c_reg_read(REG_INT_STAT_1, &status) != 0) // Clear INT1 by reading the status + { + return -1; + } + + if (i2c_reg_read(REG_INT_STAT_2, &status) != 0) // Clear INT2 by reading the status + { + return -1; + } + + if (i2c_reg_write(REG_FIFO_W_PTR, 0x00) != 0) // Clear FIFO ptr + { + return -1; + } + + if (i2c_reg_write(REG_FIFO_OVF_CNT, 0x00) != 0) // Clear FIFO ptr + { + return -1; + } + + if (i2c_reg_write(REG_FIFO_R_PTR, 0x00) != 0) // Clear FIFO ptr + { + return -1; + } + + max30101_Interrupt_Enable_1.all = 0; + max30101_Interrupt_Enable_1.bit.a_full_en = 1; // Enable FIFO almost full interrupt + if (i2c_reg_write(REG_INT_EN_1, max30101_Interrupt_Enable_1.all) != 0) { + return -1; + } + + max30101_mode_configuration.all = 0; + max30101_mode_configuration.bit.mode = 0x07; // Multi-LED mode + if (i2c_reg_write(REG_MODE_CFG, max30101_mode_configuration.all) != 0) { + return -1; + } + + return 0; +} + +//****************************************************************************** +int MAX30101::Multimode_stop(void) { + + max30101_Interrupt_Enable_1.all = 0; + max30101_Interrupt_Enable_1.bit.a_full_en = 0; // Disable FIFO almost full interrupt + if (i2c_reg_write(REG_INT_EN_1, max30101_Interrupt_Enable_1.all) != 0) { + return -1; + } + + max30101_mode_configuration.all = 0; + max30101_mode_configuration.bit.mode = 0x00; // Multi-LED mode off + if (i2c_reg_write(REG_MODE_CFG, max30101_mode_configuration.all) != 0) { + return -1; + } + + max30101_led1_pa = 0; // RED LED current, 0.0 + if (i2c_reg_write(REG_LED1_PA, max30101_led1_pa) != 0) { + return -1; + } + + max30101_led2_pa = 0; // IR LED current, 0.0 + if (i2c_reg_write(REG_LED2_PA, max30101_led2_pa) != 0) { + return -1; + } + + max30101_led3_pa = 0; // Green LED current, 0.0 + if (i2c_reg_write(REG_LED3_PA, max30101_led3_pa) != 0) { + return -1; + } + return 0; +} + +//****************************************************************************** +int MAX30101::tempread(void) { + max30101_Interrupt_Enable_2.all = 0; + max30101_Interrupt_Enable_2.bit.die_temp_rdy_en = 1; // Enable the Temp Rdy; + if (i2c_reg_write(REG_INT_EN_2, 0x02) != 0) // Interrupt Enable 2, Temperature Interrupt + { + return -1; + } + + if (i2c_reg_write(REG_TEMP_EN, 0x01) != 0) // Die Temperature Config, Temp enable... + { + return -1; + } + return 0; +} + +//****************************************************************************** +int MAX30101::i2c_reg_write(MAX30101_REG_map_t reg, char value) { + char cmdData[2] = {reg, value}; + + if (I2CM_Write(slaveAddress, NULL, 0, cmdData, 2) != 0 /*2*/) { + return -1; + } + + return 0; +} + +//****************************************************************************** +int MAX30101::i2c_reg_read(MAX30101_REG_map_t reg, char *value) { + if (I2CM_Read(slaveAddress, (char *)®, 1, value, 1) != 0 /*1*/) { + return -1; + } + + return 0; +} + +/** +* @brief Read from an I2C device +* @param slaveAddress slave address to use with transaction +* @param writeData pointer of data to write +* @param writeCount number of data to write +* @param readData pointer to buffer to read to +* @param readCount number of bytes to read +*/ +int MAX30101::I2CM_Read(int slaveAddress, char *writeData, char writeCount, + char *readData, char readCount) { + if (writeData != NULL && writeCount != 0) { + i2c->write(slaveAddress, writeData, writeCount, true); + } + if (readData != NULL && readCount != 0) { + i2c->read(slaveAddress, readData, readCount); + } + return 0; +} + +/** +* @brief Write to an I2C device +* @param slaveAddress slave address to use with transaction +* @param writeData pointer of data to write +* @param writeCount1 number of data to write +* @param writeData2 pointer to buffer to read to +* @param writeCount2 number of bytes to read +*/ +int MAX30101::I2CM_Write(int slaveAddress, char *writeData1, char writeCount1, + char *writeData2, char writeCount2) { + if (writeData1 != NULL && writeCount1 != 0) { + i2c->write(slaveAddress, writeData1, writeCount1); + } + if (writeData2 != NULL && writeCount2 != 0) { + i2c->write(slaveAddress, writeData2, writeCount2); + } + return 0; +} + +//****************************************************************************** +void MAX30101::onDataAvailable(DataCallbackFunction _onDataAvailable) { + onDataAvailableCallback = _onDataAvailable; +} + +/** +* @brief Used to notify an external function that interrupt data is available +* @param id type of data available +* @param buffer 32-bit buffer that points to the data +* @param length length of 32-bit elements available +*/ +void MAX30101::dataAvailable(uint32_t id, uint32_t *buffer, uint32_t length) { + if (onDataAvailableCallback != NULL) { + (*onDataAvailableCallback)(id, buffer, length); + } +} + +//****************************************************************************** +void MAX30101::onInterrupt(InterruptFunction _onInterrupt) { + onInterruptCallback = _onInterrupt; +} + +/** +* @brief Executed on interrupt +* @param id type of data available +* @param buffer 32-bit buffer that points to the data +* @param length length of 32-bit elements available +*/ +void MAX30101::interruptPostCallback(void) { + if (onInterruptCallback != NULL) { + (*onInterruptCallback)(); + } +} + +int max30101_enableInterrupts = 0; +/**************************************************************************************************************/ +void MAX30101MidIntHandler(void) { + MAX30101::instance->int_handler(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/MAX30101/MAX30101/MAX30101.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,454 @@ +/******************************************************************************* +/ * Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + *******************************************************************************/ +/* + * max30101.h + * + * Created on: Aug 26, 2015 + * Author: faisal.tariq + */ + +#ifndef _MAX30101_H_ +#define _MAX30101_H_ + +#include "mbed.h" + +#define MAX30101_RAW_DATA_SIZE 3 * 4 * 32 +#define MAX30101_PROC_DATA_SIZE 4 * 32 + +#define MAX30101_OXIMETER_DATA 0x10 + +#define CHUNK_SIZE 252 + +// MAX30101 Register addresses + +#define MAX30101_INT_PORT 4 +#define MAX30101_INT_PIN 0 +#define MAX30101_MASTER_NUM 2 + +/** +* Maxim Integrated MAX30101 Oximeter chip +*/ +class MAX30101 { +public: + float max30101_final_temp; // Global declaration + uint32_t max30101_buffer[MAX30101_PROC_DATA_SIZE]; // final Processed data + char max30101_rawData[MAX30101_RAW_DATA_SIZE]; // raw data from the chip + + typedef enum { // MAX30101 Register addresses + + /*Status */ + REG_INT_STAT_1 = 0x00, + REG_INT_STAT_2 = 0x01, + REG_INT_EN_1 = 0x02, + REG_INT_EN_2 = 0x03, + + REG_FIFO_W_PTR = 0x04, + REG_FIFO_OVF_CNT = 0x05, + REG_FIFO_R_PTR = 0x06, + REG_FIFO_DATA = 0x07, + /* Configuration */ + REG_FIFO_CFG = 0x08, + REG_MODE_CFG = 0x09, + REG_SPO2_CFG = 0x0A, + REG_LED1_PA = 0x0C, + REG_LED2_PA = 0x0D, + REG_LED3_PA = 0x0E, + REG_PILOT_PA = 0x10, + REG_SLT2_SLT1 = 0x11, + REG_SLT4_SLT3 = 0x12, + /* Die Temp */ + REG_TINT = 0x1F, + REG_TFRAC = 0x20, + REG_TEMP_EN = 0x21, + /* Proximity Func */ + REG_PROX_INT_THR = 0x30, + /* Part ID */ + REG_REV_ID = 0xFE, + REG_ID = 0xFF, + } MAX30101_REG_map_t; + + /**********/ + /* STATUS */ + /**********/ + /// @brief STATUS1 (0x00) + union max30101_Interrupt_Status_1_reg { + char all; + struct { + char pwr_rdy : 1; + char reserved : 3; + char prox_int : 1; + char alc_ovf : 1; + char ppg_rdy : 1; + char a_full : 1; + } bit; + } max30101_Interrupt_Status_1; + + /// @brief STATUS2 (0x01) + union max30101_Interrupt_Status_2_reg { + char all; + struct { + char reserved1 : 1; + char die_temp_rdy : 1; + char reserved2 : 6; + } bit; + } max30101_Interrupt_Status_2; + + /// @brief INTERRUPT_ENABLE1 (0x02) + volatile union max30101_Interrupt_Enable_1_reg { + uint8_t all; + struct { + uint8_t reserved1 : 4; + uint8_t prox_int_en : 1; + uint8_t alc_ovf_en : 1; + uint8_t ppg_rdy_en : 1; + uint8_t a_full_en : 1; + } bit; + } max30101_Interrupt_Enable_1; + + /// @brief INTERRUPT_ENABLE2 (0x03) + volatile union max30101_Interrupt_Enable_2_reg { + uint8_t all; + struct { + uint8_t reserved1 : 1; + uint8_t die_temp_rdy_en : 1; + uint8_t reserved2 : 6; + } bit; + } max30101_Interrupt_Enable_2; + + /*********/ + /* FIFO */ + /*********/ + // 0x04 + /// @brief FIFO_WR_PTR (0x04) + volatile union max30101_fifo_wr_ptr_reg { + uint8_t all; + struct { + uint8_t fifo_wr_ptr : 5; + uint8_t reserved1 : 3; + } bit; + } max30101_fifo_wr_ptr; + + /// @brief OVF_COUNTER (0x05) + volatile union max30101_ovf_counter_reg { + uint8_t all; + struct { + uint8_t fifo_ovf_counter : 5; + uint8_t reserved1 : 3; + } bit; + } max30101_ovf_counter_reg; + + /// @brief FIFO_READ_PTR (0x06) + volatile union max30101_fifo_rd_ptr_reg { + uint8_t all; + struct { + uint8_t fifo_rd_ptr : 5; + uint8_t reserved1 : 3; + } bit; + } max30101_fifo_rd_ptr; + + // 0x07 + uint8_t max30101_fifo_data; + + /********************/ + /* Configuration */ + /********************/ + // 0x08 + /// @brief FIFO_CONFIGURATION (0x08) + volatile union max30101_fifo_configuration_reg { + uint8_t all; + struct { + uint8_t fifo_a_full : 4; + uint8_t fifo_roll_over_en : 1; + uint8_t smp_ave : 3; + } bit; + } max30101_fifo_configuration; + + /// @brief MODE_CONFIGURATION (0x09) + volatile union max30101_mode_configuration_reg { + uint8_t all; + struct { + uint8_t mode : 3; + uint8_t reserved1 : 3; + uint8_t reset : 1; + uint8_t shdn : 1; + } bit; + } max30101_mode_configuration; + + /// @brief SPO2_CONGIGURATION (0x0A) + volatile union max30101_spo2_configuration_reg { + uint8_t all; + struct { + uint8_t led_pw : 2; + uint8_t spo2_sr : 3; + uint8_t spo2_adc_rge : 2; + uint8_t reserved1 : 1; + } bit; + } max30101_spo2_configuration; + + /// @brief LED1_PA (0x0C) + uint8_t max30101_led1_pa; + + /// @brief LED2_PA (0x0D) + uint8_t max30101_led2_pa; + + /// @brief LED3_PA (0x0E) + uint8_t max30101_led3_pa; + + /// @brief PILOT_PA (0x10) + uint8_t max30101_pilot_pa; + + volatile union max30101_multiLED_mode_ctrl_1_reg { + uint8_t all; + struct { + uint8_t slot1 : 3; + uint8_t reserved : 1; + uint8_t slot2 : 3; + uint8_t reserved1 : 1; + } bit; + } max30101_multiLED_mode_ctrl_1; + + volatile union max30101_multiLED_mode_ctrl_2_reg { + uint8_t all; + struct { + uint8_t slot3 : 3; + uint8_t reserved : 1; + uint8_t slot4 : 3; + uint8_t reserved1 : 1; + } bit; + } max30101_multiLED_mode_ctrl_2; + + /********************/ + /* Die Temperature */ + /********************/ + + uint8_t max30101_tinit; + + uint8_t max30101_tfrac; + + volatile union max30101_die_temp_config { + uint8_t all; + struct { + uint8_t temp_en : 1; + uint8_t reserved : 7; + } bit; + } max30101_die_temp_config; + /*******************************/ + /***** Function Prototypes *****/ + /*******************************/ + + uint8_t max30101_prox_int_thresh; + + /** + * MAX30101 constructor. + * + * @param sda mbed pin to use for SDA line of I2C interface. + * @param scl mbed pin to use for SCL line of I2C interface. + */ + MAX30101(PinName sda, PinName scl, int slaveAddress); + + /** + * MAX30101 constructor. + * + * @param i2c I2C object to use. + */ + MAX30101(I2C *i2c, int slaveAddress); + + /** + * MAX30101 destructor. + */ + ~MAX30101(void); + + /** + * @brief Allows reading from MAX30101 register + * @param reg: is the register address, to read from (look at max30101.h and the + * data sheet for details) + * @param value: is the pointer to the value read from the register + * @returns 0-if no error. A non-zero value indicates an error. + */ + int i2c_reg_read(MAX30101_REG_map_t reg, char *value); + + /** + * @brief Allows writing to MAX30101 register + * @param reg: is the register address, to read from (look at max30101.h and + * the + * data sheet for details) + * @param value: is the value to write to the register + * @returns 0-if if no error. A non-zero value indicates an error. + */ + int i2c_reg_write(MAX30101_REG_map_t reg, char value); + + /** + * @brief This function sets up for the SpO2 mode. The data is returned in + * the callback function + * @brief max30101_int_handler in global array: buffer[]. SP mode handles two LED (Red,IR) data. Hence it + * @brief can fill up the FIFO up to a maximum of 3bytes/sample x 32 x 2 = 192bytes. + * @param fifo_waterlevel_mark: corresponds to FIFO_A_FULL, In FIFO Configuration Register (0x08) + * @param sample_avg: corresponds to SMP_AVE, in FIFO Configuration Register (0x08) + * @param sample_rate: corresponds to SPO2_SR, IN SpO2 Configuration Register (0x0A) + * @param pulse_width: corresponds to LED_PW in SpO2 Configuration register(0x0A) + * @param red_led_current: corresponds to LED1_PA register (0x0C). Please see data sheet for values + * @param ir_led_current: corresponds to LED2_PA register (0x0D). Please see data sheet for values + * @returns 0-if everything is good. A non-zero value indicates an error. + */ + int SpO2mode_init(uint8_t fifo_waterlevel_mark, uint8_t sample_avg, + uint8_t sample_rate, uint8_t pulse_width, + uint8_t red_led_current, uint8_t ir_led_current); + + /** + * @brief This function will stop the SpO2 mode and turn off all operating LEDâs. + * @return 0-if if no error. A non-zero value indicates an error. + */ + int SpO2mode_stop(void); + + /** + * @brief This function sets up for the HR mode. The data is returned in thecallback function + * @brief max30101_int_handler in global array: buffer[].HR mode handles one LED (Red) data. Hence it can fill + * @brief up the FIFO up to a maximum of 3bytes/sample x 32 = 96bytes. + * @brief fifo_waterlevel_mark: corresponds to FIFO_A_FULL, In FIFO Configuration Register (0x08) + * @param sample_avg: corresponds to SMP_AVE, in FIFO Configuration Register (0x08) + * @param sample_rate:corresponds to SPO2_SR, IN SpO2 Configuration Register (0x0A) + * @param pulse_width: corresponds to LED_PW in SpO2 Configuration Register(0x0A) + * @param red_led_current: corresponds to LED1_PA register (0x0C). Please see data sheet for values + * @returns 0-if if no error. A non-zero value indicates an error. + */ + int HRmode_init(uint8_t fifo_waterlevel_mark, uint8_t sample_avg, + uint8_t sample_rate, uint8_t pulse_width, + uint8_t red_led_current); + + /** + * @brief This function will stop the HR mode and turn off all operating + * LEDâs. + * @return 0-if if no error. A non-zero value indicates an error. + */ + int HRmode_stop(void); + + /** + *@brief This function sets up for the Multi-mode. The data is returned in the callback function max30101_int_handler in global array: + *@brief buffer[]. Multi-LED mode can handle 1 to 4 LED combinations. Hence it can fill up the FIFO up to a maximum of + *@brief 3bytes/sample x 32 x 4 = 384bytes. + *@param fifo_waterlevel_mark: corresponds to FIFO_A_FULL, In FIFO Configuration Register (0x08) + *@param sample_avg: corresponds to SMP_AVE, in FIFO Configuration Register (0x08) + *@param sample_rate:corresponds to SPO2_SR, IN SpO2 Configuration Register (0x0A) + *@param pulse_width: corresponds to LED_PW in SpO2 Configuration register(0x0A) + *@param red_led_current: corresponds to LED1_PA register (0x0C). Please see data sheet for values + *@param ir_led_current: corresponds to LED2_PA register (0x0D). Please see data sheet for values + *@param green_led_current: corresponds to LED3_PA register (0x0E). Please see data sheet for values + *@param slot_1,â¦,slot_4: corresponds to Multi-LED Mode control Registers (0x11-0x12). + *@returns 0-if if no error. A non-zero value indicates an error. + */ + int Multimode_init(uint8_t fifo_waterlevel_mark, uint8_t sample_avg, + uint8_t sample_rate, uint8_t pulse_width, + uint8_t red_led_current, uint8_t ir_led_current, + uint8_t green_led_current, uint8_t slot_1, uint8_t slot_2, + uint8_t slot_3, uint8_t slot_4); + + /** + * @brief This function will stop the Multi-mode and turn off all operating LEDâs. + * @returns 0-if if no error. A non-zero value indicates an error. + */ + int Multimode_stop(void); + + /** + * @brief This is a function that sets up for temperature read and should be called after one of the mode + * @brief has been setup. The data is returned in the callback function max30101_int_handler. This + * @brief function needs to be called every time temperature reading is required. + * @brief Call the temp function after one of the MODES have been started + * @brief Note that the temp is disabled after one read... also, it is not necessary + * @brief to read the temp frequently... + * @returns 0-if if no error. A non-zero value indicates an error. + */ + int tempread(void); + + /** + *@brief This is a callback function which collects the data from the FIFO of the MAX30101 in a 32-bit + *@brief unsigned global array called max30101_buffer[]. Upon every interrupt from the MAX30101, this + *@brief function is called to service the FIFO of the MAX30101. This callback function also services the + *@brief interrupt for the temp data. The temp data is collected in a floating point global variable + *@brief final_temp. + *@param max30101_buffer[], global uint32_t + *@returns 0-if everything is good. A non-zero value indicates an error. + */ + int int_handler(void); + /** + * @brief type definition for data interrupt + */ + typedef void (*DataCallbackFunction)(uint32_t id, uint32_t *buffer, + uint32_t length); + /** + * @brief type definition for general interrupt + */ + typedef void (*InterruptFunction)(); + + /** + * @brief Used to connect a callback for when interrupt data is available + */ + void onInterrupt(InterruptFunction _onInterrupt); + + /** + * @brief Used to connect a callback for when interrupt data is available + */ + void onDataAvailable(DataCallbackFunction _onDataAvailable); + + static MAX30101 *instance; + +private: + /// called when interrupt data is available + void dataAvailable(uint32_t id, uint32_t *buffer, uint32_t length); + /// callback function at the end of the interrupt + void interruptPostCallback(void); + /// callback function when interrupt data is available + DataCallbackFunction onDataAvailableCallback; + /// callback function when interrupt data is available + InterruptFunction onInterruptCallback; + /// Read I2c wrapper method + int I2CM_Read(int slaveAddress, char *writeData, char writeCount, char *readData, char readCount); + /// Write I2c wrapper method + int I2CM_Write(int slaveAddress, char *writeData1, char writeCount1, char *writeData2, char writeCount2); + /// pointer to I2C object + I2C *i2c; + /// flag to track if this object is the owner (created) the I2C object + bool i2c_owner; + /// Device slave address + int slaveAddress; +}; + +/** +* @brief Resets the I2C block, when needed +*/ +extern void I2CM_Init_Reset(uint8_t index, int speed); + + /** + * @brief Used for debugging, if needed + */ +void MAX30101MidIntHandler(void); + +#endif /* _MAX30101_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/MAX30101/MAX30101_RPC.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,272 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include "MAX30101_RPC.h" +#include "StringHelper.h" +#include "MAX30101.h" +#include "Streaming.h" +#include "RpcFifo.h" +#include "RpcServer.h" +#include "StringInOut.h" +#include "MAX30101_helper.h" +#include "LIS2DH.h" +#include "Peripherals.h" +#include "DataLoggingService.h" + +//****************************************************************************** +int MAX30101_WriteReg(char argStrs[32][32], char replyStrs[32][32]) { + uint8_t args[2]; + uint8_t reply[1]; + ProcessArgs(argStrs, args, sizeof(args)); +// Peripherals::max30101()->writeReg(args[0] , args[1]); // pass in the register address and the data + reply[0] = 0x80; + FormatReply(reply, sizeof(reply), replyStrs); + return 0; +} + +//****************************************************************************** +int MAX30101_ReadReg(char argStrs[32][32], char replyStrs[32][32]) { + uint8_t args[1]; + uint8_t reply[1]; + char value; + ProcessArgs(argStrs, args, sizeof(args)); +// Peripherals::max30101()->readReg(args[0] , &value, 1); + reply[0] = (uint8_t)value; + FormatReply(reply, sizeof(reply), replyStrs); + return 0; +} + +//****************************************************************************** +int MAX30101_COMMinit(char argStrs[32][32], char replyStrs[32][32]) +{ + uint8_t args[4]; + uint8_t return_value; + ProcessArgs(argStrs,args,sizeof(args)); + + //return_value = max30101_COMMinit(args[0], args[1], args[2], args[3]); + + strcpy(replyStrs[0],"80"); + return return_value; +} + +//****************************************************************************** +int MAX30101_SpO2mode_stop(char argStrs[32][32], char replyStrs[32][32]) +{ + uint8_t args[4]; + uint8_t return_value; + ProcessArgs(argStrs,args,sizeof(args)); + + //lis2dh_Stop(); + //max30101_SpO2mode_stop(); + Peripherals::max30101()->SpO2mode_stop(); + + strcpy(replyStrs[0],"80"); + return return_value; +} + +//****************************************************************************** +int MAX30101_HRmode_stop(char argStrs[32][32], char replyStrs[32][32]) +{ + uint8_t args[4]; + ProcessArgs(argStrs,args,sizeof(args)); + + //lis2dh_Stop(); + Peripherals::max30101()->HRmode_stop(); + + strcpy(replyStrs[0],"80"); + return 0; +} + +//****************************************************************************** +int MAX30101_Multimode_stop(char argStrs[32][32], char replyStrs[32][32]) +{ + uint8_t args[4]; + ProcessArgs(argStrs,args,sizeof(args)); + + //lis2dh_Stop(); + Peripherals::max30101()->Multimode_stop(); + + strcpy(replyStrs[0],"80"); + return 0; +} + +//****************************************************************************** +void ClearInOutFifos() { + fifo_clear(GetStreamOutFifo()); // clear stream out fifo + fifo_clear(GetUSBIncomingFifo()); // clear USB serial incoming fifo +} + +int highDataRate = 0; +#define MAX30101_200HZ 2 +#define MAX30101_400HZ 3 + +/** +* Adjust the threshold of the Accel based on the data rate +* @lis2dhDataRate Data rate of the accel to determine what would be a good threshold value +*/ +static int adjustAccelThreshold(int lis2dhDataRate) { + int lis2dhFifoThreshold; + lis2dhFifoThreshold = 31; + if (lis2dhDataRate <= LIS2DH_DATARATE_50HZ) lis2dhFifoThreshold = 4; + if (lis2dhDataRate == LIS2DH_DATARATE_100HZ) lis2dhFifoThreshold = 8; + return lis2dhFifoThreshold; +} + +/** +* Evaluate the data rate of the Accel to see if we should stream using a high data rate mode +* @lis2dhDataRate Data rate of the accel to determine if this is a high data rate +*/ +static void adjustHighDataRate(int lis2dhDataRate) { + highDataRate = 0; + if (lis2dhDataRate >= LIS2DH_DATARATE_200HZ) highDataRate = 1; +} + +//****************************************************************************** +int MAX30101_SpO2mode_init(char argStrs[32][32], char replyStrs[32][32]) +{ + uint8_t args[7]; + uint8_t lis2dhDataRate; + uint8_t lis2dhFifoThreshold; + ProcessArgs(argStrs, args, sizeof(args)); + + ClearInOutFifos(); + MAX30101_Helper_SetStreamingFlag(eStreaming_SPO2,1); + Peripherals::max30101()->SpO2mode_init(args[0], args[1], args[2], args[3], args[4], args[5]); + + lis2dhDataRate = args[6]; + lis2dhFifoThreshold = adjustAccelThreshold(lis2dhDataRate); + adjustHighDataRate(lis2dhDataRate); + + Peripherals::lis2dh()->initStart(lis2dhDataRate,lis2dhFifoThreshold); + LoggingService_StartLoggingUsb(); + + strcpy(replyStrs[0],"80"); + return 0; +} + +//****************************************************************************** +int MAX30101_SpO2mode_InitStart(char argStrs[32][32], char replyStrs[32][32]) +{ + uint8_t args[6]; // Size + ProcessArgs(argStrs, args, sizeof(args)); + + ClearInOutFifos(); + MAX30101_Helper_SetStreamingFlag(eStreaming_SPO2,1); + if (args[2] >= MAX30101_200HZ) highDataRate = 1; + Peripherals::max30101()->SpO2mode_init(args[0], args[1], args[2], args[3], args[4], args[5]); + + strcpy(replyStrs[0],"80"); + return 0; +} + +//****************************************************************************** +int MAX30101_HRmode_init(char argStrs[32][32], char replyStrs[32][32]) +{ + uint8_t args[6]; + uint8_t lis2dhDataRate; + uint8_t lis2dhFifoThreshold; + ProcessArgs(argStrs, args, sizeof(args)); + + ClearInOutFifos(); + MAX30101_Helper_SetStreamingFlag(eStreaming_HR,1); + Peripherals::max30101()->HRmode_init(args[0], args[1], args[2], args[3], args[4]); + + lis2dhDataRate = args[5]; + lis2dhFifoThreshold = adjustAccelThreshold(lis2dhDataRate); + adjustHighDataRate(lis2dhDataRate); + + Peripherals::lis2dh()->initStart(lis2dhDataRate,lis2dhFifoThreshold); + LoggingService_StartLoggingUsb(); + strcpy(replyStrs[0],"80"); + return 0; +} + +//****************************************************************************** +int MAX30101_HRmode_InitStart(char argStrs[32][32], char replyStrs[32][32]) +{ + uint8_t args[5]; + ProcessArgs(argStrs, args, sizeof(args)); + + ClearInOutFifos(); + MAX30101_Helper_SetStreamingFlag(eStreaming_HR,1); + if (args[2] >= MAX30101_200HZ) highDataRate = 1; + Peripherals::max30101()->HRmode_init(args[0], args[1], args[2], args[3], args[4]); + strcpy(replyStrs[0],"80"); + return 0; +} + +//****************************************************************************** +int MAX30101_Multimode_init(char argStrs[32][32], char replyStrs[32][32]) +{ + uint8_t args[12]; + uint8_t lis2dhDataRate; + uint8_t lis2dhFifoThreshold; + ProcessArgs(argStrs, args, sizeof(args)); + + ClearInOutFifos(); + + lis2dhDataRate = args[11]; + lis2dhFifoThreshold = adjustAccelThreshold(lis2dhDataRate); + adjustHighDataRate(lis2dhDataRate); + + Peripherals::lis2dh()->initStart(lis2dhDataRate,lis2dhFifoThreshold); + + wait(0.1f); + MAX30101_Helper_SetStreamingFlag(eStreaming_MULTI, 1); + Peripherals::max30101()->Multimode_init(args[0], args[1], args[2], + args[3], args[4], args[5], args[6], + args[7], args[8], args[9], args[10]); + LoggingService_StartLoggingUsb(); + + strcpy(replyStrs[0],"80"); + return 0; +} + +//****************************************************************************** +int MAX30101_Multimode_InitStart(char argStrs[32][32], char replyStrs[32][32]) +{ + uint8_t args[11]; + ProcessArgs(argStrs, args, sizeof(args)); + + ClearInOutFifos(); + MAX30101_Helper_SetStreamingFlag(eStreaming_MULTI, 1); + if (args[2] >= MAX30101_200HZ) highDataRate = 1; + Peripherals::max30101()->Multimode_init(args[0], args[1], args[2], + args[3], args[4], args[5], args[6], + args[7], args[8], args[9], args[10]); + + strcpy(replyStrs[0],"80"); + return 0; +} + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/MAX30101/MAX30101_RPC.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _MAX30101_RPC_H_ +#define _MAX30101_RPC_H_ + +int MAX30101_WriteReg(char argStrs[32][32], char replyStrs[32][32]); +int MAX30101_ReadReg(char argStrs[32][32], char replyStrs[32][32]); +int MAX30101_StreamTest(char argStrs[32][32], char replyStrs[32][32]); +int MAX30101_COMMinit(char argStrs[32][32], char replyStrs[32][32]); +int MAX30101_SpO2mode_init(char argStrs[32][32], char replyStrs[32][32]); +int MAX30101_SpO2mode_InitStart(char argStrs[32][32], char replyStrs[32][32]); +int MAX30101_HRmode_init(char argStrs[32][32], char replyStrs[32][32]); +int MAX30101_HRmode_InitStart(char argStrs[32][32], char replyStrs[32][32]); +int MAX30101_Multimode_init(char argStrs[32][32], char replyStrs[32][32]); +int MAX30101_Multimode_InitStart(char argStrs[32][32], char replyStrs[32][32]); + +int MAX30101_SpO2mode_stop(char argStrs[32][32], char replyStrs[32][32]); +int MAX30101_HRmode_stop(char argStrs[32][32], char replyStrs[32][32]); +int MAX30101_Multimode_stop(char argStrs[32][32], char replyStrs[32][32]); + +#endif /* _MAX30101_RPC_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/MAX30101/MAX30101_helper.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,74 @@ + +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include <stdint.h> +#include "MAX30101_helper.h" +#include "MAX30101.h" +#include "Peripherals.h" + +// int8_t max30101_SpO2mode_stop(void); +// int8_t max30101_HRmode_stop(void); +// int8_t max30101_Multimode_stop(void); + +static uint8_t flags[3]; + +uint8_t MAX30101_Helper_IsStreaming(eMAX30101Flags flag) { + return flags[(uint32_t)flag]; +} + +void MAX30101_Helper_SetStreamingFlag(eMAX30101Flags flag, uint8_t state) { + flags[(uint32_t)flag] = state; +} + +void MAX30101_Helper_Stop(void) { + if (flags[(uint32_t)eStreaming_HR] == 1) { + Peripherals::max30101()->HRmode_stop(); + } + if (flags[(uint32_t)eStreaming_SPO2] == 1) { + Peripherals::max30101()->SpO2mode_stop(); + } + if (flags[(uint32_t)eStreaming_MULTI] == 1) { + Peripherals::max30101()->Multimode_stop(); + } + MAX30101_Helper_ClearStreamingFlags(); +} + +void MAX30101_Helper_ClearStreamingFlags(void) { + uint32_t i; + for (i = 0; i < 3; i++) { + flags[i] = 0; + } +} + +void MAX30101_OnInterrupt(void) { I2CM_Init_Reset(2, 1); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/MAX30101/MAX30101_helper.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef MAX30101_HELPER_H_ +#define MAX30101_HELPER_H_ + +typedef enum eMAX30101Flags { + eStreaming_HR, + eStreaming_SPO2, + eStreaming_MULTI +} eMAX30101Flags; + +uint8_t MAX30101_Helper_IsStreaming(eMAX30101Flags flag); +void MAX30101_Helper_SetStreamingFlag(eMAX30101Flags flag, uint8_t state); +void MAX30101_Helper_Stop(void); +void MAX30101_Helper_ClearStreamingFlags(void); +void MAX30101_OnInterrupt(void); + +#endif /* MAX30101_HELPER_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/MAX30205/MAX30205/MAX30205.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,134 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include "MAX30205.h" + +//****************************************************************************** +MAX30205::MAX30205(PinName sda, PinName scl, int slaveAddress) : + slaveAddress(slaveAddress) { + i2c = new I2C(sda, scl); + isOwner = true; + i2c->frequency(100000); +} + +//****************************************************************************** +MAX30205::MAX30205(I2C *i2c, int slaveAddress) : slaveAddress(slaveAddress) { + this->i2c = i2c; + i2c->frequency(100000); + isOwner = false; +} + +//****************************************************************************** +MAX30205::~MAX30205(void) { + if (isOwner == true) { + delete i2c; + } +} + +//****************************************************************************** +int MAX30205::reg_write(char reg, char value) { + int result; + char cmdData[2] = {(char)reg, value}; + result = i2c->write(slaveAddress, cmdData, 2); + if (result != 0) return -1; + return 0; +} + +//****************************************************************************** +int MAX30205::reg_write16(char reg, uint16_t value) { + int result; + char hi = (value >> 8) & 0xFF; + char lo = value & 0xFF; + char cmdData[3] = {reg, hi, lo}; + result = i2c->write(slaveAddress, cmdData, 3); + if (result != 0) return -1; + return 0; +} + +//****************************************************************************** +int MAX30205::reg_read(char reg, char *value) { + int result; + char cmdData[1] = {reg}; + + result = i2c->write(slaveAddress, cmdData, 1); + if (result != 0) return -1; + result = i2c->read(slaveAddress, value, 1); + if (result != 0) return -1; + return 0; +} + +//****************************************************************************** +int MAX30205::reg_read16(char reg, uint16_t *value) { + int result; + char data[2]; + char cmdData[1] = {reg}; + result = i2c->write(slaveAddress, cmdData, 1); + if (result != 0) return -1; + result = i2c->read(slaveAddress, data, 2); + if (result != 0) return -1; + *value = (data[0] << 8) + data[1]; + return 0; +} + +//****************************************************************************** +int MAX30205::readTemperature(uint16_t *value) { + uint8_t data[2]; + int status; + status = reg_read16(MAX30205_Temperature, (uint16_t *)&data); + *value = (data[0] << 8) + data[1]; + return status; +} + +//****************************************************************************** +float MAX30205::toCelsius(unsigned int rawTemp) { + float val; + float val1, val2; + val1 = (float)(rawTemp >> 8); + val2 = (float)(rawTemp & 0xFF); + val = val2 + (val1 / 256.0f); + return val; +} + +//****************************************************************************** +float MAX30205::toFahrenheit(float temperatureC) { + return temperatureC * 9.0f / 5.0f + 32.0f; +} + +//****************************************************************************** +int MAX30205::reg_THYST_Read(uint16_t *value) { + return reg_read16(MAX30205_THYST, value); +} + +//****************************************************************************** +int MAX30205::reg_THYST_Write(uint16_t value) { + return reg_write16(MAX30205_THYST, value); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/MAX30205/MAX30205/MAX30205.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,162 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef __MAX30205_H_ +#define __MAX30205_H_ + +#include "mbed.h" + +/** + * Driver for the MAX30205 on the HSP Platform + * + * @code + * #include <stdio.h> + * #include "mbed.h" + * #include "xxx.h" + * + * I2C i2c(I2C_SDA, I2C_SCL); + * xxx xxx(&i2c); + * + * int main(void) { + * printf("Initialized xxx\n"); + * while(1) { + * if (xxx.init() != 0) { + * printf("Error communicating with xxx\n"); + * } else { + * printf("Initialized xxx\n"); + * break; + * } + * wait(1); + * } + * + * while(1) { + * printf(""); + * wait(1); + * } + * } + * @endcode + */ + +class MAX30205 { +public: + /// MAX30205 Register Addresses + typedef enum Registers { + MAX30205_Temperature = 0x00, + MAX30205_Configuration = 0x01, + MAX30205_THYST = 0x02, + MAX30205_TOS = 0x03 + }; + + /** + * @brief Constructor using I2C PinNames + * @param sda Pinname for sda + * @param scl Pinname for scl + */ + MAX30205(PinName sda, PinName scl, int slaveAddress); + /** + * @brief Constructor using pointer to I2C object + * @param *i2c Pointer to I2C object + */ + MAX30205(I2C *i2c, int slaveAddress); + + /** @brief Destructor */ + ~MAX30205(void); + + /** @brief Write a register into device at slave address + * @param reg register address + * @param value value to write + */ + int reg_write(char reg, char value); + + /** + * @brief Detect the second instance of the MAX30205 + * @param reg register address + * @param value 8-bit value to writes + */ + int reg_read(char reg, char *value); + + /** + * @brief Write a 16-bit value into device at slave address + * @param reg register address + * @param value 16-bit value to write + */ + int reg_write16(char reg, uint16_t value); + + /** + * @brief Read a 16-bit value from a device at a slave address + * @param reg register address + * @param value pointer to store read value + */ + int reg_read16(char reg, uint16_t *value); + + /** + * @brief Read the temperature from the device into a 16 bit value + * @param value pointer to a 16 bit short + */ + int readTemperature(uint16_t *value); + + /** + * @brief Read the THYST value from a specified device instance + * @param value 16-bit pointer of value to read into + */ + int reg_THYST_Read(uint16_t *value); + + /** + * @brief Write the THYST to a device instance + * @param value 16-bit value to write + */ + int reg_THYST_Write(uint16_t value); + + /** + * @brief Convert a raw temperature value into a float + * @param rawTemp raw temperature value to convert + * @return the convereted value in degrees C + */ + float toCelsius(unsigned int rawTemp); + + /** + * @brief Convert the passed in temperature in C to Fahrenheit + * @param temperatureC Temperature in C to convert + * @returns Returns the converted Fahrenheit value + */ + float toFahrenheit(float temperatureC); + +private: + /// I2C pointer + I2C *i2c; + /// Is this object the owner of the I2C object + bool isOwner; + /// Device slave address + int slaveAddress; +}; + +#endif /* __MAX30205_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/MAX30205/MAX30205_RPC.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include "MAX30205_RPC.h" +#include "StringHelper.h" +#include "MAX30205.h" +#include "Peripherals.h" +#include "Device_Logging.h" +#include "RpcServer.h" + +extern Device_Logging *bmp280_Logging; +extern Device_Logging *MAX30205_0_Logging; +extern Device_Logging *MAX30205_1_Logging; + +//****************************************************************************** +int MAX30205_1_InitStart(char argStrs[32][32], char replyStrs[32][32]) { + uint8_t args[1]; + uint8_t reply[1]; + ProcessArgs(argStrs, args, sizeof(args)); + MAX30205_0_Logging->initStart(args[0]); + reply[0] = 0x80; + FormatReply(reply, sizeof(reply), replyStrs); + return 0; +} + +//****************************************************************************** +int MAX30205_2_InitStart(char argStrs[32][32], char replyStrs[32][32]) { + uint8_t args[1]; + uint8_t reply[1]; + ProcessArgs(argStrs, args, sizeof(args)); + MAX30205_1_Logging->initStart(args[0]); + reply[0] = 0x80; + FormatReply(reply, sizeof(reply), replyStrs); + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/MAX30205/MAX30205_RPC.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _MAX30205_RPC_H_ +#define _MAX30205_RPC_H_ + +#include "mbed.h" + +/** Start Temperature logging or Streaming at a specified seconds rate, MAX30205 Top Temp Sensor +*/ +int MAX30205_1_InitStart(char argStrs[32][32], char replyStrs[32][32]); +/** Start Temperature logging or Streaming at a specified seconds rate, MAX30205 Bottom Temp Sensor +*/ +int MAX30205_2_InitStart(char argStrs[32][32], char replyStrs[32][32]); + +#endif /* _MAX30205_RPC_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/PushButton/PushButton.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include "PushButton.h" +#include "Peripherals.h" + +void pb_hit_interrupt_fall(void); + +PushButton::PushButton(PinName pin) : interruptButton(pin) { + this->pin = pin; + + interruptButton.mode(PullUp); + // Delay for initial pullup to take effect + wait(0.01f); + // Attach the address of the interrupt handler routine for pushbutton + interruptButton.fall(&pb_hit_interrupt_fall); +} + +bool PushButton::GetButtonFallState(void) { + return buttonFallState; +} + +void PushButton::SetButtonFallState(bool state) { + buttonFallState = state; +} + +void PushButton::clearButtonFallState(void) { + buttonFallState = false; +} + +int PushButton::Read(void) { + return interruptButton.read(); +} + +void pb_hit_interrupt_fall(void) { + if (Peripherals::pushButton() != NULL) + Peripherals::pushButton()->SetButtonFallState(true); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/PushButton/PushButton.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _PUSHBUTTON_H +#define _PUSHBUTTON_H + +#include "mbed.h" + +class PushButton { +public: + /** + * @brief Constructor with a PinName + */ + PushButton(PinName pin); + /** + * @brief Get the pushed state of the button + */ + bool GetButtonFallState(void); + /** + * @brief Clear the pushed state of the button + */ + void clearButtonFallState(void); + /** + * @brief Read the button input + * @return Represented as 0 or 1 (int) + */ + int Read(void); + /** + * @brief Set the state + * @param state Set the button state to this value + */ + void SetButtonFallState(bool state); + +private: + InterruptIn interruptButton; + bool buttonFallState; + PinName pin; +}; + +#endif /* _PUSHBUTTON_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/S25FS256/S25FS512.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,472 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +// +// Flash Non-Volatile Memory +// U27 S25FS512 +// Nimitz SPIM1 +// + +#include "mbed.h" +#include "S25FS512.h" +#include "QuadSpiInterface.h" + +#define IOMUX_IO_ENABLE 1 + +#define S25FS512_SPI_PORT 1 +#define S25FS512_CS_PIN 0 +#define S25FS512_CS_POLARITY 0 +#define S25FS512_CS_ACTIVITY_DELAY 0 +#define S25FS512_CS_INACTIVITY_DELAY 0 +#define S25FS512_CLK_HI 4 +#define S25FS512_CLK_LOW 4 +#define S25FS512_ALT_CLK 0 +#define S25FS512_CLK_POLARITY 0 +#define S25FS512_CLK_PHASE 0 +#define S25FS512_WRITE 1 +#define S25FS512_READ 0 + +#define INT_PORT_B 3 +#define INT_PIN_B 6 + +uint8_t flashBuffer[257 + 10]; + +//****************************************************************************** +S25FS512::S25FS512(QuadSpiInterface *_quadSpiInterface) { + this->quadSpiInterface = _quadSpiInterface; +} + +//****************************************************************************** +S25FS512::~S25FS512(void) { +} + +//****************************************************************************** +int S25FS512::init(void) { + setQuadMode(); + return 0; +} + +//****************************************************************************** +int S25FS512::wren4Wire(void) { + uint8_t cmdArray[8]; + // Send WREN + cmdArray[0] = 0x06; + wait_1mS(); + return reg_write_read_multiple_4Wire(cmdArray, 1, flashBuffer, 1); +} + +//****************************************************************************** +uint8_t S25FS512::wren(void) { + uint8_t cmdArray[8]; + // Send WREN + cmdArray[0] = 0x06; + wait_1mS(); + return reg_write_read_multiple_quad(cmdArray, 1, flashBuffer, 0); +} + +//****************************************************************************** +int8_t S25FS512::reg_write_read_multiple_quad_last(uint8_t *bufferOut, + uint8_t numberOut, + uint8_t *bufferIn, + uint8_t numberIn, + uint8_t last) { + int32_t success = 0; + + success = quadSpiInterface->SPI_Transmit( + bufferOut, numberOut, + bufferIn, numberIn, (int)last); + + if (success != 0) return -1; + return 0; +} + +//****************************************************************************** +int8_t S25FS512::reg_write_read_multiple_4Wire(uint8_t *bufferOut, + uint8_t numberOut, + uint8_t *bufferIn, + uint8_t numberIn) { + int32_t success = 0; + success = quadSpiInterface->SPI_Transmit4Wire(bufferOut, numberOut, bufferIn, + numberIn, (int)1); + + if (success != 0) return -1; + return 0; +} + +//****************************************************************************** +int8_t S25FS512::reg_write_read_multiple_quad(uint8_t *bufferOut, + uint8_t numberOut, + uint8_t *bufferIn, + uint8_t numberIn) { + int8_t ret; + ret = reg_write_read_multiple_quad_last(bufferOut, numberOut, bufferIn, + numberIn, 1); + return ret; +} + +//****************************************************************************** +void S25FS512::readID(uint8_t *id) { + uint8_t cmd = 0x9F; + reg_write_read_multiple_quad(&cmd, 1, id, 4); +} + +//****************************************************************************** +int8_t S25FS512::writeAnyRegister(uint32_t address, uint8_t data) { + uint8_t cmdArray[5]; + cmdArray[0] = 0x71; + cmdArray[1] = (address >> 16) & 0xFF; + cmdArray[2] = (address >> 8) & 0xFF; + cmdArray[3] = (address >> 0) & 0xFF; + cmdArray[4] = data; + return reg_write_read_multiple_quad(cmdArray, 5, flashBuffer, 0); +} + +int8_t S25FS512::writeAnyRegister4Wire(uint32_t address, uint8_t data) { + uint8_t cmdArray[5]; + cmdArray[0] = 0x71; + cmdArray[1] = (address >> 16) & 0xFF; + cmdArray[2] = (address >> 8) & 0xFF; + cmdArray[3] = (address >> 0) & 0xFF; + cmdArray[4] = data; + return reg_write_read_multiple_4Wire(cmdArray, 5, flashBuffer, 5); +} + +//****************************************************************************** +int8_t S25FS512::writeRegisters(void) { + uint8_t cmdArray[3]; + wait_1mS(); + cmdArray[0] = 0x01; + cmdArray[1] = 0x00; + cmdArray[2] = 0x02; // set Quad to 1 + reg_write_read_multiple_quad(cmdArray, 3, flashBuffer, 0); + return 0; +} + +//****************************************************************************** +int8_t S25FS512::readAnyRegister(uint32_t address, uint8_t *data, + uint32_t length) { + uint8_t cmdArray[4]; + cmdArray[0] = 0x65; + cmdArray[1] = (address >> 16) & 0xFF; + cmdArray[2] = (address >> 8) & 0xFF; + cmdArray[3] = (address >> 0) & 0xFF; + return reg_write_read_multiple_quad(cmdArray, 4, data, length); +} + +//****************************************************************************** +int8_t S25FS512::bulkErase(void) { + uint8_t cmdArray[1]; + cmdArray[0] = 0x60; + return reg_write_read_multiple_quad(cmdArray, 1, flashBuffer, 0); +} + +//****************************************************************************** +int8_t S25FS512::pageProgram(uint32_t address, uint8_t *buffer) { + uint32_t i; + uint8_t cmdArray[5 + 256]; + uint8_t *ptr; + + // for (i = 0; i < 256; i++) { + // dataArray[i] = i; + //} + cmdArray[0] = 0x02; // 0x71; + // cmdArray[1] = (address >> 24) & 0xFF; + cmdArray[1] = (address >> 16) & 0xFF; + cmdArray[2] = (address >> 8) & 0xFF; + cmdArray[3] = (address >> 0) & 0xFF; + for (i = 0; i < 256; i++) { + cmdArray[4 + i] = buffer[i]; + } + // reg_write_read_multiple_quad(cmdArray,256 + 4,flashBuffer,256 + 4); + + ptr = cmdArray; + reg_write_read_multiple_quad_last(ptr, 4 + 64, flashBuffer, 0, 0); + wait_1mS(); + ptr += (4 + 64); + reg_write_read_multiple_quad_last(ptr, 64, flashBuffer, 0, 0); + wait_1mS(); + ptr += 64; + reg_write_read_multiple_quad_last(ptr, 64, flashBuffer, 0, 0); + wait_1mS(); + ptr += 64; + reg_write_read_multiple_quad_last(ptr, 64, flashBuffer, 0, 1); + wait_1mS(); + return 0; +} + +//****************************************************************************** +int8_t S25FS512::quadIoRead_Pages(uint32_t address, uint8_t *buffer, + uint32_t numberOfPages) { + uint8_t cmdArray[5]; + uint8_t *ptr; + uint8_t last; + uint32_t i; + + cmdArray[0] = 0xEB; + cmdArray[1] = (address >> 16) & 0xFF; + cmdArray[2] = (address >> 8) & 0xFF; + cmdArray[3] = (address >> 0) & 0xFF; + ptr = buffer; + last = 0; + // only send the command + reg_write_read_multiple_quad_last(cmdArray, 4, ptr, 0, 0); + wait_1mS(); + reg_write_read_multiple_quad_last(cmdArray, 0, ptr, 5, 0); + wait_1mS(); + for (i = 0; i < numberOfPages; i++) { + reg_write_read_multiple_quad_last(cmdArray, 0, ptr, 64, 0); + wait_1mS(); + ptr += 64; + reg_write_read_multiple_quad_last(cmdArray, 0, ptr, 64, 0); + wait_1mS(); + ptr += 64; + reg_write_read_multiple_quad_last(cmdArray, 0, ptr, 64, 0); + wait_1mS(); + ptr += 64; + // check if this is the last page + if ((i + 1) == numberOfPages) { + last = 1; + } + reg_write_read_multiple_quad_last(cmdArray, 0, ptr, 64, last); + wait_1mS(); + ptr += 64; + } + return 0; +} + +//****************************************************************************** +int8_t S25FS512::checkBusy(void) { + uint8_t cmdArray[5]; + cmdArray[0] = 0x05; + reg_write_read_multiple_quad(cmdArray, 1, flashBuffer, 2); + return flashBuffer[1] & 0x1; +} + +//****************************************************************************** +void S25FS512::waitTillNotBusy(void) { + while (checkBusy() == 1) { + } +} + +//****************************************************************************** +int8_t S25FS512::sectorErase(uint32_t address) { + uint8_t cmdArray[5]; + cmdArray[0] = 0xD8; + cmdArray[1] = (address >> 16) & 0xFF; + cmdArray[2] = (address >> 8) & 0xFF; + cmdArray[3] = (address >> 0) & 0xFF; + return reg_write_read_multiple_quad(cmdArray, 4, flashBuffer, 0); +} + +//****************************************************************************** +int8_t S25FS512::parameterSectorErase(uint32_t address) { + uint8_t cmdArray[5]; + cmdArray[0] = 0x20; + cmdArray[1] = (address >> 16) & 0xFF; + cmdArray[2] = (address >> 8) & 0xFF; + cmdArray[3] = (address >> 0) & 0xFF; + reg_write_read_multiple_quad(cmdArray, 4, flashBuffer, 0); + return 0; +} + +#define ONE_MS (32768 / 500) +#define ONEHUNDRED_US (32768 / 1000) +#define TEM_MS (32768 / 50) + +//****************************************************************************** +void S25FS512::wait_1mS(void) { + wait_ms(1); +} + +//****************************************************************************** +void S25FS512::wait_100uS(void) { +wait_us(100); +} + +//****************************************************************************** +void S25FS512::wait_10mS(void) { +wait_ms(10); +} + +//****************************************************************************** +int8_t S25FS512::readIdentification(uint8_t *dataArray, uint8_t length) { + // 4QIOR = 0x9F + uint8_t cmdArray[1]; + cmdArray[0] = 0x9F; // read ID command + return reg_write_read_multiple_quad(cmdArray, 1, dataArray, length); +} + +//****************************************************************************** +uint8_t S25FS512::reset(void) { + uint8_t cmdArray[8]; + wait_1mS(); + cmdArray[0] = 0x66; + reg_write_read_multiple_quad(cmdArray, 1, flashBuffer, 0); + wait_1mS(); + cmdArray[0] = 0x99; + reg_write_read_multiple_quad(cmdArray, 1, flashBuffer, 0); + return 0; +} + +//****************************************************************************** +uint8_t S25FS512::enableHWReset(void) { + uint8_t data[8]; + wait_1mS(); + // CR2V Configuration Register-2 Volatile + // bit 5 + readAnyRegister(0x00800003, data, 8); + writeAnyRegister(0x00800003, 0x64); + return 0; +} + +//****************************************************************************** +uint8_t S25FS512::detect(void) { + uint8_t array[8]; + uint8_t array2[8]; + + // Send WREN + wren(); + // Send WREN + wren(); + // delay + wait_1mS(); + // Send WREN + wren(); + // delay + wait_1mS(); + + // Send write any register cmd + writeAnyRegister(0x0003, 0x48); + // delay + wait_1mS(); + array[0] = 0x9F; // read ID command + reg_write_read_multiple_quad(array, 1, array2, 7); + return 0; +} + +//****************************************************************************** +int S25FS512::setQuadMode(void) { + wait_1mS(); + wren4Wire(); + wait_1mS(); + writeAnyRegister4Wire(0x800002, 0x02); // set Quad = 1 + wait_1mS(); + wren4Wire(); + wait_1mS(); + writeAnyRegister4Wire(0x800003, 0x48); // set 8 latency, set QPI 4-4-4 +} + +//****************************************************************************** +uint32_t S25FS512::isPageEmpty(uint8_t *ptr) { + int i; + for (i = 0; i < 256; i++) { + if (ptr[i] != 0xFF) + return 0; + } + return 1; +} + +//****************************************************************************** +int8_t S25FS512::parameterSectorErase_Helper(uint32_t address) { + waitTillNotBusy(); + wait_100uS(); + wren(); + wait_100uS(); + parameterSectorErase(address); + wait_100uS(); + waitTillNotBusy(); + wait_100uS(); + return 0; +} + +//****************************************************************************** +int8_t S25FS512::sectorErase_Helper(uint32_t address) { + waitTillNotBusy(); + wait_100uS(); + wren(); + wait_100uS(); + if (address < 0x8000) { + parameterSectorErase(address); + } else { + sectorErase(address); + } + wait_100uS(); + waitTillNotBusy(); + wait_100uS(); + return 0; +} + +//****************************************************************************** +int8_t S25FS512::bulkErase_Helper(void) { + waitTillNotBusy(); + wait_100uS(); + wren(); + wait_100uS(); + bulkErase(); + wait_100uS(); + waitTillNotBusy(); + wait_100uS(); + return 0; +} + +//****************************************************************************** +// write a page worth of data (256 bytes) from buffer, offset defined where in +// the buffer to begin write +int8_t S25FS512::writePage_Helper(uint32_t pageNumber, uint8_t *buffer, + uint32_t offset) { + uint8_t *ptr; + waitTillNotBusy(); + wait_1mS(); + wren(); + ptr = &buffer[offset]; + wait_1mS(); + pageProgram(pageNumber << 8, ptr); + wait_1mS(); + return 0; +} + +//****************************************************************************** +// read pages from flash into buffer, offset defined where in the buffer use +int8_t S25FS512::readPages_Helper(uint32_t startPageNumber, + uint32_t endPageNumber, uint8_t *buffer, + uint32_t offset) { + uint8_t *ptr; + uint32_t page; + ptr = &buffer[offset]; + for (page = startPageNumber; page <= endPageNumber; page++) { + wait_100uS(); + quadIoRead_Pages((uint32_t)(page << 8), (uint8_t *)ptr, 1); + ptr += 0x100; + } + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/S25FS256/S25FS512.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,127 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef S25FS512_H_ +#define S25FS512_H_ + +#include "mbed.h" +#include "QuadSpiInterface.h" + +class S25FS512 { +public: + S25FS512(QuadSpiInterface *_quadSpiInterface); + ~S25FS512(void); + + QuadSpiInterface *quadSpiInterface; + + /** Initialize the driver + */ + int init(void); + + /** Detect the presence of the flash device + */ + uint8_t detect(void); + + /** Read the identification of the flash + */ + int8_t readIdentification(uint8_t *dataArray, uint8_t length); + + /** Bulk erase the flash device + */ + int8_t bulkErase_Helper(void); + + /** Erase Parameter Sectors + */ + int8_t parameterSectorErase_Helper(uint32_t address); + + /** Write a Page + */ + int8_t writePage_Helper(uint32_t pageNumber, uint8_t *buffer, + uint32_t offset); + + /** Read a Page + * @param + */ + int8_t readPages_Helper(uint32_t startPageNumber, uint32_t endPageNumber, + uint8_t *buffer, uint32_t offset); + + /** Erase a Sector + @param address Address of sector to erase + */ + + int8_t sectorErase_Helper(uint32_t address); + /** Scans through byte pointer for a page worth of data to see if the page is all FFs + @param ptr Byte pointer to buffer to scan + @return Returns a 1 if the page is empty, 0 if it is not all FFs + */ + uint32_t isPageEmpty(uint8_t *ptr); + + /** Issue a software reset to the flash device + */ + + uint8_t reset(void); + /** Enable a hardware reset + */ + + uint8_t enableHWReset(void); + /** Read the id byte of this device + */ + + void readID(uint8_t *id); + +private: + int8_t reg_write_read_multiple_quad_last(uint8_t *dataIn, uint8_t numberIn, uint8_t *dataOut, uint8_t numberOut, uint8_t last); + int8_t reg_write_read_multiple_quad(uint8_t *dataIn, uint8_t numberIn, uint8_t *dataOut, uint8_t numberOut); + int8_t reg_write_read_multiple_4Wire(uint8_t *bufferOut, uint8_t numberOut, uint8_t *bufferIn, uint8_t numberIn); + uint8_t spiWriteRead (uint8_t writeNumber,uint8_t *writeData, uint8_t readNumber, uint8_t *readData); + uint8_t spiWriteRead4Wire(uint8_t writeNumber,uint8_t *writeData, uint8_t readNumber, uint8_t *readData); + + int8_t writeAnyRegister(uint32_t address, uint8_t data); + int8_t writeAnyRegister4Wire(uint32_t address, uint8_t data); + int8_t writeRegisters(void); + uint8_t wren(void); + int setQuadMode(void); + int wren4Wire(void); + // int8_t setQuadMode(); + int8_t readAnyRegister(uint32_t address, uint8_t *data, uint32_t length); + int8_t bulkErase(void); + int8_t pageProgram(uint32_t address, uint8_t *buffer); + int8_t quadIoRead_Pages(uint32_t address, uint8_t *buffer, uint32_t numberOfPages); + int8_t checkBusy(void); + void waitTillNotBusy(void); + int8_t sectorErase(uint32_t address); + int8_t parameterSectorErase(uint32_t address); + void wait_1mS(void); + void wait_100uS(void); + void wait_10mS(void); +}; +#endif /* S25FS512_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/S25FS256/S25FS512_RPC.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,122 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include "S25FS512_RPC.h" +#include "S25FS512.h" +#include "StringInOut.h" +#include "StringHelper.h" +#include "Peripherals.h" + +int S25FS512_Reset(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + Peripherals::s25FS512()->reset(); + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +int S25FS512_EnableHWReset(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + Peripherals::s25FS512()->enableHWReset(); + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +int S25FS512_SpiWriteRead(char argStrs[32][32], char replyStrs[32][32]) { + uint8_t args[16]; + uint8_t reply[16]; + uint8_t writeNumber; + uint8_t readNumber; + // get the number of bytes to write + ProcessArgs(argStrs, args, 1); + writeNumber = args[0]; + ProcessArgs(argStrs, args, writeNumber + 2); + readNumber = args[writeNumber + 1]; + FormatReply(reply, readNumber, replyStrs); + return 0; +} + +int S25FS512_SpiWriteRead4Wire(char argStrs[32][32], char replyStrs[32][32]) { + uint8_t args[16]; + uint8_t reply[16]; + uint8_t writeNumber; + uint8_t readNumber; + // get the number of bytes to write + ProcessArgs(argStrs, args, 1); + writeNumber = args[0]; + ProcessArgs(argStrs, args, writeNumber + 2); + readNumber = args[writeNumber + 1]; + FormatReply(reply, readNumber, replyStrs); + return 0; +} + +int S25FS512_ReadPage(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t args[2]; + uint32_t reply[1]; + ProcessArgs32(argStrs, args, sizeof(args) / sizeof(uint32_t)); + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +int S25FS512_ReadPagesBinary(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t args[2]; + uint32_t reply[1]; + uint8_t pageData[256]; + + uint32_t startPage; + uint32_t endPage; + uint32_t page; + + ProcessArgs32(argStrs, args, sizeof(args) / sizeof(uint32_t)); + startPage = args[0]; + endPage = args[1]; + for (page = startPage; page <= endPage; page++) { + Peripherals::s25FS512()->readPages_Helper(page, page, pageData, 0); + putBytes256Block(pageData, 1); + } + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +int S25FS512_ReadId(char argStrs[32][32], char replyStrs[32][32]) { + char str[32]; + uint8_t data[128]; + Peripherals::s25FS512()->readIdentification(data, sizeof(data)); + Peripherals::s25FS512()->readIdentification(data, sizeof(data)); + sprintf(str, "%02X%02X%02X%02X", data[0], data[1], data[2], data[3]); + strcpy(replyStrs[0], str); + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Devices/S25FS256/S25FS512_RPC.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _S25FS512_RPC_H_ +#define _S25FS512_RPC_H_ + +#include "mbed.h" + +int S25FS512_ReadPagesBinary(char argStrs[32][32], char replyStrs[32][32]); +int S25FS512_ReadPage(char argStrs[32][32], char replyStrs[32][32]); +int S25FS512_ReadPagesBinary(char argStrs[32][32], char replyStrs[32][32]); +int S25FS512_ReadId(char argStrs[32][32], char replyStrs[32][32]); +int S25FS512_Reset(char argStrs[32][32], char replyStrs[32][32]); +int S25FS512_EnableHWReset(char argStrs[32][32], char replyStrs[32][32]); +int S25FS512_SpiWriteRead(char argStrs[32][32], char replyStrs[32][32]); +int S25FS512_SpiWriteRead4Wire(char argStrs[32][32], char replyStrs[32][32]); + +#endif /* _S25FS512_RPC_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Hsp_BLE/BluetoothLE/BluetoothLE.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,172 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include "BluetoothLE.h" +#include "Characteristic.h" + +/** + * @brief Constructor for class + */ +BluetoothLE::BluetoothLE(BLE *ble, int numberOfCharacteristics) + : ble(ble), runningIndex(0), + numberOfCharacteristics(numberOfCharacteristics) { + characteristics = new Characteristic *[numberOfCharacteristics]; + gattCharacteristics = new GattCharacteristic *[numberOfCharacteristics]; +} + +/** + * @brief Destructor for class + */ +BluetoothLE::~BluetoothLE(void) { + for (int i = 0; i < numberOfCharacteristics; i++) delete characteristics[i]; + delete[] gattCharacteristics; + delete[] characteristics; +} + +/** + * @brief Initialize the advertising, characteristics, service for this platform + */ +void BluetoothLE::addCharacteristic(Characteristic *characteristic) { + characteristic->setBLE(ble); + characteristic->setIndex(runningIndex); + characteristics[runningIndex] = characteristic; + gattCharacteristics[runningIndex] = characteristic->getGattCharacteristic(); + runningIndex++; +} + +/** + * @brief Initialize the advertising, characteristics, service for this platform + */ +void BluetoothLE::initService(uint8_t *serialNumber, uint8_t *deviceName, + int nameSize, uint8_t *serviceUUID) { + ble->init(); + ble->onDisconnection(this, &BluetoothLE::disconnectionCallback); + + ble->gap().setAddress((BLEProtocol::AddressType_t)0, serialNumber); + + // Setup Advertising + ble->accumulateAdvertisingPayload( + GapAdvertisingData::BREDR_NOT_SUPPORTED | + GapAdvertisingData::LE_GENERAL_DISCOVERABLE); + ble->accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, + (uint8_t *)deviceName, nameSize); + ble->setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); + ble->setAdvertisingInterval(1600); // 1000ms; in multiples of 0.625ms. + GattService envService(serviceUUID, gattCharacteristics, + numberOfCharacteristics); + ble->gattServer().addService(envService); + ble->onDataWritten(this, &BluetoothLE::onDataWritten); + // Start Advertising + ble->startAdvertising(); +} + +static const Gap::ConnectionParams_t paramsLowPower = { + 400, /**< Minimum Connection Interval in 1.25 ms units, see @ref BLE_GAP_CP_LIMITS.*/ + 400, /**< Maximum Connection Interval in 1.25 ms units, see @ref BLE_GAP_CP_LIMITS.*/ + 60, /**< Slave Latency in number of connection events, see @ref BLE_GAP_CP_LIMITS.*/ + 3100 /**< Connection Supervision Timeout in 10 ms units, see @ref BLE_GAP_CP_LIMITS.*/ +}; + +static Gap::Handle_t connHandle = 0; + +/** + * @brief Called on BLE connection + */ +void BluetoothLE::connectionCallback( + const Gap::ConnectionCallbackParams_t *params) { + connHandle = params->handle; +} + +/** + * @brief Start advertising on a disconnect + */ +void BluetoothLE::disconnectionCallback( + const Gap::DisconnectionCallbackParams_t *params) { + _isConnected = false; + ble->startAdvertising(); +} + +/** + * @brief Called when the client writes to a writable characteristic + * @param params Pointer to a structure that contains details on what was + * written + */ +void BluetoothLE::onDataWritten(const GattWriteCallbackParams *params) { + int i; + int index = 0; + // match the characteristic handle + printf("BluetoothLE::onDataWritten "); + for (i = 0; i < numberOfCharacteristics; i++) { + if (params->handle == gattCharacteristics[i]->getValueHandle()) { + characteristics[i]->copyDataWritten(params); + index = i; + break; + } + } + (*_onDataWritten)(index); +} + +/** +* @brief Update the characteristic notification +* @param index Index of the characteristic +* @param data Pointer to the byte data to update the charateristic payload +*/ +void BluetoothLE::notifyCharacteristic(int index, uint8_t *data) { + for (int i = 0; i < characteristics[index]->getPayloadLength(); i++) { + characteristics[index]->getPayloadBytes()[i] = data[i]; + } + characteristics[index]->update(); +} + +/** +* @brief Update the characteristic notification +* @param index Index of the characteristic +* @param data Pointer to the byte data to update the charateristic payload +*/ +void BluetoothLE::notifyCharacteristicTest(int index) { + for (int i = 0; i < characteristics[index]->getPayloadLength(); i++) { + characteristics[index]->getPayloadBytes()[i]++; + } + characteristics[index]->update(); +} + +uint8_t *BluetoothLE::getDataWritten(int index, int *length) { + return characteristics[index]->getDataWritten(length); +} + +/** +* @brief Function to query if a BLE connection is active +* @return true if BLE connected, false if BLE is not connected +*/ +bool BluetoothLE::isConnected(void) { + return (ble->getGapState().connected == 1 ? true : false); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Hsp_BLE/BluetoothLE/BluetoothLE.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,137 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _BLUETOOTHLE_H_ +#define _BLUETOOTHLE_H_ + +#include "mbed.h" +#include "BLE.h" +#include "Characteristic.h" + +class BluetoothLE { +public: + BluetoothLE(BLE *ble, int numberOfCharacteristics); + ~BluetoothLE(void); + void addCharacteristic(Characteristic *characteristic); + void initService(uint8_t *serialNumber, uint8_t *deviceName, int nameSize, uint8_t *serviceUUID); + void notifyCharacteristic(int index, uint8_t *data); + + + /** + * @brief Return a characteristic based on incoming index + * @param index index into an array of characteristics + */ + Characteristic *getCharacteristic(int index) { + return characteristics[index]; + } + + /** + * @brief Get the payload for this characteristic + */ + uint8_t *getCharacteristicPayload(int index) { + return characteristics[index]->getPayloadPtr(); + } + typedef void (*PtrFunction)(int index); + + /** + * @brief Used to connect a connection callback + */ + template<typename T> + void onConnect(T *object, void (T::*member)(void)) { + _onConnect.attach( object, member ); + } + /** + * @brief Used to connect a disconnection callback + */ + template<typename T> + void onDisconnect(T *object, void (T::*member)(void)) { + _onDisconnect.attach( object, member ); + } + /** + * @brief Used to connect a characteristic written callback + */ + void onDataWritten(PtrFunction _onDataWritten) { + this->_onDataWritten = _onDataWritten; + } + /** + * @brief Get the connection state of the BLE + * @return true if connection BLE connection is present, false if no connection + */ + bool isConnected(void); + + /** + * @brief Perform a notification test + * @param index Index into an array of characteristic objects + */ + void notifyCharacteristicTest(int index); + + /** + * @brief Get the data that was written to the indexed characteristic + * @return true if connection BLE connection is present, false if no connection + */ + uint8_t *getDataWritten(int index, int *length); + +private: + /** + * @brief Disconnection callback + */ + void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params); + /** + * @brief Connection callback + */ + void connectionCallback(const Gap::ConnectionCallbackParams_t *params); + /** + * @brief Characteristic written callback + */ + void onDataWritten(const GattWriteCallbackParams *params); + + /// array of characteristic class pointers + Characteristic **characteristics; + /// array of gatt characteristic pointers + GattCharacteristic **gattCharacteristics; + /// pointer to mbed BLE layer + BLE *ble; + /// total number of characteristics + int numberOfCharacteristics; + /// flag to keep track of BLE connection state + bool _isConnected; + /// running index for building characteristic array + int runningIndex; + /// callback function for when a connection is made + FunctionPointer _onConnect; + /// callback function for when a connection is disconnected + FunctionPointer _onDisconnect; + /// callback function for when characteristic data is written + PtrFunction _onDataWritten; +}; + +#endif // _BLUETOOTHLE_H_
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Hsp_BLE/BluetoothLE/Characteristic.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,61 @@ +/******************************************************************************* +* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES +* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Except as contained in this notice, the name of Maxim Integrated +* Products, Inc. shall not be used except as stated in the Maxim Integrated +* Products, Inc. Branding Policy. +* +* The mere transfer of this software does not imply any licenses +* of trade secrets, proprietary technology, copyrights, patents, +* trademarks, maskwork rights, or any other form of intellectual +* property whatsoever. Maxim Integrated Products, Inc. retains all +* ownership rights. +******************************************************************************* +*/ +#include "Characteristic.h" + +Characteristic::Characteristic(uint16_t length, const UUID &uuid, + uint8_t additionalProperties, + GattAttribute *descriptors[], + unsigned numDescriptors) + : gattCharacteristic( + uuid, reinterpret_cast<uint8_t *>(payload.getPointer()), length, + length, additionalProperties, descriptors, numDescriptors) { + payloadLength = length; + dataWrittenLength = -1; +} + +void Characteristic::update(void) { + if (ble->getGapState().connected) { + ble->gattServer().write(gattCharacteristic.getValueHandle(), + payload.getPointer(), payloadLength); + } +} + +int Characteristic::getPayloadLength(void) { return payloadLength; } + +GattAttribute::Handle_t Characteristic::getValueHandle(void) { + return gattCharacteristic.getValueHandle(); +} + +GattCharacteristic *Characteristic::getGattCharacteristic(void) { + return &gattCharacteristic; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Hsp_BLE/BluetoothLE/Characteristic.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,112 @@ +/******************************************************************************* +* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES +* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Except as contained in this notice, the name of Maxim Integrated +* Products, Inc. shall not be used except as stated in the Maxim Integrated +* Products, Inc. Branding Policy. +* +* The mere transfer of this software does not imply any licenses +* of trade secrets, proprietary technology, copyrights, patents, +* trademarks, maskwork rights, or any other form of intellectual +* property whatsoever. Maxim Integrated Products, Inc. retains all +* ownership rights. +******************************************************************************* +*/ +#ifndef _CHARACTERISTIC_H_ +#define _CHARACTERISTIC_H_ + +#include "mbed.h" +#include "BLE.h" +#include "GattCharacteristic.h" + +class Characteristic { +public: + /** + * @brief ticker handler static method + */ + Characteristic(uint16_t length, const UUID &uuid, + uint8_t additionalProperties = + GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NONE, + GattAttribute *descriptors[] = NULL, + unsigned numDescriptors = 0); + + void setIndex(int index) { this->index = index; } + /** + * @brief Set a pointer reference to the mbed BLE framework + */ + void setBLE(BLE *ble) { this->ble = ble; } + /** + * @brief Get the pointer to the byte payload + */ + uint8_t *getPayloadPtr(void) { return payload.getPointer(); } + /** + * @brief Get the handle of the characteristic + */ + GattAttribute::Handle_t getValueHandle(); + /** + * @brief Update the characteristic + */ + void update(void); + /** + * @brief Get the GattCharacteristic + */ + GattCharacteristic *getGattCharacteristic(); + /** + * @brief Get the length of the payload + */ + int getPayloadLength(void); + + uint8_t *getPayloadBytes(void) { return payload.bytes; } + + void copyDataWritten(const GattWriteCallbackParams *params) { + int i = 0; + while (i < params->len && i < sizeof(dataWritten)) { + dataWritten[i] = params->data[i]; + i++; + } + dataWrittenLength = params->len; + } + + uint8_t *getDataWritten(int *length) { + *length = dataWrittenLength; + return dataWritten; + } + +private: + int payloadLength; + struct PayloadStruct { + uint8_t bytes[32]; + uint8_t *getPointer(void) { return bytes; } + }; + /// local copy of data written to this characteristic + uint8_t dataWritten[64]; + int dataWrittenLength; + /// payload structure for this characteristic + PayloadStruct payload; + /// gatt characteristic + GattCharacteristic gattCharacteristic; + /// mbed BLE framework pointer + BLE *ble; + /// index of this characteristic + int index; +}; + +#endif /* _CHARACTERISTIC_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Hsp_BLE/HspBLE.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,197 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include "HspBLE.h" +#include "Peripherals.h" +#include "MAX30001_helper.h" + +#define LOW_BYTE(x) ((uint8_t)((x)&0xFF)) +#define HIGH_BYTE(x) ((uint8_t)(((x) >> 8) & 0xFF)) + +/// define all of the characteristic UUIDs +uint8_t HspBLE::temperatureTopCharUUID[] = {0x35,0x44,0x53,0x1b,0x00,0xc3,0x43,0x42,0x97,0x55,0xb5,0x6a,0xbe,0x8e,0x6c,0x67}; +uint8_t HspBLE::temperatureBottomCharUUID[] = {0x35,0x44,0x53,0x1b,0x00,0xc3,0x43,0x42,0x97,0x55,0xb5,0x6a,0xbe,0x8e,0x6a,0x66}; +uint8_t HspBLE::accelerometerCharUUID[] = {0xe6,0xc9,0xda,0x1a,0x80,0x96,0x48,0xbc,0x83,0xa4,0x3f,0xca,0x38,0x37,0x05,0xaf}; +uint8_t HspBLE::heartrateCharUUID[] = {0x62,0x1a,0x00,0xe3,0xb0,0x93,0x46,0xbf,0xaa,0xdc,0xab,0xe4,0xc6,0x48,0xc5,0x69}; +uint8_t HspBLE::pressureCharUUID[] = {0x1d,0x8a,0x19,0x32,0xda,0x49,0x49,0xad,0x91,0xd8,0x80,0x08,0x32,0xe7,0xe9,0x40}; +uint8_t HspBLE::dataCharUUID[] = {0xaa,0x8a,0x19,0x32,0xda,0x49,0x49,0xad,0x91,0xd8,0x80,0x08,0x32,0xe7,0xe9,0x40}; +uint8_t HspBLE::commandCharUUID[] = {0x36,0xe5,0x5e,0x37,0x6b,0x5b,0x42,0x0b,0x91,0x07,0x0d,0x34,0xa0,0xe8,0x67,0x5a}; + + +/// define the BLE device name +uint8_t HspBLE::deviceName[] = "MAXREFDES100"; +/// define the BLE serial number +uint8_t HspBLE::serialNumber[] = {0x77, 0x22, 0x33, 0x45, 0x67, 0x89}; +/// define the BLE service UUID +uint8_t HspBLE::envServiceUUID[] = {0x5c,0x6e,0x40,0xe8,0x3b,0x7f,0x42,0x86,0xa5,0x2f,0xda,0xec,0x46,0xab,0xe8,0x51}; + +HspBLE *HspBLE::instance = NULL; + +/** +* @brief Constructor that inits the BLE helper object +* @param ble Pointer to the mbed BLE object +*/ +HspBLE::HspBLE(BLE *ble) { + bluetoothLE = new BluetoothLE(ble, NUMBER_OF_CHARACTERISTICS); + instance = this; + notificationUpdateRoundRobin = 0; +} + +/** +* @brief Constructor that deletes the bluetoothLE object +*/ +HspBLE::~HspBLE(void) { delete bluetoothLE; } + +/** +* @brief Initialize all of the HSP characteristics, initialize the ble service +* and attach callbacks +*/ +void HspBLE::init(void) { + uint8_t *serialNumberPtr; + // uint8_t serialNumberBuffer[6]; + serialNumberPtr = MAX30001_Helper_getVersion(); + printf("MAX30001 Version = %02X:%02X:%02X:%02X:%02X:%02X...\n", + serialNumberPtr[0], serialNumberPtr[1], serialNumberPtr[2], + serialNumberPtr[3], serialNumberPtr[4], serialNumberPtr[5]); + serialNumberPtr[3] = 0x00; + serialNumberPtr[4] = 0x00; + serialNumberPtr[5] = 0x03; + printf("BLE DeviceID = %02X:%02X:%02X:%02X:%02X:%02X...\n", + serialNumberPtr[0], serialNumberPtr[1], serialNumberPtr[2], + serialNumberPtr[3], serialNumberPtr[4], serialNumberPtr[5]); + + bluetoothLE->addCharacteristic(new Characteristic(2 /* number of bytes */,temperatureTopCharUUID,GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)); + bluetoothLE->addCharacteristic(new Characteristic(2 /* number of bytes */,temperatureBottomCharUUID,GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)); + bluetoothLE->addCharacteristic(new Characteristic(6 /* number of bytes */,accelerometerCharUUID,GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)); + bluetoothLE->addCharacteristic(new Characteristic(4 /* number of bytes */,heartrateCharUUID,GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)); + bluetoothLE->addCharacteristic(new Characteristic(8 /* number of bytes */,pressureCharUUID,GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)); + bluetoothLE->addCharacteristic(new Characteristic(32 /* number of bytes */,dataCharUUID,GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE)); + bluetoothLE->addCharacteristic(new Characteristic(1 /* number of bytes */,commandCharUUID,GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE)); + bluetoothLE->initService(serialNumberPtr, deviceName, sizeof(deviceName),envServiceUUID); + + bluetoothLE->onDataWritten(&HspBLE::_onDataWritten); + ticker.attach(this, &HspBLE::tickerHandler, 1); +} + +void HspBLE::_onDataWritten(int index) { + HspBLE::instance->onDataWritten(index); +} + +/** +* @brief Callback for written characteristics +* @param index Index of whose characteristic is written to +*/ +void HspBLE::onDataWritten(int index) { + int length; + uint8_t *data; + printf("onDataWritten "); + if (index == CHARACTERISTIC_CMD) { + data = bluetoothLE->getDataWritten(index, &length); + if (length >= 1) { + if (data[0] == 0x00) startDataLogging = false; + if (data[0] == 0x01) startDataLogging = true; + printf("onDataWritten index %d, data %02X, length %d ",index,data[0],length); fflush(stdout); + + } + } +} + +void HspBLE::pollSensor(int sensorId, uint8_t *data) { + + switch (sensorId) { + case CHARACTERISTIC_TEMP_TOP: { + uint16_t uShort; + Peripherals::max30205_top()->readTemperature(&uShort); + data[0] = HIGH_BYTE(uShort); + data[1] = LOW_BYTE(uShort); + } break; + case CHARACTERISTIC_TEMP_BOTTOM: { + uint16_t uShort; + Peripherals::max30205_bottom()->readTemperature(&uShort); + data[0] = HIGH_BYTE(uShort); + data[1] = LOW_BYTE(uShort); + } break; + case CHARACTERISTIC_ACCELEROMETER: { + int i; + uint8_t *bytePtr; + int16_t acclPtr[3]; + Peripherals::lis2dh()->get_motion_cached(&acclPtr[0], &acclPtr[1], + &acclPtr[2]); + bytePtr = reinterpret_cast<uint8_t *>(&acclPtr); + for (i = 0; i < sizeof(acclPtr); i++) + data[i] = bytePtr[i]; + } break; + case CHARACTERISTIC_PRESSURE: { + int i; + uint8_t *bytePtr; + float temperature; + float pressure; + Peripherals::bmp280()->ReadCompData(&temperature, &pressure); + bytePtr = reinterpret_cast<uint8_t *>(&temperature); + for (i = 0; i < sizeof(float); i++) + data[i] = bytePtr[i]; + bytePtr = reinterpret_cast<uint8_t *>(&pressure); + for (i = 0; i < sizeof(float); i++) + data[i + sizeof(float)] = bytePtr[i]; + } break; + case CHARACTERISTIC_HEARTRATE: { + int i; + uint8_t *bytePtr; + MAX30001::max30001_t heartrateData; + Peripherals::max30001()->max30001_ReadHeartrateData(&heartrateData); + bytePtr = reinterpret_cast<uint8_t *>(&heartrateData); + for (i = 0; i < sizeof(MAX30001::max30001_t); i++) + data[i] = bytePtr[i]; + } break; + } +} + +bool HspBLE::getStartDataLogging(void) { return startDataLogging; } + +/** +* @brief Timer Callback that updates all sensor characteristic notifications +*/ +void HspBLE::tickerHandler(void) { + uint8_t data[8]; + if (bluetoothLE->isConnected()) { + pollSensor(CHARACTERISTIC_TEMP_TOP, data); + bluetoothLE->notifyCharacteristic(CHARACTERISTIC_TEMP_TOP, data); + pollSensor(CHARACTERISTIC_TEMP_BOTTOM, data); + bluetoothLE->notifyCharacteristic(CHARACTERISTIC_TEMP_BOTTOM, data); + pollSensor(CHARACTERISTIC_ACCELEROMETER, data); + bluetoothLE->notifyCharacteristic(CHARACTERISTIC_ACCELEROMETER, data); + pollSensor(CHARACTERISTIC_HEARTRATE, data); + bluetoothLE->notifyCharacteristic(CHARACTERISTIC_HEARTRATE, data); + pollSensor(CHARACTERISTIC_PRESSURE, data); + bluetoothLE->notifyCharacteristic(CHARACTERISTIC_PRESSURE, data); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Hsp_BLE/HspBLE.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _HSPBLE_H_ +#define _HSPBLE_H_ + +#include "mbed.h" +#include "BluetoothLE.h" + +/// define the number of characteristics used on the HSP platform +#define NUMBER_OF_CHARACTERISTICS (7) + +/// indicies of the characteristics used +#define CHARACTERISTIC_TEMP_TOP (0) +#define CHARACTERISTIC_TEMP_BOTTOM (1) +#define CHARACTERISTIC_ACCELEROMETER (2) +#define CHARACTERISTIC_HEARTRATE (3) +#define CHARACTERISTIC_PRESSURE (4) +#define CHARACTERISTIC_DATA (5) +#define CHARACTERISTIC_CMD (6) + +class HspBLE { +public: + HspBLE(BLE *ble); + ~HspBLE(void); + void init(void); + static void _onDataWritten(int index); + void onDataWritten(int index); + void updateNotification(int index); + void pollSensor(int sensorId, uint8_t *data); + bool getStartDataLogging(void); + static HspBLE *instance; + +private: + void tickerHandler(void); + void testPattern(uint8_t *data, int length, bool clear); + + /// pointer to the helper BLE object + BluetoothLE *bluetoothLE; + /// ticker that is used to periodically update the characteristic + /// notifications + Ticker ticker; + + /// value that controls the notifications to be sent in a round robin fashion + int notificationUpdateRoundRobin; + + /// charateristic UUIDs statically defined + static uint8_t temperatureTopCharUUID[]; + static uint8_t temperatureBottomCharUUID[]; + static uint8_t accelerometerCharUUID[]; + static uint8_t heartrateCharUUID[]; + static uint8_t pressureCharUUID[]; + static uint8_t dataCharUUID[]; + static uint8_t commandCharUUID[]; + static uint8_t envServiceUUID[]; + static uint8_t deviceName[]; + static uint8_t serialNumber[]; + + /// application specific + bool startDataLogging; +}; + +#endif // _HSPBLE_H_ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Interfaces/I2C_RPC.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include <stdint.h> +#include "StringHelper.h" +#include "I2C_RPC.h" +#include "Peripherals.h" + +//****************************************************************************** +// input +// [instance] [slaveAddress] [writeNumber] [](data to write) [readNumber] +// output data to read +int I2C_WriteRead(char argStrs[32][32], char replyStrs[32][32]) { + uint8_t args[16]; + uint8_t reply[16]; + uint8_t writeNumber; + uint8_t readNumber; + uint8_t instance; + uint8_t slaveAddress; + int ret1; + int ret2; + I2C *i2c; + // get the number of bytes to write + ProcessArgs(argStrs, args, 3); // parse [instance] [slaveAddress] [writeNumber] + instance = args[0]; + slaveAddress = args[1]; + writeNumber = args[2]; + // parse [instance] [slaveAddress] [writeNumber] [](data to write) + // [readNumber] + ProcessArgs(argStrs, args, writeNumber + 4); + readNumber = args[writeNumber + 3]; + + if (instance == 1) { + i2c = Peripherals::i2c1(); + } + if (instance == 2) { + i2c = Peripherals::i2c2(); + } + ret1 = 0; + ret2 = 0; + + if (writeNumber != 0) { + ret1 = i2c->write((int)slaveAddress, (char *)&args[3], (int)writeNumber); + } + if (readNumber != 0) { + ret2 = i2c->read((int)slaveAddress, (char *)reply, (int)readNumber); + } + + if (ret1 != 0) reply[0] = 0xFF; + if (ret2 != 0) reply[0] = 0xFF; + + + // reply[0] = 0x80; + FormatReply(reply, readNumber, replyStrs); + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Interfaces/I2C_RPC.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _I2C_RPC_H_ +#define _I2C_RPC_H_ + +#include "mbed.h" + +int I2C_Init(char argStrs[32][32], char replyStrs[32][32]); +int I2C_Write(char argStrs[32][32], char replyStrs[32][32]); +int I2C_Read(char argStrs[32][32], char replyStrs[32][32]); +int I2C_WriteRead(char argStrs[32][32], char replyStrs[32][32]); + +#endif /* _I2C_RPC_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Interfaces/QuadSpiInterface.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,107 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include "QuadSpiInterface.h" + +/** +* @brief Constructor that accepts pin names for the QUAD SPI interface +* @param mosi master out slave in pin name +* @param miso master in slave out pin name +* @param sclk serial clock pin name +* @param cs chip select pin name +*/ +QuadSpiInterface::QuadSpiInterface(PinName mosi, PinName miso, PinName sclk, + PinName cs) + : spi(mosi, miso, sclk), csPin(cs) { + + } + +/** +* @brief Transmit and recieve QUAD SPI data +* @param tx_buf pointer to transmit byte buffer +* @param tx_size number of bytes to transmit +* @param rx_buf pointer to the recieve buffer +* @param rx_size number of bytes to recieve +* @param last flag to indicate if this is the last QUAD SPI transaction for the +* current chip select cycle +*/ +int QuadSpiInterface::SPI_Transmit(const uint8_t *tx_buf, uint32_t tx_size, + uint8_t *rx_buf, uint32_t rx_size, + int last) { + uint32_t i; + int result = 0; + int index = 0; + // lower chip select + csPin = 0; + // write bytes out QUAD SPI + spi.setQuadMode(); + for (i = 0; i < tx_size; i++) { + rx_buf[index] = spi.write((int)tx_buf[i]); + index++; + } + // read in bytes from QUAD SPI + for (i = 0; i < rx_size; i++) { + rx_buf[index] = (uint8_t)spi.read(); + index++; + } + // raise chip select if this is the last transaction + if (last) csPin = 1; + return result; +} + +/** +* @brief Transmit and recieve QUAD SPI data +* @param tx_buf pointer to transmit byte buffer +* @param tx_size number of bytes to transmit +* @param rx_buf pointer to the recieve buffer +* @param rx_size number of bytes to recieve +* @param last flag to indicate if this is the last QUAD SPI transaction for the +* current chip select cycle +*/ +int QuadSpiInterface::SPI_Transmit4Wire(const uint8_t *tx_buf, uint32_t tx_size, + uint8_t *rx_buf, uint32_t rx_size, + int last) { + uint32_t i; + int result = 0; + int index = 0; + // lower chip select + csPin = 0; + // write bytes out Single SPI + spi.setSingleMode(); + for (i = 0; i < tx_size; i++) { + rx_buf[index] = spi.write((int)tx_buf[i]); + index++; + } + // raise chip select if this is the last transaction + if (last) csPin = 1; + return result; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Interfaces/QuadSpiInterface.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _QUADSPIINTERFACE_H_ +#define _QUADSPIINTERFACE_H_ + +#include "mbed.h" +#include "QuadSpi.h" + +class QuadSpiInterface { +public: + /** + * @brief Constructor that accepts pin names for the QUAD SPI interface + * @param mosi master out slave in pin name + * @param miso master in slave out pin name + * @param sclk serial clock pin name + * @param cs chip select pin name + */ + QuadSpiInterface(PinName mosi, PinName miso, PinName sclk, PinName cs); + /** + * @brief Transmit and recieve QUAD SPI data + * @param tx_buf pointer to transmit byte buffer + * @param tx_size number of bytes to transmit + * @param rx_buf pointer to the recieve buffer + * @param rx_size number of bytes to recieve + * @param last flag to indicate if this is the last QUAD SPI transaction for + * the current chip select cycle + */ + int SPI_Transmit(const uint8_t *tx_buf, uint32_t tx_size, uint8_t *rx_buf, + uint32_t rx_size, int last = 1); + + /** + * @brief Transmit and recieve Four Wrire SPI data + * @param tx_buf pointer to transmit byte buffer + * @param tx_size number of bytes to transmit + * @param rx_buf pointer to the recieve buffer + * @param rx_size number of bytes to recieve + * @param last flag to indicate if this is the last QUAD SPI transaction for + * the current chip select cycle + */ + int SPI_Transmit4Wire(const uint8_t *tx_buf, uint32_t tx_size, + uint8_t *rx_buf, uint32_t rx_size, int last = 1); + +private: + // QUAD SPI object + QuadSPI spi; + // chip select object + DigitalOut csPin; +}; + +#endif // _QUADSPIINTERFACE_H_
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/LoggingService/DataLoggingService.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,567 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include "mbed.h" +#include "Logging.h" +#include "Streaming.h" +#include "RpcServer.h" +#include "S25FS512.h" +#include "BMP280.h" +#include "PacketFifo.h" +#include "DataLoggingService.h" +#include "ServiceNonInterrupt.h" +#include "HspLed.h" +#include "MAX30001_helper.h" +#include "MAX30101_helper.h" +#include "StringInOut.h" +#include "StringHelper.h" +#include "Peripherals.h" +#include "Device_Logging.h" + +/// BMP280 logging object reference +extern Device_Logging *bmp280_Logging; +/// MAX14720 instance 0 logging object reference +extern Device_Logging *MAX30205_0_Logging; +/// MAX14720 instance 1 logging object reference +extern Device_Logging *MAX30205_1_Logging; + +#define PING_PONG_BUFFER_SIZE 512 +#define HALF_OF_PING_PONG_BUFFER_SIZE PING_PONG_BUFFER_SIZE / 2 +#define MISSION_DEFINITION_SIZE 4096 + +eLoggingTrigger loggingTrigger; + +/// buffer where mission strings are stored +char loggingMissionCmds[MISSION_DEFINITION_SIZE]; +/// This houses two 256 byte ram concatenated to act as a ping-pong +uint8_t PingPong_SRAM[PING_PONG_BUFFER_SIZE]; +uint32_t buttonTrigger = 0; + +eLoggingOutput loggingOutput; +// extern int bleStartCommand; +bool volatile globalFlag; +extern int highDataRate; +static uint32_t currentPage; +static uint32_t sramIndex; +/// flag to indicate that sram buffer 0 is dirty and will need to be flushed +static uint32_t sram_buffer_0_dirty; +/// flag to indicate that sram buffer 1 is dirty and will need to be flushed +static uint32_t sram_buffer_1_dirty; +/// usb byte buffer for sending out a bulk transfer +static uint8_t usb_block[64]; +/// running index used to accumulate bytes to send as a block via bulk transfer +static uint16_t usb_block_index = 0; + +typedef enum { + eStartEvent_NULL, + eStartEvent_BLE, + eStartEvent_BUTTON, + eStartEvent_RPC_TO_USB, + eStartEvent_RPC_TO_FLASH +} eStartEvent; +static eStartEvent startEvent; + +/** +* @brief Sets a flag to start USB logging (streaming) +*/ +void LoggingService_StartLoggingUsb(void) { + loggingTrigger = eTriggerLog_RPC_USB; +} + +/** +* @brief Sets a flag to start flash logging +*/ +void LoggingService_StartLoggingFlash(void) { + loggingTrigger = eTriggerLog_RPC_FLASH; +} + +/** +* @brief Checks the various logging start condition +* @return 1 if a start condition is true, 0 if there is no start condition +*/ +static bool _LoggingService_CheckStartCondition(void) { + bool buttonPressed; + buttonPressed = Peripherals::pushButton()->GetButtonFallState(); + + // default not logging USB or flash + loggingOutput = eLogToNothing; + startEvent = eStartEvent_NULL; + if (buttonPressed) { + Peripherals::pushButton()->clearButtonFallState(); + // a falling state has been detected... wait for a fraction of a second and + // re-read the pin + // only start datalogging if the pin was released within this wait time + wait(0.75f); + int buttonRead = Peripherals::pushButton()->Read(); + // if after a period of time the button is still pressed then get out + if (buttonRead == 0) + return 0; + buttonTrigger = 0; + + loggingTrigger = eTriggerLog_BUTTON; + loggingOutput = eLogToFlash; + startEvent = eStartEvent_BUTTON; + return true; + } + if (loggingTrigger == eTriggerLog_RPC_FLASH) { + loggingOutput = eLogToFlash; + startEvent = eStartEvent_RPC_TO_FLASH; + return true; + } + if (Peripherals::hspBLE()->getStartDataLogging()) { + loggingTrigger = eTriggerLog_BLE; + loggingOutput = eLogToFlash; + startEvent = eStartEvent_BLE; + return true; + } + // check if start is from RPC call for USB streaming + if (loggingTrigger == eTriggerLog_RPC_USB) { + loggingOutput = eLogtoUsb; + startEvent = eStartEvent_RPC_TO_USB; + return true; + } + return false; +} + +/** +* @brief Read the mission string from flash into a buffer +* @return false if a mission was not defined, true if mission was read and +* buffered +*/ +static bool _LoggingService_ReadMissionFromFlash(void) { + // get mission from flash + Logging_ReadMissionFromFlash((uint8_t *)loggingMissionCmds); + if (Logging_IsMissionDefined((uint8_t *)loggingMissionCmds) == 0) { + return false; + } + printf(loggingMissionCmds); + fflush(stdout); + RPC_ProcessCmds(loggingMissionCmds); + return true; +} + +/** +* @brief Process a RPC command that is pointed to. +* @param cmd RPC string to process +*/ +void ProcessCmd(char *cmd) { + char cmd_[256]; + char reply[512]; + strcpy(cmd_, cmd); + RPC_call(cmd_, reply); +} + +/** +* @brief Buffer sensor fifo data in ram buffers, when a ram buffer is full (a +* flash page worth of data is accumulated) then flash that buffer. +* A buffer ping pong method is used so that one buffer can be flashing as +* the other buffer fills with sensor fifo data. +* @param fifoData Sensor data taken from the fifo to be stored into flash +*/ +static void _LoggingServer_OutputToFlash(uint32_t fifoData) { + uint32_t index; + char str[128]; + uint8_t *ptr; + // + // Log To Flash + // + // i.e. there is data, read one 32-bit size data at a time. + // put the fifo data into the ping-pong SRAM + PingPong_SRAM[sramIndex++] = fifoData & 0xFF; // LSByte goes into index N + PingPong_SRAM[sramIndex++] = (fifoData >> 8) & 0xFF; + PingPong_SRAM[sramIndex++] = (fifoData >> 16) & 0xFF; + PingPong_SRAM[sramIndex++] = (fifoData >> 24) & 0xFF; // MSByte goes into index N+3 + + // flag this buffer as dirty + if (sramIndex <= 256) + sram_buffer_0_dirty = 1; + else + sram_buffer_1_dirty = 1; + + if (sramIndex == 256 || + sramIndex == 512) // Either Ping SRAM or Pong SRAM location is full + { // therefore write to Flash + + index = sramIndex - 256; + ptr = &PingPong_SRAM[index]; + sprintf(str, "currentPage=%d", currentPage); + Peripherals::s25FS512()->writePage_Helper(currentPage, ptr, 0); + + // this page is no longer dirty + if (index == 0) + sram_buffer_0_dirty = 0; + if (index == 256) + sram_buffer_1_dirty = 0; + + currentPage++; + } + sramIndex = sramIndex % 512; // Wrap around the index +} + +/** +* @brief If flash ram buffers are flagged as dirty, flush to flash +*/ +static void _LoggingServer_WriteDirtySramBufferToFlash(void) { + uint8_t *ptr = PingPong_SRAM; + if (sram_buffer_0_dirty == 0 && sram_buffer_1_dirty == 0) + return; + if (sram_buffer_0_dirty == 1) { + ptr += 0; + } + if (sram_buffer_1_dirty == 1) { + ptr += 256; + } + printf("_LoggingServer_WriteDirtySramBufferToFlash:%d,%d\n", + sram_buffer_0_dirty, sram_buffer_1_dirty); + fflush(stdout); + // s25fs512_WritePage_Helper(currentPage, ptr, 0); + Peripherals::s25FS512()->writePage_Helper(currentPage, ptr, 0); +} + +/** +* @brief Initialize the USB block running index +* @param fifoData Sensor data taken from the fifo to be sent out USB +*/ +static void _LoggingServer_OutputToCdcAcm(uint32_t fifoData) { + uint8_t *ptr; + uint8_t str[16]; + sprintf((char *)str, "%X ", fifoData); + ptr = str; + usb_block_index = 0; + while (*ptr != 0) { + usb_block[usb_block_index] = *ptr; + ptr++; + usb_block_index++; + } + Peripherals::usbSerial()->writeBlock(usb_block, usb_block_index); +} + +/** +* @brief Initialize the USB block running index +*/ +static void _LoggingServer_OutputToCdcAcm_Start(void) { usb_block_index = 0; } + +/** +* @brief Buffer up fifoData from sensors, do a USB block transfer if buffer is +* full +* @param fifoData Sensor data taken from the fifo to be send out USB within a +* bulk block transfer +* @return Return the success status of the writeblock operation +*/ +static bool _LoggingServer_OutputToCdcAcm_Block(uint32_t fifoData) { + uint8_t str[64]; + uint8_t *ptr; + bool result; + // + // Log to CDCACM + // + result = true; + sprintf((char *)str, "%X ", fifoData); + ptr = str; + while (*ptr != 0) { + usb_block[usb_block_index] = *ptr; + ptr++; + usb_block_index++; + if (usb_block_index >= 64) { + result = Peripherals::usbSerial()->writeBlock(usb_block, 64); + usb_block_index = 0; + } + } + return result; +} + +/** +* @brief Output a full USB block via bulk transfer +*/ +static void _LoggingServer_OutputToCdcAcm_End(void) { + if (usb_block_index == 0) + return; + Peripherals::usbSerial()->writeBlock(usb_block, usb_block_index - 1); +} + +/** +* @brief Blink LED pattern that indicates that the flash end boundary has been +* reached +*/ +static void BlinkEndOfDatalogging(void) { + // blink to signal end of logging + Peripherals::hspLed()->pattern(0x55555555, 20); + wait(2); +} + +/** +* @brief Reads the first data page of flash, if all FF's then the page is empty +* @return 1 if the flash is empty as indicated by the first data page of the +* flash, 0 if not +*/ +int isFlashEmpty(void) { + int i; + uint8_t data[256]; + int firstDataPage = Logging_GetLoggingStartPage(); + Peripherals::s25FS512()->readPages_Helper(firstDataPage, firstDataPage, data, 0); + for (i = 0; i < 256; i++) { + if (data[i] != 0xFF) + return 0; + } + return 1; +} + +/** +* @brief Blink LED pattern that indicates that the flash is not empty and a new +* flash logging session can not occur +*/ +void BlinkFlashNotEmpty(void) { + Peripherals::hspLed()->pattern(0x55555555, 20); + wait(1); +} + +void ExecuteDefaultMission(void) { + ProcessCmd("/MAX30001/CAL_InitStart 01 01 01 03 7FF 00"); + ProcessCmd("/MAX30001/ECG_InitStart 01 01 01 00 02 03 1F 0 00 00 01"); + ProcessCmd("/MAX30001/RtoR_InitStart 01 03 0F 00 03 01 00 00 01"); + ProcessCmd("/MAX30001/Rbias_FMSTR_Init 01 02 01 01 00"); + ProcessCmd("/LIS2DH/InitStart 02 01"); +} + +void LoggingService_Init(void) { loggingTrigger = eTriggerLog_NULL; } + +/** +* @brief This routine checks to see if a USB or flash logging action needs to be taken +* The routine checks for a start condition via button press, USB command, or BLE command +* Once one of these start conditions is present, the logging begins until stopped or memory is full +* @return 1 if successful, 0 if error or logging was aborted and no logging occurred +*/ +uint8_t LoggingService_ServiceRoutine(void) { + uint32_t fifoData; + uint32_t endPage; + USBSerial *usbSerial = Peripherals::usbSerial(); + // BMP280 *bmp280 = Peripherals::bmp280(); + bool buttonPressed; + int packetBurstCount = 0; + HspLed *hspLed = Peripherals::hspLed(); + + sramIndex = 0; + // only start logging if conditions exist + + if (_LoggingService_CheckStartCondition() == false) return 0; + printf("Begin Logging..."); + if (startEvent == eStartEvent_NULL) printf("eStartEvent_NULL..."); + if (startEvent == eStartEvent_BLE) printf("eStartEvent_BLE..."); + if (startEvent == eStartEvent_BUTTON) printf("eStartEvent_BUTTON..."); + if (startEvent == eStartEvent_RPC_TO_USB) printf("eStartEvent_RPC_TO_USB..."); + if (startEvent == eStartEvent_RPC_TO_FLASH) printf("eStartEvent_RPC_TO_FLASH..."); + fflush(stdout); + + // start logging stuttered blink pattern + hspLed->pattern(0xA0F3813, 20); + + if (startEvent == eStartEvent_RPC_TO_FLASH || + startEvent == eStartEvent_BUTTON) { + // check to see if datalog already in flash... abort and force user to erase + // flash if needed + if (loggingOutput == eLogToFlash) { + if (isFlashEmpty() == 0) { + Logging_SetStart(false); + // bleStartCommand = 0x00; + BlinkFlashNotEmpty(); + hspLed->blink(1000); + printf("Abort Logging, flash log exists. "); + fflush(stdout); + return 0; + } + } + } + + if (startEvent == eStartEvent_BLE) { + // check for mission in flash + if (_LoggingService_ReadMissionFromFlash() == false) { + // if there is no mission in flash then do a default mission for the sake + // of ble Android app working "out-of-the-box" and stream RtoR and Accel + printf("No Mission in Flash...ExecuteDefaultMission..."); + fflush(stdout); + ExecuteDefaultMission(); + // do not log this data + loggingOutput = eLogToNothing; + } else { + // there is a mission in flash check if there is already logged data + if (isFlashEmpty() == 0) { + // just do default mission + printf("Logged Data Detected...ExecuteDefaultMission..."); + fflush(stdout); + ExecuteDefaultMission(); + // do not log this data + loggingOutput = eLogToNothing; + } else { + // flag that we are logging to flash + loggingOutput = eLogToFlash; + } + } + } + + // if we are logging to flash then read mission in flash + if (loggingOutput == eLogToFlash) { + if (_LoggingService_ReadMissionFromFlash() == + false) { // if there is no mission in flash then get out + Logging_SetStart(false); + Peripherals::hspLed()->pattern(0xC3C3C3C3, 20); + wait(2); + printf("Abort Logging, Mission does not exist. "); + fflush(stdout); + return 0; + } + currentPage = Logging_GetLoggingStartPage(); + endPage = Logging_GetLoggingEndPage(); + } + + MAX30001_Helper_SetupInterrupts(); + if (MAX30001_AnyStreamingSet() == 1) { + MAX30001_Helper_StartSync(); + } + + SetDataLoggingStream(TRUE); + ServiceNonInterrupt_Init(); + ServiceNonInterrupt_StartTimer(); + + while (usbSerial->readable()) { + usbSerial->_getc(); + } + fifo_clear(GetUSBIncomingFifo()); // clear USB serial incoming fifo + fifo_clear(GetStreamOutFifo()); + + sram_buffer_0_dirty = 0; + sram_buffer_1_dirty = 0; + + + if (loggingOutput == eLogToNothing) printf("eLogToNothing..."); fflush(stdout); + if (loggingOutput == eLogToFlash) printf("eLogToFlash..."); fflush(stdout); + if (loggingOutput == eLogtoUsb) printf("eLogtoUsb..."); fflush(stdout); + printf("highDataRate=%d...",highDataRate); fflush(stdout); + + + Peripherals::timestampTimer()->reset(); + Peripherals::timestampTimer()->start(); + + _LoggingServer_OutputToCdcAcm_Start(); + while (1) { + if (loggingOutput == eLogToFlash) { + // check if we are at the end of flash + if (currentPage >= endPage) { + BlinkEndOfDatalogging(); // blink for 3 seconds to signal end of logging + break; + } + } + + if (startEvent == eStartEvent_BUTTON) { + buttonPressed = Peripherals::pushButton()->GetButtonFallState(); + if (buttonPressed) { + Peripherals::pushButton()->clearButtonFallState(); + // if there is a dirty sram buffer... flush it to flash + _LoggingServer_WriteDirtySramBufferToFlash(); + BlinkEndOfDatalogging(); // blink for 3 seconds to signal end of logging + break; + } + } + + if (loggingTrigger == eTriggerLog_BLE) { + if (Peripherals::hspBLE()->getStartDataLogging() == false) { + // if there is a dirty sram buffer... flush it to flash + _LoggingServer_WriteDirtySramBufferToFlash(); + BlinkEndOfDatalogging(); // blink for 3 seconds to signal end of logging + break; + } + } + + if (startEvent == eStartEvent_RPC_TO_USB || + startEvent == eStartEvent_RPC_TO_FLASH) { + if (usbSerial->available()) { + if (loggingOutput == eLogToFlash) { + _LoggingServer_WriteDirtySramBufferToFlash(); + } + wait(0.2f); + while (usbSerial->available()) { + usbSerial->_getc(); + } + fifo_clear(GetUSBIncomingFifo()); // clear USB serial incoming fifo + fifo_clear(GetStreamOutFifo()); + break; + } + } + + // check to see if data is available + packetBurstCount = 0; + while (PacketFifo_Empty() == 0) { + if (packetBurstCount >= 100) + break; + fifoData = PacketFifo_GetUint32(); + if (loggingOutput == eLogToFlash) { + _LoggingServer_OutputToFlash(fifoData); + } + if (loggingOutput == eLogtoUsb) { + if (highDataRate == 0) + _LoggingServer_OutputToCdcAcm(fifoData); + else + _LoggingServer_OutputToCdcAcm_Block(fifoData); + } + packetBurstCount++; + } + + if (PacketFifo_Empty() != 0) { + Peripherals::ble()->waitForEvent(); + } + ServiceNonInterrupt_BMP280(bmp280_Logging); + ServiceNonInterrupt_MAX30205(MAX30205_0_Logging, + Peripherals::max30205_top(), + PACKET_MAX30205_TEMP_TOP); + ServiceNonInterrupt_MAX30205(MAX30205_1_Logging, + Peripherals::max30205_bottom(), + PACKET_MAX30205_TEMP_BOTTOM); + } + _LoggingServer_OutputToCdcAcm_End(); + printf("End Logging.\n"); + fflush(stdout); + + bmp280_Logging->stop(); + MAX30205_0_Logging->stop(); + MAX30205_1_Logging->stop(); + MAX30001_Helper_Stop(); // if any MAX30001 streams have been started, stop + // them + MAX30101_Helper_Stop(); // if any MAX30101 streams have been started, stop + // them + Peripherals::lis2dh()->stop(); + SetDataLoggingStream(FALSE); + Peripherals::timestampTimer()->stop(); + hspLed->blink(1000); + // default to non-usb packet speed optimizing + highDataRate = 0; + loggingTrigger = eTriggerLog_NULL; + return 1; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/LoggingService/DataLoggingService.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _LOGGINGSERVICE_H_ +#define _LOGGINGSERVICE_H_ + +#include "mbed.h" + +/// types of logging +typedef enum { + /// do not log + eLogToNothing, + /// log to USB + eLogtoUsb, + /// Log to external flash memory + eLogToFlash +} eLoggingOutput; + +/// types of logging +typedef enum { + eTriggerLog_NULL, + eTriggerLog_RPC_USB, + eTriggerLog_RPC_FLASH, + eTriggerLog_BUTTON, + eTriggerLog_BLE, +} eLoggingTrigger; + +/// extern that indicates the hardware button on the HSP was pressed +extern uint32_t buttonTrigger; + +void LoggingService_Init(void); + +/** +* @brief This routine checks to see if a USB or flash logging action needs to be +* taken +* The routine checks for a start condition via button press, USB +* command, or BLE command +* Once one of these start conditions is present, the logging begins +* until stopped or memory is full +* @return 1 if successful, 0 if error or logging was aborted and no logging +* occurred +*/ +uint8_t LoggingService_ServiceRoutine(void); +/** +* @brief This is called via one of the RPC USB functions to set start conditons +* to start streaming USB +*/ +void LoggingService_StartLoggingUsb(void); +/** +* @brief This is called via one of the RPC USB functions to set start conditons +* to start logging to flash +*/ +void LoggingService_StartLoggingFlash(void); + +#endif /* _LOGGINGSERVICE_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/LoggingService/Device_Logging.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include "Device_Logging.h" + +/** +* @brief Check if logging is enabled for this device +*/ +int Device_Logging::isLoggingEnabled(void) { return enabled; } + +/** +* @brief Returns the sample rate for the device, rate is in seconds +*/ +int Device_Logging::getLoggingSampleRate(void) { return sampleRate; } + +/** +* @brief Initialize the sampling rate for the device +* @param sampleRate Rate to log device output in seconds +*/ +void Device_Logging::initStart(int sampleRate) { + this->sampleRate = sampleRate; + enabled = 1; +} + +/** +* @brief Disables further datalog and streaming sampling for the device +* @param time Time for next sample in seconds, time is relative to a timer +*/ +void Device_Logging::stop(void) { enabled = 0; } + +/** +* @brief Gets a value that represents when device needs to be sampled again, +* used for datalogging and usb streaming +*/ +int Device_Logging::getNextSampleTime(void) { return nextSampleTime; } + +/** +* @brief Sets a value that represents when device needs to be sampled again, +* used for datalogging and usb streaming +* @param time Time for next sample in seconds, time is relative to a timer +*/ +void Device_Logging::setNextSampleTime(int time) { nextSampleTime = time; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/LoggingService/Device_Logging.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _DEVICE_LOGGING_H_ +#define _DEVICE_LOGGING_H_ + +#include "mbed.h" + +/** +* @brief Class that is used to store device logging parameters when logging to +* flash or streaming usb +*/ +class Device_Logging { +public: + /** + * @brief Check if logging is enabled for this device + */ + int isLoggingEnabled(void); + /** + * @brief Returns the sample rate for the device, rate is in seconds + */ + int getLoggingSampleRate(void); + /** + * @brief Initialize the sampling rate for the device + * @param sampleRate Rate to log device output in seconds + */ + void initStart(int sampleRate); + /** + * @brief Gets a value that represents when device needs to be sampled again, + * used for datalogging and usb streaming + */ + int getNextSampleTime(void); + /** + * @brief Sets a value that represents when device needs to be sampled again, + * used for datalogging and usb streaming + * @param time Time for next sample in seconds, time is relative to a timer + */ + void setNextSampleTime(int time); + /** + * @brief Disables further datalog and streaming sampling for the device + * @param time Time for next sample in seconds, time is relative to a timer + */ + void stop(void); + +private: + /// The sample rate in seconds + int sampleRate; + /// If logging is enabled or not + int enabled; + /// Bookkeeping var to keep track of the next sample time + int nextSampleTime; +}; + +#endif /* _DEVICE_LOGGING_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/LoggingService/Logging.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include "mbed.h" +#include "RpcServer.h" +#include "Logging.h" +#include "S25FS512.h" +#include "Peripherals.h" + +/// length of flash page as dictated by the device +#define LENGTH_OF_FLASH_PAGE 256 // length of flash page in bytes +/// size in bytes of the external flash device on the HSP platform +#define SIZE_OF_EXTERNAL_FLASH \ + (16777216 / 2) // length of external flash in bytes +/// start page of where the mission is defined +#define MISSION_DEFINITION_START_PAGE 0x00 +/// end page of the mission +#define MISSION_DEFINITION_END_PAGE 0x0F +/// page of where the logging data starts +#define LOGGING_START_PAGE 0x12 +/// the last logging page +#define LOGGING_END_PAGE (SIZE_OF_EXTERNAL_FLASH / LENGTH_OF_FLASH_PAGE) + +/// static flag to know if logging was started via RPC +static bool startLoggingViaRpc = false; + +/** +* @brief This will read the mission location and if there is something valid, +* then run the Logging_ProcessMissionCmds() +* @param cmdBuffer buffer +*/ +uint32_t Logging_IsMissionDefined(uint8_t *cmdBuffer) { + uint32_t valid = 1; + if ((cmdBuffer[0] == 0xFF) || (cmdBuffer[0] == 0x0)) + valid = 0; + return valid; +} + +/** +* @brief Read the mission from flash and place in buffer +* @param buffer pointer to byte array that will contain the read results +*/ +int8_t Logging_ReadMissionFromFlash(uint8_t *buffer) { + return Peripherals::s25FS512()->readPages_Helper( + MISSION_DEFINITION_START_PAGE, MISSION_DEFINITION_END_PAGE, buffer, 0); +} + +//****************************************************************************** +// return the page where mission is defined, Mission specific +uint32_t Logging_GetMissionStartPage(void) { + return MISSION_DEFINITION_START_PAGE; +} + +//****************************************************************************** +// return the page where the mission definition ends, Mission specific +uint32_t Logging_GetMissionEndPage(void) { return MISSION_DEFINITION_END_PAGE; } + +//****************************************************************************** +// Returns the location where the Writing can start from, for data logging... +uint32_t Logging_GetLoggingStartPage(void) { return LOGGING_START_PAGE; } + +//****************************************************************************** +// Returns the end location available where the Flash ends essentially.... for +// data logging. +uint32_t Logging_GetLoggingEndPage(void) { return LOGGING_END_PAGE; } + +//****************************************************************************** +void Logging_SetStart(bool state) { startLoggingViaRpc = state; } + +//****************************************************************************** +bool Logging_GetStart(void) { return startLoggingViaRpc; } + +//****************************************************************************** +// for debugging... always say that usb is not connected... for easy bench +// testing +uint32_t Usb_IsConnected(void) { return 0; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/LoggingService/Logging.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,35 @@ +#ifndef _LOGGING_H_ +#define _LOGGING_H_ + +#include "mbed.h" + +/** +* @brief This will read the mission location and if there is something valid, +* then run the Logging_ProcessMissionCmds() +* @param cmdBuffer buffer +*/ +uint32_t Logging_IsMissionDefined(uint8_t *cmdBuffer); + +int8_t Logging_ReadMissionFromFlash(uint8_t *buffer); + +// return the page where mission is defined, Mission specific +uint32_t Logging_GetMissionStartPage(void); + +// return the page where the mission definition ends, Mission specific +uint32_t Logging_GetMissionEndPage(void); + +// Returns the location where the Writing can start from, for data logging... +uint32_t Logging_GetLoggingStartPage(void); + +// Returns the end location available where the Flash ends essentially.... for +// data logging. +uint32_t Logging_GetLoggingEndPage(void); + +// returns one if the usb is connected, zero if not +uint32_t Usb_IsConnected(void); + +void Logging_SetStart(bool state); + +bool Logging_GetStart(void); + +#endif /* _LOGGING_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/LoggingService/Logging_RPC.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,279 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ****************************************************************************** + */ +#include "StringHelper.h" +#include <stdint.h> +#include "Streaming.h" +#include "StringInOut.h" +#include "DataLoggingService.h" +#include "Peripherals.h" +#include "Logging.h" + +extern char loggingMissionCmds[4096]; +uint32_t missionCmdIndex; + + //****************************************************************************** + int Logging_RPC_StartMissionDefine(char argStrs[32][32], + char replyStrs[32][32]) { + uint32_t i; + uint32_t reply[1]; + + // reset the missionCmdIndex to the beginning of the cmd buffer + missionCmdIndex = 0; + // clear the mission command buffer, fill with zeros + for (i = 0; i < sizeof(loggingMissionCmds); i++) { + loggingMissionCmds[i] = 0; + } + + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +//****************************************************************************** +int Logging_RPC_AppendMissionCmd(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + char *strPtr; + uint32_t count = 0; + uint8_t result = 0x80; + // append the string to the mission cmd log + strPtr = argStrs[0]; + while (*strPtr != 0) { + loggingMissionCmds[missionCmdIndex] = *strPtr; + missionCmdIndex++; + strPtr++; + // do not overrun buffer + if (missionCmdIndex > (sizeof(loggingMissionCmds) - 2)) { + result = 0xFF; + break; + } + count++; + // do not read more than max count in incoming string + if (count > (32 * 32)) { + result = 0xFF; + break; + } + } + if (result != 0x80) { + reply[0] = 0xFF; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; + } + // add cr/lf to the end of this cmd string + loggingMissionCmds[missionCmdIndex++] = 13; + loggingMissionCmds[missionCmdIndex++] = 10; + + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +//****************************************************************************** +int Logging_RPC_EndMissionDefine(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +//****************************************************************************** +int Logging_RPC_WriteMission(char argStrs[32][32], char replyStrs[32][32]) { + uint8_t page; + char *ptr; + uint32_t reply[1]; + + Peripherals::s25FS512()->parameterSectorErase_Helper(0x0); + ptr = loggingMissionCmds; + for (page = 0; page < 16; page++) { + Peripherals::s25FS512()->writePage_Helper(page, (uint8_t *)ptr, 0); + ptr += 256; + } + + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +//****************************************************************************** +int Logging_RPC_ReadMission(char argStrs[32][32], char replyStrs[32][32]) { + char *ptr; + uint32_t i; + // read sector 0 + ptr = loggingMissionCmds; + for (i = 0; i < 16; i++) { + Peripherals::s25FS512()->readPages_Helper(i, i, (uint8_t *)ptr, 0); + ptr += 256; + } + // strip header by shifting payload left + ptr = loggingMissionCmds; + for (i = 0; i < sizeof(loggingMissionCmds); i++) { + if (*ptr == 13) { + *ptr = ':'; + } else if (*ptr == 10) { + *ptr = ' '; + } + ptr++; + } + if (loggingMissionCmds[0] == 0xFF || loggingMissionCmds[0] == 0x0) { + sprintf(loggingMissionCmds, "%s", "null "); + } + // send it out via uart + putStr(loggingMissionCmds); + replyStrs[0][0] = 0; + return 0; +} + +//****************************************************************************** +int Logging_RPC_EraseMission(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + Peripherals::s25FS512()->parameterSectorErase_Helper(0x0); + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +#define SECTOR_SIZE_256K 0x10000 +#define PAGE_INC_256K 0x400 +#define SECTOR_SIZE_4K 0x1000 +#define PAGE_INC_4K 0x10 +#define TOTAL_SECTOR_NUMBER 263 + +//****************************************************************************** +int Logging_EraseWrittenSectors(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + uint8_t data[512]; + uint32_t address; + uint32_t pageNumber; + uint32_t pageEmpty; + uint32_t currentSector; + + pageNumber = PAGE_INC_4K; + address = SECTOR_SIZE_4K; + currentSector = 0; + printf("Logging_EraseWrittenSectors "); + fflush(stdout); + printf("pageNumber %d 0x%X ", pageNumber, pageNumber); + fflush(stdout); + printf("SECTOR_SIZE_4K %d 0x%X ...", SECTOR_SIZE_4K, SECTOR_SIZE_4K); + fflush(stdout); + // always erase this sector... the first part is used for the mission resume + // table + Peripherals::s25FS512()->sectorErase_Helper(address); + address += SECTOR_SIZE_4K; + while (currentSector < TOTAL_SECTOR_NUMBER) { + // sample the page + pageNumber = address >> 8; + Peripherals::s25FS512()->readPages_Helper(pageNumber, pageNumber, data, 0); + pageEmpty = Peripherals::s25FS512()->isPageEmpty(data); + if (pageEmpty == 0) { + Peripherals::s25FS512()->sectorErase_Helper(address); + } else { + // stop processing... all of the sectors from here on out should be empty + // printf("Logging_EraseWrittenSectors break "); fflush(stdout); + // break; + } + currentSector++; + if (currentSector < 8) { + address += SECTOR_SIZE_4K; + } + if (currentSector == 8) { + address = SECTOR_SIZE_256K; + } + if (currentSector > 8) { + address += SECTOR_SIZE_256K; + } + } + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + printf("Logging_EraseWrittenSectors done. \n"); + fflush(stdout); + return 0; +} + +//****************************************************************************** +int Logging_Start(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + Logging_SetStart(true); + reply[0] = 0x80; // indicate success + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +//****************************************************************************** +int Logging_GetLastWrittenPage(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + + uint32_t page; + uint32_t lastPage; + uint32_t pageEmpty; + uint8_t data[512]; + + printf("Logging_GetLastWrittenPage "); + fflush(stdout); + lastPage = Logging_GetLoggingEndPage(); + for (page = 2; page <= lastPage; page++) { + // Peripherals::serial()->printf("checking page %d ",page); fflush(stdout); + // sample the page + Peripherals::s25FS512()->readPages_Helper(page, page, data, 0); + pageEmpty = Peripherals::s25FS512()->isPageEmpty(data); + if (pageEmpty != 0) { + break; + } + } + if (page > lastPage) + page = lastPage; + printf("last page %d, 0x%X ", page, page); + fflush(stdout); + reply[0] = page; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +extern int highDataRate; +//****************************************************************************** +int Logging_StartLoggingUsb(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + // highDataRate = 0; + LoggingService_StartLoggingUsb(); + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} +//****************************************************************************** +int Logging_StartLoggingFlash(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + // highDataRate = 0; + LoggingService_StartLoggingFlash(); + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/LoggingService/Logging_RPC.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _LOGGING_H_ +#define _LOGGING_H_ + +int Logging_RPC_StartMissionDefine(char argStrs[32][32], char replyStrs[32][32]); +int Logging_RPC_AppendMissionCmd(char argStrs[32][32], char replyStrs[32][32]); +int Logging_RPC_EndMissionDefine(char argStrs[32][32], char replyStrs[32][32]); +int Logging_RPC_WriteMission(char argStrs[32][32], char replyStrs[32][32]); +int Logging_RPC_ReadMission(char argStrs[32][32], char replyStrs[32][32]); +int Logging_RPC_EraseMission(char argStrs[32][32], char replyStrs[32][32]); +int Logging_RPC_TestMission(char argStrs[32][32], char replyStrs[32][32]); +int Logging_RPC_TestWriteLog(char argStrs[32][32], char replyStrs[32][32]); +int Logging_RPC_TestReadLog(char argStrs[32][32], char replyStrs[32][32]); +int Logging_RPC_TestBulkErase(char argStrs[32][32], char replyStrs[32][32]); +int Logging_RPC_TestSectorsErase(char argStrs[32][32], char replyStrs[32][32]); +int Logging_RPC_TestReadPage(char argStrs[32][32], char replyStrs[32][32]); +int Logging_RPC_TestWritePage(char argStrs[32][32], char replyStrs[32][32]); +int Logging_EraseWrittenSectors(char argStrs[32][32], char replyStrs[32][32]); +int Logging_StartLoggingUsb(char argStrs[32][32], char replyStrs[32][32]); +int Logging_StartLoggingFlash(char argStrs[32][32], char replyStrs[32][32]); +int Logging_GetLastWrittenPage(char argStrs[32][32], char replyStrs[32][32]); +int Logging_Start(char argStrs[32][32], char replyStrs[32][32]); + +#endif /* _LOGGING_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/LoggingService/ServiceNonInterrupt.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,142 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include "ServiceNonInterrupt.h" +#include "Streaming.h" +#include "BMP280.h" +#include "PacketFifo.h" +#include "MAX30205.h" +#include "Stream.h" +#include "BMP280.h" +#include "PacketFifo.h" +#include "Peripherals.h" +#include "Device_Logging.h" + +/// timer used for devices that do not have interrupt capability +static Timer nonInterruptTimer; + +/// reference to logging object for the BMP280 +extern Device_Logging *bmp280_Logging; +/// reference to logging object for the MAX30205 (instance 0) +extern Device_Logging *MAX30205_0_Logging; +/// reference to logging object for the MAX30205 (instance 1) +extern Device_Logging *MAX30205_1_Logging; + +/** +* @brief Initialize the book keeping variables for non interrupt devices +*/ +void ServiceNonInterrupt_Init(void) { + // clear out the next time member in the device logging class + // this is so that the devices are sampled the very first go-around + bmp280_Logging->setNextSampleTime(0); + MAX30205_0_Logging->setNextSampleTime(0); + MAX30205_1_Logging->setNextSampleTime(0); +} + +/** +* @brief Stop the 1 second timer +*/ +void ServiceNonInterrupt_StartTimer(void) { + nonInterruptTimer.start(); + nonInterruptTimer.reset(); +} + +/** +* @brief Stop the 1 second timer +*/ +void ServiceNonInterrupt_StopTimer(void) { nonInterruptTimer.stop(); } + +/** +* @brief Get the current count of the timer +* @return timer count in seconds +*/ +static int ServiceNonInterrupt_GetTimerCount(void) { + return nonInterruptTimer.read(); +} + +/** +* @brief Log the BMP280 sensor value if it is time +* @param deviceLogging pointer to object that keeps track of logging for a +* device +*/ +void ServiceNonInterrupt_BMP280(Device_Logging *deviceLogging) { + int currentTime; + uint32_t bmp280_data[2]; // index 0 - Temp (deg C), index 1 - Press (Pa). + // Divide the result by 10 to get the correct answer. + float temp_C, press_P; + int nextTime; + + if (deviceLogging->isLoggingEnabled() == 0) + return; + currentTime = ServiceNonInterrupt_GetTimerCount(); + nextTime = deviceLogging->getNextSampleTime(); + if ((nextTime == 0) || (currentTime >= nextTime)) { + nextTime = currentTime + deviceLogging->getLoggingSampleRate(); + deviceLogging->setNextSampleTime(nextTime); + Peripherals::bmp280()->ReadCompData( + &temp_C, &press_P); // Read the Temp (index 0) and Pressure (index 1) + bmp280_data[0] = (int32_t)(temp_C * 10); + bmp280_data[1] = (int32_t)(press_P * 10); + PacketFifo_InsertPacket(PACKET_BMP280_PRESSURE, &bmp280_data[0], + 2); // Read it and insert it into the FIFO + } +} + +/** +* @brief Log the BMP280 sensor value if it is time +* @param deviceLogging pointer to object that keeps track of logging for a +* device +* @param device pointer to the device instance (MAX30205 instance 0 or MAX30205 +* instance 1) +* @param packetId packet id that is used when building a packet +*/ +void ServiceNonInterrupt_MAX30205(Device_Logging *deviceLogging, + MAX30205 *device, uint32_t packetId) { + int currentTime; + uint32_t data; + uint16_t tempData; + int nextTime; + + if (deviceLogging->isLoggingEnabled() == 0) + return; + currentTime = ServiceNonInterrupt_GetTimerCount(); + nextTime = deviceLogging->getNextSampleTime(); + if ((nextTime == 0) || (currentTime >= nextTime)) { + nextTime = currentTime + deviceLogging->getLoggingSampleRate(); + deviceLogging->setNextSampleTime(nextTime); + device->readTemperature(&tempData); + // assemble this in the correct order + data = (uint32_t)((tempData >> 8) + ((tempData & 0xFF) << 8)); + PacketFifo_InsertPacket(packetId, &data, + 1); // Read it and insert it into the FIFO + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/LoggingService/ServiceNonInterrupt.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _SERVICENONINTERRUPT_H_ +#define _SERVICENONINTERRUPT_H_ + +#include "mbed.h" +#include "Device_Logging.h" +#include "MAX30205.h" +/** +* @brief Initialize the book keeping variables for non interrupt devices +*/ +void ServiceNonInterrupt_Init(void); +/** +* @brief Start the 1 second timer +*/ +void ServiceNonInterrupt_StartTimer(void); +/** +* @brief Stop the 1 second timer +*/ +void ServiceNonInterrupt_StopTimer(void); +/** +* @brief Log the BMP280 sensor value if it is time +* @param deviceLogging pointer to object that keeps track of logging for a device +*/ +void ServiceNonInterrupt_BMP280(Device_Logging *deviceLogging); +/** +* @brief Log the BMP280 sensor value if it is time +* @param deviceLogging pointer to object that keeps track of logging for a device +* @param device pointer to the device instance (MAX30205 instance 0 or MAX30205 instance 1) +* @param packetId packet id that is used when building a packet +*/ +void ServiceNonInterrupt_MAX30205(Device_Logging *deviceLogging, MAX30205 *device, uint32_t packetId); + +#endif /* _SERVICENONINTERRUPT_H_ */ + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/QuadSPI/QuadSpi.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include "QuadSpi.h" +#include "spi_multi_api.h" + +/** Initialize a SPI master for Quad SPI + * + * @param mosi Pin used for Master Out Slave In + * @param miso Pin used for Master In Slave Out + * @param sclk Pin used for Clock + * @param ssel Pin used for Chip Select + */ +QuadSPI::QuadSPI(PinName mosi, PinName miso, PinName sclk, PinName ssel) + : SPI(mosi, miso, sclk, ssel) { +} + +/******************************************************************************/ +void QuadSPI::setQuadMode() { spi_master_width(&_spi, WidthQuad); } +/******************************************************************************/ +void QuadSPI::setSingleMode() { spi_master_width(&_spi, WidthSingle); } + +/** Write a byte out in master mode and receive a value + * + * @param value Byte Value to send + * @return Returns Zero + */ +int QuadSPI::write(int value) { + aquire(); + spi_master_write(&_spi, value); + return 0; +} + +/** Read a byte in master mode using Quad SPI simplex transfer + * + * @return Returns the value received from Quad SPI + */ +int QuadSPI::read(void) { + aquire(); + return spi_master_read(&_spi); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/QuadSPI/QuadSpi.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _QUADSPI_H_ +#define _QUADSPI_H_ + +#include "mbed.h" + + + + +/** +* This class provides a Quad SPI interface for quad spi devices +* the class also allows single (4-Wire) communication +*/ +class QuadSPI : SPI { + +public: + /** Create a QuadSPI master connected to the specified pins + * + * mosi or miso can be specfied as NC if not used + * + * @param mosi QuadSPI Master Out, Slave In pin + * @param miso QuadSPI Master In, Slave Out pin + * @param sclk QuadSPI Clock pin + * @param ssel QuadSPI chip select pin + */ + QuadSPI(PinName mosi, PinName miso, PinName sclk, PinName ssel = NC); + + /** Write to the Quad SPI Slave and return the response + * + * @param value Data to be sent to the SPI slave + * + * @returns + * none + */ + int write(int value); + + /** Read from the Quad SPI Slave and return the response + * + * @param none + * + * @returns + * Response from the SPI slave + */ + int read(void); + + /** Allow switching to and from Single SPI and Quad SPI + * + * @param none + * + * @returns + * Response from the SPI slave + */ + void setSingleMode(); + void setQuadMode(); +}; + +#endif /* _QUADSPI_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/RpcServer/PacketFifo.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include "RpcFifo.h" +#include "Streaming.h" +#include "RpcServer.h" + +// this will create a packet and insert it on the "jFifo" to be streamed out or +// saved in flash +void PacketFifo_InsertPacket(uint32_t packetId, uint32_t *buffer, + uint32_t numberInBuffer) { + StreamPacketUint32(packetId, buffer, numberInBuffer); +} + +// clears the packet fifo "jFifo" +void PacketFifo_Clear(void) { fifo_clear(GetStreamOutFifo()); } + +// returns one if fifo is empty, zero if not empty +int PacketFifo_Empty(void) { return fifo_empty(GetStreamOutFifo()); } + +// returns a uint32 from the fifo, this uint32 is destined to be streamed out +// USB or saved in flash +uint32_t PacketFifo_GetUint32(void) { + uint32_t val; + fifo_get32(GetStreamOutFifo(), &val); + return val; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/RpcServer/PacketFifo.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,61 @@ +/******************************************************************************* +* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES +* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Except as contained in this notice, the name of Maxim Integrated +* Products, Inc. shall not be used except as stated in the Maxim Integrated +* Products, Inc. Branding Policy. +* +* The mere transfer of this software does not imply any licenses +* of trade secrets, proprietary technology, copyrights, patents, +* trademarks, maskwork rights, or any other form of intellectual +* property whatsoever. Maxim Integrated Products, Inc. retains all +* ownership rights. +******************************************************************************* +*/ +#ifndef _PACKETFIFO_H_ +#define _PACKETFIFO_H_ + +#include "mbed.h" + +/** +* this will create a packet and insert it into an outbound fifo to be streamed out or saved in flash +* @param packetId number id to assign to this packet +* @param buffer a 32-bit buffer that contains data that will be used in the packet +* @param numberInBuffer the number of 32-bit elements to be copied from the buffer +*/ +void PacketFifo_InsertPacket(uint32_t packetId, uint32_t *buffer, uint32_t numberInBuffer); + +/** +* clears the packet outbound fifo +*/ +void PacketFifo_Clear(void); + +/** +* returns one if outbound fifo is empty, zero if not empty +*/ +uint32_t PacketFifo_Empty(void); + +/** +* returns a uint32 from the fifo, this uint32 is destined to be streamed out USB or saved in flash +*/ +uint32_t PacketFifo_GetUint32(void); + +#endif /* _PACKETFIFO_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/RpcServer/RpcDeclarations.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,688 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _RPCDECLARATIONS_H_ +#define _RPCDECLARATIONS_H_ + +/// define the parts of a RPC. ObjectName, MethodName and function +struct RPC_registeredProcedure { + const char *objectName; + const char *methodName; + //enum eArgType argTypes[4]; + int (*func)(char args[32][32], char results[32][32]); + struct RPC_registeredProcedure *next; +}; + +/// used to keep track of the head of the list and the end of a list +struct RPC_Object { + struct RPC_registeredProcedure *head; + struct RPC_registeredProcedure *last; +}; + + +#define I2C_NAME "I2c" +/** +* @brief /I2c/WriteRead instance slaveAddress writeNumber dataToWrite readNumber +* @details Command allows you to write and read generic I2c commands using a given I2c instance master +* @param instance The I2c master on the Nimitz to use +* @param slaveAddress Slave address to use when communicating +* @param writeNumber The number of bytes to write +* @param dataToWrite A series of space separated hex values that are to be written +* @param readNumber The number of bytes to read may be 0 if reading is not needed +* @details Example: /I2c/WriteRead 1 A0 3 11 22 33 2 +* @details This performs an I2c write and read using instance 1, slave address A0, and writes 3 bytes, +* @details the 3 bytes that are written are 11 22 33, 2 bytes are meant to be read after the write +*/ +struct RPC_registeredProcedure Define_I2c_WriteRead = { I2C_NAME, "WriteRead", I2C_WriteRead }; + +//example /I2c/WriteRead 1 A0 3 11 22 33 2 +#define System_NAME "System" + +/** +* @brief /System/ReadVer +* @details Returns the version string of the FW that is currently running +* @details Example: /System/ReadVer +* @details The command returns a version string similar to this: "HSP FW Version 2.0.1f 8/23/16" +*/ +struct RPC_registeredProcedure Define_System_ReadVer = { System_NAME, "ReadVer", System_ReadVer }; +/** +* @brief /System/ReadBuildTime +* @details Returns the build string of the FW that is currently running, this is the time and date that the firmware was built +* @details Example: /System/ReadBuildTime +* @details The command returns a build string similar to this: "Build Time: Fri Jul 1 15:48:31 2016" +*/ +struct RPC_registeredProcedure Define_System_ReadBuildTime = { System_NAME, "ReadBuildTime", System_ReadBuildTime }; + +#define MAX30101_NAME "MAX30101" //"MAX30101" +/** +* @brief /MAX30101/WriteReg address data +* @details Returns the version string of the FW that is currently running +* @param address Register address to write to within the MAX30101 +* @param data The data to write to the MAX30101 +* @details Example: /MAX30101/WriteReg 01 123456 +*/ +struct RPC_registeredProcedure Define_MAX30101_WriteReg = { MAX30101_NAME, "WriteReg", MAX30101_WriteReg }; +/** +* @brief /MAX30101/ReadReg address data +* @details Returns the version string of the FW that is currently running +* @param address Register address to write to within the MAX30101 +* @param data The data to write to the MAX30101 +* @details Example: /MAX30101/WriteReg 01 123456 +*/ +struct RPC_registeredProcedure Define_MAX30101_ReadReg = { MAX30101_NAME, "ReadReg", MAX30101_ReadReg }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30101_SpO2mode_Init = { MAX30101_NAME, "SpO2mode_init", MAX30101_SpO2mode_init }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30101_SpO2mode_InitStart = { MAX30101_NAME, "SpO2mode_InitStart", MAX30101_SpO2mode_InitStart }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30101_HRmode_Init = { MAX30101_NAME, "HRmode_init", MAX30101_HRmode_init }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30101_HRmode_InitStart = { MAX30101_NAME, "HRmode_InitStart", MAX30101_HRmode_InitStart }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30101_Multimode_init = { MAX30101_NAME, "Multimode_init", MAX30101_Multimode_init }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30101_Multimode_InitStart = { MAX30101_NAME, "Multimode_InitStart", MAX30101_Multimode_InitStart }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30101_SpO2mode_stop = { MAX30101_NAME, "SpO2mode_stop", MAX30101_SpO2mode_stop }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30101_HRmode_stop = { MAX30101_NAME, "HRmode_stop", MAX30101_HRmode_stop }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30101_Multimode_stop = { MAX30101_NAME, "Multimode_stop", MAX30101_Multimode_stop }; + +#define MAX30001_NAME "MAX30001" +#define MAX30003_NAME "MAX30003" + +#define MAX31725_NAME "MAX31725" +#define MAX30205_NAME "MAX30205" + +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30001_WriteReg = { MAX30001_NAME, "WriteReg", MAX30001_WriteReg }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30001_ReadReg = { MAX30001_NAME, "ReadReg", MAX30001_ReadReg }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30001_Start = { MAX30001_NAME, "Start", MAX30001_Start }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30001_Stop = { MAX30001_NAME, "Stop", MAX30001_Stop }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30001_Rbias_FMSTR_Init = { MAX30001_NAME, "Rbias_FMSTR_Init", MAX30001_Rbias_FMSTR_Init }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30001_CAL_InitStart = { MAX30001_NAME, "CAL_InitStart", MAX30001_CAL_InitStart }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30001_ECG_InitStart = { MAX30001_NAME, "ECG_InitStart", MAX30001_ECG_InitStart }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30001_ECGFast_Init = { MAX30001_NAME, "ECGFast_Init", MAX30001_ECGFast_Init }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30001_PACE_InitStart = { MAX30001_NAME, "PACE_InitStart", MAX30001_PACE_InitStart }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30001_BIOZ_InitStart = { MAX30001_NAME, "BIOZ_InitStart", MAX30001_BIOZ_InitStart }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30001_RtoR_InitStart = { MAX30001_NAME, "RtoR_InitStart", MAX30001_RtoR_InitStart }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30001_Stop_ECG = { MAX30001_NAME, "Stop_ECG", MAX30001_Stop_ECG }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30001_Stop_PACE = { MAX30001_NAME, "Stop_PACE", MAX30001_Stop_PACE }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30001_Stop_BIOZ = { MAX30001_NAME, "Stop_BIOZ", MAX30001_Stop_BIOZ }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30001_Stop_RtoR = { MAX30001_NAME, "Stop_RtoR", MAX30001_Stop_RtoR }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30001_Stop_Cal = { MAX30001_NAME, "Stop_Cal", MAX30001_Stop_Cal }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30001_Enable_ECG_LeadON = { MAX30001_NAME, "Enable_ECG_LeadON", MAX30001_Enable_ECG_LeadON }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30001_Enable_BIOZ_LeadON = { MAX30001_NAME, "Enable_BIOZ_LeadON", MAX30001_Enable_BIOZ_LeadON }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30001_Read_LeadON = { MAX30001_NAME, "Read_LeadON", MAX30001_Read_LeadON }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30001_StartTest = { MAX30001_NAME, "StartTest", MAX30001_StartTest }; +/** +* @brief /MAX30101/SpO2mode_init fifo_waterlevel_mark sample_avg sample_rate pulse_width red_led_current ir_led_current +* @details This function sets up for the SpO2 mode. +* @param fifo_waterlevel_mark +* @param sample_avg +* @param sample_rate +* @param pulse_width +* @param red_led_current +* @param ir_led_current +*/ +struct RPC_registeredProcedure Define_MAX30001_INT_assignment = { MAX30001_NAME, "INT_assignment", MAX30001_INT_assignment }; + +#define LOGGING_NAME "Logging" +/** +* @brief /Logging/StartMissionDefine +* @details A command to send when you are starting to define a mission +*/ +struct RPC_registeredProcedure Define_Logging_StartMissionDefine = { LOGGING_NAME, "StartMissionDefine", Logging_RPC_StartMissionDefine }; +/** +* @brief /Logging/AppendMissionCmd missionString +* @details Specify a RPC command that is part of a mission +*/ +struct RPC_registeredProcedure Define_Logging_AppendMissionCmd = { LOGGING_NAME, "AppendMissionCmd", Logging_RPC_AppendMissionCmd }; +/** +* @brief /Logging/EndMissionDefine +* @details RPC command that indicated the end of defining a mission +*/ +struct RPC_registeredProcedure Define_Logging_EndMissionDefine = { LOGGING_NAME, "EndMissionDefine", Logging_RPC_EndMissionDefine }; +/** +* @brief /Logging/WriteMission +* @details Write the described mission to flash +*/ +struct RPC_registeredProcedure Define_Logging_WriteMission = { LOGGING_NAME, "WriteMission", Logging_RPC_WriteMission }; +/** +* @brief /Logging/ReadMission +* @details Read the mission from flash +*/ +struct RPC_registeredProcedure Define_Logging_ReadMission = { LOGGING_NAME, "ReadMission", Logging_RPC_ReadMission }; +/** +* @brief /Logging/EraseMission +* @details Erase the mission in flash +*/ +struct RPC_registeredProcedure Define_Logging_EraseMission = { LOGGING_NAME, "EraseMission", Logging_RPC_EraseMission }; +/** +* @brief /Logging/EraseWrittenSectors +* @details Erase the datalog in flash, this erases all of the datalog that has been written to the flash +*/ +struct RPC_registeredProcedure Define_Logging_EraseWrittenSectors = { LOGGING_NAME, "EraseWrittenSectors", Logging_EraseWrittenSectors }; +/** +* @brief /Logging/StartLoggingUsb +* @details Start streaming data through USB +*/ +struct RPC_registeredProcedure Define_Logging_StartLoggingUsb = { LOGGING_NAME, "StartLoggingUsb", Logging_StartLoggingUsb }; +/** +* @brief /Logging/StartLoggingFlash +* @details Start logging data to flash +*/ +struct RPC_registeredProcedure Define_Logging_StartLoggingFlash = { LOGGING_NAME, "StartLoggingFlash", Logging_StartLoggingFlash }; +/** +* @brief /Logging/GetLastWrittenPage +* @details Returns the last page that has been written to flash, this call searchs until it finds an empty flash page +*/ +struct RPC_registeredProcedure Define_Logging_GetLastWrittenPage = { LOGGING_NAME, "GetLastWrittenPage", Logging_GetLastWrittenPage }; +/** +* @brief /Logging/Start +* @details Starts a datalogging session into flash, allows the ability to start datalogging via RPC call +*/ +struct RPC_registeredProcedure Define_Logging_Start = { LOGGING_NAME, "Start", Logging_Start }; + +#define LIS2DH_NAME "LIS2DH" +/** +* @brief /LIS2DH/InitStart +* @details Starts streaming interrupts from the LIS2DH device +*/ +struct RPC_registeredProcedure Define_LIS2DH_InitStart = { LIS2DH_NAME, "InitStart", LIS2DH_InitStart }; +/** +* @brief /LIS2DH/ReadReg address +* @details Reads a register +* @param address Register address to read from +*/ +struct RPC_registeredProcedure Define_LIS2DH_ReadReg = { LIS2DH_NAME, "ReadReg", LIS2DH_ReadReg }; +/** +* @brief /LIS2DH/WriteReg address data +* @details Write a register +* @param address Register address to read from +* @param data Data to write +*/ +struct RPC_registeredProcedure Define_LIS2DH_WriteReg = { LIS2DH_NAME, "WriteReg", LIS2DH_WriteReg }; +/** +* @brief /LIS2DH/Stop +* @details Stop the interrupts within the LIS2DH +*/ +struct RPC_registeredProcedure Define_LIS2DH_Stop = { LIS2DH_NAME, "Stop", LIS2DH_Stop }; + +#define BMP280_NAME "BMP280" +/** +* @brief /BMP280/InitStart +* @details Start the polling process for the BMP280 +*/ +struct RPC_registeredProcedure Define_BMP280_InitStart = { BMP280_NAME, "InitStart", BMP280_InitStart }; + +#define MAX30205_1_NAME "MAX30205_1" +#define MAX31725_1_NAME "MAX31725_1" +/** +* @brief /MAX30205_1/InitStart +* @details Start the polling process for the MAX30205 instance 1 +*/ +struct RPC_registeredProcedure Define_MAX30205_1_InitStart = { MAX30205_1_NAME, "InitStart", MAX30205_1_InitStart }; +struct RPC_registeredProcedure Define_MAX31725_1_InitStart = { MAX31725_1_NAME, "InitStart", MAX30205_1_InitStart }; + +#define MAX30205_2_NAME "MAX30205_2" +#define MAX31725_2_NAME "MAX31725_2" +/** +* @brief /MAX30205_2/InitStart +* @details Start the polling process for the MAX30205 instance 2 +*/ +struct RPC_registeredProcedure Define_MAX30205_2_InitStart = { MAX30205_2_NAME, "InitStart", MAX30205_2_InitStart }; +struct RPC_registeredProcedure Define_MAX31725_2_InitStart = { MAX31725_2_NAME, "InitStart", MAX30205_2_InitStart }; + +#define LED_NAME "Led" +/** +* @brief /Led/On +* @details Turn on the HSP onboard LED +*/ +struct RPC_registeredProcedure Define_Led_On = { LED_NAME, "On", Led_On }; +/** +* @brief /Led/Off +* @details Turn off the HSP onboard LED +*/ +struct RPC_registeredProcedure Define_Led_Off = { LED_NAME, "Off", Led_Off }; +/** +* @brief /Led/Blink mS +* @details Start blinking the HSP onboard LED +* @param mS Blink using a mS period +*/ +struct RPC_registeredProcedure Define_Led_BlinkHz = { LED_NAME, "Blink", Led_BlinkHz }; +/** +* @brief /Led/Pattern pattern +* @details Rotate a 32-bit pattern through the LED so that specific blink patterns can be obtained +* @param pattern A 32-bit pattern to rotate through +*/ +struct RPC_registeredProcedure Define_Led_BlinkPattern = { LED_NAME, "Pattern", Led_BlinkPattern }; + +#define S25FS512_NAME "S25FS512" +/** +* @brief /S25FS512/ReadId +* @details Rotate a 32-bit pattern through the LED so that specific blink patterns can be obtained +* @param pattern A 32-bit pattern to rotate through +*/ +struct RPC_registeredProcedure Define_S25FS512_ReadId = { S25FS512_NAME, "ReadId", S25FS512_ReadId }; +/** +* @brief /S25FS512/ReadPagesBinary startPage endPage +* @details Read a page from flash, return the data in binary (non-ascii) +* @param startPage The Starting page to read from +* @param endPage The last page to read from +*/ +struct RPC_registeredProcedure Define_S25FS512_ReadPagesBinary = { S25FS512_NAME, "ReadPagesBinary", S25FS512_ReadPagesBinary }; +/** +* @brief /S25FS512/Reset +* @details Issue a soft reset to the flash device +*/ +struct RPC_registeredProcedure Define_S25FS512_Reset = { S25FS512_NAME, "Reset", S25FS512_Reset }; +/** +* @brief /S25FS512/EnableHWReset +* @details Enable HW resets to the device +*/ +struct RPC_registeredProcedure Define_S25FS512_EnableHWReset = { S25FS512_NAME, "EnableHWReset", S25FS512_EnableHWReset }; +/** +* @brief /S25FS512/SpiWriteRead +* @details Write and read SPI to the flash device using Quad SPI +*/ +struct RPC_registeredProcedure Define_S25FS512_SpiWriteRead = { S25FS512_NAME, "SpiWriteRead", S25FS512_SpiWriteRead }; +/** +* @brief /S25FS512/SpiWriteRead4Wire +* @details Write and read SPI to the flash device using 4 wire +*/ +struct RPC_registeredProcedure Define_S25FS512_SpiWriteRead4Wire = { S25FS512_NAME, "SpiWriteRead4Wire", S25FS512_SpiWriteRead4Wire }; + +#define TESTING_NAME "Testing" +/** +* @brief /Testing/Test_S25FS512 +* @details Start a testing sequence for this device, returns PASS and FAIL strings and detailed results of the test +*/ +struct RPC_registeredProcedure Define_Testing_Test_S25FS512 = { TESTING_NAME, "Test_S25FS512", Test_S25FS512}; +/** +* @brief /Testing/Test_BMP280 +* @details Start a testing sequence for this device, returns PASS and FAIL strings and detailed results of the test +*/ +struct RPC_registeredProcedure Define_Testing_Test_BMP280 = { TESTING_NAME, "Test_BMP280", Test_BMP280}; +/** +* @brief /Testing/Test_LIS2DH +* @details Start a testing sequence for this device, returns PASS and FAIL strings and detailed results of the test +*/ +struct RPC_registeredProcedure Define_Testing_Test_LIS2DH = { TESTING_NAME, "Test_LIS2DH", Test_LIS2DH }; +/** +* @brief /Testing/Test_LSM6DS3 +* @details Start a testing sequence for this device, returns PASS and FAIL strings and detailed results of the test +*/ +struct RPC_registeredProcedure Define_Testing_Test_LSM6DS3 = { TESTING_NAME, "Test_LSM6DS3", Test_LSM6DS3 }; +/** +* @brief /Testing/Test_MAX30205_1 +* @details Start a testing sequence for this device, returns PASS and FAIL strings and detailed results of the test +*/ +struct RPC_registeredProcedure Define_Testing_Test_MAX30205_1 = { TESTING_NAME, "Test_MAX30205_1", Test_MAX30205_1 }; +/** +* @brief /Testing/Test_MAX30205_2 +* @details Start a testing sequence for this device, returns PASS and FAIL strings and detailed results of the test +*/ +struct RPC_registeredProcedure Define_Testing_Test_MAX30205_2 = { TESTING_NAME, "Test_MAX30205_2", Test_MAX30205_2 }; +/** +* @brief /Testing/Test_MAX30101 +* @details Start a testing sequence for this device, returns PASS and FAIL strings and detailed results of the test +*/ +struct RPC_registeredProcedure Define_Testing_Test_MAX30101 = { TESTING_NAME, "Test_MAX30101", Test_MAX30101 }; +/** +* @brief /Testing/Test_MAX30001 +* @details Start a testing sequence for this device, returns PASS and FAIL strings and detailed results of the test +*/ +struct RPC_registeredProcedure Define_Testing_Test_MAX30001 = { TESTING_NAME, "Test_MAX30001", Test_MAX30001 }; +/** +* @brief /Testing/Test_EM9301 +* @details Start a testing sequence for this device, returns PASS and FAIL strings and detailed results of the test +*/ +struct RPC_registeredProcedure Define_Testing_Test_EM9301 = { TESTING_NAME, "Test_EM9301", Test_EM9301 }; +/** +* @brief /Testing/Test_EM9301 +* @details Start a testing sequence for this device, returns PASS and FAIL strings and detailed results of the test +*/ +//struct RPC_registeredProcedure Define_Testing_Test_SensorReadings = { TESTING_NAME, "Test_SensorReadings", Test_EM9301 }; + +#define MAX14720_NAME "MAX14720" +/** +* @brief /MAX14720/ReadBoostVSet +* @details Read the BoostVSet value +* @return Returns the value from the BoostVSet register of the device +*/ +struct RPC_registeredProcedure Define_MAX14720_ReadBoostVSet = { MAX14720_NAME, "ReadBoostVSet", MAX14720_ReadBoostVSet }; +/** +* @brief /MAX14720/WriteBoostVSet +* @details Write the BoostVSet value +* @param value The binary value to set the BoostVSet register to +* @return Returns 0x80 on success of the command +*/ +struct RPC_registeredProcedure Define_MAX14720_WriteBoostVSet = { MAX14720_NAME, "WriteBoostVSet", MAX14720_WriteBoostVSet }; +/** +* @brief /MAX14720/ReadReg +* @details Read one of the MAX14720 registers +* @param address Address of the register to read +* @return Returns the value from the addressed register from the device +*/ +struct RPC_registeredProcedure Define_MAX14720_ReadReg = { MAX14720_NAME, "ReadReg", MAX14720_ReadReg }; +/** +* @brief /MAX14720/WriteReg +* @details Write one of the MAX14720 registers +* @param address Address of the register to write +* @param data Value of the data to write +* @return Returns 0x80 on success of the command +*/ +struct RPC_registeredProcedure Define_MAX14720_WriteReg = { MAX14720_NAME, "WriteReg", MAX14720_WriteReg }; + +#endif /* _RPCDECLARATIONS_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/RpcServer/RpcFifo.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,253 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include "mbed.h" +#include "RpcFifo.h" + +/****************************************************************************/ +void fifo_init(fifo_t *fifo, void *mem, unsigned int length) { + // atomic FIFO access + __disable_irq(); + + fifo->rindex = 0; + fifo->windex = 0; + fifo->data = mem; + fifo->length = length; + + __enable_irq(); +} + +/****************************************************************************/ +int fifo_put8(fifo_t *fifo, uint8_t element) { + // Check if FIFO is full + if ((fifo->windex == (fifo->rindex - 1)) || + ((fifo->rindex == 0) && (fifo->windex == (fifo->length - 1)))) { + return -1; + } + + // atomic FIFO access + __disable_irq(); + + // Put data into FIFO + ((uint8_t *)(fifo->data))[fifo->windex] = element; + + // Increment pointer + fifo->windex++; + if (fifo->windex == fifo->length) { + fifo->windex = 0; + } + + __enable_irq(); + + return 0; +} + +/****************************************************************************/ +int fifo_get8(fifo_t *fifo, uint8_t *element) { + // Check if FIFO is empty + if (fifo->rindex == fifo->windex) + return -1; + + // atomic FIFO access + __disable_irq(); + + // Get data from FIFO + *element = ((uint8_t *)(fifo->data))[fifo->rindex]; + + // Increment pointer + fifo->rindex++; + if (fifo->rindex == fifo->length) { + fifo->rindex = 0; + } + + __enable_irq(); + + return 0; +} + +/****************************************************************************/ +int fifo_put16(fifo_t *fifo, uint16_t element) { + // Check if FIFO is full + if ((fifo->windex == (fifo->rindex - 1)) || + ((fifo->rindex == 0) && (fifo->windex == (fifo->length - 1)))) { + return -1; + } + + // atomic FIFO access + __disable_irq(); + + // Put data into FIFO + ((uint16_t *)(fifo->data))[fifo->windex] = element; + + // Increment pointer + fifo->windex++; + if (fifo->windex == fifo->length) { + fifo->windex = 0; + } + + __enable_irq(); + + return 0; +} + +/****************************************************************************/ +int fifo_get16(fifo_t *fifo, uint16_t *element) { + // Check if FIFO is empty + if (fifo->rindex == fifo->windex) + return -1; + + // atomic FIFO access + __disable_irq(); + + // Get data from FIFO + *element = ((uint16_t *)(fifo->data))[fifo->rindex]; + + // Increment pointer + fifo->rindex++; + if (fifo->rindex == fifo->length) { + fifo->rindex = 0; + } + + __enable_irq(); + + return 0; +} + +/****************************************************************************/ +int fifo_put32(fifo_t *fifo, uint32_t element) { + // Check if FIFO is full + if ((fifo->windex == (fifo->rindex - 1)) || + ((fifo->rindex == 0) && (fifo->windex == (fifo->length - 1)))) { + return -1; + } + + // atomic FIFO access + __disable_irq(); + + // Put data into FIFO + ((uint32_t *)(fifo->data))[fifo->windex] = element; + + // Increment pointer + fifo->windex++; + if (fifo->windex == fifo->length) { + fifo->windex = 0; + } + + __enable_irq(); + + return 0; +} + +/****************************************************************************/ +int fifo_get32(fifo_t *fifo, uint32_t *element) { + // Check if FIFO is empty + if (fifo->rindex == fifo->windex) + return -1; + + // atomic FIFO access + __disable_irq(); + + // Get data from FIFO + *element = ((uint32_t *)(fifo->data))[fifo->rindex]; + + // Increment pointer + fifo->rindex++; + if (fifo->rindex == fifo->length) { + fifo->rindex = 0; + } + + __enable_irq(); + + return 0; +} +/****************************************************************************/ +void fifo_clear(fifo_t *fifo) { + // atomic FIFO access + __disable_irq(); + + fifo->rindex = 0; + fifo->windex = 0; + + __enable_irq(); +} + +/****************************************************************************/ +int fifo_empty(fifo_t *fifo) { return (fifo->rindex == fifo->windex); } + +/****************************************************************************/ +int fifo_full(fifo_t *fifo) { + int retval; + + // atomic FIFO access + __disable_irq(); + retval = ((fifo->windex == (fifo->rindex - 1)) || + ((fifo->rindex == 0) && (fifo->windex == (fifo->length - 1)))); + __enable_irq(); + + return retval; +} + +/****************************************************************************/ +unsigned int fifo_level(fifo_t *fifo) { + uint16_t value; + + // atomic FIFO access + __disable_irq(); + + if (fifo->windex >= fifo->rindex) { + value = fifo->windex - fifo->rindex; + } else { + value = fifo->length - fifo->rindex + fifo->windex; + } + + __enable_irq(); + + return value; +} + +/****************************************************************************/ +unsigned int fifo_remaining(fifo_t *fifo) { + uint16_t value; + + // atomic FIFO access + __disable_irq(); + + if (fifo->rindex > fifo->windex) { + value = fifo->rindex - fifo->windex - 1; + } else { + value = fifo->length - fifo->windex + fifo->rindex - 1; + } + + __enable_irq(); + + return value; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/RpcServer/RpcFifo.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,137 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + ******************************************************************************** + */ +#ifndef _RPCFIFO_H_ +#define _RPCFIFO_H_ + +#include <stdint.h> + +/// Structure used for FIFO management +typedef struct { + unsigned int length; ///< FIFO size (number of elements) + void *data; ///< pointer to the FIFO buffer + unsigned int rindex; ///< current FIFO read index + unsigned int windex; ///< current FIFO write index +} fifo_t; + +/** +* @param fifo FIFO on which to perform the operation +* @param mem memory buffer to use for FIFO element storage +* @param length number of elements that the memory buffer can contain +* @returns 0 if successful, -1 upon failure +*/ +void fifo_init(fifo_t *fifo, void *mem, unsigned int length); + +/** +* @brief Adds and 8-bit element to the FIFO +* @param fifo FIFO on which to perform the operation +* @param element element to add to the FIFO +* @returns 0 if successful, -1 upon failure +*/ +int fifo_put8(fifo_t *fifo, uint8_t element); + +/** +* @brief Gets the next 8-bit element to the FIFO +* @param fifo FIFO on which to perform the operation +* @param element pointer to where to store the element from the FIFO +* @returns 0 if successful, -1 upon failure +*/ +int fifo_get8(fifo_t *fifo, uint8_t *element); + +/** +* @brief Adds the next 16-bit element to the FIFO +* @param fifo FIFO on which to perform the operation +* @param element element to add to the FIFO +* @returns 0 if successful, -1 upon failure +*/ +int fifo_put16(fifo_t *fifo, uint16_t element); + +/** +* @brief Gets the next 16-bit element to the FIFO +* @param fifo FIFO on which to perform the operation +* @param element pointer to where to store the element from the FIFO +* @returns 0 if successful, -1 upon failure +*/ +int fifo_get16(fifo_t *fifo, uint16_t *element); + +/** +* @brief Adds the next 16-bit element to the FIFO +* @param fifo FIFO on which to perform the operation +* @param element element to add to the FIFO +* @returns 0 if successful, -1 upon failure +*/ +int fifo_put32(fifo_t *fifo, uint32_t element); + +/** +* @brief Gets the next 16-bit element to the FIFO +* @param fifo FIFO on which to perform the operation +* @param element pointer to where to store the element from the FIFO +* @returns 0 if successful, -1 upon failure +*/ +int fifo_get32(fifo_t *fifo, uint32_t *element); + +/** +* @brief Immediately resets the FIFO to the empty state +* @param fifo FIFO on which to perform the operation +*/ +void fifo_clear(fifo_t *fifo); + +/** +* @brief Determines if the FIFO is empty +* @param fifo FIFO on which to perform the operation +* @returns #TRUE if FIFO is empty, #FALSE otherwise +*/ +int fifo_empty(fifo_t *fifo); + +/** +* @brief FIFO status function +* @param fifo FIFO on which to perform the operation +* @returns #TRUE if FIFO is full, #FALSE otherwise +*/ +int fifo_full(fifo_t *fifo); + +/** +* @brief FIFO status function +* @param fifo FIFO on which to perform the operation +* @returns the number of elements currently in the FIFO +*/ +unsigned int fifo_level(fifo_t *fifo); + +/** +* @brief FIFO status function +* @param fifo FIFO on which to perform the operation +* @returns the remaining elements that can be added to the FIFO +*/ +unsigned int fifo_remaining(fifo_t *fifo); + +#endif // _RPCFIFO_H_
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/RpcServer/RpcServer.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,445 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include "RpcServer.h" +#include "StringInOut.h" +#include "StringHelper.h" +#include "MAX30001_RPC.h" +#include "MAX30101_RPC.h" +#include "LIS2DH_RPC.h" +#include "Logging_RPC.h" +#include "Peripherals.h" +#include "I2C_RPC.h" +#include "BMP280_RPC.h" +#include "MAX30205_RPC.h" +#include "HspLed_RPC.h" +#include "S25FS512_RPC.h" +#include "Testing_RPC.h" +#include "MAX14720_RPC.h" +#include "RpcDeclarations.h" +#include "Device_Logging.h" + +/// define the version string that is reported with a RPC "ReadVer" command +#define FW_VERSION_STRING "HSP FW Version 3.0.0 10/14/16" + +char args[32][32]; +char results[32][32]; + +/// define a fifo for incoming USB data +static fifo_t fifo; +/// define a buffer for incoming USB data +static uint8_t fifoBuffer[128]; +/// define stream out fifo +static fifo_t fifoStreamOut; +/// allocate a large fifo buffer for streaming out +static uint32_t streamOutBuffer[0xC000 / 4]; + +/// define a device log for the BMP280, keeps track of mission and loggin status +Device_Logging *bmp280_Logging; +/// define a device log for the MAX30205 (instance 0), keeps track of mission +/// and loggin status +Device_Logging *MAX30205_0_Logging; +/// define a device log for the MAX30205 (instance 1), keeps track of mission +/// and loggin status +Device_Logging *MAX30205_1_Logging; + +//****************************************************************************** +fifo_t *GetUSBIncomingFifo(void) { return &fifo; } + +//****************************************************************************** +fifo_t *GetStreamOutFifo(void) { return &fifoStreamOut; } + +//****************************************************************************** +int System_ReadVer(char argStrs[32][32], char replyStrs[32][32]) { + strcpy(replyStrs[0], FW_VERSION_STRING); + strcpy(replyStrs[1], "\0"); + return 0; +} + +//****************************************************************************** +int System_ReadBuildTime(char argStrs[32][32], char replyStrs[32][32]) { + // strcpy(replyStrs[0],buildTime); + // strcpy(replyStrs[1],"\0"); + return 0; +} + +//****************************************************************************** +int System_SystemCoreClock(char argStrs[32][32], char replyStrs[32][32]) { + sprintf(replyStrs[0], "SystemCoreClock = %d", SystemCoreClock); + strcpy(replyStrs[1], "\0"); + return 0; +} + +//****************************************************************************** +int System_GetTimestamp(char argStrs[32][32], char replyStrs[32][32]) { + sprintf(replyStrs[0], "GetTimestamp = %d", 0); + strcpy(replyStrs[1], "\0"); + return 0; +} + +static struct RPC_Object RPC_Procedures = {NULL, NULL}; + +//****************************************************************************** +void RPC_addProcedure(struct RPC_registeredProcedure *procedure) { + struct RPC_Object *obj = &RPC_Procedures; + if (obj->last != NULL) { + obj->last->next = procedure; + } + if (obj->head == NULL) { + obj->head = procedure; + } + procedure->next = NULL; + obj->last = procedure; +} + +//****************************************************************************** +void RPC_init(void) { + bmp280_Logging = new Device_Logging(); + MAX30205_0_Logging = new Device_Logging(); + MAX30205_1_Logging = new Device_Logging(); + + fifo_init(&fifo, fifoBuffer, sizeof(fifoBuffer)); + fifo_init(&fifoStreamOut, streamOutBuffer, + sizeof(streamOutBuffer) / sizeof(uint32_t)); + + // I2c + RPC_addProcedure(&Define_I2c_WriteRead); + + // MAX30101 + RPC_addProcedure(&Define_MAX30101_WriteReg); + RPC_addProcedure(&Define_MAX30101_ReadReg); + RPC_addProcedure(&Define_MAX30101_SpO2mode_Init); + RPC_addProcedure(&Define_MAX30101_HRmode_Init); + RPC_addProcedure(&Define_MAX30101_Multimode_init); + RPC_addProcedure(&Define_MAX30101_SpO2mode_InitStart); + RPC_addProcedure(&Define_MAX30101_HRmode_InitStart); + RPC_addProcedure(&Define_MAX30101_Multimode_InitStart); + RPC_addProcedure(&Define_MAX30101_SpO2mode_stop); + RPC_addProcedure(&Define_MAX30101_HRmode_stop); + RPC_addProcedure(&Define_MAX30101_Multimode_stop); + + // MAX30001 + RPC_addProcedure(&Define_MAX30001_WriteReg); + RPC_addProcedure(&Define_MAX30001_ReadReg); + RPC_addProcedure(&Define_MAX30001_Start); + RPC_addProcedure(&Define_MAX30001_Stop); + RPC_addProcedure(&Define_MAX30001_Enable_ECG_LeadON); + RPC_addProcedure(&Define_MAX30001_Enable_BIOZ_LeadON); + RPC_addProcedure(&Define_MAX30001_Read_LeadON); + RPC_addProcedure(&Define_MAX30001_StartTest); + RPC_addProcedure(&Define_MAX30001_INT_assignment); + RPC_addProcedure(&Define_MAX30001_Rbias_FMSTR_Init); + RPC_addProcedure(&Define_MAX30001_CAL_InitStart); + RPC_addProcedure(&Define_MAX30001_ECG_InitStart); + RPC_addProcedure(&Define_MAX30001_ECGFast_Init); + RPC_addProcedure(&Define_MAX30001_PACE_InitStart); + RPC_addProcedure(&Define_MAX30001_BIOZ_InitStart); + RPC_addProcedure(&Define_MAX30001_RtoR_InitStart); + RPC_addProcedure(&Define_MAX30001_Stop_ECG); + RPC_addProcedure(&Define_MAX30001_Stop_PACE); + RPC_addProcedure(&Define_MAX30001_Stop_BIOZ); + RPC_addProcedure(&Define_MAX30001_Stop_RtoR); + RPC_addProcedure(&Define_MAX30001_Stop_Cal); + + // Logging + RPC_addProcedure(&Define_Logging_StartMissionDefine); + RPC_addProcedure(&Define_Logging_AppendMissionCmd); + RPC_addProcedure(&Define_Logging_EndMissionDefine); + RPC_addProcedure(&Define_Logging_WriteMission); + RPC_addProcedure(&Define_Logging_ReadMission); + RPC_addProcedure(&Define_Logging_EraseMission); + RPC_addProcedure(&Define_Logging_EraseWrittenSectors); + RPC_addProcedure(&Define_Logging_StartLoggingUsb); + RPC_addProcedure(&Define_Logging_StartLoggingFlash); + RPC_addProcedure(&Define_Logging_GetLastWrittenPage); + RPC_addProcedure(&Define_Logging_Start); + + // LIS2HD + RPC_addProcedure(&Define_LIS2DH_InitStart); + RPC_addProcedure(&Define_LIS2DH_ReadReg); + RPC_addProcedure(&Define_LIS2DH_WriteReg); + RPC_addProcedure(&Define_LIS2DH_Stop); + + // BMP280 + RPC_addProcedure(&Define_BMP280_InitStart); + + // MAX30205 and MAX31725 Alias + RPC_addProcedure(&Define_MAX30205_1_InitStart); + RPC_addProcedure(&Define_MAX30205_2_InitStart); + RPC_addProcedure(&Define_MAX31725_1_InitStart); + RPC_addProcedure(&Define_MAX31725_2_InitStart); + + // led + RPC_addProcedure(&Define_Led_On); + RPC_addProcedure(&Define_Led_Off); + RPC_addProcedure(&Define_Led_BlinkHz); + RPC_addProcedure(&Define_Led_BlinkPattern); + + // S25FS512 + RPC_addProcedure(&Define_S25FS512_ReadId); + RPC_addProcedure(&Define_S25FS512_ReadPagesBinary); + RPC_addProcedure(&Define_S25FS512_Reset); + RPC_addProcedure(&Define_S25FS512_EnableHWReset); + RPC_addProcedure(&Define_S25FS512_SpiWriteRead); + RPC_addProcedure(&Define_S25FS512_SpiWriteRead4Wire); + + // Testing + RPC_addProcedure(&Define_Testing_Test_S25FS512); + RPC_addProcedure(&Define_Testing_Test_BMP280); + RPC_addProcedure(&Define_Testing_Test_LIS2DH); + RPC_addProcedure(&Define_Testing_Test_LSM6DS3); + RPC_addProcedure(&Define_Testing_Test_MAX30205_1); + RPC_addProcedure(&Define_Testing_Test_MAX30205_2); + RPC_addProcedure(&Define_Testing_Test_MAX30101); + RPC_addProcedure(&Define_Testing_Test_MAX30001); + RPC_addProcedure(&Define_Testing_Test_EM9301); + + // System + RPC_addProcedure(&Define_System_ReadVer); + RPC_addProcedure(&Define_System_ReadBuildTime); + + // MAX14720 + RPC_addProcedure(&Define_MAX14720_ReadBoostVSet); + RPC_addProcedure(&Define_MAX14720_WriteBoostVSet); + RPC_addProcedure(&Define_MAX14720_ReadReg); + RPC_addProcedure(&Define_MAX14720_WriteReg); +} + +//****************************************************************************** +struct RPC_registeredProcedure *RPC_lookup(char *objectName, char *methodName) { + struct RPC_registeredProcedure *ptr; + // lookup all registered methods + ptr = RPC_Procedures.head; + while (ptr != NULL) { + if (strcmp(ptr->objectName, objectName) == 0 && + strcmp(ptr->methodName, methodName) == 0) { + // we found a match... return with it + return ptr; + } + ptr = ptr->next; + } + return NULL; +} + +//****************************************************************************** +char *GetToken(char *inStr, char *outStr, int start, char ch) { + int i; + int index = 0; + int length = strlen(inStr); + for (i = start; i < length; i++) { + if (inStr[i] != ch) { + outStr[index++] = inStr[i]; + } else { + break; + } + } + outStr[index++] = 0; + return outStr; +} + +//****************************************************************************** +void SendCommandList(char *reply) { + struct RPC_registeredProcedure *ptr; + reply[0] = 0; + ptr = RPC_Procedures.head; + while (ptr != NULL) { + strcat(reply, "/"); + strcat(reply, ptr->objectName); + strcat(reply, "/"); + strcat(reply, ptr->methodName); + strcat(reply, ","); + ptr = ptr->next; + } + strcat(reply, "\r\n"); +} + +//****************************************************************************** +int CheckForDoubleQuote(char *str) { + int doubleQuoteFound; + // scan through arguments, see if there is a double quote for a string + // argument + doubleQuoteFound = 0; + while (*str != 0) { + if (*str == '\"') { + doubleQuoteFound = 1; + break; + } + str++; + } + return doubleQuoteFound; +} + +//****************************************************************************** +void ExtractDoubleQuoteStr(char *src, char *dst) { + int start; + + dst[0] = 0; + start = 0; + while (*src != 0) { + // look for start + if ((*src == '\"') && (start == 0)) { + start = 1; + src++; + continue; + } + // look for end + if ((*src == '\"') && (start == 1)) { + *dst = 0; // terminate the string + break; + } + if (start == 1) { + *dst = *src; + dst++; + } + src++; + } +} + +//****************************************************************************** +void RPC_call_test(void) { + int doubleQuoteFound; + char doubleQuoteStr[64]; + char *request = "/Logging/AppendMissionCmd \"BMP280 InitStart 1\""; + + // scan through arguments, see if there is a double quote for a string + // argument + doubleQuoteFound = CheckForDoubleQuote(request); + if (doubleQuoteFound) { + ExtractDoubleQuoteStr(request, doubleQuoteStr); + } +} + +//****************************************************************************** +void RPC_call(char *request, char *reply) { + const char slash[2] = "/"; + const char space[2] = " "; + char *objectName; + char *methodName; + char doubleQuoteStr[64]; + char requestCpy[128]; + char *token; + int argIndex; + int resultIndex; + int doubleQuoteFound; + struct RPC_registeredProcedure *procedurePtr; + + // clear out the reply + reply[0] = 0; + // copy the request for scanning and extraction later + strcpy(requestCpy, request); + // check for beginning forward slash + if (request[0] != '/') { + return; + } + // check for only a forward slash + if (request[0] == '/' && request[1] == 0) { + SendCommandList(reply); + return; + } + strcat(request, " "); + // get the object name + token = strtok(request, slash); + // token = GetToken(request, tokenBuffer, 1, '/'); + objectName = token; + if (objectName == NULL) + return; // must have an object name + // get the method name + token = strtok(NULL, space); + methodName = token; + if (methodName == NULL) + return; // must have a method name + + // scan through arguments, see if there is a double quote for a string + // argument + doubleQuoteFound = CheckForDoubleQuote(requestCpy); + + if (doubleQuoteFound == 0) { + // walk through arguments + argIndex = 0; + token = strtok(NULL, space); + while (token != NULL) { + // save this arg in array + strcpy(args[argIndex++], token); + // read next token arg if any + token = strtok(NULL, space); + } + // terminate the end of the string array with an empty string + strcpy(args[argIndex], "\0"); + strcpy(results[0], "\0"); + } else { + // grab out the double quote string + ExtractDoubleQuoteStr(requestCpy, doubleQuoteStr); + argIndex = 0; + // token = strtok(NULL, quote); + strcpy(args[argIndex++], doubleQuoteStr); + } + + // + // alias the MAX30001 and MAX30003 names + // + if (strcmp(objectName, MAX30003_NAME) == 0) { + strcpy(objectName, MAX30001_NAME); + } + + procedurePtr = RPC_lookup(objectName, methodName); + if (procedurePtr != NULL) { + // printf("RPC_call: %s processing\n",requestCpy); + procedurePtr->func(args, results); + } else { + printf("RPC_call: %s not found\n", requestCpy); + // printf("Unable to lookup %s %s", objectName, methodName); + } + + // loop while (if) there are results to return + resultIndex = 0; + strcpy(reply, "\0"); + while (results[resultIndex][0] != '\0') { + strcat(reply, results[resultIndex++]); + strcat(reply, " "); + } + strcat(reply, "\r\n"); +} + +//****************************************************************************** +void RPC_ProcessCmds(char *cmds) { + char cmd[32 * 32]; + char *ptrCmds; + char reply[512]; + ptrCmds = cmds; + + while (*ptrCmds != 0) { + ptrCmds = ParseUntilCRLF(ptrCmds, cmd, sizeof(cmd)); + if (*cmd != 0) { + RPC_call(cmd, reply); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/RpcServer/RpcServer.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _RPCSERVER_H_ +#define _RPCSERVER_H_ + +#include "mbed.h" +#include "RpcFifo.h" +#include "Device_Logging.h" + +/** +* @brief Reads the Version of the HSP FCache_Writel +*/ +int System_ReadVer(char argStrs[32][32], char replyStrs[32][32]); +/** +* @brief Reads the built time of the RPC FW +*/ +int System_ReadBuildTime(char argStrs[32][32], char replyStrs[32][32]); + +void RPC__init(void); +void RPC__call(char *request, char *reply); +fifo_t *GetUSBIncomingFifo(void); +fifo_t *GetStreamOutFifo(void); +/** +* @brief Batch process RPC commands +*/ +void RPC_ProcessCmds(char *cmds); +/** +* @brief Initialize the RPC server with all of the commands that it supports +*/ +void RPC_init(void); +/** +* @brief Initialize the RPC server with all of the commands that it supports +*/ +void RPC_call(char *request, char *reply); + +#endif // _RPCSERVER_H_
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/RpcServer/Streaming.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,187 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include "RpcServer.h" +#include "RpcFifo.h" +#include "Streaming.h" +#include "Peripherals.h" +#include "Test_MAX30101.h" +#include "Test_MAX30001.h" +#include "MAX30001.h" +#include "MAX30101.h" +#include "Peripherals.h" + +bool streaming = FALSE; +bool dataLogging = FALSE; + +/** +* @brief Encodes a 0x55 0xAA signature and a simple checksum to the id byte in +* the 32 bit field +* @param id Streaming ID +*/ +uint32_t StreamIdChecksumCalculate(uint32_t id) { + uint32_t sum; + uint32_t calculated; + sum = 0x55; + sum += 0xAA; + sum += id; + sum &= 0xFF; + sum = sum << 8; + calculated = 0x55AA0000 + sum + id; + return calculated; +} + +/** +* @brief Creates a packet that will be streamed via USB or saved into flash +* datalog memory +* @brief the packet created will be inserted into a fifo to be streamed at a +* later time +* @param id Streaming ID +* @param buffer Pointer to a uint32 array that contains the data to include in +* the packet +* @param number Number of elements in the buffer +*/ +void StreamPacketUint32(uint32_t id, uint32_t *buffer, uint32_t number) { + uint32_t checksumId; + if (streaming == TRUE || dataLogging == TRUE) { + checksumId = StreamIdChecksumCalculate(id); + StreamFifoId(checksumId); + StreamFifoTimeStamp(); + StreamFifoLength(number); + StreamFifoUint32Array(buffer, number); + } + if (testing_max30001 == 1) { + if (id == MAX30001_DATA_ECG) + testing_ecg_flags[TESTING_ECG_FLAG] = 1; + if (id == MAX30001_DATA_BIOZ) + testing_ecg_flags[TESTING_BIOZ_FLAG] = 1; + if (id == MAX30001_DATA_PACE) + testing_ecg_flags[TESTING_PACE_FLAG] = 1; + if (id == MAX30001_DATA_RTOR) + testing_ecg_flags[TESTING_RTOR_FLAG] = 1; + } + if (testing_max30101 == 1) { + if (id == (MAX30101_OXIMETER_DATA + 1)) + testing_max30101_flags[TESTING_HR_FLAG] = 1; + if (id == (MAX30101_OXIMETER_DATA + 2)) + testing_max30101_flags[TESTING_SPO2_FLAG] = 1; + if (id == (MAX30101_OXIMETER_DATA + 3)) + testing_max30101_flags[TESTING_MULTI_FLAG] = 1; + } +} + +/** +* @brief Insert a buffer into the out going fifo +* @param buffer Array of uint32 to send to the fifo +* @param len Length of the array +*/ +int StreamFifoUint32Array(uint32_t buffer[], uint32_t len) { + int status; + uint32_t i; + for (i = 0; i < len; i++) { + status = fifo_put32(GetStreamOutFifo(), buffer[i]); + if (status == -1) { + printf("FIFO_OF!"); + fflush(stdout); + while (1) + ; + } + } + return 0; +} + +/** +* @brief Insert a timestamp into the out going fifo +*/ +int StreamFifoTimeStamp(void) { + int status; + // uint32_t timer = timestamp_GetCurrent(); //RTC_GetVal(); + uint32_t timer = (uint32_t)Peripherals::timestampTimer()->read_us(); + status = fifo_put32(GetStreamOutFifo(), timer); + if (status == -1) { + printf("FIFO_OF!"); + fflush(stdout); + while (1) + ; + } + return 0; +} + +/** +* @brief Insert a packet id into the out going fifo +* @param id The uint32 packet id +*/ +int StreamFifoId(uint32_t id) { + int status; + status = fifo_put32(GetStreamOutFifo(), id); + if (status == -1) { + printf("FIFO_OF!"); + fflush(stdout); + while (1) + ; + } + return 0; +} + +/** +* @brief Insert a length value into the out going fifo +* @param length A uint32 number representing a length +*/ +int StreamFifoLength(uint32_t length) { + int status; + status = fifo_put32(GetStreamOutFifo(), length); + if (status == -1) { + printf("FIFO_OF!"); + fflush(stdout); + while (1) + ; + } + return 0; +} + +/** +* @brief Return a value that indicates if the system is streaming data +* @returns Returns a one or zero value +*/ +uint8_t IsStreaming(void) { return streaming; } + +/** +* @brief Set a flag to indicate if streaming is enabled +* @param state A one or zero value +*/ +void SetStreaming(uint8_t state) { streaming = state; } + +/** +* @brief Set a flag to indicate if datalogging is enabled +* @param state A one or zero value +*/ +void SetDataLoggingStream(uint8_t state) { dataLogging = state; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/RpcServer/Streaming.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _STREAMING_H_ +#define _STREAMING_H_ + +#include "mbed.h" + +#define PACKET_LIS2DH 0x20 + +#define PACKET_MAX30205_TEMP_TOP 0x40 +#define PACKET_MAX30205_TEMP_BOTTOM 0x50 +#define PACKET_BMP280_PRESSURE 0x60 +#define PACKET_LSM6DS3_ACCEL 0x70 +#define PACKET_MAX30205_TEMP 0x80 +#define PACKET_NOP 0x90 + +/** +* @brief Creates a packet that will be streamed via USB or saved into flash +* datalog memory +* @brief the packet created will be inserted into a fifo to be streamed at a +* later time +* @param id Streaming ID +* @param buffer Pointer to a uint32 array that contains the data to include in +* the packet +* @param number Number of elements in the buffer +*/ +void StreamPacketUint32(uint32_t id, uint32_t *buffer, uint32_t number); +/** +* @brief Insert a buffer into the out going fifo +* @param buffer Array of uint32 to send to the fifo +* @param len Length of the array +*/ +int StreamFifoUint32Array(uint32_t buffer[], uint32_t len); +/** +* @brief Insert a timestamp into the out going fifo +*/ +int StreamFifoTimeStamp(void); +/** +* @brief Insert a packet id into the out going fifo +* @param id The uint32 packet id +*/ +int StreamFifoId(uint32_t id); +/** +* @brief Return a value that indicates if the system is streaming data +* @returns Returns a one or zero value +*/ +uint8_t IsStreaming(void); +/** +* @brief Set a flag to indicate if streaming is enabled +* @param state A one or zero value +*/ +void SetStreaming(uint8_t state); +/** +* @brief Set a flag to indicate if datalogging is enabled +* @param state A one or zero value +*/ +void SetDataLoggingStream(uint8_t state); +/** +* @brief Insert a length value into the out going fifo +* @param length A uint32 number representing a length +*/ +int StreamFifoLength(uint32_t length); + +#endif // _STREAMING_H_
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/RpcServer/StringHelper.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,240 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include "mbed.h" +#include "StringHelper.h" + +/** +* @brief Process an array of hex alpha numeric strings representing arguments of +* type uint8 +* @param args Array of strings to process +* @param argsUintPtr Pointer of uint8 to save converted arguments +* @param numberOf Number of strings to convert +*/ +void ProcessArgs(char args[32][32], uint8_t *argsUintPtr, int numberOf) { + int i; + int val; + for (i = 0; i < numberOf; i++) { + sscanf(args[i], "%x", &val); + argsUintPtr[i] = (uint8_t)val; + } +} + +/** +* @brief Process an array of hex alpha numeric strings representing arguments of +* type uint32 +* @param args Array of strings to process +* @param argsUintPtr Pointer of uint32 to save converted arguments +* @param numberOf Number of strings to convert +*/ +void ProcessArgs32(char args[32][32], uint32_t *argsUintPtr, int numberOf) { + int i; + int val; + for (i = 0; i < numberOf; i++) { + sscanf(args[i], "%x", &val); + argsUintPtr[i] = val; + } +} + +/** +* @brief Process an array of decimal numeric strings representing arguments of +* type uint32 +* @param args Array of strings to process +* @param argsUintPtr Pointer of uint32 to save converted arguments +* @param numberOf Number of strings to convert +*/ +void ProcessArgs32Dec(char args[32][32], uint32_t *argsUintPtr, int numberOf) { + int i; + int val; + for (i = 0; i < numberOf; i++) { + sscanf(args[i], "%d", &val); + argsUintPtr[i] = val; + } +} + +/** +* @brief Parse a single string in decimal format to a uint32 number +* @param str String to process +* @returns Returns the converted number of type uint32 +*/ +uint32_t ParseAsciiDecU32(char *str) { + uint32_t val; + sscanf(str, "%d", &val); + return val; +} + +/** +* @brief Parse a single string in hex format to a uint32 number +* @param str String to process +* @returns Returns the converted number of type uint32 +*/ +uint32_t ParseAsciiHexU32(char *str) { + uint32_t val; + sscanf(str, "%x", &val); + return val; +} + +/** +* @brief Process a string that is "embedded" within another string using the /" +* delimiters +* @brief Extract the string +* @param str String to process +* @returns Returns the string +*/ +void ProcessString(char args[32][32], uint8_t *str, int numberOf) { + int i; + int start; + uint8_t *ptr; + uint8_t *strPtr; + ptr = (uint8_t *)args; + strPtr = str; + start = 0; + for (i = 0; i < numberOf; i++) { + if ((start == 0) && (*ptr == '/"')) { + start = 1; + ptr++; + continue; + } + if ((start == 1) && (*ptr == '/"')) { + break; + } + if (start == 1) { + *strPtr = *ptr; + strPtr++; + } + ptr++; + } + // terminate the string + *strPtr = 0; +} + +/** +* @brief Parse an incoming string until a CRLF is encountered, dst will contain +* the parsed string +* @param src source string to process +* @param dst destination string to contain the parsed incoming string +* @param length length of incoming src string +* @returns updated pointer in src string +*/ +char *ParseUntilCRLF(char *src, char *dst, int length) { + int i; + char *srcPtr; + + srcPtr = src; + i = 0; + *dst = 0; + while ((*srcPtr != 0) && (*srcPtr != 13)) { + dst[i] = *srcPtr; + i++; + if (i >= length) + break; + srcPtr++; + } + if (*srcPtr == 13) + srcPtr++; + if (*srcPtr == 10) + srcPtr++; + dst[i] = 0; // terminate the string + return srcPtr; +} + +/** +* @brief Parse an incoming string hex value into an 8-bit value +* @param str string to process +* @returns 8-bit byte that is parsed from the string +*/ +uint8_t StringToByte(char str[32]) { + int val; + uint8_t byt; + sscanf(str, "%x", &val); + byt = (uint8_t)val; + return byt; +} + +/** +* @brief Parse an incoming string hex value into 32-bit value +* @param str string to process +* @returns 32-bit value that is parsed from the string +*/ +uint32_t StringToInt(char str[32]) { + int val; + uint32_t byt; + sscanf(str, "%x", &val); + byt = (uint32_t)val; + return byt; +} + +/** +* @brief Format a binary 8-bit array into a string +* @param uint8Ptr byte buffer to process +* @param numberOf number of bytes in the buffer +* @param reply an array of strings to place the converted array values into +*/ +void FormatReply(uint8_t *uint8Ptr, int numberOf, char reply[32][32]) { + int i; + for (i = 0; i < numberOf; i++) { + sprintf(reply[i], "%02X", uint8Ptr[i]); + } + strcpy(reply[i], "\0"); +} + +/** +* @brief Format a binary 32-bit array into a string +* @param uint32Ptr 32-bit value buffer to process +* @param numberOf number of values in the buffer +* @param reply an array of strings to place the converted array values into +*/ +void FormatReply32(uint32_t *uint32Ptr, int numberOf, char reply[32][32]) { + int i; + for (i = 0; i < numberOf; i++) { + sprintf(reply[i], "%02X", uint32Ptr[i]); + } + strcpy(reply[i], "\0"); +} + +/** +* @brief Format a binary 8-bit array into a string +* @param data 8-bit value buffer to process +* @param length number of values in the buffer +* @param str output string buffer +* @return output string +*/ +char *BytesToHexStr(uint8_t *data, uint32_t length, char *str) { + uint32_t i; + char tmpStr[8]; + str[0] = 0; + for (i = 0; i < length; i++) { + sprintf(tmpStr, "%02X ", data[i]); + strcat(str, tmpStr); + } + return str; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/RpcServer/StringHelper.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,118 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _STRINGHELPER_H_ +#define _STRINGHELPER_H_ + +#include "mbed.h" + +/** +* @brief Process an array of hex alpha numeric strings representing arguments of +* type uint8 +* @param args Array of strings to process +* @param argsUintPtr Pointer of uint8 to save converted arguments +* @param numberOf Number of strings to convert +*/ +void ProcessArgs(char args[32][32], uint8_t *argsUintPtr, int numberOf); +/** +* @brief Format a binary 8-bit array into a string +* @param uint8Ptr byte buffer to process +* @param numberOf number of bytes in the buffer +* @param reply an array of strings to place the converted array values into +*/ +void FormatReply(uint8_t *uint8Ptr, int numberOf, char reply[32][32]); +/** +* @brief Process an array of hex alpha numeric strings representing arguments of +* type uint32 +* @param args Array of strings to process +* @param argsUintPtr Pointer of uint32 to save converted arguments +* @param numberOf Number of strings to convert +*/ +void ProcessArgs32(char args[32][32], uint32_t *argsUintPtr, int numberOf); +/** +* @brief Process an array of decimal numeric strings representing arguments of +* type uint32 +* @param args Array of strings to process +* @param argsUintPtr Pointer of uint32 to save converted arguments +* @param numberOf Number of strings to convert +*/ +void ProcessArgs32Dec(char args[32][32], uint32_t *argsUintPtr, int numberOf); +/** +* @brief Format a binary 32-bit array into a string +* @param uint32Ptr 32-bit value buffer to process +* @param numberOf number of values in the buffer +* @param reply an array of strings to place the converted array values into +*/ +void FormatReply32(uint32_t *uint32Ptr, int numberOf, char reply[32][32]); +/** +* @brief Parse an incoming string hex value into an 8-bit value +* @param str string to process +* @returns 8-bit byte that is parsed from the string +*/ +uint8_t StringToByte(char str[32]); +/** +* @brief Parse an incoming string hex value into 32-bit value +* @param str string to process +* @returns 32-bit value that is parsed from the string +*/ +uint32_t StringToInt(char str[32]); +/** +* @brief Parse a single string in decimal format to a uint32 number +* @param str String to process +* @returns Returns the converted number of type uint32 +*/ +uint32_t ParseAsciiDecU32(char *str); +/** +* @brief Parse a single string in hex format to a uint32 number +* @param str String to process +* @returns Returns the converted number of type uint32 +*/ +uint32_t ParseAsciiHexU32(char *str); +/** +* @brief Format a binary 8-bit array into a string +* @param data 8-bit value buffer to process +* @param length number of values in the buffer +* @param str output string buffer +* @return output string +*/ +char *BytesToHexStr(uint8_t *data, uint32_t length, char *str); +/** +* @brief Parse an incoming string until a CRLF is encountered, dst will contain +* the parsed string +* @param src source string to process +* @param dst destination string to contain the parsed incoming string +* @param length length of incoming src string +* @returns updated pointer in src string +*/ +char *ParseUntilCRLF(char *src, char *dst, int length); + +#endif // _STRINGHELPER_H_
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/RpcServer/StringInOut.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,195 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include "mbed.h" +#include "USBSerial.h" +#include "RpcFifo.h" +#include "RpcServer.h" +#include "StringInOut.h" +#include "Peripherals.h" + +/// a running index that keeps track of where an incoming string has been +/// buffered to +static int lineBuffer_index = 0; +/// a flag that keeps track of the state of accumulating a string +static int getLine_State = GETLINE_WAITING; + +/** +* @brief Place incoming USB characters into a fifo +* @param data_IN buffer of characters +* @param len length of data +*/ +int fifoIncomingChars(uint8_t data_IN[], unsigned int len) { + int i; + for (i = 0; i < len; i++) { + fifo_put8(GetUSBIncomingFifo(), data_IN[i]); + } + return 0; +} + +/** +* @brief Check the USB incoming fifo to see if there is data to be read +* @return 1 if there is data to be read, 0 if data is not available +*/ +int isReadReady(void) { + if (fifo_empty(GetUSBIncomingFifo()) == 0) + return 1; + return 0; +} + +/** +* @brief Clear the incoming USB read fifo +*/ +void clearOutReadFifo(void) { fifo_clear(GetUSBIncomingFifo()); } + +/** +* @brief Block until a character can be read from the USB +* @return the character read +*/ +char getch(void) { + uint8_t ch; + // block until char is ready + while (isReadReady() == 0) { + } + // read a char from buffer + fifo_get8(GetUSBIncomingFifo(), &ch); + return ch; +} + +/** +* @brief Place incoming USB characters into a fifo +* @param lineBuffer buffer to place the incoming characters +* @param bufferLength length of buffer +* @return GETLINE_WAITING if still waiting for a CRLF, GETLINE_DONE +*/ +int getLine(char *lineBuffer, int bufferLength) { + uint8_t ch; + + USBSerial *serial = Peripherals::usbSerial(); + if (getLine_State == GETLINE_DONE) { + getLine_State = GETLINE_WAITING; + } + if (serial->available() != 0) { + ch = serial->_getc(); + if (ch != 0x0A && ch != 0x0D) { + lineBuffer[lineBuffer_index++] = ch; + } + if (ch == 0x0D) { + lineBuffer[lineBuffer_index++] = 0; + lineBuffer_index = 0; + getLine_State = GETLINE_DONE; + } + if (lineBuffer_index > bufferLength) { + lineBuffer[bufferLength - 1] = 0; + getLine_State = GETLINE_DONE; + } + } + return getLine_State; +} + +/** +* @brief Block until a fixed number of characters has been accumulated from the +* incoming USB +* @param lineBuffer buffer to place the incoming characters +* @param maxLength length of buffer +*/ +void getStringFixedLength(uint8_t *lineBuffer, int maxLength) { + uint8_t ch; + int index = 0; + // block until maxLength is captured + while (1) { + ch = getch(); + lineBuffer[index++] = ch; + if (index == maxLength) + return; + } +} + +/** +* @brief Output a string out the USB serial port +* @param str output this str the USB channel +*/ +int putStr(const char *str) { + Peripherals::usbSerial()->printf("%s", str); // fflush(stdout); + // uint8_t *ptr; + // uint8_t buffer[256]; + // int index = 0; + /* int length; + ptr = (uint8_t *)str; + length = strlen(str); + + Peripherals::usbSerial()->writeBlock(ptr,length); */ + return 0; +} + +/** +* @brief Outut an array of bytes out the USB serial port +* @param data buffer to output +* @param length length of buffer +*/ +int putBytes(uint8_t *data, uint32_t length) { + int sendThis = 64; + int sent = 0; + int thisLeft; + uint8_t *ptr = data; + if (length < 64) + sendThis = length; + do { + Peripherals::usbSerial()->writeBlock(ptr, sendThis); + sent += sendThis; + ptr += sendThis; + thisLeft = length - sent; + sendThis = 64; + if (thisLeft < 64) + sendThis = thisLeft; + } while (sent != length); + return 0; +} + +/** +* @brief Outut 256 byte blocks out the USB serial using writeBlock bulk +* transfers +* @param data buffer of blocks to output +* @param length length of 256-byte blocks +*/ +int putBytes256Block(uint8_t *data, int numberBlocks) { + int i; + uint8_t *ptr; + ptr = data; + const int BLOCK_SIZE = 32; + const int FLASH_PAGE_SIZE = 256; + for (i = 0; i < numberBlocks * (FLASH_PAGE_SIZE / BLOCK_SIZE); i++) { + Peripherals::usbSerial()->writeBlock(ptr, BLOCK_SIZE); + ptr += BLOCK_SIZE; + } + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/RpcServer/StringInOut.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _STRINGINOUT_H_ +#define _STRINGINOUT_H_ + +#include "mbed.h" +#include "USBSerial.h" + +/// indicates that a string up to a CRLF is being accumulated +#define GETLINE_WAITING 1 +/// indicates that a string is being processes +#define GETLINE_PROCESSING 2 +/// indicates that a CRLF string has been buffered and can be processed +#define GETLINE_DONE 3 + +/** +* @brief Clear the incoming USB read fifo +*/ +void clearOutReadFifo(void); +/** +* @brief Block until a character can be read from the USB +* @return the character read +*/ +char getch(void); +/** +* @brief Place incoming USB characters into a fifo +* @param lineBuffer buffer to place the incoming characters +* @param bufferLength length of buffer +* @return GETLINE_WAITING if still waiting for a CRLF, GETLINE_DONE +*/ +int getLine(char *lineBuffer, int bufferLength); +/** +* @brief Block until a fixed number of characters has been accumulated from the +* incoming USB +* @param lineBuffer buffer to place the incoming characters +* @param maxLength length of buffer +*/ +void getStringFixedLength(uint8_t *lineBuffer, int maxLength); +/** +* @brief Output a string out the USB serial port +* @param str output this str the USB channel +*/ +int putStr(const char *str); +/** +* @brief Place incoming USB characters into a fifo +* @param data_IN buffer of characters +* @param len length of data +*/ +int fifoIncomingChars(uint8_t data_IN[], unsigned int len); +/** +* @brief Outut an array of bytes out the USB serial port +* @param data buffer to output +* @param length length of buffer +*/ +int putBytes(uint8_t *data, uint32_t length); +/** +* @brief Outut 256 byte blocks out the USB serial using writeBlock bulk +* transfers +* @param data buffer of blocks to output +* @param length length of 256-byte blocks +*/ +int putBytes256Block(uint8_t *data, int numberBlocks); + +#endif // _STRINGINOUT_H_
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/System/Peripherals.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include "Peripherals.h" + +I2C *Peripherals::mI2c1 = NULL; +I2C *Peripherals::mI2c2 = NULL; +USBSerial *Peripherals::mUSBSerial = NULL; +MAX30101 *Peripherals::mMAX30101 = NULL; +MAX30001 *Peripherals::mMAX30001 = NULL; +BMP280 *Peripherals::mBMP280 = NULL; +HspLed *Peripherals::mHspLed = NULL; +MAX30205 *Peripherals::mMAX30205_top = NULL; +MAX30205 *Peripherals::mMAX30205_bottom = NULL; +LIS2DH *Peripherals::mLIS2DH = NULL; +Timer *Peripherals::mTimestampTimer = NULL; +S25FS512 *Peripherals::mS25FS512 = NULL; +PushButton *Peripherals::mPushButton = NULL; +BLE *Peripherals::mBLE = NULL; +MAX14720 *Peripherals::mMAX14720 = NULL; +HspBLE *Peripherals::mhspBLE = NULL;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/System/Peripherals.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,126 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _PERIPHERALS_H_ +#define _PERIPHERALS_H_ + +#include "mbed.h" +#include "USBSerial.h" +#include "MAX30101.h" +#include "HspLed.h" +#include "MAX30205.h" +#include "LIS2DH.h" +#include "MAX30001.h" +#include "BMP280.h" +#include "S25FS512.h" +#include "PushButton.h" +#include "BLE.h" +#include "MAX14720.h" +#include "HspBLE.h" + +/** +* This static class is used as a central locatoin for all devices on the HSP platform +* it gives (in-effect) a singleton interface for each device so that anywhere in code +* one can reference on of these devices +*/ +class Peripherals { +public: + static USBSerial *setUSBSerial(USBSerial * device) { mUSBSerial = device; return device; } + static USBSerial *usbSerial(void) { return mUSBSerial; } + + static MAX30101 *max30101(void) { return mMAX30101; } + static MAX30101 *setMAX30101(MAX30101 *device) { mMAX30101 = device; return device; } + + static MAX30205 *max30205_top(void) { return mMAX30205_top; } + static MAX30205 *setMAX30205_top(MAX30205 *device) { mMAX30205_top = device; return device; } + + static MAX30205 *max30205_bottom(void) { return mMAX30205_bottom; } + static MAX30205 *setMAX30205_bottom(MAX30205 *device) { mMAX30205_bottom = device; return device; } + + static HspLed *hspLed(void) { return mHspLed; } + static HspLed *setHspLed(HspLed *device) { mHspLed = device; return device; } + + static LIS2DH *lis2dh(void) { return mLIS2DH; } + static LIS2DH *setLIS2DH(LIS2DH *device) { mLIS2DH = device; return device; } + + static MAX30001 *max30001(void) { return mMAX30001; } + static MAX30001 *setMAX30001(MAX30001 *device) { mMAX30001 = device; return device; } + + static BMP280 *bmp280(void) { return mBMP280; } + static BMP280 *setBMP280(BMP280 *device) { mBMP280 = device; return device; } + + static Timer *timestampTimer(void) { return mTimestampTimer; } + static Timer *setTimestampTimer(Timer *timer) { mTimestampTimer = timer; return timer; } + + static I2C *i2c1(void) { return mI2c1; } + static I2C *setI2c1(I2C *i2cPort) { mI2c1 = i2cPort; return i2cPort; } + + static I2C *i2c2(void) { return mI2c2; } + static I2C *setI2c2(I2C *i2cPort) { mI2c2 = i2cPort; return i2cPort; } + + static S25FS512 *s25FS512(void) { return mS25FS512; } + static S25FS512 *setS25FS512(S25FS512 *s25FS512) { mS25FS512 = s25FS512; return s25FS512; } + + static PushButton *pushButton(void) { return mPushButton; } + static PushButton *setPushButton(PushButton *pushButton) { mPushButton = pushButton; return pushButton; } + + static BLE *ble(void) { return mBLE; } + static BLE *setBLE(BLE *_ble) { mBLE = _ble; return _ble; } + + static HspBLE *hspBLE(void) { return mhspBLE; } + static HspBLE *setHspBLE(HspBLE *_hspBLE) { mhspBLE = _hspBLE; return _hspBLE; } + + static MAX14720 *max14720(void) { return mMAX14720; } + static MAX14720 *setMAX14720(MAX14720 *_MAX14720) { mMAX14720 = _MAX14720; return _MAX14720; } + +private: + static I2C *mI2c1; + static I2C *mI2c2; + static USBSerial *mUSBSerial; + static MAX30101 *mMAX30101; + static MAX30001 *mMAX30001; + static BMP280 *mBMP280; + static HspLed *mHspLed; + static Serial *mSerial; + static MAX30205 *mMAX30205_top; + static MAX30205 *mMAX30205_bottom; + static LIS2DH *mLIS2DH; + static Timer *mTimestampTimer; + static S25FS512 *mS25FS512; + static PushButton *mPushButton; + static BLE *mBLE; + static MAX14720 *mMAX14720; + static HspBLE *mhspBLE; +}; + +#endif // _PERIPHERALS_H_ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/System/System.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include "mbed.h" + +//****************************************************************************** +void I2CM_Init_Reset(uint8_t index, int speed) { + mxc_i2cm_regs_t *regs = MXC_I2CM_GET_I2CM(index); + /* reset module */ + regs->ctrl = MXC_F_I2CM_CTRL_MSTR_RESET_EN; + regs->ctrl = 0; + /* enable tx_fifo and rx_fifo */ + regs->ctrl |= (MXC_F_I2CM_CTRL_TX_FIFO_EN | MXC_F_I2CM_CTRL_RX_FIFO_EN); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/System/System.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _SYSTEM_H_ +#define _SYSTEM_H_ + +/** +* This issues a reset to the I2C Peripheral +*/ +void I2CM_Init_Reset(uint8_t index, int speed); + +#endif // _SYSTEM_H_
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Test/Test_BMP280.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include "Test_BMP280.h" +#include "Test_Utilities.h" + +//****************************************************************************** +void test_BMP280(void (*outputString)(const char *)) { + char tempStr[32]; + int pass; + uint8_t readId; + BMP280 *bmp280; + bmp280 = Peripherals::bmp280(); + + // display header + outputString("Testing BMP280|"); + + // read id test + outputString("Read ID: "); + readId = bmp280->ReadId(); + if (readId == BMP280_READID) + pass = 1; + else + pass = 0; + sprintf(tempStr, " (%02X)|", readId); + outputString(tempStr); + _printPassFail(pass, 0, outputString); + + // final results + outputString("Result: "); + _printPassFail(pass, 0, outputString); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Test/Test_BMP280.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _TEST_BMP280_H_ +#define _TEST_BMP280_H_ + +#include "mbed.h" +#include "BMP280.h" +#include "Peripherals.h" + +/** +* @brief Selftest the BMP280 and output the results as strings using the pointer function +* @param outputString Pointer to the function used to output the test results +*/ +void test_BMP280(void (*outputString)(const char *)); + +#endif / _TEST_BMP280_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Test/Test_LIS2DH.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include "Test_LIS2DH.h" +#include "Test_Utilities.h" + +//****************************************************************************** +void test_LIS2DH(void (*outputString)(const char *)) { + char tempStr[32]; + int totalPass = 1; + int pass; + uint8_t readId; + LIS2DH *lis2dh; + lis2dh = Peripherals::lis2dh(); + + // display header + outputString("Testing LIS2DH|"); + + // read id test @ 400kHz + outputString("Read ID @ 400kHz: "); + readId = lis2dh->readId(); + if (readId == LIS2DH_READID) + pass = 1; + else + pass = 0; + _printPassFail(pass, 0, outputString); + totalPass &= pass; + sprintf(tempStr, " (%02X)|", readId); + outputString(tempStr); + // end test at 100kHz + + // final results + outputString("Result: "); + _printPassFail(totalPass, 0, outputString); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Test/Test_LIS2DH.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _TEST_LIS2DH_H_ +#define _TEST_LIS2DH_H_ + +#include "mbed.h" +#include "LIS2DH.h" +#include "Peripherals.h" + +/** +* @brief Selftest the LIS2DH and output the results as strings using the pointer function +* @param outputString Pointer to the function used to output the test results +*/ +void test_LIS2DH(void (*outputString)(const char *)); + +#endif /* _TEST_LIS2DH_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Test/Test_MAX30001.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,169 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include "Test_MAX30001.h" +#include "Test_Utilities.h" + +uint32_t testing_max30001 = 0; +uint32_t testing_ecg_flags[4]; + +//****************************************************************************** +void test_MAX30001(void (*outputString)(const char *)) { + int totalPass = 1; + int pass; + uint32_t foundEcg = 0; + uint32_t foundBioz = 0; + uint32_t foundPace = 0; + uint32_t foundRtoR = 0; + uint32_t id; + char str2[128]; + int partVersion; // 0 = 30004 + // 1 = 30001 + // 2 = 30002 + // 3 = 30003 + Timer timer; + MAX30001 *max30001; + max30001 = Peripherals::max30001(); + + // read the id + max30001->max30001_reg_read(MAX30001::INFO, &id); + // read id twice because it needs to be read twice + max30001->max30001_reg_read(MAX30001::INFO, &id); + partVersion = id >> 12; + partVersion = partVersion & 0x3; + + // display header + if (partVersion == 0) + outputString("Testing MAX30004|"); + if (partVersion == 1) { + outputString("Testing MAX30001|"); + outputString("Testing ECG, RtoR, BioZ, PACE|"); + } + if (partVersion == 2) + outputString("Testing MAX30002|"); + if (partVersion == 3) { + outputString("Testing MAX30003|"); + outputString("Only Testing ECG and RtoR|"); + } + sprintf(str2, "Device ID = 0x%06X|", id); + outputString(str2); + + // clear testing flags + testing_ecg_flags[TESTING_ECG_FLAG] = 0; + testing_ecg_flags[TESTING_BIOZ_FLAG] = 0; + testing_ecg_flags[TESTING_PACE_FLAG] = 0; + testing_ecg_flags[TESTING_RTOR_FLAG] = 0; + + // start streams + testing_max30001 = 1; + if (partVersion == 1) + outputString("Start Streaming ECG, RtoR, PACE, BIOZ, CAL enabled, " + "verifying streams...|"); + if (partVersion == 3) + outputString( + "Start Streaming ECG, RtoR, CAL enabled, verifying streams...|"); + // max30001_CAL_InitStart(0b1, 0b1, 0b1, 0b011, 0x7FF, 0b0); + max30001->max30001_CAL_InitStart(0b1, 0b1, 0b1, 0b011, 0x7FF, 0b0); + max30001->max30001_ECG_InitStart(0b1, 0b1, 0b1, 0b0, 0b10, 0b11, 0x1F, 0b00, + 0b00, 0b0, 0b01); + if (partVersion == 1) + max30001->max30001_PACE_InitStart(0b1, 0b0, 0b0, 0b1, 0x0, 0b0, 0b00, 0b0, + 0b0); + if (partVersion == 1) + max30001->max30001_BIOZ_InitStart(0b1, 0b1, 0b1, 0b10, 0b11, 0b00, 7, 0b0, + 0b010, 0b0, 0b10, 0b00, 0b00, 2, 0b0, + 0b111, 0b0000); + max30001->max30001_RtoR_InitStart(0b1, 0b0011, 0b1111, 0b00, 0b0011, 0b000001, + 0b00, 0b000, 0b01); + max30001->max30001_Rbias_FMSTR_Init(0b01, 0b10, 0b1, 0b1, 0b00); + max30001->max30001_synch(); + + // look for each stream + timer.start(); + while (1) { + if ((foundEcg == 0) && (testing_ecg_flags[TESTING_ECG_FLAG] == 1)) { + foundEcg = 1; + outputString("ECG Stream: PASS|"); + } + if ((foundBioz == 0) && (testing_ecg_flags[TESTING_BIOZ_FLAG] == 1)) { + foundBioz = 1; + outputString("Bioz Stream: PASS|"); + } + if ((foundPace == 0) && (testing_ecg_flags[TESTING_PACE_FLAG] == 1)) { + foundPace = 1; + outputString("PACE Stream: PASS|"); + } + if ((foundRtoR == 0) && (testing_ecg_flags[TESTING_RTOR_FLAG] == 1)) { + foundRtoR = 1; + outputString("RtoR Stream: PASS|"); + } + if ((foundEcg == 1) && (foundBioz == 1) && (foundPace == 1) && + (foundRtoR == 1) && (partVersion == 1)) { + break; + } + if ((foundEcg == 1) && (foundRtoR == 1) && (partVersion == 3)) { + break; + } + if (timer.read() >= TESTING_MAX30001_TIMEOUT_SECONDS) { + break; + } + } + timer.stop(); + if (foundEcg == 0) { + outputString("ECG Stream: FAIL|"); + totalPass &= pass; + } + if ((foundBioz == 0) && (partVersion == 1)) { + outputString("Bioz Stream: FAIL|"); + totalPass &= pass; + } + if ((foundPace == 0) && (partVersion == 1)) { + outputString("PACE Stream: FAIL|"); + totalPass &= pass; + } + if (foundRtoR == 0) { + outputString("RtoR Stream: FAIL|"); + totalPass &= pass; + } + + // stop all streams + max30001->max30001_Stop_ECG(); + if (partVersion == 1) + max30001->max30001_Stop_PACE(); + if (partVersion == 1) + max30001->max30001_Stop_BIOZ(); + max30001->max30001_Stop_RtoR(); + testing_max30001 = 0; + // final results + outputString("Result: "); + _printPassFail(totalPass, 0, outputString); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Test/Test_MAX30001.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _TEST_MAX30001_H_ +#define _TEST_MAX30001_H_ + +#include "mbed.h" +#include "MAX30001.h" +#include "Peripherals.h" + +#define TESTING_ECG_FLAG 0 +#define TESTING_BIOZ_FLAG 1 +#define TESTING_PACE_FLAG 2 +#define TESTING_RTOR_FLAG 3 + +#define TESTING_MAX30001_TIMEOUT_SECONDS 10 + +extern uint32_t testing_max30001; +extern uint32_t testing_ecg_flags[4]; + +/** +* @brief Selftest the MAX30001 and output the results as strings using the pointer function +* @param outputString Pointer to the function used to output the test results +*/ +void test_MAX30001(void (*outputString)(const char *)); + +#endif /* _TEST_MAX30101_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Test/Test_MAX30101.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,143 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include "Test_MAX30101.h" +#include "Test_Utilities.h" + +uint32_t testing_max30101 = 0; +uint32_t testing_max30101_flags[4]; + +//****************************************************************************** +void test_MAX30101(void (*outputString)(const char *)) { + Timer timer; + int totalPass = 1; + int pass; + uint32_t foundHR = 0; + uint32_t foundSPO2 = 0; + uint32_t foundMULTI = 0; + MAX30101 *max30101; + + max30101 = Peripherals::max30101(); + + // display header + outputString("Testing MAX30101|"); + + // clear testing flags + testing_max30101_flags[TESTING_HR_FLAG] = 0; + testing_max30101_flags[TESTING_SPO2_FLAG] = 0; + testing_max30101_flags[TESTING_MULTI_FLAG] = 0; + testing_max30101 = 1; + + // + // start stream (HR) + // + outputString("Start HR Streaming...|"); + max30101->HRmode_init(0x0, 0x00, 0x01, 0x03, + 0x33); // This is the HR mode only (IR LED only) + // look for (HR) streaming + timer.start(); + while (1) { + if ((foundHR == 0) && (testing_max30101_flags[TESTING_HR_FLAG] == 1)) { + foundHR = 1; + outputString("HR Stream: PASS|"); + break; + } + if (timer.read() >= TESTING_MAX30101_TIMEOUT_SECONDS) { + break; + } + } + if (foundHR == 0) { + outputString("HR Stream: FAIL|"); + totalPass &= pass; + } + // stop stream + max30101->HRmode_stop(); + + // + // start stream (SPO2) + // + outputString("Start SPO2 Streaming...|"); + max30101->SpO2mode_init( + 0xF, 0x00, 0x01, 0x03, 0x33, + 0x33); // This is the SpO2 mode only (Red and IR LED only) + // look for (SPO2) stream + timer.reset(); + while (1) { + if ((foundSPO2 == 0) && (testing_max30101_flags[TESTING_SPO2_FLAG] == 1)) { + foundSPO2 = 1; + outputString("SPO2 Stream: PASS|"); + break; + } + if (timer.read() >= TESTING_MAX30101_TIMEOUT_SECONDS) { + break; + } + } + if (foundSPO2 == 0) { + outputString("SPO2 Stream: FAIL|"); + totalPass &= pass; + } + // stop stream + max30101->SpO2mode_stop(); + + // + // start stream (MULTI) + // + outputString("Start Multi Streaming...|"); + max30101->Multimode_init(0x00, 0x00, 0x01, 0x03, 0x33, 0x33, 0x33, 0x01, 0x02, + 0x03, 0x00); // Up to 4 LED can be turned on over + // look for (SPO2) stream + timer.reset(); + while (1) { + if ((foundMULTI == 0) && + (testing_max30101_flags[TESTING_MULTI_FLAG] == 1)) { + foundMULTI = 1; + outputString("Multi Stream: PASS|"); + break; + } + if (timer.read() >= TESTING_MAX30101_TIMEOUT_SECONDS) { + break; + } + } + if (foundMULTI == 0) { + outputString("Multi Stream: FAIL|"); + totalPass &= pass; + } + // stop stream + max30101->Multimode_stop(); + + testing_max30101 = 0; + + timer.stop(); + // final results + outputString("Result: "); + _printPassFail(totalPass, 0, outputString); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Test/Test_MAX30101.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _TEST_MAX30101_H_ +#define _TEST_MAX30101_H_ + +#include "mbed.h" +#include "MAX30101.h" +#include "Peripherals.h" + +#define TESTING_HR_FLAG 0 +#define TESTING_SPO2_FLAG 1 +#define TESTING_MULTI_FLAG 2 + +#define TESTING_MAX30101_TIMEOUT_SECONDS 2 + +extern uint32_t testing_max30101; +extern uint32_t testing_max30101_flags[4]; + +/** +* @brief Selftest the MAX30101 and output the results as strings using the pointer function +* @param outputString Pointer to the function used to output the test results +*/ +void test_MAX30101(void (*outputString)(const char *)); + +#endif /* _TEST_MAX30101_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Test/Test_MAX30205.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include "Test_MAX30205.h" +#include "Test_Utilities.h" +#include "MAX30205.h" +#include "Peripherals.h" + +//****************************************************************************** +void test_MAX30205(MAX30205 *MAX30205, void (*outputString)(const char *)) { + uint16_t value; + char tempStr[32]; + int pass; + + outputString("Write Reg_THYST to 0x1234 @ 400kHz: "); + // i2cSetSpeed(MAX30205_I2CM_INSTANCE, I2CM_SPEED_100kHz); + MAX30205->reg_THYST_Write(0x1234); + outputString("Read Reg_THYST @ 400kHz: "); + // i2cSetSpeed(MAX30205_I2CM_INSTANCE, I2CM_SPEED_100kHz); + MAX30205->reg_THYST_Read(&value); + if (value == 0x1234) + pass = 1; + else + pass = 0; + //*totalPass &= *pass; + sprintf(tempStr, " (%04X)|", value); + outputString(tempStr); + _printPassFail(pass, 0, outputString); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Test/Test_MAX30205.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _TEST_MAX30205_H_ +#define _TEST_MAX30205_H_ + +#include "mbed.h" +#include "MAX30205.h" + +/** +* @brief Selftest the MAX30101 and output the results as strings using the pointer function +* @param outputString Pointer to the function used to output the test results +*/ +void test_MAX30205(MAX30205 *MAX30205, void (*outputString)(const char *)); + +#endif /* _TEST_MAX30205_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Test/Test_S25FS512.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include "Test_S25FS512.h" +#include "Test_Utilities.h" + +//****************************************************************************** +void test_S25FS512(void (*outputString)(const char *)) { + char tempStr[32]; + uint8_t page[264]; + int totalPass = 1; + int pass; + int status; + int i; + uint8_t data[128]; + S25FS512 *s25FS512; + + s25FS512 = Peripherals::s25FS512(); + + // display header + outputString("Testing S25FS512|"); + + // read id test + s25FS512->readIdentification(data, sizeof(data)); + s25FS512->readIdentification(data, sizeof(data)); + if ((data[1] == 0x01) && (data[2] == 0x02) && (data[3] == 0x19) && + (data[4] == 0x4D)) { + sprintf(tempStr, "Read ID: Pass "); + outputString(tempStr); + } else { + sprintf(tempStr, "Read ID: Fail "); + outputString(tempStr); + totalPass = 0; + } + sprintf(tempStr, "(%02X%02X%02X%02X)|", data[1], data[2], data[3], data[4]); + outputString(tempStr); + + if (totalPass == 1) { + // format sector 0 + outputString("Formatting Sector 0, "); + s25FS512->sectorErase_Helper(0); + + // verify format sector 0 + outputString("Verifying Format of Sector 0: "); + s25FS512->readPages_Helper(0, 0, page, 0); + pass = s25FS512->isPageEmpty(page); + _printPassFail(pass, 1, outputString); + totalPass &= pass; + + // fill page with pattern + for (i = 0; i < 256; i++) { + page[i] = i; + } + // write to page 0 + outputString("Writing Page 0 to pattern, "); + s25FS512->writePage_Helper(0, page, 0); + // clear pattern in memory + for (i = 0; i < 256; i++) { + page[i] = 0x00; + } + // read back page and verify + outputString("Read Page Verify: "); + s25FS512->readPages_Helper(0, 0, page, 0); + // compare memory for pattern + pass = 1; + for (i = 0; i < 256; i++) { + if (page[i] != i) + pass = 0; + } + _printPassFail(pass, 1, outputString); + totalPass &= pass; + + // format sector 0 to clean up after tests + s25FS512->sectorErase_Helper(0); + } else { + outputString("Read Id Failed, Skipping rest of test|"); + } + + // final results + outputString("Result: "); + _printPassFail(totalPass, 0, outputString); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Test/Test_S25FS512.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _TEST_S25FS512_H_ +#define _TEST_S25FS512_H_ + +#include "mbed.h" +#include "S25FS512.h" +#include "Peripherals.h" + +/** +* @brief Selftest the S25FS512 and output the results as strings using the pointer function +* @param outputString Pointer to the function used to output the test results +*/ +void test_S25FS512(void (*outputString)(const char *)); + +#endif /* _TEST_S25FS512_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Test/Test_Utilities.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include "Test_Utilities.h" + +//****************************************************************************** +void _printPassFail(int status, int newLine, void (*outputString)(char const *)) { + if (status == 1) { + outputString("PASS"); + } else { + outputString("FAIL"); + } + if (newLine == 1) { + outputString("|"); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Test/Test_Utilities.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _TEST_UTILITIES_H_ +#define _TEST_UTILITIES_H_ + +#include "mbed.h" + +/** +* Function that will output a pass/fail formated string based on the incoming status value +* @param status Value that indicated pass or fail status +* @param newLine Should this call output a new line +* @param outputString Pointer to a function that will do the actual outputting of the string +*/ +void _printPassFail(int status, int newLine, void (*outputString)(const char *)); + +#endif /* _TEST_UTILITIES_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Test/Testing_RPC.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,130 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include <stdint.h> +#include "StringHelper.h" +#include "MAX30205.h" +#include "Test_BMP280.h" +#include "Test_LIS2DH.h" +#include "Test_MAX30001.h" +#include "Test_MAX30101.h" +#include "Test_MAX30205.h" +#include "Test_S25FS512.h" +#include "StringInOut.h" + +void outputTestResultString(const char *resultStr); + +//****************************************************************************** +int Test_S25FS512(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + test_S25FS512(outputTestResultString); + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +//****************************************************************************** +int Test_BMP280(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + test_BMP280(outputTestResultString); + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +//****************************************************************************** +int Test_LIS2DH(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + test_LIS2DH(outputTestResultString); + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +//****************************************************************************** +int Test_LSM6DS3(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +//****************************************************************************** +int Test_MAX30205_1(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + MAX30205 *max30205; + max30205 = Peripherals::max30205_top(); + test_MAX30205(max30205, outputTestResultString); + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +//****************************************************************************** +int Test_MAX30205_2(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + MAX30205 *max30205; + max30205 = Peripherals::max30205_bottom(); + test_MAX30205(max30205, outputTestResultString); + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +//****************************************************************************** +int Test_MAX30101(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + test_MAX30101(outputTestResultString); + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +//****************************************************************************** +int Test_MAX30001(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + test_MAX30001(outputTestResultString); + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +//****************************************************************************** +int Test_EM9301(char argStrs[32][32], char replyStrs[32][32]) { + uint32_t reply[1]; + reply[0] = 0x80; + FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); + return 0; +} + +//****************************************************************************** +void outputTestResultString(const char *resultStr) { putStr(resultStr); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/Test/Testing_RPC.h Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#ifndef _TESTING_RPC_H_ +#define _TESTING_RPC_H_ + +/** +* RPC executed routine that will perform platform self testing for the S25FS512 +*/ +int Test_S25FS512(char argStrs[32][32], char replyStrs[32][32]); +/** +* RPC executed routine that will perform platform self testing for the BMP280 +*/ +int Test_BMP280(char argStrs[32][32], char replyStrs[32][32]); +/** +* RPC executed routine that will perform platform self testing for the LIS2DH +*/ +int Test_LIS2DH(char argStrs[32][32], char replyStrs[32][32]); +/** +* RPC executed routine that will perform platform self testing for the LSM6DS3 +*/ +int Test_LSM6DS3(char argStrs[32][32], char replyStrs[32][32]); +/** +* RPC executed routine that will perform platform self testing for the MAX30205 +*/ +int Test_MAX30205_1(char argStrs[32][32], char replyStrs[32][32]); +/** +* RPC executed routine that will perform platform self testing for the MAX30205 +*/ +int Test_MAX30205_2(char argStrs[32][32], char replyStrs[32][32]); +/** +* RPC executed routine that will perform platform self testing for the MAX30101 +*/ +int Test_MAX30101(char argStrs[32][32], char replyStrs[32][32]); +/** +* RPC executed routine that will perform platform self testing for the MAX30001 +*/ +int Test_MAX30001(char argStrs[32][32], char replyStrs[32][32]); +/** +* RPC executed routine that will perform platform self testing for the EM9301 +*/ +int Test_EM9301(char argStrs[32][32], char replyStrs[32][32]); + +#endif /* _TESTING_RPC_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HSP/main.cpp Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,266 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ +#include "mbed.h" +#include "MAX14720.h" +#include "MAX30101.h" +#include "MAX30205.h" +#include "LIS2DH.h" +#include "USBSerial.h" +#include "RpcServer.h" +#include "StringInOut.h" +#include "Peripherals.h" +#include "BMP280.h" +#include "MAX30001.h" +#include "DataLoggingService.h" +#include "MAX30101_helper.h" +#include "S25FS512.h" +#include "QuadSpiInterface.h" +#include "PushButton.h" +#include "BLE.h" +#include "HspBLE.h" +#include "USBSerial.h" +#include "Streaming.h" + +/// define the HVOUT Boost Voltage default for the MAX14720 PMIC +#define HVOUT_VOLTAGE 4500 // set to 4500 mV + +/// define all I2C addresses +#define MAX30205_I2C_SLAVE_ADDR_TOP (0x92) +#define MAX30205_I2C_SLAVE_ADDR_BOTTOM (0x90) +#define MAX14720_I2C_SLAVE_ADDR (0x54) +#define BMP280_I2C_SLAVE_ADDR (0xEC) +#define MAX30101_I2C_SLAVE_ADDR (0xAE) +#define LIS2DH_I2C_SLAVE_ADDR (0x32) + +/// +/// wire Interfaces +/// +/// Define with Maxim VID and a Maxim assigned PID, set to version 0x0001 and non-blocking +USBSerial usbSerial(0x0b6a, 0x0100, 0x0001, false); +/// I2C Master 1 +I2C i2c1(I2C1_SDA, I2C1_SCL); // used by MAX30205 (1), MAX30205 (2), BMP280 +/// I2C Master 2 +I2C i2c2(I2C2_SDA, I2C2_SCL); // used by MAX14720, MAX30101, LIS2DH +/// SPI Master 0 with SPI0_SS for use with MAX30001 +SPI spi(SPI0_MOSI, SPI0_MISO, SPI0_SCK, SPI0_SS); // used by MAX30001 +/// SPI Master 1 +QuadSpiInterface quadSpiInterface(SPI1_MOSI, SPI1_MISO, SPI1_SCK, + SPI1_SS); // used by S25FS512 + +/// +/// Devices +/// +/// Pressure Sensor +BMP280 bmp280(&i2c1, BMP280_I2C_SLAVE_ADDR); +/// Top Local Temperature Sensor +MAX30205 MAX30205_top(&i2c1, MAX30205_I2C_SLAVE_ADDR_TOP); +/// Bottom Local Temperature Sensor +MAX30205 MAX30205_bottom(&i2c1, MAX30205_I2C_SLAVE_ADDR_BOTTOM); +/// Accelerometer +LIS2DH lis2dh(&i2c2, LIS2DH_I2C_SLAVE_ADDR); +InterruptIn lis2dh_Interrupt(P4_7); +/// PMIC +MAX14720 max14720(&i2c2, MAX14720_I2C_SLAVE_ADDR); +/// Optical Oximeter +MAX30101 max30101(&i2c2, MAX30101_I2C_SLAVE_ADDR); +InterruptIn max30101_Interrupt(P4_0); +/// External Flash +S25FS512 s25fs512(&quadSpiInterface); +/// ECG device +MAX30001 max30001(&spi); +InterruptIn max30001_InterruptB(P3_6); +InterruptIn max30001_Interrupt2B(P4_5); +/// PWM used as fclk for the MAX30001 +PwmOut pwmout(P1_7); +/// HSP platform LED +HspLed hspLed(LED_RED); +/// Packet TimeStamp Timer, set for 1uS +Timer timestampTimer; +/// HSP Platform push button +PushButton pushButton(SW1); + +/// BLE instance +static BLE ble; + +/// HSP BluetoothLE specific functions +HspBLE hspBLE(&ble); + +int main() { + // hold results for returning funtcoins + int result; + // local input state of the RPC + int inputState; + // RPC request buffer + char request[128]; + // RPC reply buffer + char reply[128]; + + // display start banner + printf("Maxim Integrated mbed hSensor 3.0.0 10/14/16\n"); + fflush(stdout); + + // initialize HVOUT on the MAX14720 PMIC + printf("Init MAX14720...\n"); + fflush(stdout); + result = max14720.init(); + if (result == MAX14720_ERROR) + printf("Error initializing MAX14720"); + max14720.boostEn = MAX14720::BOOST_ENABLED; + max14720.boostSetVoltage(HVOUT_VOLTAGE); + + // turn on red led + printf("Init HSPLED...\n"); + fflush(stdout); + hspLed.on(); + + // set NVIC priorities for GPIO to prevent priority inversion + printf("Init NVIC Priorities...\n"); + fflush(stdout); + NVIC_SetPriority(GPIO_P0_IRQn, 5); + NVIC_SetPriority(GPIO_P1_IRQn, 5); + NVIC_SetPriority(GPIO_P2_IRQn, 5); + NVIC_SetPriority(GPIO_P3_IRQn, 5); + NVIC_SetPriority(GPIO_P4_IRQn, 5); + NVIC_SetPriority(GPIO_P5_IRQn, 5); + NVIC_SetPriority(GPIO_P6_IRQn, 5); + // used by the MAX30001 + NVIC_SetPriority(SPI1_IRQn, 0); + + // Be able to statically reference these devices anywhere in the application + Peripherals::setS25FS512(&s25fs512); + Peripherals::setMAX30205_top(&MAX30205_top); + Peripherals::setMAX30205_bottom(&MAX30205_bottom); + Peripherals::setBMP280(&bmp280); + Peripherals::setLIS2DH(&lis2dh); + Peripherals::setUSBSerial(&usbSerial); + Peripherals::setTimestampTimer(×tampTimer); + Peripherals::setHspLed(&hspLed); + Peripherals::setMAX30101(&max30101); + Peripherals::setI2c1(&i2c1); + Peripherals::setI2c2(&i2c2); + Peripherals::setPushButton(&pushButton); + Peripherals::setBLE(&ble); + Peripherals::setMAX14720(&max14720); + Peripherals::setMAX30001(&max30001); + Peripherals::setHspBLE(&hspBLE); + + // init the S25FS256 external flash device + printf("Init S25FS512...\n"); + fflush(stdout); + s25fs512.init(); + + // init the BMP280 + printf("Init BMP280...\n"); + fflush(stdout); + bmp280.init(BMP280::OVERSAMPLING_X2_P, BMP280::OVERSAMPLING_X1_T, + BMP280::FILT_OFF, BMP280::NORMAL_MODE, BMP280::T_62_5); + + // Initialize BLE base layer + printf("Init HSPBLE...\n"); + fflush(stdout); + hspBLE.init(); + + // start blinking led1 + printf("Init HSPLED Blink...\n"); + fflush(stdout); + hspLed.blink(1000); + + // MAX30101 initialize interrupt + printf("Init MAX30101 callbacks, interrupt...\n"); + fflush(stdout); + max30101.onInterrupt(&MAX30101_OnInterrupt); + max30101.onDataAvailable(&StreamPacketUint32); + max30101_Interrupt.fall(&MAX30101MidIntHandler); + + // + // MAX30001 + // + printf("Init MAX30001 callbacks, interrupts...\n"); + fflush(stdout); + max30001_InterruptB.disable_irq(); + max30001_Interrupt2B.disable_irq(); + max30001_InterruptB.mode(PullUp); + max30001_InterruptB.fall(&MAX30001Mid_IntB_Handler); + max30001_Interrupt2B.mode(PullUp); + max30001_Interrupt2B.fall(&MAX30001Mid_Int2B_Handler); + max30001_InterruptB.enable_irq(); + max30001_Interrupt2B.enable_irq(); + MAX30001_AllowInterrupts(1); + // Configuring the FCLK for the ECG, set to 32.768KHZ + printf("Init MAX30001 PWM...\n"); + fflush(stdout); + pwmout.period_us(31); + pwmout.write(0.5); // 0-1 is 0-100%, 0.5 = 50% duty cycle. + max30001.max30001_sw_rst(); // Do a software reset of the MAX30001 + max30001.max30001_INT_assignment(MAX30001::MAX30001_INT_B, MAX30001::MAX30001_NO_INT, MAX30001::MAX30001_NO_INT, // en_enint_loc, en_eovf_loc, en_fstint_loc, + MAX30001::MAX30001_INT_2B, MAX30001::MAX30001_INT_2B, MAX30001::MAX30001_NO_INT, // en_dcloffint_loc, en_bint_loc, en_bovf_loc, + MAX30001::MAX30001_INT_2B, MAX30001::MAX30001_INT_2B, MAX30001::MAX30001_NO_INT, // en_bover_loc, en_bundr_loc, en_bcgmon_loc, + MAX30001::MAX30001_INT_B, MAX30001::MAX30001_NO_INT, MAX30001::MAX30001_NO_INT, // en_pint_loc, en_povf_loc, en_pedge_loc, + MAX30001::MAX30001_INT_2B, MAX30001::MAX30001_INT_B, MAX30001::MAX30001_NO_INT, // en_lonint_loc, en_rrint_loc, en_samp_loc, + MAX30001::MAX30001_INT_ODNR, MAX30001::MAX30001_INT_ODNR); // intb_Type, int2b_Type) + max30001.onDataAvailable(&StreamPacketUint32); + + // initialize the LIS2DH accelerometer and interrupts + printf("Init LIS2DH interrupt...\n"); + fflush(stdout); + lis2dh.init(); + lis2dh_Interrupt.fall(&LIS2DHIntHandler); + lis2dh_Interrupt.mode(PullUp); + // initialize the RPC server + printf("Init RPC Server...\n"); + fflush(stdout); + RPC_init(); + // initialize the logging service + printf("Init LoggingService...\n"); + fflush(stdout); + LoggingService_Init(); + + // start main loop + printf("Start main loop...\n"); + fflush(stdout); + while (1) { + // get a RPC string if one is available + inputState = getLine(request, sizeof(request)); + // if a string has been captured, process string + if (inputState == GETLINE_DONE) { + // process the RPC string + RPC_call(request, reply); + // output the reply + putStr(reply); + } + // process any logging or streaming requests + LoggingService_ServiceRoutine(); + // allow for ble processing + ble.waitForEvent(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/USBDevice.lib Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/MaximIntegrated/code/USBDevice/#6e1433359654
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Tue Oct 25 15:22:11 2016 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#e435a07d9252f133ea3d9f6c95dfb176f32ab9b6