Commit ab5c1654 authored by Theodor-Adrian Stana's avatar Theodor-Adrian Stana

usb-debug: Cleaned up code of usbdcdc

parent a601d517
#include "usbdesc.h"
/* The serial port LINE CODING data structure, used to carry information */
/* about serial port baudrate, parity etc. between host and device. */
EFM32_PACK_START(1)
struct __attribute__ ((packed)) cdc_line_coding {
uint32_t dwDTERate; /** Baudrate */
uint8_t bCharFormat; /** Stop bits, 0=1 1=1.5 2=2 */
uint8_t bParityType; /** 0=None 1=Odd 2=Even 3=Mark 4=Space */
uint8_t bDataBits; /** 5, 6, 7, 8 or 16 */
uint8_t dummy; /** To ensure size is a multiple of 4 bytes.*/
};
EFM32_PACK_END()
/*** Variables ***/
/*
* The LineCoding variable must be 4-byte aligned as it is used as USB
* transmit and receive buffer
*/
EFM32_ALIGN(4)
EFM32_PACK_START(1)
static struct cdc_line_coding __attribute__ ((aligned(4))) line_coding =
{
4800, 2, 0, 8, 0
};
EFM32_PACK_END()
/**************************************************************************//**
* @brief
* Handle USB setup commands. Implements CDC class specific commands.
*
* @param[in] setup Pointer to the setup packet received.
*
* @return USB_STATUS_OK if command accepted.
* USB_STATUS_REQ_UNHANDLED when command is unknown, the USB device
* stack will handle the request.
*****************************************************************************/
int usbdesc_cb_setup(const USB_Setup_TypeDef *setup)
{
int r = USB_STATUS_REQ_UNHANDLED;
if ((setup->Type == USB_SETUP_TYPE_CLASS) &&
(setup->Recipient == USB_SETUP_RECIPIENT_INTERFACE)) {
switch (setup->bRequest)
{
case USB_CDC_GETLINECODING:
/********************/
if ((setup->wValue == 0) &&
(setup->wIndex == 0) &&
(setup->wLength == 7) &&
(setup->Direction == USB_SETUP_DIR_IN)) {
/* Send current settings to USB host. */
USBD_Write(0, (void*) &line_coding, 7, NULL);
r = USB_STATUS_OK;
}
break;
case USB_CDC_SETLINECODING:
/********************/
if ((setup->wValue == 0) &&
(setup->wIndex == 0) &&
(setup->wLength == 7) &&
(setup->Direction != USB_SETUP_DIR_IN)) {
/* Get new settings from USB host. */
USBD_Read(0, (void*) &line_coding, 7, NULL);
r = USB_STATUS_OK;
}
break;
case USB_CDC_SETCTRLLINESTATE:
/********************/
if ((setup->wIndex == 0) &&
(setup->wLength == 0)) {
/* Do nothing ( Non compliant behaviour !! ) */
r = USB_STATUS_OK;
}
break;
}
}
return r;
}
......@@ -17,9 +17,19 @@
extern "C" {
#endif
#include "em_usb.h"
/*=====================*/
/* Function prototypes */
/*=====================*/
int usbdesc_cb_setup(const USB_Setup_TypeDef *setup);
/*===============================*/
/* Define USB endpoint addresses */
#define USBDESC_EP_DATA_OUT 0x01 /* Endpoint for USB data reception. */
#define USBDESC_EP_DATA_IN 0x81 /* Endpoint for USB data transmission. */
/*===============================*/
#define USBDESC_EP_DATA_IN 0x01 /* Endpoint for USB data reception. */
#define USBDESC_EP_DATA_OUT 0x81 /* Endpoint for USB data transmission. */
#define USBDESC_EP_NOTIFY 0x82 /* The notification endpoint (not used). */
#define USBDESC_BULK_EP_SIZE USB_MAX_EP_SIZE /* This is the max. ep size. */
......@@ -136,7 +146,7 @@ static const uint8_t configDesc[] __attribute__ ((aligned(4)))=
/*** CDC Data interface endpoint descriptors ***/
USB_ENDPOINT_DESCSIZE, /* bLength */
USB_ENDPOINT_DESCRIPTOR,/* bDescriptorType */
USBDESC_EP_DATA_OUT, /* bEndpointAddress (IN) */
USBDESC_EP_DATA_IN, /* bEndpointAddress (IN) */
USB_EPTYPE_BULK, /* bmAttributes */
USBDESC_BULK_EP_SIZE, /* wMaxPacketSize (LSB) */
0, /* wMaxPacketSize (MSB) */
......@@ -144,7 +154,7 @@ static const uint8_t configDesc[] __attribute__ ((aligned(4)))=
USB_ENDPOINT_DESCSIZE, /* bLength */
USB_ENDPOINT_DESCRIPTOR,/* bDescriptorType */
USBDESC_EP_DATA_IN, /* bEndpointAddress (OUT)*/
USBDESC_EP_DATA_OUT, /* bEndpointAddress (OUT)*/
USB_EPTYPE_BULK, /* bmAttributes */
USBDESC_BULK_EP_SIZE, /* wMaxPacketSize (LSB) */
0, /* wMaxPacketSize (MSB) */
......@@ -176,7 +186,7 @@ static const USBD_Callbacks_TypeDef callbacks =
{
.usbReset = NULL,
.usbStateChange = NULL,
.setupCmd = SetupCmd,
.setupCmd = usbdesc_cb_setup,
.isSelfPowered = NULL,
.sofInt = NULL
};
......
......@@ -101,7 +101,7 @@ override CFLAGS += -D$(DEVICE) -Wall -Wextra -mcpu=cortex-m3 -mthumb \
-fdata-sections -fomit-frame-pointer -DDEBUG_EFM_USER \
$(DEPFLAGS)
override ASMFLAGS += -x assembler-with-cpp -D$(DEVICE) -Wall -Wextra -mcpu=cortex-m3 -mthumb -DDEBUG_EFM_USER
override ASMFLAGS += -x assembler-with-cpp -D$(DEVICE) -Wall -Wextra -mcpu=cortex-m3 -mthumb -DDEBUG_EFM_USER
#
# NOTE: The -Wl,--gc-sections flag may interfere with debugging using gdb.
......@@ -119,7 +119,7 @@ INCLUDEPATHS += \
-I../../common/Device/EnergyMicro/EFM32GG/Include \
-I../../common/emlib/inc \
-I../../common/usb \
-I../usb/inc \
-I../../common/usb/inc \
-I../kits/common/drivers \
-I../kits/common/bsp \
-I../kits/EFM32GG_DK3750/config
......@@ -140,16 +140,17 @@ C_SRC += \
../../common/emlib/src/em_system.c \
../../common/emlib/src/em_timer.c \
../../common/emlib/src/em_leuart.c \
../usb/src/em_usbd.c \
../usb/src/em_usbdch9.c \
../usb/src/em_usbhal.c \
../usb/src/em_usbdep.c \
../usb/src/em_usbdint.c \
../usb/src/em_usbtimer.c \
../../common/usb/src/em_usbd.c \
../../common/usb/src/em_usbdch9.c \
../../common/usb/src/em_usbhal.c \
../../common/usb/src/em_usbdep.c \
../../common/usb/src/em_usbdint.c \
../../common/usb/src/em_usbtimer.c \
../kits/common/drivers/dmactrl.c \
../../common/usb/usbdesc.c \
../src/main.c
s_SRC +=
s_SRC +=
S_SRC += \
../../common/Device/EnergyMicro/EFM32GG/Source/GCC/startup_efm32gg.S
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment