mirror of
https://github.com/sengeiou/realtek_ameba_mp_sdk.git
synced 2026-07-06 03:25:42 +00:00
ameba micropython sdk first commit
This commit is contained in:
commit
8508ee6139
5619 changed files with 1874619 additions and 0 deletions
402
sdk/component/common/drivers/usb/device/audio/inc/usb_audio.h
Normal file
402
sdk/component/common/drivers/usb/device/audio/inc/usb_audio.h
Normal file
|
|
@ -0,0 +1,402 @@
|
|||
#ifndef __USB_AUDIO_H
|
||||
#define __USB_AUDIO_H
|
||||
|
||||
#include <platform_opts.h>
|
||||
|
||||
#ifdef CONFIG_USBD_AUDIO
|
||||
|
||||
#include "usb.h"
|
||||
#include "usb_composite.h"
|
||||
#include "usb_audio_8763.h"
|
||||
#include "ameba_otg.h"
|
||||
|
||||
#define USBD_AUDIO_DEBUG 0
|
||||
|
||||
#if USBD_AUDIO_DEBUG
|
||||
#define USBD_AUDIO_INFO(fmt, args...) printf("\n\r[ADC]%s: " fmt, __FUNCTION__, ## args)
|
||||
#define USBD_AUDIO_WARN(fmt, args...) printf("\n\r[ADC]%s: " fmt, __FUNCTION__, ## args)
|
||||
#define USBD_AUDIO_ERROR(fmt, args...) printf("\n\r[ADC]%s: " fmt, __FUNCTION__, ## args)
|
||||
#define USBD_AUDIO_ENTER printf("\n\r[ADC]%s: =>", __FUNCTION__)
|
||||
#define USBD_AUDIO_EXIT printf("\n\r[ADC]%s: <=", __FUNCTION__)
|
||||
#define USBD_AUDIO_EXIT_ERR printf("\n\r[ADC]%s: ERR <=", __FUNCTION__)
|
||||
#else
|
||||
#define USBD_AUDIO_INFO(fmt, args...)
|
||||
#define USBD_AUDIO_WARN(fmt, args...)
|
||||
#define USBD_AUDIO_ERROR(fmt, args...)
|
||||
#define USBD_AUDIO_ENTER
|
||||
#define USBD_AUDIO_EXIT
|
||||
#define USBD_AUDIO_EXIT_ERR
|
||||
#endif
|
||||
|
||||
#define USB_ISO_OUT_ENDPOINT_ADDRESS 0x02
|
||||
#define USB_ISO_IN_ENDPOINT_ADDRESS 0x81
|
||||
|
||||
struct usb_audio_control {
|
||||
dwc_list_link_t list;
|
||||
const char *name;
|
||||
uint8_t type;
|
||||
int data[5];
|
||||
int (*set)(struct usb_audio_control *con, uint8_t cmd, int value);
|
||||
int (*get)(struct usb_audio_control *con, uint8_t cmd);
|
||||
};
|
||||
|
||||
struct usb_audio_control_selector {
|
||||
dwc_list_link_t list;
|
||||
dwc_list_link_t control;
|
||||
uint8_t id;
|
||||
const char *name;
|
||||
uint8_t type;
|
||||
struct usb_descriptor_header *desc;
|
||||
};
|
||||
|
||||
#define UAC_VERSION_1 0x00
|
||||
#define UAC_VERSION_2 0x20
|
||||
|
||||
/* A.2 Audio Interface Subclass Codes */
|
||||
#define USB_SUBCLASS_AUDIOCONTROL 0x01
|
||||
#define USB_SUBCLASS_AUDIOSTREAMING 0x02
|
||||
#define USB_SUBCLASS_MIDISTREAMING 0x03
|
||||
|
||||
#define F_AUDIO_NUM_INTERFACES 2
|
||||
|
||||
/* A.5 Audio Class-Specific AC Interface Descriptor Subtypes */
|
||||
#define UAC_HEADER 0x01
|
||||
#define UAC_INPUT_TERMINAL 0x02
|
||||
#define UAC_OUTPUT_TERMINAL 0x03
|
||||
#define UAC_MIXER_UNIT 0x04
|
||||
#define UAC_SELECTOR_UNIT 0x05
|
||||
#define UAC_FEATURE_UNIT 0x06
|
||||
#define UAC1_PROCESSING_UNIT 0x07
|
||||
#define UAC1_EXTENSION_UNIT 0x08
|
||||
|
||||
|
||||
/* A.6 Audio Class-Specific AS Interface Descriptor Subtypes */
|
||||
#define UAC_AS_GENERAL 0x01
|
||||
#define UAC_FORMAT_TYPE 0x02
|
||||
#define UAC_FORMAT_SPECIFIC 0x03
|
||||
|
||||
/* A.7 Processing Unit Process Types */
|
||||
#define UAC_PROCESS_UNDEFINED 0x00
|
||||
#define UAC_PROCESS_UP_DOWNMIX 0x01
|
||||
#define UAC_PROCESS_DOLBY_PROLOGIC 0x02
|
||||
#define UAC_PROCESS_STEREO_EXTENDER 0x03
|
||||
#define UAC_PROCESS_REVERB 0x04
|
||||
#define UAC_PROCESS_CHORUS 0x05
|
||||
#define UAC_PROCESS_DYN_RANGE_COMP 0x06
|
||||
|
||||
/* A.8 Audio Class-Specific Endpoint Descriptor Subtypes */
|
||||
#define UAC_EP_GENERAL 0x01
|
||||
|
||||
/* A.9 Audio Class-Specific Request Codes */
|
||||
#define UAC_SET_ 0x00
|
||||
#define UAC_GET_ 0x80
|
||||
|
||||
#define UAC__CUR 0x1
|
||||
#define UAC__MIN 0x2
|
||||
#define UAC__MAX 0x3
|
||||
#define UAC__RES 0x4
|
||||
#define UAC__MEM 0x5
|
||||
|
||||
#define UAC_SET_CUR (UAC_SET_ | UAC__CUR)
|
||||
#define UAC_GET_CUR (UAC_GET_ | UAC__CUR)
|
||||
#define UAC_SET_MIN (UAC_SET_ | UAC__MIN)
|
||||
#define UAC_GET_MIN (UAC_GET_ | UAC__MIN)
|
||||
#define UAC_SET_MAX (UAC_SET_ | UAC__MAX)
|
||||
#define UAC_GET_MAX (UAC_GET_ | UAC__MAX)
|
||||
#define UAC_SET_RES (UAC_SET_ | UAC__RES)
|
||||
#define UAC_GET_RES (UAC_GET_ | UAC__RES)
|
||||
#define UAC_SET_MEM (UAC_SET_ | UAC__MEM)
|
||||
#define UAC_GET_MEM (UAC_GET_ | UAC__MEM)
|
||||
|
||||
#define UAC_GET_STAT 0xff
|
||||
|
||||
|
||||
/* A.10 Control Selector Codes */
|
||||
|
||||
/* A.10.1 Terminal Control Selectors */
|
||||
#define UAC_TERM_COPY_PROTECT 0x01
|
||||
|
||||
/* A.10.2 Feature Unit Control Selectors */
|
||||
#define UAC_FU_MUTE 0x01
|
||||
#define UAC_FU_VOLUME 0x02
|
||||
#define UAC_FU_BASS 0x03
|
||||
#define UAC_FU_MID 0x04
|
||||
#define UAC_FU_TREBLE 0x05
|
||||
#define UAC_FU_GRAPHIC_EQUALIZER 0x06
|
||||
#define UAC_FU_AUTOMATIC_GAIN 0x07
|
||||
#define UAC_FU_DELAY 0x08
|
||||
#define UAC_FU_BASS_BOOST 0x09
|
||||
#define UAC_FU_LOUDNESS 0x0a
|
||||
|
||||
#define UAC_CONTROL_BIT(CS) (1 << ((CS) - 1))
|
||||
|
||||
/* A.10.3.1 Up/Down-mix Processing Unit Controls Selectors */
|
||||
#define UAC_UD_ENABLE 0x01
|
||||
#define UAC_UD_MODE_SELECT 0x02
|
||||
|
||||
/* A.10.3.2 Dolby Prologic (tm) Processing Unit Controls Selectors */
|
||||
#define UAC_DP_ENABLE 0x01
|
||||
#define UAC_DP_MODE_SELECT 0x02
|
||||
|
||||
/* A.10.3.3 3D Stereo Extender Processing Unit Control Selectors */
|
||||
#define UAC_3D_ENABLE 0x01
|
||||
#define UAC_3D_SPACE 0x02
|
||||
|
||||
/* A.10.3.4 Reverberation Processing Unit Control Selectors */
|
||||
#define UAC_REVERB_ENABLE 0x01
|
||||
#define UAC_REVERB_LEVEL 0x02
|
||||
#define UAC_REVERB_TIME 0x03
|
||||
#define UAC_REVERB_FEEDBACK 0x04
|
||||
|
||||
/* A.10.3.5 Chorus Processing Unit Control Selectors */
|
||||
#define UAC_CHORUS_ENABLE 0x01
|
||||
#define UAC_CHORUS_LEVEL 0x02
|
||||
#define UAC_CHORUS_RATE 0x03
|
||||
#define UAC_CHORUS_DEPTH 0x04
|
||||
|
||||
/* A.10.3.6 Dynamic Range Compressor Unit Control Selectors */
|
||||
#define UAC_DCR_ENABLE 0x01
|
||||
#define UAC_DCR_RATE 0x02
|
||||
#define UAC_DCR_MAXAMPL 0x03
|
||||
#define UAC_DCR_THRESHOLD 0x04
|
||||
#define UAC_DCR_ATTACK_TIME 0x05
|
||||
#define UAC_DCR_RELEASE_TIME 0x06
|
||||
|
||||
/* A.10.4 Extension Unit Control Selectors */
|
||||
#define UAC_XU_ENABLE 0x01
|
||||
|
||||
/* MIDI - A.1 MS Class-Specific Interface Descriptor Subtypes */
|
||||
#define UAC_MS_HEADER 0x01
|
||||
#define UAC_MIDI_IN_JACK 0x02
|
||||
#define UAC_MIDI_OUT_JACK 0x03
|
||||
|
||||
/* MIDI - A.1 MS Class-Specific Endpoint Descriptor Subtypes */
|
||||
#define UAC_MS_GENERAL 0x01
|
||||
|
||||
/* Terminals - 2.1 USB Terminal Types */
|
||||
#define UAC_TERMINAL_UNDEFINED 0x100
|
||||
#define UAC_TERMINAL_STREAMING 0x101
|
||||
#define UAC_TERMINAL_VENDOR_SPEC 0x1FF
|
||||
|
||||
#pragma pack(push)
|
||||
#pragma pack(1)
|
||||
|
||||
/* Terminal Control Selectors */
|
||||
/* 4.3.2 Class-Specific AC Interface Descriptor */
|
||||
|
||||
struct uac1_ac_header_descriptor {
|
||||
uint8_t bLength; /* 8 + n */
|
||||
uint8_t bDescriptorType; /* USB_DT_CS_INTERFACE */
|
||||
uint8_t bDescriptorSubtype; /* UAC_MS_HEADER */
|
||||
uint16_t bcdADC; /* 0x0100 */
|
||||
uint16_t wTotalLength; /* includes Unit and Terminal desc. */
|
||||
uint8_t bInCollection; /* n */
|
||||
uint8_t baInterfaceNr[F_AUDIO_NUM_INTERFACES]; /* [n] */
|
||||
} __attribute__((packed));
|
||||
//#define AC_HEADER_COUNT 2
|
||||
#define UAC_DT_AC_HEADER_SIZE(n) (8 + (n))
|
||||
|
||||
/* 4.3.2.1 Input Terminal Descriptor */
|
||||
struct uac_input_terminal_descriptor {
|
||||
uint8_t bLength; /* in bytes: 12 */
|
||||
uint8_t bDescriptorType; /* CS_INTERFACE descriptor type */
|
||||
uint8_t bDescriptorSubtype; /* INPUT_TERMINAL descriptor subtype */
|
||||
uint8_t bTerminalID; /* Constant uniquely terminal ID */
|
||||
uint16_t wTerminalType; /* USB Audio Terminal Types */
|
||||
uint8_t bAssocTerminal; /* ID of the Output Terminal associated */
|
||||
uint8_t bNrChannels; /* Number of logical output channels */
|
||||
uint16_t wChannelConfig;
|
||||
uint8_t iChannelNames;
|
||||
uint8_t iTerminal;
|
||||
} __attribute__((packed));
|
||||
|
||||
#define UAC_DT_INPUT_TERMINAL_SIZE 12
|
||||
|
||||
/* Terminals - 2.2 Input Terminal Types */
|
||||
#define UAC_INPUT_TERMINAL_UNDEFINED 0x200
|
||||
#define UAC_INPUT_TERMINAL_MICROPHONE 0x201
|
||||
#define UAC_INPUT_TERMINAL_DESKTOP_MICROPHONE 0x202
|
||||
#define UAC_INPUT_TERMINAL_PERSONAL_MICROPHONE 0x203
|
||||
#define UAC_INPUT_TERMINAL_OMNI_DIR_MICROPHONE 0x204
|
||||
#define UAC_INPUT_TERMINAL_MICROPHONE_ARRAY 0x205
|
||||
#define UAC_INPUT_TERMINAL_PROC_MICROPHONE_ARRAY 0x206
|
||||
|
||||
/* Terminals - control selectors */
|
||||
|
||||
#define UAC_TERMINAL_CS_COPY_PROTECT_CONTROL 0x01
|
||||
|
||||
/* 4.3.2.2 Output Terminal Descriptor */
|
||||
struct uac1_output_terminal_descriptor {
|
||||
uint8_t bLength; /* in bytes: 9 */
|
||||
uint8_t bDescriptorType; /* CS_INTERFACE descriptor type */
|
||||
uint8_t bDescriptorSubtype; /* OUTPUT_TERMINAL descriptor subtype */
|
||||
uint8_t bTerminalID; /* Constant uniquely terminal ID */
|
||||
uint16_t wTerminalType; /* USB Audio Terminal Types */
|
||||
uint8_t bAssocTerminal; /* ID of the Input Terminal associated */
|
||||
uint8_t bSourceID; /* ID of the connected Unit or Terminal*/
|
||||
uint8_t iTerminal;
|
||||
} __attribute__((packed));
|
||||
|
||||
#define UAC_DT_OUTPUT_TERMINAL_SIZE 9
|
||||
|
||||
/* Terminals - 2.3 Output Terminal Types */
|
||||
#define UAC_OUTPUT_TERMINAL_UNDEFINED 0x300
|
||||
#define UAC_OUTPUT_TERMINAL_SPEAKER 0x301
|
||||
#define UAC_OUTPUT_TERMINAL_HEADPHONES 0x302
|
||||
#define UAC_OUTPUT_TERMINAL_HEAD_MOUNTED_DISPLAY_AUDIO 0x303
|
||||
#define UAC_OUTPUT_TERMINAL_DESKTOP_SPEAKER 0x304
|
||||
#define UAC_OUTPUT_TERMINAL_ROOM_SPEAKER 0x305
|
||||
#define UAC_OUTPUT_TERMINAL_COMMUNICATION_SPEAKER 0x306
|
||||
#define UAC_OUTPUT_TERMINAL_LOW_FREQ_EFFECTS_SPEAKER 0x307
|
||||
|
||||
/* Set bControlSize = 2 as default setting */
|
||||
#define UAC_DT_FEATURE_UNIT_SIZE(ch) (7 + ((ch) + 1) * 2)
|
||||
|
||||
/* As above, but more useful for defining your own descriptors: */
|
||||
//#define DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR(ch)
|
||||
|
||||
#define DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR 2
|
||||
#define DECLARE_FEATURE_UNIY_CONTROL_SIZE 1
|
||||
#define CHANNEL_CNT 2
|
||||
struct uac_feature_unit_descriptor_2 {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bDescriptorSubtype;
|
||||
uint8_t bUnitID;
|
||||
uint8_t bSourceID;
|
||||
uint8_t bControlSize;//DECLARE_FEATURE_UNIY_CONTROL_SIZE
|
||||
//uint16_t bmaControls[DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR + 1];
|
||||
uint8_t bmaControls[((DECLARE_FEATURE_UNIY_CONTROL_SIZE) * (2)) + 1];
|
||||
uint8_t iFeature;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct uac_feature_unit_descriptor_1 {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bDescriptorSubtype;
|
||||
uint8_t bUnitID;
|
||||
uint8_t bSourceID;
|
||||
uint8_t bControlSize;//DECLARE_FEATURE_UNIY_CONTROL_SIZE
|
||||
//uint16_t bmaControls[DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR + 1];
|
||||
uint8_t bmaControls[((DECLARE_FEATURE_UNIY_CONTROL_SIZE) * (1)) + 1];
|
||||
uint8_t iFeature;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct uac_feature_unit_descriptor_0 {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bDescriptorSubtype;
|
||||
uint8_t bUnitID;
|
||||
uint8_t bSourceID;
|
||||
uint8_t bControlSize;//DECLARE_FEATURE_UNIY_CONTROL_SIZE
|
||||
//uint16_t bmaControls[DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR + 1];
|
||||
uint8_t bmaControls[((DECLARE_FEATURE_UNIY_CONTROL_SIZE) * (0)) + 1];
|
||||
uint8_t iFeature;
|
||||
} __attribute__((packed));
|
||||
|
||||
/* 4.3.2.3 Mixer Unit Descriptor */
|
||||
// fongpin modify
|
||||
#define MIXER_UNIT_CONNECTED 2 // BBRRO DEFINE
|
||||
struct uac_mixer_unit_descriptor {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bDescriptorSubtype;
|
||||
uint8_t bUnitID;
|
||||
uint8_t bNrInPins;
|
||||
uint8_t baSourceID[MIXER_UNIT_CONNECTED];// modify
|
||||
uint8_t bNrChannels;// add
|
||||
uint16_t bmChannelConfig;//add
|
||||
uint8_t iChannelNames;//add
|
||||
uint8_t bmControls;// add
|
||||
uint8_t iMixer;//add
|
||||
|
||||
} __attribute__((packed));
|
||||
|
||||
/* 4.3.2.4 Selector Unit Descriptor */
|
||||
// fongpin modify
|
||||
struct uac_selector_unit_descriptor {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bDescriptorSubtype;
|
||||
uint8_t bUintID;
|
||||
uint8_t bNrInPins;
|
||||
uint8_t baSourceID;
|
||||
uint8_t iSelector;
|
||||
} __attribute__((packed));
|
||||
|
||||
/* 4.5.2 Class-Specific AS Interface Descriptor */
|
||||
struct uac1_as_header_descriptor {
|
||||
uint8_t bLength; /* in bytes: 7 */
|
||||
uint8_t bDescriptorType; /* USB_DT_CS_INTERFACE */
|
||||
uint8_t bDescriptorSubtype; /* AS_GENERAL */
|
||||
uint8_t bTerminalLink; /* Terminal ID of connected Terminal */
|
||||
uint8_t bDelay; /* Delay introduced by the data path */
|
||||
uint16_t wFormatTag; /* The Audio Data Format */
|
||||
} __attribute__((packed));
|
||||
|
||||
#define UAC_DT_AS_HEADER_SIZE 7
|
||||
|
||||
|
||||
/* Formats - A.1.1 Audio Data Format Type I Codes */
|
||||
#define UAC_FORMAT_TYPE_I_UNDEFINED 0x0
|
||||
#define UAC_FORMAT_TYPE_I_PCM 0x1
|
||||
#define UAC_FORMAT_TYPE_I_PCM8 0x2
|
||||
#define UAC_FORMAT_TYPE_I_IEEE_FLOAT 0x3
|
||||
#define UAC_FORMAT_TYPE_I_ALAW 0x4
|
||||
#define UAC_FORMAT_TYPE_I_MULAW 0x5
|
||||
|
||||
struct uac_format_type_i_discrete_descriptor {
|
||||
uint8_t bLength; /* in bytes: 8 + (ns * 3) */
|
||||
uint8_t bDescriptorType; /* USB_DT_CS_INTERFACE */
|
||||
uint8_t bDescriptorSubtype; /* FORMAT_TYPE */
|
||||
uint8_t bFormatType; /* FORMAT_TYPE_1 */
|
||||
uint8_t bNrChannels; /* physical channels in the stream */
|
||||
uint8_t bSubframeSize; /* */
|
||||
uint8_t bBitResolution;
|
||||
uint8_t bSamFreqType;
|
||||
uint8_t tSamFreq[3][3];
|
||||
} __attribute__((packed));
|
||||
|
||||
/* Formats - A.2 Format Type Codes */
|
||||
#define UAC_FORMAT_TYPE_UNDEFINED 0x0
|
||||
#define UAC_FORMAT_TYPE_I 0x1
|
||||
#define UAC_FORMAT_TYPE_II 0x2
|
||||
#define UAC_FORMAT_TYPE_III 0x3
|
||||
#define UAC_EXT_FORMAT_TYPE_I 0x81
|
||||
#define UAC_EXT_FORMAT_TYPE_II 0x82
|
||||
#define UAC_EXT_FORMAT_TYPE_III 0x83
|
||||
|
||||
struct uac_iso_endpoint_descriptor {
|
||||
uint8_t bLength; /* in bytes: 7 */
|
||||
uint8_t bDescriptorType; /* USB_DT_CS_ENDPOINT */
|
||||
uint8_t bDescriptorSubtype; /* EP_GENERAL */
|
||||
uint8_t bmAttributes;
|
||||
uint8_t bLockDelayUnits;
|
||||
uint16_t wLockDelay;
|
||||
} __attribute__((packed));
|
||||
#define UAC_ISO_ENDPOINT_DESC_SIZE 7
|
||||
|
||||
#define UAC_EP_CS_ATTR_SAMPLE_RATE 0x01
|
||||
#define UAC_EP_CS_ATTR_PITCH_CONTROL 0x02
|
||||
#define UAC_EP_CS_ATTR_FILL_MAX 0x80
|
||||
|
||||
/* status word format (3.7.1.1) */
|
||||
|
||||
#define UAC1_STATUS_TYPE_ORIG_MASK 0x0f
|
||||
#define UAC1_STATUS_TYPE_ORIG_AUDIO_CONTROL_IF 0x0
|
||||
#define UAC1_STATUS_TYPE_ORIG_AUDIO_STREAM_IF 0x1
|
||||
#define UAC1_STATUS_TYPE_ORIG_AUDIO_STREAM_EP 0x2
|
||||
|
||||
#define UAC1_STATUS_TYPE_IRQ_PENDING (1 << 7)
|
||||
#define UAC1_STATUS_TYPE_MEM_CHANGED (1 << 6)
|
||||
|
||||
struct uac1_status_word {
|
||||
uint8_t bStatusType;
|
||||
uint8_t bOriginator;
|
||||
} __attribute__((packed));
|
||||
#pragma pack(pop)
|
||||
|
||||
#endif // CONFIG_USBD_AUDIO
|
||||
|
||||
#endif // __USB_AUDIO_H
|
||||
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
#ifndef __USB_AUDIO_8763_H
|
||||
#define __USB_AUDIO_8763_H
|
||||
|
||||
#include <platform_opts.h>
|
||||
|
||||
#ifdef CONFIG_USBD_AUDIO
|
||||
|
||||
#define INPUT_TERMINAL_2CH_ID 0x01
|
||||
#define INPUT_TERMINAL_MIC_ID 0x02
|
||||
#define OUTPUT_TERMINAL_SPEAKER_ID 0x06
|
||||
#define OUTPUT_TERMINAL_USB_ID 0x07
|
||||
#define SELECTOR_UNIT_ID 0x08
|
||||
#define FEATURE_UNIT_0_ID 0x09
|
||||
#define FEATURE_UNIT_1_ID 0x0A
|
||||
#define FEATURE_UNIT_2_ID 0x0D
|
||||
#define MIXER_UNIT_2_ID 0x0F
|
||||
|
||||
#define AUDIO_CONTROL_INTF_NUM 0
|
||||
#define AUDIO_STREAM_OUT_INTF_NUM 1
|
||||
#define AUDIO_STREAM_IN_INTF_NUM 2
|
||||
|
||||
// 8763 PCM setting
|
||||
#define BIT_RES_16 16
|
||||
#define BIT_RES_24 24
|
||||
#define DEFAULT_BIT_RES BIT_RES_16
|
||||
|
||||
#define ICODEC_SR_8K 0
|
||||
#define ICODEC_SR_16K 1
|
||||
#define ICODEC_SR_32K 2
|
||||
#define ICODEC_SR_44K 3
|
||||
#define ICODEC_SR_48K 4
|
||||
#define ICODEC_SR_88K 5
|
||||
#define ICODEC_SR_96K 6
|
||||
#define ICODEC_SR_192K 7
|
||||
#define DEFAULT_SR ICODEC_SR_48K
|
||||
|
||||
#define CHANNEL_MODE_1CH 0x01
|
||||
#define CHANNEL_MODE_2CH 0x02
|
||||
#define DEFAULT_PLAY_CH CHANNEL_MODE_2CH
|
||||
#define DEFAULT_RECORD_CH CHANNEL_MODE_2CH //CHANNEL_MODE_1CH
|
||||
|
||||
typedef struct USB_DSP_STATE_ {
|
||||
uint8_t usb_ad_state;
|
||||
uint8_t usb_da_state;
|
||||
} USB_DSP_STATE;
|
||||
|
||||
enum { DSP_STOP, DSP_START};
|
||||
|
||||
typedef struct USB_ISOEP_STATE_ {
|
||||
uint8_t usb_OUTEP_state;
|
||||
uint8_t usb_INEP_state;
|
||||
} USB_ISOEP_STATE;
|
||||
|
||||
enum {ISOEP_DISABLE, ISOEP_ENABLE};
|
||||
enum {IDX_DA = 1, IDX_AD = 2};
|
||||
enum {L_GAIN = 1, R_GAIN = 2};
|
||||
|
||||
#endif // CONFIG_USBD_AUDIO
|
||||
|
||||
#endif // __USB_AUDIO_8763_H
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
#ifndef __USB_AUDIO_IF_H
|
||||
#define __USB_AUDIO_IF_H
|
||||
|
||||
#include <platform_opts.h>
|
||||
|
||||
#ifdef CONFIG_USBD_AUDIO
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct {
|
||||
void (* plug)(uint8_t audio_path, uint8_t bit_res, uint8_t sf, uint8_t chann_mode);
|
||||
void (* unplug)(uint8_t audio_path);
|
||||
bool (* put_data)(uint8_t *p_data, uint16_t len);
|
||||
void (* set_gain)(uint8_t lr_chann, uint8_t gain);
|
||||
bool (* pull_data)(uint8_t *p_data, uint16_t len);
|
||||
int (* init)(void);
|
||||
void (* deinit)(void);
|
||||
} usbd_audio_usr_cb_t;
|
||||
|
||||
int usbd_audio_init(usbd_audio_usr_cb_t *cb);
|
||||
void usbd_audio_deinit(void);
|
||||
void usbd_audio_stop(void);
|
||||
|
||||
#endif // CONFIG_USBD_AUDIO
|
||||
|
||||
#endif // __USB_AUDIO_IF_H
|
||||
85
sdk/component/common/drivers/usb/device/audio/inc/usb_uac1.h
Normal file
85
sdk/component/common/drivers/usb/device/audio/inc/usb_uac1.h
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
|
||||
/*
|
||||
* u_uac1.h -- interface to USB gadget "ALSA AUDIO" utilities
|
||||
*
|
||||
* Copyright (C) 2008 Bryan Wu <cooloney@kernel.org>
|
||||
* Copyright (C) 2008 Analog Devices, Inc
|
||||
*
|
||||
* Enter bugs at http://blackfin.uclinux.org/
|
||||
*
|
||||
* Licensed under the GPL-2 or later.
|
||||
*/
|
||||
#ifndef __U_AUDIO_H
|
||||
#define __U_AUDIO_H
|
||||
|
||||
#include <platform_opts.h>
|
||||
|
||||
#ifdef CONFIG_USBD_AUDIO
|
||||
|
||||
#include "usb_composite.h"
|
||||
#include "usb_audio_if.h"
|
||||
#include "usb_audio.h"
|
||||
#include "ameba_otg.h"
|
||||
|
||||
#define UAC1_OUT_EP_MAX_PACKET_SIZE 512
|
||||
#define UAC1_REQ_COUNT 1
|
||||
|
||||
#define UAC1_AUDIO_BUF_SIZE 1024
|
||||
#define SUPPORT_ISO_MAX_PACKET_SIZE 512 // for 19k2 *2 channel*16 bit
|
||||
|
||||
#define UAC1_ISO_OUT_EP_MAX_PACKET_SIZE 576 // must be 576 for 96K + 24-bit, ??? what about P & R ???
|
||||
#define UAC1_ISO_IN_EP_MAX_PACKET_SIZE 288 // 492, Max Packet, or Play and Record Fail in Win7
|
||||
|
||||
#define UAC1_ISO_OUT_EP_MAX_BUFFER_SIZE 576 // 24 -> 32 ( 576 -> 768 )
|
||||
#define UAC1_ISO_IN_EP_MAX_BUFFER_SIZE 288 // 32 -> 24 ( 384 -> 288 )
|
||||
|
||||
/*
|
||||
* This represents the USB side of an audio card device, managed by a USB
|
||||
* function which provides control and stream interfaces.
|
||||
*/
|
||||
|
||||
struct gaudio_snd_dev {
|
||||
struct gaudio *card;
|
||||
//struct file *filp;
|
||||
//struct snd_pcm_substream *substream;
|
||||
int access;
|
||||
int format;// bbpro: 0: 16bit, 1 : 24bit
|
||||
int channels;// bbpro:
|
||||
int rate;// ex 44100
|
||||
int sample_freq_idx;// bbpro, map to rate
|
||||
};
|
||||
|
||||
struct gaudio {
|
||||
//struct usb_function func;
|
||||
struct usb_gadget *gadget;
|
||||
|
||||
/* ALSA sound device interfaces */
|
||||
struct gaudio_snd_dev control;
|
||||
struct gaudio_snd_dev playback;
|
||||
struct gaudio_snd_dev capture;
|
||||
};
|
||||
|
||||
struct f_audio {
|
||||
struct gaudio card;
|
||||
//bbpro
|
||||
uint8_t ac_intf;
|
||||
uint8_t ac_alt;
|
||||
uint8_t as_out_intf;
|
||||
uint8_t as_out_alt;
|
||||
uint8_t as_in_intf;
|
||||
uint8_t as_in_alt;
|
||||
|
||||
/* endpoints handle full and/or high speeds */
|
||||
struct usb_ep *out_ep;
|
||||
struct usb_ep *in_ep;
|
||||
|
||||
dwc_list_link_t cs;
|
||||
uint8_t set_cmd;
|
||||
struct usb_audio_control *set_con;
|
||||
//bbpro
|
||||
struct usb_gadget *gadget;
|
||||
};
|
||||
|
||||
#endif // CONFIG_USBD_AUDIO
|
||||
|
||||
#endif // __U_AUDIO_H
|
||||
|
|
@ -0,0 +1,228 @@
|
|||
#ifndef _USBD_CDC_ACM_H_
|
||||
#define _USBD_CDC_ACM_H_
|
||||
|
||||
#include <platform_opts.h>
|
||||
|
||||
#ifdef CONFIG_USBD_CDC_ACM
|
||||
|
||||
#include <platform/platform_stdlib.h>
|
||||
#include "usb.h"
|
||||
#include "usb_gadget.h"
|
||||
#include "usb_composite.h"
|
||||
#include "osdep_service.h"
|
||||
#include "usbd_cdc_acm_if.h"
|
||||
|
||||
// Use INT in endpoint
|
||||
#define USBD_CDC_ACM_USE_INT_IN_ENDPOINT 1
|
||||
|
||||
// Use thread for bulk in transfer, turn it on when using usbd_cdc_acm_async_transmit_data API to transfer large data,
|
||||
// which can not be transfered via single bulk in transfer, i.e. the transfer size is larger than bulk_in_buf_size.
|
||||
#define USBD_CDC_ACM_USE_BULK_IN_THREAD 1
|
||||
|
||||
// Allocate async bulk in buffer, turn it on to release bulk in transfer buffer in user application ASAP.
|
||||
#define USBD_CDC_ACM_ALLOC_ASYNC_BULK_IN_BUF 0
|
||||
|
||||
// Bulk in request number
|
||||
#define USBD_CDC_ACM_BULK_IN_REQ_NUM 2
|
||||
|
||||
// Bulk out request number
|
||||
#define USBD_CDC_ACM_BULK_OUT_REQ_NUM 1
|
||||
|
||||
// Bulk transfer configurations
|
||||
#define USBD_CDC_ACM_HS_BULK_MAX_PACKET_SIZE 512
|
||||
#define USBD_CDC_ACM_FS_BULK_MAX_PACKET_SIZE 64
|
||||
|
||||
#define USBD_CDC_ACM_HS_BULK_IN_PACKET_SIZE (USBD_CDC_ACM_HS_BULK_MAX_PACKET_SIZE)
|
||||
#define USBD_CDC_ACM_HS_BULK_OUT_PACKET_SIZE (USBD_CDC_ACM_HS_BULK_MAX_PACKET_SIZE)
|
||||
#define USBD_CDC_ACM_FS_BULK_IN_PACKET_SIZE (USBD_CDC_ACM_FS_BULK_MAX_PACKET_SIZE)
|
||||
#define USBD_CDC_ACM_FS_BULK_OUT_PACKET_SIZE (USBD_CDC_ACM_FS_BULK_MAX_PACKET_SIZE)
|
||||
|
||||
#define USBD_CDC_ACM_MAX_BULK_IN_XFER_SIZE 65535
|
||||
|
||||
#define USBD_CDC_ACM_DEFAULT_BULK_IN_XFER_SIZE 1024 // Shall be <= USBD_CDC_ACM_MAX_BULK_IN_XFER_SIZE, restrict it to save memory
|
||||
#define USBD_CDC_ACM_DEFAULT_BULK_OUT_XFER_SIZE 1024 // Shall be <= USBD_CDC_ACM_MAX_BULK_IN_XFER_SIZE, restrict it to save memory
|
||||
|
||||
// Bulk in task configurations
|
||||
#define USBD_CDC_ACM_BULK_IN_TASK_PRIORITY (tskIDLE_PRIORITY + 2) // Should be lower than USBD_IRQ_THREAD_PRIORITY
|
||||
#define USBD_CDC_ACM_BULK_IN_TASK_STACK_SIZE 512
|
||||
|
||||
// Endpoint address
|
||||
#define USBD_CDC_ACM_BULK_IN_EP_ADDRESS 0x81
|
||||
#define USBD_CDC_ACM_BULK_OUT_EP_ADDRESS 0x02
|
||||
#define USBD_CDC_ACM_INT_IN_EP_ADDRESS 0x83
|
||||
|
||||
// CDC descriptor types
|
||||
#define USBD_CDC_HEADER_TYPE 0x00
|
||||
#define USBD_CDC_CALL_MANAGEMENT_TYPE 0x01
|
||||
#define USBD_CDC_ACM_TYPE 0x02
|
||||
#define USBD_CDC_UNION_TYPE 0x06
|
||||
#define USBD_CDC_COUNTRY_TYPE 0x07
|
||||
#define USBD_CDC_NETWORK_TERMINAL_TYPE 0x0A
|
||||
#define USBD_CDC_ETHERNET_TYPE 0x0F
|
||||
#define USBD_CDC_WHCM_TYPE 0x11
|
||||
#define USBD_CDC_MDLM_TYPE 0x12
|
||||
#define USBD_CDC_MDLM_DETAIL_TYPE 0x13
|
||||
#define USBD_CDC_DMM_TYPE 0x14
|
||||
#define USBD_CDC_OBEX_TYPE 0x15
|
||||
|
||||
// CDC subclass
|
||||
#define USBD_CDC_SUBCLASS_ACM 0x02
|
||||
#define USBD_CDC_SUBCLASS_ETHERNET 0x06
|
||||
#define USBD_CDC_SUBCLASS_WHCM 0x08
|
||||
#define USBD_CDC_SUBCLASS_DMM 0x09
|
||||
#define USBD_CDC_SUBCLASS_MDLM 0x0A
|
||||
#define USBD_CDC_SUBCLASS_OBEX 0x0B
|
||||
|
||||
// CDC ACM protocol
|
||||
#define USBD_CDC_ACM_PROTO_NONE 0x00
|
||||
#define USBD_CDC_ACM_PROTO_AT 0x01
|
||||
#define USBD_CDC_ACM_PROTO_VENDOR 0xFF
|
||||
|
||||
// CDC ACM requests
|
||||
#define USBD_CDC_SEND_ENCAPSULATED_COMMAND 0x00U
|
||||
#define USBD_CDC_GET_ENCAPSULATED_RESPONSE 0x01U
|
||||
#define USBD_CDC_SET_COMM_FEATURE 0x02U
|
||||
#define USBD_CDC_GET_COMM_FEATURE 0x03U
|
||||
#define USBD_CDC_CLEAR_COMM_FEATURE 0x04U
|
||||
#define USBD_CDC_SET_LINE_CODING 0x20U
|
||||
#define USBD_CDC_GET_LINE_CODING 0x21U
|
||||
#define USBD_CDC_SET_CONTROL_LINE_STATE 0x22U
|
||||
#define USBD_CDC_SEND_BREAK 0x23U
|
||||
|
||||
// CDC ACM debug options
|
||||
#define USBD_CDC_ACM_DEBUG 0
|
||||
#if USBD_CDC_ACM_DEBUG
|
||||
#define USBD_CDC_INFO(fmt, args...) printf("\n\r[CDC]%s: " fmt, __FUNCTION__, ## args)
|
||||
#define USBD_CDC_WARN(fmt, args...) printf("\n\r[CDC]%s: " fmt, __FUNCTION__, ## args)
|
||||
#define USBD_CDC_ERROR(fmt, args...) printf("\n\r[CDC]%s: " fmt, __FUNCTION__, ## args)
|
||||
#define USBD_CDC_ENTER printf("\n\r[CDC]%s: =>", __FUNCTION__)
|
||||
#define USBD_CDC_EXIT printf("\n\r[CDC]%s: <=", __FUNCTION__)
|
||||
#define USBD_CDC_EXIT_ERR printf("\n\r[CDC]%s: ERR <=", __FUNCTION__)
|
||||
#else
|
||||
#define USBD_CDC_INFO(fmt, args...)
|
||||
#define USBD_CDC_WARN(fmt, args...)
|
||||
#define USBD_CDC_ERROR(fmt, args...) printf("\n\r[CDC]%s: " fmt, __FUNCTION__, ## args)
|
||||
#define USBD_CDC_ENTER
|
||||
#define USBD_CDC_EXIT
|
||||
#define USBD_CDC_EXIT_ERR
|
||||
#endif
|
||||
|
||||
#pragma pack(push)
|
||||
#pragma pack(1)
|
||||
|
||||
// Header Functional Descriptor
|
||||
struct usb_cdc_header_desc {
|
||||
u8 bLength;
|
||||
u8 bDescriptorType;
|
||||
u8 bDescriptorSubType;
|
||||
|
||||
u16 bcdCDC;
|
||||
} __attribute__((packed));
|
||||
|
||||
#define USBD_CDC_DT_HEADER_SIZE 5
|
||||
|
||||
// Call Management Descriptor
|
||||
struct usb_cdc_call_mgmt_descriptor {
|
||||
u8 bLength;
|
||||
u8 bDescriptorType;
|
||||
u8 bDescriptorSubType;
|
||||
|
||||
u8 bmCapabilities;
|
||||
#define USB_CDC_CALL_MGMT_CAP_CALL_MGMT 0x01
|
||||
#define USB_CDC_CALL_MGMT_CAP_DATA_INTF 0x02
|
||||
|
||||
u8 bDataInterface;
|
||||
} __attribute__((packed));
|
||||
|
||||
#define USBD_CDC_DT_CALL_MGMT_SIZE 5
|
||||
|
||||
// Abstract Control Management Descriptor
|
||||
struct usb_cdc_acm_descriptor {
|
||||
u8 bLength;
|
||||
u8 bDescriptorType;
|
||||
u8 bDescriptorSubType;
|
||||
|
||||
u8 bmCapabilities;
|
||||
} __attribute__((packed));
|
||||
|
||||
#define USBD_CDC_DT_ACM_SIZE 4
|
||||
|
||||
// Union Functional Descriptor
|
||||
struct usb_cdc_union_desc {
|
||||
u8 bLength;
|
||||
u8 bDescriptorType;
|
||||
u8 bDescriptorSubType;
|
||||
|
||||
u8 bControlInterface;
|
||||
u8 bSubordinateInterface0;
|
||||
} __attribute__((packed));
|
||||
|
||||
#define USBD_CDC_DT_UNION_SIZE 5
|
||||
|
||||
typedef struct {
|
||||
u32 dwDTERate;
|
||||
u8 bCharFormat;
|
||||
u8 bParityType;
|
||||
u8 bDataBits;
|
||||
} __attribute__((packed)) usbd_cdc_acm_line_coding_t;
|
||||
|
||||
#define USBD_CDC_ACM_LINE_CODING_SIZE 7
|
||||
|
||||
#define USBD_CDC_ACM_CHAR_FORMAT_STOP_1 0
|
||||
#define USBD_CDC_ACM_CHAR_FORMAT_STOP_1_5 1
|
||||
#define USBD_CDC_ACM_CHAR_FORMAT_STOP_2 2
|
||||
|
||||
#define USBD_CDC_ACM_PARITY_TYPE_NONE 0
|
||||
#define USBD_CDC_ACM_PARITY_TYPE_ODD 1
|
||||
#define USBD_CDC_ACM_PARITY_TYPE_EVEN 2
|
||||
#define USBD_CDC_ACM_PARITY_TYPE_MARK 3
|
||||
#define USBD_CDC_ACM_PARITY_TYPE_SPACE 4
|
||||
|
||||
#define USBD_CDC_ACM_DATA_BIT_5 5
|
||||
#define USBD_CDC_ACM_DATA_BIT_6 6
|
||||
#define USBD_CDC_ACM_DATA_BIT_7 7
|
||||
#define USBD_CDC_ACM_DATA_BIT_8 8
|
||||
#define USBD_CDC_ACM_DATA_BIT_16 16
|
||||
|
||||
typedef union {
|
||||
u16 d16;
|
||||
struct {
|
||||
unsigned present:1;
|
||||
unsigned activate:1;
|
||||
unsigned reserved_2_15:14;
|
||||
} b;
|
||||
} __attribute__((packed)) usbd_cdc_acm_ctrl_line_state_t;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
struct usb_cdc_dev_t {
|
||||
u8 interface_number;
|
||||
|
||||
struct usb_gadget *gadget;
|
||||
|
||||
struct usb_ep *bulk_out_ep;
|
||||
_list bulk_out_req_list;
|
||||
u16 bulk_out_req_num;
|
||||
volatile u16 bulk_out_req_act_num;
|
||||
u16 bulk_out_buf_size;
|
||||
_mutex bulk_out_mutex;
|
||||
|
||||
struct usb_ep *bulk_in_ep;
|
||||
_list bulk_in_req_list;
|
||||
u16 bulk_in_req_num;
|
||||
volatile u16 bulk_in_req_act_num;
|
||||
u16 bulk_in_buf_size;
|
||||
_mutex bulk_in_mutex;
|
||||
volatile int bulk_in_busy;
|
||||
|
||||
#if USBD_CDC_ACM_USE_BULK_IN_THREAD
|
||||
struct task_struct bulk_in_task;
|
||||
#endif
|
||||
|
||||
usbd_cdc_acm_usr_cb_t *cb;
|
||||
};
|
||||
|
||||
#endif // CONFIG_USBD_CDC_ACM
|
||||
|
||||
#endif // _USBD_CDC_ACM_H_
|
||||
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
#ifndef _USBD_CDC_ACM_IF_H_
|
||||
#define _USBD_CDC_ACM_IF_H_
|
||||
|
||||
#include <platform_opts.h>
|
||||
|
||||
#ifdef CONFIG_USBD_CDC_ACM
|
||||
|
||||
typedef struct {
|
||||
int(* init)(void);
|
||||
int(* deinit)(void);
|
||||
int(* receive)(void *buf, u16 length);
|
||||
void(*transmit_complete)(int status);
|
||||
} usbd_cdc_acm_usr_cb_t;
|
||||
|
||||
int usbd_cdc_acm_sync_transmit_data(void *buf, u16 length);
|
||||
int usbd_cdc_acm_async_transmit_data(void *buf, u32 length);
|
||||
|
||||
int usbd_cdc_acm_init(u16 bulk_in_buf_size, u16 bulk_out_buf_size, usbd_cdc_acm_usr_cb_t *cb);
|
||||
void usbd_cdc_acm_deinit(void);
|
||||
|
||||
#endif // CONFIG_USBD_CDC_ACM
|
||||
|
||||
#endif // _USBD_CDC_ACM_IF_H_
|
||||
|
||||
208
sdk/component/common/drivers/usb/device/msc/inc/usbd_msc.h
Normal file
208
sdk/component/common/drivers/usb/device/msc/inc/usbd_msc.h
Normal file
|
|
@ -0,0 +1,208 @@
|
|||
#ifndef USBD_MSC_H
|
||||
#define USBD_MSC_H
|
||||
|
||||
#include <platform_opts.h>
|
||||
|
||||
#ifdef CONFIG_USBD_MSC
|
||||
|
||||
#include <platform/platform_stdlib.h>
|
||||
#include "usb.h"
|
||||
#include "usb_composite.h"
|
||||
#include "osdep_service.h"
|
||||
#include "sd.h"
|
||||
|
||||
/* MSC configurations */
|
||||
#define USBD_MSC_RAM_DISK 0 /* Use RAM as storage media, for test purpose only */
|
||||
|
||||
/* MSC Request Codes */
|
||||
#define USBD_MSC_REQUEST_RESET 0xFF
|
||||
#define USBD_MSC_REQUEST_GET_MAX_LUN 0xFE
|
||||
|
||||
#define USBD_MSC_MAX_LUN 1
|
||||
#define USBD_MSC_MAX_SCSI_CMD_SIZE 16
|
||||
#define USBD_MSC_BLK_BITS 9
|
||||
#define USBD_MSC_BLK_SIZE (1 << USBD_MSC_BLK_BITS)
|
||||
|
||||
/* MSC Sub Classes */
|
||||
#define USBD_MSC_SC_RBC 1 /* Typically, flash devices */
|
||||
#define USBD_MSC_SC_8020 2 /* CD-ROM */
|
||||
#define USBD_MSC_SC_QIC 3 /* QIC-157 Tapes */
|
||||
#define USBD_MSC_SC_UFI 4 /* Floppy */
|
||||
#define USBD_MSC_SC_8070 5 /* Removable media */
|
||||
#define USBD_MSC_SC_SCSI 6 /* Transparent */
|
||||
|
||||
/* MSC Protocols */
|
||||
#define USBD_MSC_PR_CB 1 /* Control/Bulk w/o interrupt */
|
||||
#define USBD_MSC_PR_CBI 0 /* Control/Bulk/Interrupt */
|
||||
#define USBD_MSC_PR_BULK 0x50 /* bulk only */
|
||||
|
||||
#define USBD_MSC_BULK_OUT_EP_ADDRESS 0x02
|
||||
#define USBD_MSC_BULK_IN_EP_ADDRESS 0x81
|
||||
|
||||
/* MSC thread priority*/
|
||||
#define USBD_MSC_BULK_CMD_THREAD_PRIORITY (tskIDLE_PRIORITY + 3) // Should be lower than USBD_IRQ_THREAD_PRIORITY
|
||||
|
||||
/* MSC device buffer configuration */
|
||||
#define USBD_MSC_NBR_BUFHD 2 /* Number of buffer header for bulk in/out data */
|
||||
#define USBD_MSC_BUFLEN (32*512) /* Default size of buffer length */
|
||||
|
||||
/* MSC tasks stack size */
|
||||
#define USBD_MSC_BULK_CMD_TASK_STACK_SIZE 512
|
||||
#define USBD_MSC_BULK_DATA_TASK_STACK_SIZE 512
|
||||
|
||||
#define USBD_MSC_HALT_ERROR_TOLERANCE 20
|
||||
|
||||
/* RAM disk configurations */
|
||||
#if USBD_MSC_RAM_DISK
|
||||
#define USBD_MSC_RAM_DISK_SIZE (USBD_MSC_BUFLEN * 2) // Should be >= 32KB
|
||||
#define USBD_MSC_RAM_DISK_SECTORS (USBD_MSC_RAM_DISK_SIZE >> USBD_MSC_BLK_BITS)
|
||||
#endif
|
||||
|
||||
/* Debug options */
|
||||
#define USBD_MSC_DEBUG 0
|
||||
#if USBD_MSC_DEBUG
|
||||
#define USBD_MSC_INFO(fmt, args...) printf("\n\r[MSC]%s: " fmt, __FUNCTION__, ## args)
|
||||
#define USBD_MSC_WARN(fmt, args...) printf("\n\r[MSC]%s: " fmt, __FUNCTION__, ## args)
|
||||
#define USBD_MSC_ERROR(fmt, args...) printf("\n\r[MSC]%s: " fmt, __FUNCTION__, ## args)
|
||||
#define USBD_MSC_ENTER printf("\n\r[MSC]%s: =>", __FUNCTION__)
|
||||
#define USBD_MSC_EXIT printf("\n\r[MSC]%s: <=", __FUNCTION__)
|
||||
#define USBD_MSC_EXIT_ERR printf("\n\r[MSC]%s: ERR <=", __FUNCTION__)
|
||||
#else
|
||||
#define USBD_MSC_INFO(fmt, args...)
|
||||
#define USBD_MSC_WARN(fmt, args...)
|
||||
#define USBD_MSC_ERROR(fmt, args...)
|
||||
#define USBD_MSC_ENTER
|
||||
#define USBD_MSC_EXIT
|
||||
#define USBD_MSC_EXIT_ERR
|
||||
#endif
|
||||
|
||||
enum data_direction {
|
||||
DATA_DIR_UNKNOWN = 0,
|
||||
DATA_DIR_FROM_HOST,
|
||||
DATA_DIR_TO_HOST,
|
||||
DATA_DIR_NONE
|
||||
};
|
||||
|
||||
//structure predefine
|
||||
struct usb_msc_dev_t;
|
||||
struct usb_msc_bufhd_t;
|
||||
|
||||
struct usb_msc_opts_t {
|
||||
SD_RESULT(*disk_init)(void);
|
||||
SD_RESULT(*disk_deinit)(void);
|
||||
SD_RESULT(*disk_getcapacity)(u32 *sectors);
|
||||
SD_RESULT(*disk_read)(u32 sector, u8 *buffer, u32 count);
|
||||
SD_RESULT(*disk_write)(u32 sector, const u8 *buffer, u32 count);
|
||||
};
|
||||
|
||||
struct usb_msc_lun_t {
|
||||
unsigned int initially_ro: 1;
|
||||
unsigned int ro: 1;
|
||||
unsigned int removable: 1;
|
||||
unsigned int cdrom: 1;
|
||||
unsigned int prevent_medium_removal: 1;
|
||||
unsigned int registered: 1;
|
||||
unsigned int info_valid: 1;
|
||||
unsigned int nofua: 1;
|
||||
|
||||
u32 sense_data;
|
||||
u32 sense_data_info;
|
||||
u32 unit_attention_data;
|
||||
|
||||
unsigned int num_sectors;
|
||||
unsigned int blkbits; /* bits of logical block size of bound block device */
|
||||
unsigned int blksize; /* logical block size of bound block device */
|
||||
const char *name;
|
||||
|
||||
unsigned int lba; /* current read and write logical block address */
|
||||
u8 is_open;
|
||||
_mutex lun_mutex;
|
||||
|
||||
struct usb_msc_opts_t *lun_opts;
|
||||
};
|
||||
|
||||
|
||||
struct usb_msc_common_t {
|
||||
struct usb_msc_dev_t *mscdev;
|
||||
|
||||
struct usb_msc_lun_t **luns;
|
||||
struct usb_msc_lun_t *curlun;
|
||||
|
||||
struct usb_gadget *gadget;
|
||||
|
||||
/* scsi cbw relevant */
|
||||
enum data_direction data_dir;
|
||||
u32 data_size;
|
||||
u32 data_size_from_cmnd;
|
||||
u32 tag;
|
||||
u32 residue;
|
||||
u8 scsi_cmnd[USBD_MSC_MAX_SCSI_CMD_SIZE];
|
||||
u8 cmnd_size;
|
||||
|
||||
u8 lun; /* current lun*/
|
||||
u8 nluns;
|
||||
|
||||
u8 nbufhd; /* number of buffer header */
|
||||
u8 nbufhd_a;
|
||||
_list bufhd_pool;
|
||||
_mutex bufhd_mutex;
|
||||
|
||||
/* bulk out cmd*/
|
||||
_list boc_list;
|
||||
_mutex boc_mutex;
|
||||
|
||||
/* bolk out data*/
|
||||
_mutex bod_mutex;
|
||||
_list bod_list;
|
||||
|
||||
struct usb_msc_bufhd_t *curbh; // current buffer header
|
||||
struct usb_msc_bufhd_t *cbw_bh; // buffer header for CBW
|
||||
struct usb_msc_bufhd_t *csw_bh; // buffer header for CSW
|
||||
|
||||
unsigned int can_stall: 1;
|
||||
unsigned int phase_error: 1;
|
||||
unsigned int short_packet_received: 1;
|
||||
unsigned int bad_lun_okay: 1;
|
||||
unsigned int running: 1;
|
||||
};
|
||||
|
||||
typedef enum _bufhd_type {
|
||||
BUFHD_CBW = 0,
|
||||
BUFHD_CSW,
|
||||
BUFHD_DATA,
|
||||
} usb_msc_bufhd_type;
|
||||
|
||||
struct usb_msc_bufhd_t {
|
||||
u8 *prebuf;
|
||||
u8 *buf;
|
||||
int buf_size;
|
||||
usb_msc_bufhd_type type;
|
||||
_list list;
|
||||
struct usb_request *reqin; /* for bulkin responses */
|
||||
struct usb_request *reqout;
|
||||
};
|
||||
|
||||
struct usb_msc_dev_t {
|
||||
struct usb_msc_common_t *common;
|
||||
|
||||
u16 interface_number;
|
||||
|
||||
struct usb_ep *in_ep;
|
||||
struct usb_ep *out_ep;
|
||||
unsigned int bulk_in_enabled: 1;
|
||||
unsigned int bulk_out_enabled: 1;
|
||||
|
||||
struct task_struct bulk_out_cmd_task;
|
||||
};
|
||||
|
||||
int usbd_msc_lun_read(struct usb_msc_lun_t *curlun, u32 sector, u8 *buffer, u32 count);
|
||||
int usbd_msc_lun_write(struct usb_msc_lun_t *curlun, u32 sector, const u8 *buffer, u32 count);
|
||||
int usbd_msc_halt_bulk_in_endpoint(struct usb_msc_dev_t *mscdev);
|
||||
void usbd_msc_put_bufhd(struct usb_msc_common_t *common, struct usb_msc_bufhd_t *bufhd);
|
||||
struct usb_msc_bufhd_t *usbd_msc_get_bufhd(struct usb_msc_common_t *common);
|
||||
int usbd_msc_bulk_in_transfer(struct usb_msc_dev_t *mscdev, struct usb_request *req);
|
||||
int usbd_msc_bulk_out_transfer(struct usb_msc_dev_t *mscdev, struct usb_request *req);
|
||||
|
||||
#endif // CONFIG_USBD_MSC
|
||||
|
||||
#endif // USBD_MSC_H
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef USBD_MSC_IF_H
|
||||
#define USBD_MSC_IF_H
|
||||
|
||||
#include <platform_opts.h>
|
||||
|
||||
#ifdef CONFIG_USBD_MSC
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
//int usbd_msc_register(void);
|
||||
int usbd_msc_init(void);
|
||||
void usbd_msc_deinit(void);
|
||||
|
||||
#endif // CONFIG_USBD_MSC
|
||||
|
||||
#endif // USBD_MSC_H
|
||||
110
sdk/component/common/drivers/usb/device/msc/inc/usbd_scsi.h
Normal file
110
sdk/component/common/drivers/usb/device/msc/inc/usbd_scsi.h
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
#ifndef USBD_SCSI_H
|
||||
#define USBD_SCSI_H
|
||||
|
||||
#include <platform_opts.h>
|
||||
|
||||
#ifdef CONFIG_USBD_MSC
|
||||
|
||||
#include "basic_types.h"
|
||||
#include "usbd_msc.h"
|
||||
|
||||
/* SCSI Commands */
|
||||
#define SCSI_FORMAT_UNIT 0x04
|
||||
#define SCSI_INQUIRY 0x12
|
||||
#define SCSI_MODE_SELECT6 0x15
|
||||
#define SCSI_MODE_SELECT10 0x55
|
||||
#define SCSI_MODE_SENSE6 0x1A
|
||||
#define SCSI_MODE_SENSE10 0x5A
|
||||
#define SCSI_ALLOW_MEDIUM_REMOVAL 0x1E
|
||||
#define SCSI_READ6 0x08
|
||||
#define SCSI_READ10 0x28
|
||||
#define SCSI_READ12 0xA8
|
||||
#define SCSI_READ16 0x88
|
||||
|
||||
#define SCSI_READ_CAPACITY10 0x25
|
||||
#define SCSI_READ_CAPACITY16 0x9E
|
||||
|
||||
#define SCSI_SYNCHRONIZE_CACHE 0x35
|
||||
#define SCSI_REQUEST_SENSE 0x03
|
||||
#define SCSI_START_STOP_UNIT 0x1B
|
||||
#define SCSI_TEST_UNIT_READY 0x00
|
||||
#define SCSI_WRITE6 0x0A
|
||||
#define SCSI_WRITE10 0x2A
|
||||
#define SCSI_WRITE12 0xAA
|
||||
#define SCSI_WRITE16 0x8A
|
||||
|
||||
#define SCSI_VERIFY10 0x2F
|
||||
#define SCSI_VERIFY12 0xAF
|
||||
#define SCSI_VERIFY16 0x8F
|
||||
|
||||
#define SCSI_SEND_DIAGNOSTIC 0x1D
|
||||
#define SCSI_READ_FORMAT_CAPACITIES 0x23
|
||||
|
||||
#define READ_FORMAT_CAPACITY_DATA_LEN 0x0C
|
||||
#define READ_CAPACITY10_DATA_LEN 0x08
|
||||
#define MODE_SENSE10_DATA_LEN 0x08
|
||||
#define MODE_SENSE6_DATA_LEN 0x04
|
||||
#define REQUEST_SENSE_DATA_LEN 0x12
|
||||
#define STANDARD_INQUIRY_DATA_LEN 0x24
|
||||
|
||||
/* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */
|
||||
#define SS_NO_SENSE 0
|
||||
#define SS_COMMUNICATION_FAILURE 0x040800
|
||||
#define SS_INVALID_COMMAND 0x052000
|
||||
#define SS_INVALID_FIELD_IN_CDB 0x052400
|
||||
#define SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x052100
|
||||
#define SS_LOGICAL_UNIT_NOT_SUPPORTED 0x052500
|
||||
#define SS_MEDIUM_NOT_PRESENT 0x023a00
|
||||
#define SS_MEDIUM_REMOVAL_PREVENTED 0x055302
|
||||
#define SS_NOT_READY_TO_READY_TRANSITION 0x062800
|
||||
#define SS_RESET_OCCURRED 0x062900
|
||||
#define SS_SAVING_PARAMETERS_NOT_SUPPORTED 0x053900
|
||||
#define SS_UNRECOVERED_READ_ERROR 0x031100
|
||||
#define SS_WRITE_ERROR 0x030c02
|
||||
#define SS_WRITE_PROTECTED 0x072700
|
||||
|
||||
#define SK(x) ((u8) ((x) >> 16)) /* Sense Key byte, etc. */
|
||||
#define ASC(x) ((u8) ((x) >> 8))
|
||||
#define ASCQ(x) ((u8) (x))
|
||||
|
||||
/*
|
||||
* Bulk only data structures
|
||||
*/
|
||||
|
||||
/* command block wrapper */
|
||||
struct bulk_cb_wrap {
|
||||
unsigned int Signature; /* contains 'USBC', denote bulk_cb_wrap */
|
||||
unsigned int Tag; /* unique per command id */
|
||||
unsigned int DataTransferLength; /* size of data for transfer */
|
||||
unsigned char Flags; /* data transfer direction */
|
||||
unsigned char Lun; /* LUN normally 0, (which command block is sent) */
|
||||
unsigned char Length; /* length of the CDB */
|
||||
unsigned char CDB[USBD_MSC_MAX_SCSI_CMD_SIZE]; /* max command */
|
||||
};
|
||||
|
||||
#define US_BULK_CB_WRAP_LEN 31
|
||||
#define US_BULK_CB_SIGN 0x43425355 /*spells out USBC */
|
||||
#define US_BULK_FLAG_IN (1 << 7)
|
||||
#define US_BULK_FLAG_OUT 0
|
||||
|
||||
/* command status wrapper */
|
||||
struct bulk_cs_wrap {
|
||||
unsigned int Signature; /* should = 'USBS' */
|
||||
unsigned int Tag; /* same as original command, echoed by the device as received */
|
||||
unsigned int Residue; /* amount not transferred */
|
||||
unsigned char Status; /* execute command status */
|
||||
};
|
||||
|
||||
#define US_BULK_CS_WRAP_LEN 13
|
||||
#define US_BULK_CS_SIGN 0x53425355 /* spells out 'USBS' */
|
||||
|
||||
// execute command status
|
||||
#define US_BULK_STAT_OK 0
|
||||
#define US_BULK_STAT_FAIL 1
|
||||
#define US_BULK_STAT_PHASE 2
|
||||
|
||||
int usbd_msc_receive_cbw(struct usb_msc_dev_t *mscdev, struct usb_request *req);
|
||||
|
||||
#endif // CONFIG_USBD_MSC
|
||||
|
||||
#endif // USBD_SCSI_H
|
||||
91
sdk/component/common/drivers/usb/device/vendor/inc/usbd_vendor.h
vendored
Normal file
91
sdk/component/common/drivers/usb/device/vendor/inc/usbd_vendor.h
vendored
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
#ifndef USBD_VENDOR_H
|
||||
#define USBD_VENDOR_H
|
||||
|
||||
#include <platform_opts.h>
|
||||
#ifdef CONFIG_USBD_VENDOR
|
||||
|
||||
#include "usb.h"
|
||||
#include "usb_composite.h"
|
||||
|
||||
// Test options
|
||||
#define CONFIG_USBD_VENDOR_ISO_IN_TEST 1
|
||||
#define CONFIG_USBD_VENDOR_ISO_OUT_TEST 1
|
||||
#define CONFIG_USBD_VENDOR_ISO_INOUT_TEST 0
|
||||
#define CONFIG_USBD_VENDOR_BULK_INOUT_TEST 0
|
||||
#define CONFIG_USBD_VENDOR_ISO_IN_REQ_ASAP 1
|
||||
#define CONFIG_USBD_VENDOR_ISO_OUT_REQ_ASAP 0
|
||||
#define CONFIG_USBD_VENDOR_ISO_DBG_TIMER 1
|
||||
#define CONFIG_USBD_VENDOR_ISO_DBG_GPIO 0
|
||||
|
||||
#define USBD_VENDOR_ISO_REQ_NUM 2
|
||||
#define USBD_VENDOR_ISO_OUT_XFER_CNT 100
|
||||
#define USBD_VENDOR_ISO_IN_CNT 512
|
||||
|
||||
/* Debug options */
|
||||
#define USBD_VENDOR_DEBUG 0
|
||||
#define USBD_VENDOR_STR "VS"
|
||||
#if USBD_VENDOR_DEBUG
|
||||
#define USBD_VENDOR_INFO(fmt, args...) printf("\n\r[%s]%s: " fmt, USBD_VENDOR_STR, __FUNCTION__, ## args)
|
||||
#define USBD_VENDOR_WARN(fmt, args...) printf("\n\r[%s]%s: " fmt, USBD_VENDOR_STR, __FUNCTION__, ## args)
|
||||
#define USBD_VENDOR_ERROR(fmt, args...) printf("\n\r[%s]%s: " fmt, USBD_VENDOR_STR, __FUNCTION__, ## args)
|
||||
#define USBD_VENDOR_ENTER printf("\n\r[%s]%s: =>", USBD_VENDOR_STR, __FUNCTION__)
|
||||
#define USBD_VENDOR_EXIT printf("\n\r[%s]%s: <=", USBD_VENDOR_STR, __FUNCTION__)
|
||||
#define USBD_VENDOR_EXIT_ERR printf("\n\r[%s]%s: ERR <=", USBD_VENDOR_STR, __FUNCTION__)
|
||||
#else
|
||||
#define USBD_VENDOR_INFO(fmt, args...)
|
||||
#define USBD_VENDOR_WARN(fmt, args...)
|
||||
#define USBD_VENDOR_ERROR(fmt, args...) printf("\n\r[%s]%s: " fmt, USBD_VENDOR_STR, __FUNCTION__, ## args)
|
||||
#define USBD_VENDOR_ENTER
|
||||
#define USBD_VENDOR_EXIT
|
||||
#define USBD_VENDOR_EXIT_ERR
|
||||
#endif
|
||||
|
||||
struct usb_vendor_common_t;
|
||||
struct usb_vendor_device_t;
|
||||
|
||||
struct usb_vendor_common_t {
|
||||
struct usb_vendor_device_t *vendev;
|
||||
struct usb_gadget *gadget;
|
||||
struct usb_ep *ep0;
|
||||
struct usb_request *req0;
|
||||
};
|
||||
|
||||
struct usb_vendor_device_t {
|
||||
struct usb_vendor_common_t *common;
|
||||
struct usb_function func;
|
||||
struct usb_ep *bulk_in_ep;
|
||||
struct usb_ep *bulk_out_ep;
|
||||
struct usb_ep *iso_in_ep;
|
||||
struct usb_ep *iso_out_ep;
|
||||
|
||||
struct usb_iso_request *iso_out_req;
|
||||
u8 *iso_out_req_buf[USBD_VENDOR_ISO_REQ_NUM];
|
||||
|
||||
struct usb_iso_request *iso_in_req;
|
||||
u8 *iso_in_req_buf[USBD_VENDOR_ISO_REQ_NUM];
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
u8 pos;
|
||||
u8 data;
|
||||
} usb_vendor_iso_out_record_t;
|
||||
|
||||
extern struct usb_gadget_strings *vendor_gadget_strings[];
|
||||
extern struct usb_device_descriptor vendor_device_desc;
|
||||
extern struct usb_config_descriptor vendor_config_desc;
|
||||
extern struct usb_interface_descriptor vendor_intf0_desc;
|
||||
extern struct usb_interface_descriptor vendor_intf1_desc;
|
||||
extern struct usb_endpoint_descriptor vendor_bulk_source_desc_FS;
|
||||
extern struct usb_endpoint_descriptor vendor_bulk_sink_desc_FS;
|
||||
extern struct usb_endpoint_descriptor vendor_bulk_source_desc_HS;
|
||||
extern struct usb_endpoint_descriptor vendor_bulk_sink_desc_HS;
|
||||
extern struct usb_endpoint_descriptor vendor_iso_source_desc_FS;
|
||||
extern struct usb_endpoint_descriptor vendor_iso_sink_desc_FS;
|
||||
extern struct usb_endpoint_descriptor vendor_iso_source_desc_HS;
|
||||
extern struct usb_endpoint_descriptor vendor_iso_sink_desc_HS;
|
||||
extern struct usb_descriptor_header *vendor_descriptors_FS[];
|
||||
extern struct usb_descriptor_header *vendor_descriptors_HS[];
|
||||
|
||||
#endif // CONFIG_USBD_VENDOR
|
||||
|
||||
#endif // USBD_VENDOR_H
|
||||
14
sdk/component/common/drivers/usb/device/vendor/inc/usbd_vendor_if.h
vendored
Normal file
14
sdk/component/common/drivers/usb/device/vendor/inc/usbd_vendor_if.h
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef USBD_VENDOR_IF_H
|
||||
#define USBD_VENDOR_IF_H
|
||||
|
||||
#include <platform_opts.h>
|
||||
#ifdef CONFIG_USBD_VENDOR
|
||||
|
||||
#include "usb.h"
|
||||
|
||||
int usbd_vendor_init(void);
|
||||
void usbd_vendor_deinit(void);
|
||||
|
||||
#endif // CONFIG_USBD_VENDOR
|
||||
|
||||
#endif // USBD_VENDOR_IF_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue