/*****************************************&**********/
/*USB                                               */
/*PIC32MX795F512L-80I/PF                            */
/****************************************************/

#include "xc.h"
#include "USB.h"

void init_USB(void)
{    
    //Turn on module
    U1PWRCbits.USBPWR = 1;
    
    //wait for PLL lock
    while(OSCCONbits.ULOCK == 0);            
            
    //Device mode doesn't power VBUS
    U1OTGCONbits.VBUSON = 0;
    
    //High Speed mode Pullups
    U1OTGCONbits.DPPULUP = 1;
    U1OTGCONbits.DMPULDWN = 1;
    
    U1BDTP1bits.BDTPTRL = 0x0000;
    U1BDTP2bits.BDTPTRH = 0x0000;
    U1BDTP3bits.BDTPTRU = 0x0000;
    
    U1EP0bits.EPRXEN = 1;
    U1EP0bits.EPTXEN = 1;
    U1EP0bits.EPHSHK = 1;
    
    U1CONbits.SOFEN = 1;
    
    //Module Enable
    U1CONbits.USBEN = 1;
    
}

