mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-28 17:52:28 +00:00
usb: set the interface handler in InterfaceBuilder.
This commit is contained in:
parent
092c2b7dfe
commit
7c6a88f3dd
@ -112,7 +112,8 @@ fn build<'d, D: Driver<'d>>(
|
||||
let len = config.report_descriptor.len();
|
||||
|
||||
let mut func = builder.function(USB_CLASS_HID, USB_SUBCLASS_NONE, USB_PROTOCOL_NONE);
|
||||
let mut iface = func.interface(Some(control));
|
||||
let mut iface = func.interface();
|
||||
iface.handler(control);
|
||||
let mut alt = iface.alt_setting(USB_CLASS_HID, USB_SUBCLASS_NONE, USB_PROTOCOL_NONE);
|
||||
|
||||
// HID descriptor
|
||||
@ -438,7 +439,7 @@ impl<'d> ControlHandler for Control<'d> {
|
||||
self.out_report_offset.store(0, Ordering::Release);
|
||||
}
|
||||
|
||||
fn get_descriptor<'a>(&'a mut self, req: Request, buf: &'a mut [u8]) -> InResponse<'a> {
|
||||
fn get_descriptor<'a>(&'a mut self, req: Request, _buf: &'a mut [u8]) -> InResponse<'a> {
|
||||
match (req.value >> 8) as u8 {
|
||||
HID_DESC_DESCTYPE_HID_REPORT => InResponse::Accepted(self.report_descriptor),
|
||||
HID_DESC_DESCTYPE_HID => InResponse::Accepted(&self.hid_descriptor),
|
||||
|
@ -178,7 +178,8 @@ impl<'d, D: Driver<'d>> CdcAcmClass<'d, D> {
|
||||
let mut func = builder.function(USB_CLASS_CDC, CDC_SUBCLASS_ACM, CDC_PROTOCOL_NONE);
|
||||
|
||||
// Control interface
|
||||
let mut iface = func.interface(Some(control));
|
||||
let mut iface = func.interface();
|
||||
iface.handler(control);
|
||||
let comm_if = iface.interface_number();
|
||||
let data_if = u8::from(comm_if) + 1;
|
||||
let mut alt = iface.alt_setting(USB_CLASS_CDC, CDC_SUBCLASS_ACM, CDC_PROTOCOL_NONE);
|
||||
@ -218,7 +219,7 @@ impl<'d, D: Driver<'d>> CdcAcmClass<'d, D> {
|
||||
let comm_ep = alt.endpoint_interrupt_in(8, 255);
|
||||
|
||||
// Data interface
|
||||
let mut iface = func.interface(None);
|
||||
let mut iface = func.interface();
|
||||
let data_if = iface.interface_number();
|
||||
let mut alt = iface.alt_setting(USB_CLASS_CDC_DATA, 0x00, CDC_PROTOCOL_NONE);
|
||||
let read_ep = alt.endpoint_bulk_out(max_packet_size);
|
||||
|
@ -267,17 +267,14 @@ impl<'a, 'd, D: Driver<'d>> FunctionBuilder<'a, 'd, D> {
|
||||
/// Add an interface to the function.
|
||||
///
|
||||
/// Interface numbers are guaranteed to be allocated consecutively, starting from 0.
|
||||
pub fn interface(
|
||||
&mut self,
|
||||
handler: Option<&'d mut dyn ControlHandler>,
|
||||
) -> InterfaceBuilder<'_, 'd, D> {
|
||||
pub fn interface(&mut self) -> InterfaceBuilder<'_, 'd, D> {
|
||||
if let Some(i) = self.iface_count_index {
|
||||
self.builder.config_descriptor.buf[i] += 1;
|
||||
}
|
||||
|
||||
let number = self.builder.interfaces.len() as _;
|
||||
let iface = Interface {
|
||||
handler,
|
||||
handler: None,
|
||||
current_alt_setting: 0,
|
||||
num_alt_settings: 0,
|
||||
};
|
||||
@ -307,6 +304,10 @@ impl<'a, 'd, D: Driver<'d>> InterfaceBuilder<'a, 'd, D> {
|
||||
self.interface_number
|
||||
}
|
||||
|
||||
pub fn handler(&mut self, handler: &'d mut dyn ControlHandler) {
|
||||
self.builder.interfaces[self.interface_number.0 as usize].handler = Some(handler);
|
||||
}
|
||||
|
||||
/// Add an alternate setting to the interface and write its descriptor.
|
||||
///
|
||||
/// Alternate setting numbers are guaranteed to be allocated consecutively, starting from 0.
|
||||
|
Loading…
Reference in New Issue
Block a user