1
1
2
2
3
- /* Copyright (c) 2011, Peter Barrett
4
- **
5
- ** Permission to use, copy, modify, and/or distribute this software for
6
- ** any purpose with or without fee is hereby granted, provided that the
7
- ** above copyright notice and this permission notice appear in all copies.
8
- **
9
- ** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10
- ** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11
- ** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
12
- ** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
13
- ** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
14
- ** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
15
- ** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
16
- ** SOFTWARE.
3
+ /* Copyright (c) 2011, Peter Barrett
4
+ **
5
+ ** Permission to use, copy, modify, and/or distribute this software for
6
+ ** any purpose with or without fee is hereby granted, provided that the
7
+ ** above copyright notice and this permission notice appear in all copies.
8
+ **
9
+ ** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10
+ ** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11
+ ** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
12
+ ** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
13
+ ** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
14
+ ** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
15
+ ** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
16
+ ** SOFTWARE.
17
17
*/
18
18
19
19
#include " USBAPI.h"
@@ -38,26 +38,26 @@ static volatile LineInfo _usbLineInfo = { 57600, 0x00, 0x00, 0x00, 0x00 };
38
38
extern const CDCDescriptor _cdcInterface PROGMEM;
39
39
const CDCDescriptor _cdcInterface =
40
40
{
41
- D_IAD (0 ,2 , CDC_COMMUNICATION_INTERFACE_CLASS,CDC_ABSTRACT_CONTROL_MODEL,1 ),
41
+ D_IAD (0 , 2 , CDC_COMMUNICATION_INTERFACE_CLASS, CDC_ABSTRACT_CONTROL_MODEL, 1 ),
42
42
43
43
// CDC communication interface
44
- D_INTERFACE (CDC_ACM_INTERFACE,1 , CDC_COMMUNICATION_INTERFACE_CLASS,CDC_ABSTRACT_CONTROL_MODEL,0 ),
45
- D_CDCCS (CDC_HEADER,0x10 ,0x01 ), // Header (1.10 bcd)
46
- D_CDCCS (CDC_CALL_MANAGEMENT,1 , 1 ), // Device handles call management (not)
47
- D_CDCCS4 (CDC_ABSTRACT_CONTROL_MANAGEMENT,6 ), // SET_LINE_CODING, GET_LINE_CODING, SET_CONTROL_LINE_STATE supported
48
- D_CDCCS (CDC_UNION,CDC_ACM_INTERFACE,CDC_DATA_INTERFACE), // Communication interface is master, data interface is slave 0
49
- D_ENDPOINT (USB_ENDPOINT_IN (CDC_ENDPOINT_ACM),USB_ENDPOINT_TYPE_INTERRUPT,0x10 ,0x40 ),
44
+ D_INTERFACE (CDC_ACM_INTERFACE, 1 , CDC_COMMUNICATION_INTERFACE_CLASS, CDC_ABSTRACT_CONTROL_MODEL, 0 ),
45
+ D_CDCCS (CDC_HEADER, 0x10 , 0x01 ), // Header (1.10 bcd)
46
+ D_CDCCS (CDC_CALL_MANAGEMENT, 1 , 1 ), // Device handles call management (not)
47
+ D_CDCCS4 (CDC_ABSTRACT_CONTROL_MANAGEMENT, 6 ), // SET_LINE_CODING, GET_LINE_CODING, SET_CONTROL_LINE_STATE supported
48
+ D_CDCCS (CDC_UNION, CDC_ACM_INTERFACE, CDC_DATA_INTERFACE), // Communication interface is master, data interface is slave 0
49
+ D_ENDPOINT (USB_ENDPOINT_IN (CDC_ENDPOINT_ACM), USB_ENDPOINT_TYPE_INTERRUPT, 0x10 , 0x40 ),
50
50
51
51
// CDC data interface
52
- D_INTERFACE (CDC_DATA_INTERFACE,2 , CDC_DATA_INTERFACE_CLASS,0 , 0 ),
53
- D_ENDPOINT (USB_ENDPOINT_OUT (CDC_ENDPOINT_OUT),USB_ENDPOINT_TYPE_BULK,0x40 ,0 ),
54
- D_ENDPOINT (USB_ENDPOINT_IN (CDC_ENDPOINT_IN ), USB_ENDPOINT_TYPE_BULK,0x40 ,0 )
52
+ D_INTERFACE (CDC_DATA_INTERFACE, 2 , CDC_DATA_INTERFACE_CLASS, 0 , 0 ),
53
+ D_ENDPOINT (USB_ENDPOINT_OUT (CDC_ENDPOINT_OUT), USB_ENDPOINT_TYPE_BULK, 0x40 , 0 ),
54
+ D_ENDPOINT (USB_ENDPOINT_IN (CDC_ENDPOINT_IN), USB_ENDPOINT_TYPE_BULK, 0x40 , 0 )
55
55
};
56
56
57
57
int WEAK CDC_GetInterface (u8 * interfaceNum)
58
58
{
59
59
interfaceNum[0 ] += 2 ; // uses 2
60
- return USB_SendControl (TRANSFER_PGM,&_cdcInterface,sizeof (_cdcInterface));
60
+ return USB_SendControl (TRANSFER_PGM, &_cdcInterface, sizeof (_cdcInterface));
61
61
}
62
62
63
63
bool WEAK CDC_Setup (Setup& setup)
@@ -69,7 +69,7 @@ bool WEAK CDC_Setup(Setup& setup)
69
69
{
70
70
if (CDC_GET_LINE_CODING == r)
71
71
{
72
- USB_SendControl (0 ,(void *)&_usbLineInfo,7 );
72
+ USB_SendControl (0 , (void *)&_usbLineInfo, 7 );
73
73
return true ;
74
74
}
75
75
}
@@ -78,7 +78,7 @@ bool WEAK CDC_Setup(Setup& setup)
78
78
{
79
79
if (CDC_SET_LINE_CODING == r)
80
80
{
81
- USB_RecvControl ((void *)&_usbLineInfo,7 );
81
+ USB_RecvControl ((void *)&_usbLineInfo, 7 );
82
82
}
83
83
84
84
if (CDC_SET_CONTROL_LINE_STATE == r)
@@ -168,20 +168,21 @@ size_t Serial_::write(uint8_t c)
168
168
169
169
size_t Serial_::write (const uint8_t *buffer, size_t size)
170
170
{
171
- /* only try to send bytes if the high-level CDC connection itself
171
+ /* only try to send bytes if the high-level CDC connection itself
172
172
is open (not just the pipe) - the OS should set lineState when the port
173
173
is opened and clear lineState when the port is closed.
174
174
bytes sent before the user opens the connection or after
175
175
the connection is closed are lost - just like with a UART. */
176
-
176
+
177
177
// TODO - ZE - check behavior on different OSes and test what happens if an
178
178
// open connection isn't broken cleanly (cable is yanked out, host dies
179
179
// or locks up, or host virtual serial port hangs)
180
180
if (_usbLineInfo.lineState > 0 ) {
181
- int r = USB_Send (CDC_TX,buffer,size);
181
+ int r = USB_Send (CDC_TX, buffer, size);
182
182
if (r > 0 ) {
183
183
return r;
184
- } else {
184
+ }
185
+ else {
185
186
setWriteError ();
186
187
return 0 ;
187
188
}
@@ -199,7 +200,7 @@ size_t Serial_::write(const uint8_t *buffer, size_t size)
199
200
// where the port is configured (lineState != 0) but not quite opened.
200
201
Serial_::operator bool () {
201
202
bool result = false ;
202
- if (_usbLineInfo.lineState > 0 )
203
+ if (_usbLineInfo.lineState > 0 )
203
204
result = true ;
204
205
delay (10 );
205
206
return result;
0 commit comments