open/close device functions
This commit is contained in:
parent
7d31cb4d45
commit
711bb1151b
3 changed files with 49 additions and 0 deletions
|
@ -118,6 +118,40 @@ API_EXPORTED void fp_dscv_devs_free(struct fp_dscv_dev **devs)
|
|||
g_free(devs);
|
||||
}
|
||||
|
||||
API_EXPORTED struct fp_dev *fp_dev_open(struct fp_dscv_dev *ddev)
|
||||
{
|
||||
struct fp_dev *dev;
|
||||
const struct fp_driver *drv = ddev->drv;
|
||||
int r;
|
||||
|
||||
usb_dev_handle *udevh = usb_open(ddev->udev);
|
||||
if (!udevh)
|
||||
return NULL;
|
||||
|
||||
dev = g_malloc0(sizeof(*dev));
|
||||
dev->drv = drv;
|
||||
dev->udev = udevh;
|
||||
|
||||
if (drv->init) {
|
||||
r = drv->init(dev);
|
||||
if (r) {
|
||||
usb_close(udevh);
|
||||
g_free(dev);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
API_EXPORTED void fp_dev_close(struct fp_dev *dev)
|
||||
{
|
||||
if (dev->drv->exit)
|
||||
dev->drv->exit(dev);
|
||||
usb_close(dev->udev);
|
||||
g_free(dev);
|
||||
}
|
||||
|
||||
API_EXPORTED int fp_init(void)
|
||||
{
|
||||
usb_init();
|
||||
|
|
|
@ -28,6 +28,12 @@
|
|||
|
||||
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a))
|
||||
|
||||
struct fp_dev {
|
||||
const struct fp_driver *drv;
|
||||
usb_dev_handle *udev;
|
||||
void *priv;
|
||||
};
|
||||
|
||||
struct usb_id {
|
||||
uint16_t vendor;
|
||||
uint16_t product;
|
||||
|
@ -38,6 +44,10 @@ struct fp_driver {
|
|||
const char *name;
|
||||
const char *full_name;
|
||||
const struct usb_id * const id_table;
|
||||
|
||||
/* Device operations */
|
||||
int (*init)(struct fp_dev *dev);
|
||||
void (*exit)(struct fp_dev *dev);
|
||||
};
|
||||
|
||||
extern const struct fp_driver upekts_driver;
|
||||
|
|
|
@ -22,11 +22,16 @@
|
|||
|
||||
/* structs that applications are not allowed to peek into */
|
||||
struct fp_dscv_dev;
|
||||
struct fp_dev;
|
||||
|
||||
/* Device discovery */
|
||||
struct fp_dscv_dev **fp_discover_devs(void);
|
||||
void fp_dscv_devs_free(struct fp_dscv_dev **devs);
|
||||
|
||||
/* Device handling */
|
||||
struct fp_dev *fp_dev_open(struct fp_dscv_dev *ddev);
|
||||
void fp_dev_close(struct fp_dev *dev);
|
||||
|
||||
int fp_init(void);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue