Exemplo n.º 1
0
void CPU_InitializeCommunication()
{
    NATIVE_PROFILE_PAL_COM();
    // STDIO can be different from the Debug Text port
    // do these first so we can print out messages

    if(COM_IsSerial(HalSystemConfig.DebugTextPort))
    {
        USART_Initialize( ConvertCOM_ComPort(HalSystemConfig.DebugTextPort), HalSystemConfig.USART_DefaultBaudRate, USART_PARITY_NONE, 8, USART_STOP_BITS_ONE, USART_FLOW_NONE );
    }

    if(COM_IsSerial(HalSystemConfig.stdio))
    {
        USART_Initialize( ConvertCOM_ComPort(HalSystemConfig.stdio), HalSystemConfig.USART_DefaultBaudRate, USART_PARITY_NONE, 8, USART_STOP_BITS_ONE, USART_FLOW_NONE );
    }

    if(COM_IsUsb(HalSystemConfig.DebugTextPort))
    {
        USB_Configure( ConvertCOM_UsbController(HalSystemConfig.DebugTextPort), NULL );
        USB_Initialize( ConvertCOM_UsbController(HalSystemConfig.DebugTextPort) );
        USB_OpenStream( ConvertCOM_UsbStream(HalSystemConfig.DebugTextPort), USB_DEBUG_EP_WRITE, USB_DEBUG_EP_READ );
    }


    Network_Initialize();
}
Exemplo n.º 2
0
/* reset device, called when receive reset interrupt*/
static void USB_Reset(void)
{
	kal_uint8 ep_num;

//	gUsbDevice.is_configured_now = KAL_FALSE;

	// initialize driver info and system interrupt
	USB_ResetDrv_Info();
	USB_Initialize_Drv();
	USB_Initialize();        /* call class reset function */

	for(ep_num=0;ep_num<gUsbDevice.resource_ep_bulkin_number;ep_num++)
	{
		if(gUsbDevice.ep_bulkin_info[ep_num].ep_reset)
			gUsbDevice.ep_bulkin_info[ep_num].ep_reset();
	}

	for(ep_num=0;ep_num<gUsbDevice.resource_ep_bulkout_number;ep_num++)
	{
		if(gUsbDevice.ep_bulkout_info[ep_num].ep_reset)
			gUsbDevice.ep_bulkout_info[ep_num].ep_reset();
	}

	for(ep_num=0;ep_num<gUsbDevice.resource_ep_intr_number;ep_num++)
	{
		if(gUsbDevice.ep_intr_info[ep_num].ep_reset)
			gUsbDevice.ep_intr_info[ep_num].ep_reset();
	}
}
Exemplo n.º 3
0
static bool gx_joypad_init(void *data)
{
   int i;
   SYS_SetResetCallback(reset_cb);
#ifdef HW_RVL
   SYS_SetPowerCallback(power_callback);
#endif

   (void)data;

   for (i = 0; i < MAX_PADS; i++)
      pad_type[i] = WPAD_EXP_NOCONTROLLER;

   PAD_Init();
#ifdef HW_RVL
   WPADInit();
#endif
#ifdef HAVE_LIBSICKSAXIS
   int i;
   USB_Initialize();
   ss_init();
   for (i = 0; i < MAX_PADS; i++)
      ss_initialize(&dev[i]);
#endif

   gx_joypad_poll();

   return true;
}
Exemplo n.º 4
0
static bool __usbstorage_Startup(void)
{
	if(USB_Initialize() < 0 || USBStorage_Initialize() < 0)
		return false;

	return true;
}
bool DS3_Init()
{
    USB_Initialize();

    if (ss_init() < 0)
    {
        return false;
    }

    ss_initialize(&first);

    return true;
}
Exemplo n.º 6
0
static void *wiiusb_hid_init(void)
{
   unsigned i;
   u8 count;
   int ret;
   usb_device_entry *dev_entries;
   wiiusb_hid_t *hid = (wiiusb_hid_t*)calloc(1, sizeof(*hid));

   (void)ret;

   if (!hid)
      goto error;

   hid->slots = pad_connection_init(MAX_USERS);

   if (!hid->slots)
      goto error;

   dev_entries = (usb_device_entry *)calloc(MAX_USERS, sizeof(*dev_entries));

   if (!dev_entries)
      goto error;

   USB_Initialize();

   if (USB_GetDeviceList(dev_entries, MAX_USERS, USB_CLASS_HID, &count) < 0)
   {
      free(dev_entries);
      goto error;
   }

   for (i = 0; i < count; i++)
   {
      if (dev_entries[i].vid > 0 && dev_entries[i].pid > 0)
         add_adapter(hid, &dev_entries[i]);
   }

   free(dev_entries);

   USB_DeviceChangeNotifyAsync(USB_CLASS_HID, wiiusb_hid_changenotify_cb, (void *)hid);

   return hid;

error:
   wiiusb_hid_free(hid);
   return NULL;
}
Exemplo n.º 7
0
BOOL DebuggerPort_Initialize( COM_HANDLE ComPortNum )
{
    NATIVE_PROFILE_PAL_COM();
    switch(ExtractTransport(ComPortNum))
    {
        case USART_TRANSPORT:
            return USART_Initialize( ConvertCOM_ComPort(ComPortNum), HalSystemConfig.USART_DefaultBaudRate, USART_PARITY_NONE, 8, USART_STOP_BITS_ONE, USART_FLOW_NONE );
        case USB_TRANSPORT:
            if(USB_CONFIG_ERR_OK != USB_Configure( ConvertCOM_UsbController(ComPortNum), NULL )) return FALSE;
            if(!USB_Initialize( ConvertCOM_UsbController(ComPortNum) ))                          return FALSE;
            return USB_OpenStream( ConvertCOM_UsbStream(ComPortNum), USB_DEBUG_EP_WRITE, USB_DEBUG_EP_READ );
        case SOCKET_TRANSPORT:
            return SOCKETS_Initialize(ConvertCOM_SockPort(ComPortNum));
    }

    return FALSE;
}
Exemplo n.º 8
0
static bool gx_joypad_init(void)
{
   SYS_SetResetCallback(reset_cb);
#ifdef HW_RVL
   SYS_SetPowerCallback(power_callback);
#endif

   PAD_Init();
#ifdef HW_RVL
   WPADInit();
#endif
#ifdef HAVE_LIBSICKSAXIS
   int i;
   USB_Initialize();
   ss_init();
   for (i = 0; i < MAX_PADS; i++)
      ss_initialize(&dev[i]);
#endif

   gx_joypad_poll();

   return true;
}
Exemplo n.º 9
0
/* init function, called when user select usb type, 
    entry function for task , B_eanble is D+ detection enable */
