Skip to main content

UsbDeviceBuilder

Struct UsbDeviceBuilder 

Source
pub struct UsbDeviceBuilder<'a, B: UsbBus> { /* private fields */ }
Expand description

Builder for UsbDevice.

§Example

ⓘ
use my_hal_usb::{UsbBusAllocator, UsbDeviceBuilder};
use my_hal_usb::class::cdc_acm::CdcAcm;
use my_hal_usb::MyBus;

let alloc = UsbBusAllocator::new(MyBus::new(/* peripheral */));
let mut serial = CdcAcm::new(&alloc);
let mut usb_dev = UsbDeviceBuilder::new(&alloc, 0x1234, 0x5678)
    .product("My Device")
    .manufacturer("My Company")
    .serial_number("001")
    .build();

loop {
    if usb_dev.poll(&mut [&mut serial]) { /* … */ }
}

Implementations§

Source§

impl<'a, B: UsbBus> UsbDeviceBuilder<'a, B>

Source

pub fn new( alloc: &'a UsbBusAllocator<B>, vendor_id: u16, product_id: u16, ) -> Self

Create a builder with the required VID/PID pair.

Source

pub fn build(self) -> UsbDevice<'a, B>

Build the UsbDevice. Allocates EP0 and enables the peripheral.

Source

pub fn device_class(self, c: u8) -> Self

Set the device class code.

Source

pub fn device_sub_class(self, c: u8) -> Self

Set the device subclass code.

Source

pub fn device_protocol(self, c: u8) -> Self

Set the device protocol code.

Source

pub fn device_release(self, r: u16) -> Self

Set the device release number (BCD).

Source

pub fn usb_rev(self, r: u16) -> Self

Set the USB specification release (BCD, e.g. 0x0200).

Source

pub fn max_packet_size_0(self, s: u8) -> Self

Set the EP0 maximum packet size (8, 16, 32 or 64).

Source

pub fn manufacturer(self, s: &'a str) -> Self

Set the manufacturer string.

Source

pub fn product(self, s: &'a str) -> Self

Set the product string.

Source

pub fn serial_number(self, s: &'a str) -> Self

Set the serial-number string.

Source

pub fn self_powered(self, v: bool) -> Self

Declare that the device is self-powered.

Source

pub fn supports_remote_wakeup(self, v: bool) -> Self

Declare remote-wakeup support.

Source

pub fn max_power_ma(self, ma: u16) -> Self

Set maximum power in mA (stored as mA/2 per USB spec).

Source

pub fn composite_with_iads(self) -> Self

Configure as a composite device with Interface Association Descriptors.

Auto Trait Implementations§

§

impl<'a, B> !RefUnwindSafe for UsbDeviceBuilder<'a, B>

§

impl<'a, B> !UnwindSafe for UsbDeviceBuilder<'a, B>

§

impl<'a, B> Forget for UsbDeviceBuilder<'a, B>

§

impl<'a, B> Freeze for UsbDeviceBuilder<'a, B>
where &'a UsbBusAllocator<B>: Freeze,

§

impl<'a, B> Move for UsbDeviceBuilder<'a, B>

§

impl<'a, B> Send for UsbDeviceBuilder<'a, B>
where &'a UsbBusAllocator<B>: Send,

§

impl<'a, B> Sync for UsbDeviceBuilder<'a, B>
where &'a UsbBusAllocator<B>: Sync,

§

impl<'a, B> Unpin for UsbDeviceBuilder<'a, B>
where &'a UsbBusAllocator<B>: Unpin,

§

impl<'a, B> UnsafeUnpin for UsbDeviceBuilder<'a, B>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.