usb-ncm: remove useless Cell.

This allows the CDC-NCM class struct to be Send, so you can run
it at a different priority than the main USB stack task.
This commit is contained in:
Dario Nieuwenhuis 2022-05-18 21:31:39 +02:00
parent 3d1501c020
commit 5eca119312

View File

@ -3,7 +3,6 @@
// This mod MUST go first, so that the others see its macros. // This mod MUST go first, so that the others see its macros.
pub(crate) mod fmt; pub(crate) mod fmt;
use core::cell::Cell;
use core::intrinsics::copy_nonoverlapping; use core::intrinsics::copy_nonoverlapping;
use core::mem::{size_of, MaybeUninit}; use core::mem::{size_of, MaybeUninit};
use embassy_usb::control::{self, ControlHandler, InResponse, OutResponse, Request}; use embassy_usb::control::{self, ControlHandler, InResponse, OutResponse, Request};
@ -119,14 +118,12 @@ impl<'a> State<'a> {
/// Shared data between Control and CdcAcmClass /// Shared data between Control and CdcAcmClass
struct ControlShared { struct ControlShared {
mac_addr: Cell<[u8; 6]>, mac_addr: [u8; 6],
} }
impl Default for ControlShared { impl Default for ControlShared {
fn default() -> Self { fn default() -> Self {
ControlShared { ControlShared { mac_addr: [0; 6] }
mac_addr: Cell::new([0; 6]),
}
} }
} }
@ -181,7 +178,7 @@ impl<'d> ControlHandler for CommControl<'d> {
fn get_string(&mut self, index: StringIndex, _lang_id: u16) -> Option<&str> { fn get_string(&mut self, index: StringIndex, _lang_id: u16) -> Option<&str> {
if index == self.mac_addr_string { if index == self.mac_addr_string {
let mac_addr = self.shared.mac_addr.get(); let mac_addr = self.shared.mac_addr;
let s = &mut self.mac_addr_str; let s = &mut self.mac_addr_str;
for i in 0..12 { for i in 0..12 {
let n = (mac_addr[i / 2] >> ((1 - i % 2) * 4)) & 0xF; let n = (mac_addr[i / 2] >> ((1 - i % 2) * 4)) & 0xF;
@ -230,8 +227,7 @@ impl<'d, D: Driver<'d>> CdcNcmClass<'d, D> {
mac_address: [u8; 6], mac_address: [u8; 6],
max_packet_size: u16, max_packet_size: u16,
) -> Self { ) -> Self {
let control_shared = &state.shared; state.shared.mac_addr = mac_address;
control_shared.mac_addr.set(mac_address);
let mut func = builder.function(USB_CLASS_CDC, CDC_SUBCLASS_NCM, CDC_PROTOCOL_NONE); let mut func = builder.function(USB_CLASS_CDC, CDC_SUBCLASS_NCM, CDC_PROTOCOL_NONE);
@ -240,7 +236,7 @@ impl<'d, D: Driver<'d>> CdcNcmClass<'d, D> {
let mac_addr_string = iface.string(); let mac_addr_string = iface.string();
iface.handler(state.comm_control.write(CommControl { iface.handler(state.comm_control.write(CommControl {
mac_addr_string, mac_addr_string,
shared: &control_shared, shared: &state.shared,
mac_addr_str: [0; 12], mac_addr_str: [0; 12],
})); }));
let comm_if = iface.interface_number(); let comm_if = iface.interface_number();
@ -305,7 +301,7 @@ impl<'d, D: Driver<'d>> CdcNcmClass<'d, D> {
data_if, data_if,
read_ep, read_ep,
write_ep, write_ep,
_control: control_shared, _control: &state.shared,
} }
} }