diff --git a/src/uart.rs b/src/uart.rs index 6ce264f..9b44205 100644 --- a/src/uart.rs +++ b/src/uart.rs @@ -138,6 +138,14 @@ pub struct UartPeripheral { + uart: UART, + _rx_pin: RX, + _tx_pin: TX, + _cts_pin: CTS, + _rts_pin: RTS +} + // TODO // pub struct UartReceiver { // _uart: UART, @@ -365,7 +373,7 @@ where UART: Deref { /// Apply all settings and configure the UART peripheral. /// This must be called before the UART peripheral can be used. - pub fn build(self) -> UartPeripheral { + pub fn build(self) -> BuiltUartPeripheral { // Configure the UART peripheral let clk_src_freq = self.clk_src_freq.unwrap(); self.uart.ctrl().write(|w| { @@ -400,20 +408,12 @@ where UART: Deref self.uart.clkdiv().write(|w| unsafe { w.clkdiv().bits(clkdiv) }); // Wait until baud clock is ready while !self.uart.ctrl().read().bclkrdy().bit_is_set() {} - UartPeripheral { - _state: PhantomData, - _clock: PhantomData, + BuiltUartPeripheral { uart: self.uart, _rx_pin: self._rx_pin, _tx_pin: self._tx_pin, _cts_pin: self._cts_pin, - _rts_pin: self._rts_pin, - clk_src: self.clk_src, - clk_src_freq: self.clk_src_freq, - baud: self.baud, - data_bits: self.data_bits, - stop_bits: self.stop_bits, - parity: self.parity, + _rts_pin: self._rts_pin } } } @@ -421,7 +421,7 @@ where UART: Deref /// # UART Methods /// These methods are used to interact with the UART peripheral after it has /// been built. -impl UartPeripheral +impl BuiltUartPeripheral where UART: Deref { @@ -480,14 +480,14 @@ where } // Embedded HAL traits -impl serial::ErrorType for UartPeripheral +impl serial::ErrorType for BuiltUartPeripheral where UART: Deref { type Error = serial::ErrorKind; } -impl serial::Read for UartPeripheral +impl serial::Read for BuiltUartPeripheral where UART: Deref { @@ -496,7 +496,7 @@ where } } -impl serial::Write for UartPeripheral +impl serial::Write for BuiltUartPeripheral where UART: Deref {