Numworks Epsilon  1.4.1
Graphing Calculator Operating System
interface.cpp
Go to the documentation of this file.
1 #include "interface.h"
2 
3 namespace Ion {
4 namespace USB {
5 namespace Device {
6 
7 static inline uint16_t min(uint16_t x, uint16_t y) { return (x<y ? x : y); }
8 
9 bool Interface::processSetupInRequest(SetupPacket * request, uint8_t * transferBuffer, uint16_t * transferBufferLength, uint16_t transferBufferMaxLength) {
11  return false;
12  }
13  switch (request->bRequest()) {
14  case (int) Request::GetStatus:
15  return getStatus(transferBuffer, transferBufferLength, transferBufferMaxLength);
16  case (int) Request::SetInterface:
17  return setInterface(request, transferBufferLength);
18  case (int) Request::GetInterface:
19  return getInterface(transferBuffer, transferBufferLength, transferBufferMaxLength);
20  case (int) Request::ClearFeature:
21  return clearFeature(transferBufferLength);
22  case (int) Request::SetFeature:
23  return setFeature(transferBufferLength);
24  }
25  return false;
26 }
27 
28 bool Interface::getStatus(uint8_t * transferBuffer, uint16_t * transferBufferLength, uint16_t transferBufferMaxLength) {
29  *transferBufferLength = min(2, transferBufferMaxLength);
30  for (int i = 0; i<*transferBufferLength; i++) {
31  transferBuffer[i] = 0; // Reserved, must be set to 0
32  }
33  return true;
34 }
35 
36 bool Interface::getInterface(uint8_t * transferBuffer, uint16_t * transferBufferLength, uint16_t transferBufferMaxLength) {
37  *transferBufferLength = min(1, transferBufferMaxLength);;
38  if (*transferBufferLength > 0) {
39  transferBuffer[0] = getActiveInterfaceAlternative();
40  }
41  return true;
42 }
43 
44 bool Interface::setInterface(SetupPacket * request, uint16_t * transferBufferLength) {
45  // We support one interface only
46  setActiveInterfaceAlternative(request->wValue());
47  // There is one interface alternative only, we no need to set it again.
48  *transferBufferLength = 0;
49  return true;
50 }
51 
52 bool Interface::clearFeature(uint16_t * transferBufferLength) {
53  // Not needed for now
54  *transferBufferLength = 0;
55  return true;
56 }
57 
58 bool Interface::setFeature(uint16_t * transferBufferLength) {
59  // Not needed for now
60  *transferBufferLength = 0;
61  return true;
62 }
63 
64 }
65 }
66 }
unsigned short uint16_t
Definition: stdint.h:5
unsigned char uint8_t
Definition: stdint.h:4
Definition: app.cpp:5
virtual uint8_t getActiveInterfaceAlternative()=0
bool processSetupInRequest(SetupPacket *request, uint8_t *transferBuffer, uint16_t *transferBufferLength, uint16_t transferBufferMaxLength) override
Definition: interface.cpp:9
RequestType requestType() const
Definition: backlight.h:6
virtual void setActiveInterfaceAlternative(uint8_t interfaceAlternativeIndex)=0