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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define ECG6_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
56 
62 #define ECG6_RETVAL uint8_t
63 
64 #define ECG6_OK 0x00
65 #define ECG6_INIT_ERROR 0xFF
66 
72 #define ECG6_REG_INTERRUPT_STATUS_1 0x00
73 #define ECG6_REG_INTERRUPT_STATUS_2 0x01
74 #define ECG6_REG_INTERRUPT_ENABLE_1 0x02
75 #define ECG6_REG_INTERRUPT_ENABLE_2 0x03
76 
82 #define ECG6_REG_FIFO_WRITE 0x04
83 #define ECG6_REG_OVERFLOW_CNT 0x05
84 #define ECG6_REG_FIFO_READ 0x06
85 #define ECG6_REG_FIFO_DATA 0x07
86 #define ECG6_REG_FIFO_CFG 0x08
87 
93 #define ECG6_REG_FIFO_DATA_CTRL_1 0x09
94 #define ECG6_REG_FIFO_DATA_CTRL_2 0x0A
95 
101 #define ECG6_REG_SYSTEM_CTRL 0x0D
102 
109 #define ECG6_REG_PPG_CFG_1 0x0E
110 #define ECG6_REG_PPG_CFG_2 0x0F
111 #define ECG6_REG_PROX_INT_THR 0x10
112 
118 #define ECG6_REG_LED_PULSE_AMPLITUDE_1 0x11
119 #define ECG6_REG_LED_PULSE_AMPLITUDE_2 0x12
120 #define ECG6_REG_LED_RANGE 0x14
121 #define ECG6_REG_LED_PILOT_PULSE_AMPLITUDE 0x15
122 
128 #define ECG6_REG_CONFIG_1 0x3C
129 #define ECG6_REG_CONFIG_3 0x3E
130 
136 #define ECG6_REG_PART_ID 0xFF
137 
143 #define ECG6_INTS1_A_FULL_ON 0x80
144 #define ECG6_INTS1_A_FULL_OFF 0x00
145 #define ECG6_INTS1_PPG_RDY_ON 0x40
146 #define ECG6_INTS1_PPG_RDY_OFF 0x00
147 #define ECG6_INTS1_ALC_OVF_ON 0x20
148 #define ECG6_INTS1_ALC_OVF_OFF 0x00
149 #define ECG6_INTS1_PROX_INIT_ON 0x10
150 #define ECG6_INTS1_PROX_INIT_OFF 0x00
151 #define ECG6_INTS1_PWR_RDY_ON 0x01
152 #define ECG6_INTS1_PWR_RDY_OFF 0x00
153 
159 #define ECG6_INTS2_VDD_OOR_ON 0x80
160 #define ECG6_INTS2_VDD_OOR_OFF 0x00
161 #define ECG6_INTS2_DRDY_ON 0x04
162 #define ECG6_INTS2_DRDY_OFF 0x00
163 
169 #define ECG6_INTE1_A_FULL_ENABLE 0x80
170 #define ECG6_INTE1_A_FULL_DISABLE 0x00
171 #define ECG6_INTE1_PPG_RDY_ENABLE 0x40
172 #define ECG6_INTE1_PPG_RDY_DISABLE 0x00
173 #define ECG6_INTE1_ALC_OVF_ENABLE 0x20
174 #define ECG6_INTE1_ALC_OVF_DISABLE 0x00
175 #define ECG6_INTE1_PROX_INT_ENABLE 0x10
176 #define ECG6_INTE1_PROX_INT_DISABLE 0x00
177 
183 #define ECG6_INTS2_VDD_OOR_ENABLE 0x80
184 #define ECG6_INTS2_VDD_OOR_DISABLE 0x00
185 #define ECG6_INTS2_DRDY_ENABLE 0x04
186 #define ECG6_INTS2_DRDY_DISABLE 0x00
187 
193 #define ECG6_FCFG_A_FULL_CLR 0x40
194 #define ECG6_FCFG_A_FULL_NO_CLR 0x00
195 #define ECG6_FCFG_A_FULL_TYPE_RPT 0x00
196 #define ECG6_FCFG_A_FULL_TYPE_ONCE 0x20
197 #define ECG6_FCFG_FIFO_ROLLS_ON_FULL_ON 0x10
198 #define ECG6_FCFG_FIFO_ROLLS_ON_FULL_OFF 0x00
199 
205 #define ECG6_SYSCTRL_FIFO_ENABLE 0x04
206 #define ECG6_SYSCTRL_FIFO_DISABLE 0x00
207 #define ECG6_SYSCTRL_SHUTDOWN_ENABLE 0x02
208 #define ECG6_SYSCTRL_SHUTDOWN_DISABLE 0x00
209 #define ECG6_SYSCTRL_RESET_ENABLE 0x01
210 #define ECG6_SYSCTRL_RESET_DISABLE 0x00
211 
217 #define ECG6_PPGCFG1_PPG_ADC_RGE_4096nA 0x00
218 #define ECG6_PPGCFG1_PPG_ADC_RGE_8192nA 0x40
219 #define ECG6_PPGCFG1_PPG_ADC_RGE_16384nA 0x80
220 #define ECG6_PPGCFG1_PPG_ADC_RGE_32768nA 0xC0
221 
222 #define ECG6_PPGCFG1_PPG_SR_10n1 0x00
223 #define ECG6_PPGCFG1_PPG_SR_20n1 0x04
224 #define ECG6_PPGCFG1_PPG_SR_50n1 0x08
225 #define ECG6_PPGCFG1_PPG_SR_84n1 0x0C
226 #define ECG6_PPGCFG1_PPG_SR_100n1 0x10
227 #define ECG6_PPGCFG1_PPG_SR_200 0x14
228 #define ECG6_PPGCFG1_PPG_SR_400 0x18
229 #define ECG6_PPGCFG1_PPG_SR_800 0x1C
230 #define ECG6_PPGCFG1_PPG_SR_1000 0x20
231 #define ECG6_PPGCFG1_PPG_SR_1600 0x24
232 #define ECG6_PPGCFG1_PPG_SR_3200 0x28
233 #define ECG6_PPGCFG1_PPG_SR_10n2 0x2C
234 #define ECG6_PPGCFG1_PPG_SR_20n2 0x30
235 #define ECG6_PPGCFG1_PPG_SR_50n2 0x34
236 #define ECG6_PPGCFG1_PPG_SR_84n2 0x38
237 #define ECG6_PPGCFG1_PPG_SR_100n2 0x3C
238 
239 #define ECG6_PPGCFG1_PPG_PW_50us 0x00
240 #define ECG6_PPGCFG1_PPG_PW_100us 0x01
241 #define ECG6_PPGCFG1_PPG_PW_200us 0x02
242 #define ECG6_PPGCFG1_PPG_PW_400us 0x03
243 
249 #define ECG6_PPGCFG2_SMP_AVE_1 0x00
250 #define ECG6_PPGCFG2_SMP_AVE_2 0x01
251 #define ECG6_PPGCFG2_SMP_AVE_4 0x02
252 #define ECG6_PPGCFG2_SMP_AVE_8 0x03
253 #define ECG6_PPGCFG2_SMP_AVE_16 0x04
254 #define ECG6_PPGCFG2_SMP_AVE_32 0x05
255 
261 #define ECG6_LRANG_LED2_SMP_AVE_50 0x00
262 #define ECG6_LRANG_LED2_SMP_AVE_100 0x04
263 #define ECG6_LRANG_LED1_SMP_AVE_50 0x00
264 #define ECG6_LRANG_LED1_SMP_AVE_100 0x01
265 
271 #define ECG6_CFG1_ADC_OSR_1600 0x00
272 #define ECG6_CFG1_ADC_OSR_800 0x01
273 #define ECG6_CFG1_ADC_OSR_400 0x02
274 #define ECG6_CFG1_ADC_OSR_200 0x03
275 #define ECG6_CFG1_ADC_OSR_3200 0x04
276 
282 #define ECG6_CFG3_PGA_GAIN_1 0x00
283 #define ECG6_CFG3_PGA_GAIN_2 0x04
284 #define ECG6_CFG3_PGA_GAIN_4 0x08
285 #define ECG6_CFG3_PGA_GAIN_8 0x0C
286 #define ECG6_CFG3_IA_GAIN_5 0x00
287 #define ECG6_CFG3_IA_GAIN_9p5 0x01
288 #define ECG6_CFG3_IA_GAIN_20 0x02
289 #define ECG6_CFG3_IA_GAIN_50 0x03
290 
296 #define ECG6_DEF_PART_ID 0x1E
297 
303 #define ECG6_DEVICE_SLAVE_ADDRESS 0x5E
304 
310 #define ECG6_SENSOR_PPG_LED_1 0x01
311 #define ECG6_SENSOR_PPG_LED_2 0x02
312 #define ECG6_SENSOR_PPG_PILOT_LED_1 0x05
313 #define ECG6_SENSOR_PPG_PILOT_LED_2 0x06
314 #define ECG6_SENSOR_ECG 0x09
315 #define ECG6_SENSOR_NONE 0x00
316  // End group macro
319 // --------------------------------------------------------------- PUBLIC TYPES
324 typedef struct
325 {
326  uint8_t a_full;
327  uint8_t ppg_rdy;
328  uint8_t alc_ovf;
329  uint8_t prox_int;
330  uint8_t pwr_rdy;
331  uint8_t vdd_oor;
332  uint8_t ecg_rdy;
333 
335 
336 typedef struct
337 {
338  uint32_t element_1;
339  uint32_t element_2;
340  uint32_t element_3;
341  uint32_t element_4;
342 
344 
345 typedef struct
346 {
379 
380 }ecg6_fifo_t;
381 
382 typedef struct
383 {
384  uint8_t element_1;
385  uint8_t element_2;
386  uint8_t element_3;
387  uint8_t element_4;
388 
390 
394 typedef struct
395 {
396  // Output pins
397 
398 
399  // Input pins
400 
401  digital_in_t int_pin;
402 
403  // Modules
404 
405  i2c_master_t i2c;
406 
407  // ctx variable
408 
409  uint8_t slave_address;
410 
411 } ecg6_t;
412 
416 typedef struct
417 {
418  // Communication gpio pins
419 
420  pin_name_t scl;
421  pin_name_t sda;
422 
423  // Additional gpio pins
424 
425  pin_name_t int_pin;
426 
427  // static variable
428 
429  uint32_t i2c_speed;
430  uint8_t i2c_address;
431 
432 } ecg6_cfg_t;
433  // End types group
435 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
436 
442 #ifdef __cplusplus
443 extern "C"{
444 #endif
445 
454 void ecg6_cfg_setup ( ecg6_cfg_t *cfg );
455 
464 ECG6_RETVAL ecg6_init ( ecg6_t *ctx, ecg6_cfg_t *cfg );
465 
545 void ecg6_default_cfg ( ecg6_t *ctx );
546 
556 void ecg6_write_data( ecg6_t *ctx, uint8_t reg, uint8_t in_data );
557 
568 void ecg6_write_data_buf( ecg6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
569 
580 uint8_t ecg6_read_data( ecg6_t *ctx, uint8_t reg );
581 
592 void ecg6_read_data_buf( ecg6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
593 
604 uint8_t ecg6_check_path_id ( ecg6_t *ctx );
605 
621 void ecg6_cfg_element( ecg6_t *ctx, ecg6_cfg_element_t *cfg );
622 
634 void ecg6_set_led_pulse( ecg6_t *ctx, uint8_t ir_led, uint8_t red_led );
635 
715 uint8_t ecg6_ppg_default_config ( ecg6_t *ctx );
716 
727 void ecg6_get_sample_data( ecg6_t *ctx, ecg6_element_t *element, uint8_t num_sample );
728 
738 void ecg6_get_all_samples( ecg6_t *ctx, ecg6_fifo_t *fifo_data );
739 
749 void ecg6_get_interrupt_status ( ecg6_t *ctx, ecg6_int_status_t *status );
750 
759 uint8_t ecg6_int_pin_state ( ecg6_t *ctx );
760 
761 
762 #ifdef __cplusplus
763 }
764 #endif
765 #endif // _ECG6_H_
766  // End public_function group
769 
770 // ------------------------------------------------------------------------- END
ecg6_int_status_t::ppg_rdy
uint8_t ppg_rdy
Definition: ecg6.h:327
ecg6_fifo_t
Definition: ecg6.h:345
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:324
ecg6_fifo_t::sample_9
ecg6_element_t sample_9
Definition: ecg6.h:356
ecg6_int_status_t::pwr_rdy
uint8_t pwr_rdy
Definition: ecg6.h:330
ecg6_element_t::element_3
uint32_t element_3
Definition: ecg6.h:340
ecg6_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ecg6.h:429
ecg6_fifo_t::sample_14
ecg6_element_t sample_14
Definition: ecg6.h:361
ecg6_fifo_t::sample_28
ecg6_element_t sample_28
Definition: ecg6.h:375
ecg6_fifo_t::sample_31
ecg6_element_t sample_31
Definition: ecg6.h:378
ecg6_fifo_t::sample_13
ecg6_element_t sample_13
Definition: ecg6.h:360
ecg6_fifo_t::sample_4
ecg6_element_t sample_4
Definition: ecg6.h:351
ecg6_cfg_t::int_pin
pin_name_t int_pin
Definition: ecg6.h:425
ecg6_fifo_t::sample_27
ecg6_element_t sample_27
Definition: ecg6.h:374
ecg6_fifo_t::sample_29
ecg6_element_t sample_29
Definition: ecg6.h:376
ecg6_cfg_element_t
Definition: ecg6.h:382
ecg6_fifo_t::sample_12
ecg6_element_t sample_12
Definition: ecg6.h:359
ecg6_fifo_t::sample_10
ecg6_element_t sample_10
Definition: ecg6.h:357
ecg6_fifo_t::sample_8
ecg6_element_t sample_8
Definition: ecg6.h:355
ecg6_cfg_element_t::element_3
uint8_t element_3
Definition: ecg6.h:386
ecg6_t::int_pin
digital_in_t int_pin
Definition: ecg6.h:401
ecg6_fifo_t::sample_18
ecg6_element_t sample_18
Definition: ecg6.h:365
ecg6_element_t::element_1
uint32_t element_1
Definition: ecg6.h:338
ecg6_fifo_t::sample_20
ecg6_element_t sample_20
Definition: ecg6.h:367
ecg6_fifo_t::sample_25
ecg6_element_t sample_25
Definition: ecg6.h:372
ecg6_fifo_t::sample_7
ecg6_element_t sample_7
Definition: ecg6.h:354
ecg6_cfg_t::scl
pin_name_t scl
Definition: ecg6.h:420
ecg6_t::slave_address
uint8_t slave_address
Definition: ecg6.h:409
ecg6_t::i2c
i2c_master_t i2c
Definition: ecg6.h:405
ecg6_int_status_t::ecg_rdy
uint8_t ecg_rdy
Definition: ecg6.h:332
ecg6_cfg_t::sda
pin_name_t sda
Definition: ecg6.h:421
ecg6_t
Click ctx object definition.
Definition: ecg6.h:394
ecg6_int_status_t::vdd_oor
uint8_t vdd_oor
Definition: ecg6.h:331
ecg6_fifo_t::sample_26
ecg6_element_t sample_26
Definition: ecg6.h:373
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:358
ecg6_cfg_t
Click configuration structure definition.
Definition: ecg6.h:416
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:362
ecg6_fifo_t::sample_17
ecg6_element_t sample_17
Definition: ecg6.h:364
ecg6_check_path_id
uint8_t ecg6_check_path_id(ecg6_t *ctx)
Function for check path ID.
ecg6_element_t
Definition: ecg6.h:336
ecg6_fifo_t::sample_19
ecg6_element_t sample_19
Definition: ecg6.h:366
ecg6_fifo_t::sample_6
ecg6_element_t sample_6
Definition: ecg6.h:353
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:369
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:62
ecg6_fifo_t::sample_23
ecg6_element_t sample_23
Definition: ecg6.h:370
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:368
ecg6_element_t::element_2
uint32_t element_2
Definition: ecg6.h:339
ecg6_cfg_t::i2c_address
uint8_t i2c_address
Definition: ecg6.h:430
ecg6_fifo_t::sample_16
ecg6_element_t sample_16
Definition: ecg6.h:363
ecg6_element_t::element_4
uint32_t element_4
Definition: ecg6.h:341
ecg6_fifo_t::sample_2
ecg6_element_t sample_2
Definition: ecg6.h:349
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:350
ecg6_cfg_element_t::element_2
uint8_t element_2
Definition: ecg6.h:385
ecg6_int_status_t::prox_int
uint8_t prox_int
Definition: ecg6.h:329
ecg6_fifo_t::sample_0
ecg6_element_t sample_0
Definition: ecg6.h:347
ecg6_fifo_t::sample_30
ecg6_element_t sample_30
Definition: ecg6.h:377
ecg6_cfg_element_t::element_4
uint8_t element_4
Definition: ecg6.h:387
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:371
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:348
ecg6_int_status_t::a_full
uint8_t a_full
Definition: ecg6.h:326
ecg6_cfg_element_t::element_1
uint8_t element_1
Definition: ecg6.h:384
ecg6_int_status_t::alc_ovf
uint8_t alc_ovf
Definition: ecg6.h:328
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:352