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 
54 #include "drv_digital_out.h"
55 #include "drv_digital_in.h"
56 #include "drv_i2c_master.h"
57 
58 // -------------------------------------------------------------- PUBLIC MACROS
59 
80 #define OXIMETER2_SLAVE_ADDRESS 0x64
81  // oximeter2_cfg
83 
94 #define OXIMETER2_MAP_MIKROBUS( cfg, mikrobus ) \
95  cfg.scl_pin = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
96  cfg.sda_pin = MIKROBUS( mikrobus, MIKROBUS_SDA );
97  // oximeter2_map
99  // oximeter2
101 
102 
107 #define OXIMETER2_RETVAL uint8_t
108 
109 #define OXIMETER2_OK 0x00
110 #define OXIMETER2_INIT_ERROR 0xFF
111 
117 #define OXIMETER2_STATUS_REG 0x00
118 #define OXIMETER2_INT_MASK_REG 0x01
119 #define OXIMETER2_INT_IO_CTL_REG 0x02
120 #define OXIMETER2_FIFO_THRESH_REG 0x06
121 #define OXIMETER2_DEVID_REG 0x08
122 #define OXIMETER2_CLK_RATIO_REG 0x0A
123 #define OXIMETER2_MODE_REG 0x10
124 #define OXIMETER2_SLOT_EN_REG 0x11
125 #define OXIMETER2_FSAMPLE_REG 0x12
126 #define OXIMETER2_PD_LED_SELECT_REG 0x14
127 #define OXIMETER2_NUM_AVG_REG 0x15
128 #define OXIMETER2_SLOTA_CH1_OFFSET_REG 0x18
129 #define OXIMETER2_SLOTA_CH2_OFFSET_REG 0x19
130 #define OXIMETER2_SLOTA_CH3_OFFSET_REG 0x1A
131 #define OXIMETER2_SLOTA_CH4_OFFSET_REG 0x1B
132 #define OXIMETER2_SLOTB_CH1_OFFSET_REG 0x1E
133 #define OXIMETER2_SLOTB_CH2_OFFSET_REG 0x1F
134 #define OXIMETER2_SLOTB_CH3_OFFSET_REG 0x20
135 #define OXIMETER2_SLOTB_CH4_OFFSET_REG 0x21
136 #define OXIMETER2_ILED1_COARSE_REG 0x23
137 #define OXIMETER2_ILED2_COARSE_REG 0x24
138 #define OXIMETER2_ILED_FINE_REG 0x25
139 #define OXIMETER2_SLOTA_LEDMODE_REG 0x30
140 #define OXIMETER2_SLOTA_NUMPULSES_REG 0x31
141 #define OXIMETER2_LED_DISABLE_REG 0x34
142 #define OXIMETER2_SLOTB_LEDMODE_REG 0x35
143 #define OXIMETER2_SLOTB_NUMPULSES_REG 0x36
144 #define OXIMETER2_EXT_SYNC_STARTUP_REG 0x38
145 #define OXIMETER2_SLOTA_AFEMODE_REG 0x39
146 #define OXIMETER2_SLOTB_AFEMODE_REG 0x3B
147 #define OXIMETER2_SLOTA_GAIN_REG 0x42
148 #define OXIMETER2_SLOTA_AFE_CON_REG 0x43
149 #define OXIMETER2_SLOTB_GAIN_REG 0x44
150 #define OXIMETER2_SLOTB_AFE_CON_REG 0x45
151 #define OXIMETER2_SAMPLE_CLK_REG 0x4B
152 #define OXIMETER2_CLK32M_ADJUST_REG 0x4D
153 #define OXIMETER2_ADC_TIMING_REG 0x4E
154 #define OXIMETER2_EXT_SYNC_SEL_REG 0x4F
155 #define OXIMETER2_CLK32M_CAL_EN_REG 0x50
156 #define OXIMETER2_TIA_INDEP_GAIN_REG 0x55
157 #define OXIMETER2_DATA_ACCESS_CTL_REG 0x5F
158 #define OXIMETER2_FIFO_ACCESS 0x60
159 #define OXIMETER2_SLOTA_PD1_16BIT_REG 0x64
160 #define OXIMETER2_SLOTA_PD2_16BIT_REG 0x65
161 #define OXIMETER2_SLOTA_PD3_16BIT_REG 0x66
162 #define OXIMETER2_SLOTA_PD4_16BIT_REG 0x67
163 #define OXIMETER2_SLOTB_PD1_16BIT_REG 0x68
164 #define OXIMETER2_SLOTB_PD2_16BIT_REG 0x69
165 #define OXIMETER2_SLOTB_PD3_16BIT_REG 0x6A
166 #define OXIMETER2_SLOTB_PD4_16BIT_REG 0x6B
167 #define OXIMETER2_A_PD1_LOW_REG 0x70
168 #define OXIMETER2_A_PD2_LOW_REG 0x71
169 #define OXIMETER2_A_PD3_LOW_REG 0x72
170 #define OXIMETER2_A_PD4_LOW_REG 0x73
171 #define OXIMETER2_A_PD1_HIGH_REG 0x74
172 #define OXIMETER2_A_PD2_HIGH_REG 0x75
173 #define OXIMETER2_A_PD3_HIGH_REG 0x76
174 #define OXIMETER2_A_PD4_HIGH_REG 0x77
175 #define OXIMETER2_B_PD1_LOW_REG 0x78
176 #define OXIMETER2_B_PD2_LOW_REG 0x79
177 #define OXIMETER2_B_PD3_LOW_REG 0x7A
178 #define OXIMETER2_B_PD4_LOW_REG 0x7B
179 #define OXIMETER2_B_PD1_HIGH_REG 0x7C
180 #define OXIMETER2_B_PD2_HIGH_REG 0x7D
181 #define OXIMETER2_B_PD3_HIGH_REG 0x7E
182 #define OXIMETER2_B_PD4_HIGH_REG 0x7F
183 
188 #define OXIMETER2_DIS_SLOT 0x00
189 #define OXIMETER2_EN_SLOT 0x01
190 
197 #define OXIMETER2_MODE_STANDBY 0x0000
198 #define OXIMETER2_MODE_PROGRAM 0x0001
199 #define OXIMETER2_MODE_SAMPLE 0x0002
200 
206 #define OXIMETER2_SAMPLE_CLK_CLK32K_EN 0x0080
207 
213 #define OXIMETER2_DATA_ACCESS_CTL_SLOTA_DATA_HOLD 0x0002
214 #define OXIMETER2_DATA_ACCESS_CTL_SLOTB_DATA_HOLD 0x0004
215 
221 #define SLOTA_LED_SEL_LEDX1 0x0001
222 #define SLOTA_LED_SEL_LEDX2 0x0002
223 
224 #define SLOTB_LED_SEL_LEDX1 0x0004
225 #define SLOTB_LED_SEL_LEDX2 0x0008
226 
232 #define OXIMETER2_ALL_CHANNELS_SELECTED 0x00
233 #define OXIMETER2_CH3_CH4_SELECTED 0x01
234 
240 #define OXIMETER2_LEDX1_EN 0x00
241 #define OXIMETER2_LEDX2_EN 0x01
242 #define OXIMETER2_DIS_LED 0x02
243 
250 #define SLOTA_PD_SEL_CH3_CH4 0x0010
251 #define SLOTA_PD_SEL_ALL_CH 0x0040
252 #define SLOTB_PD_SEL_CH3_CH4 0x1000
253 #define SLOTB_PD_SEL_ALL_CH 0x0400
254 
261 #define OXIMETER2_SLOT_A_EN 0x0001
262 #define OXIMETER2_SLOT_B_EN 0x0020
263 
269 #define OXIMETER2_AVERAGE_RES_MODE 0x00
270 #define OXIMETER2_SUM_RES_MODE 0x01
271 
273 #define OXIMETER2_16_BIT_DATA_MASK 0x0000FFFF
274 #define OXIMETER2_CLEAR_INTERRUPTS 0x00FF
275 #define OXIMETER2_PREVENT_UPDATE_OF_DATA_REGS 0x0006
276 #define OXIMETER2_ALLOW_UPDATE_OF_DATA_REGS 0x0000
277  // End group Generic registers
279  // End group macro
281 // --------------------------------------------------------------- PUBLIC TYPES
291 typedef struct
292 {
293  // Oximeter 2 Click employs I2C protocol.
294  i2c_master_t i2c;
295 
296  // I2C protocol requires slave address.
297  uint8_t slave_address;
298 
299  // Optical sensor on this Click has channels.
301 
302  // Optical sensor on this Click has Time Slots.
303  uint8_t enabled_slot_a;
304  uint8_t enabled_slot_b;
305 
306 } oximeter2_t;
307 
308 
313 typedef struct
314 {
316  pin_name_t scl_pin;
317  pin_name_t sda_pin;
318 
320  uint32_t i2c_speed;
321  uint8_t i2c_address;
325 
327 
332 typedef struct
333 {
334  uint8_t enable_slot;
336 } enable_t;
337 
338  // End types group
340 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
341 
354 
362 
369 
378 uint8_t oximeter2_write_reg( oximeter2_t *ctx, uint8_t register_address, uint16_t transfer_data );
379 
389 uint8_t oximeter2_read_reg( oximeter2_t *cfg, uint8_t register_address, uint16_t *data_out, uint8_t num_of_regs );
390 
398 uint8_t oximeter2_set_time_slot_a ( oximeter2_t* ctx, enable_t* dev_enable );
399 
407 uint8_t oximeter2_set_time_slot_b ( oximeter2_t* ctx, enable_t* dev_enable );
408 
409 
416 void oximeter2_read_data( oximeter2_t* ctx, uint32_t *channel_results );
417 
424 
432 uint8_t oximeter2_set_mode( oximeter2_t *ctx, uint8_t desired_mode );
433 
434 #ifdef __cplusplus
435 }
436 #endif
437 #endif // _OXIMETER2_H_
438  // End public_function group
440 // ------------------------------------------------------------------------- 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:316
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:324
enable_t
Oximeter 2 hardware selector.
Definition: oximeter2.h:333
oximeter2_t
Oximeter 2 Click context object.
Definition: oximeter2.h:292
oximeter2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: oximeter2.h:320
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:321
enable_t::enable_photodiode
uint8_t enable_photodiode
Definition: oximeter2.h:335
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:300
oximeter2_cfg_t
Oximeter 2 Click configuration object.
Definition: oximeter2.h:314
oximeter2_t::slave_address
uint8_t slave_address
Definition: oximeter2.h:297
oximeter2_cfg_t::dev_enabled_slot_a
uint8_t dev_enabled_slot_a
Definition: oximeter2.h:323
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:317
oximeter2_t::i2c
i2c_master_t i2c
Definition: oximeter2.h:294
oximeter2_t::enabled_slot_b
uint8_t enabled_slot_b
Definition: oximeter2.h:304
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:107
enable_t::enable_slot
uint8_t enable_slot
Definition: oximeter2.h:334
oximeter2_cfg_t::dev_enabled_channel
uint8_t dev_enabled_channel
Definition: oximeter2.h:322
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:303
oximeter2_read_data
void oximeter2_read_data(oximeter2_t *ctx, uint32_t *channel_results)
Oximeter 2 Data Read function.