13
13
14
14
static uint8_t usb_ctrl_data_buffer [32 ];
15
15
16
- static struct usb_cdc_line_coding usb_line_coding = {9600 , 0x00 , 0x00 , 0x08 }; // 9600 baud, 8N1
16
+ static struct usb_cdc_line_coding usb_line_coding = { 9600 , 0x00 , 0x00 , 0x08 }; // 9600 baud, 8N1
17
17
static uint8_t line_state ;
18
18
static uint8_t events ;
19
- static struct process * cdc_event_process = NULL ;
19
+ static struct process * cdc_event_process = NULL ;
20
20
21
21
static void
22
22
notify_user (uint8_t e )
@@ -36,18 +36,20 @@ encapsulated_command(uint8_t *data, unsigned int length)
36
36
static void
37
37
set_line_encoding (uint8_t * data , unsigned int length )
38
38
{
39
- if (length == 7 ) {
39
+ if (length == 7 ) {
40
40
#ifdef DEBUG
41
- static const char parity_char [] = {'N' , 'O' , 'E' , 'M' , 'S' };
42
- static const char * stop_bits_str [] = {"1" ,"1.5" ,"2" };
41
+ static const char parity_char [] = { 'N' , 'O' , 'E' , 'M' , 'S' };
42
+ static const char * stop_bits_str [] = { "1" , "1.5" , "2" };
43
43
const struct usb_cdc_line_coding * coding =
44
44
(const struct usb_cdc_line_coding * )usb_ctrl_data_buffer ;
45
45
char parity = ((coding -> bParityType > 4 )
46
- ? '?' : parity_char [coding -> bParityType ]);
46
+ ? '?' : parity_char [coding -> bParityType ]);
47
+
47
48
const char * stop_bits = ((coding -> bCharFormat > 2 )
48
- ? "?" : stop_bits_str [coding -> bCharFormat ]);
49
+ ? "?" : stop_bits_str [coding -> bCharFormat ]);
50
+
49
51
PRINTF ("Got CDC line coding: %ld/%d/%c/%s\n" ,
50
- coding -> dwDTERate , coding -> bDataBits , parity , stop_bits );
52
+ coding -> dwDTERate , coding -> bDataBits , parity , stop_bits );
51
53
#endif
52
54
memcpy (& usb_line_coding , data , sizeof (usb_line_coding ));
53
55
notify_user (USB_CDC_ACM_LINE_CODING );
@@ -60,12 +62,14 @@ set_line_encoding(uint8_t *data, unsigned int length)
60
62
static unsigned int
61
63
handle_cdc_acm_requests ()
62
64
{
63
- PRINTF ("CDC request %02x %02x\n" , usb_setup_buffer .bmRequestType , usb_setup_buffer .bRequest );
64
- switch (usb_setup_buffer .bmRequestType ) {
65
+ PRINTF ("CDC request %02x %02x\n" , usb_setup_buffer .bmRequestType ,
66
+ usb_setup_buffer .bRequest );
67
+ switch (usb_setup_buffer .bmRequestType ) {
65
68
case 0x21 : /* CDC interface OUT requests */
66
69
/* Check if it's the right interface */
67
- if (usb_setup_buffer .wIndex != 0 ) return 0 ;
68
- switch (usb_setup_buffer .bRequest ) {
70
+ if (usb_setup_buffer .wIndex != 0 )
71
+ return 0 ;
72
+ switch (usb_setup_buffer .bRequest ) {
69
73
case SET_CONTROL_LINE_STATE :
70
74
line_state = usb_setup_buffer .wValue ;
71
75
notify_user (USB_CDC_ACM_LINE_STATE );
@@ -74,54 +78,51 @@ handle_cdc_acm_requests()
74
78
75
79
case SEND_ENCAPSULATED_COMMAND :
76
80
{
77
- unsigned int len = usb_setup_buffer .wLength ;
78
- if (len > sizeof (usb_ctrl_data_buffer ))
79
- len = sizeof (usb_ctrl_data_buffer );
80
- usb_get_ctrl_data (usb_ctrl_data_buffer , len ,
81
- encapsulated_command );
81
+ unsigned int len = usb_setup_buffer .wLength ;
82
+ if (len > sizeof (usb_ctrl_data_buffer ))
83
+ len = sizeof (usb_ctrl_data_buffer );
84
+ usb_get_ctrl_data (usb_ctrl_data_buffer , len , encapsulated_command );
82
85
}
83
86
84
87
return 1 ;
85
88
86
89
87
90
case SET_LINE_CODING :
88
91
{
89
- unsigned int len = usb_setup_buffer .wLength ;
90
- if (len > sizeof (usb_ctrl_data_buffer ))
91
- len = sizeof (usb_ctrl_data_buffer );
92
- usb_get_ctrl_data (usb_ctrl_data_buffer , len ,
93
- set_line_encoding );
92
+ unsigned int len = usb_setup_buffer .wLength ;
93
+ if (len > sizeof (usb_ctrl_data_buffer ))
94
+ len = sizeof (usb_ctrl_data_buffer );
95
+ usb_get_ctrl_data (usb_ctrl_data_buffer , len , set_line_encoding );
94
96
}
95
97
return 1 ;
96
98
}
97
99
break ;
98
- case 0xa1 : /* CDC interface IN requests */
99
- if (usb_setup_buffer .wIndex != 0 ) return 0 ;
100
- switch (usb_setup_buffer .bRequest ) {
100
+ case 0xa1 : /* CDC interface IN requests */
101
+ if (usb_setup_buffer .wIndex != 0 )
102
+ return 0 ;
103
+ switch (usb_setup_buffer .bRequest ) {
101
104
case GET_ENCAPSULATED_RESPONSE :
102
105
PRINTF ("CDC response" );
103
106
usb_send_ctrl_status ();
104
107
return 1 ;
105
108
case GET_LINE_CODING :
106
- usb_send_ctrl_response ((uint8_t * ) & usb_line_coding , 7 );
109
+ usb_send_ctrl_response ((uint8_t * ) & usb_line_coding , 7 );
107
110
return 1 ;
108
111
}
109
112
}
110
113
return 0 ;
111
114
}
112
115
113
- static const struct USBRequestHandler cdc_acm_request_handler =
114
- {
115
- 0x21 , 0x7f ,
116
- 0x00 , 0x00 ,
117
- handle_cdc_acm_requests
118
- };
116
+ static const struct USBRequestHandler cdc_acm_request_handler = {
117
+ 0x21 , 0x7f ,
118
+ 0x00 , 0x00 ,
119
+ handle_cdc_acm_requests
120
+ };
119
121
120
- static struct USBRequestHandlerHook cdc_acm_request_hook =
121
- {
122
- NULL ,
123
- & cdc_acm_request_handler
124
- };
122
+ static struct USBRequestHandlerHook cdc_acm_request_hook = {
123
+ NULL ,
124
+ & cdc_acm_request_handler
125
+ };
125
126
126
127
void
127
128
usb_cdc_acm_setup ()
@@ -154,4 +155,3 @@ usb_cdc_acm_set_event_process(struct process *p)
154
155
{
155
156
cdc_event_process = p ;
156
157
}
157
-
0 commit comments