1141cc406Sopenharmony_ci/* sane - Scanner Access Now Easy. 2141cc406Sopenharmony_ci 3141cc406Sopenharmony_ci ScanMaker 3840 Backend 4141cc406Sopenharmony_ci Copyright (C) 2005-7 Earle F. Philhower, III 5141cc406Sopenharmony_ci earle@ziplabel.com - http://www.ziplabel.com 6141cc406Sopenharmony_ci 7141cc406Sopenharmony_ci This program is free software; you can redistribute it and/or 8141cc406Sopenharmony_ci modify it under the terms of the GNU General Public License as 9141cc406Sopenharmony_ci published by the Free Software Foundation; either version 2 of the 10141cc406Sopenharmony_ci License, or (at your option) any later version. 11141cc406Sopenharmony_ci 12141cc406Sopenharmony_ci This program is distributed in the hope that it will be useful, but 13141cc406Sopenharmony_ci WITHOUT ANY WARRANTY; without even the implied warranty of 14141cc406Sopenharmony_ci MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15141cc406Sopenharmony_ci General Public License for more details. 16141cc406Sopenharmony_ci 17141cc406Sopenharmony_ci You should have received a copy of the GNU General Public License 18141cc406Sopenharmony_ci along with this program. If not, see <https://www.gnu.org/licenses/>. 19141cc406Sopenharmony_ci 20141cc406Sopenharmony_ci As a special exception, the authors of SANE give permission for 21141cc406Sopenharmony_ci additional uses of the libraries contained in this release of SANE. 22141cc406Sopenharmony_ci 23141cc406Sopenharmony_ci The exception is that, if you link a SANE library with other files 24141cc406Sopenharmony_ci to produce an executable, this does not by itself cause the 25141cc406Sopenharmony_ci resulting executable to be covered by the GNU General Public 26141cc406Sopenharmony_ci License. Your use of that executable is in no way restricted on 27141cc406Sopenharmony_ci account of linking the SANE library code into it. 28141cc406Sopenharmony_ci 29141cc406Sopenharmony_ci This exception does not, however, invalidate any other reasons why 30141cc406Sopenharmony_ci the executable file might be covered by the GNU General Public 31141cc406Sopenharmony_ci License. 32141cc406Sopenharmony_ci 33141cc406Sopenharmony_ci If you submit changes to SANE to the maintainers to be included in 34141cc406Sopenharmony_ci a subsequent release, you agree by submitting the changes that 35141cc406Sopenharmony_ci those changes may be distributed with this exception intact. 36141cc406Sopenharmony_ci 37141cc406Sopenharmony_ci If you write modifications of your own for SANE, it is your choice 38141cc406Sopenharmony_ci whether to permit this exception to apply to your modifications. 39141cc406Sopenharmony_ci If you do not wish that, delete this exception notice. 40141cc406Sopenharmony_ci 41141cc406Sopenharmony_ci*/ 42141cc406Sopenharmony_ci 43141cc406Sopenharmony_ci#include <stdio.h> 44141cc406Sopenharmony_ci#include <stdarg.h> 45141cc406Sopenharmony_ci 46141cc406Sopenharmony_ci#ifndef BACKENDNAME 47141cc406Sopenharmony_ci#include <usb.h> 48141cc406Sopenharmony_ci#include <string.h> 49141cc406Sopenharmony_ci 50141cc406Sopenharmony_ci#ifndef DEFINED_USB_HANDLE 51141cc406Sopenharmony_ci#define DEFINED_USB_HANDLE 52141cc406Sopenharmony_citypedef usb_dev_handle *p_usb_dev_handle; 53141cc406Sopenharmony_ci#endif 54141cc406Sopenharmony_ci 55141cc406Sopenharmony_cistatic p_usb_dev_handle find_device (unsigned int idVendor, 56141cc406Sopenharmony_ci unsigned int idProduct); 57141cc406Sopenharmony_ci#else 58141cc406Sopenharmony_ci#include "../include/sane/sanei_usb.h" 59141cc406Sopenharmony_ci 60141cc406Sopenharmony_ci#ifndef USBWRAPPER 61141cc406Sopenharmony_ci#define USBWRAPPER 62141cc406Sopenharmony_ci 63141cc406Sopenharmony_citypedef SANE_Int p_usb_dev_handle; 64141cc406Sopenharmony_ci#define usb_control_msg my_usb_control_msg 65141cc406Sopenharmony_ci#define usb_bulk_read my_usb_bulk_read 66141cc406Sopenharmony_ci#define usb_bulk_write my_usb_bulk_write 67141cc406Sopenharmony_cistatic int my_usb_bulk_write (p_usb_dev_handle dev, int ep, 68141cc406Sopenharmony_ci unsigned char *bytes, 69141cc406Sopenharmony_ci int size, int timeout); 70141cc406Sopenharmony_cistatic int my_usb_bulk_read (p_usb_dev_handle dev, int ep, 71141cc406Sopenharmony_ci unsigned char *bytes, 72141cc406Sopenharmony_ci int size, int timeout); 73141cc406Sopenharmony_cistatic int my_usb_control_msg (p_usb_dev_handle dev, int requesttype, 74141cc406Sopenharmony_ci int request, int value, int index, 75141cc406Sopenharmony_ci unsigned char *bytes, 76141cc406Sopenharmony_ci int size, int timeout); 77141cc406Sopenharmony_ci#endif /* USBWRAPPER */ 78141cc406Sopenharmony_ci 79141cc406Sopenharmony_ci#endif 80141cc406Sopenharmony_ci 81141cc406Sopenharmony_ci#include "sm3840_params.h" 82141cc406Sopenharmony_ci 83141cc406Sopenharmony_cistatic void idle_ab (p_usb_dev_handle udev); 84141cc406Sopenharmony_cistatic void write_regs (p_usb_dev_handle udev, int regs, int reg1, int val1, 85141cc406Sopenharmony_ci ... /* int reg, int val, ... */ ); 86141cc406Sopenharmony_cistatic int write_vctl (p_usb_dev_handle udev, int request, int value, 87141cc406Sopenharmony_ci int index, unsigned char byte); 88141cc406Sopenharmony_cistatic int read_vctl (p_usb_dev_handle udev, int request, int value, 89141cc406Sopenharmony_ci int index, unsigned char *byte); 90141cc406Sopenharmony_ci 91141cc406Sopenharmony_ci#ifndef BACKENDNAME 92141cc406Sopenharmony_cistatic void record (p_usb_dev_handle udev, char *fname, int bytes); 93141cc406Sopenharmony_cistatic void record_image (p_usb_dev_handle udev, char *fname, int dpi, 94141cc406Sopenharmony_ci int scanpix, int scanlines, int gray, char *head, 95141cc406Sopenharmony_ci int bpp16); 96141cc406Sopenharmony_cistatic void check_buttons (p_usb_dev_handle udev, int *scan, int *print, 97141cc406Sopenharmony_ci int *mail); 98141cc406Sopenharmony_cistatic void record_head (p_usb_dev_handle udev, char *fname, int bytes, 99141cc406Sopenharmony_ci char *header); 100141cc406Sopenharmony_ci#endif 101141cc406Sopenharmony_ci 102141cc406Sopenharmony_cistatic void poll1 (p_usb_dev_handle udev); 103141cc406Sopenharmony_cistatic void poll2 (p_usb_dev_handle udev); 104141cc406Sopenharmony_ci 105141cc406Sopenharmony_cistatic void reset_scanner (p_usb_dev_handle udev); 106141cc406Sopenharmony_ci 107141cc406Sopenharmony_ci 108141cc406Sopenharmony_cistatic void set_lightmap_white (unsigned short *map, int dpi, int color); 109141cc406Sopenharmony_ci 110141cc406Sopenharmony_cistatic void calc_lightmap (unsigned short *buff, 111141cc406Sopenharmony_ci unsigned short *storage, int index, int dpi, 112141cc406Sopenharmony_ci double gain, int offset); 113141cc406Sopenharmony_cistatic void select_pixels (unsigned short *map, int dpi, int start, int end); 114141cc406Sopenharmony_ci 115141cc406Sopenharmony_cistatic void record_mem (p_usb_dev_handle udev, unsigned char **dest, 116141cc406Sopenharmony_ci int bytes); 117141cc406Sopenharmony_cistatic void set_lamp_timer (p_usb_dev_handle udev, int timeout_in_mins); 118141cc406Sopenharmony_ci 119141cc406Sopenharmony_cistatic void set_gain_black (p_usb_dev_handle udev, 120141cc406Sopenharmony_ci int r_gain, int g_gain, int b_gain, 121141cc406Sopenharmony_ci int r_black, int g_black, int b_black); 122141cc406Sopenharmony_ci 123141cc406Sopenharmony_cistatic void idle_ab (p_usb_dev_handle udev); 124141cc406Sopenharmony_cistatic void write_regs (p_usb_dev_handle udev, int regs, int reg1, int val1, 125141cc406Sopenharmony_ci ... /* int reg, int val, ... */ ); 126141cc406Sopenharmony_cistatic int write_vctl (p_usb_dev_handle udev, int request, int value, 127141cc406Sopenharmony_ci int index, unsigned char byte); 128141cc406Sopenharmony_cistatic int read_vctl (p_usb_dev_handle udev, int request, int value, 129141cc406Sopenharmony_ci int index, unsigned char *byte); 130141cc406Sopenharmony_ci 131141cc406Sopenharmony_cistatic void download_lut8 (p_usb_dev_handle udev, int dpi, int incolor); 132141cc406Sopenharmony_ci 133141cc406Sopenharmony_cistatic void record_line (int reset, 134141cc406Sopenharmony_ci p_usb_dev_handle udev, 135141cc406Sopenharmony_ci unsigned char *storeline, 136141cc406Sopenharmony_ci int dpi, int scanpix, int gray, int bpp16, 137141cc406Sopenharmony_ci int *save_i, 138141cc406Sopenharmony_ci unsigned char **save_scan_line, 139141cc406Sopenharmony_ci unsigned char **save_dpi1200_remap, 140141cc406Sopenharmony_ci unsigned char **save_color_remap); 141141cc406Sopenharmony_ci 142141cc406Sopenharmony_ci 143141cc406Sopenharmony_cistatic void prepare_params (SM3840_Params * params); 144141cc406Sopenharmony_ci 145141cc406Sopenharmony_cistatic void fix_endian_short (unsigned short *data, int count); 146141cc406Sopenharmony_ci 147141cc406Sopenharmony_ci#define rd_timeout 10000 148141cc406Sopenharmony_ci#define wr_timeout 10000 149