Added error codes to most StillImageHost demo commands.
authorDean Camera <dean@fourwalledcubicle.com>
Mon, 20 Jul 2009 02:27:32 +0000 (02:27 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Mon, 20 Jul 2009 02:27:32 +0000 (02:27 +0000)
Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.c
Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.h
Demos/Host/LowLevel/StillImageHost/StillImageHost.c
Demos/OTG/TestApp/TestApp.c

index bf85750..c0a9575 100644 (file)
@@ -80,20 +80,24 @@ void SImage_SendBlockHeader(void)
 }\r
 \r
 /** Function to receive a PIMA event container from the attached still image device. */\r
-void SImage_RecieveEventHeader(void)\r
+uint8_t SImage_RecieveEventHeader(void)\r
 {\r
+       uint8_t ErrorCode;\r
+\r
        /* Unfreeze the events pipe */\r
        Pipe_SelectPipe(SIMAGE_EVENTS_PIPE);\r
        Pipe_Unfreeze();\r
        \r
        /* Read in the event data into the global structure */\r
-       Pipe_Read_Stream_LE(&PIMA_EventBlock, sizeof(PIMA_EventBlock));\r
+       ErrorCode = Pipe_Read_Stream_LE(&PIMA_EventBlock, sizeof(PIMA_EventBlock));\r
        \r
        /* Clear the pipe after read complete to prepare for next event */\r
        Pipe_ClearIN();\r
        \r
        /* Freeze the event pipe again after use */\r
        Pipe_Freeze();\r
+       \r
+       return ErrorCode;\r
 }\r
 \r
 /** Function to receive a PIMA response container from the attached still image device. */\r
@@ -193,20 +197,24 @@ uint8_t SImage_RecieveBlockHeader(void)
  *  \param[in] Buffer  Source data buffer to send to the device\r
  *  \param[in] Bytes   Number of bytes to send\r
  */\r
-void SImage_SendData(void* Buffer, uint16_t Bytes)\r
+uint8_t SImage_SendData(void* Buffer, uint16_t Bytes)\r
 {\r
+       uint8_t ErrorCode;\r
+\r
        /* Unfreeze the data OUT pipe */\r
        Pipe_SelectPipe(SIMAGE_DATA_OUT_PIPE);\r
        Pipe_Unfreeze();\r
        \r
        /* Write the data contents to the pipe */\r
-       Pipe_Write_Stream_LE(Buffer, Bytes);\r
+       ErrorCode = Pipe_Write_Stream_LE(Buffer, Bytes);\r
 \r
        /* Send the last packet to the attached device */\r
        Pipe_ClearOUT();\r
 \r
        /* Freeze the pipe again after use */\r
        Pipe_Freeze();\r
+       \r
+       return ErrorCode;\r
 }\r
 \r
 /** Function to receive the given data to the device, after a response block has been received.\r
index 2674b6a..6000510 100644 (file)
 \r
                /** Pipe number of the Still Image events pipe */\r
                #define SIMAGE_EVENTS_PIPE             0x03\r
+               \r
+               /** Length in bytes of a given Unicode string's character length\r
+                *\r
+                *  \param[in] chars  Total number of Unicode characters in the string\r
+                */\r
+               #define UNICODE_STRING_LENGTH(chars)   (chars << 1)\r
 \r
                /** Timeout period between the issuing of a command to a device, and the reception of the first packet */\r
                #define COMMAND_DATA_TIMEOUT_MS        5000\r
        /* Function Prototypes: */\r
                void    SImage_SendBlockHeader(void);\r
                uint8_t SImage_RecieveBlockHeader(void);\r
-               void    SImage_RecieveEventHeader(void);\r
-               void    SImage_SendData(void* Buffer, uint16_t Bytes);\r
+               uint8_t SImage_RecieveEventHeader(void);\r
+               uint8_t SImage_SendData(void* Buffer, uint16_t Bytes);\r
                uint8_t SImage_ReadData(void* Buffer, uint16_t Bytes);\r
                bool    SImage_IsEventReceived(void);\r
                uint8_t SImage_ClearPipeStall(const uint8_t EndpointNum);\r
index f10de4c..dfc7cb7 100644 (file)
@@ -216,28 +216,28 @@ void StillImage_Task(void)
                        uint8_t* DeviceInfoPos = DeviceInfo;\r
                        \r
                        /* Skip over the data before the unicode device information strings */\r
