ecggsr  2.0.0.0
ecggsr.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2021 MikroElektronika d.o.o.
4 ** Contact: https://www.mikroe.com/contact
5 **
6 ** This file is part of the mikroSDK package
7 **
8 ** Commercial License Usage
9 **
10 ** Licensees holding valid commercial NECTO compilers AI licenses may use this
11 ** file in accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The mikroElektronika Company.
14 ** For licensing terms and conditions see
15 ** https://www.mikroe.com/legal/software-license-agreement.
16 ** For further information use the contact form at
17 ** https://www.mikroe.com/contact.
18 **
19 **
20 ** GNU Lesser General Public License Usage
21 **
22 ** Alternatively, this file may be used for
23 ** non-commercial projects under the terms of the GNU Lesser
24 ** General Public License version 3 as published by the Free Software
25 ** Foundation: https://www.gnu.org/licenses/lgpl-3.0.html.
26 **
27 ** The above copyright notice and this permission notice shall be
28 ** included in all copies or substantial portions of the Software.
29 **
30 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31 ** OF MERCHANTABILITY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
32 ** TO THE WARRANTIES FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
33 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
34 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
35 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
36 ** OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 **
38 ****************************************************************************/
44 // ----------------------------------------------------------------------------
45 
46 #ifndef _ECGGSR_H_
47 #define _ECGGSR_H_
48 
49 #ifdef __cplusplus
50 extern "C"{
51 #endif
52 
57 #ifdef PREINIT_SUPPORTED
58 #include "preinit.h"
59 #endif
60 
61 #ifdef MikroCCoreVersion
62  #if MikroCCoreVersion >= 1
63  #include "delays.h"
64  #endif
65 #endif
66 
67 #include "drv_digital_out.h"
68 #include "drv_digital_in.h"
69 #include "drv_i2c_master.h"
70 
71 // -------------------------------------------------------------- PUBLIC MACROS
72 
93 #define ECGGSR_SLAVE_ADDRESS 0x30
94  // ecggsr_cfg
95 
106 #define ECGGSR_MAP_MIKROBUS( cfg, mikrobus ) \
107  cfg.scl_pin = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
108  cfg.sda_pin = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
109  cfg.enable_pin = MIKROBUS( mikrobus, MIKROBUS_CS );
110 
111  // ecggsr_map
113  // ecggsr
115 
116 
121 #define ECGGSR_RETVAL uint8_t
122 
128 #define ECGGSR_GPIO_SYNC_REG 0x0F
129 #define ECGGSR_LED_CFG_REG 0x10
130 #define ECGGSR_LED_WAIT_LOW_REG 0x11
131 #define ECGGSR_LED1_CURRL_REG 0x12
132 #define ECGGSR_LED1_CURRH_REG 0x13
133 #define ECGGSR_LED2_CURRL_REG 0x14
134 #define ECGGSR_LED2_CURRH_REG 0x15
135 #define ECGGSR_LED3_CURRL_REG 0x16
136 #define ECGGSR_LED3_CURRH_REG 0x17
137 #define ECGGSR_LED4_CURRL_REG 0x18
138 #define ECGGSR_LED4_CURRH_REG 0x19
139 #define ECGGSR_LED12_MODE_REG 0x2C
140 #define ECGGSR_LED34_MODE_REG 0x2D
141 #define ECGGSR_MAN_SEQ_CFG_REG 0x2E
142 #define ECGGSR_PD_CFG_REG 0x1A
143 #define ECGGSR_PDOFFX_LEDOFF_REG 0x1B
144 #define ECGGSR_PDOFFX_LEDON_REG 0x1C
145 #define ECGGSR_PD_AMPRCCFG_REG 0x1D
146 #define ECGGSR_PD_AMPCFG_REG 0x1E
147 #define ECGGSR_OFE1_PD_THCFG_REG 0x1F
148 #define ECGGSR_SEQ_CNT_REG 0x30
149 #define ECGGSR_SEQ_DIV_REG 0x31
150 #define ECGGSR_SEQ_START_REG 0x32
151 #define ECGGSR_SEQ_PER_REG 0x33
152 #define ECGGSR_SEQ_LED_ST_REG 0x34
153 #define ECGGSR_SEQ_LED_STO_REG 0x35
154 #define ECGGSR_SEQ_SECLED_STA_REG 0x36
155 #define ECGGSR_SEQ_SECLED_STO_REG 0x37
156 #define ECGGSR_SEQ_ITG_STA_REG 0x38
157 #define ECGGSR_SEQ_ITG_STO_REG 0x39
158 #define ECGGSR_SEQ_SDP1_STA_REG 0x3A
159 #define ECGGSR_SEQ_SDP1_STO_REG 0x3B
160 #define ECGGSR_SEQ_SDP2_STA_REG 0x3C
161 #define ECGGSR_SEQ_SDP2_STO_REG 0x3D
162 #define ECGGSR_SEQ_SDM1_STA_REG 0x3E
163 #define ECGGSR_SEQ_SDM1_STO_REG 0x3F
164 #define ECGGSR_SEQ_SDM2_STA_REG 0x40
165 #define ECGGSR_SEQ_SDM2_STO_REG 0x41
166 #define ECGGSR_SEQ_ADC_REG 0x42
167 #define ECGGSR_SEQ_ADC2TIA_REG 0x43
168 #define ECGGSR_SEQ_ADC3TIA_REG 0x44
169 #define ECGGSR_SD_SUBS_REG 0x45
170 #define ECGGSR_SEQ_CFG_REG 0x46
171 #define ECGGSR_SEQ_ERR_REG 0x47
172 #define ECGGSR_SEQ_OVS_SEL_REG 0x48
173 #define ECGGSR_SEQ_OVS_VAL_REG 0x49
174 #define ECGGSR_SEQ_DIS_SEL_REG 0x4A
175 #define ECGGSR_SEQ_DIS_VAL1_REG 0x4B
176 #define ECGGSR_SEQ_DIS_VAL2_REG 0x4C
177 #define ECGGSR_CYC_COUNTER_REG 0x60
178 #define ECGGSR_SEQ_COUNTER_REG 0x61
179 #define ECGGSR_SUBS_COUNTER_REG 0x62
180 #define ECGGSR_OFE_CFGA_REG 0x50
181 #define ECGGSR_OFE1_SD_THCFG_REG 0x51
182 #define ECGGSR_OFE_CFGC_REG 0x52
183 #define ECGGSR_OFE_CFGD_REG 0x53
184 #define ECGGSR_OFE1_CFGA_REG 0x54
185 #define ECGGSR_OFE1_CFGB_REG 0x55
186 #define ECGGSR_OFE2_PD_THCFG_REG 0x56
187 #define ECGGSR_OFE2_SD_THCFG_REG 0x57
188 #define ECGGSR_OFE2_CFGA_REG 0x58
189 #define ECGGSR_OFE2_CFGB_REG 0x59
190 #define ECGGSR_LTFDATA0_L_REG 0x20
191 #define ECGGSR_LTFDATA0_H_REG 0x21
192 #define ECGGSR_LTFDATA1_L_REG 0x22
193 #define ECGGSR_LTFDATA1_H_REG 0x23
194 #define ECGGSR_ITIME_REG 0x24
195 #define ECGGSR_LTF_CONFIG_REG 0x25
196 #define ECGGSR_LTF_SEL_REG 0x26
197 #define ECGGSR_LTF_GAIN_REG 0x27
198 #define ECGGSR_LTF_CONTROL_REG 0x28
199 #define ECGGSR_AZ_CONTROL_REG 0x29
200 #define ECGGSR_OFFSET0_REG 0x2A
201 #define ECGGSR_OFFSET1_REG 0x2B
202 #define ECGGSR_LTF_THRESHOLD_LOW0_REG 0x6C
203 #define ECGGSR_LTF_THRESHOLD_LOW1_REG 0x6D
204 #define ECGGSR_LTF_THRESHOLD_HIGH0_REG 0x6E
205 #define ECGGSR_LTF_THRESHOLD_HIGH1_REG 0x6F
206 #define ECGGSR_EAF_CFG_REG 0x70
207 #define ECGGSR_EAF_GST_REG 0x80
208 #define ECGGSR_EAF_BIAS_REG 0x81
209 #define ECGGSR_EAF_DAC_REG 0x82
210 #define ECGGSR_EAF_DAC1_L_REG 0x83
211 #define ECGGSR_EAF_DAC1_H_REG 0x84
212 #define ECGGSR_EAF_DAC2_L_REG 0x85
213 #define ECGGSR_EAF_DAC2_H_REG 0x86
214 #define ECGGSR_EAF_DAC_CFG_REG 0x87
215 #define ECGGSR_OFE_NOTCH_REG 0x5A
216 #define ECGGSR_ECG_MODE_REG 0x5B
217 #define ECGGSR_ECG_CFGA_REG 0x5C
218 #define ECGGSR_ECG_CFGB_REG 0x5D
219 #define ECGGSR_ECG_THRESHOLD_LOW_REG 0x6A
220 #define ECGGSR_ECG_THRESHOLD_HIGH_REG 0x6B
221 #define ECGGSR_ECG_CFGC_REG 0x5E
222 #define ECGGSR_ECG_CFGD_REG 0x5F
223 #define ECGGSR_ADC_THRESHOLD_REG 0x68
224 #define ECGGSR_ADC_THRESHOLD_CFG_REG 0x69
225 #define ECGGSR_ADC_CFGA_REG 0x88
226 #define ECGGSR_ADC_CFGB_REG 0x89
227 #define ECGGSR_ADC_CFGC_REG 0x8A
228 #define ECGGSR_ADC_CHANNEL_MASK_L_REG 0x8B
229 #define ECGGSR_ADC_CHANNEL_MASK_H_REG 0x8C
230 #define ECGGSR_ADC_DATA_L_REG 0x8E
231 #define ECGGSR_ADC_DATA_H_REG 0x8F
232 #define ECGGSR_FIFO_CFG_REG 0x78
233 #define ECGGSR_FIFO_CNTRL_REG 0x79
234 #define ECGGSR_FIFOL_REG 0xFE
235 #define ECGGSR_FIFOH_REG 0xFF
236 #define ECGGSR_CONTROL_REG 0x00
237 #define ECGGSR_GPIO_A_REG 0x08
238 #define ECGGSR_GPIO_E_REG 0x09
239 #define ECGGSR_GPIO_O_REG 0x0A
240 #define ECGGSR_GPIO_I_REG 0x0B
241 #define ECGGSR_GPIO_P_REG 0x0C
242 #define ECGGSR_GPIO_SR_REG 0x0D
243 #define ECGGSR_SUBID_REG 0x91
244 #define ECGGSR_ID_REG 0x92
245 #define ECGGSR_STATUS_REG 0xA0
246 #define ECGGSR_STATUS2_REG 0xA1
247 #define ECGGSR_CLIPSTATUS_REG 0xA2
248 #define ECGGSR_LEDSTATUS_REG 0xA3
249 #define ECGGSR_FIFOSTATUS_REG 0xA4
250 #define ECGGSR_LTFSTATUS_REG 0xA5
251 #define ECGGSR_FIFOLEVEL_REG 0xA6
252 #define ECGGSR_INTENAB_REG 0xA8
253 #define ECGGSR_INTENAB2_REG 0xA9
254 #define ECGGSR_INTR_REG 0xAA
255 #define ECGGSR_INTR2_REG 0xAB
256 
257 #define ECGGSR_DEV_ID_MASK 0xFC
258 #define ECGGSR_DEV_ID 0x54
259 
260 
261 // 35mA current flows through LEDs.
262 #define ECGGSR_LED_CURR_LOW_2 0x80
263 #define ECGGSR_LED_CURR_HIGH_2 0x59
264 
265 
266 // 100mA current flows through LEDs.
267 #define ECGGSR_LED_CURR_LOW_3 0xC0
268 #define ECGGSR_LED_CURR_HIGH_3 0xFF
269 
270 // PPG related definitions.
271 #define ECGGSR_ENABLE_OSC_AND_LDO 0x03
272 #define ECGGSR_READ_VALUE_CONTROL_REG 0x83
273 #define ECGGSR_ENABLE_REF_AND_DIODES 0x8B
274 #define ECGGSR_ENABLE_LED12_OUTPUT 0x99
275 #define ECGGSR_ENABLE_LED4_OUTPUT 0x90
276 #define ECGGSR_CONF_PHOTODIODE 0x3E
277 #define ECGGSR_SUNLIGHT_COMPENSATION 0x5E
278 #define ECGGSR_FEEDBACK_RESISTOR 0xE2
279 #define ECGGSR_ENABLE_PHOTOAMPLIFIER 0xBC
280 #define ECGGSR_START_PPG 0xE1
281 #define ECGGSR_ENABLE_ADC 0x01
282 #define ECGGSR_START_ADC_CONVERSION 0x01
283 #define ECGGSR_ENABLE_OFE_AND_BIAS 0xE6
284 #define ECGGSR_OFE1_CFGA 0x70
285 #define ECGGSR_OFE2_CFGA 0x70
286 #define ECGGSR_ADC_DATA_H_MASK 0x3F
287 #define ECGGSR_PPG_SCALE_VAL 0x64
288 #define ECGGSR_PD_LED_CURRENT 0x80
289 #define ECGGSR_PPG_L_THRESHOLD 0x48
290 #define ECGGSR_PPG_H_THRESHOLD 0x5F
291 #define ECGGSR_PPG_MAX_VAL 0x64
292 
293 // ECG related definitions.
294 #define ECGGSR_ENABLE_SIG_REFERENCE 0x80
295 #define ECGGSR_ENABLE_BIAS_AND_GAIN 0x09
296 #define ECGGSR_INPUT_AND_REF_VOLTAGE 0xB0
297 #define ECGGSR_RESISTIVE_BIASING 0xA0
298 #define ECGGSR_GAIN_SETTINGS_STAGES1_2 0x0B
299 #define ECGGSR_ENABLE_ECG_AMPLIFIER 0x88
300 #define ECGGSR_GAIN_SETTINGS_STAGE3 0x04
301 #define ECGGSR_ENABLE_REF_AMPLIFIER 0x01
302 #define ECGGSR_START_SEQUENCER 0xE1
303 #define ECGGSR_SELECT_EFE 0x40
304 #define ECGGSR_SELECT_AMPLIFIER_INPUT 0x01
305 #define ECGGSR_ECG_SCALE_VAL 0x02
306 
307 // GSR related definitions.
308 #define ECGGSR_ENABLE_GPIO1_ANALOG 0x02
309 #define ECGGSR_SET_SLEW_RATE_GPIO1 0x02
310 #define ECGGSR_SET_GPIO1_AS_INPUT 0x46
311 #define ECGGSR_SET_RES_BIAS_GPIO1 0x40
312 
313  // generic_registers
315  // ecggsr
317 
318 // --------------------------------------------------------------- PUBLIC TYPES
319 
329 typedef enum
330 {
334 
337 
342 typedef struct
343 {
345  i2c_master_t i2c;
346 
348  uint8_t slave_address;
349 
351  pin_name_t enable_pin;
352 
353 } ecggsr_t;
354 
360 typedef struct
361 {
363  pin_name_t scl_pin;
364  pin_name_t sda_pin;
365  pin_name_t enable_pin;
366 
368  uint32_t i2c_speed;
369  uint8_t i2c_address;
370 
373 
374 } ecggsr_cfg_t;
375 
380 typedef enum
381 {
385  // End types group
387 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
388 
401 
409 err_t ecggsr_init( ecggsr_t *ctx, ecggsr_cfg_t* cfg );
410 
418 
427 err_t ecggsr_write_reg( ecggsr_t *ctx, uint8_t register_address, uint8_t transfer_data );
428 
438 err_t ecggsr_read_reg( ecggsr_t *ctx, uint8_t register_address, uint8_t *data_out, uint8_t num_of_regs );
439 
446 void ecggsr_read_dev_id( ecggsr_t *ctx, uint8_t *dev_id_out );
447 
453 void ecggsr_reset( ecggsr_t *ctx );
454  // End public_function group
456 
457 #ifdef __cplusplus
458 }
459 #endif
460 
461 #endif // _ECGGSR_H_
462 // ------------------------------------------------------------------------- END
ecggsr_reset
void ecggsr_reset(ecggsr_t *ctx)
ECG GSR Reset function.
ecggsr_default_cfg
void ecggsr_default_cfg(ecggsr_t *ctx, ecggsr_cfg_t *cfg)
Click Default Configuration function.
ecggsr_cfg_t::i2c_address
uint8_t i2c_address
Definition: ecggsr.h:369
ecggsr_t::i2c
i2c_master_t i2c
Definition: ecggsr.h:345
ENABLE_OXIMETER_FUNCTIONALITY
@ ENABLE_OXIMETER_FUNCTIONALITY
Definition: ecggsr.h:331
ENABLE_HEARTRATE_FUNCTIONALITY
@ ENABLE_HEARTRATE_FUNCTIONALITY
Definition: ecggsr.h:332
ecggsr_t
Context structure.
Definition: ecggsr.h:343
ecggsr_cfg_t::scl_pin
pin_name_t scl_pin
Definition: ecggsr.h:363
ecggsr_init_error
@ ecggsr_init_error
Definition: ecggsr.h:383
ecggsr_cfg_t::click_functionality
ecggsr_functionality_t click_functionality
Definition: ecggsr.h:372
ENABLE_GALVANIC_SKIN_RESPONSE_FUNCTIONALITY
@ ENABLE_GALVANIC_SKIN_RESPONSE_FUNCTIONALITY
Definition: ecggsr.h:333
DEFAULT_ECGGSR_CLICK_FUNCTIONALITY
@ DEFAULT_ECGGSR_CLICK_FUNCTIONALITY
Definition: ecggsr.h:335
ecggsr_functionality_t
ecggsr_functionality_t
ECG GSR type of measurement selector.
Definition: ecggsr.h:330
ecggsr_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ecggsr.h:368
ecggsr_cfg_t
Configuration structure.
Definition: ecggsr.h:361
ecggsr_t::enable_pin
pin_name_t enable_pin
Definition: ecggsr.h:351
ecggsr_write_reg
err_t ecggsr_write_reg(ecggsr_t *ctx, uint8_t register_address, uint8_t transfer_data)
Generic Write function.
ecggsr_cfg_setup
void ecggsr_cfg_setup(ecggsr_cfg_t *cfg)
ECG GSR configuration object setup function.
ecggsr_init
err_t ecggsr_init(ecggsr_t *ctx, ecggsr_cfg_t *cfg)
Initialization function.
ecggsr_err_t
ecggsr_err_t
Error Code.
Definition: ecggsr.h:381
ecggsr_cfg_t::enable_pin
pin_name_t enable_pin
Definition: ecggsr.h:365
ecggsr_read_reg
err_t ecggsr_read_reg(ecggsr_t *ctx, uint8_t register_address, uint8_t *data_out, uint8_t num_of_regs)
Generic Read function.
ecggsr_ok
@ ecggsr_ok
Definition: ecggsr.h:382
ecggsr_read_dev_id
void ecggsr_read_dev_id(ecggsr_t *ctx, uint8_t *dev_id_out)
ECG GSR Read ID function.
ecggsr_t::slave_address
uint8_t slave_address
Definition: ecggsr.h:348
ecggsr_cfg_t::sda_pin
pin_name_t sda_pin
Definition: ecggsr.h:364