From 80efacab1022351597dac95f6183204fb3f3e800 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 11 May 2019 12:05:21 +0300 Subject: [PATCH] genesys: Reuse sanei_genesys_bulk_write_data() on GL841 --- backend/genesys_gl841.c | 145 ++-------------------------------------- backend/genesys_low.c | 17 +++-- 2 files changed, 18 insertions(+), 144 deletions(-) diff --git a/backend/genesys_gl841.c b/backend/genesys_gl841.c index 2253d0ff6..078623a09 100644 --- a/backend/genesys_gl841.c +++ b/backend/genesys_gl841.c @@ -112,72 +112,6 @@ gl841_bulk_write_register (Genesys_Device * dev, return status; } -/* Write bulk data (e.g. shading, gamma) */ -static SANE_Status -gl841_bulk_write_data (Genesys_Device * dev, uint8_t addr, - uint8_t * data, size_t len) -{ - SANE_Status status; - size_t size; - uint8_t outdata[8]; - - DBG(DBG_io, "%s writing %lu bytes\n", __func__, (u_long) len); - - status = - sanei_usb_control_msg (dev->dn, REQUEST_TYPE_OUT, REQUEST_REGISTER, - VALUE_SET_REGISTER, INDEX, 1, &addr); - if (status != SANE_STATUS_GOOD) - { - DBG(DBG_error, "%s failed while setting register: %s\n", __func__, sane_strstatus(status)); - return status; - } - - while (len) - { - if (len > BULKOUT_MAXSIZE) - size = BULKOUT_MAXSIZE; - else - size = len; - - outdata[0] = BULK_OUT; - outdata[1] = BULK_RAM; - outdata[2] = VALUE_BUFFER & 0xff; - outdata[3] = (VALUE_BUFFER >> 8) & 0xff; - outdata[4] = (size & 0xff); - outdata[5] = ((size >> 8) & 0xff); - outdata[6] = ((size >> 16) & 0xff); - outdata[7] = ((size >> 24) & 0xff); - - status = - sanei_usb_control_msg (dev->dn, REQUEST_TYPE_OUT, REQUEST_BUFFER, - VALUE_BUFFER, INDEX, sizeof (outdata), - outdata); - if (status != SANE_STATUS_GOOD) - { - DBG(DBG_error, "%s failed while writing command: %s\n", __func__, sane_strstatus(status)); - return status; - } - - status = sanei_usb_write_bulk (dev->dn, data, &size); - if (status != SANE_STATUS_GOOD) - { - DBG(DBG_error, "%s failed while writing bulk data: %s\n", __func__, - sane_strstatus(status)); - return status; - } - - DBG(DBG_io2, "%s wrote %lu bytes, %lu remaining\n", __func__, (u_long) size, - (u_long) (len - size)); - - len -= size; - data += size; - } - - DBG(DBG_io, "%s: completed\n", __func__); - - return status; -} - /* for debugging transfer rate*/ /* #include @@ -227,73 +161,6 @@ gl841_set_buffer_address_gamma (Genesys_Device * dev, uint32_t addr) return status; } -/* Write bulk data (e.g. gamma) */ -GENESYS_STATIC SANE_Status -gl841_bulk_write_data_gamma (Genesys_Device * dev, uint8_t addr, - uint8_t * data, size_t len) -{ - SANE_Status status; - size_t size; - uint8_t outdata[8]; - - DBG(DBG_io, "%s writing %lu bytes\n", __func__, (u_long) len); - - status = - sanei_usb_control_msg (dev->dn, REQUEST_TYPE_OUT, REQUEST_REGISTER, - VALUE_SET_REGISTER, INDEX, 1, &addr); - if (status != SANE_STATUS_GOOD) - { - DBG(DBG_error, "%s failed while setting register: %s\n", __func__, sane_strstatus(status)); - return status; - } - - while (len) - { - if (len > BULKOUT_MAXSIZE) - size = BULKOUT_MAXSIZE; - else - size = len; - - outdata[0] = BULK_OUT; - outdata[1] = BULK_RAM; - outdata[2] = 0x00;/* 0x82 works, too */ - outdata[3] = 0x00; - outdata[4] = (size & 0xff); - outdata[5] = ((size >> 8) & 0xff); - outdata[6] = ((size >> 16) & 0xff); - outdata[7] = ((size >> 24) & 0xff); - - status = - sanei_usb_control_msg (dev->dn, REQUEST_TYPE_OUT, REQUEST_BUFFER, - VALUE_BUFFER, INDEX, sizeof (outdata), - outdata); - if (status != SANE_STATUS_GOOD) - { - DBG(DBG_error, "%s failed while writing command: %s\n", __func__, sane_strstatus(status)); - return status; - } - - status = sanei_usb_write_bulk (dev->dn, data, &size); - if (status != SANE_STATUS_GOOD) - { - DBG(DBG_error, "%s failed while writing bulk data: %s\n", __func__, - sane_strstatus(status)); - return status; - } - - DBG(DBG_io2, "%s:gamma wrote %lu bytes, %lu remaining\n", __func__, (u_long) size, - (u_long) (len - size)); - - len -= size; - data += size; - } - - DBG(DBG_io, "%s: completed\n", __func__); - - return status; -} - - /**************************************************************************** Mid level functions ****************************************************************************/ @@ -595,7 +462,7 @@ sanei_gl841_asic_test (Genesys_Device * dev) return status; } -/* status = gl841_bulk_write_data (dev, 0x3c, data, size); +/* status = sanei_genesys_bulk_write_data(dev, 0x3c, data, size); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to bulk write data: %s\n", __func__, sane_strstatus(status)); @@ -1046,9 +913,7 @@ gl841_send_slope_table (Genesys_Device * dev, int table_nr, return status; } - status = - gl841_bulk_write_data (dev, 0x3c, (uint8_t *) table, - steps * 2); + status = sanei_genesys_bulk_write_data(dev, 0x3c, (uint8_t *) table, steps * 2); if (status != SANE_STATUS_GOOD) { /*#ifdef WORDS_BIGENDIAN*/ @@ -1515,7 +1380,7 @@ uint8_t *table; RIE(sanei_genesys_write_register(dev, 0x66, 0x00)); RIE(sanei_genesys_write_register(dev, 0x5b, 0x0c)); RIE(sanei_genesys_write_register(dev, 0x5c, 0x00)); - RIE(gl841_bulk_write_data_gamma (dev, 0x28, table, 128)); + RIE(sanei_genesys_bulk_write_data(dev, 0x28, table, 128)); RIE(sanei_genesys_write_register(dev, 0x5b, 0x00)); RIE(sanei_genesys_write_register(dev, 0x5c, 0x00)); } @@ -4298,7 +4163,7 @@ gl841_send_gamma_table (Genesys_Device * dev) } /* send data */ - status = gl841_bulk_write_data_gamma (dev, 0x28, (uint8_t *) gamma, size * 2 * 3); + status = sanei_genesys_bulk_write_data(dev, 0x28, (uint8_t *) gamma, size * 2 * 3); if (status != SANE_STATUS_GOOD) { free (gamma); @@ -6036,7 +5901,7 @@ static Genesys_Command_Set gl841_cmd_set = { NULL, gl841_bulk_write_register, - gl841_bulk_write_data, + sanei_genesys_bulk_write_data, sanei_genesys_bulk_read_data, gl841_update_hardware_sensors, diff --git a/backend/genesys_low.c b/backend/genesys_low.c index 061475c6d..d9d8e245b 100644 --- a/backend/genesys_low.c +++ b/backend/genesys_low.c @@ -344,6 +344,7 @@ SANE_Status sanei_genesys_bulk_read_data(Genesys_Device * dev, uint8_t addr, uin SANE_Status sanei_genesys_bulk_write_data(Genesys_Device * dev, uint8_t addr, uint8_t* data, size_t len) { + // supported: GL841, GL843 SANE_Status status; size_t size; uint8_t outdata[8]; @@ -366,10 +367,18 @@ SANE_Status sanei_genesys_bulk_write_data(Genesys_Device * dev, uint8_t addr, ui else size = len; - outdata[0] = BULK_OUT; - outdata[1] = BULK_RAM; - outdata[2] = 0x00; - outdata[3] = 0x00; + if (dev->model->asic_type == GENESYS_GL841) { + outdata[0] = BULK_OUT; + outdata[1] = BULK_RAM; + outdata[2] = VALUE_BUFFER & 0xff; + outdata[3] = (VALUE_BUFFER >> 8) & 0xff; + } else { + outdata[0] = BULK_OUT; + outdata[1] = BULK_RAM; + outdata[2] = 0x00; + outdata[3] = 0x00; + } + outdata[4] = (size & 0xff); outdata[5] = ((size >> 8) & 0xff); outdata[6] = ((size >> 16) & 0xff);