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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define PROXIMITY3_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
56 
62 #define PROXIMITY3_RETVAL uint8_t
63 
64 #define PROXIMITY3_OK 0x00
65 #define PROXIMITY3_INIT_ERROR 0xFF
66 
73 #define PROXIMITY3_I2CADDR 0x51 // I2C ADDRESS
74 #define PROXIMITY3_ALS_CONF_REG 0x00 // Ambient Light Sensor Interrupt Threshold
75 #define PROXIMITY3_ALS_THDH_REG 0x01 // Ambient Light Sensor Threshold Data High
76 #define PROXIMITY3_ALS_THDL_REG 0x02 // Ambient Light Sensor Threshold Data Low
77 #define PROXIMITY3_PS_CONF1_CONF2_REG 0x03 // Proximity Conf1 and Conf2
78 #define PROXIMITY3_PS_CONF3_MS_REG 0x04 // Proximity Conf3 and Mode Select
79 #define PROXIMITY3_PS_CANC_REG 0x05 // Proximity Cancellation Level Setting
80 #define PROXIMITY3_PS_THDL_REG 0x06 // Proximity Sensor Threshold Data Low
81 #define PROXIMITY3_PS_THDH_REG 0x07 // Proximity Sensor Threshold Data High
82 #define PROXIMITY3_PROXIMITY_REG 0x08 // Proximity output data
83 #define PROXIMITY3_AMBIENT_REG 0x09 // Ambient Light Sensor output data
84 #define PROXIMITY3_WHITE_REG 0x0A // White output data
85 #define PROXIMITY3_INT_FLAG_REG 0x0D // Ambient Light Sensor and Proximity interrupt flags
86 #define PROXIMITY3_DEVICE_ID_REG 0x0E // Device ID
87 
93 #define PROXIMITY3_DEVICE_ID_VALUE 0x1058
94 
100 #define PROXIMITY3_ALS_CONF_CONFIG 0x0040 // Default Startup Options Ambient Light Sensor
101 #define PROXIMITY3_PS_CONF1_CONF2_CONFIG 0x0A2A // Default Startup Options Proximity Conf1 & Conf2
102 #define PROXIMITY3_PS_CONF3_MS_CONFIG 0x0770 // Default Startup Options Proximity Conf3 & MS
103 #define PROXIMITY3_PS_THDL_CONFIG 0x1388 // Proximity Interrupt Levels Threshold Data Low
104 #define PROXIMITY3_PS_THDH_CONFIG 0x2EE0 // Proximity Interrupt Levels Threshold Data High
105  // End group macro
108 // --------------------------------------------------------------- PUBLIC TYPES
117 typedef struct
118 {
119  // Input pins
120 
121  digital_in_t int_pin;
122 
123  // Modules
124 
125  i2c_master_t i2c;
126 
127  // ctx variable
128 
129  uint8_t slave_address;
130 
131 } proximity3_t;
132 
136 typedef struct
137 {
138  // Communication gpio pins
139 
140  pin_name_t scl;
141  pin_name_t sda;
142 
143  // Additional gpio pins
144 
145  pin_name_t int_pin;
146 
147  // static variable
148 
149  uint32_t i2c_speed;
150  uint8_t i2c_address;
151 
153  // End types group
155 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
156 
162 #ifdef __cplusplus
163 extern "C"{
164 #endif
165 
175 
185 
195 void proximity3_write_16 ( proximity3_t *ctx, uint8_t reg_address, uint16_t data_in );
196 
207 uint16_t proximity3_read_16 ( proximity3_t *ctx, uint8_t reg_address );
208 
219 
229 uint8_t proximity3_read_proximity ( proximity3_t *ctx );
230 
240 uint8_t proximity3_get_distance ( proximity3_t *ctx );
241 
251 uint16_t proximity3_get_illuminance ( proximity3_t *ctx );
252 
253 
254 #ifdef __cplusplus
255 }
256 #endif
257 #endif // _PROXIMITY3_H_
258  // End public_function group
261 
262 // ------------------------------------------------------------------------- END
proximity3_read_16
uint16_t proximity3_read_16(proximity3_t *ctx, uint8_t reg_address)
Generic read function.
proximity3_get_distance
uint8_t proximity3_get_distance(proximity3_t *ctx)
Get distance.
proximity3_cfg_t
Click configuration structure definition.
Definition: proximity3.h:136
proximity3_t::i2c
i2c_master_t i2c
Definition: proximity3.h:125
proximity3_init
PROXIMITY3_RETVAL proximity3_init(proximity3_t *ctx, proximity3_cfg_t *cfg)
Initialization function.
proximity3_cfg_t::scl
pin_name_t scl
Definition: proximity3.h:140
proximity3_t
Click ctx object definition.
Definition: proximity3.h:117
proximity3_cfg_t::sda
pin_name_t sda
Definition: proximity3.h:141
proximity3_read_proximity
uint8_t proximity3_read_proximity(proximity3_t *ctx)
Read proximity.
proximity3_write_16
void proximity3_write_16(proximity3_t *ctx, uint8_t reg_address, uint16_t data_in)
Generic write function.
proximity3_get_illuminance
uint16_t proximity3_get_illuminance(proximity3_t *ctx)
Get illuminance.
proximity3_t::slave_address
uint8_t slave_address
Definition: proximity3.h:129
proximity3_cfg_t::int_pin
pin_name_t int_pin
Definition: proximity3.h:145
proximity3_cfg_t::i2c_address
uint8_t i2c_address
Definition: proximity3.h:150
proximity3_t::int_pin
digital_in_t int_pin
Definition: proximity3.h:121
proximity3_read_ambient_light_sensor
uint16_t proximity3_read_ambient_light_sensor(proximity3_t *ctx)
Read ambient light sensor data.
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:149
PROXIMITY3_RETVAL
#define PROXIMITY3_RETVAL
Definition: proximity3.h:62