Commit 7aaf9b20 authored by Dean Camera's avatar Dean Camera
Browse files

Added new PRNT_Host_BytesReceived() and PRNT_Host_ReceiveByte() functions to...

Added new PRNT_Host_BytesReceived() and PRNT_Host_ReceiveByte() functions to the Print Host Class driver.
parent 6e011f88
......@@ -134,7 +134,7 @@ int main(void)
printf_P(PSTR("Sending Test Page (%d bytes)...\r\n"), TestPageLength);
if (PRNT_Host_SendData(&Printer_PRNT_Interface, &TestPageData, TestPageLength) != PIPE_RWSTREAM_NoError)
if (PRNT_Host_SendString(&Printer_PRNT_Interface, &TestPageData, TestPageLength) != PIPE_RWSTREAM_NoError)
{
puts_P(PSTR("Error Sending Page Data.\r\n"));
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
......
......@@ -56,11 +56,8 @@ uint8_t Printer_SendData(const void* const PrinterCommands,
return ErrorCode;
Pipe_ClearOUT();
while (!(Pipe_IsOUTReady()))
{
if (USB_HostState == HOST_STATE_Unattached)
return PIPE_RWSTREAM_DeviceDisconnected;
}
Pipe_WaitUntilReady();
Pipe_Freeze();
......
......@@ -182,9 +182,9 @@ uint8_t PRNT_Host_SoftReset(USB_ClassInfo_PRNT_Host_t* const PRNTInterfaceInfo)
return USB_Host_SendControlRequest(NULL);
}
uint8_t PRNT_Host_SendData(USB_ClassInfo_PRNT_Host_t* const PRNTInterfaceInfo,
void* PrinterCommands,
const uint16_t CommandSize)
uint8_t PRNT_Host_SendString(USB_ClassInfo_PRNT_Host_t* const PRNTInterfaceInfo,
void* Buffer,
const uint16_t Length)
{
uint8_t ErrorCode;
......@@ -194,19 +194,70 @@ uint8_t PRNT_Host_SendData(USB_ClassInfo_PRNT_Host_t* const PRNTInterfaceInfo,
Pipe_SelectPipe(PRNTInterfaceInfo->Config.DataOUTPipeNumber);
Pipe_Unfreeze();
if ((ErrorCode = Pipe_Write_Stream_LE(PrinterCommands, CommandSize, NO_STREAM_CALLBACK)) != PIPE_RWSTREAM_NoError)
if ((ErrorCode = Pipe_Write_Stream_LE(Buffer, Length, NO_STREAM_CALLBACK)) != PIPE_RWSTREAM_NoError)
return ErrorCode;
Pipe_ClearOUT();
while (!(Pipe_IsOUTReady()))
ErrorCode = Pipe_WaitUntilReady();
Pipe_Freeze();
return ErrorCode;
}
uint16_t PRNT_Host_BytesReceived(USB_ClassInfo_PRNT_Host_t* const PRNTInterfaceInfo)
{
if ((USB_HostState != HOST_STATE_Configured) || !(PRNTInterfaceInfo->State.IsActive))
return 0;
Pipe_SelectPipe(PRNTInterfaceInfo->Config.DataINPipeNumber);
Pipe_Unfreeze();
if (Pipe_IsINReceived())
{
if (USB_HostState == HOST_STATE_Unattached)
return PIPE_RWSTREAM_DeviceDisconnected;
if (!(Pipe_BytesInPipe()))
{
Pipe_ClearIN();
Pipe_Freeze();
return 0;
}
else
{
Pipe_Freeze();
return Pipe_BytesInPipe();
}
}
else
{
Pipe_Freeze();
return 0;
}
}
int16_t PRNT_Host_ReceiveByte(USB_ClassInfo_PRNT_Host_t* const PRNTInterfaceInfo)
{
if ((USB_HostState != HOST_STATE_Configured) || !(PRNTInterfaceInfo->State.IsActive))
return PIPE_RWSTREAM_DeviceDisconnected;
int16_t ReceivedByte = -1;
Pipe_SelectPipe(PRNTInterfaceInfo->Config.DataINPipeNumber);
Pipe_Unfreeze();
if (Pipe_IsINReceived())
{
if (Pipe_BytesInPipe())
ReceivedByte = Pipe_Read_Byte();
if (!(Pipe_BytesInPipe()))
Pipe_ClearIN();
}
Pipe_Freeze();
return PIPE_RWSTREAM_NoError;
return ReceivedByte;
}
uint8_t PRNT_Host_GetDeviceID(USB_ClassInfo_PRNT_Host_t* const PRNTInterfaceInfo,
......
......@@ -167,15 +167,42 @@
* call will fail.
*
* \param[in,out] PRNTInterfaceInfo Pointer to a structure containing a Printer Class host configuration and state.
* \param[in] PrinterCommands Pointer to a buffer containing the raw command stream to send to the printer.
* \param[in] CommandSize Size in bytes of the command stream to be sent.
* \param[in] Buffer Pointer to a buffer containing the raw command stream to send to the printer.
* \param[in] Length Size in bytes of the command stream to be sent.
*
* \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
*/
uint8_t PRNT_Host_SendData(USB_ClassInfo_PRNT_Host_t* const PRNTInterfaceInfo,
void* PrinterCommands,
const uint16_t CommandSize) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);
uint8_t PRNT_Host_SendString(USB_ClassInfo_PRNT_Host_t* const PRNTInterfaceInfo,
void* PrinterCommands,
const uint16_t Length) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);
/** Determines the number of bytes received by the printer interface from the device, waiting to be read. This indicates the number
* of bytes in the IN pipe bank only, and thus the number of calls to \ref PRNT_Host_ReceiveByte() which are guaranteed to succeed
* immediately. If multiple bytes are to be received, they should be buffered by the user application, as the pipe bank will not be
* released back to the USB controller until all bytes are read.
*
* \pre This function must only be called when the Host state machine is in the HOST_STATE_Configured state or the
* call will fail.
*
* \param[in,out] PRNTInterfaceInfo Pointer to a structure containing a Printer Class host configuration and state.
*
* \return Total number of buffered bytes received from the device.
*/
uint16_t PRNT_Host_BytesReceived(USB_ClassInfo_PRNT_Host_t* const PRNTInterfaceInfo);
/** Reads a byte of data from the device. If no data is waiting to be read of if a USB device is not connected, the function
* returns a negative value. The \ref PRNT_Host_BytesReceived() function may be queried in advance to determine how many bytes
* are currently buffered in the Printer interface's data receive pipe.
*
* \pre This function must only be called when the Host state machine is in the HOST_STATE_Configured state or the
* call will fail.
*
* \param[in,out] PRNTInterfaceInfo Pointer to a structure containing a Printer Class host configuration and state.
*
* \return Next received byte from the device, or a negative value if no data received.
*/
int16_t PRNT_Host_ReceiveByte(USB_ClassInfo_PRNT_Host_t* const PRNTInterfaceInfo);
/** Retrieves the attached printer device's ID string, formatted according to IEEE 1284. This string is sent as a
* Unicode string from the device and is automatically converted to an ASCII encoded C string by this function, thus
* the maximum reportable string length is two less than the size given (to accommodate the Unicode string length
......
......@@ -16,6 +16,7 @@
* - Added new USB_Device_GetFrameNumber() and USB_Host_GetFrameNumber() functions to retrieve the current USB frame number
* - Added new USB_Host_EnableSOFEvents(), USB_Host_DisableSOFEvents() and EVENT_USB_Host_StartOfFrame() for the user application
* handling of USB Start of Frame events while in USB Host mode
* - Added new PRNT_Host_BytesReceived() and PRNT_Host_ReceiveByte() functions to the Print Host Class driver
*
* <b>Changed:</b>
* - Removed complicated logic for the Endpoint_ConfigureEndpoint() function to use inlined or function called versions
......
......@@ -23,6 +23,10 @@
* now "const void** const DescriptorAddress". Existing applications should update their callback signatures to match this, and
* eliminate any casting of descriptor pointers to a non-const pointer.
*
* <b>Host Mode</b>
* - The PRNT_Host_SendData() function has been renamed to \ref PRNT_Host_SendString(). Existing applications should simply
* replace all references to the obsolete function name with the new function name.
*
* \section Sec_Migration100807 Migrating from 100513 to 100807
*
* <b>Non-USB Library Components</b>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment