Skip to content

Instantly share code, notes, and snippets.

@mvirkkunen
Created April 13, 2020 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvirkkunen/d2738b8cd42e16f39a0a34068c9e9084 to your computer and use it in GitHub Desktop.
Save mvirkkunen/d2738b8cd42e16f39a0a34068c9e9084 to your computer and use it in GitHub Desktop.
impl<U: UsbCore> UsbClass<U> for CdcAcmClass<U> {
fn configure(&mut self, mut config: Config<U>) -> Result<()> {
const DESC: InterfaceDescriptor = InterfaceDescriptor::class(USB_CLASS_CDC)
.sub_class(CDC_SUBCLASS_ACM).protocol(CDC_PROTOCOL_NONE);
let mut assoc = config.interface_association(DESC)?;
assoc
.interface(
&mut self.comm_if,
DESC)?
.descriptor(
CS_INTERFACE,
&[
CDC_TYPE_HEADER, // bDescriptorSubtype
0x10, 0x01 // bcdCDC (1.10)
])?
.descriptor(
CS_INTERFACE,
&[
CDC_TYPE_ACM, // bDescriptorSubtype
0x00 // bmCapabilities
])?
.descriptor(
CS_INTERFACE,
&[
CDC_TYPE_UNION, // bDescriptorSubtype
(&self.comm_if).into(), // bControlInterface
(&self.data_if).into() // bSubordinateInterface
])?
.descriptor(
CS_INTERFACE,
&[
CDC_TYPE_CALL_MANAGEMENT, // bDescriptorSubtype
0x00, // bmCapabilities
(&self.data_if).into() // bDataInterface
])?
.endpoint_in(&mut self.comm_ep)?;
assoc
.interface(
&mut self.data_if,
InterfaceDescriptor::class(USB_CLASS_CDC_DATA))?
.endpoint_in(&mut self.write_ep)?
.endpoint_out(&mut self.read_ep)?;
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment