Use Protocol type for USB interface protocol.

This commit is contained in:
Sebastian Zagrodzki
2017-04-09 18:42:04 +02:00
parent d3428d9b35
commit f91d53931a
7 changed files with 20 additions and 11 deletions

View File

@@ -86,7 +86,7 @@ type InterfaceSetup struct {
// IfClass is the USB-IF subclass code, as defined by the USB spec.
IfSubClass Class
// IfProtocol is USB protocol code, as defined by the USB spe.c
IfProtocol uint8
IfProtocol Protocol
// Endpoints has the list of endpoints available on this interface with
// this alternate setting.
Endpoints []EndpointInfo

View File

@@ -19,6 +19,7 @@ package usb
import "C"
import "strconv"
// Class represents a USB-IF class or subclass code.
type Class uint8
const (
@@ -58,6 +59,14 @@ func (c Class) String() string {
return strconv.Itoa(int(c))
}
// Protocol is the interface class protocol, qualified by the values
// of interface class and subclass.
type Protocol uint8
func (p Protocol) String() string {
return strconv.Itoa(int(p))
}
type DescriptorType uint8
const (

View File

@@ -29,9 +29,9 @@ type Descriptor struct {
Product ID // The Product identifier
// Protocol information
Class Class // The class of this device
SubClass Class // The sub-class (within the class) of this device
Protocol uint8 // The protocol (within the sub-class) of this device
Class Class // The class of this device
SubClass Class // The sub-class (within the class) of this device
Protocol Protocol // The protocol (within the sub-class) of this device
// Configuration information
Configs []ConfigInfo

View File

@@ -245,7 +245,7 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*Descriptor, error) {
Alternate: uint8(alt.bAlternateSetting),
IfClass: Class(alt.bInterfaceClass),
IfSubClass: Class(alt.bInterfaceSubClass),
IfProtocol: uint8(alt.bInterfaceProtocol),
IfProtocol: Protocol(alt.bInterfaceProtocol),
}
var ends []C.struct_libusb_endpoint_descriptor
*(*reflect.SliceHeader)(unsafe.Pointer(&ends)) = reflect.SliceHeader{
@@ -278,7 +278,7 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*Descriptor, error) {
Product: ID(desc.idProduct),
Class: Class(desc.bDeviceClass),
SubClass: Class(desc.bDeviceSubClass),
Protocol: uint8(desc.bDeviceProtocol),
Protocol: Protocol(desc.bDeviceProtocol),
Configs: cfgs,
}, nil
}

View File

@@ -58,7 +58,7 @@ func Describe(val interface{}) string {
func Classify(val interface{}) string {
var (
class, sub usb.Class
proto uint8
proto usb.Protocol
)
switch val := val.(type) {
case *usb.Descriptor:

View File

@@ -63,7 +63,7 @@ func (c Class) String() string {
// A SubClass contains the name of the subclass and any associated protocols.
type SubClass struct {
Name string
Protocol map[uint8]string
Protocol map[usb.Protocol]string
}
// String returns the name of the SubClass.
@@ -186,9 +186,9 @@ func ParseIDs(r io.Reader) (map[usb.ID]*Vendor, map[usb.Class]*Class, error) {
}
if subclass.Protocol == nil {
subclass.Protocol = make(map[uint8]string)
subclass.Protocol = make(map[usb.Protocol]string)
}
subclass.Protocol[uint8(id)] = name
subclass.Protocol[usb.Protocol(id)] = name
default:
return fmt.Errorf("too many levels of nesting for class")

View File

@@ -64,7 +64,7 @@ var (
0x01: {Name: "Direct Line"},
0x02: {
Name: "Abstract (modem)",
Protocol: map[uint8]string{
Protocol: map[usb.Protocol]string{
0x00: "None",
0x01: "AT-commands (v.25ter)",
0x02: "AT-commands (PCCA101)",