Browse Source

Device status functions must treat device pointer as volatile

main
PaulStoffregen 7 years ago
parent
commit
8f09965162
1 changed files with 28 additions and 15 deletions
  1. +28
    -15
      USBHost_t36.h

+ 28
- 15
USBHost_t36.h View File

// All USB device drivers inherit from this base class. // All USB device drivers inherit from this base class.
class USBDriver : public USBHost { class USBDriver : public USBHost {
public: public:
operator bool() { return (device != nullptr); }
uint16_t idVendor() { return (device != nullptr) ? device->idVendor : 0; }
uint16_t idProduct() { return (device != nullptr) ? device->idProduct : 0; }

const uint8_t *manufacturer()
{ return ((device == nullptr) || (device->strbuf == nullptr)) ? nullptr : &device->strbuf->buffer[device->strbuf->iStrings[strbuf_t::STR_ID_MAN]]; }
const uint8_t *product()
{ return ((device == nullptr) || (device->strbuf == nullptr)) ? nullptr : &device->strbuf->buffer[device->strbuf->iStrings[strbuf_t::STR_ID_PROD]]; }
const uint8_t *serialNumber()
{ return ((device == nullptr) || (device->strbuf == nullptr)) ? nullptr : &device->strbuf->buffer[device->strbuf->iStrings[strbuf_t::STR_ID_SERIAL]]; }

// TODO: user-level functions
// check if device is bound/active/online
// query vid, pid
// query string: manufacturer, product, serial number
//operator bool() { return (*(Device_t * volatile *)&device != nullptr); }
operator bool() {
Device_t *dev = *(Device_t * volatile *)&device;
return dev != nullptr;
}
uint16_t idVendor() {
Device_t *dev = *(Device_t * volatile *)&device;
return (device != nullptr) ? device->idVendor : 0;
}
uint16_t idProduct() {
Device_t *dev = *(Device_t * volatile *)&device;
return (device != nullptr) ? device->idProduct : 0;
}
const uint8_t *manufacturer() {
Device_t *dev = *(Device_t * volatile *)&device;
if (dev == nullptr || dev->strbuf == nullptr) return nullptr;
return &dev->strbuf->buffer[dev->strbuf->iStrings[strbuf_t::STR_ID_MAN]];
}
const uint8_t *product() {
Device_t *dev = *(Device_t * volatile *)&device;
if (dev == nullptr || dev->strbuf == nullptr) return nullptr;
return &dev->strbuf->buffer[dev->strbuf->iStrings[strbuf_t::STR_ID_PROD]];
}
const uint8_t *serialNumber() {
Device_t *dev = *(Device_t * volatile *)&device;
if (dev == nullptr || dev->strbuf == nullptr) return nullptr;
return &dev->strbuf->buffer[dev->strbuf->iStrings[strbuf_t::STR_ID_SERIAL]];
}
protected: protected:
USBDriver() : next(NULL), device(NULL) {} USBDriver() : next(NULL), device(NULL) {}
// Check if a driver wishes to claim a device or interface or group // Check if a driver wishes to claim a device or interface or group

Loading…
Cancel
Save