Ejemplo n.º 1
0
RES_CODE usb_remote_hid_t::scan_hid(uint32_t port_indx, USBSubClassCode subcls, USBProtocolCode proto)
{
	RES_CODE res;

	// select EPT_0 and device address
	ep0_hnd->mode.as_bytes[0] = EPT_0; // RX pipe
	ep0_hnd->mode.as_bytes[1] = EPT_0; // TX pipe
	res = hdc_init(port_indx);
	if(res == RES_OK)
	{
		epi_hnd->mode0 = ep0_hnd->mode0;  // device hub port
		// TRACE Device descriptor
		TRACELN("HID: dev found %x:%x", dev_descriptor.idVendor, dev_descriptor.idProduct);
		trace_usb_descriptor(&dev_descriptor.as_generic);
		if(dev_descriptor.bDeviceClass == INTERFACE_DEFINED_CLASS)
		{
			//loop the configurations
			for(uint32_t cfg_indx=0; cfg_indx<dev_descriptor.bNumConfigurations; cfg_indx++)
			{
				res = get_config_descriptor(cfg_indx);
				if(res != RES_OK)
					break;

				// TRACE Configuration descriptor(s)
				trace_usb_descriptor(&config_descriptor->as_generic);

				//loop the interfaces
				for(uint32_t iface_indx=0; iface_indx<config_descriptor->bNumInterfaces; iface_indx++)
				{
					pid = usb_get_interface(config_descriptor, iface_indx);
					if(pid && pid->bDeviceClass == HID_DEVICE_CLASS &&
							pid->bDeviceSubClass == subcls && pid->bDeviceProtocol == proto)
					{
						// set the configuration
//						set_configuration(0);
						res = set_configuration(config_descriptor->bConfigurationValue);

						if(res == RES_OK)
						{
							epi_hnd->mode.as_bytes[0] = EPT_0;
							epi_hnd->mode.as_bytes[1] = EPT_0;
							for(int i=0; i<pid->bNumEndpoints && i<2; i++)
							{
								USBEndpointDescriptor* ped;

								ped = usb_get_enpoint(config_descriptor, i);
								if(ped && ped->bmAttributes == ENDPOINT_TYPE_INTERRUPT)
								{
									if( ped->bEndpointAddress & 0x80 )
									{
										if(epi_hnd->mode.as_bytes[0] == EPT_0)
										{
											epi_hnd->mode.as_bytes[0] = ped->bEndpointAddress & 0x7F;
											epi_hnd->mode.as_ushort[1] = ep0_hnd->mode.as_ushort[1]; //drv_state_cnt
											usb_svc_configendpoint(epi_hnd, &ped->as_generic);
										}
									} else
									{
										if(epi_hnd->mode.as_bytes[1] == EPT_0)
										{
											epi_hnd->mode.as_bytes[1] = ped->bEndpointAddress ;
											epi_hnd->mode.as_ushort[1] = ep0_hnd->mode.as_ushort[1]; //drv_state_cnt
											usb_svc_configendpoint(epi_hnd, &ped->as_generic);
										}
									}
								}
							}
							hid_idle = 255;
							get_idle(HID_REPORT_ALL);
							return RES_OK;

						}
					}
				}
			}
		}
	}

	if(res == RES_OK)
		res = RES_ERROR;
	return res;
}
Ejemplo n.º 2
0
Archivo: main.c Proyecto: lokedhs/ostis
int main(int argc, char *argv[])
{
  int c;
  struct state *state = NULL;
#if TEST_BUILD
  struct test_case *test_case;
#endif
  prefs_init();

  while(1) {
    int option_index = 0;
    static struct option long_options[] = {
      {"cart",                  required_argument, 0, OPT_CART },
      {"force-extreme-disasm",  no_argument,       0, OPT_FORCE_EXTREME_DISASM },
      {"crop-screen",           no_argument,       0, OPT_CROP_SCREEN },
      {"loglevels" ,            required_argument, 0, OPT_LOGLEVELS },
      {"audio-device" ,         required_argument, 0, OPT_AUDIO_DEVICE },
#if TEST_BUILD
      {"test-case",             required_argument, 0, OPT_TEST_MODE},
#endif
      {0,                       0,                 0, 0 }
    };
    c = getopt_long(argc, argv, "a:b:c:t:s:hdpyVAMvq", long_options, &option_index);
    if(c == -1) break;

    switch(c) {
    case 'a':
      prefs_set("diskimage", optarg);
      break;
    case 'b':
      prefs_set("diskimage2", optarg);
      break;
    case 'c':
      prefs_set("hdimage", optarg);
      break;
    case 't':
      prefs_set("tosimage", optarg);
      break;
    case 's':
      prefs_set("stateimage", optarg);
      break;
    case OPT_CART:
      prefs_set("cartimage", optarg);
      break;
    case OPT_FORCE_EXTREME_DISASM:
      cprint_all = 1;
      break;
    case OPT_CROP_SCREEN:
      crop_screen = 1;
      break;
    case OPT_LOGLEVELS:
      diag_set_module_levels(optarg);
      break;
    case OPT_AUDIO_DEVICE:
      if(!strncmp("list", optarg, 4)) {
        audio_device = -1;
      } else {
        audio_device = atoi(optarg);
      }
      break;
#if TEST_BUILD
    case OPT_TEST_MODE:
      test_case_name = xstrdup(optarg);
      test_mode = 1;
      break;
#endif
    case 'd':
      debugger = 1;
      break;
    case 'p':
      ppmoutput = 1;
      break;
    case 'y':
      psgoutput = 1;
      break;
    case 'v':
      verbosity++;
      break;
    case 'q':
      verbosity = MAX(1, verbosity-1);
      break;
    case 'V':
      vsync_delay = 1;
      break;
    case 'A':
      play_audio = 1;
      break;
    case 'M':
      monitor_sm124 = 1;
      break;
    case 'h':
    default:
      printf("Usage: %s [-AdMpqvVy] [-a diskimage1] [-b diskimage2] [-c hdimage] [-t tosimage] [-s stateimage]\n",
	     argv[0]);
      exit(-1);
      break;
    }
  }

  /* Do not crop screen while debugging */
  if(debugger) {
    crop_screen = 0;
  }
  
  if((prefs.diskimage == NULL) && (argv[optind] != NULL))
    prefs_set("diskimage", argv[optind]);

  SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK|SDL_INIT_AUDIO);

