int scan_usb() { int dev_cnt = 0; usb_init(); usb_find_busses(); usb_find_devices(); struct usb_bus *bus = NULL; struct usb_device *dev = NULL; for(bus = usb_get_busses(); bus; bus = bus->next) { for(dev = bus->devices; dev; dev=dev->next) { scan_device(dev, &dev_cnt); if(dev_cnt==MAX_DEVICES) return dev_cnt; } } return dev_cnt; }
int main(int argv, char** argc) { atexit(adb_cleanup); #if defined(HAVE_FORKEXEC) // No SIGCHLD. Let the service subproc handle its children. signal(SIGPIPE, SIG_IGN); #endif init_transport_registration(); // The minimal version of adbd only uses USB. if (access("/dev/android_adb", F_OK) == 0) { usb_init(); } fdevent_loop(); usb_cleanup(); return 0; }
interrupt void usb_inth(void) #endif { if(R_UIR1 & RXD0F) // ep0 OUT packet received dataout_endp0(); if(R_UIR1 & TXD0F) // ep0 IN packet received datain_endp0(); if(R_UIR1 & TXD1F) // ep1 IN packet received datain_endp1(); if(R_UIR1 & RXD2F) // ep2 OUT packet received dataout_endp2(); if(R_UIR1 & RSTF) { // RESET received, reinitalize usb R_UIR2 = RSTFR; usb_init(); R_UCR0 = RX0E; } }
void k8061_Init( void ) { int i = 0; // Initialise libusb usb_init(); // Close all filehandles for ( i=0; i<8; i++ ) { _k8061_IsOpen[i] = 0; _k8061_Handle[i] = NULL; } // Reset buffers for ( i=0; i<50; i++ ) { _k8061_ReadBuffer[i] = 0; _k8061_WriteBuffer[i] = 0; } return; }
struct usb_dev_handle* irecv_init(unsigned int devid) { struct usb_dev_handle *handle = NULL; struct usb_device *dev = NULL; struct usb_bus *bus = NULL; usb_init(); usb_find_busses(); usb_find_devices(); for (bus = usb_get_busses(); bus; bus = bus->next) { for (dev = bus->devices; dev; dev = dev->next) { if (dev->descriptor.idVendor == VENDOR_ID && dev->descriptor.idProduct == devid) { handle = usb_open(dev); return handle; } } } return NULL; }
usb_dev_handle* setup_libusb_access() { usb_dev_handle *lvr_winusb; usb_set_debug(255); usb_init(); usb_find_busses(); usb_find_devices(); if(!(lvr_winusb = find_lvr_winusb())) { printf("Couldn't find the USB device, Exiting\n"); return NULL; } if (usb_set_configuration(lvr_winusb, 1) < 0) { printf("Could not set configuration 1 : \n"); return NULL; } if (usb_claim_interface(lvr_winusb, INTERFACE) < 0) { printf("Could not claim interface: \n"); return NULL; } return lvr_winusb; }
int main(void) { Temper *t; char buf[256]; int i, ret; usb_set_debug(0); usb_init(); usb_find_busses(); usb_find_devices(); t = TemperCreateFromDeviceNumber(0, USB_TIMEOUT, 0); if(!t) { perror("TemperCreate"); exit(-1); } /* TemperSendCommand(t, 10, 11, 12, 13, 0, 0, 2, 0); TemperSendCommand(t, 0x43, 0, 0, 0, 0, 0, 0, 0); TemperSendCommand(t, 0, 0, 0, 0, 0, 0, 0, 0); TemperSendCommand(t, 0, 0, 0, 0, 0, 0, 0, 0); TemperSendCommand(t, 0, 0, 0, 0, 0, 0, 0, 0); TemperSendCommand(t, 0, 0, 0, 0, 0, 0, 0, 0); TemperSendCommand(t, 0, 0, 0, 0, 0, 0, 0, 0); TemperSendCommand(t, 0, 0, 0, 0, 0, 0, 0, 0); */ float tempc; if(TemperGetTemperatureInC(t, &tempc) < 0) { perror("TemperGetTemperatureInC"); exit(1); } printf("temperature %.2fF %.2fC\n", (9.0 / 5.0 * tempc + 32.0), tempc); return 0; }
int main(int argc, char **argv) { signal(SIGHUP, sighandler); signal(SIGINT, sighandler); signal(SIGTERM, sighandler); signal(SIGPIPE, SIG_IGN); // Setting default file permissions to o+rw umask(~(S_IRUSR | S_IWUSR)); // Turning off buffering setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stderr, NULL, _IONBF, 0); processcommandline(argc, argv); if (!config_init(configfilename)) return 1; daemon_poll_init(); if (!usb_init()) return 2; while (!nai_flags.sigexit) { if (!usb_process()) break; if (!daemon_poll_process()) break; if (!nai_process()) break; } usb_deinit(); daemon_poll_deinit(); config_deinit(); printf("main: exiting.\n"); return 0; }
usb_dev_handle* LibUSButils::GetFirstDevice(int vendorid, int productid) { struct usb_bus* bus; struct usb_device* dev; usb_dev_handle* device_handle = NULL; // it's a null usb_init(); usb_set_debug(0); /* 3 is the max setting */ usb_find_busses(); usb_find_devices(); // Loop through each bus and device until you find the first match // open it and return it's usb device handle for (bus = usb_busses; bus; bus = bus->next) { for (dev = bus->devices; dev; dev = dev->next) { if (dev->descriptor.idVendor == vendorid && dev->descriptor.idProduct == productid) { device_handle = usb_open(dev); // Need error checking for when the device isn't found! if (!device_handle) { Logger::Log(ERROR, "Couldn't open usb device: %s", strerror(errno)); // errno = Exxxxx; // usb_open should set the error code. return NULL; } Logger::ClearLastError(); return (device_handle); } } } Logger::SetLastError("No Such device"); errno = ENOENT; // No such device return (device_handle); }
int main(void) { // set for 1 MHz clock CPU_PRESCALE(4); // set all pins as inputs with pullup resistors #if defined(PORTA) DDRF = 0; PORTF = 0xFF; #endif DDRB = 0; PORTB = 0xFF; DDRC = 0; PORTC = 0xFF; DDRD = 0; PORTD = 0xFF; #if defined(PORTE) DDRE = 0; PORTE = 0xFF; #endif #if defined(PORTF) DDRF = 0; PORTF = 0xFF; #endif // initialize USB usb_init(); // do nothing (USB code handles reboot message) while (1) { _delay_ms(1); // put the CPU into low power idle mode set_sleep_mode(SLEEP_MODE_IDLE); cli(); sleep_enable(); sei(); sleep_cpu(); sleep_disable(); } }
struct vport* vport_open() { struct usb_bus *busses; struct usb_dev_handle* usb_handle; struct usb_bus *bus; struct usb_device *dev; struct vport * tmp; tmp = (struct vport*)malloc(sizeof(struct vport)); usb_init(); usb_find_busses(); usb_find_devices(); busses = usb_get_busses(); /* find vport device in usb bus */ for (bus = busses; bus; bus = bus->next) { for (dev = bus->devices; dev; dev = dev->next) { /* condition for sucessfully hit (too bad, I only check the vendor id)*/ if (dev->descriptor.idVendor == 0x0400) { tmp->usb_handle = usb_open(dev); usb_set_configuration (tmp->usb_handle,dev->config[0].bConfigurationValue); usb_claim_interface(tmp->usb_handle, 0); usb_set_altinterface(tmp->usb_handle,0); return tmp; } } } return 0; }
unsigned int USBDeviceFactory_DiscoverDevices( LPSKYETEK_DEVICE** lpDevices ) { struct usb_bus *bus; struct usb_device *dev; unsigned int deviceCount; LPSKYETEK_DEVICE lpDevice; if((lpDevices == NULL) || (*lpDevices != NULL)) return 0; deviceCount = 0; usb_init(); usb_find_busses(); usb_find_devices(); for(bus = usb_busses; bus; bus = bus->next) { for(dev = bus->devices; dev; dev = dev->next) { if((dev->descriptor.idVendor == VID) && (dev->descriptor.idProduct == PID)) { /*printf("USB filename: %s\r\n", dev->filename);*/ if(USBDeviceFactory_CreateDevice(dev->filename, &lpDevice) != SKYETEK_SUCCESS) continue; /*printf("USB CreateDevice succeded\r\n");*/ deviceCount++; *lpDevices = (LPSKYETEK_DEVICE*)realloc(*lpDevices, (deviceCount * sizeof(LPSKYETEK_DEVICE))); *lpDevices[(deviceCount - 1)] = lpDevice; } } } return deviceCount; }
gboolean output_init (void) { struct usb_bus *bus; struct usb_device *_dev, *dev = NULL; gint intno = 0; usb_init (); usb_find_busses (); usb_find_devices (); usb_set_debug (10); for (bus = usb_busses; bus; bus = bus->next) for (_dev = bus->devices; _dev; _dev = _dev->next) if (_dev->descriptor.idVendor == VENDOR_ID && _dev->descriptor.idProduct == PRODUCT_ID) dev = _dev; if (!dev) { g_warning ("device not found\n"); return FALSE; } g_print ("device found: %s/%s (0x%04x/0x%04x)\n", dev->bus->dirname, dev->filename, dev->descriptor.idVendor, dev->descriptor.idProduct); handle = usb_open (dev); if (usb_claim_interface (handle, intno) >= 0) g_print ("successfully claimed interface %d\n", intno); else { g_warning ("failed to claim interface %d\n", intno); return FALSE; } return TRUE; }
int main(void){ // set for 16 MHz clock CPU_PRESCALE(0); usb_init(); //D0->4 Output Bits for Transistors to individual displays DDRD = 0b01011111; PORTD = 0b00000000; //C0->7 Initially setting bits to input. Will set to output to turn on. DDRC = 0b00000000; PORTC = 0b00000000; //DDRC = 0b11111111; DDRF = 0b00000000; PORTF = 0b11101010; TCCR1B = 0b00000011; TIFR1 = 0b00000001; TIMSK1 = 0b00000001; //sei(); //Turn on one of the columns for interupt purposes. PORTF &= ~(1<<2); //Setting Low DDRF |= (1<<2); //Set to Output uint8_t peeps = 0; uint16_t hourly = 0; peeps = getPeople(); hourly = getHourly(); while (1) { //.26 ticks per second, we'll say .25 for simplicity. displayMultiF((float)peeps*(float)hourly*ticks/60.0f/60.0f/4.0f); } }
void MotorController::reset() { unsigned int my_vendor = 62680; // F4D8 unsigned int my_product = 3844; // 0F04 struct usb_bus * bus; struct usb_device * dev; usb_init(); /* Initialize libusb */ usb_find_busses(); /* Find all USB busses on system */ usb_find_devices(); /* Find all devices on all USB devices */ usb_set_debug(0); bool found = false; /* usb_busses is a global variable. */ for (bus = usb_busses; bus; bus = bus->next) { for (dev = bus->devices; dev; dev = dev->next) { if(dev->descriptor.idVendor == my_vendor && dev->descriptor.idProduct == my_product) { found = true; break; } } if(found) break; } if(!found) cout << "usb motor controller is not found" << endl; assert(found); // Opens a USB device usbDeviceHandle = usb_open(dev); usb_reset(usbDeviceHandle); close(); }
void USB_init(cyg_addrword_t data) { cyg_sem_t sem; cyg_semaphore_init(&sem, 0); ppause(200); //20 Ticks, 200m seconds //init memory pci_usb_pool_init(); //usb usb_init(); //ohci ohci_hcd_init(0x5C, SYSPA_USB11_OPERATION_BASE_ADDR); //ehci ehci_hcd_init(0x6B, SYSPA_USB20_OPERATION_BASE_ADDR); //Printer Class usblp_init(); cyg_semaphore_wait(&sem); cyg_semaphore_destroy(&sem); }
usb_dev_handle *dpf_usb_open(void) { struct usb_device *d; usb_dev_handle *usb_dev; usb_init(); usb_find_busses(); usb_find_devices(); d = find_dev(); if (!d) { handle_error("No matching USB device found!"); return NULL; } usb_dev = usb_open(d); if (usb_dev == NULL) { handle_error("Failed to open usb device!"); return NULL; } return usb_dev; }
struct usb_device *cc1800_find (void) { int r; struct usb_bus *busses, *bus; struct usb_device *dev; usb_init(); r = usb_find_busses(); if (r < 0) return NULL; r = usb_find_devices(); if (r < 0) return NULL; busses = usb_get_busses(); for (bus = busses; bus != NULL; bus = bus->next) { for (dev = bus->devices; dev != NULL; dev = dev->next) { if (dev->descriptor.idVendor == CC1800_VENDOR_ID && dev->descriptor.idProduct == CC1800_PRODUCT_ID) { return dev; } } } return NULL; }
static int usb_close_output(hw_ext_module_t * hw_module,audio_devices_t device){ struct usb_internal_data_s * usb_info = (struct usb_internal_data_s *)hw_module->data; audio_policy_anm *apm=hw_module->apm; struct str_parms *param; if(usb_info==NULL) return -1; switch(usb_info->state) { case IO_OPENED: case IO_DISCONNECTED: //continue treatment break; case IO_CONNECTED: ALOG_WARN("usb_close_output : USB output is not in disconnected state ; Impossible to close it"); return -1; break; case IO_CLOSED: ALOG_WARN("usb_close_output : already closed"); return 0; break; default: ALOG_WARN("usb_close_output : unknown state"); } if (usb_info->output_handle <=0 ) { ALOG_WARN("USB output is invalid ; Impossible to connect it"); return -1; } ALOG_INFO("USB request closing "); param = str_parms_create_str("closing"); str_parms_add_str(param, "closing", "true"); apm->mp_client_interface->set_parameters(apm->mService, usb_info->output_handle, str_parms_to_str(param), 0); str_parms_destroy(param); apm->mp_client_interface->close_output(apm->mService, usb_info->output_handle); ALOG_INFO("Usb closed "); return(usb_init(hw_module)); }
int main(int argc, char **argv) { usb_dev_handle *handle = NULL; unsigned char buffer[8]; int nBytes; usb_init(); if(usbOpenDevice(&handle, USBDEV_SHARED_VENDOR, 0, USBDEV_SHARED_PRODUCT, 0) != 0){ fprintf(stderr, "Could not find USB device \"PowerSwitch\" with vid=0x%x pid=0x%x\n", USBDEV_SHARED_VENDOR, USBDEV_SHARED_PRODUCT); exit(1); } /* We have searched all devices on all busses for our USB device above. Now * try to open it and perform the vendor specific control operations for the * function requested by the user. */ DWORD time = GetTickCount(); int count = 1000; for(int i=0;i<count;i++) { nBytes = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, 0, 0, 0, (char *)buffer, sizeof(buffer), 5000); if(nBytes < 2){ if(nBytes < 0) fprintf(stderr, "USB error: %s\n", usb_strerror()); fprintf(stderr, "only %d bytes received in iteration %d\n", nBytes, i); continue; } std::cout << (char *)buffer << std::endl; } time = GetTickCount()-time; std::cout << (float)count*8 / time * 1000.f << std::endl; std::ofstream file("123.txt"); file << time; printf("test succeeded\n"); usb_close(handle); system("pause"); return 0; }
void *lothar_usb_new(uint16_t vendor, uint16_t product) { struct usb_bus *bus; usb_dev_handle *result = NULL; static int init = 0; static int interface = 0; if(!init) { usb_init(); usb_find_busses(); usb_find_devices(); init = 1; } for(bus = usb_get_busses(); bus; bus = bus->next) { struct usb_device *dev = NULL; for(dev = bus->devices; dev; dev = dev->next) { if(dev->descriptor.idVendor == vendor && dev->descriptor.idProduct == product) { result = usb_open(dev); break; } } if(result) // break out of nested loop break; } if(!result || usb_claim_interface(result, interface++)) // nothing found, or error claiming { LOTHAR_ERROR(LOTHAR_ERROR_USB_CANNOT_CREATE); return NULL; } return result; }
void Hw::SystemInit(int flags){ if(init_flags==0){ xenon_make_it_faster(XENON_SPEED_FULL); if(flags & INIT_SOUND){ } if(flags & INIT_VIDEO){ } if(flags & INIT_USB){ usb_init(); } if(flags & INIT_NETWORK){ network_init(); } sfcx_init(); init_flags = flags; } }
int machine_init(void) { int i = 0; rcc_clock_setup_hse_3v3(&rcc_hse_25mhz_3v3); gpio_create(NULL, &gpio_led0); gpio_create(NULL, &gpio_button); /* UARTS */ for (i = 0; i < NUM_UARTS; i++) { uart_create(&uart_configs[i]); } /* I2Cs */ for (i = 0; i < NUM_I2CS; i++) { i2c_create(&i2c_configs[i]); } rng_create(1, RCC_RNG); sdio_conf.rcc_reg = (uint32_t *)&RCC_APB2ENR; sdio_conf.rcc_en = RCC_APB2ENR_SDMMC1EN; sdio_init(&sdio_conf); usb_init(&usb_guest); ethernet_init(ð_config); return 0; }
int main() { char fileName[21]; struct usb_bus *bus; struct usb_device *dev; usb_init(); usb_find_busses(); usb_find_devices(); for (bus = usb_busses; bus; bus = bus->next) for (dev = bus->devices; dev; dev = dev->next){ char buffer1[5]; char buffer2[5]; sprintf(buffer1, "%04x", dev->descriptor.idVendor); sprintf(buffer2, "%04x", dev->descriptor.idProduct); if(strcmp(buffer1, "045e") == 0 && strcmp(buffer2, "0772") == 0) { sprintf(fileName, "/dev/bus/usb/%s/%s", bus->dirname, dev->filename); } } int fd; int rc; fd = open(fileName, O_WRONLY); if (fd < 0) { perror("Error opening output file"); return 1; } printf("Resetting USB device %s\n", fileName); rc = ioctl(fd, USBDEVFS_RESET, 0); if (rc < 0) { perror("Error in ioctl"); return 1; } printf("Reset successful\n"); close(fd); return 1; }
//---------------------------------------------------------------------- struct usb_dev_handle * ldn_find_verifier(void){ struct usb_device *dev; struct usb_dev_handle *hdl; int i; //[USB initialization] //printf("\ninitializing USB communication..."); usb_init(); usb_find_busses(); usb_find_devices(); //printf("[SUCCESS]."); dev = find_device(VENDOR_ID, PRODUCT_ID); if (dev == NULL) return NULL; //lockdown verifier not found! //printf("\nlockdown verifier found."); hdl = usb_open(dev); i = usb_set_configuration(hdl, 1); if (i < 0){ usb_close(hdl); return NULL; //usb_set_configuration failed; } //printf("\nlockdown verifier configuration selected."); i = usb_claim_interface(hdl, 0); if (i < 0) { usb_close(hdl); return NULL; //usb_claim_interface failed } //printf("\nclaimed lockdown USB interface."); return hdl; }
void libusb_search (libusb_t *libusb, int idVendor, int idProduct) { struct usb_bus *bus; struct usb_device *dev; usb_init(); usb_find_busses(); usb_find_devices(); libusb->busses = usb_get_busses (); libusb->dev_number = 0; for (bus = libusb->busses; bus; bus = bus->next) { for (dev = bus->devices; dev; dev = dev->next) { if ((dev->descriptor.idVendor == idVendor) && (dev->descriptor.idProduct == idProduct)) { libusb->devices[libusb->dev_number] = dev; libusb->dev_number++; } } } }
int WINAPI encoder_init () { OutputDebugString("[FPGA] usb_init start."); if(USBDevice) { encoder_deinit(); } OutputDebugString("[FPGA] usb_init new USBDevice start."); USBDevice = new CCyUSBDevice(hDevice); OutputDebugString("[FPGA] usb_init new USBDevice end."); fpga_param.nBitrate = 4*1000;// 4000kbps if(usb_init(USBDevice)) { printf("sucess\n"); OutputDebugString("[FPGA] usb_init sucess."); } else { printf("failed\n"); OutputDebugString("[FPGA] usb_init failed."); return S_ERROR; } bool fw_index; OutputDebugString("[FPGA] first usb_downloadfw."); fw_index = usb_downloadfw(USBDevice,"fpga_usb_fw.hex"); OutputDebugString("[FPGA] second usb_downloadfw."); fw_index = usb_downloadfw(USBDevice,"fpga_usb_fw.hex"); if (fw_index) { printf("sucess\n"); OutputDebugString("[FPGA] usb_downloadfw sucess."); } else { printf("failed\n"); OutputDebugString("[FPGA] usb_downloadfw failed."); return S_ERROR; } return S_SUCCESS; }
static void init(void) { led_init(); #ifdef CONFIG_CARL9170FW_DEBUG_UART uart_init(); #endif /* CONFIG_CARL9170FW_DEBUG_UART */ /* 25/50/100ms timer (depends on cpu clock) */ timer_init(0, 50000); /* USB init */ usb_init(); /* initialize DMA memory */ memset(&dma_mem, 0, sizeof(dma_mem)); /* fill DMA rings */ dma_init_descriptors(); /* clear all interrupt */ set(AR9170_MAC_REG_INT_CTRL, 0xffff); orl(AR9170_MAC_REG_AFTER_PNP, 1); /* Init watch dog control flag */ fw.watchdog_enable = 1; set(AR9170_TIMER_REG_WATCH_DOG, AR9170_WATCH_DOG_TIMER); #ifdef CONFIG_CARL9170FW_GPIO_INTERRUPT fw.cached_gpio_state.gpio = get(AR9170_GPIO_REG_PORT_DATA) & CARL9170_GPIO_MASK; #endif /* CONFIG_CARL9170FW_GPIO_INTERRUPT */ /* this will get the downqueue moving. */ down_trigger(); }
void Hw::SystemInit(int flags){ if(init_flags==0){ xenon_make_it_faster(XENON_SPEED_FULL); if(flags & INIT_SOUND){ } if(flags & INIT_VIDEO){ } if(flags & INIT_USB){ usb_init(); usb_do_poll(); } if(flags & INIT_NETWORK){ network_init(); } if(flags & INIT_ATA){ xenon_ata_init(); } if(flags & INIT_ATAPI){ xenon_atapi_init(); } if(flags & INIT_FILESYSTEM){ mount_all_devices(); findDevices(); } if(flags & INIT_SFCX){ sfcx_init(); } init_flags = flags; } }
int adb_main() { //strcpy(ADB_SIDELOAD_FILENAME, path); atexit(adb_cleanup); #if defined(HAVE_FORKEXEC) // No SIGCHLD. Let the service subproc handle its children. signal(SIGPIPE, SIG_IGN); #endif init_transport_registration(); // The minimal version of adbd only uses USB. if (access("/dev/android_adb", F_OK) == 0) { // listen on USB LOGE("listen on USB\n"); usb_init(); } if (setgid(AID_SHELL) != 0) { LOGE("failed to setgid to shell\n"); exit(1); } if (setuid(AID_SHELL) != 0) { LOGE("failed to setuid to shell\n"); exit(1); } LOGE("userid is %d\n", getuid()); LOGE("Event loop starting\n"); fdevent_loop(); usb_cleanup(); return 0; }