heartrate3  2.0.0.0
heartrate3.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 HEARTRATE3_H
36 #define HEARTRATE3_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define HEARTRATE3_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
66  cfg.clk = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
67  cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
68 
74 #define HEARTRATE3_OK 0
75 #define HEARTRATE3_ERROR -1
76 
82 #define HEARTRATE3_SLAVE_ADDR 0x58
83 
89 #define HEARTRATE3_REG_CONTROL0 0x00
90 #define HEARTRATE3_REG_LED2STC 0x01
91 #define HEARTRATE3_REG_LED2ENDC 0x02
92 #define HEARTRATE3_REG_LED1LEDSTC 0x03
93 #define HEARTRATE3_REG_LED1LEDENDC 0x04
94 #define HEARTRATE3_REG_ALED2STC 0x05
95 #define HEARTRATE3_REG_ALED2ENDC 0x06
96 #define HEARTRATE3_REG_LED1STC 0x07
97 #define HEARTRATE3_REG_LED1ENDC 0x08
98 #define HEARTRATE3_REG_LED2LEDSTC 0x09
99 #define HEARTRATE3_REG_LED2LEDENDC 0x0A
100 #define HEARTRATE3_REG_ALED1STC 0x0B
101 #define HEARTRATE3_REG_ALED1ENDC 0x0C
102 #define HEARTRATE3_REG_LED2CONVST 0x0D
103 #define HEARTRATE3_REG_LED2CONVEND 0x0E
104 #define HEARTRATE3_REG_ALED2CONVST 0x0F
105 #define HEARTRATE3_REG_ALED2CONVEND 0x10
106 #define HEARTRATE3_REG_LED1CONVST 0x11
107 #define HEARTRATE3_REG_LED1CONVEND 0x12
108 #define HEARTRATE3_REG_ALED1CONVST 0x13
109 #define HEARTRATE3_REG_ALED1CONVEND 0x14
110 #define HEARTRATE3_REG_ADCRSTSTCT0 0x15
111 #define HEARTRATE3_REG_ADCRSTENDCT0 0x16
112 #define HEARTRATE3_REG_ADCRSTSTCT1 0x17
113 #define HEARTRATE3_REG_ADCRSTENDCT1 0x18
114 #define HEARTRATE3_REG_ADCRSTSTCT2 0x19
115 #define HEARTRATE3_REG_ADCRSTENDCT2 0x1A
116 #define HEARTRATE3_REG_ADCRSTSTCT3 0x1B
117 #define HEARTRATE3_REG_ADCRSTENDCT3 0x1C
118 #define HEARTRATE3_REG_PRPCOUNT 0x1D
119 #define HEARTRATE3_REG_CONTROL1 0x1E
120 #define HEARTRATE3_REG_TIA_GAIN_SEP 0x20
121 #define HEARTRATE3_REG_TIA_GAIN 0x21
122 #define HEARTRATE3_REG_LEDCNTRL 0x22
123 #define HEARTRATE3_REG_CONTROL2 0x23
124 #define HEARTRATE3_REG_ALARM 0x29
125 #define HEARTRATE3_REG_LED2VAL 0x2A
126 #define HEARTRATE3_REG_ALED2VAL 0x2B
127 #define HEARTRATE3_REG_LED1VAL 0x2C
128 #define HEARTRATE3_REG_ALED1VAL 0x2D
129 #define HEARTRATE3_REG_LED2_ALED2VAL 0x2E
130 #define HEARTRATE3_REG_LED1_ALED1VAL 0x2F
131 #define HEARTRATE3_REG_CONTROL3 0x31
132 #define HEARTRATE3_REG_PDNCYCLESTC 0x32
133 #define HEARTRATE3_REG_PDNCYCLEENDC 0x33
134 #define HEARTRATE3_REG_PROG_TG_STC 0x34
135 #define HEARTRATE3_REG_PROG_TG_ENDC 0x35
136 #define HEARTRATE3_REG_LED3LEDSTC 0x36
137 #define HEARTRATE3_REG_LED3LEDENDC 0x37
138 #define HEARTRATE3_REG_CLKDIV_PRF 0x39
139 #define HEARTRATE3_REG_OFFDAC 0x3A
140 #define HEARTRATE3_REG_DEC 0x3D
141 #define HEARTRATE3_REG_AVG_LED2_ALED2VAL 0x3F
142 #define HEARTRATE3_REG_AVG_LED1_ALED1VAL 0x40
143 
149 #define HEARTRATE3_CONTROL0_CMD 0x000000ul
150 #define HEARTRATE3_LED2STC_CMD 0x000050ul
151 #define HEARTRATE3_LED2ENDC_CMD 0x00018Ful
152 #define HEARTRATE3_LED1LEDSTC_CMD 0x000320ul
153 #define HEARTRATE3_LED1LEDENDC_CMD 0x0004AFul
154 #define HEARTRATE3_ALED2STC_CMD 0x0001E0ul
155 #define HEARTRATE3_ALED2ENDC_CMD 0x00031Ful
156 #define HEARTRATE3_LED1STC_CMD 0x000370ul
157 #define HEARTRATE3_LED1ENDC_CMD 0x0004AFul
158 #define HEARTRATE3_LED2LEDSTC_CMD 0x000000ul
159 #define HEARTRATE3_LED2LEDENDC_CMD 0x00018Ful
160 #define HEARTRATE3_ALED1STC_CMD 0x0004FFul
161 #define HEARTRATE3_ALED1ENDC_CMD 0x00063Eul
162 #define HEARTRATE3_LED2CONVST_CMD 0x000198ul
163 #define HEARTRATE3_LED2CONVEND_CMD 0x0005BBul
164 #define HEARTRATE3_ALED2CONVST_CMD 0x0005C4ul
165 #define HEARTRATE3_ALED2CONVEND_CMD 0x0009E7ul
166 #define HEARTRATE3_LED1CONVST_CMD 0x0009F0ul
167 #define HEARTRATE3_LED1CONVEND_CMD 0x000E13ul
168 #define HEARTRATE3_ALED1CONVST_CMD 0x000E1Cul
169 #define HEARTRATE3_ALED1CONVEND_CMD 0x00123Ful
170 #define HEARTRATE3_ADCRSTSTCT0_CMD 0x000191ul
171 #define HEARTRATE3_ADCRSTENDCT0_CMD 0x000197ul
172 #define HEARTRATE3_ADCRSTSTCT1_CMD 0x0005BDul
173 #define HEARTRATE3_ADCRSTENDCT1_CMD 0x0005C3ul
174 #define HEARTRATE3_ADCRSTSTCT2_CMD 0x0009E9ul
175 #define HEARTRATE3_ADCRSTENDCT2_CMD 0x0009EFul
176 #define HEARTRATE3_ADCRSTSTCT3_CMD 0x000E15ul
177 #define HEARTRATE3_ADCRSTENDCT3_CMD 0x000E1Bul
178 #define HEARTRATE3_PRPCOUNT_CMD 0x009C3Eul
179 #define HEARTRATE3_CONTROL1_CMD 0x000103ul
180 #define HEARTRATE3_TIA_GAIN_SEP_CMD 0x008003ul
181 #define HEARTRATE3_TIA_GAIN_CMD 0x000003ul
182 #define HEARTRATE3_LEDCNTRL_CMD 0x01B6D9ul
183 #define HEARTRATE3_CONTROL2_CMD 0x104218ul
184 #define HEARTRATE3_ALARM_CMD 0x000000ul
185 #define HEARTRATE3_CONTROL3_CMD 0x000000ul
186 #define HEARTRATE3_PDNCYCLESTC_CMD 0x00155Ful
187 #define HEARTRATE3_PDNCYCLEENDC_CMD 0x00991Eul
188 #define HEARTRATE3_PROG_TG_STC_CMD 0x000000ul
189 #define HEARTRATE3_PROG_TG_ENDC_CMD 0x000000ul
190 #define HEARTRATE3_LED3LEDSTC_CMD 0x000190ul
191 #define HEARTRATE3_LED3LEDENDC_CMD 0x00031Ful
192 #define HEARTRATE3_CLKDIV_PRF_CMD 0x000000ul
193 #define HEARTRATE3_OFFDAC_CMD 0x000000ul
194 
200 #define HEARTRATE3_PIN_STATE_LOW 0x00
201 #define HEARTRATE3_PIN_STATE_HIGH 0x01
202  // End group macro
205 // --------------------------------------------------------------- PUBLIC TYPES
214 typedef struct
215 {
216  // Output pins
217  digital_out_t rst;
218  digital_out_t clk;
219 
220  // Input pins
221  digital_in_t rdy;
222 
223  // Modules
224  i2c_master_t i2c;
225 
226  // ctx variable
227  uint8_t slave_address;
228 
229 } heartrate3_t;
230 
234 typedef struct
235 {
236  // Communication gpio pins
237  pin_name_t scl;
238  pin_name_t sda;
239 
240  // Additional gpio pins
241  pin_name_t rst;
242  pin_name_t clk;
243  pin_name_t rdy;
244 
245  // static variable
246  uint32_t i2c_speed;
247  uint8_t i2c_address;
248 
250  // End types group
252 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
253 
259 #ifdef __cplusplus
260 extern "C"{
261 #endif
262 
273 
284 
294 
305 err_t heartrate3_generic_write ( heartrate3_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
306 
317 err_t heartrate3_generic_read ( heartrate3_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
318 
328 err_t heartrate3_write_data ( heartrate3_t *ctx, uint8_t reg_adr, uint32_t wr_data );
329 
339 err_t heartrate3_read_24bit ( heartrate3_t *ctx, uint8_t reg_adr, uint32_t *data_out );
340 
350 err_t heartrate3_read_16bit ( heartrate3_t *ctx, uint8_t reg_adr, uint16_t *data_out );
351 
360 void heartrate3_rst_state ( heartrate3_t *ctx, uint8_t state );
361 
370 void heartrate3_clk_state ( heartrate3_t *ctx, uint8_t state );
371 
382 
383 #ifdef __cplusplus
384 }
385 #endif
386 #endif // _HEARTRATE3_H_
387  // End public_function group
390 
391 // ------------------------------------------------------------------------- END
heartrate3_t::clk
digital_out_t clk
Definition: heartrate3.h:218
heartrate3_t
Click ctx object definition.
Definition: heartrate3.h:215
heartrate3_cfg_t::sda
pin_name_t sda
Definition: heartrate3.h:238
heartrate3_cfg_t::i2c_address
uint8_t i2c_address
Definition: heartrate3.h:247
heartrate3_t::rdy
digital_in_t rdy
Definition: heartrate3.h:221
heartrate3_cfg_t::scl
pin_name_t scl
Definition: heartrate3.h:237
heartrate3_cfg_t::rdy
pin_name_t rdy
Definition: heartrate3.h:243
heartrate3_t::rst
digital_out_t rst
Definition: heartrate3.h:217
heartrate3_cfg_t::rst
pin_name_t rst
Definition: heartrate3.h:241
heartrate3_generic_read
err_t heartrate3_generic_read(heartrate3_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Generic read function.
heartrate3_cfg_t::clk
pin_name_t clk
Definition: heartrate3.h:242
heartrate3_t::slave_address
uint8_t slave_address
Definition: heartrate3.h:227
heartrate3_t::i2c
i2c_master_t i2c
Definition: heartrate3.h:224
heartrate3_clk_state
void heartrate3_clk_state(heartrate3_t *ctx, uint8_t state)
Set Clock pin state.
heartrate3_cfg_t
Click configuration structure definition.
Definition: heartrate3.h:235
heartrate3_check_data_ready
uint8_t heartrate3_check_data_ready(heartrate3_t *ctx)
Check data ready function.
heartrate3_write_data
err_t heartrate3_write_data(heartrate3_t *ctx, uint8_t reg_adr, uint32_t wr_data)
Write data function.
heartrate3_init
err_t heartrate3_init(heartrate3_t *ctx, heartrate3_cfg_t *cfg)
Initialization function.
heartrate3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: heartrate3.h:246
heartrate3_cfg_setup
void heartrate3_cfg_setup(heartrate3_cfg_t *cfg)
Config Object Initialization function.
heartrate3_default_cfg
err_t heartrate3_default_cfg(heartrate3_t *ctx)
Click Default Configuration function.
heartrate3_read_16bit
err_t heartrate3_read_16bit(heartrate3_t *ctx, uint8_t reg_adr, uint16_t *data_out)
Read 16-bit data function.
heartrate3_generic_write
err_t heartrate3_generic_write(heartrate3_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Generic write function.
heartrate3_rst_state
void heartrate3_rst_state(heartrate3_t *ctx, uint8_t state)
Set Reset pin state.
heartrate3_read_24bit
err_t heartrate3_read_24bit(heartrate3_t *ctx, uint8_t reg_adr, uint32_t *data_out)
Read 24-bit data function.