示例#1
0
int main(void) {
    InitializeSystem();

    // Wait for reset button to be released
    while (_PORT(PIO_BTN1) == HIGH) { }

    //ADCInitialize();
    PWMInitialize();
    PWMEnable();
    USBDeviceInit();

    //ADCStartCapture();
    _LAT(PIO_LED1) = HIGH;

    ColourEngine::Initialize();
    //ColourEngine::PowerOn(1000); // Fade in
    ColourEngine::SetPower(power, 0);

    //_LAT(PIO_LED2) = HIGH;

    while (1) {
        USBDeviceTasks();
        USBUserProcess();
    }

    return 0;
}
void prepareUSB(void)
{
    USBDeviceInit();	//usb_device.c.  Initializes USB module SFRs and firmware
    					//variables to known states.

    USBDeviceAttach(); // Activate USB Interruptions
}
示例#3
0
文件: usb.c 项目: deadbok/kb10
/********************************************************************
 * Function:        static void InitializeSystem(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        InitializeSystem is a centralize initialization
 *                  routine. All required USB initialization routines
 *                  are called from here.
 *
 *                  User application initialization routine should
 *                  also be called from here.
 *
 * Note:            None
 *******************************************************************/
static void InitializeSystem(void)
{
    ADCON1 |= 0x0F;                 // Default all pins to digital

    #if defined(USE_USB_BUS_SENSE_IO)
    tris_usb_bus_sense = INPUT_PIN; // See HardwareProfile.h
    #endif

//	If the host PC sends a GetStatus (device) request, the firmware must respond
//	and let the host know if the USB peripheral device is currently bus powered
//	or self powered.  See chapter 9 in the official USB specifications for details
//	regarding this request.  If the peripheral device is capable of being both
//	self and bus powered, it should not return a hard coded value for this request.
//	Instead, firmware should check if it is currently self or bus powered, and
//	respond accordingly.  If the hardware has been configured like demonstrated
//	on the PICDEM FS USB Demo Board, an I/O pin can be polled to determine the
//	currently selected power source.  On the PICDEM FS USB Demo Board, "RA2"
//	is used for	this purpose.  If using this feature, make sure "USE_SELF_POWER_SENSE_IO"
//	has been defined in HardwareProfile - (platform).h, and that an appropriate I/O pin 
//  has been mapped	to it.
    #if defined(USE_SELF_POWER_SENSE_IO)
    tris_self_power = INPUT_PIN;	// See HardwareProfile.h
    #endif

    UserInit();

    USBDeviceInit();	//usb_device.c.  Initializes USB module SFRs and firmware
    					//variables to known states.
}//end InitializeSystem
示例#4
0
int main(void){   
	unsigned long timer;
	#define longDelay(x) timer=x; while(timer--)
    CLKDIV = 0x0000;    // Set PLL prescaler (1:1)
    init();			//setup the crystal, pins, hold the FPGA in reset
	usbbufflush();	//setup the USB byte buffer
	

    USBDeviceInit();//setup usb

    while(1){
        USBDeviceTasks(); 

    	if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) continue;
		usbbufservice();//load any USB data into byte buffer

			//send data from the FPGA receive buffer to USB
			//if((mUSBUSARTIsTxTrfReady()) && (uartincnt > 0)){
			//	putUSBUSART(&buf[0], uartincnt);
			//}

    	CDCTxService();

    }//end while

}//end main
示例#5
0
/********************************************************************
 * Function:        void main(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        Main program entry point.
 *
 * Note:            None
 *******************************************************************/
