Numworks Epsilon  1.4.1
Graphing Calculator Operating System
device.h
Go to the documentation of this file.
1 #ifndef ION_DEVICE_USB_DEVICE_H
2 #define ION_DEVICE_USB_DEVICE_H
3 
4 #include "stack/descriptor.h"
5 #include "endpoint0.h"
6 #include "interface.h"
7 #include "request_recipient.h"
8 #include "setup_packet.h"
9 
10 namespace Ion {
11 namespace USB {
12 namespace Device {
13 
14 // We only handle control transfers, on EP0.
15 class Device : public RequestRecipient {
16 public:
17  Device(Interface * interface) :
19  m_ep0(this, interface),
20  m_resetOnDisconnect(false)
21  {
22  }
23  void poll();
24  bool isSoftDisconnected() const;
25  void detach();
26  bool resetOnDisconnect() { return m_resetOnDisconnect; }
27  void setResetOnDisconnect(bool reset) { m_resetOnDisconnect = reset; }
28 protected:
29  virtual Descriptor * descriptor(uint8_t type, uint8_t index) = 0;
30  virtual void setActiveConfiguration(uint8_t configurationIndex) = 0;
31  virtual uint8_t getActiveConfiguration() = 0;
32  bool processSetupInRequest(SetupPacket * request, uint8_t * transferBuffer, uint16_t * transferBufferLength, uint16_t transferBufferMaxLength) override;
34 private:
35  // USB Standard Device Request Codes
36  enum class Request {
37  GetStatus = 0,
38  ClearFeature = 1,
39  SetFeature = 3,
40  SetAddress = 5,
41  GetDescriptor = 6,
42  SetDescriptor = 7,
43  GetConfiguration = 8,
44  SetConfiguration = 9,
45  };
46 
47  enum class TransactionType {
48  Setup,
49  In,
50  Out
51  };
52 
53  void setAddress(uint8_t address);
54  bool getStatus(uint8_t * transferBuffer, uint16_t * transferBufferLength, uint16_t transferBufferMaxLength);
55  bool getDescriptor(SetupPacket * request, uint8_t * transferBuffer, uint16_t * transferBufferLength, uint16_t transferBufferMaxLength);
56  bool getConfiguration(uint8_t * transferBuffer, uint16_t * transferBufferLength);
57  bool setConfiguration(SetupPacket * request);
58 
59  bool m_resetOnDisconnect;
60 };
61 
62 }
63 }
64 }
65 
66 #endif
bool resetOnDisconnect()
Definition: device.h:26
unsigned short uint16_t
Definition: stdint.h:5
virtual void setActiveConfiguration(uint8_t configurationIndex)=0
unsigned char uint8_t
Definition: stdint.h:4
Device(Interface *interface)
Definition: device.h:17
virtual uint8_t getActiveConfiguration()=0
Definition: app.cpp:5
bool isSoftDisconnected() const
Definition: device.cpp:81
#define false
Definition: stdbool.h:9
bool processSetupInRequest(SetupPacket *request, uint8_t *transferBuffer, uint16_t *transferBufferLength, uint16_t transferBufferMaxLength) override
Definition: device.cpp:90
virtual Descriptor * descriptor(uint8_t type, uint8_t index)=0
void setResetOnDisconnect(bool reset)
Definition: device.h:27
Definition: backlight.h:6