-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathusb_dev_hid.cxx
137 lines (111 loc) · 4.07 KB
/
usb_dev_hid.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// papoon_usb: "Not Insane" USB library for STM32F103xx MCUs
// Copyright (C) 2019,2020 Mark R. Rubin
//
// This file is part of papoon_usb.
//
// The papoon_usb program is free software: you can redistribute it
// and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// The papoon_usb program is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// (LICENSE.txt) along with the papoon_usb program. If not, see
// <https://www.gnu.org/licenses/gpl.html>
#include <usb_dev_hid.hxx>
namespace stm32f10_12357_xx {
const uint8_t UsbDevHid::_QUALIFIER_DESC[] = {
10, // bLength: qualifier size
static_cast<uint8_t>(UsbDev::Descriptor::DEVICE_QUALIFIER),
0x00, // undocumented configuration values
0x02, // " " "
0x00, // " " "
0x00, // " " "
0x00, // " " "
0x40, // " " "
0x01, // " " "
0x00, // " " "
};
bool UsbDevHid::usb_dev_hid_device_class_setup()
{
UsbDevHid *usb_dev = static_cast<UsbDevHid*>(this);
#if 0 // not working
#ifdef __GNUG__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
const uint8_t *data;
#else
const uint8_t *data = 0; // silence compiler warning
#endif
#if 0
#ifdef __GNUG__
#pragma GCC diagnostic pop
#endif
#endif
uint16_t size;
if (! _setup_packet
->request_type
. all(SetupPacket::RequestType:: RECIPIENT_INTERFACE))
return false;
if (_setup_packet->request_type.all(SetupPacket::RequestType::TYPE_CLASS)) {
switch (_setup_packet->request) {
case UsbDevHid::_REQ_SET_PROTOCOL:
usb_dev->_protocol = _setup_packet->value.bytes.byte0;
break;
case UsbDevHid::_REQ_GET_PROTOCOL:
data = &usb_dev->_protocol;
size = 1 ;
break;
case UsbDevHid::_REQ_SET_IDLE:
usb_dev->_idle_state = _setup_packet->value.bytes.byte0;
break;
case UsbDevHid::_REQ_GET_IDLE:
data = &usb_dev->_idle_state;
size = 1 ;
break;
default:
return false;
}
goto SET_SEND_OR_RECV;
}
if ( ! _setup_packet
->request_type
. all(SetupPacket::RequestType::TYPE_STANDARD)
|| (static_cast<SetupPacket::Request>(_setup_packet->request)
!= SetupPacket::Request::GET_DESCRIPTOR))
return false;
switch (_setup_packet->value.bytes.byte1) {
case static_cast<uint8_t>(UsbDev::Descriptor::DEVICE_QUALIFIER):
data = UsbDevHid::_QUALIFIER_DESC ;
size = sizeof(UsbDevHid::_QUALIFIER_DESC);
break;
#if 0 // handled by derived class
case UsbDevHid::HID_REPORT_DESC_TYPE:
data = UsbDevHid::_REPORT_DESC ;
size = sizeof(UsbDevHid::_REPORT_DESC);
break;
case UsbDevHid::HID_DESCRIPTOR_TYPE:
data = UsbDevHid::_HID_DESC ;
size = sizeof(UsbDevHid::_HID_DESC);
break;
#endif
default:
return false;
}
SET_SEND_OR_RECV:
if (_setup_packet->request_type.any( SetupPacket
::RequestType
::DIR_DEV_TO_HOST))
_send_info.set(data, size);
else
_recv_info.set(const_cast<uint8_t*>(data), size);
return true;
}
void UsbDev::set_configuration() {}
void UsbDev::set_interface () {}
} // namespace stm32f10_12357_xx {