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
50extern "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 OXIMETER2_SLAVE_ADDRESS 0x64
94
95 // oximeter2_cfg
96
107#define OXIMETER2_MAP_MIKROBUS( cfg, mikrobus ) \
108 cfg.scl_pin = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
109 cfg.sda_pin = MIKROBUS( mikrobus, MIKROBUS_SDA );
110
111 // oximeter2_map
112
113 // oximeter2
114
115
120#define OXIMETER2_RETVAL uint8_t
121
122#define OXIMETER2_OK 0x00
123#define OXIMETER2_INIT_ERROR 0xFF
130#define OXIMETER2_STATUS_REG 0x00
131#define OXIMETER2_INT_MASK_REG 0x01
132#define OXIMETER2_INT_IO_CTL_REG 0x02
133#define OXIMETER2_FIFO_THRESH_REG 0x06
134#define OXIMETER2_DEVID_REG 0x08
135#define OXIMETER2_CLK_RATIO_REG 0x0A
136#define OXIMETER2_MODE_REG 0x10
137#define OXIMETER2_SLOT_EN_REG 0x11
138#define OXIMETER2_FSAMPLE_REG 0x12
139#define OXIMETER2_PD_LED_SELECT_REG 0x14
140#define OXIMETER2_NUM_AVG_REG 0x15
141#define OXIMETER2_SLOTA_CH1_OFFSET_REG 0x18
142#define OXIMETER2_SLOTA_CH2_OFFSET_REG 0x19
143#define OXIMETER2_SLOTA_CH3_OFFSET_REG 0x1A
144#define OXIMETER2_SLOTA_CH4_OFFSET_REG 0x1B
145#define OXIMETER2_SLOTB_CH1_OFFSET_REG 0x1E
146#define OXIMETER2_SLOTB_CH2_OFFSET_REG 0x1F
147#define OXIMETER2_SLOTB_CH3_OFFSET_REG 0x20
148#define OXIMETER2_SLOTB_CH4_OFFSET_REG 0x21
149#define OXIMETER2_ILED1_COARSE_REG 0x23
150#define OXIMETER2_ILED2_COARSE_REG 0x24
151#define OXIMETER2_ILED_FINE_REG 0x25
152#define OXIMETER2_SLOTA_LEDMODE_REG 0x30
153#define OXIMETER2_SLOTA_NUMPULSES_REG 0x31
154#define OXIMETER2_LED_DISABLE_REG 0x34
155#define OXIMETER2_SLOTB_LEDMODE_REG 0x35
156#define OXIMETER2_SLOTB_NUMPULSES_REG 0x36
157#define OXIMETER2_EXT_SYNC_STARTUP_REG 0x38
158#define OXIMETER2_SLOTA_AFEMODE_REG 0x39
159#define OXIMETER2_SLOTB_AFEMODE_REG 0x3B
160#define OXIMETER2_SLOTA_GAIN_REG 0x42
161#define OXIMETER2_SLOTA_AFE_CON_REG 0x43
162#define OXIMETER2_SLOTB_GAIN_REG 0x44
163#define OXIMETER2_SLOTB_AFE_CON_REG 0x45
164#define OXIMETER2_SAMPLE_CLK_REG 0x4B
165#define OXIMETER2_CLK32M_ADJUST_REG 0x4D
166#define OXIMETER2_ADC_TIMING_REG 0x4E
167#define OXIMETER2_EXT_SYNC_SEL_REG 0x4F
168#define OXIMETER2_CLK32M_CAL_EN_REG 0x50
169#define OXIMETER2_TIA_INDEP_GAIN_REG 0x55
170#define OXIMETER2_DATA_ACCESS_CTL_REG 0x5F
171#define OXIMETER2_FIFO_ACCESS 0x60
172#define OXIMETER2_SLOTA_PD1_16BIT_REG 0x64
173#define OXIMETER2_SLOTA_PD2_16BIT_REG 0x65
174#define OXIMETER2_SLOTA_PD3_16BIT_REG 0x66
175#define OXIMETER2_SLOTA_PD4_16BIT_REG 0x67
176#define OXIMETER2_SLOTB_PD1_16BIT_REG 0x68
177#define OXIMETER2_SLOTB_PD2_16BIT_REG 0x69
178#define OXIMETER2_SLOTB_PD3_16BIT_REG 0x6A
179#define OXIMETER2_SLOTB_PD4_16BIT_REG 0x6B
180#define OXIMETER2_A_PD1_LOW_REG 0x70
181#define OXIMETER2_A_PD2_LOW_REG 0x71
182#define OXIMETER2_A_PD3_LOW_REG 0x72
183#define OXIMETER2_A_PD4_LOW_REG 0x73
184#define OXIMETER2_A_PD1_HIGH_REG 0x74
185#define OXIMETER2_A_PD2_HIGH_REG 0x75
186#define OXIMETER2_A_PD3_HIGH_REG 0x76
187#define OXIMETER2_A_PD4_HIGH_REG 0x77
188#define OXIMETER2_B_PD1_LOW_REG 0x78
189#define OXIMETER2_B_PD2_LOW_REG 0x79
190#define OXIMETER2_B_PD3_LOW_REG 0x7A
191#define OXIMETER2_B_PD4_LOW_REG 0x7B
192#define OXIMETER2_B_PD1_HIGH_REG 0x7C
193#define OXIMETER2_B_PD2_HIGH_REG 0x7D
194#define OXIMETER2_B_PD3_HIGH_REG 0x7E
195#define OXIMETER2_B_PD4_HIGH_REG 0x7F
196
201#define OXIMETER2_DIS_SLOT 0x00
202#define OXIMETER2_EN_SLOT 0x01
210#define OXIMETER2_MODE_STANDBY 0x0000
211#define OXIMETER2_MODE_PROGRAM 0x0001
212#define OXIMETER2_MODE_SAMPLE 0x0002
219#define OXIMETER2_SAMPLE_CLK_CLK32K_EN 0x0080
226#define OXIMETER2_DATA_ACCESS_CTL_SLOTA_DATA_HOLD 0x0002
227#define OXIMETER2_DATA_ACCESS_CTL_SLOTB_DATA_HOLD 0x0004
234#define SLOTA_LED_SEL_LEDX1 0x0001
235#define SLOTA_LED_SEL_LEDX2 0x0002
236
237#define SLOTB_LED_SEL_LEDX1 0x0004
238#define SLOTB_LED_SEL_LEDX2 0x0008
245#define OXIMETER2_ALL_CHANNELS_SELECTED 0x00
246#define OXIMETER2_CH3_CH4_SELECTED 0x01
253#define OXIMETER2_LEDX1_EN 0x00
254#define OXIMETER2_LEDX2_EN 0x01
255#define OXIMETER2_DIS_LED 0x02
263#define SLOTA_PD_SEL_CH3_CH4 0x0010
264#define SLOTA_PD_SEL_ALL_CH 0x0040
265#define SLOTB_PD_SEL_CH3_CH4 0x1000
266#define SLOTB_PD_SEL_ALL_CH 0x0400
267
274#define OXIMETER2_SLOT_A_EN 0x0001
275#define OXIMETER2_SLOT_B_EN 0x0020
282#define OXIMETER2_AVERAGE_RES_MODE 0x00
283#define OXIMETER2_SUM_RES_MODE 0x01
286#define OXIMETER2_16_BIT_DATA_MASK 0x0000FFFF
287#define OXIMETER2_CLEAR_INTERRUPTS 0x00FF
288#define OXIMETER2_PREVENT_UPDATE_OF_DATA_REGS 0x0006
289#define OXIMETER2_ALLOW_UPDATE_OF_DATA_REGS 0x0000
290
291 // End group Generic registers
292
293 // End group macro
294// --------------------------------------------------------------- PUBLIC TYPES
304typedef struct
305{
306 // Oximeter 2 Click employs I2C protocol.
307 i2c_master_t i2c;
308
309 // I2C protocol requires slave address.
311
312 // Optical sensor on this Click has channels.
314
315 // Optical sensor on this Click has Time Slots.
318
320
321
326typedef struct
327{
329 pin_name_t scl_pin;
330 pin_name_t sda_pin;
331
333 uint32_t i2c_speed;
334 uint8_t i2c_address;
338
340
345typedef struct
346{
347 uint8_t enable_slot;
349} enable_t;
350
351
352 // End types group
353// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
354
367
375
382
391uint8_t oximeter2_write_reg( oximeter2_t *ctx, uint8_t register_address, uint16_t transfer_data );
392
402uint8_t oximeter2_read_reg( oximeter2_t *cfg, uint8_t register_address, uint16_t *data_out, uint8_t num_of_regs );
403
411uint8_t oximeter2_set_time_slot_a ( oximeter2_t* ctx, enable_t* dev_enable );
412
420uint8_t oximeter2_set_time_slot_b ( oximeter2_t* ctx, enable_t* dev_enable );
421
422
429void oximeter2_read_data( oximeter2_t* ctx, uint32_t *channel_results );
430
437
445uint8_t oximeter2_set_mode( oximeter2_t *ctx, uint8_t desired_mode );
446
447#ifdef __cplusplus
448}
449#endif
450#endif // _OXIMETER2_H_
451
452 // End public_function group
453// ------------------------------------------------------------------------- END
#define OXIMETER2_RETVAL
Definition oximeter2.h:120
void oximeter2_reset(oximeter2_t *ctx)
Oximeter 2 Reset function.
uint8_t oximeter2_read_reg(oximeter2_t *cfg, uint8_t register_address, uint16_t *data_out, uint8_t num_of_regs)
Generic Read function.
void oximeter2_read_data(oximeter2_t *ctx, uint32_t *channel_results)
Oximeter 2 Data Read function.
OXIMETER2_RETVAL oximeter2_init(oximeter2_t *ctx, oximeter2_cfg_t *cfg)
Initialization function.
uint8_t oximeter2_set_time_slot_a(oximeter2_t *ctx, enable_t *dev_enable)
Time Slot A Set function.
uint8_t oximeter2_set_time_slot_b(oximeter2_t *ctx, enable_t *dev_enable)
Time Slot B Set function.
void oximeter2_cfg_setup(oximeter2_cfg_t *cfg)
Oximeter 2 configuration object setup function.
uint8_t oximeter2_write_reg(oximeter2_t *ctx, uint8_t register_address, uint16_t transfer_data)
Generic Write function.
void oximeter2_default_cfg(oximeter2_t *ctx)
Click Default Configuration function.
uint8_t oximeter2_set_mode(oximeter2_t *ctx, uint8_t desired_mode)
Oximeter 2 Mode Set function.
Oximeter 2 hardware selector.
Definition oximeter2.h:346
uint8_t enable_photodiode
Definition oximeter2.h:348
uint8_t enable_slot
Definition oximeter2.h:347
Oximeter 2 Click configuration object.
Definition oximeter2.h:327
pin_name_t sda_pin
Definition oximeter2.h:330
uint8_t dev_enabled_slot_b
Definition oximeter2.h:337
uint32_t i2c_speed
Definition oximeter2.h:333
uint8_t dev_enabled_slot_a
Definition oximeter2.h:336
uint8_t dev_enabled_channel
Definition oximeter2.h:335
pin_name_t scl_pin
Definition oximeter2.h:329
uint8_t i2c_address
Definition oximeter2.h:334
Oximeter 2 Click context object.
Definition oximeter2.h:305
uint8_t enabled_slot_b
Definition oximeter2.h:317
uint8_t enabled_slot_a
Definition oximeter2.h:316
i2c_master_t i2c
Definition oximeter2.h:307
uint8_t slave_address
Definition oximeter2.h:310
uint8_t enabled_channel
Definition oximeter2.h:313