Exemplo n.º 1
0
void main(void)
{
  /* Write your local variable definition here */
  int i = 0;
  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/

  /* Write your code here */
  /* For example: for(;;) { } */
  for(;;) {
	  i++;
	  if ((i%5)==0) {
		  data[0]++; /* change data */
		  TestFlash();
	  }
	  LED1_Neg();
	  WAIT1_Waitms(250);
  }

  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
  #ifdef PEX_RTOS_START
    PEX_RTOS_START();                  /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
  #endif
  /*** End of RTOS startup code.  ***/
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;;){}
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
Exemplo n.º 2
0
/******************************************************************
*  Function: TopMenu
*
*  Purpose: Generates the top level menu.
* 
******************************************************************/
static int TopMenu( void )
{
  char ch;

  /* Print the top-level menu to stdout */
  while (1)
  {
    MenuBegin("      Memory Test Main Menu");
    MenuItem( 'a', "Test RAM" );
    MenuItem( 'b', "Test Flash");
    ch = MenuEnd( 'a', 'b' );

    switch(ch)
    {
      MenuCase('a',TestRam());
      MenuCase('b',TestFlash(TEST));
      MenuCase('e',FlashErase());       /* hidden option */
      MenuCase('m',TestFlash(SHOWMAP)); /* hidden option */
    }
    if (ch == 'q')
      break;
  }
  return (ch);
}
Exemplo n.º 3
0
void ViewTest2::TestMouse()
{
	RECT rcSrc = {0,0,96,96};
	WrapMouseDown(0, 0, rcSrc, rcSrc);
	WrapMouseDown(40, 40, rcSrc, rcSrc);
	WrapMouseDown(0, 40, rcSrc, rcSrc);
	WrapMouseDown(40, 0, rcSrc, rcSrc);

	WrapMouseMoveDrag(40, 40, rcSrc, rcSrc);
	WrapMouseUp(40, 40, rcSrc, rcSrc);

	WrapMouseDown(0, 0, rcSrc, rcSrc);
	WrapMouseDownExtended(40, 40, rcSrc, rcSrc);
	WrapMouseUp(40, 40, rcSrc, rcSrc);

	// Be weird for a little bit.
	for (int i=0; i < 5; i++)
		TestFlash();
}
Exemplo n.º 4
0
int main(void)
{
    unsigned char bmButtons = 0;

    TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK);
    printf("-- USB Device HID Mouse Project %s --\n\r", SOFTPACK_VERSION);
    printf("-- %s\n\r", BOARD_NAME);
    printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

    // SPP +
    int i;

    button_flag = 0;

    //Enable RESET
    m_pRSTC->RSTC_RCR = 0xA5000008;
    m_pRSTC->RSTC_RMR = 0xA5000001;
    Delay(1000);

    // Init USB device
    //AT91F_USB_Open();

    // Configure the RTT:
    *AT91C_RTTC_RTMR = BUTTON_SAMPLING;

    // Set in PIO mode and Configure in Input
    //AT91F_PIOA_CfgPMC();

    // InitMAM
    InitMMA();

    // InitADC
    ADCInit();

    // UART0 Init
    InitUSART0();

    // Stat led
    s_pPio->PIO_PER   = BIT31;
    // Configure PA31 as output
    s_pPio->PIO_OER   = BIT31;
    // Set PA31 to HIGH
    s_pPio->PIO_SODR  = BIT31;


    // Test flash
    if(TestFlash()) 
    {
      for(i=0; i<20; i++) 
      {
        s_pPio->PIO_CODR  = BIT31; Delay(150000);
        s_pPio->PIO_SODR  = BIT31; Delay(150000);
      }
    }

    // Button
    // Configure P20 as input
    s_pPio->PIO_ODR   = BIT20;
    // Enable
    s_pPio->PIO_PER   = BIT20;

    Delay(1000);

    // CALIBRATE WHEN BUTT IS PRESS
    // while((s_pPio->PIO_PDSR&BIT20)==BIT20);

    Delay(1000);
    // SPP -

    // If they are present, configure Vbus & Wake-up pins
    PIO_InitializeInterrupts(0);

    WAKEUP_CONFIGURE();

    // If there is on board power, switch it off
  #ifdef PIN_USB_POWER_ENB
  { const Pin pinUsbPwr = PIN_USB_POWER_ENB;
    PIO_Configure(&pinUsbPwr, 1);
  }
  #endif

    // Initialize key statuses and configure push buttons
