code format

This commit is contained in:
2022-12-14 14:13:52 +03:00
parent 430a41fefc
commit c2b8a8d6da
297 changed files with 27331 additions and 24162 deletions

View File

@@ -5,22 +5,22 @@
* \~russian Устройство USB
*/
/*
PIP - Platform Independent Primitives
USB, based on libusb
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
USB, based on libusb
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//! \defgroup USB USB
//! \~\brief
@@ -61,23 +61,45 @@
struct usb_dev_handle;
class PIP_EXPORT PIUSB: public PIIODevice
{
class PIP_EXPORT PIUSB: public PIIODevice {
PIIODEVICE(PIUSB, "usb");
public:
explicit PIUSB(ushort vid = 0, ushort pid = 0);
virtual ~PIUSB();
struct PIP_EXPORT Endpoint {
Endpoint(uchar a = 0, uchar at = 0, ushort mps = 0) {address = a; attributes = at; max_packet_size = mps; parse();}
Endpoint(uchar a = 0, uchar at = 0, ushort mps = 0) {
address = a;
attributes = at;
max_packet_size = mps;
parse();
}
enum Direction {Write = 0, Read = 1};
enum TransferType {Control = 0, Isochronous = 1, Bulk = 2, Interrupt = 3};
enum SynchronisationType {NoSynchonisation= 0, Asynchronous = 2, Adaptive = 1, Synchronous = 3};
enum UsageType {DataEndpoint = 0, FeedbackEndpoint = 2, ExplicitFeedbackDataEndpoint = 1};
enum Direction {
Write = 0,
Read = 1
};
enum TransferType {
Control = 0,
Isochronous = 1,
Bulk = 2,
Interrupt = 3
};
enum SynchronisationType {
NoSynchonisation = 0,
Asynchronous = 2,
Adaptive = 1,
Synchronous = 3
};
enum UsageType {
DataEndpoint = 0,
FeedbackEndpoint = 2,
ExplicitFeedbackDataEndpoint = 1
};
void parse();
bool isNull() const {return address == 0;}
bool isNull() const { return address == 0; }
uchar address;
uchar attributes;
@@ -89,7 +111,7 @@ public:
};
struct PIP_EXPORT Interface {
Interface() {index = value_to_select = class_code = subclass_code = protocol_code = 0;}
Interface() { index = value_to_select = class_code = subclass_code = protocol_code = 0; }
uchar index;
uchar value_to_select;
ushort class_code;
@@ -99,7 +121,10 @@ public:
};
struct PIP_EXPORT Configuration {
Configuration() {index = value_to_select = attributes = max_power = 0; self_powered = remote_wakeup = false;}
Configuration() {
index = value_to_select = attributes = max_power = 0;
self_powered = remote_wakeup = false;
}
uchar index;
uchar value_to_select;
uchar attributes;
@@ -110,7 +135,12 @@ public:
};
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;}
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;
@@ -125,35 +155,41 @@ public:
PIVector<PIUSB::Configuration> configurations;
};
const PIUSB::Descriptor & currentDescriptor() const {return desc_;}
const PIUSB::Configuration & currentConfiguration() const {return conf_;}
const PIUSB::Interface & currentInterface() const {return iface_;}
const PIUSB::Descriptor & currentDescriptor() const { return desc_; }
const PIUSB::Configuration & currentConfiguration() const { return conf_; }
const PIUSB::Interface & currentInterface() const { return iface_; }
ushort vendorID() const {return vid_;}
ushort productID() const {return pid_;}
ushort vendorID() const { return vid_; }
ushort productID() const { return pid_; }
int deviceNumber() const {return property("deviceNumber").toInt();}
int timeoutRead() const {return property("timeoutRead").toInt();}
int timeoutWrite() const {return property("timeoutWrite").toInt();}
const PIUSB::Endpoint & endpointRead() const {return ep_read;}
const PIUSB::Endpoint & endpointWrite() const {return ep_write;}
int deviceNumber() const { return property("deviceNumber").toInt(); }
int timeoutRead() const { return property("timeoutRead").toInt(); }
int timeoutWrite() const { return property("timeoutWrite").toInt(); }
const PIUSB::Endpoint & endpointRead() const { return ep_read; }
const PIUSB::Endpoint & endpointWrite() const { return ep_write; }
const PIVector<PIUSB::Endpoint> & endpoints() const {return eps;}
const PIVector<PIUSB::Endpoint> & endpoints() const { return eps; }
PIVector<PIUSB::Endpoint> endpointsRead();
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) {
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"));
}
bool setConfiguration(uchar value);
bool setInterface(uchar value);
void setEndpointRead(const PIUSB::Endpoint & ep) {ep_read = ep;}
void setEndpointWrite(const PIUSB::Endpoint & ep) {ep_write = ep;}
void setDeviceNumber(int dn) {setProperty("deviceNumber", dn);}
void setTimeoutRead(int t) {setProperty("timeoutRead", t);}
void setTimeoutWrite(int t) {setProperty("timeoutWrite", t);}
void setEndpointRead(const PIUSB::Endpoint & ep) { ep_read = ep; }
void setEndpointWrite(const PIUSB::Endpoint & ep) { ep_write = ep; }
void setDeviceNumber(int dn) { setProperty("deviceNumber", dn); }
void setTimeoutRead(int t) { setProperty("timeoutRead", t); }
void setTimeoutWrite(int t) { setProperty("timeoutWrite", t); }
int controlWrite(const void * data, int max_size);
@@ -167,7 +203,7 @@ protected:
ssize_t writeDevice(const void * data, ssize_t max_size) override;
bool openDevice() override;
bool closeDevice() override;
DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Reliable;}
DeviceInfoFlags deviceInfoFlags() const override { return PIIODevice::Reliable; }
PIVector<PIUSB::Endpoint> eps;
ushort vid_, pid_;
@@ -178,9 +214,8 @@ protected:
Configuration conf_;
Interface iface_;
usb_dev_handle * hdev;
};
PIP_EXPORT PICout operator <<(PICout s, const PIUSB::Endpoint & v);
PIP_EXPORT PICout operator<<(PICout s, const PIUSB::Endpoint & v);
#endif // PIUSB_H