diff options
Diffstat (limited to 'hid/lib/drivers-stm32/usb/hid-wrapper-stm32.h')
-rw-r--r-- | hid/lib/drivers-stm32/usb/hid-wrapper-stm32.h | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/hid/lib/drivers-stm32/usb/hid-wrapper-stm32.h b/hid/lib/drivers-stm32/usb/hid-wrapper-stm32.h index 10bd29ef..0228d296 100644 --- a/hid/lib/drivers-stm32/usb/hid-wrapper-stm32.h +++ b/hid/lib/drivers-stm32/usb/hid-wrapper-stm32.h @@ -19,63 +19,54 @@ # # *****************************************************************************/ + #pragma once #include <USBComposite.h> -namespace DRIVERS { +namespace DRIVERS { class HidWrapper { public: - HidWrapper(USBCompositeSerial* _serial = nullptr) : _serial(_serial) {} - void begin() { - if(_init) + if (_init) { return; + } _init = true; _report_descriptor_length = 0; - for(uint8 i = 0; i<_count; ++i) { - _report_descriptor_length += _descriptors_size[i]; + for (unsigned index = 0; index < _count; ++index) { + _report_descriptor_length += _descriptors_size[index]; } _report_descriptor = new uint8[_report_descriptor_length]; - uint16_t index = 0; - for(uint8 i = 0; i<_count; ++i) { - memcpy(_report_descriptor + index, _report_descriptors[i], _descriptors_size[i]); - index += _descriptors_size[i]; + size_t offset = 0; + for (unsigned index = 0; index < _count; ++index) { + memcpy(_report_descriptor + offset, _report_descriptors[index], _descriptors_size[index]); + offset += _descriptors_size[index]; } - if(_serial) { - usbHid.begin(*_serial, _report_descriptor, _report_descriptor_length); - } else { - usbHid.begin(_report_descriptor, _report_descriptor_length); - } + usbHid.begin(_report_descriptor, _report_descriptor_length); } - void addReportDescriptor(const uint8_t* report_descriptor, uint16_t report_descriptor_length) { + void addReportDescriptor(const uint8_t *report_descriptor, uint16_t report_descriptor_length) { _report_descriptors[_count] = report_descriptor; _descriptors_size[_count] = report_descriptor_length; ++_count; } - USBCompositeSerial* serial() { - return _serial; - } - USBHID usbHid; private: - USBCompositeSerial* _serial; bool _init = false; static constexpr uint8_t MAX_USB_DESCRIPTORS = 2; - const uint8_t* _report_descriptors[MAX_USB_DESCRIPTORS]; + const uint8_t *_report_descriptors[MAX_USB_DESCRIPTORS]; uint8_t _descriptors_size[MAX_USB_DESCRIPTORS]; uint8_t _count = 0; - uint8_t* _report_descriptor; + uint8_t *_report_descriptor; uint16_t _report_descriptor_length; }; } |