X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/ac70ddd0a1c412bb54def48e53caaebd0b5c9c61..d11ed10c5314c44dc01c06954d1d73d4894cbff8:/Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.c diff --git a/Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.c b/Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.c index 8f05e48f4..62f3659a6 100644 --- a/Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.c +++ b/Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.c @@ -1,21 +1,21 @@ /* LUFA Library - Copyright (C) Dean Camera, 2009. + Copyright (C) Dean Camera, 2010. dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ /* - Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, and distribute this software - and its documentation for any purpose and without fee is hereby - granted, provided that the above copyright notice appear in all - copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + Copyright 2010 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 @@ -37,7 +37,6 @@ #include "StillImageCommands.h" -/* Globals: */ /** PIMA block container for the block to send to the device */ PIMA_Container_t PIMA_SendBlock; @@ -79,25 +78,35 @@ void SImage_SendBlockHeader(void) Pipe_Freeze(); } -/** Function to receive a PIMA event container from the attached still image device. */ -void SImage_RecieveEventHeader(void) +/** Function to receive a PIMA event container from the attached still image device. + * + * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum + */ +uint8_t SImage_ReceiveEventHeader(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. */ -uint8_t SImage_RecieveBlockHeader(void) +/** Function to receive a PIMA response container from the attached still image device. + * + * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum + */ +uint8_t SImage_ReceiveBlockHeader(void) { uint16_t TimeoutMSRem = COMMAND_DATA_TIMEOUT_MS; @@ -123,45 +132,39 @@ uint8_t SImage_RecieveBlockHeader(void) } } + Pipe_Freeze(); Pipe_SelectPipe(SIMAGE_DATA_OUT_PIPE); + Pipe_Unfreeze(); /* Check if pipe stalled (command failed by device) */ if (Pipe_IsStalled()) { /* Clear the stall condition on the OUT pipe */ - SImage_ClearPipeStall(SIMAGE_DATA_OUT_PIPE); + USB_Host_ClearPipeStall(SIMAGE_DATA_OUT_PIPE); /* Return error code and break out of the loop */ return PIPE_RWSTREAM_PipeStalled; } + Pipe_Freeze(); Pipe_SelectPipe(SIMAGE_DATA_IN_PIPE); + Pipe_Unfreeze(); /* Check if pipe stalled (command failed by device) */ if (Pipe_IsStalled()) { /* Clear the stall condition on the IN pipe */ - SImage_ClearPipeStall(SIMAGE_DATA_IN_PIPE); + USB_Host_ClearPipeStall(SIMAGE_DATA_IN_PIPE); /* Return error code */ return PIPE_RWSTREAM_PipeStalled; } /* Check to see if the device was disconnected, if so exit function */ - if (!(USB_IsConnected)) - { - /* Return error code */ - return PIPE_RWSTREAM_DeviceDisconnected; - } - }; - - /* Freeze OUT pipe after use */ - Pipe_SelectPipe(SIMAGE_DATA_OUT_PIPE); - Pipe_Freeze(); - - /* Select the IN data pipe for data reception */ - Pipe_SelectPipe(SIMAGE_DATA_IN_PIPE); - + if (USB_HostState == HOST_STATE_Unattached) + return PIPE_RWSTREAM_DeviceDisconnected; + } + /* Load in the response from the attached device */ Pipe_Read_Stream_LE(&PIMA_ReceivedBlock, PIMA_COMMAND_SIZE(0)); @@ -190,29 +193,35 @@ uint8_t SImage_RecieveBlockHeader(void) /** Function to send the given data to the device, after a command block has been issued. * - * \param Buffer Source data buffer to send to the device - * \param Bytes Number of bytes to send + * \param[in] Buffer Source data buffer to send to the device + * \param[in] Bytes Number of bytes to send + * + * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum */ -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. * - * \param Buffer Destination data buffer to put read bytes from the device - * \param Bytes Number of bytes to receive + * \param[out] Buffer Destination data buffer to put read bytes from the device + * \param[in] Bytes Number of bytes to receive * * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum */ @@ -254,26 +263,3 @@ bool SImage_IsEventReceived(void) return IsEventReceived; } - -/** Clears the stall condition in the attached device on the nominated endpoint number. - * - * \param EndpointNum Endpoint number in the attached device whose stall condition is to be cleared - * - * \return A value from the USB_Host_SendControlErrorCodes_t enum - */ -uint8_t SImage_ClearPipeStall(const uint8_t EndpointNum) -{ - USB_ControlRequest = (USB_Request_Header_t) - { - .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT), - .bRequest = REQ_ClearFeature, - .wValue = FEATURE_ENDPOINT_HALT, - .wIndex = EndpointNum, - .wLength = 0, - }; - - /* Select the control pipe for the request transfer */ - Pipe_SelectPipe(PIPE_CONTROLPIPE); - - return USB_Host_SendControlRequest(NULL); -}