1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
|
#ifndef __KVS40XX_H
#define __KVS40XX_H
/*
Copyright (C) 2009, Panasonic Russia Ltd.
*/
/*
Panasonic KV-S40xx USB-SCSI scanner driver.
*/
#include "../include/sane/config.h"
#include <semaphore.h>
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#undef BACKEND_NAME
#define BACKEND_NAME kvs40xx
#define DBG_ERR 1
#define DBG_WARN 2
#define DBG_MSG 3
#define DBG_INFO 4
#define DBG_DBG 5
#define PANASONIC_ID 0x04da
#define KV_S4085C 0x100c
#define KV_S4065C 0x100d
#define KV_S7075C 0x100e
#define KV_S4085CL (KV_S4085C|0x10000)
#define KV_S4085CW (KV_S4085C|0x20000)
#define KV_S4065CL (KV_S4065C|0x10000)
#define KV_S4065CW (KV_S4065C|0x20000)
#define USB 1
#define SCSI 2
#define BULK_HEADER_SIZE 12
#define MAX_READ_DATA_SIZE (0x10000-0x100)
#define BUF_SIZE MAX_READ_DATA_SIZE
#define INCORRECT_LENGTH 0xfafafafa
typedef unsigned char u8;
typedef unsigned u32;
typedef unsigned short u16;
#define SIDE_FRONT 0x00
#define SIDE_BACK 0x80
/* options */
typedef enum
{
NUM_OPTS = 0,
/* General options */
MODE_GROUP,
MODE, /* scanner modes */
RESOLUTION, /* X and Y resolution */
SOURCE,
DUPLEX, /* Duplex mode */
FEEDER_MODE, /* Feeder mode, fixed to Continuous */
LENGTHCTL, /* Length control mode */
LONG_PAPER,
MANUALFEED, /* Manual feed mode */
FEED_TIMEOUT, /* Feed timeout */
DBLFEED, /* Double feed detection mode */
DFEED_SENCE,
DFSTOP,
DFEED_L,
DFEED_C,
DFEED_R,
STAPELED_DOC, /* Detect stapled document */
FIT_TO_PAGE, /* Scanner shrinks image to fit scanned page */
/* Geometry group */
GEOMETRY_GROUP,
PAPER_SIZE, /* Paper size */
LANDSCAPE, /* true if landscape */
TL_X, /* upper left X */
TL_Y, /* upper left Y */
BR_X, /* bottom right X */
BR_Y, /* bottom right Y */
ADVANCED_GROUP,
BRIGHTNESS, /* Brightness */
CONTRAST, /* Contrast */
THRESHOLD, /* Binary threshold */
AUTOMATIC_THRESHOLD,
WHITE_LEVEL,
NOISE_REDUCTION,
INVERSE, /* Monochrome reversing */
IMAGE_EMPHASIS, /* Image emphasis */
GAMMA_CORRECTION, /* Gamma correction */
LAMP, /* Lamp -- color drop out */
RED_CHROMA,
BLUE_CHROMA,
HALFTONE_PATTERN, /* Halftone pattern */
COMPRESSION, /* JPEG Compression */
COMPRESSION_PAR, /* Compression parameter */
DESKEW,
STOP_SKEW,
CROP,
MIRROR,
BTMPOS,
TOPPOS,
/* must come last: */
NUM_OPTIONS
} KV_OPTION;
struct buf
{
u8 **buf;
volatile int head;
volatile int tail;
volatile unsigned size;
volatile int sem;
volatile SANE_Status st;
pthread_mutex_t mu;
pthread_cond_t cond;
};
struct scanner
{
char name[128];
unsigned id;
volatile int scanning;
int page;
int side;
int bus;
SANE_Int file;
SANE_Option_Descriptor opt[NUM_OPTIONS];
Option_Value val[NUM_OPTIONS];
SANE_Parameters params;
u8 *buffer;
struct buf buf[2];
u8 *data;
unsigned side_size;
unsigned read;
pthread_t thread;
};
struct window
{
u8 reserved[6];
u8 window_descriptor_block_length[2];
u8 window_identifier;
u8 reserved2;
u8 x_resolution[2];
u8 y_resolution[2];
u8 upper_left_x[4];
u8 upper_left_y[4];
u8 width[4];
u8 length[4];
u8 brightness;
u8 threshold;
u8 contrast;
u8 image_composition;
u8 bit_per_pixel;
u8 halftone_pattern[2];
u8 rif_padding; /*RIF*/
u8 bit_ordering[2];
u8 compression_type;
u8 compression_argument;
u8 reserved4[6];
u8 vendor_unique_identifier;
u8 nobuf_fstspeed_dfstop;
u8 mirror_image;
u8 image_emphasis;
u8 gamma_correction;
u8 mcd_lamp_dfeed_sens;
u8 reserved5; /*rmoir*/
u8 document_size;
u8 document_width[4];
u8 document_length[4];
u8 ahead_deskew_dfeed_scan_area_fspeed_rshad;
u8 continuous_scanning_pages;
u8 automatic_threshold_mode;
u8 automatic_separation_mode;
u8 standard_white_level_mode;
u8 b_wnr_noise_reduction;
u8 mfeed_toppos_btmpos_dsepa_hsepa_dcont_rstkr;
u8 stop_mode;
u8 red_chroma;
u8 blue_chroma;
};
struct support_info
{
/*TODO: */
unsigned char data[32];
};
void kvs40xx_init_options (struct scanner *);
SANE_Status kvs40xx_test_unit_ready (struct scanner *s);
SANE_Status kvs40xx_set_timeout (struct scanner *s, int timeout);
void kvs40xx_init_window (struct scanner *s, struct window *wnd, int wnd_id);
SANE_Status kvs40xx_set_window (struct scanner *s, int wnd_id);
SANE_Status kvs40xx_reset_window (struct scanner *s);
SANE_Status kvs40xx_read_picture_element (struct scanner *s, unsigned side,
SANE_Parameters * p);
SANE_Status read_support_info (struct scanner *s, struct support_info *inf);
SANE_Status kvs40xx_read_image_data (struct scanner *s, unsigned page,
unsigned side, void *buf,
unsigned max_size, unsigned *size);
SANE_Status kvs40xx_document_exist (struct scanner *s);
SANE_Status get_buffer_status (struct scanner *s, unsigned *data_avalible);
SANE_Status kvs40xx_scan (struct scanner *s);
SANE_Status kvs40xx_sense_handler (int fd, u_char * sense_buffer, void *arg);
SANE_Status stop_adf (struct scanner *s);
SANE_Status hopper_down (struct scanner *s);
SANE_Status inquiry (struct scanner *s, char *id);
static inline u16
swap_bytes16 (u16 x)
{
return x << 8 | x >> 8;
}
static inline u32
swap_bytes32 (u32 x)
{
return x << 24 | x >> 24 |
(x & (u32) 0x0000ff00UL) << 8 | (x & (u32) 0x00ff0000UL) >> 8;
}
static inline void
copy16 (u8 * p, u16 x)
{
memcpy (p, (u8 *) &x, sizeof (x));
}
static inline void
copy32 (u8 * p, u32 x)
{
memcpy (p, (u8 *) &x, sizeof (x));
}
#if WORDS_BIGENDIAN
static inline void
set24 (u8 * p, u32 x)
{
p[2] = x >> 16;
p[1] = x >> 8;
p[0] = x >> 0;
}
#define cpu2be16(x) (x)
#define cpu2be32(x) (x)
#define cpu2le16(x) swap_bytes16(x)
#define cpu2le32(x) swap_bytes32(x)
#define le2cpu16(x) swap_bytes16(x)
#define le2cpu32(x) swap_bytes32(x)
#define be2cpu16(x) (x)
#define be2cpu32(x) (x)
#define BIT_ORDERING 0
#elif __BYTE_ORDER == __LITTLE_ENDIAN
static inline void
set24 (u8 * p, u32 x)
{
p[0] = x >> 16;
p[1] = x >> 8;
p[2] = x >> 0;
}
#define cpu2le16(x) (x)
#define cpu2le32(x) (x)
#define cpu2be16(x) swap_bytes16(x)
#define cpu2be32(x) swap_bytes32(x)
#define le2cpu16(x) (x)
#define le2cpu32(x) (x)
#define be2cpu16(x) swap_bytes16(x)
#define be2cpu32(x) swap_bytes32(x)
#define BIT_ORDERING 1
#else
#error __BYTE_ORDER not defined
#endif
static inline u32
get24 (u8 * p)
{
u32 x = (((u32) p[0]) << 16) | (((u32) p[1]) << 8) | (((u32) p[0]) << 0);
return x;
}
#endif /*__KVS40XX_H*/
|