upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
max30100.h
Go to the documentation of this file.
1 /*
2  * Author: Noel Eck <noel.eck@intel.com>
3  * Copyright (c) 2015 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 #pragma once
26 
27 #include <errno.h>
28 #include <stdint.h>
29 
30 #include "max30100_regs.h"
31 
32 #include "mraa/gpio.h"
33 #include "mraa/i2c.h"
34 #include "upm.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
51 typedef struct {
52  /* mraa I2C context */
53  mraa_i2c_context _i2c_context;
54 
55  /* mraa gpio context (for interrupt) */
56  mraa_gpio_context _gpio_context;
57 
58  /* Sensor acquire mode */
59  MAX30100_SAMPLE_STATE sample_state;
60 
61  /* Continuous sampling function ptr */
62  func_sample_ready_handler func_sample_ready;
63 
64  /* Optional void ptr arg returned from callback */
65  void* arg;
67 
74 max30100_context* max30100_init(int16_t i2c_bus);
75 
83 
94 upm_result_t max30100_sample(max30100_context* dev, max30100_value *samp);
95 
120  int gpio_pin,
121  bool buffered,
122  func_sample_ready_handler isr,
123  void* arg);
124 
131 upm_result_t max30100_sample_stop(max30100_context* dev);
132 
141 upm_result_t max30100_read(const max30100_context* dev, MAX30100_REG reg, uint8_t* rd_data);
142 
151 upm_result_t max30100_write(const max30100_context* dev, MAX30100_REG reg, uint8_t wr_data);
152 
164 upm_result_t max30100_rd_mod_wr(const max30100_context* dev,
165  MAX30100_REG reg, uint8_t value, uint8_t mask);
166 
182 upm_result_t max30100_get_version(const max30100_context* dev, uint16_t* version);
183 
190 upm_result_t max30100_get_temperature(const max30100_context* dev, float* temperature);
191 
199 upm_result_t max30100_set_mode(const max30100_context* dev, MAX30100_MODE mode);
200 
208 upm_result_t max30100_get_mode(const max30100_context* dev, MAX30100_MODE* mode);
209 
217 upm_result_t max30100_set_high_res(const max30100_context* dev, bool high_res);
218 
226 upm_result_t max30100_get_high_res(const max30100_context* dev, bool* high_res);
227 
235 upm_result_t max30100_set_sample_rate(const max30100_context* dev, MAX30100_SR sample_rate);
236 
244 upm_result_t max30100_get_sample_rate(const max30100_context* dev, MAX30100_SR* sample_rate);
245 
253 upm_result_t max30100_set_pulse_width(const max30100_context* dev, MAX30100_LED_PW pulse_width);
254 
262 upm_result_t max30100_get_pulse_width(const max30100_context* dev, MAX30100_LED_PW* pulse_width);
263 
272 upm_result_t max30100_set_current(const max30100_context* dev,
273  MAX30100_LED_CURRENT ir,
274  MAX30100_LED_CURRENT r);
275 
284 upm_result_t max30100_get_current(const max30100_context* dev,
285  MAX30100_LED_CURRENT* ir,
286  MAX30100_LED_CURRENT* r);
287 
301 upm_result_t max30100_reset(const max30100_context* dev);
302 
314 upm_result_t max30100_sleep(const max30100_context* dev, bool sleep);
315 
316 #ifdef __cplusplus
317 }
318 #endif
upm_result_t max30100_set_pulse_width(const max30100_context *dev, MAX30100_LED_PW pulse_width)
Definition: max30100.c:296
void max30100_close(max30100_context *dev)
Definition: max30100.c:84
upm_result_t max30100_get_current(const max30100_context *dev, MAX30100_LED_CURRENT *ir, MAX30100_LED_CURRENT *r)
Definition: max30100.c:325
upm_result_t max30100_write(const max30100_context *dev, MAX30100_REG reg, uint8_t wr_data)
Definition: max30100.c:141
upm_result_t max30100_get_high_res(const max30100_context *dev, bool *high_res)
Definition: max30100.c:262
upm_result_t max30100_sample(max30100_context *dev, max30100_value *samp)
Definition: max30100.c:413
upm_result_t max30100_reset(const max30100_context *dev)
Definition: max30100.c:341
upm_result_t max30100_set_sample_rate(const max30100_context *dev, MAX30100_SR sample_rate)
Definition: max30100.c:276
upm_result_t max30100_rd_mod_wr(const max30100_context *dev, MAX30100_REG reg, uint8_t value, uint8_t mask)
Definition: max30100.c:151
upm_result_t max30100_get_sample_rate(const max30100_context *dev, MAX30100_SR *sample_rate)
Definition: max30100.c:282
Definition: max30100.h:51
upm_result_t max30100_get_version(const max30100_context *dev, uint16_t *version)
Definition: max30100.c:172
upm_result_t max30100_sample_stop(max30100_context *dev)
Definition: max30100.c:517
upm_result_t max30100_sample_continuous(max30100_context *dev, int gpio_pin, bool buffered, func_sample_ready_handler isr, void *arg)
Definition: max30100.c:455
upm_result_t max30100_read(const max30100_context *dev, MAX30100_REG reg, uint8_t *rd_data)
Definition: max30100.c:129
Definition: max30100_regs.h:36
upm_result_t max30100_set_high_res(const max30100_context *dev, bool high_res)
Definition: max30100.c:255
upm_result_t max30100_sleep(const max30100_context *dev, bool sleep)
Definition: max30100.c:349
upm_result_t max30100_set_mode(const max30100_context *dev, MAX30100_MODE mode)
Definition: max30100.c:235
upm_result_t max30100_set_current(const max30100_context *dev, MAX30100_LED_CURRENT ir, MAX30100_LED_CURRENT r)
Definition: max30100.c:316
upm_result_t max30100_get_mode(const max30100_context *dev, MAX30100_MODE *mode)
Definition: max30100.c:241
upm_result_t max30100_get_pulse_width(const max30100_context *dev, MAX30100_LED_PW *pulse_width)
Definition: max30100.c:302
max30100_context * max30100_init(int16_t i2c_bus)
Definition: max30100.c:33
upm_result_t max30100_get_temperature(const max30100_context *dev, float *temperature)
Definition: max30100.c:192