Skip to content

Instantly share code, notes, and snippets.

@mvirkkunen
Created April 13, 2020 11:13
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/b5040361049fcef4ba5ce6fe32b74116 to your computer and use it in GitHub Desktop.
Save mvirkkunen/b5040361049fcef4ba5ce6fe32b74116 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);
config
.interface_association(|a| a
.interface(&mut self.comm_if, DESC, |i| i
.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))
.interface(
&mut self.data_if,
InterfaceDescriptor::class(USB_CLASS_CDC_DATA),
|i| i
.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