blob: 0915f54a8382c5d36bfe68d410e1d7c91bf52ec3 [file] [log] [blame]
/**
* \file
*
* \brief USB Device Human Interface Device (HID) generic interface.
*
* Copyright (C) 2009 Atmel Corporation. All rights reserved.
*
* \page License
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name of Atmel may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 4. This software may only be redistributed and used in connection with an
* Atmel AVR product.
*
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*/
#ifndef _UDI_HID_GENERIC_H_
#define _UDI_HID_GENERIC_H_
#include "conf_usb.h"
#include "usb_protocol.h"
#include "usb_protocol_hid.h"
#include "udc_desc.h"
#include "udi.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* \ingroup udi_hid_group
* \defgroup udi_hid_generic_group UDI for Human Interface Device Generic Class
* base on UDI HID
* @{
*/
/**
* \name Interface Descriptor
*
* The following structures provide the interface descriptor.
* It must be implemented in USB configuration descriptor.
*/
//@{
//! Global structure which contains standard UDI API for UDC
extern UDC_DESC_STORAGE udi_api_t udi_api_hid_generic;
//! Interface descriptor structure for HID generic
typedef struct {
usb_iface_desc_t iface;
usb_hid_descriptor_t hid;
usb_ep_desc_t ep_in;
usb_ep_desc_t ep_out;
} udi_hid_generic_desc_t;
//! Report descriptor for HID generic
typedef struct {
uint8_t array[53];
} udi_hid_generic_report_desc_t;
//! By default no string associated to this interface
#ifndef UDI_HID_GENERIC_STRING_ID
#define UDI_HID_GENERIC_STRING_ID 0
#endif
//! HID mouse interval
#ifdef USB_DEVICE_HS_SUPPORT
#define UDI_HID_GENERIC_EP_INTERVEL 8
#else
#define UDI_HID_GENERIC_EP_INTERVEL 20
#endif
//! Content of HID generic interface descriptor for all speed
#define UDI_HID_GENERIC_DESC {\
.iface.bLength = sizeof(usb_iface_desc_t),\
.iface.bDescriptorType = USB_DT_INTERFACE,\
.iface.bInterfaceNumber = UDI_HID_GENERIC_IFACE_NUMBER,\
.iface.bAlternateSetting = 0,\
.iface.bNumEndpoints = 2,\
.iface.bInterfaceClass = HID_CLASS,\
.iface.bInterfaceSubClass = HID_SUB_CLASS_NOBOOT,\
.iface.bInterfaceProtocol = HID_PROTOCOL_GENERIC,\
.iface.iInterface = UDI_HID_GENERIC_STRING_ID,\
.hid.bLength = sizeof(usb_hid_descriptor_t),\
.hid.bDescriptorType = USB_DT_HID,\
.hid.bcdHID = LE16(USB_HID_BDC_V1_11),\
.hid.bCountryCode = USB_HID_NO_COUNTRY_CODE,\
.hid.bNumDescriptors = USB_HID_NUM_DESC,\
.hid.bRDescriptorType = USB_DT_HID_REPORT,\
.hid.wDescriptorLength = LE16(sizeof(udi_hid_generic_report_desc_t)),\
.ep_in.bLength = sizeof(usb_ep_desc_t),\
.ep_in.bDescriptorType = USB_DT_ENDPOINT,\
.ep_in.bEndpointAddress = UDI_HID_GENERIC_EP_IN,\
.ep_in.bmAttributes = USB_EP_TYPE_INTERRUPT,\
.ep_in.wMaxPacketSize = LE16(UDI_HID_GENERIC_EP_SIZE),\
.ep_in.bInterval = UDI_HID_GENERIC_EP_INTERVEL,\
.ep_out.bLength = sizeof(usb_ep_desc_t),\
.ep_out.bDescriptorType = USB_DT_ENDPOINT,\
.ep_out.bEndpointAddress = UDI_HID_GENERIC_EP_OUT,\
.ep_out.bmAttributes = USB_EP_TYPE_INTERRUPT,\
.ep_out.wMaxPacketSize = LE16(UDI_HID_GENERIC_EP_SIZE),\
.ep_out.bInterval = UDI_HID_GENERIC_EP_INTERVEL,\
}
//@}
/**
* \name Interface for application
*
* These routines are used by application to send generic events
*/
//@{
bool udi_hid_generic_send_report_in(uint8_t *data);
//@}
//@}
#ifdef __cplusplus
}
#endif
#endif // _UDI_HID_GENERIC_H_