proximity11  2.0.0.0
proximity11.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 PROXIMITY11_H
36 #define PROXIMITY11_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 PROXIMITY11_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 PROXIMITY11_RETVAL uint8_t
73 
74 #define PROXIMITY11_OK 0x00
75 #define PROXIMITY11_INIT_ERROR 0xFF
76 
83 #define PROXIMITY11_DEVICE_ADDRESS 0x38
84 
91 #define PROXIMITY11_SYS_CTRL 0x40
92 #define PROXIMITY11_MODE_CTRL 0x41
93 #define PROXIMITY11_ALS_PS_CTRL 0x42
94 #define PROXIMITY11_PS_CTRL 0x43
95 #define PROXIMITY11_PS_DATA_LSB 0x44
96 #define PROXIMITY11_PS_DATA_MSB 0x45
97 #define PROXIMITY11_ALS_DATA0_LSB 0x46
98 #define PROXIMITY11_ALS_DATA0_MSB 0x47
99 #define PROXIMITY11_ALS_DATA1_LSB 0x48
100 #define PROXIMITY11_ALS_DATA1_MSB 0x49
101 #define PROXIMITY11_INTERRUPT 0x4A
102 #define PROXIMITY11_PS_TH_LSB 0x4B
103 #define PROXIMITY11_PS_TH_MSB 0x4C
104 #define PROXIMITY11_PS_TL_LSB 0x4D
105 #define PROXIMITY11_PS_TL_MSB 0x4E
106 #define PROXIMITY11_ALS_DATA0_TH_LSB 0x4F
107 #define PROXIMITY11_ALS_DATA0_TH_MSB 0x50
108 #define PROXIMITY11_ALS_DATA0_TL_LSB 0x51
109 #define PROXIMITY11_ALS_DATA0_TL_MSB 0x52
110 #define PROXIMITY11_PS_OFFSET_LSB 0x53
111 #define PROXIMITY11_PS_OFFSET_MSB 0x54
112 #define PROXIMITY11_MANUFACT_ID 0x92
113  // End group macro
116 // --------------------------------------------------------------- PUBLIC TYPES
123 typedef struct
124 {
125  uint8_t als_data0_gain;
126  uint8_t als_data1_gain;
128 
129 } als_data_t;
130 
134 typedef struct
135 {
136  // Input pins
137 
138  digital_in_t int_pin;
139 
140  // Modules
141 
142  i2c_master_t i2c;
143 
144  // ctx variable
145 
146  uint8_t slave_address;
147 
148  //als data object
149 
151 
152 } proximity11_t;
153 
157 typedef struct
158 {
159  // Communication gpio pins
160 
161  pin_name_t scl;
162  pin_name_t sda;
163 
164  // Additional gpio pins
165 
166  pin_name_t int_pin;
167 
168  // static variable
169 
170  uint32_t i2c_speed;
171  uint8_t i2c_address;
172 
173  // als_data default values
174 
178 
180 
181 
182  // End types group
184 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
185 
191 #ifdef __cplusplus
192 extern "C"{
193 #endif
194 
204 
214 
223 
234 void proximity11_generic_write ( proximity11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
235 
246 void proximity11_generic_read ( proximity11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
247 
258 
269 uint8_t proximity11_get ( proximity11_t *ctx, uint8_t register_address, uint8_t *output_buffer, uint8_t n_bytes );
270 
281 uint8_t proximity11_set ( proximity11_t *ctx, uint8_t register_address, uint8_t *input_buffer, uint8_t n_bytes );
282 
291 
302 float proximity11_convert_lx ( proximity11_t *ctx, uint16_t *input_data );
303 
312 void proximity11_get_raw_ps_als_values ( proximity11_t *ctx, uint8_t *data_buffer );
313 
323 void proximity11_get_ps_als_values ( proximity11_t *ctx, uint16_t *ps_value, float *als_value );
324 
336 uint8_t proximity11_set_ps_threshold_high ( proximity11_t *ctx, uint16_t threshold_value );
337 
349 uint8_t proximity11_set_ps_threshold_low ( proximity11_t *ctx, uint16_t threshold_value );
350 
359 void proximity11_set_als_threshold_high ( proximity11_t *ctx, uint16_t threshold_value );
360 
369 void proximity11_set_als_threshold_low ( proximity11_t *ctx, uint16_t threshold_value );
370 
382 uint8_t proximity11_set_ps_offset ( proximity11_t *ctx, uint16_t offset_value );
383 
384 #ifdef __cplusplus
385 }
386 #endif
387 #endif // _PROXIMITY11_H_
388  // End public_function group
391 
392 // ------------------------------------------------------------------------- END
proximity11_set_als_threshold_high
void proximity11_set_als_threshold_high(proximity11_t *ctx, uint16_t threshold_value)
Setting High Als threshold value.
proximity11_t::slave_address
uint8_t slave_address
Definition: proximity11.h:146
proximity11_cfg_t::int_pin
pin_name_t int_pin
Definition: proximity11.h:166
proximity11_cfg_setup
void proximity11_cfg_setup(proximity11_cfg_t *cfg)
Config Object Initialization function.
als_data_t
Definition: proximity11.h:124
proximity11_set
uint8_t proximity11_set(proximity11_t *ctx, uint8_t register_address, uint8_t *input_buffer, uint8_t n_bytes)
Proximity value set function.
proximity11_default_cfg
uint8_t proximity11_default_cfg(proximity11_t *ctx)
Click Default Configuration function.
proximity11_t::int_pin
digital_in_t int_pin
Definition: proximity11.h:138
als_data_t::als_data1_gain
uint8_t als_data1_gain
Definition: proximity11.h:126
als_data_t::als_measure_time
uint16_t als_measure_time
Definition: proximity11.h:127
proximity11_set_ps_threshold_low
uint8_t proximity11_set_ps_threshold_low(proximity11_t *ctx, uint16_t threshold_value)
Setting Low PS threshold value.
proximity11_init
PROXIMITY11_RETVAL proximity11_init(proximity11_t *ctx, proximity11_cfg_t *cfg)
Initialization function.
proximity11_cfg_t
Click configuration structure definition.
Definition: proximity11.h:158
proximity11_update
void proximity11_update(proximity11_t *ctx)
Updating data for Lux calculation.
proximity11_set_ps_threshold_high
uint8_t proximity11_set_ps_threshold_high(proximity11_t *ctx, uint16_t threshold_value)
Setting High PS threshold value.
proximity11_cfg_t::als_data0_gain_cfg
uint8_t als_data0_gain_cfg
Definition: proximity11.h:175
proximity11_generic_write
void proximity11_generic_write(proximity11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
proximity11_t::i2c
i2c_master_t i2c
Definition: proximity11.h:142
proximity11_cfg_t::scl
pin_name_t scl
Definition: proximity11.h:161
PROXIMITY11_RETVAL
#define PROXIMITY11_RETVAL
Definition: proximity11.h:72
proximity11_cfg_t::i2c_address
uint8_t i2c_address
Definition: proximity11.h:171
proximity11_set_als_threshold_low
void proximity11_set_als_threshold_low(proximity11_t *ctx, uint16_t threshold_value)
Setting Low Als threshold value.
proximity11_int_get
uint8_t proximity11_int_get(proximity11_t *ctx)
Int pin get functuin.
proximity11_cfg_t::als_data1_gain_cfg
uint8_t als_data1_gain_cfg
Definition: proximity11.h:176
proximity11_convert_lx
float proximity11_convert_lx(proximity11_t *ctx, uint16_t *input_data)
Converting raw data to Lux.
proximity11_cfg_t::als_measure_time_cfg
uint16_t als_measure_time_cfg
Definition: proximity11.h:177
proximity11_get
uint8_t proximity11_get(proximity11_t *ctx, uint8_t register_address, uint8_t *output_buffer, uint8_t n_bytes)
Proximity value get function.
proximity11_get_raw_ps_als_values
void proximity11_get_raw_ps_als_values(proximity11_t *ctx, uint8_t *data_buffer)
Getting raw ALS and PS data.
proximity11_t
Click ctx object definition.
Definition: proximity11.h:135
proximity11_t::als
als_data_t als
Definition: proximity11.h:150
proximity11_generic_read
void proximity11_generic_read(proximity11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
proximity11_cfg_t::sda
pin_name_t sda
Definition: proximity11.h:162
proximity11_set_ps_offset
uint8_t proximity11_set_ps_offset(proximity11_t *ctx, uint16_t offset_value)
Setting PS offset value.
als_data_t::als_data0_gain
uint8_t als_data0_gain
Definition: proximity11.h:125
proximity11_get_ps_als_values
void proximity11_get_ps_als_values(proximity11_t *ctx, uint16_t *ps_value, float *als_value)
Getting ALS and PS values.
proximity11_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: proximity11.h:170