ecg6  2.0.0.0
ecg6.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 ECG6_H
36 #define ECG6_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 ECG6_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
66 
72 #define ECG6_RETVAL uint8_t
73 
74 #define ECG6_OK 0x00
75 #define ECG6_INIT_ERROR 0xFF
76 
82 #define ECG6_REG_INTERRUPT_STATUS_1 0x00
83 #define ECG6_REG_INTERRUPT_STATUS_2 0x01
84 #define ECG6_REG_INTERRUPT_ENABLE_1 0x02
85 #define ECG6_REG_INTERRUPT_ENABLE_2 0x03
86 
92 #define ECG6_REG_FIFO_WRITE 0x04
93 #define ECG6_REG_OVERFLOW_CNT 0x05
94 #define ECG6_REG_FIFO_READ 0x06
95 #define ECG6_REG_FIFO_DATA 0x07
96 #define ECG6_REG_FIFO_CFG 0x08
97 
103 #define ECG6_REG_FIFO_DATA_CTRL_1 0x09
104 #define ECG6_REG_FIFO_DATA_CTRL_2 0x0A
105 
111 #define ECG6_REG_SYSTEM_CTRL 0x0D
112 
119 #define ECG6_REG_PPG_CFG_1 0x0E
120 #define ECG6_REG_PPG_CFG_2 0x0F
121 #define ECG6_REG_PROX_INT_THR 0x10
122 
128 #define ECG6_REG_LED_PULSE_AMPLITUDE_1 0x11
129 #define ECG6_REG_LED_PULSE_AMPLITUDE_2 0x12
130 #define ECG6_REG_LED_RANGE 0x14
131 #define ECG6_REG_LED_PILOT_PULSE_AMPLITUDE 0x15
132 
138 #define ECG6_REG_CONFIG_1 0x3C
139 #define ECG6_REG_CONFIG_3 0x3E
140 
146 #define ECG6_REG_PART_ID 0xFF
147 
153 #define ECG6_INTS1_A_FULL_ON 0x80
154 #define ECG6_INTS1_A_FULL_OFF 0x00
155 #define ECG6_INTS1_PPG_RDY_ON 0x40
156 #define ECG6_INTS1_PPG_RDY_OFF 0x00
157 #define ECG6_INTS1_ALC_OVF_ON 0x20
158 #define ECG6_INTS1_ALC_OVF_OFF 0x00
159 #define ECG6_INTS1_PROX_INIT_ON 0x10
160 #define ECG6_INTS1_PROX_INIT_OFF 0x00
161 #define ECG6_INTS1_PWR_RDY_ON 0x01
162 #define ECG6_INTS1_PWR_RDY_OFF 0x00
163 
169 #define ECG6_INTS2_VDD_OOR_ON 0x80
170 #define ECG6_INTS2_VDD_OOR_OFF 0x00
171 #define ECG6_INTS2_DRDY_ON 0x04
172 #define ECG6_INTS2_DRDY_OFF 0x00
173 
179 #define ECG6_INTE1_A_FULL_ENABLE 0x80
180 #define ECG6_INTE1_A_FULL_DISABLE 0x00
181 #define ECG6_INTE1_PPG_RDY_ENABLE 0x40
182 #define ECG6_INTE1_PPG_RDY_DISABLE 0x00
183 #define ECG6_INTE1_ALC_OVF_ENABLE 0x20
184 #define ECG6_INTE1_ALC_OVF_DISABLE 0x00
185 #define ECG6_INTE1_PROX_INT_ENABLE 0x10
186 #define ECG6_INTE1_PROX_INT_DISABLE 0x00
187 
193 #define ECG6_INTS2_VDD_OOR_ENABLE 0x80
194 #define ECG6_INTS2_VDD_OOR_DISABLE 0x00
195 #define ECG6_INTS2_DRDY_ENABLE 0x04
196 #define ECG6_INTS2_DRDY_DISABLE 0x00
197 
203 #define ECG6_FCFG_A_FULL_CLR 0x40
204 #define ECG6_FCFG_A_FULL_NO_CLR 0x00
205 #define ECG6_FCFG_A_FULL_TYPE_RPT 0x00
206 #define ECG6_FCFG_A_FULL_TYPE_ONCE 0x20
207 #define ECG6_FCFG_FIFO_ROLLS_ON_FULL_ON 0x10
208 #define ECG6_FCFG_FIFO_ROLLS_ON_FULL_OFF 0x00
209 
215 #define ECG6_SYSCTRL_FIFO_ENABLE 0x04
216 #define ECG6_SYSCTRL_FIFO_DISABLE 0x00
217 #define ECG6_SYSCTRL_SHUTDOWN_ENABLE 0x02
218 #define ECG6_SYSCTRL_SHUTDOWN_DISABLE 0x00
219 #define ECG6_SYSCTRL_RESET_ENABLE 0x01
220 #define ECG6_SYSCTRL_RESET_DISABLE 0x00
221 
227 #define ECG6_PPGCFG1_PPG_ADC_RGE_4096nA 0x00
228 #define ECG6_PPGCFG1_PPG_ADC_RGE_8192nA 0x40
229 #define ECG6_PPGCFG1_PPG_ADC_RGE_16384nA 0x80
230 #define ECG6_PPGCFG1_PPG_ADC_RGE_32768nA 0xC0
231 
232 #define ECG6_PPGCFG1_PPG_SR_10n1 0x00
233 #define ECG6_PPGCFG1_PPG_SR_20n1 0x04
234 #define ECG6_PPGCFG1_PPG_SR_50n1 0x08
235 #define ECG6_PPGCFG1_PPG_SR_84n1 0x0C
236 #define ECG6_PPGCFG1_PPG_SR_100n1 0x10
237 #define ECG6_PPGCFG1_PPG_SR_200 0x14
238 #define ECG6_PPGCFG1_PPG_SR_400 0x18
239 #define ECG6_PPGCFG1_PPG_SR_800 0x1C
240 #define ECG6_PPGCFG1_PPG_SR_1000 0x20
241 #define ECG6_PPGCFG1_PPG_SR_1600 0x24
242 #define ECG6_PPGCFG1_PPG_SR_3200 0x28
243 #define ECG6_PPGCFG1_PPG_SR_10n2 0x2C
244 #define ECG6_PPGCFG1_PPG_SR_20n2 0x30
245 #define ECG6_PPGCFG1_PPG_SR_50n2 0x34
246 #define ECG6_PPGCFG1_PPG_SR_84n2 0x38
247 #define ECG6_PPGCFG1_PPG_SR_100n2 0x3C
248 
249 #define ECG6_PPGCFG1_PPG_PW_50us 0x00
250 #define ECG6_PPGCFG1_PPG_PW_100us 0x01
251 #define ECG6_PPGCFG1_PPG_PW_200us 0x02
252 #define ECG6_PPGCFG1_PPG_PW_400us 0x03
253 
259 #define ECG6_PPGCFG2_SMP_AVE_1 0x00
260 #define ECG6_PPGCFG2_SMP_AVE_2 0x01
261 #define ECG6_PPGCFG2_SMP_AVE_4 0x02
262 #define ECG6_PPGCFG2_SMP_AVE_8 0x03
263 #define ECG6_PPGCFG2_SMP_AVE_16 0x04
264 #define ECG6_PPGCFG2_SMP_AVE_32 0x05
265 
271 #define ECG6_LRANG_LED2_SMP_AVE_50 0x00
272 #define ECG6_LRANG_LED2_SMP_AVE_100 0x04
273 #define ECG6_LRANG_LED1_SMP_AVE_50 0x00
274 #define ECG6_LRANG_LED1_SMP_AVE_100 0x01
275 
281 #define ECG6_CFG1_ADC_OSR_1600 0x00
282 #define ECG6_CFG1_ADC_OSR_800 0x01
283 #define ECG6_CFG1_ADC_OSR_400 0x02
284 #define ECG6_CFG1_ADC_OSR_200 0x03
285 #define ECG6_CFG1_ADC_OSR_3200 0x04
286 
292 #define ECG6_CFG3_PGA_GAIN_1 0x00
293 #define ECG6_CFG3_PGA_GAIN_2 0x04
294 #define ECG6_CFG3_PGA_GAIN_4 0x08
295 #define ECG6_CFG3_PGA_GAIN_8 0x0C
296 #define ECG6_CFG3_IA_GAIN_5 0x00
297 #define ECG6_CFG3_IA_GAIN_9p5 0x01
298 #define ECG6_CFG3_IA_GAIN_20 0x02
299 #define ECG6_CFG3_IA_GAIN_50 0x03
300 
306 #define ECG6_DEF_PART_ID 0x1E
307 
313 #define ECG6_DEVICE_SLAVE_ADDRESS 0x5E
314 
320 #define ECG6_SENSOR_PPG_LED_1 0x01
321 #define ECG6_SENSOR_PPG_LED_2 0x02
322 #define ECG6_SENSOR_PPG_PILOT_LED_1 0x05
323 #define ECG6_SENSOR_PPG_PILOT_LED_2 0x06
324 #define ECG6_SENSOR_ECG 0x09
325 #define ECG6_SENSOR_NONE 0x00
326  // End group macro
329 // --------------------------------------------------------------- PUBLIC TYPES
334 typedef struct
335 {
336  uint8_t a_full;
337  uint8_t ppg_rdy;
338  uint8_t alc_ovf;
339  uint8_t prox_int;
340  uint8_t pwr_rdy;
341  uint8_t vdd_oor;
342  uint8_t ecg_rdy;
343 
345 
346 typedef struct
347 {
348  uint32_t element_1;
349  uint32_t element_2;
350  uint32_t element_3;
351  uint32_t element_4;
352 
354 
355 typedef struct
356 {
389 
390 }ecg6_fifo_t;
391 
392 typedef struct
393 {
394  uint8_t element_1;
395  uint8_t element_2;
396  uint8_t element_3;
397  uint8_t element_4;
398 
400 
404 typedef struct
405 {
406  // Output pins
407 
408 
409  // Input pins
410 
411  digital_in_t int_pin;
412 
413  // Modules
414 
415  i2c_master_t i2c;
416 
417  // ctx variable
418 
419  uint8_t slave_address;
420 
421 } ecg6_t;
422 
426 typedef struct
427 {
428  // Communication gpio pins
429 
430  pin_name_t scl;
431  pin_name_t sda;
432 
433  // Additional gpio pins
434 
435  pin_name_t int_pin;
436 
437  // static variable
438 
439  uint32_t i2c_speed;
440  uint8_t i2c_address;
441 
442 } ecg6_cfg_t;
443  // End types group
445 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
446 
452 #ifdef __cplusplus
453 extern "C"{
454 #endif
455 
465 
475 
555 void ecg6_default_cfg ( ecg6_t *ctx );
556 
566 void ecg6_write_data( ecg6_t *ctx, uint8_t reg, uint8_t in_data );
567 
578 void ecg6_write_data_buf( ecg6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
579 
590 uint8_t ecg6_read_data( ecg6_t *ctx, uint8_t reg );
591 
602 void ecg6_read_data_buf( ecg6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
603 
614 uint8_t ecg6_check_path_id ( ecg6_t *ctx );
615 
631 void ecg6_cfg_element( ecg6_t *ctx, ecg6_cfg_element_t *cfg );
632 
644 void ecg6_set_led_pulse( ecg6_t *ctx, uint8_t ir_led, uint8_t red_led );
645 
726 
737 void ecg6_get_sample_data( ecg6_t *ctx, ecg6_element_t *element, uint8_t num_sample );
738 
748 void ecg6_get_all_samples( ecg6_t *ctx, ecg6_fifo_t *fifo_data );
749 
760 
769 uint8_t ecg6_int_pin_state ( ecg6_t *ctx );
770 
771 
772 #ifdef __cplusplus
773 }
774 #endif
775 #endif // _ECG6_H_
776  // End public_function group
779 
780 // ------------------------------------------------------------------------- END
ecg6_int_status_t::ppg_rdy
uint8_t ppg_rdy
Definition: ecg6.h:337
ecg6_fifo_t
Definition: ecg6.h:356
ecg6_get_interrupt_status
void ecg6_get_interrupt_status(ecg6_t *ctx, ecg6_int_status_t *status)
Get Interrupt registers status.
ecg6_int_status_t
Definition: ecg6.h:335
ecg6_fifo_t::sample_9
ecg6_element_t sample_9
Definition: ecg6.h:366
ecg6_int_status_t::pwr_rdy
uint8_t pwr_rdy
Definition: ecg6.h:340
ecg6_element_t::element_3
uint32_t element_3
Definition: ecg6.h:350
ecg6_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ecg6.h:439
ecg6_fifo_t::sample_14
ecg6_element_t sample_14
Definition: ecg6.h:371
ecg6_fifo_t::sample_28
ecg6_element_t sample_28
Definition: ecg6.h:385
ecg6_fifo_t::sample_31
ecg6_element_t sample_31
Definition: ecg6.h:388
ecg6_fifo_t::sample_13
ecg6_element_t sample_13
Definition: ecg6.h:370
ecg6_fifo_t::sample_4
ecg6_element_t sample_4
Definition: ecg6.h:361
ecg6_cfg_t::int_pin
pin_name_t int_pin
Definition: ecg6.h:435
ecg6_fifo_t::sample_27
ecg6_element_t sample_27
Definition: ecg6.h:384
ecg6_fifo_t::sample_29
ecg6_element_t sample_29
Definition: ecg6.h:386
ecg6_cfg_element_t
Definition: ecg6.h:393
ecg6_fifo_t::sample_12
ecg6_element_t sample_12
Definition: ecg6.h:369
ecg6_fifo_t::sample_10
ecg6_element_t sample_10
Definition: ecg6.h:367
ecg6_fifo_t::sample_8
ecg6_element_t sample_8
Definition: ecg6.h:365
ecg6_cfg_element_t::element_3
uint8_t element_3
Definition: ecg6.h:396
ecg6_t::int_pin
digital_in_t int_pin
Definition: ecg6.h:411
ecg6_fifo_t::sample_18
ecg6_element_t sample_18
Definition: ecg6.h:375
ecg6_element_t::element_1
uint32_t element_1
Definition: ecg6.h:348
ecg6_fifo_t::sample_20
ecg6_element_t sample_20
Definition: ecg6.h:377
ecg6_fifo_t::sample_25
ecg6_element_t sample_25
Definition: ecg6.h:382
ecg6_fifo_t::sample_7
ecg6_element_t sample_7
Definition: ecg6.h:364
ecg6_cfg_t::scl
pin_name_t scl
Definition: ecg6.h:430
ecg6_t::slave_address
uint8_t slave_address
Definition: ecg6.h:419
ecg6_t::i2c
i2c_master_t i2c
Definition: ecg6.h:415
ecg6_int_status_t::ecg_rdy
uint8_t ecg_rdy
Definition: ecg6.h:342
ecg6_cfg_t::sda
pin_name_t sda
Definition: ecg6.h:431
ecg6_t
Click ctx object definition.
Definition: ecg6.h:405
ecg6_int_status_t::vdd_oor
uint8_t vdd_oor
Definition: ecg6.h:341
ecg6_fifo_t::sample_26
ecg6_element_t sample_26
Definition: ecg6.h:383
ecg6_cfg_setup
void ecg6_cfg_setup(ecg6_cfg_t *cfg)
Config Object Initialization function.
ecg6_fifo_t::sample_11
ecg6_element_t sample_11
Definition: ecg6.h:368
ecg6_cfg_t
Click configuration structure definition.
Definition: ecg6.h:427
ecg6_ppg_default_config
uint8_t ecg6_ppg_default_config(ecg6_t *ctx)
Function for configuration sensors to element.
ecg6_fifo_t::sample_15
ecg6_element_t sample_15
Definition: ecg6.h:372
ecg6_fifo_t::sample_17
ecg6_element_t sample_17
Definition: ecg6.h:374
ecg6_check_path_id
uint8_t ecg6_check_path_id(ecg6_t *ctx)
Function for check path ID.
ecg6_element_t
Definition: ecg6.h:347
ecg6_fifo_t::sample_19
ecg6_element_t sample_19
Definition: ecg6.h:376
ecg6_fifo_t::sample_6
ecg6_element_t sample_6
Definition: ecg6.h:363
ecg6_default_cfg
void ecg6_default_cfg(ecg6_t *ctx)
Default configuration for ECG sensor.
ecg6_fifo_t::sample_22
ecg6_element_t sample_22
Definition: ecg6.h:379
ecg6_int_pin_state
uint8_t ecg6_int_pin_state(ecg6_t *ctx)
Get Interrupt pin state.
ECG6_RETVAL
#define ECG6_RETVAL
Definition: ecg6.h:72
ecg6_fifo_t::sample_23
ecg6_element_t sample_23
Definition: ecg6.h:380
ecg6_read_data
uint8_t ecg6_read_data(ecg6_t *ctx, uint8_t reg)
Generic Read function.
ecg6_fifo_t::sample_21
ecg6_element_t sample_21
Definition: ecg6.h:378
ecg6_element_t::element_2
uint32_t element_2
Definition: ecg6.h:349
ecg6_cfg_t::i2c_address
uint8_t i2c_address
Definition: ecg6.h:440
ecg6_fifo_t::sample_16
ecg6_element_t sample_16
Definition: ecg6.h:373
ecg6_element_t::element_4
uint32_t element_4
Definition: ecg6.h:351
ecg6_fifo_t::sample_2
ecg6_element_t sample_2
Definition: ecg6.h:359
ecg6_write_data_buf
void ecg6_write_data_buf(ecg6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic Write buffer function.
ecg6_fifo_t::sample_3
ecg6_element_t sample_3
Definition: ecg6.h:360
ecg6_cfg_element_t::element_2
uint8_t element_2
Definition: ecg6.h:395
ecg6_int_status_t::prox_int
uint8_t prox_int
Definition: ecg6.h:339
ecg6_fifo_t::sample_0
ecg6_element_t sample_0
Definition: ecg6.h:357
ecg6_fifo_t::sample_30
ecg6_element_t sample_30
Definition: ecg6.h:387
ecg6_cfg_element_t::element_4
uint8_t element_4
Definition: ecg6.h:397
ecg6_get_all_samples
void ecg6_get_all_samples(ecg6_t *ctx, ecg6_fifo_t *fifo_data)
Get all samples from FIFO.
ecg6_read_data_buf
void ecg6_read_data_buf(ecg6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic Read buffer function.
ecg6_fifo_t::sample_24
ecg6_element_t sample_24
Definition: ecg6.h:381
ecg6_write_data
void ecg6_write_data(ecg6_t *ctx, uint8_t reg, uint8_t in_data)
Generic Write function.
ecg6_fifo_t::sample_1
ecg6_element_t sample_1
Definition: ecg6.h:358
ecg6_int_status_t::a_full
uint8_t a_full
Definition: ecg6.h:336
ecg6_cfg_element_t::element_1
uint8_t element_1
Definition: ecg6.h:394
ecg6_int_status_t::alc_ovf
uint8_t alc_ovf
Definition: ecg6.h:338
ecg6_init
ECG6_RETVAL ecg6_init(ecg6_t *ctx, ecg6_cfg_t *cfg)
Initialization function.
ecg6_get_sample_data
void ecg6_get_sample_data(ecg6_t *ctx, ecg6_element_t *element, uint8_t num_sample)
Get one sample from FIFO.
ecg6_fifo_t::sample_5
ecg6_element_t sample_5
Definition: ecg6.h:362