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 
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 ECG6_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
70 
76 #define ECG6_RETVAL uint8_t
77 
78 #define ECG6_OK 0x00
79 #define ECG6_INIT_ERROR 0xFF
80 
86 #define ECG6_REG_INTERRUPT_STATUS_1 0x00
87 #define ECG6_REG_INTERRUPT_STATUS_2 0x01
88 #define ECG6_REG_INTERRUPT_ENABLE_1 0x02
89 #define ECG6_REG_INTERRUPT_ENABLE_2 0x03
90 
96 #define ECG6_REG_FIFO_WRITE 0x04
97 #define ECG6_REG_OVERFLOW_CNT 0x05
98 #define ECG6_REG_FIFO_READ 0x06
99 #define ECG6_REG_FIFO_DATA 0x07
100 #define ECG6_REG_FIFO_CFG 0x08
101 
107 #define ECG6_REG_FIFO_DATA_CTRL_1 0x09
108 #define ECG6_REG_FIFO_DATA_CTRL_2 0x0A
109 
115 #define ECG6_REG_SYSTEM_CTRL 0x0D
116 
123 #define ECG6_REG_PPG_CFG_1 0x0E
124 #define ECG6_REG_PPG_CFG_2 0x0F
125 #define ECG6_REG_PROX_INT_THR 0x10
126 
132 #define ECG6_REG_LED_PULSE_AMPLITUDE_1 0x11
133 #define ECG6_REG_LED_PULSE_AMPLITUDE_2 0x12
134 #define ECG6_REG_LED_RANGE 0x14
135 #define ECG6_REG_LED_PILOT_PULSE_AMPLITUDE 0x15
136 
142 #define ECG6_REG_CONFIG_1 0x3C
143 #define ECG6_REG_CONFIG_3 0x3E
144 
150 #define ECG6_REG_PART_ID 0xFF
151 
157 #define ECG6_INTS1_A_FULL_ON 0x80
158 #define ECG6_INTS1_A_FULL_OFF 0x00
159 #define ECG6_INTS1_PPG_RDY_ON 0x40
160 #define ECG6_INTS1_PPG_RDY_OFF 0x00
161 #define ECG6_INTS1_ALC_OVF_ON 0x20
162 #define ECG6_INTS1_ALC_OVF_OFF 0x00
163 #define ECG6_INTS1_PROX_INIT_ON 0x10
164 #define ECG6_INTS1_PROX_INIT_OFF 0x00
165 #define ECG6_INTS1_PWR_RDY_ON 0x01
166 #define ECG6_INTS1_PWR_RDY_OFF 0x00
167 
173 #define ECG6_INTS2_VDD_OOR_ON 0x80
174 #define ECG6_INTS2_VDD_OOR_OFF 0x00
175 #define ECG6_INTS2_DRDY_ON 0x04
176 #define ECG6_INTS2_DRDY_OFF 0x00
177 
183 #define ECG6_INTE1_A_FULL_ENABLE 0x80
184 #define ECG6_INTE1_A_FULL_DISABLE 0x00
185 #define ECG6_INTE1_PPG_RDY_ENABLE 0x40
186 #define ECG6_INTE1_PPG_RDY_DISABLE 0x00
187 #define ECG6_INTE1_ALC_OVF_ENABLE 0x20
188 #define ECG6_INTE1_ALC_OVF_DISABLE 0x00
189 #define ECG6_INTE1_PROX_INT_ENABLE 0x10
190 #define ECG6_INTE1_PROX_INT_DISABLE 0x00
191 
197 #define ECG6_INTS2_VDD_OOR_ENABLE 0x80
198 #define ECG6_INTS2_VDD_OOR_DISABLE 0x00
199 #define ECG6_INTS2_DRDY_ENABLE 0x04
200 #define ECG6_INTS2_DRDY_DISABLE 0x00
201 
207 #define ECG6_FCFG_A_FULL_CLR 0x40
208 #define ECG6_FCFG_A_FULL_NO_CLR 0x00
209 #define ECG6_FCFG_A_FULL_TYPE_RPT 0x00
210 #define ECG6_FCFG_A_FULL_TYPE_ONCE 0x20
211 #define ECG6_FCFG_FIFO_ROLLS_ON_FULL_ON 0x10
212 #define ECG6_FCFG_FIFO_ROLLS_ON_FULL_OFF 0x00
213 
219 #define ECG6_SYSCTRL_FIFO_ENABLE 0x04
220 #define ECG6_SYSCTRL_FIFO_DISABLE 0x00
221 #define ECG6_SYSCTRL_SHUTDOWN_ENABLE 0x02
222 #define ECG6_SYSCTRL_SHUTDOWN_DISABLE 0x00
223 #define ECG6_SYSCTRL_RESET_ENABLE 0x01
224 #define ECG6_SYSCTRL_RESET_DISABLE 0x00
225 
231 #define ECG6_PPGCFG1_PPG_ADC_RGE_4096nA 0x00
232 #define ECG6_PPGCFG1_PPG_ADC_RGE_8192nA 0x40
233 #define ECG6_PPGCFG1_PPG_ADC_RGE_16384nA 0x80
234 #define ECG6_PPGCFG1_PPG_ADC_RGE_32768nA 0xC0
235 
236 #define ECG6_PPGCFG1_PPG_SR_10n1 0x00
237 #define ECG6_PPGCFG1_PPG_SR_20n1 0x04
238 #define ECG6_PPGCFG1_PPG_SR_50n1 0x08
239 #define ECG6_PPGCFG1_PPG_SR_84n1 0x0C
240 #define ECG6_PPGCFG1_PPG_SR_100n1 0x10
241 #define ECG6_PPGCFG1_PPG_SR_200 0x14
242 #define ECG6_PPGCFG1_PPG_SR_400 0x18
243 #define ECG6_PPGCFG1_PPG_SR_800 0x1C
244 #define ECG6_PPGCFG1_PPG_SR_1000 0x20
245 #define ECG6_PPGCFG1_PPG_SR_1600 0x24
246 #define ECG6_PPGCFG1_PPG_SR_3200 0x28
247 #define ECG6_PPGCFG1_PPG_SR_10n2 0x2C
248 #define ECG6_PPGCFG1_PPG_SR_20n2 0x30
249 #define ECG6_PPGCFG1_PPG_SR_50n2 0x34
250 #define ECG6_PPGCFG1_PPG_SR_84n2 0x38
251 #define ECG6_PPGCFG1_PPG_SR_100n2 0x3C
252 
253 #define ECG6_PPGCFG1_PPG_PW_50us 0x00
254 #define ECG6_PPGCFG1_PPG_PW_100us 0x01
255 #define ECG6_PPGCFG1_PPG_PW_200us 0x02
256 #define ECG6_PPGCFG1_PPG_PW_400us 0x03
257 
263 #define ECG6_PPGCFG2_SMP_AVE_1 0x00
264 #define ECG6_PPGCFG2_SMP_AVE_2 0x01
265 #define ECG6_PPGCFG2_SMP_AVE_4 0x02
266 #define ECG6_PPGCFG2_SMP_AVE_8 0x03
267 #define ECG6_PPGCFG2_SMP_AVE_16 0x04
268 #define ECG6_PPGCFG2_SMP_AVE_32 0x05
269 
275 #define ECG6_LRANG_LED2_SMP_AVE_50 0x00
276 #define ECG6_LRANG_LED2_SMP_AVE_100 0x04
277 #define ECG6_LRANG_LED1_SMP_AVE_50 0x00
278 #define ECG6_LRANG_LED1_SMP_AVE_100 0x01
279 
285 #define ECG6_CFG1_ADC_OSR_1600 0x00
286 #define ECG6_CFG1_ADC_OSR_800 0x01
287 #define ECG6_CFG1_ADC_OSR_400 0x02
288 #define ECG6_CFG1_ADC_OSR_200 0x03
289 #define ECG6_CFG1_ADC_OSR_3200 0x04
290 
296 #define ECG6_CFG3_PGA_GAIN_1 0x00
297 #define ECG6_CFG3_PGA_GAIN_2 0x04
298 #define ECG6_CFG3_PGA_GAIN_4 0x08
299 #define ECG6_CFG3_PGA_GAIN_8 0x0C
300 #define ECG6_CFG3_IA_GAIN_5 0x00
301 #define ECG6_CFG3_IA_GAIN_9p5 0x01
302 #define ECG6_CFG3_IA_GAIN_20 0x02
303 #define ECG6_CFG3_IA_GAIN_50 0x03
304 
310 #define ECG6_DEF_PART_ID 0x1E
311 
317 #define ECG6_DEVICE_SLAVE_ADDRESS 0x5E
318 
324 #define ECG6_SENSOR_PPG_LED_1 0x01
325 #define ECG6_SENSOR_PPG_LED_2 0x02
326 #define ECG6_SENSOR_PPG_PILOT_LED_1 0x05
327 #define ECG6_SENSOR_PPG_PILOT_LED_2 0x06
328 #define ECG6_SENSOR_ECG 0x09
329 #define ECG6_SENSOR_NONE 0x00
330  // End group macro
333 // --------------------------------------------------------------- PUBLIC TYPES
338 typedef struct
339 {
340  uint8_t a_full;
341  uint8_t ppg_rdy;
342  uint8_t alc_ovf;
343  uint8_t prox_int;
344  uint8_t pwr_rdy;
345  uint8_t vdd_oor;
346  uint8_t ecg_rdy;
347 
349 
350 typedef struct
351 {
352  uint32_t element_1;
353  uint32_t element_2;
354  uint32_t element_3;
355  uint32_t element_4;
356 
358 
359 typedef struct
360 {
393 
394 }ecg6_fifo_t;
395 
396 typedef struct
397 {
398  uint8_t element_1;
399  uint8_t element_2;
400  uint8_t element_3;
401  uint8_t element_4;
402 
404 
408 typedef struct
409 {
410  // Output pins
411 
412 
413  // Input pins
414 
415  digital_in_t int_pin;
416 
417  // Modules
418 
419  i2c_master_t i2c;
420 
421  // ctx variable
422 
423  uint8_t slave_address;
424 
425 } ecg6_t;
426 
430 typedef struct
431 {
432  // Communication gpio pins
433 
434  pin_name_t scl;
435  pin_name_t sda;
436 
437  // Additional gpio pins
438 
439  pin_name_t int_pin;
440 
441  // static variable
442 
443  uint32_t i2c_speed;
444  uint8_t i2c_address;
445 
446 } ecg6_cfg_t;
447  // End types group
449 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
450 
456 #ifdef __cplusplus
457 extern "C"{
458 #endif
459 
469 
479 
559 void ecg6_default_cfg ( ecg6_t *ctx );
560 
570 void ecg6_write_data( ecg6_t *ctx, uint8_t reg, uint8_t in_data );
571 
582 void ecg6_write_data_buf( ecg6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
583 
594 uint8_t ecg6_read_data( ecg6_t *ctx, uint8_t reg );
595 
606 void ecg6_read_data_buf( ecg6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
607 
618 uint8_t ecg6_check_path_id ( ecg6_t *ctx );
619 
635 void ecg6_cfg_element( ecg6_t *ctx, ecg6_cfg_element_t *cfg );
636 
648 void ecg6_set_led_pulse( ecg6_t *ctx, uint8_t ir_led, uint8_t red_led );
649 
730 
741 void ecg6_get_sample_data( ecg6_t *ctx, ecg6_element_t *element, uint8_t num_sample );
742 
752 void ecg6_get_all_samples( ecg6_t *ctx, ecg6_fifo_t *fifo_data );
753 
764 
773 uint8_t ecg6_int_pin_state ( ecg6_t *ctx );
774 
775 
776 #ifdef __cplusplus
777 }
778 #endif
779 #endif // _ECG6_H_
780  // End public_function group
783 
784 // ------------------------------------------------------------------------- END
ecg6_int_status_t::ppg_rdy
uint8_t ppg_rdy
Definition: ecg6.h:341
ecg6_fifo_t
Definition: ecg6.h:360
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:339
ecg6_fifo_t::sample_9
ecg6_element_t sample_9
Definition: ecg6.h:370
ecg6_int_status_t::pwr_rdy
uint8_t pwr_rdy
Definition: ecg6.h:344
ecg6_element_t::element_3
uint32_t element_3
Definition: ecg6.h:354
ecg6_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ecg6.h:443
ecg6_fifo_t::sample_14
ecg6_element_t sample_14
Definition: ecg6.h:375
ecg6_fifo_t::sample_28
ecg6_element_t sample_28
Definition: ecg6.h:389
ecg6_fifo_t::sample_31
ecg6_element_t sample_31
Definition: ecg6.h:392
ecg6_fifo_t::sample_13
ecg6_element_t sample_13
Definition: ecg6.h:374
ecg6_fifo_t::sample_4
ecg6_element_t sample_4
Definition: ecg6.h:365
ecg6_cfg_t::int_pin
pin_name_t int_pin
Definition: ecg6.h:439
ecg6_fifo_t::sample_27
ecg6_element_t sample_27
Definition: ecg6.h:388
ecg6_fifo_t::sample_29
ecg6_element_t sample_29
Definition: ecg6.h:390
ecg6_cfg_element_t
Definition: ecg6.h:397
ecg6_fifo_t::sample_12
ecg6_element_t sample_12
Definition: ecg6.h:373
ecg6_fifo_t::sample_10
ecg6_element_t sample_10
Definition: ecg6.h:371
ecg6_fifo_t::sample_8
ecg6_element_t sample_8
Definition: ecg6.h:369
ecg6_cfg_element_t::element_3
uint8_t element_3
Definition: ecg6.h:400
ecg6_t::int_pin
digital_in_t int_pin
Definition: ecg6.h:415
ecg6_fifo_t::sample_18
ecg6_element_t sample_18
Definition: ecg6.h:379
ecg6_element_t::element_1
uint32_t element_1
Definition: ecg6.h:352
ecg6_fifo_t::sample_20
ecg6_element_t sample_20
Definition: ecg6.h:381
ecg6_fifo_t::sample_25
ecg6_element_t sample_25
Definition: ecg6.h:386
ecg6_fifo_t::sample_7
ecg6_element_t sample_7
Definition: ecg6.h:368
ecg6_cfg_t::scl
pin_name_t scl
Definition: ecg6.h:434
ecg6_t::slave_address
uint8_t slave_address
Definition: ecg6.h:423
ecg6_t::i2c
i2c_master_t i2c
Definition: ecg6.h:419
ecg6_int_status_t::ecg_rdy
uint8_t ecg_rdy
Definition: ecg6.h:346
ecg6_cfg_t::sda
pin_name_t sda
Definition: ecg6.h:435
ecg6_t
Click ctx object definition.
Definition: ecg6.h:409
ecg6_int_status_t::vdd_oor
uint8_t vdd_oor
Definition: ecg6.h:345
ecg6_fifo_t::sample_26
ecg6_element_t sample_26
Definition: ecg6.h:387
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:372
ecg6_cfg_t
Click configuration structure definition.
Definition: ecg6.h:431
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:376
ecg6_fifo_t::sample_17
ecg6_element_t sample_17
Definition: ecg6.h:378
ecg6_check_path_id
uint8_t ecg6_check_path_id(ecg6_t *ctx)
Function for check path ID.
ecg6_element_t
Definition: ecg6.h:351
ecg6_fifo_t::sample_19
ecg6_element_t sample_19
Definition: ecg6.h:380
ecg6_fifo_t::sample_6
ecg6_element_t sample_6
Definition: ecg6.h:367
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:383
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:76
ecg6_fifo_t::sample_23
ecg6_element_t sample_23
Definition: ecg6.h:384
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:382
ecg6_element_t::element_2
uint32_t element_2
Definition: ecg6.h:353
ecg6_cfg_t::i2c_address
uint8_t i2c_address
Definition: ecg6.h:444
ecg6_fifo_t::sample_16
ecg6_element_t sample_16
Definition: ecg6.h:377
ecg6_element_t::element_4
uint32_t element_4
Definition: ecg6.h:355
ecg6_fifo_t::sample_2
ecg6_element_t sample_2
Definition: ecg6.h:363
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:364
ecg6_cfg_element_t::element_2
uint8_t element_2
Definition: ecg6.h:399
ecg6_int_status_t::prox_int
uint8_t prox_int
Definition: ecg6.h:343
ecg6_fifo_t::sample_0
ecg6_element_t sample_0
Definition: ecg6.h:361
ecg6_fifo_t::sample_30
ecg6_element_t sample_30
Definition: ecg6.h:391
ecg6_cfg_element_t::element_4
uint8_t element_4
Definition: ecg6.h:401
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:385
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:362
ecg6_int_status_t::a_full
uint8_t a_full
Definition: ecg6.h:340
ecg6_cfg_element_t::element_1
uint8_t element_1
Definition: ecg6.h:398
ecg6_int_status_t::alc_ovf
uint8_t alc_ovf
Definition: ecg6.h:342
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:366