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