summaryrefslogtreecommitdiff
path: root/backend/genesys_gl846.c
diff options
context:
space:
mode:
Diffstat (limited to 'backend/genesys_gl846.c')
-rw-r--r--backend/genesys_gl846.c186
1 files changed, 96 insertions, 90 deletions
diff --git a/backend/genesys_gl846.c b/backend/genesys_gl846.c
index 5e1f0f4..3991693 100644
--- a/backend/genesys_gl846.c
+++ b/backend/genesys_gl846.c
@@ -1,45 +1,45 @@
/* sane - Scanner Access Now Easy.
Copyright (C) 2012-2013 Stéphane Voltz <stef.dev@free.fr>
-
-
+
+
This file is part of the SANE package.
-
+
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
-
+
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
-
+
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
-
+
As a special exception, the authors of SANE give permission for
additional uses of the libraries contained in this release of SANE.
-
+
The exception is that, if you link a SANE library with other files
to produce an executable, this does not by itself cause the
resulting executable to be covered by the GNU General Public
License. Your use of that executable is in no way restricted on
account of linking the SANE library code into it.
-
+
This exception does not, however, invalidate any other reasons why
the executable file might be covered by the GNU General Public
License.
-
+
If you submit changes to SANE to the maintainers to be included in
a subsequent release, you agree by submitting the changes that
those changes may be distributed with this exception intact.
-
+
If you write modifications of your own for SANE, it is your choice
whether to permit this exception to apply to your modifications.
- If you do not wish that, delete this exception notice.
+ If you do not wish that, delete this exception notice.
*/
/** @file
@@ -62,7 +62,7 @@
/** @brief read scanned data
* Read in 0xeff0 maximum sized blocks. This read is done in 2
- * parts if not multple of 512. First read is rounded to a multiple of 512 bytes, last read fetches the
+ * parts if not multple of 512. First read is rounded to a multiple of 512 bytes, last read fetches the
* remainder. Read addr is always 0x10000000 with the memory layout setup.
* @param dev device to read data from
* @param addr address within ASIC memory space, unused but kept for API
@@ -128,7 +128,7 @@ gl846_bulk_read_data (Genesys_Device * dev, uint8_t addr,
read /= 512;
read *= 512;
}
-
+
DBG (DBG_io2,
"gl846_bulk_read_data: trying to read %lu bytes of data\n",
(u_long) read);
@@ -180,7 +180,7 @@ gl846_bulk_read_data (Genesys_Device * dev, uint8_t addr,
}
/****************************************************************************
- Mid level functions
+ Mid level functions
****************************************************************************/
static SANE_Bool
@@ -304,7 +304,7 @@ static Sensor_Profile *get_sensor_profile(int sensor_type, int dpi)
}
else
{
- if(sensors[i].dpi>=dpi
+ if(sensors[i].dpi>=dpi
&& sensors[i].dpi<sensors[idx].dpi)
{
idx=i;
@@ -560,7 +560,7 @@ gl846_init_registers (Genesys_Device * dev)
DBGCOMPLETED;
}
-/**@brief send slope table for motor movement
+/**@brief send slope table for motor movement
* Send slope_table in machine byte order
* @param dev device to send slope table
* @param table_nr index of the slope table in ASIC memory
@@ -633,7 +633,7 @@ gl846_set_adi_fe (Genesys_Device * dev, uint8_t set)
/* wait for FE to be ready */
status = sanei_genesys_get_status (dev, &val8);
- while (val8 & REG41_FEBUSY);
+ while (val8 & REG41_FEBUSY)
{
usleep (10000);
status = sanei_genesys_get_status (dev, &val8);
@@ -776,7 +776,7 @@ gl846_init_motor_regs_scan (Genesys_Device * dev,
use_fast_fed=0;
/* no fast fed since feed works well */
- if(dev->settings.yres==4444 && feed_steps>100
+ if(dev->settings.yres==4444 && feed_steps>100
&& ((flags & MOTOR_FLAG_FEED)==0))
{
use_fast_fed=1;
@@ -845,7 +845,7 @@ gl846_init_motor_regs_scan (Genesys_Device * dev,
/* correct move distance by acceleration and deceleration amounts */
feedl=feed_steps;
- if (use_fast_fed)
+ if (use_fast_fed)
{
feedl<<=fast_step_type;
dist=(scan_steps+2*fast_steps)*factor;
@@ -887,7 +887,7 @@ gl846_init_motor_regs_scan (Genesys_Device * dev,
*/
/* if quarter step, bipolar Vref2 */
- /* XXX STEF XXX GPIO
+ /* XXX STEF XXX GPIO
if (scan_step_type > 1)
{
if (scan_step_type < 3)
@@ -1021,11 +1021,11 @@ gl846_init_optical_regs_scan (Genesys_Device * dev,
"half_ccd=%d, flags=%x\n", exposure_time,
used_res, start, pixels, channels, depth, half_ccd, flags);
- /* resolution is divided according to CKSEL */
+ /* 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);
-
+
/* 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);
@@ -1040,7 +1040,7 @@ gl846_init_optical_regs_scan (Genesys_Device * dev,
/* start and end coordinate in optical dpi coordinates */
startx = start/cksel+dev->sensor.CCD_start_xoffset;
used_pixels=pixels/cksel;
-
+
/* end of sensor window */
endx = startx + used_pixels;
@@ -1184,7 +1184,7 @@ gl846_init_optical_regs_scan (Genesys_Device * dev,
{
r->value |= REG87_LEDADD;
}
- /* RGB weighting
+ /* RGB weighting
r = sanei_genesys_get_address (reg, 0x01);
r->value &= ~REG01_TRUEGRAY;
if (channels == 1 && (flags & OPTICAL_FLAG_ENABLE_LEDADD))
@@ -1229,7 +1229,7 @@ gl846_init_optical_regs_scan (Genesys_Device * dev,
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);
-
+
words_per_line *= channels;
dev->wpl = words_per_line;
@@ -1248,7 +1248,7 @@ gl846_init_optical_regs_scan (Genesys_Device * dev,
r = sanei_genesys_get_address (reg, 0x34);
r->value = dev->sensor.dummy_pixel;
-
+
DBGCOMPLETED;
return SANE_STATUS_GOOD;
}
@@ -1383,7 +1383,7 @@ gl846_init_scan_regs (Genesys_Device * dev,
depth = 8;
}
- /* we enable true gray for cis scanners only, and just when doing
+ /* we enable true gray for cis scanners only, and just when doing
* scan since color calibration is OK for this mode
*/
oflags = 0;
@@ -1393,7 +1393,7 @@ gl846_init_scan_regs (Genesys_Device * dev,
oflags |= OPTICAL_FLAG_DISABLE_GAMMA;
if(flags & SCAN_FLAG_DISABLE_LAMP)
oflags |= OPTICAL_FLAG_DISABLE_LAMP;
-
+
if (dev->model->is_cis && dev->settings.true_gray)
{
oflags |= OPTICAL_FLAG_ENABLE_LEDADD;
@@ -1504,12 +1504,12 @@ gl846_init_scan_regs (Genesys_Device * dev,
/* theory :
target_size =
(dev->settings.pixels * dev->settings.lines * channels * depth) / 8;
- but it suffers from integer overflow so we do the following:
+ but it suffers from integer overflow so we do the following:
- 1 bit color images store color data byte-wise, eg byte 0 contains
- 8 bits of red data, byte 1 contains 8 bits of green, byte 2 contains
+ 1 bit color images store color data byte-wise, eg byte 0 contains
+ 8 bits of red data, byte 1 contains 8 bits of green, byte 2 contains
8 bits of blue.
- This does not fix the overflow, though.
+ This does not fix the overflow, though.
644mp*16 = 10gp, leading to an overflow
-- pierre
*/
@@ -1969,13 +1969,13 @@ gl846_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home)
}
memcpy (local_reg, dev->reg, GENESYS_GL846_MAX_REGS * sizeof (Genesys_Register_Set));
-
+
resolution=sanei_genesys_get_lowest_ydpi(dev);
-
+
/* TODO add scan_mode to the API */
scan_mode= dev->settings.scan_mode;
dev->settings.scan_mode=SCAN_MODE_LINEART;
- gl846_init_scan_regs (dev,
+ status = gl846_init_scan_regs (dev,
local_reg,
resolution,
resolution,
@@ -1989,11 +1989,19 @@ gl846_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home)
SCAN_FLAG_DISABLE_SHADING |
SCAN_FLAG_DISABLE_GAMMA |
SCAN_FLAG_IGNORE_LINE_DISTANCE);
+ if (status != SANE_STATUS_GOOD)
+ {
+ DBG (DBG_error,
+ "gl846_slow_back_home: failed to set up registers: %s\n",
+ sane_strstatus (status));
+ DBGCOMPLETED;
+ return status;
+ }
dev->settings.scan_mode=scan_mode;
/* clear scan and feed count */
RIE (sanei_genesys_write_register (dev, REG0D, REG0D_CLRLNCNT | REG0D_CLRMCNT));
-
+
/* set up for reverse */
r = sanei_genesys_get_address (local_reg, REG02);
r->value |= REG02_MTRREV;
@@ -2153,7 +2161,7 @@ gl846_search_start_position (Genesys_Device * dev)
memcpy (dev->reg, local_reg,
GENESYS_GL846_MAX_REGS * sizeof (Genesys_Register_Set));
-/*TODO: find out where sanei_genesys_search_reference_point
+/*TODO: find out where sanei_genesys_search_reference_point
stores information, and use that correctly*/
status =
sanei_genesys_search_reference_point (dev, data, 0, dpi, pixels,
@@ -2171,7 +2179,7 @@ gl846_search_start_position (Genesys_Device * dev)
return SANE_STATUS_GOOD;
}
-/*
+/*
* sets up register for coarse gain calibration
* todo: check it for scanners using it */
static SANE_Status
@@ -2255,7 +2263,7 @@ gl846_feed (Genesys_Device * dev, unsigned int steps)
memcpy (local_reg, dev->reg, GENESYS_GL846_MAX_REGS * sizeof (Genesys_Register_Set));
resolution=sanei_genesys_get_lowest_ydpi(dev);
- gl846_init_scan_regs (dev,
+ status = gl846_init_scan_regs (dev,
local_reg,
resolution,
resolution,
@@ -2270,6 +2278,14 @@ gl846_feed (Genesys_Device * dev, unsigned int steps)
SCAN_FLAG_DISABLE_GAMMA |
SCAN_FLAG_FEEDING |
SCAN_FLAG_IGNORE_LINE_DISTANCE);
+ if (status != SANE_STATUS_GOOD)
+ {
+ DBG (DBG_error,
+ "gl846_feed: failed to set up registers: %s\n",
+ sane_strstatus (status));
+ DBGCOMPLETED;
+ return status;
+ }
/* set exposure to zero */
sanei_genesys_set_triple(local_reg,REG_EXPR,0);
@@ -2279,11 +2295,11 @@ gl846_feed (Genesys_Device * dev, unsigned int steps)
/* clear scan and feed count */
RIE (sanei_genesys_write_register (dev, REG0D, REG0D_CLRLNCNT));
RIE (sanei_genesys_write_register (dev, REG0D, REG0D_CLRMCNT));
-
+
/* set up for no scan */
r = sanei_genesys_get_address (local_reg, REG01);
r->value &= ~REG01_SCAN;
-
+
/* send registers */
RIE (dev->model->cmd_set->bulk_write_register (dev, local_reg, GENESYS_GL846_MAX_REGS));
@@ -2308,7 +2324,7 @@ gl846_feed (Genesys_Device * dev, unsigned int steps)
/* then stop scanning */
RIE(gl846_stop_action (dev));
-
+
DBGCOMPLETED;
return SANE_STATUS_GOOD;
}
@@ -2335,7 +2351,7 @@ gl846_init_regs_for_shading (Genesys_Device * dev)
DBG (DBG_io, "%s: calib_lines = %d\n", __FUNCTION__, (unsigned int)dev->calib_lines);
DBG (DBG_io, "%s: calib_pixels = %d\n", __FUNCTION__, (unsigned int)dev->calib_pixels);
- /* this is aworkaround insufficent distance for slope
+ /* this is aworkaround insufficent distance for slope
* motor acceleration TODO special motor slope for shading */
move=1;
if(dev->calib_resolution<1200)
@@ -2364,7 +2380,7 @@ gl846_init_regs_for_shading (Genesys_Device * dev)
DBG (DBG_error, "%s: failed to setup scan: %s\n", __FUNCTION__, sane_strstatus (status));
return status;
}
-
+
status = dev->model->cmd_set->bulk_write_register (dev, dev->calib_reg, GENESYS_GL846_MAX_REGS);
if (status != SANE_STATUS_GOOD)
{
@@ -2421,9 +2437,9 @@ gl846_init_regs_for_scan (Genesys_Device * dev)
assumption: steps are expressed at maximum motor resolution
- we need:
- SANE_Fixed y_offset;
- SANE_Fixed y_size;
+ we need:
+ SANE_Fixed y_offset;
+ SANE_Fixed y_size;
SANE_Fixed y_offset_calib;
mm_to_steps()=motor dpi / 2.54 / 10=motor dpi / MM_PER_INCH */
@@ -2453,7 +2469,7 @@ gl846_init_regs_for_scan (Genesys_Device * dev)
}
move=500;
}
-
+
DBG (DBG_info, "gl846_init_regs_for_scan: move=%f steps\n", move);
DBG (DBG_info, "%s: move=%f steps\n", __FUNCTION__, move);
@@ -2465,7 +2481,7 @@ gl846_init_regs_for_scan (Genesys_Device * dev)
flags = 0;
/* emulated lineart from gray data is required for now */
- if(dev->settings.scan_mode == SCAN_MODE_LINEART
+ if(dev->settings.scan_mode == SCAN_MODE_LINEART
&& dev->settings.dynamic_lineart)
{
flags |= SCAN_FLAG_DYNAMIC_LINEART;
@@ -2489,7 +2505,7 @@ gl846_init_regs_for_scan (Genesys_Device * dev)
if (status != SANE_STATUS_GOOD)
return status;
-
+
DBGCOMPLETED;
return SANE_STATUS_GOOD;
}
@@ -2512,7 +2528,7 @@ gl846_send_shading_data (Genesys_Device * dev, uint8_t * data, int size)
DBGSTART;
DBG( DBG_io2, "%s: writing %d bytes of shading data\n",__FUNCTION__,size);
- /* shading data is plit in 3 (up to 5 with IR) areas
+ /* shading data is plit in 3 (up to 5 with IR) areas
write(0x10014000,0x00000dd8)
URB 23429 bulk_out len 3544 wrote 0x33 0x10 0x....
write(0x1003e000,0x00000dd8)
@@ -2542,14 +2558,14 @@ gl846_send_shading_data (Genesys_Device * dev, uint8_t * data, int size)
fprintf(dev->binary,"P5\n%d %d\n%d\n",(endpixel-strpixel)/factor*channels,lines/channels,255);
}
}
-
+
pixels=endpixel-strpixel;
/* since we're using SHDAREA, substract startx coordinate from shading */
strpixel-=((dev->sensor.CCD_start_xoffset*600)/dev->sensor.optical_res);
-
+
/* turn pixel value into bytes 2x16 bits words */
- strpixel*=2*2;
+ strpixel*=2*2;
pixels*=2*2;
/* allocate temporary buffer */
@@ -2578,18 +2594,19 @@ gl846_send_shading_data (Genesys_Device * dev, uint8_t * data, int size)
ptr[1]=src[1];
ptr[2]=src[2];
ptr[3]=src[3];
-
+
/* next shading coefficient */
ptr+=4;
}
- RIE (sanei_genesys_read_register (dev, 0xd0+i, &val));
+ RIEF (sanei_genesys_read_register (dev, 0xd0+i, &val), buffer);
addr = val * 8192 + 0x10000000;
status = sanei_genesys_write_ahb (dev->dn, dev->usb_mode, addr, pixels, buffer);
if (status != SANE_STATUS_GOOD)
{
DBG (DBG_error, "gl846_send_shading_data; write to AHB failed (%s)\n",
sane_strstatus (status));
+ free(buffer);
return status;
}
}
@@ -2640,7 +2657,7 @@ gl846_led_calibration (Genesys_Device * dev)
used_res=sanei_genesys_compute_dpihw(dev,dev->settings.xres);
sensor=get_sensor_profile(dev->model->ccd_type, used_res);
num_pixels = (dev->sensor.sensor_pixels*used_res)/dev->sensor.optical_res;
-
+
/* initial calibration reg values */
memcpy (dev->calib_reg, dev->reg, GENESYS_GL846_MAX_REGS * sizeof (Genesys_Register_Set));
@@ -2770,18 +2787,18 @@ gl846_led_calibration (Genesys_Device * dev)
/* cleanup before return */
free (line);
-
+
/* go back home */
if(move>20)
{
status=gl846_slow_back_home (dev, SANE_TRUE);
}
-
+
DBGCOMPLETED;
return status;
}
-/**
+/**
* set up GPIO/GPOE for idle state
*/
static SANE_Status
@@ -2805,7 +2822,7 @@ gl846_init_gpio (Genesys_Device * dev)
RIE (sanei_genesys_write_register (dev, REGA7, gpios[idx].ra7));
RIE (sanei_genesys_write_register (dev, REGA6, gpios[idx].ra6));
-
+
RIE (sanei_genesys_write_register (dev, REG6B, gpios[idx].r6b));
RIE (sanei_genesys_write_register (dev, REG6C, gpios[idx].r6c));
RIE (sanei_genesys_write_register (dev, REG6D, gpios[idx].r6d));
@@ -2819,7 +2836,7 @@ gl846_init_gpio (Genesys_Device * dev)
return status;
}
-/**
+/**
* set memory layout by filling values in dedicated registers
*/
static SANE_Status
@@ -2867,7 +2884,7 @@ gl846_init_memory_layout (Genesys_Device * dev)
*/
#ifndef UNIT_TESTING
static
-#endif
+#endif
SANE_Status
gl846_boot (Genesys_Device * dev, SANE_Bool cold)
{
@@ -2882,7 +2899,7 @@ gl846_boot (Genesys_Device * dev, SANE_Bool cold)
RIE (sanei_genesys_write_register (dev, 0x0e, 0x01));
RIE (sanei_genesys_write_register (dev, 0x0e, 0x00));
}
-
+
if(dev->usb_mode == 1)
{
val = 0x14;
@@ -2950,7 +2967,7 @@ SANE_Status gl846_init (Genesys_Device * dev)
DBG_INIT ();
DBGSTART;
-
+
status=sanei_genesys_asic_init(dev, GENESYS_GL846_MAX_REGS);
DBGCOMPLETED;
@@ -2990,7 +3007,7 @@ gl846_update_hardware_sensors (Genesys_Scanner * s)
/** @brief search for a full width black or white strip.
* This function searches for a black or white stripe across the scanning area.
- * When searching backward, the searched area must completely be of the desired
+ * When searching backward, the searched area must completely be of the desired
* color since this area will be used for calibration which scans forward.
* @param dev scanner device
* @param forward SANE_TRUE if searching forward, SANE_FALSE if searching backward
@@ -3013,7 +3030,15 @@ gl846_search_strip (Genesys_Device * dev, SANE_Bool forward, SANE_Bool black)
DBG (DBG_proc, "gl846_search_strip %s %s\n", black ? "black" : "white",
forward ? "forward" : "reverse");
- gl846_set_fe (dev, AFE_SET);
+ status = gl846_set_fe (dev, AFE_SET);
+ if (status != SANE_STATUS_GOOD)
+ {
+ DBG (DBG_error,
+ "gl846_search_strip: gl846_set_fe() failed: %s\n",
+ sane_strstatus(status));
+ return status;
+ }
+
status = gl846_stop_action (dev);
if (status != SANE_STATUS_GOOD)
{
@@ -3415,7 +3440,7 @@ gl846_offset_calibration (Genesys_Device * dev)
snprintf(title,20,"offset%03d.pnm",bottom);
sanei_genesys_write_pnm_file (title, first_line, bpp, channels, pixels, lines);
}
-
+
bottomavg = dark_average (first_line, pixels, lines, channels, black_pixels);
DBG (DBG_io2, "gl846_offset_calibration: bottom avg=%d\n", bottomavg);
@@ -3429,7 +3454,7 @@ gl846_offset_calibration (Genesys_Device * dev)
DBG (DBG_info, "gl846_offset_calibration: starting second line reading\n");
RIEF2 (gl846_begin_scan (dev, dev->calib_reg, SANE_TRUE), first_line, second_line);
RIEF2 (sanei_genesys_read_data_from_scanner (dev, second_line, total_size), first_line, second_line);
-
+
topavg = dark_average (second_line, pixels, lines, channels, black_pixels);
DBG (DBG_io2, "gl846_offset_calibration: top avg=%d\n", topavg);
@@ -3572,24 +3597,10 @@ gl846_coarse_gain_calibration (Genesys_Device * dev, int dpi)
max[j] = 0;
for (i = pixels/4; i < (pixels*3/4); i++)
{
- if(bpp==16)
- {
- if (dev->model->is_cis)
- val =
- line[i * 2 + j * 2 * pixels + 1] * 256 +
- line[i * 2 + j * 2 * pixels];
- else
- val =
- line[i * 2 * channels + 2 * j + 1] * 256 +
- line[i * 2 * channels + 2 * j];
- }
- else
- {
if (dev->model->is_cis)
val = line[i + j * pixels];
else
val = line[i * channels + j];
- }
max[j] += val;
}
@@ -3619,12 +3630,6 @@ gl846_coarse_gain_calibration (Genesys_Device * dev, int dpi)
dev->frontend.gain[2] = dev->frontend.gain[1] = dev->frontend.gain[0];
}
- if (channels == 1)
- {
- dev->frontend.gain[0] = dev->frontend.gain[1];
- dev->frontend.gain[2] = dev->frontend.gain[1];
- }
-
free (line);
RIE (gl846_stop_action (dev));
@@ -3691,7 +3696,8 @@ static Genesys_Command_Set gl846_cmd_set = {
NULL,
gl846_send_shading_data,
gl846_calculate_current_setup,
- gl846_boot
+ gl846_boot,
+ NULL
};
SANE_Status