Rewritten event system to remove all macros, to make user code clearer.
[pub/USBasp.git] / Demos / Host / StillImageHost / StillImageHost.c
index 1694322..197e832 100644 (file)
 \r
 #include "StillImageHost.h"\r
 \r
-/* Project Tags, for reading out using the ButtLoad project */\r
-BUTTLOADTAG(ProjName,    "LUFA SIMG Host App");\r
-BUTTLOADTAG(BuildTime,   __TIME__);\r
-BUTTLOADTAG(BuildDate,   __DATE__);\r
-\r
 /* Scheduler Task List */\r
 TASK_LIST\r
 {\r
-       { Task: USB_USBTask          , TaskStatus: TASK_STOP },\r
-       { Task: USB_SImage_Host      , TaskStatus: TASK_STOP },\r
+       { .Task = USB_USBTask          , .TaskStatus = TASK_STOP },\r
+       { .Task = USB_SImage_Host      , .TaskStatus = TASK_STOP },\r
 };\r
 \r
 \r
@@ -86,7 +81,7 @@ int main(void)
 /** 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
-EVENT_HANDLER(USB_DeviceAttached)\r
+void EVENT_USB_DeviceAttached(void)\r
 {\r
        puts_P(PSTR("Device Attached.\r\n"));\r
        UpdateStatus(Status_USBEnumerating);\r
@@ -98,7 +93,7 @@ EVENT_HANDLER(USB_DeviceAttached)
 /** 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
-EVENT_HANDLER(USB_DeviceUnattached)\r
+void EVENT_USB_DeviceUnattached(void)\r
 {\r
        /* Stop USB management and Still Image tasks */\r
        Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);\r
@@ -111,7 +106,7 @@ EVENT_HANDLER(USB_DeviceUnattached)
 /** 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
-EVENT_HANDLER(USB_DeviceEnumerationComplete)\r
+void EVENT_USB_DeviceEnumerationComplete(void)\r
 {\r
        /* Once device is fully enumerated, start the Still Image Host task */\r
        Scheduler_SetTaskMode(USB_SImage_Host, TASK_RUN);\r
@@ -121,7 +116,7 @@ EVENT_HANDLER(USB_DeviceEnumerationComplete)
 }\r
 \r
 /** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */\r
-EVENT_HANDLER(USB_HostError)\r
+void EVENT_USB_HostError(const uint8_t ErrorCode)\r
 {\r
        USB_ShutDown();\r
 \r
@@ -135,7 +130,7 @@ EVENT_HANDLER(USB_HostError)
 /** Event handler for the USB_DeviceEnumerationFailed event. This indicates that a problem occurred while\r
  *  enumerating an attached USB device.\r
  */\r
-EVENT_HANDLER(USB_DeviceEnumerationFailed)\r
+void EVENT_USB_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode)\r
 {\r
        puts_P(PSTR(ESC_BG_RED "Dev Enum Error\r\n"));\r
        printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);\r
@@ -156,13 +151,13 @@ TASK(USB_SImage_Host)
        {\r
                case HOST_STATE_Addressed:\r
                        /* Standard request to set the device configuration to configuration 1 */\r
-                       USB_HostRequest = (USB_Host_Request_Header_t)\r
+                       USB_ControlRequest = (USB_Request_Header_t)\r
                                {\r
-                                       bmRequestType: (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),\r
-                                       bRequest:      REQ_SetConfiguration,\r
-                                       wValue:        1,\r
-                                       wIndex:        0,\r
-                                       wLength:       0,\r
+                                       .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),\r
+                                       .bRequest      = REQ_SetConfiguration,\r
+                                       .wValue        = 1,\r
+                                       .wIndex        = 0,\r
+                                       .wLength       = 0,\r
                                };\r
 \r
                        /* Select the control pipe for the request transfer */\r
@@ -216,18 +211,18 @@ TASK(USB_SImage_Host)
                        \r
                        PIMA_SendBlock = (PIMA_Container_t)\r
                                {\r
-                                       DataLength:    PIMA_COMMAND_SIZE(0),\r
-                                       Type:          CType_CommandBlock,\r
-                                       Code:          PIMA_OPERATION_GETDEVICEINFO,\r
-                                       TransactionID: 0x00000000,\r
-                                       Params:        {},\r
+                                       .DataLength    = PIMA_COMMAND_SIZE(0),\r
+                                       .Type          = CType_CommandBlock,\r
+                                       .Code          = PIMA_OPERATION_GETDEVICEINFO,\r
+                                       .TransactionID = 0x00000000,\r
+                                       .Params        = {},\r
                                };\r
                        \r
                        /* Send the GETDEVICEINFO block */\r
                        SImage_SendBlockHeader();\r
                        \r
                        /* Receive the response data block */\r
