oximeter2  2.0.0.0
oximeter2.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2020 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 _OXIMETER2_H_
47 #define _OXIMETER2_H_
48 
49 #ifdef __cplusplus
50 extern "C"{
51 #endif
52 
53 #include "mikrosdk_version.h"
54 
55 #ifdef __GNUC__
56 #if mikroSDK_GET_VERSION < 20800ul
57 #include "rcu_delays.h"
58 #else
59 #include "delays.h"
60 #endif
61 #endif
62 
63 #include "drv_digital_out.h"
64 #include "drv_digital_in.h"
65 #include "drv_i2c_master.h"
66 
67 // -------------------------------------------------------------- PUBLIC MACROS
68 
89 #define OXIMETER2_SLAVE_ADDRESS 0x64
90  // oximeter2_cfg
92 
103 #define OXIMETER2_MAP_MIKROBUS( cfg, mikrobus ) \
104  cfg.scl_pin = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
105  cfg.sda_pin = MIKROBUS( mikrobus, MIKROBUS_SDA );
106  // oximeter2_map
108  // oximeter2
110 
111 
116 #define OXIMETER2_RETVAL uint8_t
117 
118 #define OXIMETER2_OK 0x00
119 #define OXIMETER2_INIT_ERROR 0xFF
120 
126 #define OXIMETER2_STATUS_REG 0x00
127 #define OXIMETER2_INT_MASK_REG 0x01
128 #define OXIMETER2_INT_IO_CTL_REG 0x02
129 #define OXIMETER2_FIFO_THRESH_REG 0x06
130 #define OXIMETER2_DEVID_REG 0x08
131 #define OXIMETER2_CLK_RATIO_REG 0x0A
132 #define OXIMETER2_MODE_REG 0x10
133 #define OXIMETER2_SLOT_EN_REG 0x11
134 #define OXIMETER2_FSAMPLE_REG 0x12
135 #define OXIMETER2_PD_LED_SELECT_REG 0x14
136 #define OXIMETER2_NUM_AVG_REG 0x15
137 #define OXIMETER2_SLOTA_CH1_OFFSET_REG 0x18
138 #define OXIMETER2_SLOTA_CH2_OFFSET_REG 0x19
139 #define OXIMETER2_SLOTA_CH3_OFFSET_REG 0x1A
140 #define OXIMETER2_SLOTA_CH4_OFFSET_REG 0x1B
141 #define OXIMETER2_SLOTB_CH1_OFFSET_REG 0x1E
142 #define OXIMETER2_SLOTB_CH2_OFFSET_REG 0x1F
143 #define OXIMETER2_SLOTB_CH3_OFFSET_REG 0x20
144 #define OXIMETER2_SLOTB_CH4_OFFSET_REG 0x21
145 #define OXIMETER2_ILED1_COARSE_REG 0x23
146 #define OXIMETER2_ILED2_COARSE_REG 0x24
147 #define OXIMETER2_ILED_FINE_REG 0x25
148 #define OXIMETER2_SLOTA_LEDMODE_REG 0x30
149 #define OXIMETER2_SLOTA_NUMPULSES_REG 0x31
150 #define OXIMETER2_LED_DISABLE_REG 0x34
151 #define OXIMETER2_SLOTB_LEDMODE_REG 0x35
152 #define OXIMETER2_SLOTB_NUMPULSES_REG 0x36
153 #define OXIMETER2_EXT_SYNC_STARTUP_REG 0x38
154 #define OXIMETER2_SLOTA_AFEMODE_REG 0x39
155 #define OXIMETER2_SLOTB_AFEMODE_REG 0x3B
156 #define OXIMETER2_SLOTA_GAIN_REG 0x42
157 #define OXIMETER2_SLOTA_AFE_CON_REG 0x43
158 #define OXIMETER2_SLOTB_GAIN_REG 0x44
159 #define OXIMETER2_SLOTB_AFE_CON_REG 0x45
160 #define OXIMETER2_SAMPLE_CLK_REG 0x4B
161 #define OXIMETER2_CLK32M_ADJUST_REG 0x4D
162 #define OXIMETER2_ADC_TIMING_REG 0x4E
163 #define OXIMETER2_EXT_SYNC_SEL_REG 0x4F
164 #define OXIMETER2_CLK32M_CAL_EN_REG 0x50
165 #define OXIMETER2_TIA_INDEP_GAIN_REG 0x55
166 #define OXIMETER2_DATA_ACCESS_CTL_REG 0x5F
167 #define OXIMETER2_FIFO_ACCESS 0x60
168 #define OXIMETER2_SLOTA_PD1_16BIT_REG 0x64
169 #define OXIMETER2_SLOTA_PD2_16BIT_REG 0x65
170 #define OXIMETER2_SLOTA_PD3_16BIT_REG 0x66
171 #define OXIMETER2_SLOTA_PD4_16BIT_REG 0x67
172 #define OXIMETER2_SLOTB_PD1_16BIT_REG 0x68
173 #define OXIMETER2_SLOTB_PD2_16BIT_REG 0x69
174 #define OXIMETER2_SLOTB_PD3_16BIT_REG 0x6A
175 #define OXIMETER2_SLOTB_PD4_16BIT_REG 0x6B
176 #define OXIMETER2_A_PD1_LOW_REG 0x70
177 #define OXIMETER2_A_PD2_LOW_REG 0x71
178 #define OXIMETER2_A_PD3_LOW_REG 0x72
179 #define OXIMETER2_A_PD4_LOW_REG 0x73
180 #define OXIMETER2_A_PD1_HIGH_REG 0x74
181 #define OXIMETER2_A_PD2_HIGH_REG 0x75
182 #define OXIMETER2_A_PD3_HIGH_REG 0x76
183 #define OXIMETER2_A_PD4_HIGH_REG 0x77
184 #define OXIMETER2_B_PD1_LOW_REG 0x78
185 #define OXIMETER2_B_PD2_LOW_REG 0x79
186 #define OXIMETER2_B_PD3_LOW_REG 0x7A
187 #define OXIMETER2_B_PD4_LOW_REG 0x7B
188 #define OXIMETER2_B_PD1_HIGH_REG 0x7C
189 #define OXIMETER2_B_PD2_HIGH_REG 0x7D
190 #define OXIMETER2_B_PD3_HIGH_REG 0x7E
191 #define OXIMETER2_B_PD4_HIGH_REG 0x7F
192 
197 #define OXIMETER2_DIS_SLOT 0x00
198 #define OXIMETER2_EN_SLOT 0x01
199 
206 #define OXIMETER2_MODE_STANDBY 0x0000
207 #define OXIMETER2_MODE_PROGRAM 0x0001
208 #define OXIMETER2_MODE_SAMPLE 0x0002
209 
215 #define OXIMETER2_SAMPLE_CLK_CLK32K_EN 0x0080
216 
222 #define OXIMETER2_DATA_ACCESS_CTL_SLOTA_DATA_HOLD 0x0002
223 #define OXIMETER2_DATA_ACCESS_CTL_SLOTB_DATA_HOLD 0x0004
224 
230 #define SLOTA_LED_SEL_LEDX1 0x0001
231 #define SLOTA_LED_SEL_LEDX2 0x0002
232 
233 #define SLOTB_LED_SEL_LEDX1 0x0004
234 #define SLOTB_LED_SEL_LEDX2 0x0008
235 
241 #define OXIMETER2_ALL_CHANNELS_SELECTED 0x00
242 #define OXIMETER2_CH3_CH4_SELECTED 0x01
243 
249 #define OXIMETER2_LEDX1_EN 0x00
250 #define OXIMETER2_LEDX2_EN 0x01
251 #define OXIMETER2_DIS_LED 0x02
252 
259 #define SLOTA_PD_SEL_CH3_CH4 0x0010
260 #define SLOTA_PD_SEL_ALL_CH 0x0040
261 #define SLOTB_PD_SEL_CH3_CH4 0x1000
262 #define SLOTB_PD_SEL_ALL_CH 0x0400
263 
270 #define OXIMETER2_SLOT_A_EN 0x0001
271 #define OXIMETER2_SLOT_B_EN 0x0020
272 
278 #define OXIMETER2_AVERAGE_RES_MODE 0x00
279 #define OXIMETER2_SUM_RES_MODE 0x01
280 
282 #define OXIMETER2_16_BIT_DATA_MASK 0x0000FFFF
283 #define OXIMETER2_CLEAR_INTERRUPTS 0x00FF
284 #define OXIMETER2_PREVENT_UPDATE_OF_DATA_REGS 0x0006
285 #define OXIMETER2_ALLOW_UPDATE_OF_DATA_REGS 0x0000
286  // End group Generic registers
288  // End group macro
290 // --------------------------------------------------------------- PUBLIC TYPES
300 typedef struct
301 {
302  // Oximeter 2 Click employs I2C protocol.
303  i2c_master_t i2c;
304 
305  // I2C protocol requires slave address.
306  uint8_t slave_address;
307 
308  // Optical sensor on this Click has channels.
310 
311  // Optical sensor on this Click has Time Slots.
312  uint8_t enabled_slot_a;
313  uint8_t enabled_slot_b;
314 
315 } oximeter2_t;
316 
317 
322 typedef struct
323 {
325  pin_name_t scl_pin;
326  pin_name_t sda_pin;
327 
329  uint32_t i2c_speed;
330  uint8_t i2c_address;
334 
336 
341 typedef struct
342 {
343  uint8_t enable_slot;
345 } enable_t;
346 
347  // End types group
349 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
350 
363 
371 
378 
387 uint8_t oximeter2_write_reg( oximeter2_t *ctx, uint8_t register_address, uint16_t transfer_data );
388 
398 uint8_t oximeter2_read_reg( oximeter2_t *cfg, uint8_t register_address, uint16_t *data_out, uint8_t num_of_regs );
399 
407 uint8_t oximeter2_set_time_slot_a ( oximeter2_t* ctx, enable_t* dev_enable );
408 
416 uint8_t oximeter2_set_time_slot_b ( oximeter2_t* ctx, enable_t* dev_enable );
417 
418 
425 void oximeter2_read_data( oximeter2_t* ctx, uint32_t *channel_results );
426 
433 
441 uint8_t oximeter2_set_mode( oximeter2_t *ctx, uint8_t desired_mode );
442 
443 #ifdef __cplusplus
444 }
445 #endif
446 #endif // _OXIMETER2_H_
447  // End public_function group
449 // ------------------------------------------------------------------------- END
oximeter2_read_reg
uint8_t oximeter2_read_reg(oximeter2_t *cfg, uint8_t register_address, uint16_t *data_out, uint8_t num_of_regs)
Generic Read function.
oximeter2_cfg_t::scl_pin
pin_name_t scl_pin
Definition: oximeter2.h:325
oximeter2_reset
void oximeter2_reset(oximeter2_t *ctx)
Oximeter 2 Reset function.
oximeter2_cfg_t::dev_enabled_slot_b
uint8_t dev_enabled_slot_b
Definition: oximeter2.h:333
enable_t
Oximeter 2 hardware selector.
Definition: oximeter2.h:342
oximeter2_t
Oximeter 2 Click context object.
Definition: oximeter2.h:301
oximeter2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: oximeter2.h:329
oximeter2_set_time_slot_b
uint8_t oximeter2_set_time_slot_b(oximeter2_t *ctx, enable_t *dev_enable)
Time Slot B Set function.
oximeter2_cfg_t::i2c_address
uint8_t i2c_address
Definition: oximeter2.h:330
enable_t::enable_photodiode
uint8_t enable_photodiode
Definition: oximeter2.h:344
oximeter2_set_mode
uint8_t oximeter2_set_mode(oximeter2_t *ctx, uint8_t desired_mode)
Oximeter 2 Mode Set function.
oximeter2_t::enabled_channel
uint8_t enabled_channel
Definition: oximeter2.h:309
oximeter2_cfg_t
Oximeter 2 Click configuration object.
Definition: oximeter2.h:323
oximeter2_t::slave_address
uint8_t slave_address
Definition: oximeter2.h:306
oximeter2_cfg_t::dev_enabled_slot_a
uint8_t dev_enabled_slot_a
Definition: oximeter2.h:332
oximeter2_write_reg
uint8_t oximeter2_write_reg(oximeter2_t *ctx, uint8_t register_address, uint16_t transfer_data)
Generic Write function.
oximeter2_cfg_t::sda_pin
pin_name_t sda_pin
Definition: oximeter2.h:326
oximeter2_t::i2c
i2c_master_t i2c
Definition: oximeter2.h:303
oximeter2_t::enabled_slot_b
uint8_t enabled_slot_b
Definition: oximeter2.h:313
oximeter2_set_time_slot_a
uint8_t oximeter2_set_time_slot_a(oximeter2_t *ctx, enable_t *dev_enable)
Time Slot A Set function.
oximeter2_init
OXIMETER2_RETVAL oximeter2_init(oximeter2_t *ctx, oximeter2_cfg_t *cfg)
Initialization function.
oximeter2_default_cfg
void oximeter2_default_cfg(oximeter2_t *ctx)
Click Default Configuration function.
OXIMETER2_RETVAL
#define OXIMETER2_RETVAL
Definition: oximeter2.h:116
enable_t::enable_slot
uint8_t enable_slot
Definition: oximeter2.h:343
oximeter2_cfg_t::dev_enabled_channel
uint8_t dev_enabled_channel
Definition: oximeter2.h:331
oximeter2_cfg_setup
void oximeter2_cfg_setup(oximeter2_cfg_t *cfg)
Oximeter 2 configuration object setup function.
oximeter2_t::enabled_slot_a
uint8_t enabled_slot_a
Definition: oximeter2.h:312
oximeter2_read_data
void oximeter2_read_data(oximeter2_t *ctx, uint32_t *channel_results)
Oximeter 2 Data Read function.