genesys: Reuse sanei_genesys_bulk_read_data() on GL847

merge-requests/63/head
Povilas Kanapickas 2019-05-11 12:05:15 +03:00
rodzic 4af3557bbf
commit 9dc8bbfac9
2 zmienionych plików z 11 dodań i 100 usunięć

Wyświetl plik

@ -47,102 +47,6 @@
#include "genesys_gl847.h"
/****************************************************************************
Low level function
****************************************************************************/
/* ------------------------------------------------------------------------ */
/* Read and write RAM, registers and AFE */
/* ------------------------------------------------------------------------ */
/** @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
* 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
* @param data pointer where to store the read data
* @param len size to read
*/
static SANE_Status
gl847_bulk_read_data (Genesys_Device * dev, uint8_t addr,
uint8_t * data, size_t len)
{
SANE_Status status;
size_t size, target;
uint8_t outdata[8];
uint8_t *buffer;
DBG(DBG_io, "%s: requesting %lu bytes at addr=0x%02x\n", __func__, (u_long) len, addr);
if (len == 0)
return SANE_STATUS_GOOD;
target = len;
buffer = data;
/* loop until computed data size is read */
while (target)
{
if (target > 0xeff0)
{
size = 0xeff0;
}
else
{
size = target;
}
/* hard coded 0x10000000 addr */
outdata[0] = 0;
outdata[1] = 0;
outdata[2] = 0;
outdata[3] = 0x10;
/* data size to transfer */
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, 0x00, sizeof (outdata),
outdata);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s failed while writing command: %s\n", __func__, sane_strstatus(status));
return status;
}
DBG(DBG_io2, "%s: trying to read %lu bytes of data\n", __func__, (u_long) size);
status = sanei_usb_read_bulk (dev->dn, buffer, &size);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s failed while reading bulk data: %s\n", __func__,
sane_strstatus(status));
return status;
}
DBG(DBG_io2, "%s: read %lu bytes, %lu remaining\n", __func__, (u_long) size,
(u_long) (target - size));
target -= size;
buffer += size;
}
if (DBG_LEVEL >= DBG_data && dev->binary!=NULL)
{
fwrite(data, len, 1, dev->binary);
}
DBGCOMPLETED;
return SANE_STATUS_GOOD;
}
/****************************************************************************
Mid level functions
****************************************************************************/
@ -3660,7 +3564,7 @@ static Genesys_Command_Set gl847_cmd_set = {
sanei_genesys_bulk_write_register,
NULL,
gl847_bulk_read_data,
sanei_genesys_bulk_read_data,
gl847_update_hardware_sensors,

Wyświetl plik

@ -199,7 +199,9 @@ SANE_Status sanei_genesys_bulk_read_data_send_header(Genesys_Device* dev, size_t
uint8_t outdata[8];
if (dev->model->asic_type == GENESYS_GL124 ||
dev->model->asic_type == GENESYS_GL846) {
dev->model->asic_type == GENESYS_GL846 ||
dev->model->asic_type == GENESYS_GL847)
{
// hard coded 0x10000000 address
outdata[0] = 0;
outdata[1] = 0;
@ -238,6 +240,7 @@ SANE_Status sanei_genesys_bulk_read_data_send_header(Genesys_Device* dev, size_t
SANE_Status sanei_genesys_bulk_read_data(Genesys_Device * dev, uint8_t addr, uint8_t* data,
size_t len)
{
// currently supported: GL646, GL841, GL843, GL846, GL847, GL124
SANE_Status status;
size_t size, target;
uint8_t *buffer;
@ -245,7 +248,9 @@ SANE_Status sanei_genesys_bulk_read_data(Genesys_Device * dev, uint8_t addr, uin
unsigned is_addr_used = 1;
unsigned has_header_before_each_chunk = 0;
if (dev->model->asic_type == GENESYS_GL124 ||
dev->model->asic_type == GENESYS_GL846) {
dev->model->asic_type == GENESYS_GL846 ||
dev->model->asic_type == GENESYS_GL847)
{
is_addr_used = 0;
has_header_before_each_chunk = 1;
}
@ -280,8 +285,10 @@ SANE_Status sanei_genesys_bulk_read_data(Genesys_Device * dev, uint8_t addr, uin
*/
size_t max_in_size = 0xf000;
if (dev->model->asic_type == GENESYS_GL124 ||
dev->model->asic_type == GENESYS_GL846)
dev->model->asic_type == GENESYS_GL846 ||
dev->model->asic_type == GENESYS_GL847) {
max_in_size = 0xeff0;
}
if (!has_header_before_each_chunk) {
status = sanei_genesys_bulk_read_data_send_header(dev, len);