123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- #include "StillImageCommands.h"
- PIMA_Container_t PIMA_SendBlock;
- PIMA_Container_t PIMA_ReceivedBlock;
- PIMA_Container_t PIMA_EventBlock;
- void SImage_SendBlockHeader(void)
- {
-
- Pipe_SelectPipe(SIMAGE_DATA_OUT_PIPE);
- Pipe_Unfreeze();
-
- Pipe_Write_Stream_LE(&PIMA_SendBlock, PIMA_COMMAND_SIZE(0), NULL);
-
- if (PIMA_SendBlock.Type == PIMA_CONTAINER_CommandBlock)
- {
-
- uint8_t ParamBytes = (PIMA_SendBlock.DataLength - PIMA_COMMAND_SIZE(0));
-
- if (ParamBytes)
- {
-
- Pipe_Write_Stream_LE(&PIMA_SendBlock.Params, ParamBytes, NULL);
- }
-
- Pipe_ClearOUT();
- }
-
- Pipe_Freeze();
- }
- uint8_t SImage_ReceiveEventHeader(void)
- {
- uint8_t ErrorCode;
-
- Pipe_SelectPipe(SIMAGE_EVENTS_PIPE);
- Pipe_Unfreeze();
-
- ErrorCode = Pipe_Read_Stream_LE(&PIMA_EventBlock, sizeof(PIMA_EventBlock), NULL);
-
- Pipe_ClearIN();
-
- Pipe_Freeze();
- return ErrorCode;
- }
- uint8_t SImage_ReceiveBlockHeader(void)
- {
- uint16_t TimeoutMSRem = COMMAND_DATA_TIMEOUT_MS;
- uint16_t PreviousFrameNumber = USB_Host_GetFrameNumber();
-
- Pipe_SelectPipe(SIMAGE_DATA_IN_PIPE);
- Pipe_Unfreeze();
-
- while (!(Pipe_IsINReceived()))
- {
- uint16_t CurrentFrameNumber = USB_Host_GetFrameNumber();
-
- if (CurrentFrameNumber != PreviousFrameNumber)
- {
-
- PreviousFrameNumber = CurrentFrameNumber;
- TimeoutMSRem--;
-
- if (!(TimeoutMSRem))
- return PIPE_RWSTREAM_Timeout;
- }
- Pipe_Freeze();
- Pipe_SelectPipe(SIMAGE_DATA_OUT_PIPE);
- Pipe_Unfreeze();
-
- if (Pipe_IsStalled())
- {
-
- USB_Host_ClearEndpointStall(Pipe_GetBoundEndpointAddress());
-
- return PIPE_RWSTREAM_PipeStalled;
- }
- Pipe_Freeze();
- Pipe_SelectPipe(SIMAGE_DATA_IN_PIPE);
- Pipe_Unfreeze();
-
- if (Pipe_IsStalled())
- {
-
- USB_Host_ClearEndpointStall(Pipe_GetBoundEndpointAddress());
-
- return PIPE_RWSTREAM_PipeStalled;
- }
-
- if (USB_HostState == HOST_STATE_Unattached)
- return PIPE_RWSTREAM_DeviceDisconnected;
- }
-
- Pipe_Read_Stream_LE(&PIMA_ReceivedBlock, PIMA_COMMAND_SIZE(0), NULL);
-
- if (PIMA_ReceivedBlock.Type == PIMA_CONTAINER_ResponseBlock)
- {
-
- uint8_t ParamBytes = (PIMA_ReceivedBlock.DataLength - PIMA_COMMAND_SIZE(0));
-
- if (ParamBytes)
- {
-
- Pipe_Read_Stream_LE(&PIMA_ReceivedBlock.Params, ParamBytes, NULL);
- }
-
- Pipe_ClearIN();
- }
-
- Pipe_Freeze();
- return PIPE_RWSTREAM_NoError;
- }
- uint8_t SImage_SendData(void* const Buffer,
- const uint16_t Bytes)
- {
- uint8_t ErrorCode;
-
- Pipe_SelectPipe(SIMAGE_DATA_OUT_PIPE);
- Pipe_Unfreeze();
-
- ErrorCode = Pipe_Write_Stream_LE(Buffer, Bytes, NULL);
-
- Pipe_ClearOUT();
-
- Pipe_Freeze();
- return ErrorCode;
- }
- uint8_t SImage_ReadData(void* const Buffer,
- const uint16_t Bytes)
- {
- uint8_t ErrorCode;
-
- Pipe_SelectPipe(SIMAGE_DATA_IN_PIPE);
- Pipe_Unfreeze();
-
- ErrorCode = Pipe_Read_Stream_LE(Buffer, Bytes, NULL);
-
- Pipe_Freeze();
- return ErrorCode;
- }
- bool SImage_IsEventReceived(void)
- {
- bool IsEventReceived = false;
-
- Pipe_SelectPipe(SIMAGE_EVENTS_PIPE);
- Pipe_Unfreeze();
-
- if (Pipe_BytesInPipe())
- IsEventReceived = true;
-
- Pipe_Freeze();
- return IsEventReceived;
- }
|