Exemple #1
0
BSP_LED_STATE BSP_LEDStateGet(BSP_LED led)
{
	if (led == LED_1 || led == LED_2)
	{
        return(PLIB_PORTS_PinGetLatched(PORTS_ID_0, PORT_CHANNEL_A, led));
    }
    else
    {
        return(PLIB_PORTS_PinGetLatched(PORTS_ID_0, PORT_CHANNEL_D, led));
    }
}
/***********************************************
 * Application USB Device Layer Event Handler.
 ***********************************************/
void APP_USBDeviceEventHandler ( USB_DEVICE_EVENT event, void * eventData, uintptr_t context )
{
    USB_DEVICE_EVENT_DATA_CONFIGURED *configuredEventData;

    static bool led;
    
    switch ( event )
    {
        case USB_DEVICE_EVENT_SOF:
            app2Data.sofEventHasOccurred = true;
            break;

        case USB_DEVICE_EVENT_RESET:
            
            app2Data.isConfigured = false;

            break;

        case USB_DEVICE_EVENT_CONFIGURED:    
            
            /* Set the USBID pin to output (LED control) after configuration is done */
            PLIB_PORTS_PinDirectionOutputSet(PORTS_ID_0, PORT_CHANNEL_F, PORTS_BIT_POS_3);
            
            (led) ? PLIB_PORTS_PinSet(PORTS_ID_0, PORT_CHANNEL_F, PORTS_BIT_POS_3) : PLIB_PORTS_PinClear(PORTS_ID_0, PORT_CHANNEL_F, PORTS_BIT_POS_3);

            /* Check the configuration. We only support configuration 1 */
            configuredEventData = (USB_DEVICE_EVENT_DATA_CONFIGURED*)eventData;
            if ( configuredEventData->configurationValue == 1)
            {
                /* Register the CDC Device application event handler here.
                 * Note how the app2Data object pointer is passed as the
                 * user data */

                USB_DEVICE_CDC_EventHandlerSet(USB_DEVICE_CDC_INDEX_0, APP_USBDeviceCDCEventHandler, (uintptr_t)&app2Data);

                /* Mark that the device is now configured */
                app2Data.isConfigured = true;

            }
            break;

        case USB_DEVICE_EVENT_POWER_DETECTED:
            
            led = PLIB_PORTS_PinGetLatched(PORTS_ID_0, PORT_CHANNEL_F, PORTS_BIT_POS_3);
            
            /* Set the USBID pin to input (floating) so that it will be configured as DEVICE */
            PLIB_PORTS_PinDirectionInputSet(PORTS_ID_0, PORT_CHANNEL_F, PORTS_BIT_POS_3);
            
            /* VBUS was detected. We can attach the device */
            USB_DEVICE_Attach(app2Data.deviceHandle);
            break;

        case USB_DEVICE_EVENT_POWER_REMOVED:

            /* VBUS is not available any more. Detach the device. */
            USB_DEVICE_Detach(app2Data.deviceHandle);
            break;

        case USB_DEVICE_EVENT_SUSPENDED:
            break;

        case USB_DEVICE_EVENT_RESUMED:
        case USB_DEVICE_EVENT_ERROR:
        default:
            break;
    }
}
BSP_LED_STATE BSP_LEDStateGet(BSP_LED_CHANNEL led_channel, BSP_LED_PORT led_port)
{
    return(PLIB_PORTS_PinGetLatched( PORTS_ID_0, led_channel, led_port));
}
BSP_LED_STATE BSP_LEDStateGet (BSP_LED led)
{
    /* Get LED Status */
    return PLIB_PORTS_PinGetLatched (PORTS_ID_0, PORT_CHANNEL_H, led);
}