MAIN_RETURN main(void)
{
    SYSTEM_Initialize(SYSTEM_STATE_USB_START);

    USBDeviceInit();
    USBDeviceAttach();
    setup();

    while(1)
    {
        SYSTEM_Tasks();

        #if defined(USB_POLLING)
            // Interrupt or polling method.  If using polling, must call
            // this function periodically.  This function will take care
            // of processing and responding to SETUP transactions
            // (such as during the enumeration process when you first
            // plug in).  USB hosts require that USB devices should accept
            // and process SETUP packets in a timely fashion.  Therefore,
            // when using polling, this function should be called
            // regularly (such as once every 1.8ms or faster** [see
            // inline code comments in usb_device.c for explanation when
            // "or faster" applies])  In most cases, the USBDeviceTasks()
            // function does not take very long to execute (ex: <100
            // instruction cycles) before it returns.
            USBDeviceTasks();
        #endif

        //Application specific tasks
        APP_DeviceCDCBasicDemoTasks();

    }//end while
}//end main
示例#6
0
/********************************************************************
 * Function:        static void InitializeSystem(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        InitializeSystem is a centralize initialization
 *                  routine. All required USB initialization routines
 *                  are called from here.
 *
 *                  User application initialization routine should
 *                  also be called from here.
 *
 * Note:            None
 *******************************************************************/
void USBInit(void) {
	USBGenericOutHandle = 0;
	USBGenericInHandle = 0;

    USBDeviceInit();	//usb_device.c.  Initializes USB module SFRs and firmware
    					//variables to known states.
}//end InitializeSystem
示例#7
0
文件: main.c 项目: AleSuky/SkP32v1.1
// *--------------------------------------------------------------------------------*
int main(){
	
    mJTAGPortEnable(0);							// JTAG des-habilitado
	SYSTEMConfigPerformance(GetSystemClock()); 	// Activa pre-cache.-
	
	AD1PCFG = 0xFFFF;
	LED1_OUTPUT();
	LED2_OUTPUT();
	SW1_INPUT();
	SW2_INPUT();
	
	buttonCount = 0;
    buttonPressed = FALSE;
    stringPrinted = TRUE;
	
	USBDeviceInit();	
	while(1){
		#if defined(USB_INTERRUPT)
		if(USB_BUS_SENSE && (USBGetDeviceState() == DETACHED_STATE)){
			USBDeviceAttach();
		}
		#endif
		#if defined(USB_POLLING)
			// Check bus status and service USB interrupts.
			USBDeviceTasks();
		#endif
		ProcessIO();
	}
}
示例#8
0
文件: user.c 项目: nabillo/Chargeur
/* App initialisation
 * init ADC
 * init timer 1
 * init interrupts
 */
void InitApp(void)
{
    cur_State = LIPO_ALGO_STARTED;
    strncpy(battery.battery_type,"LIPO\0",5);
    battery.charge.restore_Lowest_Voltage = 5;
    battery.number_of_cells = 1;
    battery.charge.restore_Charge_Current = 0.5;
    seconds = 0;

    OpenADC( ADC_FOSC_64 & ADC_RIGHT_JUST & ADC_6_TAD,
            ADC_CH0 & ADC_INT_OFF & ADC_REF_VDD_VSS,
            ADC_1ANA );
    /* open timers */
    OpenTimer1( TIMER_INT_ON &
                T1_8BIT_RW &
                T1_SOURCE_EXT &
                T1_PS_1_1 &
                T1_OSC1EN_ON &
                T1_SYNC_EXT_OFF );

    //ei();

    USBDeviceInit();            //usb_device.c
    #if defined(USB_INTERRUPT)
      USBDeviceAttach();        //usb_device.c
    #endif

    /* TODO init PI structure */
    PI.Ki = 2;
    PI.Kp = 35;
    /* TODO init analog port */
}
示例#9
0
/********************************************************************
 * Function:        static void InitializeSystem(void)
 * Overview:        InitializeSystem is a centralize initialization
 *                  routine. All required USB initialization routines
 *                  are called from here.
 *
 *                  User application initialization routine should
 *                  also be called from here.                  
 *******************************************************************/
