heartrate6  2.0.0.0
heartrate6.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 HEARTRATE6_H
36 #define HEARTRATE6_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define HEARTRATE6_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
55 
61 #define HEARTRATE6_RETVAL uint8_t
62 
63 #define HEARTRATE6_OK 0x00
64 #define HEARTRATE6_INIT_ERROR 0xFF
65 
71 #define HEARTRATE6_SLAVE_ADDR 0x5B
72 
78 #define HEARTRATE6_MANUFACT_ID_REG1 0x0F
79 #define HEARTRATE6_MANUFACT_ID_REG2 0x92
80 #define HEARTRATE6_PART_ID_REG 0x10
81 #define HEARTRATE6_RESET_REG 0x40
82 #define HEARTRATE6_MEAS_CTRL1_REG 0x41
83 #define HEARTRATE6_MEAS_CTRL2_REG 0x42
84 #define HEARTRATE6_MEAS_START_REG 0x43
85 #define HEARTRATE6_DATA_LEDOFF_LSB_REG 0x54
86 #define HEARTRATE6_DATA_LEDOFF_MSB_REG 0x55
87 #define HEARTRATE6_DATA_LEDON_LSB_REG 0x56
88 #define HEARTRATE6_DATA_LEDON_MSB_REG 0x57
89 
95 #define HEARTRATE6_RESET_CMD 0x80
96 #define HEARTRATE6_OSC_ACTIVE 0x80
97 #define HEARTRATE6_LED_FREQ_128HZ 0x00
98 #define HEARTRATE6_LED_FREQ_64HZ 0x04
99 #define HEARTRATE6_DATAREAD_FREQ_64HZ 0x01
100 #define HEARTRATE6_DATAREAD_FREQ_32HZ 0x02
101 #define HEARTRATE6_LEDS_PULSED 0x00
102 #define HEARTRATE6_LED1_CONST_LED2_PULSED 0x40
103 #define HEARTRATE6_LED1_PULSED_LED2_CONST 0x80
104 #define HEARTRATE6_LEDS_CONST 0xC0
105 #define HEARTRATE6_LED_TIME_300MICROSEC 0x00
106 #define HEARTRATE6_LED_TIME_600MICROSEC 0x20
107 #define HEARTRATE6_LED_CURR_0MA 0x00
108 #define HEARTRATE6_LED_CURR_1MA 0x08
109 #define HEARTRATE6_LED_CURR_2MA 0x09
110 #define HEARTRATE6_LED_CURR_3MA 0x0A
111 #define HEARTRATE6_LED_CURR_6MA 0x0B
112 #define HEARTRATE6_LED_CURR_10MA 0x0C
113 #define HEARTRATE6_LED_CURR_20MA 0x0D
114 #define HEARTRATE6_LED_CURR_30MA 0x0E
115 #define HEARTRATE6_LED_CURR_60MA 0x0F
116 #define HEARTRATE6_START_MEAS 0x01
117 
123 #define HEARTRATE6_OK 0x00
124 #define HEARTRATE6_WRONG_ADDR 0x01
125 #define HEARTRATE6_NBYTES_RANGE_ERROR 0x02
126  // End group macro
129 // --------------------------------------------------------------- PUBLIC TYPES
138 typedef struct
139 {
140 
141  // Modules
142 
143  i2c_master_t i2c;
144 
145  // ctx variable
146 
147  uint8_t slave_address;
148 
149  float res;
150  uint8_t wait_time;
151 
152 } heartrate6_t;
153 
157 typedef struct
158 {
159  // Communication gpio pins
160 
161  pin_name_t scl;
162  pin_name_t sda;
163 
164  // static variable
165 
166  uint32_t i2c_speed;
167  uint8_t i2c_address;
168 
170  // End types group
172 
173 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
174 
180 #ifdef __cplusplus
181 extern "C"{
182 #endif
183 
193 
203 
212 
224 uint8_t heartrate6_write_single_byte ( heartrate6_t *ctx, uint8_t reg_addr, uint8_t data_in );
225 
238 uint8_t heartrate6_write_bytes ( heartrate6_t *ctx, uint8_t start_addr, uint8_t *data_in, uint8_t n_bytes );
239 
252 uint8_t heartrate6_read_bytes( heartrate6_t *ctx, uint8_t start_addr, uint8_t *data_out, uint8_t n_bytes );
253 
261 
270 
280 void heartrate6_set_freq ( heartrate6_t *ctx, uint8_t freq_data );
281 
291 void heartrate6_get_data ( heartrate6_t *ctx, uint16_t *led_off_data, uint16_t *led_on_data );
292 
301 
302 #ifdef __cplusplus
303 }
304 #endif
305 #endif // _HEARTRATE6_H_
306  // End public_function group
309 
310 // ------------------------------------------------------------------------- END
heartrate6_t
Click ctx object definition.
Definition: heartrate6.h:139
heartrate6_cfg_setup
void heartrate6_cfg_setup(heartrate6_cfg_t *cfg)
Config Object Initialization function.
heartrate6_t::i2c
i2c_master_t i2c
Definition: heartrate6.h:143
heartrate6_cfg_t::sda
pin_name_t sda
Definition: heartrate6.h:162
heartrate6_set_freq
void heartrate6_set_freq(heartrate6_t *ctx, uint8_t freq_data)
Frequency Set function.
heartrate6_wait_measure
void heartrate6_wait_measure(heartrate6_t *ctx)
Wait measurement function.
heartrate6_start_measure
void heartrate6_start_measure(heartrate6_t *ctx)
Measurement Start function.
heartrate6_t::wait_time
uint8_t wait_time
Definition: heartrate6.h:150
heartrate6_cfg_t::i2c_address
uint8_t i2c_address
Definition: heartrate6.h:167
heartrate6_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: heartrate6.h:166
heartrate6_cfg_t::scl
pin_name_t scl
Definition: heartrate6.h:161
heartrate6_t::res
float res
Definition: heartrate6.h:149
heartrate6_cfg_t
Click configuration structure definition.
Definition: heartrate6.h:158
heartrate6_write_single_byte
uint8_t heartrate6_write_single_byte(heartrate6_t *ctx, uint8_t reg_addr, uint8_t data_in)
Single Byte Write function.
heartrate6_reset
void heartrate6_reset(heartrate6_t *ctx)
Reset function.
HEARTRATE6_RETVAL
#define HEARTRATE6_RETVAL
Definition: heartrate6.h:61
heartrate6_get_data
void heartrate6_get_data(heartrate6_t *ctx, uint16_t *led_off_data, uint16_t *led_on_data)
Data Get function.
heartrate6_init
HEARTRATE6_RETVAL heartrate6_init(heartrate6_t *ctx, heartrate6_cfg_t *cfg)
Initialization function.
heartrate6_write_bytes
uint8_t heartrate6_write_bytes(heartrate6_t *ctx, uint8_t start_addr, uint8_t *data_in, uint8_t n_bytes)
Bytes Write function.
heartrate6_read_bytes
uint8_t heartrate6_read_bytes(heartrate6_t *ctx, uint8_t start_addr, uint8_t *data_out, uint8_t n_bytes)
Generic Read function.
heartrate6_default_cfg
void heartrate6_default_cfg(heartrate6_t *ctx)
Click Default Configuration function.
heartrate6_t::slave_address
uint8_t slave_address
Definition: heartrate6.h:147