Skip to content
/ i2c-reg Public

Create registers for reading and writing with I2C interface.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

lukwol/i2c-reg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

i2c-reg

Create registers for reading and writing with I2C interface.

Features

Effortless creation of I2C read only/write only/read write registers with various sizes.

#[derive(Register, I2cReadRegister, I2cWriteRegister)]
#[address = 0b1110]
#[size = 2]
struct TemperatureRegister;

Typesafe conversion between raw bytes and actual values when reading from/writing to registers via interface.

type Raw = <TemperatureRegister as Register>::Raw;

struct Temperature(u16);

impl Into<Raw> for Temperature {
    fn into(self) -> Raw {
        self.0.to_be_bytes()
    }
}

impl From<Raw> for Temperature {
    fn from(raw: Raw) -> Self {
        Temperature(u16::from_be_bytes(raw))
    }
}

let mut interface = I2cInterface { i2c, address: 0b0110 };
interface.write_register(TemperatureRegister, Temperature(42)).unwrap();
let temperature: Temperature = interface.read_register(TemperatureRegister).unwrap();
assert_eq!(Temperature(42), temperature);

Examples

License

Licensed under either of

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.

About

Create registers for reading and writing with I2C interface.

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages