Make Endpoint control transfers more reliable; early-abort when an incomplete packet is sent from the host (indicating end of transfer), add check for control reads to ensure that no more than wLength bytes are read from the interface.

Condense sequential printf_P/puts_P calls to single printf_P calls for size and clarity.
pull/1469/head
Dean Camera 16 years ago
parent 3848482532
commit c830fcb0e1

@ -158,8 +158,8 @@ void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
{
USB_ShutDown();
puts_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"));
printf_P(PSTR(" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"
" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
for(;;);
@ -170,10 +170,10 @@ void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
*/
void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode)
{
puts_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"));
printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);
printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode);
printf_P(PSTR(" -- In State %d\r\n" ESC_FG_WHITE), USB_HostState);
printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"
" -- Error Code %d\r\n"
" -- Sub Error Code %d\r\n"
" -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState);
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}

@ -160,8 +160,8 @@ void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
{
USB_ShutDown();
puts_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"));
printf_P(PSTR(" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"
" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
for(;;);
@ -172,10 +172,10 @@ void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
*/
void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode)
{
puts_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"));
printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);
printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode);
printf_P(PSTR(" -- In State %d\r\n" ESC_FG_WHITE), USB_HostState);
printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"
" -- Error Code %d\r\n"
" -- Sub Error Code %d\r\n"
" -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState);
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}

