96 lines
3.7 KiB
Rust
96 lines
3.7 KiB
Rust
#![allow(dead_code)]
|
|
|
|
use crate::hardware::pin::{Pin, PinDevice};
|
|
use embedded_hal::digital::PinState;
|
|
use log::trace;
|
|
use std::any::type_name;
|
|
use std::fmt::Debug;
|
|
use std::time::Instant;
|
|
|
|
pub const RCS5: PinoutChannel = PinoutChannel::ExtA(0);
|
|
pub const RCS6: PinoutChannel = PinoutChannel::ExtA(1);
|
|
pub const RCS7: PinoutChannel = PinoutChannel::ExtA(2);
|
|
pub const RCS8: PinoutChannel = PinoutChannel::ExtA(3);
|
|
pub const RCS9: PinoutChannel = PinoutChannel::ExtA(4);
|
|
pub const MOTOR0_A: PinoutChannel = PinoutChannel::ExtA(5);
|
|
pub const MOTOR0_B: PinoutChannel = PinoutChannel::ExtA(6);
|
|
pub const LED_A: PinoutChannel = PinoutChannel::ExtA(7);
|
|
pub const RCS0: PinoutChannel = PinoutChannel::ExtA(8);
|
|
pub const RCS1: PinoutChannel = PinoutChannel::ExtA(9);
|
|
pub const DRIVE0_BRAKE: PinoutChannel = PinoutChannel::ExtA(10);
|
|
pub const DRIVE0_DIR: PinoutChannel = PinoutChannel::ExtA(11);
|
|
pub const DRIVE0_DRIVEOFF: PinoutChannel = PinoutChannel::ExtA(12);
|
|
pub const RCS2: PinoutChannel = PinoutChannel::ExtA(13);
|
|
pub const RCS3: PinoutChannel = PinoutChannel::ExtA(14);
|
|
pub const RCS4: PinoutChannel = PinoutChannel::ExtA(15);
|
|
pub const MOTOR1_A: PinoutChannel = PinoutChannel::ExtB(8);
|
|
pub const MOTOR1_B: PinoutChannel = PinoutChannel::ExtB(9);
|
|
pub const MOTOR2_A: PinoutChannel = PinoutChannel::ExtB(10);
|
|
pub const MOTOR2_B: PinoutChannel = PinoutChannel::ExtB(11);
|
|
pub const MOTOR3_A: PinoutChannel = PinoutChannel::ExtB(12);
|
|
pub const MOTOR3_B: PinoutChannel = PinoutChannel::ExtB(13);
|
|
pub const OUT1: PinoutChannel = PinoutChannel::ExtB(14);
|
|
pub const OUT2: PinoutChannel = PinoutChannel::ExtB(15);
|
|
pub const OUT3: PinoutChannel = PinoutChannel::ExtB(0);
|
|
pub const OUT4: PinoutChannel = PinoutChannel::ExtB(1);
|
|
pub const OUT5: PinoutChannel = PinoutChannel::ExtB(2);
|
|
pub const OUT6: PinoutChannel = PinoutChannel::ExtB(3);
|
|
pub const OUT7: PinoutChannel = PinoutChannel::ExtB(4);
|
|
pub const OUT8: PinoutChannel = PinoutChannel::ExtB(5);
|
|
pub const OUT9: PinoutChannel = PinoutChannel::ExtB(6);
|
|
pub const LED_B: PinoutChannel = PinoutChannel::ExtB(7);
|
|
|
|
#[derive(Copy, Clone, Debug)]
|
|
pub enum PinoutChannel {
|
|
ExtA(u8),
|
|
ExtB(u8),
|
|
}
|
|
|
|
pub struct DevicePin<'a, Device: PinDevice> {
|
|
pin: u8,
|
|
device: &'a Device,
|
|
}
|
|
|
|
impl<Device: PinDevice> Pin for DevicePin<'_, Device> {
|
|
fn set(&mut self, value: PinState, valid_until: Instant, priority: u8) {
|
|
trace!(
|
|
"ChannelPin<Device={}>::set(self, value: {value:?}, valid_until: {valid_until:?}, priority: {priority})",
|
|
type_name::<Device>()
|
|
);
|
|
self.device.set_pin(self.pin, value, valid_until, priority);
|
|
}
|
|
}
|
|
|
|
pub enum ChannelPin<'a, A: PinDevice, B: PinDevice> {
|
|
ExtA(DevicePin<'a, A>),
|
|
ExtB(DevicePin<'a, B>),
|
|
}
|
|
|
|
impl<A: PinDevice, B: PinDevice> Pin for ChannelPin<'_, A, B> {
|
|
fn set(&mut self, value: PinState, valid_until: Instant, priority: u8) {
|
|
trace!(
|
|
"ChannelPin<A={}, B={}>::set(self, value: {value:?}, valid_until: {valid_until:?}, priority: {priority})",
|
|
type_name::<A>(),
|
|
type_name::<B>()
|
|
);
|
|
match self {
|
|
ChannelPin::ExtA(pin) => pin.set(value, valid_until, priority),
|
|
ChannelPin::ExtB(pin) => pin.set(value, valid_until, priority),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl PinoutChannel {
|
|
pub fn get_pin<'a>(
|
|
self,
|
|
ext_a: &'a (impl PinDevice + Debug),
|
|
ext_b: &'a (impl PinDevice + Debug),
|
|
) -> impl Pin {
|
|
trace!("PinoutChannel::get_pin(self: {self:?}, ext_a: {ext_a:?}, ext_b: {ext_b:?}");
|
|
match self {
|
|
PinoutChannel::ExtA(pin) => ChannelPin::ExtA(DevicePin { pin, device: ext_a }),
|
|
PinoutChannel::ExtB(pin) => ChannelPin::ExtB(DevicePin { pin, device: ext_b }),
|
|
}
|
|
}
|
|
}
|