@@ -126,18 +126,19 @@ impl<B: UsbBus> ControlPipe<'_, B> {
126
126
None
127
127
}
128
128
129
- pub fn handle_out ( & mut self ) -> Option < Request > {
129
+ pub fn handle_out ( & mut self ) -> Result < Option < Request > > {
130
130
match self . state {
131
131
ControlState :: DataOut ( req) => {
132
132
let i = self . i ;
133
133
let count = match self . ep_out . read ( & mut self . buf [ i..] ) {
134
134
Ok ( count) => count,
135
- Err ( UsbError :: WouldBlock ) => return None ,
136
- Err ( _ ) => {
135
+ Err ( UsbError :: WouldBlock ) => return Ok ( None ) ,
136
+ Err ( _err ) => {
137
137
// Failed to read or buffer overflow (overflow is only possible if the host
138
138
// sends more data than it indicated in the SETUP request)
139
+ usb_debug ! ( "Failed EP0 read: {:?}" , _err) ;
139
140
self . set_error ( ) ;
140
- return None ;
141
+ return Ok ( None ) ;
141
142
}
142
143
} ;
143
144
@@ -151,7 +152,7 @@ impl<B: UsbBus> ControlPipe<'_, B> {
151
152
if self . i >= self . len {
152
153
usb_debug ! ( "Request OUT complete: {:?}" , req) ;
153
154
self . state = ControlState :: CompleteOut ;
154
- return Some ( req) ;
155
+ return Ok ( Some ( req) ) ;
155
156
}
156
157
}
157
158
// The host may terminate a DATA stage early by sending a zero-length status packet
@@ -164,7 +165,7 @@ impl<B: UsbBus> ControlPipe<'_, B> {
164
165
"Control transfer completed. Current state: {:?}" ,
165
166
self . state
166
167
) ;
167
- let _ = self . ep_out . read ( & mut [ ] ) ;
168
+ self . ep_out . read ( & mut [ ] ) ? ;
168
169
self . state = ControlState :: Idle ;
169
170
}
170
171
_ => {
@@ -173,28 +174,23 @@ impl<B: UsbBus> ControlPipe<'_, B> {
173
174
"Discarding EP0 data due to unexpected state. Current state: {:?}" ,
174
175
self . state
175
176
) ;
176
- let _ = self . ep_out . read ( & mut [ ] ) ;
177
+ self . ep_out . read ( & mut [ ] ) ? ;
177
178
178
179
// Unexpected OUT packet
179
180
self . set_error ( )
180
181
}
181
182
}
182
183
183
- None
184
+ Ok ( None )
184
185
}
185
186
186
- pub fn handle_in_complete ( & mut self ) -> bool {
187
+ pub fn handle_in_complete ( & mut self ) -> Result < bool > {
187
188
match self . state {
188
189
ControlState :: DataIn => {
189
- self . write_in_chunk ( ) ;
190
+ self . write_in_chunk ( ) ? ;
190
191
}
191
192
ControlState :: DataInZlp => {
192
- if self . ep_in . write ( & [ ] ) . is_err ( ) {
193
- // There isn't much we can do if the write fails, except to wait for another
194
- // poll or for the host to resend the request.
195
- return false ;
196
- }
197
-
193
+ self . ep_in . write ( & [ ] ) ?;
198
194
usb_trace ! ( "wrote EP0: ZLP" ) ;
199
195
self . state = ControlState :: DataInLast ;
200
196
}
@@ -204,7 +200,7 @@ impl<B: UsbBus> ControlPipe<'_, B> {
204
200
}
205
201
ControlState :: StatusIn => {
206
202
self . state = ControlState :: Idle ;
207
- return true ;
203
+ return Ok ( true ) ;
208
204
}
209
205
ControlState :: Idle => {
210
206
// If we received a message on EP0 while sending the last portion of an IN
@@ -218,23 +214,14 @@ impl<B: UsbBus> ControlPipe<'_, B> {
218
214
}
219
215
} ;
220
216
221
- false
217
+ Ok ( false )
222
218
}
223
219
224
- fn write_in_chunk ( & mut self ) {
220
+ fn write_in_chunk ( & mut self ) -> Result < ( ) > {
225
221
let count = min ( self . len - self . i , self . ep_in . max_packet_size ( ) as usize ) ;
226
222
227
223
let buffer = self . static_in_buf . unwrap_or ( & self . buf ) ;
228
- let count = match self . ep_in . write ( & buffer[ self . i ..( self . i + count) ] ) {
229
- Ok ( c) => c,
230
- // There isn't much we can do if the write fails, except to wait for another poll or for
231
- // the host to resend the request.
232
- Err ( _err) => {
233
- usb_debug ! ( "Failed to write EP0: {:?}" , _err) ;
234
- return ;
235
- }
236
- } ;
237
-
224
+ let count = self . ep_in . write ( & buffer[ self . i ..( self . i + count) ] ) ?;
238
225
usb_trace ! ( "wrote EP0: {:?}" , & buffer[ self . i..( self . i + count) ] ) ;
239
226
240
227
self . i += count;
@@ -248,6 +235,8 @@ impl<B: UsbBus> ControlPipe<'_, B> {
248
235
ControlState :: DataInLast
249
236
} ;
250
237
}
238
+
239
+ Ok ( ( ) )
251
240
}
252
241
253
242
pub fn accept_out ( & mut self ) -> Result < ( ) > {
@@ -259,7 +248,7 @@ impl<B: UsbBus> ControlPipe<'_, B> {
259
248
}
260
249
} ;
261
250
262
- let _ = self . ep_in . write ( & [ ] ) ;
251
+ self . ep_in . write ( & [ ] ) ? ;
263
252
self . state = ControlState :: StatusIn ;
264
253
Ok ( ( ) )
265
254
}
@@ -301,7 +290,7 @@ impl<B: UsbBus> ControlPipe<'_, B> {
301
290
self . len = min ( data_len, req. length as usize ) ;
302
291
self . i = 0 ;
303
292
self . state = ControlState :: DataIn ;
304
- self . write_in_chunk ( ) ;
293
+ self . write_in_chunk ( ) ? ;
305
294
306
295
Ok ( ( ) )
307
296
}
0 commit comments