Example #1
0
/*********************************************************************
* Function: void SYSTEM_Tasks(void)
*
* Overview: Runs system level tasks that keep the system running
*
* PreCondition: System has been initalized with SYSTEM_Initialize()
*
* Input: None
*
* Output: None
*
********************************************************************/
void SYSTEM_Tasks(void)
{
    switch(softStartStatus)
    {
        case SOFT_START_POWER_OFF:
            break;

        case SOFT_START_POWER_START:
            if(USBGetDeviceState() != CONFIGURED_STATE)
            {
                break;
            }
            
            AppPowerEnable();
            softStartStatus = SOFT_START_POWER_ENABLED;
            break;

        case SOFT_START_POWER_ENABLED:
            if(AppPowerReady() == true)
            {
                softStartStatus = SOFT_START_POWER_READY;
                LED_Enable(LED_USB_DEVICE_STATE);
                LED_Enable(LED_USB_DEVICE_HID_CUSTOM);
				
                ADC_SetConfiguration(ADC_CONFIGURATION_DEFAULT);
                ADC_Enable(ADC_CHANNEL_POTENTIOMETER);
            }
            break;
            
        case SOFT_START_POWER_READY:
            break;
    }
}
Example #2
0
/*********************************************************************
* Function: void SYSTEM_Tasks(void)
*
* Overview: Runs system level tasks that keep the system running
*
* PreCondition: System has been initalized with SYSTEM_Initialize()
*
* Input: None
*
* Output: None
*
********************************************************************/
void SYSTEM_Tasks(void)
{
    switch(softStartStatus)
    {
        case SOFT_START_POWER_OFF:
            break;

        case SOFT_START_POWER_START:
            if(USBGetDeviceState() != CONFIGURED_STATE)
            {
                break;
            }

            AppPowerEnable();
            softStartStatus = SOFT_START_POWER_ENABLED;
            break;

        case SOFT_START_POWER_ENABLED:
            if(AppPowerReady() == true)
            {
                softStartStatus = SOFT_START_POWER_READY;
                LED_Enable(LED_USB_DEVICE_STATE);
            }
            break;

        case SOFT_START_POWER_READY:
            break;
    }
}
Example #3
0
/********************************************************************
 * Function:        void ProcessIO(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function is a place holder for other user
 *                  routines. It is a mixture of both USB and
 *                  non-USB tasks.
 *
 * Note:            None
 *******************************************************************/
