Statistics
| Branch: | Tag: | Revision:

amiro-lld / include / VCNL4020 / v1 / alld_VCNL4020_v1.h @ 01828616

History | View | Annotate | Download (15.91 KB)

1
/*
2
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2019  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_v1.h
21
 * @brief   Proximity Sensor macros and structures.
22
 *
23
 * @addtogroup lld_proximity
24
 * @{
25
 */
26

    
27
#ifndef AMIROLLD_VCNL4020_V1_H
28
#define AMIROLLD_VCNL4020_V1_H
29

    
30
#include <amiro-lld.h>
31

    
32
#if (defined(AMIROLLD_CFG_VCNL4020) && (AMIROLLD_CFG_VCNL4020 == 1)) || defined(__DOXYGEN__)
33

    
34
/******************************************************************************/
35
/* CONSTANTS                                                                  */
36
/******************************************************************************/
37

    
38
/**
39
 * @brief Fixed slave address to access the VCNL4020 via I2C.
40
 */
41
#define VCNL4020_LLD_I2C_ADDR           0x13u
42

    
43
/**
44
 * @brief Maximum frequency for I2C communication.
45
 */
46
#define VCNL4020_LLD_I2C_MAXFREQUENCY   3400000
47

    
48
/**
49
 * @brief A falling edge indicates an interrupt.
50
 */
51
#define VCNL4020_LLD_INT_EDGE           APAL_GPIO_EDGE_FALLING
52

    
53
/******************************************************************************/
54
/* SETTINGS                                                                   */
55
/******************************************************************************/
56

    
57
/******************************************************************************/
58
/* CHECKS                                                                     */
59
/******************************************************************************/
60

    
61
/******************************************************************************/
62
/* DATA STRUCTURES AND TYPES                                                  */
63
/******************************************************************************/
64

    
65
/**
66
 * @brief The VCNL4020 driver struct
67
 */
68
typedef struct {
69
  apalI2CDriver_t* i2cd;      /**< @brief The I2C Driver.     */
70
} VCNL4020Driver;
71

    
72
/**
73
 * @brief Adresses for the several I/O registers of the VCNL4020.
74
 */
75
typedef enum {
76
  VCNL4020_LLD_REGADDR_CMD          = 0x80u, /**< command register */
77
  VCNL4020_LLD_REGADDR_IDREV        = 0x81u, /**< product ID revision register */
78
  VCNL4020_LLD_REGADDR_PROXRATE     = 0x82u, /**< proximity rate register */
79
  VCNL4020_LLD_REGADDR_LEDCURRENT   = 0x83u, /**< IR LED current register */
80
  VCNL4020_LLD_REGADDR_ALPARAM      = 0x84u, /**< ambient light parameter register */
81
  VCNL4020_LLD_REGADDR_ALRES_HIGH   = 0x85u, /**< ambient light result register (high byte) */
82
  VCNL4020_LLD_REGADDR_ALRES_LOW    = 0x86u, /**< ambient light result register (low byte) */
83
  VCNL4020_LLD_REGADDR_PROXRES_HIGH = 0x87u, /**< proximity result register (high byte) */
84
  VCNL4020_LLD_REGADDR_PROXRES_LOW  = 0x88u, /**< proximity result register (low byte) */
85
  VCNL4020_LLD_REGADDR_INTCTRL      = 0x89u, /**< interrupt control register */
86
  VCNL4020_LLD_REGADDR_LTH_HIGH     = 0x8Au, /**< low threshold register (high byte) */
87
  VCNL4020_LLD_REGADDR_LTH_LOW      = 0x8Bu, /**< low threshold register (low byte) */
88
  VCNL4020_LLD_REGADDR_HTH_HIGH     = 0x8Cu, /**< high threshold register (high byte) */
89
  VCNL4020_LLD_REGADDR_HTH_LOW      = 0x8Du, /**< high threshold register (low byte) */
90
  VCNL4020_LLD_REGADDR_INTSTATUS    = 0x8Eu, /**< interrupt status register */
91
  VCNL4020_LLD_REGADDR_PMTADJ       = 0x8Fu, /**< prximity modulator timing adjustment */
92
  VCNL4020_LLD_REGADDR_AMBIRLEVEL   = 0x90u, /**< ambient IR light level register (not intended to be used) */
93
} vcnl4020_lld_regaddr_t;
94

    
95
/**
96
 * @brief Commands to control the VCNL4020.
97
 */
