32#include "../../SensorBuildOpt.h"
33#if !SENSORLIB_EXCLUDE_LTR553
35#include "../../platform/comm/I2CDeviceNoHal.hpp"
38static constexpr uint8_t LTR553_SLAVE_ADDRESS = 0x23;
265 uint8_t buffer[4] = {
299 uint8_t value = (uint8_t)(((alsIntegrationTime & 0x07) << 3) | (alsMeasurementRate & 0x07));
337 uint8_t buffer[2] = {0};
349 return (
int)buffer[0] | ((int)buffer[1] << 8);
367 uint8_t val = (count == 0) ? 0 : (count - 1);
442 uint8_t buffer[2] = {0};
448 *saturated = (buffer[1] & 0x80) == 0x80;
450 return (
int)buffer[0] | ((int)(buffer[1] & 0x07) << 8);
512 return (val >> 4) & 0x0F;
558 bool initImpl(uint8_t param)
bool clrRegBit(uint8_t reg, uint8_t bit)
bool getRegBit(uint8_t reg, uint8_t bit)
int readReg(uint8_t reg) const
int writeRegBuff(uint8_t reg, uint8_t *buf, size_t len)
int writeReg(uint8_t reg, uint8_t val)
int readRegBuff(uint8_t reg, uint8_t *buf, size_t len) const
int updateBits(uint8_t reg, uint8_t mask, uint8_t value_shifted)
bool setRegBit(uint8_t reg, uint8_t bit)
Driver for the LTR-553ALS-01 ambient light + proximity sensor (I2C).
static constexpr uint8_t REG_PS_N_PULSES
static constexpr uint8_t REG_PS_DATA_0
void setProximityThreshold(uint16_t low, uint16_t high)
Set PS threshold window.
~SensorLTR553()=default
Destructor.
PsRate
PS measurement rate (REG_PS_MEAS_RATE field).
int getManufacturerID()
Read Manufacturer ID (REG_MANUFAC_ID).
static constexpr uint8_t REG_ALS_MEAS_RATE
static constexpr uint8_t REG_PS_THRES_UP_1
static constexpr uint8_t REG_ALS_PS_STATUS
static constexpr uint8_t REG_PS_DATA_1
void enablePsIndicator()
Enable PS indicator.
static constexpr uint8_t REG_ALS_DATA_CH1_1
void setIRQLevel(IrqLevel level)
Set interrupt pin polarity.
static constexpr uint8_t REG_ALS_DATA_CH1_0
static constexpr uint8_t REG_PS_THRES_LOW_1
PsLedDuty
PS LED duty cycle (REG_PS_LED bits 4:3).
@ PS_LED_DUTY_100
100% (default)
static constexpr uint8_t REG_ALS_DATA_CH0_1
int getLightSensor(uint8_t ch)
Read ALS raw data from channel 0 or 1.
void setLightSensorThreshold(uint16_t low, uint16_t high)
Set ALS threshold window.
int getPartID()
Get Part ID (REG_PART_ID high nibble).
IrqLevel
Interrupt pin active level.
@ ALS_IRQ_ACTIVE_HIGH
INT pin is active-high.
@ ALS_IRQ_ACTIVE_LOW
INT pin is active-low (default)
static constexpr uint8_t REG_ALS_THRES_UP_1
void reset()
Software reset (REG_ALS_CONTR bit1).
void setLightSensorGain(LightSensorGain gain)
Set ALS gain.
static constexpr uint8_t REG_ALS_THRES_UP_0
static constexpr uint8_t REG_ALS_CONTR
static constexpr uint8_t REG_PS_LED
static constexpr uint8_t REG_ALS_DATA_CH0_0
static constexpr uint8_t REG_PS_THRES_UP_0
void setPsLedCurrent(PsLedCurrent cur)
Set PS LED peak current (REG_PS_LED bits 2:0).
void setPsLedPulsePeriod(PsLedPeriod period)
Set PS LED pulse modulation frequency (REG_PS_LED bits 7:5).
int getProximity(bool *saturated=NULL)
Read proximity raw data.
static constexpr uint8_t REG_PS_OFFSET_1
void setLightSensorPersists(uint8_t count)
Configure ALS interrupt persistence count.
PsLedPeriod
PS LED pulse modulation frequency (REG_PS_LED bits 7:5).
@ PS_LED_PLUSE_90KHZ
90kHz
@ PS_LED_PLUSE_50KHZ
50kHz
@ PS_LED_PLUSE_100KHZ
100kHz
@ PS_LED_PLUSE_40KHZ
40kHz
@ PS_LED_PLUSE_30KHZ
30kHz
@ PS_LED_PLUSE_80KHZ
80kHz
@ PS_LED_PLUSE_60KHZ
60kHz (default)
@ PS_LED_PLUSE_70KHZ
70kHz
bool psAvailable()
Check PS data ready flag.
void disableProximity()
Disable proximity measurement.
IrqMode
Interrupt trigger source.
@ ALS_IRQ_BOTH
Both ALS and PS measurement can trigger interrupt.
@ ALS_IRQ_DISABLE
No measurement can trigger interrupt (default)
@ ALS_IRQ_ONLY_ALS
Only ALS measurement can trigger interrupt.
@ ALS_IRQ_ONLY_PS
Only PS measurement can trigger interrupt.
void disableLightSensor()
Disable ALS measurement.
void enableProximity()
Enable proximity measurement.
void disableIRQ()
Disable all interrupt sources (mode bits = 0).
void setLightSensorRate(IntegrationTime alsIntegrationTime, MeasurementRate alsMeasurementRate)
Configure ALS integration time and measurement repeat rate.
void setProximityRate(PsRate rate)
Set PS measurement rate.
IntegrationTime
ALS integration time (REG_ALS_MEAS_RATE bits 5:3).
@ ALS_INTEGRATION_TIME_400MS
@ ALS_INTEGRATION_TIME_100MS
@ ALS_INTEGRATION_TIME_200MS
@ ALS_INTEGRATION_TIME_300MS
@ ALS_INTEGRATION_TIME_250MS
@ ALS_INTEGRATION_TIME_350MS
@ ALS_INTEGRATION_TIME_50MS
@ ALS_INTEGRATION_TIME_150MS
static constexpr uint8_t REG_PS_OFFSET_0
SensorLTR553()=default
Construct an uninitialized driver instance.
static constexpr uint8_t REG_MANUFAC_ID
void disablePsIndicator()
Disable PS indicator.
static constexpr uint8_t REG_INTERRUPT
void enableIRQ(IrqMode mode)
Enable interrupts and select which measurement sources can trigger them.
static constexpr uint8_t REG_PS_THRES_LOW_0
void setPsLedDutyCycle(PsLedDuty duty)
Set PS LED duty cycle (REG_PS_LED bits 4:3).
static constexpr uint8_t REG_ALS_THRES_LOW_0
void setPsLedPulses(uint8_t pulesNum)
Set number of PS LED pulses (REG_PS_N_PULSES bits 3:0).
LightSensorGain
ALS gain selection.
@ ALS_GAIN_1X
1 lux to 64k lux (default)
@ ALS_GAIN_48X
0.02 lux to 1.3k lux
@ ALS_GAIN_4X
0.25 lux to 16k lux
@ ALS_GAIN_8X
0.125 lux to 8k lux
@ ALS_GAIN_96X
0.01 lux to 600 lux
@ ALS_GAIN_2X
0.5 lux to 32k lux
static constexpr uint8_t REG_PS_MEAS_RATE
static constexpr uint8_t LTR553_DEFAULT_MAN_ID
Default manufacturer ID.
void setProximityPersists(uint8_t count)
Configure PS interrupt persistence count.
static constexpr uint8_t REG_INTERRUPT_PERSIST
int getRevisionID()
Get Revision ID (REG_PART_ID low nibble).
void enableLightSensor()
Enable ALS measurement.
static constexpr uint8_t REG_PART_ID
MeasurementRate
ALS measurement repeat rate (REG_ALS_MEAS_RATE bits 2:0).
@ ALS_MEASUREMENT_TIME_500MS
@ ALS_MEASUREMENT_TIME_50MS
@ ALS_MEASUREMENT_TIME_2000MS
@ ALS_MEASUREMENT_TIME_1000MS
@ ALS_MEASUREMENT_TIME_100MS
@ ALS_MEASUREMENT_TIME_200MS
static constexpr uint8_t REG_PS_CONTR
PsLedCurrent
PS LED peak current selection (REG_PS_LED bits 2:0).
static constexpr uint8_t REG_ALS_THRES_LOW_1
constexpr uint8_t _lowByte(uint16_t w)
constexpr uint8_t _highByte(uint16_t w)