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