Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Revision 2:4513f2dd207d, committed 2019-04-14
- Comitter:
- tatsuyanah
- Date:
- Sun Apr 14 02:10:11 2019 +0000
- Parent:
- 1:417090fd8386
- Commit message:
- LIBRARY ADDED
Changed in this revision
| MAX30101/MAX30101.cpp | Show annotated file Show diff for this revision Revisions of this file |
| MAX30101/MAX30101.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/MAX30101/MAX30101.cpp Sun Apr 14 02:10:11 2019 +0000
@@ -0,0 +1,215 @@
+/** \file max30101.cpp ******************************************************
+*
+* Project: MAXREFDES117#
+* Filename: max30101.cpp
+* Description: This module is an embedded controller driver for the MAX30101
+*
+*
+* --------------------------------------------------------------------
+*
+* This code follows the following naming conventions:
+*
+* char ch_pmod_value
+* char (array) s_pmod_s_string[16]
+* float f_pmod_value
+* int32_t n_pmod_value
+* int32_t (array) an_pmod_value[16]
+* int16_t w_pmod_value
+* int16_t (array) aw_pmod_value[16]
+* uint16_t uw_pmod_value
+* uint16_t (array) auw_pmod_value[16]
+* uint8_t uch_pmod_value
+* uint8_t (array) auch_pmod_buffer[16]
+* uint32_t un_pmod_value
+* int32_t * pn_pmod_value
+*
+* ------------------------------------------------------------------------- */
+/*******************************************************************************
+* 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"
+
+I2C i2cB(p9, p10);
+bool maxim_max30101_write_reg(uint8_t uch_addr1, uint8_t uch_data1)
+/**
+* \brief Write a value to a MAX30101 register
+* \par Details
+* This function writes a value to a MAX30101 register
+*
+* \param[in] uch_addr - register address
+* \param[in] uch_data - register data
+*
+* \retval true on success
+*/
+{
+ char ach_i2c_data[2];
+ ach_i2c_data[0]=uch_addr1;
+ ach_i2c_data[1]=uch_data1;
+
+ if(i2cB.write(I2C_WRITE_ADDR1, ach_i2c_data, 2, false)==0)
+ return true;
+ else
+ return false;
+}
+
+bool maxim_max30101_read_reg(uint8_t uch_addr1, uint8_t *puch_data1)
+/**
+* \brief Read a MAX30101 register
+* \par Details
+* This function reads a MAX30101 register
+*
+* \param[in] uch_addr - register address
+* \param[out] puch_data - pointer that stores the register data
+*
+* \retval true on success
+*/
+{
+ char ch_i2c_data;
+ ch_i2c_data=uch_addr1;
+ if(i2cB.write(I2C_WRITE_ADDR1, &ch_i2c_data, 1, true)!=0)
+ return false;
+ if(i2cB.read(I2C_READ_ADDR1, &ch_i2c_data, 1, false)==0)
+ {
+ *puch_data1=(uint8_t) ch_i2c_data;
+ return true;
+ }
+ else
+ return false;
+}
+
+bool maxim_max30101_init()
+/**
+* \brief Initialize the MAX30101
+* \par Details
+* This function initializes the MAX30101
+*
+* \param None
+*
+* \retval true on success
+*/
+{
+ if(!maxim_max30101_write_reg(REG_INTR_ENABLE_1,0xc0)) // INTR setting
+ return false;
+ if(!maxim_max30101_write_reg(REG_INTR_ENABLE_2,0x00))
+ return false;
+ if(!maxim_max30101_write_reg(REG_FIFO_WR_PTR,0x00)) //FIFO_WR_PTR[4:0]
+ return false;
+ if(!maxim_max30101_write_reg(REG_OVF_COUNTER,0x00)) //OVF_COUNTER[4:0]
+ return false;
+ if(!maxim_max30101_write_reg(REG_FIFO_RD_PTR,0x00)) //FIFO_RD_PTR[4:0]
+ return false;
+ if(!maxim_max30101_write_reg(REG_FIFO_CONFIG,0x0f)) //sample avg = 1, fifo rollover=false, fifo almost full = 17
+ return false;
+ if(!maxim_max30101_write_reg(REG_MODE_CONFIG,0x03)) //0x02 for Red only, 0x03 for SpO2 mode 0x07 multimode LED
+ return false;
+ if(!maxim_max30101_write_reg(REG_SPO2_CONFIG,0x27)) // SPO2_ADC range = 4096nA, SPO2 sample rate (100 Hz), LED pulseWidth (400uS)
+ return false;
+
+ if(!maxim_max30101_write_reg(REG_LED1_PA,0x24)) //Choose value for ~ 7mA for LED1
+ return false;
+ if(!maxim_max30101_write_reg(REG_LED2_PA,0x24)) // Choose value for ~ 7mA for LED2
+ return false;
+ if(!maxim_max30101_write_reg(REG_PILOT_PA,0x7f)) // Choose value for ~ 25mA for Pilot LED
+ return false;
+ return true;
+}
+
+bool maxim_max30101_read_fifo(uint32_t *pun_red_led1, uint32_t *pun_ir_led1)
+/**
+* \brief Read a set of samples from the MAX30101 FIFO register
+* \par Details
+* This function reads a set of samples from the MAX30101 FIFO register
+*
+* \param[out] *pun_red_led - pointer that stores the red LED reading data
+* \param[out] *pun_ir_led - pointer that stores the IR LED reading data
+*
+* \retval true on success
+*/
+{
+ uint32_t un_temp1;
+ unsigned char uch_temp1;
+ *pun_red_led1=0;
+ *pun_ir_led1=0;
+ char ach_i2c_data[6];
+
+ //read and clear status register
+ maxim_max30101_read_reg(REG_INTR_STATUS_1, &uch_temp1);
+ maxim_max30101_read_reg(REG_INTR_STATUS_2, &uch_temp1);
+
+ ach_i2c_data[0]=REG_FIFO_DATA;
+ if(i2cB.write(I2C_WRITE_ADDR1, ach_i2c_data, 1, true)!=0)
+ return false;
+ if(i2cB.read(I2C_READ_ADDR1, ach_i2c_data, 6, false)!=0)
+ {
+ return false;
+ }
+ un_temp1=(unsigned char) ach_i2c_data[0];
+ un_temp1<<=16;
+ *pun_red_led1+=un_temp1;
+ un_temp1=(unsigned char) ach_i2c_data[1];
+ un_temp1<<=8;
+ *pun_red_led1+=un_temp1;
+ un_temp1=(unsigned char) ach_i2c_data[2];
+ *pun_red_led1+=un_temp1;
+
+ un_temp1=(unsigned char) ach_i2c_data[3];
+ un_temp1<<=16;
+ *pun_ir_led1+=un_temp1;
+ un_temp1=(unsigned char) ach_i2c_data[4];
+ un_temp1<<=8;
+ *pun_ir_led1+=un_temp1;
+ un_temp1=(unsigned char) ach_i2c_data[5];
+ *pun_ir_led1+=un_temp1;
+ *pun_red_led1&=0x03FFFF; //Mask MSB [23:18]
+ *pun_ir_led1&=0x03FFFF; //Mask MSB [23:18]
+
+
+ return true;
+}
+
+bool maxim_max30101_reset()
+/**
+* \brief Reset the MAX30101
+* \par Details
+* This function resets the MAX30101
+*
+* \param None
+*
+* \retval true on success
+*/
+{
+ if(!maxim_max30101_write_reg(REG_MODE_CONFIG,0x40))
+ return false;
+ else
+ return true;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MAX30101/MAX30101.h Sun Apr 14 02:10:11 2019 +0000 @@ -0,0 +1,97 @@ +/** \file max30101.h ****************************************************** +* +* Project: MAXREFDES117# +* Filename: max30101.h +* Description: This module is an embedded controller driver header file for MAX30101 +* +* +* -------------------------------------------------------------------- +* +* This code follows the following naming conventions: +* +* char ch_pmod_value +* char (array) s_pmod_s_string[16] +* float f_pmod_value +* int32_t n_pmod_value +* int32_t (array) an_pmod_value[16] +* int16_t w_pmod_value +* int16_t (array) aw_pmod_value[16] +* uint16_t uw_pmod_value +* uint16_t (array) auw_pmod_value[16] +* uint8_t uch_pmod_value +* uint8_t (array) auch_pmod_buffer[16] +* uint32_t un_pmod_value +* int32_t * pn_pmod_value +* +* ------------------------------------------------------------------------- */ +/******************************************************************************* +* 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_H_ +#define MAX30101_H_ + +#include "mbed.h" + +#define I2C_WRITE_ADDR1 0xAE +#define I2C_READ_ADDR1 0xAF + +//register addresses +#define REG_INTR_STATUS_1 0x00 +#define REG_INTR_STATUS_2 0x01 +#define REG_INTR_ENABLE_1 0x02 +#define REG_INTR_ENABLE_2 0x03 +#define REG_FIFO_WR_PTR 0x04 +#define REG_OVF_COUNTER 0x05 +#define REG_FIFO_RD_PTR 0x06 +#define REG_FIFO_DATA 0x07 +#define REG_FIFO_CONFIG 0x08 +#define REG_MODE_CONFIG 0x09 +#define REG_SPO2_CONFIG 0x0A +#define REG_LED1_PA 0x0C +#define REG_LED2_PA 0x0D +#define REG_PILOT_PA 0x10 +#define REG_MULTI_LED_CTRL1 0x11 +#define REG_MULTI_LED_CTRL2 0x12 +#define REG_TEMP_INTR 0x1F +#define REG_TEMP_FRAC 0x20 +#define REG_TEMP_CONFIG 0x21 +#define REG_PROX_INT_THRESH 0x30 +#define REG_REV_ID 0xFE +#define REG_PART_ID 0xFF + +bool maxim_max30101_init(); +bool maxim_max30101_read_fifo(uint32_t *pun_red_led1, uint32_t *pun_ir_led1); +bool maxim_max30101_write_reg(uint8_t uch_addr1, uint8_t uch_data1); +bool maxim_max30101_read_reg(uint8_t uch_addr1, uint8_t *puch_data1); +bool maxim_max30101_reset(void); + +#endif /* MAX30101_H_ */ \ No newline at end of file