oximeter  2.0.0.0
oximeter.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 OXIMETER_H
36 #define OXIMETER_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
63 #define OXIMETER_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
65  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
66  cfg.io0 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
67  cfg.io1 = MIKROBUS( mikrobus, MIKROBUS_INT )
68 
74 #define OXIMETER_OK 0
75 #define OXIMETER_ERROR -1
76 
82 #define OXIMETER_REG_STATUS 0x00
83 #define OXIMETER_REG_INT_MASK 0x01
84 #define OXIMETER_REG_GPIO_DRV 0x02
85 #define OXIMETER_REG_FIFO_THRESH 0x06
86 #define OXIMETER_REG_DEVID 0x08
87 #define OXIMETER_REG_I2CS_ID 0x09
88 #define OXIMETER_REG_CLK_RATIO 0x0A
89 #define OXIMETER_REG_GPIO_CTRL 0x0B
90 #define OXIMETER_REG_SLAVE_ADDRESS_KEY 0x0D
91 #define OXIMETER_REG_SW_RESET 0x0F
92 #define OXIMETER_REG_MODE 0x10
93 #define OXIMETER_REG_SLOT_EN 0x11
94 #define OXIMETER_REG_FSAMPLE 0x12
95 #define OXIMETER_REG_PD_LED_SELECT 0x14
96 #define OXIMETER_REG_NUM_AVG 0x15
97 #define OXIMETER_REG_SLOTA_CH1_OFFSET 0x18
98 #define OXIMETER_REG_SLOTA_CH2_OFFSET 0x19
99 #define OXIMETER_REG_SLOTA_CH3_OFFSET 0x1A
100 #define OXIMETER_REG_SLOTA_CH4_OFFSET 0x1B
101 #define OXIMETER_REG_SLOTB_CH1_OFFSET 0x1E
102 #define OXIMETER_REG_SLOTB_CH2_OFFSET 0x1F
103 #define OXIMETER_REG_SLOTB_CH3_OFFSET 0x20
104 #define OXIMETER_REG_SLOTB_CH4_OFFSET 0x21
105 #define OXIMETER_REG_ILED3_COARSE 0x22
106 #define OXIMETER_REG_ILED1_COARSE 0x23
107 #define OXIMETER_REG_ILED2_COARSE 0x24
108 #define OXIMETER_REG_ILED_FINE 0x25
109 #define OXIMETER_REG_SLOTA_LED_PULSE 0x30
110 #define OXIMETER_REG_SLOTA_NUMPULSES 0x31
111 #define OXIMETER_REG_LED_DISABLE 0x34
112 #define OXIMETER_REG_SLOTB_LED_PULSE 0x35
113 #define OXIMETER_REG_SLOTB_NUMPULSES 0x36
114 #define OXIMETER_REG_ALT_PWR_DN 0x37
115 #define OXIMETER_REG_EXT_SYNC_STARTUP 0x38
116 #define OXIMETER_REG_SLOTA_AFE_WINDOW 0x39
117 #define OXIMETER_REG_SLOTB_AFE_WINDOW 0x3B
118 #define OXIMETER_REG_AFE_PWR_CFG1 0x3C
119 #define OXIMETER_REG_SLOTA_TIA_CFG 0x42
120 #define OXIMETER_REG_SLOTA_AFE_CFG 0x43
121 #define OXIMETER_REG_SLOTB_TIA_CFG 0x44
122 #define OXIMETER_REG_SLOTB_AFE_CFG 0x45
123 #define OXIMETER_REG_SAMPLE_CLK 0x4B
124 #define OXIMETER_REG_CLK32M_ADJUST 0x4D
125 #define OXIMETER_REG_ADC_CLOCK 0x4E
126 #define OXIMETER_REG_EXT_SYNC_SEL 0x4F
127 #define OXIMETER_REG_CLK32M_CAL_EN 0x50
128 #define OXIMETER_REG_AFE_PWR_CFG2 0x54
129 #define OXIMETER_REG_TIA_INDEP_GAIN 0x55
130 #define OXIMETER_REG_DIGITAL_INT_EN 0x58
131 #define OXIMETER_REG_DIG_INT_CFG 0x5A
132 #define OXIMETER_REG_DATA_ACCESS_CTL 0x5F
133 #define OXIMETER_REG_FIFO_ACCESS 0x60
134 #define OXIMETER_REG_SLOTA_PD1_16BIT 0x64
135 #define OXIMETER_REG_SLOTA_PD2_16BIT 0x65
136 #define OXIMETER_REG_SLOTA_PD3_16BIT 0x66
137 #define OXIMETER_REG_SLOTA_PD4_16BIT 0x67
138 #define OXIMETER_REG_SLOTB_PD1_16BIT 0x68
139 #define OXIMETER_REG_SLOTB_PD2_16BIT 0x69
140 #define OXIMETER_REG_SLOTB_PD3_16BIT 0x6A
141 #define OXIMETER_REG_SLOTB_PD4_16BIT 0x6B
142 #define OXIMETER_REG_A_PD1_LOW 0x70
143 #define OXIMETER_REG_A_PD2_LOW 0x71
144 #define OXIMETER_REG_A_PD3_LOW 0x72
145 #define OXIMETER_REG_A_PD4_LOW 0x73
146 #define OXIMETER_REG_A_PD1_HIGH 0x74
147 #define OXIMETER_REG_A_PD2_HIGH 0x75
148 #define OXIMETER_REG_A_PD3_HIGH 0x76
149 #define OXIMETER_REG_A_PD4_HIGH 0x77
150 #define OXIMETER_REG_B_PD1_LOW 0x78
151 #define OXIMETER_REG_B_PD2_LOW 0x79
152 #define OXIMETER_REG_B_PD3_LOW 0x7A
153 #define OXIMETER_REG_B_PD4_LOW 0x7B
154 #define OXIMETER_REG_B_PD1_HIGH 0x7C
155 #define OXIMETER_REG_B_PD2_HIGH 0x7D
156 #define OXIMETER_REG_B_PD3_HIGH 0x7E
157 #define OXIMETER_REG_B_PD4_HIGH 0x7F
158 
164 #define OXIMETER_DIS_SLOT 0x00
165 #define OXIMETER_EN_SLOT 0x01
166 
172 #define OXIMETER_NO_PHOTODIODE_CONN 0x00
173 #define OXIMETER_ALL_PHOTODIODE_CONN 0x01
174 #define OXIMETER_PD5_PD6_PD7_PD8_CONN 0x02
175 #define OXIMETER_PD1_PD2_PD3_PD4_CONN 0x03
176 
182 #define OXIMETER_PDX_TO_AFE 0x00
183 #define OXIMETER_LEDX1_EN 0x01
184 #define OXIMETER_LEDX2_EN 0x02
185 #define OXIMETER_LEDX3_EN 0x03
186 #define OXIMETER_DIS_LED 0x04
187 
193 #define OXIMETER_SLOT_NORM_OP_MODE 0x00
194 #define OXIMETER_SLOT_DIG_INT_OP_MODE 0x01
195 
201 #define OXIMETER_CH1_EN 0x00
202 #define OXIMETER_CH2_EN 0x01
203 #define OXIMETER_CH1_CH2_EN 0x02
204 #define OXIMETER_CH3_CH4_EN 0x03
205 #define OXIMETER_CH2_CH3_CH4_EN 0x04
206 #define OXIMETER_ALL_CHANN_EN 0x05
207 
213 #define OXIMETER_AVERAGE_RES_MODE 0x00
214 #define OXIMETER_SUM_RES_MODE 0x01
215 
221 #define OXIMETER_DEV_STANDBY_OP_MODE 0x0000
222 #define OXIMETER_DEV_PROGRAM_OP_MODE 0x0001
223 #define OXIMETER_DEV_NORMAL_OP_MODE 0x0002
224 
230 #define OXIMETER_DEVICE_ADDRESS 0x64
231  // End group macro
234 // --------------------------------------------------------------- PUBLIC TYPES
243 typedef struct
244 {
245  digital_in_t io0;
246  digital_in_t io1;
247 
248  // Modules
249  i2c_master_t i2c;
250 
251  // ctx variable
252  uint8_t slave_address;
253 
254  uint8_t enabled_chann;
255  uint8_t enabled_slot_a;
256  uint8_t enabled_slot_b;
258 
259 } oximeter_t;
260 
264 typedef struct
265 {
266  // Communication gpio pins
267  pin_name_t scl;
268  pin_name_t sda;
269 
270  // Additional gpio pins
271  pin_name_t io0;
272  pin_name_t io1;
273 
274  // static variable
275  uint32_t i2c_speed;
276  uint8_t i2c_address;
277 
282 
284 
285 typedef struct
286 {
287  uint8_t enable_slot;
289  uint8_t enable_led;
290 
292  // End types group
294 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
295 
301 #ifdef __cplusplus
302 extern "C"{
303 #endif
304 
314 
324 
333 
345 err_t oximeter_write_reg ( oximeter_t* ctx, uint8_t reg, uint16_t data_in );
346 
359 err_t oximeter_read_reg ( oximeter_t* ctx, uint8_t reg, uint16_t* data_out, uint8_t len );
360 
374 err_t oximeter_set_time_slot_a ( oximeter_t* ctx, oximeter_enable_t* dev_enable, uint8_t set_mode );
375 
389 err_t oximeter_set_time_slot_b ( oximeter_t* ctx, oximeter_enable_t* dev_enable, uint8_t set_mode );
390 
401 err_t oximeter_enable_channels ( oximeter_t* ctx, uint8_t select_channel );
402 
412 void oximeter_read_data ( oximeter_t* ctx, uint32_t* chann_results, uint8_t result_mode );
413 
424 
435 
444 
455 err_t oximeter_set_mode ( oximeter_t* ctx, uint16_t select_mode );
456 
457 #ifdef __cplusplus
458 }
459 #endif
460 #endif // _OXIMETER_H_
461  // End public_function group
464 
465 // ------------------------------------------------------------------------- END
oximeter_enable_channels
err_t oximeter_enable_channels(oximeter_t *ctx, uint8_t select_channel)
Channels Enable function.
oximeter_set_time_slot_b
err_t oximeter_set_time_slot_b(oximeter_t *ctx, oximeter_enable_t *dev_enable, uint8_t set_mode)
Time Slot B Set function.
oximeter_cfg_t::io0
pin_name_t io0
Definition: oximeter.h:271
oximeter_t::enabled_slot_b
uint8_t enabled_slot_b
Definition: oximeter.h:256
oximeter_cfg_t::scl
pin_name_t scl
Definition: oximeter.h:267
oximeter_cfg_t::dev_enabled_chann
uint8_t dev_enabled_chann
Definition: oximeter.h:278
oximeter_cfg_t::io1
pin_name_t io1
Definition: oximeter.h:272
oximeter_enable_t::enable_led
uint8_t enable_led
Definition: oximeter.h:289
oximeter_cfg_t::dev_result_mode_check
uint8_t dev_result_mode_check
Definition: oximeter.h:281
oximeter_set_time_slot_a
err_t oximeter_set_time_slot_a(oximeter_t *ctx, oximeter_enable_t *dev_enable, uint8_t set_mode)
Time Slot A Set function.
oximeter_cfg_t::i2c_address
uint8_t i2c_address
Definition: oximeter.h:276
oximeter_default_cfg
void oximeter_default_cfg(oximeter_t *ctx)
Click Default Configuration function.
oximeter_write_reg
err_t oximeter_write_reg(oximeter_t *ctx, uint8_t reg, uint16_t data_in)
Generic Write function.
oximeter_read_data
void oximeter_read_data(oximeter_t *ctx, uint32_t *chann_results, uint8_t result_mode)
Data Read function.
oximeter_cfg_t::dev_enabled_slot_a
uint8_t dev_enabled_slot_a
Definition: oximeter.h:279
oximeter_init
err_t oximeter_init(oximeter_t *ctx, oximeter_cfg_t *cfg)
Initialization function.
oximeter_enable_t::enable_slot
uint8_t enable_slot
Definition: oximeter.h:287
oximeter_t::i2c
i2c_master_t i2c
Definition: oximeter.h:249
oximeter_cfg_setup
void oximeter_cfg_setup(oximeter_cfg_t *cfg)
Config Object Initialization function.
oximeter_t::slave_address
uint8_t slave_address
Definition: oximeter.h:252
oximeter_enable_t::enable_photodiode
uint8_t enable_photodiode
Definition: oximeter.h:288
oximeter_enable_t
Definition: oximeter.h:286
oximeter_t
Click ctx object definition.
Definition: oximeter.h:244
oximeter_t::enabled_slot_a
uint8_t enabled_slot_a
Definition: oximeter.h:255
oximeter_read_reg
err_t oximeter_read_reg(oximeter_t *ctx, uint8_t reg, uint16_t *data_out, uint8_t len)
Generic Read function.
oximeter_get_int_gpio0
uint8_t oximeter_get_int_gpio0(oximeter_t *ctx)
GPIO0 Interrupt Get function.
oximeter_t::result_mode_check
uint8_t result_mode_check
Definition: oximeter.h:257
oximeter_reset
void oximeter_reset(oximeter_t *ctx)
Reset function.
oximeter_t::enabled_chann
uint8_t enabled_chann
Definition: oximeter.h:254
oximeter_t::io0
digital_in_t io0
Definition: oximeter.h:245
oximeter_cfg_t::sda
pin_name_t sda
Definition: oximeter.h:268
oximeter_get_int_gpio1
uint8_t oximeter_get_int_gpio1(oximeter_t *ctx)
GPIO1 Interrupt Get function.
oximeter_cfg_t::dev_enabled_slot_b
uint8_t dev_enabled_slot_b
Definition: oximeter.h:280
oximeter_set_mode
err_t oximeter_set_mode(oximeter_t *ctx, uint16_t select_mode)
Mode Set function.
oximeter_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: oximeter.h:275
oximeter_cfg_t
Click configuration structure definition.
Definition: oximeter.h:265
oximeter_t::io1
digital_in_t io1
Definition: oximeter.h:246