Remove OpenEndpoint, add InEndpoint for Read transfers.

This commit is contained in:
Sebastian Zagrodzki
2017-04-10 01:00:53 +02:00
parent dd405348e9
commit 57b10f0dd3
5 changed files with 90 additions and 118 deletions

View File

@@ -100,8 +100,7 @@ func (d *Device) Close() error {
return nil
}
// OpenEndpoint prepares a device endpoint for data transfer.
func (d *Device) OpenEndpoint(epAddr, cfgNum, ifNum, setNum uint8) (*Endpoint, error) {
func (d *Device) openEndpoint(cfgNum, ifNum, setNum, epAddr uint8) (*endpoint, error) {
var cfg *ConfigInfo
for _, c := range d.Configs {
if c.Config == cfgNum {
@@ -150,7 +149,7 @@ func (d *Device) OpenEndpoint(epAddr, cfgNum, ifNum, setNum uint8) (*Endpoint, e
return nil, fmt.Errorf("usb: didn't find endpoint address 0x%02x", epAddr)
}
end := newEndpoint(d.handle, *ifs, *ep, d.ReadTimeout, d.WriteTimeout)
end := newEndpoint(d.handle, *ifs, *ep)
// Set the configuration
activeConf, err := libusb.getConfig(d.handle)
@@ -183,6 +182,17 @@ func (d *Device) OpenEndpoint(epAddr, cfgNum, ifNum, setNum uint8) (*Endpoint, e
return end, nil
}
func (d *Device) InEndpoint(cfgNum, ifNum, setNum, epNum uint8) (*InEndpoint, error) {
ep, err := d.openEndpoint(cfgNum, ifNum, setNum, endpointAddr(epNum, EndpointDirectionIn))
if err != nil {
return nil, err
}
return &InEndpoint{
endpoint: ep,
timeout: d.ReadTimeout,
}, nil
}
// GetStringDescriptor returns a device string descriptor with the given index
// number. The first supported language is always used and the returned
// descriptor string is converted to ASCII (non-ASCII characters are replaced