Skip to content

Commit 110d351

Browse files
committed
usb moved hid class requests to hid file
1 parent 542f9c5 commit 110d351

File tree

3 files changed

+27
-40
lines changed

3 files changed

+27
-40
lines changed

klib/usb/device/keyboard.hpp

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,6 @@ namespace klib::usb::device {
2323
serial = 3
2424
};
2525

26-
/**
27-
* @brief Class specific requests for the handle class packet function
28-
*
29-
*/
30-
enum class class_request {
31-
get_report = 0x01,
32-
get_idle = 0x02,
33-
get_protocol = 0x03,
34-
set_report = 0x09,
35-
set_idle = 0x0a,
36-
set_protocol = 0x0b,
37-
};
38-
3926
// Push the current pack to the stack and set the pack to 1
4027
// as all these structs have specific sizes
4128
#pragma pack(push, 1)
@@ -678,11 +665,11 @@ namespace klib::usb::device {
678665
}
679666

680667
// convert the request to a class request
681-
const auto& request = static_cast<class_request>(packet.bRequest);
668+
const auto& request = static_cast<hid::class_request>(packet.bRequest);
682669

683670
// check what requets we got
684671
switch (request) {
685-
case class_request::get_report:
672+
case hid::class_request::get_report:
686673
// the host should not use this as a substitute for the Interrupt EP
687674
// we simply send a "no keys" report to the host
688675
std::fill_n(report_data, sizeof(report_data), 0x00);
@@ -699,7 +686,7 @@ namespace klib::usb::device {
699686
return usb::handshake::stall;
700687
}
701688
break;
702-
case class_request::get_idle:
689+
case hid::class_request::get_idle:
703690
// TODO: add support for report id != 0
704691
// for now we only support report id == 0
705692
if ((packet.wValue & 0xff) != 0x00) {
@@ -720,7 +707,7 @@ namespace klib::usb::device {
720707
}
721708
}
722709
break;
723-
case class_request::set_report:
710+
case hid::class_request::set_report:
724711
// check if the packet length is not above the max endpoint size
725712
if (packet.wLength > Usb::max_endpoint_size) {
726713
// invalid length
@@ -731,7 +718,7 @@ namespace klib::usb::device {
731718
return usb::handshake::ack;
732719
}
733720
break;
734-
case class_request::set_idle:
721+
case hid::class_request::set_idle:
735722
// TODO: add support for report id != 0
736723
// for now we only support report id == 0 and we do not
737724
// support changing the idle
@@ -743,8 +730,8 @@ namespace klib::usb::device {
743730
return usb::handshake::ack;
744731
}
745732
break;
746-
case class_request::get_protocol:
747-
case class_request::set_protocol:
733+
case hid::class_request::get_protocol:
734+
case hid::class_request::set_protocol:
748735
default:
749736
// not supported. stall
750737
return usb::handshake::stall;

klib/usb/device/mouse.hpp

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,6 @@ namespace klib::usb::device {
2323
serial = 3
2424
};
2525

26-
/**
27-
* @brief Class specific requests for the handle class packet function
28-
*
29-
*/
30-
enum class class_request {
31-
get_report = 0x01,
32-
get_idle = 0x02,
33-
get_protocol = 0x03,
34-
set_report = 0x09,
35-
set_idle = 0x0a,
36-
set_protocol = 0x0b,
37-
};
38-
3926
// Push the current pack to the stack and set the pack to 1
4027
// as all these structs have specific sizes
4128
#pragma pack(push, 1)
@@ -511,11 +498,11 @@ namespace klib::usb::device {
511498
}
512499

513500
// convert the request to a class request
514-
const auto& request = static_cast<class_request>(packet.bRequest);
501+
const auto& request = static_cast<hid::class_request>(packet.bRequest);
515502

516503
// check what requets we got
517504
switch (request) {
518-
case class_request::get_report:
505+
case hid::class_request::get_report:
519506
// the host should not use this as a substitute for the Interrupt EP
520507
// but send the data we have anyway
521508

@@ -533,7 +520,7 @@ namespace klib::usb::device {
533520
return usb::handshake::stall;
534521
}
535522
break;
536-
case class_request::get_idle:
523+
case hid::class_request::get_idle:
537524
// TODO: add support for report id != 0
538525
// for now we only support report id == 0
539526
if ((packet.wValue & 0xff) != 0x00) {
@@ -559,7 +546,7 @@ namespace klib::usb::device {
559546
}
560547
}
561548
break;
562-
case class_request::set_report:
549+
case hid::class_request::set_report:
563550
// check if the packet length is not above the max endpoint size
564551
if (packet.wLength > Usb::max_endpoint_size) {
565552
// invalid length
@@ -570,7 +557,7 @@ namespace klib::usb::device {
570557
return usb::handshake::ack;
571558
}
572559
break;
573-
case class_request::set_idle:
560+
case hid::class_request::set_idle:
574561
// TODO: add support for report id != 0
575562
// for now we only support report id == 0 and we do not
576563
// support changing the idle
@@ -582,8 +569,8 @@ namespace klib::usb::device {
582569
return usb::handshake::ack;
583570
}
584571
break;
585-
case class_request::get_protocol:
586-
case class_request::set_protocol:
572+
case hid::class_request::get_protocol:
573+
case hid::class_request::set_protocol:
587574
default:
588575
// not supported. stall
589576
return usb::handshake::stall;

klib/usb/usb/hid/descriptor.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ namespace klib::usb::hid {
1818
pyhisical = 0x23
1919
};
2020

21+
/**
22+
* @brief Class specific requests for the handle class packet function
23+
*
24+
*/
25+
enum class class_request {
26+
get_report = 0x01,
27+
get_idle = 0x02,
28+
get_protocol = 0x03,
29+
set_report = 0x09,
30+
set_idle = 0x0a,
31+
set_protocol = 0x0b,
32+
};
33+
2134
/**
2235
* @brief Hid device descriptor
2336
*

0 commit comments

Comments
 (0)