2cd1304a976db8f19284919f00a272f5b22554e7
[SCSI2SD-V6.git] / software / SCSI2SD / v3 / SCSI2SD.cydsn / Generated_Source / PSoC5 / USBFS_audio.c
1 /*******************************************************************************\r
2 * File Name: USBFS_audio.c\r
3 * Version 2.80\r
4 *\r
5 * Description:\r
6 *  USB AUDIO Class request handler.\r
7 *\r
8 * Related Document:\r
9 *  Universal Serial Bus Device Class Definition for Audio Devices Release 1.0\r
10 *\r
11 ********************************************************************************\r
12 * Copyright 2008-2014, Cypress Semiconductor Corporation.  All rights reserved.\r
13 * You may use this file only in accordance with the license, terms, conditions,\r
14 * disclaimers, and limitations in the end user license agreement accompanying\r
15 * the software package with which this file was provided.\r
16 *******************************************************************************/\r
17 \r
18 #include "USBFS.h"\r
19 \r
20 #if defined(USBFS_ENABLE_AUDIO_CLASS)\r
21 \r
22 #include "USBFS_audio.h"\r
23 #include "USBFS_pvt.h"\r
24 #if defined(USBFS_ENABLE_MIDI_STREAMING)\r
25     #include "USBFS_midi.h"\r
26 #endif /*  USBFS_ENABLE_MIDI_STREAMING*/\r
27 \r
28 \r
29 /***************************************\r
30 * Custom Declarations\r
31 ***************************************/\r
32 \r
33 /* `#START CUSTOM_DECLARATIONS` Place your declaration here */\r
34 \r
35 /* `#END` */\r
36 \r
37 \r
38 #if !defined(USER_SUPPLIED_AUDIO_HANDLER)\r
39 \r
40 \r
41 /***************************************\r
42 *    AUDIO Variables\r
43 ***************************************/\r
44 \r
45 #if defined(USBFS_ENABLE_AUDIO_STREAMING)\r
46     volatile uint8 USBFS_currentSampleFrequency[USBFS_MAX_EP][USBFS_SAMPLE_FREQ_LEN];\r
47     volatile uint8 USBFS_frequencyChanged;\r
48     volatile uint8 USBFS_currentMute;\r
49     volatile uint8 USBFS_currentVolume[USBFS_VOLUME_LEN];\r
50     volatile uint8 USBFS_minimumVolume[USBFS_VOLUME_LEN] = {USBFS_VOL_MIN_LSB,\r
51                                                                                   USBFS_VOL_MIN_MSB};\r
52     volatile uint8 USBFS_maximumVolume[USBFS_VOLUME_LEN] = {USBFS_VOL_MAX_LSB,\r
53                                                                                   USBFS_VOL_MAX_MSB};\r
54     volatile uint8 USBFS_resolutionVolume[USBFS_VOLUME_LEN] = {USBFS_VOL_RES_LSB,\r
55                                                                                      USBFS_VOL_RES_MSB};\r
56 #endif /*  USBFS_ENABLE_AUDIO_STREAMING */\r
57 \r
58 \r
59 /*******************************************************************************\r
60 * Function Name: USBFS_DispatchAUDIOClassRqst\r
61 ********************************************************************************\r
62 *\r
63 * Summary:\r
64 *  This routine dispatches class requests\r
65 *\r
66 * Parameters:\r
67 *  None.\r
68 *\r
69 * Return:\r
70 *  requestHandled\r
71 *\r
72 * Global variables:\r
73 *   USBFS_currentSampleFrequency: Contains the current audio Sample\r
74 *       Frequency. It is set by the Host using SET_CUR request to the endpoint.\r
75 *   USBFS_frequencyChanged: This variable is used as a flag for the\r
76 *       user code, to be aware that Host has been sent request for changing\r
77 *       Sample Frequency. Sample frequency will be sent on the next OUT\r
78 *       transaction. It is contains endpoint address when set. The following\r
79 *       code is recommended for detecting new Sample Frequency in main code:\r
80 *       if((USBFS_frequencyChanged != 0) &&\r
81 *       (USBFS_transferState == USBFS_TRANS_STATE_IDLE))\r
82 *       {\r
83 *          USBFS_frequencyChanged = 0;\r
84 *       }\r
85 *       USBFS_transferState variable is checked to be sure that\r
86 *             transfer completes.\r
87 *   USBFS_currentMute: Contains mute configuration set by Host.\r
88 *   USBFS_currentVolume: Contains volume level set by Host.\r
89 *\r
90 * Reentrant:\r
91 *  No.\r
92 *\r
93 *******************************************************************************/\r
94 uint8 USBFS_DispatchAUDIOClassRqst(void) \r
95 {\r
96     uint8 requestHandled = USBFS_FALSE;\r
97     uint8 bmRequestType  = CY_GET_REG8(USBFS_bmRequestType);\r
98 \r
99     #if defined(USBFS_ENABLE_AUDIO_STREAMING)\r
100         uint8 epNumber;\r
101         epNumber = CY_GET_REG8(USBFS_wIndexLo) & USBFS_DIR_UNUSED;\r
102     #endif /*  USBFS_ENABLE_AUDIO_STREAMING */\r
103 \r
104 \r
105     if ((bmRequestType & USBFS_RQST_DIR_MASK) == USBFS_RQST_DIR_D2H)\r
106     {\r
107         /* Control Read */\r
108         if((bmRequestType & USBFS_RQST_RCPT_MASK) == USBFS_RQST_RCPT_EP)\r
109         {\r
110             /* Endpoint */\r
111             switch (CY_GET_REG8(USBFS_bRequest))\r
112             {\r
113                 case USBFS_GET_CUR:\r
114                 #if defined(USBFS_ENABLE_AUDIO_STREAMING)\r
115                     if(CY_GET_REG8(USBFS_wValueHi) == USBFS_SAMPLING_FREQ_CONTROL)\r
116                     {\r
117                          /* point Control Selector is Sampling Frequency */\r
118                         USBFS_currentTD.wCount = USBFS_SAMPLE_FREQ_LEN;\r
119                         USBFS_currentTD.pData  = USBFS_currentSampleFrequency[epNumber];\r
120                         requestHandled   = USBFS_InitControlRead();\r
121                     }\r
122                 #endif /*  USBFS_ENABLE_AUDIO_STREAMING */\r
123 \r
124                 /* `#START AUDIO_READ_REQUESTS` Place other request handler here */\r
125 \r
126                 /* `#END` */\r
127                     break;\r
128                 default:\r
129                     break;\r
130             }\r
131         }\r
132         else if((bmRequestType & USBFS_RQST_RCPT_MASK) == USBFS_RQST_RCPT_IFC)\r
133         {\r
134             /* Interface or Entity ID */\r
135             switch (CY_GET_REG8(USBFS_bRequest))\r
136             {\r
137                 case USBFS_GET_CUR:\r
138                 #if defined(USBFS_ENABLE_AUDIO_STREAMING)\r
139                     if(CY_GET_REG8(USBFS_wValueHi) == USBFS_MUTE_CONTROL)\r
140                     {\r
141                         /* `#START MUTE_CONTROL_GET_REQUEST` Place multi-channel handler here */\r
142 \r
143                         /* `#END` */\r
144 \r
145                          /* Entity ID Control Selector is MUTE */\r
146                         USBFS_currentTD.wCount = 1u;\r
147                         USBFS_currentTD.pData  = &USBFS_currentMute;\r
148                         requestHandled   = USBFS_InitControlRead();\r
149                     }\r
150                     else if(CY_GET_REG8(USBFS_wValueHi) == USBFS_VOLUME_CONTROL)\r
151                     {\r
152                         /* `#START VOLUME_CONTROL_GET_REQUEST` Place multi-channel handler here */\r
153 \r
154                         /* `#END` */\r
155 \r
156                         /* Entity ID Control Selector is VOLUME, */\r
157                         USBFS_currentTD.wCount = USBFS_VOLUME_LEN;\r
158                         USBFS_currentTD.pData  = USBFS_currentVolume;\r
159                         requestHandled   = USBFS_InitControlRead();\r
160                     }\r
161                     else\r
162                     {\r
163                         /* `#START OTHER_GET_CUR_REQUESTS` Place other request handler here */\r
164 \r
165                         /* `#END` */\r
166                     }\r
167                     break;\r
168                 case USBFS_GET_MIN:    /* GET_MIN */\r
169                     if(CY_GET_REG8(USBFS_wValueHi) == USBFS_VOLUME_CONTROL)\r
170                     {\r
171                         /* Entity ID Control Selector is VOLUME, */\r
172                         USBFS_currentTD.wCount = USBFS_VOLUME_LEN;\r
173                         USBFS_currentTD.pData  = &USBFS_minimumVolume[0];\r
174                         requestHandled   = USBFS_InitControlRead();\r
175                     }\r
176                     break;\r
177                 case USBFS_GET_MAX:    /* GET_MAX */\r
178                     if(CY_GET_REG8(USBFS_wValueHi) == USBFS_VOLUME_CONTROL)\r
179                     {\r
180                         /* Entity ID Control Selector is VOLUME, */\r
181                         USBFS_currentTD.wCount = USBFS_VOLUME_LEN;\r
182                         USBFS_currentTD.pData  = &USBFS_maximumVolume[0];\r
183                         requestHandled   = USBFS_InitControlRead();\r
184                     }\r
185                     break;\r
186                 case USBFS_GET_RES:    /* GET_RES */\r
187                     if(CY_GET_REG8(USBFS_wValueHi) == USBFS_VOLUME_CONTROL)\r
188                     {\r
189                          /* Entity ID Control Selector is VOLUME, */\r
190                         USBFS_currentTD.wCount = USBFS_VOLUME_LEN;\r
191                         USBFS_currentTD.pData  = &USBFS_resolutionVolume[0];\r
192                         requestHandled   = USBFS_InitControlRead();\r
193                     }\r
194                     break;\r
195                 /* The contents of the status message is reserved for future use.\r
196                 *  For the time being, a null packet should be returned in the data stage of the\r
197                 *  control transfer, and the received null packet should be ACKed.\r
198                 */\r
199                 case USBFS_GET_STAT:\r
200                         USBFS_currentTD.wCount = 0u;\r
201                         requestHandled   = USBFS_InitControlWrite();\r
202 \r
203                 #endif /*  USBFS_ENABLE_AUDIO_STREAMING */\r
204 \r
205                 /* `#START AUDIO_WRITE_REQUESTS` Place other request handler here */\r
206 \r
207                 /* `#END` */\r
208                     break;\r
209                 default:\r
210                     break;\r
211             }\r
212         }\r
213         else\r
214         {   /* USBFS_RQST_RCPT_OTHER */\r
215         }\r
216     }\r
217     else\r
218     {\r
219         /* Control Write */\r
220         if((bmRequestType & USBFS_RQST_RCPT_MASK) == USBFS_RQST_RCPT_EP)\r
221         {\r
222             /* point */\r
223             switch (CY_GET_REG8(USBFS_bRequest))\r
224             {\r
225                 case USBFS_SET_CUR:\r
226                 #if defined(USBFS_ENABLE_AUDIO_STREAMING)\r
227                     if(CY_GET_REG8(USBFS_wValueHi) == USBFS_SAMPLING_FREQ_CONTROL)\r
228                     {\r
229                          /* point Control Selector is Sampling Frequency */\r
230                         USBFS_currentTD.wCount = USBFS_SAMPLE_FREQ_LEN;\r
231                         USBFS_currentTD.pData  = USBFS_currentSampleFrequency[epNumber];\r
232                         requestHandled   = USBFS_InitControlWrite();\r
233                         USBFS_frequencyChanged = epNumber;\r
234                     }\r
235                 #endif /*  USBFS_ENABLE_AUDIO_STREAMING */\r
236 \r
237                 /* `#START AUDIO_SAMPLING_FREQ_REQUESTS` Place other request handler here */\r
238 \r
239                 /* `#END` */\r
240                     break;\r
241                 default:\r
242                     break;\r
243             }\r
244         }\r
245         else if((bmRequestType & USBFS_RQST_RCPT_MASK) == USBFS_RQST_RCPT_IFC)\r
246         {\r
247             /* Interface or Entity ID */\r
248             switch (CY_GET_REG8(USBFS_bRequest))\r
249             {\r
250                 case USBFS_SET_CUR:\r
251                 #if defined(USBFS_ENABLE_AUDIO_STREAMING)\r
252                     if(CY_GET_REG8(USBFS_wValueHi) == USBFS_MUTE_CONTROL)\r
253                     {\r
254                         /* `#START MUTE_SET_REQUEST` Place multi-channel handler here */\r
255 \r
256                         /* `#END` */\r
257 \r
258                         /* Entity ID Control Selector is MUTE */\r
259                         USBFS_currentTD.wCount = 1u;\r
260                         USBFS_currentTD.pData  = &USBFS_currentMute;\r
261                         requestHandled   = USBFS_InitControlWrite();\r
262                     }\r
263                     else if(CY_GET_REG8(USBFS_wValueHi) == USBFS_VOLUME_CONTROL)\r
264                     {\r
265                         /* `#START VOLUME_CONTROL_SET_REQUEST` Place multi-channel handler here */\r
266 \r
267                         /* `#END` */\r
268 \r
269                         /* Entity ID Control Selector is VOLUME */\r
270                         USBFS_currentTD.wCount = USBFS_VOLUME_LEN;\r
271                         USBFS_currentTD.pData  = USBFS_currentVolume;\r
272                         requestHandled   = USBFS_InitControlWrite();\r
273                     }\r
274                     else\r
275                     {\r
276                         /* `#START OTHER_SET_CUR_REQUESTS` Place other request handler here */\r
277 \r
278                         /* `#END` */\r
279                     }\r
280                 #endif /*  USBFS_ENABLE_AUDIO_STREAMING */\r
281 \r
282                 /* `#START AUDIO_CONTROL_SEL_REQUESTS` Place other request handler here */\r
283 \r
284                 /* `#END` */\r
285                     break;\r
286                 default:\r
287                     break;\r
288             }\r
289         }\r
290         else\r
291         {\r
292             /* USBFS_RQST_RCPT_OTHER */\r
293         }\r
294     }\r
295 \r
296     return(requestHandled);\r
297 }\r
298 \r
299 #endif /* USER_SUPPLIED_AUDIO_HANDLER */\r
300 \r
301 \r
302 /*******************************************************************************\r
303 * Additional user functions supporting AUDIO Requests\r
304 ********************************************************************************/\r
305 \r
306 /* `#START AUDIO_FUNCTIONS` Place any additional functions here */\r
307 \r
308 /* `#END` */\r
309 \r
310 #endif  /*  USBFS_ENABLE_AUDIO_CLASS */\r
311 \r
312 \r
313 /* [] END OF FILE */\r