heartrate4 2.0.0.0
heartrate4.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 HEARTRATE4_H
36#define HEARTRATE4_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// -------------------------------------------------------------- PUBLIC MACROS
66#define HEARTRATE4_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl1 = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda1 = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.int1 = MIKROBUS( mikrobus, MIKROBUS_INT )
76#define HEARTRATE4_RETVAL uint8_t
77
78#define HEARTRATE4_OK 0x00
79#define HEARTRATE4_INIT_ERROR 0xFF
86#define HEARTRATE4_I2C_ADDRESS 0x57
98#define HEARTRATE4_INT_STAT1 0x00
99#define HEARTRATE4_INT_STAT2 0x01
100#define HEARTRATE4_INT_ENABLE1 0x02
101#define HEARTRATE4_INT_ENABLE2 0x03
108#define HEARTRATE4_FIFO_WRITE_PTR 0x04
109#define HEARTRATE4_FIFO_OVERFLOW 0x05
110#define HEARTRATE4_FIFO_READ_PTR 0x06
111#define HEARTRATE4_FIFO_DATA 0x07
112#define HEARTRATE4_BUFFER_LENGTH 32
119#define HEARTRATE4_FIFO_CONFIG 0x08
120#define HEARTRATE4_MODE_CONFIG 0x09
121#define HEARTRATE4_SPO2_CONFIG 0x0A //SpO2 Configuration
122#define HEARTRATE4_LED1_PULSE_AMP 0x0C
123#define HEARTRATE4_LED2_PULSE_AMP 0x0D
124#define HEARTRATE4_LED3_PULSE_AMP 0x0E
125#define HEARTRATE4_LED_PROX_AMP 0x10
126#define HEARTRATE4_MULTI_LED_CONFIG1 0x11
127#define HEARTRATE4_MULTI_LED_CONFIG2 0x12
128#define HEARTRATE4_MIN_POWER_LEVEL 0x01
129#define HEARTRATE4_AVG_POWER_LEVEL 0x1F
130#define HEARTRATE4_MAX_POWER_LEVEL 0xFF
137#define HEARTRATE4_DIE_TEMP_INT 0x1F
138#define HEARTRATE4_DIE_TEMP_FRAC 0x20
139#define HEARTRATE4_DIE_TEMP_CONFIG 0x21
146#define HEARTRATE4_PROX_INT_THRESH 0x30
153#define HEARTRATE4_REVISION_ID 0xFE
154#define HEARTRATE4_PART_ID 0xFF
156 //End registers addresses group of macro
157
167#define HEARTRATE4_INT_A_FULL_MASK (uint8_t)~0b10000000
168#define HEARTRATE4_INT_A_FULL_ENABLE 0x80
169#define HEARTRATE4_INT_A_FULL_DISABLE 0x00
170#define HEARTRATE4_INT_DATA_RDY_MASK (uint8_t)~0b01000000
171#define HEARTRATE4_INT_DATA_RDY_ENABLE 0x40
172#define HEARTRATE4_INT_DATA_RDY_DISABLE 0x00
173#define HEARTRATE4_INT_ALC_OVF_MASK (uint8_t)~0b00100000
174#define HEARTRATE4_INT_ALC_OVF_ENABLE 0x20
175#define HEARTRATE4_INT_ALC_OVF_DISABLE 0x00
176#define HEARTRATE4_INT_PROX_INT_MASK (uint8_t)~0b00010000
177#define HEARTRATE4_INT_PROX_INT_ENABLE 0x10
178#define HEARTRATE4_INT_PROX_INT_DISABLE 0x00
179#define HEARTRATE4_INT_DIE_TEMP_RDY_MASK (uint8_t)~0b00000010
180#define HEARTRATE4_INT_DIE_TEMP_RDY_ENABLE 0x02
181#define HEARTRATE4_INT_DIE_TEMP_RDY_DISABLE 0x00
188#define HEARTRATE4_SAMPLEAVG_MASK (uint8_t)~0b11100000
189#define HEARTRATE4_SAMPLEAVG_1 0x00
190#define HEARTRATE4_SAMPLEAVG_2 0x20
191#define HEARTRATE4_SAMPLEAVG_4 0x40
192#define HEARTRATE4_SAMPLEAVG_8 0x60
193#define HEARTRATE4_SAMPLEAVG_16 0x80
194#define HEARTRATE4_SAMPLEAVG_32 0xA0
195#define HEARTRATE4_ROLLOVER_MASK 0xEF
196#define HEARTRATE4_ROLLOVER_ENABLE 0x10
197#define HEARTRATE4_ROLLOVER_DISABLE 0x00
198#define HEARTRATE4_A_FULL_MASK 0xF0
205#define HEARTRATE4_SHUTDOWN_MASK 0x7F
206#define HEARTRATE4_SHUTDOWN 0x80
207#define HEARTRATE4_WAKEUP 0x00
208#define HEARTRATE4_RESET_MASK 0xBF
209#define HEARTRATE4_RESET 0x40
210#define HEARTRATE4_MODE_MASK 0xF8
211#define HEARTRATE4_MODE_REDONLY 0x02 // Heart Rate mode
212#define HEARTRATE4_MODE_REDIRONLY 0x03 // SpO2 mode
213#define HEARTRATE4_MODE_MULTILED 0x07 // Multi-LED mode
220#define HEARTRATE4_ADCRANGE_MASK 0x9F
221#define HEARTRATE4_ADCRANGE_2048 0x00
222#define HEARTRATE4_ADCRANGE_4096 0x20
223#define HEARTRATE4_ADCRANGE_8192 0x40
224#define HEARTRATE4_ADCRANGE_16384 0x60
225#define HEARTRATE4_SAMPLERATE_MASK 0xE3
226#define HEARTRATE4_SAMPLERATE_50 0x00
227#define HEARTRATE4_SAMPLERATE_100 0x04
228#define HEARTRATE4_SAMPLERATE_200 0x08
229#define HEARTRATE4_SAMPLERATE_400 0x0C
230#define HEARTRATE4_SAMPLERATE_800 0x10
231#define HEARTRATE4_SAMPLERATE_1000 0x14
232#define HEARTRATE4_SAMPLERATE_1600 0x18
233#define HEARTRATE4_SAMPLERATE_3200 0x1C
234#define HEARTRATE4_PULSEWIDTH_MASK 0xFC
235#define HEARTRATE4_PULSEWIDTH_69 0x00
236#define HEARTRATE4_PULSEWIDTH_118 0x01
237#define HEARTRATE4_PULSEWIDTH_215 0x02
238#define HEARTRATE4_PULSEWIDTH_411 0x03
245#define HEARTRATE4_SLOT1_MASK 0xF8
246#define HEARTRATE4_SLOT2_MASK 0x8F
247#define HEARTRATE4_SLOT3_MASK 0xF8
248#define HEARTRATE4_SLOT4_MASK 0x8F
249#define HEARTRATE4_SLOT_NONE 0x00
250#define HEARTRATE4_SLOT_RED_LED 0x01
251#define HEARTRATE4_SLOT_IR_LED 0x02
252#define HEARTRATE4_SLOT_GREEN_LED 0x03
253#define HEARTRATE4_SLOT_NONE_PILOT 0x04
254#define HEARTRATE4_SLOT_RED_PILOT 0x05
255#define HEARTRATE4_SLOT_IR_PILOT 0x06
256#define HEARTRATE4_SLOT_GREEN_PILOT 0x07
258 // End command group macro
259 // End group macro
260// --------------------------------------------------------------- PUBLIC TYPES
269typedef struct
270{
271 // Input pins
272
273 digital_in_t int1;
274
275 // Modules
276
277 i2c_master_t i2c;
278
279 // ctx variable
280
282
284
288typedef struct
289{
290 // Communication gpio pins
291
292 pin_name_t scl1;
293 pin_name_t sda1;
294
295 // Additional gpio pins
296
297 pin_name_t int1;
298
299 // static variable
300
301 uint32_t i2c_speed;
302 uint8_t i2c_address;
303
305
309typedef struct
310{
311 // Structure fields
312
313 uint8_t avg_samp;
314 uint8_t mode;
315 uint8_t adc_range;
316 uint8_t samp_rate;
317 uint8_t pulse_width;
318 uint8_t led_pow_lvl;
319
321
322 // End types group
323// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
324
330#ifdef __cplusplus
331extern "C"{
332#endif
333
343
353
362
372void heartrate4_write_data ( heartrate4_t *ctx, uint8_t wr_addr, uint8_t wr_data );
373
384uint8_t heartrate4_read_data ( heartrate4_t *ctx, uint8_t rd_addr );
385
396void heartrate4_multi_read ( heartrate4_t *ctx, uint8_t rd_addr, uint8_t *buffer, uint8_t cnt );
397
408void heartrate4_set_new_value ( heartrate4_t *ctx, uint8_t reg, uint8_t mask, uint8_t value );
409
420uint8_t heartrate4_get_intrrupt ( heartrate4_t *ctx, uint8_t flag );
421
446void heartrate4_enable_disable_interrupts ( heartrate4_t *ctx, uint8_t interrupt_flag, uint8_t enable_flag );
447
469void heartrate4_setting_function ( heartrate4_t *ctx, uint8_t flag, uint8_t mode );
470
491void heartrate4_setting_prox_and_amp ( heartrate4_t *ctx, uint8_t flag, uint8_t write_data );
492
502void heartrate4_enable_slot ( heartrate4_t *ctx, uint8_t slot_num, uint8_t dev );
503
512
521
541void heartrate4_fifo_setting ( heartrate4_t *ctx, uint8_t flag, uint8_t samp_num );
542
553
564
574
584
592
601
612
633uint8_t heartrate4_check_int_pow_and_temp ( heartrate4_t *ctx, uint8_t flag );
634
645uint16_t heartrate4_read_fifo_all_samples ( heartrate4_t *ctx, uint8_t *buff );
646
656
675
676#ifdef __cplusplus
677}
678#endif
679#endif // _HEARTRATE4_H_
680
681 // End public_function group
683
684// ------------------------------------------------------------------------- END
#define HEARTRATE4_RETVAL
Definition heartrate4.h:76
uint16_t heartrate4_read_fifo_all_samples(heartrate4_t *ctx, uint8_t *buff)
Read all FIFO samples function.
float heartrate4_read_temp_c(heartrate4_t *ctx)
Read temperature in Centigrade function.
void heartrate4_write_data(heartrate4_t *ctx, uint8_t wr_addr, uint8_t wr_data)
Generic write function.
void heartrate4_setting_prox_and_amp(heartrate4_t *ctx, uint8_t flag, uint8_t write_data)
Set corresponding amplitude or proximity threshold function.
void heartrate4_enable_disable_interrupts(heartrate4_t *ctx, uint8_t interrupt_flag, uint8_t enable_flag)
Enable or disable interrupt function.
void heartrate4_multi_read(heartrate4_t *ctx, uint8_t rd_addr, uint8_t *buffer, uint8_t cnt)
Multi read function.
uint32_t heartrate4_get_red_val(heartrate4_t *ctx)
Get Red value function.
void heartrate4_set_registers(heartrate4_t *ctx, heartrate4_set_registers_t *registers)
Set registers values function.
uint8_t heartrate4_get_intrrupt(heartrate4_t *ctx, uint8_t flag)
Get desired interrupt function.
void heartrate4_clear_fifo(heartrate4_t *ctx)
Clearing FIFO pointers function.
void heartrate4_setting_function(heartrate4_t *ctx, uint8_t flag, uint8_t mode)
Set corresponding configuration register function.
uint8_t heartrate4_get_write_ptr(heartrate4_t *ctx)
Read the FIFO Write Pointer function.
void heartrate4_cfg_setup(heartrate4_cfg_t *cfg)
Config Object Initialization function.
void heartrate4_reset(heartrate4_t *ctx)
Reset device function.
uint8_t heartrate4_check_int_pow_and_temp(heartrate4_t *ctx, uint8_t flag)
Check interrupt, power ready or internal temperature ready flag function.
uint8_t heartrate4_check_int(heartrate4_t *ctx)
Get Interrupt state function.
uint8_t heartrate4_read_data(heartrate4_t *ctx, uint8_t rd_addr)
Generic read function.
void heartrate4_disable_slots(heartrate4_t *ctx)
Disable slots in MultiLED mode function.
void heartrate4_default_cfg(heartrate4_t *ctx)
Click Default Configuration function.
void heartrate4_enable_slot(heartrate4_t *ctx, uint8_t slot_num, uint8_t dev)
Define slots in MultiLED mode function.
float heartrate4_read_temp_f(heartrate4_t *ctx)
Read temperature in Fahrenheit function.
void heartrate4_fifo_setting(heartrate4_t *ctx, uint8_t flag, uint8_t samp_num)
Set FIFO configuration register function.
uint32_t heartrate4_read_fifo_oldest_sample(heartrate4_t *ctx)
Read oldest FIFO sample function.
HEARTRATE4_RETVAL heartrate4_init(heartrate4_t *ctx, heartrate4_cfg_t *cfg)
Initialization function.
uint8_t heartrate4_get_read_ptr(heartrate4_t *ctx)
Read the FIFO Read Pointer function.
void heartrate4_set_new_value(heartrate4_t *ctx, uint8_t reg, uint8_t mask, uint8_t value)
Set new value function.
Click configuration structure definition.
Definition heartrate4.h:289
pin_name_t int1
Definition heartrate4.h:297
uint32_t i2c_speed
Definition heartrate4.h:301
pin_name_t sda1
Definition heartrate4.h:293
pin_name_t scl1
Definition heartrate4.h:292
uint8_t i2c_address
Definition heartrate4.h:302
Click registers object definition.
Definition heartrate4.h:310
uint8_t mode
Definition heartrate4.h:314
uint8_t led_pow_lvl
Definition heartrate4.h:318
uint8_t avg_samp
Definition heartrate4.h:313
uint8_t adc_range
Definition heartrate4.h:315
uint8_t samp_rate
Definition heartrate4.h:316
uint8_t pulse_width
Definition heartrate4.h:317
Click ctx object definition.
Definition heartrate4.h:270
digital_in_t int1
Definition heartrate4.h:273
i2c_master_t i2c
Definition heartrate4.h:277
uint8_t slave_address
Definition heartrate4.h:281