genesys: Return errors as exceptions from *send_slope_table()

merge-requests/101/head
Povilas Kanapickas 2019-07-14 23:41:04 +03:00
rodzic 7d9f4d2c58
commit 9c9a118e12
7 zmienionych plików z 81 dodań i 172 usunięć

Wyświetl plik

@ -491,20 +491,17 @@ gl124_init_registers (Genesys_Device * dev)
* @param slope_table pointer to 16 bit values array of the slope table
* @param steps number of elemnts in the slope table
*/
static SANE_Status
gl124_send_slope_table (Genesys_Device * dev, int table_nr,
uint16_t * slope_table, int steps)
static void gl124_send_slope_table(Genesys_Device* dev, int table_nr, uint16_t* slope_table,
int steps)
{
DBG_HELPER_ARGS(dbg, "table_nr = %d, steps = %d", table_nr, steps);
SANE_Status status = SANE_STATUS_GOOD;
int i;
char msg[10000];
/* sanity check */
if(table_nr<0 || table_nr>4)
{
DBG (DBG_error, "%s: invalid table number %d!\n", __func__, table_nr);
return SANE_STATUS_INVAL;
throw SaneException("invalid table number");
}
std::vector<uint8_t> table(steps * 2);
@ -526,8 +523,6 @@ gl124_send_slope_table (Genesys_Device * dev, int table_nr,
// slope table addresses are fixed
sanei_genesys_write_ahb(dev, 0x10000000 + 0x4000 * table_nr, steps * 2, table.data());
return status;
}
/** @brief * Set register values of 'special' ti type frontend
@ -636,7 +631,6 @@ gl124_init_motor_regs_scan (Genesys_Device * dev,
unsigned int flags)
{
DBG_HELPER(dbg);
SANE_Status status = SANE_STATUS_GOOD;
int use_fast_fed;
unsigned int lincnt, fast_dpi;
uint16_t scan_table[SLOPE_TABLE_SIZE];
@ -737,8 +731,8 @@ gl124_init_motor_regs_scan (Genesys_Device * dev,
factor,
dev->model->motor_type,
motors);
RIE(gl124_send_slope_table (dev, SCAN_TABLE, scan_table, scan_steps));
RIE(gl124_send_slope_table (dev, BACKTRACK_TABLE, scan_table, scan_steps));
gl124_send_slope_table(dev, SCAN_TABLE, scan_table, scan_steps);
gl124_send_slope_table(dev, BACKTRACK_TABLE, scan_table, scan_steps);
/* STEPNO */
sanei_genesys_set_double(reg,REG_STEPNO,scan_steps);
@ -761,8 +755,8 @@ gl124_init_motor_regs_scan (Genesys_Device * dev,
factor,
dev->model->motor_type,
motors);
RIE(gl124_send_slope_table (dev, STOP_TABLE, fast_table, fast_steps));
RIE(gl124_send_slope_table (dev, FAST_TABLE, fast_table, fast_steps));
gl124_send_slope_table(dev, STOP_TABLE, fast_table, fast_steps);
gl124_send_slope_table(dev, FAST_TABLE, fast_table, fast_steps);
/* FASTNO */
sanei_genesys_set_double(reg,REG_FASTNO,fast_steps);

Wyświetl plik

@ -484,6 +484,5 @@ static SANE_Status gl124_feed (Genesys_Device * dev, unsigned int steps, int rev
static SANE_Status
gl124_stop_action (Genesys_Device * dev);
static SANE_Status
gl124_send_slope_table (Genesys_Device * dev, int table_nr,
uint16_t * slope_table, int steps);
static void gl124_send_slope_table(Genesys_Device* dev, int table_nr, uint16_t* slope_table,
int steps);

Wyświetl plik

@ -1291,18 +1291,14 @@ gl646_init_regs (Genesys_Device * dev)
}
/* Send slope table for motor movement
slope_table in machine byte order
*/
static SANE_Status
gl646_send_slope_table (Genesys_Device * dev, int table_nr,
uint16_t * slope_table, int steps)
// Send slope table for motor movement slope_table in machine byte order
static void gl646_send_slope_table(Genesys_Device* dev, int table_nr, uint16_t* slope_table,
int steps)
{
DBG_HELPER_ARGS(dbg, "table_nr = %d, steps = %d)=%d .. %d", table_nr, steps, slope_table[0],
slope_table[steps - 1]);
int dpihw;
int start_address;
SANE_Status status = SANE_STATUS_GOOD;
dpihw = dev->reg.find_reg(0x05).value >> 6;
@ -1312,8 +1308,9 @@ gl646_send_slope_table (Genesys_Device * dev, int table_nr,
start_address = 0x10000;
else if (dpihw == 2) /* 2400 dpi */
start_address = 0x1f800;
else /* reserved */
return SANE_STATUS_INVAL;
else {
throw SaneException("Unexpected dpihw");
}
std::vector<uint8_t> table(steps * 2);
for (int i = 0; i < steps; i++)
@ -1325,8 +1322,6 @@ gl646_send_slope_table (Genesys_Device * dev, int table_nr,
sanei_genesys_set_buffer_address(dev, start_address + table_nr * 0x100);
sanei_genesys_bulk_write_data(dev, 0x3c, table.data(), steps * 2);
return status;
}
// Set values of Analog Device type frontend
@ -1705,17 +1700,12 @@ gl646_load_document (Genesys_Device * dev)
51,
2400,
6000, 2400, 50, 0.25, &used, &vfinal);
/* document loading:
* send regs
* start motor
* wait e1 status to become e0
*/
status = gl646_send_slope_table (dev, 1, slope_table, 50);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s: failed to send slope table 1: %s\n", __func__, sane_strstatus(status));
return status;
}
// document loading:
// send regs
// start motor
// wait e1 status to become e0
gl646_send_slope_table(dev, 1, slope_table, 50);
sanei_genesys_bulk_write_register(dev, regs);
status = gl646_start_motor (dev);
@ -1904,17 +1894,12 @@ gl646_eject_document (Genesys_Device * dev)
61,
1600,
10000, 1600, 60, 0.25, &used, &vfinal);
/* document eject:
* send regs
* start motor
* wait c1 status to become c8 : HOMESNR and ~MOTFLAG
*/
status = gl646_send_slope_table (dev, 1, slope_table, 60);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s: failed to send slope table 1: %s\n", __func__, sane_strstatus(status));
return status;
}
// document eject:
// send regs
// start motor
// wait c1 status to become c8 : HOMESNR and ~MOTFLAG
gl646_send_slope_table(dev, 1, slope_table, 60);
sanei_genesys_bulk_write_register(dev, regs);
status = gl646_start_motor (dev);
@ -2574,24 +2559,10 @@ setup_for_scan (Genesys_Device * dev,
return status;
}
/* send computed slope tables */
status =
gl646_send_slope_table (dev, 0, slope_table0,
sanei_genesys_read_reg_from_set (regs, 0x21));
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s: failed to send slope table 0: %s\n", __func__, sane_strstatus(status));
return status;
}
// send computed slope tables
gl646_send_slope_table(dev, 0, slope_table0, sanei_genesys_read_reg_from_set (regs, 0x21));
status =
gl646_send_slope_table (dev, 1, slope_table1,
sanei_genesys_read_reg_from_set (regs, 0x6b));
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s: failed to send slope table 1: %s\n", __func__, sane_strstatus(status));
return status;
}
gl646_send_slope_table(dev, 1, slope_table1, sanei_genesys_read_reg_from_set (regs, 0x6b));
return status;
}

