From 8a68203d3451c50c573c6baf4850e72d8dbabfcb Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Mon, 20 Jul 2009 02:27:32 +0000 Subject: Added error codes to most StillImageHost demo commands. --- .../LowLevel/StillImageHost/Lib/StillImageCommands.c | 16 ++++++++++++---- .../LowLevel/StillImageHost/Lib/StillImageCommands.h | 10 ++++++++-- Demos/Host/LowLevel/StillImageHost/StillImageHost.c | 20 ++++++++++---------- 3 files changed, 30 insertions(+), 16 deletions(-) (limited to 'Demos/Host/LowLevel') diff --git a/Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.c b/Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.c index bf8575084..c0a9575f4 100644 --- a/Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.c +++ b/Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.c @@ -80,20 +80,24 @@ void SImage_SendBlockHeader(void) } /** Function to receive a PIMA event container from the attached still image device. */ -void SImage_RecieveEventHeader(void) +uint8_t SImage_RecieveEventHeader(void) { + uint8_t ErrorCode; + /* Unfreeze the events pipe */ Pipe_SelectPipe(SIMAGE_EVENTS_PIPE); Pipe_Unfreeze(); /* Read in the event data into the global structure */ - Pipe_Read_Stream_LE(&PIMA_EventBlock, sizeof(PIMA_EventBlock)); + ErrorCode = Pipe_Read_Stream_LE(&PIMA_EventBlock, sizeof(PIMA_EventBlock)); /* Clear the pipe after read complete to prepare for next event */ Pipe_ClearIN(); /* Freeze the event pipe again after use */ Pipe_Freeze(); + + return ErrorCode; } /** Function to receive a PIMA response container from the attached still image device. */ @@ -193,20 +197,24 @@ uint8_t SImage_RecieveBlockHeader(void) * \param[in] Buffer Source data buffer to send to the device * \param[in] Bytes Number of bytes to send */ -void SImage_SendData(void* Buffer, uint16_t Bytes) +uint8_t SImage_SendData(void* Buffer, uint16_t Bytes) { + uint8_t ErrorCode; + /* Unfreeze the data OUT pipe */ Pipe_SelectPipe(SIMAGE_DATA_OUT_PIPE); Pipe_Unfreeze(); /* Write the data contents to the pipe */ - Pipe_Write_Stream_LE(Buffer, Bytes); + ErrorCode = Pipe_Write_Stream_LE(Buffer, Bytes); /* Send the last packet to the attached device */ Pipe_ClearOUT(); /* Freeze the pipe again after use */ Pipe_Freeze(); + + return ErrorCode; } /** Function to receive the given data to the device, after a response block has been received. diff --git a/Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.h b/Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.h index 2674b6aa5..600051051 100644 --- a/Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.h +++ b/Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.h @@ -50,6 +50,12 @@ /** Pipe number of the Still Image events pipe */ #define SIMAGE_EVENTS_PIPE 0x03 + + /** Length in bytes of a given Unicode string's character length + * + * \param[in] chars Total number of Unicode characters in the string + */ + #define UNICODE_STRING_LENGTH(chars) (chars << 1) /** Timeout period between the issuing of a command to a device, and the reception of the first packet */ #define COMMAND_DATA_TIMEOUT_MS 5000 @@ -101,8 +107,8 @@ /* Function Prototypes: */ void SImage_SendBlockHeader(void); uint8_t SImage_RecieveBlockHeader(void); - void SImage_RecieveEventHeader(void); - void SImage_SendData(void* Buffer, uint16_t Bytes); + uint8_t SImage_RecieveEventHeader(void); + uint8_t SImage_SendData(void* Buffer, uint16_t Bytes); uint8_t SImage_ReadData(void* Buffer, uint16_t Bytes); bool SImage_IsEventReceived(void); uint8_t SImage_ClearPipeStall(const uint8_t EndpointNum); diff --git a/Demos/Host/LowLevel/StillImageHost/StillImageHost.c b/Demos/Host/LowLevel/StillImageHost/StillImageHost.c index f10de4c31..dfc7cb7c1 100644 --- a/Demos/Host/LowLevel/StillImageHost/StillImageHost.c +++ b/Demos/Host/LowLevel/StillImageHost/StillImageHost.c @@ -216,28 +216,28 @@ void StillImage_Task(void) uint8_t* DeviceInfoPos = DeviceInfo; /* Skip over the data before the unicode device information strings */ - DeviceInfoPos += 8; // Skip to VendorExtensionDesc String - DeviceInfoPos += ((*DeviceInfoPos << 1) + 1); // Skip over VendorExtensionDesc String - DeviceInfoPos += 2; // Skip over FunctionalMode - DeviceInfoPos += (4 + (*(uint32_t*)DeviceInfoPos << 1)); // Skip over OperationCode Array - DeviceInfoPos += (4 + (*(uint32_t*)DeviceInfoPos << 1)); // Skip over EventCode Array - DeviceInfoPos += (4 + (*(uint32_t*)DeviceInfoPos << 1)); // Skip over DevicePropCode Array - DeviceInfoPos += (4 + (*(uint32_t*)DeviceInfoPos << 1)); // Skip over ObjectFormatCode Array - DeviceInfoPos += (4 + (*(uint32_t*)DeviceInfoPos << 1)); // Skip over ObjectFormatCode Array + DeviceInfoPos += 8; // Skip to VendorExtensionDesc String + DeviceInfoPos += (1 + UNICODE_STRING_LENGTH(*DeviceInfoPos)); // Skip over VendorExtensionDesc String + DeviceInfoPos += 2; // Skip over FunctionalMode + DeviceInfoPos += (4 + (*(uint32_t*)DeviceInfoPos << 1)); // Skip over OperationCode Array + DeviceInfoPos += (4 + (*(uint32_t*)DeviceInfoPos << 1)); // Skip over EventCode Array + DeviceInfoPos += (4 + (*(uint32_t*)DeviceInfoPos << 1)); // Skip over DevicePropCode Array + DeviceInfoPos += (4 + (*(uint32_t*)DeviceInfoPos << 1)); // Skip over ObjectFormatCode Array + DeviceInfoPos += (4 + (*(uint32_t*)DeviceInfoPos << 1)); // Skip over ObjectFormatCode Array /* Extract and convert the Manufacturer Unicode string to ASCII and print it through the USART */ char Manufacturer[*DeviceInfoPos]; UnicodeToASCII(DeviceInfoPos, Manufacturer); printf_P(PSTR(" Manufacturer: %s\r\n"), Manufacturer); - DeviceInfoPos += ((*DeviceInfoPos << 1) + 1); // Skip over Manufacturer String + DeviceInfoPos += 1 + UNICODE_STRING_LENGTH(*DeviceInfoPos); // Skip over Manufacturer String /* Extract and convert the Model Unicode string to ASCII and print it through the USART */ char Model[*DeviceInfoPos]; UnicodeToASCII(DeviceInfoPos, Model); printf_P(PSTR(" Model: %s\r\n"), Model); - DeviceInfoPos += ((*DeviceInfoPos << 1) + 1); // Skip over Model String + DeviceInfoPos += 1 + UNICODE_STRING_LENGTH(*DeviceInfoPos); // Skip over Model String /* Extract and convert the Device Version Unicode string to ASCII and print it through the USART */ char DeviceVersion[*DeviceInfoPos]; -- cgit v1.2.3