Skip to content
Open
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
25 changes: 19 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,30 @@ fn pwm_file_wo(chip: &PwmChip, pin: u32, name: &str) -> Result<File> {
let f = OpenOptions::new().write(true).open(format!(
"/sys/class/pwm/pwmchip{}/pwm{}/{}",
chip.number, pin, name
))?;
Ok(f)
));
if !f.is_ok() {
let f = OpenOptions::new().write(true).open(format!(
"/sys/class/pwm/pwmchip{}/pwm-{}:{}/{}",
chip.number, chip.number, pin, name
))?;
return Ok(f);
}
Ok(f.unwrap())
}

/// Open the specified entry name as a readable file
fn pwm_file_ro(chip: &PwmChip, pin: u32, name: &str) -> Result<File> {
let f = File::open(format!(
"/sys/class/pwm/pwmchip{}/pwm{}/{}",
"/sys/class/pwm/pwmchip{}/pwm{}-{}:",
chip.number, pin, name
))?;
Ok(f)
));
if !f.is_ok() {
let f = File::open(format!(
"/sys/class/pwm/pwmchip{}/pwm{}-{}:/{}",
chip.number, chip.number, pin, name
))?;
return Ok(f);
}
Ok(f.unwrap())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will panic if not present and it looks like with this change the original path will not be attempted at all which doesn't seem appropriate. I may have to look at the kernel sources a bit more to determine the possible path naming for these sysfs entries if some platforms have them different as you seem to indicate.

}

/// Get the u32 value from the given entry
Expand Down