aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Ealovega <[email protected]>2022-09-21 22:29:57 -0400
committerAndrew Ealovega <[email protected]>2022-09-21 22:29:57 -0400
commit5914d80968a6aca99f0018148e4b4ed7c4e06bf0 (patch)
treee9f7170ee27215555786430c1a0d450ea28a171f
parent3b58ac1bf86a2373e479e8e3cf92d2df7c29e00b (diff)
Add non blocking Bxcan constructor.
Signed-off-by: Andrew Ealovega <[email protected]>
-rw-r--r--embassy-stm32/src/can/bxcan.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/embassy-stm32/src/can/bxcan.rs b/embassy-stm32/src/can/bxcan.rs
index c0bd44e0f..bd92b35a0 100644
--- a/embassy-stm32/src/can/bxcan.rs
+++ b/embassy-stm32/src/can/bxcan.rs
@@ -12,6 +12,7 @@ pub struct Can<'d, T: Instance> {
12} 12}
13 13
14impl<'d, T: Instance> Can<'d, T> { 14impl<'d, T: Instance> Can<'d, T> {
15 /// Creates a new Bxcan instance, blocking for 11 recessive bits to sync with the CAN bus.
15 pub fn new( 16 pub fn new(
16 peri: impl Peripheral<P = T> + 'd, 17 peri: impl Peripheral<P = T> + 'd,
17 rx: impl Peripheral<P = impl RxPin<T>> + 'd, 18 rx: impl Peripheral<P = impl RxPin<T>> + 'd,
@@ -31,6 +32,28 @@ impl<'d, T: Instance> Can<'d, T> {
31 can: bxcan::Can::builder(BxcanInstance(peri)).enable(), 32 can: bxcan::Can::builder(BxcanInstance(peri)).enable(),
32 } 33 }
33 } 34 }
35
36 /// Creates a new Bxcan instance, keeping the peripheral in sleep mode.
37 /// You must call [Can::enable_non_blocking] to use the peripheral.
38 pub fn new_disabled(
39 peri: impl Peripheral<P = T> + 'd,
40 rx: impl Peripheral<P = impl RxPin<T>> + 'd,
41 tx: impl Peripheral<P = impl TxPin<T>> + 'd,
42 ) -> Self {
43 into_ref!(peri, rx, tx);
44
45 unsafe {
46 rx.set_as_af(rx.af_num(), AFType::Input);
47 tx.set_as_af(tx.af_num(), AFType::OutputPushPull);
48 }
49
50 T::enable();
51 T::reset();
52
53 Self {
54 can: bxcan::Can::builder(BxcanInstance(peri)).leave_disabled(),
55 }
56 }
34} 57}
35 58
36impl<'d, T: Instance> Drop for Can<'d, T> { 59impl<'d, T: Instance> Drop for Can<'d, T> {