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
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define PROXIMITY3_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
76#define PROXIMITY3_OK 0
77#define PROXIMITY3_ERROR -1
85#define PROXIMITY3_I2CADDR 0x51 // I2C ADDRESS
86#define PROXIMITY3_ALS_CONF_REG 0x00 // Ambient Light Sensor Interrupt Threshold
87#define PROXIMITY3_ALS_THDH_REG 0x01 // Ambient Light Sensor Threshold Data High
88#define PROXIMITY3_ALS_THDL_REG 0x02 // Ambient Light Sensor Threshold Data Low
89#define PROXIMITY3_PS_CONF1_CONF2_REG 0x03 // Proximity Conf1 and Conf2
90#define PROXIMITY3_PS_CONF3_MS_REG 0x04 // Proximity Conf3 and Mode Select
91#define PROXIMITY3_PS_CANC_REG 0x05 // Proximity Cancellation Level Setting
92#define PROXIMITY3_PS_THDL_REG 0x06 // Proximity Sensor Threshold Data Low
93#define PROXIMITY3_PS_THDH_REG 0x07 // Proximity Sensor Threshold Data High
94#define PROXIMITY3_PROXIMITY_REG 0x08 // Proximity output data
95#define PROXIMITY3_AMBIENT_REG 0x09 // Ambient Light Sensor output data
96#define PROXIMITY3_WHITE_REG 0x0A // White output data
97#define PROXIMITY3_INT_FLAG_REG 0x0D // Ambient Light Sensor and Proximity interrupt flags
98#define PROXIMITY3_DEVICE_ID_REG 0x0E // Device ID
105#define PROXIMITY3_DEVICE_ID_VALUE 0x1058
112#define PROXIMITY3_ALS_CONF_CONFIG 0x0040 // Default Startup Options Ambient Light Sensor
113#define PROXIMITY3_PS_CONF1_CONF2_CONFIG 0x0A2A // Default Startup Options Proximity Conf1 & Conf2
114#define PROXIMITY3_PS_CONF3_MS_CONFIG 0x0770 // Default Startup Options Proximity Conf3 & MS
115#define PROXIMITY3_PS_THDL_CONFIG 0x1388 // Proximity Interrupt Levels Threshold Data Low
116#define PROXIMITY3_PS_THDH_CONFIG 0x2EE0 // Proximity Interrupt Levels Threshold Data High
119 // End group macro
120// --------------------------------------------------------------- PUBLIC TYPES
129typedef struct
130{
131 // Input pins
132 digital_in_t int_pin;
133
134 // Modules
135 i2c_master_t i2c;
136
137 // ctx variable
139
141
145typedef struct
146{
147 // Communication gpio pins
148 pin_name_t scl;
149 pin_name_t sda;
150
151 // Additional gpio pins
152 pin_name_t int_pin;
153
154 // static variable
155 uint32_t i2c_speed;
156 uint8_t i2c_address;
157
159
160 // End types group
161// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
162
168#ifdef __cplusplus
169extern "C"{
170#endif
171
181
194
207
220err_t proximity3_write_16 ( proximity3_t *ctx, uint8_t reg_address, uint16_t data_in );
221
232uint16_t proximity3_read_16 ( proximity3_t *ctx, uint8_t reg_address );
233
244
255
256#ifdef __cplusplus
257}
258#endif
259#endif // _PROXIMITY3_H_
260
261 // End public_function group
263
264// ------------------------------------------------------------------------- END
uint16_t proximity3_read_16(proximity3_t *ctx, uint8_t reg_address)
Generic read function.
err_t proximity3_default_cfg(proximity3_t *ctx)
Proximity 3 default configuration function.
void proximity3_cfg_setup(proximity3_cfg_t *cfg)
Config Object Initialization function.
uint16_t proximity3_read_proximity(proximity3_t *ctx)
Read proximity.
err_t proximity3_write_16(proximity3_t *ctx, uint8_t reg_address, uint16_t data_in)
Generic write function.
uint16_t proximity3_read_als(proximity3_t *ctx)
Read ambient light sensor data.
err_t proximity3_init(proximity3_t *ctx, proximity3_cfg_t *cfg)
Initialization function.
Click configuration structure definition.
Definition proximity3.h:146
uint32_t i2c_speed
Definition proximity3.h:155
pin_name_t scl
Definition proximity3.h:148
pin_name_t int_pin
Definition proximity3.h:152
pin_name_t sda
Definition proximity3.h:149
uint8_t i2c_address
Definition proximity3.h:156
Click ctx object definition.
Definition proximity3.h:130
digital_in_t int_pin
Definition proximity3.h:132
i2c_master_t i2c
Definition proximity3.h:135
uint8_t slave_address
Definition proximity3.h:138