static void InitializeSystem(void)
{
        ANSELA = 0x00;
        ANSELB = 0x00;
        ANSELC = 0x00;

        TRISA = 0; 
        LATA = 0; 

        TRISB = 0; 
        LATB = 0; 

        TRISC = 0; 
        LATC = 0; 

        LCDReset();

//	The USB specifications require that USB peripheral devices must never source
//	current onto the Vbus pin.  Additionally, USB peripherals should not source
//	current on D+ or D- when the host/hub is not actively powering the Vbus line.
//	When designing a self powered (as opposed to bus powered) USB peripheral
//	device, the firmware should make sure not to turn on the USB module and D+
//	or D- pull up resistor unless Vbus is actively powered.  Therefore, the
//	firmware needs some means to detect when Vbus is being powered by the host.
//	A 5V tolerant I/O pin can be connected to Vbus (through a resistor), and
// 	can be used to detect when Vbus is high (host actively powering), or low
//	(host is shut down or otherwise not supplying power).  The USB firmware
// 	can then periodically poll this I/O pin to know when it is okay to turn on
//	the USB module/D+/D- pull up resistor.  When designing a purely bus powered
//	peripheral device, it is not possible to source current on D+ or D- when the
//	host is not actively providing power on Vbus. Therefore, implementing this
//	bus sense feature is optional.  This firmware can be made to use this bus
//	sense feature by making sure "USE_USB_BUS_SENSE_IO" has been defined in the
//	HardwareProfile.h file.    
    #if defined(USE_USB_BUS_SENSE_IO)
        tris_usb_bus_sense = INPUT_PIN; // See HardwareProfile.h
    #endif
    
//	If the host PC sends a GetStatus (device) request, the firmware must respond
//	and let the host know if the USB peripheral device is currently bus powered
//	or self powered.  See chapter 9 in the official USB specifications for details
//	regarding this request.  If the peripheral device is capable of being both
//	self and bus powered, it should not return a hard coded value for this request.
//	Instead, firmware should check if it is currently self or bus powered, and
//	respond accordingly.  If the hardware has been configured like demonstrated
//	on the PICDEM FS USB Demo Board, an I/O pin can be polled to determine the
//	currently selected power source.  On the PICDEM FS USB Demo Board, "RA2" 
//	is used for	this purpose.  If using this feature, make sure "USE_SELF_POWER_SENSE_IO"
//	has been defined in HardwareProfile - (platform).h, and that an appropriate I/O pin 
//  has been mapped	to it.
    #if defined(USE_SELF_POWER_SENSE_IO)
    tris_self_power = INPUT_PIN;	// See HardwareProfile.h
    #endif
    
    UserInit();

    USBDeviceInit();	//usb_device.c.  Initializes USB module SFRs and firmware
    					//variables to known states.
}//end InitializeSystem
示例#10
0
/*
 * Main program entry point.
 */
