heartrate8 2.0.0.0
heartrate8.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 HEARTRATE8_H
36#define HEARTRATE8_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 HEARTRATE8_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
76#define HEARTRATE8_RETVAL uint8_t
77
78#define HEARTRATE8_OK 0x00
79#define HEARTRATE8_INIT_ERROR 0xFF
86#define HEARTRATE8_SLAVE_ADDR 0x5B
93#define HEARTRATE8_MANUFACT_ID_REG 0x0F
94#define HEARTRATE8_PART_ID_REG 0x10
95#define HEARTRATE8_RESET_REG 0x40
96#define HEARTRATE8_MEAS_CTRL1_REG 0x41
97#define HEARTRATE8_MEAS_CTRL2_REG 0x42
98#define HEARTRATE8_MEAS_CTRL3_REG 0x43
99#define HEARTRATE8_MEAS_CTRL4_LSB_REG 0x44
100#define HEARTRATE8_MEAS_CTRL4_MSB_REG 0x45
101#define HEARTRATE8_MEAS_CTRL5_REG 0x46
102#define HEARTRATE8_MEAS_START_REG 0x47
103#define HEARTRATE8_MEAS_SYNC_REG 0x48
104#define HEARTRATE8_FIFO_LEV_REG 0x4B
105#define HEARTRATE8_FIFO_DATA0_LSB_REG 0x4C
106#define HEARTRATE8_FIFO_DATA0_MSB_REG 0x4D
107#define HEARTRATE8_FIFO_DATA1_LSB_REG 0x4E
108#define HEARTRATE8_FIFO_DATA1_MSB_REG 0x4F
109#define HEARTRATE8_IRDATA_LEDOFF_LSB_REG 0x50
110#define HEARTRATE8_IRDATA_LEDOFF_MSB_REG 0x51
111#define HEARTRATE8_IRDATA_LEDON_LSB_REG 0x52
112#define HEARTRATE8_IRDATA_LEDON_MSB_REG 0x53
113#define HEARTRATE8_GDATA_LEDOFF_LSB_REG 0x54
114#define HEARTRATE8_GDATA_LEDOFF_MSB_REG 0x55
115#define HEARTRATE8_GDATA_LEDON_LSB_REG 0x56
116#define HEARTRATE8_GDATA_LEDON_MSB_REG 0x57
117#define HEARTRATE8_INT_CLEAR_REG 0x58
124#define HEARTRATE8_RESET_CMD 0x80
125#define HEARTRATE8_OSC_ACTIVE 0x80
126#define HEARTRATE8_GREEN_MEAS_MODE 0x00
127#define HEARTRATE8_IR_MEAS_MODE 0x10
128#define HEARTRATE8_32HZ_MEAS_MODE 0x00
129#define HEARTRATE8_128HZ_MEAS_MODE 0x01
130#define HEARTRATE8_64HZ_MEAS_MODE 0x02
131#define HEARTRATE8_256HZ_MEAS_MODE 0x03
132#define HEARTRATE8_1024HZ_MEAS_MODE 0x05
133#define HEARTRATE8_NON_SYNC_MEAS_MODE 0x06
134#define HEARTRATE8_SINGLE_MEAS_MODE 0x07
135#define HEARTRATE8_LEDS_PULSED 0x00
136#define HEARTRATE8_LED1_ON 0x40
137#define HEARTRATE8_LED2_ON 0x80
138#define HEARTRATE8_LEDS_ON 0xC0
139#define HEARTRATE8_LED3_OFF 0x00
140#define HEARTRATE8_LED3_ON 0x80
141#define HEARTRATE8_STOP_EMISSION 0x00
142#define HEARTRATE8_LED_CURR_1MA 0x01
143#define HEARTRATE8_LED_CURR_2MA 0x02
144#define HEARTRATE8_LED_CURR_5MA 0x05
145#define HEARTRATE8_LED_CURR_10MA 0x0A
146#define HEARTRATE8_LED_CURR_15MA 0x0F
147#define HEARTRATE8_LED_CURR_20MA 0x14
148#define HEARTRATE8_LED_CURR_25MA 0x19
149#define HEARTRATE8_LED_CURR_30MA 0x1E
150#define HEARTRATE8_LED_CURR_35MA 0x23
151#define HEARTRATE8_LED_CURR_40MA 0x28
152#define HEARTRATE8_LED_CURR_45MA 0x2D
153#define HEARTRATE8_LED_CURR_50MA 0x32
154#define HEARTRATE8_LED_CURR_55MA 0x37
155#define HEARTRATE8_LED_CURR_60MA 0x3C
156#define HEARTRATE8_LED_CURR_63MA 0x3F
157#define HEARTRATE8_INT_DISABLE 0x00
158#define HEARTRATE8_INT_WATER_MARK_FIFO 0x01
159#define HEARTRATE8_INT_IR_THRESH 0x02
160#define HEARTRATE8_INT_MEAS_COMPLET 0x03
161#define HEARTRATE8_MEAS_START_CMD 0x01
162#define HEARTRATE8_MEAS_SYNC_CMD 0x01
169#define HEARTRATE8_FIFO_DATA_GET 0x00
170#define HEARTRATE8_IR_DATA_GET 0x01
171#define HEARTRATE8_GREEN_DATA_GET 0x02
178#define HEARTRATE8_OK 0x00
179#define HEARTRATE8_WRONG_ADDR 0x01
180#define HEARTRATE8_NBYTES_RANGE_ERROR 0x02
181#define HEARTRATE8_DATA_SEL_ERROR 0x03
182#define HEARTRATE8_INT_ACTIVE 0x00
183#define HEARTRATE8_INT_INACTIVE 0x01
186 // End group macro
187// --------------------------------------------------------------- PUBLIC TYPES
196typedef struct
197{
198
199 // Input pins
200
201 digital_in_t int_pin;
202
203 // Modules
204
205 i2c_master_t i2c;
206
207 // ctx variable
208
210
212
216typedef struct
217{
218 // Communication gpio pins
219
220 pin_name_t scl;
221 pin_name_t sda;
222
223 // Additional gpio pins
224
225 pin_name_t int_pin;
226
227 // static variable
228
229 uint32_t i2c_speed;
230 uint8_t i2c_address;
231
233
234 // End types group
235
236// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
237
243#ifdef __cplusplus
244extern "C"{
245#endif
246
256
266
275
287uint8_t heartrate8_write_single_byte ( heartrate8_t *ctx, uint8_t reg_addr, uint8_t data_in );
288
301uint8_t heartrate8_write_bytes ( heartrate8_t *ctx, uint8_t start_addr, uint8_t *data_in, uint8_t n_bytes );
302
315uint8_t heartrate8_read_bytes ( heartrate8_t *ctx, uint8_t start_addr, uint8_t *data_out, uint8_t n_bytes );
316
324
333
343
353
363
376uint8_t heartrate8_get_data ( heartrate8_t *ctx, uint8_t data_select, uint16_t *led_out_on, uint16_t *led_out_off );
377
378#ifdef __cplusplus
379}
380#endif
381#endif // _HEARTRATE8_H_
382
383 // End public_function group
385
386// ------------------------------------------------------------------------- END
#define HEARTRATE8_RETVAL
Definition heartrate8.h:76
HEARTRATE8_RETVAL heartrate8_init(heartrate8_t *ctx, heartrate8_cfg_t *cfg)
Initialization function.
void heartrate8_meas_sync(heartrate8_t *ctx)
Measurement Synchronization function.
uint8_t heartrate8_write_bytes(heartrate8_t *ctx, uint8_t start_addr, uint8_t *data_in, uint8_t n_bytes)
Generic Bytes Write function.
void heartrate8_start_measure(heartrate8_t *ctx)
Measurement Start function.
uint8_t heartrate8_write_single_byte(heartrate8_t *ctx, uint8_t reg_addr, uint8_t data_in)
Generic Single Byte Write function.
uint8_t heartrate8_int_clear(heartrate8_t *ctx)
Interrupt Clear function.
void heartrate8_cfg_setup(heartrate8_cfg_t *cfg)
Config Object Initialization function.
void heartrate8_default_cfg(heartrate8_t *ctx)
Click Default Configuration function.
uint8_t heartrate8_read_bytes(heartrate8_t *ctx, uint8_t start_addr, uint8_t *data_out, uint8_t n_bytes)
Generic Read function.
uint8_t heartrate8_get_data(heartrate8_t *ctx, uint8_t data_select, uint16_t *led_out_on, uint16_t *led_out_off)
Data Get function.
uint8_t heartrate8_check_int(heartrate8_t *ctx)
Interrupt Check function.
void heartrate8_reset(heartrate8_t *ctx)
Reset function.
Click configuration structure definition.
Definition heartrate8.h:217
uint32_t i2c_speed
Definition heartrate8.h:229
pin_name_t scl
Definition heartrate8.h:220
pin_name_t int_pin
Definition heartrate8.h:225
pin_name_t sda
Definition heartrate8.h:221
uint8_t i2c_address
Definition heartrate8.h:230
Click ctx object definition.
Definition heartrate8.h:197
digital_in_t int_pin
Definition heartrate8.h:201
i2c_master_t i2c
Definition heartrate8.h:205
uint8_t slave_address
Definition heartrate8.h:209