Blame view

build4/epsilon-master/ion/src/device/usb/stack/device.h 1.82 KB
6663b6c9   adorian   projet complet av...
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
  #ifndef ION_DEVICE_USB_DEVICE_H
  #define ION_DEVICE_USB_DEVICE_H
  
  #include "descriptor/descriptor.h"
  #include "endpoint0.h"
  #include "interface.h"
  #include "request_recipient.h"
  #include "setup_packet.h"
  
  namespace Ion {
  namespace USB {
  namespace Device {
  
  // We only handle control transfers, on EP0.
  class Device : public RequestRecipient {
  public:
    Device(Interface * interface) :
      RequestRecipient(&m_ep0),
      m_ep0(this, interface),
      m_resetOnDisconnect(false)
    {
    }
    void poll();
    bool isSoftDisconnected() const;
    void detach();
    bool resetOnDisconnect() { return m_resetOnDisconnect; }
    void setResetOnDisconnect(bool reset) { m_resetOnDisconnect = reset; }
  protected:
    virtual Descriptor * descriptor(uint8_t type, uint8_t index) = 0;
    virtual void setActiveConfiguration(uint8_t configurationIndex) = 0;
    virtual uint8_t getActiveConfiguration() = 0;
    bool processSetupInRequest(SetupPacket * request, uint8_t * transferBuffer, uint16_t * transferBufferLength, uint16_t transferBufferMaxLength) override;
    Endpoint0 m_ep0;
  private:
    // USB Standard Device Request Codes
    enum class Request {
      GetStatus        = 0,
      ClearFeature     = 1,
      SetFeature       = 3,
      SetAddress       = 5,
      GetDescriptor    = 6,
      SetDescriptor    = 7,
      GetConfiguration = 8,
      SetConfiguration = 9,
    };
  
    enum class TransactionType {
      Setup,
      In,
      Out
    };
  
    void setAddress(uint8_t address);
    bool getStatus(uint8_t * transferBuffer, uint16_t * transferBufferLength, uint16_t transferBufferMaxLength);
    bool getDescriptor(SetupPacket * request, uint8_t * transferBuffer, uint16_t * transferBufferLength, uint16_t transferBufferMaxLength);
    bool getConfiguration(uint8_t * transferBuffer, uint16_t * transferBufferLength);
    bool setConfiguration(SetupPacket * request);
  
    bool m_resetOnDisconnect;
  };
  
  }
  }
  }
  
  #endif