-                       DeviceInfoPos += 8;                                      // Skip to VendorExtensionDesc String\r
-                       DeviceInfoPos += ((*DeviceInfoPos << 1) + 1);            // Skip over VendorExtensionDesc String\r
-                       DeviceInfoPos += 2;                                      // Skip over FunctionalMode\r
-                       DeviceInfoPos += (4 + (*(uint32_t*)DeviceInfoPos << 1)); // Skip over OperationCode Array\r
-                       DeviceInfoPos += (4 + (*(uint32_t*)DeviceInfoPos << 1)); // Skip over EventCode Array\r
-                       DeviceInfoPos += (4 + (*(uint32_t*)DeviceInfoPos << 1)); // Skip over DevicePropCode Array\r
-                       DeviceInfoPos += (4 + (*(uint32_t*)DeviceInfoPos << 1)); // Skip over ObjectFormatCode Array\r
-                       DeviceInfoPos += (4 + (*(uint32_t*)DeviceInfoPos << 1)); // Skip over ObjectFormatCode Array\r
+                       DeviceInfoPos +=  8;                                          // Skip to VendorExtensionDesc String\r
+                       DeviceInfoPos += (1 + UNICODE_STRING_LENGTH(*DeviceInfoPos)); // Skip over VendorExtensionDesc String\r
+                       DeviceInfoPos +=  2;                                          // Skip over FunctionalMode\r
+                       DeviceInfoPos += (4 + (*(uint32_t*)DeviceInfoPos << 1));      // Skip over OperationCode Array\r
+                       DeviceInfoPos += (4 + (*(uint32_t*)DeviceInfoPos << 1));      // Skip over EventCode Array\r
+                       DeviceInfoPos += (4 + (*(uint32_t*)DeviceInfoPos << 1));      // Skip over DevicePropCode Array\r
+                       DeviceInfoPos += (4 + (*(uint32_t*)DeviceInfoPos << 1));      // Skip over ObjectFormatCode Array\r
+                       DeviceInfoPos += (4 + (*(uint32_t*)DeviceInfoPos << 1));      // Skip over ObjectFormatCode Array\r
                        \r
                        /* Extract and convert the Manufacturer Unicode string to ASCII and print it through the USART */\r
                        char Manufacturer[*DeviceInfoPos];\r
                        UnicodeToASCII(DeviceInfoPos, Manufacturer);\r
                        printf_P(PSTR("   Manufacturer: %s\r\n"), Manufacturer);\r
 \r
-                       DeviceInfoPos += ((*DeviceInfoPos << 1) + 1);            // Skip over Manufacturer String\r
+                       DeviceInfoPos += 1 + UNICODE_STRING_LENGTH(*DeviceInfoPos);   // Skip over Manufacturer String\r
 \r
                        /* Extract and convert the Model Unicode string to ASCII and print it through the USART */\r
                        char Model[*DeviceInfoPos];\r
                        UnicodeToASCII(DeviceInfoPos, Model);\r
                        printf_P(PSTR("   Model: %s\r\n"), Model);\r
 \r
-                       DeviceInfoPos += ((*DeviceInfoPos << 1) + 1);            // Skip over Model String\r
+                       DeviceInfoPos += 1 + UNICODE_STRING_LENGTH(*DeviceInfoPos);   // Skip over Model String\r
 \r
                        /* Extract and convert the Device Version Unicode string to ASCII and print it through the USART */\r
                        char DeviceVersion[*DeviceInfoPos];\r
index ef903f0..562348b 100644 (file)
@@ -51,7 +51,7 @@ int main(void)
                CheckButton();\r
                CheckTemperature();\r
 \r
-               /* Clear output-compare flag (logic 1 clears the flag) */\r
+               /* Clear millisecond timer's Output Compare flag (logic 1 clears the flag) */\r
                TIFR0 |= (1 << OCF0A);\r
                \r
                USB_USBTask();\r
@@ -114,11 +114,12 @@ void CheckTemperature(void)
 {\r
        static uint16_t MSElapsed = 0;\r
 \r
+       /* Timer 0's compare flag is set every millisecond */\r
        if (TIFR0 & (1 << OCF0A))\r
          MSElapsed++;\r
 \r
        /* Task runs every 10000 ticks, 10 seconds for this demo */\r
-       if (MSElapsed == 1000)\r
+       if (MSElapsed == 10000)\r
        {\r
                printf_P(PSTR("Current temperature: %d Degrees Celcius\r\n\r\n"),\r
                         (int8_t)Temperature_GetTemperature());\r
@@ -135,6 +136,7 @@ void CheckButton(void)
        static uint16_t DebounceMSElapsed = 0;\r
        static bool     IsPressed;\r
        \r
+       /* Timer 0's compare flag is set every millisecond */\r
        if (TIFR0 & (1 << OCF0A))\r
          DebounceMSElapsed++;\r
 \r