heartrate 2.0.0.0
heartrate.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to 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 MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef HEARTRATE_H
36#define HEARTRATE_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56
57// -------------------------------------------------------------- PUBLIC MACROS
67#define HEARTRATE_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
70 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
77#define HEARTRATE_RETVAL uint8_t
78
79#define HEARTRATE_OK 0x00
80#define HEARTRATE_INIT_ERROR 0xFF
87#define SLAVE_ADDRESS 0x57
94#define HEARTRATE_INT_STATUS 0x00
95#define HEARTRATE_INT_ENABLE 0x01
96#define HEARTRATE_FIFO_WRITE_PTR 0x02
97#define HEARTRATE_OVER_FLOW_CNT 0x03
98#define HEARTRATE_FIFO_READ_PTR 0x04
99#define HEARTRATE_FIFO_DATA_REG 0x05
100#define HEARTRATE_MODE_CONFIG 0x06
101#define HEARTRATE_SPO2_CONFIG 0x07
102#define HEARTRATE_LED_CONFIG 0x09
103#define HEARTRATE_TEMP_INTEGER 0x16
104#define HEARTRATE_TEMP_FRACTION 0x17
105#define HEARTRATE_REVISION_ID 0xFE
106#define HEARTRATE_PART_ID 0xFF
113#define HEARTRATE_TEMP_EN 0x08
114#define HEARTRATE_HR_ONLY 0x02
115#define HEARTRATE_SPO2_EN 0x03
122#define HEARTRATE_SPO2_HI_RES_EN 0x40
129 #define HEARTRATE_ENA_A_FULL 0x80
130 #define HEARTRATE_ENA_TEP_RDY 0x40
131 #define HEARTRATE_ENA_HR_RDY 0x20
132 #define HEARTRATE_ENA_SO2_RDY 0x10
139#define HEARTRATE_PWR_RDY 0x01
146#define HEARTRATE_SAMPLES_50 0x00
147#define HEARTRATE_SAMPLES_100 0x04
148#define HEARTRATE_SAMPLES_167 0x08
149#define HEARTRATE_SAMPLES_200 0x0C
150#define HEARTRATE_SAMPLES_400 0x10
151#define HEARTRATE_SAMPLES_600 0x14
152#define HEARTRATE_SAMPLES_800 0x18
153#define HEARTRATE_SAMPLES_1000 0x1C
160#define HEARTRATE_PULSE_WIDTH_200 0x00 // 13-bit ADC resolution
161#define HEARTRATE_PULSE_WIDTH_400 0x01 // 14-bit ADC resolution
162#define HEARTRATE_PULSE_WIDTH_800 0x02 // 15-bit ADC resolution
163#define HEARTRATE_PULSE_WIDTH_1600 0x03 // 16-bit ADC resolution
170#define HEARTRATE_IR_CURRENT_0 0x00 // 0.0 mA
171#define HEARTRATE_IR_CURRENT_44 0x01 // 4.4 mA
172#define HEARTRATE_IR_CURRENT_76 0x02 // 7.6 mA
173#define HEARTRATE_IR_CURRENT_110 0x03 // 11.0 mA
174#define HEARTRATE_IR_CURRENT_142 0x04 // 14.2 mA
175#define HEARTRATE_IR_CURRENT_174 0x05 // 17.4 mA
176#define HEARTRATE_IR_CURRENT_208 0x06 // 20.8 mA
177#define HEARTRATE_IR_CURRENT_240 0x07 // 24.0 mA
178#define HEARTRATE_IR_CURRENT_271 0x08 // 27.1 mA
179#define HEARTRATE_IR_CURRENT_306 0x09 // 30.6 mA
180#define HEARTRATE_IR_CURRENT_338 0x0A // 33.8 mA
181#define HEARTRATE_IR_CURRENT_370 0x0B // 37.0 mA
182#define HEARTRATE_IR_CURRENT_402 0x0C // 40.2 mA
183#define HEARTRATE_IR_CURRENT_436 0x0D // 43.6 mA
184#define HEARTRATE_IR_CURRENT_468 0x0E // 46.8 mA
185#define HEARTRATE_IR_CURRENT_500 0x0F // 50.0 mA
186
187#define HEARTRATE_RED_CURRENT_0 0x00 // 0.0 mA
188#define HEARTRATE_RED_CURRENT_44 0x10 // 4.4 mA
189#define HEARTRATE_RED_CURRENT_76 0x20 // 7.6 mA
190#define HEARTRATE_RED_CURRENT_110 0x30 // 11.0 mA
191#define HEARTRATE_RED_CURRENT_142 0x40 // 14.2 mA
192#define HEARTRATE_RED_CURRENT_174 0x50 // 17.4 mA
193#define HEARTRATE_RED_CURRENT_208 0x60 // 20.8 mA
194#define HEARTRATE_RED_CURRENT_240 0x70 // 24.0 mA
195#define HEARTRATE_RED_CURRENT_271 0x80 // 27.1 mA
196#define HEARTRATE_RED_CURRENT_306 0x90 // 30.6 mA
197#define HEARTRATE_RED_CURRENT_338 0xA0 // 33.8 mA
198#define HEARTRATE_RED_CURRENT_370 0xB0 // 37.0 mA
199#define HEARTRATE_RED_CURRENT_402 0xC0 // 40.2 mA
200#define HEARTRATE_RED_CURRENT_436 0xD0 // 43.6 mA
201#define HEARTRATE_RED_CURRENT_468 0xE0 // 46.8 mA
202#define HEARTRATE_RED_CURRENT_500 0xF0 // 50.0 mA
204 // End group macro
205// --------------------------------------------------------------- PUBLIC TYPES
214typedef struct
215{
216 // Input pins
217
218 digital_in_t int_pin;
219
220 // Modules
221
222 i2c_master_t i2c;
223
224 // ctx variable
225
227
229
233typedef struct
234{
235 // Communication gpio pins
236
237 pin_name_t scl;
238 pin_name_t sda;
239
240 // Additional gpio pins
241
242 pin_name_t int_pin;
243
244 // static variable
245
246 uint32_t i2c_speed;
247 uint8_t i2c_address;
248
250
251 // End types group
252// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
253
259#ifdef __cplusplus
260extern "C"{
261#endif
262
272
282
291
300
309
318
327
336void heartrate_set_config ( heartrate_t *ctx, uint8_t cfg );
337
346void heartrate_set_interrupt ( heartrate_t *ctx, uint8_t intrpts );
347
359uint8_t heartrate_read_ir_red ( heartrate_t *ctx, uint16_t *ir_buff, uint16_t *red_buff );
360
369void heartrate_read_temp ( heartrate_t *ctx, uint16_t *temp_value );
370
381
392void heartrate_generic_write ( heartrate_t *ctx, uint8_t reg, uint16_t len, uint8_t *data_buf );
393
405void heartrate_generic_read ( heartrate_t *ctx, uint8_t reg, uint16_t len, uint8_t *data_buf );
406
417void hr_shut_down ( heartrate_t *ctx, bool enable );
418
426void hr_reset ( heartrate_t *ctx );
427
437void hr_temp_enable ( heartrate_t *ctx, bool enable );
438
449int8_t hr_set_mode ( heartrate_t *ctx, uint8_t mode );
450
459void hr_spo2_high_res_enable ( heartrate_t *ctx, bool enable );
460
470uint8_t hr_spo2_set_sample_rate ( heartrate_t *ctx, uint8_t sample_rate );
471
482uint8_t hr_set_led_pulse_width ( heartrate_t *ctx, uint8_t _value );
483
494uint8_t hr_set_red_current_level ( heartrate_t *ctx, uint8_t level );
495
506uint8_t hr_set_ir_current_level ( heartrate_t *ctx, uint8_t level );
507
517
526void hr_temp_ready_int_enable ( heartrate_t *ctx, bool enable );
527
537
547
560uint8_t hr_read_diodes ( heartrate_t *ctx, uint16_t* ir_buff, uint16_t* red_buff );
561
572uint8_t hr_get_status ( heartrate_t *ctx );
573
574#ifdef __cplusplus
575}
576#endif
577#endif // _HEARTRATE_H_
578
579 // End public_function group
581
582// ------------------------------------------------------------------------- END
#define HEARTRATE_RETVAL
Definition heartrate.h:77
uint8_t hr_get_status(heartrate_t *ctx)
Function for getting the value read from the interrupt status register.
uint8_t heartrate_get_part_id(heartrate_t *ctx)
Function for getting part ID.
void hr_temp_enable(heartrate_t *ctx, bool enable)
Single temperature reading function.
void hr_heartrate_spo2_data_ready_int_enable(heartrate_t *ctx, bool enable)
Function to enable/disable the SpO2 data ready.
void heartrate_cfg_setup(heartrate_cfg_t *cfg)
Config Object Initialization function.
uint8_t hr_set_led_pulse_width(heartrate_t *ctx, uint8_t _value)
Function for setting LED pulse width.
void heartrate_read_temp(heartrate_t *ctx, uint16_t *temp_value)
Function for reading temperature.
void hr_fifo_almost_full_int_enable(heartrate_t *ctx, bool enable)
Function to enable/disable the FIFO almost full interrupt.
uint8_t hr_spo2_set_sample_rate(heartrate_t *ctx, uint8_t sample_rate)
Function for setting.
void hr_heartrate_data_ready_int_enable(heartrate_t *ctx, bool enable)
Function to enable/disable heart rate data ready interrupt.
uint8_t heartrate_get_revision_id(heartrate_t *ctx)
Function for getting revision ID.
void heartrate_set_config(heartrate_t *ctx, uint8_t cfg)
Function for configuration heartrate chip.
uint8_t hr_set_red_current_level(heartrate_t *ctx, uint8_t level)
Function for setting Red LED.
uint8_t heartrate_data_ready(heartrate_t *ctx)
Function checking if the data is ready for reading.
void hr_spo2_high_res_enable(heartrate_t *ctx, bool enable)
Function for setting the SpO2 ADC resolution.
uint8_t hr_set_ir_current_level(heartrate_t *ctx, uint8_t level)
Function for setting.
void heartrate_generic_read(heartrate_t *ctx, uint8_t reg, uint16_t len, uint8_t *data_buf)
Generic read function.
uint8_t heartrate_get_config(heartrate_t *ctx)
Function for getting configuration of the chip.
uint8_t heartrate_get_status(heartrate_t *ctx)
Function for getting status of heartrate click.
HEARTRATE_RETVAL heartrate_init(heartrate_t *ctx, heartrate_cfg_t *cfg)
Initialization function.
void heartrate_default_cfg(heartrate_t *ctx)
Click Default Configuration function.
void hr_temp_ready_int_enable(heartrate_t *ctx, bool enable)
Function to enable/disable the temperature data ready interrupt.
void heartrate_set_interrupt(heartrate_t *ctx, uint8_t intrpts)
Function for setting interrupt for heartrate click.
uint8_t hr_read_diodes(heartrate_t *ctx, uint16_t *ir_buff, uint16_t *red_buff)
Function for reading the ADC values of the IR and RED LEDs from the FIFO buffer.
void hr_shut_down(heartrate_t *ctx, bool enable)
Shut down function.
int8_t hr_set_mode(heartrate_t *ctx, uint8_t mode)
Set mode function.
void heartrate_generic_write(heartrate_t *ctx, uint8_t reg, uint16_t len, uint8_t *data_buf)
Generic write function.
void hr_reset(heartrate_t *ctx)
Reset function.
uint8_t heartrate_read_ir_red(heartrate_t *ctx, uint16_t *ir_buff, uint16_t *red_buff)
Function for reading IR and RED values.
Click configuration structure definition.
Definition heartrate.h:234
uint32_t i2c_speed
Definition heartrate.h:246
pin_name_t scl
Definition heartrate.h:237
pin_name_t int_pin
Definition heartrate.h:242
pin_name_t sda
Definition heartrate.h:238
uint8_t i2c_address
Definition heartrate.h:247
Click ctx object definition.
Definition heartrate.h:215
digital_in_t int_pin
Definition heartrate.h:218
i2c_master_t i2c
Definition heartrate.h:222
uint8_t slave_address
Definition heartrate.h:226