98
typedef enum {
99
  VCNL4020_LLD_CMDREG_CFGLOCK   = 0x80u, /**< config lock (read only, constant = 1) */
100
  VCNL4020_LLD_CMDREG_ALSRDY    = 0x40u, /**< ambient light measurement data ready flag (read only) */
101
  VCNL4020_LLD_CMDREG_PROXRDY   = 0x20u, /**< proximity measurement data ready flag (read only) */
102
  VCNL4020_LLD_CMDREG_ALSOD     = 0x10u, /**< start single on-demand ambient light measurement */
103
  VCNL4020_LLD_CMDREG_PROXOD    = 0x08u, /**< start single on-demand proximity measurement */
104
  VCNL4020_LLD_CMDREG_ALSEN     = 0x04u, /**< start periodic ambient light measurement */
105
  VCNL4020_LLD_CMDREG_PROXEN    = 0x02u, /**< start periodic proximity measurement */
106
  VCNL4020_LLD_CMDREG_SELFTIMED = 0x01u, /**< enable state-machine and clock for periodic measurement */
107
} vcnl4020_lld_cmdreg_t;
108

    
109
/**
110
 * @brief Masks to read the prodict ID revision register.
111
 */
112
typedef enum {
113
  VCNL4020_LLD_IDREVREG_ID_MASK   = 0xF0u, /**< product ID (read only, constant = 2) */
114
  VCNL4020_LLD_IDREVREG_REV_MASK  = 0x0Fu, /**< revision ID (read only, constant = 1) */
115
} vcnl4020_lld_idrevreg_t;
116

    
117
/**
118
 * @brief Frequencies for the proximity sensor of the VCNL4020.
119
 * @note  Frequencies are calculated by the formula
120
 *        freq = 250Hz / (2 ^ (7 - <value>))
121
 */
122
typedef enum {
123
  VCNL4020_LLD_PROXRATEREG_MASK       = 0x07u, /**< mask of settable bits */
124
  VCNL4020_LLD_PROXRATEREG_1_95_HZ    = 0x00u, /**< 1.95Hz sampling rate */
125
  VCNL4020_LLD_PROXRATEREG_3_90625_HZ = 0x01u, /**< 3.90625Hz sampling rate */
126
  VCNL4020_LLD_PROXRATEREG_7_8125_HZ  = 0x02u, /**< 7.8125Hz sampling rate */
127
  VCNL4020_LLD_PROXRATEREG_15_625_HZ  = 0x03u, /**< 16.625Hz sampling rate */
128
  VCNL4020_LLD_PROXRATEREG_31_25_HZ   = 0x04u, /**< 31.25Hz sampling rate */
129
  VCNL4020_LLD_PROXRATEREG_62_5_HZ    = 0x05u, /**< 62.5Hz sampling rate */
130
  VCNL4020_LLD_PROXRATEREG_125_HZ     = 0x06u, /**< 125Hz sampling rate */
131
  VCNL4020_LLD_PROXRATEREG_250_HZ     = 0x07u, /**< 250Hz sampling rate */
132
  VCNL4020_LLD_PROXRATEREG_DEFAULT    = 0x00u, /**< default sampling rate (1.95Hz) */
133
} vcnl4020_lld_proxratereg_t;
134

    
135
/**
136
 * @brief Current for the emmitting IR LED.
137
 * @note  The Current is calculated by the formula
138
 *        curr = <value> * 10mA
139
 */
