Skip to content

Commit d52822a

Browse files
committed
moved static assert to usb device instead of usb driver
1 parent cef063c commit d52822a

File tree

10 files changed

+45
-56
lines changed

10 files changed

+45
-56
lines changed

klib/usb/device/bulk.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,15 +324,15 @@ namespace klib::usb::device {
324324

325325
// make sure the endpoints support bulk
326326
// endpoints
327-
Usb::template is_valid_endpoint<
327+
static_assert(Usb::template is_valid_endpoint<
328328
InEndpoint,
329329
klib::usb::descriptor::transfer_type::bulk
330-
>();
330+
>(), "invalid bulk endpoint selected");
331331

332-
Usb::template is_valid_endpoint<
332+
static_assert(Usb::template is_valid_endpoint<
333333
OutEndpoint,
334334
klib::usb::descriptor::transfer_type::bulk
335-
>();
335+
>(), "invalid bulk endpoint selected");
336336
}
337337

338338
/**

klib/usb/device/camera.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,14 +518,15 @@ namespace klib::usb::device {
518518
template <typename Usb>
519519
static void init() {
520520
// make sure the endpoint supports interrupt endpoints
521-
Usb::template is_valid_endpoint<
521+
static_assert(Usb::template is_valid_endpoint<
522522
InterruptEndpoint,
523523
klib::usb::descriptor::transfer_type::interrupt
524-
>();
525-
Usb::template is_valid_endpoint<
524+
>(), "invalid interrupt selected");
525+
526+
static_assert(Usb::template is_valid_endpoint<
526527
Endpoint,
527528
klib::usb::descriptor::transfer_type::isochronous
528-
>();
529+
>(), "invalid isochronous selected");
529530
}
530531

531532
/**

klib/usb/device/keyboard.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,10 +661,10 @@ namespace klib::usb::device {
661661

662662
// make sure the endpoint supports interrupt
663663
// endpoints
664-
Usb::template is_valid_endpoint<
664+
static_assert(Usb::template is_valid_endpoint<
665665
Endpoint,
666666
klib::usb::descriptor::transfer_type::interrupt
667-
>();
667+
>(), "invalid interrupt endpoint selected");
668668
}
669669

670670
/**

klib/usb/device/mass_storage.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,15 @@ namespace klib::usb::device {
274274
configuration = 0x00;
275275

276276
// make sure the endpoints support the bulk endpoint type
277-
Usb::template is_valid_endpoint<
277+
static_assert(Usb::template is_valid_endpoint<
278278
usb::get_endpoint(InEndpoint),
279279
klib::usb::descriptor::transfer_type::bulk
280-
>();
281-
Usb::template is_valid_endpoint<
280+
>(), "invalid bulk endpoint selected");
281+
282+
static_assert(Usb::template is_valid_endpoint<
282283
usb::get_endpoint(OutEndpoint),
283284
klib::usb::descriptor::transfer_type::bulk
284-
>();
285+
>(), "invalid bulk endpoint selected");
285286
}
286287

287288
/**

klib/usb/device/mouse.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,10 @@ namespace klib::usb::device {
257257
template <typename Usb>
258258
static void init() {
259259
// make sure the endpoint supports interrupt endpoints
260-
Usb::template is_valid_endpoint<
260+
static_assert(Usb::template is_valid_endpoint<
261261
Endpoint,
262262
klib::usb::descriptor::transfer_type::interrupt
263-
>();
263+
>(), "invalid interrupt endpoint selected");
264264
}
265265

266266
/**

klib/usb/device/serial.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,20 +413,20 @@ namespace klib::usb::device {
413413
template <typename Usb>
414414
static void init() {
415415
// make sure the endpoints support the transfer types
416-
Usb::template is_valid_endpoint<
416+
static_assert(Usb::template is_valid_endpoint<
417417
CmdEndpoint,
418418
klib::usb::descriptor::transfer_type::interrupt
419-
>();
419+
>(), "invalid interrupt endpoint selected");
420420

421-
Usb::template is_valid_endpoint<
421+
static_assert(Usb::template is_valid_endpoint<
422422
InEndpoint,
423423
klib::usb::descriptor::transfer_type::bulk
424-
>();
424+
>(), "invalid bulk endpoint selected");
425425

426-
Usb::template is_valid_endpoint<
426+
static_assert(Usb::template is_valid_endpoint<
427427
OutEndpoint,
428428
klib::usb::descriptor::transfer_type::bulk
429-
>();
429+
>(), "invalid bulk endpoint selected");
430430
}
431431

432432
/**

targets/chip/max32625/io/usb.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,9 @@ namespace klib::max32625::io {
734734
* @tparam type
735735
*/
736736
template <uint8_t endpoint, klib::usb::descriptor::transfer_type type>
737-
constexpr static void is_valid_endpoint() {
737+
constexpr static bool is_valid_endpoint() {
738738
// TODO: implement this
739+
return true;
739740
}
740741

741742
/**

targets/core/atmel/atsam4s/usb.hpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -599,26 +599,23 @@ namespace klib::core::atsam4s::io {
599599
* @tparam type
600600
*/
601601
template <uint8_t endpoint, klib::usb::descriptor::transfer_type type>
602-
constexpr static void is_valid_endpoint() {
602+
constexpr static bool is_valid_endpoint() {
603603
using transfer_type = klib::usb::descriptor::transfer_type;
604604

605605
// make sure the endpoint is valid
606606
static_assert(endpoint <= 8, "Invalid endpoint provided");
607607

608608
// check if the endpoint supports the transfer type
609609
if constexpr (type == transfer_type::control) {
610-
static_assert((endpoint == 0) || (endpoint == 3),
611-
"Endpoint does not support control mode"
612-
);
610+
return (endpoint == 0) || (endpoint == 3);
613611
}
614612
else if constexpr (type == transfer_type::isochronous) {
615-
static_assert((0x1 << endpoint) & 0b11110110,
616-
"Endpoint does not support isochronous mode"
617-
);
613+
return ((0x1 << endpoint) & 0b11110110);
618614
}
619615

620616
// every endpoint supports bulk and interrupt. Dont
621617
// bother checking them
618+
return true;
622619
}
623620

624621
/**

targets/core/cypress/mb9bf560l/usb.hpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -704,11 +704,13 @@ namespace klib::core::mb9bf560l::io {
704704
* @tparam type
705705
*/
706706
template <uint8_t endpoint, klib::usb::descriptor::transfer_type type>
707-
constexpr static void is_valid_endpoint() {
707+
constexpr static bool is_valid_endpoint() {
708708
using transfer_type = klib::usb::descriptor::transfer_type;
709709

710710
// make sure the endpoint is valid
711-
static_assert(endpoint < endpoint_count, "Invalid endpoint provided");
711+
if (endpoint >= endpoint_count) {
712+
return false;
713+
}
712714

713715
// this chip has some weird rules. We can enable a Bulk/Interrupt
714716
// on every channel except endpoint 0.
@@ -719,19 +721,13 @@ namespace klib::core::mb9bf560l::io {
719721

720722
// check if the endpoint supports the transfer type
721723
if constexpr (type == transfer_type::control) {
722-
static_assert(endpoint == 0,
723-
"Endpoint does not support control mode"
724-
);
724+
return (endpoint == 0);
725725
}
726726
else if constexpr (type == transfer_type::interrupt || type == transfer_type::bulk) {
727-
static_assert(endpoint != 0,
728-
"Endpoint does not support interrupt/bulk mode"
729-
);
727+
return (endpoint != 0);
730728
}
731729
else {
732-
static_assert((endpoint == 2) || (endpoint == 4),
733-
"Endpoint does not support isochronous mode"
734-
);
730+
return ((endpoint == 2) || (endpoint == 4));
735731
}
736732
}
737733

targets/core/nxp/lpc17xx/usb.hpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -777,33 +777,26 @@ namespace klib::core::lpc17xx::io {
777777
* @tparam type
778778
*/
779779
template <uint8_t endpoint, klib::usb::descriptor::transfer_type type>
780-
constexpr static void is_valid_endpoint() {
780+
constexpr static bool is_valid_endpoint() {
781781
using transfer_type = klib::usb::descriptor::transfer_type;
782782

783783
// make sure the endpoint is valid
784-
static_assert(endpoint <= 0xf, "Invalid endpoint provided");
784+
if (endpoint > 0xf) {
785+
return false;
786+
}
785787

786788
// check if the endpoint supports the transfer type
787789
if constexpr (type == transfer_type::control) {
788-
static_assert(endpoint == 0,
789-
"Endpoint does not support control mode"
790-
);
790+
return (endpoint == 0);
791791
}
792792
else if constexpr (type == transfer_type::interrupt) {
793-
static_assert((0x1 << endpoint) & 0b10010010010010,
794-
"Endpoint does not support interrupt mode"
795-
);
793+
return ((0x1 << endpoint) & 0b10010010010010);
796794
}
797795
else if constexpr (type == transfer_type::isochronous) {
798-
static_assert((0x1 << endpoint) & 0b1001001001000,
799-
"Endpoint does not support isochronous mode"
800-
);
796+
return ((0x1 << endpoint) & 0b1001001001000);
801797
}
802798
else {
803-
static_assert(
804-
(0x1 << endpoint) & 0b110100100100100,
805-
"Endpoint does not support bulk mode"
806-
);
799+
return ((0x1 << endpoint) & 0b110100100100100);
807800
}
808801
}
809802

0 commit comments

Comments
 (0)