Class: LIBUSB::Endpoint

Inherits:
FFI::Struct
  • Object
show all
Includes:
Comparable
Defined in:
lib/libusb/endpoint.rb

Constant Summary collapse

TransferTypes =
[:control, :isochronous, :bulk, :interrupt]
SynchronizationTypes =
[:no_synchronization, :asynchronous, :adaptive, :synchronous]
UsageTypes =
[:data, :feedback, :implicit_feedback, :unknown]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(setting, *args) ⇒ Endpoint

Returns a new instance of Endpoint.


148
149
150
151
# File 'lib/libusb/endpoint.rb', line 148

def initialize(setting, *args)
  @setting = setting
  super(*args)
end

Instance Attribute Details

#settingSetting (readonly)

Returns the setting this endpoint belongs to.

Returns:

  • (Setting)

    the setting this endpoint belongs to.


154
155
156
# File 'lib/libusb/endpoint.rb', line 154

def setting
  @setting
end

Instance Method Details

#<=>(o) ⇒ Object


168
169
170
171
172
# File 'lib/libusb/endpoint.rb', line 168

def <=>(o)
  t = setting<=>o.setting
  t = bEndpointAddress<=>o.bEndpointAddress if t==0
  t
end

#bDescriptorTypeObject

Descriptor type (0x05)


39
40
41
# File 'lib/libusb/endpoint.rb', line 39

def bDescriptorType
  self[:bDescriptorType]
end

#bEndpointAddressInteger

The address of the endpoint described by this descriptor.

  • Bits 0..3: Endpoint Number.

  • Bits 4..6: Reserved. Set to Zero

  • Bits 7: Direction 0 = Out, 1 = In (Ignored for Control Endpoints)

Returns:

  • (Integer)

See Also:


53
54
55
# File 'lib/libusb/endpoint.rb', line 53

def bEndpointAddress
  self[:bEndpointAddress]
end

#bIntervalObject

Interval for polling endpoint data transfers. Value in frame counts. Ignored for Bulk & Control Endpoints. Isochronous must equal 1 and field may range from 1 to 255 for interrupt endpoints.

The interval is respected by the kernel driver, so user mode processes using libusb don't need to care about it.


126
127
128
# File 'lib/libusb/endpoint.rb', line 126

def bInterval
  self[:bInterval]
end

#bLengthObject

Size of Descriptor in Bytes (7 bytes)


34
35
36
# File 'lib/libusb/endpoint.rb', line 34

def bLength
  self[:bLength]
end

#bmAttributesInteger

Attributes which apply to the endpoint when it is configured using the Configuration#bConfigurationValue.

  • Bits 1..0: Transfer Type

    • 00 = Control

    • 01 = Isochronous

    • 10 = Bulk

    • 11 = Interrupt

  • Bits 7..2: are reserved. If Isochronous endpoint,

  • Bits 3..2: Synchronisation Type (Iso Mode)

    • 00 = No Synchonisation

    • 01 = Asynchronous

    • 10 = Adaptive

    • 11 = Synchronous

  • Bits 5..4: Usage Type (Iso Mode)

    • 00 = Data Endpoint

    • 01 = Feedback Endpoint

    • 10 = Explicit Feedback Data Endpoint

    • 11 = Reserved

Returns:

  • (Integer)

See Also:


91
92
93
# File 'lib/libusb/endpoint.rb', line 91

def bmAttributes
  self[:bmAttributes]
end

#bRefreshObject

For audio devices only: the rate at which synchronization feedback is provided.


131
132
133
# File 'lib/libusb/endpoint.rb', line 131

def bRefresh
  self[:bRefresh]
end

#bSynchAddressObject

For audio devices only: the address if the synch endpoint.


136
137
138
# File 'lib/libusb/endpoint.rb', line 136

def bSynchAddress
  self[:bSynchAddress]
end

#configurationObject

The Configuration this Endpoint belongs to.


164
# File 'lib/libusb/endpoint.rb', line 164

def configuration() self.setting.interface.configuration end

#deviceObject

The Device this Endpoint belongs to.


162
# File 'lib/libusb/endpoint.rb', line 162

def device() self.setting.interface.configuration.device end

#directionSymbol

Returns Either :in or :out.

Returns:

  • (Symbol)

    Either :in or :out


63
64
65
# File 'lib/libusb/endpoint.rb', line 63

def direction
  bEndpointAddress & ENDPOINT_IN == 0 ? :out : :in
end

#endpoint_numberInteger

Returns:

  • (Integer)

58
59
60
# File 'lib/libusb/endpoint.rb', line 58

def endpoint_number
  bEndpointAddress & 0b1111
end

#extraString

Extra descriptors.

Returns:

  • (String)

143
144
145
146
# File 'lib/libusb/endpoint.rb', line 143

def extra
  return if self[:extra].null?
  self[:extra].read_string(self[:extra_length])
end

#inspectObject


156
157
158
159
# File 'lib/libusb/endpoint.rb', line 156

def inspect
  type = [transfer_type, synchronization_type, usage_type].compact
  "\#<#{self.class} #{endpoint_number} #{direction} #{type.join(" ")}>"
end

#interfaceObject

The Interface this Endpoint belongs to.


166
# File 'lib/libusb/endpoint.rb', line 166

def interface() self.setting.interface end

#ss_companionSsCompanion

Get the endpoints superspeed endpoint companion descriptor (if any).

Since libusb version 1.0.16.

Returns:


182
183
184
185
186
187
188
189
190
191
# File 'lib/libusb/endpoint.rb', line 182

def ss_companion
  ep_comp = FFI::MemoryPointer.new :pointer
  res = Call.libusb_get_ss_endpoint_companion_descriptor(
    device.context.instance_variable_get(:@ctx),
    pointer,
    ep_comp
  )
  LIBUSB.raise_error res, "in libusb_get_ss_endpoint_companion_descriptor" if res!=0
  SsCompanion.new ep_comp.read_pointer
end

#synchronization_typeSymbol

Returns One of SynchronizationTypes.

Returns:


103
104
105
106
# File 'lib/libusb/endpoint.rb', line 103

def synchronization_type
  return unless transfer_type == :isochronous
  SynchronizationTypes[(bmAttributes & 0b1100) >> 2]
end

#transfer_typeSymbol

Returns One of TransferTypes.

Returns:


97
98
99
# File 'lib/libusb/endpoint.rb', line 97

def transfer_type
  TransferTypes[bmAttributes & 0b11]
end

#usage_typeSymbol

Returns One of UsageTypes.

Returns:


110
111
112
113
# File 'lib/libusb/endpoint.rb', line 110

def usage_type
  return unless transfer_type == :isochronous
  UsageTypes[(bmAttributes & 0b110000) >> 4]
end

#wMaxPacketSizeObject

Maximum Packet Size this endpoint is capable of sending or receiving


116
117
118
# File 'lib/libusb/endpoint.rb', line 116

def wMaxPacketSize
  self[:wMaxPacketSize]
end