@ -98,8 +98,8 @@ void EVENT_USB_Host_HostError(uint8_t ErrorCode)
{
USB_ShutDown();
puts_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"));
printf_P(PSTR(" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"
" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
for(;;);
@ -107,10 +107,10 @@ void EVENT_USB_Host_HostError(uint8_t ErrorCode)
void EVENT_USB_Host_DeviceEnumerationFailed(uint8_t ErrorCode, uint8_t SubErrorCode)
{
puts_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"));
printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);
printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode);
printf_P(PSTR(" -- In State %d\r\n" ESC_FG_WHITE), USB_HostState);
printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"
" -- Error Code %d\r\n"
" -- Sub Error Code %d\r\n"
" -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState);
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
@ -147,8 +147,8 @@ void Bluetooth_Management_Task(void)
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
{
puts_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n"
" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
/* Indicate error via status LEDs */
LEDs_SetAllLEDs(LEDS_LED1);

@ -101,8 +101,8 @@ void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
{
USB_ShutDown();
puts_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"));
printf_P(PSTR(" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"
" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
for(;;);
@ -113,10 +113,10 @@ void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
*/
void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode)
{
puts_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"));
printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);
printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode);
printf_P(PSTR(" -- In State %d\r\n" ESC_FG_WHITE), USB_HostState);
printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"
" -- Error Code %d\r\n"
" -- Sub Error Code %d\r\n"
" -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState);
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
@ -154,8 +154,8 @@ void CDC_Host_Task(void)
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
{
puts_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n"
" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
/* Indicate error via status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);

@ -101,8 +101,8 @@ void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
{
USB_ShutDown();
puts_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"));
printf_P(PSTR(" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"
" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
for(;;);
@ -113,10 +113,10 @@ void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
*/
void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode)
{
puts_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"));
printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);
printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode);
printf_P(PSTR(" -- In State %d\r\n" ESC_FG_WHITE), USB_HostState);
printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"
" -- Error Code %d\r\n"
" -- Sub Error Code %d\r\n"
" -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState);
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
@ -255,8 +255,8 @@ void HID_Host_Task(void)
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
{
puts_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n"
" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
/* Indicate error status */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);

@ -101,8 +101,8 @@ void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
{
USB_ShutDown();
puts_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"));
printf_P(PSTR(" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"
" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
for(;;);
@ -113,10 +113,10 @@ void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
*/
void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode)
{
puts_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"));
printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);
printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode);
printf_P(PSTR(" -- In State %d\r\n" ESC_FG_WHITE), USB_HostState);
printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"
" -- Error Code %d\r\n"
" -- Sub Error Code %d\r\n"
" -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState);
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
@ -216,8 +216,8 @@ void Keyboard_HID_Task(void)
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
{
puts_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n"
" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
/* Indicate error status */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
@ -243,8 +243,8 @@ void Keyboard_HID_Task(void)
/* Send the request, display error and wait for device detach if request fails */
if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)
{
puts_P(PSTR(ESC_FG_RED "Control Error (Set Protocol).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Control Error (Set Protocol).\r\n"
" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
/* Indicate error status */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);

@ -101,8 +101,8 @@ void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
{
USB_ShutDown();
puts_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"));
printf_P(PSTR(" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"
" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
for(;;);
@ -113,10 +113,10 @@ void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
*/
void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode)
{
puts_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"));
printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);
printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode);
printf_P(PSTR(" -- In State %d\r\n" ESC_FG_WHITE), USB_HostState);
printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"
" -- Error Code %d\r\n"
" -- Sub Error Code %d\r\n"
" -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState);
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}

@ -107,8 +107,8 @@ void EVENT_USB_HostError(const uint8_t ErrorCode)
{
USB_ShutDown();
puts_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"));
printf_P(PSTR(" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"
" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
for(;;);
@ -119,10 +119,10 @@ void EVENT_USB_HostError(const uint8_t ErrorCode)
*/
void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode)
{
puts_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"));
printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);
printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode);
printf_P(PSTR(" -- In State %d\r\n" ESC_FG_WHITE), USB_HostState);
printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"
" -- Error Code %d\r\n"
" -- Sub Error Code %d\r\n"
" -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState);
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
@ -160,8 +160,8 @@ void MassStorage_Task(void)
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
{
puts_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n"
" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
/* Indicate error via status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);

@ -101,8 +101,8 @@ void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
{
USB_ShutDown();
puts_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"));
printf_P(PSTR(" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"
" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
for(;;);
@ -113,10 +113,10 @@ void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
*/
void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode)
{
puts_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"));
printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);
printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode);
printf_P(PSTR(" -- In State %d\r\n" ESC_FG_WHITE), USB_HostState);
printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"
" -- Error Code %d\r\n"
" -- Sub Error Code %d\r\n"
" -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState);
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
@ -215,8 +215,8 @@ void Mouse_HID_Task(void)
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
{
puts_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n"
" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
/* Indicate error status */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
@ -242,8 +242,8 @@ void Mouse_HID_Task(void)
/* Send the request, display error and wait for device detach if request fails */
if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)
{
puts_P(PSTR(ESC_FG_RED "Control Error (Set Protocol).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Control Error (Set Protocol).\r\n"
" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
/* Indicate error status */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);

@ -101,8 +101,8 @@ void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
{
USB_ShutDown();
puts_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"));
printf_P(PSTR(" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"
" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
for(;;);
@ -113,10 +113,10 @@ void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
*/
void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode)
{
puts_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"));
printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);
printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode);
printf_P(PSTR(" -- In State %d\r\n" ESC_FG_WHITE), USB_HostState);
printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"
" -- Error Code %d\r\n"
" -- Sub Error Code %d\r\n"
" -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState);
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
@ -155,8 +155,8 @@ void Mouse_HID_Task(void)
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
{
puts_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n"
" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
/* Indicate error via status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
@ -171,8 +171,8 @@ void Mouse_HID_Task(void)
/* Get and process the device's first HID report descriptor */
if ((ErrorCode = GetHIDReportData()) != ParseSuccessful)
{
puts_P(PSTR(ESC_FG_RED "Report Parse Error.\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Report Parse Error.\r\n"
" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
/* Indicate error via status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);

@ -101,8 +101,8 @@ void EVENT_USB_Host_HostError(uint8_t ErrorCode)
{
USB_ShutDown();
puts_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"));
printf_P(PSTR(" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"
" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
for(;;);
@ -113,10 +113,10 @@ void EVENT_USB_Host_HostError(uint8_t ErrorCode)
*/
void EVENT_USB_Host_DeviceEnumerationFailed(uint8_t ErrorCode, uint8_t SubErrorCode)
{
puts_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"));
printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);
printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode);
printf_P(PSTR(" -- In State %d\r\n" ESC_FG_WHITE), USB_HostState);
printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"
" -- Error Code %d\r\n"
" -- Sub Error Code %d\r\n"
" -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState);
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
@ -157,8 +157,8 @@ void USB_Printer_Host(void)
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
{
puts_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n"
" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
/* Indicate error via status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
@ -183,8 +183,8 @@ void USB_Printer_Host(void)
if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)
{
puts_P(PSTR(ESC_FG_RED "Control Error (Set Interface).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Control Error (Set Interface).\r\n"
" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
/* Indicate error via status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
@ -200,8 +200,8 @@ void USB_Printer_Host(void)
char DeviceIDString[256];
if ((ErrorCode = Printer_GetDeviceID(DeviceIDString, sizeof(DeviceIDString))) != HOST_SENDCONTROL_Successful)
{
puts_P(PSTR(ESC_FG_RED "Control Error (Get DeviceID).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Control Error (Get DeviceID).\r\n"
" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
/* Indicate error via status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
@ -231,8 +231,8 @@ void USB_Printer_Host(void)
if ((ErrorCode = Printer_SendData(&TestPageData)) != PIPE_RWSTREAM_NoError)
{
puts_P(PSTR(ESC_FG_RED "Error Sending Test Page.\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Error Sending Test Page.\r\n"
" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
/* Indicate error via status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);

@ -102,8 +102,8 @@ void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
{
USB_ShutDown();
puts_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"));
printf_P(PSTR(" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"
" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
for(;;);
@ -114,10 +114,10 @@ void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
*/
void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode)
{
puts_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"));
printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);
printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode);
printf_P(PSTR(" -- In State %d\r\n" ESC_FG_WHITE), USB_HostState);
printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"
" -- Error Code %d\r\n"
" -- Sub Error Code %d\r\n"
" -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState);
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
@ -155,8 +155,8 @@ void StillImage_Task(void)
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
{
puts_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n"
" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
/* Indicate error via status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
@ -367,8 +367,8 @@ void ShowCommandError(uint8_t ErrorCode, bool ResponseCodeError)
{
char* FailureType = ((ResponseCodeError) ? PSTR("Response Code != OK") : PSTR("Transaction Fail"));
printf_P(PSTR(ESC_FG_RED "Command Error (%S).\r\n"), FailureType);
printf_P(PSTR(" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED "Command Error (%S).\r\n"
" -- Error Code %d\r\n" ESC_FG_WHITE), FailureType, ErrorCode);
/* Indicate error via status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);

@ -88,8 +88,8 @@ void EVENT_USB_InitFailure(const uint8_t ErrorCode)
else
ModeStrPtr = PSTR("N/A");
printf_P(PSTR(" -- Mode %S\r\n"), ModeStrPtr);
printf_P(PSTR(" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(" -- Mode %S\r\n"
" -- Error Code %d\r\n" ESC_FG_WHITE), ModeStrPtr, ErrorCode);
Abort_Program();
}
@ -127,10 +127,12 @@ void EVENT_USB_Device_Reset(void)
/** Event handler for the USB_Device_UnhandledControlRequest event. When fired, the event is logged to the USART. */
void EVENT_USB_Device_UnhandledControlRequest(void)
{
puts_P(PSTR(ESC_FG_YELLOW EVENT_PREFIX "Ctrl Request\r\n"));
printf_P(PSTR(" -- Req Data %d\r\n"), USB_ControlRequest.bRequest);
printf_P(PSTR(" -- Req Type %d\r\n"), USB_ControlRequest.bmRequestType);
printf_P(PSTR(" -- Req Length %d\r\n" ESC_FG_WHITE), USB_ControlRequest.wLength);
printf_P(PSTR(ESC_FG_YELLOW EVENT_PREFIX "Ctrl Request\r\n"
" -- Req Data %d\r\n"
" -- Req Type %d\r\n"
" -- Req Length %d\r\n" ESC_FG_WHITE), USB_ControlRequest.bRequest,
USB_ControlRequest.bmRequestType,
USB_ControlRequest.wLength);
}
/** Event handler for the USB_Device_ConfigurationChanged event. When fired, the event is logged to the USART. */
@ -145,8 +147,8 @@ void EVENT_USB_Device_ConfigurationChanged(void)
*/
void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
{
puts_P(PSTR(ESC_FG_RED EVENT_PREFIX "Host Mode Error\r\n"));
printf_P(PSTR(" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
printf_P(PSTR(ESC_FG_RED EVENT_PREFIX "Host Mode Error\r\n"
" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
Abort_Program();
}
@ -154,10 +156,10 @@ void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
/** Event handler for the USB_Host_DeviceEnumerationFailed event. When fired, the event is logged to the USART. */
void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode)
{
puts_P(PSTR(ESC_FG_RED EVENT_PREFIX "Dev Enum Error\r\n"));
printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);
printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode);
printf_P(PSTR(" -- In State %d\r\n" ESC_FG_WHITE), USB_HostState);
printf_P(PSTR(ESC_FG_RED EVENT_PREFIX "Dev Enum Error\r\n"
" -- Error Code %d\r\n"
" -- Sub Error Code %d\r\n"
" -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState);
}
/** Event handler for the USB_Host_DeviceEnumerationComplete event. When fired, the event is logged to the USART. */

@ -1,8 +1,12 @@
uint8_t TEMPLATE_FUNC_NAME (void* Buffer, uint16_t Length)
{
uint8_t* DataStream = (uint8_t*)(Buffer + TEMPLATE_BUFFER_OFFSET(Length));
uint8_t* DataStream = (uint8_t*)(Buffer + TEMPLATE_BUFFER_OFFSET(Length));
bool LastPacketFull = false;
while (Length)
if (Length > USB_ControlRequest.wLength)
Length = USB_ControlRequest.wLength;
while (Length || LastPacketFull)
{
if (Endpoint_IsSETUPReceived())
return ENDPOINT_RWCSTREAM_HostAborted;
@ -12,6 +16,8 @@ uint8_t TEMPLATE_FUNC_NAME (void* Buffer, uint16_t Length)
if (Endpoint_IsOUTReceived())
{
LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);
while (Length && Endpoint_BytesInEndpoint())
{
TEMPLATE_TRANSFER_BYTE(DataStream);
@ -19,6 +25,9 @@ uint8_t TEMPLATE_FUNC_NAME (void* Buffer, uint16_t Length)
}
Endpoint_ClearOUT();
if (!(LastPacketFull))
Length = 0;
}
}

Loading…
Cancel
Save