diff --git a/.github/workflows/branches.yml b/.github/workflows/branches.yml deleted file mode 100644 index bbdf1bb..0000000 --- a/.github/workflows/branches.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: Branches - -on: - push: - branches-ignore: - - "main" - -env: - CARGO_TERM_COLOR: always - -jobs: - ci: - runs-on: ubuntu-latest - - strategy: - matrix: - rust: - - stable - - beta - - nightly - - steps: - - uses: actions/checkout@v2 - - - uses: actions-rs/toolchain@v1 - name: installing toolchain - with: - profile: default - toolchain: ${{ matrix.rust }} - override: true - components: rustfmt, clippy - - - uses: actions-rs/cargo@v1 - name: build - with: - command: build - args: --release - - - uses: actions-rs/cargo@v1 - name: fmt - with: - command: fmt - args: --all -- --check - - - uses: actions-rs/cargo@v1 - name: clippy - with: - command: clippy - args: -- -D warnings \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 25dda45..0865241 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,9 +1,7 @@ -name: Main +name: CI Build on: push: - branches: - - "main" env: CARGO_TERM_COLOR: always @@ -20,30 +18,24 @@ jobs: - nightly steps: - - uses: actions/checkout@v2 - - - uses: actions-rs/toolchain@v1 - name: installing toolchain - with: - profile: default - toolchain: ${{ matrix.rust }} - override: true - components: rustfmt, clippy - - - uses: actions-rs/cargo@v1 - name: build - with: - command: build - args: --release - - - uses: actions-rs/cargo@v1 - name: fmt - with: - command: fmt - args: --all -- --check - - - uses: actions-rs/cargo@v1 - name: clippy - with: - command: clippy - args: -- -D warnings \ No newline at end of file + - uses: actions/checkout@v4 + + - name: Set up Rust toolchain + run: | + rustup toolchain install ${{ matrix.rust }} + + - name: Build examples + run: | + cargo build --examples + + - name: Build release config + run: | + cargo build --release + + - name: Check formatting + run: | + cargo fmt --all -- --check + + - name: Check formatting + run: | + cargo clippy -- -D warnings diff --git a/Cargo.toml b/Cargo.toml index 34be231..74cceb1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,10 @@ documentation = "https://docs.rs/crate/pac194x/" embedded-hal = "0.2" paste = "1.0" +# For the example +[dev-dependencies] +linux-embedded-hal = "0.3.2" + [dependencies.packed_struct] version = "0.10" default-features = false diff --git a/README.md b/README.md index ca2d8ff..d9ce2f3 100644 --- a/README.md +++ b/README.md @@ -17,25 +17,10 @@ This driver allows you to: ## Usage To use this driver, import this crate and an `embedded_hal` implementation, -then instantiate the appropriate device. - -```rust -use linux_embedded_hal::I2cdev; -use pac194x::{PAC194X, AddrSelect}; - -const SENSE_RESISTOR: f32 = 0.5; - -fn main() { - let i2c = I2cdev::new("/dev/i2c-1").unwrap(); - let mut sensor = PAC194X::new(i2c, AddrSelect::GND).unwrap(); - loop { - let bus_voltage_1 = sensor.read_bus_voltage_n(1).unwrap(); - let sense_voltage_1 = sensor.read_sense_voltage_n(1).unwrap(); - println!("Channel 1 has a bus voltage of: {:.2} V", bus_voltage_1); - println!("Channel 1 is pulling a current of: {:.2} A", sense_voltage_1 / SENSE_RESISTOR); - } -} -``` +then instantiate the appropriate device. See the `examples` folder for example code. + +Run it on Linux with `cargo build --examples linux && sudo ./target/debug/examples/linux`. +It's hardcoded to bus `/dev/i2c-3` and I2C address 0b10000 (grounded). ## Discussion diff --git a/examples/linux.rs b/examples/linux.rs new file mode 100644 index 0000000..db46f66 --- /dev/null +++ b/examples/linux.rs @@ -0,0 +1,28 @@ +use linux_embedded_hal::I2cdev; +use pac194x::{AddrSelect, PAC194X}; +use std::{thread, time::Duration}; + +const SENSE_RESISTOR: f32 = 0.5; + +fn main() { + let i2c = I2cdev::new("/dev/i2c-3").unwrap(); + let mut sensor = PAC194X::new(i2c, AddrSelect::GND); + loop { + for channel in 1..5 { + let bus_voltage = sensor.read_bus_voltage_n(channel).unwrap(); + let sense_voltage = sensor.read_sense_voltage_n(channel).unwrap(); + print!( + "CH{} {:.2}V, {:.2}A, ", + channel, + bus_voltage, + sense_voltage / SENSE_RESISTOR + ); + } + println!(); + println!(); + sensor.refresh().unwrap(); + sensor.refresh_v().unwrap(); + + thread::sleep(Duration::from_millis(100)); + } +} diff --git a/src/regs.rs b/src/regs.rs index 262dfbd..d03036b 100644 --- a/src/regs.rs +++ b/src/regs.rs @@ -261,6 +261,7 @@ pub struct SmbusSettings { /// /// - false = The auto-incrementing pointer will skip over addresses used by/for channels that are inactive (default) /// - true = he auto-incrementing pointer will not skip over addresses used by/for channels that are inactive. + /// /// When these channels are disabled, if a read is performed, it will read FF. pub no_skip: bool, #[packed_field(bits = "0")] @@ -334,31 +335,37 @@ pub struct Slow { #[packed_field(bits = "6")] /// - false = The SLOW pin has not transitioned low to high since the last REFRESH command /// - true = The SLOW pin has transitioned low to high since the last REFRESH command + /// /// The bit is reset to ‘0’ by a REFRESH or REFRESH_G command. pub slow_lh: bool, #[packed_field(bits = "5")] /// - false = The SLOW pin has not transitioned low to high since the last REFRESH command /// - true = The SLOW pin has transitioned low to high since the last REFRESH command + /// /// The bit is reset to ‘0’ by a REFRESH or REFRESH_G command. pub slow_hl: bool, #[packed_field(bits = "4")] /// - false = Disables limited REFRESH function to take place on the rising edge of the SLOW pin /// - true = Enables limited REFRESH function to take place on the rising edge of the SLOW pin + /// /// The bit is not reset automatically, it must be written to be changed. pub r_rise: bool, #[packed_field(bits = "3")] /// - false = Disables limited REFRESH_V function to take place on the rising edge of the SLOW pin /// - true = Enables limited REFRESH_V function to take place on the rising edge of the SLOW pin + /// /// The bit is not reset automatically, it must be written to be changed. pub r_v_rise: bool, #[packed_field(bits = "2")] /// - false = Disables limited REFRESH function to take place on the rising edge of the SLOW pin /// - true = Enables limited REFRESH function to take place on the rising edge of the SLOW pin + /// /// The bit is not reset automatically, it must be written to be changed. pub r_fall: bool, #[packed_field(bits = "1")] /// - false = Disables limited REFRESH_V function to take place on the rising edge of the SLOW pin /// - true = Enables limited REFRESH_V function to take place on the rising edge of the SLOW pin + /// /// The bit is not reset automatically, it must be written to be changed. pub r_v_fall: bool, }