⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 audioclass.c

📁 基于ADSP-BF535 USB驱动应用程序
💻 C
📖 第 1 页 / 共 3 页
字号:
														buffer[3] = HIBYTE (gOutLeftVol);
														buffer[4] = LOBYTE (gOutRightVol);
														buffer[5] = HIBYTE (gOutRightVol);
														*pNumBytesToTransfer = sizeof (USHORT) * 3;
														retVal = true;
														break;
													default:
														//Shouldn't really get here!
														break;
												}
											break;
									}
								break;
							default:
								//Shouldn't really get here?
								break;
						}
					break;
				case GET_MIN:
					switch (wIndexHi)
						{
							case UNITID_OUTVOLUME:
								buffer[0] = LOBYTE(OUTVOLUME_MIN);
								buffer[1] = HIBYTE(OUTVOLUME_MIN);
								if (LOBYTE(wValue) == 0xff)
									{
										memcpy (buffer+2, buffer, 2);
										memcpy (buffer+4, buffer, 2);
										*pNumBytesToTransfer = 6;
									}
								else
									*pNumBytesToTransfer = 2;
								retVal = true;
								break;
							default:
								//Shouldn't really get here?
								break;
						}
					break;
				case GET_MAX:
					switch (wIndexHi)
						{
							case UNITID_OUTVOLUME:
								buffer[0] = LOBYTE(OUTVOLUME_MAX);
								buffer[1] = HIBYTE(OUTVOLUME_MAX);
								if (LOBYTE(wValue) == 0xff)
									{
										memcpy (buffer+2, buffer, 2);
										memcpy (buffer+4, buffer, 2);
										*pNumBytesToTransfer = 6;
									}
								else
									*pNumBytesToTransfer = 2;
								retVal = true;
								break;
							default:
								//Shouldn't really get here?
								break;
						}
					break;
				case GET_RES:
					switch (wIndexHi)
						{
							case UNITID_OUTVOLUME:
								buffer[0] = LOBYTE(OUTVOLUME_RES);
								buffer[1] = HIBYTE(OUTVOLUME_RES);
								if (LOBYTE(wValue) == 0xff)
									{
										memcpy (buffer+2, buffer, 2);
										memcpy (buffer+4, buffer, 2);
										*pNumBytesToTransfer = 6;
									}
								else
									*pNumBytesToTransfer = 2;
								retVal = true;
								break;
							default:
								//Shouldn't really get here?
								break;
						}
					break;
				default:
					//Shouldn't really get here!
					break;
			}

		return(retVal);
		
	}


/*------------------------------------------------------------
*	AudioSetRequest
*
*	Parameters:  
*		bRequest - the request.
*		wIndexHi - the high byte of wIndex
*		wValue - as it comes in the setup packet
*		wLength - as it comes in the setup packet.
*		buffer - pointer to a buffer where the associated data is stored
*
*	Globals Used:
*		gOutMute, gOutLeftVol, gOutRightVol
*
*	Description:
*		This handles the Audio Class Set Requests
*
*	Returns:
*		true on success, false on failure (to stall the EP).
*
*------------------------------------------------------------*/
bool AudioSetRequest (UCHAR bRequest, UCHAR wIndexHi, USHORT wValue, USHORT wLength, UCHAR *buffer)
	{
		bool retVal = false;

		//Dprintf3 ("wIndexHi = %02x, wValue = %04x, wData = %04x", wIndexHi, wValue, *(PUSHORT)buffer);

		switch (bRequest)
			{
				case SET_CUR:
					switch (wIndexHi)
						{
							case UNITID_OUTVOLUME:
								switch (HIBYTE(wValue))
									{
										case USB_AUDIO_CONTROL_SELECTOR_MUTE_CONTROL:
											if (LOBYTE(wValue) == 0)
												{
													gOutMute = buffer[0];
													//Call whatever is required to mute the codec
													gRegChangesRequested++;
													retVal = true;
													break;
												}
											break;
										case USB_AUDIO_CONTROL_SELECTOR_VOLUME_CONTROL:
											switch (LOBYTE(wValue))
												{
													case 0:
														memcpy (&gOutLeftVol, buffer, sizeof (USHORT));
														memcpy (&gOutRightVol, buffer, sizeof (USHORT));
														//Call whatever is required to change the codec volume
														gRegChangesRequested++;
														retVal = true;
														break;
													case 1:
														memcpy (&gOutLeftVol, buffer, sizeof (USHORT));
														//Call whatever is required to change the codec volume
														gRegChangesRequested++;
														retVal = true;
														break;
													case 2:
														memcpy (&gOutRightVol, buffer, sizeof (USHORT));
														//Call whatever is required to change the codec volume
														gRegChangesRequested++;
														retVal = true;
														break;
													case 0xff:
														memcpy (&gOutLeftVol, buffer + sizeof(USHORT), sizeof (USHORT));
														memcpy (&gOutRightVol, buffer + 2 * (sizeof(USHORT)), sizeof (USHORT));
														//Call whatever is required to change the codec volume
														gRegChangesRequested++;
														retVal = true;
														break;
													default:
														//Shouldn't really get here!
														break;
												}
											break;
									}
								
								break;
							default:
								//Shouldn't really get here?
								break;
						}
					break;
				default:
					//Should not really get here
					break;
			}
		return(retVal);
	}


