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 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_i2c_master.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
67 #define OXIMETER_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
70  cfg.io0 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
71  cfg.io1 = MIKROBUS( mikrobus, MIKROBUS_INT )
72 
78 #define OXIMETER_OK 0
79 #define OXIMETER_ERROR -1
80 
86 #define OXIMETER_REG_STATUS 0x00
87 #define OXIMETER_REG_INT_MASK 0x01
88 #define OXIMETER_REG_GPIO_DRV 0x02
89 #define OXIMETER_REG_FIFO_THRESH 0x06
90 #define OXIMETER_REG_DEVID 0x08
91 #define OXIMETER_REG_I2CS_ID 0x09
92 #define OXIMETER_REG_CLK_RATIO 0x0A
93 #define OXIMETER_REG_GPIO_CTRL 0x0B
94 #define OXIMETER_REG_SLAVE_ADDRESS_KEY 0x0D
95 #define OXIMETER_REG_SW_RESET 0x0F
96 #define OXIMETER_REG_MODE 0x10
97 #define OXIMETER_REG_SLOT_EN 0x11
98 #define OXIMETER_REG_FSAMPLE 0x12
99 #define OXIMETER_REG_PD_LED_SELECT 0x14
100 #define OXIMETER_REG_NUM_AVG 0x15
101 #define OXIMETER_REG_SLOTA_CH1_OFFSET 0x18
102 #define OXIMETER_REG_SLOTA_CH2_OFFSET 0x19
103 #define OXIMETER_REG_SLOTA_CH3_OFFSET 0x1A
104 #define OXIMETER_REG_SLOTA_CH4_OFFSET 0x1B
105 #define OXIMETER_REG_SLOTB_CH1_OFFSET 0x1E
106 #define OXIMETER_REG_SLOTB_CH2_OFFSET 0x1F
107 #define OXIMETER_REG_SLOTB_CH3_OFFSET 0x20
108 #define OXIMETER_REG_SLOTB_CH4_OFFSET 0x21
109 #define OXIMETER_REG_ILED3_COARSE 0x22
110 #define OXIMETER_REG_ILED1_COARSE 0x23
111 #define OXIMETER_REG_ILED2_COARSE 0x24
112 #define OXIMETER_REG_ILED_FINE 0x25
113 #define OXIMETER_REG_SLOTA_LED_PULSE 0x30
114 #define OXIMETER_REG_SLOTA_NUMPULSES 0x31
115 #define OXIMETER_REG_LED_DISABLE 0x34
116 #define OXIMETER_REG_SLOTB_LED_PULSE 0x35
117 #define OXIMETER_REG_SLOTB_NUMPULSES 0x36
118 #define OXIMETER_REG_ALT_PWR_DN 0x37
119 #define OXIMETER_REG_EXT_SYNC_STARTUP 0x38
120 #define OXIMETER_REG_SLOTA_AFE_WINDOW 0x39
121 #define OXIMETER_REG_SLOTB_AFE_WINDOW 0x3B
122 #define OXIMETER_REG_AFE_PWR_CFG1 0x3C
123 #define OXIMETER_REG_SLOTA_TIA_CFG 0x42
124 #define OXIMETER_REG_SLOTA_AFE_CFG 0x43
125 #define OXIMETER_REG_SLOTB_TIA_CFG 0x44
126 #define OXIMETER_REG_SLOTB_AFE_CFG 0x45
127 #define OXIMETER_REG_SAMPLE_CLK 0x4B
128 #define OXIMETER_REG_CLK32M_ADJUST 0x4D
129 #define OXIMETER_REG_ADC_CLOCK 0x4E
130 #define OXIMETER_REG_EXT_SYNC_SEL 0x4F
131 #define OXIMETER_REG_CLK32M_CAL_EN 0x50
132 #define OXIMETER_REG_AFE_PWR_CFG2 0x54
133 #define OXIMETER_REG_TIA_INDEP_GAIN 0x55
134 #define OXIMETER_REG_DIGITAL_INT_EN 0x58
135 #define OXIMETER_REG_DIG_INT_CFG 0x5A
136 #define OXIMETER_REG_DATA_ACCESS_CTL 0x5F
137 #define OXIMETER_REG_FIFO_ACCESS 0x60
138 #define OXIMETER_REG_SLOTA_PD1_16BIT 0x64
139 #define OXIMETER_REG_SLOTA_PD2_16BIT 0x65
140 #define OXIMETER_REG_SLOTA_PD3_16BIT 0x66
141 #define OXIMETER_REG_SLOTA_PD4_16BIT 0x67
142 #define OXIMETER_REG_SLOTB_PD1_16BIT 0x68
143 #define OXIMETER_REG_SLOTB_PD2_16BIT 0x69
144 #define OXIMETER_REG_SLOTB_PD3_16BIT 0x6A
145 #define OXIMETER_REG_SLOTB_PD4_16BIT 0x6B
146 #define OXIMETER_REG_A_PD1_LOW 0x70
147 #define OXIMETER_REG_A_PD2_LOW 0x71
148 #define OXIMETER_REG_A_PD3_LOW 0x72
149 #define OXIMETER_REG_A_PD4_LOW 0x73
150 #define OXIMETER_REG_A_PD1_HIGH 0x74
151 #define OXIMETER_REG_A_PD2_HIGH 0x75
152 #define OXIMETER_REG_A_PD3_HIGH 0x76
153 #define OXIMETER_REG_A_PD4_HIGH 0x77
154 #define OXIMETER_REG_B_PD1_LOW 0x78
155 #define OXIMETER_REG_B_PD2_LOW 0x79
156 #define OXIMETER_REG_B_PD3_LOW 0x7A
157 #define OXIMETER_REG_B_PD4_LOW 0x7B
158 #define OXIMETER_REG_B_PD1_HIGH 0x7C
159 #define OXIMETER_REG_B_PD2_HIGH 0x7D
160 #define OXIMETER_REG_B_PD3_HIGH 0x7E
161 #define OXIMETER_REG_B_PD4_HIGH 0x7F
162 
168 #define OXIMETER_DIS_SLOT 0x00
169 #define OXIMETER_EN_SLOT 0x01
170 
176 #define OXIMETER_NO_PHOTODIODE_CONN 0x00
177 #define OXIMETER_ALL_PHOTODIODE_CONN 0x01
178 #define OXIMETER_PD5_PD6_PD7_PD8_CONN 0x02
179 #define OXIMETER_PD1_PD2_PD3_PD4_CONN 0x03
180 
186 #define OXIMETER_PDX_TO_AFE 0x00
187 #define OXIMETER_LEDX1_EN 0x01
188 #define OXIMETER_LEDX2_EN 0x02
189 #define OXIMETER_LEDX3_EN 0x03
190 #define OXIMETER_DIS_LED 0x04
191 
197 #define OXIMETER_SLOT_NORM_OP_MODE 0x00
198 #define OXIMETER_SLOT_DIG_INT_OP_MODE 0x01
199 
205 #define OXIMETER_CH1_EN 0x00
206 #define OXIMETER_CH2_EN 0x01
207 #define OXIMETER_CH1_CH2_EN 0x02
208 #define OXIMETER_CH3_CH4_EN 0x03
209 #define OXIMETER_CH2_CH3_CH4_EN 0x04
210 #define OXIMETER_ALL_CHANN_EN 0x05
211 
217 #define OXIMETER_AVERAGE_RES_MODE 0x00
218 #define OXIMETER_SUM_RES_MODE 0x01
219 
225 #define OXIMETER_DEV_STANDBY_OP_MODE 0x0000
226 #define OXIMETER_DEV_PROGRAM_OP_MODE 0x0001
227 #define OXIMETER_DEV_NORMAL_OP_MODE 0x0002
228 
234 #define OXIMETER_DEVICE_ADDRESS 0x64
235  // End group macro
238 // --------------------------------------------------------------- PUBLIC TYPES
247 typedef struct
248 {
249  digital_in_t io0;
250  digital_in_t io1;
251 
252  // Modules
253  i2c_master_t i2c;
254 
255  // ctx variable
256  uint8_t slave_address;
257 
258  uint8_t enabled_chann;
259  uint8_t enabled_slot_a;
260  uint8_t enabled_slot_b;
262 
263 } oximeter_t;
264 
268 typedef struct
269 {
270  // Communication gpio pins
271  pin_name_t scl;
272  pin_name_t sda;
273 
274  // Additional gpio pins
275  pin_name_t io0;
276  pin_name_t io1;
277 
278  // static variable
279  uint32_t i2c_speed;
280  uint8_t i2c_address;
281 
286 
288 
289 typedef struct
290 {
291  uint8_t enable_slot;
293  uint8_t enable_led;
294 
296  // End types group
298 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
299 
305 #ifdef __cplusplus
306 extern "C"{
307 #endif
308 
318 
328 
337 
349 err_t oximeter_write_reg ( oximeter_t* ctx, uint8_t reg, uint16_t data_in );
350 
363 err_t oximeter_read_reg ( oximeter_t* ctx, uint8_t reg, uint16_t* data_out, uint8_t len );
364 
378 err_t oximeter_set_time_slot_a ( oximeter_t* ctx, oximeter_enable_t* dev_enable, uint8_t set_mode );
379 
393 err_t oximeter_set_time_slot_b ( oximeter_t* ctx, oximeter_enable_t* dev_enable, uint8_t set_mode );
394 
405 err_t oximeter_enable_channels ( oximeter_t* ctx, uint8_t select_channel );
406 
416 void oximeter_read_data ( oximeter_t* ctx, uint32_t* chann_results, uint8_t result_mode );
417 
428 
439 
448 
459 err_t oximeter_set_mode ( oximeter_t* ctx, uint16_t select_mode );
460 
461 #ifdef __cplusplus
462 }
463 #endif
464 #endif // _OXIMETER_H_
465  // End public_function group
468 
469 // ------------------------------------------------------------------------- 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:275
oximeter_t::enabled_slot_b
uint8_t enabled_slot_b
Definition: oximeter.h:260
oximeter_cfg_t::scl
pin_name_t scl
Definition: oximeter.h:271
oximeter_cfg_t::dev_enabled_chann
uint8_t dev_enabled_chann
Definition: oximeter.h:282
oximeter_cfg_t::io1
pin_name_t io1
Definition: oximeter.h:276
oximeter_enable_t::enable_led
uint8_t enable_led
Definition: oximeter.h:293
oximeter_cfg_t::dev_result_mode_check
uint8_t dev_result_mode_check
Definition: oximeter.h:285
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:280
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:283
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:291
oximeter_t::i2c
i2c_master_t i2c
Definition: oximeter.h:253
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:256
oximeter_enable_t::enable_photodiode
uint8_t enable_photodiode
Definition: oximeter.h:292
oximeter_enable_t
Definition: oximeter.h:290
oximeter_t
Click ctx object definition.
Definition: oximeter.h:248
oximeter_t::enabled_slot_a
uint8_t enabled_slot_a
Definition: oximeter.h:259
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:261
oximeter_reset
void oximeter_reset(oximeter_t *ctx)
Reset function.
oximeter_t::enabled_chann
uint8_t enabled_chann
Definition: oximeter.h:258
oximeter_t::io0
digital_in_t io0
Definition: oximeter.h:249
oximeter_cfg_t::sda
pin_name_t sda
Definition: oximeter.h:272
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:284
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:279
oximeter_cfg_t
Click configuration structure definition.
Definition: oximeter.h:269
oximeter_t::io1
digital_in_t io1
Definition: oximeter.h:250