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 
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 HEARTRATE3_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70  cfg.clk = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
71  cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
72 
78 #define HEARTRATE3_OK 0
79 #define HEARTRATE3_ERROR -1
80 
86 #define HEARTRATE3_SLAVE_ADDR 0x58
87 
93 #define HEARTRATE3_REG_CONTROL0 0x00
94 #define HEARTRATE3_REG_LED2STC 0x01
95 #define HEARTRATE3_REG_LED2ENDC 0x02
96 #define HEARTRATE3_REG_LED1LEDSTC 0x03
97 #define HEARTRATE3_REG_LED1LEDENDC 0x04
98 #define HEARTRATE3_REG_ALED2STC 0x05
99 #define HEARTRATE3_REG_ALED2ENDC 0x06
100 #define HEARTRATE3_REG_LED1STC 0x07
101 #define HEARTRATE3_REG_LED1ENDC 0x08
102 #define HEARTRATE3_REG_LED2LEDSTC 0x09
103 #define HEARTRATE3_REG_LED2LEDENDC 0x0A
104 #define HEARTRATE3_REG_ALED1STC 0x0B
105 #define HEARTRATE3_REG_ALED1ENDC 0x0C
106 #define HEARTRATE3_REG_LED2CONVST 0x0D
107 #define HEARTRATE3_REG_LED2CONVEND 0x0E
108 #define HEARTRATE3_REG_ALED2CONVST 0x0F
109 #define HEARTRATE3_REG_ALED2CONVEND 0x10
110 #define HEARTRATE3_REG_LED1CONVST 0x11
111 #define HEARTRATE3_REG_LED1CONVEND 0x12
112 #define HEARTRATE3_REG_ALED1CONVST 0x13
113 #define HEARTRATE3_REG_ALED1CONVEND 0x14
114 #define HEARTRATE3_REG_ADCRSTSTCT0 0x15
115 #define HEARTRATE3_REG_ADCRSTENDCT0 0x16
116 #define HEARTRATE3_REG_ADCRSTSTCT1 0x17
117 #define HEARTRATE3_REG_ADCRSTENDCT1 0x18
118 #define HEARTRATE3_REG_ADCRSTSTCT2 0x19
119 #define HEARTRATE3_REG_ADCRSTENDCT2 0x1A
120 #define HEARTRATE3_REG_ADCRSTSTCT3 0x1B
121 #define HEARTRATE3_REG_ADCRSTENDCT3 0x1C
122 #define HEARTRATE3_REG_PRPCOUNT 0x1D
123 #define HEARTRATE3_REG_CONTROL1 0x1E
124 #define HEARTRATE3_REG_TIA_GAIN_SEP 0x20
125 #define HEARTRATE3_REG_TIA_GAIN 0x21
126 #define HEARTRATE3_REG_LEDCNTRL 0x22
127 #define HEARTRATE3_REG_CONTROL2 0x23
128 #define HEARTRATE3_REG_ALARM 0x29
129 #define HEARTRATE3_REG_LED2VAL 0x2A
130 #define HEARTRATE3_REG_ALED2VAL 0x2B
131 #define HEARTRATE3_REG_LED1VAL 0x2C
132 #define HEARTRATE3_REG_ALED1VAL 0x2D
133 #define HEARTRATE3_REG_LED2_ALED2VAL 0x2E
134 #define HEARTRATE3_REG_LED1_ALED1VAL 0x2F
135 #define HEARTRATE3_REG_CONTROL3 0x31
136 #define HEARTRATE3_REG_PDNCYCLESTC 0x32
137 #define HEARTRATE3_REG_PDNCYCLEENDC 0x33
138 #define HEARTRATE3_REG_PROG_TG_STC 0x34
139 #define HEARTRATE3_REG_PROG_TG_ENDC 0x35
140 #define HEARTRATE3_REG_LED3LEDSTC 0x36
141 #define HEARTRATE3_REG_LED3LEDENDC 0x37
142 #define HEARTRATE3_REG_CLKDIV_PRF 0x39
143 #define HEARTRATE3_REG_OFFDAC 0x3A
144 #define HEARTRATE3_REG_DEC 0x3D
145 #define HEARTRATE3_REG_AVG_LED2_ALED2VAL 0x3F
146 #define HEARTRATE3_REG_AVG_LED1_ALED1VAL 0x40
147 
153 #define HEARTRATE3_CONTROL0_CMD 0x000000ul
154 #define HEARTRATE3_LED2STC_CMD 0x000050ul
155 #define HEARTRATE3_LED2ENDC_CMD 0x00018Ful
156 #define HEARTRATE3_LED1LEDSTC_CMD 0x000320ul
157 #define HEARTRATE3_LED1LEDENDC_CMD 0x0004AFul
158 #define HEARTRATE3_ALED2STC_CMD 0x0001E0ul
159 #define HEARTRATE3_ALED2ENDC_CMD 0x00031Ful
160 #define HEARTRATE3_LED1STC_CMD 0x000370ul
161 #define HEARTRATE3_LED1ENDC_CMD 0x0004AFul
162 #define HEARTRATE3_LED2LEDSTC_CMD 0x000000ul
163 #define HEARTRATE3_LED2LEDENDC_CMD 0x00018Ful
164 #define HEARTRATE3_ALED1STC_CMD 0x0004FFul
165 #define HEARTRATE3_ALED1ENDC_CMD 0x00063Eul
166 #define HEARTRATE3_LED2CONVST_CMD 0x000198ul
167 #define HEARTRATE3_LED2CONVEND_CMD 0x0005BBul
168 #define HEARTRATE3_ALED2CONVST_CMD 0x0005C4ul
169 #define HEARTRATE3_ALED2CONVEND_CMD 0x0009E7ul
170 #define HEARTRATE3_LED1CONVST_CMD 0x0009F0ul
171 #define HEARTRATE3_LED1CONVEND_CMD 0x000E13ul
172 #define HEARTRATE3_ALED1CONVST_CMD 0x000E1Cul
173 #define HEARTRATE3_ALED1CONVEND_CMD 0x00123Ful
174 #define HEARTRATE3_ADCRSTSTCT0_CMD 0x000191ul
175 #define HEARTRATE3_ADCRSTENDCT0_CMD 0x000197ul
176 #define HEARTRATE3_ADCRSTSTCT1_CMD 0x0005BDul
177 #define HEARTRATE3_ADCRSTENDCT1_CMD 0x0005C3ul
178 #define HEARTRATE3_ADCRSTSTCT2_CMD 0x0009E9ul
179 #define HEARTRATE3_ADCRSTENDCT2_CMD 0x0009EFul
180 #define HEARTRATE3_ADCRSTSTCT3_CMD 0x000E15ul
181 #define HEARTRATE3_ADCRSTENDCT3_CMD 0x000E1Bul
182 #define HEARTRATE3_PRPCOUNT_CMD 0x009C3Eul
183 #define HEARTRATE3_CONTROL1_CMD 0x000103ul
184 #define HEARTRATE3_TIA_GAIN_SEP_CMD 0x008003ul
185 #define HEARTRATE3_TIA_GAIN_CMD 0x000003ul
186 #define HEARTRATE3_LEDCNTRL_CMD 0x01B6D9ul
187 #define HEARTRATE3_CONTROL2_CMD 0x104218ul
188 #define HEARTRATE3_ALARM_CMD 0x000000ul
189 #define HEARTRATE3_CONTROL3_CMD 0x000000ul
190 #define HEARTRATE3_PDNCYCLESTC_CMD 0x00155Ful
191 #define HEARTRATE3_PDNCYCLEENDC_CMD 0x00991Eul
192 #define HEARTRATE3_PROG_TG_STC_CMD 0x000000ul
193 #define HEARTRATE3_PROG_TG_ENDC_CMD 0x000000ul
194 #define HEARTRATE3_LED3LEDSTC_CMD 0x000190ul
195 #define HEARTRATE3_LED3LEDENDC_CMD 0x00031Ful
196 #define HEARTRATE3_CLKDIV_PRF_CMD 0x000000ul
197 #define HEARTRATE3_OFFDAC_CMD 0x000000ul
198 
204 #define HEARTRATE3_PIN_STATE_LOW 0x00
205 #define HEARTRATE3_PIN_STATE_HIGH 0x01
206  // End group macro
209 // --------------------------------------------------------------- PUBLIC TYPES
218 typedef struct
219 {
220  // Output pins
221  digital_out_t rst;
222  digital_out_t clk;
223 
224  // Input pins
225  digital_in_t rdy;
226 
227  // Modules
228  i2c_master_t i2c;
229 
230  // ctx variable
231  uint8_t slave_address;
232 
233 } heartrate3_t;
234 
238 typedef struct
239 {
240  // Communication gpio pins
241  pin_name_t scl;
242  pin_name_t sda;
243 
244  // Additional gpio pins
245  pin_name_t rst;
246  pin_name_t clk;
247  pin_name_t rdy;
248 
249  // static variable
250  uint32_t i2c_speed;
251  uint8_t i2c_address;
252 
254  // End types group
256 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
257 
263 #ifdef __cplusplus
264 extern "C"{
265 #endif
266 
277 
288 
298 
309 err_t heartrate3_generic_write ( heartrate3_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
310 
321 err_t heartrate3_generic_read ( heartrate3_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
322 
332 err_t heartrate3_write_data ( heartrate3_t *ctx, uint8_t reg_adr, uint32_t wr_data );
333 
343 err_t heartrate3_read_24bit ( heartrate3_t *ctx, uint8_t reg_adr, uint32_t *data_out );
344 
354 err_t heartrate3_read_16bit ( heartrate3_t *ctx, uint8_t reg_adr, uint16_t *data_out );
355 
364 void heartrate3_rst_state ( heartrate3_t *ctx, uint8_t state );
365 
374 void heartrate3_clk_state ( heartrate3_t *ctx, uint8_t state );
375 
386 
387 #ifdef __cplusplus
388 }
389 #endif
390 #endif // _HEARTRATE3_H_
391  // End public_function group
394 
395 // ------------------------------------------------------------------------- END
heartrate3_t::clk
digital_out_t clk
Definition: heartrate3.h:222
heartrate3_t
Click ctx object definition.
Definition: heartrate3.h:219
heartrate3_cfg_t::sda
pin_name_t sda
Definition: heartrate3.h:242
heartrate3_cfg_t::i2c_address
uint8_t i2c_address
Definition: heartrate3.h:251
heartrate3_t::rdy
digital_in_t rdy
Definition: heartrate3.h:225
heartrate3_cfg_t::scl
pin_name_t scl
Definition: heartrate3.h:241
heartrate3_cfg_t::rdy
pin_name_t rdy
Definition: heartrate3.h:247
heartrate3_t::rst
digital_out_t rst
Definition: heartrate3.h:221
heartrate3_cfg_t::rst
pin_name_t rst
Definition: heartrate3.h:245
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:246
heartrate3_t::slave_address
uint8_t slave_address
Definition: heartrate3.h:231
heartrate3_t::i2c
i2c_master_t i2c
Definition: heartrate3.h:228
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:239
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:250
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.