Expand description
§opt40xx
Barebones driver for OPT40xx ambient light sensor family based on embedded-hal traits.
This sensor family uses almost the same register map for all its members.
Each member differ by:
- Calculation formula of lux values.
- Definition of their result registers (FIFO or different channel or both).
- Output interrupt mechanism.
It’s possible to fully support each member individually by introducing member marker generics. This driver does not track sensor state, it exposes an interface to set whole registers instead, to keep things simple.
Implemented:
-
Read the measurement in raw value. See:
read_raw(). -
Read the conversion status. See:
read_status(). -
Configure main and secondary configurations. See:
set_config_a()andset_config_b(). -
Read the device ID. See:
read_device_id(). - Set the low and high limits. (Low level side is implemented but not exposed).
§Usage
use opt40xx::*;
let mut i2c = // i2c bus that implements e-hal trait.
let mut sensor = Sensor::new(i2c, Address::Gnd);
sensor.set_config_a(ConfigA {
operating_mode: OperatingMode::Continuous,
conv_time: ConversionTime::Ms25,
..Default::default()
})
.unwrap();
loop {
let measurement = sensor.read_raw(Channel::Ch0, BurstRead::Enabled).unwrap();
info!("measurement: {:?}, count: {:?}", measurement.0, measurement.1);
}§License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT) at your option.
§Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
§Feature flags
defmt— Usedefmtfor logging
Structs§
- ConfigA
- Configuration settings for register A.
- ConfigB
- Configuration settings for register B.
- Sensor
- Sensor driver
- Status
Enums§
- Address
- Possible device addresses
- Burst
Read - I2C Burst Read mode
- Channel
- Conversion
Error - Driver data conversion error
- Conversion
Time - Conversion time
- Error
- All possible errors
- Fault
Count - Fault count
- IntDirection
- Interrupt pin direction
- IntPolarity
- Interrupt pin polarity
- Latch
- Interrupt reporting mode
- Operating
Mode - Operating mode
- Quick
Wake - Quick Wake
- Range
- Light range