oximeter5  2.0.0.0
oximeter5.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef OXIMETER5_H
29 #define OXIMETER5_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_in.h"
46 #include "drv_i2c_master.h"
47 
48 
69 #define OXIMETER5_REG_INTR_STATUS_1 0x00
70 #define OXIMETER5_REG_INTR_STATUS_2 0x01
71 #define OXIMETER5_REG_INTR_ENABLE_1 0x02
72 #define OXIMETER5_REG_INTR_ENABLE_2 0x03
73 #define OXIMETER5_REG_FIFO_WR_PTR 0x04
74 #define OXIMETER5_REG_OVF_COUNTER 0x05
75 #define OXIMETER5_REG_FIFO_RD_PTR 0x06
76 #define OXIMETER5_REG_FIFO_DATA 0x07
77 #define OXIMETER5_REG_FIFO_CONFIG 0x08
78 #define OXIMETER5_REG_MODE_CONFIG 0x09
79 #define OXIMETER5_REG_SPO2_CONFIG 0x0A
80 #define OXIMETER5_REG_LED1_PA 0x0C
81 #define OXIMETER5_REG_LED2_PA 0x0D
82 #define OXIMETER5_REG_MULTI_LED_CTRL1 0x11
83 #define OXIMETER5_REG_MULTI_LED_CTRL2 0x12
84 #define OXIMETER5_REG_TEMP_INTR 0x1F
85 #define OXIMETER5_REG_TEMP_FRAC 0x20
86 #define OXIMETER5_REG_TEMP_CONFIG 0x21
87 #define OXIMETER5_REG_PROX_INT_THRESH 0x30
88 #define OXIMETER5_REG_REV_ID 0xFE
89 #define OXIMETER5_REG_PART_ID 0xFF
90  // oximeter5_reg
92 
107 // OXIMETER5_REG_INTR_ENABLE_1
108 #define OXIMETER5_SET_INTR_EN_1_FULL_EN 0x80
109 #define OXIMETER5_SET_INTR_EN_1_PPG_RDY_EN 0x40
110 #define OXIMETER5_SET_INTR_EN_1_ALC_OVF_EN 0x20
111 
112 // OXIMETER5_REG_INTR_ENABLE_2
113 #define OXIMETER5_SET_INTR_EN_2_TEMP_EN 0x80
114 #define OXIMETER5_SET_INTR_EN_2_TEMP_DIS 0x00
115 
116 // OXIMETER5_REG_FIFO_CONFIG
117 #define OXIMETER5_SET_FIFO_PTR_RESET 0x00
118 #define OXIMETER5_SET_FIFO_COUNTER_RESET 0x00
119 
120 // OXIMETER5_REG_FIFO_CONFIG
121 #define OXIMETER5_SET_FIFO_CFG_SMP_AVE_BIT_MASK 0xC0
122 #define OXIMETER5_SET_FIFO_CFG_SMP_AVE_1 0x00
123 #define OXIMETER5_SET_FIFO_CFG_SMP_AVE_2 0x20
124 #define OXIMETER5_SET_FIFO_CFG_SMP_AVE_3 0x40
125 #define OXIMETER5_SET_FIFO_CFG_SMP_AVE_8 0x60
126 #define OXIMETER5_SET_FIFO_CFG_SMP_AVE_16 0x80
127 #define OXIMETER5_SET_FIFO_CFG_SMP_AVE_32 0xC0
128 
129 #define OXIMETER5_SET_FIFO_CFG_FIFO_RL_BIT_MASK 0x10
130 #define OXIMETER5_SET_FIFO_CFG_FIFO_RL_EN 0x10
131 
132 #define OXIMETER5_SET_FIFO_CFG_DATA_SAMP_BIT_MASK 0x0F
133 #define OXIMETER5_SET_FIFO_CFG_DATA_SAMP_0 0x00
134 #define OXIMETER5_SET_FIFO_CFG_DATA_SAMP_1 0x01
135 #define OXIMETER5_SET_FIFO_CFG_DATA_SAMP_2 0x02
136 #define OXIMETER5_SET_FIFO_CFG_DATA_SAMP_3 0x03
137 #define OXIMETER5_SET_FIFO_CFG_DATA_SAMP_4 0x04
138 #define OXIMETER5_SET_FIFO_CFG_DATA_SAMP_5 0x05
139 #define OXIMETER5_SET_FIFO_CFG_DATA_SAMP_6 0x06
140 #define OXIMETER5_SET_FIFO_CFG_DATA_SAMP_7 0x07
141 #define OXIMETER5_SET_FIFO_CFG_DATA_SAMP_8 0x08
142 #define OXIMETER5_SET_FIFO_CFG_DATA_SAMP_9 0x09
143 #define OXIMETER5_SET_FIFO_CFG_DATA_SAMP_10 0x0A
144 #define OXIMETER5_SET_FIFO_CFG_DATA_SAMP_11 0x0B
145 #define OXIMETER5_SET_FIFO_CFG_DATA_SAMP_12 0x0C
146 #define OXIMETER5_SET_FIFO_CFG_DATA_SAMP_13 0x0D
147 #define OXIMETER5_SET_FIFO_CFG_DATA_SAMP_14 0x0E
148 #define OXIMETER5_SET_FIFO_CFG_DATA_SAMP_15 0x0F
149 
150 #define OXIMETER5_SET_CFG_MODE_BIT_MASK 0x07
151 #define OXIMETER5_SW_RESET 0x40
152 #define OXIMETER5_SET_CFG_MODE_HEART_RATE 0x02
153 #define OXIMETER5_SET_CFG_MODE_SpO2 0x03
154 #define OXIMETER5_SET_CFG_MODE_MULTI_LED 0x07
155 
156 #define OXIMETER5_SET_SPO2_CFG_ADC_RGE_BIT_MASK 0x60
157 #define OXIMETER5_SET_SPO2_CFG_ADC_RGE_2048 0x00
158 #define OXIMETER5_SET_SPO2_CFG_ADC_RGE_4096 0x20
159 #define OXIMETER5_SET_SPO2_CFG_ADC_RGE_8192 0x40
160 #define OXIMETER5_SET_SPO2_CFG_ADC_RGE_16384 0x60
161 
162 #define OXIMETER5_SET_SPO2_CFG_SR_SEC_BIT_MASK 0x1C
163 #define OXIMETER5_SET_SPO2_CFG_SR_SEC_50 0x00
164 #define OXIMETER5_SET_SPO2_CFG_SR_SEC_100 0x04
165 #define OXIMETER5_SET_SPO2_CFG_SR_SEC_200 0x08
166 #define OXIMETER5_SET_SPO2_CFG_SR_SEC_400 0x0C
167 #define OXIMETER5_SET_SPO2_CFG_SR_SEC_800 0x10
168 #define OXIMETER5_SET_SPO2_CFG_SR_SEC_1000 0x12
169 #define OXIMETER5_SET_SPO2_CFG_SR_SEC_1600 0x14
170 #define OXIMETER5_SET_SPO2_CFG_SR_SEC_3200 0x1C
171 
172 #define OXIMETER5_SET_SPO2_CFG_LED_PW_BIT_MASK 0x03
173 #define OXIMETER5_SET_SPO2_CFG_LED_PW_15_bit 0x00
174 #define OXIMETER5_SET_SPO2_CFG_LED_PW_16_bit 0x01
175 #define OXIMETER5_SET_SPO2_CFG_LED_PW_17_bit 0x02
176 #define OXIMETER5_SET_SPO2_CFG_LED_PW_18_bit 0x03
177 
178 #define OXIMETER5_SET_LED_PULSE_AMPL_7_2_mA 0x24
179 
180 #define OXIMETER5_SET_CFG_TEMP_DISABLE 0x00
181 #define OXIMETER5_SET_CFG_TEMP_ENABLE 0x01
182 
183 #define MAX_BRIGHTNESS 255
184 #define OXIMETER5_PN_SPO2_ERROR_DATA 255
185 #define OXIMETER5_HEART_RATE_ERROR_DATA -999
186 
187 #define OXIMETER5_INTERRUPT_INACTIVE 0x00
188 #define OXIMETER5_INTERRUPT_ACTIVE 0x01
189 
195 #define OXIMETER5_SET_DEV_ADDR 0x57
196  // oximeter5_set
198 
213 #define OXIMETER5_MAP_MIKROBUS( cfg, mikrobus ) \
214  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
215  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
216  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
217  // oximeter5_map // oximeter5
220 
225 typedef struct
226 {
227  // Input pins
228  digital_in_t int_pin;
230  // Modules
231  i2c_master_t i2c;
233  // I2C slave address
234  uint8_t slave_address;
236 } oximeter5_t;
237 
242 typedef struct
243 {
244  pin_name_t scl;
245  pin_name_t sda;
247  pin_name_t int_pin;
249  uint32_t i2c_speed;
250  uint8_t i2c_address;
253 
258 typedef enum
259 {
261  OXIMETER5_ERROR = -1
262 
264 
265 
282 
298 
313 
329 err_t oximeter5_generic_write ( oximeter5_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
330 
346 err_t oximeter5_generic_read ( oximeter5_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
347 
363 
379 
395 err_t oximeter5_read_temperature ( oximeter5_t *ctx, float *temperature );
396 
412 err_t oximeter5_set_fifo_wr_pointer ( oximeter5_t *ctx, uint8_t fifo_wr_p );
413 
429 err_t oximeter5_set_fifo_rd_pointer ( oximeter5_t *ctx, uint8_t fifo_rd_p );
430 
448 err_t oximeter5_set_fifo_cfg ( oximeter5_t *ctx, uint8_t smp_ave, uint8_t fifo_ro_en, uint8_t fifo_a_full );
449 
465 err_t oximeter5_set_mode_cfg ( oximeter5_t *ctx, uint8_t mode );
466 
484 err_t oximeter5_set_spo2_cfg ( oximeter5_t *ctx, uint8_t spo2_adc_rge, uint8_t spo2_sr, uint8_t led_pw );
485 
503 err_t oximeter5_read_sensor_data ( oximeter5_t *ctx, uint32_t *ir, uint32_t *red );
504 
526 err_t oximeter5_get_oxygen_saturation ( uint32_t *pun_ir_buffer, int32_t n_ir_buffer_length, uint32_t *pun_red_buffer, uint8_t *pn_spo2 );
527 
545 err_t oximeter5_get_heart_rate ( uint32_t *pun_ir_buffer, int32_t n_ir_buffer_length, uint32_t *pun_red_buffer, int32_t *pn_heart_rate );
546 
547 #ifdef __cplusplus
548 }
549 #endif
550 #endif // OXIMETER5_H
551  // oximeter5
553 
554 // ------------------------------------------------------------------------ END
oximeter5_get_heart_rate
err_t oximeter5_get_heart_rate(uint32_t *pun_ir_buffer, int32_t n_ir_buffer_length, uint32_t *pun_red_buffer, int32_t *pn_heart_rate)
Oximeter 5 get heart rate function.
oximeter5_set_fifo_cfg
err_t oximeter5_set_fifo_cfg(oximeter5_t *ctx, uint8_t smp_ave, uint8_t fifo_ro_en, uint8_t fifo_a_full)
Oximeter 5 set FIFO config function.
oximeter5_cfg_t::sda
pin_name_t sda
Definition: oximeter5.h:245
oximeter5_t
Oximeter 5 Click context object.
Definition: oximeter5.h:226
oximeter5_read_sensor_data
err_t oximeter5_read_sensor_data(oximeter5_t *ctx, uint32_t *ir, uint32_t *red)
Oximeter 5 get sensor data function.
oximeter5_t::slave_address
uint8_t slave_address
Definition: oximeter5.h:234
oximeter5_cfg_t::i2c_address
uint8_t i2c_address
Definition: oximeter5.h:250
oximeter5_return_value_t
oximeter5_return_value_t
Oximeter 5 Click return value data.
Definition: oximeter5.h:259
oximeter5_read_temperature
err_t oximeter5_read_temperature(oximeter5_t *ctx, float *temperature)
Oximeter 5 read temperature function.
oximeter5_t::int_pin
digital_in_t int_pin
Definition: oximeter5.h:228
oximeter5_sw_reset
err_t oximeter5_sw_reset(oximeter5_t *ctx)
Oximeter 5 soft reset function.
oximeter5_cfg_t::int_pin
pin_name_t int_pin
Definition: oximeter5.h:247
OXIMETER5_OK
@ OXIMETER5_OK
Definition: oximeter5.h:260
oximeter5_cfg_t
Oximeter 5 Click configuration object.
Definition: oximeter5.h:243
oximeter5_check_interrupt
uint8_t oximeter5_check_interrupt(oximeter5_t *ctx)
Oximeter 5 check interrupt function.
oximeter5_cfg_setup
void oximeter5_cfg_setup(oximeter5_cfg_t *cfg)
Oximeter 5 configuration object setup function.
oximeter5_set_mode_cfg
err_t oximeter5_set_mode_cfg(oximeter5_t *ctx, uint8_t mode)
Oximeter 5 set mode config function.
oximeter5_set_fifo_wr_pointer
err_t oximeter5_set_fifo_wr_pointer(oximeter5_t *ctx, uint8_t fifo_wr_p)
Oximeter 5 set FIFO write pointer function.
oximeter5_set_spo2_cfg
err_t oximeter5_set_spo2_cfg(oximeter5_t *ctx, uint8_t spo2_adc_rge, uint8_t spo2_sr, uint8_t led_pw)
Oximeter 5 set SpO2 config function.
oximeter5_set_fifo_rd_pointer
err_t oximeter5_set_fifo_rd_pointer(oximeter5_t *ctx, uint8_t fifo_rd_p)
Oximeter 5 set FIFO read pointer function.
oximeter5_t::i2c
i2c_master_t i2c
Definition: oximeter5.h:231
oximeter5_cfg_t::scl
pin_name_t scl
Definition: oximeter5.h:244
OXIMETER5_ERROR
@ OXIMETER5_ERROR
Definition: oximeter5.h:261
oximeter5_default_cfg
err_t oximeter5_default_cfg(oximeter5_t *ctx)
Oximeter 5 default configuration function.
oximeter5_get_oxygen_saturation
err_t oximeter5_get_oxygen_saturation(uint32_t *pun_ir_buffer, int32_t n_ir_buffer_length, uint32_t *pun_red_buffer, uint8_t *pn_spo2)
Oximeter 5 get oxygen saturation function.
oximeter5_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: oximeter5.h:249
oximeter5_generic_read
err_t oximeter5_generic_read(oximeter5_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Oximeter 5 I2C reading function.
oximeter5_generic_write
err_t oximeter5_generic_write(oximeter5_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Oximeter 5 I2C writing function.
oximeter5_init
err_t oximeter5_init(oximeter5_t *ctx, oximeter5_cfg_t *cfg)
Oximeter 5 initialization function.