Browse Source

common: Moved the USB initialisation code into usb.c

pull/443/merge
dragonmux 2 years ago
committed by Piotr Esden-Tempski
parent
commit
259077a87d
  1. 28
      src/platforms/common/cdcacm.c
  2. 1
      src/platforms/common/cdcacm.h
  3. 24
      src/platforms/common/usb.c
  4. 10
      src/platforms/common/usb.h
  5. 11
      src/platforms/common/usb_descriptors.h

28
src/platforms/common/cdcacm.c

@ -45,24 +45,16 @@
# include "traceswo.h"
#endif
#include "usbuart.h"
#include "serialno.h"
#include "version.h"
#include <libopencm3/cm3/nvic.h>
#include <libopencm3/usb/cdc.h>
#include <libopencm3/cm3/scb.h>
#include "usb_descriptors.h"
usbd_device * usbdev;
#include <libopencm3/usb/dfu.h>
static int configured;
static int cdcacm_gdb_dtr = 1;
static void cdcacm_set_modem_state(usbd_device *dev, int iface, bool dsr, bool dcd);
char serial_no[DFU_SERIAL_LENGTH];
static void dfu_detach_complete(usbd_device *dev, struct usb_setup_data *req)
{
(void)dev;
@ -165,7 +157,7 @@ static void cdcacm_set_modem_state(usbd_device *dev, int iface, bool dsr, bool d
usbd_ep_write_packet(dev, 0x82 + iface, buf, 10);
}
static void cdcacm_set_config(usbd_device *dev, uint16_t wValue)
void cdcacm_set_config(usbd_device *dev, uint16_t wValue)
{
configured = wValue;
@ -208,19 +200,3 @@ static void cdcacm_set_config(usbd_device *dev, uint16_t wValue)
cdcacm_set_modem_state(dev, GDB_IF_NO, true, true);
cdcacm_set_modem_state(dev, UART_IF_NO, true, true);
}
/* We need a special large control buffer for this device: */
static uint8_t usbd_control_buffer[256];
void blackmagic_usb_init(void)
{
serial_no_read(serial_no);
usbdev = usbd_init(&USB_DRIVER, &dev_desc, &config, usb_strings, sizeof(usb_strings) / sizeof(char *),
usbd_control_buffer, sizeof(usbd_control_buffer));
usbd_register_set_config_callback(usbdev, cdcacm_set_config);
nvic_set_priority(USB_IRQ, IRQ_PRI_USB);
nvic_enable_irq(USB_IRQ);
}

1
src/platforms/common/cdcacm.h

@ -31,6 +31,7 @@
#include "usb.h"
void blackmagic_usb_init(void);
void cdcacm_set_config(usbd_device *dev, uint16_t wValue);
/* Returns current usb configuration, or 0 if not configured. */
int cdcacm_get_config(void);
int cdcacm_get_dtr(void);

24
src/platforms/common/usb.c

@ -18,8 +18,32 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <libopencm3/cm3/nvic.h>
#include "general.h"
#include "usb.h"
#include "usb_descriptors.h"
#include "cdcacm.h"
#include "serialno.h"
char serial_no[DFU_SERIAL_LENGTH];
usbd_device *usbdev = NULL;
/* We need a special large control buffer for this device: */
static uint8_t usbd_control_buffer[256];
void blackmagic_usb_init(void)
{
serial_no_read(serial_no);
usbdev = usbd_init(&USB_DRIVER, &dev_desc, &config, usb_strings, sizeof(usb_strings) / sizeof(char *),
usbd_control_buffer, sizeof(usbd_control_buffer));
usbd_register_set_config_callback(usbdev, cdcacm_set_config);
nvic_set_priority(USB_IRQ, IRQ_PRI_USB);
nvic_enable_irq(USB_IRQ);
}
void USB_ISR(void)
{

10
src/platforms/common/usb.h

@ -31,4 +31,14 @@ extern usbd_device *usbdev;
#define CDCACM_UART_ENDPOINT 3
#define TRACE_ENDPOINT 5
#define GDB_IF_NO 0
#define UART_IF_NO 2
#define DFU_IF_NO 4
#ifdef PLATFORM_HAS_TRACESWO
#define TRACE_IF_NO 5
#define TOTAL_INTERFACES 6
#else
#define TOTAL_INTERFACES 5
#endif
#endif /*USB_H*/

11
src/platforms/common/usb_descriptors.h

@ -26,19 +26,10 @@
#include <libopencm3/usb/dfu.h>
#include "usb.h"
#include "version.h"
#define BOARD_IDENT "Black Magic Probe " PLATFORM_IDENT FIRMWARE_VERSION
#define GDB_IF_NO 0
#define UART_IF_NO 2
#define DFU_IF_NO 4
#ifdef PLATFORM_HAS_TRACESWO
#define TRACE_IF_NO 5
#define TOTAL_INTERFACES 6
#else
#define TOTAL_INTERFACES 5
#endif
extern char serial_no[DFU_SERIAL_LENGTH];
/* Top-level device descriptor */

Loading…
Cancel
Save