sensirion_i2c/
lib.rs

1//! Library with common functionality for I2C based sensors from Sensirion, based on the
2//! `embedded-hal` traits.
3//!
4//! ## Usage
5//!
6//! ### CRC8 calculation / validation
7//!
8//! ```
9//! use sensirion_i2c::crc8;
10//!
11//! let data = [0xbe, 0xef];
12//! let crc = crc8::calculate(&data);
13//!
14//! let data = [0xbe, 0xef, crc];
15//! assert_eq!(Ok(()), crc8::validate(&data));
16//! ```
17//!
18//! ### I2C
19//!
20//! The I2C helpers work with any `embedded_hal::i2c` implementation.
21//!
22//! ```
23//! use embedded_hal_mock::eh1::i2c::{Mock as I2cMock, Transaction as I2cTransaction};
24//! use sensirion_i2c::i2c;
25//!
26//! let expectations = [I2cTransaction::write(0x12, vec![0x34, 0x56])];
27//! let mut i2c_mock = I2cMock::new(&expectations);
28//! i2c::write_command_u16(&mut i2c_mock, 0x12, 0x3456);
29//! i2c_mock.done();
30//! ```
31//!
32//! #### `embedded-hal-async`
33//!
34//! The `i2c_async` module provides versions of the I2C helpers in this crate
35//! that use the [`embedded-hal-async`
36//! crate](https://crates.io/crates/embedded-hal-async), rather than the
37//! blocking I2C traits from `embedded-hal`.
38//!
39//! This module is only available when the `embedded-hal-async`
40//! Cargo feature is enabled.
41
42#![deny(unsafe_code)]
43#![cfg_attr(not(test), no_std)]
44#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
45
46pub mod crc8;
47pub mod i2c;
48#[cfg(feature = "embedded-hal-async")]
49pub mod i2c_async;