proximity3  2.0.0.0
proximity3.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 PROXIMITY3_H
36 #define PROXIMITY3_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 PROXIMITY3_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 PROXIMITY3_OK 0
73 #define PROXIMITY3_ERROR -1
74 
81 #define PROXIMITY3_I2CADDR 0x51 // I2C ADDRESS
82 #define PROXIMITY3_ALS_CONF_REG 0x00 // Ambient Light Sensor Interrupt Threshold
83 #define PROXIMITY3_ALS_THDH_REG 0x01 // Ambient Light Sensor Threshold Data High
84 #define PROXIMITY3_ALS_THDL_REG 0x02 // Ambient Light Sensor Threshold Data Low
85 #define PROXIMITY3_PS_CONF1_CONF2_REG 0x03 // Proximity Conf1 and Conf2
86 #define PROXIMITY3_PS_CONF3_MS_REG 0x04 // Proximity Conf3 and Mode Select
87 #define PROXIMITY3_PS_CANC_REG 0x05 // Proximity Cancellation Level Setting
88 #define PROXIMITY3_PS_THDL_REG 0x06 // Proximity Sensor Threshold Data Low
89 #define PROXIMITY3_PS_THDH_REG 0x07 // Proximity Sensor Threshold Data High
90 #define PROXIMITY3_PROXIMITY_REG 0x08 // Proximity output data
91 #define PROXIMITY3_AMBIENT_REG 0x09 // Ambient Light Sensor output data
92 #define PROXIMITY3_WHITE_REG 0x0A // White output data
93 #define PROXIMITY3_INT_FLAG_REG 0x0D // Ambient Light Sensor and Proximity interrupt flags
94 #define PROXIMITY3_DEVICE_ID_REG 0x0E // Device ID
95 
101 #define PROXIMITY3_DEVICE_ID_VALUE 0x1058
102 
108 #define PROXIMITY3_ALS_CONF_CONFIG 0x0040 // Default Startup Options Ambient Light Sensor
109 #define PROXIMITY3_PS_CONF1_CONF2_CONFIG 0x0A2A // Default Startup Options Proximity Conf1 & Conf2
110 #define PROXIMITY3_PS_CONF3_MS_CONFIG 0x0770 // Default Startup Options Proximity Conf3 & MS
111 #define PROXIMITY3_PS_THDL_CONFIG 0x1388 // Proximity Interrupt Levels Threshold Data Low
112 #define PROXIMITY3_PS_THDH_CONFIG 0x2EE0 // Proximity Interrupt Levels Threshold Data High
113  // End group macro
116 // --------------------------------------------------------------- PUBLIC TYPES
125 typedef struct
126 {
127  // Input pins
128  digital_in_t int_pin;
129 
130  // Modules
131  i2c_master_t i2c;
132 
133  // ctx variable
134  uint8_t slave_address;
135 
136 } proximity3_t;
137 
141 typedef struct
142 {
143  // Communication gpio pins
144  pin_name_t scl;
145  pin_name_t sda;
146 
147  // Additional gpio pins
148  pin_name_t int_pin;
149 
150  // static variable
151  uint32_t i2c_speed;
152  uint8_t i2c_address;
153 
155  // End types group
157 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
158 
164 #ifdef __cplusplus
165 extern "C"{
166 #endif
167 
177 
190 
203 
216 err_t proximity3_write_16 ( proximity3_t *ctx, uint8_t reg_address, uint16_t data_in );
217 
228 uint16_t proximity3_read_16 ( proximity3_t *ctx, uint8_t reg_address );
229 
240 
251 
252 #ifdef __cplusplus
253 }
254 #endif
255 #endif // _PROXIMITY3_H_
256  // End public_function group
259 
260 // ------------------------------------------------------------------------- END
proximity3_read_16
uint16_t proximity3_read_16(proximity3_t *ctx, uint8_t reg_address)
Generic read function.
proximity3_write_16
err_t proximity3_write_16(proximity3_t *ctx, uint8_t reg_address, uint16_t data_in)
Generic write function.
proximity3_cfg_t
Click configuration structure definition.
Definition: proximity3.h:142
proximity3_default_cfg
err_t proximity3_default_cfg(proximity3_t *ctx)
Proximity 3 default configuration function.
proximity3_t::i2c
i2c_master_t i2c
Definition: proximity3.h:131
proximity3_cfg_t::scl
pin_name_t scl
Definition: proximity3.h:144
proximity3_t
Click ctx object definition.
Definition: proximity3.h:126
proximity3_read_proximity
uint16_t proximity3_read_proximity(proximity3_t *ctx)
Read proximity.
proximity3_cfg_t::sda
pin_name_t sda
Definition: proximity3.h:145
proximity3_t::slave_address
uint8_t slave_address
Definition: proximity3.h:134
proximity3_cfg_t::int_pin
pin_name_t int_pin
Definition: proximity3.h:148
proximity3_cfg_t::i2c_address
uint8_t i2c_address
Definition: proximity3.h:152
proximity3_init
err_t proximity3_init(proximity3_t *ctx, proximity3_cfg_t *cfg)
Initialization function.
proximity3_read_als
uint16_t proximity3_read_als(proximity3_t *ctx)
Read ambient light sensor data.
proximity3_t::int_pin
digital_in_t int_pin
Definition: proximity3.h:128
proximity3_cfg_setup
void proximity3_cfg_setup(proximity3_cfg_t *cfg)
Config Object Initialization function.
proximity3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: proximity3.h:151