usb fix
This commit is contained in:
@@ -58,17 +58,18 @@
|
|||||||
#define PIUSB_H
|
#define PIUSB_H
|
||||||
|
|
||||||
#include "piiodevice.h"
|
#include "piiodevice.h"
|
||||||
|
#include "pip_usb_export.h"
|
||||||
|
|
||||||
struct usb_dev_handle;
|
struct usb_dev_handle;
|
||||||
|
|
||||||
class PIP_EXPORT PIUSB: public PIIODevice {
|
class PIP_USB_EXPORT PIUSB: public PIIODevice {
|
||||||
PIIODEVICE(PIUSB, "usb");
|
PIIODEVICE(PIUSB, "usb");
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit PIUSB(ushort vid = 0, ushort pid = 0);
|
explicit PIUSB(ushort vid = 0, ushort pid = 0);
|
||||||
virtual ~PIUSB();
|
virtual ~PIUSB();
|
||||||
|
|
||||||
struct PIP_EXPORT Endpoint {
|
struct PIP_USB_EXPORT Endpoint {
|
||||||
Endpoint(uchar a = 0, uchar at = 0, ushort mps = 0) {
|
Endpoint(uchar a = 0, uchar at = 0, ushort mps = 0) {
|
||||||
address = a;
|
address = a;
|
||||||
attributes = at;
|
attributes = at;
|
||||||
@@ -106,52 +107,41 @@ public:
|
|||||||
ushort max_packet_size;
|
ushort max_packet_size;
|
||||||
Direction direction;
|
Direction direction;
|
||||||
TransferType transfer_type;
|
TransferType transfer_type;
|
||||||
SynchronisationType synchronisation_type;
|
SynchronisationType synchronisation_type = NoSynchonisation;
|
||||||
UsageType usage_type;
|
UsageType usage_type = DataEndpoint;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PIP_EXPORT Interface {
|
struct PIP_USB_EXPORT Interface {
|
||||||
Interface() { index = value_to_select = class_code = subclass_code = protocol_code = 0; }
|
uchar index = 0;
|
||||||
uchar index;
|
uchar value_to_select = 0;
|
||||||
uchar value_to_select;
|
ushort class_code = 0;
|
||||||
ushort class_code;
|
ushort subclass_code = 0;
|
||||||
ushort subclass_code;
|
ushort protocol_code = 0;
|
||||||
ushort protocol_code;
|
|
||||||
PIVector<PIUSB::Endpoint> endpoints;
|
PIVector<PIUSB::Endpoint> endpoints;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PIP_EXPORT Configuration {
|
struct PIP_USB_EXPORT Configuration {
|
||||||
Configuration() {
|
uchar index = 0;
|
||||||
index = value_to_select = attributes = max_power = 0;
|
uchar value_to_select = 0;
|
||||||
self_powered = remote_wakeup = false;
|
uchar attributes = 0;
|
||||||
}
|
ushort max_power = 0; // mA
|
||||||
uchar index;
|
bool self_powered = false;
|
||||||
uchar value_to_select;
|
bool remote_wakeup = false;
|
||||||
uchar attributes;
|
|
||||||
ushort max_power; // mA
|
|
||||||
bool self_powered;
|
|
||||||
bool remote_wakeup;
|
|
||||||
PIVector<PIUSB::Interface> interfaces;
|
PIVector<PIUSB::Interface> interfaces;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PIP_EXPORT Descriptor {
|
struct PIP_USB_EXPORT Descriptor {
|
||||||
Descriptor() {
|
ushort usb_spec_number = 0;
|
||||||
usb_spec_number = 0;
|
uchar device_class = 0;
|
||||||
device_class = device_subclass = device_protocol = max_packet_size = 0;
|
uchar device_subclass = 0;
|
||||||
id_vendor = id_product = id_device_release = 0;
|
uchar device_protocol = 0;
|
||||||
index_manufacturer = index_product = index_serial = 0;
|
uchar max_packet_size = 0;
|
||||||
}
|
ushort id_vendor = 0;
|
||||||
ushort usb_spec_number;
|
ushort id_product = 0;
|
||||||
uchar device_class;
|
ushort id_device_release = 0;
|
||||||
uchar device_subclass;
|
uchar index_manufacturer = 0;
|
||||||
uchar device_protocol;
|
uchar index_product = 0;
|
||||||
uchar max_packet_size;
|
uchar index_serial = 0;
|
||||||
ushort id_vendor;
|
|
||||||
ushort id_product;
|
|
||||||
ushort id_device_release;
|
|
||||||
uchar index_manufacturer;
|
|
||||||
uchar index_product;
|
|
||||||
uchar index_serial;
|
|
||||||
PIVector<PIUSB::Configuration> configurations;
|
PIVector<PIUSB::Configuration> configurations;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -173,14 +163,8 @@ public:
|
|||||||
PIVector<PIUSB::Endpoint> endpointsWrite();
|
PIVector<PIUSB::Endpoint> endpointsWrite();
|
||||||
PIUSB::Endpoint getEndpointByAddress(uchar address);
|
PIUSB::Endpoint getEndpointByAddress(uchar address);
|
||||||
|
|
||||||
void setVendorID(ushort vid) {
|
void setVendorID(ushort vid);
|
||||||
vid_ = vid;
|
void setProductID(ushort pid);
|
||||||
setPath(PIString::fromNumber(vid_, 16).expandLeftTo(4, '0') + ':' + PIString::fromNumber(pid_, 16).expandLeftTo(4, '0'));
|
|
||||||
}
|
|
||||||
void setProductID(ushort pid) {
|
|
||||||
pid_ = pid;
|
|
||||||
setPath(PIString::fromNumber(vid_, 16).expandLeftTo(4, '0') + ':' + PIString::fromNumber(pid_, 16).expandLeftTo(4, '0'));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool setConfiguration(uchar value);
|
bool setConfiguration(uchar value);
|
||||||
bool setInterface(uchar value);
|
bool setInterface(uchar value);
|
||||||
@@ -216,6 +200,7 @@ protected:
|
|||||||
usb_dev_handle * hdev;
|
usb_dev_handle * hdev;
|
||||||
};
|
};
|
||||||
|
|
||||||
PIP_EXPORT PICout operator<<(PICout s, const PIUSB::Endpoint & v);
|
PIP_USB_EXPORT PICout operator<<(PICout s, const PIUSB::Endpoint & v);
|
||||||
|
|
||||||
#endif // PIUSB_H
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ PIUSB::PIUSB(ushort vid, ushort pid): PIIODevice("", ReadWrite) {
|
|||||||
hdev = 0;
|
hdev = 0;
|
||||||
timeout_r = timeout_w = 0;
|
timeout_r = timeout_w = 0;
|
||||||
interface_claimed = -1;
|
interface_claimed = -1;
|
||||||
setPath(PIString::fromNumber(vid_, 16).expandLeftTo(4, "0") + ":" + PIString::fromNumber(pid_, 16).expandLeftTo(4, "0"));
|
setPath(PIString::fromNumber(vid_, 16).expandLeftTo(4, '0') + ":" + PIString::fromNumber(pid_, 16).expandLeftTo(4, '0'));
|
||||||
setDeviceNumber(1);
|
setDeviceNumber(1);
|
||||||
setTimeoutRead(1000);
|
setTimeoutRead(1000);
|
||||||
setTimeoutWrite(1000);
|
setTimeoutWrite(1000);
|
||||||
@@ -53,10 +53,8 @@ PIUSB::~PIUSB() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PIUSB::Endpoint::parse() {
|
void PIUSB::Endpoint::parse() {
|
||||||
synchronisation_type = NoSynchonisation;
|
direction = (Direction)((address >> 7) & 1);
|
||||||
usage_type = DataEndpoint;
|
transfer_type = (TransferType)(attributes & 3);
|
||||||
direction = (Direction)((address >> 7) & 1);
|
|
||||||
transfer_type = (TransferType)(attributes & 3);
|
|
||||||
if (transfer_type == Isochronous) {
|
if (transfer_type == Isochronous) {
|
||||||
synchronisation_type = (SynchronisationType)((attributes >> 2) & 3);
|
synchronisation_type = (SynchronisationType)((attributes >> 2) & 3);
|
||||||
usage_type = (UsageType)((attributes >> 4) & 3);
|
usage_type = (UsageType)((attributes >> 4) & 3);
|
||||||
@@ -71,6 +69,18 @@ PIUSB::Endpoint PIUSB::getEndpointByAddress(uchar address) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PIUSB::setVendorID(ushort vid) {
|
||||||
|
vid_ = vid;
|
||||||
|
setPath(PIString::fromNumber(vid_, 16).expandLeftTo(4, '0') + ':' + PIString::fromNumber(pid_, 16).expandLeftTo(4, '0'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PIUSB::setProductID(ushort pid) {
|
||||||
|
pid_ = pid;
|
||||||
|
setPath(PIString::fromNumber(vid_, 16).expandLeftTo(4, '0') + ':' + PIString::fromNumber(pid_, 16).expandLeftTo(4, '0'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
PIVector<PIUSB::Endpoint> PIUSB::endpointsRead() {
|
PIVector<PIUSB::Endpoint> PIUSB::endpointsRead() {
|
||||||
PIVector<Endpoint> ret;
|
PIVector<Endpoint> ret;
|
||||||
piForeachC(Endpoint & i, eps)
|
piForeachC(Endpoint & i, eps)
|
||||||
|
|||||||
Reference in New Issue
Block a user