diff options
| author | Andrew Ealovega <[email protected]> | 2022-09-21 22:29:57 -0400 |
|---|---|---|
| committer | Andrew Ealovega <[email protected]> | 2022-09-21 22:29:57 -0400 |
| commit | 5914d80968a6aca99f0018148e4b4ed7c4e06bf0 (patch) | |
| tree | e9f7170ee27215555786430c1a0d450ea28a171f | |
| parent | 3b58ac1bf86a2373e479e8e3cf92d2df7c29e00b (diff) | |
Add non blocking Bxcan constructor.
Signed-off-by: Andrew Ealovega <[email protected]>
| -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 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 | ||
| 14 | impl<'d, T: Instance> Can<'d, T> { | 14 | impl<'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 | ||
| 36 | impl<'d, T: Instance> Drop for Can<'d, T> { | 59 | impl<'d, T: Instance> Drop for Can<'d, T> { |
