1
0
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:
Koen Zandberg 2019-02-01 14:29:51 +01:00
parent 74e0b5b85b
commit 537add6deb
No known key found for this signature in database
GPG Key ID: 0895A893E6D2985B
3 changed files with 91 additions and 0 deletions

View 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

View 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.

View 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;
}