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_OK 0
63 #define PROXIMITY3_ERROR -1
64 
71 #define PROXIMITY3_I2CADDR 0x51 // I2C ADDRESS
72 #define PROXIMITY3_ALS_CONF_REG 0x00 // Ambient Light Sensor Interrupt Threshold
73 #define PROXIMITY3_ALS_THDH_REG 0x01 // Ambient Light Sensor Threshold Data High
74 #define PROXIMITY3_ALS_THDL_REG 0x02 // Ambient Light Sensor Threshold Data Low
75 #define PROXIMITY3_PS_CONF1_CONF2_REG 0x03 // Proximity Conf1 and Conf2
76 #define PROXIMITY3_PS_CONF3_MS_REG 0x04 // Proximity Conf3 and Mode Select
77 #define PROXIMITY3_PS_CANC_REG 0x05 // Proximity Cancellation Level Setting
78 #define PROXIMITY3_PS_THDL_REG 0x06 // Proximity Sensor Threshold Data Low
79 #define PROXIMITY3_PS_THDH_REG 0x07 // Proximity Sensor Threshold Data High
80 #define PROXIMITY3_PROXIMITY_REG 0x08 // Proximity output data
81 #define PROXIMITY3_AMBIENT_REG 0x09 // Ambient Light Sensor output data
82 #define PROXIMITY3_WHITE_REG 0x0A // White output data
83 #define PROXIMITY3_INT_FLAG_REG 0x0D // Ambient Light Sensor and Proximity interrupt flags
84 #define PROXIMITY3_DEVICE_ID_REG 0x0E // Device ID
85 
91 #define PROXIMITY3_DEVICE_ID_VALUE 0x1058
92 
98 #define PROXIMITY3_ALS_CONF_CONFIG 0x0040 // Default Startup Options Ambient Light Sensor
99 #define PROXIMITY3_PS_CONF1_CONF2_CONFIG 0x0A2A // Default Startup Options Proximity Conf1 & Conf2
100 #define PROXIMITY3_PS_CONF3_MS_CONFIG 0x0770 // Default Startup Options Proximity Conf3 & MS
101 #define PROXIMITY3_PS_THDL_CONFIG 0x1388 // Proximity Interrupt Levels Threshold Data Low
102 #define PROXIMITY3_PS_THDH_CONFIG 0x2EE0 // Proximity Interrupt Levels Threshold Data High
103  // End group macro
106 // --------------------------------------------------------------- PUBLIC TYPES
115 typedef struct
116 {
117  // Input pins
118  digital_in_t int_pin;
119 
120  // Modules
121  i2c_master_t i2c;
122 
123  // ctx variable
124  uint8_t slave_address;
125 
126 } proximity3_t;
127 
131 typedef struct
132 {
133  // Communication gpio pins
134  pin_name_t scl;
135  pin_name_t sda;
136 
137  // Additional gpio pins
138  pin_name_t int_pin;
139 
140  // static variable
141  uint32_t i2c_speed;
142  uint8_t i2c_address;
143 
145  // End types group
147 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
148 
154 #ifdef __cplusplus
155 extern "C"{
156 #endif
157 
167 
180 
193 
206 err_t proximity3_write_16 ( proximity3_t *ctx, uint8_t reg_address, uint16_t data_in );
207 
218 uint16_t proximity3_read_16 ( proximity3_t *ctx, uint8_t reg_address );
219 
230 
241 
242 #ifdef __cplusplus
243 }
244 #endif
245 #endif // _PROXIMITY3_H_
246  // End public_function group
249 
250 // ------------------------------------------------------------------------- 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:132
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:121
proximity3_cfg_t::scl
pin_name_t scl
Definition: proximity3.h:134
proximity3_t
Click ctx object definition.
Definition: proximity3.h:116
proximity3_read_proximity
uint16_t proximity3_read_proximity(proximity3_t *ctx)
Read proximity.
proximity3_cfg_t::sda
pin_name_t sda
Definition: proximity3.h:135
proximity3_t::slave_address
uint8_t slave_address
Definition: proximity3.h:124
proximity3_cfg_t::int_pin
pin_name_t int_pin
Definition: proximity3.h:138
proximity3_cfg_t::i2c_address
uint8_t i2c_address
Definition: proximity3.h:142
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:118
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:141