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 .
*/
2020-12-26 05:56:11 +01:00
# pragma once
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
2020-12-11 03:45:24 +01:00
# include <hal.h>
2022-08-04 13:05:16 +02:00
# if STM32_USB_USE_OTG1 == TRUE
# define USB_ENDPOINTS_ARE_REORDERABLE
# endif
2019-08-30 20:19:03 +02:00
# 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 ;
2020-10-27 00:40:59 +01:00
# else
// Shared Interface
USB_Descriptor_Interface_t Shared_Interface ;
USB_HID_Descriptor_HID_t Shared_HID ;
USB_Descriptor_Endpoint_t Shared_INEndpoint ;
2019-08-30 20:19:03 +02:00
# 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
2020-10-27 00:40:59 +01:00
# if defined(SHARED_EP_ENABLE) && !defined(KEYBOARD_SHARED_EP)
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 ;
# 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
2020-07-25 14:01:15 +02:00
2022-11-26 17:14:45 +01:00
# if defined(JOYSTICK_ENABLE) && !defined(JOYSTICK_SHARED_EP)
2020-07-25 14:01:15 +02:00
// Joystick HID Interface
USB_Descriptor_Interface_t Joystick_Interface ;
USB_HID_Descriptor_HID_t Joystick_HID ;
USB_Descriptor_Endpoint_t Joystick_INEndpoint ;
# endif
2021-08-17 20:52:44 +02:00
# if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP)
// Digitizer HID Interface
USB_Descriptor_Interface_t Digitizer_Interface ;
USB_HID_Descriptor_HID_t Digitizer_HID ;
USB_Descriptor_Endpoint_t Digitizer_INEndpoint ;
# 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
2020-10-27 00:40:59 +01:00
SHARED_INTERFACE ,
2019-08-30 20:19:03 +02:00
# 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
2020-10-27 00:40:59 +01:00
# if defined(SHARED_EP_ENABLE) && !defined(KEYBOARD_SHARED_EP)
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
2022-11-26 17:14:45 +01:00
# if defined(JOYSTICK_ENABLE) && !defined(JOYSTICK_SHARED_EP)
2020-07-25 14:01:15 +02:00
JOYSTICK_INTERFACE ,
# endif
2021-08-17 20:52:44 +02:00
# if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP)
DIGITIZER_INTERFACE ,
# endif
2018-11-16 07:22:05 +01:00
TOTAL_INTERFACES
} ;
2016-08-01 07:02:52 +02:00
2024-02-28 12:00:27 +01:00
# define IS_VALID_INTERFACE(i) ((i) >= 0 && (i) < TOTAL_INTERFACES)
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 {
2022-02-12 19:29:31 +01: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
2020-12-17 15:06:30 +01:00
RAW_IN_EPNUM = NEXT_EPNUM ,
2022-08-04 13:05:16 +02:00
# ifdef USB_ENDPOINTS_ARE_REORDERABLE
2020-12-17 15:06:30 +01:00
# define RAW_OUT_EPNUM RAW_IN_EPNUM
# else
2020-12-31 17:50:32 +01:00
RAW_OUT_EPNUM = NEXT_EPNUM ,
2020-12-17 15:06:30 +01:00
# endif
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-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
2020-12-17 15:06:30 +01:00
MIDI_STREAM_IN_EPNUM = NEXT_EPNUM ,
2022-08-04 13:05:16 +02:00
# ifdef USB_ENDPOINTS_ARE_REORDERABLE
2020-12-17 15:06:30 +01:00
# define MIDI_STREAM_OUT_EPNUM MIDI_STREAM_IN_EPNUM
# else
2018-11-16 07:22:05 +01:00
MIDI_STREAM_OUT_EPNUM = NEXT_EPNUM ,
2020-12-17 15:06:30 +01:00
# endif
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
CDC_NOTIFICATION_EPNUM = NEXT_EPNUM ,
2019-08-30 20:19:03 +02:00
CDC_IN_EPNUM = NEXT_EPNUM ,
2022-08-04 13:05:16 +02:00
# ifdef USB_ENDPOINTS_ARE_REORDERABLE
2020-12-17 15:06:30 +01:00
# define CDC_OUT_EPNUM CDC_IN_EPNUM
# else
2020-12-31 17:50:32 +01:00
CDC_OUT_EPNUM = NEXT_EPNUM ,
2020-12-17 15:06:30 +01:00
# endif
2019-08-30 20:19:03 +02:00
# endif
2022-10-13 01:28:49 +02:00
2020-07-25 14:01:15 +02:00
# ifdef JOYSTICK_ENABLE
2022-11-26 17:14:45 +01:00
# if !defined(JOYSTICK_SHARED_EP)
2020-12-17 15:06:30 +01:00
JOYSTICK_IN_EPNUM = NEXT_EPNUM ,
2022-11-26 17:14:45 +01:00
# else
# define JOYSTICK_IN_EPNUM SHARED_IN_EPNUM
# endif
2020-07-25 14:01:15 +02:00
# endif
2021-08-17 20:52:44 +02:00
# ifdef DIGITIZER_ENABLE
# if !defined(DIGITIZER_SHARED_EP)
DIGITIZER_IN_EPNUM = NEXT_EPNUM ,
# else
# define DIGITIZER_IN_EPNUM SHARED_IN_EPNUM
# endif
# 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
2023-09-25 04:27:34 +02:00
# define MOUSE_EPSIZE 16
2019-08-30 20:19:03 +02:00
# define RAW_EPSIZE 32
# define CONSOLE_EPSIZE 32
# define MIDI_STREAM_EPSIZE 64
# define CDC_NOTIFICATION_EPSIZE 8
# define CDC_EPSIZE 16
2020-07-25 14:01:15 +02:00
# define JOYSTICK_EPSIZE 8
2021-08-17 20:52:44 +02:00
# define DIGITIZER_EPSIZE 8
2019-07-09 21:34:17 +02:00
2022-12-08 17:45:30 +01:00
uint16_t get_usb_descriptor ( const uint16_t wValue , const uint16_t wIndex , const uint16_t wLength , const void * * const DescriptorAddress ) ;