1 |
/*---------------------------------------------------------------------------- |
---|
2 |
* U S B - K e r n e l |
---|
3 |
*---------------------------------------------------------------------------- |
---|
4 |
* Name: ADCUSER.C |
---|
5 |
* Purpose: Audio Device Class Custom User Module |
---|
6 |
* Version: V1.10 |
---|
7 |
*---------------------------------------------------------------------------- |
---|
8 |
* This file is part of the uVision/ARM development tools. |
---|
9 |
* This software may only be used under the terms of a valid, current, |
---|
10 |
* end user licence from KEIL for a compatible version of KEIL software |
---|
11 |
* development tools. Nothing else gives you the right to use it. |
---|
12 |
* |
---|
13 |
* Copyright (c) 2005-2007 Keil Software. |
---|
14 |
*---------------------------------------------------------------------------*/ |
---|
15 |
|
---|
16 |
#include "type.h" |
---|
17 |
|
---|
18 |
#include "usb.h" |
---|
19 |
#include "audio.h" |
---|
20 |
#include "usbcfg.h" |
---|
21 |
#include "usbcore.h" |
---|
22 |
#include "adcuser.h" |
---|
23 |
|
---|
24 |
#include "demo.h" |
---|
25 |
|
---|
26 |
|
---|
27 |
WORD VolCur = 0x0100; /* Volume Current Value */ |
---|
28 |
const WORD VolMin = 0x0000; /* Volume Minimum Value */ |
---|
29 |
const WORD VolMax = 0x0100; /* Volume Maximum Value */ |
---|
30 |
const WORD VolRes = 0x0004; /* Volume Resolution */ |
---|
31 |
|
---|
32 |
|
---|
33 |
/* |
---|
34 |
* Audio Device Class Interface Get Request Callback |
---|
35 |
* Called automatically on ADC Interface Get Request |
---|
36 |
* Parameters: None (global SetupPacket and EP0Buf) |
---|
37 |
* Return Value: TRUE - Success, FALSE - Error |
---|
38 |
*/ |
---|
39 |
|
---|
40 |
BOOL ADC_IF_GetRequest (void) { |
---|
41 |
|
---|
42 |
/* |
---|
43 |
Interface = SetupPacket.wIndex.WB.L; |
---|
44 |
EntityID = SetupPacket.wIndex.WB.H; |
---|
45 |
Request = SetupPacket.bRequest; |
---|
46 |
Value = SetupPacket.wValue.W; |
---|
47 |
... |
---|
48 |
*/ |
---|
49 |
|
---|
50 |
if (SetupPacket.wIndex.W == 0x0200) { |
---|
51 |
/* Feature Unit: Interface = 0, ID = 2 */ |
---|
52 |
if (SetupPacket.wValue.WB.L == 0) { |
---|
53 |
/* Master Channel */ |
---|
54 |
switch (SetupPacket.wValue.WB.H) { |
---|
55 |
case AUDIO_MUTE_CONTROL: |
---|
56 |
switch (SetupPacket.bRequest) { |
---|
57 |
case AUDIO_REQUEST_GET_CUR: |
---|
58 |
EP0Buf[0] = Mute; |
---|
59 |
return (TRUE); |
---|
60 |
} |
---|
61 |
break; |
---|
62 |
case AUDIO_VOLUME_CONTROL: |
---|
63 |
switch (SetupPacket.bRequest) { |
---|
64 |
case AUDIO_REQUEST_GET_CUR: |
---|
65 |
*((__packed WORD *)EP0Buf) = VolCur; |
---|
66 |
return (TRUE); |
---|
67 |
case AUDIO_REQUEST_GET_MIN: |
---|
68 |
*((__packed WORD *)EP0Buf) = VolMin; |
---|
69 |
return (TRUE); |
---|
70 |
case AUDIO_REQUEST_GET_MAX: |
---|
71 |
*((__packed WORD *)EP0Buf) = VolMax; |
---|
72 |
return (TRUE); |
---|
73 |
case AUDIO_REQUEST_GET_RES: |
---|
74 |
*((__packed WORD *)EP0Buf) = VolRes; |
---|
75 |
return (TRUE); |
---|
76 |
} |
---|
77 |
break; |
---|
78 |
} |
---|
79 |
} |
---|
80 |
} |
---|
81 |
|
---|
82 |
return (FALSE); /* Not Supported */ |
---|
83 |
} |
---|
84 |
|
---|
85 |
|
---|
86 |
/* |
---|
87 |
* Audio Device Class Interface Set Request Callback |
---|
88 |
* Called automatically on ADC Interface Set Request |
---|
89 |
* Parameters: None (global SetupPacket and EP0Buf) |
---|
90 |
* Return Value: TRUE - Success, FALSE - Error |
---|
91 |
*/ |
---|
92 |
|
---|
93 |
BOOL ADC_IF_SetRequest (void) { |
---|
94 |
|
---|
95 |
/* |
---|
96 |
Interface = SetupPacket.wIndex.WB.L; |
---|
97 |
EntityID = SetupPacket.wIndex.WB.H; |
---|
98 |
Request = SetupPacket.bRequest; |
---|
99 |
Value = SetupPacket.wValue.W; |
---|
100 |
... |
---|
101 |
*/ |
---|
102 |
|
---|
103 |
if (SetupPacket.wIndex.W == 0x0200) { |
---|
104 |
/* Feature Unit: Interface = 0, ID = 2 */ |
---|
105 |
if (SetupPacket.wValue.WB.L == 0) { |
---|
106 |
/* Master Channel */ |
---|
107 |
switch (SetupPacket.wValue.WB.H) { |
---|
108 |
case AUDIO_MUTE_CONTROL: |
---|
109 |
switch (SetupPacket.bRequest) { |
---|
110 |
case AUDIO_REQUEST_SET_CUR: |
---|
111 |
Mute = EP0Buf[0]; |
---|
112 |
return (TRUE); |
---|
113 |
} |
---|
114 |
break; |
---|
115 |
case AUDIO_VOLUME_CONTROL: |
---|
116 |
switch (SetupPacket.bRequest) { |
---|
117 |
case AUDIO_REQUEST_SET_CUR: |
---|
118 |
VolCur = *((__packed WORD *)EP0Buf); |
---|
119 |
return (TRUE); |
---|
120 |
} |
---|
121 |
break; |
---|
122 |
} |
---|
123 |
} |
---|
124 |
} |
---|
125 |
|
---|
126 |
return (FALSE); /* Not Supported */ |
---|
127 |
} |
---|
128 |
|
---|
129 |
|
---|
130 |
/* |
---|
131 |
* Audio Device Class EndPoint Get Request Callback |
---|
132 |
* Called automatically on ADC EndPoint Get Request |
---|
133 |
* Parameters: None (global SetupPacket and EP0Buf) |
---|
134 |
* Return Value: TRUE - Success, FALSE - Error |
---|
135 |
*/ |
---|
136 |
|
---|
137 |
BOOL ADC_EP_GetRequest (void) { |
---|
138 |
|
---|
139 |
/* |
---|
140 |
EndPoint = SetupPacket.wIndex.WB.L; |
---|
141 |
Request = SetupPacket.bRequest; |
---|
142 |
Value = SetupPacket.wValue.W; |
---|
143 |
... |
---|
144 |
*/ |
---|
145 |
return (FALSE); /* Not Supported */ |
---|
146 |
} |
---|
147 |
|
---|
148 |
|
---|
149 |
/* |
---|
150 |
* Audio Device Class EndPoint Set Request Callback |
---|
151 |
* Called automatically on ADC EndPoint Set Request |
---|
152 |
* Parameters: None (global SetupPacket and EP0Buf) |
---|
153 |
* Return Value: TRUE - Success, FALSE - Error |
---|
154 |
*/ |
---|
155 |
|
---|
156 |
BOOL ADC_EP_SetRequest (void) { |
---|
157 |
|
---|
158 |
/* |
---|
159 |
EndPoint = SetupPacket.wIndex.WB.L; |
---|
160 |
Request = SetupPacket.bRequest; |
---|
161 |
Value = SetupPacket.wValue.W; |
---|
162 |
... |
---|
163 |
*/ |
---|
164 |
return (FALSE); /* Not Supported */ |
---|
165 |
} |
---|