2016-09-06 21:59:12 +02:00
/*
2013-07-28 10:34:41 +02:00
* Copyright 2012 , 2013 Jun Wako < wakojun @ gmail . com >
2012-06-29 09:48:36 +02:00
* This file is based on :
* LUFA - 120219 / Demos / Device / Lowlevel / KeyboardMouse
* LUFA - 120219 / Demos / Device / Lowlevel / GenericHID
*/
2012-06-28 05:59:17 +02:00
/*
2019-07-09 21:34:17 +02:00
LUFA Library
Copyright ( C ) Dean Camera , 2012.
2012-06-28 05:59:17 +02:00
2019-07-09 21:34:17 +02:00
dean [ at ] fourwalledcubicle [ dot ] com
www . lufa - lib . org
2012-06-28 05:59:17 +02:00
*/
/*
2019-07-09 21:34:17 +02:00
Copyright 2012 Dean Camera ( dean [ at ] fourwalledcubicle [ dot ] com )
Copyright 2010 Denver Gingerich ( denver [ at ] ossguy [ dot ] com )
Permission to use , copy , modify , distribute , and sell this
software and its documentation for any purpose is hereby granted
without fee , provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation , and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific , written prior permission .
The author disclaim all warranties with regard to this
software , including all implied warranties of merchantability
and fitness . In no event shall the author be liable for any
special , indirect or consequential damages or any damages
whatsoever resulting from loss of use , data or profits , whether
in an action of contract , negligence or other tortious action ,
arising out of or in connection with the use or performance of
this software .
2012-06-28 05:59:17 +02:00
*/
/** \file
*
* Header file for Descriptors . c .
*/
# ifndef _DESCRIPTORS_H_
2019-08-30 20:19:03 +02:00
# define _DESCRIPTORS_H_
2012-06-28 05:59:17 +02:00
2019-08-30 20:19:03 +02:00
# include <LUFA/Drivers/USB/USB.h>
2012-06-28 05:59:17 +02:00
2019-08-30 20:19:03 +02:00
# ifdef PROTOCOL_CHIBIOS
# include "hal.h"
# endif
2019-07-09 21:34:17 +02:00
/*
* USB descriptor structure
*/
typedef struct {
2019-08-30 20:19:03 +02:00
USB_Descriptor_Configuration_Header_t Config ;
2012-06-28 05:59:17 +02:00
2019-08-30 20:19:03 +02:00
# ifndef KEYBOARD_SHARED_EP
2012-06-28 05:59:17 +02:00
// Keyboard HID Interface
2019-08-30 20:19:03 +02:00
USB_Descriptor_Interface_t Keyboard_Interface ;
USB_HID_Descriptor_HID_t Keyboard_HID ;
USB_Descriptor_Endpoint_t Keyboard_INEndpoint ;
# endif
2012-06-28 05:59:17 +02:00
2019-10-08 20:47:37 +02:00
# ifdef RAW_ENABLE
// Raw HID Interface
USB_Descriptor_Interface_t Raw_Interface ;
USB_HID_Descriptor_HID_t Raw_HID ;
USB_Descriptor_Endpoint_t Raw_INEndpoint ;
USB_Descriptor_Endpoint_t Raw_OUTEndpoint ;
# endif
2019-08-30 20:19:03 +02:00
# if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
2012-07-13 19:47:29 +02:00
// Mouse HID Interface
2019-08-30 20:19:03 +02:00
USB_Descriptor_Interface_t Mouse_Interface ;
USB_HID_Descriptor_HID_t Mouse_HID ;
USB_Descriptor_Endpoint_t Mouse_INEndpoint ;
# endif
2019-07-09 21:34:17 +02:00
2019-08-30 20:19:03 +02:00
# ifdef SHARED_EP_ENABLE
2019-07-09 21:34:17 +02:00
// Shared Interface
2019-08-30 20:19:03 +02:00
USB_Descriptor_Interface_t Shared_Interface ;
USB_HID_Descriptor_HID_t Shared_HID ;
USB_Descriptor_Endpoint_t Shared_INEndpoint ;
# endif
2019-07-09 21:34:17 +02:00
2019-08-30 20:19:03 +02:00
# ifdef CONSOLE_ENABLE
2012-06-28 09:51:56 +02:00
// Console HID Interface
2019-08-30 20:19:03 +02:00
USB_Descriptor_Interface_t Console_Interface ;
USB_HID_Descriptor_HID_t Console_HID ;
USB_Descriptor_Endpoint_t Console_INEndpoint ;
USB_Descriptor_Endpoint_t Console_OUTEndpoint ;
# endif
# ifdef MIDI_ENABLE
USB_Descriptor_Interface_Association_t Audio_Interface_Association ;
2018-02-08 21:07:46 +01:00
// MIDI Audio Control Interface
2019-08-30 20:19:03 +02:00
USB_Descriptor_Interface_t Audio_ControlInterface ;
USB_Audio_Descriptor_Interface_AC_t Audio_ControlInterface_SPC ;
2018-02-08 21:07:46 +01:00
// MIDI Audio Streaming Interface
USB_Descriptor_Interface_t Audio_StreamInterface ;
USB_MIDI_Descriptor_AudioInterface_AS_t Audio_StreamInterface_SPC ;
USB_MIDI_Descriptor_InputJack_t MIDI_In_Jack_Emb ;
USB_MIDI_Descriptor_InputJack_t MIDI_In_Jack_Ext ;
USB_MIDI_Descriptor_OutputJack_t MIDI_Out_Jack_Emb ;
USB_MIDI_Descriptor_OutputJack_t MIDI_Out_Jack_Ext ;
USB_Audio_Descriptor_StreamEndpoint_Std_t MIDI_In_Jack_Endpoint ;
USB_MIDI_Descriptor_Jack_Endpoint_t MIDI_In_Jack_Endpoint_SPC ;
USB_Audio_Descriptor_StreamEndpoint_Std_t MIDI_Out_Jack_Endpoint ;
USB_MIDI_Descriptor_Jack_Endpoint_t MIDI_Out_Jack_Endpoint_SPC ;
2019-08-30 20:19:03 +02:00
# endif
2019-07-09 21:34:17 +02:00
2019-08-30 20:19:03 +02:00
# ifdef VIRTSER_ENABLE
USB_Descriptor_Interface_Association_t CDC_Interface_Association ;
2019-07-09 21:34:17 +02:00
// CDC Control Interface
2019-08-30 20:19:03 +02:00
USB_Descriptor_Interface_t CDC_CCI_Interface ;
USB_CDC_Descriptor_FunctionalHeader_t CDC_Functional_Header ;
USB_CDC_Descriptor_FunctionalACM_t CDC_Functional_ACM ;
USB_CDC_Descriptor_FunctionalUnion_t CDC_Functional_Union ;
USB_Descriptor_Endpoint_t CDC_NotificationEndpoint ;
2019-07-09 21:34:17 +02:00
// CDC Data Interface
2019-08-30 20:19:03 +02:00
USB_Descriptor_Interface_t CDC_DCI_Interface ;
USB_Descriptor_Endpoint_t CDC_DataOutEndpoint ;
USB_Descriptor_Endpoint_t CDC_DataInEndpoint ;
# endif
2012-06-28 05:59:17 +02:00
} USB_Descriptor_Configuration_t ;
2019-07-09 21:34:17 +02:00
/*
* Interface indexes
*/
2018-11-16 07:22:05 +01:00
enum usb_interfaces {
2019-08-30 20:19:03 +02:00
# ifndef KEYBOARD_SHARED_EP
2018-11-16 07:22:05 +01:00
KEYBOARD_INTERFACE ,
2019-08-30 20:19:03 +02:00
# else
# define KEYBOARD_INTERFACE SHARED_INTERFACE
# endif
// It is important that the Raw HID interface is at a constant
// interface number, to support Linux/OSX platforms and chrome.hid
// If Raw HID is enabled, let it be always 1.
# ifdef RAW_ENABLE
2018-11-16 07:22:05 +01:00
RAW_INTERFACE ,
2019-08-30 20:19:03 +02:00
# endif
2019-07-09 21:34:17 +02:00
2019-08-30 20:19:03 +02:00
# if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
2018-11-16 07:22:05 +01:00
MOUSE_INTERFACE ,
2019-08-30 20:19:03 +02:00
# endif
2019-07-09 21:34:17 +02:00
2019-08-30 20:19:03 +02:00
# ifdef SHARED_EP_ENABLE
2018-11-16 07:22:05 +01:00
SHARED_INTERFACE ,
2019-08-30 20:19:03 +02:00
# endif
2019-07-09 21:34:17 +02:00
2019-08-30 20:19:03 +02:00
# ifdef CONSOLE_ENABLE
2018-11-16 07:22:05 +01:00
CONSOLE_INTERFACE ,
2019-08-30 20:19:03 +02:00
# endif
2019-07-09 21:34:17 +02:00
2019-08-30 20:19:03 +02:00
# ifdef MIDI_ENABLE
2018-11-16 07:22:05 +01:00
AC_INTERFACE ,
AS_INTERFACE ,
2019-08-30 20:19:03 +02:00
# endif
2019-07-09 21:34:17 +02:00
2019-08-30 20:19:03 +02:00
# ifdef VIRTSER_ENABLE
2018-11-16 07:22:05 +01:00
CCI_INTERFACE ,
CDI_INTERFACE ,
2019-08-30 20:19:03 +02:00
# endif
2019-07-09 21:34:17 +02:00
2018-11-16 07:22:05 +01:00
TOTAL_INTERFACES
} ;
2016-08-01 07:02:52 +02:00
2019-08-30 20:19:03 +02:00
# define NEXT_EPNUM __COUNTER__
2012-06-28 05:59:17 +02:00
2019-07-09 21:34:17 +02:00
/*
* Endpoint numbers
*/
2018-11-16 07:22:05 +01:00
enum usb_endpoints {
2019-08-30 20:19:03 +02:00
__unused_epnum__ = NEXT_EPNUM , // Endpoint numbering starts at 1
2019-07-09 21:34:17 +02:00
2019-08-30 20:19:03 +02:00
# ifndef KEYBOARD_SHARED_EP
2018-11-16 07:22:05 +01:00
KEYBOARD_IN_EPNUM = NEXT_EPNUM ,
2019-08-30 20:19:03 +02:00
# else
# define KEYBOARD_IN_EPNUM SHARED_IN_EPNUM
# endif
2019-07-09 21:34:17 +02:00
2019-08-30 20:19:03 +02:00
# if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
2018-11-16 07:22:05 +01:00
MOUSE_IN_EPNUM = NEXT_EPNUM ,
2019-08-30 20:19:03 +02:00
# else
# define MOUSE_IN_EPNUM SHARED_IN_EPNUM
# endif
2019-07-09 21:34:17 +02:00
2019-08-30 20:19:03 +02:00
# ifdef RAW_ENABLE
RAW_IN_EPNUM = NEXT_EPNUM ,
2018-11-16 07:22:05 +01:00
RAW_OUT_EPNUM = NEXT_EPNUM ,
2019-08-30 20:19:03 +02:00
# endif
2019-07-09 21:34:17 +02:00
2019-08-30 20:19:03 +02:00
# ifdef SHARED_EP_ENABLE
2018-11-16 07:22:05 +01:00
SHARED_IN_EPNUM = NEXT_EPNUM ,
2019-08-30 20:19:03 +02:00
# endif
2019-07-09 21:34:17 +02:00
2019-08-30 20:19:03 +02:00
# ifdef CONSOLE_ENABLE
2018-11-16 07:22:05 +01:00
CONSOLE_IN_EPNUM = NEXT_EPNUM ,
2019-07-09 21:34:17 +02:00
2019-08-30 20:19:03 +02:00
# ifdef PROTOCOL_CHIBIOS
2019-07-09 21:34:17 +02:00
// ChibiOS has enough memory and descriptor to actually enable the endpoint
// It could use the same endpoint numbers, as that's supported by ChibiOS
// But the QMK code currently assumes that the endpoint numbers are different
2018-11-16 07:22:05 +01:00
CONSOLE_OUT_EPNUM = NEXT_EPNUM ,
2019-08-30 20:19:03 +02:00
# else
# define CONSOLE_OUT_EPNUM CONSOLE_IN_EPNUM
# endif
# endif
2019-07-09 21:34:17 +02:00
2019-08-30 20:19:03 +02:00
# ifdef MIDI_ENABLE
MIDI_STREAM_IN_EPNUM = NEXT_EPNUM ,
2018-11-16 07:22:05 +01:00
MIDI_STREAM_OUT_EPNUM = NEXT_EPNUM ,
2019-08-30 20:19:03 +02:00
# define MIDI_STREAM_IN_EPADDR (ENDPOINT_DIR_IN | MIDI_STREAM_IN_EPNUM)
# define MIDI_STREAM_OUT_EPADDR (ENDPOINT_DIR_OUT | MIDI_STREAM_OUT_EPNUM)
# endif
2019-07-09 21:34:17 +02:00
2019-08-30 20:19:03 +02:00
# ifdef VIRTSER_ENABLE
2018-11-16 07:22:05 +01:00
CDC_NOTIFICATION_EPNUM = NEXT_EPNUM ,
2019-08-30 20:19:03 +02:00
CDC_IN_EPNUM = NEXT_EPNUM ,
CDC_OUT_EPNUM = NEXT_EPNUM ,
# define CDC_NOTIFICATION_EPADDR (ENDPOINT_DIR_IN | CDC_NOTIFICATION_EPNUM)
# define CDC_IN_EPADDR (ENDPOINT_DIR_IN | CDC_IN_EPNUM)
# define CDC_OUT_EPADDR (ENDPOINT_DIR_OUT | CDC_OUT_EPNUM)
# endif
2018-11-16 07:22:05 +01:00
} ;
2019-08-30 20:19:03 +02:00
# ifdef PROTOCOL_LUFA
// LUFA tells us total endpoints including control
# define MAX_ENDPOINTS (ENDPOINT_TOTAL_ENDPOINTS - 1)
# elif defined(PROTOCOL_CHIBIOS)
// ChibiOS gives us number of available user endpoints, not control
# define MAX_ENDPOINTS USB_MAX_ENDPOINTS
# endif
// TODO - ARM_ATSAM
# if (NEXT_EPNUM - 1) > MAX_ENDPOINTS
# error There are not enough available endpoints to support all functions. Please disable one or more of the following: Mouse Keys, Extra Keys, Console, NKRO, MIDI, Serial, Steno
# endif
# define KEYBOARD_EPSIZE 8
# define SHARED_EPSIZE 32
# define MOUSE_EPSIZE 8
# define RAW_EPSIZE 32
# define CONSOLE_EPSIZE 32
# define MIDI_STREAM_EPSIZE 64
# define CDC_NOTIFICATION_EPSIZE 8
# define CDC_EPSIZE 16
2019-07-09 21:34:17 +02:00
uint16_t get_usb_descriptor ( const uint16_t wValue , const uint16_t wIndex , const void * * const DescriptorAddress ) ;
2012-06-28 05:59:17 +02:00
# endif