4 * Part of libgphoto2/camlibs/digigr8
5 * Here are the functions which are needed to get data from the camera.
7 * Copyright (c) 2005 Theodore Kilgore <kilgota@auburn.edu>
8 * Camera library support under libgphoto2.1.1 for camera(s)
9 * with chipset from Service & Quality Technologies, Taiwan.
10 * Cameras supported by this driver have Product ID 0x905C, 0x9050, or.
13 * Licensed under GNU Lesser General Public License, as part of Gphoto
14 * camera support project. For a copy of the license, see the file
15 * COPYING in the main source tree of libgphoto2.
31 #include <gphoto2/gphoto2.h>
32 #include <gphoto2/gphoto2-port.h>
35 #define GP_MODULE "digigr8"
37 #define SQWRITE gp_port_usb_msg_write
38 #define SQREAD gp_port_usb_msg_read
41 digi_init (GPPort *port, CameraPrivateLibrary *priv)
45 unsigned char *catalog = calloc(0x4010,1);
46 unsigned char *catalog_tmp;
48 if (!catalog) return GP_ERROR_NO_MEMORY;
50 SQWRITE (port, 0x0c, 0x14f4, 0x0, NULL, 0);
51 SQREAD (port, 0x0c, 0xf5, 0x00, c, 0x14);
52 SQWRITE (port, 0x0c, 0x1440, 0x110f, NULL, 0);
54 SQWRITE (port, 0x0c, 0x14f0, 0x0, NULL, 0);
56 gp_port_read (port, c, 0x14);
58 SQWRITE (port, 0x0c, 0x20, 0x40, NULL, 0);
59 gp_port_read(port, (char *)catalog, 0x4000); /* We need 16 bytes for each photo. */
62 /* The first occurence of a zero denotes end of files entries */
63 for (i=0; i<0x4000 && catalog[i]; i+=16);
64 priv->nb_entries = i>>4;
65 catalog_tmp = realloc(catalog, i+16);
66 memset (catalog_tmp+i, 0, 16);
69 * 0x913c cameras allow individual photo deletion. This causes
70 * the relevant catalog line to start with 0x64. So the related
71 * lines of config data must be removed, and the deleted
72 * images need to be cast out from the count.
75 for (j=0; j<i; j+=16) {
76 if ((!catalog[j])||(catalog_tmp[j] == 0x64)) {
77 memcpy(catalog_tmp+j, catalog_tmp+j+16, i+16-j);
81 if (catalog_tmp) priv->catalog = catalog_tmp;
82 else priv->catalog = catalog;
84 priv->catalog = NULL; /* We just have freed catalog_tmp */
88 priv->last_fetched_entry = -1;
96 digi_get_comp_ratio (CameraPrivateLibrary *priv, int entry)
98 switch (priv->catalog[16*entry]) {
111 GP_DEBUG ("Your camera has unknown resolution settings.\n");
117 digi_get_data_size (CameraPrivateLibrary *priv, int entry)
119 return ((priv->catalog[16*entry + 6] <<16)
120 | (priv->catalog[16*entry + 5] <<8)
121 | (priv->catalog[16*entry + 4] ) );
125 digi_get_picture_width (CameraPrivateLibrary *priv, int entry)
127 switch (priv->catalog[16*entry]) {
130 case 0x61: return 352;
133 case 0x72: return 176;
136 case 0x63: return 320;
138 case 0x76: return 640;
140 GP_DEBUG ("Your pictures have unknown width.\n");
146 digi_rewind (GPPort *port, CameraPrivateLibrary *priv)
148 static char dummy_buf[0x4000];
151 GP_DEBUG("REWIND cam's data pointer");
153 /* One has to read the catalog to rewind the data stream...
154 * I don't know if it's by design. There ought to be something better to do... :-/
158 SQWRITE (port, 0x0c, 0x20, 0x40, NULL, 0); /* Access config */
159 gp_port_read(port, dummy_buf, 0x4000);
162 priv->last_fetched_entry = -1;
168 digi_reset (GPPort *port)
170 /* Release current register */
171 SQWRITE (port, 0x0c, 0xa0, 0x00, NULL, 0);
178 digi_read_picture_data (GPPort *port, unsigned char *data, int size, int n )
182 int remainder = size % 0x8000;
185 SQWRITE (port, 0x0c, 0x30, 0x00, NULL, 0);
187 while ((offset + 0x8000 < size)) {
188 gp_port_read (port, (char *)data + offset, 0x8000);
189 offset = offset + 0x8000;
191 gp_port_read (port, (char *)data + offset, remainder);
196 int digi_delete_all (GPPort *port, CameraPrivateLibrary *priv)
200 unsigned char *get_size;
201 unsigned char *junk=NULL;
203 get_size=malloc(0x50);
205 return GP_ERROR_NO_MEMORY;
206 num_pics = priv->nb_entries;
207 GP_DEBUG("number of entries is %i\n", num_pics);
211 GP_DEBUG("Camera is already empty!\n");
214 SQWRITE (port, 0x0c, 0x1440, 0x110f, NULL, 0);
215 if ((gp_port_read(port, (char *)get_size, 0x50)!=0x50)) {
216 GP_DEBUG("Error in reading data\n");
219 GP_DEBUG("get_size[0x40] = 0x%x\n", get_size[0x40]);
220 size = get_size[0x40]|(get_size[0x41]<<8)|(get_size[0x42]<<16)|
221 (get_size[0x43]<<24);
222 GP_DEBUG("size = 0x%x\n", size);
225 GP_DEBUG("No size to read. This will not work.\n");
231 GP_DEBUG("allocation of junk space failed\n");
232 return GP_ERROR_NO_MEMORY;
234 gp_port_read(port, (char *)junk, size);