usb_printer: support for alternate interfaces, not just the default one.
* Tested with a Profilic USB-Parallel adapter and a Laserjet printer.
This commit is contained in:
@@ -159,25 +159,27 @@ usb_printer_device_added(usb_device newDevice, void **cookie)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < configuration->interface_count; i++) {
|
for (size_t i = 0; i < configuration->interface_count; i++) {
|
||||||
usb_interface_info *interface = configuration->interface[i].active;
|
for (size_t j = 0; j < configuration->interface[i].alt_count; j++) {
|
||||||
if (interface == NULL)
|
usb_interface_info *interface = &configuration->interface[i].alt[j];
|
||||||
continue;
|
if (interface == NULL
|
||||||
|
|| interface->descr->interface_class != PRINTER_INTERFACE_CLASS
|
||||||
if (interface->descr->interface_class == PRINTER_INTERFACE_CLASS
|
|| interface->descr->interface_subclass !=
|
||||||
&& interface->descr->interface_subclass ==
|
PRINTER_INTERFACE_SUBCLASS
|
||||||
PRINTER_INTERFACE_SUBCLASS
|
|| !(interface->descr->interface_protocol == PIT_UNIDIRECTIONAL
|
||||||
&& (interface->descr->interface_protocol == PIT_UNIDIRECTIONAL
|
|| interface->descr->interface_protocol == PIT_BIDIRECTIONAL
|
||||||
|| interface->descr->interface_protocol == PIT_BIDIRECTIONAL
|
|| interface->descr->interface_protocol
|
||||||
|| interface->descr->interface_protocol
|
== PIT_1284_4_COMPATIBLE)) {
|
||||||
== PIT_1284_4_COMPATIBLE)) {
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
bool hasIn = false;
|
bool hasIn = false;
|
||||||
bool hasOut = false;
|
bool hasOut = false;
|
||||||
for (size_t j = 0; j < interface->endpoint_count; j++) {
|
for (size_t k = 0; k < interface->endpoint_count; k++) {
|
||||||
usb_endpoint_info *endpoint = &interface->endpoint[j];
|
usb_endpoint_info *endpoint = &interface->endpoint[k];
|
||||||
if (endpoint == NULL
|
if (endpoint == NULL
|
||||||
|| endpoint->descr->attributes != USB_ENDPOINT_ATTR_BULK)
|
|| endpoint->descr->attributes != USB_ENDPOINT_ATTR_BULK) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!hasIn && (endpoint->descr->endpoint_address
|
if (!hasIn && (endpoint->descr->endpoint_address
|
||||||
& USB_ENDPOINT_ADDR_DIR_IN)) {
|
& USB_ENDPOINT_ADDR_DIR_IN)) {
|
||||||
@@ -197,6 +199,7 @@ usb_printer_device_added(usb_device newDevice, void **cookie)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
device->interface = interface->descr->interface_number;
|
device->interface = interface->descr->interface_number;
|
||||||
|
device->alternate = j;
|
||||||
device->alternate_setting = interface->descr->alternate_setting;
|
device->alternate_setting = interface->descr->alternate_setting;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -209,6 +212,13 @@ usb_printer_device_added(usb_device newDevice, void **cookie)
|
|||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
status_t status = gUSBModule->set_alt_interface(newDevice,
|
||||||
|
&configuration->interface[device->interface].alt[device->alternate]);
|
||||||
|
if (status < B_OK) {
|
||||||
|
free(device);
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
mutex_init(&device->lock, "usb_printer device lock");
|
mutex_init(&device->lock, "usb_printer device lock");
|
||||||
|
|
||||||
device->notify = create_sem(0, "usb_printer callback notify");
|
device->notify = create_sem(0, "usb_printer callback notify");
|
||||||
|
|||||||
@@ -6,10 +6,10 @@
|
|||||||
* Michael Lotz <[email protected]>
|
* Michael Lotz <[email protected]>
|
||||||
* Michael Pfeiffer <[email protected]>
|
* Michael Pfeiffer <[email protected]>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _USB_PRINTER_H_
|
#ifndef _USB_PRINTER_H_
|
||||||
#define _USB_PRINTER_H_
|
#define _USB_PRINTER_H_
|
||||||
|
|
||||||
|
|
||||||
#include <lock.h>
|
#include <lock.h>
|
||||||
#include <USB3.h>
|
#include <USB3.h>
|
||||||
|
|
||||||
@@ -45,6 +45,7 @@ typedef struct printer_device_s {
|
|||||||
usb_pipe bulk_in;
|
usb_pipe bulk_in;
|
||||||
usb_pipe bulk_out;
|
usb_pipe bulk_out;
|
||||||
uint8 interface;
|
uint8 interface;
|
||||||
|
uint8 alternate;
|
||||||
uint8 alternate_setting;
|
uint8 alternate_setting;
|
||||||
|
|
||||||
// used to store callback information
|
// used to store callback information
|
||||||
|
|||||||
Reference in New Issue
Block a user