Beispiel #1
0
/**
 * Initializes the HID Mouse %device driver.
 * \param pDescriptors Pointer to descriptor list for the HID Mouse.
 */
void HIDDMouseDriver_Initialize(const USBDDriverDescriptors *pDescriptors)
{
    HIDDMouseDriver* pMouse = &hiddMouseDriver;
    HIDDFunction* pHidd = &pMouse->hidDrv;
    USBDDriver* pUsbd = USBD_GetDriver();

    /* One input report */
    pMouse->inputReports[0] = (HIDDReport*)&hiddInputReport;
    HIDDFunction_InitializeReport(pMouse->inputReports[0],
                                  HIDDMouseDriver_REPORTDESCRIPTORSIZE,
                                  0,
                                  0, 0);

    /* Initialize USBD Driver instance */
    USBDDriver_Initialize(pUsbd,
                          pDescriptors,
                          0); /* Multiple interface settings not supported */
    /* Function initialize */
    HIDDFunction_Initialize(pHidd,
                            pUsbd, 0,
                            hiddReportDescriptor,
                            (HIDDReport**)(&pMouse->inputReports), 1,
                            0, 0);
    USBD_Init();
}
/**
 * Initializes the USB device composite device driver.
 * \param  pDescriptors Pointer to Descriptors list for CDC Serial Device.
 */
void DUALCDCDDriver_Initialize(const USBDDriverDescriptors *pDescriptors)
{
    USBDDriver *pUsbd = USBD_GetDriver();
    CDCDSerialPort *pCdcd = &dualcdcdDriver.cdcdSerialPort[0];

    TRACE_INFO("DUALCDCDDriver_Initialize\n\r");

    pCdcd = &dualcdcdDriver.cdcdSerialPort[0];
    CDCDSerialPort_Initialize(pCdcd, pUsbd,
                              0,
                              0,
                              DUALCDCDDriverDescriptors_INTERFACENUM0, 2);

    pCdcd = &dualcdcdDriver.cdcdSerialPort[1];
    CDCDSerialPort_Initialize(pCdcd, pUsbd,
                              0,
                              0,
                              DUALCDCDDriverDescriptors_INTERFACENUM1, 2);

    /*  Initialize the standard USB driver */
    USBDDriver_Initialize(pUsbd,
                          pDescriptors,
                          0);
    /*  Initialize the USB driver */
    USBD_Init();
}
/**
 * Initializes the HID Transfer %device driver.
 * \param pDescriptors Pointer to USBDDriverDescriptors instance.
 */
void HIDDTransferDriver_Initialize(const USBDDriverDescriptors * pDescriptors)
{
    HIDDTransferDriver * pDrv = &hiddTransferDriver;
    USBDDriver *pUsbd = USBD_GetDriver();

    /* One input report */
    pDrv->inputReports[0] = (HIDDReport*)&inputReport;
    HIDDFunction_InitializeReport((HIDDReport *)pDrv->inputReports[0],
                                  HIDDTransferDriver_REPORTSIZE,
                                  0,
                                  0, 0);
    /* One output report */
    pDrv->outputReports[0] = (HIDDReport*)&outputReport;
    HIDDFunction_InitializeReport((HIDDReport *)pDrv->outputReports[0],
                                  HIDDTransferDriver_REPORTSIZE,
                                  0,
                                  0, 0);

    /* Initialize USBD Driver instance */
    USBDDriver_Initialize(pUsbd,
                          pDescriptors,
                          0); /* Multiple interface settings not supported */
    /* Function instance initialize */
    HIDDFunction_Initialize(&pDrv->hidFunction,
                            pUsbd, 0,
                            hiddTransferReportDescriptor,
                            (HIDDReport **)(&pDrv->inputReports), 1,
                            (HIDDReport **)(&pDrv->outputReports), 1);
    /* Initialize USBD */
    USBD_Init();
}
Beispiel #4
0
/**
 * Initializes the MSD driver and the associated USB driver.
 * \param  pDescriptors Pointer to Descriptors list for MSD Device.
 * \param  pLuns        Pointer to a list of LUNs
 * \param  numLuns      Number of LUN in list
 * \see MSDLun
 */
void MSDDriver_Initialize(
	const USBDDriverDescriptors *pDescriptors,
	MSDLun *pLuns, unsigned char numLuns)
{
	USBDDriver *pUsbd = USBD_GetDriver();
	USBDDriver_Initialize(pUsbd, pDescriptors, 0);
	MSDFunction_Initialize(pUsbd, 0, pLuns, numLuns);
	USBD_Init();
}
Beispiel #5
0
/**
 * Starts a remote wake-up sequence if the host has explicitely enabled it
 * by sending the appropriate SET_FEATURE request.
 */
void CDCHIDDDriver_RemoteWakeUp(void)
{
	USBDDriver *pUsbd = USBD_GetDriver();

	/* Remote wake-up has been enabled */
	if (USBDDriver_IsRemoteWakeUpEnabled(pUsbd))

		USBD_RemoteWakeUp();
}
Beispiel #6
0
/**
 * Handler for incoming SETUP requests on default Control endpoint 0.
 *
 * Standard requests are forwarded to the USBDDriver_RequestHandler
 * method.
 * \param  pMsdDriver  Pointer to MSDDriver instance.
 * \param  request Pointer to a USBGenericRequest instance
 */
void MSDDriver_RequestHandler(
	const USBGenericRequest *request)
{
	USBDDriver *pUsbd = USBD_GetDriver();
	TRACE_INFO_WP("NewReq ");

	if (MSDFunction_RequestHandler(request))
		USBDDriver_RequestHandler(pUsbd, request);
}
Beispiel #7
0
/**
 * Invoked when the configuration of the device changes. Resets the mass
 * storage driver.
 * \param  pMsdDriver  Pointer to MSDDriver instance.
 * \param  cfgnum      New configuration number.
 */
void MSDDriver_ConfigurationChangeHandler(
	uint8_t cfgnum)
{
	USBDDriver *pUsbd = USBD_GetDriver();
	USBConfigurationDescriptor *pDesc;

	if (cfgnum) {
		pDesc = USBDDriver_GetCfgDescriptors(pUsbd, cfgnum);
		MSDFunction_Configure((USBGenericDescriptor *)pDesc,
							  pDesc->wTotalLength);
	}
}
/**
 * Invoked whenever the configuration value of a device is changed by the host
 * \param cfgnum Configuration number.
 */
void HIDMSDDriver_ConfigurationChangedHandler(uint8_t cfgnum)
{
    USBDDriver *pUsbd = USBD_GetDriver();
    USBConfigurationDescriptor *pDesc;
    if (cfgnum > 0) {
        pDesc = USBDDriver_GetCfgDescriptors(pUsbd, cfgnum);
        /* HID */
        HIDDKeyboard_ConfigureFunction((USBGenericDescriptor*)pDesc,
                                        pDesc->wTotalLength);
        /* MSD */
        MSDFunction_Configure((USBGenericDescriptor*)pDesc,
                              pDesc->wTotalLength);
    }
}
/**
 * Invoked whenever the configuration value of a device is changed by the host
 * \param cfgnum Configuration number.
 */
void CDCMSDDriver_ConfigurationChangedHandler(unsigned char cfgnum)
{
    USBDDriver *pUsbd = USBD_GetDriver();
    USBConfigurationDescriptor *pDesc;
    if (cfgnum > 0) {
        pDesc = USBDDriver_GetCfgDescriptors(pUsbd, cfgnum);
        /* CDC */
        CDCDSerial_ConfigureFunction((USBGenericDescriptor*)pDesc,
                                      pDesc->wTotalLength);
        /* MSD */
        MSDFunction_Configure((USBGenericDescriptor*)pDesc,
                              pDesc->wTotalLength);
    }
}
Beispiel #10
0
/**
 * Handles composite-specific USB requests sent by the host, and forwards
 * standard ones to the USB device driver.
 * \param request Pointer to a USBGenericRequest instance.
 */
void HIDAUDDDriver_RequestHandler(const USBGenericRequest *request)
{
	USBDDriver *pUsbd = USBD_GetDriver();

	TRACE_INFO_WP("NewReq ");

	if (HIDDKeyboard_RequestHandler(request) == USBRC_SUCCESS)
		return;

	if (AUDDFunction_RequestHandler(request) == USBRC_SUCCESS)
		return;

	USBDDriver_RequestHandler(pUsbd, request);
}
/**
 * Handles CDCMSD-specific USB requests sent by the host, and forwards
 * standard ones to the USB device driver.
 * \param request Pointer to a USBGenericRequest instance.
 */
void CDCMSDDriver_RequestHandler(const USBGenericRequest *request)
{
    USBDDriver *pUsbd = USBD_GetDriver();

    TRACE_INFO_WP("NewReq ");

    if (CDCDSerial_RequestHandler(request) == USBRC_SUCCESS)
        return;

    if (MSDFunction_RequestHandler(request) == USBRC_SUCCESS)
        return;

    USBDDriver_RequestHandler(pUsbd, request);
}
/**
 * Starts a remote wake-up sequence if the host has explicitely enabled it
 * by sending the appropriate SET_FEATURE request.
 */
void HIDMSDDriver_RemoteWakeUp(void)
{
    USBDDriver *pUsbd = USBD_GetDriver();

    /* Remote wake-up has been enabled */
    if (USBDDriver_IsRemoteWakeUpEnabled(pUsbd)) {

        USBD_RemoteWakeUp();
    }
    /* Remote wake-up NOT enabled */
    else {

        TRACE_WARNING("HIDMSDDDriver_RemoteWakeUp: not enabled\n\r");
    }
}
Beispiel #13
0
/**
 * Initializes the USB device composite device driver.
 */
