ecg7  2.0.0.0
ecg7.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef ECG7_H
29 #define ECG7_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_analog_in.h"
52 #include "drv_i2c_master.h"
53 
74 #define ECG7_ADC_RESOLUTION 0x0FFF
75 #define ECG7_VREF_3V3 3.3
76 #define ECG7_VREF_5V 5.0
77 
83 #define ECG7_SET_DEV_ADDR 0x4D
84  // ecg7_set
86 
101 #define ECG7_MAP_MIKROBUS( cfg, mikrobus ) \
102  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
103  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
104  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
105  // ecg7_map // ecg7
108 
113 typedef enum
114 {
119 
124 typedef struct
125 {
126  analog_in_t adc;
127  i2c_master_t i2c;
129  uint8_t slave_address;
130  pin_name_t chip_select;
131  float vref;
134 } ecg7_t;
135 
140 typedef struct
141 {
142  pin_name_t an;
143  pin_name_t scl;
144  pin_name_t sda;
146  analog_in_resolution_t resolution;
147  float vref;
149  uint32_t i2c_speed;
150  uint8_t i2c_address;
154 } ecg7_cfg_t;
155 
160 typedef enum
161 {
162  ECG7_OK = 0,
163  ECG7_ERROR = -1
164 
166 
183 
199 
213 err_t ecg7_init ( ecg7_t *ctx, ecg7_cfg_t *cfg );
214 
226 err_t ecg7_read_raw_adc ( ecg7_t *ctx, uint16_t *raw_adc );
227 
239 err_t ecg7_read_voltage ( ecg7_t *ctx, float *voltage );
240 
252 err_t ecg7_set_vref ( ecg7_t *ctx, float vref );
253 
254 #ifdef __cplusplus
255 }
256 #endif
257 #endif // ECG7_H
258  // ecg7
260 
261 // ------------------------------------------------------------------------ END
ecg7_cfg_setup
void ecg7_cfg_setup(ecg7_cfg_t *cfg)
ECG 7 configuration object setup function.
ecg7_t::i2c
i2c_master_t i2c
Definition: ecg7.h:127
ecg7_cfg_t::i2c_address
uint8_t i2c_address
Definition: ecg7.h:150
ecg7_t
ECG 7 Click context object.
Definition: ecg7.h:125
ecg7_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ecg7.h:149
ecg7_cfg_t::resolution
analog_in_resolution_t resolution
Definition: ecg7.h:146
ECG7_ERROR
@ ECG7_ERROR
Definition: ecg7.h:163
ecg7_t::slave_address
uint8_t slave_address
Definition: ecg7.h:129
ecg7_t::chip_select
pin_name_t chip_select
Definition: ecg7.h:130
ecg7_cfg_t::scl
pin_name_t scl
Definition: ecg7.h:143
ecg7_drv_t
ecg7_drv_t
ECG 7 Click driver selector.
Definition: ecg7.h:114
ecg7_read_raw_adc
err_t ecg7_read_raw_adc(ecg7_t *ctx, uint16_t *raw_adc)
ECG 7 read raw ADC value function.
ecg7_t::drv_sel
ecg7_drv_t drv_sel
Definition: ecg7.h:132
ecg7_cfg_t
ECG 7 Click configuration object.
Definition: ecg7.h:141
ECG7_DRV_SEL_ADC
@ ECG7_DRV_SEL_ADC
Definition: ecg7.h:115
ECG7_OK
@ ECG7_OK
Definition: ecg7.h:162
ecg7_cfg_t::an
pin_name_t an
Definition: ecg7.h:142
ecg7_drv_interface_selection
void ecg7_drv_interface_selection(ecg7_cfg_t *cfg, ecg7_drv_t drv_sel)
ECG 7 driver interface setup function.
ecg7_cfg_t::vref
float vref
Definition: ecg7.h:147
ecg7_set_vref
err_t ecg7_set_vref(ecg7_t *ctx, float vref)
ECG 7 set vref function.
ecg7_read_voltage
err_t ecg7_read_voltage(ecg7_t *ctx, float *voltage)
ECG 7 read voltage level function.
ecg7_init
err_t ecg7_init(ecg7_t *ctx, ecg7_cfg_t *cfg)
ECG 7 initialization function.
ecg7_cfg_t::sda
pin_name_t sda
Definition: ecg7.h:144
ecg7_cfg_t::drv_sel
ecg7_drv_t drv_sel
Definition: ecg7.h:152
ecg7_return_value_t
ecg7_return_value_t
ECG 7 Click return value data.
Definition: ecg7.h:161
ecg7_t::adc
analog_in_t adc
Definition: ecg7.h:126
ECG7_DRV_SEL_I2C
@ ECG7_DRV_SEL_I2C
Definition: ecg7.h:116
ecg7_t::vref
float vref
Definition: ecg7.h:131