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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
53 #define OXIMETER_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56  cfg.io0 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
57  cfg.io1 = MIKROBUS( mikrobus, MIKROBUS_INT )
58 
64 #define OXIMETER_RETVAL uint8_t
65 
66 #define OXIMETER_OK 0x00
67 #define OXIMETER_INIT_ERROR 0xFF
68 
74 #define OXIM_STATUS_REG 0x00
75 #define OXIM_INT_MASK_REG 0x01
76 #define OXIM_GPIO_DRV_REG 0x02
77 #define OXIM_FIFO_THRESH_REG 0x06
78 #define OXIM_DEVID_REG 0x08
79 #define OXIM_I2CS_ID_REG 0x09
80 #define OXIM_CLK_RATIO_REG 0x0A
81 #define OXIM_GPIO_CTRL_REG 0x0B
82 #define OXIM_SLAVE_ADDRESS_KEY_REG 0x0D
83 #define OXIM_SW_RESET_REG 0x0F
84 #define OXIM_MODE_REG 0x10
85 #define OXIM_SLOT_EN_REG 0x11
86 #define OXIM_FSAMPLE_REG 0x12
87 #define OXIM_PD_LED_SELECT_REG 0x14
88 #define OXIM_NUM_AVG_REG 0x15
89 #define OXIM_SLOTA_CH1_OFFSET_REG 0x18
90 #define OXIM_SLOTA_CH2_OFFSET_REG 0x19
91 #define OXIM_SLOTA_CH3_OFFSET_REG 0x1A
92 #define OXIM_SLOTA_CH4_OFFSET_REG 0x1B
93 #define OXIM_SLOTB_CH1_OFFSET_REG 0x1E
94 #define OXIM_SLOTB_CH2_OFFSET_REG 0x1F
95 #define OXIM_SLOTB_CH3_OFFSET_REG 0x20
96 #define OXIM_SLOTB_CH4_OFFSET_REG 0x21
97 #define OXIM_ILED3_COARSE_REG 0x22
98 #define OXIM_ILED1_COARSE_REG 0x23
99 #define OXIM_ILED2_COARSE_REG 0x24
100 #define OXIM_ILED_FINE_REG 0x25
101 #define OXIM_SLOTA_LED_PULSE_REG 0x30
102 #define OXIM_SLOTA_NUMPULSES_REG 0x31
103 #define OXIM_LED_DISABLE_REG 0x34
104 #define OXIM_SLOTB_LED_PULSE_REG 0x35
105 #define OXIM_SLOTB_NUMPULSES_REG 0x36
106 #define OXIM_ALT_PWR_DN_REG 0x37
107 #define OXIM_EXT_SYNC_STARTUP_REG 0x38
108 #define OXIM_SLOTA_AFE_WINDOW_REG 0x39
109 #define OXIM_SLOTB_AFE_WINDOW_REG 0x3B
110 #define OXIM_AFE_PWR_CFG1_REG 0x3C
111 #define OXIM_SLOTA_TIA_CFG_REG 0x42
112 #define OXIM_SLOTA_AFE_CFG_REG 0x43
113 #define OXIM_SLOTB_TIA_CFG_REG 0x44
114 #define OXIM_SLOTB_AFE_CFG_REG 0x45
115 #define OXIM_SAMPLE_CLK_REG 0x4B
116 #define OXIM_CLK32M_ADJUST_REG 0x4D
117 #define OXIM_ADC_CLOCK_REG 0x4E
118 #define OXIM_EXT_SYNC_SEL_REG 0x4F
119 #define OXIM_CLK32M_CAL_EN_REG 0x50
120 #define OXIM_AFE_PWR_CFG2_REG 0x54
121 #define OXIM_TIA_INDEP_GAIN_REG 0x55
122 #define OXIM_DIGITAL_INT_EN_REG 0x58
123 #define OXIM_DIG_INT_CFG_REG 0x5A
124 #define OXIM_DATA_ACCESS_CTL_REG 0x5F
125 #define OXIM_FIFO_ACCESS_REG 0x60
126 #define OXIM_SLOTA_PD1_16BIT_REG 0x64
127 #define OXIM_SLOTA_PD2_16BIT_REG 0x65
128 #define OXIM_SLOTA_PD3_16BIT_REG 0x66
129 #define OXIM_SLOTA_PD4_16BIT_REG 0x67
130 #define OXIM_SLOTB_PD1_16BIT_REG 0x68
131 #define OXIM_SLOTB_PD2_16BIT_REG 0x69
132 #define OXIM_SLOTB_PD3_16BIT_REG 0x6A
133 #define OXIM_SLOTB_PD4_16BIT_REG 0x6B
134 #define OXIM_A_PD1_LOW_REG 0x70
135 #define OXIM_A_PD2_LOW_REG 0x71
136 #define OXIM_A_PD3_LOW_REG 0x72
137 #define OXIM_A_PD4_LOW_REG 0x73
138 #define OXIM_A_PD1_HIGH_REG 0x74
139 #define OXIM_A_PD2_HIGH_REG 0x75
140 #define OXIM_A_PD3_HIGH_REG 0x76
141 #define OXIM_A_PD4_HIGH_REG 0x77
142 #define OXIM_B_PD1_LOW_REG 0x78
143 #define OXIM_B_PD2_LOW_REG 0x79
144 #define OXIM_B_PD3_LOW_REG 0x7A
145 #define OXIM_B_PD4_LOW_REG 0x7B
146 #define OXIM_B_PD1_HIGH_REG 0x7C
147 #define OXIM_B_PD2_HIGH_REG 0x7D
148 #define OXIM_B_PD3_HIGH_REG 0x7E
149 #define OXIM_B_PD4_HIGH_REG 0x7F
150 
156 #define OXIM_DIS_SLOT 0x00
157 #define OXIM_EN_SLOT 0x01
158 
164 #define OXIM_NO_PHOTODIODE_CONN 0x00
165 #define OXIM_ALL_PHOTODIODE_CONN 0x01
166 #define OXIM_PD5_PD6_PD7_PD8_CONN 0x02
167 #define OXIM_PD1_PD2_PD3_PD4_CONN 0x03
168 
174 #define OXIM_PDX_TO_AFE 0x00
175 #define OXIM_LEDX1_EN 0x01
176 #define OXIM_LEDX2_EN 0x02
177 #define OXIM_LEDX3_EN 0x03
178 #define OXIM_DIS_LED 0x04
179 
185 #define OXIM_SLOT_NORM_OP_MODE 0x00
186 #define OXIM_SLOT_DIG_INT_OP_MODE 0x01
187 
193 #define OXIM_CH1_EN 0x00
194 #define OXIM_CH2_EN 0x01
195 #define OXIM_CH1_CH2_EN 0x02
196 #define OXIM_CH3_CH4_EN 0x03
197 #define OXIM_CH2_CH3_CH4_EN 0x04
198 #define OXIM_ALL_CHANN_EN 0x05
199 
205 #define OXIM_AVERAGE_RES_MODE 0x00
206 #define OXIM_SUM_RES_MODE 0x01
207 
213 #define OXIM_DEV_STANDBY_OP_MODE 0x0000
214 #define OXIM_DEV_PROGRAM_OP_MODE 0x0001
215 #define OXIM_DEV_NORMAL_OP_MODE 0x0002
216  // End group macro
219 // --------------------------------------------------------------- PUBLIC TYPES
228 typedef struct
229 {
230  digital_in_t io0;
231 
232  digital_in_t io1;
233 
234  // Modules
235 
236  i2c_master_t i2c;
237 
238  // ctx variable
239 
240  uint8_t slave_address;
241 
242  uint8_t enabled_chann;
243  uint8_t enabled_slot_a;
244  uint8_t enabled_slot_b;
246 
247 } oximeter_t;
248 
252 typedef struct
253 {
254  // Communication gpio pins
255 
256  pin_name_t scl;
257  pin_name_t sda;
258 
259  // Additional gpio pins
260 
261  pin_name_t io0;
262  pin_name_t io1;
263 
264  // static variable
265 
266  uint32_t i2c_speed;
267  uint8_t i2c_address;
268 
273 
275 
276 typedef struct
277 {
278  uint8_t enable_slot;
280  uint8_t enable_led;
281 } enable_t;
282  // End types group
284 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
285 
291 #ifdef __cplusplus
292 extern "C"{
293 #endif
294 
303 void oximeter_cfg_setup ( oximeter_cfg_t *cfg );
304 
314 
322 void oximeter_default_cfg ( oximeter_t *ctx );
323 
335 uint8_t oxim_write_reg ( oximeter_t* ctx, uint8_t register_address,
336  uint16_t transfer_data );
337 
350 uint8_t oxim_read_reg ( oximeter_t* ctx, uint8_t register_address, uint16_t* data_out,
351  uint8_t n_registers );
352 
366 uint8_t oxim_set_time_slot_a ( oximeter_t* ctx, enable_t* dev_enable,
367  uint8_t set_mode );
368 
382 uint8_t oxim_set_time_slot_b ( oximeter_t* ctx, enable_t* dev_enable, uint8_t set_mode );
383 
394 uint8_t oxim_enable_channels ( oximeter_t* ctx, uint8_t select_channel );
395 
405 void oxim_read_data ( oximeter_t* ctx, uint32_t* chann_results, uint8_t result_mode );
406 
416 uint8_t oxim_get_interr_gpio0 ( oximeter_t* ctx );
417 
427 uint8_t oxim_get_interr_gpio1 ( oximeter_t* ctx );
428 
436 void oxim_reset ( oximeter_t* ctx );
437 
448 uint8_t oxim_set_mode ( oximeter_t* ctx, uint16_t select_mode );
449 
450 #ifdef __cplusplus
451 }
452 #endif
453 #endif // _OXIMETER_H_
454  // End public_function group
457 
458 // ------------------------------------------------------------------------- END
OXIMETER_RETVAL
#define OXIMETER_RETVAL
Definition: oximeter.h:64
oximeter_cfg_t::io0
pin_name_t io0
Definition: oximeter.h:261
oximeter_t::enabled_slot_b
uint8_t enabled_slot_b
Definition: oximeter.h:244
oximeter_cfg_t::scl
pin_name_t scl
Definition: oximeter.h:256
oximeter_cfg_t::dev_enabled_chann
uint8_t dev_enabled_chann
Definition: oximeter.h:269
oxim_reset
void oxim_reset(oximeter_t *ctx)
Reset function.
oximeter_cfg_t::io1
pin_name_t io1
Definition: oximeter.h:262
oximeter_cfg_t::dev_result_mode_check
uint8_t dev_result_mode_check
Definition: oximeter.h:272
oxim_read_data
void oxim_read_data(oximeter_t *ctx, uint32_t *chann_results, uint8_t result_mode)
Data Read function.
oximeter_cfg_t::i2c_address
uint8_t i2c_address
Definition: oximeter.h:267
oxim_get_interr_gpio1
uint8_t oxim_get_interr_gpio1(oximeter_t *ctx)
GPIO1 Interrupt Get function.
oximeter_default_cfg
void oximeter_default_cfg(oximeter_t *ctx)
Click Default Configuration function.
enable_t::enable_led
uint8_t enable_led
Definition: oximeter.h:280
enable_t
Definition: oximeter.h:276
oximeter_cfg_t::dev_enabled_slot_a
uint8_t dev_enabled_slot_a
Definition: oximeter.h:270
enable_t::enable_photodiode
uint8_t enable_photodiode
Definition: oximeter.h:279
oxim_get_interr_gpio0
uint8_t oxim_get_interr_gpio0(oximeter_t *ctx)
GPIO0 Interrupt Get function.
oximeter_t::i2c
i2c_master_t i2c
Definition: oximeter.h:236
oxim_write_reg
uint8_t oxim_write_reg(oximeter_t *ctx, uint8_t register_address, uint16_t transfer_data)
Generic Write function.
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:240
oximeter_t
Click ctx object definition.
Definition: oximeter.h:228
oximeter_t::enabled_slot_a
uint8_t enabled_slot_a
Definition: oximeter.h:243
oximeter_init
OXIMETER_RETVAL oximeter_init(oximeter_t *ctx, oximeter_cfg_t *cfg)
Initialization function.
oxim_read_reg
uint8_t oxim_read_reg(oximeter_t *ctx, uint8_t register_address, uint16_t *data_out, uint8_t n_registers)
Generic Read function.
oximeter_t::result_mode_check
uint8_t result_mode_check
Definition: oximeter.h:245
oximeter_t::enabled_chann
uint8_t enabled_chann
Definition: oximeter.h:242
oxim_set_time_slot_b
uint8_t oxim_set_time_slot_b(oximeter_t *ctx, enable_t *dev_enable, uint8_t set_mode)
Time Slot B Set function.
oxim_enable_channels
uint8_t oxim_enable_channels(oximeter_t *ctx, uint8_t select_channel)
Channels Enable function.
oximeter_t::io0
digital_in_t io0
Definition: oximeter.h:230
oximeter_cfg_t::sda
pin_name_t sda
Definition: oximeter.h:257
oxim_set_mode
uint8_t oxim_set_mode(oximeter_t *ctx, uint16_t select_mode)
Mode Set function.
oxim_set_time_slot_a
uint8_t oxim_set_time_slot_a(oximeter_t *ctx, enable_t *dev_enable, uint8_t set_mode)
Time Slot A Set function.
oximeter_cfg_t::dev_enabled_slot_b
uint8_t dev_enabled_slot_b
Definition: oximeter.h:271
oximeter_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: oximeter.h:266
enable_t::enable_slot
uint8_t enable_slot
Definition: oximeter.h:278
oximeter_cfg_t
Click configuration structure definition.
Definition: oximeter.h:252
oximeter_t::io1
digital_in_t io1
Definition: oximeter.h:232