int main (void)
{
	AD1PCFG = 0xFFFF;

	//Initialize all of the LED pins
	LATE |= 0x000F;
	TRISE &= 0xFFF0;

	USBDeviceInit();	//usb_device.c.  Initializes USB module SFRs and firmware
    				//variables to known states.
	PMCON = 0;

	for (;;) {
		// Check bus status and service USB interrupts.
		USBDeviceTasks(); // Interrupt or polling method.  If using polling, must call
        			  // this function periodically.  This function will take care
        			  // of processing and responding to SETUP transactions
        			  // (such as during the enumeration process when you first
        			  // plug in).  USB hosts require that USB devices should accept
        			  // and process SETUP packets in a timely fashion.  Therefore,
        			  // when using polling, this function should be called
        			  // frequently (such as once about every 100 microseconds) at any
        			  // time that a SETUP packet might reasonably be expected to
        			  // be sent by the host to your device.  In most cases, the
        			  // USBDeviceTasks() function does not take very long to
        			  // execute (~50 instruction cycles) before it returns.

		// Application-specific tasks.
		// Blink the LEDs according to the USB device status
		BlinkUSBStatus();

		// User Application USB tasks
		if (USBDeviceState >= CONFIGURED_STATE && ! (U1PWRC & PIC32_U1PWRC_USUSPEND)) {
			unsigned nbytes_read;
			static unsigned char inbuf[64], outbuf[64];
			static unsigned led3_count = 0;

			// Pull in some new data if there is new data to pull in
			nbytes_read = getsUSBUSART ((char*) inbuf, 64);
			if (nbytes_read != 0) {
				snprintf (outbuf, sizeof(outbuf),
					"Received %d bytes: %02x...\r\n",
					nbytes_read, inbuf[0]);
				putUSBUSART ((char*) outbuf, strlen (outbuf));
				mLED_2_Toggle();
				mLED_3_On();
				led3_count = 10000;
			}
			if (led3_count) {
				// Turn off LED3 when timeout expired.
				led3_count--;
				if (led3_count == 0)
					mLED_3_Off();
			}

			CDCTxService();
		}
	}
}
示例#11
0
int32_t main(void)
{
    DDPCONbits.JTAGEN = 0; // Disable the JTAG programming port

    /*
    SYS_CFG_WAIT_STATES (configures flash wait states from system clock)
    SYS_CFG_PB_BUS (configures the PB bus from the system clock)
    SYS_CFG_PCACHE (configures the pCache if used)
    SYS_CFG_ALL (configures the flash wait states, PB bus, and pCache)*/

    /* TODO Add user clock/system configuration code if appropriate.  */
    SYSTEMConfig(SYS_FREQ, SYS_CFG_ALL); 
    
    
    /*Configure Multivector Interrupt Mode.  Using Single Vector Mode
    is expensive from a timing perspective, so most applications
    should probably not use a Single Vector Mode*/
    INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);

    /* TODO <INSERT USER APPLICATION CODE HERE> */

    
    

    

    // initialise the IO pins and PWM outputs
    TRISD = 0;
    pickerBusTRIS = 0x00;
    pickerBus = 0x00;

    OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0); // vibration motor
    OpenOC2( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0); // head led
    OpenOC3( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0); // base led
    OpenTimer2( T2_ON | T2_PS_1_4 | T2_SOURCE_INT, 1024);
    SetDCOC1PWM(0);
    SetDCOC2PWM(0);
    SetDCOC3PWM(0);

    setVac1off;
    setVac2off;
    

    USBOutHandle = 0;
    USBInHandle = 0;
    USBDeviceInit();	//usb_device.c.  Initializes USB module SFRs and firmware

    USBDeviceAttach();
    
    init_component_picker();

    /*while(1)
    {
        LATBbits.LATB0 = feederXHome;
        LATBbits.LATB1 = feederZHome;
        //ProcessIO();
    }*/
}
示例#12
0
MAIN_RETURN main(void)
{
    SYSTEM_Initialize(SYSTEM_STATE_USB_START);

    USBDeviceInit();
    USBDeviceAttach();

    IPR1 = 0;   //All others interrupt sources will be Low priority
    IPR2 = 32; //USB interrupt is High priority
    RCONbits.IPEN = 1;  //Enabling interrupt priority
    ADCON1bits.PCFG = 0x0F; //By default all I/O digital
    CMCONbits.CM = 7; //Comparators off by default

    while(1)
    {
        SYSTEM_Tasks();

        #if defined(USB_POLLING)
            // Interrupt or polling method.  If using polling, must call
            // this function periodically.  This function will take care
            // of processing and responding to SETUP transactions
            // (such as during the enumeration process when you first
            // plug in).  USB hosts require that USB devices should accept
            // and process SETUP packets in a timely fashion.  Therefore,
            // when using polling, this function should be called
            // regularly (such as once every 1.8ms or faster** [see
            // inline code comments in usb_device.c for explanation when
            // "or faster" applies])  In most cases, the USBDeviceTasks()
            // function does not take very long to execute (ex: <100
            // instruction cycles) before it returns.
            USBDeviceTasks();
        #endif

        /* If the USB device isn't configured yet, we can't really do anything
         * else since we don't have a host to talk to.  So jump back to the
         * top of the while loop. */
        if( USBGetDeviceState() < CONFIGURED_STATE )
        {
            /* Jump back to the top of the while loop. */
            continue;
        }

        /* If we are currently suspended, then we need to see if we need to
         * issue a remote wakeup.  In either case, we shouldn't process any
         * keyboard commands since we aren't currently communicating to the host
         * thus just continue back to the start of the while loop. */
        if( USBIsDeviceSuspended() == true )
        {
            /* Jump back to the top of the while loop. */
            continue;
        }

        //Application specific tasks
        APP_DeviceCustomHIDTasks();

    }//end while
}//end main
示例#13
0
void preflight(void)
{
	printf("Initialising USB\r\n");

	USBDeviceInit();    //usb_device.c.  Initializes USB module SFRs and firmware variables to known states.
#if defined(USB_INTERRUPT)
	USBDeviceAttach();
#endif
}
示例#14
0
/********************************************************************
 * Function:        void main(void)
 *******************************************************************/
