interface.cpp
2.1 KB
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
#include "interface.h"
namespace Ion {
namespace USB {
namespace Device {
static inline uint16_t min(uint16_t x, uint16_t y) { return (x<y ? x : y); }
bool Interface::processSetupInRequest(SetupPacket * request, uint8_t * transferBuffer, uint16_t * transferBufferLength, uint16_t transferBufferMaxLength) {
if (request->requestType() != SetupPacket::RequestType::Standard) {
return false;
}
switch (request->bRequest()) {
case (int) Request::GetStatus:
return getStatus(transferBuffer, transferBufferLength, transferBufferMaxLength);
case (int) Request::SetInterface:
return setInterface(request, transferBufferLength);
case (int) Request::GetInterface:
return getInterface(transferBuffer, transferBufferLength, transferBufferMaxLength);
case (int) Request::ClearFeature:
return clearFeature(transferBufferLength);
case (int) Request::SetFeature:
return setFeature(transferBufferLength);
}
return false;
}
bool Interface::getStatus(uint8_t * transferBuffer, uint16_t * transferBufferLength, uint16_t transferBufferMaxLength) {
*transferBufferLength = min(2, transferBufferMaxLength);
for (int i = 0; i<*transferBufferLength; i++) {
transferBuffer[i] = 0; // Reserved, must be set to 0
}
return true;
}
bool Interface::getInterface(uint8_t * transferBuffer, uint16_t * transferBufferLength, uint16_t transferBufferMaxLength) {
*transferBufferLength = min(1, transferBufferMaxLength);;
if (*transferBufferLength > 0) {
transferBuffer[0] = getActiveInterfaceAlternative();
}
return true;
}
bool Interface::setInterface(SetupPacket * request, uint16_t * transferBufferLength) {
// We support one interface only
setActiveInterfaceAlternative(request->wValue());
// There is one interface alternative only, we no need to set it again.
*transferBufferLength = 0;
return true;
}
bool Interface::clearFeature(uint16_t * transferBufferLength) {
// Not needed for now
*transferBufferLength = 0;
return true;
}
bool Interface::setFeature(uint16_t * transferBufferLength) {
// Not needed for now
*transferBufferLength = 0;
return true;
}
}
}
}