Skip to main content

GsUsbClass

Struct GsUsbClass 

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

USB GS_USB class implementing the candleLight / Linux gs_usb protocol.

Provides a bidirectional CAN channel via USB bulk endpoints plus vendor-specific control requests for configuration.

Implementations§

Source§

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

Source

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

Create a new GS_USB class with default device configuration.

Call set_device_config and set_bt_const before connecting to set device-specific parameters.

Source

pub fn set_device_config(&mut self, cfg: GsDeviceConfig)

Set the device configuration reported to the host.

Source

pub fn set_bt_const(&mut self, c: GsDeviceBtConst)

Set the bit-timing constraints reported to the host.

Source

pub fn is_configured(&self) -> bool

true when the device is configured by the host.

Source

pub fn mode(&self) -> u32

Current CAN controller mode.

Source

pub fn mode_flags(&self) -> u32

Current mode flags.

Source

pub fn bit_timing(&self) -> &GsDeviceBitTiming

Current bit timing parameters.

Source

pub fn try_recv(&self) -> UsbResult<Option<GsHostFrame>>

Attempt to read a CAN frame from the host (bulk OUT).

Returns Ok(Some(frame)) when a frame is available, Ok(None) when no data is waiting, or an error.

Source

pub fn try_send(&self, frame: &GsHostFrame) -> UsbResult<()>

Send a CAN frame to the host (bulk IN).

Returns Ok(()) on success, or an error (e.g. WouldBlock if the previous packet hasn’t been sent yet).

Trait Implementations§

Source§

impl<B: UsbBus> UsbClass<B> for GsUsbClass<'_, B>

Source§

fn configuration_descriptors( &self, w: &mut DescriptorWriter<'_>, ) -> UsbResult<()>

Append this class’s interface and endpoint descriptors.
Source§

fn control_in(&mut self, xfer: ControlIn<'_, B>)

Handle a control IN transfer. Accept, reject, or pass (drop without acting).
Source§

fn control_out(&mut self, xfer: ControlOut<'_, B>)

Handle a control OUT transfer. Accept, reject, or pass (drop without acting).
Source§

fn configure(&mut self)

Called when the host sends SET_CONFIGURATION(1).
Source§

fn deconfigure(&mut self)

Called when the host sends SET_CONFIGURATION(0) or on reset.
Source§

fn reset(&mut self)

Called after a USB bus reset.
Source§

fn string(&self, index: StringIndex, lang_id: u16) -> Option<&str>

Return the string for a previously allocated StringIndex, or None.
Source§

fn endpoint_out(&mut self, addr: EndpointAddress)

Called when endpoint addr received an OUT packet.
Source§

fn endpoint_in_complete(&mut self, addr: EndpointAddress)

Called when endpoint addr completed an IN transfer.
Source§

fn endpoint_setup(&mut self, addr: EndpointAddress)

Called when endpoint addr received a SETUP packet (non-EP0 control).
Source§

fn poll(&mut self)

Called unconditionally on every UsbDevice::poll.
Source§

fn alt_setting(&mut self, interface: InterfaceNumber) -> Option<u8>

Return the current alternate setting for interface, or None.
Source§

fn set_alt_setting(&mut self, interface: InterfaceNumber, alt: u8) -> bool

Set the alternate setting for interface. Return true if handled.

Auto Trait Implementations§

§

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

§

impl<'a, B> Freeze for GsUsbClass<'a, B>
where Endpoint<'a, B, In>: Freeze, Endpoint<'a, B, Out>: Freeze,

§

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

§

impl<'a, B> RefUnwindSafe for GsUsbClass<'a, B>

§

impl<'a, B> Send for GsUsbClass<'a, B>
where Endpoint<'a, B, In>: Send, Endpoint<'a, B, Out>: Send,

§

impl<'a, B> Sync for GsUsbClass<'a, B>
where Endpoint<'a, B, In>: Sync, Endpoint<'a, B, Out>: Sync,

§

impl<'a, B> Unpin for GsUsbClass<'a, B>
where Endpoint<'a, B, In>: Unpin, Endpoint<'a, B, Out>: Unpin,

§

impl<'a, B> UnsafeUnpin for GsUsbClass<'a, B>
where Endpoint<'a, B, In>: UnsafeUnpin, Endpoint<'a, B, Out>: UnsafeUnpin,

§

impl<'a, B> UnwindSafe for GsUsbClass<'a, B>
where Endpoint<'a, B, In>: UnwindSafe, Endpoint<'a, B, Out>: UnwindSafe,

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.