Ejemplo n.º 1
0
/**********************************************************************
* Outline 		: ProcessClassSetupPacket 
* Description 	: Processes a CDC class setup packet.
*				  Provides a buffer if there is a data stage.
* Argument  	: _pSetupPacket - Setup packet.
*				  _pNumBytes - (OUT)Buffer size.
*				  _ppBuffer - (OUT)Buffer.
* Return value  : Error code
**********************************************************************/
static USB_ERR ProcessClassSetupPacket(SetupPacket* _pSetupPacket,
										uint16_t* _pNumBytes,
										uint8_t** _ppBuffer)
{
	USB_ERR err = USB_ERR_OK;
	
	switch(_pSetupPacket->bRequest)
	{
		case GET_LINE_CODING:
		{
			DEBUG_MSG_LOW(("USBCDC: GET_LINE_CODING\r\n"));
				
			/*Data IN response */
			*_pNumBytes = LINE_CODING_DATA_SIZE;
			*_ppBuffer = (uint8_t*)g_LineCoding;
			break;
		}
		case SET_LINE_CODING: /*(Required for hyperterminal)*/
		{
			DEBUG_MSG_LOW(("USBCDC: SET_LINE_CODING\r\n"));
			/*No action required for this request.*/
			/*Data OUT*/
			*_pNumBytes = SET_CONTROL_LINE_STATE_DATA_SIZE;
			*_ppBuffer = g_SET_CONTROL_LINE_STATE_DATA_Buffer;

			USB_set_linecoding_callback( 0 );	// unknown baudrate.

			break;
		}
		case SET_CONTROL_LINE_STATE:
		{
			DEBUG_MSG_LOW(("USBCDC: SET_CONTROL_LINE_STATE\r\n"));
			/*No action required for this request.*/
			/*No data response */
			*_pNumBytes = 0;		
			break;
		}
		default:
		{
			DEBUG_MSG_LOW(("USBCDC: Unsupported Class request %d\r\n",
						 _pSetupPacket->bRequest));
			err = USB_ERR_UNKNOWN_REQUEST;	
		}
	}

	return err;
}
Ejemplo n.º 2
0
/**********************************************************************
* Outline       : CBCable
* Description   : Callback when the USB cable is connected or disconnected.
* Argument      : _bConnected: true = Connected, false = Disconnected.
* Return value  : none
**********************************************************************/
static void CBCable(bool _bConnected)
{
    if(true == _bConnected)
    {
        DEBUG_MSG_LOW( ("USBCDC: Cable Connected\r\n"));

        /* Initialise data - as this is like re-starting */
        InitialiseData();

        g_bConnected = true;
    }
    else
    {
        DEBUG_MSG_LOW( ("USBCDC: Cable Disconnected\r\n"));
        g_bConnected = false;

        /*In case we are waiting on any flags set them here*/
        ReleaseFlags(USB_ERR_NOT_CONNECTED);
    }
}
Ejemplo n.º 3
0
/**********************************************************************
* Outline       : CBError
* Description   : Callback saying that an error has occoured in a
*                   lower layer.
* Argument      : _err - error code.
* Return value  : none
**********************************************************************/
static void CBError(USB_ERR _err)
{
    DEBUG_MSG_LOW(("USBCDC: ***CBError***\r\n"));

    /*If the terminal sends data to us when we're not expecting any
    then would get this and it's not an error.
    However, could be that data is arriving too quick for us to read
    and echo out.*/
    if(USB_ERR_BULK_OUT_NO_BUFFER == _err)
    {
        DEBUG_MSG_LOW(("USBCDC: No Bulk Out Buffer.\r\n"));
    }
    else
    {
        /*Try resetting HAL*/
        USBHAL_Reset();

        /*Release flags in case we are waiting on any*/
        ReleaseFlags(_err);
    }
}
Ejemplo n.º 4
0
/**********************************************************************
* Outline       : CBUnhandledSetupPacket
* Description   : Called from the USB Core when it can't deal with
*                  a setup packet.
*                  Provides a buffer if there is a data stage.
*                  Expect the core to deal with Standard requests so
*                  this should be Class specific.
*                  This is a function of type CB_SETUP_PACKET.
* Argument      : _pSetupPacket - Setup packet.
*                  _pNumBytes - (OUT)Buffer size.
*                  _ppBuffer - (OUT)Buffer.
* Return value  : Error code
**********************************************************************/
static USB_ERR CBUnhandledSetupPacket(SetupPacket* _pSetupPacket,
                                    uint16_t* _pNumBytes,
                                    uint8_t** _ppBuffer)
{
    USB_ERR err;

    switch(EXTRACT_bmRequest_TYPE(_pSetupPacket->bmRequest))
    {
        case REQUEST_CLASS:
        {
            err = ProcessClassSetupPacket(_pSetupPacket, _pNumBytes, _ppBuffer);
            break;
        }
        case REQUEST_VENDOR:
        case REQUEST_STANDARD:
        default:
        {
            DEBUG_MSG_LOW(("USBCDC: Unsupported Request type\r\n"));
            err = USB_ERR_UNKNOWN_REQUEST;
        }
    }

    return err;
}