2012-01-03 05:28:53 +01:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* @addtogroup PIOS PIOS Core hardware abstraction layer
|
|
|
|
* @{
|
|
|
|
* @addtogroup PIOS_USBHOOK USB glue code
|
|
|
|
* @brief Glue between PiOS and STM32 libs
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file pios_usbhook.c
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
|
|
* @brief Glue between PiOS and STM32 libs
|
|
|
|
* @see The GNU Public License (GPL) Version 3
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2010-09-27 09:28:45 +02:00
|
|
|
#include "pios.h"
|
2012-01-02 20:03:15 +01:00
|
|
|
#include "pios_usb.h" /* PIOS_USB_* */
|
2011-09-10 05:26:19 +02:00
|
|
|
#include "pios_usbhook.h"
|
2012-01-02 20:03:15 +01:00
|
|
|
#include "pios_usb_defs.h" /* struct usb_* */
|
2010-09-27 09:28:45 +02:00
|
|
|
#include "pios_usb_hid_pwr.h"
|
2012-01-02 20:03:15 +01:00
|
|
|
#include "pios_usb_cdc_priv.h" /* PIOS_USB_CDC_* */
|
|
|
|
#include "pios_usb_board_data.h" /* PIOS_USB_BOARD_* */
|
2010-09-27 09:28:45 +02:00
|
|
|
|
2012-02-07 08:12:55 +01:00
|
|
|
/* STM32 USB Library Definitions */
|
|
|
|
#include "usb_lib.h"
|
|
|
|
|
2012-01-14 20:17:06 +01:00
|
|
|
static ONE_DESCRIPTOR Device_Descriptor;
|
|
|
|
|
|
|
|
void PIOS_USBHOOK_RegisterDevice(const uint8_t * desc, uint16_t desc_size)
|
|
|
|
{
|
|
|
|
Device_Descriptor.Descriptor = desc;
|
|
|
|
Device_Descriptor.Descriptor_Size = desc_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ONE_DESCRIPTOR Config_Descriptor;
|
|
|
|
|
|
|
|
void PIOS_USBHOOK_RegisterConfig(uint8_t config_id, const uint8_t * desc, uint16_t desc_size)
|
|
|
|
{
|
|
|
|
Config_Descriptor.Descriptor = desc;
|
|
|
|
Config_Descriptor.Descriptor_Size = desc_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ONE_DESCRIPTOR String_Descriptor[4];
|
|
|
|
|
|
|
|
void PIOS_USBHOOK_RegisterString(enum usb_string_desc string_id, const uint8_t * desc, uint16_t desc_size)
|
|
|
|
{
|
|
|
|
if (string_id < NELEMENTS(String_Descriptor)) {
|
|
|
|
String_Descriptor[string_id].Descriptor = desc;
|
|
|
|
String_Descriptor[string_id].Descriptor_Size = desc_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-05 01:43:56 +01:00
|
|
|
static ONE_DESCRIPTOR Hid_Descriptor;
|
2012-01-14 20:17:06 +01:00
|
|
|
|
2012-03-05 01:43:56 +01:00
|
|
|
void PIOS_USB_HID_RegisterHidDescriptor(const uint8_t * desc, uint16_t desc_size)
|
2012-01-14 20:17:06 +01:00
|
|
|
{
|
2012-03-05 01:43:56 +01:00
|
|
|
Hid_Descriptor.Descriptor = desc;
|
|
|
|
Hid_Descriptor.Descriptor_Size = desc_size;
|
2012-01-14 20:17:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ONE_DESCRIPTOR Hid_Report_Descriptor;
|
|
|
|
|
2012-02-07 08:12:55 +01:00
|
|
|
void PIOS_USB_HID_RegisterHidReport(const uint8_t * desc, uint16_t desc_size)
|
2012-01-14 20:17:06 +01:00
|
|
|
{
|
|
|
|
Hid_Report_Descriptor.Descriptor = desc;
|
|
|
|
Hid_Report_Descriptor.Descriptor_Size = desc_size;
|
|
|
|
}
|
|
|
|
|
2012-01-02 20:03:15 +01:00
|
|
|
#include "stm32f10x.h" /* __IO */
|
2010-09-27 09:28:45 +02:00
|
|
|
__IO uint8_t EXTI_Enable;
|
|
|
|
|
2012-01-02 20:03:15 +01:00
|
|
|
uint32_t ProtocolValue;
|
2010-09-27 09:28:45 +02:00
|
|
|
|
|
|
|
DEVICE Device_Table = {
|
2012-01-02 20:03:15 +01:00
|
|
|
PIOS_USB_BOARD_EP_NUM,
|
2010-09-27 09:28:45 +02:00
|
|
|
1
|
|
|
|
};
|
|
|
|
|
2011-09-10 05:26:19 +02:00
|
|
|
static void PIOS_USBHOOK_Init(void);
|
|
|
|
static void PIOS_USBHOOK_Reset(void);
|
|
|
|
static void PIOS_USBHOOK_Status_In(void);
|
|
|
|
static void PIOS_USBHOOK_Status_Out(void);
|
|
|
|
static RESULT PIOS_USBHOOK_Data_Setup(uint8_t RequestNo);
|
|
|
|
static RESULT PIOS_USBHOOK_NoData_Setup(uint8_t RequestNo);
|
|
|
|
static RESULT PIOS_USBHOOK_Get_Interface_Setting(uint8_t Interface, uint8_t AlternateSetting);
|
2012-01-14 20:17:06 +01:00
|
|
|
static const uint8_t *PIOS_USBHOOK_GetDeviceDescriptor(uint16_t Length);
|
|
|
|
static const uint8_t *PIOS_USBHOOK_GetConfigDescriptor(uint16_t Length);
|
|
|
|
static const uint8_t *PIOS_USBHOOK_GetStringDescriptor(uint16_t Length);
|
2011-09-10 05:26:19 +02:00
|
|
|
|
2010-09-27 09:28:45 +02:00
|
|
|
DEVICE_PROP Device_Property = {
|
2011-09-10 05:26:19 +02:00
|
|
|
.Init = PIOS_USBHOOK_Init,
|
|
|
|
.Reset = PIOS_USBHOOK_Reset,
|
|
|
|
.Process_Status_IN = PIOS_USBHOOK_Status_In,
|
|
|
|
.Process_Status_OUT = PIOS_USBHOOK_Status_Out,
|
|
|
|
.Class_Data_Setup = PIOS_USBHOOK_Data_Setup,
|
|
|
|
.Class_NoData_Setup = PIOS_USBHOOK_NoData_Setup,
|
|
|
|
.Class_Get_Interface_Setting = PIOS_USBHOOK_Get_Interface_Setting,
|
|
|
|
.GetDeviceDescriptor = PIOS_USBHOOK_GetDeviceDescriptor,
|
|
|
|
.GetConfigDescriptor = PIOS_USBHOOK_GetConfigDescriptor,
|
|
|
|
.GetStringDescriptor = PIOS_USBHOOK_GetStringDescriptor,
|
|
|
|
.RxEP_buffer = 0,
|
|
|
|
.MaxPacketSize = 0x40,
|
2010-09-27 09:28:45 +02:00
|
|
|
};
|
|
|
|
|
2011-09-10 05:26:19 +02:00
|
|
|
static void PIOS_USBHOOK_SetConfiguration(void);
|
|
|
|
static void PIOS_USBHOOK_SetDeviceAddress(void);
|
|
|
|
|
2010-09-27 09:28:45 +02:00
|
|
|
USER_STANDARD_REQUESTS User_Standard_Requests = {
|
2011-09-10 05:26:19 +02:00
|
|
|
.User_GetConfiguration = NOP_Process,
|
|
|
|
.User_SetConfiguration = PIOS_USBHOOK_SetConfiguration,
|
|
|
|
.User_GetInterface = NOP_Process,
|
|
|
|
.User_SetInterface = NOP_Process,
|
|
|
|
.User_GetStatus = NOP_Process,
|
|
|
|
.User_ClearFeature = NOP_Process,
|
|
|
|
.User_SetEndPointFeature = NOP_Process,
|
|
|
|
.User_SetDeviceFeature = NOP_Process,
|
|
|
|
.User_SetDeviceAddress = PIOS_USBHOOK_SetDeviceAddress
|
2010-09-27 09:28:45 +02:00
|
|
|
};
|
|
|
|
|
2011-09-10 05:26:19 +02:00
|
|
|
static RESULT PIOS_USBHOOK_SetProtocol(void);
|
2012-01-14 20:17:06 +01:00
|
|
|
static const uint8_t *PIOS_USBHOOK_GetProtocolValue(uint16_t Length);
|
|
|
|
static const uint8_t *PIOS_USBHOOK_GetReportDescriptor(uint16_t Length);
|
|
|
|
static const uint8_t *PIOS_USBHOOK_GetHIDDescriptor(uint16_t Length);
|
2010-09-27 09:28:45 +02:00
|
|
|
|
|
|
|
/*******************************************************************************
|
2011-09-10 05:26:19 +02:00
|
|
|
* Function Name : PIOS_USBHOOK_Init.
|
2010-09-27 09:28:45 +02:00
|
|
|
* Description : Custom HID init routine.
|
|
|
|
* Input : None.
|
|
|
|
* Output : None.
|
|
|
|
* Return : None.
|
|
|
|
*******************************************************************************/
|
2011-09-10 05:26:19 +02:00
|
|
|
static void PIOS_USBHOOK_Init(void)
|
2010-09-27 09:28:45 +02:00
|
|
|
{
|
|
|
|
pInformation->Current_Configuration = 0;
|
2012-01-14 20:17:06 +01:00
|
|
|
|
2010-09-27 09:28:45 +02:00
|
|
|
/* Connect the device */
|
|
|
|
PowerOn();
|
|
|
|
|
|
|
|
/* Perform basic device initialization operations */
|
|
|
|
USB_SIL_Init();
|
|
|
|
|
|
|
|
bDeviceState = UNCONNECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
2011-09-10 05:26:19 +02:00
|
|
|
* Function Name : PIOS_USBHOOK_Reset.
|
2010-09-27 09:28:45 +02:00
|
|
|
* Description : Custom HID reset routine.
|
|
|
|
* Input : None.
|
|
|
|
* Output : None.
|
|
|
|
* Return : None.
|
|
|
|
*******************************************************************************/
|
2011-09-10 05:26:19 +02:00
|
|
|
static void PIOS_USBHOOK_Reset(void)
|
2010-09-27 09:28:45 +02:00
|
|
|
{
|
2011-09-10 05:26:19 +02:00
|
|
|
/* Set DEVICE as not configured */
|
2010-09-27 09:28:45 +02:00
|
|
|
pInformation->Current_Configuration = 0;
|
|
|
|
pInformation->Current_Interface = 0; /*the default Interface */
|
|
|
|
|
|
|
|
/* Current Feature initialization */
|
2012-01-02 20:03:15 +01:00
|
|
|
pInformation->Current_Feature = 0;
|
2010-09-27 09:28:45 +02:00
|
|
|
|
|
|
|
#ifdef STM32F10X_CL
|
|
|
|
/* EP0 is already configured in DFU_Init() by USB_SIL_Init() function */
|
|
|
|
|
|
|
|
/* Init EP1 IN as Interrupt endpoint */
|
|
|
|
OTG_DEV_EP_Init(EP1_IN, OTG_DEV_EP_TYPE_INT, 2);
|
|
|
|
|
|
|
|
/* Init EP1 OUT as Interrupt endpoint */
|
|
|
|
OTG_DEV_EP_Init(EP1_OUT, OTG_DEV_EP_TYPE_INT, 2);
|
|
|
|
#else
|
|
|
|
SetBTABLE(BTABLE_ADDRESS);
|
|
|
|
|
2011-09-08 03:39:56 +02:00
|
|
|
/* Initialize Endpoint 0 (Control) */
|
2010-09-27 09:28:45 +02:00
|
|
|
SetEPType(ENDP0, EP_CONTROL);
|
|
|
|
SetEPTxAddr(ENDP0, ENDP0_TXADDR);
|
2011-09-08 03:39:56 +02:00
|
|
|
SetEPTxStatus(ENDP0, EP_TX_STALL);
|
2010-09-27 09:28:45 +02:00
|
|
|
Clear_Status_Out(ENDP0);
|
2011-09-08 03:39:56 +02:00
|
|
|
|
|
|
|
SetEPRxAddr(ENDP0, ENDP0_RXADDR);
|
2010-09-27 09:28:45 +02:00
|
|
|
SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
|
|
|
|
SetEPRxValid(ENDP0);
|
|
|
|
|
2012-01-02 20:03:15 +01:00
|
|
|
#if defined(PIOS_INCLUDE_USB_HID)
|
2011-09-08 03:39:56 +02:00
|
|
|
/* Initialize Endpoint 1 (HID) */
|
2010-09-27 09:28:45 +02:00
|
|
|
SetEPType(ENDP1, EP_INTERRUPT);
|
|
|
|
SetEPTxAddr(ENDP1, ENDP1_TXADDR);
|
2012-01-02 20:03:15 +01:00
|
|
|
SetEPTxCount(ENDP1, PIOS_USB_BOARD_HID_DATA_LENGTH);
|
2011-09-08 03:39:56 +02:00
|
|
|
SetEPTxStatus(ENDP1, EP_TX_NAK);
|
|
|
|
|
2010-09-27 09:28:45 +02:00
|
|
|
SetEPRxAddr(ENDP1, ENDP1_RXADDR);
|
2012-01-02 20:03:15 +01:00
|
|
|
SetEPRxCount(ENDP1, PIOS_USB_BOARD_HID_DATA_LENGTH);
|
2010-09-27 09:28:45 +02:00
|
|
|
SetEPRxStatus(ENDP1, EP_RX_VALID);
|
2012-01-02 20:03:15 +01:00
|
|
|
#endif /* PIOS_INCLUDE_USB_HID */
|
2011-09-08 03:39:56 +02:00
|
|
|
|
2012-01-02 20:03:15 +01:00
|
|
|
#if defined(PIOS_INCLUDE_USB_CDC)
|
2011-09-08 03:39:56 +02:00
|
|
|
/* Initialize Endpoint 2 (CDC Call Control) */
|
|
|
|
SetEPType(ENDP2, EP_INTERRUPT);
|
|
|
|
SetEPTxAddr(ENDP2, ENDP2_TXADDR);
|
|
|
|
SetEPTxStatus(ENDP2, EP_TX_NAK);
|
|
|
|
|
|
|
|
SetEPRxAddr(ENDP2, ENDP2_RXADDR);
|
2012-01-02 20:03:15 +01:00
|
|
|
SetEPRxCount(ENDP2, PIOS_USB_BOARD_CDC_MGMT_LENGTH);
|
2011-09-08 03:39:56 +02:00
|
|
|
SetEPRxStatus(ENDP2, EP_RX_DIS);
|
|
|
|
|
|
|
|
/* Initialize Endpoint 3 (CDC Data) */
|
|
|
|
SetEPType(ENDP3, EP_BULK);
|
|
|
|
SetEPTxAddr(ENDP3, ENDP3_TXADDR);
|
|
|
|
SetEPTxStatus(ENDP3, EP_TX_NAK);
|
|
|
|
|
|
|
|
SetEPRxAddr(ENDP3, ENDP3_RXADDR);
|
2012-01-02 20:03:15 +01:00
|
|
|
SetEPRxCount(ENDP3, PIOS_USB_BOARD_CDC_DATA_LENGTH);
|
2011-09-08 03:39:56 +02:00
|
|
|
SetEPRxStatus(ENDP3, EP_RX_VALID);
|
|
|
|
|
2012-01-02 20:03:15 +01:00
|
|
|
#endif /* PIOS_INCLUDE_USB_CDC */
|
2010-09-27 09:28:45 +02:00
|
|
|
|
|
|
|
/* Set this device to response on default address */
|
|
|
|
SetDeviceAddress(0);
|
|
|
|
#endif /* STM32F10X_CL */
|
|
|
|
|
|
|
|
bDeviceState = ATTACHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
2011-09-10 05:26:19 +02:00
|
|
|
* Function Name : PIOS_USBHOOK_SetConfiguration.
|
2011-09-08 03:39:56 +02:00
|
|
|
* Description : Update the device state to configured
|
2010-09-27 09:28:45 +02:00
|
|
|
* Input : None.
|
|
|
|
* Output : None.
|
|
|
|
* Return : None.
|
|
|
|
*******************************************************************************/
|
2011-09-10 05:26:19 +02:00
|
|
|
static void PIOS_USBHOOK_SetConfiguration(void)
|
2010-09-27 09:28:45 +02:00
|
|
|
{
|
|
|
|
if (pInformation->Current_Configuration != 0) {
|
|
|
|
/* Device configured */
|
|
|
|
bDeviceState = CONFIGURED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable transfers */
|
2012-01-02 20:03:15 +01:00
|
|
|
PIOS_USB_ChangeConnectionState(pInformation->Current_Configuration != 0);
|
2010-09-27 09:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
2011-09-10 05:26:19 +02:00
|
|
|
* Function Name : PIOS_USBHOOK_SetConfiguration.
|
2011-09-08 03:39:56 +02:00
|
|
|
* Description : Update the device state to addressed.
|
2010-09-27 09:28:45 +02:00
|
|
|
* Input : None.
|
|
|
|
* Output : None.
|
|
|
|
* Return : None.
|
|
|
|
*******************************************************************************/
|
2011-09-10 05:26:19 +02:00
|
|
|
static void PIOS_USBHOOK_SetDeviceAddress(void)
|
2010-09-27 09:28:45 +02:00
|
|
|
{
|
|
|
|
bDeviceState = ADDRESSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
2011-09-10 05:26:19 +02:00
|
|
|
* Function Name : PIOS_USBHOOK_Status_In.
|
|
|
|
* Description : status IN routine.
|
2010-09-27 09:28:45 +02:00
|
|
|
* Input : None.
|
|
|
|
* Output : None.
|
|
|
|
* Return : None.
|
|
|
|
*******************************************************************************/
|
2011-09-10 05:26:19 +02:00
|
|
|
static void PIOS_USBHOOK_Status_In(void)
|
2010-09-27 09:28:45 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
2011-09-10 05:26:19 +02:00
|
|
|
* Function Name : PIOS_USBHOOK_Status_Out
|
|
|
|
* Description : status OUT routine.
|
2010-09-27 09:28:45 +02:00
|
|
|
* Input : None.
|
|
|
|
* Output : None.
|
|
|
|
* Return : None.
|
|
|
|
*******************************************************************************/
|
2011-09-10 05:26:19 +02:00
|
|
|
static void PIOS_USBHOOK_Status_Out(void)
|
2010-09-27 09:28:45 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
2011-09-10 05:26:19 +02:00
|
|
|
* Function Name : PIOS_USBHOOK_Data_Setup
|
2010-09-27 09:28:45 +02:00
|
|
|
* Description : Handle the data class specific requests.
|
|
|
|
* Input : Request Nb.
|
|
|
|
* Output : None.
|
|
|
|
* Return : USB_UNSUPPORT or USB_SUCCESS.
|
|
|
|
*******************************************************************************/
|
2012-02-07 08:12:55 +01:00
|
|
|
extern const uint8_t *PIOS_USB_CDC_GetLineCoding(uint16_t Length);
|
|
|
|
|
2011-09-10 05:26:19 +02:00
|
|
|
static RESULT PIOS_USBHOOK_Data_Setup(uint8_t RequestNo)
|
2010-09-27 09:28:45 +02:00
|
|
|
{
|
2012-01-14 20:17:06 +01:00
|
|
|
const uint8_t *(*CopyRoutine) (uint16_t);
|
2010-09-27 09:28:45 +02:00
|
|
|
|
|
|
|
CopyRoutine = NULL;
|
|
|
|
|
2011-09-08 03:39:56 +02:00
|
|
|
switch (Type_Recipient) {
|
|
|
|
case (STANDARD_REQUEST | INTERFACE_RECIPIENT):
|
|
|
|
switch (pInformation->USBwIndex0) {
|
2012-05-10 04:27:52 +02:00
|
|
|
#if defined(PIOS_INCLUDE_USB_CDC)
|
2012-02-24 17:22:52 +01:00
|
|
|
case 2: /* HID Interface */
|
2012-05-10 04:27:52 +02:00
|
|
|
#else
|
|
|
|
case 0: /* HID Interface */
|
|
|
|
#endif
|
2011-09-08 03:39:56 +02:00
|
|
|
switch (RequestNo) {
|
|
|
|
case GET_DESCRIPTOR:
|
|
|
|
switch (pInformation->USBwValue1) {
|
2012-01-02 20:03:15 +01:00
|
|
|
case USB_DESC_TYPE_REPORT:
|
2011-09-10 05:26:19 +02:00
|
|
|
CopyRoutine = PIOS_USBHOOK_GetReportDescriptor;
|
2011-09-08 03:39:56 +02:00
|
|
|
break;
|
2012-01-02 20:03:15 +01:00
|
|
|
case USB_DESC_TYPE_HID:
|
2011-09-10 05:26:19 +02:00
|
|
|
CopyRoutine = PIOS_USBHOOK_GetHIDDescriptor;
|
2011-09-08 03:39:56 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-27 09:28:45 +02:00
|
|
|
}
|
2011-09-08 03:39:56 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case (CLASS_REQUEST | INTERFACE_RECIPIENT):
|
|
|
|
switch (pInformation->USBwIndex0) {
|
2012-05-10 04:27:52 +02:00
|
|
|
#if defined(PIOS_INCLUDE_USB_CDC)
|
2012-02-24 17:22:52 +01:00
|
|
|
case 2: /* HID Interface */
|
2012-05-10 04:27:52 +02:00
|
|
|
#else
|
|
|
|
case 0: /* HID Interface */
|
|
|
|
#endif
|
2011-09-08 03:39:56 +02:00
|
|
|
switch (RequestNo) {
|
2012-02-07 08:12:55 +01:00
|
|
|
case USB_HID_REQ_GET_PROTOCOL:
|
2011-09-10 05:26:19 +02:00
|
|
|
CopyRoutine = PIOS_USBHOOK_GetProtocolValue;
|
2011-09-08 03:39:56 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2012-01-02 20:03:15 +01:00
|
|
|
#if defined(PIOS_INCLUDE_USB_CDC)
|
2012-02-24 17:22:52 +01:00
|
|
|
case 0: /* CDC Call Control Interface */
|
2011-09-08 03:39:56 +02:00
|
|
|
switch (RequestNo) {
|
2012-02-07 08:12:55 +01:00
|
|
|
case USB_CDC_REQ_GET_LINE_CODING:
|
2012-09-24 06:53:12 +02:00
|
|
|
CopyInRoutine = PIOS_USB_CDC_GetLineCoding;
|
2011-09-08 03:39:56 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2012-02-24 17:22:52 +01:00
|
|
|
case 1: /* CDC Data Interface */
|
2011-09-08 03:39:56 +02:00
|
|
|
switch (RequestNo) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2012-01-02 20:03:15 +01:00
|
|
|
#endif /* PIOS_INCLUDE_USB_CDC */
|
2011-09-08 03:39:56 +02:00
|
|
|
}
|
|
|
|
break;
|
2010-09-27 09:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (CopyRoutine == NULL) {
|
|
|
|
return USB_UNSUPPORT;
|
|
|
|
}
|
|
|
|
|
2012-01-14 20:17:06 +01:00
|
|
|
pInformation->Ctrl_Info.CopyDataIn = CopyRoutine;
|
2010-09-27 09:28:45 +02:00
|
|
|
pInformation->Ctrl_Info.Usb_wOffset = 0;
|
|
|
|
(*CopyRoutine) (0);
|
|
|
|
return USB_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
2011-09-10 05:26:19 +02:00
|
|
|
* Function Name : PIOS_USBHOOK_NoData_Setup
|
2010-09-27 09:28:45 +02:00
|
|
|
* Description : handle the no data class specific requests
|
|
|
|
* Input : Request Nb.
|
|
|
|
* Output : None.
|
|
|
|
* Return : USB_UNSUPPORT or USB_SUCCESS.
|
|
|
|
*******************************************************************************/
|
2012-02-07 08:12:55 +01:00
|
|
|
extern RESULT PIOS_USB_CDC_SetControlLineState(void);
|
|
|
|
extern RESULT PIOS_USB_CDC_SetLineCoding(void);
|
|
|
|
|
2011-09-10 05:26:19 +02:00
|
|
|
static RESULT PIOS_USBHOOK_NoData_Setup(uint8_t RequestNo)
|
2010-09-27 09:28:45 +02:00
|
|
|
{
|
2011-09-08 03:39:56 +02:00
|
|
|
switch (Type_Recipient) {
|
|
|
|
case (CLASS_REQUEST | INTERFACE_RECIPIENT):
|
|
|
|
switch (pInformation->USBwIndex0) {
|
2012-05-10 04:27:52 +02:00
|
|
|
#if defined(PIOS_INCLUDE_USB_CDC)
|
2012-04-15 20:31:05 +02:00
|
|
|
case 2: /* HID */
|
2012-05-10 04:27:52 +02:00
|
|
|
#else
|
|
|
|
case 0: /* HID */
|
|
|
|
#endif
|
2011-09-08 03:39:56 +02:00
|
|
|
switch (RequestNo) {
|
2012-02-07 08:12:55 +01:00
|
|
|
case USB_HID_REQ_SET_PROTOCOL:
|
2011-09-10 05:26:19 +02:00
|
|
|
return PIOS_USBHOOK_SetProtocol();
|
2011-09-08 03:39:56 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2012-01-02 20:03:15 +01:00
|
|
|
#if defined(PIOS_INCLUDE_USB_CDC)
|
2012-04-15 20:31:05 +02:00
|
|
|
case 0: /* CDC Call Control Interface */
|
2011-09-08 03:39:56 +02:00
|
|
|
switch (RequestNo) {
|
2012-02-07 08:12:55 +01:00
|
|
|
case USB_CDC_REQ_SET_LINE_CODING:
|
2012-01-02 20:03:15 +01:00
|
|
|
return PIOS_USB_CDC_SetLineCoding();
|
2011-09-08 03:39:56 +02:00
|
|
|
break;
|
2012-02-07 08:12:55 +01:00
|
|
|
case USB_CDC_REQ_SET_CONTROL_LINE_STATE:
|
2012-01-02 20:03:15 +01:00
|
|
|
return PIOS_USB_CDC_SetControlLineState();
|
2011-09-08 03:39:56 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2012-01-02 20:03:15 +01:00
|
|
|
#endif /* PIOS_INCLUDE_USB_CDC */
|
2011-09-08 03:39:56 +02:00
|
|
|
}
|
2010-09-27 09:28:45 +02:00
|
|
|
|
2011-09-08 03:39:56 +02:00
|
|
|
break;
|
2010-09-27 09:28:45 +02:00
|
|
|
}
|
2011-09-08 03:39:56 +02:00
|
|
|
|
|
|
|
return USB_UNSUPPORT;
|
2010-09-27 09:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
2011-09-10 05:26:19 +02:00
|
|
|
* Function Name : PIOS_USBHOOK_GetDeviceDescriptor.
|
2010-09-27 09:28:45 +02:00
|
|
|
* Description : Gets the device descriptor.
|
|
|
|
* Input : Length
|
|
|
|
* Output : None.
|
|
|
|
* Return : The address of the device descriptor.
|
|
|
|
*******************************************************************************/
|
2012-01-14 20:17:06 +01:00
|
|
|
static const uint8_t *PIOS_USBHOOK_GetDeviceDescriptor(uint16_t Length)
|
2010-09-27 09:28:45 +02:00
|
|
|
{
|
|
|
|
return Standard_GetDescriptorData(Length, &Device_Descriptor);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
2011-09-10 05:26:19 +02:00
|
|
|
* Function Name : PIOS_USBHOOK_GetConfigDescriptor.
|
2010-09-27 09:28:45 +02:00
|
|
|
* Description : Gets the configuration descriptor.
|
|
|
|
* Input : Length
|
|
|
|
* Output : None.
|
|
|
|
* Return : The address of the configuration descriptor.
|
|
|
|
*******************************************************************************/
|
2012-01-14 20:17:06 +01:00
|
|
|
static const uint8_t *PIOS_USBHOOK_GetConfigDescriptor(uint16_t Length)
|
2010-09-27 09:28:45 +02:00
|
|
|
{
|
|
|
|
return Standard_GetDescriptorData(Length, &Config_Descriptor);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
2011-09-10 05:26:19 +02:00
|
|
|
* Function Name : PIOS_USBHOOK_GetStringDescriptor
|
2010-09-27 09:28:45 +02:00
|
|
|
* Description : Gets the string descriptors according to the needed index
|
|
|
|
* Input : Length
|
|
|
|
* Output : None.
|
|
|
|
* Return : The address of the string descriptors.
|
|
|
|
*******************************************************************************/
|
2012-01-14 20:17:06 +01:00
|
|
|
static const uint8_t *PIOS_USBHOOK_GetStringDescriptor(uint16_t Length)
|
2010-09-27 09:28:45 +02:00
|
|
|
{
|
|
|
|
uint8_t wValue0 = pInformation->USBwValue0;
|
|
|
|
if (wValue0 > 4) {
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
return Standard_GetDescriptorData(Length, &String_Descriptor[wValue0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
2011-09-10 05:26:19 +02:00
|
|
|
* Function Name : PIOS_USBHOOK_GetReportDescriptor.
|
2010-09-27 09:28:45 +02:00
|
|
|
* Description : Gets the HID report descriptor.
|
|
|
|
* Input : Length
|
|
|
|
* Output : None.
|
|
|
|
* Return : The address of the configuration descriptor.
|
|
|
|
*******************************************************************************/
|
2012-01-14 20:17:06 +01:00
|
|
|
static const uint8_t *PIOS_USBHOOK_GetReportDescriptor(uint16_t Length)
|
2010-09-27 09:28:45 +02:00
|
|
|
{
|
2012-01-02 20:03:15 +01:00
|
|
|
return Standard_GetDescriptorData(Length, &Hid_Report_Descriptor);
|
2010-09-27 09:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
2011-09-10 05:26:19 +02:00
|
|
|
* Function Name : PIOS_USBHOOK_GetHIDDescriptor.
|
2010-09-27 09:28:45 +02:00
|
|
|
* Description : Gets the HID descriptor.
|
|
|
|
* Input : Length
|
|
|
|
* Output : None.
|
|
|
|
* Return : The address of the configuration descriptor.
|
|
|
|
*******************************************************************************/
|
2012-01-14 20:17:06 +01:00
|
|
|
static const uint8_t *PIOS_USBHOOK_GetHIDDescriptor(uint16_t Length)
|
2010-09-27 09:28:45 +02:00
|
|
|
{
|
2012-03-05 01:43:56 +01:00
|
|
|
return Standard_GetDescriptorData(Length, &Hid_Descriptor);
|
2010-09-27 09:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
2011-09-10 05:26:19 +02:00
|
|
|
* Function Name : PIOS_USBHOOK_Get_Interface_Setting.
|
2010-09-27 09:28:45 +02:00
|
|
|
* Description : tests the interface and the alternate setting according to the
|
|
|
|
* supported one.
|
|
|
|
* Input : - Interface : interface number.
|
|
|
|
* - AlternateSetting : Alternate Setting number.
|
|
|
|
* Output : None.
|
|
|
|
* Return : USB_SUCCESS or USB_UNSUPPORT.
|
|
|
|
*******************************************************************************/
|
2011-09-10 05:26:19 +02:00
|
|
|
static RESULT PIOS_USBHOOK_Get_Interface_Setting(uint8_t Interface, uint8_t AlternateSetting)
|
2010-09-27 09:28:45 +02:00
|
|
|
{
|
|
|
|
if (AlternateSetting > 0) {
|
|
|
|
return USB_UNSUPPORT;
|
|
|
|
} else if (Interface > 0) {
|
|
|
|
return USB_UNSUPPORT;
|
|
|
|
}
|
|
|
|
return USB_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
2011-09-10 05:26:19 +02:00
|
|
|
* Function Name : PIOS_USBHOOK_SetProtocol
|
|
|
|
* Description : Set Protocol request routine.
|
2010-09-27 09:28:45 +02:00
|
|
|
* Input : None.
|
|
|
|
* Output : None.
|
|
|
|
* Return : USB SUCCESS.
|
|
|
|
*******************************************************************************/
|
2011-09-10 05:26:19 +02:00
|
|
|
static RESULT PIOS_USBHOOK_SetProtocol(void)
|
2010-09-27 09:28:45 +02:00
|
|
|
{
|
|
|
|
uint8_t wValue0 = pInformation->USBwValue0;
|
|
|
|
ProtocolValue = wValue0;
|
|
|
|
return USB_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
2011-09-10 05:26:19 +02:00
|
|
|
* Function Name : PIOS_USBHOOK_GetProtocolValue
|
2010-09-27 09:28:45 +02:00
|
|
|
* Description : get the protocol value
|
|
|
|
* Input : Length.
|
|
|
|
* Output : None.
|
|
|
|
* Return : address of the protcol value.
|
|
|
|
*******************************************************************************/
|
2012-01-14 20:17:06 +01:00
|
|
|
static const uint8_t *PIOS_USBHOOK_GetProtocolValue(uint16_t Length)
|
2010-09-27 09:28:45 +02:00
|
|
|
{
|
|
|
|
if (Length == 0) {
|
|
|
|
pInformation->Ctrl_Info.Usb_wLength = 1;
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
return (uint8_t *) (&ProtocolValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
|