#if TEST_BUILD
  if(test_mode) {
    test_case = test_init(test_case_name);
    if(test_case) {
      if(test_case->cartridge_name) {
        prefs_set("cartimage", test_case->cartridge_name);
      }
      if(test_case->floppy_name) {
        prefs_set("diskimage", test_case->floppy_name);
      }
    } else {
      printf("DEBUG: Could not load test case %s\n", test_case_name);
      exit(-3);
    }
  }
#endif
  
  /* Must run before hardware module inits */
  mmu_init();

  /* This must also be run before hardware modules.
     It gives a dummy area for some memory regions to not
     cause bus errors */
  mmu_fallback_init(); 

  /* Actual hardware */
  ram_init();
  rom_init();
  cpu_init();
  if(prefs.cartimage) {
    cartridge_init(prefs.cartimage);
  } else {
    cartridge_init(NULL);
  }
  psg_init();
  midi_init();
  acia_init();
  ikbd_init();
#if INCLUDE_RTC
  rtc_init();
#endif
  dma_init();
  fdc_init();
  hdc_init(prefs.hdimage);
  mfp_init();
  screen_disable(0);
  glue_init();
  shifter_init();
  if(debugger) {
    debug_init();
    cpu_halt_for_debug();
  }
  screen_init();
  
  floppy_init(prefs.diskimage, prefs.diskimage2);

  if(prefs.stateimage) {
    state = state_load(prefs.stateimage);
  }

  if(state != NULL)
    state_restore(state);

  memset(&reset, 0, sizeof reset);
  reset.sa_sigaction = reset_action;
  sigaction(SIGHUP, &reset, NULL);

  while(cpu_run(CPU_RUN));
  return 0;
}