summaryrefslogtreecommitdiff
path: root/backend/genesys_gl847.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2017-07-15 11:25:39 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2017-07-15 11:25:39 +0200
commit1edb02101a9306fc711cd422ed507d18165b1691 (patch)
treebd2d48a139bfbe869f4f49359b63097931a45e7b /backend/genesys_gl847.c
parent2ca8a81bd0d99fe4d75c229d0e988d8ef710285f (diff)
move from support/1.0.27 to feature/1.0.27
Diffstat (limited to 'backend/genesys_gl847.c')
-rw-r--r--backend/genesys_gl847.c151
1 files changed, 96 insertions, 55 deletions
diff --git a/backend/genesys_gl847.c b/backend/genesys_gl847.c
index 7c4d19c..a3b35a2 100644
--- a/backend/genesys_gl847.c
+++ b/backend/genesys_gl847.c
@@ -1,6 +1,6 @@
/* sane - Scanner Access Now Easy.
- Copyright (C) 2010-2013 Stéphane Voltz <stef.dev@free.fr>
+ Copyright (C) 2010-2013 Stéphane Voltz <stef.dev@free.fr>
This file is part of the SANE package.
@@ -113,7 +113,7 @@ gl847_bulk_read_data (Genesys_Device * dev, uint8_t addr,
if (status != SANE_STATUS_GOOD)
{
DBG (DBG_error, "%s failed while writing command: %s\n",
- __FUNCTION__, sane_strstatus (status));
+ __func__, sane_strstatus (status));
return status;
}
@@ -158,7 +158,7 @@ gl847_bulk_read_data (Genesys_Device * dev, uint8_t addr,
DBG (DBG_io2, "gl847_bulk_read_data: %lu bytes of data read\n", (u_long) done);
}
- DBG (DBG_io2, "%s: read %lu bytes, %lu remaining\n", __FUNCTION__,
+ DBG (DBG_io2, "%s: read %lu bytes, %lu remaining\n", __func__,
(u_long) size, (u_long) (target - size));
target -= size;
@@ -265,7 +265,7 @@ gl847_get_step_multiplier (Genesys_Register_Set * regs)
value = (r->value & 0x0f)>>1;
value = 1 << value;
}
- DBG (DBG_io, "%s: step multiplier is %d\n", __FUNCTION__, value);
+ DBG (DBG_io, "%s: step multiplier is %d\n", __func__, value);
return value;
}
@@ -313,7 +313,7 @@ static Sensor_Profile *get_sensor_profile(int sensor_type, int dpi)
/* default fallback */
if(idx<0)
{
- DBG (DBG_warn,"%s: using default sensor profile\n",__FUNCTION__);
+ DBG (DBG_warn,"%s: using default sensor profile\n",__func__);
idx=0;
}
@@ -600,13 +600,13 @@ gl847_send_slope_table (Genesys_Device * dev, int table_nr,
int i;
char msg[10000];
- DBG (DBG_proc, "%s (table_nr = %d, steps = %d)\n", __FUNCTION__,
+ DBG (DBG_proc, "%s (table_nr = %d, steps = %d)\n", __func__,
table_nr, steps);
/* sanity check */
if(table_nr<0 || table_nr>4)
{
- DBG (DBG_error, "%s: invalid table number %d!\n", __FUNCTION__, table_nr);
+ DBG (DBG_error, "%s: invalid table number %d!\n", __func__, table_nr);
return SANE_STATUS_INVAL;
}
@@ -624,7 +624,7 @@ gl847_send_slope_table (Genesys_Device * dev, int table_nr,
{
sprintf (msg+strlen(msg), "%d", slope_table[i]);
}
- DBG (DBG_io, "%s: %s\n", __FUNCTION__, msg);
+ DBG (DBG_io, "%s: %s\n", __func__, msg);
}
/* slope table addresses are fixed */
@@ -634,7 +634,7 @@ gl847_send_slope_table (Genesys_Device * dev, int table_nr,
{
DBG (DBG_error,
"%s: write to AHB failed writing slope table %d (%s)\n",
- __FUNCTION__, table_nr, sane_strstatus (status));
+ __func__, table_nr, sane_strstatus (status));
}
free (table);
@@ -824,10 +824,10 @@ gl847_init_motor_regs_scan (Genesys_Device * dev,
{
use_fast_fed=1;
}
- DBG (DBG_io, "%s: use_fast_fed=%d\n", __FUNCTION__, use_fast_fed);
+ DBG (DBG_io, "%s: use_fast_fed=%d\n", __func__, use_fast_fed);
sanei_genesys_set_triple(reg, REG_LINCNT, scan_lines);
- DBG (DBG_io, "%s: lincnt=%d\n", __FUNCTION__, scan_lines);
+ DBG (DBG_io, "%s: lincnt=%d\n", __func__, scan_lines);
/* compute register 02 value */
r = sanei_genesys_get_address (reg, REG02);
@@ -906,8 +906,8 @@ gl847_init_motor_regs_scan (Genesys_Device * dev,
if (flags & MOTOR_FLAG_FEED)
dist *=2;
}
- DBG (DBG_io2, "%s: scan steps=%d\n", __FUNCTION__, scan_steps);
- DBG (DBG_io2, "%s: acceleration distance=%d\n", __FUNCTION__, dist);
+ DBG (DBG_io2, "%s: scan steps=%d\n", __func__, scan_steps);
+ DBG (DBG_io2, "%s: acceleration distance=%d\n", __func__, dist);
/* check for overflow */
if(dist<feedl)
@@ -916,7 +916,7 @@ gl847_init_motor_regs_scan (Genesys_Device * dev,
feedl = 0;
sanei_genesys_set_triple(reg,REG_FEEDL,feedl);
- DBG (DBG_io ,"%s: feedl=%d\n",__FUNCTION__,feedl);
+ DBG (DBG_io ,"%s: feedl=%d\n",__func__,feedl);
r = sanei_genesys_get_address (reg, REG0C);
ccdlmt=(r->value & REG0C_CCDLMT)+1;
@@ -1048,13 +1048,13 @@ gl847_init_optical_regs_scan (Genesys_Device * dev,
/* resolution is divided according to CKSEL */
r = sanei_genesys_get_address (reg, REG18);
cksel= (r->value & REG18_CKSEL)+1;
- DBG (DBG_io2, "%s: cksel=%d\n", __FUNCTION__, cksel);
+ DBG (DBG_io2, "%s: cksel=%d\n", __func__, cksel);
/* to manage high resolution device while keeping good
* low resolution scanning speed, we make hardware dpi vary */
dpihw=sanei_genesys_compute_dpihw(dev, used_res * cksel);
factor=dev->sensor.optical_res/dpihw;
- DBG (DBG_io2, "%s: dpihw=%d (factor=%d)\n", __FUNCTION__, dpihw, factor);
+ DBG (DBG_io2, "%s: dpihw=%d (factor=%d)\n", __func__, dpihw, factor);
/* sensor parameters */
sensor=get_sensor_profile(dev->model->ccd_type, dpihw);
@@ -1239,20 +1239,20 @@ gl847_init_optical_regs_scan (Genesys_Device * dev,
dev->line_interp = 0;
sanei_genesys_set_double(reg,REG_DPISET,dpiset);
- DBG (DBG_io2, "%s: dpiset used=%d\n", __FUNCTION__, dpiset);
+ DBG (DBG_io2, "%s: dpiset used=%d\n", __func__, dpiset);
sanei_genesys_set_double(reg,REG_STRPIXEL,startx);
sanei_genesys_set_double(reg,REG_ENDPIXEL,endx);
- DBG (DBG_io2, "%s: startx=%d\n", __FUNCTION__, startx);
- DBG (DBG_io2, "%s: endx =%d\n", __FUNCTION__, endx);
+ DBG (DBG_io2, "%s: startx=%d\n", __func__, startx);
+ DBG (DBG_io2, "%s: endx =%d\n", __func__, endx);
- DBG (DBG_io2, "%s: used_pixels=%d\n", __FUNCTION__, used_pixels);
- DBG (DBG_io2, "%s: pixels =%d\n", __FUNCTION__, pixels);
- DBG (DBG_io2, "%s: depth =%d\n", __FUNCTION__, depth);
- DBG (DBG_io2, "%s: dev->bpl =%lu\n", __FUNCTION__, (unsigned long)dev->bpl);
- DBG (DBG_io2, "%s: dev->len =%lu\n", __FUNCTION__, (unsigned long)dev->len);
- DBG (DBG_io2, "%s: dev->dist =%lu\n", __FUNCTION__, (unsigned long)dev->dist);
- DBG (DBG_io2, "%s: dev->segnb =%lu\n", __FUNCTION__, (unsigned long)dev->segnb);
+ DBG (DBG_io2, "%s: used_pixels=%d\n", __func__, used_pixels);
+ DBG (DBG_io2, "%s: pixels =%d\n", __func__, pixels);
+ DBG (DBG_io2, "%s: depth =%d\n", __func__, depth);
+ DBG (DBG_io2, "%s: dev->bpl =%lu\n", __func__, (unsigned long)dev->bpl);
+ DBG (DBG_io2, "%s: dev->len =%lu\n", __func__, (unsigned long)dev->len);
+ DBG (DBG_io2, "%s: dev->dist =%lu\n", __func__, (unsigned long)dev->dist);
+ DBG (DBG_io2, "%s: dev->segnb =%lu\n", __func__, (unsigned long)dev->segnb);
words_per_line *= channels;
dev->wpl = words_per_line;
@@ -1265,10 +1265,10 @@ gl847_init_optical_regs_scan (Genesys_Device * dev,
/* MAXWD is expressed in 4 words unit */
sanei_genesys_set_triple(reg, REG_MAXWD, (words_per_line >> 2));
- DBG (DBG_io2, "%s: words_per_line used=%d\n", __FUNCTION__, words_per_line);
+ DBG (DBG_io2, "%s: words_per_line used=%d\n", __func__, words_per_line);
sanei_genesys_set_double(reg, REG_LPERIOD, exposure_time);
- DBG (DBG_io2, "%s: exposure_time used=%d\n", __FUNCTION__, exposure_time);
+ DBG (DBG_io2, "%s: exposure_time used=%d\n", __func__, exposure_time);
r = sanei_genesys_get_address (reg, 0x34);
r->value = dev->sensor.dummy_pixel;
@@ -1669,7 +1669,7 @@ gl847_calculate_current_setup (Genesys_Device * dev)
slope_dpi = slope_dpi * (1 + dummy);
exposure_time = gl847_compute_exposure (dev, used_res);
- DBG (DBG_info, "%s : exposure_time=%d pixels\n", __FUNCTION__, exposure_time);
+ DBG (DBG_info, "%s : exposure_time=%d pixels\n", __func__, exposure_time);
/* max_shift */
max_shift=sanei_genesys_compute_max_shift(dev,channels,yres,0);
@@ -1785,7 +1785,7 @@ gl847_stop_action (Genesys_Device * dev)
if (status != SANE_STATUS_GOOD)
{
DBG (DBG_error,
- "%s: failed to read home sensor: %s\n", __FUNCTION__,
+ "%s: failed to read home sensor: %s\n", __func__,
sane_strstatus (status));
DBGCOMPLETED;
return status;
@@ -1794,7 +1794,7 @@ gl847_stop_action (Genesys_Device * dev)
/* only stop action if needed */
if (!(val40 & REG40_DATAENB) && !(val40 & REG40_MOTMFLG))
{
- DBG (DBG_info, "%s: already stopped\n", __FUNCTION__);
+ DBG (DBG_info, "%s: already stopped\n", __func__);
DBGCOMPLETED;
return SANE_STATUS_GOOD;
}
@@ -1807,7 +1807,7 @@ gl847_stop_action (Genesys_Device * dev)
if (status != SANE_STATUS_GOOD)
{
DBG (DBG_error,
- "%s: failed to write register 01: %s\n", __FUNCTION__,
+ "%s: failed to write register 01: %s\n", __func__,
sane_strstatus (status));
return status;
}
@@ -1825,7 +1825,7 @@ gl847_stop_action (Genesys_Device * dev)
if (status != SANE_STATUS_GOOD)
{
DBG (DBG_error,
- "%s: failed to read home sensor: %s\n", __FUNCTION__,
+ "%s: failed to read home sensor: %s\n", __func__,
sane_strstatus (status));
DBGCOMPLETED;
return status;
@@ -1929,10 +1929,50 @@ gl847_end_scan (Genesys_Device * dev, Genesys_Register_Set * reg,
return status;
}
-/* Moves the slider to the home (top) postion slowly */
-#ifndef UNIT_TESTING
-static
-#endif
+/** rewind scan
+ * Move back by the same amount of distance than previous scan.
+ * @param dev device to rewind
+ * @returns SANE_STATUS_GOOD on success
+ */
+GENESYS_STATIC
+SANE_Status gl847_rewind(Genesys_Device * dev)
+{
+ SANE_Status status;
+ uint8_t byte;
+
+ DBGSTART;
+
+ /* set motor reverse */
+ RIE (sanei_genesys_read_register (dev, 0x02, &byte));
+ byte |= 0x04;
+ RIE (sanei_genesys_write_register(dev, 0x02, byte));
+
+ /* and start scan, then wait completion */
+ RIE (gl847_begin_scan (dev, dev->reg, SANE_TRUE));
+ do
+ {
+ usleep(100*1000);
+ RIE (sanei_genesys_read_register (dev, REG40, &byte));
+ }
+ while(byte & REG40_MOTMFLG);
+ RIE (gl847_end_scan (dev, dev->reg, SANE_TRUE));
+
+ /* restore direction */
+ RIE (sanei_genesys_read_register (dev, 0x02, &byte));
+ byte &= 0xfb;
+ RIE (sanei_genesys_write_register(dev, 0x02, byte));
+
+ DBGCOMPLETED;
+ return SANE_STATUS_GOOD;
+}
+
+/** Park head
+ * Moves the slider to the home (top) position slowly
+ * @param dev device to park
+ * @param wait_until_home true to make the function waiting for head
+ * to be home before returning, if fals returne immediately
+ * @returns SANE_STATUS_GOO on success */
+GENESYS_STATIC
SANE_Status
gl847_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home)
{
@@ -1982,7 +2022,7 @@ gl847_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home)
/* is sensor at home? */
if (val & HOMESNR)
{
- DBG (DBG_info, "%s: already at home, completed\n", __FUNCTION__);
+ DBG (DBG_info, "%s: already at home, completed\n", __func__);
dev->scanhead_position_in_steps = 0;
DBGCOMPLETED;
return SANE_STATUS_GOOD;
@@ -2279,7 +2319,7 @@ gl847_feed (Genesys_Device * dev, unsigned int steps)
uint8_t val;
DBGSTART;
- DBG (DBG_io, "%s: steps=%d\n", __FUNCTION__, steps);
+ DBG (DBG_io, "%s: steps=%d\n", __func__, steps);
/* prepare local registers */
memcpy (local_reg, dev->reg, GENESYS_GL847_MAX_REGS * sizeof (Genesys_Register_Set));
@@ -2328,7 +2368,7 @@ gl847_feed (Genesys_Device * dev, unsigned int steps)
status = gl847_start_action (dev);
if (status != SANE_STATUS_GOOD)
{
- DBG (DBG_error, "%s: failed to start motor: %s\n", __FUNCTION__, sane_strstatus (status));
+ DBG (DBG_error, "%s: failed to start motor: %s\n", __func__, sane_strstatus (status));
gl847_stop_action (dev);
/* restore original registers */
@@ -2370,8 +2410,8 @@ gl847_init_regs_for_shading (Genesys_Device * dev)
if(dev->calib_resolution==4800)
dev->calib_lines *= 2;
dev->calib_pixels = (dev->sensor.sensor_pixels*dev->calib_resolution)/dev->sensor.optical_res;
- DBG (DBG_io, "%s: calib_lines = %d\n", __FUNCTION__, (int)dev->calib_lines);
- DBG (DBG_io, "%s: calib_pixels = %d\n", __FUNCTION__, (int)dev->calib_pixels);
+ DBG (DBG_io, "%s: calib_lines = %d\n", __func__, (int)dev->calib_lines);
+ DBG (DBG_io, "%s: calib_pixels = %d\n", __func__, (int)dev->calib_pixels);
/* this is aworkaround insufficent distance for slope
* motor acceleration TODO special motor slope for shading */
@@ -2399,14 +2439,14 @@ gl847_init_regs_for_shading (Genesys_Device * dev)
if (status != SANE_STATUS_GOOD)
{
- DBG (DBG_error, "%s: failed to setup scan: %s\n", __FUNCTION__, sane_strstatus (status));
+ DBG (DBG_error, "%s: failed to setup scan: %s\n", __func__, sane_strstatus (status));
return status;
}
status = dev->model->cmd_set->bulk_write_register (dev, dev->calib_reg, GENESYS_GL847_MAX_REGS);
if (status != SANE_STATUS_GOOD)
{
- DBG (DBG_error, "%s: failed to bulk write registers: %s\n", __FUNCTION__, sane_strstatus (status));
+ DBG (DBG_error, "%s: failed to bulk write registers: %s\n", __func__, sane_strstatus (status));
return status;
}
@@ -2474,7 +2514,7 @@ gl847_init_regs_for_scan (Genesys_Device * dev)
move += dev->settings.tl_y;
move = (move * move_dpi) / MM_PER_INCH;
move -= dev->scanhead_position_in_steps;
- DBG (DBG_info, "%s: move=%f steps\n",__FUNCTION__, move);
+ DBG (DBG_info, "%s: move=%f steps\n",__func__, move);
/* fast move to scan area */
/* we don't move fast the whole distance since it would involve
@@ -2486,14 +2526,14 @@ gl847_init_regs_for_scan (Genesys_Device * dev)
status = gl847_feed (dev, move-500);
if (status != SANE_STATUS_GOOD)
{
- DBG (DBG_error, "%s: failed to move to scan area\n",__FUNCTION__);
+ DBG (DBG_error, "%s: failed to move to scan area\n",__func__);
return status;
}
move=500;
}
DBG (DBG_info, "gl124_init_regs_for_scan: move=%f steps\n", move);
- DBG (DBG_info, "%s: move=%f steps\n", __FUNCTION__, move);
+ DBG (DBG_info, "%s: move=%f steps\n", __func__, move);
/* start */
start = SANE_UNFIX (dev->model->x_offset);
@@ -2548,7 +2588,7 @@ gl847_send_shading_data (Genesys_Device * dev, uint8_t * data, int size)
uint8_t val,*buffer,*ptr,*src;
DBGSTART;
- DBG( DBG_io2, "%s: writing %d bytes of shading data\n",__FUNCTION__,size);
+ DBG( DBG_io2, "%s: writing %d bytes of shading data\n",__func__,size);
/* shading data is plit in 3 (up to 5 with IR) areas
write(0x10014000,0x00000dd8)
@@ -2565,10 +2605,10 @@ gl847_send_shading_data (Genesys_Device * dev, uint8_t * data, int size)
/* compute deletion factor */
sanei_genesys_get_double(dev->reg,REG_DPISET,&tempo);
dpiset=tempo;
- DBG( DBG_io2, "%s: STRPIXEL=%d, ENDPIXEL=%d, PIXELS=%d, DPISET=%d\n",__FUNCTION__,strpixel,endpixel,endpixel-strpixel,dpiset);
+ DBG( DBG_io2, "%s: STRPIXEL=%d, ENDPIXEL=%d, PIXELS=%d, DPISET=%d\n",__func__,strpixel,endpixel,endpixel-strpixel,dpiset);
dpihw=sanei_genesys_compute_dpihw(dev,dpiset);
factor=dpihw/dpiset;
- DBG( DBG_io2, "%s: factor=%d\n",__FUNCTION__,factor);
+ DBG( DBG_io2, "%s: factor=%d\n",__func__,factor);
if(DBG_LEVEL>=DBG_data)
{
@@ -2593,7 +2633,7 @@ gl847_send_shading_data (Genesys_Device * dev, uint8_t * data, int size)
/* allocate temporary buffer */
buffer=(uint8_t *)malloc(pixels);
memset(buffer,0,pixels);
- DBG( DBG_io2, "%s: using chunks of %d (0x%04x) bytes\n",__FUNCTION__,pixels,pixels);
+ DBG( DBG_io2, "%s: using chunks of %d (0x%04x) bytes\n",__func__,pixels,pixels);
/* base addr of data has been written in reg D0-D4 in 4K word, so AHB address
* is 8192*reg value */
@@ -2670,7 +2710,7 @@ gl847_led_calibration (Genesys_Device * dev)
{
RIE(gl847_feed (dev, move));
}
- DBG (DBG_io, "%s: move=%f steps\n", __FUNCTION__, move);
+ DBG (DBG_io, "%s: move=%f steps\n", __func__, move);
/* offset calibration is always done in color mode */
channels = 3;
@@ -2700,7 +2740,7 @@ gl847_led_calibration (Genesys_Device * dev)
SCAN_FLAG_IGNORE_LINE_DISTANCE);
if (status != SANE_STATUS_GOOD)
{
- DBG (DBG_error, "%s: failed to setup scan: %s\n", __FUNCTION__, sane_strstatus (status));
+ DBG (DBG_error, "%s: failed to setup scan: %s\n", __func__, sane_strstatus (status));
return status;
}
@@ -2837,7 +2877,7 @@ gl847_init_gpio (Genesys_Device * dev)
}
if(gpios[idx].sensor_id==0)
{
- DBG (DBG_error, "%s: failed to find GPIO profile for sensor_id=%d\n", __FUNCTION__, dev->model->ccd_type);
+ DBG (DBG_error, "%s: failed to find GPIO profile for sensor_id=%d\n", __func__, dev->model->ccd_type);
return SANE_STATUS_INVAL;
}
@@ -2972,7 +3012,7 @@ gl847_boot (Genesys_Device * dev, SANE_Bool cold)
if (val & REG40_CHKVER)
{
RIE (sanei_genesys_read_register (dev, 0x00, &val));
- DBG (DBG_info, "%s: reported version for genesys chip is 0x%02x\n", __FUNCTION__, val);
+ DBG (DBG_info, "%s: reported version for genesys chip is 0x%02x\n", __func__, val);
}
/* Set default values for registers */
@@ -3753,6 +3793,7 @@ static Genesys_Command_Set gl847_cmd_set = {
gl847_led_calibration,
gl847_slow_back_home,
+ gl847_rewind,
sanei_genesys_bulk_write_register,
NULL,