parent
be93f1ae52
commit
79cffa030f
2 changed files with 43 additions and 48 deletions
|
@ -13,10 +13,10 @@
|
||||||
|
|
||||||
static uint8_t usb_ctrl_data_buffer[32];
|
static uint8_t usb_ctrl_data_buffer[32];
|
||||||
|
|
||||||
static struct usb_cdc_line_coding usb_line_coding = {9600, 0x00, 0x00, 0x08}; // 9600 baud, 8N1
|
static struct usb_cdc_line_coding usb_line_coding = { 9600, 0x00, 0x00, 0x08 }; // 9600 baud, 8N1
|
||||||
static uint8_t line_state;
|
static uint8_t line_state;
|
||||||
static uint8_t events;
|
static uint8_t events;
|
||||||
static struct process * cdc_event_process = NULL;
|
static struct process *cdc_event_process = NULL;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
notify_user(uint8_t e)
|
notify_user(uint8_t e)
|
||||||
|
@ -36,18 +36,20 @@ encapsulated_command(uint8_t *data, unsigned int length)
|
||||||
static void
|
static void
|
||||||
set_line_encoding(uint8_t *data, unsigned int length)
|
set_line_encoding(uint8_t *data, unsigned int length)
|
||||||
{
|
{
|
||||||
if (length == 7) {
|
if(length == 7) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
static const char parity_char[] = {'N', 'O', 'E', 'M', 'S'};
|
static const char parity_char[] = { 'N', 'O', 'E', 'M', 'S' };
|
||||||
static const char *stop_bits_str[] = {"1","1.5","2"};
|
static const char *stop_bits_str[] = { "1", "1.5", "2" };
|
||||||
const struct usb_cdc_line_coding *coding =
|
const struct usb_cdc_line_coding *coding =
|
||||||
(const struct usb_cdc_line_coding *)usb_ctrl_data_buffer;
|
(const struct usb_cdc_line_coding *)usb_ctrl_data_buffer;
|
||||||
char parity = ((coding->bParityType > 4)
|
char parity = ((coding->bParityType > 4)
|
||||||
? '?' : parity_char[coding->bParityType]);
|
? '?' : parity_char[coding->bParityType]);
|
||||||
|
|
||||||
const char *stop_bits = ((coding->bCharFormat > 2)
|
const char *stop_bits = ((coding->bCharFormat > 2)
|
||||||
? "?" : stop_bits_str[coding->bCharFormat]);
|
? "?" : stop_bits_str[coding->bCharFormat]);
|
||||||
|
|
||||||
PRINTF("Got CDC line coding: %ld/%d/%c/%s\n",
|
PRINTF("Got CDC line coding: %ld/%d/%c/%s\n",
|
||||||
coding->dwDTERate, coding->bDataBits, parity, stop_bits);
|
coding->dwDTERate, coding->bDataBits, parity, stop_bits);
|
||||||
#endif
|
#endif
|
||||||
memcpy(&usb_line_coding, data, sizeof(usb_line_coding));
|
memcpy(&usb_line_coding, data, sizeof(usb_line_coding));
|
||||||
notify_user(USB_CDC_ACM_LINE_CODING);
|
notify_user(USB_CDC_ACM_LINE_CODING);
|
||||||
|
@ -60,12 +62,14 @@ set_line_encoding(uint8_t *data, unsigned int length)
|
||||||
static unsigned int
|
static unsigned int
|
||||||
handle_cdc_acm_requests()
|
handle_cdc_acm_requests()
|
||||||
{
|
{
|
||||||
PRINTF("CDC request %02x %02x\n", usb_setup_buffer.bmRequestType, usb_setup_buffer.bRequest);
|
PRINTF("CDC request %02x %02x\n", usb_setup_buffer.bmRequestType,
|
||||||
switch(usb_setup_buffer.bmRequestType) {
|
usb_setup_buffer.bRequest);
|
||||||
|
switch (usb_setup_buffer.bmRequestType) {
|
||||||
case 0x21: /* CDC interface OUT requests */
|
case 0x21: /* CDC interface OUT requests */
|
||||||
/* Check if it's the right interface */
|
/* Check if it's the right interface */
|
||||||
if (usb_setup_buffer.wIndex != 0) return 0;
|
if(usb_setup_buffer.wIndex != 0)
|
||||||
switch(usb_setup_buffer.bRequest) {
|
return 0;
|
||||||
|
switch (usb_setup_buffer.bRequest) {
|
||||||
case SET_CONTROL_LINE_STATE:
|
case SET_CONTROL_LINE_STATE:
|
||||||
line_state = usb_setup_buffer.wValue;
|
line_state = usb_setup_buffer.wValue;
|
||||||
notify_user(USB_CDC_ACM_LINE_STATE);
|
notify_user(USB_CDC_ACM_LINE_STATE);
|
||||||
|
@ -74,11 +78,10 @@ handle_cdc_acm_requests()
|
||||||
|
|
||||||
case SEND_ENCAPSULATED_COMMAND:
|
case SEND_ENCAPSULATED_COMMAND:
|
||||||
{
|
{
|
||||||
unsigned int len = usb_setup_buffer.wLength;
|
unsigned int len = usb_setup_buffer.wLength;
|
||||||
if (len > sizeof(usb_ctrl_data_buffer))
|
if(len > sizeof(usb_ctrl_data_buffer))
|
||||||
len = sizeof(usb_ctrl_data_buffer);
|
len = sizeof(usb_ctrl_data_buffer);
|
||||||
usb_get_ctrl_data(usb_ctrl_data_buffer, len,
|
usb_get_ctrl_data(usb_ctrl_data_buffer, len, encapsulated_command);
|
||||||
encapsulated_command);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -86,42 +89,40 @@ handle_cdc_acm_requests()
|
||||||
|
|
||||||
case SET_LINE_CODING:
|
case SET_LINE_CODING:
|
||||||
{
|
{
|
||||||
unsigned int len = usb_setup_buffer.wLength;
|
unsigned int len = usb_setup_buffer.wLength;
|
||||||
if (len > sizeof(usb_ctrl_data_buffer))
|
if(len > sizeof(usb_ctrl_data_buffer))
|
||||||
len = sizeof(usb_ctrl_data_buffer);
|
len = sizeof(usb_ctrl_data_buffer);
|
||||||
usb_get_ctrl_data(usb_ctrl_data_buffer, len,
|
usb_get_ctrl_data(usb_ctrl_data_buffer, len, set_line_encoding);
|
||||||
set_line_encoding);
|
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0xa1: /* CDC interface IN requests */
|
case 0xa1: /* CDC interface IN requests */
|
||||||
if (usb_setup_buffer.wIndex != 0) return 0;
|
if(usb_setup_buffer.wIndex != 0)
|
||||||
switch(usb_setup_buffer.bRequest) {
|
return 0;
|
||||||
|
switch (usb_setup_buffer.bRequest) {
|
||||||
case GET_ENCAPSULATED_RESPONSE:
|
case GET_ENCAPSULATED_RESPONSE:
|
||||||
PRINTF("CDC response");
|
PRINTF("CDC response");
|
||||||
usb_send_ctrl_status();
|
usb_send_ctrl_status();
|
||||||
return 1;
|
return 1;
|
||||||
case GET_LINE_CODING:
|
case GET_LINE_CODING:
|
||||||
usb_send_ctrl_response((uint8_t *) &usb_line_coding, 7);
|
usb_send_ctrl_response((uint8_t *) & usb_line_coding, 7);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct USBRequestHandler cdc_acm_request_handler =
|
static const struct USBRequestHandler cdc_acm_request_handler = {
|
||||||
{
|
0x21, 0x7f,
|
||||||
0x21, 0x7f,
|
0x00, 0x00,
|
||||||
0x00, 0x00,
|
handle_cdc_acm_requests
|
||||||
handle_cdc_acm_requests
|
};
|
||||||
};
|
|
||||||
|
|
||||||
static struct USBRequestHandlerHook cdc_acm_request_hook =
|
static struct USBRequestHandlerHook cdc_acm_request_hook = {
|
||||||
{
|
NULL,
|
||||||
NULL,
|
&cdc_acm_request_handler
|
||||||
&cdc_acm_request_handler
|
};
|
||||||
};
|
|
||||||
|
|
||||||
void
|
void
|
||||||
usb_cdc_acm_setup()
|
usb_cdc_acm_setup()
|
||||||
|
@ -154,4 +155,3 @@ usb_cdc_acm_set_event_process(struct process *p)
|
||||||
{
|
{
|
||||||
cdc_event_process = p;
|
cdc_event_process = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,26 +4,21 @@
|
||||||
#include "cdc.h"
|
#include "cdc.h"
|
||||||
#include "contiki.h"
|
#include "contiki.h"
|
||||||
|
|
||||||
void
|
void usb_cdc_acm_setup();
|
||||||
usb_cdc_acm_setup();
|
|
||||||
|
|
||||||
|
|
||||||
#define USB_CDC_ACM_LINE_CODING 0x1
|
#define USB_CDC_ACM_LINE_CODING 0x1
|
||||||
#define USB_CDC_ACM_LINE_STATE 0x2
|
#define USB_CDC_ACM_LINE_STATE 0x2
|
||||||
uint8_t
|
uint8_t usb_cdc_acm_get_events(void);
|
||||||
usb_cdc_acm_get_events(void);
|
|
||||||
|
|
||||||
|
|
||||||
#define USB_CDC_ACM_DTE 0x1
|
#define USB_CDC_ACM_DTE 0x1
|
||||||
#define USB_CDC_ACM_RTS 0x2
|
#define USB_CDC_ACM_RTS 0x2
|
||||||
uint8_t
|
uint8_t usb_cdc_acm_get_line_state(void);
|
||||||
usb_cdc_acm_get_line_state(void);
|
|
||||||
|
|
||||||
|
|
||||||
const struct usb_cdc_line_coding *
|
const struct usb_cdc_line_coding *usb_cdc_acm_get_line_coding(void);
|
||||||
usb_cdc_acm_get_line_coding(void);
|
|
||||||
|
|
||||||
void
|
void usb_cdc_acm_set_event_process(struct process *p);
|
||||||
usb_cdc_acm_set_event_process(struct process *p);
|
|
||||||
|
|
||||||
#endif /* __CDC_ACM_H__UFV6K50827__ */
|
#endif /* __CDC_ACM_H__UFV6K50827__ */
|
||||||
|
|
Loading…
Add table
Reference in a new issue