void HIDAUDDDriver_Initialize(const USBDDriverDescriptors *pDescriptors)
{
	USBDDriver *pUsbd = USBD_GetDriver();

	/* Initialize the standard USB driver */
	USBDDriver_Initialize(pUsbd,
						  pDescriptors,
						  bAltInterfaces);

	/* HID */
	HIDDKeyboard_Initialize(pUsbd, HIDAUDDDriverDescriptors_HID_INTERFACE);
	/* Audio */
	AUDDFunction_Initialize(pUsbd, HIDAUDDDriverDescriptors_AUD_INTERFACE);

	/* Initialize the USB driver */
	USBD_Init();
}
/**
 * Initializes the USB device composite device driver.
 */
void CDCAUDDDriver_Initialize(const USBDDriverDescriptors *pDescriptors)
{
    USBDDriver *pUsbd = USBD_GetDriver();

    /* Initialize the standard USB driver */
    USBDDriver_Initialize(pUsbd,
                          pDescriptors,
                          bAltInterfaces);

    /* CDC */
    CDCDSerial_Initialize(pUsbd, CDCAUDDDriverDescriptors_CDC_INTERFACE);
    /* Audio */
    AUDDFunction_Initialize(pUsbd, CDCAUDDDriverDescriptors_AUD_INTERFACE);

    /* Initialize the USB driver */
    USBD_Init();
}
Beispiel #15
0
/**
 * Initializes the USB device composite device driver.
 */
void CDCHIDDDriver_Initialize(const USBDDriverDescriptors *pDescriptors)
{
	USBDDriver *pUsbd = USBD_GetDriver();

	/* Initialize the standard USB driver */
	USBDDriver_Initialize(pUsbd,
						  pDescriptors,
						  0);

	/* CDC */
	CDCDSerial_Initialize(pUsbd, CDCHIDDDriverDescriptors_CDC_INTERFACE);
	/* HID */
	HIDDKeyboard_Initialize(pUsbd, CDCHIDDDriverDescriptors_HID_INTERFACE);

	/* Initialize the USB driver */
	USBD_Init();
}
/**
 * Initializes the USB device CDCMSD device driver.
 */
void CDCMSDDriver_Initialize(
    const USBDDriverDescriptors *pDescriptors,
    MSDLun *pLuns, unsigned char numLuns)
{
    USBDDriver *pUsbd = USBD_GetDriver();

    /* Initialize the standard USB driver */
    USBDDriver_Initialize(pUsbd, pDescriptors, 0);

    /* CDC */
    CDCDSerial_Initialize(pUsbd, CDCMSDDriverDescriptors_CDC_INTERFACE);

    /* MSD */
    MSDFunction_Initialize(pUsbd, CDCMSDDriverDescriptors_MSD_INTERFACE,
                           pLuns, numLuns);

    /* Initialize the USB driver */
    USBD_Init();
}
/**
 * Initializes an USB audio speaker device driver, as well as the underlying
 * USB controller.
 */
void AUDDSpeakerDriver_Initialize(const USBDDriverDescriptors *pDescriptors)
{
    AUDDSpeakerDriver *pAudd = &auddSpeakerDriver;
    AUDDSpeakerPhone *pAudf  = &pAudd->fun;
    AUDDStream *pAuds = &pAudd->speaker;
    USBDDriver *pUsbd = USBD_GetDriver();

    AUDDSpeakerPhone_InitializeStream(
        pAuds, AUDDSpeakerDriver_NUMCHANNELS, 0,
        (AUDDStreamEventCallback)AUDDSpeaker_EventCallback, pAuds);

    AUDDSpeakerPhone_Initialize(
        pAudf, pUsbd, pAuds, 0);

    /* Initialize the USB driver */
    USBDDriver_Initialize(pUsbd,
                          pDescriptors,
                          pAudd->bAltInterfaces);
    USBD_Init();
}
/**
 * Initializes the USB device HIDMSD device driver.
 */
void HIDMSDDriver_Initialize(
    const USBDDriverDescriptors *pDescriptors,
    MSDLun *pLuns, uint8_t numLuns)
{
    USBDDriver *pUsbd = USBD_GetDriver();

    /* Initialize the standard USB driver */
    USBDDriver_Initialize(pUsbd,
                          pDescriptors,
                          0);

    /* HID */
    HIDDKeyboard_Initialize(pUsbd, HIDMSDDriverDescriptors_HID_INTERFACE);

    /* MSD */
    MSDFunction_Initialize(pUsbd, HIDMSDDriverDescriptors_MSD_INTERFACE,
                           pLuns, numLuns);

    /* Initialize the USB driver */
    USBD_Init();
}
Beispiel #19
0
/**
 * Handles configureation changed event.
 * \param cfgnum New configuration number
 */
void HIDDTransferDriver_ConfigurationChangedHandler(uint8_t cfgnum)
{
    const USBDDriverDescriptors * pDescriptors = USBD_GetDriver()->pDescriptors;
    HIDDTransferDriver * pDrv = &hiddTransferDriver;
    HIDDFunction * pHidd = &pDrv->hidFunction;

    USBConfigurationDescriptor *pDesc;

    if (cfgnum > 0) {

        /* Parse endpoints for reports */
        if (USBD_HAL_IsHighSpeed() && pDescriptors->pHsConfiguration)
            pDesc = (USBConfigurationDescriptor*)pDescriptors->pHsConfiguration;
        else
            pDesc = (USBConfigurationDescriptor*)pDescriptors->pFsConfiguration;
        HIDDFunction_ParseInterface(pHidd,
                                    (USBGenericDescriptor*)pDesc,
                                    pDesc->wTotalLength);

        /* Start polling for Output Reports */
        HIDDFunction_StartPollingOutputs(pHidd);
    }
}
Beispiel #20
0
/**
 * USBDCallbacks_RequestReceived - Invoked when a new SETUP request is
 * received. Does nothing by default.
 * \param request Pointer to the request to handle.
 */
WEAK void USBDCallbacks_RequestReceived(const USBGenericRequest *request)
{
    /* Does basic enumeration */
    USBDDriver_RequestHandler(USBD_GetDriver(), request);
}
Beispiel #21
0
/**
 * Handler for incoming SETUP requests on default Control endpoint 0.
 *
 * Standard requests are forwarded to the USBDDriver_RequestHandler
 * method.
 * \param  pMsdDriver  Pointer to MSDDriver instance.
 * \param  request Pointer to a USBGenericRequest instance
 */
uint32_t MSDFunction_RequestHandler(
    const USBGenericRequest *request)
{
    MSDDriver *pMsdDriver = &msdFunction;
    uint32_t reqCode = (USBGenericRequest_GetType(request) << 8)
                     | (USBGenericRequest_GetRequest(request));

    TRACE_INFO_WP("Msdf ");

    /* Handle requests */
    switch (reqCode) {
    /*--------------------- */
    case USBGenericRequest_CLEARFEATURE:
    /*--------------------- */
        TRACE_INFO_WP("ClrFeat ");

        switch (USBFeatureRequest_GetFeatureSelector(request)) {

        /*--------------------- */
        case USBFeatureRequest_ENDPOINTHALT:
        /*--------------------- */
            TRACE_INFO_WP("Hlt ");

            /* Do not clear the endpoint halt status if the device is waiting */
            /* for a reset recovery sequence */
            if (!pMsdDriver->waitResetRecovery) {

                /* Forward the request to the standard handler */
                USBDDriver_RequestHandler(USBD_GetDriver(), request);
            }
            else {

                TRACE_INFO_WP("No ");
            }

            USBD_Write(0, 0, 0, 0, 0);

            return USBRC_SUCCESS; /* Handled */

        }
        break;

    /*------------------- */
    case (USBGenericRequest_CLASS<<8)|MSD_GET_MAX_LUN:
    /*------------------- */
        TRACE_INFO_WP("gMaxLun ");

        /* Check request parameters */
        if ((request->wValue == 0)
            && (request->wIndex == pMsdDriver->interfaceNb)
            && (request->wLength == 1)) {

            USBD_Write(0, &(pMsdDriver->maxLun), 1, 0, 0);

        }
        else {

            TRACE_WARNING(
                "MSDDriver_RequestHandler: GetMaxLUN(%d,%d,%d)\n\r",
                request->wValue, request->wIndex, request->wLength);
            USBD_Stall(0);
        }
        return USBRC_SUCCESS; /* Handled */

    /*----------------------- */
    case (USBGenericRequest_CLASS<<8)|MSD_BULK_ONLY_RESET:
    /*----------------------- */
        TRACE_INFO_WP("Rst ");

        /* Check parameters */
        if ((request->wValue == 0)
            && (request->wIndex == pMsdDriver->interfaceNb)
            && (request->wLength == 0)) {

            /* Reset the MSD driver */
            MSDFunction_Reset();
            USBD_Write(0, 0, 0, 0, 0);
        }
        else {

            TRACE_WARNING(
                "MSDDriver_RequestHandler: Reset(%d,%d,%d)\n\r",
                request->wValue, request->wIndex, request->wLength);
            USBD_Stall(0);
        }
        return USBRC_SUCCESS; /* Handled */
    }

    return USBRC_PARAM_ERR;
}