@@ -24,7 +24,7 @@ mod hal_02;
2424mod hal_1;
2525
2626mod uart_impls;
27- use uart_impls:: RegisterBlockImpl ;
27+ use uart_impls:: RBExt ;
2828
2929use crate :: gpio:: { self , PushPull } ;
3030
@@ -77,6 +77,32 @@ pub enum Event {
7777 ParityError = 1 << 8 ,
7878}
7979
80+ /// UART interrupt events
81+ #[ enumflags2:: bitflags]
82+ #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
83+ #[ derive( Debug , Eq , PartialEq , Copy , Clone ) ]
84+ #[ repr( u16 ) ]
85+ pub enum RxEvent {
86+ /// IDLE interrupt enable
87+ Idle = 1 << 4 ,
88+ /// RXNE interrupt enable
89+ RxNotEmpty = 1 << 5 ,
90+ /// PE interrupt enable
91+ ParityError = 1 << 8 ,
92+ }
93+
94+ /// UART interrupt events
95+ #[ enumflags2:: bitflags]
96+ #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
97+ #[ derive( Debug , Eq , PartialEq , Copy , Clone ) ]
98+ #[ repr( u16 ) ]
99+ pub enum TxEvent {
100+ /// Transmission complete interrupt enable
101+ TransmissionComplete = 1 << 6 ,
102+ /// TXE interrupt enable
103+ TxEmpty = 1 << 7 ,
104+ }
105+
80106/// UART/USART status flags
81107#[ enumflags2:: bitflags]
82108#[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
@@ -128,7 +154,7 @@ pub use gpio::alt::SerialAsync as CommonPins;
128154// Implemented by all USART/UART instances
129155pub trait Instance :
130156 crate :: Sealed
131- + crate :: Ptr < RB : RegisterBlockImpl >
157+ + crate :: Ptr < RB : RBExt >
132158 + crate :: Steal
133159 + core:: ops:: Deref < Target = Self :: RB >
134160 + rcc:: Enable
@@ -161,37 +187,30 @@ pub trait TxISR {
161187 fn is_tx_empty ( & self ) -> bool ;
162188}
163189
164- /// Trait for listening [`Rx`] interrupt events.
165- pub trait RxListen {
166- /// Start listening for an rx not empty interrupt event
167- ///
168- /// Note, you will also have to enable the corresponding interrupt
169- /// in the NVIC to start receiving events.
170- fn listen ( & mut self ) ;
171-
172- /// Stop listening for the rx not empty interrupt event
173- fn unlisten ( & mut self ) ;
174-
175- /// Start listening for a line idle interrupt event
176- ///
177- /// Note, you will also have to enable the corresponding interrupt
178- /// in the NVIC to start receiving events.
179- fn listen_idle ( & mut self ) ;
190+ impl < UART : Instance > crate :: Listen for Rx < UART > {
191+ type Event = RxEvent ;
180192
181- /// Stop listening for the line idle interrupt event
182- fn unlisten_idle ( & mut self ) ;
193+ #[ inline( always) ]
194+ fn listen_event (
195+ & mut self ,
196+ disable : Option < BitFlags < Self :: Event > > ,
197+ enable : Option < BitFlags < Self :: Event > > ,
198+ ) {
199+ self . usart . listen_rx ( disable, enable)
200+ }
183201}
184202
185- /// Trait for listening [`Tx`] interrupt event.
186- pub trait TxListen {
187- /// Start listening for a tx empty interrupt event
188- ///
189- /// Note, you will also have to enable the corresponding interrupt
190- /// in the NVIC to start receiving events.
191- fn listen ( & mut self ) ;
203+ impl < UART : Instance > crate :: Listen for Tx < UART > {
204+ type Event = TxEvent ;
192205
193- /// Stop listening for the tx empty interrupt event
194- fn unlisten ( & mut self ) ;
206+ #[ inline( always) ]
207+ fn listen_event (
208+ & mut self ,
209+ disable : Option < BitFlags < Self :: Event > > ,
210+ enable : Option < BitFlags < Self :: Event > > ,
211+ ) {
212+ self . usart . listen_tx ( disable, enable)
213+ }
195214}
196215
197216/// Serial abstraction
@@ -578,34 +597,6 @@ impl<UART: Instance, WORD> TxISR for Tx<UART, WORD> {
578597 }
579598}
580599
581- impl < UART : Instance , WORD > RxListen for Rx < UART , WORD > {
582- fn listen ( & mut self ) {
583- self . usart . listen_rxne ( )
584- }
585-
586- fn unlisten ( & mut self ) {
587- self . usart . unlisten_rxne ( )
588- }
589-
590- fn listen_idle ( & mut self ) {
591- self . usart . listen_idle ( )
592- }
593-
594- fn unlisten_idle ( & mut self ) {
595- self . usart . unlisten_idle ( )
596- }
597- }
598-
599- impl < UART : Instance , WORD > TxListen for Tx < UART , WORD > {
600- fn listen ( & mut self ) {
601- self . usart . listen_txe ( )
602- }
603-
604- fn unlisten ( & mut self ) {
605- self . usart . unlisten_txe ( )
606- }
607- }
608-
609600impl < UART : Instance , WORD > crate :: ClearFlags for Serial < UART , WORD > {
610601 type Flag = CFlag ;
611602
@@ -628,20 +619,12 @@ impl<UART: Instance, WORD> crate::Listen for Serial<UART, WORD> {
628619 type Event = Event ;
629620
630621 #[ inline( always) ]
631- fn listen ( & mut self , event : impl Into < BitFlags < Event > > ) {
632- self . tx . usart . listen_event ( None , Some ( event. into ( ) ) ) ;
633- }
634-
635- #[ inline( always) ]
636- fn listen_only ( & mut self , event : impl Into < BitFlags < Self :: Event > > ) {
637- self . tx
638- . usart
639- . listen_event ( Some ( BitFlags :: ALL ) , Some ( event. into ( ) ) ) ;
640- }
641-
642- #[ inline( always) ]
643- fn unlisten ( & mut self , event : impl Into < BitFlags < Event > > ) {
644- self . tx . usart . listen_event ( Some ( event. into ( ) ) , None ) ;
622+ fn listen_event (
623+ & mut self ,
624+ disable : Option < BitFlags < Self :: Event > > ,
625+ enable : Option < BitFlags < Self :: Event > > ,
626+ ) {
627+ self . tx . usart . listen_event ( disable, enable)
645628 }
646629}
647630
0 commit comments