void USB_Init(USB_DEVICE_TYPE type, kal_bool b_enable, kal_bool is_ft_mode)
{
#if defined(DRV_USB_MCU_52M)
	#ifndef MCU_52M
		EXT_ASSERT(0, 0, 0, 0);  /* Must 52M */
	#endif   /* MCU_52M */
#endif 	/* MT6218||MT6218B||MT6219 */

	USB_Init_Drv_Info(KAL_FALSE);			/*initialize driver parameters*/
	USB_Init_Device_Status();	/*initialize global variable gUsbDevice*/

	USB_Init_Acm_Status();
	gUsbDevice.device_type = USB_CDC_ACM;

	/* register reset and ep0 interrupt handler to driver info*/
	USB_Register_Drv_Info(USB_DRV_HDLR_RESET, 0, USB_Reset);
	USB_Register_Drv_Info(USB_DRV_HDLR_EP0, 0, USB_Endpoint0_Hdlr);

	/* create descriptors */
	USB_Software_Create();

	if (is_ft_mode == KAL_TRUE)
	{
		/* reset and initialize system initial value and registers*/
		USB_Reset_Drv();  /* reset hw power register */
		USB_Initialize_Drv();

		/* initailize according to application*/
		USB_Initialize();
	
		USB_Set_DP_Pull_High(KAL_TRUE);
	}
	else
		USB_Software_Init();  
	
}
Exemplo n.º 10
0
void ApplicationEntryPoint()
{
    UINT32 ComEvent;

    g_State.Initialize();

    ComEvent = 0;
    if(COM_IsSerial(g_State.UsartPort) && (g_State.UsartPort != COM_NULL))
    {
        ComEvent = SYSTEM_EVENT_FLAG_COM_IN;
    }

#if !defined(TARGETLOCATION_RAM)
    g_State.WaitForActivity = (g_State.ProgramCount != 0); // is there a main app?

#else
    g_State.WaitForActivity = FALSE;      // forever
#endif

    {
        UINT32 ButtonsPressed;
        UINT32 ButtonsReleased;
        char   c;

        // clear any events present from startup
        while(Events_Get( SYSTEM_EVENT_FLAG_ALL ));

        // clear any junk from com port buffers
        while(DebuggerPort_Read( g_State.UsartPort, &c, sizeof(c) ));

        // clear any junk from button buffer
        while(Buttons_GetNextStateChange( ButtonsPressed, ButtonsReleased ));
    }

    {
        BOOL       ProcessingSREC     = FALSE;
        BOOL       ProcessingXREC     = FALSE;
        INT32      ProcessingZENFLASH = 0;
        INT32      Mode               = 0;
        INT32      MenuChoice         = 1;      // main application location when USB not enabled
        BOOL       MenuUpdate         = TRUE;
        UINT32     USBEvent           = 0;
        COM_HANDLE ReadPort           = COM_NULL;
        int        MenuOffset         = 1;      // no USB enabled
        INT64      WaitTimeout        = 0;

#if defined(PLATFORM_ARM_MOTE2)
        CPU_GPIO_SetPinState( LED1_GREEN, LED_ON );
#endif

        if(g_State.WaitForActivity)
        {
            WaitTimeout = HAL_Time_CurrentTime() + (INT64)g_State.WaitInterval * (10 * 1000);

            hal_printf( "Waiting %d.%03d second(s) for hex upload\r\n", g_State.WaitInterval / 1000, g_State.WaitInterval % 1000 );
        }
        else
        {
            hal_printf( "Waiting forever for hex upload\r\n" );
        }

        // checking the existence of Usb Driver, all the default values are set to no USB
        if( USB_DEVICE_STATE_NO_CONTROLLER != USB_GetStatus( ConvertCOM_UsbController(g_State.UsbPort) ) )
        {
            g_State.UsingUsb = TRUE;

            MenuChoice = 2;
            MenuOffset = 2;
        }


        while(true)
        {
            if(MenuUpdate)
            {
                MenuUpdate = FALSE;

                LCD_Clear();
                hal_fprintf( STREAM_LCD, "\f");

                switch(Mode)
                {
                case 0:
                    hal_fprintf( STREAM_LCD, "   Zen Boot\r\n\r\n" );

                    hal_fprintf( STREAM_LCD, "%c PortBooter\r\n", MenuChoice == 0 ? '*' : ' ' );

                    if(g_State.UsingUsb)
                    {
                        hal_fprintf( STREAM_LCD, "%c FlashUSB\r\n", MenuChoice == 1 ? '*' : ' ' );
                    }


                    for(int i = 0; i < g_State.ProgramCount; i++)
                    {
                        hal_fprintf( STREAM_LCD, "%c Prg:%08x\r\n", (i+MenuOffset) == MenuChoice ? '*' : ' ', g_State.Programs[i] );
                    }
                    break;

                case 1:
                    hal_printf( "PortBooter v%d.%d.%d.%d\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, VERSION_REVISION);
                    hal_fprintf( STREAM_LCD, "Waiting forever for hex upload\r\n"         );
                    break;

                case 2:
                    hal_fprintf( STREAM_LCD, "FlashUSB\r\n"                       );
                    hal_fprintf( STREAM_LCD, "Waiting forever for hex upload\r\n" );
                    break;
                }
            }

            UINT32 Events = Events_WaitForEvents( ComEvent | SYSTEM_EVENT_FLAG_BUTTON | SYSTEM_EVENT_FLAG_USB_IN, 2000 );

            if(Events & SYSTEM_EVENT_FLAG_BUTTON)
            {
                UINT32 ButtonsPressed;
                UINT32 ButtonsReleased;

                Events_Clear( SYSTEM_EVENT_FLAG_BUTTON );

                while(Buttons_GetNextStateChange( ButtonsPressed, ButtonsReleased ));
                {
                    if(g_State.SerialPortActive == FALSE)
                    {
                        //printf("%02x %02x\r\n", ButtonsPressed, ButtonsReleased);

                        // up
                        if(ButtonsPressed & BUTTON_UP)
                        {
                            switch(Mode)
                            {
                            case 0:
                                MenuChoice = __max( MenuChoice-1, 0 );
                                break;
                            }

                            g_State.WaitForActivity = FALSE;
                            MenuUpdate              = TRUE;
                        }

                        // down
                        if(ButtonsPressed & BUTTON_DOWN)
                        {
                            switch(Mode)
                            {
                            case 0:
                                MenuChoice = __min( MenuChoice+1, g_State.ProgramCount + MenuOffset-1 );
                                break;
                            }

                            g_State.WaitForActivity = FALSE;
                            MenuUpdate              = TRUE;
                        }

                        // enter button
                        if(ButtonsPressed & BUTTON_ENTR)
                        {
                            switch(Mode)
                            {
                            case 0:
                                if(MenuChoice == 0)
                                {
                                    Mode = 1;

                                    //UsingUsb = FALSE;
                                }
                                else if(g_State.UsingUsb && MenuChoice == 1)
                                {
                                    Mode = 2;
                                    USB_Configure( ConvertCOM_UsbController(g_State.UsbPort), &UsbDefaultConfiguration );
                                    USB_Initialize( ConvertCOM_UsbController(g_State.UsbPort) );
                                    USB_OpenStream( ConvertCOM_UsbStream(g_State.UsbPort), USB_DEBUG_EP_WRITE, USB_DEBUG_EP_READ );
                                    //UsingUsb = TRUE;
                                }
                                else
                                {
                                    StartApplication( (void (*)())g_State.Programs[MenuChoice-MenuOffset] );
                                }
                                break;

                            case 1:
                                Mode = 0;
                                break;

                            case 2:
                                // USB_Uninitialize();
                                Mode = 0;
                                break;
                            }

                            g_State.WaitForActivity = FALSE;
                            MenuUpdate              = TRUE;
                        }

                        if(ButtonsReleased)
                        {
                            MenuUpdate = TRUE;
                        }
                    }
                }
            }

            if((Events & ComEvent) || (Events & SYSTEM_EVENT_FLAG_USB_IN))
            {
                char c;

                if(Events & ComEvent)
                {
                    Events_Clear( ComEvent );

                    ReadPort              = g_State.UsartPort;
                    g_State.pStreamOutput = ReadPort;
                }
                else
                {
                    USBEvent = USB_GetEvent( ConvertCOM_UsbController(g_State.UsbPort), USB_EVENT_ALL );
                    if( !(USBEvent & g_State.UsbEventCode) )
                        continue;

                    g_State.pStreamOutput = g_State.UsbPort;
                    ReadPort              = g_State.UsbPort;
                }

                while(DebuggerPort_Read( ReadPort, &c, sizeof(c) ))
                {
                    if(ProcessingSREC)
                    {
                        ProcessingSREC = g_SREC.Process( c );
                    }
                    else if(ProcessingXREC)
                    {
                        ProcessingXREC = g_XREC.Process( c );
                    }
                    else if(ProcessingZENFLASH)
                    {
                        const char Signature[] = "ZENFLASH\r";

                        //printf( "Got %d at %d\r\n", c, ProcessingZENFLASH );
                        if(Signature[ProcessingZENFLASH++] == c)
                        {
                            if(Signature[ProcessingZENFLASH] == 0)
                            {
                                SignalActivity();
                                ProcessingZENFLASH = 0;
                            }
                        }
                        else
                        {
                            ProcessingZENFLASH = 0;
                        }
                    }
                    else if('S' == c)
                    {
                        ProcessingSREC = TRUE;
                    }
                    else if('X' == c)
                    {
                        ProcessingXREC = TRUE;
                    }
                    else if('Z' == c)
                    {
                        ProcessingZENFLASH = 1;
                    }
                }
            }

            if(g_State.WaitForActivity && WaitTimeout < HAL_Time_CurrentTime())
            {
#if defined(PLATFORM_ARM_MOTE2)
                CPU_GPIO_SetPinState(LED1_GREEN, LED_OFF);        // Turn off Green LED for iMOTE2
#endif
                // we didn't see anything on serial port for wait interval (2 seconds nominally),
                // continue with code - just run the normal application
                StartApplication( (void (*)())g_State.Programs[0] );
            }

        }
    }
}
Exemplo n.º 11
0
int main(int argc, char **argv)
{
    SYS_SetResetCallback(WiiResetPressed);
    SYS_SetPowerCallback(WiiPowerPressed);
    usleep(250*1000);
    GRRLIB_Init();
    GRRLIB_ttfFont *font = GRRLIB_LoadTTF(verdana_ttf, verdana_ttf_size);
    
    
    WPAD_Init();
    USB_Initialize();
    USB_DeviceChangeNotifyAsync(USB_CLASS_HID, change_notify_cb, NULL);    
    int dev_id = get_device_id();
    int fd = open_device(dev_id);
    
    struct ds4_input data;
    memset(&data, 0, sizeof(data));
    fetch_data(fd, &data);
    random_leds(fd);
    
    int screenW = rmode->fbWidth, screenH = rmode->efbHeight;
    float pos_x = screenW/2, pos_y = screenH/2;
    while (run) {
        WPAD_ScanPads();
        u32 pressed = WPAD_ButtonsDown(0);
        if (pressed & WPAD_BUTTON_B) {
            dev_id = get_device_id();
            fd = open_device(dev_id);
        }
        if (pressed & WPAD_BUTTON_A) {
            random_leds(fd);
        }
        GRRLIB_FillScreen(0x0);
        GRRLIB_PrintfTTF(15, 15, font, "ds4wii by xerpi | L1: center | R1: random color", 15, 0xFFFFFFFF);
        
        u32 color = (r<<24)|(g<<16)|(b<<8)|0xFF;
        GRRLIB_Circle(pos_x, pos_y, 15, color, 0);
        GRRLIB_Circle(pos_x, pos_y, 14, color, 0);
        
        memset(&data, 0, sizeof(data));
        fetch_data(fd, &data);
        if (data.L1) {pos_x = screenW/2, pos_y = screenH/2;}
        if (data.R1) {random_leds(fd);}
        //1920x940
        if (data.finger1active) {
            GRRLIB_Circle((screenW/1920.0f)*data.finger1X, (screenH/940.0f)*data.finger1Y, 10, 0x00FF00FF, 1);
        }
        if (data.finger2active) {
            GRRLIB_Circle((screenW/1920.0f)*data.finger2X, (screenH/940.0f)*data.finger2Y, 10, 0x0000FFFF, 1);
        }
        
        
        /*char buf1[256];
        sprintf(buf1, "aX: %8hi  aY: %8hi  aZ: %8hi", data.accelX, data.accelY, data.accelZ);
        char buf2[256];
        sprintf(buf2, "gyroX: %8hi  gyroY: %8hi  gyroZ: %8hi", data.gyroX, data.gyroY, data.gyroZ);
        GRRLIB_PrintfTTF(15, 30, font, buf1, 14, 0xFFFFFFFF);
        GRRLIB_PrintfTTF(15, 45, font, buf2, 14, 0xFFFFFFFF);
        */
        
        #define THRESHOLD 50.0f
        if (fabs(data.accelX) > THRESHOLD)
            pos_y -= data.accelX/55.0f;
        if (fabs(data.accelY) > THRESHOLD)
            pos_x -= data.accelY/55.0f;
        
        if (pressed & WPAD_BUTTON_HOME) run = 0;
        GRRLIB_Render();
    }
    
    USB_CloseDevice(&fd);
    USB_Deinitialize();
    GRRLIB_FreeTTF (font);
    GRRLIB_Exit();
    exit(0);
    return 0;
}