Skip to content

Commit 606023f

Browse files
committed
usb moved cs_interface descriptor to global descriptors
1 parent 359af3f commit 606023f

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

klib/usb/cdc/descriptor.hpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,7 @@ namespace klib::usb::cdc::detail {
4949
*
5050
*/
5151
template <typename Base, subtype SubType>
52-
struct functional {
53-
// size of the descriptor
54-
const uint8_t bFunctionLength = sizeof(Base);
55-
56-
// descriptor type (CS_INTERFACE)
57-
const descriptor::descriptor_type bDescriptorType = descriptor::descriptor_type::cs_interface;
58-
59-
// header functional descriptor subtype
60-
const uint8_t bDescriptorSubtype = static_cast<uint8_t>(SubType);
61-
};
62-
63-
// make sure the size is correct
64-
static_assert(sizeof(functional<uint8_t, subtype::header>) == 0x03, "Cdc functional descriptor size is wrong");
52+
struct functional: public descriptor::cs_interface<Base, static_cast<uint8_t>(SubType)> {};
6553
}
6654

6755
namespace klib::usb::cdc {

klib/usb/descriptor.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,25 @@ namespace klib::usb::descriptor {
436436
};
437437

438438
static_assert(sizeof(interface_association) == 8, "Interface association descriptor is not 8 bytes in length");
439+
440+
/**
441+
* @brief Base for all the class specific interface descriptors
442+
*
443+
*/
444+
template <typename Base, uint8_t SubType>
445+
struct cs_interface {
446+
// size of the descriptor
447+
const uint8_t bFunctionLength = sizeof(Base);
448+
449+
// the device class specific descriptor type
450+
const descriptor_type bDescriptorType = descriptor_type::cs_interface;
451+
452+
// header functional descriptor subtype
453+
const uint8_t bDescriptorSubtype = static_cast<uint8_t>(SubType);
454+
};
455+
456+
// make sure the size is correct
457+
static_assert(sizeof(cs_interface<uint8_t, 0x00>) == 0x03, "Class specific base descriptor size is wrong");
439458
}
440459

441460
// release the old pack so the rest of the structs are not

0 commit comments

Comments
 (0)