21
21
//! ## With `mmio_{stable, nightly}` feature
22
22
//!
23
23
//! ```rust
24
- //! use uart_16550::SerialPort ;
24
+ //! use uart_16550::MmioSerialPort ;
25
25
//!
26
26
//! const SERIAL_IO_PORT: usize = 0x1000_0000;
27
27
//!
39
39
#![ warn( missing_docs) ]
40
40
#![ cfg_attr( feature = "mmio_nightly" , feature( const_ptr_offset) ) ]
41
41
42
- use bitflags:: bitflags;
43
42
use core:: fmt;
44
43
44
+ use bitflags:: bitflags;
45
+
45
46
#[ cfg( any(
46
47
all(
47
48
not( any( feature = "port_stable" , feature = "port_nightly" ) ) ,
@@ -52,16 +53,17 @@ use core::fmt;
52
53
any( feature = "mmio_stable" , feature = "mmio_nightly" )
53
54
)
54
55
) ) ]
55
- compile_error ! (
56
- "One of these features must be enabled: `port_{stable, nightly}`, `mmio_{stable, nightly}`"
57
- ) ;
56
+ compile_error ! ( "One of these features must be enabled: `port_{stable, nightly}`, `mmio_{stable, nightly}`" ) ;
57
+
58
+ #[ cfg( any( feature = "mmio_stable" , feature = "mmio_nightly" ) ) ]
59
+ use core:: sync:: atomic:: {
60
+ AtomicPtr ,
61
+ Ordering ,
62
+ } ;
58
63
59
64
#[ cfg( any( feature = "port_stable" , feature = "port_nightly" ) ) ]
60
65
use x86_64:: instructions:: port:: Port ;
61
66
62
- #[ cfg( any( feature = "mmio_stable" , feature = "mmio_nightly" ) ) ]
63
- use core:: sync:: atomic:: { AtomicPtr , Ordering } ;
64
-
65
67
macro_rules! wait_for {
66
68
( $cond: expr) => {
67
69
while !$cond {
@@ -182,11 +184,11 @@ impl SerialPort {
182
184
self . data . write ( b' ' ) ;
183
185
wait_for ! ( self . line_sts( ) . contains( LineStsFlags :: OUTPUT_EMPTY ) ) ;
184
186
self . data . write ( 8 )
185
- }
187
+ } ,
186
188
_ => {
187
189
wait_for ! ( self . line_sts( ) . contains( LineStsFlags :: OUTPUT_EMPTY ) ) ;
188
190
self . data . write ( data) ;
189
- }
191
+ } ,
190
192
}
191
193
}
192
194
}
@@ -202,7 +204,7 @@ impl SerialPort {
202
204
203
205
/// An interface to a serial port that allows sending out individual bytes.
204
206
#[ cfg( any( feature = "mmio_stable" , feature = "mmio_nightly" ) ) ]
205
- pub struct SerialPort {
207
+ pub struct MmioSerialPort {
206
208
data : AtomicPtr < u8 > ,
207
209
int_en : AtomicPtr < u8 > ,
208
210
fifo_ctrl : AtomicPtr < u8 > ,
@@ -295,11 +297,11 @@ impl SerialPort {
295
297
self_data. write ( b' ' ) ;
296
298
wait_for ! ( self . line_sts( ) . contains( LineStsFlags :: OUTPUT_EMPTY ) ) ;
297
299
self_data. write ( 8 )
298
- }
300
+ } ,
299
301
_ => {
300
302
wait_for ! ( self . line_sts( ) . contains( LineStsFlags :: OUTPUT_EMPTY ) ) ;
301
303
self_data. write ( data) ;
302
- }
304
+ } ,
303
305
}
304
306
}
305
307
}
0 commit comments