increase command flexibility
This commit is contained in:
@@ -107,9 +107,7 @@ impl PinData {
|
||||
// Do this twice to check both the current and the current next
|
||||
// If the current is currently invalid, we'd upgrade the next to current
|
||||
for _ in 0..2 {
|
||||
let is_current_valid = self
|
||||
.valid_until
|
||||
.is_some_and(|current| current >= now);
|
||||
let is_current_valid = self.valid_until.is_some_and(|current| current >= now);
|
||||
if is_current_valid {
|
||||
self.value = self.state;
|
||||
return;
|
||||
@@ -135,10 +133,10 @@ impl PinData {
|
||||
);
|
||||
let can_replace_current = self
|
||||
.valid_until
|
||||
.is_none_or(|current| current <= valid_until);
|
||||
let can_replace_next = self
|
||||
.next_validity
|
||||
.is_none_or(|next| next <= valid_until);
|
||||
.is_none_or(|current| current <= valid_until)
|
||||
|| self.priority == priority;
|
||||
let can_replace_next = self.next_validity.is_none_or(|next| next <= valid_until)
|
||||
|| self.next_priority == priority;
|
||||
|
||||
if priority >= self.priority {
|
||||
// This is now the highest priority thing (or most recent of equal priority)
|
||||
|
||||
@@ -158,7 +158,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[allow(clippy::identity_op)]
|
||||
pub(super) fn write(&self, address: u32, data: Mct8316AVData) -> Result<()> {
|
||||
trace!("Mct8316AVDriver::write(self: {self:?}, address: {address:06x}, data: {data})");
|
||||
|
||||
@@ -78,33 +78,31 @@ where
|
||||
pub fn set_isd_config(self, isd_config: IsdConfig) -> Result<Self> {
|
||||
trace!("Mct8316AVEeprom::set_isd_config(self: {self:?}, isd_config: {isd_config:?})");
|
||||
|
||||
let expected_value = if isd_config.enable_isd { 0x4000_0000 } else { 0 }
|
||||
| if isd_config.enable_brake {
|
||||
0x2000_0000
|
||||
} else {
|
||||
0
|
||||
}
|
||||
| if isd_config.enable_high_impedance {
|
||||
0x1000_0000
|
||||
} else {
|
||||
0
|
||||
}
|
||||
| if isd_config.enable_reverse_drive {
|
||||
0x0800_0000
|
||||
} else {
|
||||
0
|
||||
}
|
||||
| if isd_config.enable_resynchronization {
|
||||
0x0400_0000
|
||||
} else {
|
||||
0
|
||||
}
|
||||
| if isd_config.enable_stationary_brake {
|
||||
0x0200_0000
|
||||
} else {
|
||||
0
|
||||
}
|
||||
| (((isd_config.stationary_detect_threshold as u32) & 0x7) << 22)
|
||||
let expected_value = if isd_config.enable_isd {
|
||||
0x4000_0000
|
||||
} else {
|
||||
0
|
||||
} | if isd_config.enable_brake {
|
||||
0x2000_0000
|
||||
} else {
|
||||
0
|
||||
} | if isd_config.enable_high_impedance {
|
||||
0x1000_0000
|
||||
} else {
|
||||
0
|
||||
} | if isd_config.enable_reverse_drive {
|
||||
0x0800_0000
|
||||
} else {
|
||||
0
|
||||
} | if isd_config.enable_resynchronization {
|
||||
0x0400_0000
|
||||
} else {
|
||||
0
|
||||
} | if isd_config.enable_stationary_brake {
|
||||
0x0200_0000
|
||||
} else {
|
||||
0
|
||||
} | (((isd_config.stationary_detect_threshold as u32) & 0x7) << 22)
|
||||
| ((isd_config.brake_mode as u32) & 0x1) << 21
|
||||
| ((isd_config.brake_config as u32) & 0x1) << 20
|
||||
| ((isd_config.brake_current_threshold as u32) & 0x7) << 17
|
||||
|
||||
@@ -1,8 +1,23 @@
|
||||
use embedded_hal::digital::PinState;
|
||||
use nautilus_common::command::{SetPin, ValidPriorityCommand};
|
||||
use std::time::Instant;
|
||||
|
||||
pub trait PinDevice {
|
||||
fn set_pin(&self, pin: u8, value: PinState, valid_until: Instant, priority: u8);
|
||||
|
||||
fn new_pinset_callback(self) -> impl Fn(ValidPriorityCommand<SetPin>)
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
move |cmd| {
|
||||
self.set_pin(
|
||||
cmd.pin,
|
||||
cmd.value.into(),
|
||||
cmd.get_valid_until_instant(),
|
||||
cmd.priority,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Pin {
|
||||
|
||||
Reference in New Issue
Block a user