amiro-lld / drivers / VCNL4020 / v1 / alld_VCNL4020.h @ ed9a1bf5
History | View | Annotate | Download (15.732 KB)
1 |
/*
|
---|---|
2 |
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
|
3 |
Copyright (C) 2016..2020 Thomas Schöpping et al.
|
4 |
|
5 |
This program is free software: you can redistribute it and/or modify
|
6 |
it under the terms of the GNU Lesser General Public License as published by
|
7 |
the Free Software Foundation, either version 3 of the License, or
|
8 |
(at your option) any later version.
|
9 |
|
10 |
This program is distributed in the hope that it will be useful,
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
GNU Lesser General Public License for more details.
|
14 |
|
15 |
You should have received a copy of the GNU Lesser General Public License
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 |
*/
|
18 |
|
19 |
/**
|
20 |
* @file alld_VCNL4020.h
|
21 |
* @brief Proximity Sensor macros and structures.
|
22 |
*
|
23 |
* @addtogroup lld_proximity
|
24 |
* @{
|
25 |
*/
|
26 |
|
27 |
#ifndef AMIROLLD_VCNL4020_H
|
28 |
#define AMIROLLD_VCNL4020_H
|
29 |
|
30 |
#include <amiro-lld.h> |
31 |
|
32 |
/******************************************************************************/
|
33 |
/* CONSTANTS */
|
34 |
/******************************************************************************/
|
35 |
|
36 |
/**
|
37 |
* @brief Fixed slave address to access the VCNL4020 via I2C.
|
38 |
*/
|
39 |
#define VCNL4020_LLD_I2C_ADDR 0x13u |
40 |
|
41 |
/**
|
42 |
* @brief Maximum frequency for I2C communication.
|
43 |
*/
|
44 |
#define VCNL4020_LLD_I2C_MAXFREQUENCY 3400000 |
45 |
|
46 |
/**
|
47 |
* @brief A falling edge indicates an interrupt.
|
48 |
*/
|
49 |
#define VCNL4020_LLD_INT_EDGE APAL_GPIO_EDGE_FALLING
|
50 |
|
51 |
/******************************************************************************/
|
52 |
/* SETTINGS */
|
53 |
/******************************************************************************/
|
54 |
|
55 |
/******************************************************************************/
|
56 |
/* CHECKS */
|
57 |
/******************************************************************************/
|
58 |
|
59 |
/******************************************************************************/
|
60 |
/* DATA STRUCTURES AND TYPES */
|
61 |
/******************************************************************************/
|
62 |
|
63 |
/**
|
64 |
* @brief The VCNL4020 driver struct
|
65 |
*/
|
66 |
typedef struct { |
67 |
apalI2CDriver_t* i2cd; /**< @brief The I2C Driver. */
|
68 |
} VCNL4020Driver; |
69 |
|
70 |
/**
|
71 |
* @brief Adresses for the several I/O registers of the VCNL4020.
|
72 |
*/
|
73 |
typedef enum { |
74 |
VCNL4020_LLD_REGADDR_CMD = 0x80u, /**< command register */ |
75 |
VCNL4020_LLD_REGADDR_IDREV = 0x81u, /**< product ID revision register */ |
76 |
VCNL4020_LLD_REGADDR_PROXRATE = 0x82u, /**< proximity rate register */ |
77 |
VCNL4020_LLD_REGADDR_LEDCURRENT = 0x83u, /**< IR LED current register */ |
78 |
VCNL4020_LLD_REGADDR_ALPARAM = 0x84u, /**< ambient light parameter register */ |
79 |
VCNL4020_LLD_REGADDR_ALRES_HIGH = 0x85u, /**< ambient light result register (high byte) */ |
80 |
VCNL4020_LLD_REGADDR_ALRES_LOW = 0x86u, /**< ambient light result register (low byte) */ |
81 |
VCNL4020_LLD_REGADDR_PROXRES_HIGH = 0x87u, /**< proximity result register (high byte) */ |
82 |
VCNL4020_LLD_REGADDR_PROXRES_LOW = 0x88u, /**< proximity result register (low byte) */ |
83 |
VCNL4020_LLD_REGADDR_INTCTRL = 0x89u, /**< interrupt control register */ |
84 |
VCNL4020_LLD_REGADDR_LTH_HIGH = 0x8Au, /**< low threshold register (high byte) */ |
85 |
VCNL4020_LLD_REGADDR_LTH_LOW = 0x8Bu, /**< low threshold register (low byte) */ |
86 |
VCNL4020_LLD_REGADDR_HTH_HIGH = 0x8Cu, /**< high threshold register (high byte) */ |
87 |
VCNL4020_LLD_REGADDR_HTH_LOW = 0x8Du, /**< high threshold register (low byte) */ |
88 |
VCNL4020_LLD_REGADDR_INTSTATUS = 0x8Eu, /**< interrupt status register */ |
89 |
VCNL4020_LLD_REGADDR_PMTADJ = 0x8Fu, /**< prximity modulator timing adjustment */ |
90 |
VCNL4020_LLD_REGADDR_AMBIRLEVEL = 0x90u, /**< ambient IR light level register (not intended to be used) */ |
91 |
} vcnl4020_lld_regaddr_t; |
92 |
|
93 |
/**
|
94 |
* @brief Commands to control the VCNL4020.
|
95 |
*/
|
96 |
typedef enum { |
97 |
VCNL4020_LLD_CMDREG_CFGLOCK = 0x80u, /**< config lock (read only, constant = 1) */ |
98 |
VCNL4020_LLD_CMDREG_ALSRDY = 0x40u, /**< ambient light measurement data ready flag (read only) */ |
99 |
VCNL4020_LLD_CMDREG_PROXRDY = 0x20u, /**< proximity measurement data ready flag (read only) */ |
100 |
VCNL4020_LLD_CMDREG_ALSOD = 0x10u, /**< start single on-demand ambient light measurement */ |
101 |
VCNL4020_LLD_CMDREG_PROXOD = 0x08u, /**< start single on-demand proximity measurement */ |
102 |
VCNL4020_LLD_CMDREG_ALSEN = 0x04u, /**< start periodic ambient light measurement */ |
103 |
VCNL4020_LLD_CMDREG_PROXEN = 0x02u, /**< start periodic proximity measurement */ |
104 |
VCNL4020_LLD_CMDREG_SELFTIMED = 0x01u, /**< enable state-machine and clock for periodic measurement */ |
105 |
} vcnl4020_lld_cmdreg_t; |
106 |
|
107 |
/**
|
108 |
* @brief Masks to read the prodict ID revision register.
|
109 |
*/
|
110 |
typedef enum { |
111 |
VCNL4020_LLD_IDREVREG_ID_MASK = 0xF0u, /**< product ID (read only, constant = 2) */ |
112 |
VCNL4020_LLD_IDREVREG_REV_MASK = 0x0Fu, /**< revision ID (read only, constant = 1) */ |
113 |
} vcnl4020_lld_idrevreg_t; |
114 |
|
115 |
/**
|
116 |
* @brief Frequencies for the proximity sensor of the VCNL4020.
|
117 |
* @note Frequencies are calculated by the formula
|
118 |
* freq = 250Hz / (2 ^ (7 - <value>))
|
119 |
*/
|
120 |
typedef enum { |
121 |
VCNL4020_LLD_PROXRATEREG_MASK = 0x07u, /**< mask of settable bits */ |
122 |
VCNL4020_LLD_PROXRATEREG_1_95_HZ = 0x00u, /**< 1.95Hz sampling rate */ |
123 |
VCNL4020_LLD_PROXRATEREG_3_90625_HZ = 0x01u, /**< 3.90625Hz sampling rate */ |
124 |
VCNL4020_LLD_PROXRATEREG_7_8125_HZ = 0x02u, /**< 7.8125Hz sampling rate */ |
125 |
VCNL4020_LLD_PROXRATEREG_15_625_HZ = 0x03u, /**< 16.625Hz sampling rate */ |
126 |
VCNL4020_LLD_PROXRATEREG_31_25_HZ = 0x04u, /**< 31.25Hz sampling rate */ |
127 |
VCNL4020_LLD_PROXRATEREG_62_5_HZ = 0x05u, /**< 62.5Hz sampling rate */ |
128 |
VCNL4020_LLD_PROXRATEREG_125_HZ = 0x06u, /**< 125Hz sampling rate */ |
129 |
VCNL4020_LLD_PROXRATEREG_250_HZ = 0x07u, /**< 250Hz sampling rate */ |
130 |
VCNL4020_LLD_PROXRATEREG_DEFAULT = 0x00u, /**< default sampling rate (1.95Hz) */ |
131 |
} vcnl4020_lld_proxratereg_t; |
132 |
|
133 |
/**
|
134 |
* @brief Current for the emmitting IR LED.
|
135 |
* @note The Current is calculated by the formula
|
136 |
* curr = <value> * 10mA
|
137 |
*/
|
138 |
typedef enum { |
139 |
VCNL4020_LLD_LEDCURRENTREG_FUSEID_MASK = 0xC0u, /**< fuse program revision (read only) */ |
140 |
VCNL4020_LLD_LEDCURRENTREG_CURRENT_MASK = 0x3Fu, /**< mask of bits to set the current */ |
141 |
VCNL4020_LLD_LEDCURRENTREG_0_mA = 0x00u, /**< 0mA IR LED current */ |
142 |
VCNL4020_LLD_LEDCURRENTREG_10_mA = 0x01u, /**< 10mA IR LED current */ |
143 |
VCNL4020_LLD_LEDCURRENTREG_20_mA = 0x02u, /**< 20mA IR LED current */ |
144 |
VCNL4020_LLD_LEDCURRENTREG_30_mA = 0x03u, /**< 30mA IR LED current */ |
145 |
VCNL4020_LLD_LEDCURRENTREG_40_mA = 0x04u, /**< 40mA IR LED current */ |
146 |
VCNL4020_LLD_LEDCURRENTREG_50_mA = 0x05u, /**< 50mA IR LED current */ |
147 |
VCNL4020_LLD_LEDCURRENTREG_60_mA = 0x06u, /**< 60mA IR LED current */ |
148 |
VCNL4020_LLD_LEDCURRENTREG_70_mA = 0x07u, /**< 70mA IR LED current */ |
149 |
VCNL4020_LLD_LEDCURRENTREG_80_mA = 0x08u, /**< 80mA IR LED current */ |
150 |
VCNL4020_LLD_LEDCURRENTREG_90_mA = 0x09u, /**< 90mA IR LED current */ |
151 |
VCNL4020_LLD_LEDCURRENTREG_100_mA = 0x0Au, /**< 100mA IR LED current */ |
152 |
VCNL4020_LLD_LEDCURRENTREG_110_mA = 0x0Bu, /**< 110mA IR LED current */ |
153 |
VCNL4020_LLD_LEDCURRENTREG_120_mA = 0x0Cu, /**< 120mA IR LED current */ |
154 |
VCNL4020_LLD_LEDCURRENTREG_130_mA = 0x0Du, /**< 130mA IR LED current */ |
155 |
VCNL4020_LLD_LEDCURRENTREG_140_mA = 0x0Eu, /**< 140mA IR LED current */ |
156 |
VCNL4020_LLD_LEDCURRENTREG_150_mA = 0x0Fu, /**< 150mA IR LED current */ |
157 |
VCNL4020_LLD_LEDCURRENTREG_160_mA = 0x10u, /**< 160mA IR LED current */ |
158 |
VCNL4020_LLD_LEDCURRENTREG_170_mA = 0x11u, /**< 170mA IR LED current */ |
159 |
VCNL4020_LLD_LEDCURRENTREG_180_mA = 0x12u, /**< 180mA IR LED current */ |
160 |
VCNL4020_LLD_LEDCURRENTREG_190_mA = 0x13u, /**< 190mA IR LED current */ |
161 |
VCNL4020_LLD_LEDCURRENTREG_200_mA = 0x14u, /**< 200mA IR LED current */ |
162 |
VCNL4020_LLD_LEDCURRENTREG_DEFAULT = 0x02u, /**< default IR LED current (20mA) */ |
163 |
} vcnl4020_lld_ledcurrentreg_t; |
164 |
|
165 |
/**
|
166 |
* @brief Ambient light measurement parameters.
|
167 |
*/
|
168 |
typedef enum { |
169 |
VCNL4020_LLD_ALPARAMREG_CONTCONV = 0x80u, /**< Continuous conversion mode flag (set = enabled) */ |
170 |
VCNL4020_LLD_ALPARAMREG_CONTCONV_DEFAULT = 0x00u, /**< Continuous conversion mode flag default value (disabled)*/ |
171 |
VCNL4020_LLD_ALPARAMREG_RATE_MASK = 0x70u, /**< mask of bits to set the measurement rate */ |
172 |
VCNL4020_LLD_ALPARAMREG_RATE_1_HZ = 0x00u, /**< 1Hz measurement rate */ |
173 |
VCNL4020_LLD_ALPARAMREG_RATE_2_HZ = 0x10u, /**< 2Hz measurement rate */ |
174 |
VCNL4020_LLD_ALPARAMREG_RATE_3_HZ = 0x20u, /**< 3Hz measurement rate */ |
175 |
VCNL4020_LLD_ALPARAMREG_RATE_4_HZ = 0x30u, /**< 4Hz measurement rate */ |
176 |
VCNL4020_LLD_ALPARAMREG_RATE_5_HZ = 0x40u, /**< 5Hz measurement rate */ |
177 |
VCNL4020_LLD_ALPARAMREG_RATE_6_HZ = 0x50u, /**< 6Hz measurement rate */ |
178 |
VCNL4020_LLD_ALPARAMREG_RATE_8_HZ = 0x60u, /**< 8Hz measurement rate */ |
179 |
VCNL4020_LLD_ALPARAMREG_RATE_10_HZ = 0x70u, /**< 10Hz measurement rate */ |
180 |
VCNL4020_LLD_ALPARAMREG_RATE_DEFAULT = 0x10u, /**< default measurement rate (2Hz) */ |
181 |
VCNL4020_LLD_ALPARAMREG_AUTOOFFSET = 0x08u, /**< Auto offset compensation flag (set = enabled) */ |
182 |
VCNL4020_LLD_ALPARAMREG_AUTOOFFSET_DEFAULT = 0x00u, /**< Auto offset compensation flag default value (disabled) */ |
183 |
VCNL4020_LLD_ALPARAMREG_AVG_MASK = 0x07u, /**< mask of bits to set the number of measurements for averaging */ |
184 |
VCNL4020_LLD_ALPARAMREG_AVG_1_CONV = 0x00u, /**< 1 conversion per measurement */ |
185 |
VCNL4020_LLD_ALPARAMREG_AVG_2_CONV = 0x01u, /**< 2 conversions per measurement */ |
186 |
VCNL4020_LLD_ALPARAMREG_AVG_4_CONV = 0x02u, /**< 4 conversions per measurement */ |
187 |
VCNL4020_LLD_ALPARAMREG_AVG_8_CONV = 0x03u, /**< 8 conversions per measurement */ |
188 |
VCNL4020_LLD_ALPARAMREG_AVG_16_CONV = 0x04u, /**< 16 conversions per measurement */ |
189 |
VCNL4020_LLD_ALPARAMREG_AVG_32_CONV = 0x05u, /**< 32 conversions per measurement */ |
190 |
VCNL4020_LLD_ALPARAMREG_AVG_64_CONV = 0x06u, /**< 64 conversions per measurement */ |
191 |
VCNL4020_LLD_ALPARAMREG_AVG_128_CONV = 0x07u, /**< 128 conversions per measurement */ |
192 |
VCNL4020_LLD_ALPARAMREG_AVG_DEFAULT = 0x05u, /**< default number of conversions per measurement (32) */ |
193 |
} vcnl4020_lld_alparamreg_t; |
194 |
|
195 |
/**
|
196 |
* @brief Interrupt control commands.
|
197 |
*/
|
198 |
typedef enum { |
199 |
VCNL4020_LLD_INTCTRLREG_CNT_MASK = 0xE0u, /**< mask of bits to set the count value */ |
200 |
VCNL4020_LLD_INTCTRLREG_CNT_1 = 0x00u, /**< 1 measurement above/below the threshold will cause an interrupt */ |
201 |
VCNL4020_LLD_INTCTRLREG_CNT_2 = 0x20u, /**< 2 measurements above/below the threshold will cause an interrupt */ |
202 |
VCNL4020_LLD_INTCTRLREG_CNT_4 = 0x40u, /**< 4 measurements above/below the threshold will cause an interrupt */ |
203 |
VCNL4020_LLD_INTCTRLREG_CNT_8 = 0x60u, /**< 8 measurements above/below the threshold will cause an interrupt */ |
204 |
VCNL4020_LLD_INTCTRLREG_CNT_16 = 0x80u, /**< 16 measurements above/below the threshold will cause an interrupt */ |
205 |
VCNL4020_LLD_INTCTRLREG_CNT_32 = 0xA0u, /**< 32 measurements above/below the threshold will cause an interrupt */ |
206 |
VCNL4020_LLD_INTCTRLREG_CNT_64 = 0xC0u, /**< 64 measurements above/below the threshold will cause an interrupt */ |
207 |
VCNL4020_LLD_INTCTRLREG_CNT_128 = 0xE0u, /**< 128 measurements above/below the threshold will cause an interrupt */ |
208 |
VCNL4020_LLD_INTCTRLREG_PROXRDY_EN = 0x08u, /**< enable interrupts at proximity data ready */ |
209 |
VCNL4020_LLD_INTCTRLREG_ALSRDY_EN = 0x04u, /**< enable interrupt at ambient data ready */ |
210 |
VCNL4020_LLD_INTCTRLREG_THRES_EN = 0x02u, /**< enable interrupt when above/below threshold */ |
211 |
VCNL4020_LLD_INTCTRLREG_THRES_SEL = 0x01u, /**< select threshold intterrupt source (0 = proximity, 1 = ambient) */ |
212 |
} vcnl4020_lld_intctrlreg_t; |
213 |
|
214 |
/**
|
215 |
* @brief Interrupt status flags.
|
216 |
*/
|
217 |
typedef enum { |
218 |
VCNL4020_LLD_INTSTATUSREG_PROXRDY = 0x08u, /**< proximity data ready */ |
219 |
VCNL4020_LLD_INTSTATUSREG_ALSRDY = 0x04u, /**< ambient light measurement data ready */ |
220 |
VCNL4020_LLD_INTSTATUSREG_THLOW = 0x02u, /**< low threshold exceeded */ |
221 |
VCNL4020_LLD_INTSTATUSREG_THHIGH = 0x01u, /**< high threshold exceeded */ |
222 |
} vcnl4020_lld_intstatusreg_t; |
223 |
|
224 |
/**
|
225 |
* @brief Proximuty modulation timing adjustment parameters.
|
226 |
*/
|
227 |
typedef enum { |
228 |
VCNL4020_LLD_PMTADJREG_DELAY_MASK = 0xE0u, /**< mask of bits to set the modulation delay time */ |
229 |
VCNL4020_LLD_PMTADJREG_DELAY_DEFAULT = 0x00u, /**< default modulation delay time */ |
230 |
VCNL4020_LLD_PMTADJREG_PROXFREQ_MASK = 0x18u, /**< mask of bits to set the signal requency */ |
231 |
VCNL4020_LLD_PMTADJREG_PROXFREQ_390_625_KHz = 0x00u, /**< 390.625KHz signal frequency */ |
232 |
VCNL4020_LLD_PMTADJREG_PROXFREQ_781_25_KHz = 0x08u, /**< 781.25KHz signal frequency */ |
233 |
VCNL4020_LLD_PMTADJREG_PROXFREQ_1562_5_KHz = 0x10u, /**< 1.5625MHz signal frequency */ |
234 |
VCNL4020_LLD_PMTADJREG_PROXFREQ_3125_KHz = 0x18u, /**< 3.125MHz signal frequency */ |
235 |
VCNL4020_LLD_PMTADJREG_PROXFREQ_DEFAULT = 0x00u, /**< default signal frequency (390.625KHz) */ |
236 |
VCNL4020_LLD_PMTADJREG_DEAD_MASK = 0x07u, /**< mask of bits to set the modulation dead time */ |
237 |
VCNL4020_LLD_PMTADJREG_DEAD_DEFAULT = 0x01u, /**< default modulation dead time */ |
238 |
} vcnl4020_lld_pmtadjreg_t; |
239 |
|
240 |
/******************************************************************************/
|
241 |
/* MACROS */
|
242 |
/******************************************************************************/
|
243 |
|
244 |
/******************************************************************************/
|
245 |
/* EXTERN DECLARATIONS */
|
246 |
/******************************************************************************/
|
247 |
|
248 |
#ifdef __cplusplus
|
249 |
extern "C" { |
250 |
#endif
|
251 |
apalExitStatus_t vcnl4020_lld_readreg(const VCNL4020Driver* const vcnld, const vcnl4020_lld_regaddr_t reg, uint8_t* const data, const apalTime_t timeout); |
252 |
apalExitStatus_t vcnl4020_lld_writereg(const VCNL4020Driver* const vcnld, const vcnl4020_lld_regaddr_t reg, const uint8_t data, const apalTime_t timeout); |
253 |
|
254 |
apalExitStatus_t vcnl4020_lld_readals(const VCNL4020Driver* const vcnld, uint16_t* const als, const apalTime_t timeout); |
255 |
apalExitStatus_t vcnl4020_lld_readprox(const VCNL4020Driver* const vcnld, uint16_t* const prox, const apalTime_t timeout); |
256 |
apalExitStatus_t vcnl4020_lld_readalsandprox(const VCNL4020Driver* const vcnld, uint16_t* const als, uint16_t* const prox, const apalTime_t timeout); |
257 |
|
258 |
apalExitStatus_t vcnl4020_lld_readlth(const VCNL4020Driver* const vcnld, uint16_t* const th, const apalTime_t timeout); |
259 |
apalExitStatus_t vcnl4020_lld_readhth(const VCNL4020Driver* const vcnld, uint16_t* const th, const apalTime_t timeout); |
260 |
apalExitStatus_t vcnl4020_lld_readth(const VCNL4020Driver* const vcnld, uint16_t* const lth, uint16_t* const hth, const apalTime_t timeout); |
261 |
apalExitStatus_t vcnl4020_lld_writelth(const VCNL4020Driver* const vcnld, const uint16_t th, const apalTime_t timeout); |
262 |
apalExitStatus_t vcnl4020_lld_writehth(const VCNL4020Driver* const vcnld, const uint16_t th, const apalTime_t timeout); |
263 |
apalExitStatus_t vcnl4020_lld_writeth(const VCNL4020Driver* const vcnld, const uint16_t lth, const uint16_t hth, const apalTime_t timeout); |
264 |
#ifdef __cplusplus
|
265 |
} |
266 |
#endif
|
267 |
|
268 |
/******************************************************************************/
|
269 |
/* INLINE FUNCTIONS */
|
270 |
/******************************************************************************/
|
271 |
|
272 |
#endif /* AMIROLLD_VCNL4020_H */ |
273 |
|
274 |
/** @} */
|
275 |
|