-                       if ((ErrorCode = SImage_RecieveBlockHeader()) != PIPE_RWSTREAM_ERROR_NoError)\r
+                       if ((ErrorCode = SImage_RecieveBlockHeader()) != PIPE_RWSTREAM_NoError)\r
                        {\r
                                ShowCommandError(ErrorCode, false);\r
                                break;\r
@@ -243,7 +238,7 @@ TASK(USB_SImage_Host)
                        SImage_ReadData(DeviceInfo, DeviceInfoSize);\r
                        \r
                        /* Once all the data has been read, the pipe must be cleared before the response can be sent */\r
-                       Pipe_ClearCurrentBank();\r
+                       Pipe_ClearIN();\r
                        \r
                        /* Create a pointer for walking through the info dataset */\r
                        uint8_t* DeviceInfoPos = DeviceInfo;\r
@@ -278,7 +273,7 @@ TASK(USB_SImage_Host)
                        printf_P(PSTR("   Device Version: %s\r\n"), DeviceVersion);\r
 \r
                        /* Receive the final response block from the device */\r
-                       if ((ErrorCode = SImage_RecieveBlockHeader()) != PIPE_RWSTREAM_ERROR_NoError)\r
+                       if ((ErrorCode = SImage_RecieveBlockHeader()) != PIPE_RWSTREAM_NoError)\r
                        {\r
                                ShowCommandError(ErrorCode, false);\r
                                break;\r
@@ -295,18 +290,18 @@ TASK(USB_SImage_Host)
                        \r
                        PIMA_SendBlock = (PIMA_Container_t)\r
                                {\r
-                                       DataLength:    PIMA_COMMAND_SIZE(1),\r
-                                       Type:          CType_CommandBlock,\r
-                                       Code:          PIMA_OPERATION_OPENSESSION,\r
-                                       TransactionID: 0x00000000,\r
-                                       Params:        {0x00000001},\r
+                                       .DataLength    = PIMA_COMMAND_SIZE(1),\r
+                                       .Type          = CType_CommandBlock,\r
+                                       .Code          = PIMA_OPERATION_OPENSESSION,\r
+                                       .TransactionID = 0x00000000,\r
+                                       .Params        = {0x00000001},\r
                                };\r
                        \r
                        /* Send the OPENSESSION block, open a session with an ID of 0x0001 */\r
                        SImage_SendBlockHeader();\r
                        \r
                        /* Receive the response block from the device */\r
-                       if ((ErrorCode = SImage_RecieveBlockHeader()) != PIPE_RWSTREAM_ERROR_NoError)\r
+                       if ((ErrorCode = SImage_RecieveBlockHeader()) != PIPE_RWSTREAM_NoError)\r
                        {\r
                                ShowCommandError(ErrorCode, false);\r
                                break;\r
@@ -323,18 +318,18 @@ TASK(USB_SImage_Host)
 \r
                        PIMA_SendBlock = (PIMA_Container_t)\r
                                {\r
-                                       DataLength:    PIMA_COMMAND_SIZE(1),\r
-                                       Type:          CType_CommandBlock,\r
-                                       Code:          PIMA_OPERATION_CLOSESESSION,\r
-                                       TransactionID: 0x00000001,\r
-                                       Params:        {0x00000001},\r
+                                       .DataLength    = PIMA_COMMAND_SIZE(1),\r
+                                       .Type          = CType_CommandBlock,\r
+                                       .Code          = PIMA_OPERATION_CLOSESESSION,\r
+                                       .TransactionID = 0x00000001,\r
+                                       .Params        = {0x00000001},\r
                                };\r
                        \r
                        /* Send the CLOSESESSION block, close the session with an ID of 0x0001 */\r
                        SImage_SendBlockHeader();\r
                        \r
                        /* Receive the response block from the device */\r
-                       if ((ErrorCode = SImage_RecieveBlockHeader()) != PIPE_RWSTREAM_ERROR_NoError)\r
+                       if ((ErrorCode = SImage_RecieveBlockHeader()) != PIPE_RWSTREAM_NoError)\r
                        {\r
                                ShowCommandError(ErrorCode, false);\r
                                break;\r
@@ -422,7 +417,7 @@ void UpdateStatus(uint8_t CurrentStatus)
 /** Displays a PIMA command error via the device's serial port.\r
  *\r
  *  \param ErrorCode          Error code of the function which failed to complete successfully\r
- *  \param ResponseErrorCode  Indicates if the error is due to a command failed indication from the device, or a communication failure\r
+ *  \param ResponseCodeError  Indicates if the error is due to a command failed indication from the device, or a communication failure\r
  */\r
 void ShowCommandError(uint8_t ErrorCode, bool ResponseCodeError)\r
 {\r