140
typedef enum {
141
  VCNL4020_LLD_LEDCURRENTREG_FUSEID_MASK  = 0xC0u, /**< fuse program revision (read only) */
142
  VCNL4020_LLD_LEDCURRENTREG_CURRENT_MASK = 0x3Fu, /**< mask of bits to set the current */
143
  VCNL4020_LLD_LEDCURRENTREG_0_mA         = 0x00u, /**< 0mA IR LED current */
144
  VCNL4020_LLD_LEDCURRENTREG_10_mA        = 0x01u, /**< 10mA IR LED current */
145
  VCNL4020_LLD_LEDCURRENTREG_20_mA        = 0x02u, /**< 20mA IR LED current */
146
  VCNL4020_LLD_LEDCURRENTREG_30_mA        = 0x03u, /**< 30mA IR LED current */
147
  VCNL4020_LLD_LEDCURRENTREG_40_mA        = 0x04u, /**< 40mA IR LED current */
148
  VCNL4020_LLD_LEDCURRENTREG_50_mA        = 0x05u, /**< 50mA IR LED current */
149
  VCNL4020_LLD_LEDCURRENTREG_60_mA        = 0x06u, /**< 60mA IR LED current */
150
  VCNL4020_LLD_LEDCURRENTREG_70_mA        = 0x07u, /**< 70mA IR LED current */
151
  VCNL4020_LLD_LEDCURRENTREG_80_mA        = 0x08u, /**< 80mA IR LED current */
152
  VCNL4020_LLD_LEDCURRENTREG_90_mA        = 0x09u, /**< 90mA IR LED current */
153
  VCNL4020_LLD_LEDCURRENTREG_100_mA       = 0x0Au, /**< 100mA IR LED current */
154
  VCNL4020_LLD_LEDCURRENTREG_110_mA       = 0x0Bu, /**< 110mA IR LED current */
155
  VCNL4020_LLD_LEDCURRENTREG_120_mA       = 0x0Cu, /**< 120mA IR LED current */
156
  VCNL4020_LLD_LEDCURRENTREG_130_mA       = 0x0Du, /**< 130mA IR LED current */
157
  VCNL4020_LLD_LEDCURRENTREG_140_mA       = 0x0Eu, /**< 140mA IR LED current */
158
  VCNL4020_LLD_LEDCURRENTREG_150_mA       = 0x0Fu, /**< 150mA IR LED current */
159
  VCNL4020_LLD_LEDCURRENTREG_160_mA       = 0x10u, /**< 160mA IR LED current */
160
  VCNL4020_LLD_LEDCURRENTREG_170_mA       = 0x11u, /**< 170mA IR LED current */
161
  VCNL4020_LLD_LEDCURRENTREG_180_mA       = 0x12u, /**< 180mA IR LED current */
162
  VCNL4020_LLD_LEDCURRENTREG_190_mA       = 0x13u, /**< 190mA IR LED current */
163
  VCNL4020_LLD_LEDCURRENTREG_200_mA       = 0x14u, /**< 200mA IR LED current */
164
  VCNL4020_LLD_LEDCURRENTREG_DEFAULT      = 0x02u, /**< default IR LED current (20mA) */
165
} vcnl4020_lld_ledcurrentreg_t;
166

    
167
/**
168
 * @brief Ambient light measurement parameters.
169
 */
170
typedef enum {
171
  VCNL4020_LLD_ALPARAMREG_CONTCONV            = 0x80u, /**< Continuous conversion mode flag (set = enabled) */
172
  VCNL4020_LLD_ALPARAMREG_CONTCONV_DEFAULT    = 0x00u, /**< Continuous conversion mode flag default value (disabled)*/
173
  VCNL4020_LLD_ALPARAMREG_RATE_MASK           = 0x70u, /**< mask of bits to set the measurement rate */
174
  VCNL4020_LLD_ALPARAMREG_RATE_1_HZ           = 0x00u, /**< 1Hz measurement rate */
175
  VCNL4020_LLD_ALPARAMREG_RATE_2_HZ           = 0x10u, /**< 2Hz measurement rate */
176
  VCNL4020_LLD_ALPARAMREG_RATE_3_HZ           = 0x20u, /**< 3Hz measurement rate */
177
  VCNL4020_LLD_ALPARAMREG_RATE_4_HZ           = 0x30u, /**< 4Hz measurement rate */
178
  VCNL4020_LLD_ALPARAMREG_RATE_5_HZ           = 0x40u, /**< 5Hz measurement rate */
179
  VCNL4020_LLD_ALPARAMREG_RATE_6_HZ           = 0x50u, /**< 6Hz measurement rate */
180
  VCNL4020_LLD_ALPARAMREG_RATE_8_HZ           = 0x60u, /**< 8Hz measurement rate */
181
  VCNL4020_LLD_ALPARAMREG_RATE_10_HZ          = 0x70u, /**< 10Hz measurement rate */
182
  VCNL4020_LLD_ALPARAMREG_RATE_DEFAULT        = 0x10u, /**< default measurement rate (2Hz) */
183
  VCNL4020_LLD_ALPARAMREG_AUTOOFFSET          = 0x08u, /**< Auto offset compensation flag (set = enabled) */
184
  VCNL4020_LLD_ALPARAMREG_AUTOOFFSET_DEFAULT  = 0x00u, /**< Auto offset compensation flag default value (disabled) */
185
  VCNL4020_LLD_ALPARAMREG_AVG_MASK            = 0x07u, /**< mask of bits to set the number of measurements for averaging */
186
  VCNL4020_LLD_ALPARAMREG_AVG_1_CONV          = 0x00u, /**< 1 conversion per measurement */
187
  VCNL4020_LLD_ALPARAMREG_AVG_2_CONV          = 0x01u, /**< 2 conversions per measurement */
188
  VCNL4020_LLD_ALPARAMREG_AVG_4_CONV          = 0x02u, /**< 4 conversions per measurement */
189
  VCNL4020_LLD_ALPARAMREG_AVG_8_CONV          = 0x03u, /**< 8 conversions per measurement */
190
  VCNL4020_LLD_ALPARAMREG_AVG_16_CONV         = 0x04u, /**< 16 conversions per measurement */
191
  VCNL4020_LLD_ALPARAMREG_AVG_32_CONV         = 0x05u, /**< 32 conversions per measurement */
192
  VCNL4020_LLD_ALPARAMREG_AVG_64_CONV         = 0x06u, /**< 64 conversions per measurement */
193
  VCNL4020_LLD_ALPARAMREG_AVG_128_CONV        = 0x07u, /**< 128 conversions per measurement */
194
  VCNL4020_LLD_ALPARAMREG_AVG_DEFAULT         = 0x05u, /**< default number of conversions per measurement (32) */
195
} vcnl4020_lld_alparamreg_t;
196

    
197
/**
198
 * @brief Interrupt control commands.
199
 */
