proximity3  2.0.0.0
proximity3.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef PROXIMITY3_H
36 #define PROXIMITY3_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define PROXIMITY3_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
57 
63 #define PROXIMITY3_RETVAL uint8_t
64 
65 #define PROXIMITY3_OK 0x00
66 #define PROXIMITY3_INIT_ERROR 0xFF
67 
74 #define PROXIMITY3_I2CADDR 0x51 // I2C ADDRESS
75 #define PROXIMITY3_ALS_CONF_REG 0x00 // Ambient Light Sensor Interrupt Threshold
76 #define PROXIMITY3_ALS_THDH_REG 0x01 // Ambient Light Sensor Threshold Data High
77 #define PROXIMITY3_ALS_THDL_REG 0x02 // Ambient Light Sensor Threshold Data Low
78 #define PROXIMITY3_PS_CONF1_CONF2_REG 0x03 // Proximity Conf1 and Conf2
79 #define PROXIMITY3_PS_CONF3_MS_REG 0x04 // Proximity Conf3 and Mode Select
80 #define PROXIMITY3_PS_CANC_REG 0x05 // Proximity Cancellation Level Setting
81 #define PROXIMITY3_PS_THDL_REG 0x06 // Proximity Sensor Threshold Data Low
82 #define PROXIMITY3_PS_THDH_REG 0x07 // Proximity Sensor Threshold Data High
83 #define PROXIMITY3_PROXIMITY_REG 0x08 // Proximity output data
84 #define PROXIMITY3_AMBIENT_REG 0x09 // Ambient Light Sensor output data
85 #define PROXIMITY3_WHITE_REG 0x0A // White output data
86 #define PROXIMITY3_INT_FLAG_REG 0x0D // Ambient Light Sensor and Proximity interrupt flags
87 #define PROXIMITY3_DEVICE_ID_REG 0x0E // Device ID
88 
94 #define PROXIMITY3_DEVICE_ID_VALUE 0x1058
95 
101 #define PROXIMITY3_ALS_CONF_CONFIG 0x0040 // Default Startup Options Ambient Light Sensor
102 #define PROXIMITY3_PS_CONF1_CONF2_CONFIG 0x0A2A // Default Startup Options Proximity Conf1 & Conf2
103 #define PROXIMITY3_PS_CONF3_MS_CONFIG 0x0770 // Default Startup Options Proximity Conf3 & MS
104 #define PROXIMITY3_PS_THDL_CONFIG 0x1388 // Proximity Interrupt Levels Threshold Data Low
105 #define PROXIMITY3_PS_THDH_CONFIG 0x2EE0 // Proximity Interrupt Levels Threshold Data High
106  // End group macro
109 // --------------------------------------------------------------- PUBLIC TYPES
118 typedef struct
119 {
120  // Input pins
121 
122  digital_in_t int_pin;
123 
124  // Modules
125 
126  i2c_master_t i2c;
127 
128  // ctx variable
129 
130  hal_i2c_address_t slave_address;
131 
132 } proximity3_t;
133 
137 typedef struct
138 {
139  // Communication gpio pins
140 
141  pin_name_t scl;
142  pin_name_t sda;
143 
144  // Additional gpio pins
145 
146  pin_name_t int_pin;
147 
148  // static variable
149 
150  hal_i2c_speed_t i2c_speed;
151  hal_i2c_address_t i2c_address;
152 
154  // End types group
156 
157 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
158 
164 #ifdef __cplusplus
165 extern "C"{
166 #endif
167 
177 
186 
187 
197 void proximity3_generic_write ( proximity3_t *ctx, uint8_t reg_address, uint16_t data_in );
198 
210 uint16_t proximity3_generic_read ( proximity3_t *ctx, uint8_t reg_address );
211 
223 
235 
246 uint8_t proximity3_get_distance( proximity3_t *ctx );
247 
259 
260 
261 
262 #ifdef __cplusplus
263 }
264 #endif
265 #endif // _PROXIMITY3_H_
266  // End public_function group
269 
270 // ------------------------------------------------------------------------- END
hal_i2c_address_t slave_address
Definition: proximity3.h:130
uint8_t proximity3_read_proximity(proximity3_t *ctx)
Read proximity.
uint16_t proximity3_read_ambient_light_sensor(proximity3_t *ctx)
Read ambient light sensor data.
PROXIMITY3_RETVAL proximity3_init(proximity3_t *ctx, proximity3_cfg_t *cfg)
Initialization function.
hal_i2c_address_t i2c_address
Definition: proximity3.h:151
digital_in_t int_pin
Definition: proximity3.h:122
uint8_t proximity3_get_distance(proximity3_t *ctx)
Get distance.
pin_name_t sda
Definition: proximity3.h:142
i2c_master_t i2c
Definition: proximity3.h:126
Click configuration structure definition.
Definition: proximity3.h:137
pin_name_t scl
Definition: proximity3.h:141
uint16_t proximity3_get_illuminance(proximity3_t *ctx)
Get illuminance.
uint16_t proximity3_generic_read(proximity3_t *ctx, uint8_t reg_address)
Generic read function.
Click ctx object definition.
Definition: proximity3.h:118
hal_i2c_speed_t i2c_speed
Definition: proximity3.h:150
pin_name_t int_pin
Definition: proximity3.h:146
void proximity3_generic_write(proximity3_t *ctx, uint8_t reg_address, uint16_t data_in)
Generic write function.
void proximity3_cfg_setup(proximity3_cfg_t *cfg)
Config Object Initialization function.
#define PROXIMITY3_RETVAL
Definition: proximity3.h:63