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