summaryrefslogtreecommitdiff
path: root/camlibs/digita/usb.c
blob: 4ea5649c85e26ff41dfa054e08e4d11621f9fd23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 * usb.c
 *
 *  USB digita support
 *
 * Copyright 1999-2000, Johannes Erdfelt <jerdfelt@valinux.com>
 */

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>

#include "digita.h"

#include <gpio.h>

static int digita_usb_read(struct digita_device *dev, void *buffer, int len)
{
#ifdef GPIO_USB
	return gpio_read(dev->gpdev, buffer, len);
#else
	return GPIO_ERROR;
#endif
}

static int digita_usb_send(struct digita_device *dev, void *buffer, int len)
{
#ifdef GPIO_USB
	return gpio_write(dev->gpdev, buffer, len);
#else
	return GPIO_ERROR;
#endif
}

struct camera_to_usb {
	char *name;
	unsigned short idVendor;
	unsigned short idProduct;
} camera_to_usb[] = {
	{ "Kodak DC220", 0x040A, 0x0100 },
	{ "Kodak DC260", 0x040A, 0x0110 },
	{ "Kodak DC265", 0x040A, 0x0111 },
	{ "Kodak DC290", 0x040A, 0x0112 },
};

#ifdef GPIO_USB
int digita_usb_probe(struct digita_device *dev, int i)
{
	if (i >= sizeof(camera_to_usb) / sizeof(struct camera_to_usb))
		goto err;

	if (gpio_usb_find_device(dev->gpdev, camera_to_usb[i].idVendor,
				camera_to_usb[i].idProduct) == GPIO_OK) {
		printf("found '%s' @ %s/%s\n", camera_to_usb[i].name,
			dev->gpdev->usb_device->bus->dirname, 
			dev->gpdev->usb_device->filename);
		return 0;
	}

err:
	fprintf(stderr, "unable to find any compatible USB cameras\n");

	return -1;
}
#endif

int digita_usb_open(struct digita_device *dev, Camera *camera)
{
#ifdef GPIO_USB
	gpio_device_settings settings;
	int i;

	fprintf(stderr, "digita: user selected %s\n", camera->model);

	dev->gpdev = gpio_new(GPIO_DEVICE_USB);
	if (!dev->gpdev)
		return -1;

	for (i = 0; i < sizeof(camera_to_usb) / sizeof(struct camera_to_usb); i++) {
		fprintf(stderr, "digita: %s, %s\n", camera->model, camera_to_usb[i].name);

		if (!strcmp(camera->model, camera_to_usb[i].name))
			break;
	}

	if (digita_usb_probe(dev, i) < 0)
		return -1;

	settings.usb.inep = 0x81;
	settings.usb.outep = 0x02;
	settings.usb.config = 1;
	settings.usb.interface = 0;
	settings.usb.altsetting = 0;

	digita_send = digita_usb_send;
	digita_read = digita_usb_read;

	gpio_set_settings(dev->gpdev, settings);
	if (gpio_open(dev->gpdev) < 0) {
		fprintf(stderr, "error opening device\n");
		return -1;
	}

	return 0;
#else
	return -1;
#endif
}