~chmanie/ad5328

8300d35a83976f30dfc9781f0c1200d9a889cd05 — chmanie 4 months ago a47c95c main v0.1.1
Implement From for Channel
2 files changed, 17 insertions(+), 1 deletions(-)

M Cargo.toml
M src/lib.rs
M Cargo.toml => Cargo.toml +1 -1
@@ 4,7 4,7 @@ description = "A rust-embedded driver for the Analog Devices ad5328 DAC"
categories = ["embedded", "hardware-support", "no-std"]
documentation = "https://docs.rs/ad5328"
authors = ["Chris Maniewski"]
version = "0.1.0"
version = "0.1.1"
edition = "2021"
readme = "README.md"
license = "MIT OR Apache-2.0"

M src/lib.rs => src/lib.rs +16 -0
@@ 30,6 30,22 @@ impl From<Channel> for u8 {
    }
}

impl From<u8> for Channel {
    fn from(chan: u8) -> Self {
        match chan {
            0 => Channel::A,
            1 => Channel::B,
            2 => Channel::C,
            3 => Channel::D,
            4 => Channel::E,
            5 => Channel::F,
            6 => Channel::G,
            7 => Channel::H,
            _ => panic!("Not a valid Ad5328 channel"),
        }
    }
}

impl Channel {
    fn as_u16(&self) -> u16 {
        (*self as u16) << 12