Numworks Epsilon  1.4.1
Graphing Calculator Operating System
endpoint0.h
Go to the documentation of this file.
1 #ifndef ION_DEVICE_USB_ENDPOINT0_H
2 #define ION_DEVICE_USB_ENDPOINT0_H
3 
4 #include "setup_packet.h"
5 
6 namespace Ion {
7 namespace USB {
8 namespace Device {
9 
10 class RequestRecipient;
11 
12 class Endpoint0 {
13 public:
14  enum class State {
15  Idle,
16  Stalled,
17  DataIn,
18  LastDataIn,
19  StatusIn,
20  DataOut,
22  StatusOut,
23  };
24 
25  constexpr static int k_maxPacketSize = 64;
26  constexpr static int MaxTransferSize = 2048;
27 
28  //constexpr Endpoint0(RequestRecipient * device, RequestRecipient * interface) :
29  Endpoint0(RequestRecipient * device, RequestRecipient * interface) :
30  m_forceNAK(false),
31  m_bufferOffset(0),
32  m_transferBufferLength(0),
33  m_receivedPacketSize(0),
34  m_zeroLengthPacketNeeded(false),
35  m_request(),
36  m_requestRecipients{device, interface},
37  m_state(State::Idle),
38  m_largeBuffer{0}
39  {
40  }
41  void setup();
42  void setupOut();
43  void setOutNAK(bool nak);
44  void enableOut();
45  void reset();
46  bool NAKForced() const { return m_forceNAK; }
48  void processINpacket();
49  void processOUTpacket();
50  void flushTxFifo();
51  void flushRxFifo();
52  void setReceivedPacketSize(uint16_t size) { m_receivedPacketSize = size; }
53  void discardUnreadData();
54  void stallTransaction();
56  void setState(State state) { m_state = state; }
57  void sendSomeData(); // Writes the next data packet and updates the state.
58  void clearForOutTransactions(uint16_t wLength);
59 
60 private:
61  uint16_t receiveSomeData();
62  uint16_t readPacket(void * buffer, uint16_t length);
63  uint16_t writePacket(const void * buffer, uint16_t length);
64 
65  bool m_forceNAK;
66  int m_bufferOffset; // When sending large data stored in the buffer, the offset keeps tracks of which data packet should be sent next.
67  uint16_t m_transferBufferLength;
68  uint16_t m_receivedPacketSize;
69  bool m_zeroLengthPacketNeeded;
70  SetupPacket m_request;
71  RequestRecipient * m_requestRecipients[2];
72  State m_state;
73  uint8_t m_largeBuffer[MaxTransferSize];
74 };
75 
76 }
77 }
78 }
79 
80 #endif
void clearForOutTransactions(uint16_t wLength)
Definition: endpoint0.cpp:254
static constexpr int k_maxPacketSize
Definition: endpoint0.h:25
unsigned short uint16_t
Definition: stdint.h:5
unsigned char uint8_t
Definition: stdint.h:4
Definition: app.cpp:5
static constexpr int MaxTransferSize
Definition: endpoint0.h:26
#define false
Definition: stdbool.h:9
void setOutNAK(bool nak)
Definition: endpoint0.cpp:69
void setReceivedPacketSize(uint16_t size)
Definition: endpoint0.h:52
Definition: backlight.h:6
void setState(State state)
Definition: endpoint0.h:56
Endpoint0(RequestRecipient *device, RequestRecipient *interface)
Definition: endpoint0.h:29