添加一些关于midi播放的项目
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_conf.h
|
||||
* @author MCD Application Team
|
||||
* @version V4.1.0
|
||||
* @date 26-May-2017
|
||||
* @brief Midi CDC Device Demo configuration header
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 __USB_CONF_H
|
||||
#define __USB_CONF_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
/* External variables --------------------------------------------------------*/
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/* EP_NUM */
|
||||
/* defines how many endpoints are used by the device */
|
||||
/*-------------------------------------------------------------*/
|
||||
|
||||
#define EP_NUM (6)
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/* -------------- Buffer Description Table -----------------*/
|
||||
/*-------------------------------------------------------------*/
|
||||
/* buffer table base address */
|
||||
/* buffer table base address */
|
||||
#define BTABLE_ADDRESS (0x00)
|
||||
|
||||
/* EP0 */
|
||||
/* rx/tx buffer base address */
|
||||
#define ENDP0_RXADDR (0x40)
|
||||
#define ENDP0_TXADDR (0x80)
|
||||
|
||||
/* EP1 */
|
||||
/* tx buffer base address */
|
||||
#define ENDP1_TXADDR (0xC0)
|
||||
#define ENDP2_TXADDR (0x100)
|
||||
#define ENDP3_RXADDR (0x110)
|
||||
#define ENDP4_RXADDR (0x150)
|
||||
#define ENDP5_TXADDR (0x190)
|
||||
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/* ------------------- ISTR events -------------------------*/
|
||||
/*-------------------------------------------------------------*/
|
||||
/* IMR_MSK */
|
||||
/* mask defining which events has to be handled */
|
||||
/* by the device application software */
|
||||
#define IMR_MSK (CNTR_CTRM | CNTR_WKUPM | CNTR_SUSPM | CNTR_ERRM | CNTR_SOFM \
|
||||
| CNTR_ESOFM | CNTR_RESETM )
|
||||
|
||||
/*#define CTR_CALLBACK*/
|
||||
/*#define DOVR_CALLBACK*/
|
||||
/*#define ERR_CALLBACK*/
|
||||
/*#define WKUP_CALLBACK*/
|
||||
/*#define SUSP_CALLBACK*/
|
||||
/*#define RESET_CALLBACK*/
|
||||
/*#define SOF_CALLBACK*/
|
||||
/*#define ESOF_CALLBACK*/
|
||||
/* CTR service routines */
|
||||
/* associated to defined endpoints */
|
||||
/*#define EP1_IN_Callback NOP_Process*/
|
||||
#define EP2_IN_Callback NOP_Process
|
||||
#define EP3_IN_Callback NOP_Process
|
||||
#define EP4_IN_Callback NOP_Process
|
||||
/*#define EP5_IN_Callback NOP_Process*/
|
||||
#define EP6_IN_Callback NOP_Process
|
||||
#define EP7_IN_Callback NOP_Process
|
||||
|
||||
#define EP1_OUT_Callback NOP_Process
|
||||
#define EP2_OUT_Callback NOP_Process
|
||||
/*#define EP3_OUT_Callback NOP_Process*/
|
||||
/*#define EP4_OUT_Callback NOP_Process*/
|
||||
#define EP5_OUT_Callback NOP_Process
|
||||
#define EP6_OUT_Callback NOP_Process
|
||||
#define EP7_OUT_Callback NOP_Process
|
||||
|
||||
#endif /* __USB_CONF_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,345 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_desc.c
|
||||
* @author MCD Application Team
|
||||
* @version V4.1.0
|
||||
* @date 26-May-2017
|
||||
* @brief Descriptors for Usb midi and Cdc composite device.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_lib.h"
|
||||
#include "usb_desc.h"
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
const uint8_t Midi_CDC_Device_DeviceDescriptor[] =
|
||||
{
|
||||
0x12, /* bLength */
|
||||
USB_DEVICE_DESCRIPTOR_TYPE, /* bDescriptorType */
|
||||
0x00,
|
||||
0x02, /* bcdUSB = 2.00 */
|
||||
0xEF, // Class Code
|
||||
0x02, // Subclass code
|
||||
0x01, // Protocol code
|
||||
0x40, /* bMaxPacketSize0 */
|
||||
0x83,
|
||||
0x04, /* idVendor = 0x0483 */
|
||||
0x66,
|
||||
0x67, /* idProduct = 0x7666 */
|
||||
0x00,
|
||||
0x02, /* bcdDevice = 2.00 */
|
||||
1, /* Index of string descriptor describing manufacturer */
|
||||
2, /* Index of string descriptor describing product */
|
||||
3, /* Index of string descriptor describing the device's serial number */
|
||||
0x01 /* bNumConfigurations */
|
||||
};
|
||||
|
||||
const uint8_t Midi_CDC_Device_ConfigDescriptor[] =
|
||||
{
|
||||
/*Configuration Descriptor*/
|
||||
0x09, /* bLength: Configuration Descriptor size */
|
||||
USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
|
||||
MIDI_CDC_DEV_SIZ_CONFIG_DESC, /* wTotalLength:no of returned bytes */
|
||||
0x00,
|
||||
0x04, /* bNumInterfaces: 4 interface */
|
||||
0x01, /* bConfigurationValue: Configuration value */
|
||||
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
|
||||
0xC0, /* bmAttributes: self powered */
|
||||
0x32, /* MaxPower 0 mA */
|
||||
|
||||
/* Interface Association Descriptor: Audio Function 1*/
|
||||
0x08, // Size of this descriptor in bytes
|
||||
0x0B, // Interface assocication descriptor type
|
||||
MIDI_IF_0_ID, // The first associated interface
|
||||
0x02, // Number of contiguous associated interface
|
||||
0x01, // bInterfaceClass of the first interface
|
||||
0x01, // bInterfaceSubclass of the first interface
|
||||
0x00, // bInterfaceProtocol of the first interface
|
||||
0x00, // Interface string index
|
||||
|
||||
0x09, //sizeof(USB_INTF_DSC), // Size of this descriptor in bytes
|
||||
USB_INTERFACE_DESCRIPTOR_TYPE, // INTERFACE descriptor type
|
||||
MIDI_IF_0_ID, // Interface Number
|
||||
0, // Alternate Setting Number
|
||||
0, // Number of endpoints in this intf
|
||||
1, // Class code
|
||||
1, // Subclass code
|
||||
0, // Protocol code
|
||||
0, // Interface string index
|
||||
/* MIDI Adapter Class-specific AC Interface Descriptor */
|
||||
0x09, //bLength
|
||||
0x24, //bDescriptorType - CS_INTERFACE
|
||||
0x01, //bDescriptorSubtype - HEADER
|
||||
0x00, 0x01, //bcdADC
|
||||
0x09, 0x00, //wTotalLength
|
||||
0x01, //bInCollection
|
||||
0x01, //baInterfaceNr(1)
|
||||
|
||||
/* MIDI Adapter Standard MS Interface Descriptor */
|
||||
0x09, //bLength
|
||||
USB_INTERFACE_DESCRIPTOR_TYPE, //bDescriptorType
|
||||
MIDI_IF_1_ID, //bInterfaceNumber
|
||||
0x00, //bAlternateSetting
|
||||
0x02, //bNumEndpoints
|
||||
0x01, //bInterfaceClass
|
||||
0x03, //bInterfaceSubclass
|
||||
0x00, //bInterfaceProtocol
|
||||
0x00, //iInterface
|
||||
|
||||
/* MIDI Adapter Class-specific MS Interface Descriptor */
|
||||
0x07, //bLength
|
||||
0x24, //bDescriptorType - CS_INTERFACE
|
||||
0x01, //bDescriptorSubtype - MS_HEADER
|
||||
0x00, 0x01, //BcdADC
|
||||
0x41, 0x00, //wTotalLength
|
||||
|
||||
/* MIDI Adapter MIDI IN Jack Descriptor (Embedded) */
|
||||
0x06, //bLength
|
||||
0x24, //bDescriptorType - CS_INTERFACE
|
||||
0x02, //bDescriptorSubtype - MIDI_IN_JACK
|
||||
0x01, //bJackType - EMBEDDED
|
||||
0x01, //bJackID
|
||||
0x00, //iJack
|
||||
|
||||
/* MIDI Adapter MIDI IN Jack Descriptor (External) */
|
||||
0x06, //bLength
|
||||
0x24, //bDescriptorType - CS_INTERFACE
|
||||
0x02, //bDescriptorSubtype - MIDI_IN_JACK
|
||||
0x02, //bJackType - EXTERNAL
|
||||
0x02, //bJackID
|
||||
0x00, //iJack
|
||||
|
||||
/* MIDI Adapter MIDI OUT Jack Descriptor (Embedded) */
|
||||
0x09, //bLength
|
||||
0x24, //bDescriptorType - CS_INTERFACE
|
||||
0x03, //bDescriptorSubtype - MIDI_OUT_JACK
|
||||
0x01, //bJackType - EMBEDDED
|
||||
0x03, //bJackID
|
||||
0x01, //bNrInputPins
|
||||
0x02, //BaSourceID(1)
|
||||
0x01, //BaSourcePin(1)
|
||||
0x00, //iJack
|
||||
|
||||
/* MIDI Adapter MIDI OUT Jack Descriptor (External) */
|
||||
0x09, //bLength
|
||||
0x24, //bDescriptorType - CS_INTERFACE
|
||||
0x03, //bDescriptorSubtype - MIDI_OUT_JACK
|
||||
0x02, //bJackType - EXTERNAL
|
||||
0x04, //bJackID
|
||||
0x01, //bNrInputPins
|
||||
0x01, //BaSourceID(1)
|
||||
0x01, //BaSourcePin(1)
|
||||
0x00, //iJack
|
||||
|
||||
/* MIDI Adapter Standard Bulk OUT Endpoint Descriptor */
|
||||
0x09, //bLength
|
||||
USB_ENDPOINT_DESCRIPTOR_TYPE, //bDescriptorType - ENDPOINT
|
||||
0x04, //bEndpointAddress - OUT
|
||||
0x02, //bmAttributes
|
||||
MIDI_CDC_DEV_DATA_SIZE, 0x00, //wMaxPacketSize
|
||||
0x00, //bInterval
|
||||
0x00, //bRefresh
|
||||
0x00, //bSynchAddress
|
||||
|
||||
/* MIDI Adapter Class-specific Bulk OUT Endpoint Descriptor */
|
||||
0x05, //bLength
|
||||
0x25, //bDescriptorType - CS_ENDPOINT
|
||||
0x01, //bDescriptorSubtype - MS_GENERAL
|
||||
0x01, //bNumEmbMIDIJack
|
||||
0x01, //BaAssocJackID(1)
|
||||
|
||||
/* MIDI Adapter Standard Bulk IN Endpoint Descriptor */
|
||||
0x09, //bLength
|
||||
USB_ENDPOINT_DESCRIPTOR_TYPE, //bDescriptorType
|
||||
0x85, //bEndpointAddress
|
||||
0x02, //bmAttributes
|
||||
MIDI_CDC_DEV_DATA_SIZE, 0x00, //wMaxPacketSize
|
||||
0x00, //bInterval
|
||||
0x00, //bRefresh
|
||||
0x00, //bSynchAddress
|
||||
|
||||
/* MIDI Adapter Class-specific Bulk IN Endpoint Descriptor */
|
||||
0x05, //bLength
|
||||
0x25, //bDescriptorType - CS_ENDPOINT
|
||||
0x01, //bDescriptorSubtype - MS_GENERAL
|
||||
0x01, //bNumEmbMIDIJack
|
||||
0x03, //BaAssocJackID(1)
|
||||
// IAD ------------------------------------------------------------------------------------------------------------
|
||||
|
||||
// Interface Association Descriptor
|
||||
0x08, // Size of this descriptor in bytes
|
||||
0x0B, // Interface association descriptor type
|
||||
CDC_COM_IF_ID, // First associated interface
|
||||
0x02, // Number of contiguous associated interfaces
|
||||
0x02, // bInterfaceClass of the first interface
|
||||
0x02, // bInterfaceSubClass of the first interface
|
||||
0x01, // bInterfaceProtocol of the first interface
|
||||
0x00, // Interface string index
|
||||
/*Interface Descriptor*/
|
||||
0x09, /* bLength: Interface Descriptor size */
|
||||
USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: Interface */
|
||||
/* Interface descriptor type */
|
||||
CDC_COM_IF_ID, /* 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 */
|
||||
CDC_DATA_IF_ID, /* 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_COM_IF_ID, /* bMasterInterface: Communication class interface */
|
||||
CDC_DATA_IF_ID, /* bSlaveInterface0: Data Class Interface */
|
||||
/*Endpoint 2 Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
|
||||
0x82, /* bEndpointAddress: (IN2) */
|
||||
0x03, /* bmAttributes: Interrupt */
|
||||
MIDI_CDC_DEV_INT_SIZE, /* wMaxPacketSize: */
|
||||
0x00,
|
||||
0xFF, /* bInterval: */
|
||||
/*Data class interface descriptor*/
|
||||
0x09, /* bLength: Endpoint Descriptor size */
|
||||
USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: */
|
||||
CDC_DATA_IF_ID, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x02, /* bNumEndpoints: Two endpoints used */
|
||||
0x0A, /* bInterfaceClass: CDC */
|
||||
0x00, /* bInterfaceSubClass: */
|
||||
0x00, /* bInterfaceProtocol: */
|
||||
0x00, /* iInterface: */
|
||||
/*Endpoint 3 Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
|
||||
0x03, /* bEndpointAddress: (OUT3) */
|
||||
0x02, /* bmAttributes: Bulk */
|
||||
MIDI_CDC_DEV_DATA_SIZE, /* wMaxPacketSize: */
|
||||
0x00,
|
||||
0x00, /* bInterval: ignore for Bulk transfer */
|
||||
/*Endpoint 1 Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
|
||||
0x81, /* bEndpointAddress: (IN1) */
|
||||
0x02, /* bmAttributes: Bulk */
|
||||
MIDI_CDC_DEV_DATA_SIZE, /* wMaxPacketSize: */
|
||||
0x00,
|
||||
0x00, /* bInterval */
|
||||
|
||||
};
|
||||
|
||||
/* USB String Descriptors */
|
||||
const uint8_t Midi_CDC_Device_StringLangID[MIDI_CDC_DEV_SIZ_STRING_LANGID] =
|
||||
{
|
||||
MIDI_CDC_DEV_SIZ_STRING_LANGID,
|
||||
USB_STRING_DESCRIPTOR_TYPE,
|
||||
0x09,
|
||||
0x04 /* LangID = 0x0409: U.S. English */
|
||||
};
|
||||
|
||||
const uint8_t Midi_CDC_Device_StringVendor[MIDI_CDC_DEV_SIZ_STRING_VENDOR] =
|
||||
{
|
||||
MIDI_CDC_DEV_SIZ_STRING_VENDOR, /* Size of Vendor string */
|
||||
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType*/
|
||||
/* Manufacturer: "STMicroelectronics" */
|
||||
'Y',
|
||||
0,
|
||||
'u',
|
||||
0,
|
||||
'a',
|
||||
0,
|
||||
'n',
|
||||
};
|
||||
|
||||
const uint8_t Midi_CDC_Device_StringProduct[MIDI_CDC_DEV_SIZ_STRING_PRODUCT] =
|
||||
{
|
||||
MIDI_CDC_DEV_SIZ_STRING_PRODUCT, /* bLength */
|
||||
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
|
||||
/* Product name: "STM32 Midi CDC Device" */
|
||||
'Y',
|
||||
0,
|
||||
'U',
|
||||
0,
|
||||
'A',
|
||||
0,
|
||||
'N',
|
||||
0,
|
||||
'\'',
|
||||
0,
|
||||
'S',
|
||||
0,
|
||||
' ',
|
||||
0,
|
||||
'M',
|
||||
0,
|
||||
'U',
|
||||
0,
|
||||
'S',
|
||||
0,
|
||||
'I',
|
||||
0,
|
||||
'C',
|
||||
0,
|
||||
' ',
|
||||
0,
|
||||
'B',
|
||||
0,
|
||||
'O',
|
||||
0,
|
||||
'X',
|
||||
0,
|
||||
};
|
||||
|
||||
uint8_t Midi_CDC_Device_StringSerial[MIDI_CDC_DEV_SIZ_STRING_SERIAL] =
|
||||
{
|
||||
MIDI_CDC_DEV_SIZ_STRING_SERIAL, /* bLength */
|
||||
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
|
||||
'S', 0, 'T', 0, 'M', 0, '3', 0, '2', 0};
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_desc.h
|
||||
* @author MCD Application Team
|
||||
* @version V4.1.0
|
||||
* @date 26-May-2017
|
||||
* @brief Descriptor Header for Midi CDC Device Device
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 __USB_DESC_H
|
||||
#define __USB_DESC_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported define -----------------------------------------------------------*/
|
||||
#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 MIDI_CDC_DEV_DATA_SIZE 64
|
||||
#define MIDI_CDC_DEV_INT_SIZE 8
|
||||
|
||||
#define MIDI_CDC_DEV_SIZ_DEVICE_DESC 18
|
||||
#define MIDI_CDC_DEV_SIZ_CONFIG_DESC 67+92+8+8
|
||||
#define MIDI_CDC_DEV_SIZ_STRING_LANGID 4
|
||||
#define MIDI_CDC_DEV_SIZ_STRING_VENDOR 10
|
||||
#define MIDI_CDC_DEV_SIZ_STRING_PRODUCT 41
|
||||
#define MIDI_CDC_DEV_SIZ_STRING_SERIAL 26
|
||||
|
||||
#define STANDARD_ENDPOINT_DESC_SIZE 0x09
|
||||
|
||||
#define MIDI_IF_0_ID 0
|
||||
#define MIDI_IF_1_ID 1
|
||||
#define CDC_COM_IF_ID 2
|
||||
#define CDC_DATA_IF_ID 3
|
||||
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
extern const uint8_t Midi_CDC_Device_DeviceDescriptor[MIDI_CDC_DEV_SIZ_DEVICE_DESC];
|
||||
extern const uint8_t Midi_CDC_Device_ConfigDescriptor[MIDI_CDC_DEV_SIZ_CONFIG_DESC];
|
||||
|
||||
extern const uint8_t Midi_CDC_Device_StringLangID[MIDI_CDC_DEV_SIZ_STRING_LANGID];
|
||||
extern const uint8_t Midi_CDC_Device_StringVendor[MIDI_CDC_DEV_SIZ_STRING_VENDOR];
|
||||
extern const uint8_t Midi_CDC_Device_StringProduct[MIDI_CDC_DEV_SIZ_STRING_PRODUCT];
|
||||
extern uint8_t Midi_CDC_Device_StringSerial[MIDI_CDC_DEV_SIZ_STRING_SERIAL];
|
||||
|
||||
#endif /* __USB_DESC_H */
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_endp.c
|
||||
* @author MCD Application Team
|
||||
* @version V4.1.0
|
||||
* @date 26-May-2017
|
||||
* @brief Endpoint routines
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_lib.h"
|
||||
#include "usb_desc.h"
|
||||
#include "usb_mem.h"
|
||||
#include "hal.h"
|
||||
#include "usb_istr.h"
|
||||
#include "usb_pwr.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
|
||||
/* Interval between sending IN packets in frame number (1 frame = 1ms) */
|
||||
#define VCOMPORT_IN_FRAME_INTERVAL 5
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
extern __IO uint32_t packet_sent;
|
||||
extern __IO uint32_t packet_receive;
|
||||
extern __IO uint8_t Receive_Buffer[64];
|
||||
uint32_t Receive_length;
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : EP1_IN_Callback
|
||||
* Description :
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
|
||||
void EP1_IN_Callback (void)
|
||||
{
|
||||
packet_sent = 1;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : EP3_OUT_Callback
|
||||
* Description :
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void EP3_OUT_Callback(void)
|
||||
{
|
||||
packet_receive = 1;
|
||||
Receive_length = GetEPRxCount(ENDP3);
|
||||
PMAToUserBufferCopy((unsigned char*)Receive_Buffer, ENDP3_RXADDR, Receive_length);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : EP5_IN_Callback
|
||||
* Description :
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
|
||||
void EP5_IN_Callback (void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : EP4_OUT_Callback
|
||||
* Description :
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void EP4_OUT_Callback(void)
|
||||
{
|
||||
packet_receive = 1;
|
||||
Receive_length = GetEPRxCount(ENDP4);
|
||||
PMAToUserBufferCopy((unsigned char*)Receive_Buffer, ENDP4_RXADDR, Receive_length);
|
||||
}
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,242 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_istr.c
|
||||
* @author MCD Application Team
|
||||
* @version V4.1.0
|
||||
* @date 26-May-2017
|
||||
* @brief ISTR events interrupt service routines
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_lib.h"
|
||||
#include "usb_prop.h"
|
||||
#include "usb_pwr.h"
|
||||
#include "usb_istr.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
__IO uint16_t wIstr; /* ISTR register last read value */
|
||||
__IO uint8_t bIntPackSOF = 0; /* SOFs received between 2 consecutive packets */
|
||||
__IO uint32_t esof_counter =0; /* expected SOF counter */
|
||||
__IO uint32_t wCNTR=0;
|
||||
|
||||
/* Extern variables ----------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/* function pointers to non-control endpoints service routines */
|
||||
void (*pEpInt_IN[7])(void) =
|
||||
{
|
||||
EP1_IN_Callback,
|
||||
EP2_IN_Callback,
|
||||
EP3_IN_Callback,
|
||||
EP4_IN_Callback,
|
||||
EP5_IN_Callback,
|
||||
EP6_IN_Callback,
|
||||
EP7_IN_Callback,
|
||||
};
|
||||
|
||||
void (*pEpInt_OUT[7])(void) =
|
||||
{
|
||||
EP1_OUT_Callback,
|
||||
EP2_OUT_Callback,
|
||||
EP3_OUT_Callback,
|
||||
EP4_OUT_Callback,
|
||||
EP5_OUT_Callback,
|
||||
EP6_OUT_Callback,
|
||||
EP7_OUT_Callback,
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USB_Istr
|
||||
* Description : ISTR events interrupt service routine
|
||||
* Input :
|
||||
* Output :
|
||||
* Return :
|
||||
*******************************************************************************/
|
||||
void USB_Istr(void)
|
||||
{
|
||||
uint32_t i=0;
|
||||
__IO uint32_t EP[8];
|
||||
|
||||
wIstr = _GetISTR();
|
||||
|
||||
#if (IMR_MSK & ISTR_SOF)
|
||||
if (wIstr & ISTR_SOF & wInterrupt_Mask)
|
||||
{
|
||||
_SetISTR((uint16_t)CLR_SOF);
|
||||
bIntPackSOF++;
|
||||
|
||||
#ifdef SOF_CALLBACK
|
||||
SOF_Callback();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
|
||||
|
||||
#if (IMR_MSK & ISTR_CTR)
|
||||
if (wIstr & ISTR_CTR & wInterrupt_Mask)
|
||||
{
|
||||
/* servicing of the endpoint correct transfer interrupt */
|
||||
/* clear of the CTR flag into the sub */
|
||||
CTR_LP();
|
||||
#ifdef CTR_CALLBACK
|
||||
CTR_Callback();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
|
||||
#if (IMR_MSK & ISTR_RESET)
|
||||
if (wIstr & ISTR_RESET & wInterrupt_Mask)
|
||||
{
|
||||
_SetISTR((uint16_t)CLR_RESET);
|
||||
Device_Property.Reset();
|
||||
#ifdef RESET_CALLBACK
|
||||
RESET_Callback();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
|
||||
#if (IMR_MSK & ISTR_DOVR)
|
||||
if (wIstr & ISTR_DOVR & wInterrupt_Mask)
|
||||
{
|
||||
_SetISTR((uint16_t)CLR_DOVR);
|
||||
#ifdef DOVR_CALLBACK
|
||||
DOVR_Callback();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
|
||||
#if (IMR_MSK & ISTR_ERR)
|
||||
if (wIstr & ISTR_ERR & wInterrupt_Mask)
|
||||
{
|
||||
_SetISTR((uint16_t)CLR_ERR);
|
||||
#ifdef ERR_CALLBACK
|
||||
ERR_Callback();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
|
||||
#if (IMR_MSK & ISTR_WKUP)
|
||||
if (wIstr & ISTR_WKUP & wInterrupt_Mask)
|
||||
{
|
||||
_SetISTR((uint16_t)CLR_WKUP);
|
||||
Resume(RESUME_EXTERNAL);
|
||||
#ifdef WKUP_CALLBACK
|
||||
WKUP_Callback();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
|
||||
#if (IMR_MSK & ISTR_SUSP)
|
||||
if (wIstr & ISTR_SUSP & wInterrupt_Mask)
|
||||
{
|
||||
|
||||
/* check if SUSPEND is possible */
|
||||
if (fSuspendEnabled)
|
||||
{
|
||||
Suspend();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* if not possible then resume after xx ms */
|
||||
Resume(RESUME_LATER);
|
||||
}
|
||||
/* clear of the ISTR bit must be done after setting of CNTR_FSUSP */
|
||||
_SetISTR((uint16_t)CLR_SUSP);
|
||||
#ifdef SUSP_CALLBACK
|
||||
SUSP_Callback();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
|
||||
|
||||
#if (IMR_MSK & ISTR_ESOF)
|
||||
if (wIstr & ISTR_ESOF & wInterrupt_Mask)
|
||||
{
|
||||
/* clear ESOF flag in ISTR */
|
||||
_SetISTR((uint16_t)CLR_ESOF);
|
||||
|
||||
if ((_GetFNR()&FNR_RXDP)!=0)
|
||||
{
|
||||
/* increment ESOF counter */
|
||||
esof_counter ++;
|
||||
|
||||
/* test if we enter in ESOF more than 3 times with FSUSP =0 and RXDP =1=>> possible missing SUSP flag*/
|
||||
if ((esof_counter >3)&&((_GetCNTR()&CNTR_FSUSP)==0))
|
||||
{
|
||||
/* this a sequence to apply a force RESET*/
|
||||
|
||||
/*Store CNTR value */
|
||||
wCNTR = _GetCNTR();
|
||||
|
||||
/*Store endpoints registers status */
|
||||
for (i=0;i<8;i++) EP[i] = _GetENDPOINT(i);
|
||||
|
||||
/*apply FRES */
|
||||
wCNTR|=CNTR_FRES;
|
||||
_SetCNTR(wCNTR);
|
||||
|
||||
/*clear FRES*/
|
||||
wCNTR&=~CNTR_FRES;
|
||||
_SetCNTR(wCNTR);
|
||||
|
||||
/*poll for RESET flag in ISTR*/
|
||||
while((_GetISTR()&ISTR_RESET) == 0);
|
||||
/* clear RESET flag in ISTR */
|
||||
_SetISTR((uint16_t)CLR_RESET);
|
||||
|
||||
/*restore Enpoints*/
|
||||
for (i=0;i<8;i++)
|
||||
_SetENDPOINT(i, EP[i]);
|
||||
|
||||
esof_counter = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
esof_counter = 0;
|
||||
}
|
||||
|
||||
/* resume handling timing is made with ESOFs */
|
||||
Resume(RESUME_ESOF); /* request without change of the machine state */
|
||||
|
||||
#ifdef ESOF_CALLBACK
|
||||
ESOF_Callback();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
} /* USB_Istr */
|
||||
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,104 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_istr.h
|
||||
* @author MCD Application Team
|
||||
* @version V4.1.0
|
||||
* @date 26-May-2017
|
||||
* @brief This file includes the peripherals header files in the user application.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 __USB_ISTR_H
|
||||
#define __USB_ISTR_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usb_conf.h"
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
void USB_Istr(void);
|
||||
|
||||
/* function prototypes Automatically built defining related macros */
|
||||
|
||||
void EP1_IN_Callback(void);
|
||||
void EP2_IN_Callback(void);
|
||||
void EP3_IN_Callback(void);
|
||||
void EP4_IN_Callback(void);
|
||||
void EP5_IN_Callback(void);
|
||||
void EP6_IN_Callback(void);
|
||||
void EP7_IN_Callback(void);
|
||||
|
||||
void EP1_OUT_Callback(void);
|
||||
void EP2_OUT_Callback(void);
|
||||
void EP3_OUT_Callback(void);
|
||||
void EP4_OUT_Callback(void);
|
||||
void EP5_OUT_Callback(void);
|
||||
void EP6_OUT_Callback(void);
|
||||
void EP7_OUT_Callback(void);
|
||||
|
||||
#ifdef CTR_CALLBACK
|
||||
void CTR_Callback(void);
|
||||
#endif
|
||||
|
||||
#ifdef DOVR_CALLBACK
|
||||
void DOVR_Callback(void);
|
||||
#endif
|
||||
|
||||
#ifdef ERR_CALLBACK
|
||||
void ERR_Callback(void);
|
||||
#endif
|
||||
|
||||
#ifdef WKUP_CALLBACK
|
||||
void WKUP_Callback(void);
|
||||
#endif
|
||||
|
||||
#ifdef SUSP_CALLBACK
|
||||
void SUSP_Callback(void);
|
||||
#endif
|
||||
|
||||
#ifdef RESET_CALLBACK
|
||||
void RESET_Callback(void);
|
||||
#endif
|
||||
|
||||
#ifdef SOF_CALLBACK
|
||||
void SOF_Callback(void);
|
||||
#endif
|
||||
|
||||
#ifdef ESOF_CALLBACK
|
||||
void ESOF_Callback(void);
|
||||
#endif
|
||||
#endif /*__USB_ISTR_H*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,468 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_prop.c
|
||||
* @author MCD Application Team
|
||||
* @version V4.1.0
|
||||
* @date 26-May-2017
|
||||
* @brief All processing related to Virtual Com Port Demo
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_lib.h"
|
||||
#include "usb_conf.h"
|
||||
#include "usb_prop.h"
|
||||
#include "usb_desc.h"
|
||||
#include "usb_pwr.h"
|
||||
#include "hal.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
uint8_t Request = 0;
|
||||
|
||||
LINE_CODING linecoding =
|
||||
{
|
||||
115200, /* baud rate*/
|
||||
0x00, /* stop bits-1*/
|
||||
0x00, /* parity - none*/
|
||||
0x08 /* no. of bits 8*/
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Structures initializations */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
DEVICE Device_Table =
|
||||
{
|
||||
EP_NUM,
|
||||
1};
|
||||
|
||||
DEVICE_PROP Device_Property =
|
||||
{
|
||||
Midi_CDC_Device_init,
|
||||
Midi_CDC_Device_Reset,
|
||||
Midi_CDC_Device_Status_In,
|
||||
Midi_CDC_Device_Status_Out,
|
||||
Midi_CDC_Device_Data_Setup,
|
||||
Midi_CDC_Device_NoData_Setup,
|
||||
Midi_CDC_Device_Get_Interface_Setting,
|
||||
Midi_CDC_Device_GetDeviceDescriptor,
|
||||
Midi_CDC_Device_GetConfigDescriptor,
|
||||
Midi_CDC_Device_GetStringDescriptor,
|
||||
0,
|
||||
0x40 /*MAX PACKET SIZE*/
|
||||
};
|
||||
|
||||
USER_STANDARD_REQUESTS User_Standard_Requests =
|
||||
{
|
||||
Midi_CDC_Device_GetConfiguration,
|
||||
Midi_CDC_Device_SetConfiguration,
|
||||
Midi_CDC_Device_GetInterface,
|
||||
Midi_CDC_Device_SetInterface,
|
||||
Midi_CDC_Device_GetStatus,
|
||||
Midi_CDC_Device_ClearFeature,
|
||||
Midi_CDC_Device_SetEndPointFeature,
|
||||
Midi_CDC_Device_SetDeviceFeature,
|
||||
Midi_CDC_Device_SetDeviceAddress};
|
||||
|
||||
ONE_DESCRIPTOR Device_Descriptor =
|
||||
{
|
||||
(uint8_t *)Midi_CDC_Device_DeviceDescriptor,
|
||||
MIDI_CDC_DEV_SIZ_DEVICE_DESC};
|
||||
|
||||
ONE_DESCRIPTOR Config_Descriptor =
|
||||
{
|
||||
(uint8_t *)Midi_CDC_Device_ConfigDescriptor,
|
||||
MIDI_CDC_DEV_SIZ_CONFIG_DESC};
|
||||
|
||||
ONE_DESCRIPTOR String_Descriptor[4] =
|
||||
{
|
||||
{(uint8_t *)Midi_CDC_Device_StringLangID, MIDI_CDC_DEV_SIZ_STRING_LANGID},
|
||||
{(uint8_t *)Midi_CDC_Device_StringVendor, MIDI_CDC_DEV_SIZ_STRING_VENDOR},
|
||||
{(uint8_t *)Midi_CDC_Device_StringProduct, MIDI_CDC_DEV_SIZ_STRING_PRODUCT},
|
||||
{(uint8_t *)Midi_CDC_Device_StringSerial, MIDI_CDC_DEV_SIZ_STRING_SERIAL}};
|
||||
|
||||
/* Extern variables ----------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Extern function prototypes ------------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/*******************************************************************************
|
||||
* Function Name : Midi_CDC_Device_init.
|
||||
* Description : Midi CDC Device Mouse init routine.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Midi_CDC_Device_init(void)
|
||||
{
|
||||
|
||||
/* Update the serial number string descriptor with the data from the unique
|
||||
ID*/
|
||||
InitSnStringWith64bitId();
|
||||
|
||||
pInformation->Current_Configuration = 0;
|
||||
|
||||
/* Connect the device */
|
||||
PowerOn();
|
||||
|
||||
/* Perform basic device initialization operations */
|
||||
USB_SIL_Init();
|
||||
|
||||
bDeviceState = UNCONNECTED;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Midi_CDC_Device_Reset
|
||||
* Description : Virtual_Com_Port Mouse reset routine
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Midi_CDC_Device_Reset(void)
|
||||
{
|
||||
/* Set Virtual_Com_Port DEVICE as not configured */
|
||||
pInformation->Current_Configuration = 0;
|
||||
|
||||
/* Current Feature initialization */
|
||||
pInformation->Current_Feature = Midi_CDC_Device_ConfigDescriptor[7];
|
||||
|
||||
/* Set Virtual_Com_Port DEVICE with the default Interface*/
|
||||
pInformation->Current_Interface = 0;
|
||||
|
||||
SetBTABLE(BTABLE_ADDRESS);
|
||||
|
||||
/* Initialize Endpoint 0 */
|
||||
SetEPType(ENDP0, EP_CONTROL);
|
||||
SetEPTxStatus(ENDP0, EP_TX_STALL);
|
||||
SetEPRxAddr(ENDP0, ENDP0_RXADDR);
|
||||
SetEPTxAddr(ENDP0, ENDP0_TXADDR);
|
||||
Clear_Status_Out(ENDP0);
|
||||
SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
|
||||
SetEPRxValid(ENDP0);
|
||||
|
||||
/* Initialize Endpoint 1 */
|
||||
SetEPType(ENDP1, EP_BULK);
|
||||
SetEPTxAddr(ENDP1, ENDP1_TXADDR);
|
||||
SetEPTxStatus(ENDP1, EP_TX_NAK);
|
||||
SetEPRxStatus(ENDP1, EP_RX_DIS);
|
||||
|
||||
/* Initialize Endpoint 2 */
|
||||
SetEPType(ENDP2, EP_INTERRUPT);
|
||||
SetEPTxAddr(ENDP2, ENDP2_TXADDR);
|
||||
SetEPRxStatus(ENDP2, EP_RX_DIS);
|
||||
SetEPTxStatus(ENDP2, EP_TX_NAK);
|
||||
|
||||
/* Initialize Endpoint 3 */
|
||||
SetEPType(ENDP3, EP_BULK);
|
||||
SetEPRxAddr(ENDP3, ENDP3_RXADDR);
|
||||
SetEPRxCount(ENDP3, MIDI_CDC_DEV_DATA_SIZE);
|
||||
SetEPRxStatus(ENDP3, EP_RX_VALID);
|
||||
SetEPTxStatus(ENDP3, EP_TX_DIS);
|
||||
|
||||
/* Initialize Endpoint 5 */
|
||||
SetEPType(ENDP5, EP_BULK);
|
||||
SetEPTxAddr(ENDP5, ENDP5_TXADDR);
|
||||
SetEPRxStatus(ENDP5, EP_RX_DIS);
|
||||
SetEPTxStatus(ENDP5, EP_TX_NAK);
|
||||
|
||||
/* Initialize Endpoint 4 */
|
||||
SetEPType(ENDP4, EP_BULK);
|
||||
SetEPRxAddr(ENDP4, ENDP4_RXADDR);
|
||||
SetEPRxCount(ENDP4, MIDI_CDC_DEV_DATA_SIZE);
|
||||
SetEPRxStatus(ENDP4, EP_RX_VALID);
|
||||
SetEPTxStatus(ENDP4, EP_TX_DIS);
|
||||
|
||||
/* Set this device to response on default address */
|
||||
SetDeviceAddress(0);
|
||||
|
||||
bDeviceState = ATTACHED;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Midi_CDC_Device_SetConfiguration.
|
||||
* Description : Update the device state to configured.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Midi_CDC_Device_SetConfiguration(void)
|
||||
{
|
||||
DEVICE_INFO *pInfo = &Device_Info;
|
||||
|
||||
if (pInfo->Current_Configuration != 0)
|
||||
{
|
||||
/* Device configured */
|
||||
bDeviceState = CONFIGURED;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Midi_CDC_Device_SetConfiguration.
|
||||
* Description : Update the device state to addressed.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Midi_CDC_Device_SetDeviceAddress(void)
|
||||
{
|
||||
bDeviceState = ADDRESSED;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Midi_CDC_Device_Status_In.
|
||||
* Description : Midi CDC Device Status In Routine.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Midi_CDC_Device_Status_In(void)
|
||||
{
|
||||
if (Request == SET_LINE_CODING)
|
||||
{
|
||||
Request = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Midi_CDC_Device_Status_Out
|
||||
* Description : Midi CDC Device Status OUT Routine.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Midi_CDC_Device_Status_Out(void)
|
||||
{
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Midi_CDC_Device_Data_Setup
|
||||
* Description : handle the data class specific requests
|
||||
* Input : Request Nb.
|
||||
* Output : None.
|
||||
* Return : USB_UNSUPPORT or USB_SUCCESS.
|
||||
*******************************************************************************/
|
||||
RESULT Midi_CDC_Device_Data_Setup(uint8_t RequestNo)
|
||||
{
|
||||
uint8_t *(*CopyRoutine)(uint16_t);
|
||||
|
||||
CopyRoutine = NULL;
|
||||
|
||||
if (RequestNo == GET_LINE_CODING)
|
||||
{
|
||||
if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
|
||||
{
|
||||
CopyRoutine = Midi_CDC_Device_GetLineCoding;
|
||||
}
|
||||
}
|
||||
else if (RequestNo == SET_LINE_CODING)
|
||||
{
|
||||
if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
|
||||
{
|
||||
CopyRoutine = Midi_CDC_Device_SetLineCoding;
|
||||
}
|
||||
Request = SET_LINE_CODING;
|
||||
}
|
||||
|
||||
if (CopyRoutine == NULL)
|
||||
{
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
|
||||
pInformation->Ctrl_Info.CopyData = CopyRoutine;
|
||||
pInformation->Ctrl_Info.Usb_wOffset = 0;
|
||||
(*CopyRoutine)(0);
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Midi_CDC_Device_NoData_Setup.
|
||||
* Description : handle the no data class specific requests.
|
||||
* Input : Request Nb.
|
||||
* Output : None.
|
||||
* Return : USB_UNSUPPORT or USB_SUCCESS.
|
||||
*******************************************************************************/
|
||||
RESULT Midi_CDC_Device_NoData_Setup(uint8_t RequestNo)
|
||||
{
|
||||
|
||||
if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
|
||||
{
|
||||
if (RequestNo == SET_COMM_FEATURE)
|
||||
{
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
else if (RequestNo == SET_CONTROL_LINE_STATE)
|
||||
{
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Midi_CDC_Device_GetDeviceDescriptor.
|
||||
* Description : Gets the device descriptor.
|
||||
* Input : Length.
|
||||
* Output : None.
|
||||
* Return : The address of the device descriptor.
|
||||
*******************************************************************************/
|
||||
uint8_t *Midi_CDC_Device_GetDeviceDescriptor(uint16_t Length)
|
||||
{
|
||||
return Standard_GetDescriptorData(Length, &Device_Descriptor);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Midi_CDC_Device_GetConfigDescriptor.
|
||||
* Description : get the configuration descriptor.
|
||||
* Input : Length.
|
||||
* Output : None.
|
||||
* Return : The address of the configuration descriptor.
|
||||
*******************************************************************************/
|
||||
uint8_t *Midi_CDC_Device_GetConfigDescriptor(uint16_t Length)
|
||||
{
|
||||
return Standard_GetDescriptorData(Length, &Config_Descriptor);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Midi_CDC_Device_GetStringDescriptor
|
||||
* Description : Gets the string descriptors according to the needed index
|
||||
* Input : Length.
|
||||
* Output : None.
|
||||
* Return : The address of the string descriptors.
|
||||
*******************************************************************************/
|
||||
uint8_t *Midi_CDC_Device_GetStringDescriptor(uint16_t Length)
|
||||
{
|
||||
uint8_t wValue0 = pInformation->USBwValue0;
|
||||
if (wValue0 >= 4)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Standard_GetDescriptorData(Length, &String_Descriptor[wValue0]);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Midi_CDC_Device_Get_Interface_Setting.
|
||||
* Description : test the interface and the alternate setting according to the
|
||||
* supported one.
|
||||
* Input1 : uint8_t: Interface : interface number.
|
||||
* Input2 : uint8_t: AlternateSetting : Alternate Setting number.
|
||||
* Output : None.
|
||||
* Return : The address of the string descriptors.
|
||||
*******************************************************************************/
|
||||
RESULT Midi_CDC_Device_Get_Interface_Setting(uint8_t Interface, uint8_t AlternateSetting)
|
||||
{
|
||||
if (AlternateSetting > 0)
|
||||
{
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
else if (Interface > 1)
|
||||
{
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Midi_CDC_Device_GetLineCoding.
|
||||
* Description : send the linecoding structure to the PC host.
|
||||
* Input : Length.
|
||||
* Output : None.
|
||||
* Return : Linecoding structure base address.
|
||||
*******************************************************************************/
|
||||
uint8_t *Midi_CDC_Device_GetLineCoding(uint16_t Length)
|
||||
{
|
||||
if (Length == 0)
|
||||
{
|
||||
pInformation->Ctrl_Info.Usb_wLength = sizeof(linecoding);
|
||||
return NULL;
|
||||
}
|
||||
return (uint8_t *)&linecoding;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Midi_CDC_Device_SetLineCoding.
|
||||
* Description : Set the linecoding structure fields.
|
||||
* Input : Length.
|
||||
* Output : None.
|
||||
* Return : Linecoding structure base address.
|
||||
*******************************************************************************/
|
||||
uint8_t *Midi_CDC_Device_SetLineCoding(uint16_t Length)
|
||||
{
|
||||
if (Length == 0)
|
||||
{
|
||||
pInformation->Ctrl_Info.Usb_wLength = sizeof(linecoding);
|
||||
return NULL;
|
||||
}
|
||||
return (uint8_t *)&linecoding;
|
||||
}
|
||||
|
||||
void InitSnStringWith64bitId(void)
|
||||
{
|
||||
uint64_t id = HAL_GetHwSerialNum();
|
||||
if (id != 0)
|
||||
{
|
||||
IntToUnicode(id & 0xFFFFFFFF, &Midi_CDC_Device_StringSerial[2], 8);
|
||||
IntToUnicode((id >> 32) & 0xFFFFFFFF, &Midi_CDC_Device_StringSerial[18], 4);
|
||||
}
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : HexToChar.
|
||||
* Description : Convert Hex 32Bits value into char.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void IntToUnicode(uint32_t value, uint8_t *pbuf, uint8_t len)
|
||||
{
|
||||
uint8_t idx = 0;
|
||||
|
||||
for (idx = 0; idx < len; idx++)
|
||||
{
|
||||
if (((value >> 28)) < 0xA)
|
||||
{
|
||||
pbuf[2 * idx] = (value >> 28) + '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
|
||||
}
|
||||
|
||||
value = value << 4;
|
||||
|
||||
pbuf[2 * idx + 1] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_prop.h
|
||||
* @author MCD Application Team
|
||||
* @version V4.1.0
|
||||
* @date 26-May-2017
|
||||
* @brief All processing related to Midi CDC Device Demo (Endpoint 0)
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 __usb_prop_H
|
||||
#define __usb_prop_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t bitrate;
|
||||
uint8_t format;
|
||||
uint8_t paritytype;
|
||||
uint8_t datatype;
|
||||
}LINE_CODING;
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported define -----------------------------------------------------------*/
|
||||
|
||||
#define Midi_CDC_Device_GetConfiguration NOP_Process
|
||||
//#define Midi_CDC_Device_SetConfiguration NOP_Process
|
||||
#define Midi_CDC_Device_GetInterface NOP_Process
|
||||
#define Midi_CDC_Device_SetInterface NOP_Process
|
||||
#define Midi_CDC_Device_GetStatus NOP_Process
|
||||
#define Midi_CDC_Device_ClearFeature NOP_Process
|
||||
#define Midi_CDC_Device_SetEndPointFeature NOP_Process
|
||||
#define Midi_CDC_Device_SetDeviceFeature NOP_Process
|
||||
//#define Midi_CDC_Device_SetDeviceAddress NOP_Process
|
||||
|
||||
#define SEND_ENCAPSULATED_COMMAND 0x00
|
||||
#define GET_ENCAPSULATED_RESPONSE 0x01
|
||||
#define SET_COMM_FEATURE 0x02
|
||||
#define GET_COMM_FEATURE 0x03
|
||||
#define CLEAR_COMM_FEATURE 0x04
|
||||
#define SET_LINE_CODING 0x20
|
||||
#define GET_LINE_CODING 0x21
|
||||
#define SET_CONTROL_LINE_STATE 0x22
|
||||
#define SEND_BREAK 0x23
|
||||
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void Midi_CDC_Device_init(void);
|
||||
void Midi_CDC_Device_Reset(void);
|
||||
void Midi_CDC_Device_SetConfiguration(void);
|
||||
void Midi_CDC_Device_SetDeviceAddress (void);
|
||||
void Midi_CDC_Device_Status_In (void);
|
||||
void Midi_CDC_Device_Status_Out (void);
|
||||
RESULT Midi_CDC_Device_Data_Setup(uint8_t);
|
||||
RESULT Midi_CDC_Device_NoData_Setup(uint8_t);
|
||||
RESULT Midi_CDC_Device_Get_Interface_Setting(uint8_t Interface, uint8_t AlternateSetting);
|
||||
uint8_t *Midi_CDC_Device_GetDeviceDescriptor(uint16_t );
|
||||
uint8_t *Midi_CDC_Device_GetConfigDescriptor(uint16_t);
|
||||
uint8_t *Midi_CDC_Device_GetStringDescriptor(uint16_t);
|
||||
|
||||
uint8_t *Midi_CDC_Device_GetLineCoding(uint16_t Length);
|
||||
uint8_t *Midi_CDC_Device_SetLineCoding(uint16_t Length);
|
||||
|
||||
void InitSnStringWith64bitId(void);
|
||||
void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len);
|
||||
|
||||
#endif /* __usb_prop_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -0,0 +1,351 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_pwr.c
|
||||
* @author MCD Application Team
|
||||
* @version V4.1.0
|
||||
* @date 26-May-2017
|
||||
* @brief Connection/disconnection & power management
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_lib.h"
|
||||
#include "usb_pwr.h"
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
__IO uint32_t bDeviceState = UNCONNECTED; /* USB device status */
|
||||
__IO bool fSuspendEnabled = TRUE; /* true when suspend is possible */
|
||||
__IO uint32_t EP[8];
|
||||
|
||||
struct
|
||||
{
|
||||
__IO RESUME_STATE eState;
|
||||
__IO uint8_t bESOFcnt;
|
||||
}
|
||||
ResumeS;
|
||||
|
||||
__IO uint32_t remotewakeupon=0;
|
||||
|
||||
/* Extern variables ----------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Extern function prototypes ------------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Function Name : PowerOn
|
||||
* Description :
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : USB_SUCCESS.
|
||||
*/
|
||||
RESULT PowerOn(void)
|
||||
{
|
||||
uint16_t wRegVal;
|
||||
|
||||
#if !defined (USE_NUCLEO)
|
||||
/*** cable plugged-in ? ***/
|
||||
USB_Cable_Config(ENABLE);
|
||||
#endif
|
||||
|
||||
/*** CNTR_PWDN = 0 ***/
|
||||
wRegVal = CNTR_FRES;
|
||||
_SetCNTR(wRegVal);
|
||||
|
||||
/* The following sequence is recommended:
|
||||
1- FRES = 0
|
||||
2- Wait until RESET flag = 1 (polling)
|
||||
3- clear ISTR register */
|
||||
|
||||
/*** CNTR_FRES = 0 ***/
|
||||
wInterrupt_Mask = 0;
|
||||
|
||||
_SetCNTR(wInterrupt_Mask);
|
||||
|
||||
/* Wait until RESET flag = 1 (polling) */
|
||||
while((_GetISTR()&ISTR_RESET) == 1);
|
||||
|
||||
/*** Clear pending interrupts ***/
|
||||
SetISTR(0);
|
||||
|
||||
/*** Set interrupt mask ***/
|
||||
wInterrupt_Mask = CNTR_RESETM | CNTR_SUSPM | CNTR_WKUPM;
|
||||
_SetCNTR(wInterrupt_Mask);
|
||||
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function Name : PowerOff
|
||||
* Description : handles switch-off conditions
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : USB_SUCCESS.
|
||||
**/
|
||||
RESULT PowerOff()
|
||||
{
|
||||
/* disable all interrupts and force USB reset */
|
||||
_SetCNTR(CNTR_FRES);
|
||||
|
||||
/* clear interrupt status register */
|
||||
_SetISTR(0);
|
||||
|
||||
#if !defined (USE_NUCLEO)
|
||||
/* Disable the Pull-Up*/
|
||||
USB_Cable_Config(DISABLE);
|
||||
#endif
|
||||
/* switch-off device */
|
||||
_SetCNTR(CNTR_FRES + CNTR_PDWN);
|
||||
/* sw variables reset */
|
||||
/* ... */
|
||||
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function Name : Suspend
|
||||
* Description : sets suspend mode operating conditions
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : USB_SUCCESS.
|
||||
*/
|
||||
void Suspend(void)
|
||||
{
|
||||
uint32_t i =0;
|
||||
uint16_t wCNTR;
|
||||
#ifdef USB_LOW_PWR_MGMT_SUPPORT
|
||||
uint32_t tmpreg = 0;
|
||||
__IO uint32_t savePWR_CR=0;
|
||||
#endif
|
||||
|
||||
|
||||
/* suspend preparation */
|
||||
/* ... */
|
||||
|
||||
/*Store CNTR value */
|
||||
wCNTR = _GetCNTR();
|
||||
|
||||
/* This a sequence to apply a force RESET to handle a robustness case */
|
||||
|
||||
/*Store endpoints registers status */
|
||||
for (i=0;i<8;i++) EP[i] = _GetENDPOINT(i);
|
||||
|
||||
/* unmask RESET flag */
|
||||
wCNTR|=CNTR_RESETM;
|
||||
_SetCNTR(wCNTR);
|
||||
|
||||
/*apply FRES */
|
||||
wCNTR|=CNTR_FRES;
|
||||
_SetCNTR(wCNTR);
|
||||
|
||||
/*clear FRES*/
|
||||
wCNTR&=~CNTR_FRES;
|
||||
_SetCNTR(wCNTR);
|
||||
|
||||
/*poll for RESET flag in ISTR*/
|
||||
while((_GetISTR()&ISTR_RESET) == 0);
|
||||
|
||||
/* clear RESET flag in ISTR */
|
||||
_SetISTR((uint16_t)CLR_RESET);
|
||||
|
||||
/*restore Enpoints*/
|
||||
for (i=0;i<8;i++)
|
||||
_SetENDPOINT(i, EP[i]);
|
||||
|
||||
/* Now it is safe to enter macrocell in suspend mode */
|
||||
wCNTR |= CNTR_FSUSP;
|
||||
_SetCNTR(wCNTR);
|
||||
|
||||
/* force low-power mode in the macrocell */
|
||||
wCNTR = _GetCNTR();
|
||||
wCNTR |= CNTR_LPMODE;
|
||||
_SetCNTR(wCNTR);
|
||||
|
||||
#ifdef USB_LOW_PWR_MGMT_SUPPORT
|
||||
/*prepare entry in low power mode (STOP mode)*/
|
||||
/* Select the regulator state in STOP mode*/
|
||||
savePWR_CR = PWR->CR;
|
||||
tmpreg = PWR->CR;
|
||||
/* Clear PDDS and LPDS bits */
|
||||
tmpreg &= ((uint32_t)0xFFFFFFFC);
|
||||
/* Set LPDS bit according to PWR_Regulator value */
|
||||
tmpreg |= PWR_Regulator_LowPower;
|
||||
/* Store the new value */
|
||||
PWR->CR = tmpreg;
|
||||
/* Set SLEEPDEEP bit of Cortex System Control Register */
|
||||
#if defined(STM32F303xE) || defined(STM32F302x8) || defined(STM32F303xC) || defined (STM32F37X)
|
||||
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
|
||||
#else
|
||||
SCB->SCR |= SCB_SCR_SLEEPDEEP;
|
||||
#endif
|
||||
|
||||
/* enter system in STOP mode, only when wakeup flag in not set */
|
||||
if((_GetISTR()&ISTR_WKUP)==0)
|
||||
{
|
||||
__WFI();
|
||||
/* Reset SLEEPDEEP bit of Cortex System Control Register */
|
||||
#if defined(STM32F303xE) || defined(STM32F302x8) || defined(STM32F303xC) || defined (STM32F37X)
|
||||
SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
|
||||
#else
|
||||
SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Clear Wakeup flag */
|
||||
_SetISTR(CLR_WKUP);
|
||||
/* clear FSUSP to abort entry in suspend mode */
|
||||
wCNTR = _GetCNTR();
|
||||
wCNTR&=~CNTR_FSUSP;
|
||||
_SetCNTR(wCNTR);
|
||||
|
||||
/*restore sleep mode configuration */
|
||||
/* restore Power regulator config in sleep mode*/
|
||||
PWR->CR = savePWR_CR;
|
||||
|
||||
/* Reset SLEEPDEEP bit of Cortex System Control Register */
|
||||
#if defined(STM32F303xE) || defined(STM32F302x8) || defined(STM32F303xC) || defined (STM32F37X)
|
||||
SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
|
||||
#else
|
||||
SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP);
|
||||
#endif
|
||||
}
|
||||
#endif /* USB_LOW_PWR_MGMT_SUPPORT */
|
||||
}
|
||||
|
||||
/**
|
||||
* Function Name : Resume_Init
|
||||
* Description : Handles wake-up restoring normal operations
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : USB_SUCCESS.
|
||||
*/
|
||||
void Resume_Init(void)
|
||||
{
|
||||
uint16_t wCNTR;
|
||||
|
||||
/* ------------------ ONLY WITH BUS-POWERED DEVICES ---------------------- */
|
||||
/* restart the clocks */
|
||||
/* ... */
|
||||
|
||||
/* CNTR_LPMODE = 0 */
|
||||
wCNTR = _GetCNTR();
|
||||
wCNTR &= (~CNTR_LPMODE);
|
||||
_SetCNTR(wCNTR);
|
||||
|
||||
#ifdef USB_LOW_PWR_MGMT_SUPPORT
|
||||
/* restore full power */
|
||||
/* ... on connected devices */
|
||||
Leave_LowPowerMode();
|
||||
|
||||
#endif /* USB_LOW_PWR_MGMT_SUPPORT */
|
||||
|
||||
/* reset FSUSP bit */
|
||||
_SetCNTR(IMR_MSK);
|
||||
|
||||
/* reverse suspend preparation */
|
||||
/* ... */
|
||||
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Resume
|
||||
* Description : This is the state machine handling resume operations and
|
||||
* timing sequence. The control is based on the Resume structure
|
||||
* variables and on the ESOF interrupt calling this subroutine
|
||||
* without changing machine state.
|
||||
* Input : a state machine value (RESUME_STATE)
|
||||
* RESUME_ESOF doesn't change ResumeS.eState allowing
|
||||
* decrementing of the ESOF counter in different states.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Resume(RESUME_STATE eResumeSetVal)
|
||||
{
|
||||
uint16_t wCNTR;
|
||||
|
||||
if (eResumeSetVal != RESUME_ESOF)
|
||||
ResumeS.eState = eResumeSetVal;
|
||||
switch (ResumeS.eState)
|
||||
{
|
||||
case RESUME_EXTERNAL:
|
||||
if (remotewakeupon ==0)
|
||||
{
|
||||
Resume_Init();
|
||||
ResumeS.eState = RESUME_OFF;
|
||||
}
|
||||
else /* RESUME detected during the RemoteWAkeup signalling => keep RemoteWakeup handling*/
|
||||
{
|
||||
ResumeS.eState = RESUME_ON;
|
||||
}
|
||||
break;
|
||||
case RESUME_INTERNAL:
|
||||
Resume_Init();
|
||||
ResumeS.eState = RESUME_START;
|
||||
remotewakeupon = 1;
|
||||
break;
|
||||
case RESUME_LATER:
|
||||
ResumeS.bESOFcnt = 2;
|
||||
ResumeS.eState = RESUME_WAIT;
|
||||
break;
|
||||
case RESUME_WAIT:
|
||||
ResumeS.bESOFcnt--;
|
||||
if (ResumeS.bESOFcnt == 0)
|
||||
ResumeS.eState = RESUME_START;
|
||||
break;
|
||||
case RESUME_START:
|
||||
wCNTR = _GetCNTR();
|
||||
wCNTR |= CNTR_RESUME;
|
||||
_SetCNTR(wCNTR);
|
||||
ResumeS.eState = RESUME_ON;
|
||||
ResumeS.bESOFcnt = 10;
|
||||
break;
|
||||
case RESUME_ON:
|
||||
ResumeS.bESOFcnt--;
|
||||
if (ResumeS.bESOFcnt == 0)
|
||||
{
|
||||
wCNTR = _GetCNTR();
|
||||
wCNTR &= (~CNTR_RESUME);
|
||||
_SetCNTR(wCNTR);
|
||||
ResumeS.eState = RESUME_OFF;
|
||||
remotewakeupon = 0;
|
||||
}
|
||||
break;
|
||||
case RESUME_OFF:
|
||||
case RESUME_ESOF:
|
||||
default:
|
||||
ResumeS.eState = RESUME_OFF;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_pwr.h
|
||||
* @author MCD Application Team
|
||||
* @version V4.1.0
|
||||
* @date 26-May-2017
|
||||
* @brief Connection/disconnection & power management header
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 __USB_PWR_H
|
||||
#define __USB_PWR_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
typedef enum _RESUME_STATE
|
||||
{
|
||||
RESUME_EXTERNAL,
|
||||
RESUME_INTERNAL,
|
||||
RESUME_LATER,
|
||||
RESUME_WAIT,
|
||||
RESUME_START,
|
||||
RESUME_ON,
|
||||
RESUME_OFF,
|
||||
RESUME_ESOF
|
||||
} RESUME_STATE;
|
||||
|
||||
typedef enum _DEVICE_STATE
|
||||
{
|
||||
UNCONNECTED,
|
||||
ATTACHED,
|
||||
POWERED,
|
||||
SUSPENDED,
|
||||
ADDRESSED,
|
||||
CONFIGURED
|
||||
} DEVICE_STATE;
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void Suspend(void);
|
||||
void Resume_Init(void);
|
||||
void Resume(RESUME_STATE eResumeSetVal);
|
||||
RESULT PowerOn(void);
|
||||
RESULT PowerOff(void);
|
||||
|
||||
/* External variables --------------------------------------------------------*/
|
||||
extern __IO uint32_t bDeviceState; /* USB device status */
|
||||
extern __IO bool fSuspendEnabled; /* true when suspend is possible */
|
||||
|
||||
#endif /*__USB_PWR_H*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
Reference in New Issue
Block a user