Skip to content

Commit 973c337

Browse files
committed
simplify Tb6612fng::new: take Motors instead of pins
this lets the caller construct the `Motor` and hand it over to `Tb6612fng` instead of having to pass all the pins. this reduces the risk fo mixing up the pins as the old API wuold take 7 pins as an input.
1 parent 57d86a1 commit 973c337

File tree

1 file changed

+9
-39
lines changed

1 file changed

+9
-39
lines changed

src/lib.rs

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,7 @@ pub enum MotorError<IN1Error, IN2Error, PWMError> {
4242
/// Defines errors which can happen when calling [`Tb6612fng::new()`].
4343
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
4444
#[cfg_attr(feature = "defmt-03", derive(Format))]
45-
pub enum Tb6612fngError<
46-
MAIN1Error,
47-
MAIN2Error,
48-
MAPWMError,
49-
MBIN1Error,
50-
MBIN2Error,
51-
MBPWMError,
52-
STBYError,
53-
> {
54-
/// An error in setting the initial `drive()` of `motor_a`
55-
MotorA(MotorError<MAIN1Error, MAIN2Error, MAPWMError>),
56-
/// An error in setting the initial `drive()` of `motor_b`
57-
MotorB(MotorError<MBIN1Error, MBIN2Error, MBPWMError>),
45+
pub enum Tb6612fngError<STBYError> {
5846
/// An error in setting the initial output of the standby pin
5947
Standby(STBYError),
6048
}
@@ -133,15 +121,11 @@ where
133121
/// # let standby = PinMock::new(&[PinTransaction::set(High)]);
134122
/// # let mut standby_ = standby.clone();
135123
///
136-
/// use tb6612fng::Tb6612fng;
124+
/// use tb6612fng::{Motor, Tb6612fng};
137125
///
138126
/// let controller = Tb6612fng::new(
139-
/// motor_a_in1,
140-
/// motor_a_in2,
141-
/// motor_a_pwm,
142-
/// motor_b_in1,
143-
/// motor_b_in2,
144-
/// motor_b_pwm,
127+
/// Motor::new(motor_a_in1, motor_a_in2, motor_a_pwm).unwrap(),
128+
/// Motor::new(motor_b_in1, motor_b_in2, motor_b_pwm).unwrap(),
145129
/// standby,
146130
/// );
147131
///
@@ -155,30 +139,16 @@ where
155139
/// ```
156140
#[allow(clippy::type_complexity)]
157141
pub fn new(
158-
motor_a_in1: MAIN1,
159-
motor_a_in2: MAIN2,
160-
motor_a_pwm: MAPWM,
161-
motor_b_in1: MBIN1,
162-
motor_b_in2: MBIN2,
163-
motor_b_pwm: MBPWM,
142+
motor_a: Motor<MAIN1, MAIN2, MAPWM>,
143+
motor_b: Motor<MBIN1, MBIN2, MBPWM>,
164144
standby: STBY,
165145
) -> Result<
166146
Tb6612fng<MAIN1, MAIN2, MAPWM, MBIN1, MBIN2, MBPWM, STBY>,
167-
Tb6612fngError<
168-
MAIN1::Error,
169-
MAIN2::Error,
170-
MAPWM::Error,
171-
MBIN1::Error,
172-
MBIN2::Error,
173-
MBPWM::Error,
174-
STBY::Error,
175-
>,
147+
Tb6612fngError<STBY::Error>,
176148
> {
177149
let mut controller = Tb6612fng {
178-
motor_a: Motor::new(motor_a_in1, motor_a_in2, motor_a_pwm)
179-
.map_err(Tb6612fngError::MotorA)?,
180-
motor_b: Motor::new(motor_b_in1, motor_b_in2, motor_b_pwm)
181-
.map_err(Tb6612fngError::MotorB)?,
150+
motor_a,
151+
motor_b,
182152
standby,
183153
};
184154

0 commit comments

Comments
 (0)