MAIN_RETURN main(void)
{
    SYSTEM_Initialize();

    USBDeviceInit();
    USBDeviceAttach();

    while(1)
    {
        SYSTEM_Tasks();

        #if defined(USB_POLLING)
            USBDeviceTasks();
        #endif

        /* If the USB device isn't configured yet, we can't really do anything
         * else since we don't have a host to talk to.  So jump back to the
         * top of the while loop. */
        if( USBGetDeviceState() < CONFIGURED_STATE )
        {
            /* Jump back to the top of the while loop. */
            continue;
        }

        /* If we are currently suspended, then we need to see if we need to
         * issue a remote wakeup.  In either case, we shouldn't process any
         * keyboard commands since we aren't currently communicating to the host
         * thus just continue back to the start of the while loop. */
        if( USBIsDeviceSuspended() == true )
        {
            /* Jump back to the top of the while loop. */
            continue;
        }
        // implement nMCLR button
        if ( BUTTON_IsPressed(BUTTON_S1)) {
            LUNSoftDetach(0);       // mark the media as temporarily unavailable 
            ICSP_nMCLR = SLAVE_RESET;
            LED_Off(GREEN_LED);     // turn off RED LED to indicate ready for download
            LED_On (RED_LED);
            DIRECT_Initialize();    // reset the programming state machine
        }
        else { // simply act as a slave reset 
            LUNSoftAttach(0);                       // mark the media as available
            if ( !DIRECT_ProgrammingInProgress()) {  // do not release during prog.!
                ICSP_nMCLR = SLAVE_RUN;
                LED_On(GREEN_LED);   // turn off RED LED to indicate ready for download
                LED_Off(RED_LED);
            }
        }

        //Application specific tasks
        APP_DeviceMSDTasks();
        APP_DeviceCDCEmulatorTasks();

    }//end while
}//end main
示例#15
0
文件: usb_tty.c 项目: acacio1986/V2
void usb_tty_init(void){
    /* queue para o envio de string pela usb
     * usada principalmente por:
     * - printf
     * - usb_tty_print
     */
    usb_buffer_queue = xQueueCreate(8, sizeof(USB_BUFFER));

    USBDeviceInit();
}
示例#16
0
void CDC_init()
{
    USBDeviceInit();		// Initializes USB module SFRs and firmware
    #if defined(__32MX220F032D__)||defined(__32MX250F128B__)||defined(__32MX220F032B__)
        // nothing to do
    #else
        USBDeviceAttach();
    #endif
    Delayms(1500);
}
示例#17
0
/***************************************************
 * Function:        void Init(void)
 *
 * OverView:		All calling related to Initialized functions.
 *
 * Note:			None
 ***************************************************/
