|
1 | 1 | use core::fmt; |
2 | 2 |
|
3 | | -use x86_64::instructions::port::Port; |
| 3 | +use x86_64::instructions::port::{Port, PortReadOnly, PortWriteOnly}; |
4 | 4 |
|
5 | 5 | use crate::LineStsFlags; |
6 | 6 |
|
7 | 7 | /// An interface to a serial port that allows sending out individual bytes. |
8 | 8 | pub struct SerialPort { |
9 | 9 | data: Port<u8>, |
10 | | - int_en: Port<u8>, |
11 | | - fifo_ctrl: Port<u8>, |
12 | | - line_ctrl: Port<u8>, |
13 | | - modem_ctrl: Port<u8>, |
14 | | - line_sts: Port<u8>, |
| 10 | + int_en: PortWriteOnly<u8>, |
| 11 | + fifo_ctrl: PortWriteOnly<u8>, |
| 12 | + line_ctrl: PortWriteOnly<u8>, |
| 13 | + modem_ctrl: PortWriteOnly<u8>, |
| 14 | + line_sts: PortReadOnly<u8>, |
15 | 15 | } |
16 | 16 |
|
17 | 17 | impl SerialPort { |
18 | 18 | /// Creates a new serial port interface on the given I/O port. |
19 | 19 | /// |
20 | 20 | /// This function is unsafe because the caller must ensure that the given base address |
21 | 21 | /// really points to a serial port device. |
22 | | - #[cfg(feature = "nightly")] |
23 | 22 | pub const unsafe fn new(base: u16) -> Self { |
24 | 23 | Self { |
25 | 24 | data: Port::new(base), |
26 | | - int_en: Port::new(base + 1), |
27 | | - fifo_ctrl: Port::new(base + 2), |
28 | | - line_ctrl: Port::new(base + 3), |
29 | | - modem_ctrl: Port::new(base + 4), |
30 | | - line_sts: Port::new(base + 5), |
31 | | - } |
32 | | - } |
33 | | - |
34 | | - /// Creates a new serial port interface on the given I/O port. |
35 | | - /// |
36 | | - /// This function is unsafe because the caller must ensure that the given base address |
37 | | - /// really points to a serial port device. |
38 | | - #[cfg(feature = "stable")] |
39 | | - pub unsafe fn new(base: u16) -> Self { |
40 | | - Self { |
41 | | - data: Port::new(base), |
42 | | - int_en: Port::new(base + 1), |
43 | | - fifo_ctrl: Port::new(base + 2), |
44 | | - line_ctrl: Port::new(base + 3), |
45 | | - modem_ctrl: Port::new(base + 4), |
46 | | - line_sts: Port::new(base + 5), |
| 25 | + int_en: PortWriteOnly::new(base + 1), |
| 26 | + fifo_ctrl: PortWriteOnly::new(base + 2), |
| 27 | + line_ctrl: PortWriteOnly::new(base + 3), |
| 28 | + modem_ctrl: PortWriteOnly::new(base + 4), |
| 29 | + line_sts: PortReadOnly::new(base + 5), |
47 | 30 | } |
48 | 31 | } |
49 | 32 |
|
@@ -93,11 +76,11 @@ impl SerialPort { |
93 | 76 | self.data.write(b' '); |
94 | 77 | wait_for!(self.line_sts().contains(LineStsFlags::OUTPUT_EMPTY)); |
95 | 78 | self.data.write(8) |
96 | | - }, |
| 79 | + } |
97 | 80 | _ => { |
98 | 81 | wait_for!(self.line_sts().contains(LineStsFlags::OUTPUT_EMPTY)); |
99 | 82 | self.data.write(data); |
100 | | - }, |
| 83 | + } |
101 | 84 | } |
102 | 85 | } |
103 | 86 | } |
|
0 commit comments