cc2531: USB changes:
- usb cdc-acm: * implement get line coding * use printf only when debugging * Add events - usb-core: do not force debugging See Pull Request #18
This commit is contained in:
parent
c1d72475d7
commit
0a6e65acdf
3 changed files with 82 additions and 15 deletions
|
@ -5,18 +5,39 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef DEBUG
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define PRINTF(...)
|
||||
#endif
|
||||
|
||||
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 uint8_t line_state;
|
||||
static uint8_t events;
|
||||
static struct process * cdc_event_process = NULL;
|
||||
|
||||
static void
|
||||
notify_user(uint8_t e)
|
||||
{
|
||||
events |= e;
|
||||
if(cdc_event_process) {
|
||||
process_poll(cdc_event_process);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
encapsulated_command(uint8_t *data, unsigned int length)
|
||||
{
|
||||
printf("Got CDC command: length %d\n", 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) {
|
||||
#ifdef DEBUG
|
||||
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 =
|
||||
|
@ -25,8 +46,11 @@ set_line_encoding(uint8_t *data, unsigned int length)
|
|||
? '?' : 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",
|
||||
PRINTF("Got CDC line coding: %ld/%d/%c/%s\n",
|
||||
coding->dwDTERate, coding->bDataBits, parity, stop_bits);
|
||||
#endif
|
||||
memcpy(&usb_line_coding, data, sizeof(usb_line_coding));
|
||||
notify_user(USB_CDC_ACM_LINE_CODING);
|
||||
usb_send_ctrl_status();
|
||||
} else {
|
||||
usb_error_stall();
|
||||
|
@ -36,23 +60,15 @@ set_line_encoding(uint8_t *data, unsigned int length)
|
|||
static unsigned int
|
||||
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, 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");
|
||||
}
|
||||
line_state = usb_setup_buffer.wValue;
|
||||
notify_user(USB_CDC_ACM_LINE_STATE);
|
||||
usb_send_ctrl_status();
|
||||
return 1;
|
||||
|
||||
|
@ -83,9 +99,12 @@ handle_cdc_acm_requests()
|
|||
if (usb_setup_buffer.wIndex != 0) return 0;
|
||||
switch(usb_setup_buffer.bRequest) {
|
||||
case GET_ENCAPSULATED_RESPONSE:
|
||||
printf("CDC response");
|
||||
PRINTF("CDC response");
|
||||
usb_send_ctrl_status();
|
||||
return 1;
|
||||
case GET_LINE_CODING:
|
||||
usb_send_ctrl_response((uint8_t *) &usb_line_coding, 7);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
@ -109,3 +128,30 @@ usb_cdc_acm_setup()
|
|||
{
|
||||
usb_register_request_handler(&cdc_acm_request_hook);
|
||||
}
|
||||
|
||||
uint8_t
|
||||
usb_cdc_acm_get_events(void)
|
||||
{
|
||||
uint8_t r = events;
|
||||
events = 0;
|
||||
return r;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
usb_cdc_acm_get_line_state(void)
|
||||
{
|
||||
return line_state;
|
||||
}
|
||||
|
||||
const struct usb_cdc_line_coding *
|
||||
usb_cdc_acm_get_line_coding(void)
|
||||
{
|
||||
return &usb_line_coding;
|
||||
}
|
||||
|
||||
void
|
||||
usb_cdc_acm_set_event_process(struct process *p)
|
||||
{
|
||||
cdc_event_process = p;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,29 @@
|
|||
#ifndef __CDC_ACM_H__UFV6K50827__
|
||||
#define __CDC_ACM_H__UFV6K50827__
|
||||
|
||||
#include "cdc.h"
|
||||
#include "contiki.h"
|
||||
|
||||
void
|
||||
usb_cdc_acm_setup();
|
||||
|
||||
|
||||
#define USB_CDC_ACM_LINE_CODING 0x1
|
||||
#define USB_CDC_ACM_LINE_STATE 0x2
|
||||
uint8_t
|
||||
usb_cdc_acm_get_events(void);
|
||||
|
||||
|
||||
#define USB_CDC_ACM_DTE 0x1
|
||||
#define USB_CDC_ACM_RTS 0x2
|
||||
uint8_t
|
||||
usb_cdc_acm_get_line_state(void);
|
||||
|
||||
|
||||
const struct usb_cdc_line_coding *
|
||||
usb_cdc_acm_get_line_coding(void);
|
||||
|
||||
void
|
||||
usb_cdc_acm_set_event_process(struct process *p);
|
||||
|
||||
#endif /* __CDC_ACM_H__UFV6K50827__ */
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
#define DEBUG
|
||||
#ifdef DEBUG
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
|
|
Loading…
Reference in a new issue