void Init(void)
{
	InitializeSystem();		//	Initialize Related to connect usb port.
	InitializeUser();		//	Initialize for User Variables.
	InitializeDevice();		//	Initialize PICF4550 LED, PWM, ADC Ports
	USBDeviceInit();		//	Initialize USB Module.

	#if defined(USB_INTERRUPT)
		USBDeviceAttach();	//	Enable to find USB Device
	#endif
}
示例#18
0
// Initialise the PIC
void initialisePic(void)
{
    // PIC port set up --------------------------------------------------------

	// Default all pins to digital
    ANSEL = 0x00;

	// Configure ports as inputs (1) or outputs(0)
/*	TRISA = 0b11111111;
	TRISB = 0b11111111;
	TRISC = 0b11111111;
#if defined(__18F4550)
	TRISD = 0b00000000;
	TRISE = 0b00000000;
#endif

	// Clear all ports
	PORTA = 0b00000000;
	PORTB = 0b00000000;
	PORTC = 0b00000000;
#if defined(__18F4550)
	PORTD = 0b00000000;
	PORTE = 0b00000000;
#endif*/

	PORTC = 0x00;
	LATC = 0x00;

	TRISC = 0x04;

	// If you have a VBUS sense pin (for self-powered devices when you
	// want to detect if the USB host is connected) you have to specify
	// your input pin in HardwareProfile.h
    #if defined(USE_USB_BUS_SENSE_IO)
    	tris_usb_bus_sense = INPUT_PIN;
    #endif
    
    // In the case of a device which can be both self-powered and bus-powered
    // the device must respond correctly to a GetStatus (device) request and
    // tell the host how it is currently powered.
    //
    // To do this you must device a pin which is high when self powered and low
    // when bus powered and define this in HardwareProfile.h
    #if defined(USE_SELF_POWER_SENSE_IO)
    	tris_self_power = INPUT_PIN;
    #endif

    // Application specific initialisation
    applicationInit();
    
    // Initialise the USB device
    USBDeviceInit();
}
示例#19
0
/**
 * InitializeSystem:
 **/
