|
33 | 33 | #include "api/Stream.h" |
34 | 34 | #include "api/RingBuffer.h" |
35 | 35 | #include "api/USBAPI.h" |
| 36 | +#include "CDC.h" |
36 | 37 |
|
37 | 38 | #if ARDUINO_API_VERSION > 10000 |
38 | 39 | using namespace arduino; |
@@ -97,12 +98,87 @@ class USBDeviceClass { |
97 | 98 | extern USBDeviceClass USBDevice; |
98 | 99 |
|
99 | 100 | //================================================================================ |
100 | | -//================================================================================ |
101 | | -// MSC 'Driver' |
| 101 | +// Serial over CDC (Serial1 is the physical port) |
| 102 | + |
| 103 | +class Serial_ : public Stream, public arduino::PluggableUSBModule |
| 104 | +{ |
| 105 | +public: |
| 106 | + Serial_(USBDeviceClass &_usb); |
| 107 | + void begin(uint32_t baud_count); |
| 108 | + void begin(unsigned long, uint8_t); |
| 109 | + void end(void); |
| 110 | + |
| 111 | + virtual int available(void); |
| 112 | + virtual int availableForWrite(void); |
| 113 | + virtual int peek(void); |
| 114 | + virtual int read(void); |
| 115 | + virtual void flush(void); |
| 116 | + virtual void clear(void); |
| 117 | + virtual size_t write(uint8_t); |
| 118 | + virtual size_t write(const uint8_t *buffer, size_t size); |
| 119 | + using Print::write; // pull in write(str) from Print |
| 120 | + operator bool(); |
| 121 | + |
| 122 | + size_t readBytes(char *buffer, size_t length); |
| 123 | + |
| 124 | + // This method allows processing "SEND_BREAK" requests sent by |
| 125 | + // the USB host. Those requests indicate that the host wants to |
| 126 | + // send a BREAK signal and are accompanied by a single uint16_t |
| 127 | + // value, specifying the duration of the break. The value 0 |
| 128 | + // means to end any current break, while the value 0xffff means |
| 129 | + // to start an indefinite break. |
| 130 | + // readBreak() will return the value of the most recent break |
| 131 | + // request, but will return it at most once, returning -1 when |
| 132 | + // readBreak() is called again (until another break request is |
| 133 | + // received, which is again returned once). |
| 134 | + // This also mean that if two break requests are received |
| 135 | + // without readBreak() being called in between, the value of the |
| 136 | + // first request is lost. |
| 137 | + // Note that the value returned is a long, so it can return |
| 138 | + // 0-0xffff as well as -1. |
| 139 | + int32_t readBreak(); |
| 140 | + |
| 141 | + // These return the settings specified by the USB host for the |
| 142 | + // serial port. These aren't really used, but are offered here |
| 143 | + // in case a sketch wants to act on these settings. |
| 144 | + uint32_t baud(); |
| 145 | + uint8_t stopbits(); |
| 146 | + uint8_t paritytype(); |
| 147 | + uint8_t numbits(); |
| 148 | + bool dtr(); |
| 149 | + bool rts(); |
| 150 | + enum { |
| 151 | + ONE_STOP_BIT = 0, |
| 152 | + ONE_AND_HALF_STOP_BIT = 1, |
| 153 | + TWO_STOP_BITS = 2, |
| 154 | + }; |
| 155 | + enum { |
| 156 | + NO_PARITY = 0, |
| 157 | + ODD_PARITY = 1, |
| 158 | + EVEN_PARITY = 2, |
| 159 | + MARK_PARITY = 3, |
| 160 | + SPACE_PARITY = 4, |
| 161 | + }; |
| 162 | + |
| 163 | +protected: |
| 164 | + // Implementation of the PUSBListNode |
| 165 | + int getInterface(uint8_t* interfaceNum); |
| 166 | + int getDescriptor(USBSetup& setup); |
| 167 | + bool setup(USBSetup& setup); |
| 168 | + uint8_t getShortName(char* name); |
| 169 | + void handleEndpoint(int ep); |
| 170 | + void enableInterrupt(); |
| 171 | + |
| 172 | +friend USBDeviceClass; |
102 | 173 |
|
103 | | -uint32_t MSC_GetInterface(uint8_t* interfaceNum); |
104 | | -uint32_t MSC_GetDescriptor(uint32_t i); |
105 | | -bool MSC_Setup(USBSetup& setup); |
106 | | -bool MSC_Data(uint8_t rx,uint8_t tx); |
| 174 | +private: |
| 175 | + int availableForStore(void); |
| 176 | + |
| 177 | + USBDeviceClass &usb; |
| 178 | + bool stalled; |
| 179 | + unsigned int epType[3]; |
| 180 | + |
| 181 | +}; |
| 182 | +extern Serial_ SerialUSB; |
107 | 183 |
|
108 | 184 | #endif // __cplusplus |
0 commit comments