use embedded_hal::digital::blocking::OutputPin;
use fugit::NanosDurationU32 as Nanoseconds;
use crate::step_mode::StepMode;
pub trait EnableStepModeControl<Resources> {
type WithStepModeControl: SetStepMode;
fn enable_step_mode_control(
self,
res: Resources,
) -> Self::WithStepModeControl;
}
pub trait SetStepMode {
const SETUP_TIME: Nanoseconds;
const HOLD_TIME: Nanoseconds;
type Error;
type StepMode: StepMode;
fn apply_mode_config(
&mut self,
step_mode: Self::StepMode,
) -> Result<(), Self::Error>;
fn enable_driver(&mut self) -> Result<(), Self::Error>;
}
pub trait EnableDirectionControl<Resources> {
type WithDirectionControl: SetDirection;
fn enable_direction_control(
self,
res: Resources,
) -> Self::WithDirectionControl;
}
pub trait SetDirection {
const SETUP_TIME: Nanoseconds;
type Dir: OutputPin;
type Error;
fn dir(&mut self) -> Result<&mut Self::Dir, Self::Error>;
}
pub trait EnableStepControl<Resources> {
type WithStepControl: Step;
fn enable_step_control(self, res: Resources) -> Self::WithStepControl;
}
pub trait Step {
const PULSE_LENGTH: Nanoseconds;
type Step: OutputPin;
type Error;
fn step(&mut self) -> Result<&mut Self::Step, Self::Error>;
}
pub trait EnableMotionControl<Resources, const TIMER_HZ: u32> {
type WithMotionControl: MotionControl;
fn enable_motion_control(self, res: Resources) -> Self::WithMotionControl;
}
pub trait MotionControl {
type Velocity: Copy;
type Error;
fn move_to_position(
&mut self,
max_velocity: Self::Velocity,
target_step: i32,
) -> Result<(), Self::Error>;
fn reset_position(&mut self, step: i32) -> Result<(), Self::Error>;
fn update(&mut self) -> Result<bool, Self::Error>;
}