Skip to content

Commit 9719649

Browse files
authored
fix!: Re-add GCLK0 for CAN dependencies (#930)
1 parent cfbc4ad commit 9719649

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

boards/atsame54_xpro/examples/mcan.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,14 @@ mod app {
161161

162162
let (pclk_can1, gclk0) = clock::pclk::Pclk::enable(tokens.pclks.can1, gclk0);
163163

164-
let dependencies =
165-
hal::can::Dependencies::new(pclk_can1, clocks.ahbs.can1, can1_rx, can1_tx, device.can1);
164+
let (dependencies, _gclk0) = hal::can::Dependencies::new(
165+
gclk0,
166+
pclk_can1,
167+
clocks.ahbs.can1,
168+
can1_rx,
169+
can1_tx,
170+
device.can1,
171+
);
166172

167173
let mut can =
168174
mcan::bus::CanConfigurable::new(375.kHz(), dependencies, ctx.local.can_memory).unwrap();

hal/src/peripherals/can.rs

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
use crate::{
1414
clock::v2::{
1515
ahb::{AhbClk, AhbId},
16+
gclk::{EnabledGclk0, GclkSourceId},
1617
pclk::{Pclk, PclkId, PclkSourceId},
1718
types::Can0,
1819
},
1920
gpio::*,
20-
typelevel::Sealed,
21+
typelevel::{Decrement, Increment, PrivateDecrement, PrivateIncrement, Sealed},
2122
};
2223
use atsamd_hal_macros::hal_cfg;
2324

@@ -46,22 +47,43 @@ impl<ID: PclkId + AhbId, PS: PclkSourceId, RX, TX, CAN> Dependencies<ID, PS, RX,
4647
///
4748
/// This struct implements [`mcan_core::Dependencies`] trait, making it
4849
/// possible to construct an instance of `mcan::bus::CanConfigurable`.
49-
pub fn new(pclk: Pclk<ID, PS>, ahbclk: AhbClk<ID>, rx: RX, tx: TX, can: CAN) -> Self {
50+
pub fn new<I: GclkSourceId, S: Increment>(
51+
gclk0: EnabledGclk0<I, S>,
52+
pclk: Pclk<ID, PS>,
53+
ahbclk: AhbClk<ID>,
54+
rx: RX,
55+
tx: TX,
56+
can: CAN,
57+
) -> (Self, EnabledGclk0<I, S::Inc>) {
5058
let host_freq = pclk.freq();
51-
Self {
52-
pclk,
53-
host_freq,
54-
ahbclk,
55-
rx,
56-
tx,
57-
can,
58-
}
59+
(
60+
Self {
61+
pclk,
62+
host_freq,
63+
ahbclk,
64+
rx,
65+
tx,
66+
can,
67+
},
68+
gclk0.inc(),
69+
)
5970
}
6071
/// Destroy an instance of `Dependencies` struct.
6172
///
6273
/// Releases all enclosed objects back to the user.
6374
#[allow(clippy::type_complexity)]
64-
pub fn free(self) -> (Pclk<ID, PS>, HertzU32, AhbClk<ID>, RX, TX, CAN) {
75+
pub fn free<I: GclkSourceId, S: Decrement>(
76+
self,
77+
gclk0: EnabledGclk0<I, S>,
78+
) -> (
79+
EnabledGclk0<I, S::Dec>,
80+
Pclk<ID, PS>,
81+
HertzU32,
82+
AhbClk<ID>,
83+
RX,
84+
TX,
85+
CAN,
86+
) {
6587
let Self {
6688
pclk,
6789
host_freq,
@@ -70,7 +92,7 @@ impl<ID: PclkId + AhbId, PS: PclkSourceId, RX, TX, CAN> Dependencies<ID, PS, RX,
7092
tx,
7193
can,
7294
} = self;
73-
(pclk, host_freq, ahbclk, rx, tx, can)
95+
(gclk0.dec(), pclk, host_freq, ahbclk, rx, tx, can)
7496
}
7597
}
7698

0 commit comments

Comments
 (0)