200
typedef enum {
201
  VCNL4020_LLD_INTCTRLREG_CNT_MASK    = 0xE0u, /**< mask of bits to set the count value */
202
  VCNL4020_LLD_INTCTRLREG_CNT_1       = 0x00u, /**< 1 measurement above/below the threshold will cause an interrupt */
203
  VCNL4020_LLD_INTCTRLREG_CNT_2       = 0x20u, /**< 2 measurements above/below the threshold will cause an interrupt */
204
  VCNL4020_LLD_INTCTRLREG_CNT_4       = 0x40u, /**< 4 measurements above/below the threshold will cause an interrupt */
205
  VCNL4020_LLD_INTCTRLREG_CNT_8       = 0x60u, /**< 8 measurements above/below the threshold will cause an interrupt */
206
  VCNL4020_LLD_INTCTRLREG_CNT_16      = 0x80u, /**< 16 measurements above/below the threshold will cause an interrupt */
207
  VCNL4020_LLD_INTCTRLREG_CNT_32      = 0xA0u, /**< 32 measurements above/below the threshold will cause an interrupt */
208
  VCNL4020_LLD_INTCTRLREG_CNT_64      = 0xC0u, /**< 64 measurements above/below the threshold will cause an interrupt */
209
  VCNL4020_LLD_INTCTRLREG_CNT_128     = 0xE0u, /**< 128 measurements above/below the threshold will cause an interrupt */
210
  VCNL4020_LLD_INTCTRLREG_PROXRDY_EN  = 0x08u, /**< enable interrupts at proximity data ready */
211
  VCNL4020_LLD_INTCTRLREG_ALSRDY_EN   = 0x04u, /**< enable interrupt at ambient data ready */
212
  VCNL4020_LLD_INTCTRLREG_THRES_EN    = 0x02u, /**< enable interrupt when above/below threshold */
213
  VCNL4020_LLD_INTCTRLREG_THRES_SEL   = 0x01u, /**< select threshold intterrupt source (0 = proximity, 1 = ambient) */
214
} vcnl4020_lld_intctrlreg_t;
215

    
216
/**
217
 * @brief Interrupt status flags.
218
 */
219
typedef enum {
220
  VCNL4020_LLD_INTSTATUSREG_PROXRDY = 0x08u, /**< proximity data ready */
221
  VCNL4020_LLD_INTSTATUSREG_ALSRDY  = 0x04u, /**< ambient light measurement data ready */
222
  VCNL4020_LLD_INTSTATUSREG_THLOW   = 0x02u, /**< low threshold exceeded */
223
  VCNL4020_LLD_INTSTATUSREG_THHIGH  = 0x01u, /**< high threshold exceeded */
224
} vcnl4020_lld_intstatusreg_t;
225

    
226
/**
227
 * @brief Proximuty modulation timing adjustment parameters.
228
 */
