Skip to content

Commit d10724f

Browse files
authored
Add files via upload
1 parent 0045856 commit d10724f

File tree

4 files changed

+173
-0
lines changed

4 files changed

+173
-0
lines changed

Inc/usb_audio.h

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// usb_audio.h
2+
// Copyright (c) 2017 Sugioka Y.
3+
// This file is released under the MIT License.
4+
// http://opensource.org/licenses/mit-license.php
5+
6+
#ifndef __USB_AUDIO_H
7+
#define __USB_AUDIO_H
8+
9+
//All configurations are declared in usb_audio_dscr.h
10+
11+
typedef void (*USBAudio_CallbackFunc)(void);
12+
13+
void USBAudio_Init(PCD_HandleTypeDef *hpcd);
14+
void USBAudio_DeInit(void);
15+
void USBAudio_RegisterCallback(USBAudio_CallbackFunc startPlayback,
16+
USBAudio_CallbackFunc stopPlayback,
17+
USBAudio_CallbackFunc freqChanged);
18+
void USBAudio_Start(void);
19+
void USBAudio_Stop(void);
20+
//return: Sampling frequency e.g) 44100, 48000
21+
uint32_t USBAudio_AudioFreq(void);
22+
//return: Ready to play or not
23+
uint8_t USBAudio_Enough(void);
24+
//Get audio packet and increment buffer read addr
25+
//return: Pointer to audio packet buffer or NULL(buffer is not ready)
26+
uint8_t* USBAudio_GetPacketBuffer(uint16_t *length);
27+
28+
//should be called from HAL_PCD_xxCallback function. don't call other anywhere
29+
void USBAudio_SetupStageCallback(PCD_HandleTypeDef *hpcd);
30+
void USBAudio_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
31+
void USBAudio_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
32+
void USBAudio_SOFCallback(PCD_HandleTypeDef *hpcd);
33+
void USBAudio_ResetCallback(PCD_HandleTypeDef *hpcd);
34+
void USBAudio_SuspendCallback(PCD_HandleTypeDef *hpcd);
35+
void USBAudio_ResumeCallback(PCD_HandleTypeDef *hpcd);
36+
void USBAudio_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
37+
void USBAudio_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
38+
void USBAudio_ConnectCallback(PCD_HandleTypeDef *hpcd);
39+
void USBAudio_DisconnectCallback(PCD_HandleTypeDef *hpcd);
40+
41+
#endif

Inc/usb_audio_dscr.h

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// usb_audio_dscr.h
2+
// Copyright (c) 2017 Sugioka Y.
3+
// This file is released under the MIT License.
4+
// http://opensource.org/licenses/mit-license.php
5+
6+
#include "stm32f1xx_hal.h"
7+
8+
#ifndef __USB_AUDIO_DSCR_H
9+
#define __USB_AUDIO_DSCR_H
10+
11+
#define USB_VID 1155 //STMicroelectronics
12+
//#define USB_PID 22336 //Test device
13+
#define USB_PID 22337
14+
15+
//Attributes
16+
#define SELF_POWERED 0
17+
#define REMOTE_WAKEUP 0
18+
19+
//STM32F103 has 512 bytes PMA
20+
#define PMA_SIZE 512
21+
22+
//Control packet size
23+
#define EP0_PACKET_SIZE 8
24+
//Audio packet size
25+
#define AUDIO_PACKET_SIZE 200 //(48+1)*2*2=196
26+
//Feedback packet size, must be 3
27+
#define FEEDBACK_PACKET_SIZE 3
28+
29+
//Audio packet buffering length
30+
#define AUDIO_BUFFER_LEN 16
31+
//
32+
#define FEEDBACK_RATE 5 //1-9, 2^5=32[ms]
33+
34+
//---------------------------------
35+
36+
#define USBAUDIO_MANUFACTURER_STRING_DSCR_LEN 38
37+
#define USBAUDIO_PRODUCT_STRING_DSCR_LEN 36
38+
39+
#define USBAUDIO_DEVICE_DSCR_LEN 18
40+
#define USBAUDIO_CONFIGURATION_DSCR_LEN 112
41+
42+
#define USBAUDIO_MANUFACTURER_STRING_DSCR_ID 1
43+
#define USBAUDIO_PRODUCT_STRING_DSCR_ID 2
44+
45+
extern uint8_t USBAudio_Manufacturer_StringDscr[];
46+
extern uint8_t USBAudio_Product_StringDscr[];
47+
extern uint8_t USBAudio_DeviceDscr[];
48+
//extern uint8_t USBAudio_DeviceQualifierDscr[];
49+
extern uint8_t USBAudio_ConfigurationDscr[];
50+
51+
#endif

