embedded_stepper/
builders.rs

1#![allow(clippy::needless_pass_by_value)]
2
3use embedded_hal::delay::DelayNs;
4use embedded_hal::digital::OutputPin;
5
6use crate::{
7    stepper::Stepper,
8    motors::{StepperMotor2, StepperMotor4, StepperMotor5},
9};
10
11/// Build a 2-pin stepper controller.
12///
13/// - `number_of_steps`: steps per revolution (or per full cycle of your sequence)
14pub fn create_stepper_2pin<P1, P2, D>(
15    p1: P1,
16    p2: P2,
17    delay: D,
18    number_of_steps: u32,
19) -> Stepper<StepperMotor2<P1, P2>, D>
20where
21    P1: OutputPin,
22    P2: OutputPin<Error = P1::Error>,
23    D: DelayNs,
24{
25    let motor = StepperMotor2 { p1, p2 };
26    Stepper::new(number_of_steps, motor, delay)
27}
28
29/// Build a 4-pin stepper controller.
30pub fn create_stepper_4pin<P1, P2, P3, P4, D>(
31    p1: P1,
32    p2: P2,
33    p3: P3,
34    p4: P4,
35    delay: D,
36    number_of_steps: u32,
37) -> Stepper<StepperMotor4<P1, P2, P3, P4>, D>
38where
39    P1: OutputPin,
40    P2: OutputPin<Error = P1::Error>,
41    P3: OutputPin<Error = P1::Error>,
42    P4: OutputPin<Error = P1::Error>,
43    D: DelayNs,
44{
45    let motor = StepperMotor4 { p1, p2, p3, p4 };
46    Stepper::new(number_of_steps, motor, delay)
47}
48
49/// Build a 5-pin stepper controller
50pub fn create_stepper_5pin<P1, P2, P3, P4, P5, D>(
51    p1: P1,
52    p2: P2,
53    p3: P3,
54    p4: P4,
55    p5: P5,
56    delay: D,
57    number_of_steps: u32,
58) -> Stepper<StepperMotor5<P1, P2, P3, P4, P5>, D>
59where
60    P1: OutputPin,
61    P2: OutputPin<Error = P1::Error>,
62    P3: OutputPin<Error = P1::Error>,
63    P4: OutputPin<Error = P1::Error>,
64    P5: OutputPin<Error = P1::Error>,
65    D: DelayNs,
66{
67    let motor = StepperMotor5 { p1, p2, p3, p4, p5 };
68    Stepper::new(number_of_steps, motor, delay)
69}