From ae8cb155efc65000d4454d2499e9408b0d372097 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 9 May 2020 10:38:41 +0300 Subject: [PATCH 1/2] genesys: Simplify register setup on gl841 --- backend/genesys/gl841.cpp | 41 ++----------------------------- backend/genesys/gl841_registers.h | 2 ++ 2 files changed, 4 insertions(+), 39 deletions(-) diff --git a/backend/genesys/gl841.cpp b/backend/genesys/gl841.cpp index b1fa49ec6..6c580c673 100644 --- a/backend/genesys/gl841.cpp +++ b/backend/genesys/gl841.cpp @@ -685,7 +685,6 @@ static void gl841_init_motor_regs_scan(Genesys_Device* dev, const Genesys_Sensor unsigned int slow_time; unsigned int feedl; unsigned int min_restep = 0x20; - uint32_t z1, z2; fast_exposure = gl841_exposure_time(dev, sensor, dev->motor.base_ydpi / 4, @@ -867,16 +866,8 @@ static void gl841_init_motor_regs_scan(Genesys_Device* dev, const Genesys_Sensor z1 = (slope_0_time-1) % exposure_time; z2 = (slope_0_time-1) % exposure_time; */ - z1 = z2 = 0; - - DBG(DBG_info, "%s: z1 = %d\n", __func__, z1); - DBG(DBG_info, "%s: z2 = %d\n", __func__, z2); - reg->set8(0x60, ((z1 >> 16) & 0xff)); - reg->set8(0x61, ((z1 >> 8) & 0xff)); - reg->set8(0x62, (z1 & 0xff)); - reg->set8(0x63, ((z2 >> 16) & 0xff)); - reg->set8(0x64, ((z2 >> 8) & 0xff)); - reg->set8(0x65, (z2 & 0xff)); + reg->set24(REG_0x60, 0); + reg->set24(REG_0x63, 0); reg->find_reg(REG_0x1E).value &= REG_0x1E_WDTIME; reg->find_reg(REG_0x1E).value |= scan_dummy; reg->set8(0x67, 0x3f | (static_cast(scan_step_type) << 6)); @@ -1109,34 +1100,6 @@ void CommandSetGl841::init_regs_for_scan_session(Genesys_Device* dev, const Gene int slope_dpi = 0; int dummy = 0; -/* -results: - -for scanner: -start -end -dpiset -exposure_time -dummy -z1 -z2 - -for ordered_read: - dev->words_per_line - dev->read_factor - dev->requested_buffer_size - dev->read_buffer_size - dev->read_pos - dev->read_bytes_in_buffer - dev->read_bytes_left - dev->max_shift - dev->stagger - -independent of our calculated values: - dev->total_bytes_read - dev->bytes_to_read - */ - /* dummy */ /* dummy lines: may not be usefull, for instance 250 dpi works with 0 or 1 dummy line. Maybe the dummy line adds correctness since the motor runs diff --git a/backend/genesys/gl841_registers.h b/backend/genesys/gl841_registers.h index 8e0c20414..2fac27823 100644 --- a/backend/genesys/gl841_registers.h +++ b/backend/genesys/gl841_registers.h @@ -224,10 +224,12 @@ static constexpr RegShift REG_0x5ES_DECSEL = 5; static constexpr RegMask REG_0x5E_STOPTIM = 0x1f; static constexpr RegShift REG_0x5ES_STOPTIM = 0; +static constexpr RegAddr REG_0x60 = 0x60; static constexpr RegMask REG_0x60_ZIMOD = 0x1f; static constexpr RegMask REG_0x61_Z1MOD = 0xff; static constexpr RegMask REG_0x62_Z1MOD = 0xff; +static constexpr RegAddr REG_0x63 = 0x63; static constexpr RegMask REG_0x63_Z2MOD = 0x1f; static constexpr RegMask REG_0x64_Z2MOD = 0xff; static constexpr RegMask REG_0x65_Z2MOD = 0xff; From 4691b92d80478c97701ed04b9817f92a268d2235 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 9 May 2020 10:38:42 +0300 Subject: [PATCH 2/2] genesys: Simplify motor profile selection on gl841 --- backend/genesys/gl841.cpp | 71 +++++++++----------------------- backend/genesys/tables_motor.cpp | 63 ++++++++++++++++++++++------ 2 files changed, 71 insertions(+), 63 deletions(-) diff --git a/backend/genesys/gl841.cpp b/backend/genesys/gl841.cpp index 6c580c673..930ce6bff 100644 --- a/backend/genesys/gl841.cpp +++ b/backend/genesys/gl841.cpp @@ -664,10 +664,9 @@ static void gl841_init_motor_regs_feed(Genesys_Device* dev, const Genesys_Sensor } static void gl841_init_motor_regs_scan(Genesys_Device* dev, const Genesys_Sensor& sensor, - Genesys_Register_Set* reg, + Genesys_Register_Set* reg, const MotorProfile& motor_profile, unsigned int scan_exposure_time,/*pixel*/ unsigned scan_yres, // dpi, motor resolution - StepType scan_step_type, unsigned int scan_lines,/*lines, scan resolution*/ unsigned int scan_dummy, // number of scan lines to add in a scan_lines line @@ -677,7 +676,7 @@ static void gl841_init_motor_regs_scan(Genesys_Device* dev, const Genesys_Sensor { DBG_HELPER_ARGS(dbg, "scan_exposure_time=%d, scan_yres=%d, scan_step_type=%d, scan_lines=%d," " scan_dummy=%d, feed_steps=%d, flags=%x", - scan_exposure_time, scan_yres, static_cast(scan_step_type), + scan_exposure_time, scan_yres, static_cast(motor_profile.step_type), scan_lines, scan_dummy, feed_steps, static_cast(flags)); unsigned int fast_exposure; int use_fast_fed = 0; @@ -716,15 +715,15 @@ static void gl841_init_motor_regs_scan(Genesys_Device* dev, const Genesys_Sensor */ auto slow_table = sanei_genesys_create_slope_table3(dev->model->asic_type, dev->motor, - scan_step_type, scan_exposure_time, - scan_yres); + motor_profile.step_type, + scan_exposure_time, scan_yres); auto back_table = sanei_genesys_create_slope_table3(dev->model->asic_type, dev->motor, - scan_step_type, 0, scan_yres); + motor_profile.step_type, 0, scan_yres); - if (feed_steps < (slow_table.steps_count >> static_cast(scan_step_type))) { + if (feed_steps < (slow_table.steps_count >> static_cast(motor_profile.step_type))) { /*TODO: what should we do here?? go back to exposure calculation?*/ - feed_steps = slow_table.steps_count >> static_cast(scan_step_type); + feed_steps = slow_table.steps_count >> static_cast(motor_profile.step_type); } auto fast_table = sanei_genesys_create_slope_table3(dev->model->asic_type, dev->motor, @@ -732,9 +731,9 @@ static void gl841_init_motor_regs_scan(Genesys_Device* dev, const Genesys_Sensor dev->motor.base_ydpi / 4); unsigned max_fast_slope_steps_count = 1; - if (feed_steps > (slow_table.steps_count >> static_cast(scan_step_type)) + 2) { + if (feed_steps > (slow_table.steps_count >> static_cast(motor_profile.step_type)) + 2) { max_fast_slope_steps_count = (feed_steps - - (slow_table.steps_count >> static_cast(scan_step_type))) / 2; + (slow_table.steps_count >> static_cast(motor_profile.step_type))) / 2; } if (fast_table.steps_count > max_fast_slope_steps_count) { @@ -750,7 +749,7 @@ static void gl841_init_motor_regs_scan(Genesys_Device* dev, const Genesys_Sensor use_fast_fed = 0; } else if (feed_steps < fast_table.steps_count * 2 + - (slow_table.steps_count >> static_cast(scan_step_type))) + (slow_table.steps_count >> static_cast(motor_profile.step_type))) { use_fast_fed = 0; DBG(DBG_info, "%s: feed too short, slow move forced.\n", __func__); @@ -766,11 +765,11 @@ static void gl841_init_motor_regs_scan(Genesys_Device* dev, const Genesys_Sensor fast_time = fast_exposure / 4 * (feed_steps - fast_table.steps_count*2 - - (slow_table.steps_count >> static_cast(scan_step_type))) + (slow_table.steps_count >> static_cast(motor_profile.step_type))) + fast_table.pixeltime_sum*2 + slow_table.pixeltime_sum; slow_time = (scan_exposure_time * scan_yres) / dev->motor.base_ydpi * - (feed_steps - (slow_table.steps_count >> static_cast(scan_step_type))) + (feed_steps - (slow_table.steps_count >> static_cast(motor_profile.step_type))) + slow_table.pixeltime_sum; DBG(DBG_info, "%s: Time for slow move: %d\n", __func__, slow_time); @@ -781,11 +780,11 @@ static void gl841_init_motor_regs_scan(Genesys_Device* dev, const Genesys_Sensor if (use_fast_fed) { feedl = feed_steps - fast_table.steps_count * 2 - - (slow_table.steps_count >> static_cast(scan_step_type)); - } else if ((feed_steps << static_cast(scan_step_type)) < slow_table.steps_count) { + (slow_table.steps_count >> static_cast(motor_profile.step_type)); + } else if ((feed_steps << static_cast(motor_profile.step_type)) < slow_table.steps_count) { feedl = 0; } else { - feedl = (feed_steps << static_cast(scan_step_type)) - slow_table.steps_count; + feedl = (feed_steps << static_cast(motor_profile.step_type)) - slow_table.steps_count; } DBG(DBG_info, "%s: Decided to use %s mode\n", __func__, use_fast_fed?"fast feed":"slow feed"); @@ -870,7 +869,7 @@ static void gl841_init_motor_regs_scan(Genesys_Device* dev, const Genesys_Sensor reg->set24(REG_0x63, 0); reg->find_reg(REG_0x1E).value &= REG_0x1E_WDTIME; reg->find_reg(REG_0x1E).value |= scan_dummy; - reg->set8(0x67, 0x3f | (static_cast(scan_step_type) << 6)); + reg->set8(0x67, 0x3f | (static_cast(motor_profile.step_type) << 6)); reg->set8(0x68, 0x3f); reg->set8(REG_STEPNO, (slow_table.steps_count >> 1) + (slow_table.steps_count & 1)); reg->set8(REG_FASTNO, (back_table.steps_count >> 1) + (back_table.steps_count & 1)); @@ -1056,37 +1055,6 @@ int led_exposure; return exposure_time; } -/**@brief compute scan_step_type - * Try to do at least 4 steps per line. if that is impossible we will have to - * live with that. - * @param dev device - * @param yres motor resolution - */ -static StepType gl841_scan_step_type(Genesys_Device *dev, int yres) -{ - StepType type = StepType::FULL; - - /* TODO : check if there is a bug around the use of max_step_type */ - /* should be <=1, need to chek all devices entry in genesys_devices */ - if (yres * 4 < dev->motor.base_ydpi || dev->motor.max_step_type() == StepType::FULL) { - type = StepType::FULL; - } else if (yres * 4 < dev->motor.base_ydpi * 2 || - dev->motor.max_step_type() <= StepType::HALF) - { - type = StepType::HALF; - } else { - type = StepType::QUARTER; - } - - /* this motor behaves differently */ - if (dev->model->motor_id==MotorId::CANON_LIDE_80) { - // driven by 'frequency' tables ? - type = StepType::FULL; - } - - return type; -} - void CommandSetGl841::init_regs_for_scan_session(Genesys_Device* dev, const Genesys_Sensor& sensor, Genesys_Register_Set* reg, const ScanSession& session) const @@ -1138,10 +1106,11 @@ dummy \ scanned lines slope_dpi = slope_dpi * (1 + dummy); - StepType scan_step_type = gl841_scan_step_type(dev, session.params.yres); + const auto& motor_profile = get_motor_profile(dev->motor.profiles, 0, session); + exposure_time = gl841_exposure_time(dev, sensor, slope_dpi, - scan_step_type, + motor_profile.step_type, session.pixel_startx, session.optical_pixels); DBG(DBG_info, "%s : exposure_time=%d pixels\n", __func__, exposure_time); @@ -1166,7 +1135,7 @@ dummy \ scanned lines if (has_flag(session.params.flags, ScanFlag::SINGLE_LINE)) { gl841_init_motor_regs_off(reg, session.optical_line_count); } else { - gl841_init_motor_regs_scan(dev, sensor, reg, exposure_time, slope_dpi, scan_step_type, + gl841_init_motor_regs_scan(dev, sensor, reg, motor_profile, exposure_time, slope_dpi, session.optical_line_count, dummy, move, session.params.flags); } diff --git a/backend/genesys/tables_motor.cpp b/backend/genesys/tables_motor.cpp index c90472cdc..718325555 100644 --- a/backend/genesys/tables_motor.cpp +++ b/backend/genesys/tables_motor.cpp @@ -106,8 +106,14 @@ void genesys_init_motor_tables() motor = Genesys_Motor(); motor.id = MotorId::CANON_LIDE_35; motor.base_ydpi = 1200; - motor.profiles.push_back({MotorSlope::create_from_steps(3500, 1300, 60), StepType::FULL, 0}); - motor.profiles.push_back({MotorSlope::create_from_steps(3500, 1400, 60), StepType::HALF, 0}); + + profile = MotorProfile{MotorSlope::create_from_steps(3500, 1300, 60), StepType::FULL, 0}; + profile.resolutions = {75, 100, 150, 200}; + motor.profiles.push_back(profile); + + profile = MotorProfile{MotorSlope::create_from_steps(3500, 1400, 60), StepType::HALF, 0}; + profile.resolutions = {300, 600, 1200, 2400}; + motor.profiles.push_back(profile); s_motors->push_back(std::move(motor)); @@ -123,32 +129,58 @@ void genesys_init_motor_tables() motor.id = MotorId::XP300; motor.base_ydpi = 300; // works best with GPIO10, GPIO14 off - motor.profiles.push_back({MotorSlope::create_from_steps(3700, 3700, 2), StepType::FULL, 0}); - motor.profiles.push_back({MotorSlope::create_from_steps(11000, 11000, 2), StepType::HALF, 0}); + profile = MotorProfile{MotorSlope::create_from_steps(3700, 3700, 2), StepType::FULL, 0}; + profile.resolutions = {}; // used during fast moves + motor.profiles.push_back(profile); + + // FIXME: this motor profile is useless + profile = MotorProfile{MotorSlope::create_from_steps(11000, 11000, 2), StepType::HALF, 0}; + profile.resolutions = {75, 150, 300, 600}; + motor.profiles.push_back(profile); s_motors->push_back(std::move(motor)); motor = Genesys_Motor(); motor.id = MotorId::DP665; motor.base_ydpi = 750; - motor.profiles.push_back({MotorSlope::create_from_steps(3000, 2500, 10), StepType::FULL, 0}); - motor.profiles.push_back({MotorSlope::create_from_steps(11000, 11000, 2), StepType::HALF, 0}); + + profile = MotorProfile{MotorSlope::create_from_steps(3000, 2500, 10), StepType::FULL, 0}; + profile.resolutions = {75, 150}; + motor.profiles.push_back(profile); + + // FIXME: this motor profile is useless + profile = MotorProfile{MotorSlope::create_from_steps(11000, 11000, 2), StepType::HALF, 0}; + profile.resolutions = {300, 600, 1200}; + motor.profiles.push_back(profile); s_motors->push_back(std::move(motor)); motor = Genesys_Motor(); motor.id = MotorId::ROADWARRIOR; motor.base_ydpi = 750; - motor.profiles.push_back({MotorSlope::create_from_steps(3000, 2600, 10), StepType::FULL, 0}); - motor.profiles.push_back({MotorSlope::create_from_steps(11000, 11000, 2), StepType::HALF, 0}); + + profile = MotorProfile{MotorSlope::create_from_steps(3000, 2600, 10), StepType::FULL, 0}; + profile.resolutions = {75, 150}; + motor.profiles.push_back(profile); + + // FIXME: this motor profile is useless + profile = MotorProfile{MotorSlope::create_from_steps(11000, 11000, 2), StepType::HALF, 0}; + profile.resolutions = {300, 600, 1200}; + motor.profiles.push_back(profile); s_motors->push_back(std::move(motor)); motor = Genesys_Motor(); motor.id = MotorId::DSMOBILE_600; motor.base_ydpi = 750; - motor.profiles.push_back({MotorSlope::create_from_steps(6666, 3700, 8), StepType::FULL, 0}); - motor.profiles.push_back({MotorSlope::create_from_steps(6666, 3700, 8), StepType::HALF, 0}); + + profile = MotorProfile{MotorSlope::create_from_steps(6666, 3700, 8), StepType::FULL, 0}; + profile.resolutions = {75, 150}; + motor.profiles.push_back(profile); + + profile = MotorProfile{MotorSlope::create_from_steps(6666, 3700, 8), StepType::HALF, 0}; + profile.resolutions = {300, 600, 1200}; + motor.profiles.push_back(profile); s_motors->push_back(std::move(motor)); @@ -385,8 +417,15 @@ void genesys_init_motor_tables() motor = Genesys_Motor(); motor.id = MotorId::PLUSTEK_OPTICPRO_3600; motor.base_ydpi = 1200; - motor.profiles.push_back({MotorSlope::create_from_steps(3500, 1300, 60), StepType::FULL, 0}); - motor.profiles.push_back({MotorSlope::create_from_steps(3500, 3250, 60), StepType::HALF, 0}); + + profile = MotorProfile{MotorSlope::create_from_steps(3500, 1300, 60), StepType::FULL, 0}; + profile.resolutions = {75, 100, 150, 200}; + motor.profiles.push_back(profile); + + // FIXME: this motor profile is almost useless + profile = MotorProfile{MotorSlope::create_from_steps(3500, 3250, 60), StepType::HALF, 0}; + profile.resolutions = {300, 400, 600, 1200}; + motor.profiles.push_back(profile); s_motors->push_back(std::move(motor));