cargo fmt

This commit is contained in:
NGnius (Graham) 2024-02-18 17:33:52 -05:00
parent ef5afdee93
commit 75e0a8792b
6 changed files with 77 additions and 52 deletions

View file

@ -17,7 +17,11 @@ fn main() {
match cli.op {
args::Operation::ReadAll => {
let (bytes_per_line, range) = if cli.extended { (16, 0..=u16::MAX) } else { (8, 0..=(u8::MAX as u16)) };
let (bytes_per_line, range) = if cli.extended {
(16, 0..=u16::MAX)
} else {
(8, 0..=(u8::MAX as u16))
};
for addr in range {
let addr_mod = addr % bytes_per_line;
if addr_mod == 0 {
@ -31,21 +35,25 @@ fn main() {
}
}
println!("");
},
}
args::Operation::Read { address } => {
println!("{:#02x}", ec.get(address));
},
}
args::Operation::WritePattern { bytes } => {
let range = if cli.extended { 0..=u16::MAX } else { 0..=(u8::MAX as u16) };
let range = if cli.extended {
0..=u16::MAX
} else {
0..=(u8::MAX as u16)
};
for addr in range {
println!("{:#02x}", addr);
for b in bytes.iter() {
ec.set(addr, *b);
}
}
},
}
args::Operation::Write { address, value } => {
ec.set(address, value);
},
}
}
}

View file

@ -115,24 +115,30 @@ impl embedded_io::Write for EmbeddedController {
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
let size = self.rw_size as u8;
match self.rw_size {
ValueSize::Byte => for &b in buf {
ValueSize::Byte => {
for &b in buf {
self.wait_for_write_ready();
self.cmd_requested = 1; // don't re-request, but still wait
super::ports::outb(self.data_address, b);
},
ValueSize::Word => for i in (0..buf.len()).step_by(size as usize) {
}
}
ValueSize::Word => {
for i in (0..buf.len()).step_by(size as usize) {
self.wait_for_write_ready();
self.cmd_requested = 1; // don't re-request, but still wait
let w = [buf[i], buf[i + 1]];
super::ports::outw(self.data_address, u16::from_ne_bytes(w));
},
ValueSize::Long => for i in (0..buf.len()).step_by(size as usize) {
}
}
ValueSize::Long => {
for i in (0..buf.len()).step_by(size as usize) {
self.wait_for_write_ready();
self.cmd_requested = 1; // don't re-request, but still wait
let l = [buf[i], buf[i + 1], buf[i + 2], buf[i + 3]];
super::ports::outl(self.data_address, u32::from_ne_bytes(l));
}
}
}
self.cmd_requested = 0;
Ok(buf.len())
}
@ -145,7 +151,8 @@ impl embedded_io::Write for EmbeddedController {
impl embedded_io::WriteReady for EmbeddedController {
fn write_ready(&mut self) -> Result<bool, Self::Error> {
self.request_if_not_already();
let ready = super::ports::inb(self.cmd_address) & 2 == 0 || self.cmd_requested == MAX_WAIT_CHECKS;
let ready =
super::ports::inb(self.cmd_address) & 2 == 0 || self.cmd_requested == MAX_WAIT_CHECKS;
if ready {
self.cmd_requested = 0;
}
@ -157,20 +164,25 @@ impl embedded_io::Read for EmbeddedController {
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
let size = self.rw_size as u8;
match self.rw_size {
ValueSize::Byte => for b in buf.iter_mut() {
ValueSize::Byte => {
for b in buf.iter_mut() {
self.wait_for_read_ready();
self.cmd_requested = 1; // don't re-request, but still wait
*b = super::ports::inb(self.data_address);
},
ValueSize::Word => for i in (0..buf.len()).step_by(size as usize) {
}
}
ValueSize::Word => {
for i in (0..buf.len()).step_by(size as usize) {
self.wait_for_read_ready();
self.cmd_requested = 1; // don't re-request, but still wait
let w = super::ports::inw(self.data_address).to_ne_bytes();
for j in 0..(size as usize) {
buf[i + j] = w[j];
}
},
ValueSize::Long => for i in (0..buf.len()).step_by(size as usize) {
}
}
ValueSize::Long => {
for i in (0..buf.len()).step_by(size as usize) {
self.wait_for_read_ready();
self.cmd_requested = 1; // don't re-request, but still wait
let l = super::ports::inl(self.data_address).to_ne_bytes();
@ -179,6 +191,7 @@ impl embedded_io::Read for EmbeddedController {
}
}
}
}
self.cmd_requested = 0;
Ok(buf.len())
}
@ -187,7 +200,8 @@ impl embedded_io::Read for EmbeddedController {
impl embedded_io::ReadReady for EmbeddedController {
fn read_ready(&mut self) -> Result<bool, Self::Error> {
self.request_if_not_already();
let ready = super::ports::inb(self.cmd_address) & 1 != 0 || self.cmd_requested == MAX_WAIT_CHECKS;
let ready =
super::ports::inb(self.cmd_address) & 1 != 0 || self.cmd_requested == MAX_WAIT_CHECKS;
if ready {
self.cmd_requested = 0;
}

View file

@ -8,12 +8,12 @@
mod controller;
mod ports;
pub mod unnamed_power;
pub use controller::{EmbeddedController, ControllerGet, GetValue, ControllerSet, SetValue};
pub use controller::{ControllerGet, ControllerSet, EmbeddedController, GetValue, SetValue};
#[cfg(test)]
mod tests {
use std::io::Error;
use super::unnamed_power::raw_io;
use std::io::Error;
//#[test]
#[allow(dead_code)]

View file

@ -75,7 +75,10 @@ mod ports_internal {
}
// Fallback (compiler error)
#[cfg(not(any(all(any(target_arch = "x86", target_arch = "x86_64")), target_os = "linux")))]
#[cfg(not(any(
all(any(target_arch = "x86", target_arch = "x86_64")),
target_os = "linux"
)))]
mod ports_internal {
#[inline]
pub(crate) fn outb(port: u16, val: u8) {

View file

@ -1,5 +1,5 @@
mod addresses;
pub use addresses::{Setting, Charge, ChargeMode, ControlBoard, BreathingColour, StaticColour};
pub use addresses::{BreathingColour, Charge, ChargeMode, ControlBoard, Setting, StaticColour};
#[cfg(feature = "std")]
pub mod raw_io;
@ -42,9 +42,9 @@ impl super::ControllerSet<Setting> for UnnamedPowerEC {
#[cfg(test)]
mod test {
use std::io::Error;
use super::*;
use crate::ec::raw_io;
use std::io::Error;
//#[test]
#[allow(dead_code)]