diff options
author | Andrew Ealovega <Andrew@Ealovega.dev> | 2022-09-21 22:29:57 -0400 |
---|---|---|
committer | Andrew Ealovega <Andrew@Ealovega.dev> | 2022-09-21 22:29:57 -0400 |
commit | 5914d80968a6aca99f0018148e4b4ed7c4e06bf0 (patch) | |
tree | e9f7170ee27215555786430c1a0d450ea28a171f /embassy-stm32 | |
parent | 3b58ac1bf86a2373e479e8e3cf92d2df7c29e00b (diff) | |
download | embassy-5914d80968a6aca99f0018148e4b4ed7c4e06bf0.zip |
Add non blocking Bxcan constructor.
Signed-off-by: Andrew Ealovega <Andrew@Ealovega.dev>
Diffstat (limited to 'embassy-stm32')
-rw-r--r-- | embassy-stm32/src/can/bxcan.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/embassy-stm32/src/can/bxcan.rs b/embassy-stm32/src/can/bxcan.rs index c0bd44e0..bd92b35a 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> { } 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( peri: impl Peripheral<P = 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(), } } + + /// 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> { |