Expand description
SyscallDriver for the STMicro HTS221 relative humidity and temperature sensor using the I2C bus.
https://www.st.com/en/mems-and-sensors/hts221.html
The HTS221 is an ultra-compact sensor for relative humidity and temperature. It includes a sensing element and a mixed signal ASIC to provide the measurement information through digital serial interfaces. The sensing element consists of a polymer dielectric planar capacitor structure capable of detecting relative humidity variations and is manufactured using a dedicated ST process.
§Driver Semantics
This driver exposes the HTS221’s temperature and humidity functionality via the TemperatureDriver and HumidityDriver HIL interfaces. The driver does not attempt to support multiple concurrent requests for temperature or multiple concurrent requests for humidity, but does support a concurrent request each for temperature and humidity. It is not the role of this driver to provide virtualization to multiple clients, but it does provide virtualization to allow it to be used from both a temperature and humidity driver.
Specifically, the implementation always reads both temperature and humidity (the chip always provides both anyway). If the driver receives a request for either temperature or humidity while a request for the other is outstanding, both will be returned to their respective clients when the I2C transaction is completed, rather than performing two separate transactions.
§Polling for data readiness
The HTS221 has a data-ready line that can provide an interrupt when temperature and humidity data is ready. However, the primary board (the Nano 33 BLE Sense) this driver was developed for does not connect that line to the MCU and, typically, data is ready within a couple read/write I2C transactions. So, the driver polls the status register instead. This is probably not optimal from an energy perspective, so should a use case for an interrupt driven interface arise, some brave soul should modify the driver to support both.
§Limitations
The driver uses floating point math to adjust readings based on the calibration registers. This is accurate and matches the chip’s datasheet’s recommendation, but could increase code size significantly in platforms that do not have hardware support for floating point operations.
§Usage
let hts221_i2c = static_init!(
capsules::virtual_i2c::I2CDevice,
capsules::virtual_i2c::I2CDevice::new(i2c_bus, 0x5f));
let hts221 = static_init!(
capsules::hts221::Hts221<'static>,
capsules::hts221::Hts221::new(hts221_i2c,
&mut capsules::hts221::BUFFER));
hts221_i2c.set_client(hts221);