diff --git a/boards/atsame54_xpro/examples/mcan.rs b/boards/atsame54_xpro/examples/mcan.rs index 6843129b6494..5cad635297f6 100644 --- a/boards/atsame54_xpro/examples/mcan.rs +++ b/boards/atsame54_xpro/examples/mcan.rs @@ -161,8 +161,14 @@ mod app { let (pclk_can1, gclk0) = clock::pclk::Pclk::enable(tokens.pclks.can1, gclk0); - let dependencies = - hal::can::Dependencies::new(pclk_can1, clocks.ahbs.can1, can1_rx, can1_tx, device.can1); + let (dependencies, _gclk0) = hal::can::Dependencies::new( + gclk0, + pclk_can1, + clocks.ahbs.can1, + can1_rx, + can1_tx, + device.can1, + ); let mut can = mcan::bus::CanConfigurable::new(375.kHz(), dependencies, ctx.local.can_memory).unwrap(); diff --git a/hal/src/peripherals/can.rs b/hal/src/peripherals/can.rs index 6f462b37ad81..044238b615f3 100644 --- a/hal/src/peripherals/can.rs +++ b/hal/src/peripherals/can.rs @@ -13,11 +13,12 @@ use crate::{ clock::v2::{ ahb::{AhbClk, AhbId}, + gclk::{EnabledGclk0, GclkSourceId}, pclk::{Pclk, PclkId, PclkSourceId}, types::Can0, }, gpio::*, - typelevel::Sealed, + typelevel::{Decrement, Increment, PrivateDecrement, PrivateIncrement, Sealed}, }; use atsamd_hal_macros::hal_cfg; @@ -46,22 +47,43 @@ impl Dependencies, ahbclk: AhbClk, rx: RX, tx: TX, can: CAN) -> Self { + pub fn new( + gclk0: EnabledGclk0, + pclk: Pclk, + ahbclk: AhbClk, + rx: RX, + tx: TX, + can: CAN, + ) -> (Self, EnabledGclk0) { let host_freq = pclk.freq(); - Self { - pclk, - host_freq, - ahbclk, - rx, - tx, - can, - } + ( + Self { + pclk, + host_freq, + ahbclk, + rx, + tx, + can, + }, + gclk0.inc(), + ) } /// Destroy an instance of `Dependencies` struct. /// /// Releases all enclosed objects back to the user. #[allow(clippy::type_complexity)] - pub fn free(self) -> (Pclk, HertzU32, AhbClk, RX, TX, CAN) { + pub fn free( + self, + gclk0: EnabledGclk0, + ) -> ( + EnabledGclk0, + Pclk, + HertzU32, + AhbClk, + RX, + TX, + CAN, + ) { let Self { pclk, host_freq, @@ -70,7 +92,7 @@ impl Dependencies