tm4c129x_hal/
serial.rs

1//! Serial
2
3// uart_hal_macro can be called with too-many arguments
4#![allow(clippy::too_many_arguments)]
5
6use core::{fmt, marker::PhantomData};
7
8use crate::{
9    gpio::*,
10    hal::{prelude::*, serial},
11    sysctl::{self, Clocks},
12    time::Bps,
13};
14use nb::{self, block};
15use void::Void;
16
17pub use tm4c129x::{UART0, UART1, UART2, UART3, UART4, UART5, UART6, UART7};
18pub use tm4c_hal::serial::NewlineMode;
19use tm4c_hal::{uart_hal_macro, uart_pin_macro};
20
21/// Serial abstraction
22pub struct Serial<UART, TX, RX, RTS, CTS> {
23    uart: UART,
24    tx_pin: TX,
25    rx_pin: RX,
26    rts_pin: RTS,
27    cts_pin: CTS,
28    nl_mode: NewlineMode,
29}
30
31/// Serial receiver
32pub struct Rx<UART, RX, CTS> {
33    _uart: PhantomData<UART>,
34    pin: RX,
35    flow_pin: CTS,
36}
37
38/// Serial transmitter
39pub struct Tx<UART, TX, RTS> {
40    uart: UART,
41    pin: TX,
42    flow_pin: RTS,
43    nl_mode: NewlineMode,
44}
45
46uart_pin_macro!(UART0,
47    cts: [(gpioh::PH1, AF1), (gpiom::PM4, AF1), (gpiob::PB4, AF1)],
48    // dcd: [(gpioh::PH2, AF1), (gpiom::PM5, AF1), (gpiop::PP3, AF2)],
49    // dsr: [(gpioh::PH3, AF1), (gpiom::PM6, AF1), (gpiop::PP4, AF2)],
50    // dtr: [(gpiop::PP2, AF1)],
51    // ri: [(gpiok::PK7, AF1), (gpiom::PM7, AF1)],
52    rts: [(gpioh::PH0, AF1), (gpiob::PB5, AF1)],
53    rx: [(gpioa::PA0, AF1)],
54    tx: [(gpioa::PA1, AF1)],
55);
56
57uart_pin_macro!(UART1,
58    cts: [(gpion::PN1, AF1), (gpiop::PP3, AF1)],
59    // dcd: [(gpioe::PE2, AF1), (gpion::PN2, AF1)],
60    // dsr: [(gpioe::PE1, AF1), (gpion::PN3, AF1)],
61    // dtr: [(gpioe::PE3, AF1), (gpion::PN4, AF1)],
62    // ri: [(gpioe::PE4, AF1), (gpion::PN5, AF1)],
63    rts: [(gpioe::PE0, AF1), (gpion::PN0, AF1)],
64    rx: [(gpiob::PB0, AF1), (gpioq::PQ4, AF1)],
65    tx: [(gpiob::PB1, AF1)],
66);
67
68uart_pin_macro!(UART2,
69    cts: [(gpiod::PD7, AF1), (gpion::PN3, AF2)],
70    rts: [(gpiod::PD6, AF1), (gpion::PN2, AF2)],
71    rx: [(gpioa::PA6, AF1), (gpiod::PD4, AF1)],
72    tx: [(gpioa::PA7, AF1), (gpiod::PD5, AF1)],
73);
74
75uart_pin_macro!(UART3,
76    cts: [(gpiop::PP5, AF1), (gpion::PN5, AF2)],
77    rts: [(gpiop::PP4, AF1), (gpion::PN4, AF2)],
78    rx: [(gpioa::PA4, AF1), (gpioj::PJ0, AF1)],
79    tx: [(gpioa::PA5, AF1), (gpioj::PJ1, AF1)],
80);
81
82uart_pin_macro!(UART4,
83    cts: [(gpiok::PK3, AF1)],
84    rts: [(gpiok::PK2, AF1)],
85    rx: [(gpioa::PA2, AF1), (gpiok::PK0, AF1)],
86    tx: [(gpioa::PA3, AF1), (gpiok::PK1, AF1)],
87);
88
89uart_pin_macro!(UART5,
90    cts: [],
91    rts: [],
92    rx: [(gpioc::PC6, AF1)],
93    tx: [(gpioc::PC7, AF1)],
94);
95
96uart_pin_macro!(UART6,
97    cts: [],
98    rts: [],
99    rx: [(gpiop::PP0, AF1)],
100    tx: [(gpiop::PP1, AF1)],
101);
102
103uart_pin_macro!(UART7,
104    cts: [],
105    rts: [],
106    rx: [(gpioc::PC4, AF1)],
107    tx: [(gpioc::PC5, AF1)],
108);
109
110uart_hal_macro! {
111    UART0: (Uart0, uart0),
112    UART1: (Uart1, uart1),
113    UART2: (Uart2, uart2),
114    UART3: (Uart3, uart3),
115    UART4: (Uart4, uart4),
116    UART5: (Uart5, uart5),
117    UART6: (Uart6, uart6),
118    UART7: (Uart7, uart7),
119}