7 static uint8_t usb_ctrl_data_buffer[32];
10 encapsulated_command(uint8_t *data,
unsigned int length)
12 printf(
"Got CDC command: length %d\n", length);
13 usb_send_ctrl_status();
16 set_line_encoding(uint8_t *data,
unsigned int length)
19 static const char parity_char[] = {
'N',
'O',
'E',
'M',
'S'};
20 static const char *stop_bits_str[] = {
"1",
"1.5",
"2"};
21 const struct usb_cdc_line_coding *coding =
22 (
const struct usb_cdc_line_coding *)usb_ctrl_data_buffer;
23 char parity = ((coding->bParityType > 4)
24 ?
'?' : parity_char[coding->bParityType]);
25 const char *stop_bits = ((coding->bCharFormat > 2)
26 ?
"?" : stop_bits_str[coding->bCharFormat]);
27 printf(
"Got CDC line coding: %ld/%d/%c/%s\n",
28 coding->dwDTERate, coding->bDataBits, parity, stop_bits);
29 usb_send_ctrl_status();
36 handle_cdc_acm_requests()
38 printf(
"CDC request %02x %02x\n", usb_setup_buffer.bmRequestType, usb_setup_buffer.bRequest);
39 switch(usb_setup_buffer.bmRequestType) {
42 if (usb_setup_buffer.wIndex != 0)
return 0;
43 switch(usb_setup_buffer.bRequest) {
44 case SET_CONTROL_LINE_STATE:
45 if (usb_setup_buffer.wValue & 0x02) {
50 if (usb_setup_buffer.wValue & 0x01) {
55 usb_send_ctrl_status();
58 case SEND_ENCAPSULATED_COMMAND:
60 unsigned int len = usb_setup_buffer.wLength;
61 if (len >
sizeof(usb_ctrl_data_buffer))
62 len =
sizeof(usb_ctrl_data_buffer);
63 usb_get_ctrl_data(usb_ctrl_data_buffer, len,
64 encapsulated_command);
72 unsigned int len = usb_setup_buffer.wLength;
73 if (len >
sizeof(usb_ctrl_data_buffer))
74 len =
sizeof(usb_ctrl_data_buffer);
75 usb_get_ctrl_data(usb_ctrl_data_buffer, len,
82 if (usb_setup_buffer.wIndex != 0)
return 0;
83 switch(usb_setup_buffer.bRequest) {
84 case GET_ENCAPSULATED_RESPONSE:
85 printf(
"CDC response");
86 usb_send_ctrl_status();
93 static const struct USBRequestHandler cdc_acm_request_handler =
97 handle_cdc_acm_requests
100 static struct USBRequestHandlerHook cdc_acm_request_hook =
103 &cdc_acm_request_handler
109 usb_register_request_handler(&cdc_acm_request_hook);