Wyświetl plik

@ -695,17 +695,13 @@ gl841_init_registers (Genesys_Device * dev)
DBG(DBG_proc, "%s complete\n", __func__);
}
/* Send slope table for motor movement
slope_table in machine byte order
*/
static SANE_Status
gl841_send_slope_table (Genesys_Device * dev, int table_nr,
uint16_t * slope_table, int steps)
// Send slope table for motor movement slope_table in machine byte order
static void gl841_send_slope_table(Genesys_Device* dev, int table_nr, uint16_t* slope_table,
int steps)
{
DBG_HELPER_ARGS(dbg, "table_nr = %d, steps = %d", table_nr, steps);
int dpihw;
int start_address;
SANE_Status status = SANE_STATUS_GOOD;
char msg[4000];
/*#ifdef WORDS_BIGENDIAN*/
int i;
@ -719,8 +715,9 @@ gl841_send_slope_table (Genesys_Device * dev, int table_nr,
start_address = 0x10000;
else if (dpihw == 2) /* 2400 dpi */
start_address = 0x20000;
else /* reserved */
return SANE_STATUS_INVAL;
else {
throw SaneException("Unexpected dpihw");
}
std::vector<uint8_t> table(steps * 2);
for(i = 0; i < steps; i++) {
@ -741,8 +738,6 @@ gl841_send_slope_table (Genesys_Device * dev, int table_nr,
sanei_genesys_set_buffer_address(dev, start_address + table_nr * 0x200);
sanei_genesys_bulk_write_data(dev, 0x3c, table.data(), steps * 2);
return status;
}
static void gl841_set_lide80_fe(Genesys_Device* dev, uint8_t set)
@ -1011,7 +1006,6 @@ gl841_init_motor_regs(Genesys_Device * dev,
unsigned int flags)
{
DBG_HELPER_ARGS(dbg, "feed_steps=%d, action=%d, flags=%x", feed_steps, action, flags);
SANE_Status status = SANE_STATUS_GOOD;
unsigned int fast_exposure;
int scan_power_mode;
int use_fast_fed = 0;
@ -1023,11 +1017,11 @@ gl841_init_motor_regs(Genesys_Device * dev,
memset(fast_slope_table,0xff,512);
gl841_send_slope_table (dev, 0, fast_slope_table, 256);
gl841_send_slope_table (dev, 1, fast_slope_table, 256);
gl841_send_slope_table (dev, 2, fast_slope_table, 256);
gl841_send_slope_table (dev, 3, fast_slope_table, 256);
gl841_send_slope_table (dev, 4, fast_slope_table, 256);
gl841_send_slope_table(dev, 0, fast_slope_table, 256);
gl841_send_slope_table(dev, 1, fast_slope_table, 256);
gl841_send_slope_table(dev, 2, fast_slope_table, 256);
gl841_send_slope_table(dev, 3, fast_slope_table, 256);
gl841_send_slope_table(dev, 4, fast_slope_table, 256);
gl841_write_freq(dev, dev->motor.base_ydpi / 4);
@ -1132,10 +1126,7 @@ HOME_FREE: 3
r->value &= ~0x40;
status = gl841_send_slope_table (dev, 3, fast_slope_table, 256);
if (status != SANE_STATUS_GOOD)
return status;
gl841_send_slope_table(dev, 3, fast_slope_table, 256);
r = sanei_genesys_get_address(reg, 0x67);
r->value = 0x3f;
@ -1179,7 +1170,6 @@ gl841_init_motor_regs_scan(Genesys_Device * dev, const Genesys_Sensor& sensor,
" scan_dummy=%d, feed_steps=%d, scan_power_mode=%d, flags=%x",
scan_exposure_time, scan_yres, scan_step_type, scan_lines, scan_dummy,
feed_steps, scan_power_mode, flags);
SANE_Status status = SANE_STATUS_GOOD;
unsigned int fast_exposure;
int use_fast_fed = 0;
int dummy_power_mode;
@ -1209,11 +1199,11 @@ gl841_init_motor_regs_scan(Genesys_Device * dev, const Genesys_Sensor& sensor,
memset(slow_slope_table,0xff,512);
gl841_send_slope_table (dev, 0, slow_slope_table, 256);
gl841_send_slope_table (dev, 1, slow_slope_table, 256);
gl841_send_slope_table (dev, 2, slow_slope_table, 256);
gl841_send_slope_table (dev, 3, slow_slope_table, 256);
gl841_send_slope_table (dev, 4, slow_slope_table, 256);
gl841_send_slope_table(dev, 0, slow_slope_table, 256);
gl841_send_slope_table(dev, 1, slow_slope_table, 256);
gl841_send_slope_table(dev, 2, slow_slope_table, 256);
gl841_send_slope_table(dev, 3, slow_slope_table, 256);
gl841_send_slope_table(dev, 4, slow_slope_table, 256);
/* motor frequency table */
gl841_write_freq(dev, scan_yres);
@ -1386,36 +1376,20 @@ HOME_FREE: 3
else
r->value &= ~0x40;
status = gl841_send_slope_table (dev, 0, slow_slope_table, 256);
gl841_send_slope_table(dev, 0, slow_slope_table, 256);
if (status != SANE_STATUS_GOOD)
return status;
gl841_send_slope_table(dev, 1, back_slope_table, 256);
status = gl841_send_slope_table (dev, 1, back_slope_table, 256);
if (status != SANE_STATUS_GOOD)
return status;
status = gl841_send_slope_table (dev, 2, slow_slope_table, 256);
if (status != SANE_STATUS_GOOD)
return status;
gl841_send_slope_table(dev, 2, slow_slope_table, 256);
if (use_fast_fed) {
status = gl841_send_slope_table (dev, 3, fast_slope_table, 256);
if (status != SANE_STATUS_GOOD)
return status;
gl841_send_slope_table(dev, 3, fast_slope_table, 256);
}
if (flags & MOTOR_FLAG_AUTO_GO_HOME){
status = gl841_send_slope_table (dev, 4, fast_slope_table, 256);
if (status != SANE_STATUS_GOOD)
return status;
if (flags & MOTOR_FLAG_AUTO_GO_HOME) {
gl841_send_slope_table(dev, 4, fast_slope_table, 256);
}
/* now reg 0x21 and 0x24 are available, we can calculate reg 0x22 and 0x23,
reg 0x60-0x62 and reg 0x63-0x65
rule:

Wyświetl plik

@ -74,12 +74,9 @@ static void gl843_set_buffer_address(Genesys_Device* dev, uint32_t addr)
* @param size size of the chunk of data
* @param data pointer to the data to write
*/
static SANE_Status
write_data (Genesys_Device * dev, uint32_t addr, uint32_t size,
uint8_t * data)
static void write_data(Genesys_Device* dev, uint32_t addr, uint32_t size, uint8_t* data)
{
DBG_HELPER(dbg);
SANE_Status status = SANE_STATUS_GOOD;
gl843_set_buffer_address(dev, addr);
@ -88,7 +85,6 @@ write_data (Genesys_Device * dev, uint32_t addr, uint32_t size,
// set back address to 0
gl843_set_buffer_address(dev, 0);
return status;
}
/****************************************************************************
@ -724,16 +720,12 @@ gl843_init_registers (Genesys_Device * dev)
dev->calib_reg = dev->reg;
}
/* Send slope table for motor movement
slope_table in machine byte order
*/
static SANE_Status
gl843_send_slope_table (Genesys_Device * dev, int table_nr,
uint16_t * slope_table, int steps)
// Send slope table for motor movement slope_table in machine byte order
static void gl843_send_slope_table(Genesys_Device* dev, int table_nr, uint16_t* slope_table,
int steps)
{
DBG_HELPER_ARGS(dbg, "table_nr = %d, steps = %d", table_nr, steps);
SANE_Status status = SANE_STATUS_GOOD;
int i;
char msg[10000];
@ -754,17 +746,9 @@ gl843_send_slope_table (Genesys_Device * dev, int table_nr,
DBG(DBG_io, "%s: %s\n", __func__, msg);
}
/* slope table addresses are fixed : 0x4000, 0x4800, 0x5000, 0x5800, 0x6000 */
/* XXX STEF XXX USB 1.1 ? sanei_genesys_write_0x8c (dev, 0x0f, 0x14); */
status = write_data (dev, 0x4000 + 0x800 * table_nr, steps * 2, table.data());
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s: write data failed writing slope table %d (%s)\n", __func__, table_nr,
sane_strstatus(status));
}
return status;
// slope table addresses are fixed : 0x4000, 0x4800, 0x5000, 0x5800, 0x6000
// XXX STEF XXX USB 1.1 ? sanei_genesys_write_0x8c (dev, 0x0f, 0x14);
write_data(dev, 0x4000 + 0x800 * table_nr, steps * 2, table.data());
}
@ -863,7 +847,6 @@ gl843_init_motor_regs_scan (Genesys_Device * dev,
exposure, scan_yres, scan_step_type, scan_lines, scan_dummy, feed_steps,
scan_power_mode, flags);
SANE_Status status = SANE_STATUS_GOOD;
int use_fast_fed, coeff;
unsigned int lincnt;
uint16_t scan_table[1024];
@ -915,8 +898,8 @@ gl843_init_motor_regs_scan (Genesys_Device * dev,
factor,
dev->model->motor_type,
gl843_motors);
RIE(gl843_send_slope_table (dev, SCAN_TABLE, scan_table, scan_steps*factor));
RIE(gl843_send_slope_table (dev, BACKTRACK_TABLE, scan_table, scan_steps*factor));
gl843_send_slope_table(dev, SCAN_TABLE, scan_table, scan_steps * factor);
gl843_send_slope_table(dev, BACKTRACK_TABLE, scan_table, scan_steps * factor);
/* STEPNO */
r = sanei_genesys_get_address (reg, REG_STEPNO);
@ -941,9 +924,9 @@ gl843_init_motor_regs_scan (Genesys_Device * dev,
factor,
dev->model->motor_type,
gl843_motors);
RIE(gl843_send_slope_table (dev, STOP_TABLE, fast_table, fast_steps*factor));
RIE(gl843_send_slope_table (dev, FAST_TABLE, fast_table, fast_steps*factor));
RIE(gl843_send_slope_table (dev, HOME_TABLE, fast_table, fast_steps*factor));
gl843_send_slope_table(dev, STOP_TABLE, fast_table, fast_steps * factor);
gl843_send_slope_table(dev, FAST_TABLE, fast_table, fast_steps * factor);
gl843_send_slope_table(dev, HOME_TABLE, fast_table, fast_steps * factor);
/* FASTNO */
r = sanei_genesys_get_address (reg, REG_FASTNO);

Wyświetl plik

@ -422,20 +422,17 @@ gl846_init_registers (Genesys_Device * dev)
* @param slope_table pointer to 16 bit values array of the slope table
* @param steps number of elements in the slope table
*/
static SANE_Status
gl846_send_slope_table (Genesys_Device * dev, int table_nr,
uint16_t * slope_table, int steps)
static void gl846_send_slope_table(Genesys_Device* dev, int table_nr, uint16_t* slope_table,
int steps)
{
DBG_HELPER_ARGS(dbg, "table_nr = %d, steps = %d", table_nr, steps);
SANE_Status status = SANE_STATUS_GOOD;
int i;
char msg[10000];
/* sanity check */
if(table_nr<0 || table_nr>4)
{
DBG (DBG_error, "%s: invalid table number %d!\n", __func__, table_nr);
return SANE_STATUS_INVAL;
throw SaneException("invalid table number %d", table_nr);
}
std::vector<uint8_t> table(steps * 2);
@ -457,8 +454,6 @@ gl846_send_slope_table (Genesys_Device * dev, int table_nr,
// slope table addresses are fixed
sanei_genesys_write_ahb(dev, 0x10000000 + 0x4000 * table_nr, steps * 2, table.data());
return status;
}
/**
@ -549,7 +544,6 @@ gl846_init_motor_regs_scan (Genesys_Device * dev,
"scan_dummy=%d, feed_steps=%d, scan_power_mode=%d, flags=%x",
scan_exposure_time, scan_yres, scan_step_type, scan_lines, scan_dummy,
feed_steps, scan_power_mode, flags);
SANE_Status status = SANE_STATUS_GOOD;
int use_fast_fed;
unsigned int fast_dpi;
uint16_t scan_table[SLOPE_TABLE_SIZE];
@ -607,8 +601,8 @@ gl846_init_motor_regs_scan (Genesys_Device * dev,
factor,
dev->model->motor_type,
gl846_motors);
RIE(gl846_send_slope_table (dev, SCAN_TABLE, scan_table, scan_steps*factor));
RIE(gl846_send_slope_table (dev, BACKTRACK_TABLE, scan_table, scan_steps*factor));
gl846_send_slope_table(dev, SCAN_TABLE, scan_table, scan_steps * factor);
gl846_send_slope_table(dev, BACKTRACK_TABLE, scan_table, scan_steps * factor);
/* fast table */
fast_dpi=sanei_genesys_get_lowest_ydpi(dev);
@ -631,9 +625,9 @@ gl846_init_motor_regs_scan (Genesys_Device * dev,
/* manual override of high start value */
fast_table[0]=fast_table[1];
RIE(gl846_send_slope_table (dev, STOP_TABLE, fast_table, fast_steps*factor));
RIE(gl846_send_slope_table (dev, FAST_TABLE, fast_table, fast_steps*factor));
RIE(gl846_send_slope_table (dev, HOME_TABLE, fast_table, fast_steps*factor));
gl846_send_slope_table(dev, STOP_TABLE, fast_table, fast_steps * factor);
gl846_send_slope_table(dev, FAST_TABLE, fast_table, fast_steps * factor);
gl846_send_slope_table(dev, HOME_TABLE, fast_table, fast_steps * factor);
/* correct move distance by acceleration and deceleration amounts */
feedl=feed_steps;

Wyświetl plik

@ -442,20 +442,17 @@ gl847_init_registers (Genesys_Device * dev)
* @param slope_table pointer to 16 bit values array of the slope table
* @param steps number of elements in the slope table
*/
static SANE_Status
gl847_send_slope_table (Genesys_Device * dev, int table_nr,
uint16_t * slope_table, int steps)
static void gl847_send_slope_table(Genesys_Device* dev, int table_nr, uint16_t* slope_table,
int steps)
{
DBG_HELPER_ARGS(dbg, "table_nr = %d, steps = %d", table_nr, steps);
SANE_Status status = SANE_STATUS_GOOD;
int i;
char msg[10000];
/* sanity check */
if(table_nr<0 || table_nr>4)
{
DBG (DBG_error, "%s: invalid table number %d!\n", __func__, table_nr);
return SANE_STATUS_INVAL;
throw SaneException("invalid table number %d", table_nr);
}
std::vector<uint8_t> table(steps * 2);
@ -477,8 +474,6 @@ gl847_send_slope_table (Genesys_Device * dev, int table_nr,
// slope table addresses are fixed
sanei_genesys_write_ahb(dev, 0x10000000 + 0x4000 * table_nr, steps * 2, table.data());
return status;
}
/**
@ -581,7 +576,6 @@ gl847_init_motor_regs_scan (Genesys_Device * dev,
"scan_dummy=%d, feed_steps=%d, scan_power_mode=%d, flags=%x",
scan_exposure_time, scan_yres, scan_step_type, scan_lines, scan_dummy,
feed_steps, scan_power_mode, flags);
SANE_Status status = SANE_STATUS_GOOD;
int use_fast_fed;
unsigned int fast_dpi;
uint16_t scan_table[SLOPE_TABLE_SIZE];
@ -639,8 +633,8 @@ gl847_init_motor_regs_scan (Genesys_Device * dev,
factor,
dev->model->motor_type,
gl847_motors);
RIE(gl847_send_slope_table (dev, SCAN_TABLE, scan_table, scan_steps*factor));
RIE(gl847_send_slope_table (dev, BACKTRACK_TABLE, scan_table, scan_steps*factor));
gl847_send_slope_table(dev, SCAN_TABLE, scan_table, scan_steps * factor);
gl847_send_slope_table(dev, BACKTRACK_TABLE, scan_table, scan_steps * factor);
/* fast table */
fast_dpi=sanei_genesys_get_lowest_ydpi(dev);
@ -663,9 +657,9 @@ gl847_init_motor_regs_scan (Genesys_Device * dev,
/* manual override of high start value */
fast_table[0]=fast_table[1];
RIE(gl847_send_slope_table (dev, STOP_TABLE, fast_table, fast_steps*factor));
RIE(gl847_send_slope_table (dev, FAST_TABLE, fast_table, fast_steps*factor));
RIE(gl847_send_slope_table (dev, HOME_TABLE, fast_table, fast_steps*factor));
gl847_send_slope_table(dev, STOP_TABLE, fast_table, fast_steps * factor);
gl847_send_slope_table(dev, FAST_TABLE, fast_table, fast_steps * factor);
gl847_send_slope_table(dev, HOME_TABLE, fast_table, fast_steps * factor);
/* correct move distance by acceleration and deceleration amounts */
feedl=feed_steps;