2016-09-06 19:59:12 +00:00
/*
2013-07-28 08:34:41 +00:00
* Copyright 2012 , 2013 Jun Wako < wakojun @ gmail . com >
2012-06-29 07:48:36 +00:00
* This file is based on :
* LUFA - 120219 / Demos / Device / Lowlevel / KeyboardMouse
* LUFA - 120219 / Demos / Device / Lowlevel / GenericHID
*/
2012-06-28 03:59:17 +00:00
/*
2019-07-09 19:34:17 +00:00
LUFA Library
Copyright ( C ) Dean Camera , 2012.
2012-06-28 03:59:17 +00:00
2019-07-09 19:34:17 +00:00
dean [ at ] fourwalledcubicle [ dot ] com
www . lufa - lib . org
2012-06-28 03:59:17 +00:00
*/
/*
2019-07-09 19:34:17 +00: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 03:59:17 +00:00
*/
/** \file
*
* Header file for Descriptors . c .
*/
2020-12-26 04:56:11 +00:00
# pragma once
2012-06-28 03:59:17 +00:00
2019-08-30 18:19:03 +00:00
# include <LUFA/Drivers/USB/USB.h>
2012-06-28 03:59:17 +00:00
2019-08-30 18:19:03 +00:00
# ifdef PROTOCOL_CHIBIOS
2020-12-11 02:45:24 +00:00
# include <hal.h>
2022-08-04 11:05:16 +00:00
# if STM32_USB_USE_OTG1 == TRUE
# define USB_ENDPOINTS_ARE_REORDERABLE
# endif
2019-08-30 18:19:03 +00:00
# endif
2019-07-09 19:34:17 +00:00
/*
* USB descriptor structure
*/
typedef struct {
2019-08-30 18:19:03 +00:00
USB_Descriptor_Configuration_Header_t Config ;
2012-06-28 03:59:17 +00:00
2019-08-30 18:19:03 +00:00
# ifndef KEYBOARD_SHARED_EP
2012-06-28 03:59:17 +00:00
// Keyboard HID Interface
2019-08-30 18:19:03 +00:00
USB_Descriptor_Interface_t Keyboard_Interface ;
USB_HID_Descriptor_HID_t Keyboard_HID ;
USB_Descriptor_Endpoint_t Keyboard_INEndpoint ;
2020-10-26 23:40:59 +00: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 18:19:03 +00:00
# endif
2012-06-28 03:59:17 +00:00
2019-10-08 18:47:37 +00: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 18:19:03 +00:00
# if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
2012-07-13 17:47:29 +00:00
// Mouse HID Interface
2019-08-30 18:19:03 +00:00
USB_Descriptor_Interface_t Mouse_Interface ;
USB_HID_Descriptor_HID_t Mouse_HID ;
USB_Descriptor_Endpoint_t Mouse_INEndpoint ;
# endif
2019-07-09 19:34:17 +00:00
2020-10-26 23:40:59 +00:00
# if defined(SHARED_EP_ENABLE) && !defined(KEYBOARD_SHARED_EP)
2019-07-09 19:34:17 +00:00
// Shared Interface
2019-08-30 18:19:03 +00:00
USB_Descriptor_Interface_t Shared_Interface ;
USB_HID_Descriptor_HID_t Shared_HID ;
USB_Descriptor_Endpoint_t Shared_INEndpoint ;
# endif
2019-07-09 19:34:17 +00:00
2019-08-30 18:19:03 +00:00
# ifdef CONSOLE_ENABLE
2012-06-28 07:51:56 +00:00
// Console HID Interface
2019-08-30 18:19:03 +00: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 20:07:46 +00:00
// MIDI Audio Control Interface
2019-08-30 18:19:03 +00:00
USB_Descriptor_Interface_t Audio_ControlInterface ;
USB_Audio_Descriptor_Interface_AC_t Audio_ControlInterface_SPC ;
2018-02-08 20:07:46 +00: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 18:19:03 +00:00
# endif
2019-07-09 19:34:17 +00:00
2019-08-30 18:19:03 +00:00
# ifdef VIRTSER_ENABLE
USB_Descriptor_Interface_Association_t CDC_Interface_Association ;
2019-07-09 19:34:17 +00:00
// CDC Control Interface
2019-08-30 18:19:03 +00: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 19:34:17 +00:00
// CDC Data Interface
2019-08-30 18:19:03 +00:00
USB_Descriptor_Interface_t CDC_DCI_Interface ;
USB_Descriptor_Endpoint_t CDC_DataOutEndpoint ;
USB_Descriptor_Endpoint_t CDC_DataInEndpoint ;
# endif
2020-07-25 12:01:15 +00:00
2022-11-26 16:14:45 +00:00
# if defined(JOYSTICK_ENABLE) && !defined(JOYSTICK_SHARED_EP)
2020-07-25 12:01:15 +00: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 18:52:44 +00: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 03:59:17 +00:00
} USB_Descriptor_Configuration_t ;
2019-07-09 19:34:17 +00:00
/*
* Interface indexes
*/
2018-11-16 06:22:05 +00:00
enum usb_interfaces {
2019-08-30 18:19:03 +00:00
# ifndef KEYBOARD_SHARED_EP
2018-11-16 06:22:05 +00:00
KEYBOARD_INTERFACE ,
2019-08-30 18:19:03 +00:00
# else
2020-10-26 23:40:59 +00:00
SHARED_INTERFACE ,
2019-08-30 18:19:03 +00: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 06:22:05 +00:00
RAW_INTERFACE ,
2019-08-30 18:19:03 +00:00
# endif
2019-07-09 19:34:17 +00:00
2019-08-30 18:19:03 +00:00
# if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
2018-11-16 06:22:05 +00:00
MOUSE_INTERFACE ,
2019-08-30 18:19:03 +00:00
# endif
2019-07-09 19:34:17 +00:00
2020-10-26 23:40:59 +00:00
# if defined(SHARED_EP_ENABLE) && !defined(KEYBOARD_SHARED_EP)
2018-11-16 06:22:05 +00:00
SHARED_INTERFACE ,
2019-08-30 18:19:03 +00:00
# endif
2019-07-09 19:34:17 +00:00
2019-08-30 18:19:03 +00:00
# ifdef CONSOLE_ENABLE
2018-11-16 06:22:05 +00:00
CONSOLE_INTERFACE ,
2019-08-30 18:19:03 +00:00
# endif
2019-07-09 19:34:17 +00:00
2019-08-30 18:19:03 +00:00
# ifdef MIDI_ENABLE
2018-11-16 06:22:05 +00:00
AC_INTERFACE ,
AS_INTERFACE ,
2019-08-30 18:19:03 +00:00
# endif
2019-07-09 19:34:17 +00:00
2019-08-30 18:19:03 +00:00
# ifdef VIRTSER_ENABLE
2018-11-16 06:22:05 +00:00
CCI_INTERFACE ,
CDI_INTERFACE ,
2019-08-30 18:19:03 +00:00
# endif
2019-07-09 19:34:17 +00:00
2022-11-26 16:14:45 +00:00
# if defined(JOYSTICK_ENABLE) && !defined(JOYSTICK_SHARED_EP)
2020-07-25 12:01:15 +00:00
JOYSTICK_INTERFACE ,
# endif
2021-08-17 18:52:44 +00:00
# if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP)
DIGITIZER_INTERFACE ,
# endif
2018-11-16 06:22:05 +00:00
TOTAL_INTERFACES
} ;
2016-08-01 05:02:52 +00:00
2019-08-30 18:19:03 +00:00
# define NEXT_EPNUM __COUNTER__
2012-06-28 03:59:17 +00:00
2019-07-09 19:34:17 +00:00
/*
* Endpoint numbers
*/
2018-11-16 06:22:05 +00:00
enum usb_endpoints {
2022-02-12 18:29:31 +00:00
__unused_epnum__ = NEXT_EPNUM , // Endpoint numbering starts at 1
2019-07-09 19:34:17 +00:00
2019-08-30 18:19:03 +00:00
# ifndef KEYBOARD_SHARED_EP
2018-11-16 06:22:05 +00:00
KEYBOARD_IN_EPNUM = NEXT_EPNUM ,
2019-08-30 18:19:03 +00:00
# else
# define KEYBOARD_IN_EPNUM SHARED_IN_EPNUM
# endif
2019-07-09 19:34:17 +00:00
2019-08-30 18:19:03 +00:00
# if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
2018-11-16 06:22:05 +00:00
MOUSE_IN_EPNUM = NEXT_EPNUM ,
2019-08-30 18:19:03 +00:00
# else
# define MOUSE_IN_EPNUM SHARED_IN_EPNUM
# endif
2019-07-09 19:34:17 +00:00
2019-08-30 18:19:03 +00:00
# ifdef RAW_ENABLE
2020-12-17 14:06:30 +00:00
RAW_IN_EPNUM = NEXT_EPNUM ,
2022-08-04 11:05:16 +00:00
# ifdef USB_ENDPOINTS_ARE_REORDERABLE
2020-12-17 14:06:30 +00:00
# define RAW_OUT_EPNUM RAW_IN_EPNUM
# else
2020-12-31 16:50:32 +00:00
RAW_OUT_EPNUM = NEXT_EPNUM ,
2020-12-17 14:06:30 +00:00
# endif
2019-08-30 18:19:03 +00:00
# endif
2019-07-09 19:34:17 +00:00
2019-08-30 18:19:03 +00:00
# ifdef SHARED_EP_ENABLE
2018-11-16 06:22:05 +00:00
SHARED_IN_EPNUM = NEXT_EPNUM ,
2019-08-30 18:19:03 +00:00
# endif
2019-07-09 19:34:17 +00:00
2019-08-30 18:19:03 +00:00
# ifdef CONSOLE_ENABLE
2018-11-16 06:22:05 +00:00
CONSOLE_IN_EPNUM = NEXT_EPNUM ,
2019-07-09 19:34:17 +00:00
2019-08-30 18:19:03 +00:00
# ifdef PROTOCOL_CHIBIOS
2020-12-17 14:06:30 +00: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
2022-08-04 11:05:16 +00:00
# ifdef USB_ENDPOINTS_ARE_REORDERABLE
2020-12-17 14:06:30 +00:00
# define CONSOLE_OUT_EPNUM CONSOLE_IN_EPNUM
# else
2022-10-12 23:28:49 +00:00
CONSOLE_OUT_EPNUM = NEXT_EPNUM ,
2020-12-17 14:06:30 +00:00
# endif
2019-08-30 18:19:03 +00:00
# else
# define CONSOLE_OUT_EPNUM CONSOLE_IN_EPNUM
# endif
# endif
2019-07-09 19:34:17 +00:00
2019-08-30 18:19:03 +00:00
# ifdef MIDI_ENABLE
2020-12-17 14:06:30 +00:00
MIDI_STREAM_IN_EPNUM = NEXT_EPNUM ,
2022-08-04 11:05:16 +00:00
# ifdef USB_ENDPOINTS_ARE_REORDERABLE
2020-12-17 14:06:30 +00:00
# define MIDI_STREAM_OUT_EPNUM MIDI_STREAM_IN_EPNUM
# else
2018-11-16 06:22:05 +00:00
MIDI_STREAM_OUT_EPNUM = NEXT_EPNUM ,
2020-12-17 14:06:30 +00:00
# endif
2019-08-30 18:19:03 +00:00
# endif
2019-07-09 19:34:17 +00:00
2019-08-30 18:19:03 +00:00
# ifdef VIRTSER_ENABLE
2018-11-16 06:22:05 +00:00
CDC_NOTIFICATION_EPNUM = NEXT_EPNUM ,
2019-08-30 18:19:03 +00:00
CDC_IN_EPNUM = NEXT_EPNUM ,
2022-08-04 11:05:16 +00:00
# ifdef USB_ENDPOINTS_ARE_REORDERABLE
2020-12-17 14:06:30 +00:00
# define CDC_OUT_EPNUM CDC_IN_EPNUM
# else
2020-12-31 16:50:32 +00:00
CDC_OUT_EPNUM = NEXT_EPNUM ,
2020-12-17 14:06:30 +00:00
# endif
2019-08-30 18:19:03 +00:00
# endif
2022-10-12 23:28:49 +00:00
2020-07-25 12:01:15 +00:00
# ifdef JOYSTICK_ENABLE
2022-11-26 16:14:45 +00:00
# if !defined(JOYSTICK_SHARED_EP)
2020-12-17 14:06:30 +00:00
JOYSTICK_IN_EPNUM = NEXT_EPNUM ,
2022-11-26 16:14:45 +00:00
# else
# define JOYSTICK_IN_EPNUM SHARED_IN_EPNUM
# endif
2020-07-25 12:01:15 +00:00
# endif
2021-08-17 18:52:44 +00: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 06:22:05 +00:00
} ;
2019-08-30 18:19:03 +00: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 02:27:34 +00:00
# define MOUSE_EPSIZE 16
2019-08-30 18:19:03 +00: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 12:01:15 +00:00
# define JOYSTICK_EPSIZE 8
2021-08-17 18:52:44 +00:00
# define DIGITIZER_EPSIZE 8
2019-07-09 19:34:17 +00:00
2022-12-08 16:45:30 +00:00
uint16_t get_usb_descriptor ( const uint16_t wValue , const uint16_t wIndex , const uint16_t wLength , const void * * const DescriptorAddress ) ;