2019-02-06 12:00:19 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 Koen Zandberg
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @ingroup sys_auto_init
|
|
|
|
* @{
|
|
|
|
* @file
|
|
|
|
* @brief initializes USBUS, usb devices and handlers
|
|
|
|
*
|
|
|
|
* This auto initialization for USBUS is designed to cover the common use case
|
2019-10-23 10:43:52 +02:00
|
|
|
* of a single USB peripheral. An USBUS instance is started with USB function
|
2019-02-06 12:00:19 +01:00
|
|
|
* handlers based on which module is compiled in.
|
|
|
|
*
|
2019-10-23 10:43:52 +02:00
|
|
|
* If this doesn't suit your use case, a different initialization function can
|
2019-02-06 12:00:19 +01:00
|
|
|
* to be created based on this initialization sequence.
|
|
|
|
*
|
|
|
|
* @author Koen Zandberg <koen@bergzand.net>
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2020-01-16 18:59:04 +01:00
|
|
|
#define USB_H_USER_IS_RIOT_INTERNAL
|
|
|
|
|
2020-10-21 15:58:33 +02:00
|
|
|
#include <assert.h>
|
|
|
|
|
2019-02-06 12:00:19 +01:00
|
|
|
#include "usb/usbus.h"
|
2023-03-10 08:19:30 +01:00
|
|
|
#include "usb/usbus/control.h"
|
2019-02-06 12:00:19 +01:00
|
|
|
|
2019-02-27 22:23:14 +01:00
|
|
|
#ifdef MODULE_USBUS_CDC_ECM
|
|
|
|
#include "usb/usbus/cdc/ecm.h"
|
|
|
|
usbus_cdcecm_device_t cdcecm;
|
|
|
|
#endif
|
2019-02-28 21:40:35 +01:00
|
|
|
#ifdef MODULE_USBUS_CDC_ACM
|
|
|
|
#include "usb/usbus/cdc/acm.h"
|
|
|
|
#endif
|
2020-12-15 17:13:11 +01:00
|
|
|
#ifdef MODULE_USBUS_DFU
|
|
|
|
#include "usb/usbus/dfu.h"
|
|
|
|
static usbus_dfu_device_t dfu;
|
|
|
|
#endif
|
2023-03-10 08:19:30 +01:00
|
|
|
#ifdef MODULE_USBUS_HID
|
|
|
|
#include "usb/usbus/hid.h"
|
|
|
|
#endif
|
2023-03-07 00:08:17 +01:00
|
|
|
#ifdef MODULE_USBUS_MSC
|
|
|
|
#include "usb/usbus/msc.h"
|
|
|
|
static usbus_msc_device_t msc;
|
|
|
|
#endif
|
2019-02-27 22:23:14 +01:00
|
|
|
|
2023-03-10 08:19:30 +01:00
|
|
|
#ifndef MODULE_USBUS_CDC_ACM
|
|
|
|
#define USBUS_CDC_ACM_EP_IN_REQUIRED_NUMOF 0
|
|
|
|
#define USBUS_CDC_ACM_EP_OUT_REQUIRED_NUMOF 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MODULE_USBUS_CDC_ECM
|
|
|
|
#define USBUS_CDC_ECM_EP_IN_REQUIRED_NUMOF 0
|
|
|
|
#define USBUS_CDC_ECM_EP_OUT_REQUIRED_NUMOF 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MODULE_USBUS_HID
|
|
|
|
#define USBUS_HID_EP_IN_REQUIRED_NUMOF 0
|
|
|
|
#define USBUS_HID_EP_OUT_REQUIRED_NUMOF 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MODULE_USBUS_MSC
|
|
|
|
#define USBUS_MSC_EP_IN_REQUIRED_NUMOF 0
|
|
|
|
#define USBUS_MSC_EP_OUT_REQUIRED_NUMOF 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define USBUS_EP_IN_REQUIRED_NUMOF (USBUS_CONTROL_EP_IN_REQUIRED_NUMOF + \
|
|
|
|
USBUS_CDC_ACM_EP_IN_REQUIRED_NUMOF + \
|
|
|
|
USBUS_CDC_ECM_EP_IN_REQUIRED_NUMOF + \
|
|
|
|
USBUS_HID_EP_IN_REQUIRED_NUMOF + \
|
|
|
|
USBUS_MSC_EP_IN_REQUIRED_NUMOF)
|
|
|
|
|
|
|
|
#define USBUS_EP_OUT_REQUIRED_NUMOF (USBUS_CONTROL_EP_OUT_REQUIRED_NUMOF + \
|
|
|
|
USBUS_CDC_ACM_EP_OUT_REQUIRED_NUMOF + \
|
|
|
|
USBUS_CDC_ECM_EP_OUT_REQUIRED_NUMOF + \
|
|
|
|
USBUS_HID_EP_OUT_REQUIRED_NUMOF + \
|
|
|
|
USBUS_MSC_EP_OUT_REQUIRED_NUMOF)
|
|
|
|
|
|
|
|
static_assert(USBUS_EP_IN_REQUIRED_NUMOF <= USBDEV_NUM_ENDPOINTS,
|
|
|
|
"Number of required IN endpoints exceeded");
|
|
|
|
|
|
|
|
static_assert(USBUS_EP_OUT_REQUIRED_NUMOF <= USBDEV_NUM_ENDPOINTS,
|
|
|
|
"Number of required OUT endpoints exceeded");
|
|
|
|
|
2019-02-06 12:00:19 +01:00
|
|
|
static char _stack[USBUS_STACKSIZE];
|
|
|
|
static usbus_t usbus;
|
|
|
|
|
|
|
|
void auto_init_usb(void)
|
|
|
|
{
|
|
|
|
/* Get driver context */
|
|
|
|
usbdev_t *usbdev = usbdev_get_ctx(0);
|
|
|
|
assert(usbdev);
|
|
|
|
|
|
|
|
/* Initialize basic usbus struct, don't start the thread yet */
|
|
|
|
usbus_init(&usbus, usbdev);
|
|
|
|
|
2019-02-27 22:23:14 +01:00
|
|
|
/* USBUS function handlers initialization */
|
2019-02-28 21:40:35 +01:00
|
|
|
#ifdef MODULE_STDIO_CDC_ACM
|
|
|
|
void usb_cdc_acm_stdio_init(usbus_t *usbus);
|
|
|
|
usb_cdc_acm_stdio_init(&usbus);
|
|
|
|
#endif
|
|
|
|
|
2019-02-27 22:23:14 +01:00
|
|
|
#ifdef MODULE_USBUS_CDC_ECM
|
|
|
|
usbus_cdcecm_init(&usbus, &cdcecm);
|
|
|
|
#endif
|
2019-02-06 12:00:19 +01:00
|
|
|
|
2020-12-15 17:13:11 +01:00
|
|
|
#ifdef MODULE_USBUS_DFU
|
|
|
|
usbus_dfu_init(&usbus, &dfu, USB_DFU_PROTOCOL_RUNTIME_MODE);
|
|
|
|
#endif
|
|
|
|
|
2023-03-07 00:08:17 +01:00
|
|
|
#ifdef MODULE_USBUS_MSC
|
|
|
|
/* Initialize Mass Storage Class */
|
|
|
|
usbus_msc_init(&usbus, &msc);
|
|
|
|
#endif
|
|
|
|
|
2019-02-06 12:00:19 +01:00
|
|
|
/* Finally initialize USBUS thread */
|
|
|
|
usbus_create(_stack, USBUS_STACKSIZE, USBUS_PRIO, USBUS_TNAME, &usbus);
|
|
|
|
}
|
2023-03-07 00:47:01 +01:00
|
|
|
|
|
|
|
usbus_t *usbus_auto_init_get(void)
|
|
|
|
{
|
|
|
|
return &usbus;
|
|
|
|
}
|