229
typedef enum {
230
  VCNL4020_LLD_PMTADJREG_DELAY_MASK           = 0xE0u, /**< mask of bits to set the modulation delay time */
231
  VCNL4020_LLD_PMTADJREG_DELAY_DEFAULT        = 0x00u, /**< default modulation delay time */
232
  VCNL4020_LLD_PMTADJREG_PROXFREQ_MASK        = 0x18u, /**< mask of bits to set the signal requency */
233
  VCNL4020_LLD_PMTADJREG_PROXFREQ_390_625_KHz = 0x00u, /**< 390.625KHz signal frequency */
234
  VCNL4020_LLD_PMTADJREG_PROXFREQ_781_25_KHz  = 0x08u, /**< 781.25KHz signal frequency */
235
  VCNL4020_LLD_PMTADJREG_PROXFREQ_1562_5_KHz  = 0x10u, /**< 1.5625MHz signal frequency */
236
  VCNL4020_LLD_PMTADJREG_PROXFREQ_3125_KHz    = 0x18u, /**< 3.125MHz signal frequency */
237
  VCNL4020_LLD_PMTADJREG_PROXFREQ_DEFAULT     = 0x00u, /**< default signal frequency (390.625KHz) */
238
  VCNL4020_LLD_PMTADJREG_DEAD_MASK            = 0x07u, /**< mask of bits to set the modulation dead time */
239
  VCNL4020_LLD_PMTADJREG_DEAD_DEFAULT         = 0x01u, /**< default modulation dead time */
240
} vcnl4020_lld_pmtadjreg_t;
241

    
242
/******************************************************************************/
243
/* MACROS                                                                     */
244
/******************************************************************************/
245

    
246
/******************************************************************************/
247
/* EXTERN DECLARATIONS                                                        */
248
/******************************************************************************/
249

    
250
#ifdef __cplusplus
251
extern "C" {
252
#endif
253
  apalExitStatus_t vcnl4020_lld_readreg(const VCNL4020Driver* const vcnld, const vcnl4020_lld_regaddr_t reg, uint8_t* const data, const apalTime_t timeout);
254
  apalExitStatus_t vcnl4020_lld_writereg(const VCNL4020Driver* const vcnld, const vcnl4020_lld_regaddr_t reg, const uint8_t data, const apalTime_t timeout);
255

    
256
  apalExitStatus_t vcnl4020_lld_readals(const VCNL4020Driver* const vcnld, uint16_t* const als, const apalTime_t timeout);
257
  apalExitStatus_t vcnl4020_lld_readprox(const VCNL4020Driver* const vcnld, uint16_t* const prox, const apalTime_t timeout);
258
  apalExitStatus_t vcnl4020_lld_readalsandprox(const VCNL4020Driver* const vcnld, uint16_t* const als, uint16_t* const prox, const apalTime_t timeout);
259

    
260
  apalExitStatus_t vcnl4020_lld_readlth(const VCNL4020Driver* const vcnld, uint16_t* const th, const apalTime_t timeout);
261
  apalExitStatus_t vcnl4020_lld_readhth(const VCNL4020Driver* const vcnld, uint16_t* const th, const apalTime_t timeout);
262
  apalExitStatus_t vcnl4020_lld_readth(const VCNL4020Driver* const vcnld, uint16_t* const lth, uint16_t* const hth, const apalTime_t timeout);
263
  apalExitStatus_t vcnl4020_lld_writelth(const VCNL4020Driver* const vcnld, const uint16_t th, const apalTime_t timeout);
264
  apalExitStatus_t vcnl4020_lld_writehth(const VCNL4020Driver* const vcnld, const uint16_t th, const apalTime_t timeout);
265
  apalExitStatus_t vcnl4020_lld_writeth(const VCNL4020Driver* const vcnld, const uint16_t lth, const uint16_t hth, const apalTime_t timeout);
266
#ifdef __cplusplus
267
}
268
#endif
269

    
270
/******************************************************************************/
271
/* INLINE FUNCTIONS                                                           */
272
/******************************************************************************/
273

    
274
#endif /* defined(AMIROLLD_CFG_VCNL4020) && (AMIROLLD_CFG_VCNL4020 == 1) */
275

    
276
#endif /* AMIROLLD_VCNL4020_V1_H */
277

    
278
/** @} */