static void
InitializeSystem(void)
{
#if defined(__18F46J50)
	/* Enable the PLL and wait 2+ms until the PLL locks
	 * before enabling USB module */
	unsigned int pll_startup_counter = 600;
	OSCTUNEbits.PLLEN = 1;
	while (pll_startup_counter--);

	/* default all pins to digital */
	ANCON0 = 0xFF;
	ANCON1 = 0xFF;
#elif defined(__18F4550)
	/* default all pins to digital */
	ADCON1 = 0x0F;
#endif

	/* set RA0, RA1 to output (freq scaling),
	 * set RA2, RA3 to output (color select),
	 * set RA5 to input (frequency counter),
	 * (RA6 is "don't care" in OSC2 mode)
	 * set RA7 to input (OSC1, HSPLL in) */
	TRISA = 0xf0;

	/* set RB0 to RB3 to input (h/w revision) others input (unused) */
	TRISB = 0xff;

	/* set RC0 to RC2 to input (unused) */
	TRISC = 0xff;

	/* set RD0 to RD7 to input (unused) */
	TRISD = 0xff;

	/* set RE0, RE1 output (LEDs) others input (unused) */
	TRISE = 0x3c;

	/* set the LED state initially */
	PORTE = CH_STATUS_LED_RED;

	/* only turn on the USB module when the device has power */
#if defined(USE_USB_BUS_SENSE_IO)
	tris_usb_bus_sense = INPUT_PIN;
#endif

	/* we're self powered */
#if defined(USE_SELF_POWER_SENSE_IO)
	tris_self_power = INPUT_PIN;
#endif

	/* Initializes USB module SFRs and firmware variables to known states */
	USBDeviceInit();
}
示例#20
0
文件: main.c 项目: jrapp01/SrDesign
static void InitializeSystem(void)
{
    AD1PCFG = 0xFFFF;   
    SYSTEMConfigPerformance(80000000);
    UserInit();
    USBDeviceInit();	// Initializes USB module SFRs and firmware
    			// variables to known states.
    ConfigINT0(EXT_INT_PRI_6 | RISING_EDGE_INT | EXT_INT_ENABLE);
    
    mPMPOpen(PMP_CONTROL, PMP_MODE, PMP_PORT, PMP_INT);
    PMPSetAddress(0x4000);
}
示例#21
0
int main(void)
#endif
{
    InitializeSystem();

    USBDeviceInit();

    while(1)
    {
        USBDeviceTasks(); 
        ProcessIO();        
    }
}
示例#22
0
void __init()
{
	unsigned int pll_startup_counter = 600;
	OSCTUNEbits.PLLEN = 1;  //Enable the PLL and wait 2+ms until the PLL locks before enabling USB module
	while(pll_startup_counter--);

    ANCON0 = 0xFF;                  // Default all pins to digital
    ANCON1 = 0xFF;                  // Default all pins to digital

    InitializeUSART();
	USBInitCDC();
    USBDeviceInit();
}
示例#23
0
void preflight(void)
{
	printf("Initialising USB\r\n");
	USBDeviceInit();        //usb_device.c.  Initializes USB module SFRs and firmware variables to known states.
	#if defined(USB_INTERRUPT)
		USBDeviceAttach();
	#endif
	delay_ms(100);

	printf("Preflight setup\r\n");
	while (U1OTGSTATbits.VBUSVD)
	{
		#if defined(USB_POLLING)
		// Check bus status and service USB interrupts.
		USBDeviceTasks();   // Interrupt or polling method.  If using polling, must call
		                    // this function periodically.  This function will take care
		                    // of processing and responding to SETUP transactions 
		                    // (such as during the enumeration process when you first
		                    // plug in).  USB hosts require that USB devices should accept
		                    // and process SETUP packets in a timely fashion.  Therefore,
		                    // when using polling, this function should be called 
		                    // regularly (such as once every 1.8ms or faster** [see 
		                    // inline code comments in usb_device.c for explanation when
		                    // "or faster" applies])  In most cases, the USBDeviceTasks() 
		                    // function does not take very long to execute (ex: <100 
		                    // instruction cycles) before it returns.
		#endif

		// User Application USB tasks
		if ((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) {
			// do nothing
		} else {
#if (USE_MSD == 1)
			MSDTasks();
#endif
#if (USE_CDC == 1)
			CDCTasks();
#endif
		}
#if (CONSOLE_UART != 0)
		console();
#endif
	}

	led_off(LED_RED);
	led_off(LED_BLUE);
	led_off(LED_GREEN);
	led_off(LED_ORANGE);

	printf("Preflight complete\r\n");
}
示例#24
0
/*
 * Main program entry point.
 */
int main (void)
{
        /* Unlock CFGCON register. */
        SYSKEY = 0;
        SYSKEY = 0xAA996655;
        SYSKEY = 0x556699AA;
        CFGCON &= (1 << 13);            // clear IOLOCK

        /* Disable JTAG ports, to make more pins available. */
        CFGCON &= (1 << 3);             // clear JTAGEN

        /* Use all ports as digital. */
        ANSELA = 0;
        ANSELB = 0;
        ANSELC = 0;

	// Activate all of the LED pins.
	LATBSET = MASKB_LED1;
	TRISBCLR = MASKB_LED1;
	LATASET = MASKA_LED2;
	TRISACLR = MASKA_LED2;

	USBDeviceInit();	//usb_device.c.  Initializes USB module SFRs and firmware
    				//variables to known states.
	PMCON = 0;

	for (;;) {
		// Check bus status and service USB interrupts.
		USBDeviceTasks(); // Interrupt or polling method.  If using polling, must call
        			  // this function periodically.  This function will take care
        			  // of processing and responding to SETUP transactions
        			  // (such as during the enumeration process when you first
        			  // plug in).  USB hosts require that USB devices should accept
        			  // and process SETUP packets in a timely fashion.  Therefore,
        			  // when using polling, this function should be called
        			  // frequently (such as once about every 100 microseconds) at any
        			  // time that a SETUP packet might reasonably be expected to
        			  // be sent by the host to your device.  In most cases, the
        			  // USBDeviceTasks() function does not take very long to
        			  // execute (~50 instruction cycles) before it returns.

		// Application-specific tasks.
		// Blink the LEDs according to the USB device status
		blink_status();

		// User Application USB tasks
		if (USBDeviceState >= CONFIGURED_STATE && ! (U1PWRC & PIC32_U1PWRC_USUSPEND)) {
			send_receive();
		}
	}
}
示例#25
0
文件: main.c 项目: z9u2k/remote
/**
 * prepare system on boot
 */
static void InitializeSystem(void) {
    #if defined(__18CXX)
        SetupTimer();
        INTCONbits.GIEH = 1;
    #endif
    
    InitLED();
    LED_Off();

    InitReceiver();
    ReceiverOff();
    
    USBDeviceInit();
}
示例#26
0
// Initialise the PIC
static void initialisePic(void)
{
    // PIC port set up --------------------------------------------------------

	// Default all pins to digital
    ADCON1 = 0x0F;

    // Configure ports as inputs (1) or outputs(0)
    TRISA = 0b00000000;
    TRISB = 0b00000000;
    TRISC = 0b00000000;
    TRISD = 0b00000000;
    TRISE = 0b00000000;

    // Clear all ports
    PORTA = 0b00000000;
    PORTB = 0b00000000;
    PORTC = 0b00000000;
    PORTD = 0b00000000;
    PORTE = 0b00000000;

    // initialise the atmega IC
    atmegaFeederRunningTRIS = 1;
    atmegaResetPin = 1;
    
    
    // initialise i2c communication
    OpenI2C( MASTER, SLEW_OFF);
    SSPADD = 0x70;
    
    // Application specific initialisation
    applicationInit();
    
    // Initialise the USB device
    USBDeviceInit();

    // Initialise the output pins
    setVac1off;
    setVac2off;
    setVibrationoff;
    OpenTimer2( TIMER_INT_OFF & T2_PS_1_1);

    // load pwm values from eeprom
    led1_duty_cycle = Read_b_eep(baseLED_EEPROM_address);
    led2_duty_cycle = Read_b_eep(headLED_EEPROM_address);

    // initialise the stepper driver and start timer 0 at 1 microsecond intervals
    
    
}
示例#27
0
MAIN_RETURN main(void) {
    gpio_init();
    timer_init();
    SYSTEM_Initialize(SYSTEM_STATE_USB_START);
    USBDeviceInit();
    USBDeviceAttach();
    while (1) {
        SYSTEM_Tasks();
#if defined(USB_POLLING)
        USBDeviceTasks();
#endif
        //APP_DeviceCDCBasicDemoTasks();
        serial_update();
    }
}
示例#28
0
static void InitializeSystem(void)
{
	ADCON1 |= 0x0F;					// Default all pins to digital

	#if defined(USE_USB_BUS_SENSE_IO)
	tris_usb_bus_sense = INPUT_PIN; // See HardwareProfile.h
	#endif
	#if defined(USE_SELF_POWER_SENSE_IO)
	tris_self_power = INPUT_PIN;	// See HardwareProfile.h
	#endif
	
	UserInit();

	USBDeviceInit();	//usb_device.c.	 Initializes USB module SFRs and firmware
}//end InitializeSystem
示例#29
0
static void InitializeSystem(void) {
    ADCON1 |= 0x0F;
//    TRISCbits.TRISC6=0;
//    TRISCbits.TRISC7 =0;
//    LATCbits.LATC6 =0;
//    LATCbits.LATC7=0;
    USBDeviceInit();
#if defined(USE_UART)
    Init_UART(BAUD_RATE);
    Init_Tran_UART();
    Init_Rec_UART();
#endif
#if defined(USE_LCD)
    Init_PORTS();
    Init_LCD();
#endif
}
示例#30
0
文件: usb_user.c 项目: TexZK/RATT
void Usb_UserInit( void )
{
#ifndef	DONT_USE_DEBUG_CONSOLE
	Debug_PrintConst_Initializing();
    Debug_PrintRom_( "USB" );
    Debug_PrintConst_Dots();
#endif
    
    // Reset variables
	usb_outHandle = 0;
	usb_inHandle = 0;
	
	// Initialize USB module
    USBDeviceInit();

#ifndef	DONT_USE_DEBUG_CONSOLE    
    Debug_PrintConst_Ok();
    Debug_PrintConst_NewLine();
#endif
}