22
33extern crate alloc;
44
5- use core:: { any:: Any , ptr :: NonNull } ;
5+ use core:: any:: Any ;
66
77use alloc:: boxed:: Box ;
88use bitflags:: bitflags;
@@ -57,6 +57,8 @@ pub enum TransferError {
5757 Framing ,
5858 #[ error( "Break condition" ) ]
5959 Break ,
60+ #[ error( "Serial port released" ) ]
61+ SerialReleased ,
6062}
6163
6264impl From < RegisterTransferError > for TransferError {
@@ -170,7 +172,7 @@ impl Config {
170172 }
171173}
172174
173- pub trait Register : Clone + Send + Sync + Any + ' static {
175+ pub trait Register : Send + Sync + Any + ' static {
174176 // ==================== 基础数据传输 ====================
175177 fn write_byte ( & mut self , byte : u8 ) ;
176178 fn read_byte ( & self ) -> Result < u8 , RegisterTransferError > ;
@@ -215,7 +217,7 @@ pub trait Register: Clone + Send + Sync + Any + 'static {
215217 fn write_reg ( & mut self , offset : usize , value : u32 ) ;
216218
217219 fn get_base ( & self ) -> usize ;
218- fn set_base ( & mut self , base : NonNull < u8 > ) ;
220+ fn set_base ( & mut self , base : usize ) ;
219221
220222 fn read_buf ( & mut self , buf : & mut [ u8 ] ) -> Result < usize , RegisterTransferError > {
221223 let mut read_count = 0 ;
@@ -257,14 +259,14 @@ pub trait Register: Clone + Send + Sync + Any + 'static {
257259 }
258260}
259261
260- #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
261- pub struct NotMatchError ;
262-
263262pub trait Interface : DriverGeneric {
264263 fn irq_handler ( & mut self ) -> Option < Box < dyn TIrqHandler > > ;
265264 fn take_tx ( & mut self ) -> Option < Box < dyn TSender > > ;
266265 fn take_rx ( & mut self ) -> Option < Box < dyn TReciever > > ;
266+ /// Base address of the serial port
267267 fn base ( & self ) -> usize ;
268+ /// Set base address of the serial port
269+ fn set_base ( & mut self , base : usize ) ;
268270
269271 fn set_config ( & mut self , config : & Config ) -> Result < ( ) , ConfigError > ;
270272
@@ -289,7 +291,7 @@ pub trait TIrqHandler: Send + Sync + 'static {
289291
290292pub trait TSender : Send + ' static {
291293 /// Send data from buf, return sent bytes. If return bytes is less than buf.len(), it means no more space, need to retry later.
292- fn send ( & mut self , buf : & [ u8 ] ) -> usize ;
294+ fn send ( & mut self , buf : & [ u8 ] ) -> Result < usize , TransferError > ;
293295}
294296
295297pub trait TReciever : Send + ' static {
0 commit comments