#if defined(at91cap9dk)
    const Pin pinRow0 = PIN_KEYBOARD_ROW0;
    PIO_Configure(&pinRow0, 1);
#endif       
    PIO_Configure(pinsJoystick, PIO_LISTSIZE(pinsJoystick));

    // HID driver initialization
    HIDDMouseDriver_Initialize();

    // connect if needed
    VBUS_CONFIGURE();
    
    // Infinite loop
    while (1) 
    {
       // SPP +
       #define TIMEOUT  100
       static int Timeout = TIMEOUT;
        GetCoordinates();
        base_y = Coordinates[0]/NSAMPLE;
        base_x = Coordinates[1]/NSAMPLE;
        base_z = Coordinates[2]/NSAMPLE;
       // SPP -

        if( USBState == STATE_SUSPEND ) 
        {
            TRACE_DEBUG("suspend  !\n\r");
            USBState = STATE_IDLE;
            LowPowerMode();
        }
        if( USBState == STATE_RESUME ) 
        {
            // Return in normal MODE
            NormalPowerMode();
            USBState = STATE_IDLE;
            TRACE_DEBUG("resume !\n\r");
        }
        if (USBD_GetState() < USBD_STATE_CONFIGURED)
            continue;

        if (!Timeout)
        {
        
            unsigned char status;

            do 
            {
               status = HIDDMouseDriver_ChangePoints(bmButtons, base_x, base_y);
            }
            while (status != USBD_STATUS_SUCCESS);
            Timeout = TIMEOUT;
        }
        else
           Timeout--;
        
    }
}
Exemplo n.º 5
0
//
//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	HDC hdc;
	int wmId, wmEvent;
	PAINTSTRUCT ps;

	switch (message) 
	{
	case WM_COMMAND:
		wmId    = LOWORD(wParam); 
		wmEvent = HIWORD(wParam); 
		// Parse the menu selections:
		switch (wmId)
		{	
		case IDM_HELP_ABOUT:
			DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
			break;
		case IDM_FILE_EXIT:
			SendMessage (hWnd, WM_CLOSE, 0, 0);
			break;
		case IDM_FLASH_ERASE:
			if (gSystemErrorHasOccured != TRUE){
				LoadString(hInst, IDS_FLASH_ERASE, szStatus, MAX_LOADSTRING);
				InvalidateRect(hWnd,NULL,TRUE);
				UpdateWindow(hWnd);
				Sleep(100);
				EraseFlash(hWnd);
				LoadString(hInst, IDS_IDLE, szStatus, MAX_LOADSTRING);
				InvalidateRect(hWnd,NULL,TRUE);
				UpdateWindow(hWnd);
				Sleep(100);
						
			}
			else
				SystemErrorAlert(hWnd);
			break;
		case IDM_FLASH_TEST_TIMED:
			LoadString(hInst, IDS_FLASH_TEST_TIMED, szStatus, MAX_LOADSTRING);
			InvalidateRect(hWnd,NULL,TRUE);
			gTimerID = SetTimer(hWnd,BB_TEST_FLASH,50,NULL);
			break;
		case IDM_FLASH_TEST_STRAIGHT:
			TestFlash(hWnd);
			break;
		case IDM_FLASH_SAVE:
			LoadString(hInst, IDS_FLASH_SAVE_BL, szStatus, MAX_LOADSTRING);					
			InvalidateRect(hWnd,NULL,TRUE);
			UpdateWindow(hWnd);
			Sleep(100);
			SaveFlash(hWnd);
			LoadString(hInst, IDS_IDLE, szStatus, MAX_LOADSTRING);
			InvalidateRect(hWnd,NULL,TRUE);
			UpdateWindow(hWnd);
			Sleep(100);
			break;
		case IDM_FLASH_SAVE_WINCE:
			LoadString(hInst, IDS_FLASH_SAVE_WINCE, szStatus, MAX_LOADSTRING);					
			InvalidateRect(hWnd,NULL,TRUE);
			UpdateWindow(hWnd);
			Sleep(100);
			SaveFlashWince(hWnd);
			LoadString(hInst, IDS_IDLE, szStatus, MAX_LOADSTRING);
			InvalidateRect(hWnd,NULL,TRUE);
			UpdateWindow(hWnd);
			Sleep(100);
			break;
		case IDM_FLASH_PROTECT_WINCE:
			LoadString(hInst, IDS_FLASH_PROTECT_WINCE, szStatus, MAX_LOADSTRING);					
			InvalidateRect(hWnd,NULL,TRUE);
			UpdateWindow(hWnd);
			Sleep(100);
			ProtectWince(hWnd);
			LoadString(hInst, IDS_IDLE, szStatus, MAX_LOADSTRING);
			InvalidateRect(hWnd,NULL,TRUE);
			UpdateWindow(hWnd);
			Sleep(100);
			break;
		case IDM_FLASH_SAVE_GZ:
			LoadString(hInst, IDS_FLASH_SAVE_BL_GZ, szStatus, MAX_LOADSTRING);					
			InvalidateRect(hWnd,NULL,TRUE);
			UpdateWindow(hWnd);
			Sleep(100);
			SaveFlashGZ(hWnd);
			LoadString(hInst, IDS_IDLE, szStatus, MAX_LOADSTRING);
			InvalidateRect(hWnd,NULL,TRUE);
			UpdateWindow(hWnd);
			Sleep(100);
			break;
		case IDM_FLASH_PROGRAM:
			if (gSystemErrorHasOccured != TRUE){
				if (LoadImage(hWnd) != TRUE) //loaded, so program it
					return 0;
				LoadString(hInst, IDS_FLASH_PROTECT_WINCE, szStatus, MAX_LOADSTRING);
				InvalidateRect(hWnd,NULL,TRUE);
				UpdateWindow(hWnd);
				Sleep(100);
				ProtectWince(hWnd);

				if (gSystemErrorHasOccured == TRUE)
					return 0;

				LoadString(hInst, IDS_FLASH_ERASE, szStatus, MAX_LOADSTRING);
				InvalidateRect(hWnd,NULL,TRUE);
				UpdateWindow(hWnd);
				Sleep(100);
				EraseFlash(hWnd);

				LoadString(hInst, IDS_FLASH_PROGRAM, szStatus, MAX_LOADSTRING);
				InvalidateRect(hWnd,NULL,FALSE);
				UpdateWindow(hWnd);
				Sleep(100);
				if (ProgramFlash(hWnd) == TRUE)
					VerifyFlash(hWnd);						
				LoadString(hInst, IDS_IDLE, szStatus, MAX_LOADSTRING);
				InvalidateRect(hWnd,NULL,TRUE);
				UpdateWindow(hWnd);
				Sleep(100);
			}
			else
				SystemErrorAlert(hWnd);
			break;
		case IDM_FLASH_PROGRAM_XPLE:
			if (gSystemErrorHasOccured != TRUE){
				if (LoadImage(hWnd) != TRUE) //loaded, so program it
					return 0;
				for (int i=0; i < 50; i++){
					LoadString(hInst, IDS_FLASH_PROTECT_WINCE, szStatus, MAX_LOADSTRING);
					InvalidateRect(hWnd,NULL,TRUE);
					UpdateWindow(hWnd);
					Sleep(100);
					ProtectWince(hWnd);

					if (gSystemErrorHasOccured == TRUE)
						return 0;

					LoadString(hInst, IDS_FLASH_ERASE, szStatus, MAX_LOADSTRING);
					InvalidateRect(hWnd,NULL,TRUE);
					UpdateWindow(hWnd);
					Sleep(100);
					EraseFlash(hWnd);

					LoadString(hInst, IDS_FLASH_PROGRAM, szStatus, MAX_LOADSTRING);
					InvalidateRect(hWnd,NULL,FALSE);
					UpdateWindow(hWnd);
					Sleep(100);
					ProgramFlash(hWnd);
					LoadString(hInst, IDS_IDLE, szStatus, MAX_LOADSTRING);
					InvalidateRect(hWnd,NULL,TRUE);
					UpdateWindow(hWnd);
					Sleep(100);
				}
				VerifyFlash(hWnd);
			}
			else
				SystemErrorAlert(hWnd);
			break;
				
		case IDM_FLASH_SHOW:
			ShowFlash(hWnd);
			break;
		case IDM_FLASH_VERIFY:
			VerifyFlash(hWnd);
			break;
		case IDOK:
			//SendMessage(hWnd, WM_ACTIVATE, MAKEWPARAM(WA_INACTIVE, 0), (LPARAM)hWnd);
			//SendMessage (hWnd, WM_CLOSE, 0, 0);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		break;
	case WM_TIMER:
		// this method isn;t used anymore, really
		KillTimer(hWnd,wParam);
		if (wParam == BB_TEST_FLASH){
			TestFlash(hWnd);
			LoadString(hInst, IDS_IDLE, szStatus, MAX_LOADSTRING);
			InvalidateRect(hWnd,NULL,TRUE);
		}
		else{}

	case WM_CREATE:
		hwndCB = CreateRpCommandBar(hWnd);
		break;
	case WM_PAINT:
		RECT rt;
		hdc = BeginPaint(hWnd, &ps);
		GetClientRect(hWnd, &rt);
		DrawText(hdc, szStatus, _tcslen(szStatus), &rt, 
			 DT_CENTER);
		EndPaint(hWnd, &ps);
		break; 
	case WM_DESTROY:
		CommandBar_Destroy(hwndCB);
		PostQuitMessage(0);
		break;
	case WM_SETTINGCHANGE:
		SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai);
     		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}