Inc/usb_def.h

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// usb_def.h
2+
// Copyright (c) 2017 Sugioka Y.
3+
// This file is released under the MIT License.
4+
// http://opensource.org/licenses/mit-license.php
5+
6+
#ifndef __USB_DEF_H
7+
#define __USB_DEF_H
8+
9+
#ifndef NULL
10+
#define NULL 0
11+
#endif
12+
13+
#ifndef LOBYTE
14+
#define LOBYTE(x) (x & 0xFF)
15+
#endif
16+
17+
#ifndef HIBYTE
18+
#define HIBYTE(x) ((x >> 8) & 0xFF)
19+
#endif
20+
21+
#ifndef MIN
22+
#define MIN(x,y) (x <= y ? x : y)
23+
#endif
24+
25+
#define DEVICE_DSCR 0x01
26+
#define CONFIGURATION_DSCR 0x02
27+
#define STRING_DSCR 0x03
28+
#define INTERFACE_DSCR 0x04
29+
#define ENDPOINT_DSCR 0x05
30+
#define DEVICE_QUALIFIER_DSCR 0x06
31+
#define OTHER_SPEED_CONFIGURATION_DSCR 0x07
32+
33+
#define EP_TYPE_CONTROL 0
34+
#define EP_TYPE_ISOCHRONOUS 1
35+
#define EP_TYPE_BULK 2
36+
#define EP_TYPE_INTERRUPT 3
37+
38+
#define USB_REQ_TYPE_STANDARD (0<<5)
39+
#define USB_REQ_TYPE_CLASS (1<<5)
40+
#define USB_REQ_TYPE_VENDOR (2<<5)
41+
#define USB_REQ_TYPE_DEVICE 0
42+
#define USB_REQ_TYPE_INTERFACE 1
43+
#define USB_REQ_TYPE_ENDPOINT 2
44+
#define USB_REQ_STD_SET_ADDRESS 0x05
45+
#define USB_REQ_STD_GET_DESCRIPTOR 0x06
46+
#define USB_REQ_STD_SET_DESCRIPTOR 0x07
47+
#define USB_REQ_STD_CLEAR_FEATURE 0x01
48+
#define USB_REQ_STD_SET_FEATURE 0x03
49+
#define USB_REQ_STD_GET_CONFIGURATION 0x08
50+
#define USB_REQ_STD_SET_CONFIGURATION 0x09
51+
#define USB_REQ_STD_GET_INTERFACE 0x0A
52+
#define USB_REQ_STD_SET_INTERFACE 0x0B
53+
#define USB_REQ_STD_GET_STATUS 0x00
54+
#define USB_REQ_STD_SYNCH_FRAME 0x0C
55+
56+
#define USB_REQ_STD_GD_DEVICE 0x01
57+
#define USB_REQ_STD_GD_CONFIGURATION 0x02
58+
#define USB_REQ_STD_GD_STRING 0x03
59+
#define USB_REQ_STD_GD_DEVICE_QUALIFIER 0x06
60+
#define USB_REQ_STD_GD_OTHER_SPEED_CONFIGURATION 0x07
61+
62+
#define USB_REQ_STD_FT_REMOTEWAKEUP 0x02
63+
64+
//Class request
65+
#define USB_REQ_CLASS_SET_CUR 0x01
66+
#define USB_REQ_CLASS_GET_CUR 0x81
67+
68+
#endif

Inc/usb_pcd.h

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// usb_pcd.h
2+
// Copyright (c) 2017 S. Yuya
3+
// This file is released under the MIT License.
4+
// http://opensource.org/licenses/mit-license.php
5+
6+
#ifndef __USB_PCD_H
7+
#define __USB_PCD_H
8+
9+
#ifndef NULL
10+
#define NULL 0
11+
#endif
12+
13+
#endif

0 commit comments

Comments
 (0)