Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions .github/workflows/branches.yml

This file was deleted.

52 changes: 22 additions & 30 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: Main
name: CI Build

on:
push:
branches:
- "main"

env:
CARGO_TERM_COLOR: always
Expand All @@ -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
- 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
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 4 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 28 additions & 0 deletions examples/linux.rs
Original file line number Diff line number Diff line change
@@ -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));
}
}
7 changes: 7 additions & 0 deletions src/regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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,
}
Expand Down