tm4c_hal/serial.rs
1//! Serial code that is generic to both the TM4C123 and TM4C129, such as the pin traits.
2
3// The macro is required for the "sealed trait" pattern to work:
4// the traits and the gpios have to be defined in the same crate
5
6///! An internal macro to generate the UART traits
7#[macro_export]
8macro_rules! uart_traits_macro {
9 () => {
10 /// TX pin
11 pub trait TxPin<UART>: crate::Sealed {}
12
13 /// RX pin
14 pub trait RxPin<UART>: crate::Sealed {}
15
16 /// CTS pin
17 pub trait CtsPin<UART>: crate::Sealed {
18 /// Enables the CTS functionality if a valid pin is given (not `()`).
19 fn enable(&mut self, _uart: &mut UART);
20 }
21
22 /// DCD pin
23 pub trait DcdPin<UART>: crate::Sealed {
24 /// Enables the DCD functionality if a valid pin is given (not `()`).
25 fn enable(&mut self, _uart: &mut UART);
26 }
27
28 /// DSR pin
29 pub trait DsrPin<UART>: crate::Sealed {
30 /// Enables the DSR functionality if a valid pin is given (not `()`).
31 fn enable(&mut self, _uart: &mut UART);
32 }
33
34 /// DTR pin
35 pub trait DtrPin<UART>: crate::Sealed {
36 /// Enables the DTR functionality if a valid pin is given (not `()`).
37 fn enable(&mut self, _uart: &mut UART);
38 }
39
40 /// RI pin
41 pub trait RiPin<UART>: crate::Sealed {
42 /// Enables the RI functionality if a valid pin is given (not `()`).
43 fn enable(&mut self, _uart: &mut UART);
44 }
45
46 /// RTS pin
47 pub trait RtsPin<UART>: crate::Sealed {
48 /// Enables the RTS functionality if a valid pin is given (not `()`).
49 fn enable(&mut self, _uart: &mut UART);
50 }
51
52 impl<U> TxPin<U> for () {}
53
54 impl<U> RxPin<U> for () {}
55
56 impl<U> CtsPin<U> for () {
57 fn enable(&mut self, _uart: &mut U) {
58 // Do nothing
59 }
60 }
61 impl<U> DcdPin<U> for () {
62 fn enable(&mut self, _uart: &mut U) {
63 // Do nothing
64 }
65 }
66 impl<U> DsrPin<U> for () {
67 fn enable(&mut self, _uart: &mut U) {
68 // Do nothing
69 }
70 }
71 impl<U> DtrPin<U> for () {
72 fn enable(&mut self, _uart: &mut U) {
73 // Do nothing
74 }
75 }
76 impl<U> RiPin<U> for () {
77 fn enable(&mut self, _uart: &mut U) {
78 // Do nothing
79 }
80 }
81 impl<U> RtsPin<U> for () {
82 fn enable(&mut self, _uart: &mut U) {
83 // Do nothing
84 }
85 }
86 };
87}
88
89/// writeln!() emits LF chars, so this is useful
90/// if you're writing text with your UART
91#[derive(PartialEq, Clone, Copy)]
92pub enum NewlineMode {
93 /// Emit octets as received
94 Binary,
95 /// Emit an extra CR before every LF
96 SwapLFtoCRLF,
97}