mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
USBUS: add minimal working example
This commit is contained in:
parent
74e0b5b85b
commit
537add6deb
31
examples/usbus_minimal/Makefile
Normal file
31
examples/usbus_minimal/Makefile
Normal file
@ -0,0 +1,31 @@
|
||||
# name of your application
|
||||
APPLICATION = usbus_minimal
|
||||
|
||||
# If no BOARD is found in the environment, use this default:
|
||||
BOARD ?= samr21-xpro
|
||||
|
||||
# This has to be the absolute path to the RIOT base directory:
|
||||
RIOTBASE ?= $(CURDIR)/../..
|
||||
|
||||
# Comment this out to disable code in RIOT that does safety checking
|
||||
# which is not needed in a production environment but helps in the
|
||||
# development process:
|
||||
DEVELHELP ?= 1
|
||||
|
||||
USEMODULE += usbus
|
||||
|
||||
# USB device vendor and product ID
|
||||
USB_VID ?= 1209
|
||||
USB_PID ?= 0001
|
||||
|
||||
# Change this to 0 show compiler invocation lines by default:
|
||||
QUIET ?= 1
|
||||
|
||||
CFLAGS += -DUSB_CONFIG_VID=0x$(USB_VID) -DUSB_CONFIG_PID=0x$(USB_PID)
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
|
||||
ifeq ($(USB_VID):$(USB_PID), 1209:0001)
|
||||
$(shell $(COLOR_ECHO) "$(COLOR_RED)Private testing pid.codes USB VID/PID used!, do not use it outside of test environments!$(COLOR_RESET)" 1>&2)
|
||||
$(shell $(COLOR_ECHO) "$(COLOR_RED)MUST NOT be used on any device redistributed, sold or manufactured, VID/PID is not unique!$(COLOR_RESET)" 1>&2)
|
||||
endif
|
16
examples/usbus_minimal/README.md
Normal file
16
examples/usbus_minimal/README.md
Normal file
@ -0,0 +1,16 @@
|
||||
# usbus_minimal example
|
||||
|
||||
This is a minimalistic example for RIOT's USB stack. The application will
|
||||
initialize and start the USB stack. The stack is started without any USB
|
||||
handlers, it should show up as an empty USB device on the host.
|
||||
|
||||
RIOT doesn't own any USB vendor and product ID. To compile this example, add
|
||||
your own vendor and product ID to the makefile:
|
||||
|
||||
```
|
||||
CFLAGS += -DUSB_CONFIG_VID=0xYOURVID -DUSB_CONFIG_PID=0xYOURPID
|
||||
```
|
||||
|
||||
The example demonstrates basic USB communication between a host and a RIOT
|
||||
based USB peripheral. Tools such as `lsusb` should display the device and
|
||||
detailed information about the device such as descriptor strings.
|
44
examples/usbus_minimal/main.c
Normal file
44
examples/usbus_minimal/main.c
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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 examples
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Example application for demonstrating the RIOT USB stack
|
||||
*
|
||||
* @author Koen Zandberg <koen@bergzand.net>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "usb/usbus.h"
|
||||
|
||||
static char _stack[USBUS_STACKSIZE];
|
||||
|
||||
static usbus_t usbus;
|
||||
/* TODO: remove as soon as we have decent auto_init */
|
||||
#include "periph_conf.h"
|
||||
#include "sam_usb.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
puts("RIOT USB stack example application");
|
||||
|
||||
/* TODO: remove as soon as we have decent auto_init */
|
||||
usbdev_t *usbdev_ctx = usbdev_get_ctx(0);
|
||||
/* start usb stack */
|
||||
usbus_init(&usbus, usbdev_ctx);
|
||||
usbus_create(_stack, sizeof(_stack), USBUS_PRIO, USBUS_TNAME, &usbus);
|
||||
|
||||
/* start shell */
|
||||
puts("Started USB stack!");
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user