/*------------------------------------------------------------
*	OnGetDeviceDescriptor
*
*	Parameters:  
*		buffer - location (DMA buffer) where the descriptor data is to
*			be put.
*		pNumBytesToTransfer - points to a location where the original wLength
*			is stored. This routine should update this location to indicate
*			the actual number of bytes transferred to the buffer.
*
*	Globals Used:
*		gTheDeviceDescriptor
*
*	Description:
*		This routine is in response to a GET DEVICE DESCRIPTOR
*		setup request. This routine fills in the required data
*
*	Returns:
*		true - always!
*
*------------------------------------------------------------*/
bool OnGetDeviceDescriptor (void *buffer, PUINT pNumBytesToTransfer)
	{
		if (*pNumBytesToTransfer < sizeof (gTheDeviceDescriptor))
			memcpy (buffer, &gTheDeviceDescriptor, *pNumBytesToTransfer);
		else
			{
				memcpy (buffer, &gTheDeviceDescriptor, sizeof (gTheDeviceDescriptor));
				*pNumBytesToTransfer = sizeof (gTheDeviceDescriptor);
			}

		return(true);
	}



/*------------------------------------------------------------
*	OnGetConfigDescriptor
*
*	Parameters:  
*		buffer - location (DMA buffer) where the descriptor data is to
*			be put.
*		pNumBytesToTransfer - points to a location where the original wLength
*			is stored. This routine should update this location to indicate
*			the actual number of bytes transferred to the buffer.
*
*	Globals Used:
*		gTheConfigDescriptor
*
*	Description:
*		This routine is in response to a GET CONFIG DESCRIPTOR
*		setup request. This routine fills in the required data
*
*	Returns:
*		true - always!
*
*------------------------------------------------------------*/
bool OnGetConfigDescriptor (void *buffer, PUINT pNumBytesToTransfer)
	{

		if (*pNumBytesToTransfer < sizeof(gTheConfigDescriptor))
			memcpy (buffer, &gTheConfigDescriptor, *pNumBytesToTransfer);
		else
			{
				memcpy (buffer, &gTheConfigDescriptor, sizeof (gTheConfigDescriptor));
				*pNumBytesToTransfer = sizeof (gTheConfigDescriptor);
			}

		return (true);
	}



