oximeter3  2.0.0.0
oximeter3.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 OXIMETER3_H
36 #define OXIMETER3_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define OXIMETER3_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
66 
72 #define OXIMETER3_RETVAL uint8_t
73 
74 #define OXIMETER3_OK 0x00
75 #define OXIMETER3_INIT_ERROR 0xFF
76 #define OXIMETER3_ERROR 0xFF
77 
83 #define OXIMETER3_SLAVE_ADDRESS 0x13
84 
89 #define OXIMETER3_REG_COMMAND 0x80
90 #define OXIMETER3_REG_PRODUCT_ID 0x81
91 #define OXIMETER3_REG_PROX_RATE 0x82
92 #define OXIMETER3_REG_LED_CURRENT 0x83
93 #define OXIMETER3_REG_ALS_PARAMETER 0x84
94 #define OXIMETER3_REG_ALS_RESULT_MSB 0x85
95 #define OXIMETER3_REG_ALS_RESULT_LSB 0x86
96 #define OXIMETER3_REG_PROX_RESULT_MSB 0x87
97 #define OXIMETER3_REG_PROX_RESULT_LSB 0x88
98 #define OXIMETER3_REG_INTERRUPT_CTRL 0x89
99 #define OXIMETER3_REG_LOW_THRESHOLD_MSB 0x8A
100 #define OXIMETER3_REG_LOW_THRESHOLD_LSB 0x8B
101 #define OXIMETER3_REG_HIGH_THRESHOLD_MSB 0x8C
102 #define OXIMETER3_REG_HIGH_THRESHOLD_LSB 0x8D
103 #define OXIMETER3_REG_INTERRUPT_STATUS 0x8E
104 #define OXIMETER3_REG_PROX_MODULATOR_TIMING 0x8F
105 
111 #define OXIMETER3_CMD_ALS_SINGLE_MEASUREMENT_ENABLE 0x10
112 #define OXIMETER3_CMD_ALS_SINGLE_MEASUREMENT_DISABLE 0x00
113 #define OXIMETER3_CMD_PROX_SINGLE_MEASUREMENT_ENABLE 0x08
114 #define OXIMETER3_CMD_PROX_SINGLE_MEASUREMENT_DISABLE 0x00
115 #define OXIMETER3_CMD_ALS_PERIODIC_MEASUREMENT_ENABLE 0x04
116 #define OXIMETER3_CMD_ALS_PERIODIC_MEASUREMENT_DISABLE 0x00
117 #define OXIMETER3_CMD_PROX_PERIODIC_MEASUREMENT_ENABLE 0x02
118 #define OXIMETER3_CMD_PROX_PERIODIC_MEASUREMENT_DISABLE 0x00
119 #define OXIMETER3_CMD_MEASUREMENT_ENABLE 0x01
120 #define OXIMETER3_CMD_MEASUREMENT_DISABLE 0x00
121 
122 #define OXIMETER3_CMD_ALS_DATA_READY 0x40
123 #define OXIMETER3_CMD_PROX_DATA_READY 0x20
124 
130 #define OXIMETER3_PROX_RATE_1p95_MPS 0x00
131 #define OXIMETER3_PROX_RATE_3p90625_MPS 0x01
132 #define OXIMETER3_PROX_RATE_7p8125_MPS 0x02
133 #define OXIMETER3_PROX_RATE_16p625_MPS 0x03
134 #define OXIMETER3_PROX_RATE_31p25_MPS 0x04
135 #define OXIMETER3_PROX_RATE_62p5_MPS 0x05
136 #define OXIMETER3_PROX_RATE_125_MPS 0x06
137 #define OXIMETER3_PROX_RATE_250_MPS 0x07
138 
144 #define OXIMETER3_LED_CURR_MIN 1
145 #define OXIMETER3_LED_CURR_MID 12
146 #define OXIMETER3_LED_CURR_MAX 20
147 
153 #define OXIMETER3_ALS_PARAM_CONT_CONVERSION_ENABLE 0x80
154 #define OXIMETER3_ALS_PARAM_CONT_CONVERSION_DISABLE 0x00
155 #define OXIMETER3_ALS_PARAM_AUTO_OFSEN_ENABLE 0x08
156 #define OXIMETER3_ALS_PARAM_AUTO_OFSEN_DISABLE 0x00
157 #define OXIMETER3_ALS_PARAM_1_SAMPEL_PER_S 0x00
158 #define OXIMETER3_ALS_PARAM_2_SAMPEL_PER_S 0x10
159 #define OXIMETER3_ALS_PARAM_3_SAMPEL_PER_S 0x20
160 #define OXIMETER3_ALS_PARAM_4_SAMPEL_PER_S 0x30
161 #define OXIMETER3_ALS_PARAM_5_SAMPEL_PER_S 0x40
162 #define OXIMETER3_ALS_PARAM_6_SAMPEL_PER_S 0x50
163 #define OXIMETER3_ALS_PARAM_8_SAMPEL_PER_S 0x60
164 #define OXIMETER3_ALS_PARAM_10_SAMPEL_PER_S 0x70
165 
171 #define OXIMETER3_INT_CTRL_1_CNT 0x00
172 #define OXIMETER3_INT_CTRL_2_CNT 0x20
173 #define OXIMETER3_INT_CTRL_4_CNT 0x40
174 #define OXIMETER3_INT_CTRL_8_CNT 0x60
175 #define OXIMETER3_INT_CTRL_16_CNT 0x80
176 #define OXIMETER3_INT_CTRL_32_CNT 0xA0
177 #define OXIMETER3_INT_CTRL_64_CNT 0xC0
178 #define OXIMETER3_INT_CTRL_128_CNT 0xE0
179 #define OXIMETER3_INT_CTRL_INT_ON_PROX_RDY 0x08
180 #define OXIMETER3_INT_CTRL_INT_ON_ALS_RDY 0x04
181 #define OXIMETER3_INT_CTRL_INT_ON_THRESHOLD 0x02
182 #define OXIMETER3_INT_CTRL_INT_ON_THRESHOLD_PROX 0x00
183 #define OXIMETER3_INT_CTRL_INT_ON_THRESHOLD_ALS 0x01
184 
190 #define OXIMETER3_INT_STATUS_PROX 0x08
191 #define OXIMETER3_INT_STATUS_ALS 0x04
192 #define OXIMETER3_INT_STATUS_LOW_THRESHOLD 0x02
193 #define OXIMETER3_INT_STATUS_HIGH_THRESHOLD 0x01
194 
200 #define OXIMETER3_PROX_TIMING_FREQ_390p625_KHZ 0x00
201 #define OXIMETER3_PROX_TIMING_FREQ_781p25_KHZ 0x01
202 #define OXIMETER3_PROX_TIMING_FREQ_1p5625_MHZ 0x10
203 #define OXIMETER3_PROX_TIMING_FREQ_3p125_MHZ 0x11
204 
210 #define OXIMETER3_ID_VAL 0x21
211 
217 #define OXIMETER3_ALS 0x11
218 #define OXIMETER3_PROX 0x22
219 #define OXIMETER3_HEART_RATE 0x33
220 
226 #define SHIFT_VALUE 8
227  // End group macro
230 // --------------------------------------------------------------- PUBLIC TYPES
239 typedef struct
240 {
241  digital_in_t int_pin;
242 
243  // Modules
244 
245  i2c_master_t i2c;
246 
247  // ctx variable
248 
249  uint8_t slave_address;
250 
251 } oximeter3_t;
252 
256 typedef struct
257 {
258  // Communication gpio pins
259 
260  pin_name_t scl;
261  pin_name_t sda;
262 
263  // Additional gpio pins
264 
265  pin_name_t int_pin;
266 
267  // static variable
268 
269  uint32_t i2c_speed;
270  uint8_t i2c_address;
271 
273  // End types group
275 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
276 
282 #ifdef __cplusplus
283 extern "C"{
284 #endif
285 
295 
304 
315 void oximeter3_generic_write ( oximeter3_t *ctx, uint8_t reg, uint8_t data_buf );
316 
326 uint8_t oximeter3_generic_read ( oximeter3_t *ctx, uint8_t reg );
327 
336 
347 uint16_t oximeter3_read_value ( oximeter3_t *ctx, uint8_t type_macro );
348 
349 #ifdef __cplusplus
350 }
351 #endif
352 #endif // _OXIMETER3_H_
353  // End public_function group
356 
357 // ------------------------------------------------------------------------- END
oximeter3_cfg_t::scl
pin_name_t scl
Definition: oximeter3.h:260
oximeter3_generic_read
uint8_t oximeter3_generic_read(oximeter3_t *ctx, uint8_t reg)
Generic read function.
oximeter3_cfg_t::int_pin
pin_name_t int_pin
Definition: oximeter3.h:265
oximeter3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: oximeter3.h:269
oximeter3_cfg_t::sda
pin_name_t sda
Definition: oximeter3.h:261
oximeter3_generic_write
void oximeter3_generic_write(oximeter3_t *ctx, uint8_t reg, uint8_t data_buf)
Generic write function.
oximeter3_cfg_t
Click configuration structure definition.
Definition: oximeter3.h:257
oximeter3_cfg_setup
void oximeter3_cfg_setup(oximeter3_cfg_t *cfg)
Config Object Initialization function.
oximeter3_read_value
uint16_t oximeter3_read_value(oximeter3_t *ctx, uint8_t type_macro)
Generic function for reading als and proximity values.
oximeter3_init
OXIMETER3_RETVAL oximeter3_init(oximeter3_t *ctx, oximeter3_cfg_t *cfg)
Initialization function.
oximeter3_t::int_pin
digital_in_t int_pin
Definition: oximeter3.h:241
OXIMETER3_RETVAL
#define OXIMETER3_RETVAL
Definition: oximeter3.h:72
oximeter3_get_int_status
uint8_t oximeter3_get_int_status(oximeter3_t *ctx)
Gets state of the int pin.
oximeter3_t::i2c
i2c_master_t i2c
Definition: oximeter3.h:245
oximeter3_t
Click ctx object definition.
Definition: oximeter3.h:240
oximeter3_cfg_t::i2c_address
uint8_t i2c_address
Definition: oximeter3.h:270
oximeter3_t::slave_address
uint8_t slave_address
Definition: oximeter3.h:249