upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Data Structures | Functions
Include dependency graph for max30100.h:

API Description

/*
* Author: Noel Eck <noel.eck@intel.com>
* Copyright (c) 2016 Intel Corporation.
*
* 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 THE AUTHORS OR COPYRIGHT HOLDERS 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.
*/
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include "max30100.h"
#include "upm_utilities.h"
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
void my_sample_handler(max30100_value sample, void* arg)
{
printf("My callback sample IR: %d R: %d\n",
sample.IR, sample.R);
}
int main()
{
signal(SIGINT, sig_handler);
if (!sensor)
{
printf("max30100_init() failed\n");
return -1;
}
/* Get the temperature */
float temp;
if (max30100_get_temperature(sensor, &temp) != UPM_SUCCESS)
{
printf("max30100_get_temperature failed\n");
goto max30100_exit;
}
/* Get the version */
uint16_t version;
if (max30100_get_version(sensor, &version) != UPM_SUCCESS)
{
printf("max30100_get_version failed\n");
goto max30100_exit;
}
printf("Temperature: %f C\n", temp);
printf("Version: 0x%04x\n", version);
/* Set high-res (50 Hz, 16-bit) */
if (max30100_set_high_res(sensor, true) != UPM_SUCCESS)
{
printf("max30100_set_high_res failed\n");
goto max30100_exit;
}
/* Set to sample SpO2 */
if (max30100_set_mode(sensor, MAX30100_MODE_SPO2_EN) != UPM_SUCCESS)
{
printf("max30100_set_mode failed\n");
goto max30100_exit;
}
/* Read continuously, stepping up the LED current every second,
* us GPIO 0 as the interrupt pin */
max30100_sample_continuous(sensor, 0, false, &my_sample_handler, sensor);
for (int i = MAX30100_LED_CURRENT_0_0_MA;
i <= MAX30100_LED_CURRENT_50_0_MA && shouldRun; i++)
{
/* Toggle the LED current */
printf("Setting LED current = %d\n", i);
if ( max30100_set_current(sensor, (MAX30100_LED_CURRENT)i,
(MAX30100_LED_CURRENT)i) != UPM_SUCCESS )
{
printf("max30100_set_current failed\n");
goto max30100_exit;
}
upm_delay(1);
}
/* Read individual samples */
for (int i = 0; i < 10; i++)
{
if (max30100_sample(sensor, &samp) != UPM_SUCCESS)
{
printf("max30100_sample failed\n");
goto max30100_exit;
}
printf("Single value IR: %d R: %d\n", samp.IR, samp.R);
}
max30100_exit:
printf("Exiting\n");
max30100_close(sensor);
return 0;
}

Go to the source code of this file.

Data Structures

struct  max30100_context
 

Functions

max30100_contextmax30100_init (int16_t i2c_bus)
 
void max30100_close (max30100_context *dev)
 
upm_result_t max30100_sample (max30100_context *dev, max30100_value *samp)
 
upm_result_t max30100_sample_continuous (max30100_context *dev, int gpio_pin, bool buffered, func_sample_ready_handler isr, void *arg)
 
upm_result_t max30100_sample_stop (max30100_context *dev)
 
upm_result_t max30100_read (const max30100_context *dev, MAX30100_REG reg, uint8_t *rd_data)
 
upm_result_t max30100_write (const max30100_context *dev, MAX30100_REG reg, uint8_t wr_data)
 
upm_result_t max30100_rd_mod_wr (const max30100_context *dev, MAX30100_REG reg, uint8_t value, uint8_t mask)
 
upm_result_t max30100_get_version (const max30100_context *dev, uint16_t *version)
 
upm_result_t max30100_get_temperature (const max30100_context *dev, float *temperature)
 
upm_result_t max30100_set_mode (const max30100_context *dev, MAX30100_MODE mode)
 
upm_result_t max30100_get_mode (const max30100_context *dev, MAX30100_MODE *mode)
 
upm_result_t max30100_set_high_res (const max30100_context *dev, bool high_res)
 
upm_result_t max30100_get_high_res (const max30100_context *dev, bool *high_res)
 
