Add config, interfaces, endpoints, etc
This commit is contained in:
@@ -5,17 +5,16 @@ package usb
|
||||
import "C"
|
||||
|
||||
type Descriptor struct {
|
||||
desc *C.struct_libusb_device_descriptor
|
||||
desc *C.struct_libusb_device_descriptor
|
||||
|
||||
Type DescriptorType // The type of this descriptor
|
||||
Spec BCD // USB Specification Release Number
|
||||
Class Class // The class of this device
|
||||
SubClass uint8 // The sub-class (within the class) of this device
|
||||
Protocol uint8 // The protocol (within the sub-class) of this device
|
||||
Vendor ID // The 8-bit Vendor identifer
|
||||
Product ID // The 8-bit Product identifier
|
||||
Device BCD // The device version
|
||||
Configs int // Number of configurations
|
||||
Type DescriptorType // The type of this descriptor
|
||||
Spec BCD // USB Specification Release Number
|
||||
Class Class // The class of this device
|
||||
SubClass uint8 // The sub-class (within the class) of this device
|
||||
Protocol uint8 // The protocol (within the sub-class) of this device
|
||||
Vendor ID // The 8-bit Vendor identifer
|
||||
Product ID // The 8-bit Product identifier
|
||||
Device BCD // The device version
|
||||
}
|
||||
|
||||
func newDescriptor(dev *C.libusb_device) (*Descriptor, error) {
|
||||
@@ -33,10 +32,36 @@ func newDescriptor(dev *C.libusb_device) (*Descriptor, error) {
|
||||
Vendor: ID(desc.idVendor),
|
||||
Product: ID(desc.idProduct),
|
||||
Device: BCD(desc.bcdDevice),
|
||||
Configs: int(desc.bNumConfigurations),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Configurations returns a list of configurations configured on this
|
||||
// device. Each config must be Closed.
|
||||
func (d *DeviceInfo) Configurations() (_c []*Config, _e error) {
|
||||
var desc C.struct_libusb_device_descriptor
|
||||
if errno := C.libusb_get_device_descriptor(d.dev, &desc); errno < 0 {
|
||||
return nil, usbError(errno)
|
||||
}
|
||||
|
||||
var cfgs []*Config
|
||||
defer func() {
|
||||
if _e != nil {
|
||||
for _, c := range cfgs {
|
||||
c.Close()
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
for i := 0; i < int(desc.bNumConfigurations); i++ {
|
||||
var cfg *C.struct_libusb_config_descriptor
|
||||
if errno := C.libusb_get_config_descriptor(d.dev, C.uint8_t(i), &cfg); errno < 0 {
|
||||
return nil, usbError(errno)
|
||||
}
|
||||
cfgs = append(cfgs, newConfig(cfg))
|
||||
}
|
||||
return cfgs, nil
|
||||
}
|
||||
|
||||
/*
|
||||
func (d Descriptor) str(idx int) (string, error) {
|
||||
str := [64]byte{}
|
||||
|
Reference in New Issue
Block a user