void ProcessIO(void)
{   
	static unsigned char cerr,nl,n,i,b;
	static unsigned int p,q;
	static rtccTimeDate td;    
	// Soft Start the APP_VDD
    if(AppPowerReady() == FALSE) return;

/* --------------------
 * User input section, handles touchbuttons, and the menu button
 * for less cpu stress it runs on every 2000th loop.
 * buttonstate bits flags if the butoon pressed or released for
 * exclude repetition. position and screen variables points the
 * cursors place, and the action depends on it (incrementing,
 * decrementing variables even the position and screen variable.
 * if the screen variable changed, the screenvalid become false
 * pointing the drawing section to refresh screen.
 * if the positon variable changed, the positionchanged become
 * true pointing that the cursor moves. 	
 * -------------------- */

	if(executionTick++>2000)
	{
		executionTick=0;       
       //<editor-fold desc="reset button">
		if(buttonstate.bits.b3)									// button RB0 : Menu
			{ 
				if(PORTBbits.RB0) 
				{
					resetcounter=0;
					screenvalid=0;
					buttonstate.bits.b3=0;
				}
				else  
				{
					strcpypgm2ram(cbuf,(const rom far char *)"Reset ");
					if(!(resetcounter++%10)||(!resetcounter))
					{
						itoa(10-resetcounter/10,cbuf+6);
						rjustify(cbuf+6,2);
						oledPutStringINV((unsigned char *)cbuf,7,0);
					}
					if(resetcounter>105)
					{
						_asm
						RESET
						_endasm
					}						
				}
			}
		else
			if(!PORTBbits.RB0)
Example #4
0
/********************************************************************
 * Function:        void ProcessIO(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function is a place holder for other user
 *                  routines. It is a mixture of both USB and
 *                  non-USB tasks.
 *
 * Note:            None
 *******************************************************************/
void ProcessIO(void)
{   
    //BMA150_REG reg_MSB;
    //BMA150_REG reg_LSB;
	unsigned int w1;

	if(DemoIntroState == 0xFF)
    {
	    //BL_CheckLoaderEnabled();
		
		if (g_ballGth == 0 && g_ballGtt == 0)
			Step(0.04f, 1);
		else
			Step(0.04f, 0);
		DrawScene();

		if (g_endGame == 1)
		{
			g_endGame = 0;
			DemoIntroState = 8;
		}
		
		w1 = mTouchReadButton(3);
		if (w1 < 600)
		{
			DemoIntroState = 6;
			g_menuSelected = 0;
			FillDisplay(0x00);
		}
		
    }
	
    // User Application USB tasks
    //if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return;

	// Soft Start the APP_VDD
    if(AppPowerReady() == FALSE) return;

    DemoIntroduction();
}		//end ProcessIO
Example #5
0
/******************************************************************************
 * Function:        void USBCBWakeFromSuspend(void)
 *
 * Overview:        The host may put USB peripheral devices in low power
 *					suspend mode (by "sending" 3+ms of idle).  Once in suspend
 *					mode, the host may wake the device back up by sending non-
 *					idle state signalling.
 *					
 *					This call back is invoked when a wakeup from USB suspend 
 *					is detected.
 *****************************************************************************/
void USBCBWakeFromSuspend(void)
{
	// If clock switching or other power savings measures were taken when
	// executing the USBCBSuspend() function, now would be a good time to
	// switch back to normal full power run mode conditions.  The host allows
	// a few milliseconds of wakeup time, after which the device must be 
	// fully back to normal, and capable of receiving and processing USB
	// packets.  In order to do this, the USB module must receive proper
	// clocking (IE: 48MHz clock must be available to SIE for full speed USB
	// operation).

	#if defined(SOFTSTART_ENABLED)
	while(AppPowerReady() == FALSE)
	{
		// Soft Start the APP_VDD	
	}
	#endif
	
	set_osc_48Mhz();
	
	//OSCCONbits.SCS0  = 0; 	// use primary clock
	//OSCCONbits.SCS1  = 0; 	//  (PRI_RUN)
}
Example #6
0
/********************************************************************
 * Function:        void ProcessIO(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function is a place holder for other user
 *                  routines. It is a mixture of both USB and
 *                  non-USB tasks.
 *
 * Note:            None
 *******************************************************************/
void ProcessIO(void)
{
    if(DemoIntroState == 0xFF)
    {
        BL_CheckLoaderEnabled();
    }

    // User Application USB tasks
    if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return;

    // Soft Start the APP_VDD
    if(AppPowerReady() == FALSE) return;

    DemoIntroduction();

    if(!HIDRxHandleBusy(USBOutHandle))        //Check if data was received from the host.
    {

        switch(ReceivedDataBuffer[0])       //Look at the data the host sent, to see what kind of application specific command it sent.
        {
        case 0x80:  //mTouch callibration command
            mTouchCalibrate();
            break;

        case 0x20:
        {
            WORD potVoltage;

            if(!HIDTxHandleBusy(USBInHandle))
            {
                /* Select ADC channel */
                ADCON0bits.CHS = 4;

                /* Make sure A/D interrupt is not set */
                PIR1bits.ADIF = 0;

                /* Begin A/D conversion */
                ADCON0bits.GO=1;
                //Wait for A/D convert complete
                while(!PIR1bits.ADIF);

                /* Get the value from the A/D */
                potVoltage = ADRES;

                ToSendDataBuffer[0] = 0x20;
                ToSendDataBuffer[1] = (BYTE)(potVoltage);
                ToSendDataBuffer[2] = (BYTE)(potVoltage>>8);

                USBInHandle = HIDTxPacket(HID_EP,(BYTE*)&ToSendDataBuffer[0],64);
            }
        }
        break;

        case 0x30:
        {
            WORD w;

            if(!HIDTxHandleBusy(USBInHandle))
            {
                w = mTouchReadButton(0);

                ToSendDataBuffer[0] = 0x30;
                ToSendDataBuffer[1] = (BYTE)w;
                ToSendDataBuffer[2] = (BYTE)(w>>8);

                USBInHandle = HIDTxPacket(HID_EP,(BYTE*)&ToSendDataBuffer[0],64);
            }
        }
        break;

        case 0x31:
        {
            WORD w;

            if(!HIDTxHandleBusy(USBInHandle))
            {
                w = mTouchReadButton(1);

                ToSendDataBuffer[0] = 0x31;
                ToSendDataBuffer[1] = (BYTE)w;
                ToSendDataBuffer[2] = (BYTE)(w>>8);

                USBInHandle = HIDTxPacket(HID_EP,(BYTE*)&ToSendDataBuffer[0],64);
            }
        }