upm_result_t max30100_set_sample_rate (const max30100_context *dev, MAX30100_SR sample_rate)
 
upm_result_t max30100_get_sample_rate (const max30100_context *dev, MAX30100_SR *sample_rate)
 
upm_result_t max30100_set_pulse_width (const max30100_context *dev, MAX30100_LED_PW pulse_width)
 
upm_result_t max30100_get_pulse_width (const max30100_context *dev, MAX30100_LED_PW *pulse_width)
 
upm_result_t max30100_set_current (const max30100_context *dev, MAX30100_LED_CURRENT ir, MAX30100_LED_CURRENT r)
 
upm_result_t max30100_get_current (const max30100_context *dev, MAX30100_LED_CURRENT *ir, MAX30100_LED_CURRENT *r)
 
upm_result_t max30100_reset (const max30100_context *dev)
 
upm_result_t max30100_sleep (const max30100_context *dev, bool sleep)
 

Function Documentation

max30100_context* max30100_init ( int16_t  i2c_bus)

Initialize sensor. Note, the MAX30100 I2C address is set to 0x57.

Parameters
i2c_busTarget I2C bus
Returns
sensor context pointer
void max30100_close ( max30100_context dev)

Sensor close method.

Cleans up any memory held by this device

Parameters
devSensor context pointer
upm_result_t max30100_sample ( max30100_context dev,
max30100_value samp 
)

Sample a single set of infrared/red values

