Commit 98faf2d7 authored by Theodor-Adrian Stana's avatar Theodor-Adrian Stana

usb-debug: Made easier to use

parent d945b39c
#include "usbdesc.h"
#include <stdio.h>
#include <string.h>
#include "usbdbg.h"
#include "em_usb.h"
/* The serial port LINE CODING data structure, used to carry information */
/* about serial port baudrate, parity etc. between host and device. */
......@@ -36,7 +39,7 @@ EFM32_PACK_END()
* 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 usbdbg_cb_setup(const USB_Setup_TypeDef *setup)
{
int r = USB_STATUS_REQ_UNHANDLED;
......@@ -82,3 +85,50 @@ int usbdesc_cb_setup(const USB_Setup_TypeDef *setup)
return r;
}
/**************************************************************************//**
* @brief
* Wrapper for USB device stack init.
*
* @param[in] none
*
* @return none
*****************************************************************************/
void usbdbg_init()
{
USBD_Init(&initstruct);
}
/**************************************************************************//**
* @brief
* USB puts() function. Prints up to USBDBG_BULK_EP_SIZE-1 characters on
* USB, or throws EOF if more than USBDBG_BULK_EP_SIZE-1 characters are
* attempted to be transmitted, or the EOF character itself is received.
*
* @param[in] s String to put on USB
*
* @return 1 on success
* -1 (EOF) otherwise
*****************************************************************************/
int usbdbg_puts(const char *s)
{
char buf[USBDBG_BULK_EP_SIZE];
int cnt = 0;
/* Fill buffer */
while (*s) {
if ((*s == EOF) || (cnt == USBDBG_BULK_EP_SIZE-1))
return EOF;
buf[cnt++] = *s;
s++;
}
/* Null-terminate and roll back pointer */
buf[cnt] = '\0';
/* Call USB stack function we're so desperately trying to hide */
USBD_Write(USBDBG_EP_DATA_OUT, (void *)buf, strlen(buf), NULL);
return 1;
}
......@@ -22,17 +22,19 @@ extern "C" {
/*=====================*/
/* Function prototypes */
/*=====================*/
int usbdesc_cb_setup(const USB_Setup_TypeDef *setup);
void usbdbg_init();
int usbdbg_puts(const char *s);
int usbdbg_cb_setup(const USB_Setup_TypeDef *setup);
/*===============================*/
/* Define USB endpoint addresses */
/*===============================*/
#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 USBDBG_EP_DATA_IN 0x01 /* Endpoint for USB data reception. */
#define USBDBG_EP_DATA_OUT 0x81 /* Endpoint for USB data transmission. */
#define USBDBG_EP_NOTIFY 0x82 /* The notification endpoint (not used). */
#define USBDESC_BULK_EP_SIZE USB_MAX_EP_SIZE /* This is the max. ep size. */
#define USBDBG_BULK_EP_SIZE USB_MAX_EP_SIZE /* This is the max. ep size. */
EFM32_ALIGN(4)
static const USB_DeviceDescriptor_TypeDef deviceDesc __attribute__ ((aligned(4)))=
......@@ -126,9 +128,9 @@ static const uint8_t configDesc[] __attribute__ ((aligned(4)))=
/*** CDC Notification endpoint descriptor ***/
USB_ENDPOINT_DESCSIZE, /* bLength */
USB_ENDPOINT_DESCRIPTOR,/* bDescriptorType */
USBDESC_EP_NOTIFY, /* bEndpointAddress (IN) */
USBDBG_EP_NOTIFY, /* bEndpointAddress (IN) */
USB_EPTYPE_INTR, /* bmAttributes */
USBDESC_BULK_EP_SIZE, /* wMaxPacketSize (LSB) */
USBDBG_BULK_EP_SIZE, /* wMaxPacketSize (LSB) */
0, /* wMaxPacketSize (MSB) */
0xFF, /* bInterval */
......@@ -146,17 +148,17 @@ static const uint8_t configDesc[] __attribute__ ((aligned(4)))=
/*** CDC Data interface endpoint descriptors ***/
USB_ENDPOINT_DESCSIZE, /* bLength */
USB_ENDPOINT_DESCRIPTOR,/* bDescriptorType */
USBDESC_EP_DATA_IN, /* bEndpointAddress (IN) */
USBDBG_EP_DATA_IN, /* bEndpointAddress (IN) */
USB_EPTYPE_BULK, /* bmAttributes */
USBDESC_BULK_EP_SIZE, /* wMaxPacketSize (LSB) */
USBDBG_BULK_EP_SIZE, /* wMaxPacketSize (LSB) */
0, /* wMaxPacketSize (MSB) */
0, /* bInterval */
USB_ENDPOINT_DESCSIZE, /* bLength */
USB_ENDPOINT_DESCRIPTOR,/* bDescriptorType */
USBDESC_EP_DATA_OUT, /* bEndpointAddress (OUT)*/
USBDBG_EP_DATA_OUT, /* bEndpointAddress (OUT)*/
USB_EPTYPE_BULK, /* bmAttributes */
USBDESC_BULK_EP_SIZE, /* wMaxPacketSize (LSB) */
USBDBG_BULK_EP_SIZE, /* wMaxPacketSize (LSB) */
0, /* wMaxPacketSize (MSB) */
0 /* bInterval */
};
......@@ -186,7 +188,7 @@ static const USBD_Callbacks_TypeDef callbacks =
{
.usbReset = NULL,
.usbStateChange = NULL,
.setupCmd = usbdesc_cb_setup,
.setupCmd = usbdbg_cb_setup,
.isSelfPowered = NULL,
.sofInt = NULL
};
......
......@@ -147,7 +147,7 @@ C_SRC += \
../../common/usb/src/em_usbdint.c \
../../common/usb/src/em_usbtimer.c \
../kits/common/drivers/dmactrl.c \
../../common/usb/usbdesc.c \
../../common/usb/usbdbg.c \
../src/main.c
s_SRC +=
......
......@@ -27,7 +27,7 @@
#include "bsp.h"
#include "bsp_trace.h"
#include "usbdesc.h"
#include "usbdbg.h"
/**************************************************************************//**
*
......@@ -82,7 +82,7 @@ int main(void)
GPIO_PinModeSet(gpioPortE, 11, gpioModePushPull, 0);;
GPIO_PinModeSet(gpioPortE, 12, gpioModePushPull, 1);;
USBD_Init(&initstruct);
usbdbg_init();
/*
* When using a debugger it is practical to uncomment the following three
......@@ -98,7 +98,7 @@ int main(void)
{
GPIO_PinOutToggle(gpioPortE, 11);
GPIO_PinOutToggle(gpioPortE, 12);
USBD_Write(USBDESC_EP_DATA_OUT, (void *)tmp, strlen(tmp), NULL);
usbdbg_puts(tmp);
delay(1000);
}
}
......
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