Skip to content

Commit b12648d

Browse files
committed
avoid static mut for USB test device builder
1 parent a6e6c91 commit b12648d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/test_class.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ mod sizes {
2222
pub const INTERRUPT_ENDPOINT: u16 = 31;
2323
}
2424

25-
static mut CONTROL_BUFFER: UnsafeCell<[u8; 256]> = UnsafeCell::new([0; 256]);
25+
pub struct ControlBuffer(UnsafeCell<[u8; 256]>);
26+
27+
unsafe impl Sync for ControlBuffer {}
28+
29+
static CONTROL_BUFFER: ControlBuffer = ControlBuffer(UnsafeCell::new([0; 256]));
2630

2731
/// Test USB class for testing USB driver implementations. Supports various endpoint types and
2832
/// requests for testing USB peripheral drivers on actual hardware.
@@ -115,7 +119,7 @@ impl<B: UsbBus> TestClass<'_, B> {
115119
usb_bus: &'a UsbBusAllocator<B>,
116120
) -> UsbDeviceBuilder<'a, B> {
117121
UsbDeviceBuilder::new(usb_bus, UsbVidPid(VID, PID), unsafe {
118-
CONTROL_BUFFER.get_mut()
122+
&mut *(CONTROL_BUFFER.0.get())
119123
})
120124
.strings(&[StringDescriptors::default()
121125
.manufacturer(MANUFACTURER)

0 commit comments

Comments
 (0)