1
+ #ifndef __CDC_H__
2
+ #define __CDC_H__
3
+
4
+ #include " Arduino.h"
5
+ #include " api/Stream.h"
6
+ #include " api/USBAPI.h"
7
+
8
+ #if defined (USBCON)
9
+
10
+ // ================================================================================
11
+ // ================================================================================
12
+ // Serial over CDC (Serial1 is the physical port)
13
+
14
+ #define RINGBUFFER_FORCE_SMALL_SIZE
15
+ #include " api/RingBuffer.h"
16
+
17
+ #ifndef SERIAL_BUFFER_SIZE
18
+ #if ((RAMEND - RAMSTART) < 1023)
19
+ #define SERIAL_BUFFER_SIZE 16
20
+ #else
21
+ #define SERIAL_BUFFER_SIZE 64
22
+ #endif
23
+ #endif
24
+ #if (SERIAL_BUFFER_SIZE > 256)
25
+ #error Please lower the CDC Buffer size
26
+ #endif
27
+
28
+ class Serial_ : public Stream
29
+ {
30
+ private:
31
+ int peek_buffer;
32
+ public:
33
+ Serial_ () { peek_buffer = -1 ; };
34
+ void begin (unsigned long );
35
+ void begin (unsigned long , uint8_t );
36
+ void end (void );
37
+
38
+ virtual int available (void );
39
+ virtual int peek (void );
40
+ virtual int read (void );
41
+ virtual int availableForWrite (void );
42
+ virtual void flush (void );
43
+ virtual size_t write (uint8_t );
44
+ virtual size_t write (const uint8_t *, size_t );
45
+ using Print::write; // pull in write(str) and write(buf, size) from Print
46
+ operator bool ();
47
+
48
+ // RingBuffer _rx_buffer(SERIAL_BUFFER_SIZE);
49
+
50
+ // This method allows processing "SEND_BREAK" requests sent by
51
+ // the USB host. Those requests indicate that the host wants to
52
+ // send a BREAK signal and are accompanied by a single uint16_t
53
+ // value, specifying the duration of the break. The value 0
54
+ // means to end any current break, while the value 0xffff means
55
+ // to start an indefinite break.
56
+ // readBreak() will return the value of the most recent break
57
+ // request, but will return it at most once, returning -1 when
58
+ // readBreak() is called again (until another break request is
59
+ // received, which is again returned once).
60
+ // This also mean that if two break requests are received
61
+ // without readBreak() being called in between, the value of the
62
+ // first request is lost.
63
+ // Note that the value returned is a long, so it can return
64
+ // 0-0xffff as well as -1.
65
+ int32_t readBreak ();
66
+
67
+ // These return the settings specified by the USB host for the
68
+ // serial port. These aren't really used, but are offered here
69
+ // in case a sketch wants to act on these settings.
70
+ uint32_t baud ();
71
+ uint8_t stopbits ();
72
+ uint8_t paritytype ();
73
+ uint8_t numbits ();
74
+ bool dtr ();
75
+ bool rts ();
76
+ enum {
77
+ ONE_STOP_BIT = 0 ,
78
+ ONE_AND_HALF_STOP_BIT = 1 ,
79
+ TWO_STOP_BITS = 2 ,
80
+ };
81
+ enum {
82
+ NO_PARITY = 0 ,
83
+ ODD_PARITY = 1 ,
84
+ EVEN_PARITY = 2 ,
85
+ MARK_PARITY = 3 ,
86
+ SPACE_PARITY = 4 ,
87
+ };
88
+
89
+ };
90
+ extern Serial_ Serial;
91
+
92
+ #define HAVE_CDCSERIAL
93
+
94
+ // ================================================================================
95
+ // ================================================================================
96
+ // CSC 'Driver'
97
+
98
+ int CDC_GetInterface (uint8_t * interfaceNum);
99
+ int CDC_GetDescriptor (int i);
100
+ bool CDC_Setup (USBSetup& setup);
101
+
102
+ #endif
103
+
104
+ #endif
0 commit comments