From ef688275595404329216aee9873ea63e9486a536 Mon Sep 17 00:00:00 2001 From: Koen Zandberg Date: Wed, 6 Feb 2019 12:00:19 +0100 Subject: [PATCH] auto_init_usb: initial implementation --- sys/auto_init/Makefile | 4 +++ sys/auto_init/auto_init.c | 6 +++++ sys/auto_init/usb/Makefile | 3 +++ sys/auto_init/usb/auto_init_usb.c | 42 +++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 sys/auto_init/usb/Makefile create mode 100644 sys/auto_init/usb/auto_init_usb.c diff --git a/sys/auto_init/Makefile b/sys/auto_init/Makefile index 7b76278ee8..e14091c42d 100644 --- a/sys/auto_init/Makefile +++ b/sys/auto_init/Makefile @@ -18,4 +18,8 @@ ifneq (,$(filter auto_init_loramac,$(USEMODULE))) DIRS += loramac endif +ifneq (,$(filter auto_init_usbus,$(USEMODULE))) + DIRS += usb +endif + include $(RIOTBASE)/Makefile.base diff --git a/sys/auto_init/auto_init.c b/sys/auto_init/auto_init.c index 2ae86cb552..30a2106e7c 100644 --- a/sys/auto_init/auto_init.c +++ b/sys/auto_init/auto_init.c @@ -182,6 +182,12 @@ void auto_init(void) auto_init_loramac(); #endif +/* initialize USB devices */ +#ifdef MODULE_AUTO_INIT_USBUS + extern void auto_init_usb(void); + auto_init_usb(); +#endif + /* initialize network devices */ #ifdef MODULE_AUTO_INIT_GNRC_NETIF diff --git a/sys/auto_init/usb/Makefile b/sys/auto_init/usb/Makefile new file mode 100644 index 0000000000..783b427d05 --- /dev/null +++ b/sys/auto_init/usb/Makefile @@ -0,0 +1,3 @@ +MODULE = auto_init_usbus + +include $(RIOTBASE)/Makefile.base diff --git a/sys/auto_init/usb/auto_init_usb.c b/sys/auto_init/usb/auto_init_usb.c new file mode 100644 index 0000000000..5eb5d1edad --- /dev/null +++ b/sys/auto_init/usb/auto_init_usb.c @@ -0,0 +1,42 @@ +/* + * 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 + * of a single usb peripheral. An USBUS instance is started with USB function + * handlers based on which module is compiled in. + * + * If this doesn't suit your use case, a different intialization function can + * to be created based on this initialization sequence. + * + * @author Koen Zandberg + * @} + */ + +#include "usb/usbus.h" + +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); + + + /* Finally initialize USBUS thread */ + usbus_create(_stack, USBUS_STACKSIZE, USBUS_PRIO, USBUS_TNAME, &usbus); +}