-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
1,577 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
### Put generated sources in a separate directory | ||
BUILTSRCDIR = src_$(TARGET) | ||
ifeq (${wildcard $(BUILTSRCDIR)},) | ||
DUMMY := ${shell mkdir $(BUILTSRCDIR)} | ||
endif | ||
|
||
STRUCTGEN = structgen | ||
|
||
PROJECTDIRS += $(BUILTSRCDIR) | ||
|
||
USB_STRING_DESCRIPTORS ?= $(CONTIKI_CPU_ARM)/common/usb/cdc-acm/string-descriptors.xml | ||
|
||
XMLDIRS= | ||
|
||
USB = usb-arch.c usb-core.c | ||
|
||
ifdef USB_CDC_ACM_CLASS | ||
CONTIKI_CPU_DIRS += ../common/usb/cdc-acm | ||
USB += cdc-acm.c cdc-acm-descriptors.c cdc-acm-string-descriptors.c | ||
XMLDIRS += $(CONTIKI_CPU_ARM)/common/usb/cdc-acm/ | ||
endif | ||
|
||
ifdef USB_CDC_ETH_CLASS | ||
CONTIKI_CPU_DIRS += ../common/usb/cdc-eth | ||
USB += cdc-eth.c cdc-eth-descriptors.c cdc-eth-string-descriptors.c dhcps.c | ||
XMLDIRS += $(CONTIKI_CPU_ARM)/common/usb/cdc-eth/ | ||
endif | ||
|
||
ifdef USB_MASS_STORAGE_CLASS | ||
CONTIKI_CPU_DIRS += ../common/usb/msc | ||
USB += usb-msc-bulk.c usb-rbc.c msc-descriptors-consts.c msc-descriptors.c | ||
XMLDIRS += $(CONTIKI_CPU_ARM)/common/usb/msc | ||
endif | ||
|
||
ifdef USB_MSC_QIC157 | ||
CONTIKI_CPU_DIRS += ../common/usb/msc | ||
USB += usb-msc-bulk.c usb-qic157.c msc-qic157-descriptors.c msc-qic157-string-descriptors.c | ||
XMLDIRS += $(CONTIKI_CPU_ARM)/common/usb/msc | ||
endif | ||
|
||
ifdef USB_MSC_STREAMING | ||
CONTIKI_CPU_DIRS += ../common/usb/msc | ||
USB += usb-msc-bulk.c usb-streaming.c msc-scsi-streaming-descriptors-consts.c msc-scsi-streaming-descriptors.c | ||
XMLDIRS += $(CONTIKI_CPU_ARM)/common/usb/msc | ||
endif | ||
|
||
ifdef USB_MTP_CLASS | ||
CONTIKI_CPU_DIRS += ../common/usb/mtp | ||
USB += usb-mtp.c mtp-descriptors-consts.c mtp-descriptors.c | ||
STRUCTGENDIRS += $(CONTIKI_CPU_ARM)/common/usb/mtp | ||
endif | ||
|
||
vpath %.xml $(XMLDIRS) | ||
vpath %.gen.c $(STRUCTGENDIRS) | ||
|
||
%.c: %.xml | ||
$(XSLTPROC) $(CONTIKI_CPU_ARM)/common/usb/string-descriptors.xslt $^ >$(BUILTSRCDIR)/$@ | ||
|
||
%-consts.c: %.gen.c | ||
$(CPP) -I$(CFLAGS) $< | $(STRUCTGEN) --output $(BUILTSRCDIR)/$*-consts.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
#include "descriptors.h" | ||
#include "contiki-conf.h" | ||
#include "cdc.h" | ||
#include "usb-arch.h" | ||
|
||
const struct usb_st_device_descriptor device_descriptor = | ||
{ | ||
sizeof(struct usb_st_device_descriptor), | ||
DEVICE, | ||
0x0210, | ||
CDC, | ||
0, | ||
0, | ||
CTRL_EP_SIZE, | ||
0xffff, | ||
0xffff, | ||
0x0030, | ||
2, | ||
1, | ||
3, | ||
1 | ||
}; | ||
|
||
const struct configuration_st { | ||
struct usb_st_configuration_descriptor configuration; | ||
struct usb_st_interface_descriptor comm; | ||
struct usb_cdc_header_func_descriptor header; | ||
struct usb_cdc_abstract_ctrl_mgmnt_func_descriptor abstract_ctrl; | ||
struct usb_cdc_union_func_descriptor union_descr; | ||
struct usb_cdc_call_mgmnt_func_descriptor call_mgmt; | ||
#if 1 | ||
struct usb_st_endpoint_descriptor ep_notification; | ||
#endif | ||
struct usb_st_interface_descriptor data; | ||
struct usb_st_endpoint_descriptor ep_in; | ||
struct usb_st_endpoint_descriptor ep_out; | ||
} BYTE_ALIGNED configuration_block = | ||
{ | ||
/* Configuration */ | ||
{ | ||
sizeof(configuration_block.configuration), | ||
CONFIGURATION, | ||
sizeof(configuration_block), | ||
2, | ||
1, | ||
0, | ||
0x80, | ||
50 | ||
}, | ||
{ | ||
sizeof(configuration_block.comm), | ||
INTERFACE, | ||
0, | ||
0, | ||
1, | ||
CDC, | ||
ABSTRACT_CONTROL_MODEL, | ||
V_25TER_PROTOCOL, | ||
0 | ||
}, | ||
{ | ||
sizeof(configuration_block.header), | ||
CS_INTERFACE, | ||
CDC_FUNC_DESCR_HEADER, | ||
0x0110 | ||
}, | ||
{ | ||
sizeof(configuration_block.abstract_ctrl), | ||
CS_INTERFACE, | ||
CDC_FUNC_DESCR_ABSTRACT_CTRL_MGMNT, | ||
0 | ||
}, | ||
{ | ||
sizeof(configuration_block.union_descr), | ||
CS_INTERFACE, | ||
CDC_FUNC_DESCR_UNION, | ||
0, /* Master */ | ||
{1} /* Slave */ | ||
}, | ||
{ | ||
sizeof(configuration_block.call_mgmt), | ||
CS_INTERFACE, | ||
CDC_FUNC_DESCR_CALL_MGMNT, | ||
0x02, | ||
1 /* data interface */ | ||
}, | ||
{ | ||
sizeof(configuration_block.ep_notification), | ||
ENDPOINT, | ||
0x83, | ||
0x03, | ||
USB_EP3_SIZE, | ||
100 | ||
}, | ||
{ | ||
sizeof(configuration_block.data), | ||
INTERFACE, | ||
1, | ||
0, | ||
2, | ||
CDC_DATA, | ||
0, | ||
TRANSPARENT_PROTOCOL, | ||
0 | ||
}, | ||
{ | ||
sizeof(configuration_block.ep_in), | ||
ENDPOINT, | ||
0x81, | ||
0x02, | ||
USB_EP1_SIZE, | ||
0 | ||
}, | ||
{ | ||
sizeof(configuration_block.ep_out), | ||
ENDPOINT, | ||
0x02, | ||
0x02, | ||
USB_EP2_SIZE, | ||
0 | ||
} | ||
|
||
}; | ||
|
||
const struct usb_st_configuration_descriptor const *configuration_head = | ||
(struct usb_st_configuration_descriptor const*)&configuration_block; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#include "cdc-acm.h" | ||
#include "cdc.h" | ||
#include "usb-api.h" | ||
#include "usb-core.h" | ||
|
||
#include <stdio.h> | ||
|
||
static uint8_t usb_ctrl_data_buffer[32]; | ||
|
||
static void | ||
encapsulated_command(uint8_t *data, unsigned int length) | ||
{ | ||
printf("Got CDC command: length %d\n", length); | ||
usb_send_ctrl_status(); | ||
} | ||
static void | ||
set_line_encoding(uint8_t *data, unsigned int length) | ||
{ | ||
if (length == 7) { | ||
static const char parity_char[] = {'N', 'O', 'E', 'M', 'S'}; | ||
static const char *stop_bits_str[] = {"1","1.5","2"}; | ||
const struct usb_cdc_line_coding *coding = | ||
(const struct usb_cdc_line_coding *)usb_ctrl_data_buffer; | ||
char parity = ((coding->bParityType > 4) | ||
? '?' : parity_char[coding->bParityType]); | ||
const char *stop_bits = ((coding->bCharFormat > 2) | ||
? "?" : stop_bits_str[coding->bCharFormat]); | ||
printf("Got CDC line coding: %ld/%d/%c/%s\n", | ||
coding->dwDTERate, coding->bDataBits, parity, stop_bits); | ||
usb_send_ctrl_status(); | ||
} else { | ||
usb_error_stall(); | ||
} | ||
} | ||
|
||
static unsigned int | ||
handle_cdc_acm_requests() | ||
{ | ||
printf("CDC request %02x %02x\n", usb_setup_buffer.bmRequestType, usb_setup_buffer.bRequest); | ||
switch(usb_setup_buffer.bmRequestType) { | ||
case 0x21: /* CDC interface OUT requests */ | ||
/* Check if it's the right interface */ | ||
if (usb_setup_buffer.wIndex != 0) return 0; | ||
switch(usb_setup_buffer.bRequest) { | ||
case SET_CONTROL_LINE_STATE: | ||
if (usb_setup_buffer.wValue & 0x02) { | ||
puts("Carrier on"); | ||
} else { | ||
puts("Carrier off"); | ||
} | ||
if (usb_setup_buffer.wValue & 0x01) { | ||
puts("DTE on"); | ||
} else { | ||
puts("DTE off"); | ||
} | ||
usb_send_ctrl_status(); | ||
return 1; | ||
|
||
case SEND_ENCAPSULATED_COMMAND: | ||
{ | ||
unsigned int len = usb_setup_buffer.wLength; | ||
if (len > sizeof(usb_ctrl_data_buffer)) | ||
len = sizeof(usb_ctrl_data_buffer); | ||
usb_get_ctrl_data(usb_ctrl_data_buffer, len, | ||
encapsulated_command); | ||
} | ||
|
||
return 1; | ||
|
||
|
||
case SET_LINE_CODING: | ||
{ | ||
unsigned int len = usb_setup_buffer.wLength; | ||
if (len > sizeof(usb_ctrl_data_buffer)) | ||
len = sizeof(usb_ctrl_data_buffer); | ||
usb_get_ctrl_data(usb_ctrl_data_buffer, len, | ||
set_line_encoding); | ||
} | ||
return 1; | ||
} | ||
break; | ||
case 0xa1: /* CDC interface IN requests */ | ||
if (usb_setup_buffer.wIndex != 0) return 0; | ||
switch(usb_setup_buffer.bRequest) { | ||
case GET_ENCAPSULATED_RESPONSE: | ||
printf("CDC response"); | ||
usb_send_ctrl_status(); | ||
return 1; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
static const struct USBRequestHandler cdc_acm_request_handler = | ||
{ | ||
0x21, 0x7f, | ||
0x00, 0x00, | ||
handle_cdc_acm_requests | ||
}; | ||
|
||
static struct USBRequestHandlerHook cdc_acm_request_hook = | ||
{ | ||
NULL, | ||
&cdc_acm_request_handler | ||
}; | ||
|
||
void | ||
usb_cdc_acm_setup() | ||
{ | ||
usb_register_request_handler(&cdc_acm_request_hook); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#ifndef __CDC_ACM_H__UFV6K50827__ | ||
#define __CDC_ACM_H__UFV6K50827__ | ||
|
||
void | ||
usb_cdc_acm_setup(); | ||
|
||
#endif /* __CDC_ACM_H__UFV6K50827__ */ |
Oops, something went wrong.