feat: move sync and handshake methods to struct implementation
This commit is contained in:
parent
6defd8963f
commit
caa1ff9f24
21
src/lib.rs
21
src/lib.rs
|
@ -69,11 +69,7 @@ where
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P> SoftSerial<P> for HalfDuplexSerial<P>
|
pub fn poll(&self) -> PollResult {
|
||||||
where
|
|
||||||
P: PinOps + StaticPinOps,
|
|
||||||
{
|
|
||||||
fn poll(&self) -> PollResult {
|
|
||||||
P::into_output();
|
P::into_output();
|
||||||
delay_cycles(1);
|
delay_cycles(1);
|
||||||
P::into_pull_up_input();
|
P::into_pull_up_input();
|
||||||
|
@ -95,7 +91,7 @@ where
|
||||||
PollResult::Ok(())
|
PollResult::Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn response(&self) {
|
pub fn response(&self) {
|
||||||
P::into_output_high();
|
P::into_output_high();
|
||||||
|
|
||||||
delay_us(FIRST_HALF_SERIAL_DELAY);
|
delay_us(FIRST_HALF_SERIAL_DELAY);
|
||||||
|
@ -108,21 +104,27 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
fn sync_transmitter(&self) {
|
pub fn sync_transmitter(&self) {
|
||||||
P::into_output();
|
P::into_output();
|
||||||
|
|
||||||
delay_us(SERIAL_DELAY);
|
delay_us(SERIAL_DELAY / 2);
|
||||||
|
|
||||||
P::set_high();
|
P::set_high();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
fn sync_reciever(&self) {
|
pub fn sync_reciever(&self) {
|
||||||
while P::is_high() {}
|
while P::is_high() {}
|
||||||
|
|
||||||
while P::is_low() {}
|
while P::is_low() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn reset(&self) {
|
||||||
|
P::into_pull_up_input();
|
||||||
|
while P::is_low() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub trait SoftSerialWriter<P, T>
|
pub trait SoftSerialWriter<P, T>
|
||||||
where
|
where
|
||||||
|
@ -228,4 +230,3 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue