Projet

Général

Profil

Demo src » app_led_usb_status.c

Anonyme, 24/11/2021 14:32

 
/*******************************************************************************
Copyright 2016 Microchip Technology Inc. (www.microchip.com)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

To request to license the code under the MLA license (www.microchip.com/mla_license),
please contact mla_licensing@microchip.com
*******************************************************************************/

// *****************************************************************************
// *****************************************************************************
// Section: Included Files
// *****************************************************************************
// *****************************************************************************
#include "stdint.h"
#include "system.h"
#include "usb_device.h"


// *****************************************************************************
// *****************************************************************************
// Section: File Scope or Global Constants
// *****************************************************************************
// *****************************************************************************


// *****************************************************************************
// *****************************************************************************
// Section: File Scope Data Types
// *****************************************************************************
// *****************************************************************************


// *****************************************************************************
// *****************************************************************************
// Section: Macros or Functions
// *****************************************************************************
// *****************************************************************************

void APP_LEDUpdateUSBStatus(void)
{
static uint16_t ledCount = 0;

if(USBIsDeviceSuspended() == true)
{
LED_Off(LED_USB_DEVICE_STATE);
return;
}

switch(USBGetDeviceState())
{
case CONFIGURED_STATE:
/* We are configured. Blink fast.
* On for 75ms, off for 75ms, then reset/repeat. */
if(ledCount == 1)
{
LED_On(LED_USB_DEVICE_STATE);
}
else if(ledCount == 75)
{
LED_Off(LED_USB_DEVICE_STATE);
}
else if(ledCount > 150)
{
ledCount = 0;
}
break;

default:
/* We aren't configured yet, but we aren't suspended so let's blink with
* a slow pulse. On for 50ms, then off for 950ms, then reset/repeat. */
if(ledCount == 1)
{
LED_On(LED_USB_DEVICE_STATE);
}
else if(ledCount == 50)
{
LED_Off(LED_USB_DEVICE_STATE);
}
else if(ledCount > 950)
{
ledCount = 0;
}
break;
}

/* Increment the millisecond counter. */
ledCount++;
}

/*******************************************************************************
End of File
*/
(3-3/8)