diff --git a/Demos/Device/Incomplete/Sideshow/Descriptors.c b/Demos/Device/Incomplete/Sideshow/Descriptors.c new file mode 100644 index 0000000000..5691d456e2 --- /dev/null +++ b/Demos/Device/Incomplete/Sideshow/Descriptors.c @@ -0,0 +1,238 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, 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. +*/ + +#include "Descriptors.h" + +USB_Descriptor_Device_t PROGMEM DeviceDescriptor = +{ + Header: {Size: sizeof(USB_Descriptor_Device_t), Type: DTYPE_Device}, + + USBSpecification: VERSION_BCD(02.00), + Class: 0x00, + SubClass: 0x00, + Protocol: 0x00, + + Endpoint0Size: 8, + + VendorID: 0x03EB, + ProductID: 0xDC03, + ReleaseNumber: 0x0000, + + ManufacturerStrIndex: 0x01, + ProductStrIndex: 0x02, + SerialNumStrIndex: 0x03, + + NumberOfConfigurations: 1 +}; + +USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = +{ + Config: + { + Header: {Size: sizeof(USB_Descriptor_Configuration_Header_t), Type: DTYPE_Configuration}, + + TotalConfigurationSize: sizeof(USB_Descriptor_Configuration_t), + TotalInterfaces: 1, + + ConfigurationNumber: 1, + ConfigurationStrIndex: NO_DESCRIPTOR, + + ConfigAttributes: (USB_CONFIG_ATTR_BUSPOWERED | USB_CONFIG_ATTR_SELFPOWERED), + + MaxPowerConsumption: USB_CONFIG_POWER_MA(100) + }, + + Interface: + { + Header: {Size: sizeof(USB_Descriptor_Interface_t), Type: DTYPE_Interface}, + + InterfaceNumber: 0, + AlternateSetting: 0, + + TotalEndpoints: 2, + + Class: 0xFF, + SubClass: 0x00, + Protocol: 0x00, + + InterfaceStrIndex: NO_DESCRIPTOR + }, + + DataInEndpoint: + { + Header: {Size: sizeof(USB_Descriptor_Endpoint_t), Type: DTYPE_Endpoint}, + + EndpointAddress: (ENDPOINT_DESCRIPTOR_DIR_IN | SIDESHOW_IN_EPNUM), + Attributes: EP_TYPE_BULK, + EndpointSize: SIDESHOW_IO_EPSIZE, + PollingIntervalMS: 0x00 + }, + + DataOutEndpoint: + { + Header: {Size: sizeof(USB_Descriptor_Endpoint_t), Type: DTYPE_Endpoint}, + + EndpointAddress: (ENDPOINT_DESCRIPTOR_DIR_OUT | SIDESHOW_OUT_EPNUM), + Attributes: EP_TYPE_BULK, + EndpointSize: SIDESHOW_IO_EPSIZE, + PollingIntervalMS: 0x00 + } +}; + +USB_Descriptor_String_t PROGMEM LanguageString = +{ + Header: {Size: USB_STRING_LEN(1), Type: DTYPE_String}, + + UnicodeString: {LANGUAGE_ID_ENG} +}; + +USB_Descriptor_String_t PROGMEM ManufacturerString = +{ + Header: {Size: USB_STRING_LEN(11), Type: DTYPE_String}, + + UnicodeString: L"Dean Camera" +}; + +USB_Descriptor_String_t PROGMEM ProductString = +{ + Header: {Size: USB_STRING_LEN(22), Type: DTYPE_String}, + + UnicodeString: L"LUFA Sideshow Demo" +}; + +USB_Descriptor_String_t PROGMEM SerialNumberString = +{ + Header: {Size: USB_STRING_LEN(12), Type: DTYPE_String}, + + UnicodeString: L"000000000000" +}; + +USB_OSDescriptor_t PROGMEM OSDescriptorString = +{ + Header: {Size: sizeof(USB_OSDescriptor_t), Type: DTYPE_String}, + + Signature: L"MSFT100", + VendorCode: REQ_GetOSFeatureDescriptor +}; + +USB_OSCompatibleIDDescriptor_t PROGMEM DevCompatIDs = +{ + TotalLength: sizeof(USB_OSCompatibleIDDescriptor_t), + Version: 0x0100, + Index: EXTENDED_COMPAT_ID_DESCRIPTOR, + TotalSections: 1, + + SideshowCompatID: {FirstInterfaceNumber: 0x00, + CompatibleID: "SIDESHW", + SubCompatibleID: "UNIV1"} +}; + +uint16_t USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, void** const DescriptorAddress) +{ + const uint8_t DescriptorType = (wValue >> 8); + const uint8_t DescriptorNumber = (wValue & 0xFF); + + void* Address = NULL; + uint16_t Size = NO_DESCRIPTOR; + + switch (DescriptorType) + { + case DTYPE_Device: + Address = DESCRIPTOR_ADDRESS(DeviceDescriptor); + Size = sizeof(USB_Descriptor_Device_t); + break; + case DTYPE_Configuration: + Address = DESCRIPTOR_ADDRESS(ConfigurationDescriptor); + Size = sizeof(USB_Descriptor_Configuration_t); + break; + case DTYPE_String: + switch (DescriptorNumber) + { + case 0x00: + Address = DESCRIPTOR_ADDRESS(LanguageString); + Size = pgm_read_byte(&LanguageString.Header.Size); + break; + case 0x01: + Address = DESCRIPTOR_ADDRESS(ManufacturerString); + Size = pgm_read_byte(&ManufacturerString.Header.Size); + break; + case 0x02: + Address = DESCRIPTOR_ADDRESS(ProductString); + Size = pgm_read_byte(&ProductString.Header.Size); + break; + case 0x03: + Address = DESCRIPTOR_ADDRESS(SerialNumberString); + Size = pgm_read_byte(&SerialNumberString.Header.Size); + break; + case 0xEE: + /* Great, another Microsoft-proprietary extention. String address 0xEE is used + by Windows for "OS Descriptors", which in this case allows us to indicate that + our device is Sideshow compatible. Most people would be happy using the normal + 0xFF 0x?? 0x?? Class/Subclass/Protocol values like the USBIF intended. */ + + Address = DESCRIPTOR_ADDRESS(OSDescriptorString); + Size = pgm_read_byte(&OSDescriptorString.Header.Size); + break; + } + + break; + } + + *DescriptorAddress = Address; + return Size; +} + +bool USB_GetOSFeatureDescriptor(const uint16_t wValue, const uint8_t wIndex, + void** const DescriptorAddress, uint16_t* const DescriptorSize) +{ + void* Address = NULL; + uint16_t Size = 0; + + /* Check if a device level OS feature descriptor is being requested */ + if (wValue == 0x0000) + { + /* Only the Extended Device Compatibility descriptor is supported */ + if (wIndex == EXTENDED_COMPAT_ID_DESCRIPTOR) + { + Address = DESCRIPTOR_ADDRESS(DevCompatIDs); + Size = sizeof(USB_OSCompatibleIDDescriptor_t); + } + } + + if (Address != NULL) + { + *DescriptorAddress = Address; + *DescriptorSize = Size; + + return true; + } + + return false; +} \ No newline at end of file diff --git a/Demos/Device/Incomplete/Sideshow/Descriptors.h b/Demos/Device/Incomplete/Sideshow/Descriptors.h new file mode 100644 index 0000000000..f12ef81f1f --- /dev/null +++ b/Demos/Device/Incomplete/Sideshow/Descriptors.h @@ -0,0 +1,95 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, 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. +*/ + +#ifndef _DESCRIPTORS_H_ +#define _DESCRIPTORS_H_ + + /* Includes: */ + #include + + #include + + #include "Sideshow.h" + + /* Macros: */ + #define SIDESHOW_IN_EPNUM 3 + #define SIDESHOW_OUT_EPNUM 4 + #define SIDESHOW_IO_EPSIZE 64 + + /* Type Defines: */ + typedef struct + { + USB_Descriptor_Configuration_Header_t Config; + USB_Descriptor_Interface_t Interface; + USB_Descriptor_Endpoint_t DataInEndpoint; + USB_Descriptor_Endpoint_t DataOutEndpoint; + } USB_Descriptor_Configuration_t; + + typedef struct + { + USB_Descriptor_Header_t Header; + + int Signature[7]; + uint16_t VendorCode; + } USB_OSDescriptor_t; + + typedef struct + { + uint8_t FirstInterfaceNumber; + + uint8_t RESERVED; + + uint8_t CompatibleID[8]; + uint8_t SubCompatibleID[8]; + + uint8_t RESERVED2[6]; + } USB_OSCompatibleSection_t; + + typedef struct + { + uint32_t TotalLength; + uint16_t Version; + uint16_t Index; + uint8_t TotalSections; + + uint8_t RESERVED[7]; + + USB_OSCompatibleSection_t SideshowCompatID; + } USB_OSCompatibleIDDescriptor_t; + + /* Function Prototypes: */ + uint16_t USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, void** const DescriptorAddress) + ATTR_WARN_UNUSED_RESULT ATTR_WEAK ATTR_NON_NULL_PTR_ARG(3); + + bool USB_GetOSFeatureDescriptor(const uint16_t wValue, const uint8_t wIndex, + void** const DescriptorAddress, uint16_t* const DescriptorSize) + ATTR_WARN_UNUSED_RESULT ATTR_WEAK ATTR_NON_NULL_PTR_ARG(3, 4); + +#endif diff --git a/Demos/Device/Incomplete/Sideshow/Sideshow.c b/Demos/Device/Incomplete/Sideshow/Sideshow.c new file mode 100644 index 0000000000..c963359824 --- /dev/null +++ b/Demos/Device/Incomplete/Sideshow/Sideshow.c @@ -0,0 +1,221 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, 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. +*/ + +/* + SideShow Class demonstration application. This give a reference + for implementing Microsoft SideShow compatible devices in an + embedded environment. SideShow allows for gadget data displayed + on a Vista machine to also be displayed on an externally connected + interactive display. Upon enumeration on a Vista system, this will + appear as a new SideShow device which can have gadgets loaded onto + it. + + Note that while the incomming content is buffered in packet struct + form, the data is not actually displayed. It is left to the user to + write sufficient code to read out the packed data for display to a + screen. + + Installed gadgets can be accessed through the InstalledApplications + array, with entries that have their InUse flag set being active. As + only the active content is displayed on the device due to memory + constraints, new content can be requested as needed. +*/ + +/* + USB Mode: Device + USB Class: Sideshow Device (Microsoft Only) + USB Subclass: Bulk Only + Relevant Standards: Microsoft Sideshow Specification + Microsoft OS Descriptors Specification + XML Specification + Usable Speeds: Full Speed Mode +*/ + +#include "Sideshow.h" + +/* Project Tags, for reading out using the ButtLoad project */ +BUTTLOADTAG(ProjName, "LUFA Sideshow App"); +BUTTLOADTAG(BuildTime, __TIME__); +BUTTLOADTAG(BuildDate, __DATE__); +BUTTLOADTAG(LUFAVersion, "LUFA V" LUFA_VERSION_STRING); + +/* Scheduler Task List */ +TASK_LIST +{ + { Task: USB_USBTask , TaskStatus: TASK_STOP }, + { Task: USB_Sideshow , TaskStatus: TASK_STOP }, +}; + +int main(void) +{ + /* Disable watchdog if enabled by bootloader/fuses */ + MCUSR &= ~(1 << WDRF); + wdt_disable(); + + /* Disable Clock Division */ + SetSystemClockPrescaler(0); + + /* Hardware Initialization */ + SerialStream_Init(9600, false); + LEDs_Init(); + HWB_Init(); + + /* Indicate USB not ready */ + LEDs_SetAllLEDs(LEDS_LED1 | LEDS_LED3); + + /* Initialize Scheduler so that it can be used */ + Scheduler_Init(); + + /* Initialize USB Subsystem */ + USB_Init(); + + /* Scheduling - routine never returns, so put this last in the main function */ + Scheduler_Start(); +} + +EVENT_HANDLER(USB_Connect) +{ + /* Start USB management task */ + Scheduler_SetTaskMode(USB_USBTask, TASK_RUN); + + /* Indicate USB enumerating */ + LEDs_SetAllLEDs(LEDS_LED1 | LEDS_LED4); +} + +EVENT_HANDLER(USB_Disconnect) +{ + /* Stop running mass storage and USB management tasks */ + Scheduler_SetTaskMode(USB_Sideshow, TASK_STOP); + Scheduler_SetTaskMode(USB_USBTask, TASK_STOP); + + /* Indicate USB not ready */ + LEDs_SetAllLEDs(LEDS_LED1 | LEDS_LED3); +} + +EVENT_HANDLER(USB_ConfigurationChanged) +{ + /* Setup Sideshow In and Out Endpoints */ + Endpoint_ConfigureEndpoint(SIDESHOW_IN_EPNUM, EP_TYPE_BULK, + ENDPOINT_DIR_IN, SIDESHOW_IO_EPSIZE, + ENDPOINT_BANK_SINGLE); + + Endpoint_ConfigureEndpoint(SIDESHOW_OUT_EPNUM, EP_TYPE_BULK, + ENDPOINT_DIR_OUT, SIDESHOW_IO_EPSIZE, + ENDPOINT_BANK_SINGLE); + + /* Indicate USB connected and ready */ + LEDs_SetAllLEDs(LEDS_LED2 | LEDS_LED4); + + /* Start Sideshow task */ + Scheduler_SetTaskMode(USB_Sideshow, TASK_RUN); +} + +EVENT_HANDLER(USB_UnhandledControlPacket) +{ + /* Process UFI specific control requests */ + switch (bRequest) + { + case REQ_GetOSFeatureDescriptor: + if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_VENDOR | REQREC_DEVICE)) + { + uint16_t wValue = Endpoint_Read_Word_LE(); + uint16_t wIndex = Endpoint_Read_Word_LE(); + uint16_t wLength = Endpoint_Read_Word_LE(); + + void* DescriptorPointer; + uint16_t DescriptorSize; + + bool SendZLP = true; + + if (!(USB_GetOSFeatureDescriptor(wValue, wIndex, &DescriptorPointer, &DescriptorSize))) + return; + + Endpoint_ClearSetupReceived(); + + if (wLength > DescriptorSize) + wLength = DescriptorSize; + + while (wLength && (!(Endpoint_IsSetupOUTReceived()))) + { + while (!(Endpoint_IsSetupINReady())); + + while (wLength && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize)) + { + #if defined(USE_RAM_DESCRIPTORS) + Endpoint_Write_Byte(*((uint8_t*)DescriptorPointer++)); + #elif defined (USE_EEPROM_DESCRIPTORS) + Endpoint_Write_Byte(eeprom_read_byte(DescriptorPointer++)); + #else + Endpoint_Write_Byte(pgm_read_byte(DescriptorPointer++)); + #endif + + wLength--; + } + + SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize); + Endpoint_ClearSetupIN(); + } + + if (Endpoint_IsSetupOUTReceived()) + { + Endpoint_ClearSetupOUT(); + return; + } + + if (SendZLP) + { + while (!(Endpoint_IsSetupINReady())); + Endpoint_ClearSetupIN(); + } + + while (!(Endpoint_IsSetupOUTReceived())); + Endpoint_ClearSetupOUT(); + } + + break; + } +} + +TASK(USB_Sideshow) +{ + /* Check if the USB System is connected to a Host */ + if (USB_IsConnected) + { + /* Select the SideShow data out endpoint */ + Endpoint_SelectEndpoint(SIDESHOW_OUT_EPNUM); + + /* Check to see if a new SideShow message has been received */ + if (Endpoint_ReadWriteAllowed()) + { + /* Process the received SideShow message */ + Sideshow_ProcessCommandPacket(); + } + } +} diff --git a/Demos/Device/Incomplete/Sideshow/Sideshow.h b/Demos/Device/Incomplete/Sideshow/Sideshow.h new file mode 100644 index 0000000000..7b88182924 --- /dev/null +++ b/Demos/Device/Incomplete/Sideshow/Sideshow.h @@ -0,0 +1,64 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, 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. +*/ + +#ifndef _SIDESHOW_H_ +#define _SIDESHOW_H_ + + /* Includes: */ + #include + #include + + #include "Descriptors.h" + #include "SideshowCommands.h" + + #include // Library Version Information + #include // PROGMEM tags readable by the ButtLoad project + #include // USB Functionality + #include // HWB button driver + #include // LEDs driver + #include // Dataflash chip driver + #include // Simple scheduler for task management + #include // Serial stream driver + + /* Macros: */ + #define REQ_GetOSFeatureDescriptor 0x01 + + #define EXTENDED_COMPAT_ID_DESCRIPTOR 0x0004 + + /* Task Definitions: */ + TASK(USB_Sideshow); + + /* Event Handlers: */ + HANDLES_EVENT(USB_Connect); + HANDLES_EVENT(USB_Disconnect); + HANDLES_EVENT(USB_ConfigurationChanged); + HANDLES_EVENT(USB_UnhandledControlPacket); + +#endif diff --git a/Demos/Device/Incomplete/Sideshow/SideshowApplications.c b/Demos/Device/Incomplete/Sideshow/SideshowApplications.c new file mode 100644 index 0000000000..f2789c4a73 --- /dev/null +++ b/Demos/Device/Incomplete/Sideshow/SideshowApplications.c @@ -0,0 +1,72 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, 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. +*/ + +#include "SideshowApplications.h" + +SideShow_Application_t InstalledApplications[MAX_APPLICATIONS]; + + +uint8_t SideShow_GetTotalApplications(void) +{ + uint8_t TotalInstalledApps = 0; + + for (uint8_t App = 0; App < ARRAY_ELEMENTS(InstalledApplications); App++) + { + if (InstalledApplications[App].InUse) + TotalInstalledApps++; + } + + return TotalInstalledApps; +} + +SideShow_Application_t* SideShow_GetFreeApplication(void) +{ + for (uint8_t App = 0; App < ARRAY_ELEMENTS(InstalledApplications); App++) + { + if (!(InstalledApplications[App].InUse)) + return &InstalledApplications[App]; + } + + return NULL; +} + +SideShow_Application_t* SideShow_GetApplicationFromGUID(GUID_t* GUID) +{ + for (uint8_t App = 0; App < ARRAY_ELEMENTS(InstalledApplications); App++) + { + if (InstalledApplications[App].InUse) + { + if (memcmp(&InstalledApplications[App].ApplicationID, GUID, sizeof(GUID_t)) == 0) + return &InstalledApplications[App]; + } + } + + return NULL; +} diff --git a/Demos/Device/Incomplete/Sideshow/SideshowApplications.h b/Demos/Device/Incomplete/Sideshow/SideshowApplications.h new file mode 100644 index 0000000000..133acf994c --- /dev/null +++ b/Demos/Device/Incomplete/Sideshow/SideshowApplications.h @@ -0,0 +1,63 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, 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. +*/ + +#ifndef _SIDESHOW_APPLICATIONS_H_ +#define _SIDESHOW_APPLICATIONS_H_ + + /* Includes: */ + #include + #include + #include + + #include "SideshowCommon.h" + + /* Type Defines: */ + typedef struct + { + bool InUse; + GUID_t ApplicationID; + GUID_t EndpointID; + UNICODE_STRING_t(50) ApplicationName; + uint32_t CachePolicy; + uint32_t OnlineOnly; + bool HaveContent; + uint32_t CurrentContentID; + uint8_t CurrentContent[MAX_CONTENTBUFFER_PER_APP]; + } SideShow_Application_t; + + /* External Variables: */ + extern SideShow_Application_t InstalledApplications[MAX_APPLICATIONS]; + + /* Function Prototypes: */ + uint8_t SideShow_GetTotalApplications(void); + SideShow_Application_t* SideShow_GetFreeApplication(void); + SideShow_Application_t* SideShow_GetApplicationFromGUID(GUID_t* GUID); + +#endif diff --git a/Demos/Device/Incomplete/Sideshow/SideshowCommands.c b/Demos/Device/Incomplete/Sideshow/SideshowCommands.c new file mode 100644 index 0000000000..2dd49b42d5 --- /dev/null +++ b/Demos/Device/Incomplete/Sideshow/SideshowCommands.c @@ -0,0 +1,490 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, 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. +*/ + +#define INCLUDE_FROM_SIDESHOWCOMMANDS_H +#include "SideshowCommands.h" + +UNICODE_STRING_t(80) UserSID = {LengthInBytes: sizeof(SECURITY_INTERACTIVE_RID_SID), + UnicodeString: SECURITY_INTERACTIVE_RID_SID}; + +Unicode_String_t DeviceName = {LengthInBytes: sizeof(L"LUFA Sideshow Device"), + UnicodeString: L"LUFA Sideshow Device"}; + +Unicode_String_t Manufacturer = {LengthInBytes: sizeof(L"Dean Camera"), + UnicodeString: L"Dean Camera"}; + +Unicode_String_t SupportedLanguage = {LengthInBytes: sizeof(L"en-US:1"), + UnicodeString: L"en-US:1"}; + +void Sideshow_ProcessCommandPacket(void) +{ + SideShow_PacketHeader_t PacketHeader; + + Endpoint_SelectEndpoint(SIDESHOW_OUT_EPNUM); + Endpoint_Read_Stream_LE(&PacketHeader, sizeof(SideShow_PacketHeader_t)); + + PacketHeader.Type.Response = true; + + printf("\r\nCmd: %lX", (PacketHeader.Type.TypeLong & 0x00FFFFFF)); + + switch (PacketHeader.Type.TypeLong & 0x00FFFFFF) + { + case SIDESHOW_CMD_PING: + SideShow_Ping(&PacketHeader); + break; + case SIDESHOW_CMD_SYNC: + SideShow_Sync(&PacketHeader); + break; + case SIDESHOW_CMD_GET_CURRENT_USER: + SideShow_GetCurrentUser(&PacketHeader); + break; + case SIDESHOW_CMD_SET_CURRENT_USER: + SideShow_SetCurrentUser(&PacketHeader); + break; + case SIDESHOW_CMD_GET_CAPABILITIES: + SideShow_GetCapabilities(&PacketHeader); + break; + case SIDESHOW_CMD_GET_DEVICE_NAME: + SideShow_GetString(&PacketHeader, &DeviceName); + break; + case SIDESHOW_CMD_GET_MANUFACTURER: + SideShow_GetString(&PacketHeader, &Manufacturer); + break; + case SIDESHOW_CMD_GET_APPLICATION_ORDER: + SideShow_GetApplicationOrder(&PacketHeader); + break; + case SIDESHOW_CMD_GET_SUPPORTED_ENDPOINTS: + SideShow_GetSupportedEndpoints(&PacketHeader); + break; + case SIDESHOW_CMD_ADD_APPLICATION: + SideShow_AddApplication(&PacketHeader); + break; + case SIDESHOW_CMD_ADD_CONTENT: + SideShow_AddContent(&PacketHeader); + break; + case SIDESHOW_CMD_DELETE_CONTENT: + SideShow_DeleteContent(&PacketHeader); + break; + case SIDESHOW_CMD_DELETE_ALL_CONTENT: + SideShow_DeleteAllContent(&PacketHeader); + break; + case SIDESHOW_CMD_DELETE_APPLICATION: + SideShow_DeleteApplication(&PacketHeader); + break; + case SIDESHOW_CMD_DELETE_ALL_APPLICATIONS: + SideShow_DeleteAllApplications(&PacketHeader); + break; + default: + PacketHeader.Length -= sizeof(SideShow_PacketHeader_t); + + Endpoint_Discard_Stream(PacketHeader.Length); + Endpoint_ClearCurrentBank(); + + PacketHeader.Length = sizeof(SideShow_PacketHeader_t); + PacketHeader.Type.NAK = true; + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(&PacketHeader, sizeof(SideShow_PacketHeader_t)); + Endpoint_ClearCurrentBank(); + + printf(" UNK"); + } +} + +static void SideShow_Ping(SideShow_PacketHeader_t* PacketHeader) +{ + Endpoint_ClearCurrentBank(); + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + Endpoint_ClearCurrentBank(); +} + +static void SideShow_Sync(SideShow_PacketHeader_t* PacketHeader) +{ + GUID_t ProtocolGUID; + + Endpoint_Read_Stream_LE(&ProtocolGUID, sizeof(GUID_t)); + Endpoint_ClearCurrentBank(); + + if (memcmp(&ProtocolGUID, (uint32_t[])STANDARD_PROTOCOL_GUID, sizeof(GUID_t)) != 0) + PacketHeader->Type.NAK = true; + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + Endpoint_Write_Stream_LE(&ProtocolGUID, sizeof(GUID_t)); + Endpoint_ClearCurrentBank(); +} + +static void SideShow_GetCurrentUser(SideShow_PacketHeader_t* PacketHeader) +{ + Endpoint_ClearCurrentBank(); + + PacketHeader->Length = sizeof(SideShow_PacketHeader_t) + sizeof(uint32_t) + UserSID.LengthInBytes; + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + SideShow_Write_Unicode_String(&UserSID); + Endpoint_ClearCurrentBank(); +} + +static void SideShow_SetCurrentUser(SideShow_PacketHeader_t* PacketHeader) +{ + SideShow_Read_Unicode_String(&UserSID, sizeof(UserSID.UnicodeString)); + Endpoint_ClearCurrentBank(); + + PacketHeader->Length = sizeof(SideShow_PacketHeader_t); + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + Endpoint_ClearCurrentBank(); +} + +static void SideShow_GetCapabilities(SideShow_PacketHeader_t* PacketHeader) +{ + SideShow_PropertyKey_t Property; + SideShow_PropertyData_t PropertyData; + + Endpoint_Read_Stream_LE(&Property, sizeof(SideShow_PropertyKey_t)); + Endpoint_ClearCurrentBank(); + + printf(" ID: %lu", Property.PropertyID); + + PacketHeader->Length = sizeof(SideShow_PacketHeader_t); + + if (memcmp(&Property.PropertyGUID, (uint32_t[])SIDESHOW_PROPERTY_GUID, sizeof(GUID_t)) == 0) + { + switch (Property.PropertyID) + { + case PROPERTY_SIDESHOW_SCREENTYPE: + PropertyData.DataType = VT_I4; + PropertyData.Data.Data32 = ScreenText; + PacketHeader->Length += sizeof(uint32_t); + + break; + case PROPERTY_SIDESHOW_SCREENWIDTH: + case PROPERTY_SIDESHOW_CLIENTWIDTH: + PropertyData.DataType = VT_UI2; + PropertyData.Data.Data16 = 16; + PacketHeader->Length += sizeof(uint16_t); + + break; + case PROPERTY_SIDESHOW_SCREENHEIGHT: + case PROPERTY_SIDESHOW_CLIENTHEIGHT: + PropertyData.DataType = VT_UI2; + PropertyData.Data.Data16 = 2; + PacketHeader->Length += sizeof(uint16_t); + + break; + case PROPERTY_SIDESHOW_COLORDEPTH: + PropertyData.DataType = VT_UI2; + PropertyData.Data.Data16 = 1; + PacketHeader->Length += sizeof(uint16_t); + + break; + case PROPERTY_SIDESHOW_COLORTYPE: + PropertyData.DataType = VT_UI2; + PropertyData.Data.Data16 = BlackAndWhiteDisplay; + PacketHeader->Length += sizeof(uint16_t); + + break; + case PROPERTY_SIDESHOW_DATACACHE: + PropertyData.DataType = VT_BOOL; + PropertyData.Data.Data16 = false; + PacketHeader->Length += sizeof(uint16_t); + + break; + case PROPERTY_SIDESHOW_SUPPORTEDLANGS: + case PROPERTY_SIDESHOW_CURRENTLANG: + PropertyData.DataType = VT_LPWSTR; + PropertyData.Data.DataPointer = &SupportedLanguage; + PacketHeader->Length += SupportedLanguage.LengthInBytes; + + break; + default: + PropertyData.DataType = VT_EMPTY; + break; + } + } + else if (memcmp(&Property.PropertyGUID, (uint32_t[])DEVICE_PROPERTY_GUID, sizeof(GUID_t)) == 0) + { + switch (Property.PropertyID) + { + case PROPERTY_DEVICE_DEVICETYPE: + PropertyData.DataType = VT_UI4; + PropertyData.Data.Data32 = GenericDevice; + PacketHeader->Length += sizeof(uint32_t); + + break; + } + } + else + { + PacketHeader->Type.NAK = true; + + printf(" WRONG GUID"); + printf(" %lX %lX %lX %lX", Property.PropertyGUID.Chunks[0], Property.PropertyGUID.Chunks[1], + Property.PropertyGUID.Chunks[2], Property.PropertyGUID.Chunks[3]); + } + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + + if (!(PacketHeader->Type.NAK)) + { + switch (PropertyData.DataType) + { + case VT_UI4: + case VT_I4: + Endpoint_Write_Stream_LE(&PropertyData.Data.Data32, sizeof(uint32_t)); + break; + case VT_UI2: + case VT_I2: + case VT_BOOL: + Endpoint_Write_Stream_LE(&PropertyData.Data.Data16, sizeof(uint16_t)); + break; + case VT_LPWSTR: + SideShow_Write_Unicode_String((Unicode_String_t*)PropertyData.Data.Data16); + break; + } + } + + Endpoint_ClearCurrentBank(); + return; +} + +static void SideShow_GetString(SideShow_PacketHeader_t* PacketHeader, void* UnicodeStruct) +{ + Endpoint_ClearCurrentBank(); + + PacketHeader->Length = sizeof(SideShow_PacketHeader_t) + + sizeof(uint32_t) + ((Unicode_String_t*)UnicodeStruct)->LengthInBytes; + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + SideShow_Write_Unicode_String(UnicodeStruct); + Endpoint_ClearCurrentBank(); +} + +static void SideShow_GetApplicationOrder(SideShow_PacketHeader_t* PacketHeader) +{ + uint8_t TotalInstalledApplications = SideShow_GetTotalApplications(); + uint16_t GadgetGUIDBytes = (TotalInstalledApplications * sizeof(GUID_t)); + + Endpoint_ClearCurrentBank(); + + PacketHeader->Length = sizeof(SideShow_PacketHeader_t) + + sizeof(uint32_t) + GadgetGUIDBytes; + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + Endpoint_Write_DWord_LE(TotalInstalledApplications); + + for (uint8_t App = 0; App < MAX_APPLICATIONS; App++) + { + if (InstalledApplications[App].InUse == true) + Endpoint_Write_Stream_LE(&InstalledApplications[App].ApplicationID, sizeof(GUID_t)); + } + + Endpoint_ClearCurrentBank(); +} + +static void SideShow_GetSupportedEndpoints(SideShow_PacketHeader_t* PacketHeader) +{ + GUID_t SupportedEndpointGUID = (GUID_t){Chunks: SIMPLE_CONTENT_FORMAT_GUID}; + + Endpoint_ClearCurrentBank(); + + PacketHeader->Length = sizeof(SideShow_PacketHeader_t) + sizeof(uint32_t) + sizeof(GUID_t); + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + Endpoint_Write_DWord_LE(1); + Endpoint_Write_Stream_LE(&SupportedEndpointGUID, sizeof(GUID_t)); + Endpoint_ClearCurrentBank(); +} + +static void SideShow_AddApplication(SideShow_PacketHeader_t* PacketHeader) +{ + SideShow_Application_t* CurrApp; + GUID_t ApplicationID; + + Endpoint_Read_Stream_LE(&ApplicationID, sizeof(GUID_t)); + + CurrApp = SideShow_GetApplicationFromGUID(&ApplicationID); + + if (CurrApp == NULL) + CurrApp = SideShow_GetFreeApplication(); + + if (CurrApp == NULL) + { + PacketHeader->Length -= sizeof(SideShow_PacketHeader_t) + sizeof(GUID_t); + + Endpoint_Discard_Stream(PacketHeader->Length); + Endpoint_ClearCurrentBank(); + + PacketHeader->Type.NAK = true; + } + else + { + CurrApp->ApplicationID = ApplicationID; + Endpoint_Read_Stream_LE(&CurrApp->EndpointID, sizeof(GUID_t)); + SideShow_Read_Unicode_String(&CurrApp->ApplicationName, sizeof(CurrApp->ApplicationName.UnicodeString)); + Endpoint_Read_Stream_LE(&CurrApp->CachePolicy, sizeof(uint32_t)); + Endpoint_Read_Stream_LE(&CurrApp->OnlineOnly, sizeof(uint32_t)); + SideShow_Discard_Byte_Stream(); + SideShow_Discard_Byte_Stream(); + SideShow_Discard_Byte_Stream(); + Endpoint_ClearCurrentBank(); + + CurrApp->InUse = true; + CurrApp->HaveContent = false; + CurrApp->CurrentContentID = 1; + } + + PacketHeader->Length = sizeof(SideShow_PacketHeader_t); + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + Endpoint_ClearCurrentBank(); +} + +static void SideShow_DeleteApplication(SideShow_PacketHeader_t* PacketHeader) +{ + GUID_t ApplicationGUID; + + Endpoint_Read_Stream_LE(&ApplicationGUID, sizeof(GUID_t)); + Endpoint_ClearCurrentBank(); + + SideShow_Application_t* AppToDelete = SideShow_GetApplicationFromGUID(&ApplicationGUID); + + if (AppToDelete != NULL) + { + AppToDelete->InUse = false; + } + else + PacketHeader->Type.NAK = true; + + PacketHeader->Length = sizeof(SideShow_PacketHeader_t); + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + Endpoint_ClearCurrentBank(); +} + +static void SideShow_DeleteAllApplications(SideShow_PacketHeader_t* PacketHeader) +{ + Endpoint_ClearCurrentBank(); + + for (uint8_t App = 0; App < MAX_APPLICATIONS; App++) + InstalledApplications[App].InUse = false; + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + Endpoint_ClearCurrentBank(); +} + +static void SideShow_AddContent(SideShow_PacketHeader_t* PacketHeader) +{ + GUID_t ApplicationID; + GUID_t EndpointID; + SideShow_Application_t* Application; + + Endpoint_Read_Stream_LE(&ApplicationID, sizeof(GUID_t)); + Endpoint_Read_Stream_LE(&EndpointID, sizeof(GUID_t)); + + Application = SideShow_GetApplicationFromGUID(&ApplicationID); + + if (Application == NULL) + { + SideShow_Discard_Byte_Stream(); + PacketHeader->Type.NAK = true; + } + else if (!(SideShow_AddSimpleContent(PacketHeader, Application))) + { + PacketHeader->Type.NAK = true; + } + + Endpoint_ClearCurrentBank(); + + PacketHeader->Length = sizeof(SideShow_PacketHeader_t); + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + Endpoint_ClearCurrentBank(); +} + +static void SideShow_DeleteContent(SideShow_PacketHeader_t* PacketHeader) +{ + GUID_t ApplicationID; + GUID_t EndpointID; + uint32_t ContentID; + + Endpoint_Read_Stream_LE(&ApplicationID, sizeof(GUID_t)); + Endpoint_Read_Stream_LE(&EndpointID, sizeof(GUID_t)); + Endpoint_Read_Stream_LE(&ContentID, sizeof(uint32_t)); + Endpoint_ClearCurrentBank(); + + SideShow_Application_t* Application = SideShow_GetApplicationFromGUID(&ApplicationID); + + if ((Application != NULL) && (Application->CurrentContentID == ContentID)) + Application->HaveContent = false; + else + PacketHeader->Type.NAK = true; + + PacketHeader->Length = sizeof(SideShow_PacketHeader_t); + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + Endpoint_ClearCurrentBank(); +} + +static void SideShow_DeleteAllContent(SideShow_PacketHeader_t* PacketHeader) +{ + GUID_t ApplicationID; + GUID_t EndpointID; + + Endpoint_Read_Stream_LE(&ApplicationID, sizeof(GUID_t)); + Endpoint_Read_Stream_LE(&EndpointID, sizeof(GUID_t)); + Endpoint_ClearCurrentBank(); + + SideShow_Application_t* Application = SideShow_GetApplicationFromGUID(&ApplicationID); + + if (Application != NULL) + Application->HaveContent = false; + else + PacketHeader->Type.NAK = true; + + PacketHeader->Length = sizeof(SideShow_PacketHeader_t); + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + Endpoint_ClearCurrentBank(); +} diff --git a/Demos/Device/Incomplete/Sideshow/SideshowCommands.h b/Demos/Device/Incomplete/Sideshow/SideshowCommands.h new file mode 100644 index 0000000000..197bc95888 --- /dev/null +++ b/Demos/Device/Incomplete/Sideshow/SideshowCommands.h @@ -0,0 +1,165 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, 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. +*/ + +#ifndef _SIDESHOW_COMMANDS_H_ +#define _SIDESHOW_COMMANDS_H_ + + /* Includes: */ + #include + #include + #include + + #include "Sideshow.h" + #include "SideshowCommon.h" + #include "SideshowApplications.h" + #include "SideshowContent.h" + + /* Enumerations: */ + enum SideShow_PropertyKey_Types_t + { + VT_EMPTY = 0, + VT_NULL = 1, + VT_I2 = 2, + VT_I4 = 3, + VT_R4 = 4, + VT_R8 = 5, + VT_CY = 6, + VT_DATE = 7, + VT_BSTR = 8, + VT_DISPATCH = 9, + VT_ERROR = 10, + VT_BOOL = 11, + VT_VARIANT = 12, + VT_UNKNOWN = 13, + VT_UI1 = 17, + VT_UI2 = 18, + VT_UI4 = 19, + VT_LPWSTR = 31, + }; + + enum SideShow_ScreenTypeText_t + { + ScreenBitmap = 0, + ScreenText = 1, + }; + + enum SideShow_ColorTypes_t + { + ColorDisplay = 0, + GrayscaleDisplay = 1, + BlackAndWhiteDisplay = 2, + }; + + enum SideShow_DeviceTypes_t + { + GenericDevice = 0, + CameraDevice = 1, + MediaPlayerDevice = 2, + PhoneDevice = 3, + VideoDevice = 4, + PIMDevice = 5, + AudioRecorderDevice = 6 + }; + + /* Type Defines: */ + typedef struct + { + GUID_t PropertyGUID; + uint32_t PropertyID; + } SideShow_PropertyKey_t; + + typedef struct + { + uint32_t DataType; + + union + { + void* DataPointer; + uint8_t Data8; + uint16_t Data16; + uint32_t Data32; + } Data; + } SideShow_PropertyData_t; + + /* Macros: */ + #define SIDESHOW_CMD_PING 0x001 + #define SIDESHOW_CMD_SET_CURRENT_USER 0x100 + #define SIDESHOW_CMD_GET_CURRENT_USER 0x101 + #define SIDESHOW_CMD_GET_CAPABILITIES 0x103 + #define SIDESHOW_CMD_GET_APPLICATION_ORDER 0x104 + #define SIDESHOW_CMD_ADD_APPLICATION 0x10D + #define SIDESHOW_CMD_DELETE_APPLICATION 0x10E + #define SIDESHOW_CMD_DELETE_ALL_APPLICATIONS 0x10F + #define SIDESHOW_CMD_ADD_CONTENT 0x114 + #define SIDESHOW_CMD_DELETE_CONTENT 0x115 + #define SIDESHOW_CMD_DELETE_ALL_CONTENT 0x116 + #define SIDESHOW_CMD_GET_SUPPORTED_ENDPOINTS 0x117 + #define SIDESHOW_CMD_GET_DEVICE_NAME 0x500 + #define SIDESHOW_CMD_GET_MANUFACTURER 0x501 + #define SIDESHOW_CMD_SYNC 0x502 + + #define PROPERTY_SIDESHOW_DEVICEID 1 + #define PROPERTY_SIDESHOW_SCREENTYPE 2 + #define PROPERTY_SIDESHOW_SCREENWIDTH 3 + #define PROPERTY_SIDESHOW_SCREENHEIGHT 4 + #define PROPERTY_SIDESHOW_COLORDEPTH 5 + #define PROPERTY_SIDESHOW_COLORTYPE 6 + #define PROPERTY_SIDESHOW_DATACACHE 7 + #define PROPERTY_SIDESHOW_SUPPORTEDLANGS 8 + #define PROPERTY_SIDESHOW_CURRENTLANG 9 + #define PROPERTY_SIDESHOW_SUPPORTEDTHEMES 10 + #define PROPERTY_SIDESHOW_IMAGEFORMAT 14 + #define PROPERTY_SIDESHOW_CLIENTWIDTH 15 + #define PROPERTY_SIDESHOW_CLIENTHEIGHT 16 + #define PROPERTY_SIDESHOW_DEVICEICON 17 + + #define PROPERTY_DEVICE_DEVICETYPE 15 + + /* Function Prototypes: */ + void Sideshow_ProcessCommandPacket(void); + + #if defined(INCLUDE_FROM_SIDESHOWCOMMANDS_H) + static void SideShow_Ping(SideShow_PacketHeader_t* PacketHeader); + static void SideShow_Sync(SideShow_PacketHeader_t* PacketHeader); + static void SideShow_GetCurrentUser(SideShow_PacketHeader_t* PacketHeader); + static void SideShow_SetCurrentUser(SideShow_PacketHeader_t* PacketHeader); + static void SideShow_GetCapabilities(SideShow_PacketHeader_t* PacketHeader); + static void SideShow_GetString(SideShow_PacketHeader_t* PacketHeader, void* UnicodeStruct); + static void SideShow_GetApplicationOrder(SideShow_PacketHeader_t* PacketHeader); + static void SideShow_GetSupportedEndpoints(SideShow_PacketHeader_t* PacketHeader); + static void SideShow_AddApplication(SideShow_PacketHeader_t* PacketHeader); + static void SideShow_DeleteApplication(SideShow_PacketHeader_t* PacketHeader); + static void SideShow_DeleteAllApplications(SideShow_PacketHeader_t* PacketHeader); + static void SideShow_AddContent(SideShow_PacketHeader_t* PacketHeader); + static void SideShow_DeleteContent(SideShow_PacketHeader_t* PacketHeader); + static void SideShow_DeleteAllContent(SideShow_PacketHeader_t* PacketHeader); + #endif + +#endif diff --git a/Demos/Device/Incomplete/Sideshow/SideshowCommon.c b/Demos/Device/Incomplete/Sideshow/SideshowCommon.c new file mode 100644 index 0000000000..a45dbd9716 --- /dev/null +++ b/Demos/Device/Incomplete/Sideshow/SideshowCommon.c @@ -0,0 +1,70 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, 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. +*/ + +#include "SideshowCommon.h" + +uint16_t SideShow_Read_Unicode_String(void* UnicodeString, uint16_t MaxBytes) +{ + Unicode_String_t* UnicodeStruct = (Unicode_String_t*)UnicodeString; + uint32_t UnicodeCharsToRead; + + Endpoint_Read_Stream_LE(&UnicodeCharsToRead, sizeof(uint32_t)); + + int UnicodeData[UnicodeCharsToRead]; + + UnicodeStruct->LengthInBytes = (UnicodeCharsToRead << 1); + + Endpoint_Read_Stream_LE(&UnicodeData, UnicodeStruct->LengthInBytes); + + if (UnicodeStruct->LengthInBytes > MaxBytes) + UnicodeStruct->LengthInBytes = MaxBytes; + + memcpy(&UnicodeStruct->UnicodeString, &UnicodeData, UnicodeStruct->LengthInBytes); + + return ((UnicodeCharsToRead << 1) + sizeof(uint32_t)); +} + +void SideShow_Write_Unicode_String(void* UnicodeString) +{ + Unicode_String_t* UnicodeStruct = (Unicode_String_t*)UnicodeString; + + uint32_t StringSizeInCharacters = (UnicodeStruct->LengthInBytes >> 1); + + Endpoint_Write_Stream_LE(&StringSizeInCharacters, sizeof(uint32_t)); + Endpoint_Write_Stream_LE(&UnicodeStruct->UnicodeString, UnicodeStruct->LengthInBytes); +} + +void SideShow_Discard_Byte_Stream(void) +{ + uint32_t StreamSize; + + Endpoint_Read_Stream_LE(&StreamSize, sizeof(uint32_t)); + Endpoint_Discard_Stream(StreamSize); +} diff --git a/Demos/Device/Incomplete/Sideshow/SideshowCommon.h b/Demos/Device/Incomplete/Sideshow/SideshowCommon.h new file mode 100644 index 0000000000..cea81ce660 --- /dev/null +++ b/Demos/Device/Incomplete/Sideshow/SideshowCommon.h @@ -0,0 +1,101 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, 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. +*/ + +#ifndef _SIDESHOW_COMMON_H_ +#define _SIDESHOW_COMMON_H_ + + /* Includes: */ + #include + #include + + #include + + /* Macros: */ + #define ARRAY_ELEMENTS(x) (sizeof(x) / sizeof(x[0])) + + #define UNICODE_STRING_t(x) struct \ + { \ + uint16_t LengthInBytes; \ + int UnicodeString[x]; \ + } + + // {A33F248B-882F-4531-82C2-ED3B90C5C520} + #define STANDARD_PROTOCOL_GUID {0xA33F248B, 0x4531882F, 0x3BEDC282, 0x20C5C590} + // {A9A5353F-2D4B-47CE-93EE-759F3A7DDA4F} + #define SIMPLE_CONTENT_FORMAT_GUID {0xA9A5353F, 0x47CE2D4B, 0x9F75EE93, 0x4FDA7D3A} + // {8ABC88A8-857B-4ad7-A35A-B5942F492B99} + #define SIDESHOW_PROPERTY_GUID {0x8ABC88A8, 0x4AD7857B, 0x94B55AA3, 0x992B492F} + // {26D4979A-E643-4626-9E2B-736DC0C92FDC} + #define DEVICE_PROPERTY_GUID {0x26D4979A, 0x4626E643, 0x6D732B9E, 0xDC2FC9C0} + + #define SECURITY_INTERACTIVE_RID_SID L"S-1-5-4" + + #define MAX_APPLICATIONS 4 + #define MAX_CONTENTBUFFER_PER_APP 1024 + + /* Type Defines: */ + typedef struct + { + uint32_t Chunks[4]; + } GUID_t; + + typedef struct + { + uint16_t LengthInBytes; + int UnicodeString[]; + } Unicode_String_t; + + typedef union + { + uint32_t TypeLong; + + struct + { + uint8_t TypeBytes[3]; + + int ErrorCode : 6; + int NAK : 1; + int Response : 1; + }; + } SideShowPacketType_t; + + typedef struct + { + uint32_t Length; + SideShowPacketType_t Type; + uint16_t Number; + } SideShow_PacketHeader_t; + + /* Function Prototypes: */ + uint16_t SideShow_Read_Unicode_String(void* UnicodeString, uint16_t MaxBytes); + void SideShow_Write_Unicode_String(void* UnicodeString); + void SideShow_Discard_Byte_Stream(void); + +#endif \ No newline at end of file diff --git a/Demos/Device/Incomplete/Sideshow/SideshowContent.c b/Demos/Device/Incomplete/Sideshow/SideshowContent.c new file mode 100644 index 0000000000..9b8b375ecb --- /dev/null +++ b/Demos/Device/Incomplete/Sideshow/SideshowContent.c @@ -0,0 +1,76 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, 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. +*/ + +#define INCLUDE_FROM_SIDESHOWCONTENT_C +#include "SideshowContent.h" + +bool SideShow_AddSimpleContent(SideShow_PacketHeader_t* PacketHeader, SideShow_Application_t* Application) +{ + uint32_t ContentSize; + uint32_t ContentID; + + Endpoint_Read_Stream_LE(&ContentID, sizeof(uint32_t)); + + PacketHeader->Length -= sizeof(uint32_t); + + if (Application->CurrentContentID != ContentID) + { + Endpoint_Discard_Stream(PacketHeader->Length); + + return false; + } + + Endpoint_Read_Stream_LE(&ContentSize, sizeof(uint32_t)); + Endpoint_Read_Stream_LE(&Application->CurrentContent, sizeof(XML_START_TAG) - 1); + + PacketHeader->Length -= sizeof(uint32_t) + (sizeof(XML_START_TAG) - 1); + + if (!(memcmp(&Application->CurrentContent, XML_START_TAG, (sizeof(XML_START_TAG) - 1)))) + { + SideShow_ProcessXMLContent(&Application->CurrentContent, (ContentSize - (sizeof(XML_END_TAG) - 1))); + + Endpoint_Discard_Stream(sizeof(XML_END_TAG) - 1); + + Application->HaveContent = true; + } + else + { + printf(" BINARY"); + Endpoint_Discard_Stream(ContentSize); + } + + return true; +} + +static void SideShow_ProcessXMLContent(void* ContentData, uint32_t ContentSize) +{ + printf(" XML"); + Endpoint_Discard_Stream(ContentSize); +} diff --git a/Demos/Device/Incomplete/Sideshow/SideshowContent.h b/Demos/Device/Incomplete/Sideshow/SideshowContent.h new file mode 100644 index 0000000000..a9333a8ed5 --- /dev/null +++ b/Demos/Device/Incomplete/Sideshow/SideshowContent.h @@ -0,0 +1,124 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, 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. +*/ + +#ifndef _SIDESHOW_CONTENT_H_ +#define _SIDESHOW_CONTENT_H_ + + /* Includes: */ + #include + #include + #include + + #include "SideshowCommon.h" + #include "SideshowApplications.h" + + /* Enums: */ + enum SideShow_ContentTypes_t + { + Content_Menu = 0, + Content_Content = 1, + Content_MenuItem = 2, + Content_Button = 3, + Content_Text = 4, + Content_EndOfContent = 5 + }; + + enum SideShow_ActionTypes_t + { + TODO + }; + + enum SideShow_AlignmentTypes_t + { + TODO2 + }; + + /* Type Defines: */ + typedef struct + { + uint8_t ContentType; + uint8_t ContentSize; + } SideShow_Content_Header_t; + + typedef struct + { + SideShow_Content_Header_t Header; + + uint32_t ItemID; + uint8_t ActionType; + char Title[]; + } SideShow_Content_Menu_t; + + typedef struct + { + SideShow_Content_Header_t Header; + + uint32_t ItemID; + uint32_t Target; + bool IsSelected; + char Text[]; + } SideShow_Content_MenuItem_t; + + typedef struct + { + SideShow_Content_Header_t Header; + + uint8_t Key; + uint32_t Target; + } SideShow_Content_Button_t; + + typedef struct + { + SideShow_Content_Header_t Header; + + uint32_t ItemID; + uint32_t AssociatedMenuID; + char Title[]; + } SideShow_Content_Content_t; + + typedef struct + { + SideShow_Content_Header_t Header; + + char Text[]; + } SideShow_Content_Text_t; + + /* Defines: */ + #define XML_START_TAG "" + #define XML_END_TAG "" + + /* Function Prototypes: */ + bool SideShow_AddSimpleContent(SideShow_PacketHeader_t* PacketHeader, SideShow_Application_t* Application); + + #if defined(INCLUDE_FROM_SIDESHOWCONTENT_C) + static void SideShow_ProcessXMLContent(void* ContentData, uint32_t ContentSize); + #endif + +#endif \ No newline at end of file diff --git a/Demos/Device/Incomplete/Sideshow/makefile b/Demos/Device/Incomplete/Sideshow/makefile new file mode 100644 index 0000000000..672d0c00bf --- /dev/null +++ b/Demos/Device/Incomplete/Sideshow/makefile @@ -0,0 +1,668 @@ +# Hey Emacs, this is a -*- makefile -*- +#---------------------------------------------------------------------------- +# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al. +# +# 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 +# +#---------------------------------------------------------------------------- +# 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 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 board (see library BoardTypes.h documentation, USER or blank 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. 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. +# Typical values are: +# F_CPU = 1000000 +# F_CPU = 1843200 +# F_CPU = 2000000 +# F_CPU = 3686400 +# F_CPU = 4000000 +# F_CPU = 7372800 +# F_CPU = 8000000 +# F_CPU = 11059200 +# F_CPU = 14745600 +# F_CPU = 16000000 +# F_CPU = 18432000 +# F_CPU = 20000000 +F_CPU = 8000000 + + +# Output format. (can be srec, ihex, binary) +FORMAT = ihex + + +# Target file name (without extension). +TARGET = Sideshow + + +# Object files directory +# To put object files in current directory, use a dot (.), do NOT make +# this an empty or blank macro! +OBJDIR = . + + +# List C source files here. (C dependencies are automatically generated.) +SRC = $(TARGET).c \ + Descriptors.c \ + SideshowCommon.c \ + SideshowCommands.c \ + SideshowApplications.c \ + SideshowContent.c \ + ../../LUFA/Scheduler/Scheduler.c \ + ../../LUFA/Drivers/USB/LowLevel/LowLevel.c \ + ../../LUFA/Drivers/USB/LowLevel/Endpoint.c \ + ../../LUFA/Drivers/USB/LowLevel/DevChapter9.c \ + ../../LUFA/Drivers/USB/HighLevel/USBTask.c \ + ../../LUFA/Drivers/USB/HighLevel/USBInterrupt.c \ + ../../LUFA/Drivers/USB/HighLevel/Events.c \ + ../../LUFA/Drivers/USB/HighLevel/StdDescriptors.c \ + ../../LUFA/Drivers/AT90USBXXX/Serial_Stream.c \ + ../../LUFA/Drivers/AT90USBXXX/Serial.c \ + + +# 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 = ../../ + + +# 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=gnu99 + + +# Place -D or -U options here for C sources +CDEFS = -DF_CPU=$(F_CPU)UL -DBOARD=BOARD_$(BOARD) -DUSE_NONSTANDARD_DESCRIPTOR_NAMES +CDEFS += -DUSB_DEVICE_ONLY -DUSE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" +CDEFS += -DNO_STREAM_CALLBACKS + + +# Place -D or -U options here for ASM sources +ADEFS = -DF_CPU=$(F_CPU) + + +# Place -D or -U options here for C++ sources +CPPDEFS = -DF_CPU=$(F_CPU)UL +#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 += -fpack-struct +CFLAGS += -fshort-enums +CFLAGS += -finline-limit=20 +CFLAGS += -Wall +CFLAGS += -Wstrict-prototypes +CFLAGS += -Wundef +#CFLAGS += -fno-unit-at-a-time +#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 +CFLAGS += -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: alf avr910 avrisp bascom bsd +# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500 +# +# 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 checkhooks checklibmode 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 + +checkhooks: build + @echo + @echo ------- Unhooked LUFA Events ------- + @$(shell) (grep -s '^Event.*LUFA/.*\\.o' $(TARGET).map | \ + cut -d' ' -f1 | cut -d'_' -f2- | grep ".*") || \ + echo "(None)" + @echo ----- End Unhooked LUFA Events ----- + +checklibmode: + @echo + @echo ----------- Library Mode ----------- + @$(shell) ($(CC) $(ALL_CFLAGS) -E -dM - < /dev/null \ + | grep 'USB_\(DEVICE\|HOST\)_ONLY' | cut -d' ' -f2 | grep ".*") \ + || echo "No specific mode (both device and host mode allowable)." + @echo ------------------------------------ + +# Display compiler version information. +gccversion : + @$(CC) --version + + + +# Program the device. +program: $(TARGET).hex $(TARGET).eep + $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) + + +# 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 $< $@ + +%.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 -z -S $< > $@ + +# 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 clean_binary end + +clean_binary: + $(REMOVE) $(TARGET).hex + +clean_list: + @echo $(MSG_CLEANING) + $(REMOVE) $(TARGET).eep + $(REMOVE) $(TARGET).cof + $(REMOVE) $(TARGET).elf + $(REMOVE) $(TARGET).map + $(REMOVE) $(TARGET).sym + $(REMOVE) $(TARGET).lss + $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o) + $(REMOVE) $(SRC:%.c=$(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. + +# 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 checkhooks checklibmode begin \ +finish end sizebefore sizeafter gccversion \ +build elf hex eep lss sym coff extcoff \ +clean clean_list clean_binary program debug \ +gdb-config doxygen diff --git a/LUFA.pnproj b/LUFA.pnproj index 68aebfbe81..83c62b79a7 100644 --- a/LUFA.pnproj +++ b/LUFA.pnproj @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file