Exemplo n.º 6
0
//*--------------------------------------------------------------------------------------
//* Function Name       : main
//* Object              :
//*--------------------------------------------------------------------------------------
int main ( void )
{
//    char button = 0;
//    int x = 0, y = 0, j = 0;
//    int adc;
//    int i = 0;
    int x,y,z,i;

    button_flag = 0;

    //Init trace DBGU
    //AT91F_DBGU_Init();
    //AT91F_DBGU_Printk("\n\r-I- BasicUSB 1.1 (USB_DP_PUP) \n\r0) Set Pull-UP 1) Clear Pull UP\n\r");

    //Enable RESET
    m_pRSTC->RSTC_RCR = 0xA5000008;
    m_pRSTC->RSTC_RMR = 0xA5000001;
    Delay(1000);

    // Init USB device
    AT91F_USB_Open();

    // Configure the RTT:
    *AT91C_RTTC_RTMR = BUTTON_SAMPLING;

    // Set in PIO mode and Configure in Input
    AT91F_PIOA_CfgPMC();
    // AT91F_PIO_CfgInput(AT91C_BASE_PIOA, (SW1|SW2));

   // Wait for the end of enumeration
   // while (!HID.IsConfigured(&HID));

    // InitMAM
    InitMMA();

    // InitADC
    ADCInit();

    // UART0 Init
    InitUSART0();

    // Stat led
    s_pPio->PIO_PER   = BIT31;
    // Configure PA31 as output
    s_pPio->PIO_OER   = BIT31;
    // Set PA31 to HIGH
    s_pPio->PIO_SODR  = BIT31;


    // Test flash
    if(TestFlash()) {

      for(i=0; i<20; i++) {
        s_pPio->PIO_CODR  = BIT31; Delay(150000);
        s_pPio->PIO_SODR  = BIT31; Delay(150000);
      }
    }

    // Button
    // Configure P20 as input
    s_pPio->PIO_ODR   = BIT20;
    // Enable
    s_pPio->PIO_PER   = BIT20;

    Delay(1000);

    // CALIBRATE WHEN BUTT IS PRESS
    // while((s_pPio->PIO_PDSR&BIT20)==BIT20);

    Delay(1000);

    // Get coordinates
    GetCoordinates();

    base_y = Coordinates[0]/NSAMPLE;
    base_x = Coordinates[1]/NSAMPLE;
    base_z = Coordinates[2]/NSAMPLE;


    // Start waiting some cmd
    while (1) {

      // Check enumeration
      if (HID.IsConfigured(&HID)) {

        // check button status
        if((s_pPio->PIO_PDSR&BIT20)==0) {

          // Set PA31 to LOW
          s_pPio->PIO_CODR  = BIT31;

          // set button flag
          button_flag = 0x01;

          Delay(1000);

        }
        else {

          // Set PA31 to HIGH
          // s_pPio->PIO_SODR  = BIT31;

          // clear button flag
          button_flag = 0x00;

        }


        GetCoordinates();

        Delay(10000);

//*        if((j++)==100) {
//*
//*         print_view = PRINT_COORDINATES;
//*         write_report_USART0();
//*
//*         // print_view = PRINT_DIVERSION;
//*         // write_report_USART0();
//*
//*         j=0;
//*        }

        y = 478 - Coordinates[0]/NSAMPLE;
        // y = base_y - Coordinates[0]/NSAMPLE;

        if(y>40) {
          if(y<50)
            HID.SendReport(&HID, button_flag, 0, -1);
          else if (y<100)
            HID.SendReport(&HID, button_flag, 0, -2);
          else if (y<150)
            HID.SendReport(&HID, button_flag, 0, -3);
          else if (y<200)
            HID.SendReport(&HID, button_flag, 0, -6);
          else
            HID.SendReport(&HID, button_flag, 0, -16);
        }
        else if(y<-40){
        if(y>-50)
            HID.SendReport(&HID, button_flag, 0, 1);
          else if (y>-100)
            HID.SendReport(&HID, button_flag, 0, 2);
          else if (y>-150)
            HID.SendReport(&HID, button_flag, 0, 3);
          else if (y>-200)
            HID.SendReport(&HID, button_flag, 0, 6);
          else
            HID.SendReport(&HID, button_flag, 0, 16);

        }

        x = 565 - Coordinates[1]/NSAMPLE;
        // x = base_x - Coordinates[1]/NSAMPLE;

        if(x>40) {
          if(x<50)
            HID.SendReport(&HID, button_flag, -1, 0);
          else if (x<100)
            HID.SendReport(&HID, button_flag, -2, 0);
          else if (x<150)
            HID.SendReport(&HID, button_flag, -3, 0);
          else if (x<200)
            HID.SendReport(&HID, button_flag, -6, 0);
          else
            HID.SendReport(&HID, button_flag, -16, 0);
        }
        else if(x<-40){
          if(x>-50)
            HID.SendReport(&HID, button_flag, 1, 0);
          else if (x>-100)
            HID.SendReport(&HID, button_flag, 2, 0);
          else if (x>-150)
            HID.SendReport(&HID, button_flag, 3, 0);
          else if (x>-200)
            HID.SendReport(&HID, button_flag, 6, 0);
          else
            HID.SendReport(&HID, button_flag, 16, 0);

        }

        // just test Z coordinate
        z = Coordinates[2]/NSAMPLE;

        if(z<300) {
          s_pPio->PIO_CODR  = BIT31;
        }
        else {
          s_pPio->PIO_SODR  = BIT31;
        }

        Delay(20);



//*      x = ((150) - GetADC4())/20;
//*      HID.SendReport(&HID, button, x, 0);
//*      Delay(50);
//*      HID.SendReport(&HID, button, ((base_y) - GetADC5())/50, 0);
//*      Delay(50);
//*      HID.SendReport(&HID, button, ((base_z) - GetADC6())/50, 0);
//*      Delay(50);
//*
//*       button = 0;
//*
//*       for(j=0; j<100; j++) {
//*           HID.SendReport(&HID, button, 1, 0);
//*           Delay(50);
//*       }
//*
//*       for(j=0; j<100; j++) {
//*           HID.SendReport(&HID, button, 0, 1);
//*           Delay(50);
//*       }
//*
//*       for(j=0; j<100; j++) {
//*         HID.SendReport(&HID, button, -1, 0);
//*         Delay(50);
//*       }
//*
//*       for(j=0; j<100; j++) {
//*         HID.SendReport(&HID, button, 0, -1);
//*         Delay(50);
//*       }

      }
   }
}