Ejemplo n.º 1
0
int usbhost_claim_device(int virtdev_index)
{
	D(bug("USBHost: claim_device() %d", virtdev_index));

	int r;
	int dev_index, int_index;

	dev_index = virtual_device[virtdev_index].idx_dev;
	int_index = virtual_device[virtdev_index].idx_interface;

	r = libusb_kernel_driver_active(devh[dev_index], int_index);
	if (r < 0) {
		D(bug("USBHost: Checking if kernel driver is active failed. Error %d", r));
		return -1;
	}

	if (r == 1) {
		D(bug("USBHost: Kernel driver active for interface"));
		D(bug("USBHost: Trying to detach it"));
		r = libusb_detach_kernel_driver(devh[dev_index], int_index);
	} else goto claim;

	if (r < 0) {
		D(bug("USBHost: Driver detaching failed"));
		return -1;
	}

claim:	r = libusb_claim_interface(devh[dev_index], int_index);
	if (r < 0) {
		D(bug("USBHost: Claiming interface failed"));
		return -1;
 	}

	virtual_device[virtdev_index].connected = true;
	if (++number_ports_used == NUMBER_OF_PORTS)
		disable_buttons();

	for (int i = 0; i < NUMBER_OF_PORTS; i++) {
		if (roothub.port[i].busy == true)
			continue;
		roothub.port[i].busy = true;
		roothub.port[i].port_number = i;
		roothub.port[i].device_index = dev_index;
		virtual_device[virtdev_index].port_number = i;
		break;
	}

	fill_port_status(virtual_device[virtdev_index].port_number, virtual_device[virtdev_index].connected);

	return r;
}
Ejemplo n.º 2
0
void buttons_init(void) {
	btn_table[0] = &yes_btn;
	btn_table[1] = &no_btn;
	disable_buttons();
	_lwmsgq_init((pointer) btns_msg_queue, NUM_BTN_MESSAGES, MSG_SIZE_ALIGNED);
}