1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
//! Serial

pub use tm4c123x::{UART0, UART1, UART2, UART3, UART4, UART5, UART6, UART7};
pub use tm4c_hal::{serial::*, uart_hal_macro, uart_pin_macro};

#[rustfmt::skip]
use crate::{
    gpio::{
        gpioa, gpiob, gpioc, gpiod, gpioe, gpiof,
        AlternateFunction, OutputMode, AF1, AF2, AF8,
    },
    hal::{prelude::*, serial},
    sysctl,
    sysctl::Clocks,
    time::Bps,
};
use core::{fmt, marker::PhantomData};
use nb::{self, block};
use void::Void;

/// Serial abstraction
pub struct Serial<UART, TX, RX, RTS, CTS> {
    uart: UART,
    tx_pin: TX,
    rx_pin: RX,
    rts_pin: RTS,
    cts_pin: CTS,
    nl_mode: NewlineMode,
}

/// Serial receiver
pub struct Rx<UART, RX, CTS> {
    _uart: PhantomData<UART>,
    pin: RX,
    flow_pin: CTS,
}

/// Serial transmitter
pub struct Tx<UART, TX, RTS> {
    uart: UART,
    pin: TX,
    flow_pin: RTS,
    nl_mode: NewlineMode,
}

uart_pin_macro!(UART0,
    cts: [],
    rts: [],
    rx: [(gpioa::PA0, AF1)],
    tx: [(gpioa::PA1, AF1)],
);

uart_pin_macro!(UART1,
    cts: [(gpioc::PC5, AF8), (gpiof::PF1, AF1)],
    rts: [(gpioc::PC4, AF8), (gpiof::PF0, AF1)],
    rx: [(gpiob::PB0, AF1), (gpioc::PC4, AF2)],
    tx: [(gpiob::PB1, AF1), (gpioc::PC5, AF2)],
);

uart_pin_macro!(UART2,
    cts: [],
    rts: [],
    rx: [(gpiod::PD6, AF1)],
    tx: [(gpiod::PD7, AF1)],
);

uart_pin_macro!(UART3,
    cts: [],
    rts: [],
    rx: [(gpioc::PC6, AF1)],
    tx: [(gpioc::PC7, AF1)],
);

uart_pin_macro!(UART4,
    cts: [],
    rts: [],
    rx: [(gpioc::PC4, AF1)],
    tx: [(gpioc::PC5, AF1)],
);

uart_pin_macro!(UART5,
    cts: [],
    rts: [],
    rx: [(gpioe::PE4, AF1)],
    tx: [(gpioe::PE5, AF1)],
);

uart_pin_macro!(UART6,
    cts: [],
    rts: [],
    rx: [(gpiod::PD4, AF1)],
    tx: [(gpiod::PD5, AF1)],
);

uart_pin_macro!(UART7,
    cts: [],
    rts: [],
    rx: [(gpioe::PE0, AF1)],
    tx: [(gpioe::PE1, AF1)],
);

uart_hal_macro! {
    UART0: (Uart0, uart0),
    UART1: (Uart1, uart1),
    UART2: (Uart2, uart2),
    UART3: (Uart3, uart3),
    UART4: (Uart4, uart4),
    UART5: (Uart5, uart5),
    UART6: (Uart6, uart6),
    UART7: (Uart7, uart7),
}