/*------------------------------------------------------------
*	OnGetStringDescriptor
*
*	Parameters:  
*		wValue - the string to be retrieved
*		buffer - location (DMA buffer) where the descriptor data is to
*			be put.
*		pNumBytesToTransfer - points to a location where the original wLength
*			is stored. This routine should update this location to indicate
*			the actual number of bytes transferred to the buffer.
*
*	Globals Used:
*		Not Yet!
*
*	Description:
*		This routine is in response to a GET STRING DESCRIPTOR
*		setup request. This routine fills in the required data
*
*	Returns:
*		true - always!
*
*------------------------------------------------------------*/
bool OnGetStringDescriptor (UCHAR stringIndex, USHORT langID, void *buffer, PUINT pNumBytesToTransfer)
	{
		bool retVal = false;
		UINT neededSpace = 0;
		UINT maxBytesToTransfer = 0;
		UINT outIndex = 0, charIndex = 0;

		if (stringIndex == 0)
			{
				//Need to return a langid array here!
				if (*pNumBytesToTransfer < sizeof (gTheLangIDArray))
					memcpy (buffer, &gTheLangIDArray, *pNumBytesToTransfer);
				else
					{
						memcpy (buffer, &gTheLangIDArray, sizeof (gTheLangIDArray));
						*pNumBytesToTransfer = sizeof (gTheLangIDArray);
					}
				retVal = true;
			}
		else if ((stringIndex < TOTAL_STRING_DESCRIPTORS) && (stringIndex > 0))
			{
				//Convert this to a zero based index
				stringIndex--;
				neededSpace = (strlen (gTheStringDescriptors[stringIndex]) + 1) * 2;
				if (neededSpace > *pNumBytesToTransfer)
					maxBytesToTransfer = *pNumBytesToTransfer;
				else
					maxBytesToTransfer = *pNumBytesToTransfer = neededSpace;

				//Transfer as many as we can
				((char *)buffer)[outIndex++] = neededSpace;
				((char *)buffer)[outIndex++] = USB_STRING_DESCRIPTOR;
				while ((outIndex + 1) < maxBytesToTransfer)
					{
						((char *)buffer)[outIndex++] = gTheStringDescriptors[stringIndex][charIndex++];
						((char *)buffer)[outIndex++] = 0;
					}


				retVal = true;
			}

		//Don't have any strings yet!
		return(retVal);
	}




/*------------------------------------------------------------
*	OnConfigRequest
*
*	Parameters:  
*		newConfiguration - the new configuration after Config request.
*		newInterface - the new interface after Config(Set Interface) request.
*		newAltSetting - the new alt setting after Config(Set Interface) request
*
*	Globals Used:
*		gPrepareReport
*
*	Description:
*		This routien is called in response to a configuration change - i.e.
*		after receiving a Set Config or a Set Interface request.
*
*	Returns:
*		true - always
*
*------------------------------------------------------------*/
bool OnConfigRequest (UCHAR newConfiguration, UCHAR newInterface, UCHAR newAltSetting)
	{
		//Dprintf3 ("Audio Dev Config Request: %02x, %02x, %02x!", (UINT)newConfiguration, (UINT)newInterface, (UINT)newAltSetting);
		if ((newConfiguration == EP_CONFIG1))// && (newInterface == INTERFACE_FOR_HID) &&
			//(newAltSetting == ALTSETTING_FOR_HID))
			{
				//Looks like we're in, setup our IN endpoint if we want to!
				Dprintf ("Audio Device Configured!");
				if (newInterface == INTERFACE_FOR_AUDIOSTREAMING)
					{
						if ((newAltSetting == ALTSETTING_FOR_AUDIOSTREAMING_48K) && (!gIsPlaybackActive))
							{
								gTimeoutCount = 0;
								gIsPlaybackActive = true;
								//ToDo: Initialize the codec to start receiving data.
								Dprintf ("Starting Playback!");


#if PROVIDE_FEEDBACK
								//Initialize Feedback Fs.
								gFeedbackData = FEEDBACK_FREQUENCY_NORMAL;
								//Activate Endpoint
								ActivateEndpoint (EP2, USBD_TYP_ISO, FEEDBACK_PACKET_SIZE, FEEDBACK_PACKET_SIZE);
								//Prepare for a transfer.
								OnInTransferComplete (EP2);

#endif // PROVIDE_FEEDBACK

								//init the pointers
								gDataBufferHead = gDataBufferTail = 0;

								//Setup and Arm our endpoint
								ActivateEndpoint (EP1, USBD_TYP_ISO, MAX_PACKET_SIZE, MAX_PACKET_SIZE);
								PrepareOUTEPForXFer (EP1);
								ArmEndpoint (EP1, EP_OUT);
								gEnablePlaybackCountdown = PLAYBACK_DELAY;
							}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -