Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions boards/atsame54_xpro/examples/mcan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
46 changes: 34 additions & 12 deletions hal/src/peripherals/can.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -46,22 +47,43 @@ impl<ID: PclkId + AhbId, PS: PclkSourceId, RX, TX, CAN> Dependencies<ID, PS, RX,
///
/// This struct implements [`mcan_core::Dependencies`] trait, making it
/// possible to construct an instance of `mcan::bus::CanConfigurable`.
pub fn new(pclk: Pclk<ID, PS>, ahbclk: AhbClk<ID>, rx: RX, tx: TX, can: CAN) -> Self {
pub fn new<I: GclkSourceId, S: Increment>(
gclk0: EnabledGclk0<I, S>,
pclk: Pclk<ID, PS>,
ahbclk: AhbClk<ID>,
rx: RX,
tx: TX,
can: CAN,
) -> (Self, EnabledGclk0<I, S::Inc>) {
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<ID, PS>, HertzU32, AhbClk<ID>, RX, TX, CAN) {
pub fn free<I: GclkSourceId, S: Decrement>(
self,
gclk0: EnabledGclk0<I, S>,
) -> (
EnabledGclk0<I, S::Dec>,
Pclk<ID, PS>,
HertzU32,
AhbClk<ID>,
RX,
TX,
CAN,
) {
let Self {
pclk,
host_freq,
Expand All @@ -70,7 +92,7 @@ impl<ID: PclkId + AhbId, PS: PclkSourceId, RX, TX, CAN> Dependencies<ID, PS, RX,
tx,
can,
} = self;
(pclk, host_freq, ahbclk, rx, tx, can)
(gclk0.dec(), pclk, host_freq, ahbclk, rx, tx, can)
}
}

Expand Down