Commit 711bb115 authored by Daniel Drake's avatar Daniel Drake

open/close device functions

parent 7d31cb4d
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment