Merge #960
960: Add non blocking Bxcan constructor r=Dirbaio a=andyblarblar This PR adds a non-blocking constructor to the Bxcan Can wrapper struct. This allows for the creation of the Can periferal without blocking for a sync with the Can bus. Co-authored-by: Andrew Ealovega <Andrew@Ealovega.dev>
This commit is contained in:
commit
a9efbf18c6
@ -12,6 +12,7 @@ pub struct Can<'d, T: Instance> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'d, T: Instance> Can<'d, T> {
|
impl<'d, T: Instance> Can<'d, T> {
|
||||||
|
/// Creates a new Bxcan instance, blocking for 11 recessive bits to sync with the CAN bus.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
peri: impl Peripheral<P = T> + 'd,
|
peri: impl Peripheral<P = T> + 'd,
|
||||||
rx: impl Peripheral<P = impl RxPin<T>> + 'd,
|
rx: impl Peripheral<P = impl RxPin<T>> + 'd,
|
||||||
@ -31,6 +32,28 @@ impl<'d, T: Instance> Can<'d, T> {
|
|||||||
can: bxcan::Can::builder(BxcanInstance(peri)).enable(),
|
can: bxcan::Can::builder(BxcanInstance(peri)).enable(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a new Bxcan instance, keeping the peripheral in sleep mode.
|
||||||
|
/// You must call [Can::enable_non_blocking] to use the peripheral.
|
||||||
|
pub fn new_disabled(
|
||||||
|
peri: impl Peripheral<P = T> + 'd,
|
||||||
|
rx: impl Peripheral<P = impl RxPin<T>> + 'd,
|
||||||
|
tx: impl Peripheral<P = impl TxPin<T>> + 'd,
|
||||||
|
) -> Self {
|
||||||
|
into_ref!(peri, rx, tx);
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
rx.set_as_af(rx.af_num(), AFType::Input);
|
||||||
|
tx.set_as_af(tx.af_num(), AFType::OutputPushPull);
|
||||||
|
}
|
||||||
|
|
||||||
|
T::enable();
|
||||||
|
T::reset();
|
||||||
|
|
||||||
|
Self {
|
||||||
|
can: bxcan::Can::builder(BxcanInstance(peri)).leave_disabled(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'d, T: Instance> Drop for Can<'d, T> {
|
impl<'d, T: Instance> Drop for Can<'d, T> {
|
||||||
|
Loading…
Reference in New Issue
Block a user