first commit
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : USB_DEVICE
|
||||
* @version : v1.0_Cube
|
||||
* @brief : This file implements the USB Device
|
||||
******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics International N.V.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted, provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistribution 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. Neither the name of STMicroelectronics nor the names of other
|
||||
* contributors to this software may be used to endorse or promote products
|
||||
* derived from this software without specific written permission.
|
||||
* 4. This software, including modifications and/or derivative works of this
|
||||
* software, must execute solely and exclusively on microcontroller or
|
||||
* microprocessor devices manufactured by or for STMicroelectronics.
|
||||
* 5. Redistribution and use of this software other than as permitted under
|
||||
* this license is void and will automatically terminate your rights under
|
||||
* this license.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
|
||||
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
|
||||
* SHALL STMICROELECTRONICS OR CONTRIBUTORS 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
#include "usb_device.h"
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_desc.h"
|
||||
#include "usbd_composite.h"
|
||||
#include "usbd_audio_if.h"
|
||||
|
||||
/* USB Device Core handle declaration */
|
||||
USBD_HandleTypeDef hUsbDeviceFS;
|
||||
|
||||
/* init function */
|
||||
void MX_USB_DEVICE_Init(void)
|
||||
{
|
||||
|
||||
/* Init Device Library,Add Supported Class and Start the library*/
|
||||
USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS);
|
||||
|
||||
USBD_RegisterClass(&hUsbDeviceFS, &USBD_COMP);
|
||||
|
||||
USBD_COMP_RegisterInterface(&hUsbDeviceFS, &USBD_COMP_fops_FS);
|
||||
|
||||
USBD_Start(&hUsbDeviceFS);
|
||||
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,517 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : usbd_audio_if.c
|
||||
* @brief : Generic media access Layer.
|
||||
******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics International N.V.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted, provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistribution 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. Neither the name of STMicroelectronics nor the names of other
|
||||
* contributors to this software may be used to endorse or promote products
|
||||
* derived from this software without specific written permission.
|
||||
* 4. This software, including modifications and/or derivative works of this
|
||||
* software, must execute solely and exclusively on microcontroller or
|
||||
* microprocessor devices manufactured by or for STMicroelectronics.
|
||||
* 5. Redistribution and use of this software other than as permitted under
|
||||
* this license is void and will automatically terminate your rights under
|
||||
* this license.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
|
||||
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
|
||||
* SHALL STMICROELECTRONICS OR CONTRIBUTORS 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_audio_if.h"
|
||||
/* USER CODE BEGIN INCLUDE */
|
||||
#include "uhsdr_board.h"
|
||||
#include "audio_driver.h"
|
||||
/* USER CODE END INCLUDE */
|
||||
|
||||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_AUDIO
|
||||
* @brief usbd core module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_AUDIO_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/* USER CODE BEGIN PRIVATE_TYPES */
|
||||
/* USER CODE END PRIVATE_TYPES */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_AUDIO_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
/* USER CODE BEGIN PRIVATE_DEFINES */
|
||||
/* USER CODE END PRIVATE_DEFINES */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_AUDIO_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
/* USER CODE BEGIN PRIVATE_MACRO */
|
||||
/* USER CODE END PRIVATE_MACRO */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_AUDIO_IF_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
/* USER CODE BEGIN PRIVATE_VARIABLES */
|
||||
/* USER CODE END PRIVATE_VARIABLES */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_AUDIO_IF_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
extern USBD_HandleTypeDef hUsbDeviceFS;
|
||||
/* USER CODE BEGIN EXPORTED_VARIABLES */
|
||||
/* USER CODE END EXPORTED_VARIABLES */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_AUDIO_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
static int8_t AUDIO_Init_FS (uint32_t AudioFreq, uint32_t Volume, uint32_t options);
|
||||
static int8_t AUDIO_DeInit_FS (uint32_t options);
|
||||
static int8_t AUDIO_AudioCmd_FS (uint8_t* pbuf, uint32_t size, uint8_t cmd);
|
||||
static int8_t AUDIO_VolumeCtl_FS (uint8_t vol);
|
||||
static int8_t AUDIO_MuteCtl_FS (uint8_t cmd);
|
||||
static int8_t AUDIO_PeriodicTC_FS (uint8_t cmd);
|
||||
static int8_t AUDIO_GetState_FS (void);
|
||||
static int8_t AUDIO_InVolumeCtl_FS (uint8_t vol);
|
||||
|
||||
|
||||
/* Audio Machine States */
|
||||
typedef enum
|
||||
{
|
||||
AUDIO_STATE_INACTIVE = 0x00,
|
||||
AUDIO_STATE_ACTIVE,
|
||||
AUDIO_STATE_PLAYING,
|
||||
AUDIO_STATE_PAUSED,
|
||||
AUDIO_STATE_STOPPED,
|
||||
AUDIO_STATE_ERROR
|
||||
} USB_AUDIO_MACHINE_State_t;
|
||||
|
||||
|
||||
|
||||
/* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */
|
||||
static USB_AUDIO_MACHINE_State_t AudioState = AUDIO_STATE_INACTIVE;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
USB_DIG_AUDIO_OUT_INIT = 0,
|
||||
USB_DIG_AUDIO_OUT_IDLE,
|
||||
USB_DIG_ADUIO_OUT_TX,
|
||||
} USB_AUDIO_State_t;
|
||||
|
||||
USB_AUDIO_State_t usb_dig_audio_state = USB_DIG_AUDIO_OUT_INIT;
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup usbd_audio_out_if_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define USB_AUDIO_OUT_NUM_BUF 16
|
||||
#define USB_AUDIO_OUT_PKT_SIZE (AUDIO_OUT_PACKET/2)
|
||||
#define USB_AUDIO_OUT_BUF_SIZE (USB_AUDIO_OUT_NUM_BUF * USB_AUDIO_OUT_PKT_SIZE)
|
||||
|
||||
static volatile int16_t out_buffer[USB_AUDIO_OUT_BUF_SIZE]; //buffer for filtered PCM data from Recv.
|
||||
static volatile uint16_t out_buffer_tail;
|
||||
static volatile uint16_t out_buffer_head;
|
||||
static volatile uint16_t out_buffer_overflow;
|
||||
static volatile uint16_t out_buffer_underflow;
|
||||
|
||||
static void audio_out_put_buffer(int16_t sample)
|
||||
{
|
||||
|
||||
uint32_t next_head = (out_buffer_head + 1) %USB_AUDIO_OUT_BUF_SIZE;
|
||||
|
||||
if (next_head != out_buffer_head)
|
||||
{
|
||||
out_buffer[out_buffer_head] = sample;
|
||||
out_buffer_head = next_head;
|
||||
}
|
||||
else
|
||||
{
|
||||
// ok. We loose data now, should never ever happen, but so what
|
||||
// will cause minor distortion if only a few bytes.
|
||||
out_buffer_overflow++;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t audio_out_buffer_fill()
|
||||
{
|
||||
uint16_t temp_head = out_buffer_head;
|
||||
return ((((temp_head < out_buffer_tail)?USB_AUDIO_OUT_BUF_SIZE:0) + temp_head) - out_buffer_tail);
|
||||
}
|
||||
|
||||
volatile int16_t* audio_out_buffer_next_pkt(uint32_t len)
|
||||
{
|
||||
if (audio_out_buffer_fill() >= len)
|
||||
{
|
||||
return &out_buffer[out_buffer_tail];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
static void audio_out_buffer_pop_pkt(volatile int16_t* ptr, uint32_t len)
|
||||
{
|
||||
if (ptr)
|
||||
{
|
||||
// there was data and pkt has been used
|
||||
// free the space
|
||||
out_buffer_tail = (out_buffer_tail+len)%USB_AUDIO_OUT_BUF_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
/* len is length in stereo samples */
|
||||
void UsbdAudio_FillTxBuffer(AudioSample_t *buffer, uint32_t len)
|
||||
{
|
||||
volatile int16_t *pkt = audio_out_buffer_next_pkt(2*len);
|
||||
|
||||
static uint16_t fill_buffer = 1;
|
||||
if (fill_buffer == 0 && pkt)
|
||||
{
|
||||
for (uint32_t idx = len; idx; idx--)
|
||||
{
|
||||
// the purpose is to place the USB input exactly as the I2S does
|
||||
// which is weird if on F4 and 32 Bit transfers are done. (mixed endian)
|
||||
// for all other systems we scale 16bit USB audio to 32bit
|
||||
// on 16 bit audio nothing at all happens here.
|
||||
buffer->l = I2S_Int16_2_AudioSample(*pkt++);
|
||||
buffer->r = I2S_Int16_2_AudioSample(*pkt++);
|
||||
buffer++;
|
||||
}
|
||||
audio_out_buffer_pop_pkt(pkt,2*len);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fill_buffer == 0)
|
||||
{
|
||||
out_buffer_underflow++;
|
||||
fill_buffer = 1;
|
||||
}
|
||||
if (audio_out_buffer_next_pkt((USB_AUDIO_OUT_BUF_SIZE*2)/3) != NULL)
|
||||
{
|
||||
fill_buffer = 0;
|
||||
}
|
||||
// Deliver silence if not enough data is stored in buffer
|
||||
for (uint32_t idx = len; idx; idx--)
|
||||
{
|
||||
buffer->l = 0;
|
||||
buffer->r = 0;
|
||||
buffer++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE END PRIVATE_FUNCTIONS_DECLARATION */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
USBD_AUDIO_ItfTypeDef USBD_AUDIO_fops_FS =
|
||||
{
|
||||
AUDIO_Init_FS,
|
||||
AUDIO_DeInit_FS,
|
||||
AUDIO_AudioCmd_FS,
|
||||
AUDIO_VolumeCtl_FS,
|
||||
AUDIO_MuteCtl_FS,
|
||||
AUDIO_PeriodicTC_FS,
|
||||
AUDIO_GetState_FS,
|
||||
AUDIO_InVolumeCtl_FS,
|
||||
};
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/**
|
||||
* @brief AUDIO_Init_FS
|
||||
* Initializes the AUDIO media low layer over USB FS IP
|
||||
* @param AudioFreq: Audio frequency used to play the audio stream.
|
||||
* @param Volume: Initial volume level (from 0 (Mute) to 100 (Max))
|
||||
* @param options: Reserved for future use
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t AUDIO_Init_FS(uint32_t AudioFreq, uint32_t Volume, uint32_t options)
|
||||
{
|
||||
/* USER CODE BEGIN 0 */
|
||||
AudioState = AUDIO_STATE_ACTIVE;
|
||||
return (USBD_OK);
|
||||
/* USER CODE END 0 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief AUDIO_DeInit_FS
|
||||
* DeInitializes the AUDIO media low layer
|
||||
* @param options: Reserved for future use
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t AUDIO_DeInit_FS(uint32_t options)
|
||||
{
|
||||
/* USER CODE BEGIN 1 */
|
||||
AudioState = AUDIO_STATE_INACTIVE;
|
||||
return (USBD_OK);
|
||||
/* USER CODE END 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief AUDIO_AudioCmd_FS
|
||||
* Handles AUDIO command.
|
||||
* @param pbuf: Pointer to buffer of data to be sent
|
||||
* @param size: Number of data to be sent (in bytes)
|
||||
* @param cmd: Command opcode
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
|
||||
static uint16_t fill;
|
||||
|
||||
static int8_t AUDIO_AudioCmd_FS (uint8_t* pbuf, uint32_t size, uint8_t cmd)
|
||||
{
|
||||
/* USER CODE BEGIN 2 */
|
||||
/* Check the current state */
|
||||
if ((AudioState == AUDIO_STATE_INACTIVE) || (AudioState == AUDIO_STATE_ERROR))
|
||||
{
|
||||
AudioState = AUDIO_STATE_ERROR;
|
||||
return USBD_FAIL;
|
||||
}
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
/* Process the PLAY command ----------------------------*/
|
||||
case AUDIO_CMD_START:
|
||||
case AUDIO_CMD_PLAY:
|
||||
/* If current state is Active or Stopped */
|
||||
if ((AudioState == AUDIO_STATE_ACTIVE) || \
|
||||
(AudioState == AUDIO_STATE_STOPPED) || \
|
||||
(AudioState == AUDIO_STATE_PAUSED) || \
|
||||
(AudioState == AUDIO_STATE_PLAYING))
|
||||
{
|
||||
|
||||
|
||||
if ((ts.txrx_mode == TRX_MODE_RX && (ts.rx_iq_source == RX_IQ_DIG || ts.rx_iq_source == RX_IQ_DIGIQ))
|
||||
|| (ts.txrx_mode == TRX_MODE_TX && (ts.tx_audio_source == TX_AUDIO_DIG || ts.tx_audio_source == TX_AUDIO_DIGIQ)))
|
||||
{
|
||||
uint16_t* pkt = (uint16_t*)pbuf;
|
||||
uint32_t count;
|
||||
static bool too_high = false;
|
||||
|
||||
fill = audio_out_buffer_fill();
|
||||
// USB_AUDIO_OUT_NUM_BUF * USB_AUDIO_OUT_PKT_SIZE
|
||||
bool is_low_space = fill > (3*(USB_AUDIO_OUT_NUM_BUF/4) * USB_AUDIO_OUT_PKT_SIZE);
|
||||
bool is_high_space = fill < (USB_AUDIO_OUT_NUM_BUF/4 * USB_AUDIO_OUT_PKT_SIZE);
|
||||
bool is_high_ok = fill > (3*(USB_AUDIO_OUT_NUM_BUF/4) * USB_AUDIO_OUT_PKT_SIZE);
|
||||
// bool is_low_ok = fill < ((USB_AUDIO_OUT_NUM_BUF/4) * USB_AUDIO_OUT_PKT_SIZE);
|
||||
|
||||
uint16_t num_samples = size/2;
|
||||
|
||||
if (is_high_ok)
|
||||
{
|
||||
too_high = false;
|
||||
} else {
|
||||
too_high = is_high_space;
|
||||
}
|
||||
|
||||
|
||||
if (is_low_space)
|
||||
{
|
||||
num_samples-=2;
|
||||
}
|
||||
for (count =0; count < num_samples; count++)
|
||||
{
|
||||
audio_out_put_buffer(pkt[count]);
|
||||
}
|
||||
if (too_high)
|
||||
{
|
||||
audio_out_put_buffer(pkt[num_samples-2]);
|
||||
audio_out_put_buffer(pkt[num_samples-1]);
|
||||
}
|
||||
|
||||
}
|
||||
AudioState = AUDIO_STATE_PLAYING;
|
||||
return USBD_OK;
|
||||
}
|
||||
else /* Not allowed command */
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
/* Process the STOP command ----------------------------*/
|
||||
case AUDIO_CMD_STOP:
|
||||
if (AudioState != AUDIO_STATE_PLAYING)
|
||||
{
|
||||
/* Unsupported command */
|
||||
return USBD_FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
AudioState = AUDIO_STATE_STOPPED;
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/* Process the PAUSE command ---------------------------*/
|
||||
case AUDIO_CMD_PAUSE:
|
||||
if (AudioState != AUDIO_STATE_PLAYING)
|
||||
{
|
||||
/* Unsupported command */
|
||||
return USBD_FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
AudioState = AUDIO_STATE_PAUSED;
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/* Unsupported command ---------------------------------*/
|
||||
default:
|
||||
return USBD_FAIL;
|
||||
}
|
||||
return USBD_OK;
|
||||
/* USER CODE END 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief AUDIO_VolumeCtl_FS
|
||||
* Controls AUDIO Volume.
|
||||
* @param vol: volume level (0..100)
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t AUDIO_VolumeCtl_FS (uint8_t vol)
|
||||
{
|
||||
/* USER CODE BEGIN 3 */
|
||||
uint16_t source = ts.tx_audio_source == TX_AUDIO_DIGIQ?TX_AUDIO_DIGIQ:TX_AUDIO_DIG;
|
||||
ts.tx_gain[source] = vol;
|
||||
return (USBD_OK);
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief AUDIO_MuteCtl_FS
|
||||
* Controls AUDIO Mute.
|
||||
* @param cmd: command opcode
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t AUDIO_MuteCtl_FS (uint8_t cmd)
|
||||
{
|
||||
/* USER CODE BEGIN 4 */
|
||||
return (USBD_OK);
|
||||
/* USER CODE END 4 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief AUDIO_PeriodicT_FS
|
||||
* @param cmd: Command opcode
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t AUDIO_PeriodicTC_FS (uint8_t cmd)
|
||||
{
|
||||
/* USER CODE BEGIN 5 */
|
||||
return (USBD_OK);
|
||||
/* USER CODE END 5 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief AUDIO_GetState_FS
|
||||
* Gets AUDIO State.
|
||||
* @param None
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t AUDIO_GetState_FS (void)
|
||||
{
|
||||
/* USER CODE BEGIN 6 */
|
||||
return (USBD_OK);
|
||||
/* USER CODE END 6 */
|
||||
}
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* @brief Manages the DMA full Transfer complete event.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void TransferComplete_CallBack_FS(void)
|
||||
{
|
||||
/* USER CODE BEGIN 7 */
|
||||
USBD_AUDIO_Sync(&hUsbDeviceFS, AUDIO_OFFSET_FULL);
|
||||
/* USER CODE END 7 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Manages the DMA Half Transfer complete event.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void HalfTransfer_CallBack_FS(void)
|
||||
{
|
||||
/* USER CODE BEGIN 8 */
|
||||
USBD_AUDIO_Sync(&hUsbDeviceFS, AUDIO_OFFSET_HALF);
|
||||
/* USER CODE END 8 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */
|
||||
/* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
static int8_t AUDIO_InVolumeCtl_FS (uint8_t vol)
|
||||
{
|
||||
/* Call low layer volume setting function */
|
||||
ts.rx_gain[RX_AUDIO_DIG].value = vol;
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : usbd_audio_if.h
|
||||
* @brief : header file for the usbd_audio_if file
|
||||
******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics International N.V.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted, provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistribution 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. Neither the name of STMicroelectronics nor the names of other
|
||||
* contributors to this software may be used to endorse or promote products
|
||||
* derived from this software without specific written permission.
|
||||
* 4. This software, including modifications and/or derivative works of this
|
||||
* software, must execute solely and exclusively on microcontroller or
|
||||
* microprocessor devices manufactured by or for STMicroelectronics.
|
||||
* 5. Redistribution and use of this software other than as permitted under
|
||||
* this license is void and will automatically terminate your rights under
|
||||
* this license.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
|
||||
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
|
||||
* SHALL STMICROELECTRONICS OR CONTRIBUTORS 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBD_AUDIO_IF_H
|
||||
#define __USBD_AUDIO_IF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_audio_cdc_comp.h"
|
||||
/* USER CODE BEGIN INCLUDE */
|
||||
#include "audio_driver.h"
|
||||
/* USER CODE END INCLUDE */
|
||||
|
||||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_AUDIO_IF
|
||||
* @brief header
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_AUDIO_IF_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
/* USER CODE BEGIN EXPORTED_DEFINES */
|
||||
/* USER CODE END EXPORTED_DEFINES */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_AUDIO_IF_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
/* USER CODE BEGIN EXPORTED_TYPES */
|
||||
/* USER CODE END EXPORTED_TYPES */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_AUDIO_IF_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
/* USER CODE BEGIN EXPORTED_MACRO */
|
||||
/* USER CODE END EXPORTED_MACRO */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_AUDIO_IF_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
extern USBD_AUDIO_ItfTypeDef USBD_AUDIO_fops_FS;
|
||||
|
||||
/* USER CODE BEGIN EXPORTED_VARIABLES */
|
||||
/* USER CODE END EXPORTED_VARIABLES */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_AUDIO_IF_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Manages the DMA full Transfer complete event.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void TransferComplete_CallBack_FS(void);
|
||||
|
||||
/**
|
||||
* @brief Manages the DMA Half Transfer complete event.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void HalfTransfer_CallBack_FS(void);
|
||||
|
||||
/* USER CODE BEGIN EXPORTED_FUNCTIONS */
|
||||
extern void UsbdAudio_PutSample(int16_t sample);
|
||||
void UsbdAudio_FillTxBuffer(AudioSample_t *buffer, uint32_t len);
|
||||
/* USER CODE END EXPORTED_FUNCTIONS */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_AUDIO_IF_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,471 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : usbd_cdc_if.c
|
||||
* @brief :
|
||||
******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics International N.V.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted, provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistribution 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. Neither the name of STMicroelectronics nor the names of other
|
||||
* contributors to this software may be used to endorse or promote products
|
||||
* derived from this software without specific written permission.
|
||||
* 4. This software, including modifications and/or derivative works of this
|
||||
* software, must execute solely and exclusively on microcontroller or
|
||||
* microprocessor devices manufactured by or for STMicroelectronics.
|
||||
* 5. Redistribution and use of this software other than as permitted under
|
||||
* this license is void and will automatically terminate your rights under
|
||||
* this license.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
|
||||
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
|
||||
* SHALL STMICROELECTRONICS OR CONTRIBUTORS 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_cdc_if.h"
|
||||
#include "cat_driver.h"
|
||||
#include "usb_device.h"
|
||||
#include "usbd_composite.h"
|
||||
#include "usbd_composite_desc.h"
|
||||
|
||||
/* USER CODE BEGIN INCLUDE */
|
||||
/* USER CODE END INCLUDE */
|
||||
|
||||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CDC
|
||||
* @brief usbd core module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CDC_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/* USER CODE BEGIN PRIVATE_TYPES */
|
||||
/* USER CODE END PRIVATE_TYPES */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CDC_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
/* USER CODE BEGIN PRIVATE_DEFINES */
|
||||
/* Define size for the receive and transmit buffer over CDC */
|
||||
/* It's up to user to redefine and/or remove those define */
|
||||
#define APP_RX_DATA_SIZE 64
|
||||
#define APP_TX_DATA_SIZE 2048
|
||||
/* USER CODE END PRIVATE_DEFINES */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/** @defgroup USBD_CDC_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
/* USER CODE BEGIN PRIVATE_MACRO */
|
||||
/* USER CODE END PRIVATE_MACRO */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CDC_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/* Create buffer for reception and transmission */
|
||||
/* It's up to user to redefine and/or remove those define */
|
||||
/* Received Data over USB are stored in this buffer */
|
||||
uint8_t UserRxBufferFS[APP_RX_DATA_SIZE];
|
||||
|
||||
/* Send Data over USB CDC are stored in this buffer */
|
||||
uint8_t UserTxBufferFS [APP_TX_DATA_SIZE];
|
||||
|
||||
uint32_t CDC_Tx_PtrIn = 0;
|
||||
uint32_t CDC_Tx_PtrOut = 0;
|
||||
uint32_t CDC_Tx_Length = 0;
|
||||
|
||||
uint8_t CDC_Tx_State = 0;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t speed;
|
||||
uint8_t stop;
|
||||
uint8_t parity;
|
||||
uint8_t bits;
|
||||
} CdvVcp_LineCoding_t;
|
||||
|
||||
static CdvVcp_LineCoding_t CDC_Linecoding =
|
||||
{
|
||||
// 9600 8n1
|
||||
.speed = 9600,
|
||||
.stop = 0, // 1 stop bit
|
||||
.bits = 8, // 8 data bits
|
||||
.parity = 0, // parity none
|
||||
};
|
||||
|
||||
/* USER CODE BEGIN PRIVATE_VARIABLES */
|
||||
/* USER CODE END PRIVATE_VARIABLES */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CDC_IF_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
__IO CdcVcp_CtrlLines_t cdcvcp_ctrllines;
|
||||
/* USER CODE BEGIN EXPORTED_VARIABLES */
|
||||
/* USER CODE END EXPORTED_VARIABLES */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CDC_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
static int8_t CDC_Init_FS (void);
|
||||
static int8_t CDC_DeInit_FS (void);
|
||||
static int8_t CDC_Control_FS (uint8_t cmd, uint8_t* pbuf, uint16_t length);
|
||||
static int8_t CDC_Receive_FS (uint8_t* pbuf, uint32_t *Len);
|
||||
static int8_t CDC_SOF (USBD_HandleTypeDef *pdev);
|
||||
static int8_t CDC_DataIn (USBD_HandleTypeDef *pdev);
|
||||
|
||||
/* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */
|
||||
/* USER CODE END PRIVATE_FUNCTIONS_DECLARATION */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
USBD_CDC_ItfTypeDef USBD_Interface_fops_FS =
|
||||
{
|
||||
CDC_Init_FS,
|
||||
CDC_DeInit_FS,
|
||||
CDC_Control_FS,
|
||||
CDC_Receive_FS,
|
||||
CDC_SOF,
|
||||
CDC_DataIn
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/**
|
||||
* @brief CDC_Init_FS
|
||||
* Initializes the CDC media low layer over the FS USB IP
|
||||
* @param None
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t CDC_Init_FS(void)
|
||||
{
|
||||
/* USER CODE BEGIN 3 */
|
||||
/* Set Application Buffers */
|
||||
USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0);
|
||||
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, UserRxBufferFS);
|
||||
return (USBD_OK);
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CDC_DeInit_FS
|
||||
* DeInitializes the CDC media low layer
|
||||
* @param None
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t CDC_DeInit_FS(void)
|
||||
{
|
||||
/* USER CODE BEGIN 4 */
|
||||
return (USBD_OK);
|
||||
/* USER CODE END 4 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CDC_Control_FS
|
||||
* Manage the CDC class requests
|
||||
* @param cmd: Command code
|
||||
* @param pbuf: Buffer containing command data (request parameters)
|
||||
* @param length: Number of data to be sent (in bytes)
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t CDC_Control_FS (uint8_t cmd, uint8_t* pbuf, uint16_t length)
|
||||
{
|
||||
/* USER CODE BEGIN 5 */
|
||||
switch (cmd)
|
||||
{
|
||||
case CDC_SEND_ENCAPSULATED_COMMAND:
|
||||
|
||||
break;
|
||||
|
||||
case CDC_GET_ENCAPSULATED_RESPONSE:
|
||||
|
||||
break;
|
||||
|
||||
case CDC_SET_COMM_FEATURE:
|
||||
|
||||
break;
|
||||
|
||||
case CDC_GET_COMM_FEATURE:
|
||||
|
||||
break;
|
||||
|
||||
case CDC_CLEAR_COMM_FEATURE:
|
||||
|
||||
break;
|
||||
|
||||
/*******************************************************************************/
|
||||
/* Line Coding Structure */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Offset | Field | Size | Value | Description */
|
||||
/* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits per second*/
|
||||
/* 4 | bCharFormat | 1 | Number | Stop bits */
|
||||
/* 0 - 1 Stop bit */
|
||||
/* 1 - 1.5 Stop bits */
|
||||
/* 2 - 2 Stop bits */
|
||||
/* 5 | bParityType | 1 | Number | Parity */
|
||||
/* 0 - None */
|
||||
/* 1 - Odd */
|
||||
/* 2 - Even */
|
||||
/* 3 - Mark */
|
||||
/* 4 - Space */
|
||||
/* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */
|
||||
/*******************************************************************************/
|
||||
case CDC_SET_LINE_CODING:
|
||||
// just copy the requested line coding
|
||||
// we ignore it for now but keep it to
|
||||
// satisfy the host when it asks for the current
|
||||
// line coding
|
||||
memcpy(&CDC_Linecoding,pbuf,sizeof(CDC_Linecoding));
|
||||
break;
|
||||
case CDC_GET_LINE_CODING:
|
||||
memcpy(pbuf,&CDC_Linecoding,length);
|
||||
break;
|
||||
|
||||
case CDC_SET_CONTROL_LINE_STATE:
|
||||
{
|
||||
// we get wValue here as buffer
|
||||
uint16_t wValue = *(uint16_t*)&(pbuf[0]);
|
||||
cdcvcp_ctrllines.dtr = (wValue & 0x01)?1:0;
|
||||
cdcvcp_ctrllines.rts = (wValue & 0x02)?1:0;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case CDC_SEND_BREAK:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return (USBD_OK);
|
||||
/* USER CODE END 5 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CDC_Receive_FS
|
||||
* Data received over USB OUT endpoint are sent over CDC interface
|
||||
* through this function.
|
||||
*
|
||||
* @note
|
||||
* This function will block any OUT packet reception on USB endpoint
|
||||
* untill exiting this function. If you exit this function before transfer
|
||||
* is complete on CDC interface (ie. using DMA controller) it will result
|
||||
* in receiving more data while previous ones are still not sent.
|
||||
*
|
||||
* @param Buf: Buffer of data to be received
|
||||
* @param Len: Number of data received (in bytes)
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len)
|
||||
{
|
||||
/* USER CODE BEGIN 6 */
|
||||
for (uint32_t i = 0; i < *Len; i++)
|
||||
{
|
||||
CatDriver_InterfaceBufferAddData(Buf[i]);
|
||||
}
|
||||
|
||||
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
|
||||
USBD_CDC_ReceivePacket(&hUsbDeviceFS);
|
||||
return (USBD_OK);
|
||||
/* USER CODE END 6 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CDC_Transmit_FS
|
||||
* Data send over USB IN endpoint are sent over CDC interface
|
||||
* through this function.
|
||||
* @note
|
||||
*
|
||||
*
|
||||
* @param Buf: Buffer of data to be send
|
||||
* @param Len: Number of data to be send (in bytes)
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY
|
||||
*/
|
||||
uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)
|
||||
{
|
||||
uint8_t result = USBD_OK;
|
||||
/* USER CODE BEGIN 7 */
|
||||
uint32_t tx_counter = 0;
|
||||
|
||||
while (tx_counter < Len)
|
||||
{
|
||||
UserTxBufferFS[CDC_Tx_PtrIn] = *(Buf+tx_counter);
|
||||
|
||||
CDC_Tx_PtrIn++;
|
||||
|
||||
/* To avoid buffer overflow */
|
||||
if (CDC_Tx_PtrIn >= APP_TX_DATA_SIZE)
|
||||
{
|
||||
CDC_Tx_PtrIn = 0;
|
||||
}
|
||||
|
||||
tx_counter++;
|
||||
}
|
||||
/* USER CODE END 7 */
|
||||
return result;
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */
|
||||
/* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
|
||||
static void CDC_InitiateTransmit(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
uint16_t USB_Tx_ptr;
|
||||
uint16_t USB_Tx_length;
|
||||
|
||||
if (CDC_Tx_Length > CDC_DATA_FS_IN_PACKET_SIZE)
|
||||
{
|
||||
USB_Tx_ptr = CDC_Tx_PtrOut;
|
||||
USB_Tx_length = CDC_DATA_FS_IN_PACKET_SIZE;
|
||||
|
||||
CDC_Tx_PtrOut += CDC_DATA_FS_IN_PACKET_SIZE;
|
||||
CDC_Tx_Length -= CDC_DATA_FS_IN_PACKET_SIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
USB_Tx_ptr = CDC_Tx_PtrOut;
|
||||
USB_Tx_length = CDC_Tx_Length;
|
||||
|
||||
CDC_Tx_PtrOut += CDC_Tx_Length;
|
||||
CDC_Tx_Length = 0;
|
||||
}
|
||||
|
||||
CDC_Tx_State = 1;
|
||||
|
||||
USBD_CDC_SetTxBuffer(pdev,
|
||||
&UserTxBufferFS[USB_Tx_ptr],
|
||||
USB_Tx_length);
|
||||
/* Prepare the available data buffer to be sent on IN endpoint */
|
||||
USBD_CDC_TransmitPacket(pdev);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Handle_USBAsynchXfer
|
||||
* Send data to USB
|
||||
* @param pdev: instance
|
||||
* @retval None
|
||||
*/
|
||||
static void CDC_Handle_USBAsynchXfer (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
|
||||
if(CDC_Tx_State != 1)
|
||||
{
|
||||
|
||||
if (CDC_Tx_PtrOut == APP_TX_DATA_SIZE)
|
||||
{
|
||||
CDC_Tx_PtrOut = 0;
|
||||
}
|
||||
|
||||
if(CDC_Tx_PtrOut == CDC_Tx_PtrIn)
|
||||
{
|
||||
CDC_Tx_Length = 0;
|
||||
CDC_Tx_State = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(CDC_Tx_PtrOut > CDC_Tx_PtrIn) /* rollback */
|
||||
{
|
||||
CDC_Tx_Length = APP_TX_DATA_SIZE - CDC_Tx_PtrOut;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
CDC_Tx_Length = CDC_Tx_PtrIn - CDC_Tx_PtrOut;
|
||||
|
||||
}
|
||||
CDC_InitiateTransmit(pdev);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int8_t CDC_DataIn (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
if (CDC_Tx_State == 1)
|
||||
{
|
||||
if (CDC_Tx_Length == 0)
|
||||
{
|
||||
CDC_Tx_State = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
CDC_InitiateTransmit(pdev);
|
||||
}
|
||||
}
|
||||
|
||||
return CDC_Tx_State;
|
||||
}
|
||||
|
||||
static int8_t CDC_SOF (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
static uint32_t FrameCount = 0;
|
||||
|
||||
if (FrameCount++ == 2) // every second frame
|
||||
{
|
||||
/* Reset the frame counter */
|
||||
FrameCount = 0;
|
||||
|
||||
/* Check the data to be sent through IN pipe */
|
||||
CDC_Handle_USBAsynchXfer(pdev);
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : usbd_cdc_if.h
|
||||
* @brief : Header for usbd_cdc_if file.
|
||||
******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics International N.V.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted, provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistribution 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. Neither the name of STMicroelectronics nor the names of other
|
||||
* contributors to this software may be used to endorse or promote products
|
||||
* derived from this software without specific written permission.
|
||||
* 4. This software, including modifications and/or derivative works of this
|
||||
* software, must execute solely and exclusively on microcontroller or
|
||||
* microprocessor devices manufactured by or for STMicroelectronics.
|
||||
* 5. Redistribution and use of this software other than as permitted under
|
||||
* this license is void and will automatically terminate your rights under
|
||||
* this license.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
|
||||
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
|
||||
* SHALL STMICROELECTRONICS OR CONTRIBUTORS 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBD_CDC_IF_H
|
||||
#define __USBD_CDC_IF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_cdc.h"
|
||||
/* USER CODE BEGIN INCLUDE */
|
||||
/* USER CODE END INCLUDE */
|
||||
|
||||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CDC_IF
|
||||
* @brief header
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CDC_IF_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
/* USER CODE BEGIN EXPORTED_DEFINES */
|
||||
/* USER CODE END EXPORTED_DEFINES */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CDC_IF_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
/* USER CODE BEGIN EXPORTED_TYPES */
|
||||
typedef struct {
|
||||
uint16_t
|
||||
dtr:1,
|
||||
rts:1;
|
||||
} CdcVcp_CtrlLines_t;
|
||||
|
||||
extern __IO CdcVcp_CtrlLines_t cdcvcp_ctrllines;
|
||||
/* USER CODE END EXPORTED_TYPES */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CDC_IF_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
/* USER CODE BEGIN EXPORTED_MACRO */
|
||||
/* USER CODE END EXPORTED_MACRO */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_AUDIO_IF_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
extern USBD_CDC_ItfTypeDef USBD_Interface_fops_FS;
|
||||
|
||||
/* USER CODE BEGIN EXPORTED_VARIABLES */
|
||||
/* USER CODE END EXPORTED_VARIABLES */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CDC_IF_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len);
|
||||
|
||||
/* USER CODE BEGIN EXPORTED_FUNCTIONS */
|
||||
/* USER CODE END EXPORTED_FUNCTIONS */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_CDC_IF_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+364
@@ -0,0 +1,364 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : usbd_desc.c
|
||||
* @version : v1.0_Cube
|
||||
* @brief : This file implements the USB Device descriptors
|
||||
******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics International N.V.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted, provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistribution 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. Neither the name of STMicroelectronics nor the names of other
|
||||
* contributors to this software may be used to endorse or promote products
|
||||
* derived from this software without specific written permission.
|
||||
* 4. This software, including modifications and/or derivative works of this
|
||||
* software, must execute solely and exclusively on microcontroller or
|
||||
* microprocessor devices manufactured by or for STMicroelectronics.
|
||||
* 5. Redistribution and use of this software other than as permitted under
|
||||
* this license is void and will automatically terminate your rights under
|
||||
* this license.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
|
||||
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
|
||||
* SHALL STMICROELECTRONICS OR CONTRIBUTORS 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_desc.h"
|
||||
#include "usbd_conf.h"
|
||||
|
||||
#include "hardware/uhsdr_board.h"
|
||||
|
||||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_DESC
|
||||
* @brief USBD descriptors module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_DESC_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_DESC_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
#define USBD_VID 0x0483
|
||||
#define USBD_LANGID_STRING 1033
|
||||
#define USBD_MANUFACTURER_STRING (uint8_t*)"UHSDR Community (based on STM Drivers)"
|
||||
#define USBD_PID_FS 0x5732
|
||||
#define USBD_PRODUCT_STRING_FS (uint8_t*)"USB Interface "TRX_ID
|
||||
#define USBD_SERIALNUMBER_STRING_FS (uint8_t*)"00000000002A"
|
||||
#define USBD_CONFIGURATION_STRING_FS (uint8_t*)"AUDIO/COM Config"
|
||||
#define USBD_INTERFACE_STRING_FS (uint8_t*)TRX_ID" Audio Com"
|
||||
|
||||
#define USB_SIZ_BOS_DESC 0x0C
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_DESC_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_DESC_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
uint8_t * USBD_FS_DeviceDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
|
||||
uint8_t * USBD_FS_LangIDStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
|
||||
uint8_t * USBD_FS_ManufacturerStrDescriptor ( USBD_SpeedTypeDef speed , uint16_t *length);
|
||||
uint8_t * USBD_FS_ProductStrDescriptor ( USBD_SpeedTypeDef speed , uint16_t *length);
|
||||
uint8_t * USBD_FS_SerialStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
|
||||
uint8_t * USBD_FS_ConfigStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
|
||||
uint8_t * USBD_FS_InterfaceStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
|
||||
|
||||
#ifdef USB_SUPPORT_USER_STRING_DESC
|
||||
uint8_t * USBD_FS_USRStringDesc (USBD_SpeedTypeDef speed, uint8_t idx , uint16_t *length);
|
||||
#endif /* USB_SUPPORT_USER_STRING_DESC */
|
||||
|
||||
#if (USBD_LPM_ENABLED == 1)
|
||||
uint8_t *USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed , uint16_t *length);
|
||||
#endif
|
||||
|
||||
USBD_DescriptorsTypeDef FS_Desc =
|
||||
{
|
||||
USBD_FS_DeviceDescriptor,
|
||||
USBD_FS_LangIDStrDescriptor,
|
||||
USBD_FS_ManufacturerStrDescriptor,
|
||||
USBD_FS_ProductStrDescriptor,
|
||||
USBD_FS_SerialStrDescriptor,
|
||||
USBD_FS_ConfigStrDescriptor,
|
||||
USBD_FS_InterfaceStrDescriptor,
|
||||
#if (USBD_LPM_ENABLED == 1)
|
||||
USBD_FS_USR_BOSDescriptor,
|
||||
#endif
|
||||
};
|
||||
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
/* USB Standard Device Descriptor */
|
||||
__ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
|
||||
{
|
||||
0x12, /*bLength */
|
||||
USB_DESC_TYPE_DEVICE, /*bDescriptorType*/
|
||||
#if (USBD_LPM_ENABLED == 1)
|
||||
0x01, /*bcdUSB */ /* changed to USB version 2.01
|
||||
in order to support LPM L1 suspend
|
||||
resume test of USBCV3.0*/
|
||||
#else
|
||||
0x00, /* bcdUSB */
|
||||
#endif
|
||||
0x02,
|
||||
/* Typically only the bDeviceClass is set at the device level.
|
||||
* Most class specifications choose to identify itself at the interface level
|
||||
* and as a result set the bDeviceClass as 0x00.
|
||||
* This allows for the one device to support multiple classes. */
|
||||
0x00, /*0xEF bDeviceClass*/
|
||||
0x00, /*0x02 bDeviceSubClass*/
|
||||
0x01, /*bDeviceProtocol*/
|
||||
USB_MAX_EP0_SIZE, /*bMaxPacketSize*/
|
||||
LOBYTE(USBD_VID), /*idVendor*/
|
||||
HIBYTE(USBD_VID), /*idVendor*/
|
||||
LOBYTE(USBD_PID_FS), /*idVendor*/
|
||||
HIBYTE(USBD_PID_FS), /*idVendor*/
|
||||
0x00, /*bcdDevice rel. 2.00*/
|
||||
0x02,
|
||||
USBD_IDX_MFC_STR, /*Index of manufacturer string*/
|
||||
USBD_IDX_PRODUCT_STR, /*Index of product string*/
|
||||
USBD_IDX_SERIAL_STR, /*Index of serial number string*/
|
||||
USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/
|
||||
} ;
|
||||
/* USB_DeviceDescriptor */
|
||||
/* BOS descriptor */
|
||||
#if (USBD_LPM_ENABLED == 1)
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
__ALIGN_BEGIN uint8_t USBD_FS_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
|
||||
{
|
||||
0x5,
|
||||
USB_DESC_TYPE_BOS,
|
||||
0xC,
|
||||
0x0,
|
||||
0x1, /* 1 device capability */
|
||||
/* device capability*/
|
||||
0x7,
|
||||
USB_DEVICE_CAPABITY_TYPE,
|
||||
0x2,
|
||||
0x2, /*LPM capability bit set */
|
||||
0x0,
|
||||
0x0,
|
||||
0x0
|
||||
};
|
||||
#endif
|
||||
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END =
|
||||
{
|
||||
USB_LEN_LANGID_STR_DESC,
|
||||
USB_DESC_TYPE_STRING,
|
||||
LOBYTE(USBD_LANGID_STRING),
|
||||
HIBYTE(USBD_LANGID_STRING),
|
||||
};
|
||||
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
__ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_DESC_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_DESC_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBD_FS_DeviceDescriptor
|
||||
* return the device descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer to data length variable
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t * USBD_FS_DeviceDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_FS_DeviceDesc);
|
||||
return USBD_FS_DeviceDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_FS_LangIDStrDescriptor
|
||||
* return the LangID string descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer to data length variable
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t * USBD_FS_LangIDStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_LangIDDesc);
|
||||
return USBD_LangIDDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_FS_ProductStrDescriptor
|
||||
* return the product string descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer to data length variable
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t * USBD_FS_ProductStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
|
||||
{
|
||||
if(speed == 0)
|
||||
{
|
||||
USBD_GetString (USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_GetString (USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
|
||||
}
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_FS_ManufacturerStrDescriptor
|
||||
* return the manufacturer string descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer to data length variable
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t * USBD_FS_ManufacturerStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
|
||||
{
|
||||
USBD_GetString (USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_FS_SerialStrDescriptor
|
||||
* return the serial number string descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer to data length variable
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t * USBD_FS_SerialStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
|
||||
{
|
||||
if(speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
USBD_GetString (USBD_SERIALNUMBER_STRING_FS, USBD_StrDesc, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_GetString (USBD_SERIALNUMBER_STRING_FS, USBD_StrDesc, length);
|
||||
}
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_FS_ConfigStrDescriptor
|
||||
* return the configuration string descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer to data length variable
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t * USBD_FS_ConfigStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
|
||||
{
|
||||
if(speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
USBD_GetString (USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_GetString (USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
|
||||
}
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_HS_InterfaceStrDescriptor
|
||||
* return the interface string descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer to data length variable
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t * USBD_FS_InterfaceStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
|
||||
{
|
||||
if(speed == 0)
|
||||
{
|
||||
USBD_GetString (USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_GetString (USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
|
||||
}
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
#if (USBD_LPM_ENABLED == 1)
|
||||
/**
|
||||
* @brief USBD_FS_USR_BOSDescriptor
|
||||
* return the BOS descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer to data length variable
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed , uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_FS_BOSDesc);
|
||||
return (uint8_t*)USBD_FS_BOSDesc;
|
||||
}
|
||||
#endif
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+189
@@ -0,0 +1,189 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : usbd_desc.h
|
||||
* @version : v1.0_Cube
|
||||
* @brief : Header for usbd_desc file.
|
||||
******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics International N.V.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted, provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistribution 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. Neither the name of STMicroelectronics nor the names of other
|
||||
* contributors to this software may be used to endorse or promote products
|
||||
* derived from this software without specific written permission.
|
||||
* 4. This software, including modifications and/or derivative works of this
|
||||
* software, must execute solely and exclusively on microcontroller or
|
||||
* microprocessor devices manufactured by or for STMicroelectronics.
|
||||
* 5. Redistribution and use of this software other than as permitted under
|
||||
* this license is void and will automatically terminate your rights under
|
||||
* this license.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
|
||||
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
|
||||
* SHALL STMICROELECTRONICS OR CONTRIBUTORS 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBD_DESC__H__
|
||||
#define __USBD_DESC__H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_def.h"
|
||||
|
||||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_DESC
|
||||
* @brief general defines for the usb device library file
|
||||
* @{
|
||||
*/
|
||||
#define AUDIO_DESCRIPTOR_TYPE 0x21
|
||||
#define USB_DEVICE_CLASS_AUDIO 0x01
|
||||
#define AUDIO_SUBCLASS_AUDIOCONTROL 0x01
|
||||
#define AUDIO_SUBCLASS_AUDIOSTREAMING 0x02
|
||||
#define AUDIO_PROTOCOL_UNDEFINED 0x00
|
||||
#define AUDIO_STREAMING_GENERAL 0x01
|
||||
#define AUDIO_STREAMING_FORMAT_TYPE 0x02
|
||||
|
||||
/* Audio Descriptor Types */
|
||||
#define AUDIO_INTERFACE_DESCRIPTOR_TYPE 0x24
|
||||
#define AUDIO_ENDPOINT_DESCRIPTOR_TYPE 0x25
|
||||
|
||||
/* Audio Control Interface Descriptor Subtypes */
|
||||
#define AUDIO_CONTROL_HEADER 0x01
|
||||
#define AUDIO_CONTROL_INPUT_TERMINAL 0x02
|
||||
#define AUDIO_CONTROL_OUTPUT_TERMINAL 0x03
|
||||
#define AUDIO_CONTROL_FEATURE_UNIT 0x06
|
||||
|
||||
#define AUDIO_INTERFACE_DESC_SIZE 9
|
||||
#define USB_AUDIO_DESC_SIZ 0x09
|
||||
#define AUDIO_STANDARD_ENDPOINT_DESC_SIZE 0x09
|
||||
#define AUDIO_STREAMING_ENDPOINT_DESC_SIZE 0x07
|
||||
|
||||
#define AUDIO_SAMPLE_FREQ(frq) (uint8_t)(frq), (uint8_t)((frq >> 8)), (uint8_t)((frq >> 16))
|
||||
#define AUDIO_IN_PACKET (uint32_t)(((USBD_AUDIO_IN_FREQ * USBD_AUDIO_IN_CHANNELS * 2) /1000))
|
||||
#define AUDIO_PACKET_SZE(frq,channels) (uint8_t)(((frq * channels * 2)/1000) & 0xFF), \
|
||||
(uint8_t)((((frq * channels * 2)/1000) >> 8) & 0xFF)
|
||||
#define SAMPLE_FREQ(frq) (uint8_t)(frq), (uint8_t)((frq >> 8)), (uint8_t)((frq >> 16))
|
||||
|
||||
|
||||
#define USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE 0x0B
|
||||
#define USB_INTERFACE_ASSOCIATION_DESC_SIZE 0x08
|
||||
|
||||
#define USB_DEVICE_CLASS_MISCELLANEOUS 0xEF
|
||||
|
||||
|
||||
#define CDC_DESCRIPTOR_TYPE 0x21
|
||||
|
||||
#define DEVICE_CLASS_CDC 0x02
|
||||
#define DEVICE_SUBCLASS_CDC 0x00
|
||||
|
||||
|
||||
#define USB_DEVICE_DESCRIPTOR_TYPE 0x01
|
||||
#define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02
|
||||
#define USB_STRING_DESCRIPTOR_TYPE 0x03
|
||||
#define USB_INTERFACE_DESCRIPTOR_TYPE 0x04
|
||||
#define USB_ENDPOINT_DESCRIPTOR_TYPE 0x05
|
||||
|
||||
#define STANDARD_ENDPOINT_DESC_SIZE 0x09
|
||||
|
||||
#define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
|
||||
#define AUDIO_ENDPOINT_GENERAL 0x01
|
||||
|
||||
#define AUDIO_INPUT_TERMINAL_DESC_SIZE 0x0C
|
||||
#define AUDIO_OUTPUT_TERMINAL_DESC_SIZE 0x09
|
||||
#define AUDIO_STREAMING_INTERFACE_DESC_SIZE 0x07
|
||||
|
||||
#define AUDIO_CONTROL_MUTE 0x0001
|
||||
#define AUDIO_CONTROL_VOLUME 0x0002
|
||||
|
||||
|
||||
|
||||
#define CDC_IN_EP 0x81 /* EP1 for data IN */
|
||||
#define CDC_OUT_EP 0x01 /* EP1 for data OUT */
|
||||
#define CDC_CMD_EP 0x82 /* EP2 for CDC commands */
|
||||
#define CDC_CTRL_IF 0x00
|
||||
#define CDC_DATA_IF 0x01
|
||||
#define CDC_TOTAL_IF_NUM 0x02
|
||||
|
||||
#define AUDIO_OUT_EP 0x02
|
||||
#define AUDIO_IN_EP 0x83
|
||||
#define AUDIO_CTRL_IF 0x02
|
||||
#define AUDIO_OUT_IF 0x03
|
||||
#define AUDIO_IN_IF 0x04
|
||||
#define AUDIO_TOTAL_IF_NUM 0x03
|
||||
|
||||
/** @defgroup USB_DESC_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_DESC_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_DESC_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_DESC_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
extern USBD_DescriptorsTypeDef FS_Desc;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_DESC_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_DESC_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+223
@@ -0,0 +1,223 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_audio_cdc_comp.h
|
||||
* @author MCD Application Team/ mcHF Devel
|
||||
* @version V2.4.2
|
||||
* @date 11-December-2015
|
||||
* @brief header file for the usbd_audio.c file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_AUDIO_COMP_H
|
||||
#define __USB_AUDIO_COMP_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_ioreq.h"
|
||||
#include "usbd_desc.h"
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_AUDIO
|
||||
* @brief This file is the Header file for usbd_audio.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_AUDIO_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
///#define AUDIO_OUT_EP 0x01
|
||||
|
||||
// #define USB_AUDIO_CONFIG_DESC_SIZ 109
|
||||
|
||||
|
||||
#define USBD_AUDIO_OUT_CHANNELS 2
|
||||
#define USBD_AUDIO_IN_CHANNELS 2
|
||||
|
||||
#define USBD_AUDIO_IN_OUT_DIV 1
|
||||
// USBD_IN_AUDIO_IN_OUT_DIV must be set to an integer number between 3 and 1
|
||||
// in order to keep within the limits of the existing code in audio_driver.c audio_rx_processor
|
||||
|
||||
#define USBD_AUDIO_IN_FREQ (USBD_AUDIO_FREQ/USBD_AUDIO_IN_OUT_DIV)
|
||||
|
||||
|
||||
#define AUDIO_CONTROL_MUTE 0x0001
|
||||
|
||||
#define AUDIO_FORMAT_TYPE_I 0x01
|
||||
#define AUDIO_FORMAT_TYPE_III 0x03
|
||||
|
||||
#define AUDIO_ENDPOINT_GENERAL 0x01
|
||||
|
||||
#define AUDIO_REQ_GET_CUR 0x81
|
||||
#define AUDIO_REQ_SET_CUR 0x01
|
||||
|
||||
#define AUDIO_OUT_STREAMING_CTRL 0x02
|
||||
#define AUDIO_IN_STREAMING_CTRL 0x06
|
||||
|
||||
|
||||
|
||||
#define AUDIO_OUT_PACKET (uint32_t)(((USBD_AUDIO_FREQ * 2 * 2) /1000))
|
||||
#define AUDIO_DEFAULT_VOLUME 70
|
||||
|
||||
/* Number of sub-packets in the audio transfer buffer. You can modify this value but always make sure
|
||||
that it is an even number and higher than 3 */
|
||||
#define AUDIO_OUT_PACKET_NUM 16
|
||||
/* Total size of the audio transfer buffer */
|
||||
#define AUDIO_TOTAL_BUF_SIZE ((uint32_t)(AUDIO_OUT_PACKET * AUDIO_OUT_PACKET_NUM))
|
||||
|
||||
/* Audio Commands enumeration */
|
||||
typedef enum
|
||||
{
|
||||
AUDIO_CMD_START = 1,
|
||||
AUDIO_CMD_PLAY,
|
||||
AUDIO_CMD_STOP,
|
||||
AUDIO_CMD_PAUSE
|
||||
}AUDIO_CMD_TypeDef;
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
AUDIO_OFFSET_NONE = 0,
|
||||
AUDIO_OFFSET_HALF,
|
||||
AUDIO_OFFSET_FULL,
|
||||
AUDIO_OFFSET_UNKNOWN,
|
||||
}
|
||||
AUDIO_OffsetTypeDef;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t cmd;
|
||||
uint8_t data[USB_MAX_EP0_SIZE];
|
||||
uint8_t len;
|
||||
uint8_t unit;
|
||||
}
|
||||
USBD_AUDIO_ControlTypeDef;
|
||||
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
__IO uint32_t alt_setting[USBD_MAX_NUM_INTERFACES+1];
|
||||
// uint8_t buffer[AUDIO_TOTAL_BUF_SIZE];
|
||||
// AUDIO_OffsetTypeDef offset;
|
||||
// uint8_t rd_enable;
|
||||
// uint16_t rd_ptr;
|
||||
// uint16_t wr_ptr;
|
||||
USBD_AUDIO_ControlTypeDef control;
|
||||
uint32_t SendFlag;
|
||||
uint32_t PlayFlag;
|
||||
}
|
||||
USBD_AUDIO_HandleTypeDef;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int8_t (*Init) (uint32_t AudioFreq, uint32_t Volume, uint32_t options);
|
||||
int8_t (*DeInit) (uint32_t options);
|
||||
int8_t (*AudioCmd) (uint8_t* pbuf, uint32_t size, uint8_t cmd);
|
||||
int8_t (*VolumeCtl) (uint8_t vol);
|
||||
int8_t (*MuteCtl) (uint8_t cmd);
|
||||
int8_t (*PeriodicTC) (uint8_t cmd);
|
||||
int8_t (*GetState) (void);
|
||||
int8_t (*InVolumeCtl) (uint8_t vol);
|
||||
}USBD_AUDIO_ItfTypeDef;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern USBD_ClassTypeDef USBD_AUDIO;
|
||||
#define USBD_AUDIO_CLASS &USBD_AUDIO
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t USBD_AUDIO_RegisterInterface (USBD_HandleTypeDef *pdev,
|
||||
USBD_AUDIO_ItfTypeDef *fops);
|
||||
|
||||
void USBD_AUDIO_Sync (USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
typedef struct UsbAudioUnit_s
|
||||
{
|
||||
uint8_t cs;
|
||||
uint8_t cn;
|
||||
int16_t min;
|
||||
int16_t max;
|
||||
uint16_t res;
|
||||
int16_t cur;
|
||||
__IO uint8_t* ptr; // pointer to data structure which is used elsewhere to store volume
|
||||
} UsbAudioUnit;
|
||||
|
||||
// In / Out Volume;
|
||||
|
||||
enum
|
||||
{
|
||||
UnitVolumeTX = 0,
|
||||
UnitVolumeRX,
|
||||
UnitMax
|
||||
};
|
||||
extern UsbAudioUnit usbUnits[UnitMax];
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USB_AUDIO_COMP_H */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+957
@@ -0,0 +1,957 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_audio.c
|
||||
* @author MCD Application Team
|
||||
* @version V2.4.2
|
||||
* @date 11-December-2015
|
||||
* @brief This file provides the Audio core functions.
|
||||
*
|
||||
* @verbatim
|
||||
*
|
||||
* ===================================================================
|
||||
* AUDIO Class Description
|
||||
* ===================================================================
|
||||
* This driver manages the Audio Class 1.0 following the "USB Device Class Definition for
|
||||
* Audio Devices V1.0 Mar 18, 98".
|
||||
* This driver implements the following aspects of the specification:
|
||||
* - Device descriptor management
|
||||
* - Configuration descriptor management
|
||||
* - Standard AC Interface Descriptor management
|
||||
* - 1 Audio Streaming Interface (with single channel, PCM, Stereo mode)
|
||||
* - 1 Audio Streaming Endpoint
|
||||
* - 1 Audio Terminal Input (1 channel)
|
||||
* - Audio Class-Specific AC Interfaces
|
||||
* - Audio Class-Specific AS Interfaces
|
||||
* - AudioControl Requests: only SET_CUR and GET_CUR requests are supported (for Mute)
|
||||
* - Audio Feature Unit (limited to Mute control)
|
||||
* - Audio Synchronization type: Asynchronous
|
||||
* - Single fixed audio sampling rate (configurable in usbd_conf.h file)
|
||||
* The current audio class version supports the following audio features:
|
||||
* - Pulse Coded Modulation (PCM) format
|
||||
* - sampling rate: 48KHz.
|
||||
* - Bit resolution: 16
|
||||
* - Number of channels: 2
|
||||
* - No volume control
|
||||
* - Mute/Unmute capability
|
||||
* - Asynchronous Endpoints
|
||||
*
|
||||
* @note In HS mode and when the DMA is used, all variables and data structures
|
||||
* dealing with the DMA during the transaction process should be 32-bit aligned.
|
||||
*
|
||||
*
|
||||
* @endverbatim
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_desc.h"
|
||||
#include "usbd_audio_cdc_comp.h"
|
||||
#include "usbd_ctlreq.h"
|
||||
#include "uhsdr_board.h"
|
||||
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_AUDIO
|
||||
* @brief usbd core module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_AUDIO_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_AUDIO_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_AUDIO_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_AUDIO_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
#define AUDIO_CONTROL_MUTE 0x0001
|
||||
#define AUDIO_CONTROL_VOLUME 0x0002
|
||||
|
||||
#define AUDIO_FORMAT_TYPE_I 0x01
|
||||
#define AUDIO_FORMAT_TYPE_III 0x03
|
||||
|
||||
#define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
|
||||
#define AUDIO_ENDPOINT_GENERAL 0x01
|
||||
|
||||
#define AUDIO_REQ_GET_CUR 0x81
|
||||
#define AUDIO_REQ_GET_MIN 0x82
|
||||
#define AUDIO_REQ_GET_MAX 0x83
|
||||
#define AUDIO_REQ_GET_RES 0x84
|
||||
|
||||
|
||||
// mcHF USB Config below
|
||||
|
||||
/* AudioFreq * DataSize (2 bytes) * NumChannels (Stereo: 2) */
|
||||
#define MCHF_AUDIO_OUT_PACKET (uint32_t)(((USBD_AUDIO_FREQ * USBD_AUDIO_OUT_CHANNELS * 2) /1000))
|
||||
|
||||
|
||||
#define AUDIO_OUT_EP 0x02
|
||||
#define AUDIO_IN_EP 0x83
|
||||
#define AUDIO_CTRL_IF 0x02
|
||||
#define AUDIO_OUT_IF 0x03
|
||||
#define AUDIO_IN_IF 0x04
|
||||
#define AUDIO_TOTAL_IF_NUM 0x03
|
||||
|
||||
|
||||
|
||||
#define OUT_PACKET_NUM 4
|
||||
/* Total size of the audio transfer buffer */
|
||||
#define TOTAL_OUT_BUF_SIZE ((uint32_t)(AUDIO_OUT_PACKET * OUT_PACKET_NUM))
|
||||
|
||||
|
||||
uint8_t IsocOutBuff [TOTAL_OUT_BUF_SIZE * 2];
|
||||
uint8_t* IsocOutWrPtr = IsocOutBuff;
|
||||
uint8_t* IsocOutRdPtr = IsocOutBuff;
|
||||
|
||||
static void audio_out_packet(USBD_HandleTypeDef* pdev, USBD_AUDIO_HandleTypeDef *haudio, USBD_AUDIO_ItfTypeDef *ops)
|
||||
{
|
||||
// mchf_board_green_led(PlayFlag != 0);
|
||||
// during init the first buffer part was already set up to receive data
|
||||
// if we end up here, one chunk of data has arrived. Thats cool. And it is
|
||||
// a good time to hand over the packet to the next layer.
|
||||
// we do that now, since we can be sure that there is at least one packet of
|
||||
// data.
|
||||
// The buffer implementation is quite interesting, since it uses
|
||||
// OUT_PACKET_NUM + 1 slots but allocates OUT_PACKET_NUM * 2 slots
|
||||
// just to be on the save side I guess. Don't know which side this is, though.
|
||||
|
||||
/* If all available buffers have been consumed, stop playing */
|
||||
if (IsocOutWrPtr >= (IsocOutBuff + (AUDIO_OUT_PACKET * OUT_PACKET_NUM)))
|
||||
{
|
||||
/* All buffers are full: roll back */
|
||||
IsocOutWrPtr = IsocOutBuff;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Increment the buffer pointer */
|
||||
IsocOutWrPtr += AUDIO_OUT_PACKET;
|
||||
}
|
||||
|
||||
/* Toggle the frame index */
|
||||
/*
|
||||
((USB_OTG_CORE_HANDLE*)pdev)->dev.out_ep[epnum].even_odd_frame =
|
||||
(((USB_OTG_CORE_HANDLE*)pdev)->dev.out_ep[epnum].even_odd_frame)? 0:1;
|
||||
|
||||
*/
|
||||
/* Prepare Out endpoint to receive next audio packet */
|
||||
USBD_LL_PrepareReceive(pdev,
|
||||
AUDIO_OUT_EP,
|
||||
(uint8_t*)(IsocOutWrPtr),
|
||||
AUDIO_OUT_PACKET);
|
||||
|
||||
if (haudio->PlayFlag)
|
||||
{
|
||||
haudio->PlayFlag = 5;
|
||||
/* Start playing received packet */
|
||||
ops->AudioCmd(IsocOutRdPtr,
|
||||
AUDIO_OUT_PACKET,
|
||||
AUDIO_CMD_PLAY);
|
||||
|
||||
/* Increment the Buffer pointer or roll it back when all buffers all full */
|
||||
if (IsocOutRdPtr >= (IsocOutBuff + (AUDIO_OUT_PACKET * OUT_PACKET_NUM)))
|
||||
{
|
||||
/* Roll back to the start of buffer */
|
||||
IsocOutRdPtr = IsocOutBuff;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Increment to the next sub-buffer */
|
||||
IsocOutRdPtr += AUDIO_OUT_PACKET;
|
||||
}
|
||||
}
|
||||
|
||||
/* Increment the Buffer pointer or roll it back when all buffers are full */
|
||||
|
||||
/* Trigger the start of streaming only when half buffer is full */
|
||||
if (haudio->PlayFlag == 0)
|
||||
{
|
||||
if (IsocOutWrPtr >= (IsocOutBuff + ((AUDIO_OUT_PACKET * OUT_PACKET_NUM) / 2)))
|
||||
{
|
||||
/* Enable start of Streaming */
|
||||
haudio->PlayFlag = 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void audio_out_packet_prepare(USBD_HandleTypeDef* pdev, USBD_AUDIO_HandleTypeDef *haudio, USBD_AUDIO_ItfTypeDef *ops)
|
||||
{
|
||||
if (haudio->PlayFlag)
|
||||
{
|
||||
haudio->PlayFlag--;
|
||||
if (haudio->PlayFlag == 0)
|
||||
{
|
||||
/* Pause the audio stream */
|
||||
ops->AudioCmd(IsocOutBuff, /* Samples buffer pointer */
|
||||
AUDIO_OUT_PACKET, /* Number of samples in Bytes */
|
||||
AUDIO_CMD_PAUSE); /* Command to be processed */
|
||||
|
||||
/* Stop entering play loop */
|
||||
haudio->PlayFlag = 0;
|
||||
|
||||
/* Reset buffer pointers */
|
||||
IsocOutRdPtr = IsocOutBuff;
|
||||
IsocOutWrPtr = IsocOutBuff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// local stuff
|
||||
#define USB_AUDIO_IN_NUM_BUF 8
|
||||
#define USB_AUDIO_IN_PKT_SIZE (AUDIO_IN_PACKET/2)
|
||||
// size in samples not size in bytes
|
||||
#define USB_AUDIO_IN_BUF_SIZE (USB_AUDIO_IN_NUM_BUF * USB_AUDIO_IN_PKT_SIZE)
|
||||
|
||||
|
||||
|
||||
|
||||
static int16_t Silence[USB_AUDIO_IN_PKT_SIZE];
|
||||
|
||||
typedef struct {
|
||||
int16_t buffer[USB_AUDIO_IN_BUF_SIZE]; //buffer for filtered PCM data from Recv.
|
||||
uint16_t buffer_tail;
|
||||
uint16_t buffer_head;
|
||||
uint16_t buffer_overflow;
|
||||
} audio_buffer_t;
|
||||
|
||||
static volatile audio_buffer_t in;
|
||||
|
||||
void UsbdAudio_PutSample(int16_t sample)
|
||||
{
|
||||
in.buffer[in.buffer_head] = sample;
|
||||
in.buffer_head= (in.buffer_head + 1) %USB_AUDIO_IN_BUF_SIZE;
|
||||
// now test buffer full
|
||||
if (in.buffer_head == in.buffer_tail)
|
||||
{
|
||||
// ok. We loose data now, should never ever happen, but so what
|
||||
// will cause minor distortion if only a few bytes.
|
||||
in.buffer_overflow++;
|
||||
}
|
||||
}
|
||||
|
||||
volatile int16_t* audio_in_buffer_next_pkt()
|
||||
{
|
||||
int16_t *retval;
|
||||
uint16_t room;
|
||||
uint16_t temp_head = in.buffer_head;
|
||||
room = ((((temp_head < in.buffer_tail)?USB_AUDIO_IN_BUF_SIZE:0) + temp_head) - in.buffer_tail);
|
||||
if (room >= USB_AUDIO_IN_PKT_SIZE)
|
||||
{
|
||||
retval = (int16_t*)&in.buffer[in.buffer_tail];
|
||||
}
|
||||
else
|
||||
{
|
||||
retval = NULL;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
void audio_in_buffer_pop_pkt(int16_t* ptr)
|
||||
{
|
||||
if (ptr)
|
||||
{
|
||||
// there was data and pkt has been used
|
||||
// free the space
|
||||
in.buffer_tail = (in.buffer_tail+USB_AUDIO_IN_PKT_SIZE)%USB_AUDIO_IN_BUF_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
static void audio_in_fill_ep_fifo(void *pdev)
|
||||
{
|
||||
uint8_t *pkt = (uint8_t*)audio_in_buffer_next_pkt();
|
||||
static uint16_t fill_buffer = (USB_AUDIO_IN_NUM_BUF/2) + 1;
|
||||
|
||||
if (fill_buffer == 0 && pkt)
|
||||
{
|
||||
USBD_LL_Transmit(pdev,AUDIO_IN_EP, pkt, AUDIO_IN_PACKET);
|
||||
audio_in_buffer_pop_pkt((int16_t*)pkt);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fill_buffer == 0)
|
||||
{
|
||||
fill_buffer = USB_AUDIO_IN_NUM_BUF/2 + 1;
|
||||
}
|
||||
fill_buffer--;
|
||||
// transmit something if we do not have enough in buffer
|
||||
USBD_LL_Transmit(pdev,AUDIO_IN_EP, (uint8_t*)Silence, AUDIO_IN_PACKET);
|
||||
}
|
||||
}
|
||||
|
||||
UsbAudioUnit usbUnits[UnitMax] =
|
||||
{
|
||||
{
|
||||
.cs = AUDIO_CONTROL_VOLUME,
|
||||
.cn = AUDIO_OUT_STREAMING_CTRL,
|
||||
.min = -31 * 0x100,
|
||||
.max = 0 * 0x100,
|
||||
.res = 0x100,
|
||||
.cur = -16* 0x100,
|
||||
.ptr = &ts.tx_gain[TX_AUDIO_DIG]
|
||||
},
|
||||
{
|
||||
.cs = AUDIO_CONTROL_VOLUME,
|
||||
.cn = AUDIO_IN_STREAMING_CTRL,
|
||||
.min = -31 * 0x100,
|
||||
.max = 0 * 0x100,
|
||||
.res = 0x100,
|
||||
.cur = -16* 0x100,
|
||||
.ptr = &ts.rx_gain[RX_AUDIO_DIG].value
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
static uint8_t USBD_AUDIO_Init (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_AUDIO_DeInit (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_AUDIO_Setup (USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static uint8_t *USBD_AUDIO_GetCfgDesc (uint16_t *length);
|
||||
|
||||
static uint8_t *USBD_AUDIO_GetDeviceQualifierDesc (uint16_t *length);
|
||||
|
||||
static uint8_t USBD_AUDIO_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_AUDIO_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_AUDIO_EP0_RxReady (USBD_HandleTypeDef *pdev);
|
||||
|
||||
static uint8_t USBD_AUDIO_EP0_TxReady (USBD_HandleTypeDef *pdev);
|
||||
|
||||
static uint8_t USBD_AUDIO_SOF (USBD_HandleTypeDef *pdev);
|
||||
|
||||
static uint8_t USBD_AUDIO_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_AUDIO_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
static void AUDIO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
|
||||
static void AUDIO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_AUDIO_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
USBD_ClassTypeDef USBD_AUDIO =
|
||||
{
|
||||
USBD_AUDIO_Init,
|
||||
USBD_AUDIO_DeInit,
|
||||
USBD_AUDIO_Setup,
|
||||
USBD_AUDIO_EP0_TxReady,
|
||||
USBD_AUDIO_EP0_RxReady,
|
||||
USBD_AUDIO_DataIn,
|
||||
USBD_AUDIO_DataOut,
|
||||
USBD_AUDIO_SOF,
|
||||
USBD_AUDIO_IsoINIncomplete,
|
||||
USBD_AUDIO_IsoOutIncomplete,
|
||||
USBD_AUDIO_GetCfgDesc,
|
||||
USBD_AUDIO_GetCfgDesc,
|
||||
USBD_AUDIO_GetCfgDesc,
|
||||
USBD_AUDIO_GetDeviceQualifierDesc,
|
||||
};
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_AUDIO_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END=
|
||||
{
|
||||
USB_LEN_DEV_QUALIFIER_DESC,
|
||||
USB_DESC_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_AUDIO_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBD_AUDIO_Init
|
||||
* Initialize the AUDIO interface
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
|
||||
static uint8_t USBD_AUDIO_Init (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
{
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
|
||||
/* Open EP OUT */
|
||||
USBD_LL_OpenEP(pdev,
|
||||
AUDIO_OUT_EP,
|
||||
USBD_EP_TYPE_ISOC,
|
||||
AUDIO_OUT_PACKET);
|
||||
|
||||
/* Open EP IN */
|
||||
USBD_LL_OpenEP(pdev,
|
||||
AUDIO_IN_EP,
|
||||
USBD_EP_TYPE_ISOC,
|
||||
AUDIO_IN_PACKET);
|
||||
|
||||
|
||||
/* Allocate Audio structure */
|
||||
pdev->pClassData = USBD_malloc(sizeof (USBD_AUDIO_HandleTypeDef));
|
||||
|
||||
if(pdev->pClassData == NULL)
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
||||
memset(haudio,0,sizeof(USBD_AUDIO_HandleTypeDef));
|
||||
#if 0
|
||||
haudio->offset = AUDIO_OFFSET_UNKNOWN;
|
||||
haudio->wr_ptr = 0;
|
||||
haudio->rd_ptr = 0;
|
||||
haudio->rd_enable = 0;
|
||||
#endif
|
||||
/* Initialize the Audio output Hardware layer */
|
||||
if (((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->Init(USBD_AUDIO_FREQ, AUDIO_DEFAULT_VOLUME, 0) != USBD_OK)
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
|
||||
/* Prepare Out endpoint to receive 1st packet */
|
||||
USBD_LL_PrepareReceive(pdev,
|
||||
AUDIO_OUT_EP,
|
||||
IsocOutBuff,
|
||||
AUDIO_OUT_PACKET);
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_AUDIO_Init
|
||||
* DeInitialize the AUDIO layer
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_DeInit (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
{
|
||||
|
||||
/* Open EP OUT */
|
||||
USBD_LL_CloseEP(pdev,
|
||||
AUDIO_OUT_EP);
|
||||
|
||||
/* Open EP OUT */
|
||||
USBD_LL_CloseEP(pdev,
|
||||
AUDIO_IN_EP);
|
||||
|
||||
/* DeInit physical Interface components */
|
||||
if(pdev->pClassData != NULL)
|
||||
{
|
||||
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->DeInit(0);
|
||||
USBD_free(pdev->pClassData);
|
||||
pdev->pClassData = NULL;
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_AUDIO_Setup
|
||||
* Handle the AUDIO specific requests
|
||||
* @param pdev: instance
|
||||
* @param req: usb requests
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_Setup (USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
uint8_t ret = USBD_OK;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef*)pdev->pClassData;
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
case USB_REQ_TYPE_CLASS :
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case AUDIO_REQ_GET_MIN:
|
||||
case AUDIO_REQ_GET_MAX:
|
||||
case AUDIO_REQ_GET_RES:
|
||||
case AUDIO_REQ_GET_CUR:
|
||||
AUDIO_REQ_GetCurrent(pdev, req);
|
||||
break;
|
||||
|
||||
case AUDIO_REQ_SET_CUR:
|
||||
AUDIO_REQ_SetCurrent(pdev, req);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_GET_DESCRIPTOR:
|
||||
// handled at composite level
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_INTERFACE :
|
||||
USBD_CtlSendData (pdev,
|
||||
(uint8_t *)&(haudio->alt_setting),
|
||||
1);
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE :
|
||||
if ((uint8_t)(req->wIndex) <= USBD_MAX_NUM_INTERFACES)
|
||||
{
|
||||
haudio->alt_setting[req->wIndex] = (uint8_t)(req->wValue);
|
||||
|
||||
if (haudio->alt_setting[AUDIO_IN_IF] == 1)
|
||||
{
|
||||
if (!haudio->SendFlag)
|
||||
{
|
||||
haudio->SendFlag = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
haudio->SendFlag = 0;
|
||||
USBD_LL_FlushEP(pdev,AUDIO_IN_EP);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Call the error management function (command will be nacked */
|
||||
USBD_CtlError (pdev, req);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_AUDIO_GetCfgDesc
|
||||
* return configuration descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_AUDIO_GetCfgDesc (uint16_t *length)
|
||||
{
|
||||
*length = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_AUDIO_DataIn
|
||||
* handle data IN Stage
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_DataIn (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
{
|
||||
uint8_t retval = USBD_OK;
|
||||
if (epnum == (AUDIO_IN_EP & 0x7f))
|
||||
{
|
||||
USBD_LL_FlushEP(pdev,AUDIO_IN_EP); //very important!!!
|
||||
audio_in_fill_ep_fifo(pdev);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_AUDIO_EP0_RxReady
|
||||
* handle EP0 Rx Ready event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_EP0_RxReady (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
uint8_t retval = USBD_OK;
|
||||
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef*)pdev->pClassData;
|
||||
|
||||
if (haudio->control.cmd == AUDIO_REQ_SET_CUR)
|
||||
{/* In this driver, to simplify code, only SET_CUR request is managed */
|
||||
|
||||
if (haudio->control.unit == AUDIO_OUT_STREAMING_CTRL)
|
||||
{
|
||||
// ((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->MuteCtl(haudio->control.data[0]);
|
||||
int16_t val = (int16_t)((uint16_t)haudio->control.data[0] | ((uint16_t)haudio->control.data[1])<<8) ;
|
||||
retval =((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->VolumeCtl((val/0x100)+31);
|
||||
usbUnits[UnitVolumeTX].cur = val;
|
||||
|
||||
haudio->control.cmd = 0;
|
||||
haudio->control.len = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// ((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->MuteCtl(haudio->control.data[0]);
|
||||
int16_t val = (int16_t)((uint16_t)haudio->control.data[0] | ((uint16_t)haudio->control.data[1])<<8) ;
|
||||
retval =((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->InVolumeCtl((val/0x100)+31);
|
||||
usbUnits[UnitVolumeTX].cur = val;
|
||||
|
||||
haudio->control.cmd = 0;
|
||||
haudio->control.len = 0;
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
/**
|
||||
* @brief USBD_AUDIO_EP0_TxReady
|
||||
* handle EP0 TRx Ready event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_EP0_TxReady (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Only OUT control data are processed */
|
||||
return USBD_OK;
|
||||
}
|
||||
/**
|
||||
* @brief USBD_AUDIO_SOF
|
||||
* handle SOF event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_SOF (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_AUDIO_HandleTypeDef* haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
||||
|
||||
if (haudio->SendFlag == 1)
|
||||
{
|
||||
USBD_LL_FlushEP(pdev,AUDIO_IN_EP);//very important!!!
|
||||
audio_in_fill_ep_fifo(pdev);
|
||||
haudio->SendFlag = 2;
|
||||
}
|
||||
|
||||
audio_out_packet_prepare(pdev, haudio, (USBD_AUDIO_ItfTypeDef *)pdev->pUserData);
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* @brief USBD_AUDIO_SOF
|
||||
* handle SOF event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
void USBD_AUDIO_Sync (USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset)
|
||||
{
|
||||
int8_t shift = 0;
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef*)pdev->pClassData;
|
||||
|
||||
haudio->offset = offset;
|
||||
|
||||
|
||||
if(haudio->rd_enable == 1)
|
||||
{
|
||||
haudio->rd_ptr += AUDIO_TOTAL_BUF_SIZE/2;
|
||||
|
||||
if (haudio->rd_ptr == AUDIO_TOTAL_BUF_SIZE)
|
||||
{
|
||||
/* roll back */
|
||||
haudio->rd_ptr = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(haudio->rd_ptr > haudio->wr_ptr)
|
||||
{
|
||||
if((haudio->rd_ptr - haudio->wr_ptr) < AUDIO_OUT_PACKET)
|
||||
{
|
||||
shift = -4;
|
||||
}
|
||||
else if((haudio->rd_ptr - haudio->wr_ptr) > (AUDIO_TOTAL_BUF_SIZE - AUDIO_OUT_PACKET))
|
||||
{
|
||||
shift = 4;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if((haudio->wr_ptr - haudio->rd_ptr) < AUDIO_OUT_PACKET)
|
||||
{
|
||||
shift = 4;
|
||||
}
|
||||
else if((haudio->wr_ptr - haudio->rd_ptr) > (AUDIO_TOTAL_BUF_SIZE - AUDIO_OUT_PACKET))
|
||||
{
|
||||
shift = -4;
|
||||
}
|
||||
}
|
||||
|
||||
if(haudio->offset == AUDIO_OFFSET_FULL)
|
||||
{
|
||||
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->AudioCmd(&haudio->buffer[0],
|
||||
AUDIO_TOTAL_BUF_SIZE/2 - shift,
|
||||
AUDIO_CMD_PLAY);
|
||||
haudio->offset = AUDIO_OFFSET_NONE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/**
|
||||
* @brief USBD_AUDIO_IsoINIncomplete
|
||||
* handle data ISO IN Incomplete event
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
/**
|
||||
* @brief USBD_AUDIO_IsoOutIncomplete
|
||||
* handle data ISO OUT Incomplete event
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
/**
|
||||
* @brief USBD_AUDIO_DataOut
|
||||
* handle data OUT Stage
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_DataOut (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
{
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef*)pdev->pClassData;
|
||||
|
||||
if (epnum == AUDIO_OUT_EP)
|
||||
{
|
||||
|
||||
audio_out_packet(pdev, haudio, (USBD_AUDIO_ItfTypeDef *)pdev->pUserData);
|
||||
|
||||
#if 0
|
||||
/* Increment the Buffer pointer or roll it back when all buffers are full */
|
||||
|
||||
haudio->wr_ptr += AUDIO_OUT_PACKET;
|
||||
|
||||
if (haudio->wr_ptr == AUDIO_TOTAL_BUF_SIZE)
|
||||
{/* All buffers are full: roll back */
|
||||
haudio->wr_ptr = 0;
|
||||
|
||||
if(haudio->offset == AUDIO_OFFSET_UNKNOWN)
|
||||
{
|
||||
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->AudioCmd(&haudio->buffer[0],
|
||||
AUDIO_TOTAL_BUF_SIZE/2,
|
||||
AUDIO_CMD_START);
|
||||
haudio->offset = AUDIO_OFFSET_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
if(haudio->rd_enable == 0)
|
||||
{
|
||||
if (haudio->wr_ptr == (AUDIO_TOTAL_BUF_SIZE / 2))
|
||||
{
|
||||
haudio->rd_enable = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Prepare Out endpoint to receive next audio packet */
|
||||
USBD_LL_PrepareReceive(pdev,
|
||||
AUDIO_OUT_EP,
|
||||
&haudio->buffer[haudio->wr_ptr],
|
||||
AUDIO_OUT_PACKET);
|
||||
#endif
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief AUDIO_Req_GetCurrent
|
||||
* Handles the GET_CUR Audio control request.
|
||||
* @param pdev: instance
|
||||
* @param req: setup class request
|
||||
* @retval status
|
||||
*/
|
||||
static void AUDIO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
||||
|
||||
UsbAudioUnit *unit = &usbUnits[HIBYTE(req->wIndex) == AUDIO_OUT_STREAMING_CTRL?UnitVolumeTX:UnitVolumeRX];
|
||||
// find the right unit by index
|
||||
|
||||
memset(haudio->control.data, 0, 64);
|
||||
int16_t* word =(int16_t*) &haudio->control.data[0];
|
||||
|
||||
switch(req->bRequest)
|
||||
{
|
||||
case AUDIO_REQ_GET_MIN:
|
||||
word[0] = unit->min;
|
||||
break;
|
||||
case AUDIO_REQ_GET_MAX:
|
||||
word[0] = unit->max;
|
||||
break;
|
||||
case AUDIO_REQ_GET_RES:
|
||||
word[0] = unit->res;
|
||||
break;
|
||||
case AUDIO_REQ_GET_CUR:
|
||||
// we load the current value from the application layer and convert it.
|
||||
// not the most beautiful approach
|
||||
unit->cur = (((int16_t)(*unit->ptr))-31)*0x100;
|
||||
word[0] = unit->cur;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Send the current mute state */
|
||||
USBD_CtlSendData (pdev,
|
||||
haudio->control.data,
|
||||
req->wLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief AUDIO_Req_SetCurrent
|
||||
* Handles the SET_CUR Audio control request.
|
||||
* @param pdev: instance
|
||||
* @param req: setup class request
|
||||
* @retval status
|
||||
*/
|
||||
static void AUDIO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef*)pdev->pClassData;
|
||||
|
||||
if (req->wLength)
|
||||
{
|
||||
/* Prepare the reception of the buffer over EP0 */
|
||||
USBD_CtlPrepareRx (pdev,
|
||||
haudio->control.data,
|
||||
req->wLength);
|
||||
|
||||
haudio->control.cmd = AUDIO_REQ_SET_CUR; /* Set the request value */
|
||||
haudio->control.len = req->wLength; /* Set the request data length */
|
||||
haudio->control.unit = HIBYTE(req->wIndex); /* Set the request target unit */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief DeviceQualifierDescriptor
|
||||
* return Device Qualifier descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_AUDIO_GetDeviceQualifierDesc (uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_AUDIO_DeviceQualifierDesc);
|
||||
return USBD_AUDIO_DeviceQualifierDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_AUDIO_RegisterInterface
|
||||
* @param fops: Audio interface callback
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_AUDIO_RegisterInterface (USBD_HandleTypeDef *pdev,
|
||||
USBD_AUDIO_ItfTypeDef *fops)
|
||||
{
|
||||
if(fops != NULL)
|
||||
{
|
||||
pdev->pUserData= fops;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+180
@@ -0,0 +1,180 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_cdc.h
|
||||
* @author MCD Application Team
|
||||
* @version V2.4.2
|
||||
* @date 11-December-2015
|
||||
* @brief header file for the usbd_cdc.c file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_CDC_H
|
||||
#define __USB_CDC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_ioreq.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup usbd_cdc
|
||||
* @brief This file is the Header file for usbd_cdc.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup usbd_cdc_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
#define CDC_IN_EP 0x81 /* EP1 for data IN */
|
||||
#define CDC_OUT_EP 0x01 /* EP1 for data OUT */
|
||||
#define CDC_CMD_EP 0x82 /* EP2 for CDC commands */
|
||||
|
||||
/* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */
|
||||
#define CDC_DATA_HS_MAX_PACKET_SIZE 512 /* Endpoint IN & OUT Packet size */
|
||||
#define CDC_DATA_FS_MAX_PACKET_SIZE 64 /* Endpoint IN & OUT Packet size */
|
||||
#define CDC_CMD_PACKET_SIZE 8 /* Control Endpoint Packet size */
|
||||
|
||||
#define USB_CDC_CONFIG_DESC_SIZ 67
|
||||
#define CDC_DATA_HS_IN_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE
|
||||
#define CDC_DATA_HS_OUT_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE
|
||||
|
||||
#define CDC_DATA_FS_IN_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE
|
||||
#define CDC_DATA_FS_OUT_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE
|
||||
|
||||
/*---------------------------------------------------------------------*/
|
||||
/* CDC definitions */
|
||||
/*---------------------------------------------------------------------*/
|
||||
#define CDC_SEND_ENCAPSULATED_COMMAND 0x00
|
||||
#define CDC_GET_ENCAPSULATED_RESPONSE 0x01
|
||||
#define CDC_SET_COMM_FEATURE 0x02
|
||||
#define CDC_GET_COMM_FEATURE 0x03
|
||||
#define CDC_CLEAR_COMM_FEATURE 0x04
|
||||
#define CDC_SET_LINE_CODING 0x20
|
||||
#define CDC_GET_LINE_CODING 0x21
|
||||
#define CDC_SET_CONTROL_LINE_STATE 0x22
|
||||
#define CDC_SEND_BREAK 0x23
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t bitrate;
|
||||
uint8_t format;
|
||||
uint8_t paritytype;
|
||||
uint8_t datatype;
|
||||
}USBD_CDC_LineCodingTypeDef;
|
||||
|
||||
typedef struct _USBD_CDC_Itf
|
||||
{
|
||||
int8_t (* Init) (void);
|
||||
int8_t (* DeInit) (void);
|
||||
int8_t (* Control) (uint8_t, uint8_t * , uint16_t);
|
||||
int8_t (* Receive) (uint8_t *, uint32_t *);
|
||||
int8_t (* SOF) (USBD_HandleTypeDef *pdev);
|
||||
int8_t (* DataIn) (USBD_HandleTypeDef *pdev);
|
||||
}USBD_CDC_ItfTypeDef;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t data[CDC_DATA_HS_MAX_PACKET_SIZE/4]; /* Force 32bits alignment */
|
||||
uint8_t CmdOpCode;
|
||||
uint8_t CmdLength;
|
||||
uint8_t *RxBuffer;
|
||||
uint8_t *TxBuffer;
|
||||
uint32_t RxLength;
|
||||
uint32_t TxLength;
|
||||
|
||||
__IO uint32_t TxState;
|
||||
__IO uint32_t RxState;
|
||||
}
|
||||
USBD_CDC_HandleTypeDef;
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern USBD_ClassTypeDef USBD_CDC;
|
||||
#define USBD_CDC_CLASS &USBD_CDC
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t USBD_CDC_RegisterInterface (USBD_HandleTypeDef *pdev,
|
||||
USBD_CDC_ItfTypeDef *fops);
|
||||
|
||||
uint8_t USBD_CDC_SetTxBuffer (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuff,
|
||||
uint16_t length);
|
||||
|
||||
uint8_t USBD_CDC_SetRxBuffer (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuff);
|
||||
|
||||
uint8_t USBD_CDC_ReceivePacket (USBD_HandleTypeDef *pdev);
|
||||
|
||||
uint8_t USBD_CDC_TransmitPacket (USBD_HandleTypeDef *pdev);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USB_CDC_H */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+955
@@ -0,0 +1,955 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_cdc.c
|
||||
* @author MCD Application Team
|
||||
* @version V2.4.2
|
||||
* @date 11-December-2015
|
||||
* @brief This file provides the high layer firmware functions to manage the
|
||||
* following functionalities of the USB CDC Class:
|
||||
* - Initialization and Configuration of high and low layer
|
||||
* - Enumeration as CDC Device (and enumeration for each implemented memory interface)
|
||||
* - OUT/IN data transfer
|
||||
* - Command IN transfer (class requests management)
|
||||
* - Error management
|
||||
*
|
||||
* @verbatim
|
||||
*
|
||||
* ===================================================================
|
||||
* CDC Class Driver Description
|
||||
* ===================================================================
|
||||
* This driver manages the "Universal Serial Bus Class Definitions for Communications Devices
|
||||
* Revision 1.2 November 16, 2007" and the sub-protocol specification of "Universal Serial Bus
|
||||
* Communications Class Subclass Specification for PSTN Devices Revision 1.2 February 9, 2007"
|
||||
* This driver implements the following aspects of the specification:
|
||||
* - Device descriptor management
|
||||
* - Configuration descriptor management
|
||||
* - Enumeration as CDC device with 2 data endpoints (IN and OUT) and 1 command endpoint (IN)
|
||||
* - Requests management (as described in section 6.2 in specification)
|
||||
* - Abstract Control Model compliant
|
||||
* - Union Functional collection (using 1 IN endpoint for control)
|
||||
* - Data interface class
|
||||
*
|
||||
* These aspects may be enriched or modified for a specific user application.
|
||||
*
|
||||
* This driver doesn't implement the following aspects of the specification
|
||||
* (but it is possible to manage these features with some modifications on this driver):
|
||||
* - Any class-specific aspect relative to communication classes should be managed by user application.
|
||||
* - All communication classes other than PSTN are not managed
|
||||
*
|
||||
* @endverbatim
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_desc.h"
|
||||
#include "usbd_cdc.h"
|
||||
#include "usbd_cdc_if.h"
|
||||
#include "usbd_ctlreq.h"
|
||||
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CDC
|
||||
* @brief usbd core module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CDC_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CDC_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CDC_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CDC_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
|
||||
static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static uint8_t USBD_CDC_DataIn (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev);
|
||||
|
||||
static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length);
|
||||
|
||||
static uint8_t *USBD_CDC_GetHSCfgDesc (uint16_t *length);
|
||||
|
||||
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length);
|
||||
|
||||
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length);
|
||||
|
||||
uint8_t *USBD_CDC_GetDeviceQualifierDescriptor (uint16_t *length);
|
||||
|
||||
static uint8_t USBD_CDC_SOF (USBD_HandleTypeDef *pdev);
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_CDC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
||||
{
|
||||
USB_LEN_DEV_QUALIFIER_DESC,
|
||||
USB_DESC_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CDC_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/* CDC interface class callbacks structure */
|
||||
USBD_ClassTypeDef USBD_CDC =
|
||||
{
|
||||
USBD_CDC_Init,
|
||||
USBD_CDC_DeInit,
|
||||
USBD_CDC_Setup,
|
||||
NULL, /* EP0_TxSent, */
|
||||
USBD_CDC_EP0_RxReady,
|
||||
USBD_CDC_DataIn,
|
||||
USBD_CDC_DataOut,
|
||||
USBD_CDC_SOF,
|
||||
NULL,
|
||||
NULL,
|
||||
USBD_CDC_GetHSCfgDesc,
|
||||
USBD_CDC_GetFSCfgDesc,
|
||||
USBD_CDC_GetOtherSpeedCfgDesc,
|
||||
USBD_CDC_GetDeviceQualifierDescriptor,
|
||||
};
|
||||
|
||||
/* USB CDC device Configuration Descriptor */
|
||||
__ALIGN_BEGIN uint8_t USBD_CDC_CfgHSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
{
|
||||
/*Configuration Descriptor*/
|
||||
0x09, /* bLength: Configuration Descriptor size */
|
||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||
USB_CDC_CONFIG_DESC_SIZ, /* wTotalLength:no of returned bytes */
|
||||
0x00,
|
||||
0x02, /* bNumInterfaces: 2 interface */
|
||||
0x01, /* bConfigurationValue: Configuration value */
|
||||
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
|
||||
0xC0, /* bmAttributes: self powered */
|
||||
0x32, /* MaxPower 0 mA */
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*Interface Descriptor */
|
||||
0x09, /* bLength: Interface Descriptor size */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */
|
||||
/* Interface descriptor type */
|
||||
0x00, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x01, /* bNumEndpoints: One endpoints used */
|
||||
0x02, /* bInterfaceClass: Communication Interface Class */
|
||||
0x02, /* bInterfaceSubClass: Abstract Control Model */
|
||||
0x01, /* bInterfaceProtocol: Common AT commands */
|
||||
0x00, /* iInterface: */
|
||||
|
||||
/*Header Functional Descriptor*/
|
||||
0x05, /* bLength: Endpoint Descriptor size */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x00, /* bDescriptorSubtype: Header Func Desc */
|
||||
0x10, /* bcdCDC: spec release number */
|
||||
0x01,
|
||||
|
||||
/*Call Management Functional Descriptor*/
|
||||
0x05, /* bFunctionLength */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x01, /* bDescriptorSubtype: Call Management Func Desc */
|
||||
0x00, /* bmCapabilities: D0+D1 */
|
||||
0x01, /* bDataInterface: 1 */
|
||||
|
||||
/*ACM Functional Descriptor*/
|
||||
0x04, /* bFunctionLength */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x02, /* bDescriptorSubtype: Abstract Control Management desc */
|
||||
0x02, /* bmCapabilities */
|
||||
|
||||
/*Union Functional Descriptor*/
|
||||
0x05, /* bFunctionLength */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x06, /* bDescriptorSubtype: Union func desc */
|
||||
0x00, /* bMasterInterface: Communication class interface */
|
||||
0x01, /* bSlaveInterface0: Data Class Interface */
|
||||
|
||||
/*Endpoint 2 Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||
CDC_CMD_EP, /* bEndpointAddress */
|
||||
0x03, /* bmAttributes: Interrupt */
|
||||
LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */
|
||||
HIBYTE(CDC_CMD_PACKET_SIZE),
|
||||
0x10, /* bInterval: */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*Data class interface descriptor*/
|
||||
0x09, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */
|
||||
0x01, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x02, /* bNumEndpoints: Two endpoints used */
|
||||
0x0A, /* bInterfaceClass: CDC */
|
||||
0x00, /* bInterfaceSubClass: */
|
||||
0x00, /* bInterfaceProtocol: */
|
||||
0x00, /* iInterface: */
|
||||
|
||||
/*Endpoint OUT Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||
CDC_OUT_EP, /* bEndpointAddress */
|
||||
0x02, /* bmAttributes: Bulk */
|
||||
LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */
|
||||
HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE),
|
||||
0x00, /* bInterval: ignore for Bulk transfer */
|
||||
|
||||
/*Endpoint IN Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||
CDC_IN_EP, /* bEndpointAddress */
|
||||
0x02, /* bmAttributes: Bulk */
|
||||
LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */
|
||||
HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE),
|
||||
0x00 /* bInterval: ignore for Bulk transfer */
|
||||
} ;
|
||||
|
||||
|
||||
/* USB CDC device Configuration Descriptor */
|
||||
__ALIGN_BEGIN uint8_t USBD_CDC_CfgFSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
{
|
||||
/*Configuration Descriptor*/
|
||||
0x09, /* bLength: Configuration Descriptor size */
|
||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||
USB_CDC_CONFIG_DESC_SIZ, /* wTotalLength:no of returned bytes */
|
||||
0x00,
|
||||
0x02, /* bNumInterfaces: 2 interface */
|
||||
0x01, /* bConfigurationValue: Configuration value */
|
||||
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
|
||||
0xC0, /* bmAttributes: self powered */
|
||||
0x32, /* MaxPower 0 mA */
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*Interface Descriptor */
|
||||
0x09, /* bLength: Interface Descriptor size */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */
|
||||
/* Interface descriptor type */
|
||||
0x00, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x01, /* bNumEndpoints: One endpoints used */
|
||||
0x02, /* bInterfaceClass: Communication Interface Class */
|
||||
0x02, /* bInterfaceSubClass: Abstract Control Model */
|
||||
0x01, /* bInterfaceProtocol: Common AT commands */
|
||||
0x00, /* iInterface: */
|
||||
|
||||
/*Header Functional Descriptor*/
|
||||
0x05, /* bLength: Endpoint Descriptor size */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x00, /* bDescriptorSubtype: Header Func Desc */
|
||||
0x10, /* bcdCDC: spec release number */
|
||||
0x01,
|
||||
|
||||
/*Call Management Functional Descriptor*/
|
||||
0x05, /* bFunctionLength */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x01, /* bDescriptorSubtype: Call Management Func Desc */
|
||||
0x00, /* bmCapabilities: D0+D1 */
|
||||
0x01, /* bDataInterface: 1 */
|
||||
|
||||
/*ACM Functional Descriptor*/
|
||||
0x04, /* bFunctionLength */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x02, /* bDescriptorSubtype: Abstract Control Management desc */
|
||||
0x02, /* bmCapabilities */
|
||||
|
||||
/*Union Functional Descriptor*/
|
||||
0x05, /* bFunctionLength */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x06, /* bDescriptorSubtype: Union func desc */
|
||||
0x00, /* bMasterInterface: Communication class interface */
|
||||
0x01, /* bSlaveInterface0: Data Class Interface */
|
||||
|
||||
/*Endpoint 2 Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||
CDC_CMD_EP, /* bEndpointAddress */
|
||||
0x03, /* bmAttributes: Interrupt */
|
||||
LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */
|
||||
HIBYTE(CDC_CMD_PACKET_SIZE),
|
||||
0x10, /* bInterval: */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*Data class interface descriptor*/
|
||||
0x09, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */
|
||||
0x01, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x02, /* bNumEndpoints: Two endpoints used */
|
||||
0x0A, /* bInterfaceClass: CDC */
|
||||
0x00, /* bInterfaceSubClass: */
|
||||
0x00, /* bInterfaceProtocol: */
|
||||
0x00, /* iInterface: */
|
||||
|
||||
/*Endpoint OUT Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||
CDC_OUT_EP, /* bEndpointAddress */
|
||||
0x02, /* bmAttributes: Bulk */
|
||||
LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */
|
||||
HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE),
|
||||
0x00, /* bInterval: ignore for Bulk transfer */
|
||||
|
||||
/*Endpoint IN Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||
CDC_IN_EP, /* bEndpointAddress */
|
||||
0x02, /* bmAttributes: Bulk */
|
||||
LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */
|
||||
HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE),
|
||||
0x00 /* bInterval: ignore for Bulk transfer */
|
||||
} ;
|
||||
|
||||
__ALIGN_BEGIN uint8_t USBD_CDC_OtherSpeedCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
{
|
||||
0x09, /* bLength: Configuation Descriptor size */
|
||||
USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION,
|
||||
USB_CDC_CONFIG_DESC_SIZ,
|
||||
0x00,
|
||||
0x02, /* bNumInterfaces: 2 interfaces */
|
||||
0x01, /* bConfigurationValue: */
|
||||
0x04, /* iConfiguration: */
|
||||
0xC0, /* bmAttributes: */
|
||||
0x32, /* MaxPower 100 mA */
|
||||
|
||||
/*Interface Descriptor */
|
||||
0x09, /* bLength: Interface Descriptor size */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */
|
||||
/* Interface descriptor type */
|
||||
0x00, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x01, /* bNumEndpoints: One endpoints used */
|
||||
0x02, /* bInterfaceClass: Communication Interface Class */
|
||||
0x02, /* bInterfaceSubClass: Abstract Control Model */
|
||||
0x01, /* bInterfaceProtocol: Common AT commands */
|
||||
0x00, /* iInterface: */
|
||||
|
||||
/*Header Functional Descriptor*/
|
||||
0x05, /* bLength: Endpoint Descriptor size */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x00, /* bDescriptorSubtype: Header Func Desc */
|
||||
0x10, /* bcdCDC: spec release number */
|
||||
0x01,
|
||||
|
||||
/*Call Management Functional Descriptor*/
|
||||
0x05, /* bFunctionLength */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x01, /* bDescriptorSubtype: Call Management Func Desc */
|
||||
0x00, /* bmCapabilities: D0+D1 */
|
||||
0x01, /* bDataInterface: 1 */
|
||||
|
||||
/*ACM Functional Descriptor*/
|
||||
0x04, /* bFunctionLength */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x02, /* bDescriptorSubtype: Abstract Control Management desc */
|
||||
0x02, /* bmCapabilities */
|
||||
|
||||
/*Union Functional Descriptor*/
|
||||
0x05, /* bFunctionLength */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x06, /* bDescriptorSubtype: Union func desc */
|
||||
0x00, /* bMasterInterface: Communication class interface */
|
||||
0x01, /* bSlaveInterface0: Data Class Interface */
|
||||
|
||||
/*Endpoint 2 Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT , /* bDescriptorType: Endpoint */
|
||||
CDC_CMD_EP, /* bEndpointAddress */
|
||||
0x03, /* bmAttributes: Interrupt */
|
||||
LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */
|
||||
HIBYTE(CDC_CMD_PACKET_SIZE),
|
||||
0xFF, /* bInterval: */
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*Data class interface descriptor*/
|
||||
0x09, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */
|
||||
0x01, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x02, /* bNumEndpoints: Two endpoints used */
|
||||
0x0A, /* bInterfaceClass: CDC */
|
||||
0x00, /* bInterfaceSubClass: */
|
||||
0x00, /* bInterfaceProtocol: */
|
||||
0x00, /* iInterface: */
|
||||
|
||||
/*Endpoint OUT Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||
CDC_OUT_EP, /* bEndpointAddress */
|
||||
0x02, /* bmAttributes: Bulk */
|
||||
0x40, /* wMaxPacketSize: */
|
||||
0x00,
|
||||
0x00, /* bInterval: ignore for Bulk transfer */
|
||||
|
||||
/*Endpoint IN Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||
CDC_IN_EP, /* bEndpointAddress */
|
||||
0x02, /* bmAttributes: Bulk */
|
||||
0x40, /* wMaxPacketSize: */
|
||||
0x00,
|
||||
0x00 /* bInterval */
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CDC_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_Init
|
||||
* Initialize the CDC interface
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
{
|
||||
uint8_t ret = 0;
|
||||
USBD_CDC_HandleTypeDef *hcdc;
|
||||
|
||||
if(pdev->dev_speed == USBD_SPEED_HIGH )
|
||||
{
|
||||
/* Open EP IN */
|
||||
USBD_LL_OpenEP(pdev,
|
||||
CDC_IN_EP,
|
||||
USBD_EP_TYPE_BULK,
|
||||
CDC_DATA_HS_IN_PACKET_SIZE);
|
||||
|
||||
/* Open EP OUT */
|
||||
USBD_LL_OpenEP(pdev,
|
||||
CDC_OUT_EP,
|
||||
USBD_EP_TYPE_BULK,
|
||||
CDC_DATA_HS_OUT_PACKET_SIZE);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Open EP IN */
|
||||
USBD_LL_OpenEP(pdev,
|
||||
CDC_IN_EP,
|
||||
USBD_EP_TYPE_BULK,
|
||||
CDC_DATA_FS_IN_PACKET_SIZE);
|
||||
|
||||
/* Open EP OUT */
|
||||
USBD_LL_OpenEP(pdev,
|
||||
CDC_OUT_EP,
|
||||
USBD_EP_TYPE_BULK,
|
||||
CDC_DATA_FS_OUT_PACKET_SIZE);
|
||||
}
|
||||
/* Open Command IN EP */
|
||||
USBD_LL_OpenEP(pdev,
|
||||
CDC_CMD_EP,
|
||||
USBD_EP_TYPE_INTR,
|
||||
CDC_CMD_PACKET_SIZE);
|
||||
|
||||
|
||||
pdev->pClassData = USBD_malloc(sizeof (USBD_CDC_HandleTypeDef));
|
||||
|
||||
if(pdev->pClassData == NULL)
|
||||
{
|
||||
ret = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
|
||||
/* Init physical Interface components */
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Init();
|
||||
|
||||
/* Init Xfer states */
|
||||
hcdc->TxState =0;
|
||||
hcdc->RxState =0;
|
||||
|
||||
if(pdev->dev_speed == USBD_SPEED_HIGH )
|
||||
{
|
||||
/* Prepare Out endpoint to receive next packet */
|
||||
USBD_LL_PrepareReceive(pdev,
|
||||
CDC_OUT_EP,
|
||||
hcdc->RxBuffer,
|
||||
CDC_DATA_HS_OUT_PACKET_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Prepare Out endpoint to receive next packet */
|
||||
USBD_LL_PrepareReceive(pdev,
|
||||
CDC_OUT_EP,
|
||||
hcdc->RxBuffer,
|
||||
CDC_DATA_FS_OUT_PACKET_SIZE);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_Init
|
||||
* DeInitialize the CDC layer
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
{
|
||||
uint8_t ret = 0;
|
||||
|
||||
/* Open EP IN */
|
||||
USBD_LL_CloseEP(pdev,
|
||||
CDC_IN_EP);
|
||||
|
||||
/* Open EP OUT */
|
||||
USBD_LL_CloseEP(pdev,
|
||||
CDC_OUT_EP);
|
||||
|
||||
/* Open Command IN EP */
|
||||
USBD_LL_CloseEP(pdev,
|
||||
CDC_CMD_EP);
|
||||
|
||||
|
||||
/* DeInit physical Interface components */
|
||||
if(pdev->pClassData != NULL)
|
||||
{
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->DeInit();
|
||||
USBD_free(pdev->pClassData);
|
||||
pdev->pClassData = NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_Setup
|
||||
* Handle the CDC specific requests
|
||||
* @param pdev: instance
|
||||
* @param req: usb requests
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
static uint8_t ifalt = 0;
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
case USB_REQ_TYPE_CLASS :
|
||||
if (req->wLength)
|
||||
{
|
||||
if (req->bmRequest & 0x80)
|
||||
{
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest,
|
||||
(uint8_t *)hcdc->data,
|
||||
req->wLength);
|
||||
USBD_CtlSendData (pdev,
|
||||
(uint8_t *)hcdc->data,
|
||||
req->wLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
hcdc->CmdOpCode = req->bRequest;
|
||||
hcdc->CmdLength = req->wLength;
|
||||
|
||||
USBD_CtlPrepareRx (pdev,
|
||||
(uint8_t *)hcdc->data,
|
||||
req->wLength);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest,
|
||||
(uint8_t*)&req->wValue,
|
||||
0);
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_GET_INTERFACE :
|
||||
USBD_CtlSendData (pdev,
|
||||
&ifalt,
|
||||
1);
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE :
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_DataIn
|
||||
* Data sent on non-control IN endpoint
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint number
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CDC_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
|
||||
if(pdev->pClassData != NULL)
|
||||
{
|
||||
|
||||
hcdc->TxState = ((USBD_CDC_ItfTypeDef *)&USBD_Interface_fops_FS)->DataIn(pdev);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_DataIn
|
||||
* Data sent on non-control IN endpoint
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint number
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CDC_SOF (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
// USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
|
||||
if(pdev->pClassData != NULL)
|
||||
{
|
||||
((USBD_CDC_ItfTypeDef *)&USBD_Interface_fops_FS)->SOF(pdev);
|
||||
return USBD_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_DataOut
|
||||
* Data received on non-control Out endpoint
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint number
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
static uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
|
||||
/* Get the received data length */
|
||||
hcdc->RxLength = USBD_LL_GetRxDataSize (pdev, epnum);
|
||||
|
||||
/* USB data will be immediately processed, this allow next USB traffic being
|
||||
NAKed till the end of the application Xfer */
|
||||
if(pdev->pClassData != NULL)
|
||||
{
|
||||
//((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Receive(hcdc->RxBuffer, &hcdc->RxLength);
|
||||
((USBD_CDC_ItfTypeDef *)&USBD_Interface_fops_FS)->Receive(hcdc->RxBuffer, &hcdc->RxLength);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_DataOut
|
||||
* Data received on non-control Out endpoint
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint number
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
|
||||
if((pdev->pUserData != NULL) && (hcdc->CmdOpCode != 0xFF))
|
||||
{
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(hcdc->CmdOpCode,
|
||||
(uint8_t *)hcdc->data,
|
||||
hcdc->CmdLength);
|
||||
hcdc->CmdOpCode = 0xFF;
|
||||
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_GetFSCfgDesc
|
||||
* Return configuration descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_CDC_CfgFSDesc);
|
||||
return USBD_CDC_CfgFSDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_GetHSCfgDesc
|
||||
* Return configuration descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CDC_GetHSCfgDesc (uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_CDC_CfgHSDesc);
|
||||
return USBD_CDC_CfgHSDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_GetCfgDesc
|
||||
* Return configuration descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_CDC_OtherSpeedCfgDesc);
|
||||
return USBD_CDC_OtherSpeedCfgDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeviceQualifierDescriptor
|
||||
* return Device Qualifier descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_CDC_GetDeviceQualifierDescriptor (uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_CDC_DeviceQualifierDesc);
|
||||
return USBD_CDC_DeviceQualifierDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_RegisterInterface
|
||||
* @param pdev: device instance
|
||||
* @param fops: CD Interface callback
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_CDC_RegisterInterface (USBD_HandleTypeDef *pdev,
|
||||
USBD_CDC_ItfTypeDef *fops)
|
||||
{
|
||||
uint8_t ret = USBD_FAIL;
|
||||
|
||||
if(fops != NULL)
|
||||
{
|
||||
pdev->pUserData= fops;
|
||||
ret = USBD_OK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_SetTxBuffer
|
||||
* @param pdev: device instance
|
||||
* @param pbuff: Tx Buffer
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_CDC_SetTxBuffer (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuff,
|
||||
uint16_t length)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
|
||||
hcdc->TxBuffer = pbuff;
|
||||
hcdc->TxLength = length;
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_SetRxBuffer
|
||||
* @param pdev: device instance
|
||||
* @param pbuff: Rx Buffer
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_CDC_SetRxBuffer (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuff)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
|
||||
hcdc->RxBuffer = pbuff;
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_DataOut
|
||||
* Data received on non-control Out endpoint
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint number
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
|
||||
if(pdev->pClassData != NULL)
|
||||
{
|
||||
if(hcdc->TxState == 0)
|
||||
{
|
||||
/* Tx Transfer in progress */
|
||||
hcdc->TxState = 1;
|
||||
|
||||
/* Transmit next packet */
|
||||
USBD_LL_Transmit(pdev,
|
||||
CDC_IN_EP,
|
||||
hcdc->TxBuffer,
|
||||
hcdc->TxLength);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return USBD_BUSY;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_ReceivePacket
|
||||
* prepare OUT Endpoint for reception
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
|
||||
/* Suspend or Resume USB Out process */
|
||||
if(pdev->pClassData != NULL)
|
||||
{
|
||||
if(pdev->dev_speed == USBD_SPEED_HIGH )
|
||||
{
|
||||
/* Prepare Out endpoint to receive next packet */
|
||||
USBD_LL_PrepareReceive(pdev,
|
||||
CDC_OUT_EP,
|
||||
hcdc->RxBuffer,
|
||||
CDC_DATA_HS_OUT_PACKET_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Prepare Out endpoint to receive next packet */
|
||||
USBD_LL_PrepareReceive(pdev,
|
||||
CDC_OUT_EP,
|
||||
hcdc->RxBuffer,
|
||||
CDC_DATA_FS_OUT_PACKET_SIZE);
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+555
@@ -0,0 +1,555 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file USBD_COMP.c
|
||||
* @author DB4PLE
|
||||
* @version V1.0.0
|
||||
* @date 11-December-2015
|
||||
* @brief This file provides the composite core functions.
|
||||
*
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <drivers/usb/device/class/composite/usbd_composite.h>
|
||||
#include "usbd_desc.h"
|
||||
#include "usbd_ctlreq.h"
|
||||
#include "uhsdr_board.h"
|
||||
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_COMP
|
||||
* @brief usbd core module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_COMP_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_COMP_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_COMP_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_COMP_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
static uint8_t USBD_COMP_Init (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_COMP_DeInit (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_COMP_Setup (USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static uint8_t *USBD_COMP_GetCfgDesc (uint16_t *length);
|
||||
|
||||
static uint8_t *USBD_COMP_GetDeviceQualifierDesc (uint16_t *length);
|
||||
|
||||
static uint8_t USBD_COMP_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_COMP_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_COMP_EP0_RxReady (USBD_HandleTypeDef *pdev);
|
||||
|
||||
static uint8_t USBD_COMP_EP0_TxReady (USBD_HandleTypeDef *pdev);
|
||||
|
||||
static uint8_t USBD_COMP_SOF (USBD_HandleTypeDef *pdev);
|
||||
|
||||
static uint8_t USBD_COMP_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_COMP_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_COMP_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
USBD_ClassTypeDef USBD_COMP =
|
||||
{
|
||||
USBD_COMP_Init,
|
||||
USBD_COMP_DeInit,
|
||||
USBD_COMP_Setup,
|
||||
USBD_COMP_EP0_TxReady,
|
||||
USBD_COMP_EP0_RxReady,
|
||||
USBD_COMP_DataIn,
|
||||
USBD_COMP_DataOut,
|
||||
USBD_COMP_SOF,
|
||||
USBD_COMP_IsoINIncomplete,
|
||||
USBD_COMP_IsoOutIncomplete,
|
||||
USBD_COMP_GetCfgDesc,
|
||||
USBD_COMP_GetCfgDesc,
|
||||
USBD_COMP_GetCfgDesc,
|
||||
USBD_COMP_GetDeviceQualifierDesc,
|
||||
};
|
||||
|
||||
USBD_COMP_ItfTypeDef USBD_COMP_fops_FS;
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_COMP_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END=
|
||||
{
|
||||
USB_LEN_DEV_QUALIFIER_DESC,
|
||||
USB_DESC_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_COMP_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBD_COMP_Init
|
||||
* Initialize the AUDIO interface
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
|
||||
static inline void switchToClass(USBD_HandleTypeDef *pdev,USBD_ClassCompInfo* class)
|
||||
{
|
||||
pdev->pClassData = class->classData;
|
||||
pdev->pUserData = class->userData;
|
||||
}
|
||||
static inline void saveClass(USBD_HandleTypeDef *pdev,USBD_ClassCompInfo* class)
|
||||
{
|
||||
class->classData = pdev->pClassData;
|
||||
class->userData = pdev->pUserData;
|
||||
}
|
||||
|
||||
|
||||
static uint8_t USBD_COMP_Init (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
{
|
||||
uint8_t retval = USBD_OK;
|
||||
|
||||
for (int i = 0; i < CLASS_NUM && retval == USBD_OK; i++)
|
||||
{
|
||||
switchToClass(pdev,&dev_instance[i]);
|
||||
retval = dev_instance[i].class->Init(pdev,cfgidx);
|
||||
saveClass(pdev,&dev_instance[i]);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_COMP_Init
|
||||
* DeInitialize the AUDIO layer
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_COMP_DeInit (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
{
|
||||
uint8_t retval = USBD_OK;
|
||||
|
||||
for (int i = 0; i < CLASS_NUM && retval == USBD_OK; i++)
|
||||
{
|
||||
switchToClass(pdev,&dev_instance[i]);
|
||||
retval = dev_instance[i].class->DeInit(pdev,cfgidx);
|
||||
saveClass(pdev,&dev_instance[i]);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_COMP_Setup
|
||||
* Handle the AUDIO specific requests
|
||||
* @param pdev: instance
|
||||
* @param req: usb requests
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
static uint8_t* USBD_COMP_FindDescriptor(uint8_t desc_type)
|
||||
{
|
||||
|
||||
uint8_t* retval = NULL;
|
||||
uint16_t desc_len;
|
||||
uint8_t* desc_ptr = USBD_COMP_GetCfgDesc(&desc_len);
|
||||
|
||||
for (int32_t i = 0; i < desc_len; i += desc_ptr[i])
|
||||
{
|
||||
if (desc_ptr[i+1] == desc_type)
|
||||
{
|
||||
retval = &desc_ptr[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
static uint8_t USBD_COMP_Setup (USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
uint16_t len;
|
||||
uint8_t *pbuf;
|
||||
uint8_t ret = USBD_OK;
|
||||
uint8_t done = 0;
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
case USB_REQ_TYPE_CLASS :
|
||||
switch(req->bmRequest & USB_REQ_RECIPIENT_MASK)
|
||||
{
|
||||
case USB_REQ_RECIPIENT_INTERFACE:
|
||||
for (int i = 0; i < CLASS_NUM; i++)
|
||||
{
|
||||
uint8_t interface = req->wValue >> 8;
|
||||
if (interface >= dev_instance[i].minIf && interface <= dev_instance[i].maxIf)
|
||||
{
|
||||
switchToClass(pdev,&dev_instance[i]);
|
||||
ret = dev_instance[i].class->Setup(pdev,req);
|
||||
done = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (done != 1)
|
||||
{
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_GET_DESCRIPTOR:
|
||||
{
|
||||
pbuf = USBD_COMP_FindDescriptor(req->wValue >> 8);
|
||||
|
||||
if(pbuf != NULL)
|
||||
{
|
||||
len = MIN(pbuf[0], req->wLength);
|
||||
|
||||
USBD_CtlSendData (pdev,
|
||||
pbuf,
|
||||
len);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_INTERFACE :
|
||||
case USB_REQ_SET_INTERFACE :
|
||||
if ((uint8_t)(req->wIndex) <= USBD_MAX_NUM_INTERFACES)
|
||||
{
|
||||
for (int i = 0; i < CLASS_NUM; i++)
|
||||
{
|
||||
if (req->wIndex >= dev_instance[i].minIf && req->wIndex <= dev_instance[i].maxIf)
|
||||
{
|
||||
switchToClass(pdev,&dev_instance[i]);
|
||||
ret = dev_instance[i].class->Setup(pdev,req);
|
||||
done = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Call the error management function (command will be nacked */
|
||||
USBD_CtlError (pdev, req);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_COMP_GetCfgDesc
|
||||
* return configuration descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_COMP_GetCfgDesc (uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_COMP_CfgDesc);
|
||||
return USBD_COMP_CfgDesc;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_COMP_DataIn
|
||||
* handle data IN Stage
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_COMP_DataIn (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
{
|
||||
uint8_t retval = USBD_OK;
|
||||
if (epnum <= USBD_MAX_EP)
|
||||
{
|
||||
uint8_t classIdx = usbdEpMap.in[epnum];
|
||||
|
||||
if (classIdx < CLASS_NUM)
|
||||
{
|
||||
if (dev_instance[classIdx].class->DataIn != NULL)
|
||||
{
|
||||
switchToClass(pdev,&dev_instance[classIdx]);
|
||||
retval = dev_instance[classIdx].class->DataIn(pdev,epnum);
|
||||
}
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_COMP_EP0_RxReady
|
||||
* handle EP0 Rx Ready event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_COMP_EP0_RxReady (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
uint8_t retval = USBD_OK;
|
||||
for (int i = 0; i < CLASS_NUM; i++)
|
||||
{
|
||||
if (dev_instance[i].class->EP0_RxReady != NULL)
|
||||
{
|
||||
switchToClass(pdev,&dev_instance[i]);
|
||||
retval = dev_instance[i].class->EP0_RxReady(pdev);
|
||||
}
|
||||
if (retval != USBD_OK)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
/**
|
||||
* @brief USBD_COMP_EP0_TxReady
|
||||
* handle EP0 TRx Ready event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_COMP_EP0_TxReady (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
uint8_t retval = USBD_OK;
|
||||
for (int i = 0; i < CLASS_NUM; i++)
|
||||
{
|
||||
if (dev_instance[i].class->EP0_TxSent != NULL)
|
||||
{
|
||||
switchToClass(pdev,&dev_instance[i]);
|
||||
retval = dev_instance[i].class->EP0_TxSent(pdev);
|
||||
}
|
||||
if (retval != USBD_OK)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
/**
|
||||
* @brief USBD_COMP_SOF
|
||||
* handle SOF event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_COMP_SOF (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
uint8_t retval = USBD_OK;
|
||||
for (int i = 0; i < CLASS_NUM; i++)
|
||||
{
|
||||
if (dev_instance[i].class->SOF != NULL)
|
||||
{
|
||||
switchToClass(pdev,&dev_instance[i]);
|
||||
retval = dev_instance[i].class->SOF(pdev);
|
||||
if (retval != USBD_OK)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_COMP_IsoINIncomplete
|
||||
* handle data ISO IN Incomplete event
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_COMP_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
uint8_t retval = USBD_OK;
|
||||
for (int i = 0; i < CLASS_NUM; i++)
|
||||
{
|
||||
if (dev_instance[i].class->IsoINIncomplete != NULL)
|
||||
{
|
||||
switchToClass(pdev,&dev_instance[i]);
|
||||
retval = dev_instance[i].class->IsoINIncomplete(pdev, epnum);
|
||||
if (retval != USBD_OK)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
/**
|
||||
* @brief USBD_COMP_IsoOutIncomplete
|
||||
* handle data ISO OUT Incomplete event
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_COMP_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
uint8_t retval = USBD_OK;
|
||||
for (int i = 0; i < CLASS_NUM; i++)
|
||||
{
|
||||
if (dev_instance[i].class->IsoOUTIncomplete != NULL)
|
||||
{
|
||||
switchToClass(pdev,&dev_instance[i]);
|
||||
retval = dev_instance[i].class->IsoOUTIncomplete(pdev, epnum);
|
||||
if (retval != USBD_OK)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
/**
|
||||
* @brief USBD_COMP_DataOut
|
||||
* handle data OUT Stage
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_COMP_DataOut (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
{
|
||||
uint8_t retval = USBD_OK;
|
||||
if (epnum <= USBD_MAX_EP)
|
||||
{
|
||||
uint8_t classIdx = usbdEpMap.out[epnum];
|
||||
|
||||
if (classIdx < CLASS_NUM)
|
||||
{
|
||||
if (dev_instance[classIdx].class->DataOut != NULL)
|
||||
{
|
||||
switchToClass(pdev,&dev_instance[classIdx]);
|
||||
retval = dev_instance[classIdx].class->DataOut(pdev,epnum);
|
||||
}
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief DeviceQualifierDescriptor
|
||||
* return Device Qualifier descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_COMP_GetDeviceQualifierDesc (uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_COMP_DeviceQualifierDesc);
|
||||
return USBD_COMP_DeviceQualifierDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_COMP_RegisterInterface
|
||||
* @param fops: Audio interface callback
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_COMP_RegisterInterface (USBD_HandleTypeDef *pdev,
|
||||
USBD_COMP_ItfTypeDef *fops)
|
||||
{
|
||||
if(fops != NULL)
|
||||
{
|
||||
pdev->pUserData= fops;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file USBD_COMP_cdc_comp.h
|
||||
* @author MCD Application Team/ mcHF Devel
|
||||
* @version V2.4.2
|
||||
* @date 11-December-2015
|
||||
* @brief header file for the USBD_COMP.c file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_COMPOSITE_H
|
||||
#define __USB_COMPOSITE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_ioreq.h"
|
||||
#include "usbd_desc.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_COMP
|
||||
* @brief This file is the Header file for USBD_COMP.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_COMP_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
USBD_ClassTypeDef* class;
|
||||
void* classData;
|
||||
void* userData;
|
||||
uint16_t ctrlIf;
|
||||
uint16_t minIf;
|
||||
uint16_t maxIf;
|
||||
} USBD_ClassCompInfo;
|
||||
|
||||
#define USBD_MAX_EP 3
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t in[USBD_MAX_EP+1];
|
||||
uint8_t out[USBD_MAX_EP+1];
|
||||
} usbd_ep_map_t;
|
||||
|
||||
|
||||
#define CLASS_AUDIO 0
|
||||
#define CLASS_CDC 1
|
||||
#define CLASS_NUM 2
|
||||
#define CLASS_UNUSED 0xFF
|
||||
|
||||
extern const usbd_ep_map_t usbdEpMap;
|
||||
|
||||
extern USBD_ClassCompInfo dev_instance[CLASS_NUM];
|
||||
|
||||
#define USB_AUDIO_CONFIG_DESC_SIZ (9+101+73 + 8 + 66 + 9 +7)
|
||||
extern uint8_t USBD_COMP_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ];
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
}
|
||||
USBD_COMP_HandleTypeDef;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
}USBD_COMP_ItfTypeDef;
|
||||
|
||||
extern USBD_COMP_ItfTypeDef USBD_COMP_fops_FS;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern USBD_ClassTypeDef USBD_COMP;
|
||||
#define USBD_COMP_CLASS &USBD_COMP
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t USBD_COMP_RegisterInterface (USBD_HandleTypeDef *pdev,
|
||||
USBD_COMP_ItfTypeDef *fops);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USB_COMPOSITE_H */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+523
@@ -0,0 +1,523 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file USBD_COMP.c
|
||||
* @author MCD Application Team
|
||||
* @version V2.4.2
|
||||
* @date 11-December-2015
|
||||
* @brief This file provides the Audio core functions.
|
||||
*
|
||||
* @verbatim
|
||||
*
|
||||
* ===================================================================
|
||||
* AUDIO Class Description
|
||||
* ===================================================================
|
||||
* This driver manages the Audio Class 1.0 following the "USB Device Class Definition for
|
||||
* Audio Devices V1.0 Mar 18, 98".
|
||||
* This driver implements the following aspects of the specification:
|
||||
* - Device descriptor management
|
||||
* - Configuration descriptor management
|
||||
* - Standard AC Interface Descriptor management
|
||||
* - 1 Audio Streaming Interface (with single channel, PCM, Stereo mode)
|
||||
* - 1 Audio Streaming Endpoint
|
||||
* - 1 Audio Terminal Input (1 channel)
|
||||
* - Audio Class-Specific AC Interfaces
|
||||
* - Audio Class-Specific AS Interfaces
|
||||
* - AudioControl Requests: only SET_CUR and GET_CUR requests are supported (for Mute)
|
||||
* - Audio Feature Unit (limited to Mute control)
|
||||
* - Audio Synchronization type: Asynchronous
|
||||
* - Single fixed audio sampling rate (configurable in usbd_conf.h file)
|
||||
* The current audio class version supports the following audio features:
|
||||
* - Pulse Coded Modulation (PCM) format
|
||||
* - sampling rate: 48KHz.
|
||||
* - Bit resolution: 16
|
||||
* - Number of channels: 2
|
||||
* - No volume control
|
||||
* - Mute/Unmute capability
|
||||
* - Asynchronous Endpoints
|
||||
*
|
||||
* @note In HS mode and when the DMA is used, all variables and data structures
|
||||
* dealing with the DMA during the transaction process should be 32-bit aligned.
|
||||
*
|
||||
*
|
||||
* @endverbatim
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <drivers/usb/device/class/composite/usbd_composite.h>
|
||||
#include <drivers/usb/device/class/composite/usbd_composite_desc.h>
|
||||
#include "usbd_desc.h"
|
||||
#include "usbd_ctlreq.h"
|
||||
#include "uhsdr_board.h"
|
||||
#include "usbd_cdc.h"
|
||||
#include "usbd_audio_cdc_comp.h"
|
||||
#include "usbd_audio_if.h"
|
||||
#include "usbd_cdc_if.h"
|
||||
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_COMP
|
||||
* @brief usbd core module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_COMP_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_COMP_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_COMP_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
#define AUDIO_SAMPLE_FREQ(frq) (uint8_t)(frq), (uint8_t)((frq >> 8)), (uint8_t)((frq >> 16))
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_COMP_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* USB AUDIO device Configuration Descriptor */
|
||||
__ALIGN_BEGIN uint8_t USBD_COMP_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
{
|
||||
/* Configuration 1 */
|
||||
0x09, /* bLength */
|
||||
USB_DESC_TYPE_CONFIGURATION, // USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType */
|
||||
LOBYTE(USB_AUDIO_CONFIG_DESC_SIZ), /* wTotalLength 109 bytes*/
|
||||
HIBYTE(USB_AUDIO_CONFIG_DESC_SIZ),
|
||||
0x05, /* bNumInterfaces */
|
||||
0x01, /* bConfigurationValue */
|
||||
0x00, /* iConfiguration */
|
||||
0xC0, /* bmAttributes BUS Powred*/
|
||||
0x32, /* bMaxPower = 100 mA*/
|
||||
/* 09 byte*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
USB_INTERFACE_ASSOCIATION_DESC_SIZE,
|
||||
USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE,
|
||||
CDC_CTRL_IF, /* first interface */
|
||||
CDC_TOTAL_IF_NUM, /* bNumInterfaces */
|
||||
0x02, /* bInterfaceClass */
|
||||
0x02, /* bInterfaceSubClass */
|
||||
0x01, /* bInterfaceProtocol */
|
||||
0x00, /* String Index */
|
||||
|
||||
/*Interface Descriptor */
|
||||
0x09, /* bLength: Interface Descriptor size */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */
|
||||
/* Interface descriptor type */
|
||||
CDC_CTRL_IF, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x01, /* bNumEndpoints: One endpoints used */
|
||||
0x02, /* bInterfaceClass: Communication Interface Class */
|
||||
0x02, /* bInterfaceSubClass: Abstract Control Model */
|
||||
0x01, /* bInterfaceProtocol: Common AT commands */
|
||||
0x00, /* iInterface: */
|
||||
|
||||
/*Header Functional Descriptor*/
|
||||
0x05, /* bLength: Endpoint Descriptor size */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x00, /* bDescriptorSubtype: Header Func Desc */
|
||||
0x10, /* bcdCDC: spec release number */
|
||||
0x01,
|
||||
|
||||
/*Call Management Functional Descriptor*/
|
||||
0x05, /* bFunctionLength */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x01, /* bDescriptorSubtype: Call Management Func Desc */
|
||||
0x00, /* bmCapabilities: D0+D1 */
|
||||
0x01, /* bDataInterface: 1 */
|
||||
|
||||
/*ACM Functional Descriptor*/
|
||||
0x04, /* bFunctionLength */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x02, /* bDescriptorSubtype: Abstract Control Management desc */
|
||||
0x02, /* bmCapabilities */
|
||||
|
||||
/*Union Functional Descriptor*/
|
||||
0x05, /* bFunctionLength */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x06, /* bDescriptorSubtype: Union func desc */
|
||||
CDC_CTRL_IF, /* bMasterInterface: Communication class interface */
|
||||
CDC_DATA_IF, /* bSlaveInterface0: Data Class Interface */
|
||||
|
||||
/*Endpoint 2 Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
|
||||
CDC_CMD_EP, /* bEndpointAddress */
|
||||
0x03, /* bmAttributes: Interrupt */
|
||||
LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */
|
||||
HIBYTE(CDC_CMD_PACKET_SIZE),
|
||||
#ifdef USE_USB_OTG_HS
|
||||
0x10, /* bInterval: */
|
||||
#else
|
||||
0xFF, /* bInterval: */
|
||||
#endif /* USE_USB_OTG_HS */
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*Data class interface descriptor*/
|
||||
0x09, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */
|
||||
CDC_DATA_IF, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x02, /* bNumEndpoints: Two endpoints used */
|
||||
0x0A, /* bInterfaceClass: CDC */
|
||||
0x00, /* bInterfaceSubClass: */
|
||||
0x00, /* bInterfaceProtocol: */
|
||||
0x00, /* iInterface: */
|
||||
|
||||
/*Endpoint OUT Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
|
||||
CDC_OUT_EP, /* bEndpointAddress */
|
||||
0x02, /* bmAttributes: Bulk */
|
||||
LOBYTE(CDC_DATA_FS_OUT_PACKET_SIZE), /* wMaxPacketSize: */
|
||||
HIBYTE(CDC_DATA_FS_OUT_PACKET_SIZE),
|
||||
0x00, /* bInterval: ignore for Bulk transfer */
|
||||
|
||||
/*Endpoint IN Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
|
||||
CDC_IN_EP, /* bEndpointAddress */
|
||||
0x02, /* bmAttributes: Bulk */
|
||||
LOBYTE(CDC_DATA_FS_IN_PACKET_SIZE), /* wMaxPacketSize: */
|
||||
HIBYTE(CDC_DATA_FS_IN_PACKET_SIZE),
|
||||
0x00, /* bInterval: ignore for Bulk transfer */
|
||||
|
||||
USB_INTERFACE_ASSOCIATION_DESC_SIZE,
|
||||
USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE,
|
||||
AUDIO_CTRL_IF, /* first interface */
|
||||
AUDIO_TOTAL_IF_NUM, /* bNumInterfaces */
|
||||
USB_DEVICE_CLASS_AUDIO, /* bInterfaceClass */
|
||||
AUDIO_SUBCLASS_AUDIOCONTROL, /* bInterfaceSubClass */
|
||||
AUDIO_PROTOCOL_UNDEFINED, /* bInterfaceProtocol */
|
||||
0x00, /* String Index */
|
||||
|
||||
/* USB Sound Standard interface descriptor */
|
||||
AUDIO_INTERFACE_DESC_SIZE, /* bLength */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType */
|
||||
AUDIO_CTRL_IF, /* bInterfaceNumber */
|
||||
0x00, /* bAlternateSetting */
|
||||
0x00, /* bNumEndpoints */
|
||||
USB_DEVICE_CLASS_AUDIO, /* bInterfaceClass */
|
||||
AUDIO_SUBCLASS_AUDIOCONTROL, /* bInterfaceSubClass */
|
||||
AUDIO_PROTOCOL_UNDEFINED, /* bInterfaceProtocol */
|
||||
0x00, /* iInterface */
|
||||
|
||||
/* 09 byte*/
|
||||
// Begin AudioControl Descriptors
|
||||
/* USB Speaker Class-specific AC Interface Descriptor */
|
||||
AUDIO_INTERFACE_DESC_SIZE + 1, /* bLength */
|
||||
AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
|
||||
AUDIO_CONTROL_HEADER, /* bDescriptorSubtype */
|
||||
0x00, /* 1.00 */ /* bcdADC */
|
||||
0x01,
|
||||
61 + 9 + 7,
|
||||
0x00,
|
||||
0x02, /* bInCollection */
|
||||
AUDIO_OUT_IF, /* baInterfaceNr */
|
||||
AUDIO_IN_IF, /* baInterfaceNr */
|
||||
|
||||
/* 09 byte*/
|
||||
/* USB Speaker Input Terminal Descriptor */
|
||||
AUDIO_INPUT_TERMINAL_DESC_SIZE, /* bLength */
|
||||
AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
|
||||
AUDIO_CONTROL_INPUT_TERMINAL, /* bDescriptorSubtype */
|
||||
0x01, /* bTerminalID */
|
||||
0x01, /* wTerminalType AUDIO_TERMINAL_USB_STREAMING 0x0101 */
|
||||
0x01,
|
||||
0x00, /* bAssocTerminal */
|
||||
/* bNrChannels conflict
|
||||
* In the "Type III Format" (actually type I) descriptor, bNrChannels is set to 2
|
||||
* But in the input terminal desc, bNrChannels is 1
|
||||
* Also, wChannelConfig is wrong, even if it was mono */
|
||||
0x02, /* bNrChannels */
|
||||
0x03, /* wChannelConfig 0x0000 Mono; 0x03, 0x00 (L/R front) */
|
||||
0x00,
|
||||
0x00, /* iChannelNames */
|
||||
0x00, /* iTerminal */
|
||||
/* 12 byte*/
|
||||
|
||||
/* USB Speaker Audio Feature Unit Descriptor */
|
||||
0x09, /* bLength */
|
||||
AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
|
||||
AUDIO_CONTROL_FEATURE_UNIT, /* bDescriptorSubtype */
|
||||
AUDIO_OUT_STREAMING_CTRL, /* bUnitID */
|
||||
0x01, /* bSourceID */
|
||||
0x01, /* bControlSize */
|
||||
AUDIO_CONTROL_VOLUME, /* bmaControls(0) */
|
||||
0x00, /* bmaControls(1) */
|
||||
0x00, /* iTerminal */
|
||||
/* 09 byte*/
|
||||
|
||||
/*USB Speaker Output Terminal Descriptor */
|
||||
0x09, /* bLength */
|
||||
AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
|
||||
AUDIO_CONTROL_OUTPUT_TERMINAL, /* bDescriptorSubtype */
|
||||
0x03, /* bTerminalID */
|
||||
0x01, /* wTerminalType 0x0301*/
|
||||
0x03,
|
||||
0x00, /* bAssocTerminal */
|
||||
0x02, /* bSourceID */
|
||||
0x00, /* iTerminal */
|
||||
/* 09 byte*/
|
||||
|
||||
/*USB Microphone Input Terminal Descriptor */
|
||||
0x0C, // Size of the descriptor, in bytes
|
||||
AUDIO_INTERFACE_DESCRIPTOR_TYPE, // CS_INTERFACE Descriptor Type
|
||||
AUDIO_CONTROL_INPUT_TERMINAL, // INPUT_TERMINAL descriptor subtype
|
||||
0x04, // ID of this Terminal.
|
||||
0x01,0x02, // Terminal is Microphone (0x01,0x02)
|
||||
0x00, // No association
|
||||
USBD_AUDIO_IN_CHANNELS, // One or two channel
|
||||
0x03,0x00, /* wChannelConfig 0x0000 Mono; 0x03, 0x00 (L/R front) */
|
||||
0x00, // Unused.
|
||||
0x00, // Unused.
|
||||
|
||||
/* USB Microphone Output Terminal Descriptor */
|
||||
0x09, // Size of the descriptor, in bytes (bLength)
|
||||
AUDIO_INTERFACE_DESCRIPTOR_TYPE, // CS_INTERFACE Descriptor Type (bDescriptorType)
|
||||
AUDIO_CONTROL_OUTPUT_TERMINAL, // OUTPUT_TERMINAL descriptor subtype (bDescriptorSubtype)
|
||||
0x05, // ID of this Terminal. (bTerminalID)
|
||||
0x01, 0x01, // USB Streaming. (wTerminalType
|
||||
0x00, // unused (bAssocTerminal)
|
||||
0x07, // From Input Terminal.(bSourceID)
|
||||
0x00, // unused (iTerminal)
|
||||
|
||||
/* USB Speaker Audio Feature Unit Descriptor */
|
||||
0x09, /* bLength */
|
||||
AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
|
||||
AUDIO_CONTROL_FEATURE_UNIT, /* bDescriptorSubtype */
|
||||
0x06, /* bUnitID */
|
||||
0x04, /* bSourceID */
|
||||
0x01, /* bControlSize */
|
||||
AUDIO_CONTROL_VOLUME, /* bmaControls(0) */
|
||||
0x00, /* bmaControls(1) */
|
||||
0x00, /* iTerminal */
|
||||
/* 09 byte*/
|
||||
|
||||
/* AC Selector Unit Descriptor */
|
||||
0x07, // bLength
|
||||
0x24, // bDescriptorType
|
||||
0x05, // bDescriptorSubtype
|
||||
0x07, // bUnitID
|
||||
0x01, // bBrInPins
|
||||
0x06, // baSourceID(1)
|
||||
0x00, // iSelector
|
||||
|
||||
// ========================================== END AudioControl
|
||||
/* USB Speaker Standard AS Interface Descriptor - Audio Streaming Zero Bandwith */
|
||||
/* Interface 1, Alternate Setting 0 */
|
||||
AUDIO_INTERFACE_DESC_SIZE, /* bLength */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType */
|
||||
AUDIO_OUT_IF, /* bInterfaceNumber */
|
||||
0x00, /* bAlternateSetting */
|
||||
0x00, /* bNumEndpoints */
|
||||
USB_DEVICE_CLASS_AUDIO, /* bInterfaceClass */
|
||||
AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubClass */
|
||||
AUDIO_PROTOCOL_UNDEFINED, /* bInterfaceProtocol */
|
||||
0x00, /* iInterface */
|
||||
/* 09 byte*/
|
||||
|
||||
/* USB Speaker Standard AS Interface Descriptor - Audio Streaming Operational */
|
||||
/* Interface 1, Alternate Setting 1 */
|
||||
AUDIO_INTERFACE_DESC_SIZE, /* bLength */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType */
|
||||
AUDIO_OUT_IF, /* bInterfaceNumber */
|
||||
0x01, /* bAlternateSetting */
|
||||
0x01, /* bNumEndpoints */
|
||||
USB_DEVICE_CLASS_AUDIO, /* bInterfaceClass */
|
||||
AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubClass */
|
||||
AUDIO_PROTOCOL_UNDEFINED, /* bInterfaceProtocol */
|
||||
0x00, /* iInterface */
|
||||
/* 09 byte*/
|
||||
|
||||
/* USB Speaker Audio Streaming Interface Descriptor */
|
||||
AUDIO_STREAMING_INTERFACE_DESC_SIZE, /* bLength */
|
||||
AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
|
||||
AUDIO_STREAMING_GENERAL, /* bDescriptorSubtype */
|
||||
0x01, /* bTerminalLink */
|
||||
0x01, /* bDelay */
|
||||
0x01, /* wFormatTag AUDIO_FORMAT_PCM 0x0001*/
|
||||
0x00,
|
||||
/* 07 byte*/
|
||||
|
||||
/* USB Speaker Audio Type I Format Interface Descriptor */
|
||||
0x0B, /* bLength */
|
||||
AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
|
||||
AUDIO_STREAMING_FORMAT_TYPE, /* bDescriptorSubtype */
|
||||
/* Type III" format descriptor is assigned, but wFormatTag on AS interface desc is set to PCM
|
||||
* (type III is not PCM). As Type III is not a popular one, it should be of Type I */
|
||||
AUDIO_FORMAT_TYPE_I, /* bFormatType */
|
||||
0x02, /* bNrChannels */
|
||||
0x02, /* bSubFrameSize : 2 Bytes per frame (16bits) */
|
||||
16, /* bBitResolution (16-bits per sample) */
|
||||
0x01, /* bSamFreqType only one frequency supported */
|
||||
SAMPLE_FREQ(USBD_AUDIO_FREQ), /* Audio sampling frequency coded on 3 bytes */
|
||||
/* 11 byte*/
|
||||
|
||||
/* Endpoint 1 - Standard Descriptor */
|
||||
AUDIO_STANDARD_ENDPOINT_DESC_SIZE, /* bLength */
|
||||
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */
|
||||
AUDIO_OUT_EP, /* bEndpointAddress 1 out endpoint*/
|
||||
USB_ENDPOINT_TYPE_ISOCHRONOUS, /* bmAttributes */
|
||||
AUDIO_PACKET_SZE(USBD_AUDIO_FREQ,USBD_AUDIO_OUT_CHANNELS), /* wMaxPacketSize in Bytes (Freq(Samples)*2(Stereo)*2(HalfWord)) */
|
||||
0x01, /* bInterval */
|
||||
0x00, /* bRefresh */
|
||||
0x00, /* bSynchAddress */
|
||||
/* 09 byte*/
|
||||
|
||||
/* Endpoint - Audio Streaming Descriptor*/
|
||||
AUDIO_STREAMING_ENDPOINT_DESC_SIZE, /* bLength */
|
||||
AUDIO_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */
|
||||
AUDIO_ENDPOINT_GENERAL, /* bDescriptor */
|
||||
0x00, /* bmAttributes */
|
||||
0x00, /* bLockDelayUnits */
|
||||
0x00, /* wLockDelay */
|
||||
0x00,
|
||||
/* 07 byte*/
|
||||
|
||||
/* From Here is the Microphone */
|
||||
/* USB Microphone Standard AS Interface Descriptor (Alt. Set. 0) (CODE == 3)*/ //zero-bandwidth interface
|
||||
|
||||
/*
|
||||
* Microphone Standard AS Interface Descriptor - Audio Streaming Zero Bandwith
|
||||
* Interface 1, Alternate Setting 0
|
||||
*/
|
||||
AUDIO_INTERFACE_DESC_SIZE, // Size of the descriptor, in bytes (bLength)
|
||||
USB_DESC_TYPE_INTERFACE, // INTERFACE descriptor type (bDescriptorType) 0x04
|
||||
AUDIO_IN_IF, // Index of this interface. (bInterfaceNumber) ?????????? (3<) (1<<) (1<M)
|
||||
0x00, // Index of this alternate setting. (bAlternateSetting)
|
||||
0x00, // 0 endpoints. (bNumEndpoints)
|
||||
USB_DEVICE_CLASS_AUDIO, // AUDIO (bInterfaceClass)
|
||||
AUDIO_SUBCLASS_AUDIOSTREAMING, // AUDIO_STREAMING (bInterfaceSubclass)
|
||||
AUDIO_PROTOCOL_UNDEFINED, // Unused. (bInterfaceProtocol)
|
||||
0x00, // Unused. (iInterface)
|
||||
|
||||
/* USB Microphone Standard AS Interface Descriptor (Alt. Set. 1) (CODE == 4)*/
|
||||
|
||||
/*
|
||||
* Microphone Standard AS Interface Descriptor - Audio Streaming Zero Bandwith
|
||||
* Interface 1, Alternate Setting 1
|
||||
*/
|
||||
AUDIO_INTERFACE_DESC_SIZE, // Size of the descriptor, in bytes (bLength)
|
||||
USB_DESC_TYPE_INTERFACE, // INTERFACE descriptor type (bDescriptorType)
|
||||
AUDIO_IN_IF, // Index of this interface. (bInterfaceNumber)
|
||||
0x01, // Index of this alternate setting. (bAlternateSetting)
|
||||
0x01, // 1 endpoint (bNumEndpoints)
|
||||
USB_DEVICE_CLASS_AUDIO, // AUDIO (bInterfaceClass)
|
||||
AUDIO_SUBCLASS_AUDIOSTREAMING, // AUDIO_STREAMING (bInterfaceSubclass)
|
||||
AUDIO_PROTOCOL_UNDEFINED, // Unused. (bInterfaceProtocol)
|
||||
0x00, // Unused. (iInterface)
|
||||
|
||||
/* USB Microphone Class-specific AS General Interface Descriptor (CODE == 5)*/
|
||||
AUDIO_STREAMING_INTERFACE_DESC_SIZE, // Size of the descriptor, in bytes (bLength)
|
||||
AUDIO_INTERFACE_DESCRIPTOR_TYPE, // CS_INTERFACE Descriptor Type (bDescriptorType) 0x24
|
||||
AUDIO_STREAMING_GENERAL, // GENERAL subtype (bDescriptorSubtype) 0x01
|
||||
0x05, // Unit ID of the Output Terminal.(bTerminalLink)
|
||||
0x01, // Interface delay. (bDelay)
|
||||
0x01,0x00, // PCM Format (wFormatTag)
|
||||
|
||||
/* USB Microphone Type I Format Type Descriptor (CODE == 6)*/
|
||||
/* Microphone Audio Type I Format Interface Descriptor */
|
||||
0x0B, // Size of the descriptor, in bytes (bLength)
|
||||
AUDIO_INTERFACE_DESCRIPTOR_TYPE,// CS_INTERFACE Descriptor Type (bDescriptorType) 0x24
|
||||
AUDIO_STREAMING_FORMAT_TYPE, // FORMAT_TYPE subtype. (bDescriptorSubtype) 0x02
|
||||
0x01, // FORMAT_TYPE_I. (bFormatType)
|
||||
USBD_AUDIO_IN_CHANNELS, // One or two channel.(bNrChannels)
|
||||
0x02, // Two bytes per audio subframe.(bSubFrameSize)
|
||||
0x10, // 16 bits per sample.(bBitResolution)
|
||||
0x01, // One frequency supported. (bSamFreqType)
|
||||
(USBD_AUDIO_IN_FREQ&0xFF),((USBD_AUDIO_IN_FREQ>>8)&0xFF),0x00, // (tSamFreq) (NOT COMPLETE!!!)
|
||||
|
||||
/* USB Microphone Standard Endpoint Descriptor (CODE == 8)*/ //Standard AS Isochronous Audio Data Endpoint Descriptor
|
||||
/* Endpoint 1 - Standard Descriptor */
|
||||
AUDIO_STANDARD_ENDPOINT_DESC_SIZE, // Size of the descriptor, in bytes (bLength)
|
||||
USB_DESC_TYPE_ENDPOINT, // ENDPOINT descriptor (bDescriptorType)
|
||||
AUDIO_IN_EP, // IN Endpoint 1. (bEndpointAddress)
|
||||
USB_ENDPOINT_TYPE_ISOCHRONOUS, // Isochronous, not shared. (bmAttributes)//USB_ENDPOINT_TYPE_asynchronous USB_ENDPOINT_TYPE_ISOCHRONOUS
|
||||
(AUDIO_IN_PACKET&0xFF),((AUDIO_IN_PACKET>>8)&0xFF), //bytes per packet (wMaxPacketSize)
|
||||
0x01, // One packet per frame.(bInterval)
|
||||
0x00, // Unused. (bRefresh)
|
||||
0x00, // Unused. (bSynchAddress)
|
||||
|
||||
/* USB Microphone Class-specific Isoc. Audio Data Endpoint Descriptor */
|
||||
0x07, // Size of the descriptor, in bytes (bLength)
|
||||
AUDIO_ENDPOINT_DESCRIPTOR_TYPE, // CS_ENDPOINT Descriptor Type (bDescriptorType) 0x25
|
||||
AUDIO_ENDPOINT_GENERAL, // GENERAL subtype. (bDescriptorSubtype) 0x01
|
||||
0x00, // No sampling frequency control, no pitch control, no packet padding.(bmAttributes)
|
||||
0x00, // Unused. (bLockDelayUnits)
|
||||
0x00,0x00, // Unused. (wLockDelay)
|
||||
} ;
|
||||
|
||||
|
||||
const usbd_ep_map_t usbdEpMap =
|
||||
{
|
||||
.in = { CLASS_UNUSED, CLASS_CDC, CLASS_CDC, CLASS_AUDIO },
|
||||
.out = { CLASS_UNUSED, CLASS_CDC, CLASS_AUDIO, CLASS_UNUSED }
|
||||
};
|
||||
|
||||
USBD_ClassCompInfo dev_instance[CLASS_NUM] =
|
||||
{
|
||||
{
|
||||
.class = &USBD_AUDIO,
|
||||
.userData = &USBD_AUDIO_fops_FS,
|
||||
.ctrlIf = AUDIO_CTRL_IF,
|
||||
.minIf = AUDIO_CTRL_IF,
|
||||
.maxIf = AUDIO_IN_IF
|
||||
},
|
||||
{
|
||||
.class = &USBD_CDC,
|
||||
.userData = &USBD_Interface_fops_FS,
|
||||
.ctrlIf = CDC_CTRL_IF,
|
||||
.minIf = CDC_CTRL_IF,
|
||||
.maxIf = CDC_DATA_IF
|
||||
}
|
||||
};
|
||||
|
||||
+172
@@ -0,0 +1,172 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file USBD_COMP_cdc_comp.h
|
||||
* @author MCD Application Team/ mcHF Devel
|
||||
* @version V2.4.2
|
||||
* @date 11-December-2015
|
||||
* @brief header file for the USBD_COMP.c file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_COMPOSITE_H
|
||||
#define __USB_COMPOSITE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_ioreq.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_COMP
|
||||
* @brief This file is the Header file for USBD_COMP.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_COMP_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
USBD_ClassTypeDef* class;
|
||||
void* classData;
|
||||
void* userData;
|
||||
uint16_t ctrlIf;
|
||||
uint16_t minIf;
|
||||
uint16_t maxIf;
|
||||
} USBD_ClassCompInfo;
|
||||
|
||||
#define USBD_MAX_EP 3
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t in[USBD_MAX_EP+1];
|
||||
uint8_t out[USBD_MAX_EP+1];
|
||||
} usbd_ep_map_t;
|
||||
|
||||
|
||||
#define CLASS_AUDIO 0
|
||||
#define CLASS_CDC 1
|
||||
#define CLASS_NUM 2
|
||||
#define CLASS_UNUSED 0xFF
|
||||
|
||||
extern usbd_ep_map_t usbdEpMap;
|
||||
|
||||
extern USBD_ClassCompInfo dev_instance[CLASS_NUM];
|
||||
|
||||
#define USB_AUDIO_CONFIG_DESC_SIZ (9+101+73 + 8 + 66 + 9 +7)
|
||||
extern uint8_t USBD_COMP_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ];
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
}
|
||||
USBD_COMP_HandleTypeDef;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
}USBD_COMP_ItfTypeDef;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
#define AUDIO_DESCRIPTOR_TYPE 0x21
|
||||
#define USB_DEVICE_CLASS_AUDIO 0x01
|
||||
#define AUDIO_SUBCLASS_AUDIOCONTROL 0x01
|
||||
#define AUDIO_SUBCLASS_AUDIOSTREAMING 0x02
|
||||
#define AUDIO_PROTOCOL_UNDEFINED 0x00
|
||||
#define AUDIO_STREAMING_GENERAL 0x01
|
||||
#define AUDIO_STREAMING_FORMAT_TYPE 0x02
|
||||
|
||||
/* Audio Descriptor Types */
|
||||
#define AUDIO_INTERFACE_DESCRIPTOR_TYPE 0x24
|
||||
#define AUDIO_ENDPOINT_DESCRIPTOR_TYPE 0x25
|
||||
|
||||
/* Audio Control Interface Descriptor Subtypes */
|
||||
#define AUDIO_CONTROL_HEADER 0x01
|
||||
#define AUDIO_CONTROL_INPUT_TERMINAL 0x02
|
||||
#define AUDIO_CONTROL_OUTPUT_TERMINAL 0x03
|
||||
#define AUDIO_CONTROL_FEATURE_UNIT 0x06
|
||||
|
||||
#define AUDIO_INTERFACE_DESC_SIZE 9
|
||||
#define USB_AUDIO_DESC_SIZ 0x09
|
||||
#define AUDIO_STANDARD_ENDPOINT_DESC_SIZE 0x09
|
||||
#define AUDIO_STREAMING_ENDPOINT_DESC_SIZE 0x07
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern USBD_ClassTypeDef USBD_COMP;
|
||||
#define USBD_COMP_CLASS &USBD_COMP
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t USBD_COMP_RegisterInterface (USBD_HandleTypeDef *pdev,
|
||||
USBD_COMP_ItfTypeDef *fops);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USB_COMPOSITE_H */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,350 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_hid.h
|
||||
* @author MCD Application Team
|
||||
* @version V3.2.2
|
||||
* @date 07-July-2015
|
||||
* @brief This file contains all the prototypes for the usbh_hid.c
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive ----------------------------------------------*/
|
||||
#ifndef __USBH_HID_H
|
||||
#define __USBH_HID_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbh_core.h"
|
||||
#include "usbh_hid_mouse.h"
|
||||
#include "usbh_hid_keybd.h"
|
||||
|
||||
/** @addtogroup USBH_LIB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_HID_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_HID_CORE
|
||||
* @brief This file is the Header file for usbh_hid.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_HID_CORE_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define HID_MIN_POLL 10
|
||||
#define HID_REPORT_SIZE 16
|
||||
#define HID_MAX_USAGE 10
|
||||
#define HID_MAX_NBR_REPORT_FMT 10
|
||||
#define HID_QUEUE_SIZE 10
|
||||
|
||||
#define HID_ITEM_LONG 0xFE
|
||||
|
||||
#define HID_ITEM_TYPE_MAIN 0x00
|
||||
#define HID_ITEM_TYPE_GLOBAL 0x01
|
||||
#define HID_ITEM_TYPE_LOCAL 0x02
|
||||
#define HID_ITEM_TYPE_RESERVED 0x03
|
||||
|
||||
|
||||
#define HID_MAIN_ITEM_TAG_INPUT 0x08
|
||||
#define HID_MAIN_ITEM_TAG_OUTPUT 0x09
|
||||
#define HID_MAIN_ITEM_TAG_COLLECTION 0x0A
|
||||
#define HID_MAIN_ITEM_TAG_FEATURE 0x0B
|
||||
#define HID_MAIN_ITEM_TAG_ENDCOLLECTION 0x0C
|
||||
|
||||
|
||||
#define HID_GLOBAL_ITEM_TAG_USAGE_PAGE 0x00
|
||||
#define HID_GLOBAL_ITEM_TAG_LOG_MIN 0x01
|
||||
#define HID_GLOBAL_ITEM_TAG_LOG_MAX 0x02
|
||||
#define HID_GLOBAL_ITEM_TAG_PHY_MIN 0x03
|
||||
#define HID_GLOBAL_ITEM_TAG_PHY_MAX 0x04
|
||||
#define HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT 0x05
|
||||
#define HID_GLOBAL_ITEM_TAG_UNIT 0x06
|
||||
#define HID_GLOBAL_ITEM_TAG_REPORT_SIZE 0x07
|
||||
#define HID_GLOBAL_ITEM_TAG_REPORT_ID 0x08
|
||||
#define HID_GLOBAL_ITEM_TAG_REPORT_COUNT 0x09
|
||||
#define HID_GLOBAL_ITEM_TAG_PUSH 0x0A
|
||||
#define HID_GLOBAL_ITEM_TAG_POP 0x0B
|
||||
|
||||
|
||||
#define HID_LOCAL_ITEM_TAG_USAGE 0x00
|
||||
#define HID_LOCAL_ITEM_TAG_USAGE_MIN 0x01
|
||||
#define HID_LOCAL_ITEM_TAG_USAGE_MAX 0x02
|
||||
#define HID_LOCAL_ITEM_TAG_DESIGNATOR_INDEX 0x03
|
||||
#define HID_LOCAL_ITEM_TAG_DESIGNATOR_MIN 0x04
|
||||
#define HID_LOCAL_ITEM_TAG_DESIGNATOR_MAX 0x05
|
||||
#define HID_LOCAL_ITEM_TAG_STRING_INDEX 0x07
|
||||
#define HID_LOCAL_ITEM_TAG_STRING_MIN 0x08
|
||||
#define HID_LOCAL_ITEM_TAG_STRING_MAX 0x09
|
||||
#define HID_LOCAL_ITEM_TAG_DELIMITER 0x0A
|
||||
|
||||
|
||||
/* States for HID State Machine */
|
||||
typedef enum
|
||||
{
|
||||
HID_INIT= 0,
|
||||
HID_IDLE,
|
||||
HID_SEND_DATA,
|
||||
HID_BUSY,
|
||||
HID_GET_DATA,
|
||||
HID_SYNC,
|
||||
HID_POLL,
|
||||
HID_ERROR,
|
||||
}
|
||||
HID_StateTypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
HID_REQ_INIT = 0,
|
||||
HID_REQ_IDLE,
|
||||
HID_REQ_GET_REPORT_DESC,
|
||||
HID_REQ_GET_HID_DESC,
|
||||
HID_REQ_SET_IDLE,
|
||||
HID_REQ_SET_PROTOCOL,
|
||||
HID_REQ_SET_REPORT,
|
||||
|
||||
}
|
||||
HID_CtlStateTypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
HID_MOUSE = 0x01,
|
||||
HID_KEYBOARD = 0x02,
|
||||
HID_UNKNOWN = 0xFF,
|
||||
}
|
||||
HID_TypeTypeDef;
|
||||
|
||||
|
||||
typedef struct _HID_ReportData
|
||||
{
|
||||
uint8_t ReportID;
|
||||
uint8_t ReportType;
|
||||
uint16_t UsagePage;
|
||||
uint32_t Usage[HID_MAX_USAGE];
|
||||
uint32_t NbrUsage;
|
||||
uint32_t UsageMin;
|
||||
uint32_t UsageMax;
|
||||
int32_t LogMin;
|
||||
int32_t LogMax;
|
||||
int32_t PhyMin;
|
||||
int32_t PhyMax;
|
||||
int32_t UnitExp;
|
||||
uint32_t Unit;
|
||||
uint32_t ReportSize;
|
||||
uint32_t ReportCnt;
|
||||
uint32_t Flag;
|
||||
uint32_t PhyUsage;
|
||||
uint32_t AppUsage;
|
||||
uint32_t LogUsage;
|
||||
}
|
||||
HID_ReportDataTypeDef;
|
||||
|
||||
typedef struct _HID_ReportIDTypeDef {
|
||||
uint8_t Size; /* Report size return by the device id */
|
||||
uint8_t ReportID; /* Report Id */
|
||||
uint8_t Type; /* Report Type (INPUT/OUTPUT/FEATURE) */
|
||||
} HID_ReportIDTypeDef;
|
||||
|
||||
typedef struct _HID_CollectionTypeDef
|
||||
{
|
||||
uint32_t Usage;
|
||||
uint8_t Type;
|
||||
struct _HID_CollectionTypeDef *NextPtr;
|
||||
} HID_CollectionTypeDef;
|
||||
|
||||
|
||||
typedef struct _HID_AppCollectionTypeDef {
|
||||
uint32_t Usage;
|
||||
uint8_t Type;
|
||||
uint8_t NbrReportFmt;
|
||||
HID_ReportDataTypeDef ReportData[HID_MAX_NBR_REPORT_FMT];
|
||||
} HID_AppCollectionTypeDef;
|
||||
|
||||
|
||||
typedef struct _HIDDescriptor
|
||||
{
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint16_t bcdHID; /* indicates what endpoint this descriptor is describing */
|
||||
uint8_t bCountryCode; /* specifies the transfer type. */
|
||||
uint8_t bNumDescriptors; /* specifies the transfer type. */
|
||||
uint8_t bReportDescriptorType; /* Maximum Packet Size this endpoint is capable of sending or receiving */
|
||||
uint16_t wItemLength; /* is used to specify the polling interval of certain transfers. */
|
||||
}
|
||||
HID_DescTypeDef;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t *buf;
|
||||
uint16_t head;
|
||||
uint16_t tail;
|
||||
uint16_t size;
|
||||
uint8_t lock;
|
||||
} FIFO_TypeDef;
|
||||
|
||||
|
||||
/* Structure for HID process */
|
||||
typedef struct _HID_Process
|
||||
{
|
||||
uint8_t OutPipe;
|
||||
uint8_t InPipe;
|
||||
HID_StateTypeDef state;
|
||||
uint8_t OutEp;
|
||||
uint8_t InEp;
|
||||
HID_CtlStateTypeDef ctl_state;
|
||||
FIFO_TypeDef fifo;
|
||||
uint8_t *pData;
|
||||
uint16_t length;
|
||||
uint8_t ep_addr;
|
||||
uint16_t poll;
|
||||
uint32_t timer;
|
||||
uint8_t DataReady;
|
||||
HID_DescTypeDef HID_Desc;
|
||||
USBH_StatusTypeDef ( * Init)(USBH_HandleTypeDef *phost);
|
||||
}
|
||||
HID_HandleTypeDef;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_HID_CORE_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define USB_HID_GET_REPORT 0x01
|
||||
#define USB_HID_GET_IDLE 0x02
|
||||
#define USB_HID_GET_PROTOCOL 0x03
|
||||
#define USB_HID_SET_REPORT 0x09
|
||||
#define USB_HID_SET_IDLE 0x0A
|
||||
#define USB_HID_SET_PROTOCOL 0x0B
|
||||
|
||||
|
||||
|
||||
|
||||
/* HID Class Codes */
|
||||
#define USB_HID_CLASS 0x03
|
||||
|
||||
/* Interface Descriptor field values for HID Boot Protocol */
|
||||
#define HID_BOOT_CODE 0x01
|
||||
#define HID_KEYBRD_BOOT_CODE 0x01
|
||||
#define HID_MOUSE_BOOT_CODE 0x02
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_HID_CORE_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_HID_CORE_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
extern USBH_ClassTypeDef HID_Class;
|
||||
#define USBH_HID_CLASS &HID_Class
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_HID_CORE_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
|
||||
USBH_StatusTypeDef USBH_HID_SetReport (USBH_HandleTypeDef *phost,
|
||||
uint8_t reportType,
|
||||
uint8_t reportId,
|
||||
uint8_t* reportBuff,
|
||||
uint8_t reportLen);
|
||||
|
||||
USBH_StatusTypeDef USBH_HID_GetReport (USBH_HandleTypeDef *phost,
|
||||
uint8_t reportType,
|
||||
uint8_t reportId,
|
||||
uint8_t* reportBuff,
|
||||
uint8_t reportLen);
|
||||
|
||||
USBH_StatusTypeDef USBH_HID_GetHIDReportDescriptor (USBH_HandleTypeDef *phost,
|
||||
uint16_t length);
|
||||
|
||||
USBH_StatusTypeDef USBH_HID_GetHIDDescriptor (USBH_HandleTypeDef *phost,
|
||||
uint16_t length);
|
||||
|
||||
USBH_StatusTypeDef USBH_HID_SetIdle (USBH_HandleTypeDef *phost,
|
||||
uint8_t duration,
|
||||
uint8_t reportId);
|
||||
|
||||
USBH_StatusTypeDef USBH_HID_SetProtocol (USBH_HandleTypeDef *phost,
|
||||
uint8_t protocol);
|
||||
|
||||
void USBH_HID_EventCallback(USBH_HandleTypeDef *phost);
|
||||
|
||||
HID_TypeTypeDef USBH_HID_GetDeviceType(USBH_HandleTypeDef *phost);
|
||||
|
||||
uint8_t USBH_HID_GetPollInterval(USBH_HandleTypeDef *phost);
|
||||
|
||||
void hid_fifo_init(FIFO_TypeDef * f, uint8_t * buf, uint16_t size);
|
||||
|
||||
uint16_t hid_fifo_read(FIFO_TypeDef * f, void * buf, uint16_t nbytes);
|
||||
|
||||
uint16_t hid_fifo_write(FIFO_TypeDef * f, const void * buf, uint16_t nbytes);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBH_HID_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
+326
@@ -0,0 +1,326 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_hid_keybd.h
|
||||
* @author MCD Application Team
|
||||
* @version V3.2.2
|
||||
* @date 07-July-2015
|
||||
* @brief This file contains all the prototypes for the usbh_hid_keybd.c
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive -----------------------------------------------*/
|
||||
#ifndef __USBH_HID_KEYBD_H
|
||||
#define __USBH_HID_KEYBD_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbh_hid.h"
|
||||
#include "usbh_hid_keybd.h"
|
||||
|
||||
/** @addtogroup USBH_LIB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_HID_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_HID_KEYBD
|
||||
* @brief This file is the Header file for usbh_hid_keybd.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_HID_KEYBD_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
#define KEY_NONE 0x00
|
||||
#define KEY_ERRORROLLOVER 0x01
|
||||
#define KEY_POSTFAIL 0x02
|
||||
#define KEY_ERRORUNDEFINED 0x03
|
||||
#define KEY_A 0x04
|
||||
#define KEY_B 0x05
|
||||
#define KEY_C 0x06
|
||||
#define KEY_D 0x07
|
||||
#define KEY_E 0x08
|
||||
#define KEY_F 0x09
|
||||
#define KEY_G 0x0A
|
||||
#define KEY_H 0x0B
|
||||
#define KEY_I 0x0C
|
||||
#define KEY_J 0x0D
|
||||
#define KEY_K 0x0E
|
||||
#define KEY_L 0x0F
|
||||
#define KEY_M 0x10
|
||||
#define KEY_N 0x11
|
||||
#define KEY_O 0x12
|
||||
#define KEY_P 0x13
|
||||
#define KEY_Q 0x14
|
||||
#define KEY_R 0x15
|
||||
#define KEY_S 0x16
|
||||
#define KEY_T 0x17
|
||||
#define KEY_U 0x18
|
||||
#define KEY_V 0x19
|
||||
#define KEY_W 0x1A
|
||||
#define KEY_X 0x1B
|
||||
#define KEY_Y 0x1C
|
||||
#define KEY_Z 0x1D
|
||||
#define KEY_1_EXCLAMATION_MARK 0x1E
|
||||
#define KEY_2_AT 0x1F
|
||||
#define KEY_3_NUMBER_SIGN 0x20
|
||||
#define KEY_4_DOLLAR 0x21
|
||||
#define KEY_5_PERCENT 0x22
|
||||
#define KEY_6_CARET 0x23
|
||||
#define KEY_7_AMPERSAND 0x24
|
||||
#define KEY_8_ASTERISK 0x25
|
||||
#define KEY_9_OPARENTHESIS 0x26
|
||||
#define KEY_0_CPARENTHESIS 0x27
|
||||
#define KEY_ENTER 0x28
|
||||
#define KEY_ESCAPE 0x29
|
||||
#define KEY_BACKSPACE 0x2A
|
||||
#define KEY_TAB 0x2B
|
||||
#define KEY_SPACEBAR 0x2C
|
||||
#define KEY_MINUS_UNDERSCORE 0x2D
|
||||
#define KEY_EQUAL_PLUS 0x2E
|
||||
#define KEY_OBRACKET_AND_OBRACE 0x2F
|
||||
#define KEY_CBRACKET_AND_CBRACE 0x30
|
||||
#define KEY_BACKSLASH_VERTICAL_BAR 0x31
|
||||
#define KEY_NONUS_NUMBER_SIGN_TILDE 0x32
|
||||
#define KEY_SEMICOLON_COLON 0x33
|
||||
#define KEY_SINGLE_AND_DOUBLE_QUOTE 0x34
|
||||
#define KEY_GRAVE ACCENT AND TILDE 0x35
|
||||
#define KEY_COMMA_AND_LESS 0x36
|
||||
#define KEY_DOT_GREATER 0x37
|
||||
#define KEY_SLASH_QUESTION 0x38
|
||||
#define KEY_CAPS LOCK 0x39
|
||||
#define KEY_F1 0x3A
|
||||
#define KEY_F2 0x3B
|
||||
#define KEY_F3 0x3C
|
||||
#define KEY_F4 0x3D
|
||||
#define KEY_F5 0x3E
|
||||
#define KEY_F6 0x3F
|
||||
#define KEY_F7 0x40
|
||||
#define KEY_F8 0x41
|
||||
#define KEY_F9 0x42
|
||||
#define KEY_F10 0x43
|
||||
#define KEY_F11 0x44
|
||||
#define KEY_F12 0x45
|
||||
#define KEY_PRINTSCREEN 0x46
|
||||
#define KEY_SCROLL LOCK 0x47
|
||||
#define KEY_PAUSE 0x48
|
||||
#define KEY_INSERT 0x49
|
||||
#define KEY_HOME 0x4A
|
||||
#define KEY_PAGEUP 0x4B
|
||||
#define KEY_DELETE 0x4C
|
||||
#define KEY_END1 0x4D
|
||||
#define KEY_PAGEDOWN 0x4E
|
||||
#define KEY_RIGHTARROW 0x4F
|
||||
#define KEY_LEFTARROW 0x50
|
||||
#define KEY_DOWNARROW 0x51
|
||||
#define KEY_UPARROW 0x52
|
||||
#define KEY_KEYPAD_NUM_LOCK_AND_CLEAR 0x53
|
||||
#define KEY_KEYPAD_SLASH 0x54
|
||||
#define KEY_KEYPAD_ASTERIKS 0x55
|
||||
#define KEY_KEYPAD_MINUS 0x56
|
||||
#define KEY_KEYPAD_PLUS 0x57
|
||||
#define KEY_KEYPAD_ENTER 0x58
|
||||
#define KEY_KEYPAD_1_END 0x59
|
||||
#define KEY_KEYPAD_2_DOWN_ARROW 0x5A
|
||||
#define KEY_KEYPAD_3_PAGEDN 0x5B
|
||||
#define KEY_KEYPAD_4_LEFT_ARROW 0x5C
|
||||
#define KEY_KEYPAD_5 0x5D
|
||||
#define KEY_KEYPAD_6_RIGHT_ARROW 0x5E
|
||||
#define KEY_KEYPAD_7_HOME 0x5F
|
||||
#define KEY_KEYPAD_8_UP_ARROW 0x60
|
||||
#define KEY_KEYPAD_9_PAGEUP 0x61
|
||||
#define KEY_KEYPAD_0_INSERT 0x62
|
||||
#define KEY_KEYPAD_DECIMAL_SEPARATOR_DELETE 0x63
|
||||
#define KEY_NONUS_BACK_SLASH_VERTICAL_BAR 0x64
|
||||
#define KEY_APPLICATION 0x65
|
||||
#define KEY_POWER 0x66
|
||||
#define KEY_KEYPAD_EQUAL 0x67
|
||||
#define KEY_F13 0x68
|
||||
#define KEY_F14 0x69
|
||||
#define KEY_F15 0x6A
|
||||
#define KEY_F16 0x6B
|
||||
#define KEY_F17 0x6C
|
||||
#define KEY_F18 0x6D
|
||||
#define KEY_F19 0x6E
|
||||
#define KEY_F20 0x6F
|
||||
#define KEY_F21 0x70
|
||||
#define KEY_F22 0x71
|
||||
#define KEY_F23 0x72
|
||||
#define KEY_F24 0x73
|
||||
#define KEY_EXECUTE 0x74
|
||||
#define KEY_HELP 0x75
|
||||
#define KEY_MENU 0x76
|
||||
#define KEY_SELECT 0x77
|
||||
#define KEY_STOP 0x78
|
||||
#define KEY_AGAIN 0x79
|
||||
#define KEY_UNDO 0x7A
|
||||
#define KEY_CUT 0x7B
|
||||
#define KEY_COPY 0x7C
|
||||
#define KEY_PASTE 0x7D
|
||||
#define KEY_FIND 0x7E
|
||||
#define KEY_MUTE 0x7F
|
||||
#define KEY_VOLUME_UP 0x80
|
||||
#define KEY_VOLUME_DOWN 0x81
|
||||
#define KEY_LOCKING_CAPS_LOCK 0x82
|
||||
#define KEY_LOCKING_NUM_LOCK 0x83
|
||||
#define KEY_LOCKING_SCROLL_LOCK 0x84
|
||||
#define KEY_KEYPAD_COMMA 0x85
|
||||
#define KEY_KEYPAD_EQUAL_SIGN 0x86
|
||||
#define KEY_INTERNATIONAL1 0x87
|
||||
#define KEY_INTERNATIONAL2 0x88
|
||||
#define KEY_INTERNATIONAL3 0x89
|
||||
#define KEY_INTERNATIONAL4 0x8A
|
||||
#define KEY_INTERNATIONAL5 0x8B
|
||||
#define KEY_INTERNATIONAL6 0x8C
|
||||
#define KEY_INTERNATIONAL7 0x8D
|
||||
#define KEY_INTERNATIONAL8 0x8E
|
||||
#define KEY_INTERNATIONAL9 0x8F
|
||||
#define KEY_LANG1 0x90
|
||||
#define KEY_LANG2 0x91
|
||||
#define KEY_LANG3 0x92
|
||||
#define KEY_LANG4 0x93
|
||||
#define KEY_LANG5 0x94
|
||||
#define KEY_LANG6 0x95
|
||||
#define KEY_LANG7 0x96
|
||||
#define KEY_LANG8 0x97
|
||||
#define KEY_LANG9 0x98
|
||||
#define KEY_ALTERNATE_ERASE 0x99
|
||||
#define KEY_SYSREQ 0x9A
|
||||
#define KEY_CANCEL 0x9B
|
||||
#define KEY_CLEAR 0x9C
|
||||
#define KEY_PRIOR 0x9D
|
||||
#define KEY_RETURN 0x9E
|
||||
#define KEY_SEPARATOR 0x9F
|
||||
#define KEY_OUT 0xA0
|
||||
#define KEY_OPER 0xA1
|
||||
#define KEY_CLEAR_AGAIN 0xA2
|
||||
#define KEY_CRSEL 0xA3
|
||||
#define KEY_EXSEL 0xA4
|
||||
#define KEY_KEYPAD_00 0xB0
|
||||
#define KEY_KEYPAD_000 0xB1
|
||||
#define KEY_THOUSANDS_SEPARATOR 0xB2
|
||||
#define KEY_DECIMAL_SEPARATOR 0xB3
|
||||
#define KEY_CURRENCY_UNIT 0xB4
|
||||
#define KEY_CURRENCY_SUB_UNIT 0xB5
|
||||
#define KEY_KEYPAD_OPARENTHESIS 0xB6
|
||||
#define KEY_KEYPAD_CPARENTHESIS 0xB7
|
||||
#define KEY_KEYPAD_OBRACE 0xB8
|
||||
#define KEY_KEYPAD_CBRACE 0xB9
|
||||
#define KEY_KEYPAD_TAB 0xBA
|
||||
#define KEY_KEYPAD_BACKSPACE 0xBB
|
||||
#define KEY_KEYPAD_A 0xBC
|
||||
#define KEY_KEYPAD_B 0xBD
|
||||
#define KEY_KEYPAD_C 0xBE
|
||||
#define KEY_KEYPAD_D 0xBF
|
||||
#define KEY_KEYPAD_E 0xC0
|
||||
#define KEY_KEYPAD_F 0xC1
|
||||
#define KEY_KEYPAD_XOR 0xC2
|
||||
#define KEY_KEYPAD_CARET 0xC3
|
||||
#define KEY_KEYPAD_PERCENT 0xC4
|
||||
#define KEY_KEYPAD_LESS 0xC5
|
||||
#define KEY_KEYPAD_GREATER 0xC6
|
||||
#define KEY_KEYPAD_AMPERSAND 0xC7
|
||||
#define KEY_KEYPAD_LOGICAL_AND 0xC8
|
||||
#define KEY_KEYPAD_VERTICAL_BAR 0xC9
|
||||
#define KEY_KEYPAD_LOGIACL_OR 0xCA
|
||||
#define KEY_KEYPAD_COLON 0xCB
|
||||
#define KEY_KEYPAD_NUMBER_SIGN 0xCC
|
||||
#define KEY_KEYPAD_SPACE 0xCD
|
||||
#define KEY_KEYPAD_AT 0xCE
|
||||
#define KEY_KEYPAD_EXCLAMATION_MARK 0xCF
|
||||
#define KEY_KEYPAD_MEMORY_STORE 0xD0
|
||||
#define KEY_KEYPAD_MEMORY_RECALL 0xD1
|
||||
#define KEY_KEYPAD_MEMORY_CLEAR 0xD2
|
||||
#define KEY_KEYPAD_MEMORY_ADD 0xD3
|
||||
#define KEY_KEYPAD_MEMORY_SUBTRACT 0xD4
|
||||
#define KEY_KEYPAD_MEMORY_MULTIPLY 0xD5
|
||||
#define KEY_KEYPAD_MEMORY_DIVIDE 0xD6
|
||||
#define KEY_KEYPAD_PLUSMINUS 0xD7
|
||||
#define KEY_KEYPAD_CLEAR 0xD8
|
||||
#define KEY_KEYPAD_CLEAR_ENTRY 0xD9
|
||||
#define KEY_KEYPAD_BINARY 0xDA
|
||||
#define KEY_KEYPAD_OCTAL 0xDB
|
||||
#define KEY_KEYPAD_DECIMAL 0xDC
|
||||
#define KEY_KEYPAD_HEXADECIMAL 0xDD
|
||||
#define KEY_LEFTCONTROL 0xE0
|
||||
#define KEY_LEFTSHIFT 0xE1
|
||||
#define KEY_LEFTALT 0xE2
|
||||
#define KEY_LEFT_GUI 0xE3
|
||||
#define KEY_RIGHTCONTROL 0xE4
|
||||
#define KEY_RIGHTSHIFT 0xE5
|
||||
#define KEY_RIGHTALT 0xE6
|
||||
#define KEY_RIGHT_GUI 0xE7
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t state;
|
||||
uint8_t lctrl;
|
||||
uint8_t lshift;
|
||||
uint8_t lalt;
|
||||
uint8_t lgui;
|
||||
uint8_t rctrl;
|
||||
uint8_t rshift;
|
||||
uint8_t ralt;
|
||||
uint8_t rgui;
|
||||
uint8_t keys[6];
|
||||
}
|
||||
HID_KEYBD_Info_TypeDef;
|
||||
|
||||
USBH_StatusTypeDef USBH_HID_KeybdInit(USBH_HandleTypeDef *phost);
|
||||
HID_KEYBD_Info_TypeDef *USBH_HID_GetKeybdInfo(USBH_HandleTypeDef *phost);
|
||||
uint8_t USBH_HID_GetASCIICode(HID_KEYBD_Info_TypeDef *info, uint32_t idx);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBH_HID_KEYBD_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_hid_mouse.h
|
||||
* @author MCD Application Team
|
||||
* @version V3.2.2
|
||||
* @date 07-July-2015
|
||||
* @brief This file contains all the prototypes for the usbh_hid_mouse.c
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive ----------------------------------------------*/
|
||||
#ifndef __USBH_HID_MOUSE_H
|
||||
#define __USBH_HID_MOUSE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbh_hid.h"
|
||||
|
||||
/** @addtogroup USBH_LIB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_HID_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_HID_MOUSE
|
||||
* @brief This file is the Header file for usbh_hid_mouse.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_HID_MOUSE_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef struct _HID_MOUSE_Info
|
||||
{
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
uint8_t buttons[3];
|
||||
}
|
||||
HID_MOUSE_Info_TypeDef;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_HID_MOUSE_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_HID_MOUSE_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_HID_MOUSE_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_HID_MOUSE_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_HID_MouseInit(USBH_HandleTypeDef *phost);
|
||||
HID_MOUSE_Info_TypeDef *USBH_HID_GetMouseInfo(USBH_HandleTypeDef *phost);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBH_HID_MOUSE_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_hid_parser.c
|
||||
* @author MCD Application Team
|
||||
* @version V3.2.2
|
||||
* @date 07-July-2015
|
||||
* @brief This file is the header file of the usbh_hid_parser.c
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive -----------------------------------------------*/
|
||||
#ifndef __USBH_HID_PARSER_H
|
||||
#define __USBH_HID_PARSER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbh_hid.h"
|
||||
#include "usbh_hid_usage.h"
|
||||
|
||||
/** @addtogroup USBH_LIB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_HID_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_HID_PARSER
|
||||
* @brief This file is the Header file for usbh_hid_parser.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_HID_PARSER_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t *data;
|
||||
uint32_t size;
|
||||
uint8_t shift;
|
||||
uint8_t count;
|
||||
uint8_t sign;
|
||||
uint32_t logical_min; /*min value device can return*/
|
||||
uint32_t logical_max; /*max value device can return*/
|
||||
uint32_t physical_min; /*min vale read can report*/
|
||||
uint32_t physical_max; /*max value read can report*/
|
||||
uint32_t resolution;
|
||||
}
|
||||
HID_Report_ItemTypedef;
|
||||
|
||||
|
||||
uint32_t HID_ReadItem (HID_Report_ItemTypedef *ri, uint8_t ndx);
|
||||
uint32_t HID_WriteItem(HID_Report_ItemTypedef *ri, uint32_t value, uint8_t ndx);
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBH_HID_PARSER_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+200
@@ -0,0 +1,200 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_hid_usage.c
|
||||
* @author MCD Application Team
|
||||
* @version V3.2.2
|
||||
* @date 07-July-2015
|
||||
* @brief This file contain the USAGE page codes
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* Define to prevent recursive ----------------------------------------------*/
|
||||
#ifndef __USDH_HID_USAGE_H
|
||||
#define __USDH_HID_USAGE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @addtogroup USBH_LIB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_HID_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_HID_USAGE
|
||||
* @brief This file is the Header file for usbh_hid_usage.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_HID_USAGE_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/****************************************************/
|
||||
/* HID 1.11 usage pages */
|
||||
/****************************************************/
|
||||
|
||||
#define HID_USAGE_PAGE_UNDEFINED uint16_t (0x00) /* Undefined */
|
||||
/**** Top level pages */
|
||||
#define HID_USAGE_PAGE_GEN_DES uint16_t (0x01) /* Generic Desktop Controls*/
|
||||
#define HID_USAGE_PAGE_SIM_CTR uint16_t (0x02) /* Simulation Controls */
|
||||
#define HID_USAGE_PAGE_VR_CTR uint16_t (0x03) /* VR Controls */
|
||||
#define HID_USAGE_PAGE_SPORT_CTR uint16_t (0x04) /* Sport Controls */
|
||||
#define HID_USAGE_PAGE_GAME_CTR uint16_t (0x05) /* Game Controls */
|
||||
#define HID_USAGE_PAGE_GEN_DEV uint16_t (0x06) /* Generic Device Controls */
|
||||
#define HID_USAGE_PAGE_KEYB uint16_t (0x07) /* Keyboard/Keypad */
|
||||
#define HID_USAGE_PAGE_LED uint16_t (0x08) /* LEDs */
|
||||
#define HID_USAGE_PAGE_BUTTON uint16_t (0x09) /* Button */
|
||||
#define HID_USAGE_PAGE_ORDINAL uint16_t (0x0A) /* Ordinal */
|
||||
#define HID_USAGE_PAGE_PHONE uint16_t (0x0B) /* Telephony */
|
||||
#define HID_USAGE_PAGE_CONSUMER uint16_t (0x0C) /* Consumer */
|
||||
#define HID_USAGE_PAGE_DIGITIZER uint16_t (0x0D) /* Digitizer*/
|
||||
/* 0E Reserved */
|
||||
#define HID_USAGE_PAGE_PID uint16_t (0x0F) /* PID Page (force feedback and related devices) */
|
||||
#define HID_USAGE_PAGE_UNICODE uint16_t (0x10) /* Unicode */
|
||||
/* 11-13 Reserved */
|
||||
#define HID_USAGE_PAGE_ALNUM_DISP uint16_t (0x14) /* Alphanumeric Display */
|
||||
/* 15-1f Reserved */
|
||||
/**** END of top level pages */
|
||||
/* 25-3f Reserved */
|
||||
#define HID_USAGE_PAGE_MEDICAL uint16_t (0x40) /* Medical Instruments */
|
||||
/* 41-7F Reserved */
|
||||
/*80-83 Monitor pages USB Device Class Definition for Monitor Devices
|
||||
84-87 Power pages USB Device Class Definition for Power Devices */
|
||||
/* 88-8B Reserved */
|
||||
#define HID_USAGE_PAGE_BARCODE uint16_t (0x8C) /* Bar Code Scanner page */
|
||||
#define HID_USAGE_PAGE_SCALE uint16_t (0x8D) /* Scale page */
|
||||
#define HID_USAGE_PAGE_MSR uint16_t (0x8E) /* Magnetic Stripe Reading (MSR) Devices */
|
||||
#define HID_USAGE_PAGE_POS uint16_t (0x8F) /* Reserved Point of Sale pages */
|
||||
#define HID_USAGE_PAGE_CAMERA_CTR uint16_t (0x90) /* Camera Control Page */
|
||||
#define HID_USAGE_PAGE_ARCADE uint16_t (0x91) /* Arcade Page */
|
||||
|
||||
/****************************************************/
|
||||
/* Usage definitions for the "Generic Desktop" page */
|
||||
/****************************************************/
|
||||
#define HID_USAGE_UNDEFINED uint16_t (0x00) /* Undefined */
|
||||
#define HID_USAGE_POINTER uint16_t (0x01) /* Pointer (Physical Collection) */
|
||||
#define HID_USAGE_MOUSE uint16_t (0x02) /* Mouse (Application Collection) */
|
||||
/* 03 Reserved */
|
||||
#define HID_USAGE_JOYSTICK uint16_t (0x04) /* Joystick (Application Collection) */
|
||||
#define HID_USAGE_GAMEPAD uint16_t (0x05) /* Game Pad (Application Collection) */
|
||||
#define HID_USAGE_KBD uint16_t (0x06) /* Keyboard (Application Collection) */
|
||||
#define HID_USAGE_KEYPAD uint16_t (0x07) /* Keypad (Application Collection) */
|
||||
#define HID_USAGE_MAX_CTR uint16_t (0x08) /* Multi-axis Controller (Application Collection) */
|
||||
/* 09-2F Reserved */
|
||||
#define HID_USAGE_X uint16_t (0x30) /* X (Dynamic Value) */
|
||||
#define HID_USAGE_Y uint16_t (0x31) /* Y (Dynamic Value) */
|
||||
#define HID_USAGE_Z uint16_t (0x32) /* Z (Dynamic Value) */
|
||||
#define HID_USAGE_RX uint16_t (0x33) /* Rx (Dynamic Value) */
|
||||
#define HID_USAGE_RY uint16_t (0x34) /* Ry (Dynamic Value) */
|
||||
#define HID_USAGE_RZ uint16_t (0x35) /* Rz (Dynamic Value) */
|
||||
#define HID_USAGE_SLIDER uint16_t (0x36) /* Slider (Dynamic Value) */
|
||||
#define HID_USAGE_DIAL uint16_t (0x37) /* Dial (Dynamic Value) */
|
||||
#define HID_USAGE_WHEEL uint16_t (0x38) /* Wheel (Dynamic Value) */
|
||||
#define HID_USAGE_HATSW uint16_t (0x39) /* Hat switch (Dynamic Value) */
|
||||
#define HID_USAGE_COUNTEDBUF uint16_t (0x3A) /* Counted Buffer (Logical Collection) */
|
||||
#define HID_USAGE_BYTECOUNT uint16_t (0x3B) /* Byte Count (Dynamic Value) */
|
||||
#define HID_USAGE_MOTIONWAKE uint16_t (0x3C) /* Motion Wakeup (One Shot Control) */
|
||||
#define HID_USAGE_START uint16_t (0x3D) /* Start (On/Off Control) */
|
||||
#define HID_USAGE_SELECT uint16_t (0x3E) /* Select (On/Off Control) */
|
||||
/* 3F Reserved */
|
||||
#define HID_USAGE_VX uint16_t (0x40) /* Vx (Dynamic Value) */
|
||||
#define HID_USAGE_VY uint16_t (0x41) /* Vy (Dynamic Value) */
|
||||
#define HID_USAGE_VZ uint16_t (0x42) /* Vz (Dynamic Value) */
|
||||
#define HID_USAGE_VBRX uint16_t (0x43) /* Vbrx (Dynamic Value) */
|
||||
#define HID_USAGE_VBRY uint16_t (0x44) /* Vbry (Dynamic Value) */
|
||||
#define HID_USAGE_VBRZ uint16_t (0x45) /* Vbrz (Dynamic Value) */
|
||||
#define HID_USAGE_VNO uint16_t (0x46) /* Vno (Dynamic Value) */
|
||||
#define HID_USAGE_FEATNOTIF uint16_t (0x47) /* Feature Notification (Dynamic Value),(Dynamic Flag) */
|
||||
/* 48-7F Reserved */
|
||||
#define HID_USAGE_SYSCTL uint16_t (0x80) /* System Control (Application Collection) */
|
||||
#define HID_USAGE_PWDOWN uint16_t (0x81) /* System Power Down (One Shot Control) */
|
||||
#define HID_USAGE_SLEEP uint16_t (0x82) /* System Sleep (One Shot Control) */
|
||||
#define HID_USAGE_WAKEUP uint16_t (0x83) /* System Wake Up (One Shot Control) */
|
||||
#define HID_USAGE_CONTEXTM uint16_t (0x84) /* System Context Menu (One Shot Control) */
|
||||
#define HID_USAGE_MAINM uint16_t (0x85) /* System Main Menu (One Shot Control) */
|
||||
#define HID_USAGE_APPM uint16_t (0x86) /* System App Menu (One Shot Control) */
|
||||
#define HID_USAGE_MENUHELP uint16_t (0x87) /* System Menu Help (One Shot Control) */
|
||||
#define HID_USAGE_MENUEXIT uint16_t (0x88) /* System Menu Exit (One Shot Control) */
|
||||
#define HID_USAGE_MENUSELECT uint16_t (0x89) /* System Menu Select (One Shot Control) */
|
||||
#define HID_USAGE_SYSM_RIGHT uint16_t (0x8A) /* System Menu Right (Re-Trigger Control) */
|
||||
#define HID_USAGE_SYSM_LEFT uint16_t (0x8B) /* System Menu Left (Re-Trigger Control) */
|
||||
#define HID_USAGE_SYSM_UP uint16_t (0x8C) /* System Menu Up (Re-Trigger Control) */
|
||||
#define HID_USAGE_SYSM_DOWN uint16_t (0x8D) /* System Menu Down (Re-Trigger Control) */
|
||||
#define HID_USAGE_COLDRESET uint16_t (0x8E) /* System Cold Restart (One Shot Control) */
|
||||
#define HID_USAGE_WARMRESET uint16_t (0x8F) /* System Warm Restart (One Shot Control) */
|
||||
#define HID_USAGE_DUP uint16_t (0x90) /* D-pad Up (On/Off Control) */
|
||||
#define HID_USAGE_DDOWN uint16_t (0x91) /* D-pad Down (On/Off Control) */
|
||||
#define HID_USAGE_DRIGHT uint16_t (0x92) /* D-pad Right (On/Off Control) */
|
||||
#define HID_USAGE_DLEFT uint16_t (0x93) /* D-pad Left (On/Off Control) */
|
||||
/* 94-9F Reserved */
|
||||
#define HID_USAGE_SYS_DOCK uint16_t (0xA0) /* System Dock (One Shot Control) */
|
||||
#define HID_USAGE_SYS_UNDOCK uint16_t (0xA1) /* System Undock (One Shot Control) */
|
||||
#define HID_USAGE_SYS_SETUP uint16_t (0xA2) /* System Setup (One Shot Control) */
|
||||
#define HID_USAGE_SYS_BREAK uint16_t (0xA3) /* System Break (One Shot Control) */
|
||||
#define HID_USAGE_SYS_DBGBRK uint16_t (0xA4) /* System Debugger Break (One Shot Control) */
|
||||
#define HID_USAGE_APP_BRK uint16_t (0xA5) /* Application Break (One Shot Control) */
|
||||
#define HID_USAGE_APP_DBGBRK uint16_t (0xA6) /* Application Debugger Break (One Shot Control) */
|
||||
#define HID_USAGE_SYS_SPKMUTE uint16_t (0xA7) /* System Speaker Mute (One Shot Control) */
|
||||
#define HID_USAGE_SYS_HIBERN uint16_t (0xA8) /* System Hibernate (One Shot Control) */
|
||||
/* A9-AF Reserved */
|
||||
#define HID_USAGE_SYS_SIDPINV uint16_t (0xB0) /* System Display Invert (One Shot Control) */
|
||||
#define HID_USAGE_SYS_DISPINT uint16_t (0xB1) /* System Display Internal (One Shot Control) */
|
||||
#define HID_USAGE_SYS_DISPEXT uint16_t (0xB2) /* System Display External (One Shot Control) */
|
||||
#define HID_USAGE_SYS_DISPBOTH uint16_t (0xB3) /* System Display Both (One Shot Control) */
|
||||
#define HID_USAGE_SYS_DISPDUAL uint16_t (0xB4) /* System Display Dual (One Shot Control) */
|
||||
#define HID_USAGE_SYS_DISPTGLIE uint16_t (0xB5) /* System Display Toggle Int/Ext (One Shot Control) */
|
||||
#define HID_USAGE_SYS_DISP_SWAP uint16_t (0xB6) /* System Display Swap Primary/Secondary (One Shot Control) */
|
||||
#define HID_USAGE_SYS_DIPS_LCDA uint16_t (0xB7) /* System Display LCD Autoscale (One Shot Control) */
|
||||
/* B8-FFFF Reserved */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USDH_HID_USAGE_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,824 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_hid.c
|
||||
* @author MCD Application Team
|
||||
* @version V3.2.2
|
||||
* @date 07-July-2015
|
||||
* @brief This file is the HID Layer Handlers for USB Host HID class.
|
||||
*
|
||||
* @verbatim
|
||||
*
|
||||
* ===================================================================
|
||||
* HID Class Description
|
||||
* ===================================================================
|
||||
* This module manages the HID class V1.11 following the "Device Class Definition
|
||||
* for Human Interface Devices (HID) Version 1.11 Jun 27, 2001".
|
||||
* This driver implements the following aspects of the specification:
|
||||
* - The Boot Interface Subclass
|
||||
* - The Mouse and Keyboard protocols
|
||||
*
|
||||
* @endverbatim
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbh_hid.h"
|
||||
#include "usbh_hid_parser.h"
|
||||
|
||||
|
||||
/** @addtogroup USBH_LIB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_HID_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_HID_CORE
|
||||
* @brief This file includes HID Layer Handlers for USB Host HID class.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_HID_CORE_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_HID_CORE_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_HID_CORE_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_HID_CORE_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_HID_CORE_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
static USBH_StatusTypeDef USBH_HID_InterfaceInit (USBH_HandleTypeDef *phost);
|
||||
static USBH_StatusTypeDef USBH_HID_InterfaceDeInit (USBH_HandleTypeDef *phost);
|
||||
static USBH_StatusTypeDef USBH_HID_ClassRequest(USBH_HandleTypeDef *phost);
|
||||
static USBH_StatusTypeDef USBH_HID_Process(USBH_HandleTypeDef *phost);
|
||||
static USBH_StatusTypeDef USBH_HID_SOFProcess(USBH_HandleTypeDef *phost);
|
||||
static void USBH_HID_ParseHIDDesc (HID_DescTypeDef *desc, uint8_t *buf);
|
||||
|
||||
extern USBH_StatusTypeDef USBH_HID_MouseInit(USBH_HandleTypeDef *phost);
|
||||
extern USBH_StatusTypeDef USBH_HID_KeybdInit(USBH_HandleTypeDef *phost);
|
||||
|
||||
USBH_ClassTypeDef HID_Class =
|
||||
{
|
||||
"HID",
|
||||
USB_HID_CLASS,
|
||||
USBH_HID_InterfaceInit,
|
||||
USBH_HID_InterfaceDeInit,
|
||||
USBH_HID_ClassRequest,
|
||||
USBH_HID_Process,
|
||||
USBH_HID_SOFProcess,
|
||||
NULL,
|
||||
};
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_HID_CORE_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBH_HID_InterfaceInit
|
||||
* The function init the HID class.
|
||||
* @param phost: Host handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
static USBH_StatusTypeDef USBH_HID_InterfaceInit (USBH_HandleTypeDef *phost)
|
||||
{
|
||||
uint8_t max_ep;
|
||||
uint8_t num = 0;
|
||||
uint8_t interface;
|
||||
|
||||
USBH_StatusTypeDef status = USBH_FAIL ;
|
||||
HID_HandleTypeDef *HID_Handle;
|
||||
|
||||
interface = USBH_FindInterface(phost, phost->pActiveClass->ClassCode, HID_BOOT_CODE, 0xFF);
|
||||
|
||||
if(interface == 0xFF) /* No Valid Interface */
|
||||
{
|
||||
status = USBH_FAIL;
|
||||
USBH_DbgLog ("Cannot Find the interface for %s class.", phost->pActiveClass->Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBH_SelectInterface (phost, interface);
|
||||
phost->pActiveClass->pData = (HID_HandleTypeDef *)USBH_malloc (sizeof(HID_HandleTypeDef));
|
||||
HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData;
|
||||
HID_Handle->state = HID_ERROR;
|
||||
|
||||
/*Decode Bootclass Protocol: Mouse or Keyboard*/
|
||||
if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol == HID_KEYBRD_BOOT_CODE)
|
||||
{
|
||||
USBH_UsrLog ("KeyBoard device found!");
|
||||
HID_Handle->Init = USBH_HID_KeybdInit;
|
||||
}
|
||||
else if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol == HID_MOUSE_BOOT_CODE)
|
||||
{
|
||||
USBH_UsrLog ("Mouse device found!");
|
||||
HID_Handle->Init = USBH_HID_MouseInit;
|
||||
}
|
||||
else
|
||||
{
|
||||
USBH_UsrLog ("Protocol not supported.");
|
||||
return USBH_FAIL;
|
||||
}
|
||||
|
||||
HID_Handle->state = HID_INIT;
|
||||
HID_Handle->ctl_state = HID_REQ_INIT;
|
||||
HID_Handle->ep_addr = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bEndpointAddress;
|
||||
HID_Handle->length = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].wMaxPacketSize;
|
||||
HID_Handle->poll = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bInterval ;
|
||||
|
||||
if (HID_Handle->poll < HID_MIN_POLL)
|
||||
{
|
||||
HID_Handle->poll = HID_MIN_POLL;
|
||||
}
|
||||
|
||||
/* Check fo available number of endpoints */
|
||||
/* Find the number of EPs in the Interface Descriptor */
|
||||
/* Choose the lower number in order not to overrun the buffer allocated */
|
||||
max_ep = ( (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bNumEndpoints <= USBH_MAX_NUM_ENDPOINTS) ?
|
||||
phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bNumEndpoints :
|
||||
USBH_MAX_NUM_ENDPOINTS);
|
||||
|
||||
|
||||
/* Decode endpoint IN and OUT address from interface descriptor */
|
||||
for ( ;num < max_ep; num++)
|
||||
{
|
||||
if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[num].bEndpointAddress & 0x80)
|
||||
{
|
||||
HID_Handle->InEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[num].bEndpointAddress);
|
||||
HID_Handle->InPipe =\
|
||||
USBH_AllocPipe(phost, HID_Handle->InEp);
|
||||
|
||||
/* Open pipe for IN endpoint */
|
||||
USBH_OpenPipe (phost,
|
||||
HID_Handle->InPipe,
|
||||
HID_Handle->InEp,
|
||||
phost->device.address,
|
||||
phost->device.speed,
|
||||
USB_EP_TYPE_INTR,
|
||||
HID_Handle->length);
|
||||
|
||||
USBH_LL_SetToggle (phost, HID_Handle->InPipe, 0);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
HID_Handle->OutEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[num].bEndpointAddress);
|
||||
HID_Handle->OutPipe =\
|
||||
USBH_AllocPipe(phost, HID_Handle->OutEp);
|
||||
|
||||
/* Open pipe for OUT endpoint */
|
||||
USBH_OpenPipe (phost,
|
||||
HID_Handle->OutPipe,
|
||||
HID_Handle->OutEp,
|
||||
phost->device.address,
|
||||
phost->device.speed,
|
||||
USB_EP_TYPE_INTR,
|
||||
HID_Handle->length);
|
||||
|
||||
USBH_LL_SetToggle (phost, HID_Handle->OutPipe, 0);
|
||||
}
|
||||
|
||||
}
|
||||
status = USBH_OK;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_HID_InterfaceDeInit
|
||||
* The function DeInit the Pipes used for the HID class.
|
||||
* @param phost: Host handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_HID_InterfaceDeInit (USBH_HandleTypeDef *phost )
|
||||
{
|
||||
HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData;
|
||||
|
||||
if(HID_Handle->InPipe != 0x00)
|
||||
{
|
||||
USBH_ClosePipe (phost, HID_Handle->InPipe);
|
||||
USBH_FreePipe (phost, HID_Handle->InPipe);
|
||||
HID_Handle->InPipe = 0; /* Reset the pipe as Free */
|
||||
}
|
||||
|
||||
if(HID_Handle->OutPipe != 0x00)
|
||||
{
|
||||
USBH_ClosePipe(phost, HID_Handle->OutPipe);
|
||||
USBH_FreePipe (phost, HID_Handle->OutPipe);
|
||||
HID_Handle->OutPipe = 0; /* Reset the pipe as Free */
|
||||
}
|
||||
|
||||
if(phost->pActiveClass->pData)
|
||||
{
|
||||
USBH_free (phost->pActiveClass->pData);
|
||||
}
|
||||
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_HID_ClassRequest
|
||||
* The function is responsible for handling Standard requests
|
||||
* for HID class.
|
||||
* @param phost: Host handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
static USBH_StatusTypeDef USBH_HID_ClassRequest(USBH_HandleTypeDef *phost)
|
||||
{
|
||||
|
||||
USBH_StatusTypeDef status = USBH_BUSY;
|
||||
USBH_StatusTypeDef classReqStatus = USBH_BUSY;
|
||||
HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData;
|
||||
|
||||
/* Switch HID state machine */
|
||||
switch (HID_Handle->ctl_state)
|
||||
{
|
||||
case HID_REQ_INIT:
|
||||
case HID_REQ_GET_HID_DESC:
|
||||
|
||||
/* Get HID Desc */
|
||||
if (USBH_HID_GetHIDDescriptor (phost, USB_HID_DESC_SIZE)== USBH_OK)
|
||||
{
|
||||
|
||||
USBH_HID_ParseHIDDesc(&HID_Handle->HID_Desc, phost->device.Data);
|
||||
HID_Handle->ctl_state = HID_REQ_GET_REPORT_DESC;
|
||||
}
|
||||
|
||||
break;
|
||||
case HID_REQ_GET_REPORT_DESC:
|
||||
|
||||
|
||||
/* Get Report Desc */
|
||||
if (USBH_HID_GetHIDReportDescriptor(phost, HID_Handle->HID_Desc.wItemLength) == USBH_OK)
|
||||
{
|
||||
/* The descriptor is available in phost->device.Data */
|
||||
|
||||
HID_Handle->ctl_state = HID_REQ_SET_IDLE;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case HID_REQ_SET_IDLE:
|
||||
|
||||
classReqStatus = USBH_HID_SetIdle (phost, 0, 0);
|
||||
|
||||
/* set Idle */
|
||||
if (classReqStatus == USBH_OK)
|
||||
{
|
||||
HID_Handle->ctl_state = HID_REQ_SET_PROTOCOL;
|
||||
}
|
||||
else if(classReqStatus == USBH_NOT_SUPPORTED)
|
||||
{
|
||||
HID_Handle->ctl_state = HID_REQ_SET_PROTOCOL;
|
||||
}
|
||||
break;
|
||||
|
||||
case HID_REQ_SET_PROTOCOL:
|
||||
/* set protocol */
|
||||
if (USBH_HID_SetProtocol (phost, 0) == USBH_OK)
|
||||
{
|
||||
HID_Handle->ctl_state = HID_REQ_IDLE;
|
||||
|
||||
/* all requests performed*/
|
||||
phost->pUser(phost, HOST_USER_CLASS_ACTIVE);
|
||||
status = USBH_OK;
|
||||
}
|
||||
break;
|
||||
|
||||
case HID_REQ_IDLE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_HID_Process
|
||||
* The function is for managing state machine for HID data transfers
|
||||
* @param phost: Host handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
static USBH_StatusTypeDef USBH_HID_Process(USBH_HandleTypeDef *phost)
|
||||
{
|
||||
USBH_StatusTypeDef status = USBH_OK;
|
||||
HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData;
|
||||
|
||||
switch (HID_Handle->state)
|
||||
{
|
||||
case HID_INIT:
|
||||
HID_Handle->Init(phost);
|
||||
case HID_IDLE:
|
||||
if(USBH_HID_GetReport (phost,
|
||||
0x01,
|
||||
0,
|
||||
HID_Handle->pData,
|
||||
HID_Handle->length) == USBH_OK)
|
||||
{
|
||||
|
||||
hid_fifo_write(&HID_Handle->fifo, HID_Handle->pData, HID_Handle->length);
|
||||
HID_Handle->state = HID_SYNC;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case HID_SYNC:
|
||||
|
||||
/* Sync with start of Even Frame */
|
||||
if(phost->Timer & 1)
|
||||
{
|
||||
HID_Handle->state = HID_GET_DATA;
|
||||
}
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case HID_GET_DATA:
|
||||
|
||||
USBH_InterruptReceiveData(phost,
|
||||
HID_Handle->pData,
|
||||
HID_Handle->length,
|
||||
HID_Handle->InPipe);
|
||||
|
||||
HID_Handle->state = HID_POLL;
|
||||
HID_Handle->timer = phost->Timer;
|
||||
HID_Handle->DataReady = 0;
|
||||
break;
|
||||
|
||||
case HID_POLL:
|
||||
|
||||
if(USBH_LL_GetURBState(phost , HID_Handle->InPipe) == USBH_URB_DONE)
|
||||
{
|
||||
if(HID_Handle->DataReady == 0)
|
||||
{
|
||||
hid_fifo_write(&HID_Handle->fifo, HID_Handle->pData, HID_Handle->length);
|
||||
HID_Handle->DataReady = 1;
|
||||
USBH_HID_EventCallback(phost);
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if(USBH_LL_GetURBState(phost , HID_Handle->InPipe) == USBH_URB_STALL) /* IN Endpoint Stalled */
|
||||
{
|
||||
|
||||
/* Issue Clear Feature on interrupt IN endpoint */
|
||||
if(USBH_ClrFeature(phost,
|
||||
HID_Handle->ep_addr) == USBH_OK)
|
||||
{
|
||||
/* Change state to issue next IN token */
|
||||
HID_Handle->state = HID_GET_DATA;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_HID_SOFProcess
|
||||
* The function is for managing the SOF Process
|
||||
* @param phost: Host handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
static USBH_StatusTypeDef USBH_HID_SOFProcess(USBH_HandleTypeDef *phost)
|
||||
{
|
||||
HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData;
|
||||
|
||||
if(HID_Handle->state == HID_POLL)
|
||||
{
|
||||
if(( phost->Timer - HID_Handle->timer) >= HID_Handle->poll)
|
||||
{
|
||||
HID_Handle->state = HID_GET_DATA;
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_Get_HID_ReportDescriptor
|
||||
* Issue report Descriptor command to the device. Once the response
|
||||
* received, parse the report descriptor and update the status.
|
||||
* @param phost: Host handle
|
||||
* @param Length : HID Report Descriptor Length
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_HID_GetHIDReportDescriptor (USBH_HandleTypeDef *phost,
|
||||
uint16_t length)
|
||||
{
|
||||
|
||||
USBH_StatusTypeDef status;
|
||||
|
||||
status = USBH_GetDescriptor(phost,
|
||||
USB_REQ_RECIPIENT_INTERFACE | USB_REQ_TYPE_STANDARD,
|
||||
USB_DESC_HID_REPORT,
|
||||
phost->device.Data,
|
||||
length);
|
||||
|
||||
/* HID report descriptor is available in phost->device.Data.
|
||||
In case of USB Boot Mode devices for In report handling ,
|
||||
HID report descriptor parsing is not required.
|
||||
In case, for supporting Non-Boot Protocol devices and output reports,
|
||||
user may parse the report descriptor*/
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_Get_HID_Descriptor
|
||||
* Issue HID Descriptor command to the device. Once the response
|
||||
* received, parse the report descriptor and update the status.
|
||||
* @param phost: Host handle
|
||||
* @param Length : HID Descriptor Length
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_HID_GetHIDDescriptor (USBH_HandleTypeDef *phost,
|
||||
uint16_t length)
|
||||
{
|
||||
|
||||
USBH_StatusTypeDef status;
|
||||
|
||||
status = USBH_GetDescriptor( phost,
|
||||
USB_REQ_RECIPIENT_INTERFACE | USB_REQ_TYPE_STANDARD,
|
||||
USB_DESC_HID,
|
||||
phost->device.Data,
|
||||
length);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_Set_Idle
|
||||
* Set Idle State.
|
||||
* @param phost: Host handle
|
||||
* @param duration: Duration for HID Idle request
|
||||
* @param reportId : Targeted report ID for Set Idle request
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_HID_SetIdle (USBH_HandleTypeDef *phost,
|
||||
uint8_t duration,
|
||||
uint8_t reportId)
|
||||
{
|
||||
|
||||
phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE |\
|
||||
USB_REQ_TYPE_CLASS;
|
||||
|
||||
|
||||
phost->Control.setup.b.bRequest = USB_HID_SET_IDLE;
|
||||
phost->Control.setup.b.wValue.w = (duration << 8 ) | reportId;
|
||||
|
||||
phost->Control.setup.b.wIndex.w = 0;
|
||||
phost->Control.setup.b.wLength.w = 0;
|
||||
|
||||
return USBH_CtlReq(phost, 0 , 0 );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBH_HID_Set_Report
|
||||
* Issues Set Report
|
||||
* @param phost: Host handle
|
||||
* @param reportType : Report type to be sent
|
||||
* @param reportId : Targeted report ID for Set Report request
|
||||
* @param reportBuff : Report Buffer
|
||||
* @param reportLen : Length of data report to be send
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_HID_SetReport (USBH_HandleTypeDef *phost,
|
||||
uint8_t reportType,
|
||||
uint8_t reportId,
|
||||
uint8_t* reportBuff,
|
||||
uint8_t reportLen)
|
||||
{
|
||||
|
||||
phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE |\
|
||||
USB_REQ_TYPE_CLASS;
|
||||
|
||||
|
||||
phost->Control.setup.b.bRequest = USB_HID_SET_REPORT;
|
||||
phost->Control.setup.b.wValue.w = (reportType << 8 ) | reportId;
|
||||
|
||||
phost->Control.setup.b.wIndex.w = 0;
|
||||
phost->Control.setup.b.wLength.w = reportLen;
|
||||
|
||||
return USBH_CtlReq(phost, reportBuff , reportLen );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBH_HID_GetReport
|
||||
* retreive Set Report
|
||||
* @param phost: Host handle
|
||||
* @param reportType : Report type to be sent
|
||||
* @param reportId : Targeted report ID for Set Report request
|
||||
* @param reportBuff : Report Buffer
|
||||
* @param reportLen : Length of data report to be send
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_HID_GetReport (USBH_HandleTypeDef *phost,
|
||||
uint8_t reportType,
|
||||
uint8_t reportId,
|
||||
uint8_t* reportBuff,
|
||||
uint8_t reportLen)
|
||||
{
|
||||
|
||||
phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_RECIPIENT_INTERFACE |\
|
||||
USB_REQ_TYPE_CLASS;
|
||||
|
||||
|
||||
phost->Control.setup.b.bRequest = USB_HID_GET_REPORT;
|
||||
phost->Control.setup.b.wValue.w = (reportType << 8 ) | reportId;
|
||||
|
||||
phost->Control.setup.b.wIndex.w = 0;
|
||||
phost->Control.setup.b.wLength.w = reportLen;
|
||||
|
||||
return USBH_CtlReq(phost, reportBuff , reportLen );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_Set_Protocol
|
||||
* Set protocol State.
|
||||
* @param phost: Host handle
|
||||
* @param protocol : Set Protocol for HID : boot/report protocol
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_HID_SetProtocol(USBH_HandleTypeDef *phost,
|
||||
uint8_t protocol)
|
||||
{
|
||||
|
||||
|
||||
phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE |\
|
||||
USB_REQ_TYPE_CLASS;
|
||||
|
||||
|
||||
phost->Control.setup.b.bRequest = USB_HID_SET_PROTOCOL;
|
||||
phost->Control.setup.b.wValue.w = protocol != 0 ? 0 : 1;
|
||||
phost->Control.setup.b.wIndex.w = 0;
|
||||
phost->Control.setup.b.wLength.w = 0;
|
||||
|
||||
return USBH_CtlReq(phost, 0 , 0 );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_ParseHIDDesc
|
||||
* This function Parse the HID descriptor
|
||||
* @param desc: HID Descriptor
|
||||
* @param buf: Buffer where the source descriptor is available
|
||||
* @retval None
|
||||
*/
|
||||
static void USBH_HID_ParseHIDDesc (HID_DescTypeDef *desc, uint8_t *buf)
|
||||
{
|
||||
|
||||
desc->bLength = *(uint8_t *) (buf + 0);
|
||||
desc->bDescriptorType = *(uint8_t *) (buf + 1);
|
||||
desc->bcdHID = LE16 (buf + 2);
|
||||
desc->bCountryCode = *(uint8_t *) (buf + 4);
|
||||
desc->bNumDescriptors = *(uint8_t *) (buf + 5);
|
||||
desc->bReportDescriptorType = *(uint8_t *) (buf + 6);
|
||||
desc->wItemLength = LE16 (buf + 7);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_HID_GetDeviceType
|
||||
* Return Device function.
|
||||
* @param phost: Host handle
|
||||
* @retval HID function: HID_MOUSE / HID_KEYBOARD
|
||||
*/
|
||||
HID_TypeTypeDef USBH_HID_GetDeviceType(USBH_HandleTypeDef *phost)
|
||||
{
|
||||
HID_TypeTypeDef type = HID_UNKNOWN;
|
||||
|
||||
if(phost->gState == HOST_CLASS)
|
||||
{
|
||||
|
||||
if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol \
|
||||
== HID_KEYBRD_BOOT_CODE)
|
||||
{
|
||||
type = HID_KEYBOARD;
|
||||
}
|
||||
else if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol \
|
||||
== HID_MOUSE_BOOT_CODE)
|
||||
{
|
||||
type= HID_MOUSE;
|
||||
}
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBH_HID_GetPollInterval
|
||||
* Return HID device poll time
|
||||
* @param phost: Host handle
|
||||
* @retval poll time (ms)
|
||||
*/
|
||||
uint8_t USBH_HID_GetPollInterval(USBH_HandleTypeDef *phost)
|
||||
{
|
||||
HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData;
|
||||
|
||||
if((phost->gState == HOST_CLASS_REQUEST) ||
|
||||
(phost->gState == HOST_INPUT) ||
|
||||
(phost->gState == HOST_SET_CONFIGURATION) ||
|
||||
(phost->gState == HOST_CHECK_CLASS) ||
|
||||
((phost->gState == HOST_CLASS)))
|
||||
{
|
||||
return (HID_Handle->poll);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief fifo_init
|
||||
* Initialize FIFO.
|
||||
* @param f: Fifo address
|
||||
* @param buf: Fifo buffer
|
||||
* @param size: Fifo Size
|
||||
* @retval none
|
||||
*/
|
||||
void hid_fifo_init(FIFO_TypeDef * f, uint8_t * buf, uint16_t size)
|
||||
{
|
||||
f->head = 0;
|
||||
f->tail = 0;
|
||||
f->lock = 0;
|
||||
f->size = size;
|
||||
f->buf = buf;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief fifo_read
|
||||
* Read from FIFO.
|
||||
* @param f: Fifo address
|
||||
* @param buf: read buffer
|
||||
* @param nbytes: number of item to read
|
||||
* @retval number of read items
|
||||
*/
|
||||
uint16_t hid_fifo_read(FIFO_TypeDef * f, void * buf, uint16_t nbytes)
|
||||
{
|
||||
uint16_t i;
|
||||
uint8_t * p;
|
||||
p = (uint8_t*) buf;
|
||||
|
||||
if(f->lock == 0)
|
||||
{
|
||||
f->lock = 1;
|
||||
for(i=0; i < nbytes; i++)
|
||||
{
|
||||
if( f->tail != f->head )
|
||||
{
|
||||
*p++ = f->buf[f->tail];
|
||||
f->tail++;
|
||||
if( f->tail == f->size )
|
||||
{
|
||||
f->tail = 0;
|
||||
}
|
||||
} else
|
||||
{
|
||||
f->lock = 0;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
f->lock = 0;
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief fifo_write
|
||||
* Read from FIFO.
|
||||
* @param f: Fifo address
|
||||
* @param buf: read buffer
|
||||
* @param nbytes: number of item to write
|
||||
* @retval number of written items
|
||||
*/
|
||||
uint16_t hid_fifo_write(FIFO_TypeDef * f, const void * buf, uint16_t nbytes)
|
||||
{
|
||||
uint16_t i;
|
||||
const uint8_t * p;
|
||||
p = (const uint8_t*) buf;
|
||||
if(f->lock == 0)
|
||||
{
|
||||
f->lock = 1;
|
||||
for(i=0; i < nbytes; i++)
|
||||
{
|
||||
if( (f->head + 1 == f->tail) ||
|
||||
( (f->head + 1 == f->size) && (f->tail == 0)) )
|
||||
{
|
||||
f->lock = 0;
|
||||
return i;
|
||||
}
|
||||
else
|
||||
{
|
||||
f->buf[f->head] = *p++;
|
||||
f->head++;
|
||||
if( f->head == f->size )
|
||||
{
|
||||
f->head = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
f->lock = 0;
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief The function is a callback about HID Data events
|
||||
* @param phost: Selected device
|
||||
* @retval None
|
||||
*/
|
||||
__weak void USBH_HID_EventCallback(USBH_HandleTypeDef *phost)
|
||||
{
|
||||
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+418
@@ -0,0 +1,418 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_hid_keybd.c
|
||||
* @author MCD Application Team
|
||||
* @version V3.2.2
|
||||
* @date 07-July-2015
|
||||
* @brief This file is the application layer for USB Host HID Keyboard handling
|
||||
* QWERTY and AZERTY Keyboard are supported as per the selection in
|
||||
* usbh_hid_keybd.h
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbh_hid_keybd.h"
|
||||
#include "usbh_hid_parser.h"
|
||||
|
||||
/** @addtogroup USBH_LIB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_HID_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_HID_KEYBD
|
||||
* @brief This file includes HID Layer Handlers for USB Host HID class.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_HID_KEYBD_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_HID_KEYBD_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#ifndef AZERTY_KEYBOARD
|
||||
#define QWERTY_KEYBOARD
|
||||
#endif
|
||||
#define KBD_LEFT_CTRL 0x01
|
||||
#define KBD_LEFT_SHIFT 0x02
|
||||
#define KBD_LEFT_ALT 0x04
|
||||
#define KBD_LEFT_GUI 0x08
|
||||
#define KBD_RIGHT_CTRL 0x10
|
||||
#define KBD_RIGHT_SHIFT 0x20
|
||||
#define KBD_RIGHT_ALT 0x40
|
||||
#define KBD_RIGHT_GUI 0x80
|
||||
#define KBR_MAX_NBR_PRESSED 6
|
||||
|
||||
/** @defgroup USBH_HID_KEYBD_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_HID_KEYBD_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
static USBH_StatusTypeDef USBH_HID_KeybdDecode(USBH_HandleTypeDef *phost);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_HID_KEYBD_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
HID_KEYBD_Info_TypeDef keybd_info;
|
||||
uint32_t keybd_report_data[2];
|
||||
|
||||
static const HID_Report_ItemTypedef imp_0_lctrl={
|
||||
(uint8_t*)keybd_report_data+0, /*data*/
|
||||
1, /*size*/
|
||||
0, /*shift*/
|
||||
0, /*count (only for array items)*/
|
||||
0, /*signed?*/
|
||||
0, /*min value read can return*/
|
||||
1, /*max value read can return*/
|
||||
0, /*min vale device can report*/
|
||||
1, /*max value device can report*/
|
||||
1 /*resolution*/
|
||||
};
|
||||
static const HID_Report_ItemTypedef imp_0_lshift={
|
||||
(uint8_t*)keybd_report_data+0, /*data*/
|
||||
1, /*size*/
|
||||
1, /*shift*/
|
||||
0, /*count (only for array items)*/
|
||||
0, /*signed?*/
|
||||
0, /*min value read can return*/
|
||||
1, /*max value read can return*/
|
||||
0, /*min vale device can report*/
|
||||
1, /*max value device can report*/
|
||||
1 /*resolution*/
|
||||
};
|
||||
static const HID_Report_ItemTypedef imp_0_lalt={
|
||||
(uint8_t*)keybd_report_data+0, /*data*/
|
||||
1, /*size*/
|
||||
2, /*shift*/
|
||||
0, /*count (only for array items)*/
|
||||
0, /*signed?*/
|
||||
0, /*min value read can return*/
|
||||
1, /*max value read can return*/
|
||||
0, /*min vale device can report*/
|
||||
1, /*max value device can report*/
|
||||
1 /*resolution*/
|
||||
};
|
||||
static const HID_Report_ItemTypedef imp_0_lgui={
|
||||
(uint8_t*)keybd_report_data+0, /*data*/
|
||||
1, /*size*/
|
||||
3, /*shift*/
|
||||
0, /*count (only for array items)*/
|
||||
0, /*signed?*/
|
||||
0, /*min value read can return*/
|
||||
1, /*max value read can return*/
|
||||
0, /*min vale device can report*/
|
||||
1, /*max value device can report*/
|
||||
1 /*resolution*/
|
||||
};
|
||||
static const HID_Report_ItemTypedef imp_0_rctrl={
|
||||
(uint8_t*)keybd_report_data+0, /*data*/
|
||||
1, /*size*/
|
||||
4, /*shift*/
|
||||
0, /*count (only for array items)*/
|
||||
0, /*signed?*/
|
||||
0, /*min value read can return*/
|
||||
1, /*max value read can return*/
|
||||
0, /*min vale device can report*/
|
||||
1, /*max value device can report*/
|
||||
1 /*resolution*/
|
||||
};
|
||||
static const HID_Report_ItemTypedef imp_0_rshift={
|
||||
(uint8_t*)keybd_report_data+0, /*data*/
|
||||
1, /*size*/
|
||||
5, /*shift*/
|
||||
0, /*count (only for array items)*/
|
||||
0, /*signed?*/
|
||||
0, /*min value read can return*/
|
||||
1, /*max value read can return*/
|
||||
0, /*min vale device can report*/
|
||||
1, /*max value device can report*/
|
||||
1 /*resolution*/
|
||||
};
|
||||
static const HID_Report_ItemTypedef imp_0_ralt={
|
||||
(uint8_t*)keybd_report_data+0, /*data*/
|
||||
1, /*size*/
|
||||
6, /*shift*/
|
||||
0, /*count (only for array items)*/
|
||||
0, /*signed?*/
|
||||
0, /*min value read can return*/
|
||||
1, /*max value read can return*/
|
||||
0, /*min vale device can report*/
|
||||
1, /*max value device can report*/
|
||||
1 /*resolution*/
|
||||
};
|
||||
static const HID_Report_ItemTypedef imp_0_rgui={
|
||||
(uint8_t*)keybd_report_data+0, /*data*/
|
||||
1, /*size*/
|
||||
7, /*shift*/
|
||||
0, /*count (only for array items)*/
|
||||
0, /*signed?*/
|
||||
0, /*min value read can return*/
|
||||
1, /*max value read can return*/
|
||||
0, /*min vale device can report*/
|
||||
1, /*max value device can report*/
|
||||
1 /*resolution*/
|
||||
};
|
||||
|
||||
static const HID_Report_ItemTypedef imp_0_key_array={
|
||||
(uint8_t*)keybd_report_data+2, /*data*/
|
||||
8, /*size*/
|
||||
0, /*shift*/
|
||||
6, /*count (only for array items)*/
|
||||
0, /*signed?*/
|
||||
0, /*min value read can return*/
|
||||
101, /*max value read can return*/
|
||||
0, /*min vale device can report*/
|
||||
101, /*max value device can report*/
|
||||
1 /*resolution*/
|
||||
};
|
||||
|
||||
#ifdef QWERTY_KEYBOARD
|
||||
static const int8_t HID_KEYBRD_Key[] = {
|
||||
'\0', '`', '1', '2', '3', '4', '5', '6',
|
||||
'7', '8', '9', '0', '-', '=', '\0', '\r',
|
||||
'\t', 'q', 'w', 'e', 'r', 't', 'y', 'u',
|
||||
'i', 'o', 'p', '[', ']', '\\',
|
||||
'\0', 'a', 's', 'd', 'f', 'g', 'h', 'j',
|
||||
'k', 'l', ';', '\'', '\0', '\n',
|
||||
'\0', '\0', 'z', 'x', 'c', 'v', 'b', 'n',
|
||||
'm', ',', '.', '/', '\0', '\0',
|
||||
'\0', '\0', '\0', ' ', '\0', '\0', '\0', '\0',
|
||||
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
|
||||
'\0', '\0', '\0', '\0', '\0', '\r', '\0', '\0',
|
||||
'\0', '\0', '\0', '\0', '\0', '\0',
|
||||
'\0', '\0', '7', '4', '1',
|
||||
'\0', '/', '8', '5', '2',
|
||||
'0', '*', '9', '6', '3',
|
||||
'.', '-', '+', '\0', '\n', '\0', '\0', '\0', '\0', '\0', '\0',
|
||||
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
|
||||
'\0', '\0', '\0', '\0'
|
||||
};
|
||||
|
||||
static const int8_t HID_KEYBRD_ShiftKey[] = {
|
||||
'\0', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')',
|
||||
'_', '+', '\0', '\0', '\0', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U',
|
||||
'I', 'O', 'P', '{', '}', '|', '\0', 'A', 'S', 'D', 'F', 'G',
|
||||
'H', 'J', 'K', 'L', ':', '"', '\0', '\n', '\0', '\0', 'Z', 'X',
|
||||
'C', 'V', 'B', 'N', 'M', '<', '>', '?', '\0', '\0', '\0', '\0',
|
||||
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
|
||||
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
|
||||
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
|
||||
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
|
||||
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
|
||||
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
static const int8_t HID_KEYBRD_Key[] = {
|
||||
'\0', '`', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
|
||||
'-', '=', '\0', '\r', '\t', 'a', 'z', 'e', 'r', 't', 'y', 'u',
|
||||
'i', 'o', 'p', '[', ']', '\\', '\0', 'q', 's', 'd', 'f', 'g',
|
||||
'h', 'j', 'k', 'l', 'm', '\0', '\0', '\n', '\0', '\0', 'w', 'x',
|
||||
'c', 'v', 'b', 'n', ',', ';', ':', '!', '\0', '\0', '\0', '\0',
|
||||
'\0', ' ', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
|
||||
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\r', '\0', '\0', '\0',
|
||||
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '7', '4', '1','\0', '/',
|
||||
'8', '5', '2', '0', '*', '9', '6', '3', '.', '-', '+', '\0',
|
||||
'\n', '\0', '\0', '\0', '\0', '\0', '\0','\0', '\0', '\0', '\0', '\0', '\0',
|
||||
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'
|
||||
};
|
||||
|
||||
static const int8_t HID_KEYBRD_ShiftKey[] = {
|
||||
'\0', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_',
|
||||
'+', '\0', '\0', '\0', 'A', 'Z', 'E', 'R', 'T', 'Y', 'U', 'I', 'O',
|
||||
'P', '{', '}', '*', '\0', 'Q', 'S', 'D', 'F', 'G', 'H', 'J', 'K',
|
||||
'L', 'M', '%', '\0', '\n', '\0', '\0', 'W', 'X', 'C', 'V', 'B', 'N',
|
||||
'?', '.', '/', '\0', '\0', '\0','\0', '\0', '\0', '\0', '\0', '\0', '\0',
|
||||
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
|
||||
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
|
||||
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
|
||||
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
|
||||
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'
|
||||
};
|
||||
#endif
|
||||
|
||||
static const uint8_t HID_KEYBRD_Codes[] = {
|
||||
0, 0, 0, 0, 31, 50, 48, 33,
|
||||
19, 34, 35, 36, 24, 37, 38, 39, /* 0x00 - 0x0F */
|
||||
52, 51, 25, 26, 17, 20, 32, 21,
|
||||
23, 49, 18, 47, 22, 46, 2, 3, /* 0x10 - 0x1F */
|
||||
4, 5, 6, 7, 8, 9, 10, 11,
|
||||
43, 110, 15, 16, 61, 12, 13, 27, /* 0x20 - 0x2F */
|
||||
28, 29, 42, 40, 41, 1, 53, 54,
|
||||
55, 30, 112, 113, 114, 115, 116, 117, /* 0x30 - 0x3F */
|
||||
118, 119, 120, 121, 122, 123, 124, 125,
|
||||
126, 75, 80, 85, 76, 81, 86, 89, /* 0x40 - 0x4F */
|
||||
79, 84, 83, 90, 95, 100, 105, 106,
|
||||
108, 93, 98, 103, 92, 97, 102, 91, /* 0x50 - 0x5F */
|
||||
96, 101, 99, 104, 45, 129, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, /* 0x60 - 0x6F */
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, /* 0x70 - 0x7F */
|
||||
0, 0, 0, 0, 0, 107, 0, 56,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, /* 0x80 - 0x8F */
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, /* 0x90 - 0x9F */
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, /* 0xA0 - 0xAF */
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, /* 0xB0 - 0xBF */
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, /* 0xC0 - 0xCF */
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, /* 0xD0 - 0xDF */
|
||||
58, 44, 60, 127, 64, 57, 62, 128 /* 0xE0 - 0xE7 */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief USBH_HID_KeybdInit
|
||||
* The function init the HID keyboard.
|
||||
* @param phost: Host handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_HID_KeybdInit(USBH_HandleTypeDef *phost)
|
||||
{
|
||||
uint32_t x;
|
||||
HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData;
|
||||
|
||||
keybd_info.lctrl=keybd_info.lshift= 0;
|
||||
keybd_info.lalt=keybd_info.lgui= 0;
|
||||
keybd_info.rctrl=keybd_info.rshift= 0;
|
||||
keybd_info.ralt=keybd_info.rgui=0;
|
||||
|
||||
|
||||
for(x=0; x< (sizeof(keybd_report_data)/sizeof(uint32_t)); x++)
|
||||
{
|
||||
keybd_report_data[x]=0;
|
||||
}
|
||||
|
||||
if(HID_Handle->length > (sizeof(keybd_report_data)/sizeof(uint32_t)))
|
||||
{
|
||||
HID_Handle->length = (sizeof(keybd_report_data)/sizeof(uint32_t));
|
||||
}
|
||||
HID_Handle->pData = (uint8_t*)keybd_report_data;
|
||||
hid_fifo_init(&HID_Handle->fifo, phost->device.Data, HID_QUEUE_SIZE * sizeof(keybd_report_data));
|
||||
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_HID_GetKeybdInfo
|
||||
* The function return keyboard information.
|
||||
* @param phost: Host handle
|
||||
* @retval keyboard information
|
||||
*/
|
||||
HID_KEYBD_Info_TypeDef *USBH_HID_GetKeybdInfo(USBH_HandleTypeDef *phost)
|
||||
{
|
||||
if(USBH_HID_KeybdDecode(phost) == USBH_OK)
|
||||
{
|
||||
return &keybd_info;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_HID_KeybdDecode
|
||||
* The function decode keyboard data.
|
||||
* @param phost: Host handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
static USBH_StatusTypeDef USBH_HID_KeybdDecode(USBH_HandleTypeDef *phost)
|
||||
{
|
||||
uint8_t x;
|
||||
|
||||
HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData;
|
||||
if(HID_Handle->length == 0)
|
||||
{
|
||||
return USBH_FAIL;
|
||||
}
|
||||
/*Fill report */
|
||||
if(hid_fifo_read(&HID_Handle->fifo, &keybd_report_data, HID_Handle->length) == HID_Handle->length)
|
||||
{
|
||||
|
||||
keybd_info.lctrl=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lctrl, 0);
|
||||
keybd_info.lshift=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lshift, 0);
|
||||
keybd_info.lalt=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lalt, 0);
|
||||
keybd_info.lgui=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lgui, 0);
|
||||
keybd_info.rctrl=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_rctrl, 0);
|
||||
keybd_info.rshift=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_rshift, 0);
|
||||
keybd_info.ralt=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_ralt, 0);
|
||||
keybd_info.rgui=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_rgui, 0);
|
||||
|
||||
for(x=0; x < sizeof(keybd_info.keys); x++)
|
||||
{
|
||||
keybd_info.keys[x]=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_key_array, x);
|
||||
}
|
||||
|
||||
return USBH_OK;
|
||||
}
|
||||
return USBH_FAIL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_HID_GetASCIICode
|
||||
* The function decode keyboard data into ASCII characters.
|
||||
* @param phost: Host handle
|
||||
* @param info: Keyboard information
|
||||
* @retval ASCII code
|
||||
*/
|
||||
uint8_t USBH_HID_GetASCIICode(HID_KEYBD_Info_TypeDef *info, uint32_t idx)
|
||||
{
|
||||
uint8_t output;
|
||||
if((info->lshift == 1) || (info->rshift))
|
||||
{
|
||||
output = HID_KEYBRD_ShiftKey[HID_KEYBRD_Codes[info->keys[idx]]];
|
||||
}
|
||||
else
|
||||
{
|
||||
output = HID_KEYBRD_Key[HID_KEYBRD_Codes[info->keys[idx]]];
|
||||
}
|
||||
return output;
|
||||
}
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
+267
@@ -0,0 +1,267 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_hid_mouse.c
|
||||
* @author MCD Application Team
|
||||
* @version V3.2.2
|
||||
* @date 07-July-2015
|
||||
* @brief This file is the application layer for USB Host HID Mouse Handling.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbh_hid_mouse.h"
|
||||
#include "usbh_hid_parser.h"
|
||||
|
||||
|
||||
/** @addtogroup USBH_LIB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_HID_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_HID_MOUSE
|
||||
* @brief This file includes HID Layer Handlers for USB Host HID class.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_HID_MOUSE_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_HID_MOUSE_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_HID_MOUSE_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_HID_MOUSE_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
static USBH_StatusTypeDef USBH_HID_MouseDecode(USBH_HandleTypeDef *phost);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_HID_MOUSE_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
HID_MOUSE_Info_TypeDef mouse_info;
|
||||
uint32_t mouse_report_data[1];
|
||||
|
||||
/* Structures defining how to access items in a HID mouse report */
|
||||
/* Access button 1 state. */
|
||||
static const HID_Report_ItemTypedef prop_b1={
|
||||
(uint8_t *)mouse_report_data+0, /*data*/
|
||||
1, /*size*/
|
||||
0, /*shift*/
|
||||
0, /*count (only for array items)*/
|
||||
0, /*signed?*/
|
||||
0, /*min value read can return*/
|
||||
1, /*max value read can return*/
|
||||
0, /*min value device can report*/
|
||||
1, /*max value device can report*/
|
||||
1 /*resolution*/
|
||||
};
|
||||
|
||||
/* Access button 2 state. */
|
||||
static const HID_Report_ItemTypedef prop_b2={
|
||||
(uint8_t *)mouse_report_data+0, /*data*/
|
||||
1, /*size*/
|
||||
1, /*shift*/
|
||||
0, /*count (only for array items)*/
|
||||
0, /*signed?*/
|
||||
0, /*min value read can return*/
|
||||
1, /*max value read can return*/
|
||||
0, /*min value device can report*/
|
||||
1, /*max value device can report*/
|
||||
1 /*resolution*/
|
||||
};
|
||||
|
||||
/* Access button 3 state. */
|
||||
static const HID_Report_ItemTypedef prop_b3={
|
||||
(uint8_t *)mouse_report_data+0, /*data*/
|
||||
1, /*size*/
|
||||
2, /*shift*/
|
||||
0, /*count (only for array items)*/
|
||||
0, /*signed?*/
|
||||
0, /*min value read can return*/
|
||||
1, /*max value read can return*/
|
||||
0, /*min vale device can report*/
|
||||
1, /*max value device can report*/
|
||||
1 /*resolution*/
|
||||
};
|
||||
|
||||
/* Access x coordinate change. */
|
||||
static const HID_Report_ItemTypedef prop_x={
|
||||
(uint8_t *)mouse_report_data+1, /*data*/
|
||||
8, /*size*/
|
||||
0, /*shift*/
|
||||
0, /*count (only for array items)*/
|
||||
1, /*signed?*/
|
||||
0, /*min value read can return*/
|
||||
0xFFFF,/*max value read can return*/
|
||||
0, /*min vale device can report*/
|
||||
0xFFFF,/*max value device can report*/
|
||||
1 /*resolution*/
|
||||
};
|
||||
|
||||
/* Access y coordinate change. */
|
||||
static const HID_Report_ItemTypedef prop_y={
|
||||
(uint8_t *)mouse_report_data+2, /*data*/
|
||||
8, /*size*/
|
||||
0, /*shift*/
|
||||
0, /*count (only for array items)*/
|
||||
1, /*signed?*/
|
||||
0, /*min value read can return*/
|
||||
0xFFFF,/*max value read can return*/
|
||||
0, /*min vale device can report*/
|
||||
0xFFFF,/*max value device can report*/
|
||||
1 /*resolution*/
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_HID_MOUSE_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBH_HID_MouseInit
|
||||
* The function init the HID mouse.
|
||||
* @param phost: Host handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_HID_MouseInit(USBH_HandleTypeDef *phost)
|
||||
{
|
||||
HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData;
|
||||
|
||||
mouse_info.x=0;
|
||||
mouse_info.y=0;
|
||||
mouse_info.buttons[0]=0;
|
||||
mouse_info.buttons[1]=0;
|
||||
mouse_info.buttons[2]=0;
|
||||
|
||||
mouse_report_data[0]=0;
|
||||
|
||||
if(HID_Handle->length > sizeof(mouse_report_data))
|
||||
{
|
||||
HID_Handle->length = sizeof(mouse_report_data);
|
||||
}
|
||||
HID_Handle->pData = (uint8_t *)mouse_report_data;
|
||||
hid_fifo_init(&HID_Handle->fifo, phost->device.Data, HID_QUEUE_SIZE * sizeof(mouse_report_data));
|
||||
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_HID_GetMouseInfo
|
||||
* The function return mouse information.
|
||||
* @param phost: Host handle
|
||||
* @retval mouse information
|
||||
*/
|
||||
HID_MOUSE_Info_TypeDef *USBH_HID_GetMouseInfo(USBH_HandleTypeDef *phost)
|
||||
{
|
||||
if(USBH_HID_MouseDecode(phost)== USBH_OK)
|
||||
{
|
||||
return &mouse_info;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_HID_MouseDecode
|
||||
* The function decode mouse data.
|
||||
* @param phost: Host handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
static USBH_StatusTypeDef USBH_HID_MouseDecode(USBH_HandleTypeDef *phost)
|
||||
{
|
||||
HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData;
|
||||
|
||||
if(HID_Handle->length == 0)
|
||||
{
|
||||
return USBH_FAIL;
|
||||
}
|
||||
/*Fill report */
|
||||
if(hid_fifo_read(&HID_Handle->fifo, &mouse_report_data, HID_Handle->length) == HID_Handle->length)
|
||||
{
|
||||
|
||||
/*Decode report */
|
||||
mouse_info.x = (int16_t )HID_ReadItem((HID_Report_ItemTypedef *) &prop_x, 0);
|
||||
mouse_info.y = (int16_t )HID_ReadItem((HID_Report_ItemTypedef *) &prop_y, 0);
|
||||
|
||||
mouse_info.buttons[0]=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b1, 0);
|
||||
mouse_info.buttons[1]=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b2, 0);
|
||||
mouse_info.buttons[2]=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b3, 0);
|
||||
|
||||
return USBH_OK;
|
||||
}
|
||||
return USBH_FAIL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+235
@@ -0,0 +1,235 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_hid_parser.c
|
||||
* @author MCD Application Team
|
||||
* @version V3.2.2
|
||||
* @date 07-July-2015
|
||||
* @brief This file is the HID Layer Handlers for USB Host HID class.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbh_hid_parser.h"
|
||||
|
||||
|
||||
/** @addtogroup USBH_LIB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_HID_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_HID_PARSER
|
||||
* @brief This file includes HID parsers for USB Host HID class.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_HID_PARSER_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_HID_PARSER_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_HID_PARSER_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_HID_PARSER_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_HID_PARSER_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_HID_PARSER_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief HID_ReadItem
|
||||
* The function read a report item.
|
||||
* @param ri: report item
|
||||
* @param ndx: report index
|
||||
* @retval status (0 : fail / otherwise: item value)
|
||||
*/
|
||||
uint32_t HID_ReadItem(HID_Report_ItemTypedef *ri, uint8_t ndx)
|
||||
{
|
||||
uint32_t val=0;
|
||||
uint32_t x=0;
|
||||
uint32_t bofs;
|
||||
uint8_t *data=ri->data;
|
||||
uint8_t shift=ri->shift;
|
||||
|
||||
/* get the logical value of the item */
|
||||
|
||||
/* if this is an array, wee may need to offset ri->data.*/
|
||||
if (ri->count > 0)
|
||||
{
|
||||
/* If app tries to read outside of the array. */
|
||||
if (ri->count <= ndx)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* calculate bit offset */
|
||||
bofs = ndx*ri->size;
|
||||
bofs += shift;
|
||||
/* calculate byte offset + shift pair from bit offset. */
|
||||
data+=bofs/8;
|
||||
shift=(uint8_t)(bofs%8);
|
||||
}
|
||||
/* read data bytes in little endian order */
|
||||
for(x=0; x < ((ri->size & 0x7) ? (ri->size/8)+1 : (ri->size/8)); x++)
|
||||
{
|
||||
val=(uint32_t)(*data << (x*8));
|
||||
}
|
||||
val=(val >> shift) & ((1<<ri->size)-1);
|
||||
|
||||
if (val < ri->logical_min || val > ri->logical_max)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* convert logical value to physical value */
|
||||
/* See if the number is negative or not. */
|
||||
if ((ri->sign) && (val & (1<<(ri->size-1))))
|
||||
{
|
||||
/* yes, so sign extend value to 32 bits. */
|
||||
int vs=(int)((-1 & ~((1<<(ri->size))-1)) | val);
|
||||
|
||||
if(ri->resolution == 1)
|
||||
{
|
||||
return((uint32_t)vs);
|
||||
}
|
||||
return((uint32_t)(vs*ri->resolution));
|
||||
}
|
||||
else
|
||||
{
|
||||
if(ri->resolution == 1)
|
||||
{
|
||||
return(val);
|
||||
}
|
||||
return(val*ri->resolution);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief HID_WriteItem
|
||||
* The function write a report item.
|
||||
* @param ri: report item
|
||||
* @param ndx: report index
|
||||
* @retval status (1: fail/ 0 : Ok)
|
||||
*/
|
||||
uint32_t HID_WriteItem(HID_Report_ItemTypedef *ri, uint32_t value, uint8_t ndx)
|
||||
{
|
||||
uint32_t x;
|
||||
uint32_t mask;
|
||||
uint32_t bofs;
|
||||
uint8_t *data=ri->data;
|
||||
uint8_t shift=ri->shift;
|
||||
|
||||
if (value < ri->physical_min || value > ri->physical_max)
|
||||
{
|
||||
return(1);
|
||||
}
|
||||
|
||||
/* if this is an array, wee may need to offset ri->data.*/
|
||||
if (ri->count > 0)
|
||||
{
|
||||
/* If app tries to read outside of the array. */
|
||||
if (ri->count >= ndx)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
/* calculate bit offset */
|
||||
bofs = ndx*ri->size;
|
||||
bofs += shift;
|
||||
/* calculate byte offset + shift pair from bit offset. */
|
||||
data+=bofs/8;
|
||||
shift=(uint8_t)(bofs%8);
|
||||
|
||||
}
|
||||
|
||||
/* Convert physical value to logical value. */
|
||||
if (ri->resolution != 1)
|
||||
{
|
||||
value=value/ri->resolution;
|
||||
}
|
||||
|
||||
/* Write logical value to report in little endian order. */
|
||||
mask=(uint32_t)((1<<ri->size)-1);
|
||||
value = (value & mask) << shift;
|
||||
|
||||
for(x=0; x < ((ri->size & 0x7) ? (ri->size/8)+1 : (ri->size/8)); x++)
|
||||
{
|
||||
*(ri->data+x)=(uint8_t)((*(ri->data+x) & ~(mask>>(x*8))) | ((value>>(x*8)) & (mask>>(x*8))));
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
Reference in New Issue
Block a user