-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2012.\r
- \r
- dean [at] fourwalledcubicle [dot] com\r
- www.lufa-lib.org\r
-*/\r
-\r
-/*\r
- Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
- Copyright 2010 Peter Lawrence (majbthrd [at] gmail [dot] com)\r
-\r
- Permission to use, copy, modify, distribute, and sell this \r
- software and its documentation for any purpose is hereby granted\r
- without fee, provided that the above copyright notice appear in \r
- all copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting \r
- documentation, and that the name of the author not be used in \r
- advertising or publicity pertaining to distribution of the \r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-/** \file\r
- *\r
- * Header file for Descriptors.c.\r
- */\r
- \r
-#ifndef _DESCRIPTORS_H_\r
-#define _DESCRIPTORS_H_\r
-\r
- /* Includes: */\r
- #include <avr/pgmspace.h>\r
-\r
- #include <LUFA/Drivers/USB/USB.h>\r
-\r
- /* Macros: */\r
- /** Endpoint address of the TMC notification IN endpoint. */\r
- #define TMC_NOTIFICATION_EPADDR (ENDPOINT_DIR_IN | 2)\r
-\r
- /** Endpoint address of the TMC device-to-host data IN endpoint. */\r
- #define TMC_IN_EPADDR (ENDPOINT_DIR_IN | 3)\r
-\r
- /** Endpoint address of the TMC host-to-device data OUT endpoint. */\r
- #define TMC_OUT_EPADDR (ENDPOINT_DIR_OUT | 4)\r
-\r
- /** Size in bytes of the TMC data endpoints. */\r
- #define TMC_IO_EPSIZE 64\r
-\r
- /** Size in bytes of the TMC notification endpoint. */\r
- #define TMC_NOTIFICATION_EPSIZE 8\r
-\r
- /* Type Defines: */\r
- /** Type define for the device configuration descriptor structure. This must be defined in the\r
- * application code, as the configuration descriptor contains several sub-descriptors which\r
- * vary between devices, and which describe the device's usage to the host.\r
- */\r
- typedef struct\r
- {\r
- USB_Descriptor_Configuration_Header_t Config;\r
- \r
- // Test and Measurement Interface\r
- USB_Descriptor_Interface_t TM_Interface;\r
- USB_Descriptor_Endpoint_t TM_DataOutEndpoint;\r
- USB_Descriptor_Endpoint_t TM_DataInEndpoint;\r
- USB_Descriptor_Endpoint_t TM_NotificationEndpoint;\r
- } USB_Descriptor_Configuration_t;\r
-\r
- /* Function Prototypes: */\r
- uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,\r
- const uint8_t wIndex,\r
- const void** const DescriptorAddress)\r
- ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);\r
-\r
-#endif\r
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+ Copyright 2010 Peter Lawrence (majbthrd [at] gmail [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 Descriptors.c.
+ */
+
+#ifndef _DESCRIPTORS_H_
+#define _DESCRIPTORS_H_
+
+ /* Includes: */
+ #include <avr/pgmspace.h>
+
+ #include <LUFA/Drivers/USB/USB.h>
+
+ /* Macros: */
+ /** Endpoint address of the TMC notification IN endpoint. */
+ #define TMC_NOTIFICATION_EPADDR (ENDPOINT_DIR_IN | 2)
+
+ /** Endpoint address of the TMC device-to-host data IN endpoint. */
+ #define TMC_IN_EPADDR (ENDPOINT_DIR_IN | 3)
+
+ /** Endpoint address of the TMC host-to-device data OUT endpoint. */
+ #define TMC_OUT_EPADDR (ENDPOINT_DIR_OUT | 4)
+
+ /** Size in bytes of the TMC data endpoints. */
+ #define TMC_IO_EPSIZE 64
+
+ /** Size in bytes of the TMC notification endpoint. */
+ #define TMC_NOTIFICATION_EPSIZE 8
+
+ /* Type Defines: */
+ /** Type define for the device configuration descriptor structure. This must be defined in the
+ * application code, as the configuration descriptor contains several sub-descriptors which
+ * vary between devices, and which describe the device's usage to the host.
+ */
+ typedef struct
+ {
+ USB_Descriptor_Configuration_Header_t Config;
+
+ // Test and Measurement Interface
+ USB_Descriptor_Interface_t TM_Interface;
+ USB_Descriptor_Endpoint_t TM_DataOutEndpoint;
+ USB_Descriptor_Endpoint_t TM_DataInEndpoint;
+ USB_Descriptor_Endpoint_t TM_NotificationEndpoint;
+ } USB_Descriptor_Configuration_t;
+
+ /* Function Prototypes: */
+ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
+ const uint8_t wIndex,
+ const void** const DescriptorAddress)
+ ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
+
+#endif
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2012.\r
- \r
- dean [at] fourwalledcubicle [dot] com\r
- www.lufa-lib.org\r
-*/\r
-\r
-/*\r
- Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, distribute, and sell this \r
- software and its documentation for any purpose is hereby granted\r
- without fee, provided that the above copyright notice appear in \r
- all copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting \r
- documentation, and that the name of the author not be used in \r
- advertising or publicity pertaining to distribution of the \r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-#ifndef _TESTANDMEASUREMENT_H_\r
-#define _TESTANDMEASUREMENT_H_\r
-\r
- /* Includes: */\r
- #include <avr/io.h>\r
- #include <avr/wdt.h>\r
- #include <avr/power.h>\r
- #include <avr/interrupt.h>\r
-\r
- #include "Descriptors.h"\r
-\r
- #include <LUFA/Drivers/USB/USB.h>\r
- #include <LUFA/Drivers/Board/LEDs.h>\r
-\r
- /* Macros: */\r
- /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */\r
- #define LEDMASK_USB_NOTREADY LEDS_LED1\r
-\r
- /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */\r
- #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3)\r
-\r
- /** LED mask for the library LED driver, to indicate that the USB interface is ready. */\r
- #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4)\r
-\r
- /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */\r
- #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3)\r
- \r
- /** LED mask for the library LED driver, to indicate that the USB interface is busy. */\r
- #define LEDMASK_USB_BUSY LEDS_LED2\r
-\r
- #define Req_InitiateAbortBulkOut 0x01\r
- #define Req_CheckAbortBulkOutStatus 0x02\r
- #define Req_InitiateAbortBulkIn 0x03\r
- #define Req_CheckAbortBulkInStatus 0x04\r
- #define Req_InitiateClear 0x05\r
- #define Req_CheckClearStatus 0x06\r
- #define Req_GetCapabilities 0x07\r
- #define Req_IndicatorPulse 0x40\r
- \r
- #define TMC_STATUS_SUCCESS 0x01\r
- #define TMC_STATUS_PENDING 0x02\r
- #define TMC_STATUS_FAILED 0x80\r
- #define TMC_STATUS_TRANSFER_NOT_IN_PROGRESS 0x81\r
- #define TMC_STATUS_SPLIT_NOT_IN_PROGRESS 0x82\r
- #define TMC_STATUS_SPLIT_IN_PROGRESS 0x83\r
- \r
- #define TMC_MESSAGEID_DEV_DEP_MSG_OUT 0x01\r
- #define TMC_MESSAGEID_DEV_DEP_MSG_IN 0x02\r
- #define TMC_MESSAGEID_DEV_VENDOR_OUT 0x7E\r
- #define TMC_MESSAGEID_DEV_VENDOR_IN 0x7F\r
-\r
- /* Type Defines */\r
- typedef struct\r
- {\r
- uint8_t Status;\r
- uint8_t Reserved;\r
-\r
- uint16_t TMCVersion;\r
- \r
- struct\r
- {\r
- unsigned ListenOnly : 1;\r
- unsigned TalkOnly : 1;\r
- unsigned PulseIndicateSupported : 1;\r
- unsigned Reserved : 5;\r
- } Interface;\r
- \r
- struct\r
- {\r
- unsigned SupportsAbortINOnMatch : 1;\r
- unsigned Reserved : 7;\r
- } Device;\r
- \r
- uint8_t Reserved2[6];\r
- uint8_t Reserved3[12]; \r
- } TMC_Capabilities_t;\r
- \r
- typedef struct\r
- {\r
- uint8_t LastMessageTransaction;\r
- uint8_t TermChar;\r
- uint8_t Reserved[2];\r
- } TMC_DevOUTMessageHeader_t;\r
-\r
- typedef struct\r
- {\r
- uint8_t LastMessageTransaction;\r
- uint8_t Reserved[3];\r
- } TMC_DevINMessageHeader_t;\r
-\r
- typedef struct\r
- {\r
- uint8_t MessageID;\r
- uint8_t Tag;\r
- uint8_t InverseTag;\r
- uint8_t Reserved;\r
- uint32_t TransferSize;\r
- \r
- union\r
- {\r
- TMC_DevOUTMessageHeader_t DeviceOUT;\r
- TMC_DevINMessageHeader_t DeviceIN;\r
- uint32_t VendorSpecific;\r
- } MessageIDSpecific;\r
- } TMC_MessageHeader_t;\r
-\r
- /* Function Prototypes: */\r
- void SetupHardware(void);\r
- void TMC_Task(void);\r
- bool ReadTMCHeader(TMC_MessageHeader_t* const MessageHeader);\r
- bool WriteTMCHeader(TMC_MessageHeader_t* const MessageHeader);\r
-\r
- void EVENT_USB_Device_Connect(void);\r
- void EVENT_USB_Device_Disconnect(void);\r
- void EVENT_USB_Device_ConfigurationChanged(void);\r
- void EVENT_USB_Device_ControlRequest(void);\r
-\r
-#endif\r
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 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.
+*/
+
+#ifndef _TESTANDMEASUREMENT_H_
+#define _TESTANDMEASUREMENT_H_
+
+ /* Includes: */
+ #include <avr/io.h>
+ #include <avr/wdt.h>
+ #include <avr/power.h>
+ #include <avr/interrupt.h>
+
+ #include "Descriptors.h"
+
+ #include <LUFA/Drivers/USB/USB.h>
+ #include <LUFA/Drivers/Board/LEDs.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)
+
+ /** LED mask for the library LED driver, to indicate that the USB interface is busy. */
+ #define LEDMASK_USB_BUSY LEDS_LED2
+
+ #define Req_InitiateAbortBulkOut 0x01
+ #define Req_CheckAbortBulkOutStatus 0x02
+ #define Req_InitiateAbortBulkIn 0x03
+ #define Req_CheckAbortBulkInStatus 0x04
+ #define Req_InitiateClear 0x05
+ #define Req_CheckClearStatus 0x06
+ #define Req_GetCapabilities 0x07
+ #define Req_IndicatorPulse 0x40
+
+ #define TMC_STATUS_SUCCESS 0x01
+ #define TMC_STATUS_PENDING 0x02
+ #define TMC_STATUS_FAILED 0x80
+ #define TMC_STATUS_TRANSFER_NOT_IN_PROGRESS 0x81
+ #define TMC_STATUS_SPLIT_NOT_IN_PROGRESS 0x82
+ #define TMC_STATUS_SPLIT_IN_PROGRESS 0x83
+
+ #define TMC_MESSAGEID_DEV_DEP_MSG_OUT 0x01
+ #define TMC_MESSAGEID_DEV_DEP_MSG_IN 0x02
+ #define TMC_MESSAGEID_DEV_VENDOR_OUT 0x7E
+ #define TMC_MESSAGEID_DEV_VENDOR_IN 0x7F
+
+ /* Type Defines */
+ typedef struct
+ {
+ uint8_t Status;
+ uint8_t Reserved;
+
+ uint16_t TMCVersion;
+
+ struct
+ {
+ unsigned ListenOnly : 1;
+ unsigned TalkOnly : 1;
+ unsigned PulseIndicateSupported : 1;
+ unsigned Reserved : 5;
+ } Interface;
+
+ struct
+ {
+ unsigned SupportsAbortINOnMatch : 1;
+ unsigned Reserved : 7;
+ } Device;
+
+ uint8_t Reserved2[6];
+ uint8_t Reserved3[12];
+ } TMC_Capabilities_t;
+
+ typedef struct
+ {
+ uint8_t LastMessageTransaction;
+ uint8_t TermChar;
+ uint8_t Reserved[2];
+ } TMC_DevOUTMessageHeader_t;
+
+ typedef struct
+ {
+ uint8_t LastMessageTransaction;
+ uint8_t Reserved[3];
+ } TMC_DevINMessageHeader_t;
+
+ typedef struct
+ {
+ uint8_t MessageID;
+ uint8_t Tag;
+ uint8_t InverseTag;
+ uint8_t Reserved;
+ uint32_t TransferSize;
+
+ union
+ {
+ TMC_DevOUTMessageHeader_t DeviceOUT;
+ TMC_DevINMessageHeader_t DeviceIN;
+ uint32_t VendorSpecific;
+ } MessageIDSpecific;
+ } TMC_MessageHeader_t;
+
+ /* Function Prototypes: */
+ void SetupHardware(void);
+ void TMC_Task(void);
+ bool ReadTMCHeader(TMC_MessageHeader_t* const MessageHeader);
+ bool WriteTMCHeader(TMC_MessageHeader_t* const MessageHeader);
+
+ void EVENT_USB_Device_Connect(void);
+ void EVENT_USB_Device_Disconnect(void);
+ void EVENT_USB_Device_ConfigurationChanged(void);
+ void EVENT_USB_Device_ControlRequest(void);
+
+#endif
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2012.\r
-\r
- dean [at] fourwalledcubicle [dot] com\r
- www.lufa-lib.org\r
-*/\r
-\r
-/*\r
- Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, distribute, and sell this\r
- software and its documentation for any purpose is hereby granted\r
- without fee, provided that the above copyright notice appear in\r
- all copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting\r
- documentation, and that the name of the author not be used in\r
- advertising or publicity pertaining to distribution of the\r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-/** \file\r
- *\r
- * Main source file for the AndroidAccessoryHost demo. This file contains the main tasks of\r
- * the demo and is responsible for the initial application hardware configuration.\r
- */\r
-\r
-#include "AndroidAccessoryHost.h"\r
-\r
-/** LUFA Android Open Accessory Class driver interface configuration and state information. This\r
- * structure is passed to all Android Open Accessory Class driver functions, so that multiple\r
- * instances of the same class within a device can be differentiated from one another.\r
- */\r
-USB_ClassInfo_AOA_Host_t AndroidDevice_AOA_Interface =\r
- {\r
- .Config =\r
- {\r
- .DataINPipe =\r
- {\r
- .Address = (PIPE_DIR_IN | 1),\r
- .Banks = 1,\r
- },\r
- .DataOUTPipe =\r
- {\r
- .Address = (PIPE_DIR_OUT | 2),\r
- .Banks = 1,\r
- }, \r
- .PropertyStrings =\r
- {\r
- [AOA_STRING_Manufacturer] = "Dean Camera",\r
- [AOA_STRING_Model] = "LUFA Android Demo",\r
- [AOA_STRING_Description] = "LUFA Android Demo",\r
- [AOA_STRING_Version] = "1.0",\r
- [AOA_STRING_URI] = "http://www.lufa-lib.org",\r
- [AOA_STRING_Serial] = "0000000012345678",\r
- },\r
- },\r
- };\r
-\r
-\r
-/** Main program entry point. This routine configures the hardware required by the application, then\r
- * enters a loop to run the application tasks in sequence.\r
- */\r
-int main(void)\r
-{\r
- SetupHardware();\r
- \r
- puts_P(PSTR(ESC_FG_CYAN "Android Accessory Host Demo running.\r\n" ESC_FG_WHITE));\r
-\r
- LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
- sei();\r
-\r
- for (;;)\r
- {\r
- AOAHost_Task();\r
-\r
- AOA_Host_USBTask(&AndroidDevice_AOA_Interface);\r
- USB_USBTask();\r
- }\r
-}\r
-\r
-/** Configures the board hardware and chip peripherals for the demo's functionality. */\r
-void SetupHardware(void)\r
-{\r
- /* Disable watchdog if enabled by bootloader/fuses */\r
- MCUSR &= ~(1 << WDRF);\r
- wdt_disable();\r
-\r
- /* Disable clock division */\r
- clock_prescale_set(clock_div_1);\r
-\r
- /* Hardware Initialization */\r
- Serial_Init(9600, false);\r
- LEDs_Init();\r
- USB_Init();\r
-\r
- /* Create a stdio stream for the serial port for stdin and stdout */\r
- Serial_CreateStream(NULL);\r
-}\r
-\r
-/** Task to manage an enumerated USB Android Accessory device once connected, to print received data\r
- * from the device to the serial port.\r
- */\r
-void AOAHost_Task(void)\r
-{\r
- if (USB_HostState != HOST_STATE_Configured)\r
- return;\r
-\r
- if (AOA_Host_BytesReceived(&AndroidDevice_AOA_Interface))\r
- {\r
- /* Echo received bytes from the attached device through the USART */\r
- int16_t ReceivedByte = AOA_Host_ReceiveByte(&AndroidDevice_AOA_Interface);\r
- if (!(ReceivedByte < 0))\r
- putchar(ReceivedByte);\r
- }\r
-}\r
-\r
-/** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and\r
- * starts the library USB task to begin the enumeration and USB management process.\r
- */\r
-void EVENT_USB_Host_DeviceAttached(void)\r
-{\r
- puts_P(PSTR("Device Attached.\r\n"));\r
- LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);\r
-}\r
-\r
-/** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and\r
- * stops the library USB task management process.\r
- */\r
-void EVENT_USB_Host_DeviceUnattached(void)\r
-{\r
- puts_P(PSTR("\r\nDevice Unattached.\r\n"));\r
- LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
-}\r
-\r
-/** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully\r
- * enumerated by the host and is now ready to be used by the application.\r
- */\r
-void EVENT_USB_Host_DeviceEnumerationComplete(void)\r
-{\r
- LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);\r
-\r
- USB_Descriptor_Device_t DeviceDescriptor;\r
-\r
- if (USB_Host_GetDeviceDescriptor(&DeviceDescriptor) != HOST_SENDCONTROL_Successful)\r
- {\r
- puts_P(PSTR("Error Retrieving Device Descriptor.\r\n"));\r
- LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
- return; \r
- }\r
-\r
- bool NeedModeSwitch;\r
- if (!(AOA_Host_ValidateAccessoryDevice(&AndroidDevice_AOA_Interface, &DeviceDescriptor, &NeedModeSwitch)))\r
- {\r
- puts_P(PSTR("Not an Android device.\r\n"));\r
- LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
- return;\r
- }\r
- \r
- if (NeedModeSwitch)\r
- {\r
- puts_P(PSTR("Not in Accessory mode, switching...\r\n"));\r
- AOA_Host_StartAccessoryMode(&AndroidDevice_AOA_Interface);\r
- return;\r
- }\r
-\r
- uint16_t ConfigDescriptorSize;\r
- uint8_t ConfigDescriptorData[512];\r
-\r
- if (USB_Host_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData,\r
- sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful)\r
- {\r
- puts_P(PSTR("Error Retrieving Configuration Descriptor.\r\n"));\r
- LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
- return;\r
- }\r
-\r
- if (AOA_Host_ConfigurePipes(&AndroidDevice_AOA_Interface,\r
- ConfigDescriptorSize, ConfigDescriptorData) != AOA_ENUMERROR_NoError)\r
- {\r
- puts_P(PSTR("Attached Device Not a Valid Android Accessory Class Device.\r\n"));\r
- LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
- return;\r
- }\r
-\r
- if (USB_Host_SetDeviceConfiguration(1) != HOST_SENDCONTROL_Successful)\r
- {\r
- puts_P(PSTR("Error Setting Device Configuration.\r\n"));\r
- LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
- return;\r
- }\r
-\r
- puts_P(PSTR("Android Device Enumerated.\r\n"));\r
- LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
-}\r
-\r
-/** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */\r
-void EVENT_USB_Host_HostError(const uint8_t ErrorCode)\r
-{\r
- USB_Disable();\r
-\r
- printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"\r
- " -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);\r
-\r
- LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
- for(;;);\r
-}\r
-\r
-/** Event handler for the USB_DeviceEnumerationFailed event. This indicates that a problem occurred while\r
- * enumerating an attached USB device.\r
- */\r
-void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode,\r
- const uint8_t SubErrorCode)\r
-{\r
- printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"\r
- " -- Error Code %d\r\n"\r
- " -- Sub Error Code %d\r\n"\r
- " -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState);\r
-\r
- LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
-}\r
-\r
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 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 AndroidAccessoryHost demo. This file contains the main tasks of
+ * the demo and is responsible for the initial application hardware configuration.
+ */
+
+#include "AndroidAccessoryHost.h"
+
+/** LUFA Android Open Accessory Class driver interface configuration and state information. This
+ * structure is passed to all Android Open Accessory Class driver functions, so that multiple
+ * instances of the same class within a device can be differentiated from one another.
+ */
+USB_ClassInfo_AOA_Host_t AndroidDevice_AOA_Interface =
+ {
+ .Config =
+ {
+ .DataINPipe =
+ {
+ .Address = (PIPE_DIR_IN | 1),
+ .Banks = 1,
+ },
+ .DataOUTPipe =
+ {
+ .Address = (PIPE_DIR_OUT | 2),
+ .Banks = 1,
+ },
+ .PropertyStrings =
+ {
+ [AOA_STRING_Manufacturer] = "Dean Camera",
+ [AOA_STRING_Model] = "LUFA Android Demo",
+ [AOA_STRING_Description] = "LUFA Android Demo",
+ [AOA_STRING_Version] = "1.0",
+ [AOA_STRING_URI] = "http://www.lufa-lib.org",
+ [AOA_STRING_Serial] = "0000000012345678",
+ },
+ },
+ };
+
+
+/** 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 "Android Accessory Host Demo running.\r\n" ESC_FG_WHITE));
+
+ LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
+ sei();
+
+ for (;;)
+ {
+ AOAHost_Task();
+
+ AOA_Host_USBTask(&AndroidDevice_AOA_Interface);
+ 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);
+ LEDs_Init();
+ USB_Init();
+
+ /* Create a stdio stream for the serial port for stdin and stdout */
+ Serial_CreateStream(NULL);
+}
+
+/** Task to manage an enumerated USB Android Accessory device once connected, to print received data
+ * from the device to the serial port.
+ */
+void AOAHost_Task(void)
+{
+ if (USB_HostState != HOST_STATE_Configured)
+ return;
+
+ if (AOA_Host_BytesReceived(&AndroidDevice_AOA_Interface))
+ {
+ /* Echo received bytes from the attached device through the USART */
+ int16_t ReceivedByte = AOA_Host_ReceiveByte(&AndroidDevice_AOA_Interface);
+ if (!(ReceivedByte < 0))
+ putchar(ReceivedByte);
+ }
+}
+
+/** 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("Device Attached.\r\n"));
+ 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("\r\nDevice Unattached.\r\n"));
+ 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_ENUMERATING);
+
+ USB_Descriptor_Device_t DeviceDescriptor;
+
+ if (USB_Host_GetDeviceDescriptor(&DeviceDescriptor) != HOST_SENDCONTROL_Successful)
+ {
+ puts_P(PSTR("Error Retrieving Device Descriptor.\r\n"));
+ LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+ return;
+ }
+
+ bool NeedModeSwitch;
+ if (!(AOA_Host_ValidateAccessoryDevice(&AndroidDevice_AOA_Interface, &DeviceDescriptor, &NeedModeSwitch)))
+ {
+ puts_P(PSTR("Not an Android device.\r\n"));
+ LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+ return;
+ }
+
+ if (NeedModeSwitch)
+ {
+ puts_P(PSTR("Not in Accessory mode, switching...\r\n"));
+ AOA_Host_StartAccessoryMode(&AndroidDevice_AOA_Interface);
+ return;
+ }
+
+ uint16_t ConfigDescriptorSize;
+ uint8_t ConfigDescriptorData[512];
+
+ if (USB_Host_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData,
+ sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful)
+ {
+ puts_P(PSTR("Error Retrieving Configuration Descriptor.\r\n"));
+ LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+ return;
+ }
+
+ if (AOA_Host_ConfigurePipes(&AndroidDevice_AOA_Interface,
+ ConfigDescriptorSize, ConfigDescriptorData) != AOA_ENUMERROR_NoError)
+ {
+ puts_P(PSTR("Attached Device Not a Valid Android Accessory Class Device.\r\n"));
+ LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+ return;
+ }
+
+ if (USB_Host_SetDeviceConfiguration(1) != HOST_SENDCONTROL_Successful)
+ {
+ puts_P(PSTR("Error Setting Device Configuration.\r\n"));
+ LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+ return;
+ }
+
+ puts_P(PSTR("Android Device Enumerated.\r\n"));
+ 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);
+}
+
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2012.\r
-\r
- dean [at] fourwalledcubicle [dot] com\r
- www.lufa-lib.org\r
-*/\r
-\r
-/*\r
- Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, distribute, and sell this\r
- software and its documentation for any purpose is hereby granted\r
- without fee, provided that the above copyright notice appear in\r
- all copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting\r
- documentation, and that the name of the author not be used in\r
- advertising or publicity pertaining to distribution of the\r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-/** \file\r
- *\r
- * Header file for AndroidAccessoryHost.c.\r
- */\r
-\r
-#ifndef _ANDROIDACCESSORY_HOST_H_\r
-#define _ANDROIDACCESSORY_HOST_H_\r
-\r
- /* Includes: */\r
- #include <avr/io.h>\r
- #include <avr/wdt.h>\r
- #include <avr/pgmspace.h>\r
- #include <avr/power.h>\r
- #include <avr/interrupt.h>\r
- #include <stdio.h>\r
-\r
- #include <LUFA/Drivers/Misc/TerminalCodes.h>\r
- #include <LUFA/Drivers/Peripheral/Serial.h>\r
- #include <LUFA/Drivers/Board/LEDs.h>\r
- #include <LUFA/Drivers/USB/USB.h>\r
-\r
- /* Macros: */\r
- /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */\r
- #define LEDMASK_USB_NOTREADY LEDS_LED1\r
-\r
- /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */\r
- #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3)\r
-\r
- /** LED mask for the library LED driver, to indicate that the USB interface is ready. */\r
- #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4)\r
-\r
- /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */\r
- #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3)\r
-\r
- /* Function Prototypes: */\r
- void SetupHardware(void);\r
- void AOAHost_Task(void);\r
-\r
- void EVENT_USB_Host_HostError(const uint8_t ErrorCode);\r
- void EVENT_USB_Host_DeviceAttached(void);\r
- void EVENT_USB_Host_DeviceUnattached(void);\r
- void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode,\r
- const uint8_t SubErrorCode);\r
- void EVENT_USB_Host_DeviceEnumerationComplete(void);\r
-\r
-#endif\r
-\r
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 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 AndroidAccessoryHost.c.
+ */
+
+#ifndef _ANDROIDACCESSORY_HOST_H_
+#define _ANDROIDACCESSORY_HOST_H_
+
+ /* Includes: */
+ #include <avr/io.h>
+ #include <avr/wdt.h>
+ #include <avr/pgmspace.h>
+ #include <avr/power.h>
+ #include <avr/interrupt.h>
+ #include <stdio.h>
+
+ #include <LUFA/Drivers/Misc/TerminalCodes.h>
+ #include <LUFA/Drivers/Peripheral/Serial.h>
+ #include <LUFA/Drivers/Board/LEDs.h>
+ #include <LUFA/Drivers/USB/USB.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 SetupHardware(void);
+ void AOAHost_Task(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
+
-#\r
-# LUFA Library\r
-# Copyright (C) Dean Camera, 2012.\r
-#\r
-# dean [at] fourwalledcubicle [dot] com\r
-# www.lufa-lib.org\r
-#\r
-\r
-LUFA_BUILD_MODULES += HID\r
-LUFA_BUILD_TARGETS += hid hid-teensy\r
-LUFA_BUILD_MANDATORY_VARS += MCU TARGET\r
-LUFA_BUILD_OPTIONAL_VARS += \r
-LUFA_BUILD_PROVIDED_VARS += \r
-LUFA_BUILD_PROVIDED_MACROS += \r
-\r
-# -----------------------------------------------------------------------------\r
-# LUFA HID Bootloader Buildsystem Makefile Module.\r
-# -----------------------------------------------------------------------------\r
-# DESCRIPTION:\r
-# Provides a set of targets to re-program a device currently running a HID\r
-# class bootloader with a project's FLASH files.\r
-# -----------------------------------------------------------------------------\r
-# TARGETS:\r
-#\r
-# hid - Program FLASH into target via\r
-# hid_bootloader_cli\r
-# hid-teensy - Program FLASH into target via\r
-# teensy_loader_cli\r
-#\r
-# MANDATORY PARAMETERS:\r
-#\r
-# MCU - Microcontroller device model name\r
-# TARGET - Application name\r
-#\r
-# OPTIONAL PARAMETERS:\r
-#\r
-# (None)\r
-#\r
-# PROVIDED VARIABLES:\r
-#\r
-# (None)\r
-#\r
-# PROVIDED MACROS:\r
-#\r
-# (None)\r
-#\r
-# -----------------------------------------------------------------------------\r
-\r
-ERROR_IF_UNSET ?= $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set))\r
-ERROR_IF_EMPTY ?= $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank))\r
-ERROR_IF_NONBOOL ?= $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N))\r
-\r
-# Sanity-check values of mandatory user-supplied variables\r
-$(foreach MANDATORY_VAR, $(LUFA_BUILD_MANDATORY_VARS), $(call ERROR_IF_UNSET, $(MANDATORY_VAR)))\r
-$(call ERROR_IF_EMPTY, MCU)\r
-$(call ERROR_IF_EMPTY, TARGET)\r
-\r
-# Output Messages\r
-MSG_HID_BOOTLOADER_CMD := ' [HID] :'\r
-\r
-hid: $(TARGET).hex $(MAKEFILE_LIST)\r
- @echo $(MSG_HID_BOOTLOADER_CMD) Programming FLASH with hid_bootloader_cli using \"$<\"\r
- hid_bootloader_cli -mmcu=$(MCU) -v $<\r
-\r
-hid-teensy: $(TARGET).hex $(MAKEFILE_LIST)\r
- @echo $(MSG_HID_BOOTLOADER_CMD) Programming FLASH with teensy_loader_cli using \"$<\"\r
- teensy_loader_cli -mmcu=$(MCU) -v $<\r
-\r
-# Phony build targets for this module\r
-.PHONY: hid hid-teensy\r
+#
+# LUFA Library
+# Copyright (C) Dean Camera, 2012.
+#
+# dean [at] fourwalledcubicle [dot] com
+# www.lufa-lib.org
+#
+
+LUFA_BUILD_MODULES += HID
+LUFA_BUILD_TARGETS += hid hid-teensy
+LUFA_BUILD_MANDATORY_VARS += MCU TARGET
+LUFA_BUILD_OPTIONAL_VARS +=
+LUFA_BUILD_PROVIDED_VARS +=
+LUFA_BUILD_PROVIDED_MACROS +=
+
+# -----------------------------------------------------------------------------
+# LUFA HID Bootloader Buildsystem Makefile Module.
+# -----------------------------------------------------------------------------
+# DESCRIPTION:
+# Provides a set of targets to re-program a device currently running a HID
+# class bootloader with a project's FLASH files.
+# -----------------------------------------------------------------------------
+# TARGETS:
+#
+# hid - Program FLASH into target via
+# hid_bootloader_cli
+# hid-teensy - Program FLASH into target via
+# teensy_loader_cli
+#
+# MANDATORY PARAMETERS:
+#
+# MCU - Microcontroller device model name
+# TARGET - Application name
+#
+# OPTIONAL PARAMETERS:
+#
+# (None)
+#
+# PROVIDED VARIABLES:
+#
+# (None)
+#
+# PROVIDED MACROS:
+#
+# (None)
+#
+# -----------------------------------------------------------------------------
+
+ERROR_IF_UNSET ?= $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set))
+ERROR_IF_EMPTY ?= $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank))
+ERROR_IF_NONBOOL ?= $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N))
+
+# Sanity-check values of mandatory user-supplied variables
+$(foreach MANDATORY_VAR, $(LUFA_BUILD_MANDATORY_VARS), $(call ERROR_IF_UNSET, $(MANDATORY_VAR)))
+$(call ERROR_IF_EMPTY, MCU)
+$(call ERROR_IF_EMPTY, TARGET)
+
+# Output Messages
+MSG_HID_BOOTLOADER_CMD := ' [HID] :'
+
+hid: $(TARGET).hex $(MAKEFILE_LIST)
+ @echo $(MSG_HID_BOOTLOADER_CMD) Programming FLASH with hid_bootloader_cli using \"$<\"
+ hid_bootloader_cli -mmcu=$(MCU) -v $<
+
+hid-teensy: $(TARGET).hex $(MAKEFILE_LIST)
+ @echo $(MSG_HID_BOOTLOADER_CMD) Programming FLASH with teensy_loader_cli using \"$<\"
+ teensy_loader_cli -mmcu=$(MCU) -v $<
+
+# Phony build targets for this module
+.PHONY: hid hid-teensy
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2012.\r
-\r
- dean [at] fourwalledcubicle [dot] com\r
- www.lufa-lib.org\r
-*/\r
-\r
-/*\r
- Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, distribute, and sell this\r
- software and its documentation for any purpose is hereby granted\r
- without fee, provided that the above copyright notice appear in\r
- all copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting\r
- documentation, and that the name of the author not be used in\r
- advertising or publicity pertaining to distribution of the\r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-/** \file\r
- * \brief Board specific Buttons driver header for the Micropendous series boards.\r
- * \copydetails Group_Buttons_MICROPENDOUS_32U2\r
- *\r
- * \note This file should not be included directly. It is automatically included as needed by the Buttons driver\r
- * dispatch header located in LUFA/Drivers/Board/Buttons.h.\r
- */\r
-\r
-/** \ingroup Group_Buttons\r
- * \defgroup Group_Buttons_MICROPENDOUS_A MICROPENDOUS_A\r
- * \brief Board specific Button driver header for the Micropendous A (https://code.google.com/p/micropendous/wiki/MicropendousA).\r
- *\r
- * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details.\r
- */\r
-\r
-/** \ingroup Group_Buttons\r
- * \defgroup Group_Buttons_MICROPENDOUS_1 MICROPENDOUS_1\r
- * \brief Board specific Button driver header for the Micropendous 1 (https://code.google.com/p/micropendous/wiki/Micropendous1).\r
- *\r
- * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details.\r
- */\r
-\r
-/** \ingroup Group_Buttons\r
- * \defgroup Group_Buttons_MICROPENDOUS_2 MICROPENDOUS_2\r
- * \brief Board specific Button driver header for the Micropendous 2 (https://code.google.com/p/micropendous/wiki/Micropendous2).\r
- *\r
- * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details.\r
- */\r
- \r
-/** \ingroup Group_Buttons\r
- * \defgroup Group_Buttons_MICROPENDOUS_3 MICROPENDOUS_3\r
- * \brief Board specific Button driver header for the Micropendous 3 (https://code.google.com/p/micropendous/wiki/Micropendous3).\r
- *\r
- * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details.\r
- */\r
- \r
-/** \ingroup Group_Buttons\r
- * \defgroup Group_Buttons_MICROPENDOUS_4 MICROPENDOUS_4\r
- * \brief Board specific Button driver header for the Micropendous 4 (https://code.google.com/p/micropendous/wiki/Micropendous4).\r
- *\r
- * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details.\r
- */\r
-\r
-/** \ingroup Group_Buttons\r
- * \defgroup Group_Buttons_MICROPENDOUS_DIP MICROPENDOUS_DIP\r
- * \brief Board specific Button driver header for the Micropendous DIP (https://code.google.com/p/micropendous/wiki/MicropendousDIP).\r
- *\r
- * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details.\r
- */\r
-\r
-/** \ingroup Group_Buttons\r
- * \defgroup Group_Buttons_MICROPENDOUS_REV1 MICROPENDOUS_REV1\r
- * \brief Board specific Button driver header for the Micropendous Arduino-like Revision 1 (https://code.google.com/p/micropendous/wiki/Micropendous).\r
- *\r
- * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details.\r
- */\r
-\r
-/** \ingroup Group_Buttons\r
- * \defgroup Group_Buttons_MICROPENDOUS_REV2 MICROPENDOUS_REV2\r
- * \brief Board specific Button driver header for the Micropendous Arduino-like Revision 2 (https://code.google.com/p/micropendous/wiki/Micropendous).\r
- *\r
- * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details.\r
- */\r
-\r
-/** \ingroup Group_Buttons\r
- * \defgroup Group_Buttons_MICROPENDOUS_32U2 MICROPENDOUS_32U2\r
- * \brief Board specific Buttons driver header for the Micropendous 32U2.\r
- *\r
- * \note There are multiple supported Micropendous boards, compile with <code>BOARD = MICROPENDOUS_{VERSION}</code>.\r
- *\r
- * Board specific Buttons driver header for the Micropendous 32U2 (https://code.google.com/p/micropendous/wiki/Micropendous_32U2).\r
- *\r
- * <b>BOARD_MICROPENDOUS_1 and BOARD_MICROPENDOUS_32U2</b>:\r
- * <table>\r
- * <tr><th>Name</th><th>Info</th><th>Active Level</th><th>Port Pin</th></tr>\r
- * <tr><td>BUTTONS_BUTTON1</td><td>HWB Button</td><td>Low</td><td>PORTD.7</td></tr>\r
- * </table>\r
- *\r
- * <b>Other Revisions</b>:\r
- * <table>\r
- * <tr><th>Name</th><th>Info</th><th>Active Level</th><th>Port Pin</th></tr>\r
- * <tr><td>BUTTONS_BUTTON1</td><td>HWB Button</td><td>Low</td><td>PORTE.2</td></tr>\r
- * </table>\r
- *\r
- * @{\r
- */\r
-\r
-#ifndef __BUTTONS_MICROPENDOUS_H__\r
-#define __BUTTONS_MICROPENDOUS_H__\r
-\r
- /* Includes: */\r
- #include "../../../../Common/Common.h"\r
-\r
- /* Enable C linkage for C++ Compilers: */\r
- #if defined(__cplusplus)\r
- extern "C" {\r
- #endif\r
-\r
- /* Preprocessor Checks: */\r
- #if !defined(__INCLUDE_FROM_BUTTONS_H)\r
- #error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead.\r
- #endif\r
-\r
- /* Private Interface - For use in library only: */\r
- #if !defined(__DOXYGEN__)\r
- #if (BOARD == BOARD_MICROPENDOUS_32U2)\r
- #define _BOARD_BUTTON1_MASK (1 << 7)\r
- #define _BOARD_BUTTON_PORTLETTER D\r
- #elif (BOARD == BOARD_MICROPENDOUS_A)\r
- #define _BOARD_BUTTON1_MASK (1 << 2)\r
- #define _BOARD_BUTTON_PORTLETTER E\r
- #elif (BOARD == BOARD_MICROPENDOUS_1)\r
- #define _BOARD_BUTTON1_MASK (1 << 7)\r
- #define _BOARD_BUTTON_PORTLETTER D\r
- #elif (BOARD == BOARD_MICROPENDOUS_2)\r
- #define _BOARD_BUTTON1_MASK (1 << 2)\r
- #define _BOARD_BUTTON_PORTLETTER E\r
- #elif (BOARD == BOARD_MICROPENDOUS_3)\r
- #define _BOARD_BUTTON1_MASK (1 << 2)\r
- #define _BOARD_BUTTON_PORTLETTER E\r
- #elif (BOARD == BOARD_MICROPENDOUS_4)\r
- #define _BOARD_BUTTON1_MASK (1 << 2)\r
- #define _BOARD_BUTTON_PORTLETTER E\r
- #elif (BOARD == BOARD_MICROPENDOUS_DIP)\r
- #define _BOARD_BUTTON1_MASK (1 << 2)\r
- #define _BOARD_BUTTON_PORTLETTER E\r
- #elif (BOARD == BOARD_MICROPENDOUS_REV1)\r
- #define _BOARD_BUTTON1_MASK (1 << 2)\r
- #define _BOARD_BUTTON_PORTLETTER E\r
- #elif (BOARD == BOARD_MICROPENDOUS_REV2)\r
- #define _BOARD_BUTTON1_MASK (1 << 2)\r
- #define _BOARD_BUTTON_PORTLETTER E\r
- #endif\r
- \r
- #define _BOARD_BUTTON_CONCAT2(Reg, Letter) Reg ## Letter\r
- #define _BOARD_BUTTON_CONCAT(Reg, Letter) _BOARD_BUTTON_CONCAT2(Reg, Letter)\r
-\r
- #define _BOARD_BUTTON_PORT _BOARD_BUTTON_CONCAT(PORT, _BOARD_BUTTON_PORTLETTER)\r
- #define _BOARD_BUTTON_PIN _BOARD_BUTTON_CONCAT(PIN, _BOARD_BUTTON_PORTLETTER)\r
- #define _BOARD_BUTTON_DDR _BOARD_BUTTON_CONCAT(DDR, _BOARD_BUTTON_PORTLETTER)\r
- #endif\r
-\r
- /* Public Interface - May be used in end-application: */\r
- /* Macros: */\r
- /** Button mask for the first button on the board. */\r
- #define BUTTONS_BUTTON1 _BOARD_BUTTON1_MASK\r
-\r
- /* Inline Functions: */\r
- #if !defined(__DOXYGEN__)\r
- static inline void Buttons_Init(void)\r
- {\r
- _BOARD_BUTTON_DDR &= ~BUTTONS_BUTTON1;\r
- _BOARD_BUTTON_PORT |= BUTTONS_BUTTON1;\r
- }\r
-\r
- static inline void Buttons_Disable(void)\r
- {\r
- _BOARD_BUTTON_DDR &= ~BUTTONS_BUTTON1;\r
- _BOARD_BUTTON_PORT &= ~BUTTONS_BUTTON1;\r
- }\r
-\r
- static inline uint8_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT;\r
- static inline uint8_t Buttons_GetStatus(void)\r
- {\r
- return ((_BOARD_BUTTON_PIN & BUTTONS_BUTTON1) ^ BUTTONS_BUTTON1);\r
- }\r
- #endif\r
-\r
- /* Disable C linkage for C++ Compilers: */\r
- #if defined(__cplusplus)\r
- }\r
- #endif\r
-\r
-#endif\r
-\r
-/** @} */\r
-\r
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 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
+ * \brief Board specific Buttons driver header for the Micropendous series boards.
+ * \copydetails Group_Buttons_MICROPENDOUS_32U2
+ *
+ * \note This file should not be included directly. It is automatically included as needed by the Buttons driver
+ * dispatch header located in LUFA/Drivers/Board/Buttons.h.
+ */
+
+/** \ingroup Group_Buttons
+ * \defgroup Group_Buttons_MICROPENDOUS_A MICROPENDOUS_A
+ * \brief Board specific Button driver header for the Micropendous A (https://code.google.com/p/micropendous/wiki/MicropendousA).
+ *
+ * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details.
+ */
+
+/** \ingroup Group_Buttons
+ * \defgroup Group_Buttons_MICROPENDOUS_1 MICROPENDOUS_1
+ * \brief Board specific Button driver header for the Micropendous 1 (https://code.google.com/p/micropendous/wiki/Micropendous1).
+ *
+ * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details.
+ */
+
+/** \ingroup Group_Buttons
+ * \defgroup Group_Buttons_MICROPENDOUS_2 MICROPENDOUS_2
+ * \brief Board specific Button driver header for the Micropendous 2 (https://code.google.com/p/micropendous/wiki/Micropendous2).
+ *
+ * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details.
+ */
+
+/** \ingroup Group_Buttons
+ * \defgroup Group_Buttons_MICROPENDOUS_3 MICROPENDOUS_3
+ * \brief Board specific Button driver header for the Micropendous 3 (https://code.google.com/p/micropendous/wiki/Micropendous3).
+ *
+ * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details.
+ */
+
+/** \ingroup Group_Buttons
+ * \defgroup Group_Buttons_MICROPENDOUS_4 MICROPENDOUS_4
+ * \brief Board specific Button driver header for the Micropendous 4 (https://code.google.com/p/micropendous/wiki/Micropendous4).
+ *
+ * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details.
+ */
+
+/** \ingroup Group_Buttons
+ * \defgroup Group_Buttons_MICROPENDOUS_DIP MICROPENDOUS_DIP
+ * \brief Board specific Button driver header for the Micropendous DIP (https://code.google.com/p/micropendous/wiki/MicropendousDIP).
+ *
+ * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details.
+ */
+
+/** \ingroup Group_Buttons
+ * \defgroup Group_Buttons_MICROPENDOUS_REV1 MICROPENDOUS_REV1
+ * \brief Board specific Button driver header for the Micropendous Arduino-like Revision 1 (https://code.google.com/p/micropendous/wiki/Micropendous).
+ *
+ * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details.
+ */
+
+/** \ingroup Group_Buttons
+ * \defgroup Group_Buttons_MICROPENDOUS_REV2 MICROPENDOUS_REV2
+ * \brief Board specific Button driver header for the Micropendous Arduino-like Revision 2 (https://code.google.com/p/micropendous/wiki/Micropendous).
+ *
+ * See \ref Group_Buttons_MICROPENDOUS_32U2 for more details.
+ */
+
+/** \ingroup Group_Buttons
+ * \defgroup Group_Buttons_MICROPENDOUS_32U2 MICROPENDOUS_32U2
+ * \brief Board specific Buttons driver header for the Micropendous 32U2.
+ *
+ * \note There are multiple supported Micropendous boards, compile with <code>BOARD = MICROPENDOUS_{VERSION}</code>.
+ *
+ * Board specific Buttons driver header for the Micropendous 32U2 (https://code.google.com/p/micropendous/wiki/Micropendous_32U2).
+ *
+ * <b>BOARD_MICROPENDOUS_1 and BOARD_MICROPENDOUS_32U2</b>:
+ * <table>
+ * <tr><th>Name</th><th>Info</th><th>Active Level</th><th>Port Pin</th></tr>
+ * <tr><td>BUTTONS_BUTTON1</td><td>HWB Button</td><td>Low</td><td>PORTD.7</td></tr>
+ * </table>
+ *
+ * <b>Other Revisions</b>:
+ * <table>
+ * <tr><th>Name</th><th>Info</th><th>Active Level</th><th>Port Pin</th></tr>
+ * <tr><td>BUTTONS_BUTTON1</td><td>HWB Button</td><td>Low</td><td>PORTE.2</td></tr>
+ * </table>
+ *
+ * @{
+ */
+
+#ifndef __BUTTONS_MICROPENDOUS_H__
+#define __BUTTONS_MICROPENDOUS_H__
+
+ /* Includes: */
+ #include "../../../../Common/Common.h"
+
+ /* Enable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ extern "C" {
+ #endif
+
+ /* Preprocessor Checks: */
+ #if !defined(__INCLUDE_FROM_BUTTONS_H)
+ #error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead.
+ #endif
+
+ /* Private Interface - For use in library only: */
+ #if !defined(__DOXYGEN__)
+ #if (BOARD == BOARD_MICROPENDOUS_32U2)
+ #define _BOARD_BUTTON1_MASK (1 << 7)
+ #define _BOARD_BUTTON_PORTLETTER D
+ #elif (BOARD == BOARD_MICROPENDOUS_A)
+ #define _BOARD_BUTTON1_MASK (1 << 2)
+ #define _BOARD_BUTTON_PORTLETTER E
+ #elif (BOARD == BOARD_MICROPENDOUS_1)
+ #define _BOARD_BUTTON1_MASK (1 << 7)
+ #define _BOARD_BUTTON_PORTLETTER D
+ #elif (BOARD == BOARD_MICROPENDOUS_2)
+ #define _BOARD_BUTTON1_MASK (1 << 2)
+ #define _BOARD_BUTTON_PORTLETTER E
+ #elif (BOARD == BOARD_MICROPENDOUS_3)
+ #define _BOARD_BUTTON1_MASK (1 << 2)
+ #define _BOARD_BUTTON_PORTLETTER E
+ #elif (BOARD == BOARD_MICROPENDOUS_4)
+ #define _BOARD_BUTTON1_MASK (1 << 2)
+ #define _BOARD_BUTTON_PORTLETTER E
+ #elif (BOARD == BOARD_MICROPENDOUS_DIP)
+ #define _BOARD_BUTTON1_MASK (1 << 2)
+ #define _BOARD_BUTTON_PORTLETTER E
+ #elif (BOARD == BOARD_MICROPENDOUS_REV1)
+ #define _BOARD_BUTTON1_MASK (1 << 2)
+ #define _BOARD_BUTTON_PORTLETTER E
+ #elif (BOARD == BOARD_MICROPENDOUS_REV2)
+ #define _BOARD_BUTTON1_MASK (1 << 2)
+ #define _BOARD_BUTTON_PORTLETTER E
+ #endif
+
+ #define _BOARD_BUTTON_CONCAT2(Reg, Letter) Reg ## Letter
+ #define _BOARD_BUTTON_CONCAT(Reg, Letter) _BOARD_BUTTON_CONCAT2(Reg, Letter)
+
+ #define _BOARD_BUTTON_PORT _BOARD_BUTTON_CONCAT(PORT, _BOARD_BUTTON_PORTLETTER)
+ #define _BOARD_BUTTON_PIN _BOARD_BUTTON_CONCAT(PIN, _BOARD_BUTTON_PORTLETTER)
+ #define _BOARD_BUTTON_DDR _BOARD_BUTTON_CONCAT(DDR, _BOARD_BUTTON_PORTLETTER)
+ #endif
+
+ /* Public Interface - May be used in end-application: */
+ /* Macros: */
+ /** Button mask for the first button on the board. */
+ #define BUTTONS_BUTTON1 _BOARD_BUTTON1_MASK
+
+ /* Inline Functions: */
+ #if !defined(__DOXYGEN__)
+ static inline void Buttons_Init(void)
+ {
+ _BOARD_BUTTON_DDR &= ~BUTTONS_BUTTON1;
+ _BOARD_BUTTON_PORT |= BUTTONS_BUTTON1;
+ }
+
+ static inline void Buttons_Disable(void)
+ {
+ _BOARD_BUTTON_DDR &= ~BUTTONS_BUTTON1;
+ _BOARD_BUTTON_PORT &= ~BUTTONS_BUTTON1;
+ }
+
+ static inline uint8_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT;
+ static inline uint8_t Buttons_GetStatus(void)
+ {
+ return ((_BOARD_BUTTON_PIN & BUTTONS_BUTTON1) ^ BUTTONS_BUTTON1);
+ }
+ #endif
+
+ /* Disable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ }
+ #endif
+
+#endif
+
+/** @} */
+
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2012.\r
-\r
- dean [at] fourwalledcubicle [dot] com\r
- www.lufa-lib.org\r
-*/\r
-\r
-/*\r
- Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, distribute, and sell this\r
- software and its documentation for any purpose is hereby granted\r
- without fee, provided that the above copyright notice appear in\r
- all copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting\r
- documentation, and that the name of the author not be used in\r
- advertising or publicity pertaining to distribution of the\r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-/** \file\r
- * \brief Board specific Buttons driver header for the Paranoid Studio USB2AX.\r
- * \copydetails Group_Buttons_USB2AX\r
- *\r
- * \note This file should not be included directly. It is automatically included as needed by the Buttons driver\r
- * dispatch header located in LUFA/Drivers/Board/Buttons.h.\r
- */\r
-\r
-/** \ingroup Group_Buttons\r
- * \defgroup Group_Buttons_USB2AX_V3 USB2AX_V3\r
- * \brief Board specific Button driver header for the Paranoid Studio USB2AX revision 3.\r
- *\r
- * See \ref Group_Buttons_USB2AX for more details.\r
- */\r
-\r
-/** \ingroup Group_Buttons\r
- * \defgroup Group_Buttons_USB2AX USB2AX\r
- * \brief Board specific Buttons driver header for the Paranoid Studio USB2AX.\r
- *\r
- * \note For version 3 USB2AX boards, compile with <code>BOARD = USB2AX_V3</code>.\r
- *\r
- * Board specific Buttons driver header for the Paranoid Studio USB2AX (http://paranoidstudio.assembla.com/wiki/show/paranoidstudio/USB2AX).\r
- *\r
- * <table>\r
- * <tr><th>Name</th><th>Info</th><th>Active Level</th><th>Port Pin</th></tr>\r
- * <tr><td>BUTTONS_BUTTON1</td><td>HWB Button</td><td>Low</td><td>PORTD.7</td></tr>\r
- * </table>\r
- *\r
- * @{\r
- */\r
-\r
-#ifndef __BUTTONS_USB2AX_H__\r
-#define __BUTTONS_USB2AX_H__\r
-\r
- /* Includes: */\r
- #include "../../../../Common/Common.h"\r
-\r
- /* Enable C linkage for C++ Compilers: */\r
- #if defined(__cplusplus)\r
- extern "C" {\r
- #endif\r
-\r
- /* Preprocessor Checks: */\r
- #if !defined(__INCLUDE_FROM_BUTTONS_H)\r
- #error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead.\r
- #endif\r
-\r
- /* Public Interface - May be used in end-application: */\r
- /* Macros: */\r
- /** Button mask for the first button on the board. */\r
- #define BUTTONS_BUTTON1 (1 << 7)\r
-\r
- /* Inline Functions: */\r
- #if !defined(__DOXYGEN__)\r
- static inline void Buttons_Init(void)\r
- {\r
- DDRD &= ~BUTTONS_BUTTON1;\r
- PORTD |= BUTTONS_BUTTON1;\r
- }\r
-\r
- static inline void Buttons_Disable(void)\r
- {\r
- DDRD &= ~BUTTONS_BUTTON1;\r
- PORTD &= ~BUTTONS_BUTTON1;\r
- }\r
-\r
- static inline uint8_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT;\r
- static inline uint8_t Buttons_GetStatus(void)\r
- {\r
- return ((PIND & BUTTONS_BUTTON1) ^ BUTTONS_BUTTON1);\r
- }\r
- #endif\r
-\r
- /* Disable C linkage for C++ Compilers: */\r
- #if defined(__cplusplus)\r
- }\r
- #endif\r
-\r
-#endif\r
-\r
-/** @} */\r
-\r
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 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
+ * \brief Board specific Buttons driver header for the Paranoid Studio USB2AX.
+ * \copydetails Group_Buttons_USB2AX
+ *
+ * \note This file should not be included directly. It is automatically included as needed by the Buttons driver
+ * dispatch header located in LUFA/Drivers/Board/Buttons.h.
+ */
+
+/** \ingroup Group_Buttons
+ * \defgroup Group_Buttons_USB2AX_V3 USB2AX_V3
+ * \brief Board specific Button driver header for the Paranoid Studio USB2AX revision 3.
+ *
+ * See \ref Group_Buttons_USB2AX for more details.
+ */
+
+/** \ingroup Group_Buttons
+ * \defgroup Group_Buttons_USB2AX USB2AX
+ * \brief Board specific Buttons driver header for the Paranoid Studio USB2AX.
+ *
+ * \note For version 3 USB2AX boards, compile with <code>BOARD = USB2AX_V3</code>.
+ *
+ * Board specific Buttons driver header for the Paranoid Studio USB2AX (http://paranoidstudio.assembla.com/wiki/show/paranoidstudio/USB2AX).
+ *
+ * <table>
+ * <tr><th>Name</th><th>Info</th><th>Active Level</th><th>Port Pin</th></tr>
+ * <tr><td>BUTTONS_BUTTON1</td><td>HWB Button</td><td>Low</td><td>PORTD.7</td></tr>
+ * </table>
+ *
+ * @{
+ */
+
+#ifndef __BUTTONS_USB2AX_H__
+#define __BUTTONS_USB2AX_H__
+
+ /* Includes: */
+ #include "../../../../Common/Common.h"
+
+ /* Enable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ extern "C" {
+ #endif
+
+ /* Preprocessor Checks: */
+ #if !defined(__INCLUDE_FROM_BUTTONS_H)
+ #error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead.
+ #endif
+
+ /* Public Interface - May be used in end-application: */
+ /* Macros: */
+ /** Button mask for the first button on the board. */
+ #define BUTTONS_BUTTON1 (1 << 7)
+
+ /* Inline Functions: */
+ #if !defined(__DOXYGEN__)
+ static inline void Buttons_Init(void)
+ {
+ DDRD &= ~BUTTONS_BUTTON1;
+ PORTD |= BUTTONS_BUTTON1;
+ }
+
+ static inline void Buttons_Disable(void)
+ {
+ DDRD &= ~BUTTONS_BUTTON1;
+ PORTD &= ~BUTTONS_BUTTON1;
+ }
+
+ static inline uint8_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT;
+ static inline uint8_t Buttons_GetStatus(void)
+ {
+ return ((PIND & BUTTONS_BUTTON1) ^ BUTTONS_BUTTON1);
+ }
+ #endif
+
+ /* Disable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ }
+ #endif
+
+#endif
+
+/** @} */
+
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2012.\r
-\r
- dean [at] fourwalledcubicle [dot] com\r
- www.lufa-lib.org\r
-*/\r
-\r
-/*\r
- Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, distribute, and sell this\r
- software and its documentation for any purpose is hereby granted\r
- without fee, provided that the above copyright notice appear in\r
- all copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting\r
- documentation, and that the name of the author not be used in\r
- advertising or publicity pertaining to distribution of the\r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-/** \file\r
- * \brief Board specific LED driver header for the Paranoid Studio USB2AX.\r
- * \copydetails Group_LEDs_USB2AX\r
- *\r
- * \note This file should not be included directly. It is automatically included as needed by the LEDs driver\r
- * dispatch header located in LUFA/Drivers/Board/LEDs.h.\r
- */\r
- \r
-/** \ingroup Group_LEDs\r
- * \defgroup Group_LEDs_USB2AX_V3 USB2AX_V3\r
- * \brief Board specific LED driver header for the Paranoid Studio USB2AX revision 3.\r
- *\r
- * See \ref Group_LEDs_USB2AX for more details.\r
- */\r
-\r
-/** \ingroup Group_LEDs\r
- * \defgroup Group_LEDs_USB2AX USB2AX\r
- * \brief Board specific LED driver header for the Paranoid Studio USB2AX.\r
- *\r
- * \note For version 3 USB2AX boards, compile with <code>BOARD = USB2AX_V3</code>.\r
- *\r
- * Board specific LED driver header for the Paranoid Studio USB2AX (http://paranoidstudio.assembla.com/wiki/show/paranoidstudio/USB2AX).\r
- *\r
- * <b>USB2AX</b>:\r
- * <table>\r
- * <tr><th>Name</th><th>Color</th><th>Info</th><th>Active Level</th><th>Port Pin</th></tr>\r
- * <tr><td>LEDS_LED1</td><td>Green</td><td>General Indicator</td><td>High</td><td>PORTC.6</td></tr>\r
- * </table>\r
- *\r
- * <b>USB2AX_V3</b>:\r
- * <table>\r
- * <tr><th>Name</th><th>Color</th><th>Info</th><th>Active Level</th><th>Port Pin</th></tr>\r
- * <tr><td>LEDS_LED1</td><td>Green</td><td>General Indicator</td><td>High</td><td>PORTD.1</td></tr>\r
- * </table>\r
- *\r
- * @{\r
- */\r
-\r
-#ifndef __LEDS_USB2AX_H__\r
-#define __LEDS_USB2AX_H__\r
-\r
- /* Includes: */\r
- #include "../../../../Common/Common.h"\r
-\r
- /* Enable C linkage for C++ Compilers: */\r
- #if defined(__cplusplus)\r
- extern "C" {\r
- #endif\r
-\r
- /* Preprocessor Checks: */\r
- #if !defined(__INCLUDE_FROM_LEDS_H)\r
- #error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.\r
- #endif\r
-\r
- /* Private Interface - For use in library only: */\r
- #if !defined(__DOXYGEN__)\r
- /* Macros: */\r
- #if (BOARD == BOARD_USB2AX)\r
- #define USB2AX_LEDS_LED1 (1 << 6)\r
- #else\r
- #define USB2AX_LEDS_LED1 (1 << 1) \r
- #endif\r
- #endif\r
-\r
- /* Public Interface - May be used in end-application: */\r
- /* Macros: */\r
- /** LED mask for the first LED on the board. */\r
- #define LEDS_LED1 USB2AX_LEDS_LED1\r
-\r
- /** LED mask for all the LEDs on the board. */\r
- #define LEDS_ALL_LEDS LEDS_LED1\r
-\r
- /** LED mask for none of the board LEDs. */\r
- #define LEDS_NO_LEDS 0\r
-\r
- /* Inline Functions: */\r
- #if !defined(__DOXYGEN__)\r
- static inline void LEDs_Init(void)\r
- {\r
- #if (BOARD == BOARD_USB2AX)\r
- DDRC |= LEDS_ALL_LEDS;\r
- PORTC &= ~LEDS_ALL_LEDS; \r
- #else\r
- DDRD |= LEDS_ALL_LEDS;\r
- PORTD &= ~LEDS_ALL_LEDS; \r
- #endif \r
- }\r
-\r
- static inline void LEDs_Disable(void)\r
- {\r
- #if (BOARD == BOARD_USB2AX)\r
- DDRC &= ~LEDS_ALL_LEDS;\r
- PORTC &= ~LEDS_ALL_LEDS; \r
- #else\r
- DDRD &= ~LEDS_ALL_LEDS;\r
- PORTD &= ~LEDS_ALL_LEDS; \r
- #endif \r
- }\r
-\r
- static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask)\r
- {\r
- #if (BOARD == BOARD_USB2AX)\r
- PORTC |= LEDMask; \r
- #else\r
- PORTD |= LEDMask;\r
- #endif\r
- }\r
-\r
- static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask)\r
- {\r
- #if (BOARD == BOARD_USB2AX)\r
- PORTC &= ~LEDMask;\r
- #else\r
- PORTD &= ~LEDMask;\r
- #endif\r
- }\r
-\r
- static inline void LEDs_SetAllLEDs(const uint8_t LEDMask)\r
- {\r
- #if (BOARD == BOARD_USB2AX)\r
- PORTC = ((PORTC & ~LEDS_ALL_LEDS) | LEDMask); \r
- #else\r
- PORTD = ((PORTD & ~LEDS_ALL_LEDS) | LEDMask);\r
- #endif\r
- }\r
-\r
- static inline void LEDs_ChangeLEDs(const uint8_t LEDMask,\r
- const uint8_t ActiveMask)\r
- {\r
- #if (BOARD == BOARD_USB2AX)\r
- PORTC = ((PORTC & ~LEDMask) | ActiveMask); \r
- #else\r
- PORTD = ((PORTD & ~LEDMask) | ActiveMask);\r
- #endif\r
- }\r
-\r
- static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)\r
- {\r
- #if (BOARD == BOARD_USB2AX)\r
- PINC = LEDMask; \r
- #else\r
- PIND = LEDMask;\r
- #endif\r
- }\r
-\r
- static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;\r
- static inline uint8_t LEDs_GetLEDs(void)\r
- {\r
- #if (BOARD == BOARD_USB2AX)\r
- return (PORTC & LEDS_ALL_LEDS); \r
- #else\r
- return (PORTD & LEDS_ALL_LEDS);\r
- #endif\r
- }\r
- #endif\r
-\r
- /* Disable C linkage for C++ Compilers: */\r
- #if defined(__cplusplus)\r
- }\r
- #endif\r
-\r
-#endif\r
-\r
-/** @} */\r
-\r
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 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
+ * \brief Board specific LED driver header for the Paranoid Studio USB2AX.
+ * \copydetails Group_LEDs_USB2AX
+ *
+ * \note This file should not be included directly. It is automatically included as needed by the LEDs driver
+ * dispatch header located in LUFA/Drivers/Board/LEDs.h.
+ */
+
+/** \ingroup Group_LEDs
+ * \defgroup Group_LEDs_USB2AX_V3 USB2AX_V3
+ * \brief Board specific LED driver header for the Paranoid Studio USB2AX revision 3.
+ *
+ * See \ref Group_LEDs_USB2AX for more details.
+ */
+
+/** \ingroup Group_LEDs
+ * \defgroup Group_LEDs_USB2AX USB2AX
+ * \brief Board specific LED driver header for the Paranoid Studio USB2AX.
+ *
+ * \note For version 3 USB2AX boards, compile with <code>BOARD = USB2AX_V3</code>.
+ *
+ * Board specific LED driver header for the Paranoid Studio USB2AX (http://paranoidstudio.assembla.com/wiki/show/paranoidstudio/USB2AX).
+ *
+ * <b>USB2AX</b>:
+ * <table>
+ * <tr><th>Name</th><th>Color</th><th>Info</th><th>Active Level</th><th>Port Pin</th></tr>
+ * <tr><td>LEDS_LED1</td><td>Green</td><td>General Indicator</td><td>High</td><td>PORTC.6</td></tr>
+ * </table>
+ *
+ * <b>USB2AX_V3</b>:
+ * <table>
+ * <tr><th>Name</th><th>Color</th><th>Info</th><th>Active Level</th><th>Port Pin</th></tr>
+ * <tr><td>LEDS_LED1</td><td>Green</td><td>General Indicator</td><td>High</td><td>PORTD.1</td></tr>
+ * </table>
+ *
+ * @{
+ */
+
+#ifndef __LEDS_USB2AX_H__
+#define __LEDS_USB2AX_H__
+
+ /* Includes: */
+ #include "../../../../Common/Common.h"
+
+ /* Enable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ extern "C" {
+ #endif
+
+ /* Preprocessor Checks: */
+ #if !defined(__INCLUDE_FROM_LEDS_H)
+ #error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
+ #endif
+
+ /* Private Interface - For use in library only: */
+ #if !defined(__DOXYGEN__)
+ /* Macros: */
+ #if (BOARD == BOARD_USB2AX)
+ #define USB2AX_LEDS_LED1 (1 << 6)
+ #else
+ #define USB2AX_LEDS_LED1 (1 << 1)
+ #endif
+ #endif
+
+ /* Public Interface - May be used in end-application: */
+ /* Macros: */
+ /** LED mask for the first LED on the board. */
+ #define LEDS_LED1 USB2AX_LEDS_LED1
+
+ /** LED mask for all the LEDs on the board. */
+ #define LEDS_ALL_LEDS LEDS_LED1
+
+ /** LED mask for none of the board LEDs. */
+ #define LEDS_NO_LEDS 0
+
+ /* Inline Functions: */
+ #if !defined(__DOXYGEN__)
+ static inline void LEDs_Init(void)
+ {
+ #if (BOARD == BOARD_USB2AX)
+ DDRC |= LEDS_ALL_LEDS;
+ PORTC &= ~LEDS_ALL_LEDS;
+ #else
+ DDRD |= LEDS_ALL_LEDS;
+ PORTD &= ~LEDS_ALL_LEDS;
+ #endif
+ }
+
+ static inline void LEDs_Disable(void)
+ {
+ #if (BOARD == BOARD_USB2AX)
+ DDRC &= ~LEDS_ALL_LEDS;
+ PORTC &= ~LEDS_ALL_LEDS;
+ #else
+ DDRD &= ~LEDS_ALL_LEDS;
+ PORTD &= ~LEDS_ALL_LEDS;
+ #endif
+ }
+
+ static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask)
+ {
+ #if (BOARD == BOARD_USB2AX)
+ PORTC |= LEDMask;
+ #else
+ PORTD |= LEDMask;
+ #endif
+ }
+
+ static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask)
+ {
+ #if (BOARD == BOARD_USB2AX)
+ PORTC &= ~LEDMask;
+ #else
+ PORTD &= ~LEDMask;
+ #endif
+ }
+
+ static inline void LEDs_SetAllLEDs(const uint8_t LEDMask)
+ {
+ #if (BOARD == BOARD_USB2AX)
+ PORTC = ((PORTC & ~LEDS_ALL_LEDS) | LEDMask);
+ #else
+ PORTD = ((PORTD & ~LEDS_ALL_LEDS) | LEDMask);
+ #endif
+ }
+
+ static inline void LEDs_ChangeLEDs(const uint8_t LEDMask,
+ const uint8_t ActiveMask)
+ {
+ #if (BOARD == BOARD_USB2AX)
+ PORTC = ((PORTC & ~LEDMask) | ActiveMask);
+ #else
+ PORTD = ((PORTD & ~LEDMask) | ActiveMask);
+ #endif
+ }
+
+ static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
+ {
+ #if (BOARD == BOARD_USB2AX)
+ PINC = LEDMask;
+ #else
+ PIND = LEDMask;
+ #endif
+ }
+
+ static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
+ static inline uint8_t LEDs_GetLEDs(void)
+ {
+ #if (BOARD == BOARD_USB2AX)
+ return (PORTC & LEDS_ALL_LEDS);
+ #else
+ return (PORTD & LEDS_ALL_LEDS);
+ #endif
+ }
+ #endif
+
+ /* Disable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ }
+ #endif
+
+#endif
+
+/** @} */
+
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2012.\r
-\r
- dean [at] fourwalledcubicle [dot] com\r
- www.lufa-lib.org\r
-*/\r
-\r
-/*\r
- Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, distribute, and sell this\r
- software and its documentation for any purpose is hereby granted\r
- without fee, provided that the above copyright notice appear in\r
- all copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting\r
- documentation, and that the name of the author not be used in\r
- advertising or publicity pertaining to distribution of the\r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-/** \file\r
- * \brief Master include file for the library USB Android Open Accessory Class driver.\r
- *\r
- * Master include file for the library USB Android Open Accessory Class driver, for both host and device modes, where available.\r
- *\r
- * This file should be included in all user projects making use of this optional class driver, instead of\r
- * including any headers in the USB/ClassDriver/Device, USB/ClassDriver/Host or USB/ClassDriver/Common subdirectories.\r
- */\r
-\r
-/** \ingroup Group_USBClassDrivers\r
- * \defgroup Group_USBClassAOA Android Open Accessory Class Driver\r
- *\r
- * \section Sec_Dependencies Module Source Dependencies\r
- * The following files must be built with any user project that uses this module:\r
- * - LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.c <i>(Makefile source module name: LUFA_SRC_USBCLASS)</i>\r
- *\r
- * \section Sec_ModDescription Module Description\r
- * Android Open Accessory Class Driver module. This module contains an internal implementation of the USB Android Open Accessory\r
- * Class, for Host USB mode. User applications can use this class driver instead of implementing the Android Open Accessory Class\r
- * manually via the low-level LUFA APIs.\r
- *\r
- * This module is designed to simplify the user code by exposing only the required interface needed to interface with\r
- * Host using the USB Android Open Accessory Class.\r
- *\r
- * @{\r
- */\r
-\r
-#ifndef _AOA_CLASS_H_\r
-#define _AOA_CLASS_H_\r
-\r
- /* Macros: */\r
- #define __INCLUDE_FROM_USB_DRIVER\r
- #define __INCLUDE_FROM_AOA_DRIVER\r
-\r
- /* Includes: */\r
- #include "../Core/USBMode.h"\r
-\r
- #if defined(USB_CAN_BE_HOST)\r
- #include "Host/AndroidAccessoryClassHost.h"\r
- #endif\r
-\r
-#endif\r
-\r
-/** @} */\r
-\r
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 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
+ * \brief Master include file for the library USB Android Open Accessory Class driver.
+ *
+ * Master include file for the library USB Android Open Accessory Class driver, for both host and device modes, where available.
+ *
+ * This file should be included in all user projects making use of this optional class driver, instead of
+ * including any headers in the USB/ClassDriver/Device, USB/ClassDriver/Host or USB/ClassDriver/Common subdirectories.
+ */
+
+/** \ingroup Group_USBClassDrivers
+ * \defgroup Group_USBClassAOA Android Open Accessory Class Driver
+ *
+ * \section Sec_Dependencies Module Source Dependencies
+ * The following files must be built with any user project that uses this module:
+ * - LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.c <i>(Makefile source module name: LUFA_SRC_USBCLASS)</i>
+ *
+ * \section Sec_ModDescription Module Description
+ * Android Open Accessory Class Driver module. This module contains an internal implementation of the USB Android Open Accessory
+ * Class, for Host USB mode. User applications can use this class driver instead of implementing the Android Open Accessory Class
+ * manually via the low-level LUFA APIs.
+ *
+ * This module is designed to simplify the user code by exposing only the required interface needed to interface with
+ * Host using the USB Android Open Accessory Class.
+ *
+ * @{
+ */
+
+#ifndef _AOA_CLASS_H_
+#define _AOA_CLASS_H_
+
+ /* Macros: */
+ #define __INCLUDE_FROM_USB_DRIVER
+ #define __INCLUDE_FROM_AOA_DRIVER
+
+ /* Includes: */
+ #include "../Core/USBMode.h"
+
+ #if defined(USB_CAN_BE_HOST)
+ #include "Host/AndroidAccessoryClassHost.h"
+ #endif
+
+#endif
+
+/** @} */
+
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2012.\r
-\r
- dean [at] fourwalledcubicle [dot] com\r
- www.lufa-lib.org\r
-*/\r
-\r
-/*\r
- Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, distribute, and sell this\r
- software and its documentation for any purpose is hereby granted\r
- without fee, provided that the above copyright notice appear in\r
- all copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting\r
- documentation, and that the name of the author not be used in\r
- advertising or publicity pertaining to distribution of the\r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-/** \file\r
- * \brief Common definitions and declarations for the library USB Android Open Accessory Class driver.\r
- *\r
- * Common definitions and declarations for the library USB Android Open Accessory Class driver.\r
- *\r
- * \note This file should not be included directly. It is automatically included as needed by the USB module driver\r
- * dispatch header located in LUFA/Drivers/USB.h.\r
- */\r
-\r
-/** \ingroup Group_USBClassAOA\r
- * \defgroup Group_USBClassAOACommon Common Class Definitions\r
- *\r
- * \section Sec_ModDescription Module Description\r
- * Constants, Types and Enum definitions that are common to both Device and Host modes for the USB\r
- * Android Open Accessory Class.\r
- *\r
- * @{\r
- */\r
-\r
-#ifndef _AOA_CLASS_COMMON_H_\r
-#define _AOA_CLASS_COMMON_H_\r
-\r
- /* Includes: */\r
- #include "../../Core/StdDescriptors.h"\r
-\r
- /* Enable C linkage for C++ Compilers: */\r
- #if defined(__cplusplus)\r
- extern "C" {\r
- #endif\r
-\r
- /* Preprocessor Checks: */\r
- #if !defined(__INCLUDE_FROM_AOA_DRIVER)\r
- #error Do not include this file directly. Include LUFA/Drivers/USB.h instead.\r
- #endif\r
-\r
- /* Macros: */\r
- /** Product ID value in a Device Descriptor to indicate an Android device in Open Accessory mode. */\r
- #define ANDROID_ACCESSORY_PRODUCT_ID 0x2D00\r
-\r
- /** Product ID value in a Device Descriptor to indicate an Android device in Open Accessory and Android Debug mode. */\r
- #define ANDROID_ACCESSORY_ADB_PRODUCT_ID 0x2D01\r
-\r
- /* Enums: */\r
- /** Enum for possible Class, Subclass and Protocol values of device and interface descriptors relating to the\r
- * Android Open Accessory class.\r
- */\r
- enum AOA_Descriptor_ClassSubclassProtocol_t\r
- {\r
- AOA_CSCP_AOADataClass = 0xFF, /**< Descriptor Class value indicating that the device or interface\r
- * belongs to the AOA data class.\r
- */\r
- AOA_CSCP_AOADataSubclass = 0xFF, /**< Descriptor Subclass value indicating that the device or interface\r
- * belongs to AOA data subclass.\r
- */\r
- AOA_CSCP_AOADataProtocol = 0x00, /**< Descriptor Protocol value indicating that the device or interface\r
- * belongs to the AOA data class protocol.\r
- */\r
- };\r
-\r
- /** Enum for the Android Open Accessory class specific control requests that can be issued by the USB bus host. */\r
- enum AOA_ClassRequests_t\r
- {\r
- AOA_REQ_GetAccessoryProtocol = 0x33, /**< Android Open Accessory control request to retrieve the device's supported Accessory Protocol version. */\r
- AOA_REQ_SendString = 0x34, /**< Android Open Accessory control request to set an accessory property string in the device. */\r
- AOA_REQ_StartAccessoryMode = 0x35, /**< Android Open Accessory control request to switch the device into Accessory mode. */\r
- };\r
-\r
- /** Enum for the possible Android Open Accessory property string indexes. */\r
- enum AOA_Strings_t\r
- {\r
- AOA_STRING_Manufacturer = 0, /**< Index of the Manufacturer property string. */\r
- AOA_STRING_Model = 1, /**< Index of the Model Name property string. */\r
- AOA_STRING_Description = 2, /**< Index of the Description property string. */\r
- AOA_STRING_Version = 3, /**< Index of the Version Number property string. */\r
- AOA_STRING_URI = 4, /**< Index of the URI Information property string. */\r
- AOA_STRING_Serial = 5, /**< Index of the Serial Number property string. */\r
- \r
- #if !defined(__DOXYGEN__)\r
- AOA_STRING_TOTAL_STRINGS\r
- #endif\r
- };\r
- \r
- /** Enum for the possible Android Open Accessory protocol versions. */\r
- enum AOA_Protocols_t\r
- {\r
- AOA_PROTOCOL_AccessoryV1 = 0x0001, /**< Android Open Accessory version 1. */\r
- };\r
-\r
- /* Disable C linkage for C++ Compilers: */\r
- #if defined(__cplusplus)\r
- }\r
- #endif\r
-\r
-#endif\r
-\r
-/** @} */\r
-\r
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 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
+ * \brief Common definitions and declarations for the library USB Android Open Accessory Class driver.
+ *
+ * Common definitions and declarations for the library USB Android Open Accessory Class driver.
+ *
+ * \note This file should not be included directly. It is automatically included as needed by the USB module driver
+ * dispatch header located in LUFA/Drivers/USB.h.
+ */
+
+/** \ingroup Group_USBClassAOA
+ * \defgroup Group_USBClassAOACommon Common Class Definitions
+ *
+ * \section Sec_ModDescription Module Description
+ * Constants, Types and Enum definitions that are common to both Device and Host modes for the USB
+ * Android Open Accessory Class.
+ *
+ * @{
+ */
+
+#ifndef _AOA_CLASS_COMMON_H_
+#define _AOA_CLASS_COMMON_H_
+
+ /* Includes: */
+ #include "../../Core/StdDescriptors.h"
+
+ /* Enable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ extern "C" {
+ #endif
+
+ /* Preprocessor Checks: */
+ #if !defined(__INCLUDE_FROM_AOA_DRIVER)
+ #error Do not include this file directly. Include LUFA/Drivers/USB.h instead.
+ #endif
+
+ /* Macros: */
+ /** Product ID value in a Device Descriptor to indicate an Android device in Open Accessory mode. */
+ #define ANDROID_ACCESSORY_PRODUCT_ID 0x2D00
+
+ /** Product ID value in a Device Descriptor to indicate an Android device in Open Accessory and Android Debug mode. */
+ #define ANDROID_ACCESSORY_ADB_PRODUCT_ID 0x2D01
+
+ /* Enums: */
+ /** Enum for possible Class, Subclass and Protocol values of device and interface descriptors relating to the
+ * Android Open Accessory class.
+ */
+ enum AOA_Descriptor_ClassSubclassProtocol_t
+ {
+ AOA_CSCP_AOADataClass = 0xFF, /**< Descriptor Class value indicating that the device or interface
+ * belongs to the AOA data class.
+ */
+ AOA_CSCP_AOADataSubclass = 0xFF, /**< Descriptor Subclass value indicating that the device or interface
+ * belongs to AOA data subclass.
+ */
+ AOA_CSCP_AOADataProtocol = 0x00, /**< Descriptor Protocol value indicating that the device or interface
+ * belongs to the AOA data class protocol.
+ */
+ };
+
+ /** Enum for the Android Open Accessory class specific control requests that can be issued by the USB bus host. */
+ enum AOA_ClassRequests_t
+ {
+ AOA_REQ_GetAccessoryProtocol = 0x33, /**< Android Open Accessory control request to retrieve the device's supported Accessory Protocol version. */
+ AOA_REQ_SendString = 0x34, /**< Android Open Accessory control request to set an accessory property string in the device. */
+ AOA_REQ_StartAccessoryMode = 0x35, /**< Android Open Accessory control request to switch the device into Accessory mode. */
+ };
+
+ /** Enum for the possible Android Open Accessory property string indexes. */
+ enum AOA_Strings_t
+ {
+ AOA_STRING_Manufacturer = 0, /**< Index of the Manufacturer property string. */
+ AOA_STRING_Model = 1, /**< Index of the Model Name property string. */
+ AOA_STRING_Description = 2, /**< Index of the Description property string. */
+ AOA_STRING_Version = 3, /**< Index of the Version Number property string. */
+ AOA_STRING_URI = 4, /**< Index of the URI Information property string. */
+ AOA_STRING_Serial = 5, /**< Index of the Serial Number property string. */
+
+ #if !defined(__DOXYGEN__)
+ AOA_STRING_TOTAL_STRINGS
+ #endif
+ };
+
+ /** Enum for the possible Android Open Accessory protocol versions. */
+ enum AOA_Protocols_t
+ {
+ AOA_PROTOCOL_AccessoryV1 = 0x0001, /**< Android Open Accessory version 1. */
+ };
+
+ /* Disable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ }
+ #endif
+
+#endif
+
+/** @} */
+
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2012.\r
-\r
- dean [at] fourwalledcubicle [dot] com\r
- www.lufa-lib.org\r
-*/\r
-\r
-/*\r
- Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, distribute, and sell this\r
- software and its documentation for any purpose is hereby granted\r
- without fee, provided that the above copyright notice appear in\r
- all copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting\r
- documentation, and that the name of the author not be used in\r
- advertising or publicity pertaining to distribution of the\r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-#define __INCLUDE_FROM_USB_DRIVER\r
-#include "../../Core/USBMode.h"\r
-\r
-#if defined(USB_CAN_BE_HOST)\r
-\r
-#define __INCLUDE_FROM_AOA_DRIVER\r
-#define __INCLUDE_FROM_ANDROIDACCESSORY_HOST_C\r
-#include "AndroidAccessoryClassHost.h"\r
-\r
-bool AOA_Host_ValidateAccessoryDevice(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,\r
- const USB_Descriptor_Device_t* const DeviceDescriptor,\r
- bool* const NeedModeSwitch)\r
-{\r
- (void)AOAInterfaceInfo;\r
-\r
- if (DeviceDescriptor->Header.Type != DTYPE_Device)\r
- return false;\r
-\r
- *NeedModeSwitch = ((DeviceDescriptor->ProductID != ANDROID_ACCESSORY_PRODUCT_ID) &&\r
- (DeviceDescriptor->ProductID != ANDROID_ACCESSORY_ADB_PRODUCT_ID));\r
-\r
- return true;\r
-}\r
-\r
-uint8_t AOA_Host_ConfigurePipes(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,\r
- uint16_t ConfigDescriptorSize,\r
- void* ConfigDescriptorData)\r
-{\r
- USB_Descriptor_Endpoint_t* DataINEndpoint = NULL;\r
- USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL;\r
- USB_Descriptor_Interface_t* AOAInterface = NULL;\r
-\r
- memset(&AOAInterfaceInfo->State, 0x00, sizeof(AOAInterfaceInfo->State));\r
-\r
- if (DESCRIPTOR_TYPE(ConfigDescriptorData) != DTYPE_Configuration)\r
- return AOA_ENUMERROR_InvalidConfigDescriptor;\r
- \r
- if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,\r
- DCOMP_AOA_Host_NextAndroidAccessoryInterface) != DESCRIPTOR_SEARCH_COMP_Found)\r
- {\r
- return AOA_ENUMERROR_NoCompatibleInterfaceFound;\r
- }\r
- \r
- AOAInterface = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Interface_t);\r
-\r
- while (!(DataINEndpoint) || !(DataOUTEndpoint))\r
- {\r
- if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,\r
- DCOMP_AOA_Host_NextInterfaceBulkEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)\r
- {\r
- return AOA_ENUMERROR_NoCompatibleInterfaceFound;\r
- }\r
-\r
- USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Endpoint_t);\r
-\r
- if ((EndpointData->EndpointAddress & ENDPOINT_DIR_MASK) == ENDPOINT_DIR_IN)\r
- DataINEndpoint = EndpointData;\r
- else\r
- DataOUTEndpoint = EndpointData;\r
- }\r
-\r
- AOAInterfaceInfo->Config.DataINPipe.Size = le16_to_cpu(DataINEndpoint->EndpointSize);\r
- AOAInterfaceInfo->Config.DataINPipe.EndpointAddress = DataINEndpoint->EndpointAddress;\r
- AOAInterfaceInfo->Config.DataINPipe.Type = EP_TYPE_BULK;\r
- \r
- AOAInterfaceInfo->Config.DataOUTPipe.Size = le16_to_cpu(DataOUTEndpoint->EndpointSize);\r
- AOAInterfaceInfo->Config.DataOUTPipe.EndpointAddress = DataOUTEndpoint->EndpointAddress;\r
- AOAInterfaceInfo->Config.DataOUTPipe.Type = EP_TYPE_BULK;\r
- \r
- if (!(Pipe_ConfigurePipeTable(&AOAInterfaceInfo->Config.DataINPipe, 1)))\r
- return false;\r
- \r
- if (!(Pipe_ConfigurePipeTable(&AOAInterfaceInfo->Config.DataOUTPipe, 1)))\r
- return false;\r
-\r
- AOAInterfaceInfo->State.IsActive = true;\r
- AOAInterfaceInfo->State.InterfaceNumber = AOAInterface->InterfaceNumber;\r
-\r
- return AOA_ENUMERROR_NoError;\r
-}\r
-\r
-static uint8_t DCOMP_AOA_Host_NextAndroidAccessoryInterface(void* const CurrentDescriptor)\r
-{\r
- USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);\r
-\r
- if (Header->Type == DTYPE_Interface)\r
- {\r
- USB_Descriptor_Interface_t* Interface = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Interface_t);\r
-\r
- if ((Interface->Class == AOA_CSCP_AOADataClass) &&\r
- (Interface->SubClass == AOA_CSCP_AOADataSubclass) &&\r
- (Interface->Protocol == AOA_CSCP_AOADataProtocol))\r
- {\r
- return DESCRIPTOR_SEARCH_Found;\r
- }\r
- }\r
-\r
- return DESCRIPTOR_SEARCH_NotFound;\r
-}\r
-\r
-static uint8_t DCOMP_AOA_Host_NextInterfaceBulkEndpoint(void* const CurrentDescriptor)\r
-{\r
- USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);\r
-\r
- if (Header->Type == DTYPE_Endpoint)\r
- {\r
- USB_Descriptor_Endpoint_t* Endpoint = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Endpoint_t);\r
-\r
- uint8_t EndpointType = (Endpoint->Attributes & EP_TYPE_MASK);\r
-\r
- if ((EndpointType == EP_TYPE_BULK) && (!(Pipe_IsEndpointBound(Endpoint->EndpointAddress))))\r
- return DESCRIPTOR_SEARCH_Found;\r
- }\r
- else if (Header->Type == DTYPE_Interface)\r
- {\r
- return DESCRIPTOR_SEARCH_Fail;\r
- }\r
-\r
- return DESCRIPTOR_SEARCH_NotFound;\r
-}\r
-\r
-void AOA_Host_USBTask(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo)\r
-{\r
- if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive))\r
- return;\r
-\r
- #if !defined(NO_CLASS_DRIVER_AUTOFLUSH)\r
- AOA_Host_Flush(AOAInterfaceInfo);\r
- #endif\r
-}\r
-\r
-uint8_t AOA_Host_StartAccessoryMode(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo)\r
-{\r
- uint8_t ErrorCode;\r
- \r
- uint16_t AccessoryProtocol;\r
- if ((ErrorCode = AOA_Host_GetAccessoryProtocol(&AccessoryProtocol)) != HOST_WAITERROR_Successful)\r
- return ErrorCode;\r
-\r
- if (AccessoryProtocol != CPU_TO_LE16(AOA_PROTOCOL_AccessoryV1))\r
- return AOA_ERROR_LOGICAL_CMD_FAILED;\r
-\r
- for (uint8_t PropertyIndex = 0; PropertyIndex < AOA_STRING_TOTAL_STRINGS; PropertyIndex++)\r
- {\r
- if ((ErrorCode = AOA_Host_SendPropertyString(AOAInterfaceInfo, PropertyIndex)) != HOST_WAITERROR_Successful)\r
- return ErrorCode;\r
- }\r
-\r
- USB_ControlRequest = (USB_Request_Header_t)\r
- {\r
- .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_VENDOR | REQREC_DEVICE),\r
- .bRequest = AOA_REQ_StartAccessoryMode,\r
- .wValue = 0,\r
- .wIndex = 0,\r
- .wLength = 0,\r
- };\r
-\r
- Pipe_SelectPipe(PIPE_CONTROLPIPE);\r
- return USB_Host_SendControlRequest(NULL); \r
-}\r
-\r
-static uint8_t AOA_Host_GetAccessoryProtocol(uint16_t* const Protocol)\r
-{\r
- USB_ControlRequest = (USB_Request_Header_t)\r
- {\r
- .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_VENDOR | REQREC_DEVICE),\r
- .bRequest = AOA_REQ_GetAccessoryProtocol,\r
- .wValue = 0,\r
- .wIndex = 0,\r
- .wLength = sizeof(uint16_t),\r
- };\r
-\r
- Pipe_SelectPipe(PIPE_CONTROLPIPE);\r
- return USB_Host_SendControlRequest(Protocol);\r
-}\r
-\r
-static uint8_t AOA_Host_SendPropertyString(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,\r
- const uint8_t StringIndex)\r
-{ \r
- const char* String = AOAInterfaceInfo->Config.PropertyStrings[StringIndex];\r
- \r
- if (String == NULL)\r
- String = "";\r
-\r
- USB_ControlRequest = (USB_Request_Header_t)\r
- {\r
- .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_VENDOR | REQREC_DEVICE),\r
- .bRequest = AOA_REQ_SendString,\r
- .wValue = 0,\r
- .wIndex = StringIndex,\r
- .wLength = (strlen(String) + 1),\r
- };\r
-\r
- Pipe_SelectPipe(PIPE_CONTROLPIPE);\r
- return USB_Host_SendControlRequest((char*)String);\r
-}\r
-\r
-uint8_t AOA_Host_SendData(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,\r
- const uint8_t* const Buffer,\r
- const uint16_t Length)\r
-{\r
- if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive))\r
- return PIPE_READYWAIT_DeviceDisconnected;\r
-\r
- uint8_t ErrorCode;\r
-\r
- Pipe_SelectPipe(AOAInterfaceInfo->Config.DataOUTPipe.Address);\r
-\r
- Pipe_Unfreeze();\r
- ErrorCode = Pipe_Write_Stream_LE(Buffer, Length, NULL);\r
- Pipe_Freeze();\r
-\r
- return ErrorCode;\r
-}\r
-\r
-uint8_t AOA_Host_SendString(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,\r
- const char* const String)\r
-{\r
- if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive))\r
- return PIPE_READYWAIT_DeviceDisconnected;\r
-\r
- uint8_t ErrorCode;\r
-\r
- Pipe_SelectPipe(AOAInterfaceInfo->Config.DataOUTPipe.Address);\r
-\r
- Pipe_Unfreeze();\r
- ErrorCode = Pipe_Write_Stream_LE(String, strlen(String), NULL);\r
- Pipe_Freeze();\r
-\r
- return ErrorCode;\r
-}\r
-\r
-uint8_t AOA_Host_SendByte(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,\r
- const uint8_t Data)\r
-{\r
- if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive))\r
- return PIPE_READYWAIT_DeviceDisconnected;\r
-\r
- uint8_t ErrorCode;\r
-\r
- Pipe_SelectPipe(AOAInterfaceInfo->Config.DataOUTPipe.Address);\r
- Pipe_Unfreeze();\r
-\r
- if (!(Pipe_IsReadWriteAllowed()))\r
- {\r
- Pipe_ClearOUT();\r
-\r
- if ((ErrorCode = Pipe_WaitUntilReady()) != PIPE_READYWAIT_NoError)\r
- return ErrorCode;\r
- }\r
-\r
- Pipe_Write_8(Data);\r
- Pipe_Freeze();\r
-\r
- return PIPE_READYWAIT_NoError;\r
-}\r
-\r
-uint16_t AOA_Host_BytesReceived(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo)\r
-{\r
- if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive))\r
- return 0;\r
-\r
- Pipe_SelectPipe(AOAInterfaceInfo->Config.DataINPipe.Address);\r
- Pipe_Unfreeze();\r
-\r
- if (Pipe_IsINReceived())\r
- {\r
- if (!(Pipe_BytesInPipe()))\r
- {\r
- Pipe_ClearIN();\r
- Pipe_Freeze();\r
- return 0;\r
- }\r
- else\r
- {\r
- Pipe_Freeze();\r
- return Pipe_BytesInPipe();\r
- }\r
- }\r
- else\r
- {\r
- Pipe_Freeze();\r
-\r
- return 0;\r
- }\r
-}\r
-\r
-int16_t AOA_Host_ReceiveByte(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo)\r
-{\r
- if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive))\r
- return -1;\r
-\r
- int16_t ReceivedByte = -1;\r
-\r
- Pipe_SelectPipe(AOAInterfaceInfo->Config.DataINPipe.Address);\r
- Pipe_Unfreeze();\r
-\r
- if (Pipe_IsINReceived())\r
- {\r
- if (Pipe_BytesInPipe())\r
- ReceivedByte = Pipe_Read_8();\r
-\r
- if (!(Pipe_BytesInPipe()))\r
- Pipe_ClearIN();\r
- }\r
-\r
- Pipe_Freeze();\r
-\r
- return ReceivedByte;\r
-}\r
-\r
-uint8_t AOA_Host_Flush(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo)\r
-{\r
- if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive))\r
- return PIPE_READYWAIT_DeviceDisconnected;\r
-\r
- uint8_t ErrorCode;\r
-\r
- Pipe_SelectPipe(AOAInterfaceInfo->Config.DataOUTPipe.Address);\r
- Pipe_Unfreeze();\r
-\r
- if (!(Pipe_BytesInPipe()))\r
- return PIPE_READYWAIT_NoError;\r
-\r
- bool BankFull = !(Pipe_IsReadWriteAllowed());\r
-\r
- Pipe_ClearOUT();\r
-\r
- if (BankFull)\r
- {\r
- if ((ErrorCode = Pipe_WaitUntilReady()) != PIPE_READYWAIT_NoError)\r
- return ErrorCode;\r
-\r
- Pipe_ClearOUT();\r
- }\r
-\r
- Pipe_Freeze();\r
-\r
- return PIPE_READYWAIT_NoError;\r
-}\r
-\r
-#if defined(FDEV_SETUP_STREAM)\r
-void AOA_Host_CreateStream(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,\r
- FILE* const Stream)\r
-{\r
- *Stream = (FILE)FDEV_SETUP_STREAM(AOA_Host_putchar, AOA_Host_getchar, _FDEV_SETUP_RW);\r
- fdev_set_udata(Stream, AOAInterfaceInfo);\r
-}\r
-\r
-void AOA_Host_CreateBlockingStream(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,\r
- FILE* const Stream)\r
-{\r
- *Stream = (FILE)FDEV_SETUP_STREAM(AOA_Host_putchar, AOA_Host_getchar_Blocking, _FDEV_SETUP_RW);\r
- fdev_set_udata(Stream, AOAInterfaceInfo);\r
-}\r
-\r
-static int AOA_Host_putchar(char c,\r
- FILE* Stream)\r
-{\r
- return AOA_Host_SendByte((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream), c) ? _FDEV_ERR : 0;\r
-}\r
-\r
-static int AOA_Host_getchar(FILE* Stream)\r
-{\r
- int16_t ReceivedByte = AOA_Host_ReceiveByte((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream));\r
-\r
- if (ReceivedByte < 0)\r
- return _FDEV_EOF;\r
-\r
- return ReceivedByte;\r
-}\r
-\r
-static int AOA_Host_getchar_Blocking(FILE* Stream)\r
-{\r
- int16_t ReceivedByte;\r
-\r
- while ((ReceivedByte = AOA_Host_ReceiveByte((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream))) < 0)\r
- {\r
- if (USB_HostState == HOST_STATE_Unattached)\r
- return _FDEV_EOF;\r
-\r
- AOA_Host_USBTask((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream));\r
- USB_USBTask();\r
- }\r
-\r
- return ReceivedByte;\r
-}\r
-#endif\r
-\r
-#endif\r
-\r
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 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.
+*/
+
+#define __INCLUDE_FROM_USB_DRIVER
+#include "../../Core/USBMode.h"
+
+#if defined(USB_CAN_BE_HOST)
+
+#define __INCLUDE_FROM_AOA_DRIVER
+#define __INCLUDE_FROM_ANDROIDACCESSORY_HOST_C
+#include "AndroidAccessoryClassHost.h"
+
+bool AOA_Host_ValidateAccessoryDevice(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,
+ const USB_Descriptor_Device_t* const DeviceDescriptor,
+ bool* const NeedModeSwitch)
+{
+ (void)AOAInterfaceInfo;
+
+ if (DeviceDescriptor->Header.Type != DTYPE_Device)
+ return false;
+
+ *NeedModeSwitch = ((DeviceDescriptor->ProductID != ANDROID_ACCESSORY_PRODUCT_ID) &&
+ (DeviceDescriptor->ProductID != ANDROID_ACCESSORY_ADB_PRODUCT_ID));
+
+ return true;
+}
+
+uint8_t AOA_Host_ConfigurePipes(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,
+ uint16_t ConfigDescriptorSize,
+ void* ConfigDescriptorData)
+{
+ USB_Descriptor_Endpoint_t* DataINEndpoint = NULL;
+ USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL;
+ USB_Descriptor_Interface_t* AOAInterface = NULL;
+
+ memset(&AOAInterfaceInfo->State, 0x00, sizeof(AOAInterfaceInfo->State));
+
+ if (DESCRIPTOR_TYPE(ConfigDescriptorData) != DTYPE_Configuration)
+ return AOA_ENUMERROR_InvalidConfigDescriptor;
+
+ if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
+ DCOMP_AOA_Host_NextAndroidAccessoryInterface) != DESCRIPTOR_SEARCH_COMP_Found)
+ {
+ return AOA_ENUMERROR_NoCompatibleInterfaceFound;
+ }
+
+ AOAInterface = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Interface_t);
+
+ while (!(DataINEndpoint) || !(DataOUTEndpoint))
+ {
+ if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
+ DCOMP_AOA_Host_NextInterfaceBulkEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
+ {
+ return AOA_ENUMERROR_NoCompatibleInterfaceFound;
+ }
+
+ USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Endpoint_t);
+
+ if ((EndpointData->EndpointAddress & ENDPOINT_DIR_MASK) == ENDPOINT_DIR_IN)
+ DataINEndpoint = EndpointData;
+ else
+ DataOUTEndpoint = EndpointData;
+ }
+
+ AOAInterfaceInfo->Config.DataINPipe.Size = le16_to_cpu(DataINEndpoint->EndpointSize);
+ AOAInterfaceInfo->Config.DataINPipe.EndpointAddress = DataINEndpoint->EndpointAddress;
+ AOAInterfaceInfo->Config.DataINPipe.Type = EP_TYPE_BULK;
+
+ AOAInterfaceInfo->Config.DataOUTPipe.Size = le16_to_cpu(DataOUTEndpoint->EndpointSize);
+ AOAInterfaceInfo->Config.DataOUTPipe.EndpointAddress = DataOUTEndpoint->EndpointAddress;
+ AOAInterfaceInfo->Config.DataOUTPipe.Type = EP_TYPE_BULK;
+
+ if (!(Pipe_ConfigurePipeTable(&AOAInterfaceInfo->Config.DataINPipe, 1)))
+ return false;
+
+ if (!(Pipe_ConfigurePipeTable(&AOAInterfaceInfo->Config.DataOUTPipe, 1)))
+ return false;
+
+ AOAInterfaceInfo->State.IsActive = true;
+ AOAInterfaceInfo->State.InterfaceNumber = AOAInterface->InterfaceNumber;
+
+ return AOA_ENUMERROR_NoError;
+}
+
+static uint8_t DCOMP_AOA_Host_NextAndroidAccessoryInterface(void* const 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 == AOA_CSCP_AOADataClass) &&
+ (Interface->SubClass == AOA_CSCP_AOADataSubclass) &&
+ (Interface->Protocol == AOA_CSCP_AOADataProtocol))
+ {
+ return DESCRIPTOR_SEARCH_Found;
+ }
+ }
+
+ return DESCRIPTOR_SEARCH_NotFound;
+}
+
+static uint8_t DCOMP_AOA_Host_NextInterfaceBulkEndpoint(void* const 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);
+
+ uint8_t EndpointType = (Endpoint->Attributes & EP_TYPE_MASK);
+
+ if ((EndpointType == EP_TYPE_BULK) && (!(Pipe_IsEndpointBound(Endpoint->EndpointAddress))))
+ return DESCRIPTOR_SEARCH_Found;
+ }
+ else if (Header->Type == DTYPE_Interface)
+ {
+ return DESCRIPTOR_SEARCH_Fail;
+ }
+
+ return DESCRIPTOR_SEARCH_NotFound;
+}
+
+void AOA_Host_USBTask(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo)
+{
+ if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive))
+ return;
+
+ #if !defined(NO_CLASS_DRIVER_AUTOFLUSH)
+ AOA_Host_Flush(AOAInterfaceInfo);
+ #endif
+}
+
+uint8_t AOA_Host_StartAccessoryMode(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo)
+{
+ uint8_t ErrorCode;
+
+ uint16_t AccessoryProtocol;
+ if ((ErrorCode = AOA_Host_GetAccessoryProtocol(&AccessoryProtocol)) != HOST_WAITERROR_Successful)
+ return ErrorCode;
+
+ if (AccessoryProtocol != CPU_TO_LE16(AOA_PROTOCOL_AccessoryV1))
+ return AOA_ERROR_LOGICAL_CMD_FAILED;
+
+ for (uint8_t PropertyIndex = 0; PropertyIndex < AOA_STRING_TOTAL_STRINGS; PropertyIndex++)
+ {
+ if ((ErrorCode = AOA_Host_SendPropertyString(AOAInterfaceInfo, PropertyIndex)) != HOST_WAITERROR_Successful)
+ return ErrorCode;
+ }
+
+ USB_ControlRequest = (USB_Request_Header_t)
+ {
+ .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_VENDOR | REQREC_DEVICE),
+ .bRequest = AOA_REQ_StartAccessoryMode,
+ .wValue = 0,
+ .wIndex = 0,
+ .wLength = 0,
+ };
+
+ Pipe_SelectPipe(PIPE_CONTROLPIPE);
+ return USB_Host_SendControlRequest(NULL);
+}
+
+static uint8_t AOA_Host_GetAccessoryProtocol(uint16_t* const Protocol)
+{
+ USB_ControlRequest = (USB_Request_Header_t)
+ {
+ .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_VENDOR | REQREC_DEVICE),
+ .bRequest = AOA_REQ_GetAccessoryProtocol,
+ .wValue = 0,
+ .wIndex = 0,
+ .wLength = sizeof(uint16_t),
+ };
+
+ Pipe_SelectPipe(PIPE_CONTROLPIPE);
+ return USB_Host_SendControlRequest(Protocol);
+}
+
+static uint8_t AOA_Host_SendPropertyString(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,
+ const uint8_t StringIndex)
+{
+ const char* String = AOAInterfaceInfo->Config.PropertyStrings[StringIndex];
+
+ if (String == NULL)
+ String = "";
+
+ USB_ControlRequest = (USB_Request_Header_t)
+ {
+ .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_VENDOR | REQREC_DEVICE),
+ .bRequest = AOA_REQ_SendString,
+ .wValue = 0,
+ .wIndex = StringIndex,
+ .wLength = (strlen(String) + 1),
+ };
+
+ Pipe_SelectPipe(PIPE_CONTROLPIPE);
+ return USB_Host_SendControlRequest((char*)String);
+}
+
+uint8_t AOA_Host_SendData(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,
+ const uint8_t* const Buffer,
+ const uint16_t Length)
+{
+ if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive))
+ return PIPE_READYWAIT_DeviceDisconnected;
+
+ uint8_t ErrorCode;
+
+ Pipe_SelectPipe(AOAInterfaceInfo->Config.DataOUTPipe.Address);
+
+ Pipe_Unfreeze();
+ ErrorCode = Pipe_Write_Stream_LE(Buffer, Length, NULL);
+ Pipe_Freeze();
+
+ return ErrorCode;
+}
+
+uint8_t AOA_Host_SendString(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,
+ const char* const String)
+{
+ if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive))
+ return PIPE_READYWAIT_DeviceDisconnected;
+
+ uint8_t ErrorCode;
+
+ Pipe_SelectPipe(AOAInterfaceInfo->Config.DataOUTPipe.Address);
+
+ Pipe_Unfreeze();
+ ErrorCode = Pipe_Write_Stream_LE(String, strlen(String), NULL);
+ Pipe_Freeze();
+
+ return ErrorCode;
+}
+
+uint8_t AOA_Host_SendByte(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,
+ const uint8_t Data)
+{
+ if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive))
+ return PIPE_READYWAIT_DeviceDisconnected;
+
+ uint8_t ErrorCode;
+
+ Pipe_SelectPipe(AOAInterfaceInfo->Config.DataOUTPipe.Address);
+ Pipe_Unfreeze();
+
+ if (!(Pipe_IsReadWriteAllowed()))
+ {
+ Pipe_ClearOUT();
+
+ if ((ErrorCode = Pipe_WaitUntilReady()) != PIPE_READYWAIT_NoError)
+ return ErrorCode;
+ }
+
+ Pipe_Write_8(Data);
+ Pipe_Freeze();
+
+ return PIPE_READYWAIT_NoError;
+}
+
+uint16_t AOA_Host_BytesReceived(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo)
+{
+ if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive))
+ return 0;
+
+ Pipe_SelectPipe(AOAInterfaceInfo->Config.DataINPipe.Address);
+ Pipe_Unfreeze();
+
+ if (Pipe_IsINReceived())
+ {
+ if (!(Pipe_BytesInPipe()))
+ {
+ Pipe_ClearIN();
+ Pipe_Freeze();
+ return 0;
+ }
+ else
+ {
+ Pipe_Freeze();
+ return Pipe_BytesInPipe();
+ }
+ }
+ else
+ {
+ Pipe_Freeze();
+
+ return 0;
+ }
+}
+
+int16_t AOA_Host_ReceiveByte(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo)
+{
+ if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive))
+ return -1;
+
+ int16_t ReceivedByte = -1;
+
+ Pipe_SelectPipe(AOAInterfaceInfo->Config.DataINPipe.Address);
+ Pipe_Unfreeze();
+
+ if (Pipe_IsINReceived())
+ {
+ if (Pipe_BytesInPipe())
+ ReceivedByte = Pipe_Read_8();
+
+ if (!(Pipe_BytesInPipe()))
+ Pipe_ClearIN();
+ }
+
+ Pipe_Freeze();
+
+ return ReceivedByte;
+}
+
+uint8_t AOA_Host_Flush(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo)
+{
+ if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive))
+ return PIPE_READYWAIT_DeviceDisconnected;
+
+ uint8_t ErrorCode;
+
+ Pipe_SelectPipe(AOAInterfaceInfo->Config.DataOUTPipe.Address);
+ Pipe_Unfreeze();
+
+ if (!(Pipe_BytesInPipe()))
+ return PIPE_READYWAIT_NoError;
+
+ bool BankFull = !(Pipe_IsReadWriteAllowed());
+
+ Pipe_ClearOUT();
+
+ if (BankFull)
+ {
+ if ((ErrorCode = Pipe_WaitUntilReady()) != PIPE_READYWAIT_NoError)
+ return ErrorCode;
+
+ Pipe_ClearOUT();
+ }
+
+ Pipe_Freeze();
+
+ return PIPE_READYWAIT_NoError;
+}
+
+#if defined(FDEV_SETUP_STREAM)
+void AOA_Host_CreateStream(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,
+ FILE* const Stream)
+{
+ *Stream = (FILE)FDEV_SETUP_STREAM(AOA_Host_putchar, AOA_Host_getchar, _FDEV_SETUP_RW);
+ fdev_set_udata(Stream, AOAInterfaceInfo);
+}
+
+void AOA_Host_CreateBlockingStream(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,
+ FILE* const Stream)
+{
+ *Stream = (FILE)FDEV_SETUP_STREAM(AOA_Host_putchar, AOA_Host_getchar_Blocking, _FDEV_SETUP_RW);
+ fdev_set_udata(Stream, AOAInterfaceInfo);
+}
+
+static int AOA_Host_putchar(char c,
+ FILE* Stream)
+{
+ return AOA_Host_SendByte((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream), c) ? _FDEV_ERR : 0;
+}
+
+static int AOA_Host_getchar(FILE* Stream)
+{
+ int16_t ReceivedByte = AOA_Host_ReceiveByte((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream));
+
+ if (ReceivedByte < 0)
+ return _FDEV_EOF;
+
+ return ReceivedByte;
+}
+
+static int AOA_Host_getchar_Blocking(FILE* Stream)
+{
+ int16_t ReceivedByte;
+
+ while ((ReceivedByte = AOA_Host_ReceiveByte((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream))) < 0)
+ {
+ if (USB_HostState == HOST_STATE_Unattached)
+ return _FDEV_EOF;
+
+ AOA_Host_USBTask((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream));
+ USB_USBTask();
+ }
+
+ return ReceivedByte;
+}
+#endif
+
+#endif
+
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2012.\r
-\r
- dean [at] fourwalledcubicle [dot] com\r
- www.lufa-lib.org\r
-*/\r
-\r
-/*\r
- Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, distribute, and sell this\r
- software and its documentation for any purpose is hereby granted\r
- without fee, provided that the above copyright notice appear in\r
- all copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting\r
- documentation, and that the name of the author not be used in\r
- advertising or publicity pertaining to distribution of the\r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-/** \file\r
- * \brief Host mode driver for the library USB Android Open Accessory Class driver.\r
- *\r
- * Host mode driver for the library USB Android Open Accessory Class driver.\r
- *\r
- * \note This file should not be included directly. It is automatically included as needed by the USB module driver\r
- * dispatch header located in LUFA/Drivers/USB.h.\r
- */\r
-\r
-/** \ingroup Group_USBClassAOA\r
- * \defgroup Group_USBClassAndroidAccessoryHost Android Open Accessory Class Host Mode Driver\r
- *\r
- * \section Sec_Dependencies Module Source Dependencies\r
- * The following files must be built with any user project that uses this module:\r
- * - LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.c <i>(Makefile source module name: LUFA_SRC_USBCLASS)</i>\r
- *\r
- * \section Sec_ModDescription Module Description\r
- * Host Mode USB Class driver framework interface, for the Android Open Accessory USB Class driver.\r
- *\r
- * @{\r
- */\r
-\r
-#ifndef __AOA_CLASS_HOST_H__\r
-#define __AOA_CLASS_HOST_H__\r
-\r
- /* Includes: */\r
- #include "../../USB.h"\r
- #include "../Common/AndroidAccessoryClassCommon.h"\r
-\r
- #include <stdio.h>\r
-\r
- /* Enable C linkage for C++ Compilers: */\r
- #if defined(__cplusplus)\r
- extern "C" {\r
- #endif\r
-\r
- /* Preprocessor Checks: */\r
- #if !defined(__INCLUDE_FROM_AOA_DRIVER)\r
- #error Do not include this file directly. Include LUFA/Drivers/USB.h instead.\r
- #endif\r
-\r
- /* Public Interface - May be used in end-application: */\r
- /* Macros: */\r
- /** Error code for some Android Open Accessory Host functions, indicating a logical (and not hardware) error. */\r
- #define AOA_ERROR_LOGICAL_CMD_FAILED 0x80\r
-\r
- /* Type Defines: */\r
- /** \brief Android Open Accessory Class Host Mode Configuration and State Structure.\r
- *\r
- * Class state structure. An instance of this structure should be made within the user application,\r
- * and passed to each of the Android Open Accessory class driver functions as the \c AOAInterfaceInfo\r
- * parameter. This stores each Android Open Accessory interface's configuration and state information.\r
- */\r
- typedef struct\r
- {\r
- struct\r
- {\r
- USB_Pipe_Table_t DataINPipe; /**< Data IN Pipe configuration table. */\r
- USB_Pipe_Table_t DataOUTPipe; /**< Data OUT Pipe configuration table. */\r
- \r
- char* PropertyStrings[AOA_STRING_TOTAL_STRINGS]; /**< Android Accessory property strings, sent to identify the accessory when the\r
- * Android device is switched into Open Accessory mode. */\r
- } Config; /**< Config data for the USB class interface within the device. All elements in this section\r
- * <b>must</b> be set or the interface will fail to enumerate and operate correctly.\r
- */\r
- struct\r
- {\r
- bool IsActive; /**< Indicates if the current interface instance is connected to an attached device, valid\r
- * after \ref AOA_Host_ConfigurePipes() is called and the Host state machine is in the\r
- * Configured state.\r
- */\r
- uint8_t InterfaceNumber; /**< Interface index of the AOA interface within the attached device. */\r
- } State; /**< State data for the USB class interface within the device. All elements in this section\r
- * <b>may</b> be set to initial values, but may also be ignored to default to sane values when\r
- * the interface is enumerated.\r
- */\r
- } USB_ClassInfo_AOA_Host_t;\r
-\r
- /* Enums: */\r
- /** Enum for the possible error codes returned by the \ref AOA_Host_ConfigurePipes() function. */\r
- enum AOA_Host_EnumerationFailure_ErrorCodes_t\r
- {\r
- AOA_ENUMERROR_NoError = 0, /**< Configuration Descriptor was processed successfully. */\r
- AOA_ENUMERROR_InvalidConfigDescriptor = 1, /**< The device returned an invalid Configuration Descriptor. */\r
- AOA_ENUMERROR_NoCompatibleInterfaceFound = 2, /**< A compatible Android Open Accessory interface was not found in the device's Configuration Descriptor. */\r
- AOA_ENUMERROR_PipeConfigurationFailed = 3, /**< One or more pipes for the specified interface could not be configured correctly. */\r
- };\r
-\r
- /* Function Prototypes: */\r
- /** General management task for a given Android Open Accessory host class interface, required for the correct operation of the interface.\r
- * This should be called frequently in the main program loop, before the master USB management task \ref USB_USBTask().\r
- *\r
- * \param[in,out] AOAInterfaceInfo Pointer to a structure containing an Android Open Accessory Class host configuration and state.\r
- */\r
- void AOA_Host_USBTask(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Validates a device descriptor, to check if the device is a valid Android device, and if it is currently in Android Open Accessory mode.\r
- *\r
- * \param[in,out] AOAInterfaceInfo Pointer to a structure containing an AOA Class host configuration and state.\r
- * \param[in] DeviceDescriptor Pointer a buffer containing the attached device's Device Descriptor.\r
- * \param[out] NeedModeSwitch Pointer to a boolean where the mode switch requirement of the attached device is to be stored.\r
- *\r
- * \return Boolean \c true if the attached device is a valid Android device, \c false otherwise.\r
- */\r
- bool AOA_Host_ValidateAccessoryDevice(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,\r
- const USB_Descriptor_Device_t* const DeviceDescriptor,\r
- bool* const NeedModeSwitch) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2) ATTR_NON_NULL_PTR_ARG(3);\r
-\r
- /** Host interface configuration routine, to configure a given Android Open Accessory host interface instance using the Configuration\r
- * Descriptor read from an attached USB device. This function automatically updates the given Android Open Accessory Host instance's\r
- * state values and configures the pipes required to communicate with the interface if it is found within the device. This should be\r
- * called once after the stack has enumerated the attached device, while the host state machine is in the Addressed state.\r
- *\r
- * \param[in,out] AOAInterfaceInfo Pointer to a structure containing an AOA Class host configuration and state.\r
- * \param[in] ConfigDescriptorSize Length of the attached device's Configuration Descriptor.\r
- * \param[in] ConfigDescriptorData Pointer to a buffer containing the attached device's Configuration Descriptor.\r
- *\r
- * \return A value from the \ref AOA_Host_EnumerationFailure_ErrorCodes_t enum.\r
- */\r
- uint8_t AOA_Host_ConfigurePipes(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,\r
- uint16_t ConfigDescriptorSize,\r
- void* ConfigDescriptorData) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(3);\r
- \r
- /** Starts Accessory Mode in the attached Android device. This function will validate the device's Android Open Accessory protocol\r
- * version, send the configured property strings, and request a switch to Android Open Accessory mode.\r
- *\r
- * \param[in,out] AOAInterfaceInfo Pointer to a structure containing an AOA Class host configuration and state.\r
- *\r
- * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum, or \ref AOA_ERROR_LOGICAL_CMD_FAILED if a logical error occurred..\r
- */\r
- uint8_t AOA_Host_StartAccessoryMode(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Sends a given data buffer to the attached USB device, if connected. If a device is not connected when the function is\r
- * called, the data will be discarded. Bytes will be queued for transmission to the device until either the pipe bank\r
- * becomes full, or the \ref AOA_Host_Flush() function is called to flush the pending data to the device. This allows for\r
- * multiple bytes to be packed into a single pipe packet, increasing data throughput.\r
- *\r
- * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the\r
- * call will fail.\r
- *\r
- * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state.\r
- * \param[in] Buffer Pointer to a buffer containing the data to send to the device.\r
- * \param[in] Length Length of the data to send to the device.\r
- *\r
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t AOA_Host_SendData(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,\r
- const uint8_t* const Buffer,\r
- const uint16_t Length);\r
-\r
- /** Sends a given null-terminated string to the attached USB device, if connected. If a device is not connected when the\r
- * function is called, the string is discarded. Bytes will be queued for transmission to the device until either the pipe\r
- * bank becomes full, or the \ref AOA_Host_Flush() function is called to flush the pending data to the device. This allows\r
- * for multiple bytes to be packed into a single pipe packet, increasing data throughput.\r
- *\r
- * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the\r
- * call will fail.\r
- *\r
- * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state.\r
- * \param[in] String Pointer to the null terminated string to send to the device.\r
- *\r
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t AOA_Host_SendString(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,\r
- const char* const String) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);\r
-\r
- /** Sends a given byte to the attached USB device, if connected. If a device is not connected when the function is called, the\r
- * byte is discarded. Bytes will be queued for transmission to the device until either the pipe bank becomes full, or the\r
- * \ref AOA_Host_Flush() function is called to flush the pending data to the host. This allows for multiple bytes to be\r
- * packed into a single pipe packet, increasing data throughput.\r
- *\r
- * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the\r
- * call will fail.\r
- *\r
- * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state.\r
- * \param[in] Data Byte of data to send to the device.\r
- *\r
- * \return A value from the \ref Pipe_WaitUntilReady_ErrorCodes_t enum.\r
- */\r
- uint8_t AOA_Host_SendByte(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,\r
- const uint8_t Data) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Determines the number of bytes received by the AOA interface from the device, waiting to be read. This indicates the number\r
- * of bytes in the IN pipe bank only, and thus the number of calls to \ref AOA_Host_ReceiveByte() which are guaranteed to succeed\r
- * immediately. If multiple bytes are to be received, they should be buffered by the user application, as the pipe bank will not be\r
- * released back to the USB controller until all bytes are read.\r
- *\r
- * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the\r
- * call will fail.\r
- *\r
- * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state.\r
- *\r
- * \return Total number of buffered bytes received from the device.\r
- */\r
- uint16_t AOA_Host_BytesReceived(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Reads a byte of data from the device. If no data is waiting to be read of if a USB device is not connected, the function\r
- * returns a negative value. The \ref AOA_Host_BytesReceived() function may be queried in advance to determine how many bytes\r
- * are currently buffered in the AOA interface's data receive pipe.\r
- *\r
- * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the\r
- * call will fail.\r
- *\r
- * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state.\r
- *\r
- * \return Next received byte from the device, or a negative value if no data received.\r
- */\r
- int16_t AOA_Host_ReceiveByte(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Flushes any data waiting to be sent, ensuring that the send buffer is cleared.\r
- *\r
- * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the\r
- * call will fail.\r
- *\r
- * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state.\r
- *\r
- * \return A value from the \ref Pipe_WaitUntilReady_ErrorCodes_t enum.\r
- */\r
- uint8_t AOA_Host_Flush(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Creates a standard character stream for the given AOA Device instance so that it can be used with all the regular\r
- * functions in the standard \c <stdio.h> library that accept a \c FILE stream as a destination (e.g. \c fprintf). The created\r
- * stream is bidirectional and can be used for both input and output functions.\r
- *\r
- * Reading data from this stream is non-blocking, i.e. in most instances, complete strings cannot be read in by a single\r
- * fetch, as the endpoint will not be ready at some point in the transmission, aborting the transfer. However, this may\r
- * be used when the read data is processed byte-per-bye (via \c getc()) or when the user application will implement its own\r
- * line buffering.\r
- *\r
- * \note The created stream can be given as \c stdout if desired to direct the standard output from all \c <stdio.h> functions\r
- * to the given AOA interface.\r
- * \n\n\r
- *\r
- * \note This function is not available on all microcontroller architectures.\r
- *\r
- * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class configuration and state.\r
- * \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed.\r
- */\r
- void AOA_Host_CreateStream(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,\r
- FILE* const Stream);\r
-\r
- /** Identical to \ref AOA_Host_CreateStream(), except that reads are blocking until the calling stream function terminates\r
- * the transfer. While blocking, the USB and AOA service tasks are called repeatedly to maintain USB communications.\r
- *\r
- * \note This function is not available on all microcontroller architectures.\r
- *\r
- * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class configuration and state.\r
- * \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed.\r
- */\r
- void AOA_Host_CreateBlockingStream(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,\r
- FILE* const Stream);\r
-\r
- /* Private Interface - For use in library only: */\r
- #if !defined(__DOXYGEN__)\r
- /* Function Prototypes: */\r
- #if defined(__INCLUDE_FROM_ANDROIDACCESSORY_HOST_C)\r
- #if defined(FDEV_SETUP_STREAM)\r
- static int AOA_Host_putchar(char c,\r
- FILE* Stream) ATTR_NON_NULL_PTR_ARG(2);\r
- static int AOA_Host_getchar(FILE* Stream) ATTR_NON_NULL_PTR_ARG(1);\r
- static int AOA_Host_getchar_Blocking(FILE* Stream) ATTR_NON_NULL_PTR_ARG(1);\r
- #endif\r
-\r
- static uint8_t AOA_Host_GetAccessoryProtocol(uint16_t* const Protocol) ATTR_NON_NULL_PTR_ARG(1);\r
- static uint8_t AOA_Host_SendPropertyString(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,\r
- const uint8_t StringIndex) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- static uint8_t DCOMP_AOA_Host_NextAndroidAccessoryInterface(void* const CurrentDescriptor)\r
- ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);\r
- static uint8_t DCOMP_AOA_Host_NextInterfaceBulkEndpoint(void* const CurrentDescriptor)\r
- ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);\r
- #endif\r
- #endif\r
-\r
- /* Disable C linkage for C++ Compilers: */\r
- #if defined(__cplusplus)\r
- }\r
- #endif\r
-\r
-#endif\r
-\r
-/** @} */\r
-\r
-\r
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 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
+ * \brief Host mode driver for the library USB Android Open Accessory Class driver.
+ *
+ * Host mode driver for the library USB Android Open Accessory Class driver.
+ *
+ * \note This file should not be included directly. It is automatically included as needed by the USB module driver
+ * dispatch header located in LUFA/Drivers/USB.h.
+ */
+
+/** \ingroup Group_USBClassAOA
+ * \defgroup Group_USBClassAndroidAccessoryHost Android Open Accessory Class Host Mode Driver
+ *
+ * \section Sec_Dependencies Module Source Dependencies
+ * The following files must be built with any user project that uses this module:
+ * - LUFA/Drivers/USB/Class/Host/AndroidAccessoryClassHost.c <i>(Makefile source module name: LUFA_SRC_USBCLASS)</i>
+ *
+ * \section Sec_ModDescription Module Description
+ * Host Mode USB Class driver framework interface, for the Android Open Accessory USB Class driver.
+ *
+ * @{
+ */
+
+#ifndef __AOA_CLASS_HOST_H__
+#define __AOA_CLASS_HOST_H__
+
+ /* Includes: */
+ #include "../../USB.h"
+ #include "../Common/AndroidAccessoryClassCommon.h"
+
+ #include <stdio.h>
+
+ /* Enable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ extern "C" {
+ #endif
+
+ /* Preprocessor Checks: */
+ #if !defined(__INCLUDE_FROM_AOA_DRIVER)
+ #error Do not include this file directly. Include LUFA/Drivers/USB.h instead.
+ #endif
+
+ /* Public Interface - May be used in end-application: */
+ /* Macros: */
+ /** Error code for some Android Open Accessory Host functions, indicating a logical (and not hardware) error. */
+ #define AOA_ERROR_LOGICAL_CMD_FAILED 0x80
+
+ /* Type Defines: */
+ /** \brief Android Open Accessory Class Host Mode Configuration and State Structure.
+ *
+ * Class state structure. An instance of this structure should be made within the user application,
+ * and passed to each of the Android Open Accessory class driver functions as the \c AOAInterfaceInfo
+ * parameter. This stores each Android Open Accessory interface's configuration and state information.
+ */
+ typedef struct
+ {
+ struct
+ {
+ USB_Pipe_Table_t DataINPipe; /**< Data IN Pipe configuration table. */
+ USB_Pipe_Table_t DataOUTPipe; /**< Data OUT Pipe configuration table. */
+
+ char* PropertyStrings[AOA_STRING_TOTAL_STRINGS]; /**< Android Accessory property strings, sent to identify the accessory when the
+ * Android device is switched into Open Accessory mode. */
+ } Config; /**< Config data for the USB class interface within the device. All elements in this section
+ * <b>must</b> be set or the interface will fail to enumerate and operate correctly.
+ */
+ struct
+ {
+ bool IsActive; /**< Indicates if the current interface instance is connected to an attached device, valid
+ * after \ref AOA_Host_ConfigurePipes() is called and the Host state machine is in the
+ * Configured state.
+ */
+ uint8_t InterfaceNumber; /**< Interface index of the AOA interface within the attached device. */
+ } State; /**< State data for the USB class interface within the device. All elements in this section
+ * <b>may</b> be set to initial values, but may also be ignored to default to sane values when
+ * the interface is enumerated.
+ */
+ } USB_ClassInfo_AOA_Host_t;
+
+ /* Enums: */
+ /** Enum for the possible error codes returned by the \ref AOA_Host_ConfigurePipes() function. */
+ enum AOA_Host_EnumerationFailure_ErrorCodes_t
+ {
+ AOA_ENUMERROR_NoError = 0, /**< Configuration Descriptor was processed successfully. */
+ AOA_ENUMERROR_InvalidConfigDescriptor = 1, /**< The device returned an invalid Configuration Descriptor. */
+ AOA_ENUMERROR_NoCompatibleInterfaceFound = 2, /**< A compatible Android Open Accessory interface was not found in the device's Configuration Descriptor. */
+ AOA_ENUMERROR_PipeConfigurationFailed = 3, /**< One or more pipes for the specified interface could not be configured correctly. */
+ };
+
+ /* Function Prototypes: */
+ /** General management task for a given Android Open Accessory host class interface, required for the correct operation of the interface.
+ * This should be called frequently in the main program loop, before the master USB management task \ref USB_USBTask().
+ *
+ * \param[in,out] AOAInterfaceInfo Pointer to a structure containing an Android Open Accessory Class host configuration and state.
+ */
+ void AOA_Host_USBTask(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Validates a device descriptor, to check if the device is a valid Android device, and if it is currently in Android Open Accessory mode.
+ *
+ * \param[in,out] AOAInterfaceInfo Pointer to a structure containing an AOA Class host configuration and state.
+ * \param[in] DeviceDescriptor Pointer a buffer containing the attached device's Device Descriptor.
+ * \param[out] NeedModeSwitch Pointer to a boolean where the mode switch requirement of the attached device is to be stored.
+ *
+ * \return Boolean \c true if the attached device is a valid Android device, \c false otherwise.
+ */
+ bool AOA_Host_ValidateAccessoryDevice(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,
+ const USB_Descriptor_Device_t* const DeviceDescriptor,
+ bool* const NeedModeSwitch) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2) ATTR_NON_NULL_PTR_ARG(3);
+
+ /** Host interface configuration routine, to configure a given Android Open Accessory host interface instance using the Configuration
+ * Descriptor read from an attached USB device. This function automatically updates the given Android Open Accessory Host instance's
+ * state values and configures the pipes required to communicate with the interface if it is found within the device. This should be
+ * called once after the stack has enumerated the attached device, while the host state machine is in the Addressed state.
+ *
+ * \param[in,out] AOAInterfaceInfo Pointer to a structure containing an AOA Class host configuration and state.
+ * \param[in] ConfigDescriptorSize Length of the attached device's Configuration Descriptor.
+ * \param[in] ConfigDescriptorData Pointer to a buffer containing the attached device's Configuration Descriptor.
+ *
+ * \return A value from the \ref AOA_Host_EnumerationFailure_ErrorCodes_t enum.
+ */
+ uint8_t AOA_Host_ConfigurePipes(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,
+ uint16_t ConfigDescriptorSize,
+ void* ConfigDescriptorData) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(3);
+
+ /** Starts Accessory Mode in the attached Android device. This function will validate the device's Android Open Accessory protocol
+ * version, send the configured property strings, and request a switch to Android Open Accessory mode.
+ *
+ * \param[in,out] AOAInterfaceInfo Pointer to a structure containing an AOA Class host configuration and state.
+ *
+ * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum, or \ref AOA_ERROR_LOGICAL_CMD_FAILED if a logical error occurred..
+ */
+ uint8_t AOA_Host_StartAccessoryMode(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Sends a given data buffer to the attached USB device, if connected. If a device is not connected when the function is
+ * called, the data will be discarded. Bytes will be queued for transmission to the device until either the pipe bank
+ * becomes full, or the \ref AOA_Host_Flush() function is called to flush the pending data to the device. This allows for
+ * multiple bytes to be packed into a single pipe packet, increasing data throughput.
+ *
+ * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the
+ * call will fail.
+ *
+ * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state.
+ * \param[in] Buffer Pointer to a buffer containing the data to send to the device.
+ * \param[in] Length Length of the data to send to the device.
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t AOA_Host_SendData(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,
+ const uint8_t* const Buffer,
+ const uint16_t Length);
+
+ /** Sends a given null-terminated string to the attached USB device, if connected. If a device is not connected when the
+ * function is called, the string is discarded. Bytes will be queued for transmission to the device until either the pipe
+ * bank becomes full, or the \ref AOA_Host_Flush() function is called to flush the pending data to the device. This allows
+ * for multiple bytes to be packed into a single pipe packet, increasing data throughput.
+ *
+ * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the
+ * call will fail.
+ *
+ * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state.
+ * \param[in] String Pointer to the null terminated string to send to the device.
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t AOA_Host_SendString(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,
+ const char* const String) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);
+
+ /** Sends a given byte to the attached USB device, if connected. If a device is not connected when the function is called, the
+ * byte is discarded. Bytes will be queued for transmission to the device until either the pipe bank becomes full, or the
+ * \ref AOA_Host_Flush() function is called to flush the pending data to the host. This allows for multiple bytes to be
+ * packed into a single pipe packet, increasing data throughput.
+ *
+ * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the
+ * call will fail.
+ *
+ * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state.
+ * \param[in] Data Byte of data to send to the device.
+ *
+ * \return A value from the \ref Pipe_WaitUntilReady_ErrorCodes_t enum.
+ */
+ uint8_t AOA_Host_SendByte(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,
+ const uint8_t Data) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Determines the number of bytes received by the AOA interface from the device, waiting to be read. This indicates the number
+ * of bytes in the IN pipe bank only, and thus the number of calls to \ref AOA_Host_ReceiveByte() which are guaranteed to succeed
+ * immediately. If multiple bytes are to be received, they should be buffered by the user application, as the pipe bank will not be
+ * released back to the USB controller until all bytes are read.
+ *
+ * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the
+ * call will fail.
+ *
+ * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state.
+ *
+ * \return Total number of buffered bytes received from the device.
+ */
+ uint16_t AOA_Host_BytesReceived(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Reads a byte of data from the device. If no data is waiting to be read of if a USB device is not connected, the function
+ * returns a negative value. The \ref AOA_Host_BytesReceived() function may be queried in advance to determine how many bytes
+ * are currently buffered in the AOA interface's data receive pipe.
+ *
+ * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the
+ * call will fail.
+ *
+ * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state.
+ *
+ * \return Next received byte from the device, or a negative value if no data received.
+ */
+ int16_t AOA_Host_ReceiveByte(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Flushes any data waiting to be sent, ensuring that the send buffer is cleared.
+ *
+ * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the
+ * call will fail.
+ *
+ * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class host configuration and state.
+ *
+ * \return A value from the \ref Pipe_WaitUntilReady_ErrorCodes_t enum.
+ */
+ uint8_t AOA_Host_Flush(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Creates a standard character stream for the given AOA Device instance so that it can be used with all the regular
+ * functions in the standard \c <stdio.h> library that accept a \c FILE stream as a destination (e.g. \c fprintf). The created
+ * stream is bidirectional and can be used for both input and output functions.
+ *
+ * Reading data from this stream is non-blocking, i.e. in most instances, complete strings cannot be read in by a single
+ * fetch, as the endpoint will not be ready at some point in the transmission, aborting the transfer. However, this may
+ * be used when the read data is processed byte-per-bye (via \c getc()) or when the user application will implement its own
+ * line buffering.
+ *
+ * \note The created stream can be given as \c stdout if desired to direct the standard output from all \c <stdio.h> functions
+ * to the given AOA interface.
+ * \n\n
+ *
+ * \note This function is not available on all microcontroller architectures.
+ *
+ * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class configuration and state.
+ * \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed.
+ */
+ void AOA_Host_CreateStream(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,
+ FILE* const Stream);
+
+ /** Identical to \ref AOA_Host_CreateStream(), except that reads are blocking until the calling stream function terminates
+ * the transfer. While blocking, the USB and AOA service tasks are called repeatedly to maintain USB communications.
+ *
+ * \note This function is not available on all microcontroller architectures.
+ *
+ * \param[in,out] AOAInterfaceInfo Pointer to a structure containing a AOA Class configuration and state.
+ * \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed.
+ */
+ void AOA_Host_CreateBlockingStream(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,
+ FILE* const Stream);
+
+ /* Private Interface - For use in library only: */
+ #if !defined(__DOXYGEN__)
+ /* Function Prototypes: */
+ #if defined(__INCLUDE_FROM_ANDROIDACCESSORY_HOST_C)
+ #if defined(FDEV_SETUP_STREAM)
+ static int AOA_Host_putchar(char c,
+ FILE* Stream) ATTR_NON_NULL_PTR_ARG(2);
+ static int AOA_Host_getchar(FILE* Stream) ATTR_NON_NULL_PTR_ARG(1);
+ static int AOA_Host_getchar_Blocking(FILE* Stream) ATTR_NON_NULL_PTR_ARG(1);
+ #endif
+
+ static uint8_t AOA_Host_GetAccessoryProtocol(uint16_t* const Protocol) ATTR_NON_NULL_PTR_ARG(1);
+ static uint8_t AOA_Host_SendPropertyString(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,
+ const uint8_t StringIndex) ATTR_NON_NULL_PTR_ARG(1);
+
+ static uint8_t DCOMP_AOA_Host_NextAndroidAccessoryInterface(void* const CurrentDescriptor)
+ ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
+ static uint8_t DCOMP_AOA_Host_NextInterfaceBulkEndpoint(void* const CurrentDescriptor)
+ ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
+ #endif
+ #endif
+
+ /* Disable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ }
+ #endif
+
+#endif
+
+/** @} */
+
+
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2012.\r
- \r
- dean [at] fourwalledcubicle [dot] com\r
- www.lufa-lib.org\r
-*/\r
-\r
-/*\r
- Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, distribute, and sell this \r
- software and its documentation for any purpose is hereby granted\r
- without fee, provided that the above copyright notice appear in \r
- all copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting \r
- documentation, and that the name of the author not be used in \r
- advertising or publicity pertaining to distribution of the \r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-#include "../../../../Common/Common.h"\r
-#if (ARCH == ARCH_AVR8)\r
-\r
-#define __INCLUDE_FROM_USB_DRIVER\r
-#include "../USBMode.h"\r
-\r
-#if defined(USB_CAN_BE_DEVICE)\r
-\r
-#include "EndpointStream_AVR8.h"\r
-\r
-#if !defined(CONTROL_ONLY_DEVICE)\r
-uint8_t Endpoint_Discard_Stream(uint16_t Length,\r
- uint16_t* const BytesProcessed)\r
-{\r
- uint8_t ErrorCode;\r
- uint16_t BytesInTransfer = 0;\r
- \r
- if ((ErrorCode = Endpoint_WaitUntilReady()))\r
- return ErrorCode;\r
- \r
- if (BytesProcessed != NULL)\r
- Length -= *BytesProcessed;\r
-\r
- while (Length)\r
- {\r
- if (!(Endpoint_IsReadWriteAllowed()))\r
- {\r
- Endpoint_ClearOUT();\r
-\r
- if (BytesProcessed != NULL)\r
- {\r
- *BytesProcessed += BytesInTransfer;\r
- return ENDPOINT_RWSTREAM_IncompleteTransfer;\r
- }\r
-\r
- if ((ErrorCode = Endpoint_WaitUntilReady()))\r
- return ErrorCode;\r
- }\r
- else\r
- {\r
- Endpoint_Discard_8();\r
-\r
- Length--;\r
- BytesInTransfer++;\r
- }\r
- }\r
- \r
- return ENDPOINT_RWSTREAM_NoError;\r
-}\r
-\r
-uint8_t Endpoint_Null_Stream(uint16_t Length,\r
- uint16_t* const BytesProcessed)\r
-{\r
- uint8_t ErrorCode;\r
- uint16_t BytesInTransfer = 0;\r
- \r
- if ((ErrorCode = Endpoint_WaitUntilReady()))\r
- return ErrorCode;\r
- \r
- if (BytesProcessed != NULL)\r
- Length -= *BytesProcessed;\r
-\r
- while (Length)\r
- {\r
- if (!(Endpoint_IsReadWriteAllowed()))\r
- {\r
- Endpoint_ClearIN();\r
-\r
- if (BytesProcessed != NULL)\r
- {\r
- *BytesProcessed += BytesInTransfer;\r
- return ENDPOINT_RWSTREAM_IncompleteTransfer;\r
- }\r
-\r
- if ((ErrorCode = Endpoint_WaitUntilReady()))\r
- return ErrorCode;\r
- }\r
- else\r
- {\r
- Endpoint_Write_8(0);\r
-\r
- Length--;\r
- BytesInTransfer++;\r
- }\r
- }\r
- \r
- return ENDPOINT_RWSTREAM_NoError;\r
-}\r
-\r
-/* The following abuses the C preprocessor in order to copy-paste common code with slight alterations,\r
- * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */\r
-\r
-#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_LE\r
-#define TEMPLATE_BUFFER_TYPE const void*\r
-#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()\r
-#define TEMPLATE_BUFFER_OFFSET(Length) 0\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)\r
-#include "Template/Template_Endpoint_RW.c"\r
-\r
-#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE\r
-#define TEMPLATE_BUFFER_TYPE const void*\r
-#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()\r
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)\r
-#include "Template/Template_Endpoint_RW.c"\r
-\r
-#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE\r
-#define TEMPLATE_BUFFER_TYPE void*\r
-#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()\r
-#define TEMPLATE_BUFFER_OFFSET(Length) 0\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()\r
-#include "Template/Template_Endpoint_RW.c"\r
-\r
-#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE\r
-#define TEMPLATE_BUFFER_TYPE void*\r
-#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()\r
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()\r
-#include "Template/Template_Endpoint_RW.c"\r
-\r
-#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE)\r
- #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE\r
- #define TEMPLATE_BUFFER_TYPE const void*\r
- #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()\r
- #define TEMPLATE_BUFFER_OFFSET(Length) 0\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))\r
- #include "Template/Template_Endpoint_RW.c"\r
-\r
- #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE\r
- #define TEMPLATE_BUFFER_TYPE const void*\r
- #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()\r
- #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))\r
- #include "Template/Template_Endpoint_RW.c"\r
-#endif\r
-\r
-#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE)\r
- #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE\r
- #define TEMPLATE_BUFFER_TYPE const void*\r
- #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()\r
- #define TEMPLATE_BUFFER_OFFSET(Length) 0\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))\r
- #include "Template/Template_Endpoint_RW.c"\r
-\r
- #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE\r
- #define TEMPLATE_BUFFER_TYPE const void*\r
- #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()\r
- #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))\r
- #include "Template/Template_Endpoint_RW.c"\r
-\r
- #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE\r
- #define TEMPLATE_BUFFER_TYPE void*\r
- #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()\r
- #define TEMPLATE_BUFFER_OFFSET(Length) 0\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())\r
- #include "Template/Template_Endpoint_RW.c"\r
-\r
- #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE\r
- #define TEMPLATE_BUFFER_TYPE void*\r
- #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()\r
- #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())\r
- #include "Template/Template_Endpoint_RW.c"\r
-#endif\r
-\r
-#endif\r
-\r
-#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE\r
-#define TEMPLATE_BUFFER_OFFSET(Length) 0\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)\r
-#include "Template/Template_Endpoint_Control_W.c"\r
-\r
-#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE\r
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)\r
-#include "Template/Template_Endpoint_Control_W.c"\r
-\r
-#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE\r
-#define TEMPLATE_BUFFER_OFFSET(Length) 0\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()\r
-#include "Template/Template_Endpoint_Control_R.c"\r
-\r
-#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE\r
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()\r
-#include "Template/Template_Endpoint_Control_R.c"\r
-\r
-#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE)\r
- #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_LE\r
- #define TEMPLATE_BUFFER_OFFSET(Length) 0\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))\r
- #include "Template/Template_Endpoint_Control_W.c"\r
-\r
- #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_BE\r
- #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))\r
- #include "Template/Template_Endpoint_Control_W.c"\r
-#endif\r
-\r
-#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE)\r
- #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_LE\r
- #define TEMPLATE_BUFFER_OFFSET(Length) 0\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))\r
- #include "Template/Template_Endpoint_Control_W.c"\r
-\r
- #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_BE\r
- #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))\r
- #include "Template/Template_Endpoint_Control_W.c"\r
-\r
- #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_LE\r
- #define TEMPLATE_BUFFER_OFFSET(Length) 0\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())\r
- #include "Template/Template_Endpoint_Control_R.c"\r
-\r
- #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_BE\r
- #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())\r
- #include "Template/Template_Endpoint_Control_R.c"\r
-#endif\r
-\r
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 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.
+*/
+
+#include "../../../../Common/Common.h"
+#if (ARCH == ARCH_AVR8)
+
+#define __INCLUDE_FROM_USB_DRIVER
+#include "../USBMode.h"
+
+#if defined(USB_CAN_BE_DEVICE)
+
+#include "EndpointStream_AVR8.h"
+
+#if !defined(CONTROL_ONLY_DEVICE)
+uint8_t Endpoint_Discard_Stream(uint16_t Length,
+ uint16_t* const BytesProcessed)
+{
+ uint8_t ErrorCode;
+ uint16_t BytesInTransfer = 0;
+
+ if ((ErrorCode = Endpoint_WaitUntilReady()))
+ return ErrorCode;
+
+ if (BytesProcessed != NULL)
+ Length -= *BytesProcessed;
+
+ while (Length)
+ {
+ if (!(Endpoint_IsReadWriteAllowed()))
+ {
+ Endpoint_ClearOUT();
+
+ if (BytesProcessed != NULL)
+ {
+ *BytesProcessed += BytesInTransfer;
+ return ENDPOINT_RWSTREAM_IncompleteTransfer;
+ }
+
+ if ((ErrorCode = Endpoint_WaitUntilReady()))
+ return ErrorCode;
+ }
+ else
+ {
+ Endpoint_Discard_8();
+
+ Length--;
+ BytesInTransfer++;
+ }
+ }
+
+ return ENDPOINT_RWSTREAM_NoError;
+}
+
+uint8_t Endpoint_Null_Stream(uint16_t Length,
+ uint16_t* const BytesProcessed)
+{
+ uint8_t ErrorCode;
+ uint16_t BytesInTransfer = 0;
+
+ if ((ErrorCode = Endpoint_WaitUntilReady()))
+ return ErrorCode;
+
+ if (BytesProcessed != NULL)
+ Length -= *BytesProcessed;
+
+ while (Length)
+ {
+ if (!(Endpoint_IsReadWriteAllowed()))
+ {
+ Endpoint_ClearIN();
+
+ if (BytesProcessed != NULL)
+ {
+ *BytesProcessed += BytesInTransfer;
+ return ENDPOINT_RWSTREAM_IncompleteTransfer;
+ }
+
+ if ((ErrorCode = Endpoint_WaitUntilReady()))
+ return ErrorCode;
+ }
+ else
+ {
+ Endpoint_Write_8(0);
+
+ Length--;
+ BytesInTransfer++;
+ }
+ }
+
+ return ENDPOINT_RWSTREAM_NoError;
+}
+
+/* The following abuses the C preprocessor in order to copy-paste common code with slight alterations,
+ * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */
+
+#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_LE
+#define TEMPLATE_BUFFER_TYPE const void*
+#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)
+#include "Template/Template_Endpoint_RW.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE
+#define TEMPLATE_BUFFER_TYPE const void*
+#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)
+#include "Template/Template_Endpoint_RW.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE
+#define TEMPLATE_BUFFER_TYPE void*
+#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()
+#include "Template/Template_Endpoint_RW.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE
+#define TEMPLATE_BUFFER_TYPE void*
+#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()
+#include "Template/Template_Endpoint_RW.c"
+
+#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE)
+ #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE
+ #define TEMPLATE_BUFFER_TYPE const void*
+ #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
+ #define TEMPLATE_BUFFER_OFFSET(Length) 0
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))
+ #include "Template/Template_Endpoint_RW.c"
+
+ #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE
+ #define TEMPLATE_BUFFER_TYPE const void*
+ #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
+ #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))
+ #include "Template/Template_Endpoint_RW.c"
+#endif
+
+#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE)
+ #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE
+ #define TEMPLATE_BUFFER_TYPE const void*
+ #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
+ #define TEMPLATE_BUFFER_OFFSET(Length) 0
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))
+ #include "Template/Template_Endpoint_RW.c"
+
+ #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE
+ #define TEMPLATE_BUFFER_TYPE const void*
+ #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
+ #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))
+ #include "Template/Template_Endpoint_RW.c"
+
+ #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE
+ #define TEMPLATE_BUFFER_TYPE void*
+ #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
+ #define TEMPLATE_BUFFER_OFFSET(Length) 0
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())
+ #include "Template/Template_Endpoint_RW.c"
+
+ #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE
+ #define TEMPLATE_BUFFER_TYPE void*
+ #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
+ #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())
+ #include "Template/Template_Endpoint_RW.c"
#endif
-#endif\r
+#endif
+
+#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)
+#include "Template/Template_Endpoint_Control_W.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)
+#include "Template/Template_Endpoint_Control_W.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()
+#include "Template/Template_Endpoint_Control_R.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()
+#include "Template/Template_Endpoint_Control_R.c"
+
+#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE)
+ #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_LE
+ #define TEMPLATE_BUFFER_OFFSET(Length) 0
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))
+ #include "Template/Template_Endpoint_Control_W.c"
+
+ #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_BE
+ #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))
+ #include "Template/Template_Endpoint_Control_W.c"
+#endif
+
+#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE)
+ #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_LE
+ #define TEMPLATE_BUFFER_OFFSET(Length) 0
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))
+ #include "Template/Template_Endpoint_Control_W.c"
+
+ #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_BE
+ #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))
+ #include "Template/Template_Endpoint_Control_W.c"
+
+ #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_LE
+ #define TEMPLATE_BUFFER_OFFSET(Length) 0
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())
+ #include "Template/Template_Endpoint_Control_R.c"
+
+ #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_BE
+ #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())
+ #include "Template/Template_Endpoint_Control_R.c"
+#endif
+
+#endif
+
+#endif
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2012.\r
- \r
- dean [at] fourwalledcubicle [dot] com\r
- www.lufa-lib.org\r
-*/\r
-\r
-/*\r
- Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, distribute, and sell this \r
- software and its documentation for any purpose is hereby granted\r
- without fee, provided that the above copyright notice appear in \r
- all copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting \r
- documentation, and that the name of the author not be used in \r
- advertising or publicity pertaining to distribution of the \r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-/** \file\r
- * \brief Endpoint data stream transmission and reception management for the AVR8 microcontrollers.\r
- * \copydetails Group_EndpointStreamRW_AVR8\r
- *\r
- * \note This file should not be included directly. It is automatically included as needed by the USB driver\r
- * dispatch header located in LUFA/Drivers/USB/USB.h.\r
- */\r
-\r
-/** \ingroup Group_EndpointStreamRW\r
- * \defgroup Group_EndpointStreamRW_AVR8 Read/Write of Multi-Byte Streams (AVR8)\r
- * \brief Endpoint data stream transmission and reception management for the Atmel AVR8 architecture.\r
- *\r
- * Functions, macros, variables, enums and types related to data reading and writing of data streams from\r
- * and to endpoints.\r
- *\r
- * @{\r
- */ \r
-\r
-#ifndef __ENDPOINT_STREAM_AVR8_H__\r
-#define __ENDPOINT_STREAM_AVR8_H__\r
-\r
- /* Includes: */\r
- #include "../../../../Common/Common.h"\r
- #include "../USBMode.h" \r
- #include "../USBTask.h"\r
- \r
- /* Enable C linkage for C++ Compilers: */\r
- #if defined(__cplusplus)\r
- extern "C" {\r
- #endif\r
-\r
- /* Preprocessor Checks: */\r
- #if !defined(__INCLUDE_FROM_USB_DRIVER)\r
- #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.\r
- #endif\r
-\r
- /* Public Interface - May be used in end-application: */\r
- /* Function Prototypes: */\r
- /** \name Stream functions for null data */\r
- //@{\r
-\r
- /** Reads and discards the given number of bytes from the currently selected endpoint's bank,\r
- * discarding fully read packets from the host as needed. The last packet is not automatically\r
- * discarded once the remaining bytes has been read; the user is responsible for manually\r
- * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro.\r
- *\r
- * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,\r
- * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid\r
- * storage location, the transfer will instead be performed as a series of chunks. Each time\r
- * the endpoint bank becomes empty while there is still data to process (and after the current\r
- * packet has been acknowledged) the BytesProcessed location will be updated with the total number\r
- * of bytes processed in the stream, and the function will exit with an error code of\r
- * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed\r
- * in the user code - to continue the transfer, call the function again with identical parameters\r
- * and it will resume until the BytesProcessed value reaches the total transfer length.\r
- *\r
- * <b>Single Stream Transfer Example:</b>\r
- * \code\r
- * uint8_t ErrorCode;\r
- * \r
- * if ((ErrorCode = Endpoint_Discard_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * <b>Partial Stream Transfers Example:</b>\r
- * \code\r
- * uint8_t ErrorCode;\r
- * uint16_t BytesProcessed;\r
- * \r
- * BytesProcessed = 0;\r
- * while ((ErrorCode = Endpoint_Discard_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)\r
- * {\r
- * // Stream not yet complete - do other actions here, abort if required\r
- * }\r
- * \r
- * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * \note This routine should not be used on CONTROL type endpoints.\r
- *\r
- * \param[in] Length Number of bytes to discard via the currently selected endpoint.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be read at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Discard_Stream(uint16_t Length,\r
- uint16_t* const BytesProcessed);\r
-\r
- /** Writes a given number of zeroed bytes to the currently selected endpoint's bank, sending\r
- * full packets to the host as needed. The last packet is not automatically sent once the \r
- * remaining bytes have been written; the user is responsible for manually sending the last\r
- * packet to the host via the \ref Endpoint_ClearIN() macro.\r
- *\r
- * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,\r
- * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid\r
- * storage location, the transfer will instead be performed as a series of chunks. Each time\r
- * the endpoint bank becomes full while there is still data to process (and after the current\r
- * packet transmission has been initiated) the BytesProcessed location will be updated with the\r
- * total number of bytes processed in the stream, and the function will exit with an error code of\r
- * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed\r
- * in the user code - to continue the transfer, call the function again with identical parameters\r
- * and it will resume until the BytesProcessed value reaches the total transfer length.\r
- *\r
- * <b>Single Stream Transfer Example:</b>\r
- * \code\r
- * uint8_t ErrorCode;\r
- * \r
- * if ((ErrorCode = Endpoint_Null_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * <b>Partial Stream Transfers Example:</b>\r
- * \code\r
- * uint8_t ErrorCode;\r
- * uint16_t BytesProcessed;\r
- * \r
- * BytesProcessed = 0;\r
- * while ((ErrorCode = Endpoint_Null_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)\r
- * {\r
- * // Stream not yet complete - do other actions here, abort if required\r
- * }\r
- * \r
- * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * \note This routine should not be used on CONTROL type endpoints.\r
- *\r
- * \param[in] Length Number of zero bytes to send via the currently selected endpoint.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be read at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Null_Stream(uint16_t Length,\r
- uint16_t* const BytesProcessed);\r
-\r
- //@}\r
-\r
- /** \name Stream functions for RAM source/destination data */\r
- //@{\r
- \r
- /** Writes the given number of bytes to the endpoint from the given buffer in little endian,\r
- * sending full packets to the host as needed. The last packet filled is not automatically sent;\r
- * the user is responsible for manually sending the last written packet to the host via the\r
- * \ref Endpoint_ClearIN() macro.\r
- *\r
- * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,\r
- * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid\r
- * storage location, the transfer will instead be performed as a series of chunks. Each time\r
- * the endpoint bank becomes full while there is still data to process (and after the current\r
- * packet transmission has been initiated) the BytesProcessed location will be updated with the\r
- * total number of bytes processed in the stream, and the function will exit with an error code of\r
- * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed\r
- * in the user code - to continue the transfer, call the function again with identical parameters\r
- * and it will resume until the BytesProcessed value reaches the total transfer length.\r
- *\r
- * <b>Single Stream Transfer Example:</b>\r
- * \code\r
- * uint8_t DataStream[512];\r
- * uint8_t ErrorCode;\r
- * \r
- * if ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream),\r
- * NULL)) != ENDPOINT_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * <b>Partial Stream Transfers Example:</b>\r
- * \code\r
- * uint8_t DataStream[512];\r
- * uint8_t ErrorCode;\r
- * uint16_t BytesProcessed;\r
- *\r
- * BytesProcessed = 0;\r
- * while ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream),\r
- * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)\r
- * {\r
- * // Stream not yet complete - do other actions here, abort if required\r
- * }\r
- *\r
- * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * \note This routine should not be used on CONTROL type endpoints.\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be written at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_Stream_LE(const void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Writes the given number of bytes to the endpoint from the given buffer in big endian,\r
- * sending full packets to the host as needed. The last packet filled is not automatically sent;\r
- * the user is responsible for manually sending the last written packet to the host via the\r
- * \ref Endpoint_ClearIN() macro.\r
- *\r
- * \note This routine should not be used on CONTROL type endpoints.\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be written at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_Stream_BE(const void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
- \r
- /** Reads the given number of bytes from the endpoint from the given buffer in little endian,\r
- * discarding fully read packets from the host as needed. The last packet is not automatically\r
- * discarded once the remaining bytes has been read; the user is responsible for manually\r
- * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro.\r
- *\r
- * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,\r
- * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid\r
- * storage location, the transfer will instead be performed as a series of chunks. Each time\r
- * the endpoint bank becomes empty while there is still data to process (and after the current\r
- * packet has been acknowledged) the BytesProcessed location will be updated with the total number\r
- * of bytes processed in the stream, and the function will exit with an error code of\r
- * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed\r
- * in the user code - to continue the transfer, call the function again with identical parameters\r
- * and it will resume until the BytesProcessed value reaches the total transfer length.\r
- *\r
- * <b>Single Stream Transfer Example:</b>\r
- * \code\r
- * uint8_t DataStream[512];\r
- * uint8_t ErrorCode;\r
- * \r
- * if ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream),\r
- * NULL)) != ENDPOINT_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * <b>Partial Stream Transfers Example:</b>\r
- * \code\r
- * uint8_t DataStream[512];\r
- * uint8_t ErrorCode;\r
- * uint16_t BytesProcessed;\r
- * \r
- * BytesProcessed = 0;\r
- * while ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream),\r
- * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)\r
- * {\r
- * // Stream not yet complete - do other actions here, abort if required\r
- * }\r
- * \r
- * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * \note This routine should not be used on CONTROL type endpoints.\r
- *\r
- * \param[out] Buffer Pointer to the destination data buffer to write to.\r
- * \param[in] Length Number of bytes to send via the currently selected endpoint.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be read at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Read_Stream_LE(void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Reads the given number of bytes from the endpoint from the given buffer in big endian,\r
- * discarding fully read packets from the host as needed. The last packet is not automatically\r
- * discarded once the remaining bytes has been read; the user is responsible for manually\r
- * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro.\r
- *\r
- * \note This routine should not be used on CONTROL type endpoints.\r
- *\r
- * \param[out] Buffer Pointer to the destination data buffer to write to.\r
- * \param[in] Length Number of bytes to send via the currently selected endpoint.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be read at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Read_Stream_BE(void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in little endian,\r
- * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared\r
- * in both failure and success states; the user is responsible for manually clearing the setup OUT to\r
- * finalize the transfer via the \ref Endpoint_ClearOUT() macro.\r
- *\r
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
- * to clear the status stage when using this routine in a control transaction.\r
- * \n\n\r
- *\r
- * \note This routine should only be used on CONTROL type endpoints.\r
- *\r
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained\r
- * together; i.e. the entire stream data must be read or written at the one time.\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- *\r
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_Control_Stream_LE(const void* const Buffer,\r
- uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in big endian,\r
- * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared\r
- * in both failure and success states; the user is responsible for manually clearing the setup OUT to\r
- * finalize the transfer via the \ref Endpoint_ClearOUT() macro.\r
- *\r
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
- * to clear the status stage when using this routine in a control transaction.\r
- * \n\n\r
- *\r
- * \note This routine should only be used on CONTROL type endpoints.\r
- *\r
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained\r
- * together; i.e. the entire stream data must be read or written at the one time.\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- *\r
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_Control_Stream_BE(const void* const Buffer,\r
- uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in little endian,\r
- * discarding fully read packets from the host as needed. The device IN acknowledgement is not\r
- * automatically sent after success or failure states; the user is responsible for manually sending the\r
- * setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.\r
- *\r
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
- * to clear the status stage when using this routine in a control transaction.\r
- * \n\n\r
- *\r
- * \note This routine should only be used on CONTROL type endpoints.\r
- *\r
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained\r
- * together; i.e. the entire stream data must be read or written at the one time.\r
- *\r
- * \param[out] Buffer Pointer to the destination data buffer to write to.\r
- * \param[in] Length Number of bytes to send via the currently selected endpoint.\r
- *\r
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Read_Control_Stream_LE(void* const Buffer,\r
- uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in big endian,\r
- * discarding fully read packets from the host as needed. The device IN acknowledgement is not\r
- * automatically sent after success or failure states; the user is responsible for manually sending the\r
- * setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.\r
- *\r
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
- * to clear the status stage when using this routine in a control transaction.\r
- * \n\n\r
- *\r
- * \note This routine should only be used on CONTROL type endpoints.\r
- *\r
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained\r
- * together; i.e. the entire stream data must be read or written at the one time.\r
- *\r
- * \param[out] Buffer Pointer to the destination data buffer to write to.\r
- * \param[in] Length Number of bytes to send via the currently selected endpoint.\r
- *\r
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Read_Control_Stream_BE(void* const Buffer,\r
- uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);\r
- //@}\r
-\r
- /** \name Stream functions for EEPROM source/destination data */\r
- //@{\r
-\r
- /** EEPROM buffer source version of \ref Endpoint_Write_Stream_LE().\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be written at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_EStream_LE(const void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** EEPROM buffer source version of \ref Endpoint_Write_Stream_BE().\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be written at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_EStream_BE(const void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** EEPROM buffer destination version of \ref Endpoint_Read_Stream_LE().\r
- *\r
- * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space.\r
- * \param[in] Length Number of bytes to send via the currently selected endpoint.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be read at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Read_EStream_LE(void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** EEPROM buffer destination version of \ref Endpoint_Read_Stream_BE().\r
- *\r
- * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space.\r
- * \param[in] Length Number of bytes to send via the currently selected endpoint.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be read at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Read_EStream_BE(void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** EEPROM buffer source version of Endpoint_Write_Control_Stream_LE.\r
- *\r
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
- * to clear the status stage when using this routine in a control transaction.\r
- * \n\n\r
- *\r
- * \note This routine should only be used on CONTROL type endpoints.\r
- * \n\n\r
- *\r
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained\r
- * together; i.e. the entire stream data must be read or written at the one time.\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- *\r
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_Control_EStream_LE(const void* const Buffer,\r
- uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** EEPROM buffer source version of \ref Endpoint_Write_Control_Stream_BE().\r
- *\r
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
- * to clear the status stage when using this routine in a control transaction.\r
- * \n\n\r
- *\r
- * \note This routine should only be used on CONTROL type endpoints.\r
- * \n\n\r
- *\r
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained\r
- * together; i.e. the entire stream data must be read or written at the one time.\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- *\r
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_Control_EStream_BE(const void* const Buffer,\r
- uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_LE().\r
- *\r
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
- * to clear the status stage when using this routine in a control transaction.\r
- * \n\n\r
- *\r
- * \note This routine should only be used on CONTROL type endpoints.\r
- * \n\n\r
- *\r
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained\r
- * together; i.e. the entire stream data must be read or written at the one time.\r
- *\r
- * \param[out] Buffer Pointer to the destination data buffer to write to.\r
- * \param[in] Length Number of bytes to send via the currently selected endpoint.\r
- *\r
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Read_Control_EStream_LE(void* const Buffer,\r
- uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_BE().\r
- *\r
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
- * to clear the status stage when using this routine in a control transaction.\r
- * \n\n\r
- *\r
- * \note This routine should only be used on CONTROL type endpoints.\r
- * \n\n\r
- *\r
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained\r
- * together; i.e. the entire stream data must be read or written at the one time.\r
- *\r
- * \param[out] Buffer Pointer to the destination data buffer to write to.\r
- * \param[in] Length Number of bytes to send via the currently selected endpoint.\r
- *\r
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Read_Control_EStream_BE(void* const Buffer,\r
- uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);\r
- //@}\r
-\r
- /** \name Stream functions for PROGMEM source/destination data */\r
- //@{\r
-\r
- /** FLASH buffer source version of \ref Endpoint_Write_Stream_LE().\r
- *\r
- * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be written at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_PStream_LE(const void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** FLASH buffer source version of \ref Endpoint_Write_Stream_BE().\r
- *\r
- * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be written at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_PStream_BE(const void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_LE().\r
- *\r
- * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.\r
- *\r
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
- * to clear the status stage when using this routine in a control transaction.\r
- * \n\n\r
- *\r
- * \note This routine should only be used on CONTROL type endpoints.\r
- * \n\n\r
- *\r
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained\r
- * together; i.e. the entire stream data must be read or written at the one time.\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- *\r
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_Control_PStream_LE(const void* const Buffer,\r
- uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_BE().\r
- *\r
- * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.\r
- *\r
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
- * to clear the status stage when using this routine in a control transaction.\r
- * \n\n\r
- *\r
- * \note This routine should only be used on CONTROL type endpoints.\r
- * \n\n\r
- *\r
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained\r
- * together; i.e. the entire stream data must be read or written at the one time.\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- *\r
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_Control_PStream_BE(const void* const Buffer,\r
- uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);\r
- //@}\r
-\r
- /* Disable C linkage for C++ Compilers: */\r
- #if defined(__cplusplus)\r
- }\r
- #endif\r
- \r
-#endif\r
-\r
-/** @} */\r
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 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
+ * \brief Endpoint data stream transmission and reception management for the AVR8 microcontrollers.
+ * \copydetails Group_EndpointStreamRW_AVR8
+ *
+ * \note This file should not be included directly. It is automatically included as needed by the USB driver
+ * dispatch header located in LUFA/Drivers/USB/USB.h.
+ */
+
+/** \ingroup Group_EndpointStreamRW
+ * \defgroup Group_EndpointStreamRW_AVR8 Read/Write of Multi-Byte Streams (AVR8)
+ * \brief Endpoint data stream transmission and reception management for the Atmel AVR8 architecture.
+ *
+ * Functions, macros, variables, enums and types related to data reading and writing of data streams from
+ * and to endpoints.
+ *
+ * @{
+ */
+
+#ifndef __ENDPOINT_STREAM_AVR8_H__
+#define __ENDPOINT_STREAM_AVR8_H__
+
+ /* Includes: */
+ #include "../../../../Common/Common.h"
+ #include "../USBMode.h"
+ #include "../USBTask.h"
+
+ /* Enable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ extern "C" {
+ #endif
+
+ /* Preprocessor Checks: */
+ #if !defined(__INCLUDE_FROM_USB_DRIVER)
+ #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
+ #endif
+
+ /* Public Interface - May be used in end-application: */
+ /* Function Prototypes: */
+ /** \name Stream functions for null data */
+ //@{
+
+ /** Reads and discards the given number of bytes from the currently selected endpoint's bank,
+ * discarding fully read packets from the host as needed. The last packet is not automatically
+ * discarded once the remaining bytes has been read; the user is responsible for manually
+ * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro.
+ *
+ * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
+ * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
+ * storage location, the transfer will instead be performed as a series of chunks. Each time
+ * the endpoint bank becomes empty while there is still data to process (and after the current
+ * packet has been acknowledged) the BytesProcessed location will be updated with the total number
+ * of bytes processed in the stream, and the function will exit with an error code of
+ * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
+ * in the user code - to continue the transfer, call the function again with identical parameters
+ * and it will resume until the BytesProcessed value reaches the total transfer length.
+ *
+ * <b>Single Stream Transfer Example:</b>
+ * \code
+ * uint8_t ErrorCode;
+ *
+ * if ((ErrorCode = Endpoint_Discard_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * <b>Partial Stream Transfers Example:</b>
+ * \code
+ * uint8_t ErrorCode;
+ * uint16_t BytesProcessed;
+ *
+ * BytesProcessed = 0;
+ * while ((ErrorCode = Endpoint_Discard_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)
+ * {
+ * // Stream not yet complete - do other actions here, abort if required
+ * }
+ *
+ * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * \note This routine should not be used on CONTROL type endpoints.
+ *
+ * \param[in] Length Number of bytes to discard via the currently selected endpoint.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be read at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Discard_Stream(uint16_t Length,
+ uint16_t* const BytesProcessed);
+
+ /** Writes a given number of zeroed bytes to the currently selected endpoint's bank, sending
+ * full packets to the host as needed. The last packet is not automatically sent once the
+ * remaining bytes have been written; the user is responsible for manually sending the last
+ * packet to the host via the \ref Endpoint_ClearIN() macro.
+ *
+ * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
+ * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
+ * storage location, the transfer will instead be performed as a series of chunks. Each time
+ * the endpoint bank becomes full while there is still data to process (and after the current
+ * packet transmission has been initiated) the BytesProcessed location will be updated with the
+ * total number of bytes processed in the stream, and the function will exit with an error code of
+ * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
+ * in the user code - to continue the transfer, call the function again with identical parameters
+ * and it will resume until the BytesProcessed value reaches the total transfer length.
+ *
+ * <b>Single Stream Transfer Example:</b>
+ * \code
+ * uint8_t ErrorCode;
+ *
+ * if ((ErrorCode = Endpoint_Null_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * <b>Partial Stream Transfers Example:</b>
+ * \code
+ * uint8_t ErrorCode;
+ * uint16_t BytesProcessed;
+ *
+ * BytesProcessed = 0;
+ * while ((ErrorCode = Endpoint_Null_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)
+ * {
+ * // Stream not yet complete - do other actions here, abort if required
+ * }
+ *
+ * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * \note This routine should not be used on CONTROL type endpoints.
+ *
+ * \param[in] Length Number of zero bytes to send via the currently selected endpoint.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be read at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Null_Stream(uint16_t Length,
+ uint16_t* const BytesProcessed);
+
+ //@}
+
+ /** \name Stream functions for RAM source/destination data */
+ //@{
+
+ /** Writes the given number of bytes to the endpoint from the given buffer in little endian,
+ * sending full packets to the host as needed. The last packet filled is not automatically sent;
+ * the user is responsible for manually sending the last written packet to the host via the
+ * \ref Endpoint_ClearIN() macro.
+ *
+ * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
+ * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
+ * storage location, the transfer will instead be performed as a series of chunks. Each time
+ * the endpoint bank becomes full while there is still data to process (and after the current
+ * packet transmission has been initiated) the BytesProcessed location will be updated with the
+ * total number of bytes processed in the stream, and the function will exit with an error code of
+ * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
+ * in the user code - to continue the transfer, call the function again with identical parameters
+ * and it will resume until the BytesProcessed value reaches the total transfer length.
+ *
+ * <b>Single Stream Transfer Example:</b>
+ * \code
+ * uint8_t DataStream[512];
+ * uint8_t ErrorCode;
+ *
+ * if ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream),
+ * NULL)) != ENDPOINT_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * <b>Partial Stream Transfers Example:</b>
+ * \code
+ * uint8_t DataStream[512];
+ * uint8_t ErrorCode;
+ * uint16_t BytesProcessed;
+ *
+ * BytesProcessed = 0;
+ * while ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream),
+ * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)
+ * {
+ * // Stream not yet complete - do other actions here, abort if required
+ * }
+ *
+ * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * \note This routine should not be used on CONTROL type endpoints.
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be written at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Stream_LE(const void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Writes the given number of bytes to the endpoint from the given buffer in big endian,
+ * sending full packets to the host as needed. The last packet filled is not automatically sent;
+ * the user is responsible for manually sending the last written packet to the host via the
+ * \ref Endpoint_ClearIN() macro.
+ *
+ * \note This routine should not be used on CONTROL type endpoints.
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be written at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Stream_BE(const void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Reads the given number of bytes from the endpoint from the given buffer in little endian,
+ * discarding fully read packets from the host as needed. The last packet is not automatically
+ * discarded once the remaining bytes has been read; the user is responsible for manually
+ * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro.
+ *
+ * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
+ * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
+ * storage location, the transfer will instead be performed as a series of chunks. Each time
+ * the endpoint bank becomes empty while there is still data to process (and after the current
+ * packet has been acknowledged) the BytesProcessed location will be updated with the total number
+ * of bytes processed in the stream, and the function will exit with an error code of
+ * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
+ * in the user code - to continue the transfer, call the function again with identical parameters
+ * and it will resume until the BytesProcessed value reaches the total transfer length.
+ *
+ * <b>Single Stream Transfer Example:</b>
+ * \code
+ * uint8_t DataStream[512];
+ * uint8_t ErrorCode;
+ *
+ * if ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream),
+ * NULL)) != ENDPOINT_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * <b>Partial Stream Transfers Example:</b>
+ * \code
+ * uint8_t DataStream[512];
+ * uint8_t ErrorCode;
+ * uint16_t BytesProcessed;
+ *
+ * BytesProcessed = 0;
+ * while ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream),
+ * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)
+ * {
+ * // Stream not yet complete - do other actions here, abort if required
+ * }
+ *
+ * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * \note This routine should not be used on CONTROL type endpoints.
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be read at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_Stream_LE(void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Reads the given number of bytes from the endpoint from the given buffer in big endian,
+ * discarding fully read packets from the host as needed. The last packet is not automatically
+ * discarded once the remaining bytes has been read; the user is responsible for manually
+ * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro.
+ *
+ * \note This routine should not be used on CONTROL type endpoints.
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be read at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_Stream_BE(void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in little endian,
+ * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared
+ * in both failure and success states; the user is responsible for manually clearing the setup OUT to
+ * finalize the transfer via the \ref Endpoint_ClearOUT() macro.
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Control_Stream_LE(const void* const Buffer,
+ uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in big endian,
+ * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared
+ * in both failure and success states; the user is responsible for manually clearing the setup OUT to
+ * finalize the transfer via the \ref Endpoint_ClearOUT() macro.
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Control_Stream_BE(const void* const Buffer,
+ uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in little endian,
+ * discarding fully read packets from the host as needed. The device IN acknowledgement is not
+ * automatically sent after success or failure states; the user is responsible for manually sending the
+ * setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_Control_Stream_LE(void* const Buffer,
+ uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in big endian,
+ * discarding fully read packets from the host as needed. The device IN acknowledgement is not
+ * automatically sent after success or failure states; the user is responsible for manually sending the
+ * setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_Control_Stream_BE(void* const Buffer,
+ uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+ //@}
+
+ /** \name Stream functions for EEPROM source/destination data */
+ //@{
+
+ /** EEPROM buffer source version of \ref Endpoint_Write_Stream_LE().
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be written at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_EStream_LE(const void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer source version of \ref Endpoint_Write_Stream_BE().
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be written at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_EStream_BE(const void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer destination version of \ref Endpoint_Read_Stream_LE().
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be read at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_EStream_LE(void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer destination version of \ref Endpoint_Read_Stream_BE().
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be read at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_EStream_BE(void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer source version of Endpoint_Write_Control_Stream_LE.
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ * \n\n
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Control_EStream_LE(const void* const Buffer,
+ uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer source version of \ref Endpoint_Write_Control_Stream_BE().
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ * \n\n
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Control_EStream_BE(const void* const Buffer,
+ uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_LE().
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ * \n\n
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_Control_EStream_LE(void* const Buffer,
+ uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_BE().
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ * \n\n
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_Control_EStream_BE(void* const Buffer,
+ uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+ //@}
+
+ /** \name Stream functions for PROGMEM source/destination data */
+ //@{
+
+ /** FLASH buffer source version of \ref Endpoint_Write_Stream_LE().
+ *
+ * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be written at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_PStream_LE(const void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** FLASH buffer source version of \ref Endpoint_Write_Stream_BE().
+ *
+ * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be written at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_PStream_BE(const void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_LE().
+ *
+ * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ * \n\n
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Control_PStream_LE(const void* const Buffer,
+ uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_BE().
+ *
+ * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ * \n\n
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Control_PStream_BE(const void* const Buffer,
+ uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+ //@}
+
+ /* Disable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ }
+ #endif
+
+#endif
+
+/** @} */
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2012.\r
- \r
- dean [at] fourwalledcubicle [dot] com\r
- www.lufa-lib.org\r
-*/\r
-\r
-/*\r
- Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, distribute, and sell this \r
- software and its documentation for any purpose is hereby granted\r
- without fee, provided that the above copyright notice appear in \r
- all copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting \r
- documentation, and that the name of the author not be used in \r
- advertising or publicity pertaining to distribution of the \r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
- \r
-/** \file\r
- * \brief Pipe data stream transmission and reception management for the AVR8 microcontrollers\r
- * \copydetails Group_PipeStreamRW_AVR8\r
- *\r
- * \note This file should not be included directly. It is automatically included as needed by the USB driver\r
- * dispatch header located in LUFA/Drivers/USB/USB.h.\r
- */\r
-\r
-/** \ingroup Group_PipeStreamRW\r
- * \defgroup Group_PipeStreamRW_AVR8 Read/Write of Multi-Byte Streams (AVR8)\r
- * \brief Pipe data stream transmission and reception management for the Atmel AVR8 architecture.\r
- *\r
- * Functions, macros, variables, enums and types related to data reading and writing of data streams from\r
- * and to pipes.\r
- *\r
- * @{\r
- */\r
-\r
-#ifndef __PIPE_STREAM_AVR8_H__\r
-#define __PIPE_STREAM_AVR8_H__\r
-\r
- /* Includes: */\r
- #include "../../../../Common/Common.h"\r
- #include "../USBMode.h" \r
- #include "../USBTask.h"\r
- \r
- /* Enable C linkage for C++ Compilers: */\r
- #if defined(__cplusplus)\r
- extern "C" {\r
- #endif\r
-\r
- /* Preprocessor Checks: */\r
- #if !defined(__INCLUDE_FROM_USB_DRIVER)\r
- #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.\r
- #endif\r
- \r
- /* Public Interface - May be used in end-application: */\r
- /* Function Prototypes: */\r
- /** \name Stream functions for null data */\r
- //@{\r
-\r
- /** Reads and discards the given number of bytes from the pipe, discarding fully read packets from the host\r
- * as needed. The last packet is not automatically discarded once the remaining bytes has been read; the\r
- * user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearIN() macro.\r
- *\r
- * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or\r
- * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer\r
- * will instead be performed as a series of chunks. Each time the pipe bank becomes empty while there is still data\r
- * to process (and after the current packet has been acknowledged) the BytesProcessed location will be updated with\r
- * the total number of bytes processed in the stream, and the function will exit with an error code of\r
- * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to\r
- * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed\r
- * value reaches the total transfer length.\r
- *\r
- * <b>Single Stream Transfer Example:</b>\r
- * \code\r
- * uint8_t ErrorCode;\r
- * \r
- * if ((ErrorCode = Pipe_Discard_Stream(512, NULL)) != PIPE_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * <b>Partial Stream Transfers Example:</b>\r
- * \code\r
- * uint8_t ErrorCode;\r
- * uint16_t BytesProcessed;\r
- * \r
- * BytesProcessed = 0;\r
- * while ((ErrorCode = Pipe_Discard_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)\r
- * {\r
- * // Stream not yet complete - do other actions here, abort if required\r
- * }\r
- * \r
- * if (ErrorCode != PIPE_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without\r
- * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().\r
- *\r
- * \param[in] Length Number of bytes to discard via the currently selected pipe.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should\r
- * updated, \c NULL if the entire stream should be processed at once.\r
- *\r
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Pipe_Discard_Stream(uint16_t Length,\r
- uint16_t* const BytesProcessed);\r
-\r
- /** Writes a given number of zeroed bytes to the pipe, sending full pipe packets from the host to the device\r
- * as needed. The last packet is not automatically sent once the remaining bytes has been written; the\r
- * user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearOUT() macro.\r
- *\r
- * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or\r
- * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer\r
- * will instead be performed as a series of chunks. Each time the pipe bank becomes full while there is still data\r
- * to process (and after the current packet transmission has been initiated) the BytesProcessed location will be\r
- * updated with the total number of bytes processed in the stream, and the function will exit with an error code of\r
- * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to\r
- * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed\r
- * value reaches the total transfer length.\r
- *\r
- * <b>Single Stream Transfer Example:</b>\r
- * \code\r
- * uint8_t ErrorCode;\r
- * \r
- * if ((ErrorCode = Pipe_Null_Stream(512, NULL)) != PIPE_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * <b>Partial Stream Transfers Example:</b>\r
- * \code\r
- * uint8_t ErrorCode;\r
- * uint16_t BytesProcessed;\r
- * \r
- * BytesProcessed = 0;\r
- * while ((ErrorCode = Pipe_Null_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)\r
- * {\r
- * // Stream not yet complete - do other actions here, abort if required\r
- * }\r
- * \r
- * if (ErrorCode != PIPE_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without\r
- * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().\r
- *\r
- * \param[in] Length Number of zero bytes to write via the currently selected pipe.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should\r
- * updated, \c NULL if the entire stream should be processed at once.\r
- *\r
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Pipe_Null_Stream(uint16_t Length,\r
- uint16_t* const BytesProcessed);\r
-\r
- //@}\r
-\r
- /** \name Stream functions for RAM source/destination data */\r
- //@{\r
- \r
- /** Writes the given number of bytes to the pipe from the given buffer in little endian,\r
- * sending full packets to the device as needed. The last packet filled is not automatically sent;\r
- * the user is responsible for manually sending the last written packet to the host via the\r
- * \ref Pipe_ClearOUT() macro. Between each USB packet, the given stream callback function is\r
- * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.\r
- *\r
- * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,\r
- * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid\r
- * storage location, the transfer will instead be performed as a series of chunks. Each time\r
- * the pipe bank becomes full while there is still data to process (and after the current\r
- * packet transmission has been initiated) the BytesProcessed location will be updated with the\r
- * total number of bytes processed in the stream, and the function will exit with an error code of\r
- * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed\r
- * in the user code - to continue the transfer, call the function again with identical parameters\r
- * and it will resume until the BytesProcessed value reaches the total transfer length.\r
- *\r
- * <b>Single Stream Transfer Example:</b>\r
- * \code\r
- * uint8_t DataStream[512];\r
- * uint8_t ErrorCode;\r
- * \r
- * if ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream),\r
- * NULL)) != PIPE_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * <b>Partial Stream Transfers Example:</b>\r
- * \code\r
- * uint8_t DataStream[512];\r
- * uint8_t ErrorCode;\r
- * uint16_t BytesProcessed;\r
- * \r
- * BytesProcessed = 0;\r
- * while ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream),\r
- * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)\r
- * {\r
- * // Stream not yet complete - do other actions here, abort if required\r
- * }\r
- * \r
- * if (ErrorCode != PIPE_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without\r
- * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should\r
- * updated, \c NULL if the entire stream should be written at once.\r
- *\r
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Pipe_Write_Stream_LE(const void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Writes the given number of bytes to the pipe from the given buffer in big endian,\r
- * sending full packets to the device as needed. The last packet filled is not automatically sent;\r
- * the user is responsible for manually sending the last written packet to the host via the\r
- * \ref Pipe_ClearOUT() macro. Between each USB packet, the given stream callback function is\r
- * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.\r
- *\r
- * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without\r
- * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should\r
- * updated, \c NULL if the entire stream should be written at once.\r
- *\r
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Pipe_Write_Stream_BE(const void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Reads the given number of bytes from the pipe into the given buffer in little endian,\r
- * sending full packets to the device as needed. The last packet filled is not automatically sent;\r
- * the user is responsible for manually sending the last written packet to the host via the\r
- * \ref Pipe_ClearIN() macro. Between each USB packet, the given stream callback function is\r
- * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.\r
- *\r
- * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,\r
- * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid\r
- * storage location, the transfer will instead be performed as a series of chunks. Each time\r
- * the pipe bank becomes empty while there is still data to process (and after the current\r
- * packet has been acknowledged) the BytesProcessed location will be updated with the total number\r
- * of bytes processed in the stream, and the function will exit with an error code of\r
- * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed\r
- * in the user code - to continue the transfer, call the function again with identical parameters\r
- * and it will resume until the BytesProcessed value reaches the total transfer length.\r
- *\r
- * <b>Single Stream Transfer Example:</b>\r
- * \code\r
- * uint8_t DataStream[512];\r
- * uint8_t ErrorCode;\r
- * \r
- * if ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream),\r
- * NULL)) != PIPE_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * <b>Partial Stream Transfers Example:</b>\r
- * \code\r
- * uint8_t DataStream[512];\r
- * uint8_t ErrorCode;\r
- * uint16_t BytesProcessed;\r
- * \r
- * BytesProcessed = 0;\r
- * while ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream),\r
- * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)\r
- * {\r
- * // Stream not yet complete - do other actions here, abort if required\r
- * }\r
- * \r
- * if (ErrorCode != PIPE_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without\r
- * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().\r
- *\r
- * \param[out] Buffer Pointer to the source data buffer to write to.\r
- * \param[in] Length Number of bytes to read for the currently selected pipe to read from.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should\r
- * updated, \c NULL if the entire stream should be read at once.\r
- *\r
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Pipe_Read_Stream_LE(void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Reads the given number of bytes from the pipe into the given buffer in big endian,\r
- * sending full packets to the device as needed. The last packet filled is not automatically sent;\r
- * the user is responsible for manually sending the last written packet to the host via the\r
- * \ref Pipe_ClearIN() macro. Between each USB packet, the given stream callback function is\r
- * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.\r
- *\r
- * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without\r
- * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().\r
- *\r
- * \param[out] Buffer Pointer to the source data buffer to write to.\r
- * \param[in] Length Number of bytes to read for the currently selected pipe to read from.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should\r
- * updated, \c NULL if the entire stream should be read at once.\r
- *\r
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Pipe_Read_Stream_BE(void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
- //@}\r
-\r
- /** \name Stream functions for EEPROM source/destination data */\r
- //@{\r
- \r
- /** EEPROM buffer source version of \ref Pipe_Write_Stream_LE().\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should\r
- * updated, \c NULL if the entire stream should be written at once.\r
- *\r
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Pipe_Write_EStream_LE(const void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
- \r
- /** EEPROM buffer source version of \ref Pipe_Write_Stream_BE().\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should\r
- * updated, \c NULL if the entire stream should be written at once.\r
- *\r
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Pipe_Write_EStream_BE(const void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** EEPROM buffer source version of \ref Pipe_Read_Stream_LE().\r
- *\r
- * \param[out] Buffer Pointer to the source data buffer to write to.\r
- * \param[in] Length Number of bytes to read for the currently selected pipe to read from.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should\r
- * updated, \c NULL if the entire stream should be read at once.\r
- *\r
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Pipe_Read_EStream_LE(void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
- \r
- /** EEPROM buffer source version of \ref Pipe_Read_Stream_BE().\r
- *\r
- * \param[out] Buffer Pointer to the source data buffer to write to.\r
- * \param[in] Length Number of bytes to read for the currently selected pipe to read from.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should\r
- * updated, \c NULL if the entire stream should be read at once.\r
- *\r
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Pipe_Read_EStream_BE(void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
- //@}\r
-\r
- /** \name Stream functions for PROGMEM source/destination data */\r
- //@{\r
- \r
- /** FLASH buffer source version of \ref Pipe_Write_Stream_LE().\r
- *\r
- * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should\r
- * updated, \c NULL if the entire stream should be written at once.\r
- *\r
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Pipe_Write_PStream_LE(const void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
- \r
- /** FLASH buffer source version of \ref Pipe_Write_Stream_BE().\r
- *\r
- * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should\r
- * updated, \c NULL if the entire stream should be written at once.\r
- *\r
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Pipe_Write_PStream_BE(const void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
- //@}\r
-\r
- /* Disable C linkage for C++ Compilers: */\r
- #if defined(__cplusplus)\r
- }\r
- #endif\r
- \r
-#endif\r
-\r
-/** @} */\r
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 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
+ * \brief Pipe data stream transmission and reception management for the AVR8 microcontrollers
+ * \copydetails Group_PipeStreamRW_AVR8
+ *
+ * \note This file should not be included directly. It is automatically included as needed by the USB driver
+ * dispatch header located in LUFA/Drivers/USB/USB.h.
+ */
+
+/** \ingroup Group_PipeStreamRW
+ * \defgroup Group_PipeStreamRW_AVR8 Read/Write of Multi-Byte Streams (AVR8)
+ * \brief Pipe data stream transmission and reception management for the Atmel AVR8 architecture.
+ *
+ * Functions, macros, variables, enums and types related to data reading and writing of data streams from
+ * and to pipes.
+ *
+ * @{
+ */
+
+#ifndef __PIPE_STREAM_AVR8_H__
+#define __PIPE_STREAM_AVR8_H__
+
+ /* Includes: */
+ #include "../../../../Common/Common.h"
+ #include "../USBMode.h"
+ #include "../USBTask.h"
+
+ /* Enable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ extern "C" {
+ #endif
+
+ /* Preprocessor Checks: */
+ #if !defined(__INCLUDE_FROM_USB_DRIVER)
+ #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
+ #endif
+
+ /* Public Interface - May be used in end-application: */
+ /* Function Prototypes: */
+ /** \name Stream functions for null data */
+ //@{
+
+ /** Reads and discards the given number of bytes from the pipe, discarding fully read packets from the host
+ * as needed. The last packet is not automatically discarded once the remaining bytes has been read; the
+ * user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearIN() macro.
+ *
+ * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or
+ * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer
+ * will instead be performed as a series of chunks. Each time the pipe bank becomes empty while there is still data
+ * to process (and after the current packet has been acknowledged) the BytesProcessed location will be updated with
+ * the total number of bytes processed in the stream, and the function will exit with an error code of
+ * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to
+ * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed
+ * value reaches the total transfer length.
+ *
+ * <b>Single Stream Transfer Example:</b>
+ * \code
+ * uint8_t ErrorCode;
+ *
+ * if ((ErrorCode = Pipe_Discard_Stream(512, NULL)) != PIPE_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * <b>Partial Stream Transfers Example:</b>
+ * \code
+ * uint8_t ErrorCode;
+ * uint16_t BytesProcessed;
+ *
+ * BytesProcessed = 0;
+ * while ((ErrorCode = Pipe_Discard_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)
+ * {
+ * // Stream not yet complete - do other actions here, abort if required
+ * }
+ *
+ * if (ErrorCode != PIPE_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
+ * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
+ *
+ * \param[in] Length Number of bytes to discard via the currently selected pipe.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
+ * updated, \c NULL if the entire stream should be processed at once.
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Discard_Stream(uint16_t Length,
+ uint16_t* const BytesProcessed);
+
+ /** Writes a given number of zeroed bytes to the pipe, sending full pipe packets from the host to the device
+ * as needed. The last packet is not automatically sent once the remaining bytes has been written; the
+ * user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearOUT() macro.
+ *
+ * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or
+ * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer
+ * will instead be performed as a series of chunks. Each time the pipe bank becomes full while there is still data
+ * to process (and after the current packet transmission has been initiated) the BytesProcessed location will be
+ * updated with the total number of bytes processed in the stream, and the function will exit with an error code of
+ * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to
+ * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed
+ * value reaches the total transfer length.
+ *
+ * <b>Single Stream Transfer Example:</b>
+ * \code
+ * uint8_t ErrorCode;
+ *
+ * if ((ErrorCode = Pipe_Null_Stream(512, NULL)) != PIPE_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * <b>Partial Stream Transfers Example:</b>
+ * \code
+ * uint8_t ErrorCode;
+ * uint16_t BytesProcessed;
+ *
+ * BytesProcessed = 0;
+ * while ((ErrorCode = Pipe_Null_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)
+ * {
+ * // Stream not yet complete - do other actions here, abort if required
+ * }
+ *
+ * if (ErrorCode != PIPE_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
+ * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
+ *
+ * \param[in] Length Number of zero bytes to write via the currently selected pipe.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
+ * updated, \c NULL if the entire stream should be processed at once.
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Null_Stream(uint16_t Length,
+ uint16_t* const BytesProcessed);
+
+ //@}
+
+ /** \name Stream functions for RAM source/destination data */
+ //@{
+
+ /** Writes the given number of bytes to the pipe from the given buffer in little endian,
+ * sending full packets to the device as needed. The last packet filled is not automatically sent;
+ * the user is responsible for manually sending the last written packet to the host via the
+ * \ref Pipe_ClearOUT() macro. Between each USB packet, the given stream callback function is
+ * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
+ *
+ * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
+ * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
+ * storage location, the transfer will instead be performed as a series of chunks. Each time
+ * the pipe bank becomes full while there is still data to process (and after the current
+ * packet transmission has been initiated) the BytesProcessed location will be updated with the
+ * total number of bytes processed in the stream, and the function will exit with an error code of
+ * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
+ * in the user code - to continue the transfer, call the function again with identical parameters
+ * and it will resume until the BytesProcessed value reaches the total transfer length.
+ *
+ * <b>Single Stream Transfer Example:</b>
+ * \code
+ * uint8_t DataStream[512];
+ * uint8_t ErrorCode;
+ *
+ * if ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream),
+ * NULL)) != PIPE_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * <b>Partial Stream Transfers Example:</b>
+ * \code
+ * uint8_t DataStream[512];
+ * uint8_t ErrorCode;
+ * uint16_t BytesProcessed;
+ *
+ * BytesProcessed = 0;
+ * while ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream),
+ * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)
+ * {
+ * // Stream not yet complete - do other actions here, abort if required
+ * }
+ *
+ * if (ErrorCode != PIPE_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
+ * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
+ * updated, \c NULL if the entire stream should be written at once.
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Write_Stream_LE(const void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Writes the given number of bytes to the pipe from the given buffer in big endian,
+ * sending full packets to the device as needed. The last packet filled is not automatically sent;
+ * the user is responsible for manually sending the last written packet to the host via the
+ * \ref Pipe_ClearOUT() macro. Between each USB packet, the given stream callback function is
+ * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
+ *
+ * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
+ * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
+ * updated, \c NULL if the entire stream should be written at once.
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Write_Stream_BE(const void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Reads the given number of bytes from the pipe into the given buffer in little endian,
+ * sending full packets to the device as needed. The last packet filled is not automatically sent;
+ * the user is responsible for manually sending the last written packet to the host via the
+ * \ref Pipe_ClearIN() macro. Between each USB packet, the given stream callback function is
+ * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
+ *
+ * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
+ * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
+ * storage location, the transfer will instead be performed as a series of chunks. Each time
+ * the pipe bank becomes empty while there is still data to process (and after the current
+ * packet has been acknowledged) the BytesProcessed location will be updated with the total number
+ * of bytes processed in the stream, and the function will exit with an error code of
+ * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
+ * in the user code - to continue the transfer, call the function again with identical parameters
+ * and it will resume until the BytesProcessed value reaches the total transfer length.
+ *
+ * <b>Single Stream Transfer Example:</b>
+ * \code
+ * uint8_t DataStream[512];
+ * uint8_t ErrorCode;
+ *
+ * if ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream),
+ * NULL)) != PIPE_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * <b>Partial Stream Transfers Example:</b>
+ * \code
+ * uint8_t DataStream[512];
+ * uint8_t ErrorCode;
+ * uint16_t BytesProcessed;
+ *
+ * BytesProcessed = 0;
+ * while ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream),
+ * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)
+ * {
+ * // Stream not yet complete - do other actions here, abort if required
+ * }
+ *
+ * if (ErrorCode != PIPE_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
+ * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
+ *
+ * \param[out] Buffer Pointer to the source data buffer to write to.
+ * \param[in] Length Number of bytes to read for the currently selected pipe to read from.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
+ * updated, \c NULL if the entire stream should be read at once.
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Read_Stream_LE(void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Reads the given number of bytes from the pipe into the given buffer in big endian,
+ * sending full packets to the device as needed. The last packet filled is not automatically sent;
+ * the user is responsible for manually sending the last written packet to the host via the
+ * \ref Pipe_ClearIN() macro. Between each USB packet, the given stream callback function is
+ * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
+ *
+ * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
+ * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
+ *
+ * \param[out] Buffer Pointer to the source data buffer to write to.
+ * \param[in] Length Number of bytes to read for the currently selected pipe to read from.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
+ * updated, \c NULL if the entire stream should be read at once.
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Read_Stream_BE(void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+ //@}
+
+ /** \name Stream functions for EEPROM source/destination data */
+ //@{
+
+ /** EEPROM buffer source version of \ref Pipe_Write_Stream_LE().
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
+ * updated, \c NULL if the entire stream should be written at once.
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Write_EStream_LE(const void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer source version of \ref Pipe_Write_Stream_BE().
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
+ * updated, \c NULL if the entire stream should be written at once.
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Write_EStream_BE(const void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer source version of \ref Pipe_Read_Stream_LE().
+ *
+ * \param[out] Buffer Pointer to the source data buffer to write to.
+ * \param[in] Length Number of bytes to read for the currently selected pipe to read from.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
+ * updated, \c NULL if the entire stream should be read at once.
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Read_EStream_LE(void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer source version of \ref Pipe_Read_Stream_BE().
+ *
+ * \param[out] Buffer Pointer to the source data buffer to write to.
+ * \param[in] Length Number of bytes to read for the currently selected pipe to read from.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
+ * updated, \c NULL if the entire stream should be read at once.
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Read_EStream_BE(void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+ //@}
+
+ /** \name Stream functions for PROGMEM source/destination data */
+ //@{
+
+ /** FLASH buffer source version of \ref Pipe_Write_Stream_LE().
+ *
+ * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
+ * updated, \c NULL if the entire stream should be written at once.
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Write_PStream_LE(const void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** FLASH buffer source version of \ref Pipe_Write_Stream_BE().
+ *
+ * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
+ * updated, \c NULL if the entire stream should be written at once.
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Write_PStream_BE(const void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+ //@}
+
+ /* Disable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ }
+ #endif
+
+#endif
+
+/** @} */
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2012.\r
- \r
- dean [at] fourwalledcubicle [dot] com\r
- www.lufa-lib.org\r
-*/\r
-\r
-/*\r
- Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, distribute, and sell this \r
- software and its documentation for any purpose is hereby granted\r
- without fee, provided that the above copyright notice appear in \r
- all copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting \r
- documentation, and that the name of the author not be used in \r
- advertising or publicity pertaining to distribution of the \r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-#include "../../../../Common/Common.h"\r
-#if (ARCH == ARCH_UC3)\r
-\r
-#define __INCLUDE_FROM_USB_DRIVER\r
-#include "../USBMode.h"\r
-\r
-#if defined(USB_CAN_BE_DEVICE)\r
-\r
-#include "EndpointStream_UC3.h"\r
-\r
-#if !defined(CONTROL_ONLY_DEVICE)\r
-uint8_t Endpoint_Discard_Stream(uint16_t Length,\r
- uint16_t* const BytesProcessed)\r
-{\r
- uint8_t ErrorCode;\r
- uint16_t BytesInTransfer = 0;\r
- \r
- if ((ErrorCode = Endpoint_WaitUntilReady()))\r
- return ErrorCode;\r
- \r
- if (BytesProcessed != NULL)\r
- Length -= *BytesProcessed;\r
-\r
- while (Length)\r
- {\r
- if (!(Endpoint_IsReadWriteAllowed()))\r
- {\r
- Endpoint_ClearOUT();\r
-\r
- if (BytesProcessed != NULL)\r
- {\r
- *BytesProcessed += BytesInTransfer;\r
- return ENDPOINT_RWSTREAM_IncompleteTransfer;\r
- }\r
-\r
- if ((ErrorCode = Endpoint_WaitUntilReady()))\r
- return ErrorCode;\r
- }\r
- else\r
- {\r
- Endpoint_Discard_8();\r
-\r
- Length--;\r
- BytesInTransfer++;\r
- }\r
- }\r
- \r
- return ENDPOINT_RWSTREAM_NoError;\r
-}\r
-\r
-uint8_t Endpoint_Null_Stream(uint16_t Length,\r
- uint16_t* const BytesProcessed)\r
-{\r
- uint8_t ErrorCode;\r
- uint16_t BytesInTransfer = 0;\r
- \r
- if ((ErrorCode = Endpoint_WaitUntilReady()))\r
- return ErrorCode;\r
- \r
- if (BytesProcessed != NULL)\r
- Length -= *BytesProcessed;\r
-\r
- while (Length)\r
- {\r
- if (!(Endpoint_IsReadWriteAllowed()))\r
- {\r
- Endpoint_ClearIN();\r
-\r
- if (BytesProcessed != NULL)\r
- {\r
- *BytesProcessed += BytesInTransfer;\r
- return ENDPOINT_RWSTREAM_IncompleteTransfer;\r
- }\r
-\r
- if ((ErrorCode = Endpoint_WaitUntilReady()))\r
- return ErrorCode;\r
- }\r
- else\r
- {\r
- Endpoint_Write_8(0);\r
-\r
- Length--;\r
- BytesInTransfer++;\r
- }\r
- }\r
- \r
- return ENDPOINT_RWSTREAM_NoError;\r
-}\r
-\r
-/* The following abuses the C preprocessor in order to copy-paste common code with slight alterations,\r
- * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */\r
-\r
-#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_LE\r
-#define TEMPLATE_BUFFER_TYPE const void*\r
-#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()\r
-#define TEMPLATE_BUFFER_OFFSET(Length) 0\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)\r
-#include "Template/Template_Endpoint_RW.c"\r
-\r
-#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE\r
-#define TEMPLATE_BUFFER_TYPE const void*\r
-#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()\r
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)\r
-#include "Template/Template_Endpoint_RW.c"\r
-\r
-#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE\r
-#define TEMPLATE_BUFFER_TYPE void*\r
-#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()\r
-#define TEMPLATE_BUFFER_OFFSET(Length) 0\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()\r
-#include "Template/Template_Endpoint_RW.c"\r
-\r
-#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE\r
-#define TEMPLATE_BUFFER_TYPE void*\r
-#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()\r
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()\r
-#include "Template/Template_Endpoint_RW.c"\r
-\r
-#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE)\r
- #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE\r
- #define TEMPLATE_BUFFER_TYPE const void*\r
- #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()\r
- #define TEMPLATE_BUFFER_OFFSET(Length) 0\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))\r
- #include "Template/Template_Endpoint_RW.c"\r
-\r
- #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE\r
- #define TEMPLATE_BUFFER_TYPE const void*\r
- #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()\r
- #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))\r
- #include "Template/Template_Endpoint_RW.c"\r
-#endif\r
-\r
-#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE)\r
- #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE\r
- #define TEMPLATE_BUFFER_TYPE const void*\r
- #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()\r
- #define TEMPLATE_BUFFER_OFFSET(Length) 0\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))\r
- #include "Template/Template_Endpoint_RW.c"\r
-\r
- #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE\r
- #define TEMPLATE_BUFFER_TYPE const void*\r
- #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()\r
- #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))\r
- #include "Template/Template_Endpoint_RW.c"\r
-\r
- #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE\r
- #define TEMPLATE_BUFFER_TYPE void*\r
- #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()\r
- #define TEMPLATE_BUFFER_OFFSET(Length) 0\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())\r
- #include "Template/Template_Endpoint_RW.c"\r
-\r
- #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE\r
- #define TEMPLATE_BUFFER_TYPE void*\r
- #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()\r
- #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())\r
- #include "Template/Template_Endpoint_RW.c"\r
-#endif\r
-\r
-#endif\r
-\r
-#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE\r
-#define TEMPLATE_BUFFER_OFFSET(Length) 0\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)\r
-#include "Template/Template_Endpoint_Control_W.c"\r
-\r
-#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE\r
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)\r
-#include "Template/Template_Endpoint_Control_W.c"\r
-\r
-#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE\r
-#define TEMPLATE_BUFFER_OFFSET(Length) 0\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()\r
-#include "Template/Template_Endpoint_Control_R.c"\r
-\r
-#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE\r
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()\r
-#include "Template/Template_Endpoint_Control_R.c"\r
-\r
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 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.
+*/
+
+#include "../../../../Common/Common.h"
+#if (ARCH == ARCH_UC3)
+
+#define __INCLUDE_FROM_USB_DRIVER
+#include "../USBMode.h"
+
+#if defined(USB_CAN_BE_DEVICE)
+
+#include "EndpointStream_UC3.h"
+
+#if !defined(CONTROL_ONLY_DEVICE)
+uint8_t Endpoint_Discard_Stream(uint16_t Length,
+ uint16_t* const BytesProcessed)
+{
+ uint8_t ErrorCode;
+ uint16_t BytesInTransfer = 0;
+
+ if ((ErrorCode = Endpoint_WaitUntilReady()))
+ return ErrorCode;
+
+ if (BytesProcessed != NULL)
+ Length -= *BytesProcessed;
+
+ while (Length)
+ {
+ if (!(Endpoint_IsReadWriteAllowed()))
+ {
+ Endpoint_ClearOUT();
+
+ if (BytesProcessed != NULL)
+ {
+ *BytesProcessed += BytesInTransfer;
+ return ENDPOINT_RWSTREAM_IncompleteTransfer;
+ }
+
+ if ((ErrorCode = Endpoint_WaitUntilReady()))
+ return ErrorCode;
+ }
+ else
+ {
+ Endpoint_Discard_8();
+
+ Length--;
+ BytesInTransfer++;
+ }
+ }
+
+ return ENDPOINT_RWSTREAM_NoError;
+}
+
+uint8_t Endpoint_Null_Stream(uint16_t Length,
+ uint16_t* const BytesProcessed)
+{
+ uint8_t ErrorCode;
+ uint16_t BytesInTransfer = 0;
+
+ if ((ErrorCode = Endpoint_WaitUntilReady()))
+ return ErrorCode;
+
+ if (BytesProcessed != NULL)
+ Length -= *BytesProcessed;
+
+ while (Length)
+ {
+ if (!(Endpoint_IsReadWriteAllowed()))
+ {
+ Endpoint_ClearIN();
+
+ if (BytesProcessed != NULL)
+ {
+ *BytesProcessed += BytesInTransfer;
+ return ENDPOINT_RWSTREAM_IncompleteTransfer;
+ }
+
+ if ((ErrorCode = Endpoint_WaitUntilReady()))
+ return ErrorCode;
+ }
+ else
+ {
+ Endpoint_Write_8(0);
+
+ Length--;
+ BytesInTransfer++;
+ }
+ }
+
+ return ENDPOINT_RWSTREAM_NoError;
+}
+
+/* The following abuses the C preprocessor in order to copy-paste common code with slight alterations,
+ * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */
+
+#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_LE
+#define TEMPLATE_BUFFER_TYPE const void*
+#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)
+#include "Template/Template_Endpoint_RW.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE
+#define TEMPLATE_BUFFER_TYPE const void*
+#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)
+#include "Template/Template_Endpoint_RW.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE
+#define TEMPLATE_BUFFER_TYPE void*
+#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()
+#include "Template/Template_Endpoint_RW.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE
+#define TEMPLATE_BUFFER_TYPE void*
+#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()
+#include "Template/Template_Endpoint_RW.c"
+
+#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE)
+ #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE
+ #define TEMPLATE_BUFFER_TYPE const void*
+ #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
+ #define TEMPLATE_BUFFER_OFFSET(Length) 0
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))
+ #include "Template/Template_Endpoint_RW.c"
+
+ #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE
+ #define TEMPLATE_BUFFER_TYPE const void*
+ #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
+ #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))
+ #include "Template/Template_Endpoint_RW.c"
+#endif
+
+#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE)
+ #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE
+ #define TEMPLATE_BUFFER_TYPE const void*
+ #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
+ #define TEMPLATE_BUFFER_OFFSET(Length) 0
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))
+ #include "Template/Template_Endpoint_RW.c"
+
+ #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE
+ #define TEMPLATE_BUFFER_TYPE const void*
+ #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
+ #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))
+ #include "Template/Template_Endpoint_RW.c"
+
+ #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE
+ #define TEMPLATE_BUFFER_TYPE void*
+ #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
+ #define TEMPLATE_BUFFER_OFFSET(Length) 0
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())
+ #include "Template/Template_Endpoint_RW.c"
+
+ #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE
+ #define TEMPLATE_BUFFER_TYPE void*
+ #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
+ #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())
+ #include "Template/Template_Endpoint_RW.c"
#endif
-#endif\r
+#endif
+
+#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)
+#include "Template/Template_Endpoint_Control_W.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)
+#include "Template/Template_Endpoint_Control_W.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()
+#include "Template/Template_Endpoint_Control_R.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()
+#include "Template/Template_Endpoint_Control_R.c"
+
+#endif
+
+#endif
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2012.\r
- \r
- dean [at] fourwalledcubicle [dot] com\r
- www.lufa-lib.org\r
-*/\r
-\r
-/*\r
- Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, distribute, and sell this \r
- software and its documentation for any purpose is hereby granted\r
- without fee, provided that the above copyright notice appear in \r
- all copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting \r
- documentation, and that the name of the author not be used in \r
- advertising or publicity pertaining to distribution of the \r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-/** \file\r
- * \brief Endpoint data stream transmission and reception management for the AVR32 UC3 microcontrollers.\r
- * \copydetails Group_EndpointStreamRW_UC3\r
- *\r
- * \note This file should not be included directly. It is automatically included as needed by the USB driver\r
- * dispatch header located in LUFA/Drivers/USB/USB.h.\r
- */\r
-\r
-/** \ingroup Group_EndpointStreamRW\r
- * \defgroup Group_EndpointStreamRW_UC3 Read/Write of Multi-Byte Streams (UC3)\r
- * \brief Endpoint data stream transmission and reception management for the Atmel AVR32 UC3 architecture.\r
- *\r
- * Functions, macros, variables, enums and types related to data reading and writing of data streams from\r
- * and to endpoints.\r
- *\r
- * @{\r
- */ \r
-\r
-#ifndef __ENDPOINT_STREAM_UC3_H__\r
-#define __ENDPOINT_STREAM_UC3_H__\r
-\r
- /* Includes: */\r
- #include "../../../../Common/Common.h"\r
- #include "../USBMode.h"\r
- #include "../USBTask.h"\r
- \r
- /* Enable C linkage for C++ Compilers: */\r
- #if defined(__cplusplus)\r
- extern "C" {\r
- #endif\r
-\r
- /* Preprocessor Checks: */\r
- #if !defined(__INCLUDE_FROM_USB_DRIVER)\r
- #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.\r
- #endif\r
-\r
- /* Public Interface - May be used in end-application: */\r
- /* Function Prototypes: */\r
- /** \name Stream functions for null data */\r
- //@{\r
-\r
- /** Reads and discards the given number of bytes from the currently selected endpoint's bank,\r
- * discarding fully read packets from the host as needed. The last packet is not automatically\r
- * discarded once the remaining bytes has been read; the user is responsible for manually\r
- * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro.\r
- *\r
- * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,\r
- * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid\r
- * storage location, the transfer will instead be performed as a series of chunks. Each time\r
- * the endpoint bank becomes empty while there is still data to process (and after the current\r
- * packet has been acknowledged) the BytesProcessed location will be updated with the total number\r
- * of bytes processed in the stream, and the function will exit with an error code of\r
- * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed\r
- * in the user code - to continue the transfer, call the function again with identical parameters\r
- * and it will resume until the BytesProcessed value reaches the total transfer length.\r
- *\r
- * <b>Single Stream Transfer Example:</b>\r
- * \code\r
- * uint8_t ErrorCode;\r
- * \r
- * if ((ErrorCode = Endpoint_Discard_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * <b>Partial Stream Transfers Example:</b>\r
- * \code\r
- * uint8_t ErrorCode;\r
- * uint16_t BytesProcessed;\r
- * \r
- * BytesProcessed = 0;\r
- * while ((ErrorCode = Endpoint_Discard_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)\r
- * {\r
- * // Stream not yet complete - do other actions here, abort if required\r
- * }\r
- * \r
- * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * \note This routine should not be used on CONTROL type endpoints.\r
- *\r
- * \param[in] Length Number of bytes to discard via the currently selected endpoint.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be read at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Discard_Stream(uint16_t Length,\r
- uint16_t* const BytesProcessed);\r
-\r
- /** Writes a given number of zeroed bytes to the currently selected endpoint's bank, sending\r
- * full packets to the host as needed. The last packet is not automatically sent once the \r
- * remaining bytes have been written; the user is responsible for manually sending the last\r
- * packet to the host via the \ref Endpoint_ClearIN() macro.\r
- *\r
- * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,\r
- * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid\r
- * storage location, the transfer will instead be performed as a series of chunks. Each time\r
- * the endpoint bank becomes full while there is still data to process (and after the current\r
- * packet transmission has been initiated) the BytesProcessed location will be updated with the\r
- * total number of bytes processed in the stream, and the function will exit with an error code of\r
- * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed\r
- * in the user code - to continue the transfer, call the function again with identical parameters\r
- * and it will resume until the BytesProcessed value reaches the total transfer length.\r
- *\r
- * <b>Single Stream Transfer Example:</b>\r
- * \code\r
- * uint8_t ErrorCode;\r
- * \r
- * if ((ErrorCode = Endpoint_Null_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * <b>Partial Stream Transfers Example:</b>\r
- * \code\r
- * uint8_t ErrorCode;\r
- * uint16_t BytesProcessed;\r
- * \r
- * BytesProcessed = 0;\r
- * while ((ErrorCode = Endpoint_Null_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)\r
- * {\r
- * // Stream not yet complete - do other actions here, abort if required\r
- * }\r
- * \r
- * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * \note This routine should not be used on CONTROL type endpoints.\r
- *\r
- * \param[in] Length Number of zero bytes to send via the currently selected endpoint.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be read at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Null_Stream(uint16_t Length,\r
- uint16_t* const BytesProcessed);\r
-\r
- //@}\r
-\r
- /** \name Stream functions for RAM source/destination data */\r
- //@{\r
- \r
- /** Writes the given number of bytes to the endpoint from the given buffer in little endian,\r
- * sending full packets to the host as needed. The last packet filled is not automatically sent;\r
- * the user is responsible for manually sending the last written packet to the host via the\r
- * \ref Endpoint_ClearIN() macro.\r
- *\r
- * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,\r
- * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid\r
- * storage location, the transfer will instead be performed as a series of chunks. Each time\r
- * the endpoint bank becomes full while there is still data to process (and after the current\r
- * packet transmission has been initiated) the BytesProcessed location will be updated with the\r
- * total number of bytes processed in the stream, and the function will exit with an error code of\r
- * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed\r
- * in the user code - to continue the transfer, call the function again with identical parameters\r
- * and it will resume until the BytesProcessed value reaches the total transfer length.\r
- *\r
- * <b>Single Stream Transfer Example:</b>\r
- * \code\r
- * uint8_t DataStream[512];\r
- * uint8_t ErrorCode;\r
- * \r
- * if ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream),\r
- * NULL)) != ENDPOINT_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * <b>Partial Stream Transfers Example:</b>\r
- * \code\r
- * uint8_t DataStream[512];\r
- * uint8_t ErrorCode;\r
- * uint16_t BytesProcessed;\r
- * \r
- * BytesProcessed = 0;\r
- * while ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream),\r
- * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)\r
- * {\r
- * // Stream not yet complete - do other actions here, abort if required\r
- * }\r
- * \r
- * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * \note This routine should not be used on CONTROL type endpoints.\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be written at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_Stream_LE(const void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Writes the given number of bytes to the endpoint from the given buffer in big endian,\r
- * sending full packets to the host as needed. The last packet filled is not automatically sent;\r
- * the user is responsible for manually sending the last written packet to the host via the\r
- * \ref Endpoint_ClearIN() macro.\r
- *\r
- * \note This routine should not be used on CONTROL type endpoints.\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be written at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_Stream_BE(const void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
- \r
- /** Reads the given number of bytes from the endpoint from the given buffer in little endian,\r
- * discarding fully read packets from the host as needed. The last packet is not automatically\r
- * discarded once the remaining bytes has been read; the user is responsible for manually\r
- * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro.\r
- *\r
- * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,\r
- * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid\r
- * storage location, the transfer will instead be performed as a series of chunks. Each time\r
- * the endpoint bank becomes empty while there is still data to process (and after the current\r
- * packet has been acknowledged) the BytesProcessed location will be updated with the total number\r
- * of bytes processed in the stream, and the function will exit with an error code of\r
- * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed\r
- * in the user code - to continue the transfer, call the function again with identical parameters\r
- * and it will resume until the BytesProcessed value reaches the total transfer length.\r
- *\r
- * <b>Single Stream Transfer Example:</b>\r
- * \code\r
- * uint8_t DataStream[512];\r
- * uint8_t ErrorCode;\r
- * \r
- * if ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream),\r
- * NULL)) != ENDPOINT_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * <b>Partial Stream Transfers Example:</b>\r
- * \code\r
- * uint8_t DataStream[512];\r
- * uint8_t ErrorCode;\r
- * uint16_t BytesProcessed;\r
- * \r
- * BytesProcessed = 0;\r
- * while ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream),\r
- * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)\r
- * {\r
- * // Stream not yet complete - do other actions here, abort if required\r
- * }\r
- * \r
- * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * \note This routine should not be used on CONTROL type endpoints.\r
- *\r
- * \param[out] Buffer Pointer to the destination data buffer to write to.\r
- * \param[in] Length Number of bytes to send via the currently selected endpoint.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be read at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Read_Stream_LE(void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Reads the given number of bytes from the endpoint from the given buffer in big endian,\r
- * discarding fully read packets from the host as needed. The last packet is not automatically\r
- * discarded once the remaining bytes has been read; the user is responsible for manually\r
- * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro.\r
- *\r
- * \note This routine should not be used on CONTROL type endpoints.\r
- *\r
- * \param[out] Buffer Pointer to the destination data buffer to write to.\r
- * \param[in] Length Number of bytes to send via the currently selected endpoint.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be read at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Read_Stream_BE(void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in little endian,\r
- * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared\r
- * in both failure and success states; the user is responsible for manually clearing the setup OUT to\r
- * finalize the transfer via the \ref Endpoint_ClearOUT() macro.\r
- *\r
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
- * to clear the status stage when using this routine in a control transaction.\r
- * \n\n\r
- *\r
- * \note This routine should only be used on CONTROL type endpoints.\r
- *\r
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained\r
- * together; i.e. the entire stream data must be read or written at the one time.\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- *\r
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_Control_Stream_LE(const void* const Buffer,\r
- uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in big endian,\r
- * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared\r
- * in both failure and success states; the user is responsible for manually clearing the setup OUT to\r
- * finalize the transfer via the \ref Endpoint_ClearOUT() macro.\r
- *\r
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
- * to clear the status stage when using this routine in a control transaction.\r
- * \n\n\r
- *\r
- * \note This routine should only be used on CONTROL type endpoints.\r
- *\r
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained\r
- * together; i.e. the entire stream data must be read or written at the one time.\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- *\r
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_Control_Stream_BE(const void* const Buffer,\r
- uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in little endian,\r
- * discarding fully read packets from the host as needed. The device IN acknowledgement is not\r
- * automatically sent after success or failure states; the user is responsible for manually sending the\r
- * setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.\r
- *\r
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
- * to clear the status stage when using this routine in a control transaction.\r
- * \n\n\r
- *\r
- * \note This routine should only be used on CONTROL type endpoints.\r
- *\r
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained\r
- * together; i.e. the entire stream data must be read or written at the one time.\r
- *\r
- * \param[out] Buffer Pointer to the destination data buffer to write to.\r
- * \param[in] Length Number of bytes to send via the currently selected endpoint.\r
- *\r
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Read_Control_Stream_LE(void* const Buffer,\r
- uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in big endian,\r
- * discarding fully read packets from the host as needed. The device IN acknowledgement is not\r
- * automatically sent after success or failure states; the user is responsible for manually sending the\r
- * setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.\r
- *\r
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
- * to clear the status stage when using this routine in a control transaction.\r
- * \n\n\r
- *\r
- * \note This routine should only be used on CONTROL type endpoints.\r
- *\r
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained\r
- * together; i.e. the entire stream data must be read or written at the one time.\r
- *\r
- * \param[out] Buffer Pointer to the destination data buffer to write to.\r
- * \param[in] Length Number of bytes to send via the currently selected endpoint.\r
- *\r
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Read_Control_Stream_BE(void* const Buffer,\r
- uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);\r
- //@}\r
-\r
- /* Disable C linkage for C++ Compilers: */\r
- #if defined(__cplusplus)\r
- }\r
- #endif\r
- \r
-#endif\r
-\r
-/** @} */\r
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 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
+ * \brief Endpoint data stream transmission and reception management for the AVR32 UC3 microcontrollers.
+ * \copydetails Group_EndpointStreamRW_UC3
+ *
+ * \note This file should not be included directly. It is automatically included as needed by the USB driver
+ * dispatch header located in LUFA/Drivers/USB/USB.h.
+ */
+
+/** \ingroup Group_EndpointStreamRW
+ * \defgroup Group_EndpointStreamRW_UC3 Read/Write of Multi-Byte Streams (UC3)
+ * \brief Endpoint data stream transmission and reception management for the Atmel AVR32 UC3 architecture.
+ *
+ * Functions, macros, variables, enums and types related to data reading and writing of data streams from
+ * and to endpoints.
+ *
+ * @{
+ */
+
+#ifndef __ENDPOINT_STREAM_UC3_H__
+#define __ENDPOINT_STREAM_UC3_H__
+
+ /* Includes: */
+ #include "../../../../Common/Common.h"
+ #include "../USBMode.h"
+ #include "../USBTask.h"
+
+ /* Enable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ extern "C" {
+ #endif
+
+ /* Preprocessor Checks: */
+ #if !defined(__INCLUDE_FROM_USB_DRIVER)
+ #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
+ #endif
+
+ /* Public Interface - May be used in end-application: */
+ /* Function Prototypes: */
+ /** \name Stream functions for null data */
+ //@{
+
+ /** Reads and discards the given number of bytes from the currently selected endpoint's bank,
+ * discarding fully read packets from the host as needed. The last packet is not automatically
+ * discarded once the remaining bytes has been read; the user is responsible for manually
+ * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro.
+ *
+ * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
+ * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
+ * storage location, the transfer will instead be performed as a series of chunks. Each time
+ * the endpoint bank becomes empty while there is still data to process (and after the current
+ * packet has been acknowledged) the BytesProcessed location will be updated with the total number
+ * of bytes processed in the stream, and the function will exit with an error code of
+ * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
+ * in the user code - to continue the transfer, call the function again with identical parameters
+ * and it will resume until the BytesProcessed value reaches the total transfer length.
+ *
+ * <b>Single Stream Transfer Example:</b>
+ * \code
+ * uint8_t ErrorCode;
+ *
+ * if ((ErrorCode = Endpoint_Discard_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * <b>Partial Stream Transfers Example:</b>
+ * \code
+ * uint8_t ErrorCode;
+ * uint16_t BytesProcessed;
+ *
+ * BytesProcessed = 0;
+ * while ((ErrorCode = Endpoint_Discard_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)
+ * {
+ * // Stream not yet complete - do other actions here, abort if required
+ * }
+ *
+ * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * \note This routine should not be used on CONTROL type endpoints.
+ *
+ * \param[in] Length Number of bytes to discard via the currently selected endpoint.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be read at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Discard_Stream(uint16_t Length,
+ uint16_t* const BytesProcessed);
+
+ /** Writes a given number of zeroed bytes to the currently selected endpoint's bank, sending
+ * full packets to the host as needed. The last packet is not automatically sent once the
+ * remaining bytes have been written; the user is responsible for manually sending the last
+ * packet to the host via the \ref Endpoint_ClearIN() macro.
+ *
+ * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
+ * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
+ * storage location, the transfer will instead be performed as a series of chunks. Each time
+ * the endpoint bank becomes full while there is still data to process (and after the current
+ * packet transmission has been initiated) the BytesProcessed location will be updated with the
+ * total number of bytes processed in the stream, and the function will exit with an error code of
+ * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
+ * in the user code - to continue the transfer, call the function again with identical parameters
+ * and it will resume until the BytesProcessed value reaches the total transfer length.
+ *
+ * <b>Single Stream Transfer Example:</b>
+ * \code
+ * uint8_t ErrorCode;
+ *
+ * if ((ErrorCode = Endpoint_Null_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * <b>Partial Stream Transfers Example:</b>
+ * \code
+ * uint8_t ErrorCode;
+ * uint16_t BytesProcessed;
+ *
+ * BytesProcessed = 0;
+ * while ((ErrorCode = Endpoint_Null_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)
+ * {
+ * // Stream not yet complete - do other actions here, abort if required
+ * }
+ *
+ * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * \note This routine should not be used on CONTROL type endpoints.
+ *
+ * \param[in] Length Number of zero bytes to send via the currently selected endpoint.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be read at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Null_Stream(uint16_t Length,
+ uint16_t* const BytesProcessed);
+
+ //@}
+
+ /** \name Stream functions for RAM source/destination data */
+ //@{
+
+ /** Writes the given number of bytes to the endpoint from the given buffer in little endian,
+ * sending full packets to the host as needed. The last packet filled is not automatically sent;
+ * the user is responsible for manually sending the last written packet to the host via the
+ * \ref Endpoint_ClearIN() macro.
+ *
+ * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
+ * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
+ * storage location, the transfer will instead be performed as a series of chunks. Each time
+ * the endpoint bank becomes full while there is still data to process (and after the current
+ * packet transmission has been initiated) the BytesProcessed location will be updated with the
+ * total number of bytes processed in the stream, and the function will exit with an error code of
+ * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
+ * in the user code - to continue the transfer, call the function again with identical parameters
+ * and it will resume until the BytesProcessed value reaches the total transfer length.
+ *
+ * <b>Single Stream Transfer Example:</b>
+ * \code
+ * uint8_t DataStream[512];
+ * uint8_t ErrorCode;
+ *
+ * if ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream),
+ * NULL)) != ENDPOINT_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * <b>Partial Stream Transfers Example:</b>
+ * \code
+ * uint8_t DataStream[512];
+ * uint8_t ErrorCode;
+ * uint16_t BytesProcessed;
+ *
+ * BytesProcessed = 0;
+ * while ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream),
+ * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)
+ * {
+ * // Stream not yet complete - do other actions here, abort if required
+ * }
+ *
+ * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * \note This routine should not be used on CONTROL type endpoints.
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be written at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Stream_LE(const void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Writes the given number of bytes to the endpoint from the given buffer in big endian,
+ * sending full packets to the host as needed. The last packet filled is not automatically sent;
+ * the user is responsible for manually sending the last written packet to the host via the
+ * \ref Endpoint_ClearIN() macro.
+ *
+ * \note This routine should not be used on CONTROL type endpoints.
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be written at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Stream_BE(const void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Reads the given number of bytes from the endpoint from the given buffer in little endian,
+ * discarding fully read packets from the host as needed. The last packet is not automatically
+ * discarded once the remaining bytes has been read; the user is responsible for manually
+ * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro.
+ *
+ * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
+ * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
+ * storage location, the transfer will instead be performed as a series of chunks. Each time
+ * the endpoint bank becomes empty while there is still data to process (and after the current
+ * packet has been acknowledged) the BytesProcessed location will be updated with the total number
+ * of bytes processed in the stream, and the function will exit with an error code of
+ * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
+ * in the user code - to continue the transfer, call the function again with identical parameters
+ * and it will resume until the BytesProcessed value reaches the total transfer length.
+ *
+ * <b>Single Stream Transfer Example:</b>
+ * \code
+ * uint8_t DataStream[512];
+ * uint8_t ErrorCode;
+ *
+ * if ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream),
+ * NULL)) != ENDPOINT_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * <b>Partial Stream Transfers Example:</b>
+ * \code
+ * uint8_t DataStream[512];
+ * uint8_t ErrorCode;
+ * uint16_t BytesProcessed;
+ *
+ * BytesProcessed = 0;
+ * while ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream),
+ * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)
+ * {
+ * // Stream not yet complete - do other actions here, abort if required
+ * }
+ *
+ * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * \note This routine should not be used on CONTROL type endpoints.
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be read at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_Stream_LE(void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Reads the given number of bytes from the endpoint from the given buffer in big endian,
+ * discarding fully read packets from the host as needed. The last packet is not automatically
+ * discarded once the remaining bytes has been read; the user is responsible for manually
+ * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro.
+ *
+ * \note This routine should not be used on CONTROL type endpoints.
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be read at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_Stream_BE(void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in little endian,
+ * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared
+ * in both failure and success states; the user is responsible for manually clearing the setup OUT to
+ * finalize the transfer via the \ref Endpoint_ClearOUT() macro.
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Control_Stream_LE(const void* const Buffer,
+ uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in big endian,
+ * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared
+ * in both failure and success states; the user is responsible for manually clearing the setup OUT to
+ * finalize the transfer via the \ref Endpoint_ClearOUT() macro.
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Control_Stream_BE(const void* const Buffer,
+ uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in little endian,
+ * discarding fully read packets from the host as needed. The device IN acknowledgement is not
+ * automatically sent after success or failure states; the user is responsible for manually sending the
+ * setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_Control_Stream_LE(void* const Buffer,
+ uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in big endian,
+ * discarding fully read packets from the host as needed. The device IN acknowledgement is not
+ * automatically sent after success or failure states; the user is responsible for manually sending the
+ * setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_Control_Stream_BE(void* const Buffer,
+ uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+ //@}
+
+ /* Disable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ }
+ #endif
+
+#endif
+
+/** @} */
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2012.\r
- \r
- dean [at] fourwalledcubicle [dot] com\r
- www.lufa-lib.org\r
-*/\r
-\r
-/*\r
- Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, distribute, and sell this \r
- software and its documentation for any purpose is hereby granted\r
- without fee, provided that the above copyright notice appear in \r
- all copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting \r
- documentation, and that the name of the author not be used in \r
- advertising or publicity pertaining to distribution of the \r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-#include "../../../../Common/Common.h"\r
-#if (ARCH == ARCH_UC3)\r
-\r
-#define __INCLUDE_FROM_USB_DRIVER\r
-#include "../USBMode.h"\r
-\r
-#if defined(USB_CAN_BE_HOST)\r
-\r
-#include "PipeStream_UC3.h"\r
-\r
-uint8_t Pipe_Discard_Stream(uint16_t Length,\r
- uint16_t* const BytesProcessed)\r
-{\r
- uint8_t ErrorCode;\r
- uint16_t BytesInTransfer = 0;\r
- \r
- Pipe_SetPipeToken(PIPE_TOKEN_IN);\r
-\r
- if ((ErrorCode = Pipe_WaitUntilReady()))\r
- return ErrorCode;\r
-\r
- if (BytesProcessed != NULL)\r
- Length -= *BytesProcessed;\r
-\r
- while (Length)\r
- {\r
- if (!(Pipe_IsReadWriteAllowed()))\r
- {\r
- Pipe_ClearIN();\r
- \r
- if (BytesProcessed != NULL)\r
- {\r
- *BytesProcessed += BytesInTransfer;\r
- return PIPE_RWSTREAM_IncompleteTransfer;\r
- }\r
-\r
- if ((ErrorCode = Pipe_WaitUntilReady()))\r
- return ErrorCode;\r
- }\r
- else\r
- {\r
- Pipe_Discard_8();\r
- \r
- Length--;\r
- BytesInTransfer++;\r
- }\r
- }\r
-\r
- return PIPE_RWSTREAM_NoError;\r
-}\r
-\r
-uint8_t Pipe_Null_Stream(uint16_t Length,\r
- uint16_t* const BytesProcessed)\r
-{\r
- uint8_t ErrorCode;\r
- uint16_t BytesInTransfer = 0;\r
- \r
- Pipe_SetPipeToken(PIPE_TOKEN_OUT);\r
-\r
- if ((ErrorCode = Pipe_WaitUntilReady()))\r
- return ErrorCode;\r
-\r
- if (BytesProcessed != NULL)\r
- Length -= *BytesProcessed;\r
-\r
- while (Length)\r
- {\r
- if (!(Pipe_IsReadWriteAllowed()))\r
- {\r
- Pipe_ClearOUT();\r
- \r
- if (BytesProcessed != NULL)\r
- {\r
- *BytesProcessed += BytesInTransfer;\r
- return PIPE_RWSTREAM_IncompleteTransfer;\r
- }\r
- \r
- USB_USBTask();\r
-\r
- if ((ErrorCode = Pipe_WaitUntilReady()))\r
- return ErrorCode;\r
- }\r
- else\r
- {\r
- Pipe_Write_8(0);\r
- \r
- Length--;\r
- BytesInTransfer++;\r
- }\r
- }\r
-\r
- return PIPE_RWSTREAM_NoError;\r
-}\r
-\r
-/* The following abuses the C preprocessor in order to copy-paste common code with slight alterations,\r
- * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */\r
-\r
-#define TEMPLATE_FUNC_NAME Pipe_Write_Stream_LE\r
-#define TEMPLATE_BUFFER_TYPE const void*\r
-#define TEMPLATE_TOKEN PIPE_TOKEN_OUT\r
-#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()\r
-#define TEMPLATE_BUFFER_OFFSET(Length) 0\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream += Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_8(*BufferPtr)\r
-#include "Template/Template_Pipe_RW.c"\r
-\r
-#define TEMPLATE_FUNC_NAME Pipe_Write_Stream_BE\r
-#define TEMPLATE_BUFFER_TYPE const void*\r
-#define TEMPLATE_TOKEN PIPE_TOKEN_OUT\r
-#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()\r
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream -= Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_8(*BufferPtr)\r
-#include "Template/Template_Pipe_RW.c"\r
-\r
-#define TEMPLATE_FUNC_NAME Pipe_Read_Stream_LE\r
-#define TEMPLATE_BUFFER_TYPE void*\r
-#define TEMPLATE_TOKEN PIPE_TOKEN_IN\r
-#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN()\r
-#define TEMPLATE_BUFFER_OFFSET(Length) 0\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream += Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Pipe_Read_8()\r
-#include "Template/Template_Pipe_RW.c"\r
-\r
-#define TEMPLATE_FUNC_NAME Pipe_Read_Stream_BE\r
-#define TEMPLATE_BUFFER_TYPE void*\r
-#define TEMPLATE_TOKEN PIPE_TOKEN_IN\r
-#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN()\r
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream -= Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Pipe_Read_8()\r
-#include "Template/Template_Pipe_RW.c"\r
-\r
-#endif\r
-
-#endif\r
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 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.
+*/
+
+#include "../../../../Common/Common.h"
+#if (ARCH == ARCH_UC3)
+
+#define __INCLUDE_FROM_USB_DRIVER
+#include "../USBMode.h"
+
+#if defined(USB_CAN_BE_HOST)
+
+#include "PipeStream_UC3.h"
+
+uint8_t Pipe_Discard_Stream(uint16_t Length,
+ uint16_t* const BytesProcessed)
+{
+ uint8_t ErrorCode;
+ uint16_t BytesInTransfer = 0;
+
+ Pipe_SetPipeToken(PIPE_TOKEN_IN);
+
+ if ((ErrorCode = Pipe_WaitUntilReady()))
+ return ErrorCode;
+
+ if (BytesProcessed != NULL)
+ Length -= *BytesProcessed;
+
+ while (Length)
+ {
+ if (!(Pipe_IsReadWriteAllowed()))
+ {
+ Pipe_ClearIN();
+
+ if (BytesProcessed != NULL)
+ {
+ *BytesProcessed += BytesInTransfer;
+ return PIPE_RWSTREAM_IncompleteTransfer;
+ }
+
+ if ((ErrorCode = Pipe_WaitUntilReady()))
+ return ErrorCode;
+ }
+ else
+ {
+ Pipe_Discard_8();
+
+ Length--;
+ BytesInTransfer++;
+ }
+ }
+
+ return PIPE_RWSTREAM_NoError;
+}
+
+uint8_t Pipe_Null_Stream(uint16_t Length,
+ uint16_t* const BytesProcessed)
+{
+ uint8_t ErrorCode;
+ uint16_t BytesInTransfer = 0;
+
+ Pipe_SetPipeToken(PIPE_TOKEN_OUT);
+
+ if ((ErrorCode = Pipe_WaitUntilReady()))
+ return ErrorCode;
+
+ if (BytesProcessed != NULL)
+ Length -= *BytesProcessed;
+
+ while (Length)
+ {
+ if (!(Pipe_IsReadWriteAllowed()))
+ {
+ Pipe_ClearOUT();
+
+ if (BytesProcessed != NULL)
+ {
+ *BytesProcessed += BytesInTransfer;
+ return PIPE_RWSTREAM_IncompleteTransfer;
+ }
+
+ USB_USBTask();
+
+ if ((ErrorCode = Pipe_WaitUntilReady()))
+ return ErrorCode;
+ }
+ else
+ {
+ Pipe_Write_8(0);
+
+ Length--;
+ BytesInTransfer++;
+ }
+ }
+
+ return PIPE_RWSTREAM_NoError;
+}
+
+/* The following abuses the C preprocessor in order to copy-paste common code with slight alterations,
+ * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */
+
+#define TEMPLATE_FUNC_NAME Pipe_Write_Stream_LE
+#define TEMPLATE_BUFFER_TYPE const void*
+#define TEMPLATE_TOKEN PIPE_TOKEN_OUT
+#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream += Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_8(*BufferPtr)
+#include "Template/Template_Pipe_RW.c"
+
+#define TEMPLATE_FUNC_NAME Pipe_Write_Stream_BE
+#define TEMPLATE_BUFFER_TYPE const void*
+#define TEMPLATE_TOKEN PIPE_TOKEN_OUT
+#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream -= Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_8(*BufferPtr)
+#include "Template/Template_Pipe_RW.c"
+
+#define TEMPLATE_FUNC_NAME Pipe_Read_Stream_LE
+#define TEMPLATE_BUFFER_TYPE void*
+#define TEMPLATE_TOKEN PIPE_TOKEN_IN
+#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN()
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream += Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Pipe_Read_8()
+#include "Template/Template_Pipe_RW.c"
+
+#define TEMPLATE_FUNC_NAME Pipe_Read_Stream_BE
+#define TEMPLATE_BUFFER_TYPE void*
+#define TEMPLATE_TOKEN PIPE_TOKEN_IN
+#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN()
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream -= Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Pipe_Read_8()
+#include "Template/Template_Pipe_RW.c"
+
+#endif
+
+#endif
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2012.\r
- \r
- dean [at] fourwalledcubicle [dot] com\r
- www.lufa-lib.org\r
-*/\r
-\r
-/*\r
- Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, distribute, and sell this \r
- software and its documentation for any purpose is hereby granted\r
- without fee, provided that the above copyright notice appear in \r
- all copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting \r
- documentation, and that the name of the author not be used in \r
- advertising or publicity pertaining to distribution of the \r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
- \r
-/** \file\r
- * \brief Pipe data stream transmission and reception management for the AVR32 UC3 microcontrollers.\r
- * \copydetails Group_PipeStreamRW_UC3\r
- *\r
- * \note This file should not be included directly. It is automatically included as needed by the USB driver\r
- * dispatch header located in LUFA/Drivers/USB/USB.h.\r
- */\r
-\r
-/** \ingroup Group_PipeStreamRW\r
- * \defgroup Group_PipeStreamRW_UC3 Read/Write of Multi-Byte Streams (UC3)\r
- * \brief Pipe data stream transmission and reception management for the Atmel AVR32 UC3 architecture.\r
- *\r
- * Functions, macros, variables, enums and types related to data reading and writing of data streams from\r
- * and to pipes.\r
- *\r
- * @{\r
- */\r
-\r
-#ifndef __PIPE_STREAM_UC3_H__\r
-#define __PIPE_STREAM_UC3_H__\r
-\r
- /* Includes: */\r
- #include "../../../../Common/Common.h"\r
- #include "../USBMode.h"\r
- #include "../USBTask.h"\r
- \r
- /* Enable C linkage for C++ Compilers: */\r
- #if defined(__cplusplus)\r
- extern "C" {\r
- #endif\r
-\r
- /* Preprocessor Checks: */\r
- #if !defined(__INCLUDE_FROM_USB_DRIVER)\r
- #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.\r
- #endif\r
- \r
- /* Public Interface - May be used in end-application: */\r
- /* Function Prototypes: */\r
- /** \name Stream functions for null data */\r
- //@{\r
-\r
- /** Reads and discards the given number of bytes from the pipe, discarding fully read packets from the host\r
- * as needed. The last packet is not automatically discarded once the remaining bytes has been read; the\r
- * user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearIN() macro.\r
- *\r
- * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or\r
- * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer\r
- * will instead be performed as a series of chunks. Each time the pipe bank becomes empty while there is still data\r
- * to process (and after the current packet has been acknowledged) the BytesProcessed location will be updated with\r
- * the total number of bytes processed in the stream, and the function will exit with an error code of\r
- * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to\r
- * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed\r
- * value reaches the total transfer length.\r
- *\r
- * <b>Single Stream Transfer Example:</b>\r
- * \code\r
- * uint8_t ErrorCode;\r
- * \r
- * if ((ErrorCode = Pipe_Discard_Stream(512, NULL)) != PIPE_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- * \r
- * <b>Partial Stream Transfers Example:</b>\r
- * \code\r
- * uint8_t ErrorCode;\r
- * uint16_t BytesProcessed;\r
- * \r
- * BytesProcessed = 0;\r
- * while ((ErrorCode = Pipe_Discard_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)\r
- * {\r
- * // Stream not yet complete - do other actions here, abort if required\r
- * }\r
- * \r
- * if (ErrorCode != PIPE_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without\r
- * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().\r
- *\r
- * \param[in] Length Number of bytes to discard via the currently selected pipe.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should\r
- * updated, \c NULL if the entire stream should be processed at once.\r
- *\r
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Pipe_Discard_Stream(uint16_t Length,\r
- uint16_t* const BytesProcessed);\r
-\r
- /** Writes a given number of zeroed bytes to the pipe, sending full pipe packets from the host to the device\r
- * as needed. The last packet is not automatically sent once the remaining bytes has been written; the\r
- * user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearOUT() macro.\r
- *\r
- * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or\r
- * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer\r
- * will instead be performed as a series of chunks. Each time the pipe bank becomes full while there is still data\r
- * to process (and after the current packet transmission has been initiated) the BytesProcessed location will be\r
- * updated with the total number of bytes processed in the stream, and the function will exit with an error code of\r
- * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to\r
- * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed\r
- * value reaches the total transfer length.\r
- *\r
- * <b>Single Stream Transfer Example:</b>\r
- * \code\r
- * uint8_t ErrorCode;\r
- * \r
- * if ((ErrorCode = Pipe_Null_Stream(512, NULL)) != PIPE_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * <b>Partial Stream Transfers Example:</b>\r
- * \code\r
- * uint8_t ErrorCode;\r
- * uint16_t BytesProcessed;\r
- * \r
- * BytesProcessed = 0;\r
- * while ((ErrorCode = Pipe_Null_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)\r
- * {\r
- * // Stream not yet complete - do other actions here, abort if required\r
- * }\r
- * \r
- * if (ErrorCode != PIPE_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without\r
- * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().\r
- *\r
- * \param[in] Length Number of zero bytes to write via the currently selected pipe.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should\r
- * updated, \c NULL if the entire stream should be processed at once.\r
- *\r
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Pipe_Null_Stream(uint16_t Length,\r
- uint16_t* const BytesProcessed);\r
-\r
- //@}\r
-\r
- /** \name Stream functions for RAM source/destination data */\r
- //@{\r
- \r
- /** Writes the given number of bytes to the pipe from the given buffer in little endian,\r
- * sending full packets to the device as needed. The last packet filled is not automatically sent;\r
- * the user is responsible for manually sending the last written packet to the host via the\r
- * \ref Pipe_ClearOUT() macro. Between each USB packet, the given stream callback function is\r
- * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.\r
- *\r
- * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,\r
- * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid\r
- * storage location, the transfer will instead be performed as a series of chunks. Each time\r
- * the pipe bank becomes full while there is still data to process (and after the current\r
- * packet transmission has been initiated) the BytesProcessed location will be updated with the\r
- * total number of bytes processed in the stream, and the function will exit with an error code of\r
- * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed\r
- * in the user code - to continue the transfer, call the function again with identical parameters\r
- * and it will resume until the BytesProcessed value reaches the total transfer length.\r
- *\r
- * <b>Single Stream Transfer Example:</b>\r
- * \code\r
- * uint8_t DataStream[512];\r
- * uint8_t ErrorCode;\r
- * \r
- * if ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream),\r
- * NULL)) != PIPE_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * <b>Partial Stream Transfers Example:</b>\r
- * \code\r
- * uint8_t DataStream[512];\r
- * uint8_t ErrorCode;\r
- * uint16_t BytesProcessed;\r
- * \r
- * BytesProcessed = 0;\r
- * while ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream),\r
- * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)\r
- * {\r
- * // Stream not yet complete - do other actions here, abort if required\r
- * }\r
- * \r
- * if (ErrorCode != PIPE_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without\r
- * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should\r
- * updated, \c NULL if the entire stream should be written at once.\r
- *\r
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Pipe_Write_Stream_LE(const void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Writes the given number of bytes to the pipe from the given buffer in big endian,\r
- * sending full packets to the device as needed. The last packet filled is not automatically sent;\r
- * the user is responsible for manually sending the last written packet to the host via the\r
- * \ref Pipe_ClearOUT() macro. Between each USB packet, the given stream callback function is\r
- * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.\r
- *\r
- * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without\r
- * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should\r
- * updated, \c NULL if the entire stream should be written at once.\r
- *\r
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Pipe_Write_Stream_BE(const void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Reads the given number of bytes from the pipe into the given buffer in little endian,\r
- * sending full packets to the device as needed. The last packet filled is not automatically sent;\r
- * the user is responsible for manually sending the last written packet to the host via the\r
- * \ref Pipe_ClearIN() macro. Between each USB packet, the given stream callback function is\r
- * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.\r
- *\r
- * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,\r
- * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid\r
- * storage location, the transfer will instead be performed as a series of chunks. Each time\r
- * the pipe bank becomes empty while there is still data to process (and after the current\r
- * packet has been acknowledged) the BytesProcessed location will be updated with the total number\r
- * of bytes processed in the stream, and the function will exit with an error code of\r
- * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed\r
- * in the user code - to continue the transfer, call the function again with identical parameters\r
- * and it will resume until the BytesProcessed value reaches the total transfer length.\r
- *\r
- * <b>Single Stream Transfer Example:</b>\r
- * \code\r
- * uint8_t DataStream[512];\r
- * uint8_t ErrorCode;\r
- * \r
- * if ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream),\r
- * NULL)) != PIPE_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * <b>Partial Stream Transfers Example:</b>\r
- * \code\r
- * uint8_t DataStream[512];\r
- * uint8_t ErrorCode;\r
- * uint16_t BytesProcessed;\r
- * \r
- * BytesProcessed = 0;\r
- * while ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream),\r
- * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)\r
- * {\r
- * // Stream not yet complete - do other actions here, abort if required\r
- * }\r
- * \r
- * if (ErrorCode != PIPE_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without\r
- * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().\r
- *\r
- * \param[out] Buffer Pointer to the source data buffer to write to.\r
- * \param[in] Length Number of bytes to read for the currently selected pipe to read from.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should\r
- * updated, \c NULL if the entire stream should be read at once.\r
- *\r
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Pipe_Read_Stream_LE(void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Reads the given number of bytes from the pipe into the given buffer in big endian,\r
- * sending full packets to the device as needed. The last packet filled is not automatically sent;\r
- * the user is responsible for manually sending the last written packet to the host via the\r
- * \ref Pipe_ClearIN() macro. Between each USB packet, the given stream callback function is\r
- * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.\r
- *\r
- * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without\r
- * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().\r
- *\r
- * \param[out] Buffer Pointer to the source data buffer to write to.\r
- * \param[in] Length Number of bytes to read for the currently selected pipe to read from.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should\r
- * updated, \c NULL if the entire stream should be read at once.\r
- *\r
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Pipe_Read_Stream_BE(void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
- //@}\r
-\r
- /* Disable C linkage for C++ Compilers: */\r
- #if defined(__cplusplus)\r
- }\r
- #endif\r
- \r
-#endif\r
-\r
-/** @} */\r
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 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
+ * \brief Pipe data stream transmission and reception management for the AVR32 UC3 microcontrollers.
+ * \copydetails Group_PipeStreamRW_UC3
+ *
+ * \note This file should not be included directly. It is automatically included as needed by the USB driver
+ * dispatch header located in LUFA/Drivers/USB/USB.h.
+ */
+
+/** \ingroup Group_PipeStreamRW
+ * \defgroup Group_PipeStreamRW_UC3 Read/Write of Multi-Byte Streams (UC3)
+ * \brief Pipe data stream transmission and reception management for the Atmel AVR32 UC3 architecture.
+ *
+ * Functions, macros, variables, enums and types related to data reading and writing of data streams from
+ * and to pipes.
+ *
+ * @{
+ */
+
+#ifndef __PIPE_STREAM_UC3_H__
+#define __PIPE_STREAM_UC3_H__
+
+ /* Includes: */
+ #include "../../../../Common/Common.h"
+ #include "../USBMode.h"
+ #include "../USBTask.h"
+
+ /* Enable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ extern "C" {
+ #endif
+
+ /* Preprocessor Checks: */
+ #if !defined(__INCLUDE_FROM_USB_DRIVER)
+ #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
+ #endif
+
+ /* Public Interface - May be used in end-application: */
+ /* Function Prototypes: */
+ /** \name Stream functions for null data */
+ //@{
+
+ /** Reads and discards the given number of bytes from the pipe, discarding fully read packets from the host
+ * as needed. The last packet is not automatically discarded once the remaining bytes has been read; the
+ * user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearIN() macro.
+ *
+ * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or
+ * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer
+ * will instead be performed as a series of chunks. Each time the pipe bank becomes empty while there is still data
+ * to process (and after the current packet has been acknowledged) the BytesProcessed location will be updated with
+ * the total number of bytes processed in the stream, and the function will exit with an error code of
+ * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to
+ * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed
+ * value reaches the total transfer length.
+ *
+ * <b>Single Stream Transfer Example:</b>
+ * \code
+ * uint8_t ErrorCode;
+ *
+ * if ((ErrorCode = Pipe_Discard_Stream(512, NULL)) != PIPE_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * <b>Partial Stream Transfers Example:</b>
+ * \code
+ * uint8_t ErrorCode;
+ * uint16_t BytesProcessed;
+ *
+ * BytesProcessed = 0;
+ * while ((ErrorCode = Pipe_Discard_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)
+ * {
+ * // Stream not yet complete - do other actions here, abort if required
+ * }
+ *
+ * if (ErrorCode != PIPE_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
+ * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
+ *
+ * \param[in] Length Number of bytes to discard via the currently selected pipe.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
+ * updated, \c NULL if the entire stream should be processed at once.
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Discard_Stream(uint16_t Length,
+ uint16_t* const BytesProcessed);
+
+ /** Writes a given number of zeroed bytes to the pipe, sending full pipe packets from the host to the device
+ * as needed. The last packet is not automatically sent once the remaining bytes has been written; the
+ * user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearOUT() macro.
+ *
+ * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or
+ * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer
+ * will instead be performed as a series of chunks. Each time the pipe bank becomes full while there is still data
+ * to process (and after the current packet transmission has been initiated) the BytesProcessed location will be
+ * updated with the total number of bytes processed in the stream, and the function will exit with an error code of
+ * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to
+ * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed
+ * value reaches the total transfer length.
+ *
+ * <b>Single Stream Transfer Example:</b>
+ * \code
+ * uint8_t ErrorCode;
+ *
+ * if ((ErrorCode = Pipe_Null_Stream(512, NULL)) != PIPE_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * <b>Partial Stream Transfers Example:</b>
+ * \code
+ * uint8_t ErrorCode;
+ * uint16_t BytesProcessed;
+ *
+ * BytesProcessed = 0;
+ * while ((ErrorCode = Pipe_Null_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)
+ * {
+ * // Stream not yet complete - do other actions here, abort if required
+ * }
+ *
+ * if (ErrorCode != PIPE_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
+ * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
+ *
+ * \param[in] Length Number of zero bytes to write via the currently selected pipe.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
+ * updated, \c NULL if the entire stream should be processed at once.
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Null_Stream(uint16_t Length,
+ uint16_t* const BytesProcessed);
+
+ //@}
+
+ /** \name Stream functions for RAM source/destination data */
+ //@{
+
+ /** Writes the given number of bytes to the pipe from the given buffer in little endian,
+ * sending full packets to the device as needed. The last packet filled is not automatically sent;
+ * the user is responsible for manually sending the last written packet to the host via the
+ * \ref Pipe_ClearOUT() macro. Between each USB packet, the given stream callback function is
+ * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
+ *
+ * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
+ * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
+ * storage location, the transfer will instead be performed as a series of chunks. Each time
+ * the pipe bank becomes full while there is still data to process (and after the current
+ * packet transmission has been initiated) the BytesProcessed location will be updated with the
+ * total number of bytes processed in the stream, and the function will exit with an error code of
+ * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
+ * in the user code - to continue the transfer, call the function again with identical parameters
+ * and it will resume until the BytesProcessed value reaches the total transfer length.
+ *
+ * <b>Single Stream Transfer Example:</b>
+ * \code
+ * uint8_t DataStream[512];
+ * uint8_t ErrorCode;
+ *
+ * if ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream),
+ * NULL)) != PIPE_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * <b>Partial Stream Transfers Example:</b>
+ * \code
+ * uint8_t DataStream[512];
+ * uint8_t ErrorCode;
+ * uint16_t BytesProcessed;
+ *
+ * BytesProcessed = 0;
+ * while ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream),
+ * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)
+ * {
+ * // Stream not yet complete - do other actions here, abort if required
+ * }
+ *
+ * if (ErrorCode != PIPE_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
+ * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
+ * updated, \c NULL if the entire stream should be written at once.
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Write_Stream_LE(const void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Writes the given number of bytes to the pipe from the given buffer in big endian,
+ * sending full packets to the device as needed. The last packet filled is not automatically sent;
+ * the user is responsible for manually sending the last written packet to the host via the
+ * \ref Pipe_ClearOUT() macro. Between each USB packet, the given stream callback function is
+ * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
+ *
+ * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
+ * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
+ * updated, \c NULL if the entire stream should be written at once.
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Write_Stream_BE(const void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Reads the given number of bytes from the pipe into the given buffer in little endian,
+ * sending full packets to the device as needed. The last packet filled is not automatically sent;
+ * the user is responsible for manually sending the last written packet to the host via the
+ * \ref Pipe_ClearIN() macro. Between each USB packet, the given stream callback function is
+ * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
+ *
+ * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
+ * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
+ * storage location, the transfer will instead be performed as a series of chunks. Each time
+ * the pipe bank becomes empty while there is still data to process (and after the current
+ * packet has been acknowledged) the BytesProcessed location will be updated with the total number
+ * of bytes processed in the stream, and the function will exit with an error code of
+ * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
+ * in the user code - to continue the transfer, call the function again with identical parameters
+ * and it will resume until the BytesProcessed value reaches the total transfer length.
+ *
+ * <b>Single Stream Transfer Example:</b>
+ * \code
+ * uint8_t DataStream[512];
+ * uint8_t ErrorCode;
+ *
+ * if ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream),
+ * NULL)) != PIPE_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * <b>Partial Stream Transfers Example:</b>
+ * \code
+ * uint8_t DataStream[512];
+ * uint8_t ErrorCode;
+ * uint16_t BytesProcessed;
+ *
+ * BytesProcessed = 0;
+ * while ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream),
+ * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)
+ * {
+ * // Stream not yet complete - do other actions here, abort if required
+ * }
+ *
+ * if (ErrorCode != PIPE_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
+ * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
+ *
+ * \param[out] Buffer Pointer to the source data buffer to write to.
+ * \param[in] Length Number of bytes to read for the currently selected pipe to read from.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
+ * updated, \c NULL if the entire stream should be read at once.
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Read_Stream_LE(void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Reads the given number of bytes from the pipe into the given buffer in big endian,
+ * sending full packets to the device as needed. The last packet filled is not automatically sent;
+ * the user is responsible for manually sending the last written packet to the host via the
+ * \ref Pipe_ClearIN() macro. Between each USB packet, the given stream callback function is
+ * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
+ *
+ * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
+ * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
+ *
+ * \param[out] Buffer Pointer to the source data buffer to write to.
+ * \param[in] Length Number of bytes to read for the currently selected pipe to read from.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
+ * updated, \c NULL if the entire stream should be read at once.
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Read_Stream_BE(void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+ //@}
+
+ /* Disable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ }
+ #endif
+
+#endif
+
+/** @} */
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2012.\r
- \r
- dean [at] fourwalledcubicle [dot] com\r
- www.lufa-lib.org\r
-*/\r
-\r
-/*\r
- Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, distribute, and sell this \r
- software and its documentation for any purpose is hereby granted\r
- without fee, provided that the above copyright notice appear in \r
- all copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting \r
- documentation, and that the name of the author not be used in \r
- advertising or publicity pertaining to distribution of the \r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-#include "../../../../Common/Common.h"\r
-#if (ARCH == ARCH_XMEGA)\r
-\r
-#define __INCLUDE_FROM_USB_DRIVER\r
-#include "../USBMode.h"\r
-\r
-#if defined(USB_CAN_BE_DEVICE)\r
-\r
-#include "EndpointStream_XMEGA.h"\r
-\r
-#if !defined(CONTROL_ONLY_DEVICE)\r
-uint8_t Endpoint_Discard_Stream(uint16_t Length,\r
- uint16_t* const BytesProcessed)\r
-{\r
- uint8_t ErrorCode;\r
- uint16_t BytesInTransfer = 0;\r
- \r
- if ((ErrorCode = Endpoint_WaitUntilReady()))\r
- return ErrorCode;\r
- \r
- if (BytesProcessed != NULL)\r
- Length -= *BytesProcessed;\r
-\r
- while (Length)\r
- {\r
- if (!(Endpoint_IsReadWriteAllowed()))\r
- {\r
- Endpoint_ClearOUT();\r
-\r
- if (BytesProcessed != NULL)\r
- {\r
- *BytesProcessed += BytesInTransfer;\r
- return ENDPOINT_RWSTREAM_IncompleteTransfer;\r
- }\r
-\r
- if ((ErrorCode = Endpoint_WaitUntilReady()))\r
- return ErrorCode;\r
- }\r
- else\r
- {\r
- Endpoint_Discard_8();\r
-\r
- Length--;\r
- BytesInTransfer++;\r
- }\r
- }\r
- \r
- return ENDPOINT_RWSTREAM_NoError;\r
-}\r
-\r
-uint8_t Endpoint_Null_Stream(uint16_t Length,\r
- uint16_t* const BytesProcessed)\r
-{\r
- uint8_t ErrorCode;\r
- uint16_t BytesInTransfer = 0;\r
- \r
- if ((ErrorCode = Endpoint_WaitUntilReady()))\r
- return ErrorCode;\r
- \r
- if (BytesProcessed != NULL)\r
- Length -= *BytesProcessed;\r
-\r
- while (Length)\r
- {\r
- if (!(Endpoint_IsReadWriteAllowed()))\r
- {\r
- Endpoint_ClearIN();\r
-\r
- if (BytesProcessed != NULL)\r
- {\r
- *BytesProcessed += BytesInTransfer;\r
- return ENDPOINT_RWSTREAM_IncompleteTransfer;\r
- }\r
-\r
- if ((ErrorCode = Endpoint_WaitUntilReady()))\r
- return ErrorCode;\r
- }\r
- else\r
- {\r
- Endpoint_Write_8(0);\r
-\r
- Length--;\r
- BytesInTransfer++;\r
- }\r
- }\r
- \r
- return ENDPOINT_RWSTREAM_NoError;\r
-}\r
-\r
-/* The following abuses the C preprocessor in order to copy-paste common code with slight alterations,\r
- * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */\r
-\r
-#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_LE\r
-#define TEMPLATE_BUFFER_TYPE const void*\r
-#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()\r
-#define TEMPLATE_BUFFER_OFFSET(Length) 0\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)\r
-#include "Template/Template_Endpoint_RW.c"\r
-\r
-#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE\r
-#define TEMPLATE_BUFFER_TYPE const void*\r
-#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()\r
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)\r
-#include "Template/Template_Endpoint_RW.c"\r
-\r
-#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE\r
-#define TEMPLATE_BUFFER_TYPE void*\r
-#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()\r
-#define TEMPLATE_BUFFER_OFFSET(Length) 0\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()\r
-#include "Template/Template_Endpoint_RW.c"\r
-\r
-#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE\r
-#define TEMPLATE_BUFFER_TYPE void*\r
-#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()\r
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()\r
-#include "Template/Template_Endpoint_RW.c"\r
-\r
-#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE)\r
- #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE\r
- #define TEMPLATE_BUFFER_TYPE const void*\r
- #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()\r
- #define TEMPLATE_BUFFER_OFFSET(Length) 0\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))\r
- #include "Template/Template_Endpoint_RW.c"\r
-\r
- #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE\r
- #define TEMPLATE_BUFFER_TYPE const void*\r
- #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()\r
- #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))\r
- #include "Template/Template_Endpoint_RW.c"\r
-#endif\r
-\r
-#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE)\r
- #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE\r
- #define TEMPLATE_BUFFER_TYPE const void*\r
- #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()\r
- #define TEMPLATE_BUFFER_OFFSET(Length) 0\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))\r
- #include "Template/Template_Endpoint_RW.c"\r
-\r
- #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE\r
- #define TEMPLATE_BUFFER_TYPE const void*\r
- #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()\r
- #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))\r
- #include "Template/Template_Endpoint_RW.c"\r
-\r
- #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE\r
- #define TEMPLATE_BUFFER_TYPE void*\r
- #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()\r
- #define TEMPLATE_BUFFER_OFFSET(Length) 0\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())\r
- #include "Template/Template_Endpoint_RW.c"\r
-\r
- #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE\r
- #define TEMPLATE_BUFFER_TYPE void*\r
- #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()\r
- #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())\r
- #include "Template/Template_Endpoint_RW.c"\r
-#endif\r
-\r
-#endif\r
-\r
-#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE\r
-#define TEMPLATE_BUFFER_OFFSET(Length) 0\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)\r
-#include "Template/Template_Endpoint_Control_W.c"\r
-\r
-#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE\r
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)\r
-#include "Template/Template_Endpoint_Control_W.c"\r
-\r
-#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE\r
-#define TEMPLATE_BUFFER_OFFSET(Length) 0\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()\r
-#include "Template/Template_Endpoint_Control_R.c"\r
-\r
-#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE\r
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
-#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount\r
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()\r
-#include "Template/Template_Endpoint_Control_R.c"\r
-\r
-#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE)\r
- #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_LE\r
- #define TEMPLATE_BUFFER_OFFSET(Length) 0\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))\r
- #include "Template/Template_Endpoint_Control_W.c"\r
-\r
- #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_BE\r
- #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))\r
- #include "Template/Template_Endpoint_Control_W.c"\r
-#endif\r
-\r
-#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE)\r
- #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_LE\r
- #define TEMPLATE_BUFFER_OFFSET(Length) 0\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))\r
- #include "Template/Template_Endpoint_Control_W.c"\r
-\r
- #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_BE\r
- #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))\r
- #include "Template/Template_Endpoint_Control_W.c"\r
-\r
- #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_LE\r
- #define TEMPLATE_BUFFER_OFFSET(Length) 0\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())\r
- #include "Template/Template_Endpoint_Control_R.c"\r
-\r
- #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_BE\r
- #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)\r
- #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount\r
- #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())\r
- #include "Template/Template_Endpoint_Control_R.c"\r
-#endif\r
-\r
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 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.
+*/
+
+#include "../../../../Common/Common.h"
+#if (ARCH == ARCH_XMEGA)
+
+#define __INCLUDE_FROM_USB_DRIVER
+#include "../USBMode.h"
+
+#if defined(USB_CAN_BE_DEVICE)
+
+#include "EndpointStream_XMEGA.h"
+
+#if !defined(CONTROL_ONLY_DEVICE)
+uint8_t Endpoint_Discard_Stream(uint16_t Length,
+ uint16_t* const BytesProcessed)
+{
+ uint8_t ErrorCode;
+ uint16_t BytesInTransfer = 0;
+
+ if ((ErrorCode = Endpoint_WaitUntilReady()))
+ return ErrorCode;
+
+ if (BytesProcessed != NULL)
+ Length -= *BytesProcessed;
+
+ while (Length)
+ {
+ if (!(Endpoint_IsReadWriteAllowed()))
+ {
+ Endpoint_ClearOUT();
+
+ if (BytesProcessed != NULL)
+ {
+ *BytesProcessed += BytesInTransfer;
+ return ENDPOINT_RWSTREAM_IncompleteTransfer;
+ }
+
+ if ((ErrorCode = Endpoint_WaitUntilReady()))
+ return ErrorCode;
+ }
+ else
+ {
+ Endpoint_Discard_8();
+
+ Length--;
+ BytesInTransfer++;
+ }
+ }
+
+ return ENDPOINT_RWSTREAM_NoError;
+}
+
+uint8_t Endpoint_Null_Stream(uint16_t Length,
+ uint16_t* const BytesProcessed)
+{
+ uint8_t ErrorCode;
+ uint16_t BytesInTransfer = 0;
+
+ if ((ErrorCode = Endpoint_WaitUntilReady()))
+ return ErrorCode;
+
+ if (BytesProcessed != NULL)
+ Length -= *BytesProcessed;
+
+ while (Length)
+ {
+ if (!(Endpoint_IsReadWriteAllowed()))
+ {
+ Endpoint_ClearIN();
+
+ if (BytesProcessed != NULL)
+ {
+ *BytesProcessed += BytesInTransfer;
+ return ENDPOINT_RWSTREAM_IncompleteTransfer;
+ }
+
+ if ((ErrorCode = Endpoint_WaitUntilReady()))
+ return ErrorCode;
+ }
+ else
+ {
+ Endpoint_Write_8(0);
+
+ Length--;
+ BytesInTransfer++;
+ }
+ }
+
+ return ENDPOINT_RWSTREAM_NoError;
+}
+
+/* The following abuses the C preprocessor in order to copy-paste common code with slight alterations,
+ * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */
+
+#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_LE
+#define TEMPLATE_BUFFER_TYPE const void*
+#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)
+#include "Template/Template_Endpoint_RW.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE
+#define TEMPLATE_BUFFER_TYPE const void*
+#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)
+#include "Template/Template_Endpoint_RW.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE
+#define TEMPLATE_BUFFER_TYPE void*
+#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()
+#include "Template/Template_Endpoint_RW.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE
+#define TEMPLATE_BUFFER_TYPE void*
+#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()
+#include "Template/Template_Endpoint_RW.c"
+
+#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE)
+ #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE
+ #define TEMPLATE_BUFFER_TYPE const void*
+ #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
+ #define TEMPLATE_BUFFER_OFFSET(Length) 0
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))
+ #include "Template/Template_Endpoint_RW.c"
+
+ #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE
+ #define TEMPLATE_BUFFER_TYPE const void*
+ #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
+ #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))
+ #include "Template/Template_Endpoint_RW.c"
+#endif
+
+#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE)
+ #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE
+ #define TEMPLATE_BUFFER_TYPE const void*
+ #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
+ #define TEMPLATE_BUFFER_OFFSET(Length) 0
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))
+ #include "Template/Template_Endpoint_RW.c"
+
+ #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE
+ #define TEMPLATE_BUFFER_TYPE const void*
+ #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
+ #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))
+ #include "Template/Template_Endpoint_RW.c"
+
+ #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE
+ #define TEMPLATE_BUFFER_TYPE void*
+ #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
+ #define TEMPLATE_BUFFER_OFFSET(Length) 0
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())
+ #include "Template/Template_Endpoint_RW.c"
+
+ #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE
+ #define TEMPLATE_BUFFER_TYPE void*
+ #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
+ #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())
+ #include "Template/Template_Endpoint_RW.c"
#endif
-#endif\r
+#endif
+
+#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)
+#include "Template/Template_Endpoint_Control_W.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)
+#include "Template/Template_Endpoint_Control_W.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()
+#include "Template/Template_Endpoint_Control_R.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()
+#include "Template/Template_Endpoint_Control_R.c"
+
+#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE)
+ #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_LE
+ #define TEMPLATE_BUFFER_OFFSET(Length) 0
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))
+ #include "Template/Template_Endpoint_Control_W.c"
+
+ #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_BE
+ #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))
+ #include "Template/Template_Endpoint_Control_W.c"
+#endif
+
+#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE)
+ #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_LE
+ #define TEMPLATE_BUFFER_OFFSET(Length) 0
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))
+ #include "Template/Template_Endpoint_Control_W.c"
+
+ #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_BE
+ #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))
+ #include "Template/Template_Endpoint_Control_W.c"
+
+ #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_LE
+ #define TEMPLATE_BUFFER_OFFSET(Length) 0
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())
+ #include "Template/Template_Endpoint_Control_R.c"
+
+ #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_BE
+ #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+ #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+ #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())
+ #include "Template/Template_Endpoint_Control_R.c"
+#endif
+
+#endif
+
+#endif
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2012.\r
- \r
- dean [at] fourwalledcubicle [dot] com\r
- www.lufa-lib.org\r
-*/\r
-\r
-/*\r
- Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, distribute, and sell this \r
- software and its documentation for any purpose is hereby granted\r
- without fee, provided that the above copyright notice appear in \r
- all copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting \r
- documentation, and that the name of the author not be used in \r
- advertising or publicity pertaining to distribution of the \r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-/** \file\r
- * \brief Endpoint data stream transmission and reception management for the AVR XMEGA microcontrollers.\r
- * \copydetails Group_EndpointStreamRW_XMEGA\r
- *\r
- * \note This file should not be included directly. It is automatically included as needed by the USB driver\r
- * dispatch header located in LUFA/Drivers/USB/USB.h.\r
- */\r
-\r
-/** \ingroup Group_EndpointStreamRW\r
- * \defgroup Group_EndpointStreamRW_XMEGA Read/Write of Multi-Byte Streams (XMEGA)\r
- * \brief Endpoint data stream transmission and reception management for the Atmel AVR XMEGA architecture.\r
- *\r
- * Functions, macros, variables, enums and types related to data reading and writing of data streams from\r
- * and to endpoints.\r
- *\r
- * @{\r
- */ \r
-\r
-#ifndef __ENDPOINT_STREAM_XMEGA_H__\r
-#define __ENDPOINT_STREAM_XMEGA_H__\r
-\r
- /* Includes: */\r
- #include "../../../../Common/Common.h"\r
- #include "../USBMode.h" \r
- #include "../USBTask.h"\r
- \r
- /* Enable C linkage for C++ Compilers: */\r
- #if defined(__cplusplus)\r
- extern "C" {\r
- #endif\r
-\r
- /* Preprocessor Checks: */\r
- #if !defined(__INCLUDE_FROM_USB_DRIVER)\r
- #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.\r
- #endif\r
-\r
- /* Public Interface - May be used in end-application: */\r
- /* Function Prototypes: */\r
- /** \name Stream functions for null data */\r
- //@{\r
-\r
- /** Reads and discards the given number of bytes from the currently selected endpoint's bank,\r
- * discarding fully read packets from the host as needed. The last packet is not automatically\r
- * discarded once the remaining bytes has been read; the user is responsible for manually\r
- * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro.\r
- *\r
- * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,\r
- * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid\r
- * storage location, the transfer will instead be performed as a series of chunks. Each time\r
- * the endpoint bank becomes empty while there is still data to process (and after the current\r
- * packet has been acknowledged) the BytesProcessed location will be updated with the total number\r
- * of bytes processed in the stream, and the function will exit with an error code of\r
- * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed\r
- * in the user code - to continue the transfer, call the function again with identical parameters\r
- * and it will resume until the BytesProcessed value reaches the total transfer length.\r
- *\r
- * <b>Single Stream Transfer Example:</b>\r
- * \code\r
- * uint8_t ErrorCode;\r
- * \r
- * if ((ErrorCode = Endpoint_Discard_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * <b>Partial Stream Transfers Example:</b>\r
- * \code\r
- * uint8_t ErrorCode;\r
- * uint16_t BytesProcessed;\r
- * \r
- * BytesProcessed = 0;\r
- * while ((ErrorCode = Endpoint_Discard_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)\r
- * {\r
- * // Stream not yet complete - do other actions here, abort if required\r
- * }\r
- * \r
- * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * \note This routine should not be used on CONTROL type endpoints.\r
- *\r
- * \param[in] Length Number of bytes to discard via the currently selected endpoint.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be read at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Discard_Stream(uint16_t Length,\r
- uint16_t* const BytesProcessed);\r
-\r
- /** Writes a given number of zeroed bytes to the currently selected endpoint's bank, sending\r
- * full packets to the host as needed. The last packet is not automatically sent once the \r
- * remaining bytes have been written; the user is responsible for manually sending the last\r
- * packet to the host via the \ref Endpoint_ClearIN() macro.\r
- *\r
- * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,\r
- * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid\r
- * storage location, the transfer will instead be performed as a series of chunks. Each time\r
- * the endpoint bank becomes full while there is still data to process (and after the current\r
- * packet transmission has been initiated) the BytesProcessed location will be updated with the\r
- * total number of bytes processed in the stream, and the function will exit with an error code of\r
- * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed\r
- * in the user code - to continue the transfer, call the function again with identical parameters\r
- * and it will resume until the BytesProcessed value reaches the total transfer length.\r
- *\r
- * <b>Single Stream Transfer Example:</b>\r
- * \code\r
- * uint8_t ErrorCode;\r
- * \r
- * if ((ErrorCode = Endpoint_Null_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * <b>Partial Stream Transfers Example:</b>\r
- * \code\r
- * uint8_t ErrorCode;\r
- * uint16_t BytesProcessed;\r
- * \r
- * BytesProcessed = 0;\r
- * while ((ErrorCode = Endpoint_Null_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)\r
- * {\r
- * // Stream not yet complete - do other actions here, abort if required\r
- * }\r
- * \r
- * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * \note This routine should not be used on CONTROL type endpoints.\r
- *\r
- * \param[in] Length Number of zero bytes to send via the currently selected endpoint.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be read at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Null_Stream(uint16_t Length,\r
- uint16_t* const BytesProcessed);\r
-\r
- //@}\r
-\r
- /** \name Stream functions for RAM source/destination data */\r
- //@{\r
- \r
- /** Writes the given number of bytes to the endpoint from the given buffer in little endian,\r
- * sending full packets to the host as needed. The last packet filled is not automatically sent;\r
- * the user is responsible for manually sending the last written packet to the host via the\r
- * \ref Endpoint_ClearIN() macro.\r
- *\r
- * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,\r
- * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid\r
- * storage location, the transfer will instead be performed as a series of chunks. Each time\r
- * the endpoint bank becomes full while there is still data to process (and after the current\r
- * packet transmission has been initiated) the BytesProcessed location will be updated with the\r
- * total number of bytes processed in the stream, and the function will exit with an error code of\r
- * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed\r
- * in the user code - to continue the transfer, call the function again with identical parameters\r
- * and it will resume until the BytesProcessed value reaches the total transfer length.\r
- *\r
- * <b>Single Stream Transfer Example:</b>\r
- * \code\r
- * uint8_t DataStream[512];\r
- * uint8_t ErrorCode;\r
- * \r
- * if ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream),\r
- * NULL)) != ENDPOINT_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * <b>Partial Stream Transfers Example:</b>\r
- * \code\r
- * uint8_t DataStream[512];\r
- * uint8_t ErrorCode;\r
- * uint16_t BytesProcessed;\r
- * \r
- * BytesProcessed = 0;\r
- * while ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream),\r
- * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)\r
- * {\r
- * // Stream not yet complete - do other actions here, abort if required\r
- * }\r
- * \r
- * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * \note This routine should not be used on CONTROL type endpoints.\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be written at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_Stream_LE(const void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Writes the given number of bytes to the endpoint from the given buffer in big endian,\r
- * sending full packets to the host as needed. The last packet filled is not automatically sent;\r
- * the user is responsible for manually sending the last written packet to the host via the\r
- * \ref Endpoint_ClearIN() macro.\r
- *\r
- * \note This routine should not be used on CONTROL type endpoints.\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be written at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_Stream_BE(const void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
- \r
- /** Reads the given number of bytes from the endpoint from the given buffer in little endian,\r
- * discarding fully read packets from the host as needed. The last packet is not automatically\r
- * discarded once the remaining bytes has been read; the user is responsible for manually\r
- * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro.\r
- *\r
- * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,\r
- * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid\r
- * storage location, the transfer will instead be performed as a series of chunks. Each time\r
- * the endpoint bank becomes empty while there is still data to process (and after the current\r
- * packet has been acknowledged) the BytesProcessed location will be updated with the total number\r
- * of bytes processed in the stream, and the function will exit with an error code of\r
- * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed\r
- * in the user code - to continue the transfer, call the function again with identical parameters\r
- * and it will resume until the BytesProcessed value reaches the total transfer length.\r
- *\r
- * <b>Single Stream Transfer Example:</b>\r
- * \code\r
- * uint8_t DataStream[512];\r
- * uint8_t ErrorCode;\r
- * \r
- * if ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream),\r
- * NULL)) != ENDPOINT_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * <b>Partial Stream Transfers Example:</b>\r
- * \code\r
- * uint8_t DataStream[512];\r
- * uint8_t ErrorCode;\r
- * uint16_t BytesProcessed;\r
- * \r
- * BytesProcessed = 0;\r
- * while ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream),\r
- * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)\r
- * {\r
- * // Stream not yet complete - do other actions here, abort if required\r
- * }\r
- * \r
- * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)\r
- * {\r
- * // Stream failed to complete - check ErrorCode here\r
- * }\r
- * \endcode\r
- *\r
- * \note This routine should not be used on CONTROL type endpoints.\r
- *\r
- * \param[out] Buffer Pointer to the destination data buffer to write to.\r
- * \param[in] Length Number of bytes to send via the currently selected endpoint.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be read at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Read_Stream_LE(void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Reads the given number of bytes from the endpoint from the given buffer in big endian,\r
- * discarding fully read packets from the host as needed. The last packet is not automatically\r
- * discarded once the remaining bytes has been read; the user is responsible for manually\r
- * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro.\r
- *\r
- * \note This routine should not be used on CONTROL type endpoints.\r
- *\r
- * \param[out] Buffer Pointer to the destination data buffer to write to.\r
- * \param[in] Length Number of bytes to send via the currently selected endpoint.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be read at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Read_Stream_BE(void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in little endian,\r
- * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared\r
- * in both failure and success states; the user is responsible for manually clearing the setup OUT to\r
- * finalize the transfer via the \ref Endpoint_ClearOUT() macro.\r
- *\r
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
- * to clear the status stage when using this routine in a control transaction.\r
- * \n\n\r
- *\r
- * \note This routine should only be used on CONTROL type endpoints.\r
- *\r
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained\r
- * together; i.e. the entire stream data must be read or written at the one time.\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- *\r
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_Control_Stream_LE(const void* const Buffer,\r
- uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in big endian,\r
- * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared\r
- * in both failure and success states; the user is responsible for manually clearing the setup OUT to\r
- * finalize the transfer via the \ref Endpoint_ClearOUT() macro.\r
- *\r
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
- * to clear the status stage when using this routine in a control transaction.\r
- * \n\n\r
- *\r
- * \note This routine should only be used on CONTROL type endpoints.\r
- *\r
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained\r
- * together; i.e. the entire stream data must be read or written at the one time.\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- *\r
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_Control_Stream_BE(const void* const Buffer,\r
- uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in little endian,\r
- * discarding fully read packets from the host as needed. The device IN acknowledgement is not\r
- * automatically sent after success or failure states; the user is responsible for manually sending the\r
- * setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.\r
- *\r
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
- * to clear the status stage when using this routine in a control transaction.\r
- * \n\n\r
- *\r
- * \note This routine should only be used on CONTROL type endpoints.\r
- *\r
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained\r
- * together; i.e. the entire stream data must be read or written at the one time.\r
- *\r
- * \param[out] Buffer Pointer to the destination data buffer to write to.\r
- * \param[in] Length Number of bytes to send via the currently selected endpoint.\r
- *\r
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Read_Control_Stream_LE(void* const Buffer,\r
- uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in big endian,\r
- * discarding fully read packets from the host as needed. The device IN acknowledgement is not\r
- * automatically sent after success or failure states; the user is responsible for manually sending the\r
- * setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.\r
- *\r
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
- * to clear the status stage when using this routine in a control transaction.\r
- * \n\n\r
- *\r
- * \note This routine should only be used on CONTROL type endpoints.\r
- *\r
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained\r
- * together; i.e. the entire stream data must be read or written at the one time.\r
- *\r
- * \param[out] Buffer Pointer to the destination data buffer to write to.\r
- * \param[in] Length Number of bytes to send via the currently selected endpoint.\r
- *\r
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Read_Control_Stream_BE(void* const Buffer,\r
- uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);\r
- //@}\r
-\r
- /** \name Stream functions for EEPROM source/destination data */\r
- //@{\r
-\r
- /** EEPROM buffer source version of \ref Endpoint_Write_Stream_LE().\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be written at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_EStream_LE(const void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** EEPROM buffer source version of \ref Endpoint_Write_Stream_BE().\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be written at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_EStream_BE(const void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** EEPROM buffer destination version of \ref Endpoint_Read_Stream_LE().\r
- *\r
- * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space.\r
- * \param[in] Length Number of bytes to send via the currently selected endpoint.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be read at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Read_EStream_LE(void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** EEPROM buffer destination version of \ref Endpoint_Read_Stream_BE().\r
- *\r
- * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space.\r
- * \param[in] Length Number of bytes to send via the currently selected endpoint.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be read at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Read_EStream_BE(void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** EEPROM buffer source version of Endpoint_Write_Control_Stream_LE.\r
- *\r
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
- * to clear the status stage when using this routine in a control transaction.\r
- * \n\n\r
- *\r
- * \note This routine should only be used on CONTROL type endpoints.\r
- * \n\n\r
- *\r
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained\r
- * together; i.e. the entire stream data must be read or written at the one time.\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- *\r
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_Control_EStream_LE(const void* const Buffer,\r
- uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** EEPROM buffer source version of \ref Endpoint_Write_Control_Stream_BE().\r
- *\r
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
- * to clear the status stage when using this routine in a control transaction.\r
- * \n\n\r
- *\r
- * \note This routine should only be used on CONTROL type endpoints.\r
- * \n\n\r
- *\r
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained\r
- * together; i.e. the entire stream data must be read or written at the one time.\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- *\r
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_Control_EStream_BE(const void* const Buffer,\r
- uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_LE().\r
- *\r
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
- * to clear the status stage when using this routine in a control transaction.\r
- * \n\n\r
- *\r
- * \note This routine should only be used on CONTROL type endpoints.\r
- * \n\n\r
- *\r
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained\r
- * together; i.e. the entire stream data must be read or written at the one time.\r
- *\r
- * \param[out] Buffer Pointer to the destination data buffer to write to.\r
- * \param[in] Length Number of bytes to send via the currently selected endpoint.\r
- *\r
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Read_Control_EStream_LE(void* const Buffer,\r
- uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_BE().\r
- *\r
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
- * to clear the status stage when using this routine in a control transaction.\r
- * \n\n\r
- *\r
- * \note This routine should only be used on CONTROL type endpoints.\r
- * \n\n\r
- *\r
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained\r
- * together; i.e. the entire stream data must be read or written at the one time.\r
- *\r
- * \param[out] Buffer Pointer to the destination data buffer to write to.\r
- * \param[in] Length Number of bytes to send via the currently selected endpoint.\r
- *\r
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Read_Control_EStream_BE(void* const Buffer,\r
- uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);\r
- //@}\r
-\r
- /** \name Stream functions for PROGMEM source/destination data */\r
- //@{\r
-\r
- /** FLASH buffer source version of \ref Endpoint_Write_Stream_LE().\r
- *\r
- * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be written at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_PStream_LE(const void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** FLASH buffer source version of \ref Endpoint_Write_Stream_BE().\r
- *\r
- * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current\r
- * transaction should be updated, \c NULL if the entire stream should be written at once.\r
- *\r
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_PStream_BE(const void* const Buffer,\r
- uint16_t Length,\r
- uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_LE().\r
- *\r
- * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.\r
- *\r
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
- * to clear the status stage when using this routine in a control transaction.\r
- * \n\n\r
- *\r
- * \note This routine should only be used on CONTROL type endpoints.\r
- * \n\n\r
- *\r
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained\r
- * together; i.e. the entire stream data must be read or written at the one time.\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- *\r
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_Control_PStream_LE(const void* const Buffer,\r
- uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
- /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_BE().\r
- *\r
- * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.\r
- *\r
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt\r
- * to clear the status stage when using this routine in a control transaction.\r
- * \n\n\r
- *\r
- * \note This routine should only be used on CONTROL type endpoints.\r
- * \n\n\r
- *\r
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained\r
- * together; i.e. the entire stream data must be read or written at the one time.\r
- *\r
- * \param[in] Buffer Pointer to the source data buffer to read from.\r
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.\r
- *\r
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.\r
- */\r
- uint8_t Endpoint_Write_Control_PStream_BE(const void* const Buffer,\r
- uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);\r
- //@}\r
-\r
- /* Disable C linkage for C++ Compilers: */\r
- #if defined(__cplusplus)\r
- }\r
- #endif\r
- \r
-#endif\r
-\r
-/** @} */\r
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 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
+ * \brief Endpoint data stream transmission and reception management for the AVR XMEGA microcontrollers.
+ * \copydetails Group_EndpointStreamRW_XMEGA
+ *
+ * \note This file should not be included directly. It is automatically included as needed by the USB driver
+ * dispatch header located in LUFA/Drivers/USB/USB.h.
+ */
+
+/** \ingroup Group_EndpointStreamRW
+ * \defgroup Group_EndpointStreamRW_XMEGA Read/Write of Multi-Byte Streams (XMEGA)
+ * \brief Endpoint data stream transmission and reception management for the Atmel AVR XMEGA architecture.
+ *
+ * Functions, macros, variables, enums and types related to data reading and writing of data streams from
+ * and to endpoints.
+ *
+ * @{
+ */
+
+#ifndef __ENDPOINT_STREAM_XMEGA_H__
+#define __ENDPOINT_STREAM_XMEGA_H__
+
+ /* Includes: */
+ #include "../../../../Common/Common.h"
+ #include "../USBMode.h"
+ #include "../USBTask.h"
+
+ /* Enable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ extern "C" {
+ #endif
+
+ /* Preprocessor Checks: */
+ #if !defined(__INCLUDE_FROM_USB_DRIVER)
+ #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
+ #endif
+
+ /* Public Interface - May be used in end-application: */
+ /* Function Prototypes: */
+ /** \name Stream functions for null data */
+ //@{
+
+ /** Reads and discards the given number of bytes from the currently selected endpoint's bank,
+ * discarding fully read packets from the host as needed. The last packet is not automatically
+ * discarded once the remaining bytes has been read; the user is responsible for manually
+ * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro.
+ *
+ * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
+ * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
+ * storage location, the transfer will instead be performed as a series of chunks. Each time
+ * the endpoint bank becomes empty while there is still data to process (and after the current
+ * packet has been acknowledged) the BytesProcessed location will be updated with the total number
+ * of bytes processed in the stream, and the function will exit with an error code of
+ * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
+ * in the user code - to continue the transfer, call the function again with identical parameters
+ * and it will resume until the BytesProcessed value reaches the total transfer length.
+ *
+ * <b>Single Stream Transfer Example:</b>
+ * \code
+ * uint8_t ErrorCode;
+ *
+ * if ((ErrorCode = Endpoint_Discard_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * <b>Partial Stream Transfers Example:</b>
+ * \code
+ * uint8_t ErrorCode;
+ * uint16_t BytesProcessed;
+ *
+ * BytesProcessed = 0;
+ * while ((ErrorCode = Endpoint_Discard_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)
+ * {
+ * // Stream not yet complete - do other actions here, abort if required
+ * }
+ *
+ * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * \note This routine should not be used on CONTROL type endpoints.
+ *
+ * \param[in] Length Number of bytes to discard via the currently selected endpoint.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be read at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Discard_Stream(uint16_t Length,
+ uint16_t* const BytesProcessed);
+
+ /** Writes a given number of zeroed bytes to the currently selected endpoint's bank, sending
+ * full packets to the host as needed. The last packet is not automatically sent once the
+ * remaining bytes have been written; the user is responsible for manually sending the last
+ * packet to the host via the \ref Endpoint_ClearIN() macro.
+ *
+ * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
+ * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
+ * storage location, the transfer will instead be performed as a series of chunks. Each time
+ * the endpoint bank becomes full while there is still data to process (and after the current
+ * packet transmission has been initiated) the BytesProcessed location will be updated with the
+ * total number of bytes processed in the stream, and the function will exit with an error code of
+ * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
+ * in the user code - to continue the transfer, call the function again with identical parameters
+ * and it will resume until the BytesProcessed value reaches the total transfer length.
+ *
+ * <b>Single Stream Transfer Example:</b>
+ * \code
+ * uint8_t ErrorCode;
+ *
+ * if ((ErrorCode = Endpoint_Null_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * <b>Partial Stream Transfers Example:</b>
+ * \code
+ * uint8_t ErrorCode;
+ * uint16_t BytesProcessed;
+ *
+ * BytesProcessed = 0;
+ * while ((ErrorCode = Endpoint_Null_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)
+ * {
+ * // Stream not yet complete - do other actions here, abort if required
+ * }
+ *
+ * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * \note This routine should not be used on CONTROL type endpoints.
+ *
+ * \param[in] Length Number of zero bytes to send via the currently selected endpoint.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be read at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Null_Stream(uint16_t Length,
+ uint16_t* const BytesProcessed);
+
+ //@}
+
+ /** \name Stream functions for RAM source/destination data */
+ //@{
+
+ /** Writes the given number of bytes to the endpoint from the given buffer in little endian,
+ * sending full packets to the host as needed. The last packet filled is not automatically sent;
+ * the user is responsible for manually sending the last written packet to the host via the
+ * \ref Endpoint_ClearIN() macro.
+ *
+ * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
+ * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
+ * storage location, the transfer will instead be performed as a series of chunks. Each time
+ * the endpoint bank becomes full while there is still data to process (and after the current
+ * packet transmission has been initiated) the BytesProcessed location will be updated with the
+ * total number of bytes processed in the stream, and the function will exit with an error code of
+ * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
+ * in the user code - to continue the transfer, call the function again with identical parameters
+ * and it will resume until the BytesProcessed value reaches the total transfer length.
+ *
+ * <b>Single Stream Transfer Example:</b>
+ * \code
+ * uint8_t DataStream[512];
+ * uint8_t ErrorCode;
+ *
+ * if ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream),
+ * NULL)) != ENDPOINT_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * <b>Partial Stream Transfers Example:</b>
+ * \code
+ * uint8_t DataStream[512];
+ * uint8_t ErrorCode;
+ * uint16_t BytesProcessed;
+ *
+ * BytesProcessed = 0;
+ * while ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream),
+ * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)
+ * {
+ * // Stream not yet complete - do other actions here, abort if required
+ * }
+ *
+ * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * \note This routine should not be used on CONTROL type endpoints.
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be written at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Stream_LE(const void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Writes the given number of bytes to the endpoint from the given buffer in big endian,
+ * sending full packets to the host as needed. The last packet filled is not automatically sent;
+ * the user is responsible for manually sending the last written packet to the host via the
+ * \ref Endpoint_ClearIN() macro.
+ *
+ * \note This routine should not be used on CONTROL type endpoints.
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be written at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Stream_BE(const void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Reads the given number of bytes from the endpoint from the given buffer in little endian,
+ * discarding fully read packets from the host as needed. The last packet is not automatically
+ * discarded once the remaining bytes has been read; the user is responsible for manually
+ * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro.
+ *
+ * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
+ * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
+ * storage location, the transfer will instead be performed as a series of chunks. Each time
+ * the endpoint bank becomes empty while there is still data to process (and after the current
+ * packet has been acknowledged) the BytesProcessed location will be updated with the total number
+ * of bytes processed in the stream, and the function will exit with an error code of
+ * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
+ * in the user code - to continue the transfer, call the function again with identical parameters
+ * and it will resume until the BytesProcessed value reaches the total transfer length.
+ *
+ * <b>Single Stream Transfer Example:</b>
+ * \code
+ * uint8_t DataStream[512];
+ * uint8_t ErrorCode;
+ *
+ * if ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream),
+ * NULL)) != ENDPOINT_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * <b>Partial Stream Transfers Example:</b>
+ * \code
+ * uint8_t DataStream[512];
+ * uint8_t ErrorCode;
+ * uint16_t BytesProcessed;
+ *
+ * BytesProcessed = 0;
+ * while ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream),
+ * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)
+ * {
+ * // Stream not yet complete - do other actions here, abort if required
+ * }
+ *
+ * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)
+ * {
+ * // Stream failed to complete - check ErrorCode here
+ * }
+ * \endcode
+ *
+ * \note This routine should not be used on CONTROL type endpoints.
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be read at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_Stream_LE(void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Reads the given number of bytes from the endpoint from the given buffer in big endian,
+ * discarding fully read packets from the host as needed. The last packet is not automatically
+ * discarded once the remaining bytes has been read; the user is responsible for manually
+ * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro.
+ *
+ * \note This routine should not be used on CONTROL type endpoints.
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be read at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_Stream_BE(void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in little endian,
+ * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared
+ * in both failure and success states; the user is responsible for manually clearing the setup OUT to
+ * finalize the transfer via the \ref Endpoint_ClearOUT() macro.
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Control_Stream_LE(const void* const Buffer,
+ uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in big endian,
+ * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared
+ * in both failure and success states; the user is responsible for manually clearing the setup OUT to
+ * finalize the transfer via the \ref Endpoint_ClearOUT() macro.
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Control_Stream_BE(const void* const Buffer,
+ uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in little endian,
+ * discarding fully read packets from the host as needed. The device IN acknowledgement is not
+ * automatically sent after success or failure states; the user is responsible for manually sending the
+ * setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_Control_Stream_LE(void* const Buffer,
+ uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in big endian,
+ * discarding fully read packets from the host as needed. The device IN acknowledgement is not
+ * automatically sent after success or failure states; the user is responsible for manually sending the
+ * setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_Control_Stream_BE(void* const Buffer,
+ uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+ //@}
+
+ /** \name Stream functions for EEPROM source/destination data */
+ //@{
+
+ /** EEPROM buffer source version of \ref Endpoint_Write_Stream_LE().
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be written at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_EStream_LE(const void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer source version of \ref Endpoint_Write_Stream_BE().
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be written at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_EStream_BE(const void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer destination version of \ref Endpoint_Read_Stream_LE().
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be read at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_EStream_LE(void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer destination version of \ref Endpoint_Read_Stream_BE().
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be read at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_EStream_BE(void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer source version of Endpoint_Write_Control_Stream_LE.
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ * \n\n
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Control_EStream_LE(const void* const Buffer,
+ uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer source version of \ref Endpoint_Write_Control_Stream_BE().
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ * \n\n
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Control_EStream_BE(const void* const Buffer,
+ uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_LE().
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ * \n\n
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_Control_EStream_LE(void* const Buffer,
+ uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_BE().
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ * \n\n
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_Control_EStream_BE(void* const Buffer,
+ uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+ //@}
+
+ /** \name Stream functions for PROGMEM source/destination data */
+ //@{
+
+ /** FLASH buffer source version of \ref Endpoint_Write_Stream_LE().
+ *
+ * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be written at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_PStream_LE(const void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** FLASH buffer source version of \ref Endpoint_Write_Stream_BE().
+ *
+ * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
+ * transaction should be updated, \c NULL if the entire stream should be written at once.
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_PStream_BE(const void* const Buffer,
+ uint16_t Length,
+ uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_LE().
+ *
+ * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ * \n\n
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Control_PStream_LE(const void* const Buffer,
+ uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_BE().
+ *
+ * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ * \n\n
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Control_PStream_BE(const void* const Buffer,
+ uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+ //@}
+
+ /* Disable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ }
+ #endif
+
+#endif
+
+/** @} */