1313use 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} ;
2223use 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