Note, all setup (sample rate, LED current, and pulse width must be done prior to calling this sample method.

Parameters
devSensor context pointer
sampIR/R values are returned in this structure
Returns
Function result code

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t max30100_sample_continuous ( max30100_context dev,
int  gpio_pin,
bool  buffered,
func_sample_ready_handler  isr,
void *  arg 
)

Continuously sample Infrared/Red values.

This method requires a GPIO pin which is used to signal sample/samples ready. The INT * pin is open-drain and requires a pullup resistor. The interrupt pin is not designed to sink large currents, so the pull-up resistor value should be large, such as 4.7k ohm. The RCWL-0530 PCB which this library was designed with had the I2C lines and INT pin pulled up to 1.8v.

Note, all setup (sample rate, mode, LED current, and pulse width must be done prior to calling this sample method.

Parameters
devSensor context pointer
gpio_pinGPIO pin used for interrupt (input from sensor INT pin)
bufferedEnable buffered sampling. In buffered sampling mode, the device reads 16 samples at a time. This can help with I2C read timing. buffered == true, enable buffered sampling buffered == false, single-sample mode
isrFunction pointer which handles 1 IR/R sample and a void ptr arg
argVoid * passed back with ISR call
Returns
Function result code

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t max30100_sample_stop ( max30100_context dev)

Stop continuous sampling. Disable interrupts.

Parameters
devSensor context pointer
Returns
Function result code

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t max30100_read ( const max30100_context dev,
MAX30100_REG  reg,
uint8_t *  rd_data 
)

Read Oximeter and heart-rate sensor register

Parameters
devSensor context pointer
regTarget register
rd_dataData from sensor
Returns
Function result code

Here is the caller graph for this function:

upm_result_t max30100_write ( const max30100_context dev,
MAX30100_REG  reg,
uint8_t  wr_data 
)

Write Oximeter and heart-rate sensor register

Parameters
devSensor context pointer
regTarget register to write
wr_dataTarget data to write
Returns
Function result code

Here is the caller graph for this function:

upm_result_t max30100_rd_mod_wr ( const max30100_context dev,
MAX30100_REG  reg,
uint8_t  value,
uint8_t  mask 
)

Read modify write Oximeter and heart-rate sensor register

Parameters
devSensor context pointer
regTarget register
valueTarget bits to set/clear
maskSpecify the bits to set/clear If mask = 0xf0, read full byte, modify only the upper 4 bits If mask = 0xaa, read full byte, modify every other bit
Returns
Function result code

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t max30100_get_version ( const max30100_context dev,
uint16_t *  version 
)

Get sensor version Sensor version is a 2 byte value: upper byte = PART ID lower byte = REVISION ID

example: version() return 0x1105 0x11 = PART ID 0x05 = REVISION

Parameters
devSensor context pointer
rd_dataSensor version
Returns
Function result code

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t max30100_get_temperature ( const max30100_context dev,
float *  temperature 
)

Get temperature reading from device

Parameters
devSensor context pointer
rd_dataTemperature in degrees Celsius
Returns
Function result code

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t max30100_set_mode ( const max30100_context dev,
MAX30100_MODE  mode 
)

Set the sampling mode (none vs red only vs SpO2)

Parameters
devSensor context pointer
modeSensor mode value to write into the mode configuration register
Returns
Function result code

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t max30100_get_mode ( const max30100_context dev,
MAX30100_MODE *  mode 
)

Get the mode field from the mode configuration register

Parameters
devSensor context pointer
modeSensor mode value read from mode configuration register
Returns
Function result code

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t max30100_set_high_res ( const max30100_context dev,
bool  high_res 
)

Set the high-res field in the SpO2 configuration register

Parameters
devSensor context pointer
high_resSensor high-res value to write into the SpO2 configuration register
Returns
Function result code

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t max30100_get_high_res ( const max30100_context dev,
bool *  high_res 
)

Get the high-res field from the SpO2 configuration register

Parameters
devSensor context pointer
high_resSensor high_res value read from the SpO2 configuration register
Returns
Function result code

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t max30100_set_sample_rate ( const max30100_context dev,
MAX30100_SR  sample_rate 
)

Set the sample rate field in the SpO2 configuration register

Parameters
devSensor context pointer
sample_rateSensor sample rate value to write into the SpO2 configuration register
Returns
Function result code

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t max30100_get_sample_rate ( const max30100_context dev,
MAX30100_SR *  sample_rate 
)

Get the sample rate field from the SpO2 configuration register

Parameters
devSensor context pointer
sample_rateSensor sample rate value read from the SpO2 configuration register
Returns
Function result code

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t max30100_set_pulse_width ( const max30100_context dev,
MAX30100_LED_PW  pulse_width 
)

Set the pulse width field in the SpO2 configuration register

Parameters
devSensor context pointer
pulse_widthSensor pulse width value to write into the SpO2 configuration register
Returns
Function result code

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t max30100_get_pulse_width ( const max30100_context dev,
MAX30100_LED_PW *  pulse_width 
)

Get the pulse width field from the SpO2 configuration register

Parameters
devSensor context pointer
pulse_widthSensor pulse width value read from the SpO2 configuration register
Returns
Function result code

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t max30100_set_current ( const max30100_context dev,
MAX30100_LED_CURRENT  ir,
MAX30100_LED_CURRENT  r 
)

Set the LED current

Parameters
devSensor context pointer
irInfrared LED current enum
rRed LED current enum
Returns
Function result code

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t max30100_get_current ( const max30100_context dev,
MAX30100_LED_CURRENT *  ir,
MAX30100_LED_CURRENT *  r 
)

Get the LED current

Parameters
devSensor context pointer
irInfrared LED current read from the LED configuration register
rRed LED current read from the LED configuration register
Returns
Function result code

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t max30100_reset ( const max30100_context dev)

Reset sensor

When the RESET bit is set to one, all configuration, threshold, and data registers are reset to their power-on-state. The only exception is writing both RESET and TEMP_EN bits to one at the same time since temperature data registers 0x16 and 0x17 are not cleared. The RESET bit is cleared automatically back to zero after the reset sequence is completed.

Parameters
devSensor context pointer
Returns
Function result code

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t max30100_sleep ( const max30100_context dev,
bool  sleep 
)

Put device into power-save mode. While in power-save mode, all registers retain their values, and write/read operations function as normal. All interrupts are cleared to zero in this mode.

Parameters
devSensor context pointer
sleepEnter/exit power-save mode true = Enter power-save mode false = Exit power-save mode
Returns
Function result code

Here is the call graph for this function:

Here is the caller graph for this function: