@@ -13,7 +13,7 @@ use crate::{
13
13
pac:: USBD ,
14
14
} ;
15
15
use core:: sync:: atomic:: { compiler_fence, Ordering } ;
16
- use core:: { cell:: Cell , mem , ptr } ;
16
+ use core:: cell:: Cell ;
17
17
use core:: mem:: MaybeUninit ;
18
18
use cortex_m:: interrupt:: { self , Mutex } ;
19
19
use usb_device:: {
@@ -31,10 +31,6 @@ fn dma_end() {
31
31
}
32
32
33
33
struct Buffers {
34
- // Ptr and size is stored separately to save space
35
- in_bufs : [ * mut u8 ; 9 ] ,
36
- out_bufs : [ * mut u8 ; 9 ] ,
37
-
38
34
// Buffers can be up to 64 Bytes since this is a Full-Speed implementation.
39
35
in_lens : [ u8 ; 9 ] ,
40
36
out_lens : [ u8 ; 9 ] ,
@@ -43,8 +39,6 @@ struct Buffers {
43
39
impl Buffers {
44
40
fn new ( ) -> Self {
45
41
Self {
46
- in_bufs : [ ptr:: null_mut ( ) ; 9 ] ,
47
- out_bufs : [ ptr:: null_mut ( ) ; 9 ] ,
48
42
in_lens : [ 0 ; 9 ] ,
49
43
out_lens : [ 0 ; 9 ] ,
50
44
}
@@ -72,7 +66,6 @@ pub struct Usbd<'c> {
72
66
periph : Mutex < USBD > ,
73
67
// argument passed to `UsbDeviceBuilder.max_packet_size_0`
74
68
max_packet_size_0 : u16 ,
75
- unalloc_buffers : & ' static mut [ u8 ] ,
76
69
bufs : Buffers ,
77
70
used_in : u8 ,
78
71
used_out : u8 ,
@@ -90,19 +83,14 @@ impl<'c> Usbd<'c> {
90
83
/// # Parameters
91
84
///
92
85
/// * `periph`: The raw USBD peripheral.
93
- /// * `endpoint_buffers`: Backing storage for the endpoint buffers. This
94
- /// needs to be big enough to accomodate all buffers of all endpoints, or
95
- /// `alloc_ep` will fail.
96
86
#[ inline]
97
- pub fn new_alloc < L , LSTAT > (
87
+ pub fn new < L , LSTAT > (
98
88
periph : USBD ,
99
- endpoint_buffers : & ' static mut [ u8 ] ,
100
89
_clocks : & ' c Clocks < ExternalOscillator , L , LSTAT > ,
101
90
) -> UsbBusAllocator < Self > {
102
91
UsbBusAllocator :: new ( Self {
103
92
periph : Mutex :: new ( periph) ,
104
93
max_packet_size_0 : 0 ,
105
- unalloc_buffers : endpoint_buffers,
106
94
bufs : Buffers :: new ( ) ,
107
95
used_in : 0 ,
108
96
used_out : 0 ,
@@ -123,36 +111,6 @@ impl<'c> Usbd<'c> {
123
111
unsafe { & * USBD :: ptr ( ) } . usbaddr . read ( ) . addr ( ) . bits ( )
124
112
}
125
113
126
- fn alloc_ep_buf (
127
- & mut self ,
128
- ep_type : EndpointType ,
129
- mut size : u16 ,
130
- ) -> usb_device:: Result < & ' static mut [ u8 ] > {
131
- if self . unalloc_buffers . len ( ) < usize:: from ( size) {
132
- Err ( UsbError :: EndpointMemoryOverflow )
133
- } else {
134
- if ep_type == EndpointType :: Bulk || ep_type == EndpointType :: Interrupt {
135
- // datasheet: buffer must be 4-byte aligned and its size must be a multiple of 4
136
- let rem = self . unalloc_buffers . as_mut_ptr ( ) as usize % 4 ;
137
- if rem != 0 {
138
- let ( _padding, remaining) =
139
- mem:: replace ( & mut self . unalloc_buffers , & mut [ ] ) . split_at_mut ( 4 - rem) ;
140
- self . unalloc_buffers = remaining;
141
- }
142
-
143
- let rem = size % 4 ;
144
- if rem != 0 {
145
- size = size + 4 - rem;
146
- }
147
- }
148
- assert ! ( size <= 64 ) ;
149
- let ( alloc, remaining) =
150
- mem:: replace ( & mut self . unalloc_buffers , & mut [ ] ) . split_at_mut ( size. into ( ) ) ;
151
- self . unalloc_buffers = remaining;
152
- Ok ( alloc)
153
- }
154
- }
155
-
156
114
fn is_used ( & self , ep : EndpointAddress ) -> bool {
157
115
if ep. index ( ) == 8 {
158
116
// ISO
@@ -234,8 +192,6 @@ impl UsbBus for Usbd<'_> {
234
192
self . max_packet_size_0 = max_packet_size;
235
193
}
236
194
237
- let buf = self . alloc_ep_buf ( ep_type, max_packet_size) ?;
238
-
239
195
if false {
240
196
unimplemented ! (
241
197
"alloc_ep({:?}, {:?}, {:?}, {}, {})" ,
@@ -247,15 +203,13 @@ impl UsbBus for Usbd<'_> {
247
203
) ;
248
204
}
249
205
250
- let ( used, bufs , lens) = match ep_dir {
206
+ let ( used, lens) = match ep_dir {
251
207
UsbDirection :: In => (
252
208
& mut self . used_in ,
253
- & mut self . bufs . in_bufs ,
254
209
& mut self . bufs . in_lens ,
255
210
) ,
256
211
UsbDirection :: Out => (
257
212
& mut self . used_out ,
258
- & mut self . bufs . out_bufs ,
259
213
& mut self . bufs . out_lens ,
260
214
) ,
261
215
} ;
@@ -271,8 +225,7 @@ impl UsbBus for Usbd<'_> {
271
225
return Err ( UsbError :: EndpointOverflow ) ;
272
226
} else {
273
227
* flag = true ;
274
- bufs[ 8 ] = buf. as_mut_ptr ( ) ;
275
- lens[ 8 ] = buf. len ( ) as u8 ;
228
+ lens[ 8 ] = max_packet_size as u8 ;
276
229
return Ok ( EndpointAddress :: from_parts ( 0x08 , ep_dir) ) ;
277
230
}
278
231
}
@@ -297,8 +250,7 @@ impl UsbBus for Usbd<'_> {
297
250
}
298
251
299
252
* used |= 1 << alloc_index;
300
- bufs[ alloc_index as usize ] = buf. as_mut_ptr ( ) ;
301
- lens[ alloc_index as usize ] = buf. len ( ) as u8 ;
253
+ lens[ alloc_index as usize ] = max_packet_size as u8 ;
302
254
303
255
let addr = EndpointAddress :: from_parts ( alloc_index as usize , ep_dir) ;
304
256
Ok ( addr)
0 commit comments