File tree 2 files changed +43
-0
lines changed
2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ //! Blocking CAN API
2
+
3
+ /// A blocking CAN interface that is able to transmit and receive frames.
4
+ pub trait Can {
5
+ /// Associated frame type.
6
+ type Frame : crate :: can:: Frame ;
7
+
8
+ /// Associated error type.
9
+ type Error ;
10
+
11
+ /// Puts a frame in the transmit buffer. Blocks until space is available in
12
+ /// the transmit buffer.
13
+ fn try_transmit ( & mut self , frame : & Self :: Frame ) -> Result < ( ) , Self :: Error > ;
14
+
15
+ /// Blocks until a frame was received or an error occured.
16
+ fn try_receive ( & mut self ) -> Result < Self :: Frame , Self :: Error > ;
17
+ }
18
+
19
+ /// Default implementation of `blocking::can::Can` for implementers of `can::Can`
20
+ pub trait Default : crate :: can:: Can { }
21
+
22
+ impl < S > crate :: blocking:: can:: Can for S
23
+ where
24
+ S : Default ,
25
+ {
26
+ type Frame = S :: Frame ;
27
+ type Error = S :: Error ;
28
+
29
+ fn try_transmit ( & mut self , frame : & Self :: Frame ) -> Result < ( ) , Self :: Error > {
30
+ let mut replaced_frame;
31
+ let mut frame_to_transmit = frame;
32
+ while let Some ( f) = nb:: block!( self . try_transmit( & frame_to_transmit) ) ? {
33
+ replaced_frame = f;
34
+ frame_to_transmit = & replaced_frame;
35
+ }
36
+ Ok ( ( ) )
37
+ }
38
+
39
+ fn try_receive ( & mut self ) -> Result < Self :: Frame , Self :: Error > {
40
+ nb:: block!( self . try_receive( ) )
41
+ }
42
+ }
Original file line number Diff line number Diff line change 4
4
//! traits. To save boilerplate when that's the case a `Default` marker trait may be provided.
5
5
//! Implementing that marker trait will opt in your type into a blanket implementation.
6
6
7
+ pub mod can;
7
8
pub mod delay;
8
9
pub mod i2c;
9
10
pub mod rng;
You can’t perform that action at this time.
0 commit comments