@@ -127,6 +127,72 @@ impl Provider {
127127 }
128128}
129129
130+ bitfield ! {
131+ /// Flags for disconnect events
132+ #[ derive( Copy , Clone , PartialEq , Eq ) ]
133+ #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
134+ struct ConsumerDisconnectRaw ( u32 ) ;
135+ impl Debug ;
136+ /// Renegotiation
137+ ///
138+ /// When set this flag indicates that the current consumer is attempting to negotiate a new power capability.
139+ pub bool , renegotiation, set_renegotiation: 0 ;
140+ /// Switching
141+ ///
142+ /// When set this flag indicates that the service is switching to a different PSU.
143+ pub bool , switching, set_switching: 1 ;
144+ }
145+
146+ /// Type safe wrapper for consumer disconnect flags
147+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
148+ #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
149+ pub struct ConsumerDisconnect ( ConsumerDisconnectRaw ) ;
150+
151+ impl ConsumerDisconnect {
152+ /// Create new consumer disconnect flags with no flags set
153+ pub const fn none ( ) -> Self {
154+ Self ( ConsumerDisconnectRaw ( 0 ) )
155+ }
156+
157+ /// Builder method to set the renegotiation flag
158+ pub fn with_renegotiation ( mut self , value : bool ) -> Self {
159+ self . set_renegotiation ( value) ;
160+ self
161+ }
162+
163+ /// Set the value of the renegotiation flag
164+ pub fn set_renegotiation ( & mut self , value : bool ) {
165+ self . 0 . set_renegotiation ( value) ;
166+ }
167+
168+ /// Get the value of the renegotiation flag
169+ pub fn renegotiation ( & self ) -> bool {
170+ self . 0 . renegotiation ( )
171+ }
172+
173+ /// Builder method to set the switching flag
174+ pub fn with_switching ( mut self , value : bool ) -> Self {
175+ self . set_switching ( value) ;
176+ self
177+ }
178+
179+ /// Set the value of the switching flag
180+ pub fn set_switching ( & mut self , value : bool ) {
181+ self . 0 . set_switching ( value) ;
182+ }
183+
184+ /// Get the value of the switching flag
185+ pub fn switching ( & self ) -> bool {
186+ self . 0 . switching ( )
187+ }
188+ }
189+
190+ impl Default for ConsumerDisconnect {
191+ fn default ( ) -> Self {
192+ Self :: none ( )
193+ }
194+ }
195+
130196#[ cfg( test) ]
131197mod tests {
132198 use super :: * ;
@@ -180,4 +246,20 @@ mod tests {
180246 provider. set_psu_type ( PsuType :: Unknown ) ;
181247 assert_eq ! ( provider. 0.0 , 0x0 ) ;
182248 }
249+
250+ #[ test]
251+ fn test_consumer_disconnect_renegotiation ( ) {
252+ let mut disconnect = ConsumerDisconnect :: none ( ) . with_renegotiation ( true ) ;
253+ assert_eq ! ( disconnect. 0.0 , 0x1 ) ;
254+ disconnect. set_renegotiation ( false ) ;
255+ assert_eq ! ( disconnect. 0.0 , 0x0 ) ;
256+ }
257+
258+ #[ test]
259+ fn test_consumer_disconnect_switching ( ) {
260+ let mut disconnect = ConsumerDisconnect :: none ( ) . with_switching ( true ) ;
261+ assert_eq ! ( disconnect. 0.0 , 0x2 ) ;
262+ disconnect. set_switching ( false ) ;
263+ assert_eq ! ( disconnect. 0.0 , 0x0 ) ;
264+ }
183265}
0 commit comments