From 68468e0aea1c5b95c4b0d6277063863099c9ba21 Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Mon, 30 May 2011 11:36:21 +0000 Subject: [PATCH] Added new incomplete AudioOutputHost Host LowLevel demo. --- .../AudioInputHost/AudioInputHost.c | 4 +- .../AudioInputHost/AudioInputHost.h | 6 +- .../AudioInputHost/AudioInputHost.o | Bin 20140 -> 0 bytes .../AudioInputHost/ConfigDescriptor.c | 4 +- .../AudioOutputHost/AudioOutputHost.c | 254 +++++++ .../AudioOutputHost/AudioOutputHost.h | 81 ++ .../AudioOutputHost/ConfigDescriptor.c | 220 ++++++ .../AudioOutputHost/ConfigDescriptor.h | 72 ++ .../Host/Incomplete/AudioOutputHost/makefile | 714 ++++++++++++++++++ LUFA.pnproj | 2 +- LUFA/Drivers/USB/Class/Device/CDC.h | 1 + LUFA/ManPages/ChangeLog.txt | 1 + 12 files changed, 1351 insertions(+), 8 deletions(-) delete mode 100644 Demos/Host/Incomplete/AudioInputHost/AudioInputHost.o create mode 100644 Demos/Host/Incomplete/AudioOutputHost/AudioOutputHost.c create mode 100644 Demos/Host/Incomplete/AudioOutputHost/AudioOutputHost.h create mode 100644 Demos/Host/Incomplete/AudioOutputHost/ConfigDescriptor.c create mode 100644 Demos/Host/Incomplete/AudioOutputHost/ConfigDescriptor.h create mode 100644 Demos/Host/Incomplete/AudioOutputHost/makefile diff --git a/Demos/Host/Incomplete/AudioInputHost/AudioInputHost.c b/Demos/Host/Incomplete/AudioInputHost/AudioInputHost.c index 7ac8f0015c..8c98bcf6f9 100644 --- a/Demos/Host/Incomplete/AudioInputHost/AudioInputHost.c +++ b/Demos/Host/Incomplete/AudioInputHost/AudioInputHost.c @@ -43,7 +43,7 @@ int main(void) { SetupHardware(); - puts_P(PSTR(ESC_FG_CYAN "Audio Host Demo running.\r\n" ESC_FG_WHITE)); + puts_P(PSTR(ESC_FG_CYAN "Audio Input Host Demo running.\r\n" ESC_FG_WHITE)); LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); sei(); @@ -208,7 +208,7 @@ void Audio_Task(void) /* Sample reload timer initialization */ TIMSK0 = (1 << OCIE0A); - OCR0A = ((F_CPU / 8 / 8000) - 1); + OCR0A = ((F_CPU / 8 / 48000) - 1); TCCR0A = (1 << WGM01); // CTC mode TCCR0B = (1 << CS01); // Fcpu/8 speed diff --git a/Demos/Host/Incomplete/AudioInputHost/AudioInputHost.h b/Demos/Host/Incomplete/AudioInputHost/AudioInputHost.h index 6a3b8502c5..e3952329db 100644 --- a/Demos/Host/Incomplete/AudioInputHost/AudioInputHost.h +++ b/Demos/Host/Incomplete/AudioInputHost/AudioInputHost.h @@ -30,11 +30,11 @@ /** \file * - * Header file for AudioHost.c. + * Header file for AudioInputHost.c. */ -#ifndef _AUDIO_HOST_H_ -#define _AUDIO_HOST_H_ +#ifndef _AUDIO_INPUT_HOST_H_ +#define _AUDIO_INPUT_HOST_H_ /* Includes: */ #include diff --git a/Demos/Host/Incomplete/AudioInputHost/AudioInputHost.o b/Demos/Host/Incomplete/AudioInputHost/AudioInputHost.o deleted file mode 100644 index f8bafd3d1332c63e8a1f0fc5386c44051f4d23da..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20140 zcmc(G33Ob=m3F=EmMkn;vL$1i*v9SH#>Uv%yvfFR(}ESeD3VMdD70JZCtJ|!7QJ{O zfQ4-mY-d2SFgTC|<_}vk!xj=8CM;$$aK1} zkjy!A{<7=UcW>Rgb*t*u@~WS9HLh!N97mbps5X_Ql=}8;r5;4)LM<>y%~x|(|96x# z&Y4wOQS2|BTsqEabv6}_EmX=kLHSFU6`x()T%nYIrYbI80STo70*jO?2sp*X5GimV zQaA_lQ^qJYN(vURU{QtRFV#ZD6gp*$@)vnZ>qaXz8l==gvRFuzBv~TDLXIhe4b)kB zsx!N!xq|x23KThGnWfaYKu%@l6`pyz<_gF0ij1F*B2|z+H6yLa>NP*_!y6h!z{s$q>zS+>|r4fm17mMQEU<(oD^+LN3A2}4c7j|s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HKWu8X5 z7?Co>x-BwBY&PXt9V787q)mt{`ykS_h%8I|X++Zx-N2ORdUy%>@Pl`hV%+V>Zj~gh}2Kqk4Tx@knTkctil7~TExI=4b^@m=l7)?~)6U_Pb1Hts2X9Ne3 z{#bAU(w_;&5};lXT!{1)#6l`TcolJ!;CF!8mN$@ofLPv$2Lmc6pMDZRG`=^QGzSoY zdk@<}ALBm3_A<-^W_uYbfsK#x_iR&^dF5mI1P_sAdB0K!%(BEqz@{u+-`Fso81*tt zLM%U5L+#K08Q$DvSNgFAvhUjkZ$^4Kq7QtoF;@xZc+zjk=NNuY@L{AJcj~zr>2(&? z<1T!Tw~?WoZKpFE3a4gYRp^n(eet^oO{w+v|ovD7tD z@YzT)%o+Y%i_c}3HZcDj!L>*mEUfzhG8cfiQTS|Yo8TDIPh0q6!5mvxFvnBhqe9O^ zzUgdE)nw(jSN^f3sl9)Bnil9J!YmeYFAUHw5#y z!6yXoK>DO$>fpLbdEy@lru;F%?E6;)e-G)K7Jggs^GFMcxuGG9gz19DKRHy!CxgV| zhjWNImgWoQ%vO(&*5l4a}} zFPJ=Sv)DF;d|>i}#4;~t3Z`z|7O|Oo9POunRTGQ-3k9E#w2m0#$iU@~xCvvridg0a T%M+iDRJUE)xQ={aj>UfiGT`u> diff --git a/Demos/Host/Incomplete/AudioInputHost/ConfigDescriptor.c b/Demos/Host/Incomplete/AudioInputHost/ConfigDescriptor.c index 5dcd602acf..589012aaa3 100644 --- a/Demos/Host/Incomplete/AudioInputHost/ConfigDescriptor.c +++ b/Demos/Host/Incomplete/AudioInputHost/ConfigDescriptor.c @@ -120,7 +120,7 @@ uint8_t ProcessConfigurationDescriptor(void) /* Retrieve the endpoint address from the endpoint descriptor */ USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t); - /* If the endpoint is a IN type endpoint */ + /* Save the endpoint if it is an IN type endpoint */ if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) DataINEndpoint = EndpointData; } @@ -129,7 +129,7 @@ uint8_t ProcessConfigurationDescriptor(void) StreamingInterfaceAltSetting = AudioStreamingInterface->AlternateSetting; StreamingEndpointAddress = DataINEndpoint->EndpointAddress; - /* Configure the HID data IN pipe */ + /* Configure the Audio data IN pipe */ Pipe_ConfigurePipe(AUDIO_DATA_IN_PIPE, EP_TYPE_ISOCHRONOUS, PIPE_TOKEN_IN, DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_DOUBLE); diff --git a/Demos/Host/Incomplete/AudioOutputHost/AudioOutputHost.c b/Demos/Host/Incomplete/AudioOutputHost/AudioOutputHost.c new file mode 100644 index 0000000000..fed18cb0c5 --- /dev/null +++ b/Demos/Host/Incomplete/AudioOutputHost/AudioOutputHost.c @@ -0,0 +1,254 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2011. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * Main source file for the AudioOutputHost demo. This file contains the main tasks of + * the demo and is responsible for the initial application hardware configuration. + */ + +#include "AudioOutputHost.h" + +/** Main program entry point. This routine configures the hardware required by the application, then + * enters a loop to run the application tasks in sequence. + */ +int main(void) +{ + SetupHardware(); + + puts_P(PSTR(ESC_FG_CYAN "Audio Output Host Demo running.\r\n" ESC_FG_WHITE)); + + LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); + sei(); + + for (;;) + { + Audio_Task(); + USB_USBTask(); + } +} + +/** Configures the board hardware and chip peripherals for the demo's functionality. */ +void SetupHardware(void) +{ + /* Disable watchdog if enabled by bootloader/fuses */ + MCUSR &= ~(1 << WDRF); + wdt_disable(); + + /* Disable clock division */ + clock_prescale_set(clock_div_1); + + /* Hardware Initialization */ + Serial_Init(9600, false); + Buttons_Init(); + LEDs_Init(); + USB_Init(); + + /* Create a stdio stream for the serial port for stdin and stdout */ + Serial_CreateStream(NULL); +} + +/** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and + * starts the library USB task to begin the enumeration and USB management process. + */ +void EVENT_USB_Host_DeviceAttached(void) +{ + puts_P(PSTR(ESC_FG_GREEN "Device Attached.\r\n" ESC_FG_WHITE)); + LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); +} + +/** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and + * stops the library USB task management process. + */ +void EVENT_USB_Host_DeviceUnattached(void) +{ + puts_P(PSTR(ESC_FG_GREEN "Device Unattached.\r\n" ESC_FG_WHITE)); + LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); +} + +/** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully + * enumerated by the host and is now ready to be used by the application. + */ +void EVENT_USB_Host_DeviceEnumerationComplete(void) +{ + LEDs_SetAllLEDs(LEDMASK_USB_READY); +} + +/** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */ +void EVENT_USB_Host_HostError(const uint8_t ErrorCode) +{ + USB_Disable(); + + printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n" + " -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode); + + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + for(;;); +} + +/** Event handler for the USB_DeviceEnumerationFailed event. This indicates that a problem occurred while + * enumerating an attached USB device. + */ +void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, + const uint8_t SubErrorCode) +{ + printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n" + " -- Error Code %d\r\n" + " -- Sub Error Code %d\r\n" + " -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState); + + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); +} + +void Audio_Task(void) +{ + uint8_t ErrorCode; + + switch (USB_HostState) + { + case HOST_STATE_Addressed: + puts_P(PSTR("Getting Config Data.\r\n")); + + /* Get and process the configuration descriptor data */ + if ((ErrorCode = ProcessConfigurationDescriptor()) != SuccessfulConfigRead) + { + if (ErrorCode == ControlError) + puts_P(PSTR(ESC_FG_RED "Control Error (Get Configuration).\r\n")); + else + puts_P(PSTR(ESC_FG_RED "Invalid Device.\r\n")); + + printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode); + + /* Indicate error status */ + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + + /* Wait until USB device disconnected */ + USB_HostState = HOST_STATE_WaitForDeviceRemoval; + break; + } + + /* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */ + if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful) + { + printf_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n" + " -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode); + + /* Indicate error status */ + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + + /* Wait until USB device disconnected */ + USB_HostState = HOST_STATE_WaitForDeviceRemoval; + break; + } + + if ((ErrorCode = USB_Host_SetInterfaceAltSetting(StreamingInterfaceIndex, + StreamingInterfaceAltSetting)) != HOST_SENDCONTROL_Successful) + { + printf_P(PSTR(ESC_FG_RED "Could not set alternative streaming interface setting.\r\n" + " -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode); + + /* Indicate error status */ + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + + /* Wait until USB device disconnected */ + USB_HostState = HOST_STATE_WaitForDeviceRemoval; + break; + } + + USB_ControlRequest = (USB_Request_Header_t) + { + .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_ENDPOINT), + .bRequest = AUDIO_REQ_SetCurrent, + .wValue = 0x0100, + .wIndex = StreamingEndpointAddress, + .wLength = sizeof(USB_Audio_SampleFreq_t), + }; + + USB_Audio_SampleFreq_t SampleRate = AUDIO_SAMPLE_FREQ(48000); + + /* Select the control pipe for the request transfer */ + Pipe_SelectPipe(PIPE_CONTROLPIPE); + + /* Set the sample rate on the streaming interface endpoint */ + if ((ErrorCode = USB_Host_SendControlRequest(&SampleRate)) != HOST_SENDCONTROL_Successful) + { + /* Indicate error status */ + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + + /* Wait until USB device disconnected */ + USB_HostState = HOST_STATE_WaitForDeviceRemoval; + break; + } + + /* Sample reload timer initialization */ + TIMSK0 = (1 << OCIE0A); + OCR0A = ((F_CPU / 8 / 48000) - 1); + TCCR0A = (1 << WGM01); // CTC mode + TCCR0B = (1 << CS01); // Fcpu/8 speed + + puts_P(PSTR("Speaker Enumerated.\r\n")); + + USB_HostState = HOST_STATE_Configured; + break; + case HOST_STATE_Configured: + break; + } +} + +/** ISR to handle the reloading of the endpoint with the next sample. */ +ISR(TIMER0_COMPA_vect, ISR_BLOCK) +{ + uint8_t PrevPipe = Pipe_GetCurrentPipe(); + + Pipe_SelectPipe(AUDIO_DATA_OUT_PIPE); + Pipe_Unfreeze(); + + /* Check if the current pipe can be written to (device ready for more data) */ + if (Pipe_IsOUTReady()) + { + static uint8_t SquareWaveSampleCount; + static int16_t CurrentWaveValue; + + if (SquareWaveSampleCount++ == 0xFF) + CurrentWaveValue ^= 0x8000; + + /* Only generate audio if the board button is being pressed */ + int16_t Sample_16Bit = (Buttons_GetStatus() & BUTTONS_BUTTON1) ? CurrentWaveValue : 0; + + Pipe_Write_16_LE(Sample_16Bit); + Pipe_Write_16_LE(Sample_16Bit); + + if (!(Pipe_IsReadWriteAllowed())) + Pipe_ClearOUT(); + } + + Pipe_Freeze(); + Pipe_SelectPipe(PrevPipe); +} diff --git a/Demos/Host/Incomplete/AudioOutputHost/AudioOutputHost.h b/Demos/Host/Incomplete/AudioOutputHost/AudioOutputHost.h new file mode 100644 index 0000000000..4772bb3eaa --- /dev/null +++ b/Demos/Host/Incomplete/AudioOutputHost/AudioOutputHost.h @@ -0,0 +1,81 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2011. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * Header file for AudioOutputHost.c. + */ + +#ifndef _AUDIO_OUTPUT_HOST_H_ +#define _AUDIO_OUTPUT_HOST_H_ + + /* Includes: */ + #include + #include + #include + #include + #include + #include + + #include + #include + #include + #include + #include + #include + + #include "ConfigDescriptor.h" + + /* Macros: */ + /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ + #define LEDMASK_USB_NOTREADY LEDS_LED1 + + /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */ + #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3) + + /** LED mask for the library LED driver, to indicate that the USB interface is ready. */ + #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4) + + /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */ + #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3) + + /* Function Prototypes: */ + void Audio_Task(void); + void SetupHardware(void); + + void EVENT_USB_Host_HostError(const uint8_t ErrorCode); + void EVENT_USB_Host_DeviceAttached(void); + void EVENT_USB_Host_DeviceUnattached(void); + void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, + const uint8_t SubErrorCode); + void EVENT_USB_Host_DeviceEnumerationComplete(void); + +#endif + diff --git a/Demos/Host/Incomplete/AudioOutputHost/ConfigDescriptor.c b/Demos/Host/Incomplete/AudioOutputHost/ConfigDescriptor.c new file mode 100644 index 0000000000..30b50c6819 --- /dev/null +++ b/Demos/Host/Incomplete/AudioOutputHost/ConfigDescriptor.c @@ -0,0 +1,220 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2011. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * USB Device Configuration Descriptor processing routines, to determine the correct pipe configurations + * needed to communication with an attached USB device. Descriptors are special computer-readable structures + * which the host requests upon device enumeration, to determine the device's capabilities and functions. + */ + +#include "ConfigDescriptor.h" + +/** Index of the currently used Audio Streaming Interface within the device. */ +uint8_t StreamingInterfaceIndex = 0; + +/** Alternative Setting of the currently used Audio Streaming Interface within the device. */ +uint8_t StreamingInterfaceAltSetting = 0; + +/** Address of the streaming audio endpoint currently in use within the device. */ +uint8_t StreamingEndpointAddress = 0; + + +/** Reads and processes an attached device's descriptors, to determine compatibility and pipe configurations. This + * routine will read in the entire configuration descriptor, and configure the hosts pipes to correctly communicate + * with compatible devices. + * + * This routine searches for a Streaming Audio interface descriptor containing a valid Isochronous audio endpoint. + * + * \return An error code from the \ref RNDISHost_GetConfigDescriptorDataCodes_t enum. + */ +uint8_t ProcessConfigurationDescriptor(void) +{ + uint8_t ConfigDescriptorData[512]; + void* CurrConfigLocation = ConfigDescriptorData; + uint16_t CurrConfigBytesRem; + + USB_Descriptor_Interface_t* AudioControlInterface = NULL; + USB_Descriptor_Interface_t* AudioStreamingInterface = NULL; + USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; + + /* Retrieve the entire configuration descriptor into the allocated buffer */ + switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) + { + case HOST_GETCONFIG_Successful: + break; + case HOST_GETCONFIG_InvalidData: + return InvalidConfigDataReturned; + case HOST_GETCONFIG_BuffOverflow: + return DescriptorTooLarge; + default: + return ControlError; + } + + while (!(DataOUTEndpoint)) + { + /* See if we've found a likely compatible interface, and if there is an endpoint within that interface */ + if (!(AudioControlInterface) || + USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextAudioInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) + { + /* Check if we haven't found an Audio Control interface yet, or if we have run out of related Audio Streaming interfaces */ + if (!(AudioControlInterface) || + USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextAudioStreamInterface) != DESCRIPTOR_SEARCH_COMP_Found) + { + /* Find a new Audio Control interface if the current one doesn't contain a compatible streaming interface */ + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextAudioControlInterface) != DESCRIPTOR_SEARCH_COMP_Found) + { + /* Descriptor not found, error out */ + return NoCompatibleInterfaceFound; + } + + /* Save the interface in case we need to refer back to it later */ + AudioControlInterface = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t); + + /* Find the next Audio Streaming interface within that Audio Control interface */ + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextAudioStreamInterface) != DESCRIPTOR_SEARCH_COMP_Found) + { + /* Descriptor not found, error out */ + return NoCompatibleInterfaceFound; + } + } + + /* Save the interface in case we need to refer back to it later */ + AudioStreamingInterface = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t); + + /* Skip the remainder of the loop as we have not found an endpoint yet */ + continue; + } + + /* Retrieve the endpoint address from the endpoint descriptor */ + USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t); + + /* Save the endpoint if it is an OUT type endpoint */ + if (!(EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN)) + DataOUTEndpoint = EndpointData; + } + + StreamingInterfaceIndex = AudioStreamingInterface->InterfaceNumber; + StreamingInterfaceAltSetting = AudioStreamingInterface->AlternateSetting; + StreamingEndpointAddress = DataOUTEndpoint->EndpointAddress; + + /* Configure the Audio data OUT pipe */ + Pipe_ConfigurePipe(AUDIO_DATA_OUT_PIPE, EP_TYPE_ISOCHRONOUS, PIPE_TOKEN_OUT, + DataOUTEndpoint->EndpointAddress, DataOUTEndpoint->EndpointSize, PIPE_BANK_DOUBLE); + + /* Valid data found, return success */ + return SuccessfulConfigRead; +} + +/** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's + * configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration + * descriptor processing if an incompatible descriptor configuration is found. + * + * This comparator searches for the next Interface descriptor of the correct Audio Control Class, Subclass and Protocol values. + * + * \return A value from the DSEARCH_Return_ErrorCodes_t enum + */ +uint8_t DComp_NextAudioControlInterface(void* CurrentDescriptor) +{ + USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t); + + if (Header->Type == DTYPE_Interface) + { + USB_Descriptor_Interface_t* Interface = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Interface_t); + + if ((Interface->Class == AUDIO_CSCP_AudioClass) && + (Interface->SubClass == AUDIO_CSCP_ControlSubclass) && + (Interface->Protocol == AUDIO_CSCP_ControlProtocol)) + { + return DESCRIPTOR_SEARCH_Found; + } + } + + return DESCRIPTOR_SEARCH_NotFound; +} + +/** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's + * configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration + * descriptor processing if an incompatible descriptor configuration is found. + * + * This comparator searches for the next Interface descriptor of the correct Audio Streaming Class, Subclass and Protocol values. + * + * \return A value from the DSEARCH_Return_ErrorCodes_t enum + */ +uint8_t DComp_NextAudioStreamInterface(void* CurrentDescriptor) +{ + USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t); + + if (Header->Type == DTYPE_Interface) + { + USB_Descriptor_Interface_t* Interface = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Interface_t); + + if ((Interface->Class == AUDIO_CSCP_AudioClass) && + (Interface->SubClass == AUDIO_CSCP_AudioStreamingSubclass) && + (Interface->Protocol == AUDIO_CSCP_StreamingProtocol)) + { + return DESCRIPTOR_SEARCH_Found; + } + } + + return DESCRIPTOR_SEARCH_NotFound; +} + +/** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's + * configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration + * descriptor processing if an incompatible descriptor configuration is found. + * + * This comparator searches for the next Isochronous Endpoint descriptor within the current interface, aborting the + * search if another interface descriptor is found before the next endpoint. + * + * \return A value from the DSEARCH_Return_ErrorCodes_t enum + */ +uint8_t DComp_NextAudioInterfaceDataEndpoint(void* CurrentDescriptor) +{ + USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t); + + if (Header->Type == DTYPE_Endpoint) + { + USB_Descriptor_Endpoint_t* Endpoint = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Endpoint_t); + + if ((Endpoint->Attributes & EP_TYPE_MASK) == EP_TYPE_ISOCHRONOUS) + return DESCRIPTOR_SEARCH_Found; + } + else if (Header->Type == DTYPE_Interface) + { + return DESCRIPTOR_SEARCH_Fail; + } + + return DESCRIPTOR_SEARCH_NotFound; +} diff --git a/Demos/Host/Incomplete/AudioOutputHost/ConfigDescriptor.h b/Demos/Host/Incomplete/AudioOutputHost/ConfigDescriptor.h new file mode 100644 index 0000000000..c952a2813a --- /dev/null +++ b/Demos/Host/Incomplete/AudioOutputHost/ConfigDescriptor.h @@ -0,0 +1,72 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2011. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * Header file for ConfigDescriptor.c. + */ + +#ifndef _CONFIGDESCRIPTOR_H_ +#define _CONFIGDESCRIPTOR_H_ + + /* Includes: */ + #include + + #include "AudioOutputHost.h" + + /* Macros: */ + /** Pipe number for the Audio data OUT pipe. */ + #define AUDIO_DATA_OUT_PIPE 1 + + /* Enums: */ + /** Enum for the possible return codes of the \ref ProcessConfigurationDescriptor() function. */ + enum KeyboardHost_GetConfigDescriptorDataCodes_t + { + SuccessfulConfigRead = 0, /**< Configuration Descriptor was processed successfully */ + ControlError = 1, /**< A control request to the device failed to complete successfully */ + DescriptorTooLarge = 2, /**< The device's Configuration Descriptor is too large to process */ + InvalidConfigDataReturned = 3, /**< The device returned an invalid Configuration Descriptor */ + NoCompatibleInterfaceFound = 4, /**< A compatible interface with the required endpoints was not found */ + }; + + /* External Variables: */ + extern uint8_t StreamingInterfaceIndex; + extern uint8_t StreamingInterfaceAltSetting; + extern uint8_t StreamingEndpointAddress; + + /* Function Prototypes: */ + uint8_t ProcessConfigurationDescriptor(void); + + uint8_t DComp_NextAudioControlInterface(void* CurrentDescriptor); + uint8_t DComp_NextAudioStreamInterface(void* CurrentDescriptor); + uint8_t DComp_NextAudioInterfaceDataEndpoint(void* CurrentDescriptor); + +#endif + diff --git a/Demos/Host/Incomplete/AudioOutputHost/makefile b/Demos/Host/Incomplete/AudioOutputHost/makefile new file mode 100644 index 0000000000..2a9e8d03a1 --- /dev/null +++ b/Demos/Host/Incomplete/AudioOutputHost/makefile @@ -0,0 +1,714 @@ +# Hey Emacs, this is a -*- makefile -*- +#---------------------------------------------------------------------------- +# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al. +# >> Modified for use with the LUFA project. << +# +# Released to the Public Domain +# +# Additional material for this makefile was written by: +# Peter Fleury +# Tim Henigan +# Colin O'Flynn +# Reiner Patommel +# Markus Pfaff +# Sander Pool +# Frederik Rouleau +# Carlos Lamas +# Dean Camera +# Opendous Inc. +# Denver Gingerich +# +#---------------------------------------------------------------------------- +# On command line: +# +# make all = Make software. +# +# make clean = Clean out built project files. +# +# make coff = Convert ELF to AVR COFF. +# +# make extcoff = Convert ELF to AVR Extended COFF. +# +# make program = Download the hex file to the device, using avrdude. +# Please customize the avrdude settings below first! +# +# make dfu = Download the hex file to the device, using dfu-programmer (must +# have dfu-programmer installed). +# +# make flip = Download the hex file to the device, using Atmel FLIP (must +# have Atmel FLIP installed). +# +# make dfu-ee = Download the eeprom file to the device, using dfu-programmer +# (must have dfu-programmer installed). +# +# make flip-ee = Download the eeprom file to the device, using Atmel FLIP +# (must have Atmel FLIP installed). +# +# make doxygen = Generate DoxyGen documentation for the project (must have +# DoxyGen installed) +# +# make debug = Start either simulavr or avarice as specified for debugging, +# with avr-gdb or avr-insight as the front end for debugging. +# +# make filename.s = Just compile filename.c into the assembler code only. +# +# make filename.i = Create a preprocessed source file for use in submitting +# bug reports to the GCC project. +# +# To rebuild project do "make clean" then "make all". +#---------------------------------------------------------------------------- + + +# MCU name +MCU = at90usb1287 + + +# Target architecture (see library "Board Types" documentation). +ARCH = AVR8 + + +# Target board (see library "Board Types" documentation, NONE for projects not requiring +# LUFA board drivers). If USER is selected, put custom board drivers in a directory called +# "Board" inside the application directory. +BOARD = USBKEY + + +# Processor frequency. +# This will define a symbol, F_CPU, in all source code files equal to the +# processor frequency in Hz. You can then use this symbol in your source code to +# calculate timings. Do NOT tack on a 'UL' at the end, this will be done +# automatically to create a 32-bit value in your source code. +# +# This will be an integer division of F_USB below, as it is sourced by +# F_USB after it has run through any CPU prescalers. Note that this value +# does not *change* the processor frequency - it should merely be updated to +# reflect the processor speed set externally so that the code can use accurate +# software delays. +F_CPU = 8000000 + + +# Input clock frequency. +# This will define a symbol, F_USB, in all source code files equal to the +# input clock frequency (before any prescaling is performed) in Hz. This value may +# differ from F_CPU if prescaling is used on the latter, and is required as the +# raw input clock is fed directly to the PLL sections of the AVR for high speed +# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL' +# at the end, this will be done automatically to create a 32-bit value in your +# source code. +# +# If no clock division is performed on the input clock inside the AVR (via the +# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU. +F_USB = $(F_CPU) + + +# Output format. (can be srec, ihex, binary) +FORMAT = ihex + + +# Target file name (without extension). +TARGET = AudioOutputHost + + +# Object files directory +# To put object files in current directory, use a dot (.), do NOT make +# this an empty or blank macro! +OBJDIR = . + + +# Path to the LUFA library +LUFA_PATH = ../../../.. + + +# LUFA library compile-time options and predefined tokens +LUFA_OPTS = -D USB_HOST_ONLY +LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" + + +# Create the LUFA source path variables by including the LUFA root makefile +include $(LUFA_PATH)/LUFA/makefile + + +# List C source files here. (C dependencies are automatically generated.) +SRC = $(TARGET).c \ + ConfigDescriptor.c \ + $(LUFA_SRC_USB) \ + $(LUFA_SRC_SERIAL) + + +# List C++ source files here. (C dependencies are automatically generated.) +CPPSRC = + + +# List Assembler source files here. +# Make them always end in a capital .S. Files ending in a lowercase .s +# will not be considered source files but generated files (assembler +# output from the compiler), and will be deleted upon "make clean"! +# Even though the DOS/Win* filesystem matches both .s and .S the same, +# it will preserve the spelling of the filenames, and gcc itself does +# care about how the name is spelled on its command-line. +ASRC = + + +# Optimization level, can be [0, 1, 2, 3, s]. +# 0 = turn off optimization. s = optimize for size. +# (Note: 3 is not always the best optimization level. See avr-libc FAQ.) +OPT = s + + +# Debugging format. +# Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs. +# AVR Studio 4.10 requires dwarf-2. +# AVR [Extended] COFF format requires stabs, plus an avr-objcopy run. +DEBUG = dwarf-2 + + +# List any extra directories to look for include files here. +# Each directory must be seperated by a space. +# Use forward slashes for directory separators. +# For a directory that has spaces, enclose it in quotes. +EXTRAINCDIRS = $(LUFA_PATH)/ + + +# Compiler flag to set the C Standard level. +# c89 = "ANSI" C +# gnu89 = c89 plus GCC extensions +# c99 = ISO C99 standard (not yet fully implemented) +# gnu99 = c99 plus GCC extensions +CSTANDARD = -std=c99 + + +# Place -D or -U options here for C sources +CDEFS = -DF_CPU=$(F_CPU)UL +CDEFS += -DF_USB=$(F_USB)UL +CDEFS += -DBOARD=BOARD_$(BOARD) -DARCH=ARCH_$(ARCH) +CDEFS += $(LUFA_OPTS) + + +# Place -D or -U options here for ASM sources +ADEFS = -DF_CPU=$(F_CPU) +ADEFS += -DF_USB=$(F_USB)UL +ADEFS += -DBOARD=BOARD_$(BOARD) +ADEFS += $(LUFA_OPTS) + +# Place -D or -U options here for C++ sources +CPPDEFS = -DF_CPU=$(F_CPU)UL +CPPDEFS += -DF_USB=$(F_USB)UL +CPPDEFS += -DBOARD=BOARD_$(BOARD) +CPPDEFS += $(LUFA_OPTS) +#CPPDEFS += -D__STDC_LIMIT_MACROS +#CPPDEFS += -D__STDC_CONSTANT_MACROS + + + +#---------------- Compiler Options C ---------------- +# -g*: generate debugging information +# -O*: optimization level +# -f...: tuning, see GCC manual and avr-libc documentation +# -Wall...: warning level +# -Wa,...: tell GCC to pass this to the assembler. +# -adhlns...: create assembler listing +CFLAGS = -g$(DEBUG) +CFLAGS += $(CDEFS) +CFLAGS += -O$(OPT) +CFLAGS += -funsigned-char +CFLAGS += -funsigned-bitfields +CFLAGS += -ffunction-sections +CFLAGS += -fno-inline-small-functions +CFLAGS += -fpack-struct +CFLAGS += -fshort-enums +CFLAGS += -fno-strict-aliasing +CFLAGS += -Wall +CFLAGS += -Wstrict-prototypes +#CFLAGS += -mshort-calls +#CFLAGS += -fno-unit-at-a-time +#CFLAGS += -Wundef +#CFLAGS += -Wunreachable-code +#CFLAGS += -Wsign-compare +CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst) +CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) +CFLAGS += $(CSTANDARD) + + +#---------------- Compiler Options C++ ---------------- +# -g*: generate debugging information +# -O*: optimization level +# -f...: tuning, see GCC manual and avr-libc documentation +# -Wall...: warning level +# -Wa,...: tell GCC to pass this to the assembler. +# -adhlns...: create assembler listing +CPPFLAGS = -g$(DEBUG) +CPPFLAGS += $(CPPDEFS) +CPPFLAGS += -O$(OPT) +CPPFLAGS += -funsigned-char +CPPFLAGS += -funsigned-bitfields +CPPFLAGS += -fpack-struct +CPPFLAGS += -fshort-enums +CPPFLAGS += -fno-exceptions +CPPFLAGS += -Wall +CPPFLAGS += -Wundef +#CPPFLAGS += -mshort-calls +#CPPFLAGS += -fno-unit-at-a-time +#CPPFLAGS += -Wstrict-prototypes +#CPPFLAGS += -Wunreachable-code +#CPPFLAGS += -Wsign-compare +CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst) +CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) +#CPPFLAGS += $(CSTANDARD) + + +#---------------- Assembler Options ---------------- +# -Wa,...: tell GCC to pass this to the assembler. +# -adhlns: create listing +# -gstabs: have the assembler create line number information; note that +# for use in COFF files, additional information about filenames +# and function names needs to be present in the assembler source +# files -- see avr-libc docs [FIXME: not yet described there] +# -listing-cont-lines: Sets the maximum number of continuation lines of hex +# dump that will be displayed for a given single line of source input. +ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100 + + +#---------------- Library Options ---------------- +# Minimalistic printf version +PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min + +# Floating point printf version (requires MATH_LIB = -lm below) +PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt + +# If this is left blank, then it will use the Standard printf version. +PRINTF_LIB = +#PRINTF_LIB = $(PRINTF_LIB_MIN) +#PRINTF_LIB = $(PRINTF_LIB_FLOAT) + + +# Minimalistic scanf version +SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min + +# Floating point + %[ scanf version (requires MATH_LIB = -lm below) +SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt + +# If this is left blank, then it will use the Standard scanf version. +SCANF_LIB = +#SCANF_LIB = $(SCANF_LIB_MIN) +#SCANF_LIB = $(SCANF_LIB_FLOAT) + + +MATH_LIB = -lm + + +# List any extra directories to look for libraries here. +# Each directory must be seperated by a space. +# Use forward slashes for directory separators. +# For a directory that has spaces, enclose it in quotes. +EXTRALIBDIRS = + + + +#---------------- External Memory Options ---------------- + +# 64 KB of external RAM, starting after internal RAM (ATmega128!), +# used for variables (.data/.bss) and heap (malloc()). +#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff + +# 64 KB of external RAM, starting after internal RAM (ATmega128!), +# only used for heap (malloc()). +#EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff + +EXTMEMOPTS = + + + +#---------------- Linker Options ---------------- +# -Wl,...: tell GCC to pass this to linker. +# -Map: create map file +# --cref: add cross reference to map file +LDFLAGS = -Wl,-Map=$(TARGET).map,--cref +LDFLAGS += -Wl,--relax +LDFLAGS += -Wl,--gc-sections +LDFLAGS += $(EXTMEMOPTS) +LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS)) +LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) +#LDFLAGS += -T linker_script.x + + + +#---------------- Programming Options (avrdude) ---------------- + +# Programming hardware +# Type: avrdude -c ? +# to get a full listing. +# +AVRDUDE_PROGRAMMER = jtagmkII + +# com1 = serial port. Use lpt1 to connect to parallel port. +AVRDUDE_PORT = usb + +AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex +#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep + + +# Uncomment the following if you want avrdude's erase cycle counter. +# Note that this counter needs to be initialized first using -Yn, +# see avrdude manual. +#AVRDUDE_ERASE_COUNTER = -y + +# Uncomment the following if you do /not/ wish a verification to be +# performed after programming the device. +#AVRDUDE_NO_VERIFY = -V + +# Increase verbosity level. Please use this when submitting bug +# reports about avrdude. See +# to submit bug reports. +#AVRDUDE_VERBOSE = -v -v + +AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) +AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY) +AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE) +AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER) + + + +#---------------- Debugging Options ---------------- + +# For simulavr only - target MCU frequency. +DEBUG_MFREQ = $(F_CPU) + +# Set the DEBUG_UI to either gdb or insight. +# DEBUG_UI = gdb +DEBUG_UI = insight + +# Set the debugging back-end to either avarice, simulavr. +DEBUG_BACKEND = avarice +#DEBUG_BACKEND = simulavr + +# GDB Init Filename. +GDBINIT_FILE = __avr_gdbinit + +# When using avarice settings for the JTAG +JTAG_DEV = /dev/com1 + +# Debugging port used to communicate between GDB / avarice / simulavr. +DEBUG_PORT = 4242 + +# Debugging host used to communicate between GDB / avarice / simulavr, normally +# just set to localhost unless doing some sort of crazy debugging when +# avarice is running on a different computer. +DEBUG_HOST = localhost + + + +#============================================================================ + + +# Define programs and commands. +SHELL = sh +CC = avr-gcc +OBJCOPY = avr-objcopy +OBJDUMP = avr-objdump +SIZE = avr-size +AR = avr-ar rcs +NM = avr-nm +AVRDUDE = avrdude +REMOVE = rm -f +REMOVEDIR = rm -rf +COPY = cp +WINSHELL = cmd + + +# Define Messages +# English +MSG_ERRORS_NONE = Errors: none +MSG_BEGIN = -------- begin -------- +MSG_END = -------- end -------- +MSG_SIZE_BEFORE = Size before: +MSG_SIZE_AFTER = Size after: +MSG_COFF = Converting to AVR COFF: +MSG_EXTENDED_COFF = Converting to AVR Extended COFF: +MSG_FLASH = Creating load file for Flash: +MSG_EEPROM = Creating load file for EEPROM: +MSG_EXTENDED_LISTING = Creating Extended Listing: +MSG_SYMBOL_TABLE = Creating Symbol Table: +MSG_LINKING = Linking: +MSG_COMPILING = Compiling C: +MSG_COMPILING_CPP = Compiling C++: +MSG_ASSEMBLING = Assembling: +MSG_CLEANING = Cleaning project: +MSG_CREATING_LIBRARY = Creating library: + + + + +# Define all object files. +OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o) + +# Define all listing files. +LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst) + + +# Compiler flags to generate dependency files. +GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d + + +# Combine all necessary flags and optional flags. +# Add target processor to flags. +ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS) +ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS) +ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) + + + + + +# Default target. +all: begin gccversion sizebefore build sizeafter end + +# Change the build target to build a HEX file or a library. +build: elf hex eep lss sym +#build: lib + + +elf: $(TARGET).elf +hex: $(TARGET).hex +eep: $(TARGET).eep +lss: $(TARGET).lss +sym: $(TARGET).sym +LIBNAME=lib$(TARGET).a +lib: $(LIBNAME) + + + +# Eye candy. +# AVR Studio 3.x does not check make's exit code but relies on +# the following magic strings to be generated by the compile job. +begin: + @echo + @echo $(MSG_BEGIN) + +end: + @echo $(MSG_END) + @echo + + +# Display size of file. +HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex +ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf +MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) ) +FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr ) + + +sizebefore: + @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \ + 2>/dev/null; echo; fi + +sizeafter: + @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \ + 2>/dev/null; echo; fi + + + +# Display compiler version information. +gccversion : + @$(CC) --version + + +# Program the device. +program: $(TARGET).hex $(TARGET).eep + $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) + +flip: $(TARGET).hex + batchisp -hardware usb -device $(MCU) -operation erase f + batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program + batchisp -hardware usb -device $(MCU) -operation start reset 0 + +dfu: $(TARGET).hex + dfu-programmer $(MCU) erase + dfu-programmer $(MCU) flash $(TARGET).hex + dfu-programmer $(MCU) reset + +flip-ee: $(TARGET).hex $(TARGET).eep + $(COPY) $(TARGET).eep $(TARGET)eep.hex + batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase + batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $(TARGET)eep.hex program + batchisp -hardware usb -device $(MCU) -operation start reset 0 + $(REMOVE) $(TARGET)eep.hex + +dfu-ee: $(TARGET).hex $(TARGET).eep + dfu-programmer $(MCU) eeprom-flash $(TARGET).eep + dfu-programmer $(MCU) reset + + +# Generate avr-gdb config/init file which does the following: +# define the reset signal, load the target file, connect to target, and set +# a breakpoint at main(). +gdb-config: + @$(REMOVE) $(GDBINIT_FILE) + @echo define reset >> $(GDBINIT_FILE) + @echo SIGNAL SIGHUP >> $(GDBINIT_FILE) + @echo end >> $(GDBINIT_FILE) + @echo file $(TARGET).elf >> $(GDBINIT_FILE) + @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE) +ifeq ($(DEBUG_BACKEND),simulavr) + @echo load >> $(GDBINIT_FILE) +endif + @echo break main >> $(GDBINIT_FILE) + +debug: gdb-config $(TARGET).elf +ifeq ($(DEBUG_BACKEND), avarice) + @echo Starting AVaRICE - Press enter when "waiting to connect" message displays. + @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \ + $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT) + @$(WINSHELL) /c pause + +else + @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \ + $(DEBUG_MFREQ) --port $(DEBUG_PORT) +endif + @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE) + + + + +# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. +COFFCONVERT = $(OBJCOPY) --debugging +COFFCONVERT += --change-section-address .data-0x800000 +COFFCONVERT += --change-section-address .bss-0x800000 +COFFCONVERT += --change-section-address .noinit-0x800000 +COFFCONVERT += --change-section-address .eeprom-0x810000 + + + +coff: $(TARGET).elf + @echo + @echo $(MSG_COFF) $(TARGET).cof + $(COFFCONVERT) -O coff-avr $< $(TARGET).cof + + +extcoff: $(TARGET).elf + @echo + @echo $(MSG_EXTENDED_COFF) $(TARGET).cof + $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof + + + +# Create final output files (.hex, .eep) from ELF output file. +%.hex: %.elf + @echo + @echo $(MSG_FLASH) $@ + $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock $< $@ + +%.eep: %.elf + @echo + @echo $(MSG_EEPROM) $@ + -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ + --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0 + +# Create extended listing file from ELF output file. +%.lss: %.elf + @echo + @echo $(MSG_EXTENDED_LISTING) $@ + $(OBJDUMP) -h -S -z $< > $@ + +# Create a symbol table from ELF output file. +%.sym: %.elf + @echo + @echo $(MSG_SYMBOL_TABLE) $@ + $(NM) -n $< > $@ + + + +# Create library from object files. +.SECONDARY : $(TARGET).a +.PRECIOUS : $(OBJ) +%.a: $(OBJ) + @echo + @echo $(MSG_CREATING_LIBRARY) $@ + $(AR) $@ $(OBJ) + + +# Link: create ELF output file from object files. +.SECONDARY : $(TARGET).elf +.PRECIOUS : $(OBJ) +%.elf: $(OBJ) + @echo + @echo $(MSG_LINKING) $@ + $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS) + + +# Compile: create object files from C source files. +$(OBJDIR)/%.o : %.c + @echo + @echo $(MSG_COMPILING) $< + $(CC) -c $(ALL_CFLAGS) $< -o $@ + + +# Compile: create object files from C++ source files. +$(OBJDIR)/%.o : %.cpp + @echo + @echo $(MSG_COMPILING_CPP) $< + $(CC) -c $(ALL_CPPFLAGS) $< -o $@ + + +# Compile: create assembler files from C source files. +%.s : %.c + $(CC) -S $(ALL_CFLAGS) $< -o $@ + + +# Compile: create assembler files from C++ source files. +%.s : %.cpp + $(CC) -S $(ALL_CPPFLAGS) $< -o $@ + + +# Assemble: create object files from assembler source files. +$(OBJDIR)/%.o : %.S + @echo + @echo $(MSG_ASSEMBLING) $< + $(CC) -c $(ALL_ASFLAGS) $< -o $@ + + +# Create preprocessed source for use in sending a bug report. +%.i : %.c + $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@ + + +# Target: clean project. +clean: begin clean_list end + +clean_list : + @echo + @echo $(MSG_CLEANING) + $(REMOVE) $(TARGET).hex + $(REMOVE) $(TARGET).eep + $(REMOVE) $(TARGET).cof + $(REMOVE) $(TARGET).elf + $(REMOVE) $(TARGET).map + $(REMOVE) $(TARGET).sym + $(REMOVE) $(TARGET).lss + $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o) + $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst) + $(REMOVE) $(SRC:.c=.s) + $(REMOVE) $(SRC:.c=.d) + $(REMOVE) $(SRC:.c=.i) + $(REMOVEDIR) .dep + +doxygen: + @echo Generating Project Documentation... + @doxygen Doxygen.conf + @echo Documentation Generation Complete. + +clean_doxygen: + rm -rf Documentation + +# Create object files directory +$(shell mkdir $(OBJDIR) 2>/dev/null) + + +# Include the dependency files. +-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*) + + +# Listing of phony targets. +.PHONY : all begin finish end sizebefore sizeafter gccversion \ +build elf hex eep lss sym coff extcoff doxygen clean \ +clean_list clean_doxygen program dfu flip flip-ee dfu-ee \ +debug gdb-config + diff --git a/LUFA.pnproj b/LUFA.pnproj index 8b0155b272..3f9ec0eed8 100644 --- a/LUFA.pnproj +++ b/LUFA.pnproj @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/LUFA/Drivers/USB/Class/Device/CDC.h b/LUFA/Drivers/USB/Class/Device/CDC.h index b2d148da38..6f78a24ddd 100644 --- a/LUFA/Drivers/USB/Class/Device/CDC.h +++ b/LUFA/Drivers/USB/Class/Device/CDC.h @@ -338,6 +338,7 @@ #endif void CDC_Device_Event_Stub(void) ATTR_CONST; + void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo) ATTR_WEAK ATTR_NON_NULL_PTR_ARG(1) ATTR_ALIAS(CDC_Device_Event_Stub); void EVENT_CDC_Device_ControLineStateChanged(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo) diff --git a/LUFA/ManPages/ChangeLog.txt b/LUFA/ManPages/ChangeLog.txt index c4fe713e83..ecbabad5de 100644 --- a/LUFA/ManPages/ChangeLog.txt +++ b/LUFA/ManPages/ChangeLog.txt @@ -18,6 +18,7 @@ * - Added new MediaControl project * - Added new incomplete AndroidAccessoryHost Host LowLevel demo * - Added new incomplete AudioInputHost Host LowLevel demo + * - Added new incomplete AudioOutputHost Host LowLevel demo * * Changed: * - Core: