1 /* sane - Scanner Access Now Easy. 2 3 Copyright (C) 2007-2012 stef.dev@free.fr 4 5 This file is part of the SANE package. 6 7 This program is free software; you can redistribute it and/or 8 modify it under the terms of the GNU General Public License as 9 published by the Free Software Foundation; either version 2 of the 10 License, or (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, but 13 WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program. If not, see <https://www.gnu.org/licenses/>. 19 20 As a special exception, the authors of SANE give permission for 21 additional uses of the libraries contained in this release of SANE. 22 23 The exception is that, if you link a SANE library with other files 24 to produce an executable, this does not by itself cause the 25 resulting executable to be covered by the GNU General Public 26 License. Your use of that executable is in no way restricted on 27 account of linking the SANE library code into it. 28 29 This exception does not, however, invalidate any other reasons why 30 the executable file might be covered by the GNU General Public 31 License. 32 33 If you submit changes to SANE to the maintainers to be included in 34 a subsequent release, you agree by submitting the changes that 35 those changes may be distributed with this exception intact. 36 37 If you write modifications of your own for SANE, it is your choice 38 whether to permit this exception to apply to your modifications. 39 If you do not wish that, delete this exception notice. 40 */ 41 42 #ifndef RTS88XX_LIB_H 43 #define RTS88XX_LIB_H 44 #include "../include/sane/sane.h" 45 #include "../include/sane/sanei_usb.h" 46 #include <unistd.h> 47 #include <string.h> 48 49 /* TODO put his in a place where it can be reused */ 50 51 #define DBG_error0 0 /* errors/warnings printed even with debuglevel 0 */ 52 #define DBG_error 1 /* fatal errors */ 53 #define DBG_init 2 /* initialization and scanning time messages */ 54 #define DBG_warn 3 /* warnings and non-fatal errors */ 55 #define DBG_info 4 /* informational messages */ 56 #define DBG_proc 5 /* starting/finishing functions */ 57 #define DBG_io 6 /* io functions */ 58 #define DBG_io2 7 /* io functions that are called very often */ 59 #define DBG_data 8 /* log data sent and received */ 60 61 /* 62 * defines for registers name 63 */ 64 #define CONTROL_REG 0xb3 65 #define CONTROLER_REG 0x1d 66 67 /* geometry registers */ 68 #define START_LINE 0x60 69 #define END_LINE 0x62 70 #define START_PIXEL 0x66 71 #define END_PIXEL 0x6c 72 73 #define RTS88XX_MAX_XFER_SIZE 0xFFC0 74 75 #define LOBYTE(x) ((uint8_t)((x) & 0xFF)) 76 #define HIBYTE(x) ((uint8_t)((x) >> 8)) 77 78 /* this function init the rts88xx library */ 79 void sanei_rts88xx_lib_init (void); 80 SANE_Bool sanei_rts88xx_is_color (SANE_Byte * regs); 81 82 void sanei_rts88xx_set_gray_scan (SANE_Byte * regs); 83 void sanei_rts88xx_set_color_scan (SANE_Byte * regs); 84 void sanei_rts88xx_set_offset (SANE_Byte * regs, SANE_Byte red, 85 SANE_Byte green, SANE_Byte blue); 86 void sanei_rts88xx_set_gain (SANE_Byte * regs, SANE_Byte red, SANE_Byte green, 87 SANE_Byte blue); 88 void sanei_rts88xx_set_scan_frequency (SANE_Byte * regs, int frequency); 89 90 /* 91 * set scan area 92 */ 93 void sanei_rts88xx_set_scan_area (SANE_Byte * reg, SANE_Int ystart, 94 SANE_Int yend, SANE_Int xstart, 95 SANE_Int xend); 96 97 /* 98 * read one register at given index 99 */ 100 SANE_Status sanei_rts88xx_read_reg (SANE_Int devnum, SANE_Int index, 101 SANE_Byte * reg); 102 103 /* 104 * read scanned data from scanner up to the size given. The actual length read is returned. 105 */ 106 SANE_Status sanei_rts88xx_read_data (SANE_Int devnum, SANE_Word * length, 107 unsigned char *dest); 108 109 /* 110 * write one register at given index 111 */ 112 SANE_Status sanei_rts88xx_write_reg (SANE_Int devnum, SANE_Int index, 113 SANE_Byte * reg); 114 115 /* 116 * write length consecutive registers, starting at index 117 * register 0xb3 is never wrote in bulk register write, so we split 118 * write if it belongs to the register set sent 119 */ 120 SANE_Status sanei_rts88xx_write_regs (SANE_Int devnum, SANE_Int start, 121 SANE_Byte * source, SANE_Int length); 122 123 /* read several registers starting at the given index */ 124 SANE_Status sanei_rts88xx_read_regs (SANE_Int devnum, SANE_Int start, 125 SANE_Byte * dest, SANE_Int length); 126 127 /* 128 * get status by reading registers 0x10 and 0x11 129 */ 130 SANE_Status sanei_rts88xx_get_status (SANE_Int devnum, SANE_Byte * regs); 131 /* 132 * set status by writing registers 0x10 and 0x11 133 */ 134 SANE_Status sanei_rts88xx_set_status (SANE_Int devnum, SANE_Byte * regs, 135 SANE_Byte reg10, SANE_Byte reg11); 136 137 /* 138 * get lamp status by reading registers 0x84 to 0x8d 139 */ 140 SANE_Status sanei_rts88xx_get_lamp_status (SANE_Int devnum, SANE_Byte * regs); 141 142 /* reset lamp */ 143 SANE_Status sanei_rts88xx_reset_lamp (SANE_Int devnum, SANE_Byte * regs); 144 145 /* get lcd panel status */ 146 SANE_Status sanei_rts88xx_get_lcd (SANE_Int devnum, SANE_Byte * regs); 147 148 /* 149 * write to special control register CONTROL_REG=0xb3 150 */ 151 SANE_Status sanei_rts88xx_write_control (SANE_Int devnum, SANE_Byte value); 152 153 /* 154 * send the cancel control sequence 155 */ 156 SANE_Status sanei_rts88xx_cancel (SANE_Int devnum); 157 158 /* 159 * read available data count from scanner 160 */ 161 SANE_Status sanei_rts88xx_data_count (SANE_Int devnum, SANE_Word * count); 162 163 /* 164 * wait for scanned data to be available, if busy is true, check is scanner is busy 165 * while waiting. The number of data bytes of available data is returned in 'count'. 166 */ 167 SANE_Status sanei_rts88xx_wait_data (SANE_Int devnum, SANE_Bool busy, 168 SANE_Word * count); 169 170 /* 171 * write the given number of bytes pointed by value into memory 172 */ 173 SANE_Status sanei_rts88xx_write_mem (SANE_Int devnum, SANE_Int length, 174 SANE_Int extra, SANE_Byte * value); 175 176 /* 177 * set memory with the given data 178 */ 179 SANE_Status sanei_rts88xx_set_mem (SANE_Int devnum, SANE_Byte ctrl1, 180 SANE_Byte ctrl2, SANE_Int length, 181 SANE_Byte * value); 182 183 /* 184 * read the given number of bytes from memory into buffer 185 */ 186 SANE_Status sanei_rts88xx_read_mem (SANE_Int devnum, SANE_Int length, 187 SANE_Byte * value); 188 189 /* 190 * get memory 191 */ 192 SANE_Status sanei_rts88xx_get_mem (SANE_Int devnum, SANE_Byte ctrl1, 193 SANE_Byte ctrl2, SANE_Int length, 194 SANE_Byte * value); 195 196 /* 197 * write to the nvram controller 198 */ 199 SANE_Status sanei_rts88xx_nvram_ctrl (SANE_Int devnum, SANE_Int length, 200 SANE_Byte * value); 201 202 /* 203 * setup nvram 204 */ 205 SANE_Status sanei_rts88xx_setup_nvram (SANE_Int devnum, SANE_Int length, 206 SANE_Byte * value); 207 208 209 /* does a simple scan, putting data in image */ 210 /* SANE_Status sanei_rts88xx_simple_scan (SANE_Int devnum, SANE_Byte * regs, int regcount, SANE_Word size, unsigned char *image); */ 211 #endif /* not RTS88XX_LIB_H */ 212