Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

327 lines
9.5 KiB

  1. #ifndef _PMXE3_H
  2. #define _PMXE3_H
  3. #include "devio.h"
  4. //////////////////////////////////////////////////////////////////////////////////////////////////
  5. //
  6. // Notes:
  7. //
  8. // To control the Visioneer scanners, you need to create two handles. One is the standard
  9. // CreateFile handle, (\\.\USBSCAN0), and the other is a "\2" added value. (ex. \\.\USBSCAN0\2)
  10. // All reading of values and data is done with "\\.\USBSCAN0\2", and writing values is done with
  11. // "\\.\USBSCAN0".
  12. //
  13. //////////////////////////////////////////////////////////////////////////////////////////////////
  14. //
  15. // common defines
  16. //
  17. //////////////////////////////////////////
  18. // Taken from NTDDK.H //
  19. //////////////////////////////////////////
  20. #define FILE_ANY_ACCESS 0
  21. #define FILE_READ_ACCESS ( 0x0001 ) // file & pipe
  22. #define FILE_WRITE_ACCESS ( 0x0002 ) // file & pipe
  23. #define METHOD_BUFFERED 0
  24. #define METHOD_IN_DIRECT 1
  25. #define METHOD_OUT_DIRECT 2
  26. #define METHOD_NEITHER 3
  27. #define CTL_CODE( DeviceType, Function, Method, Access ) ( \
  28. ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  29. )
  30. //////////////////////////////////////////
  31. // Taken from USBSCAN.H //
  32. //////////////////////////////////////////
  33. #define FILE_DEVICE_USB_SCAN 0x8000
  34. #define IOCTL_INDEX 0x0800
  35. #define IOCTL_GET_VERSION CTL_CODE(FILE_DEVICE_USB_SCAN,IOCTL_INDEX, METHOD_BUFFERED,FILE_ANY_ACCESS)
  36. #define IOCTL_CANCEL_IO CTL_CODE(FILE_DEVICE_USB_SCAN,IOCTL_INDEX+1, METHOD_BUFFERED,FILE_ANY_ACCESS)
  37. #define IOCTL_WAIT_ON_DEVICE_EVENT CTL_CODE(FILE_DEVICE_USB_SCAN,IOCTL_INDEX+2, METHOD_BUFFERED,FILE_ANY_ACCESS)
  38. #define IOCTL_READ_REGISTERS CTL_CODE(FILE_DEVICE_USB_SCAN,IOCTL_INDEX+3, METHOD_BUFFERED,FILE_ANY_ACCESS)
  39. #define IOCTL_WRITE_REGISTERS CTL_CODE(FILE_DEVICE_USB_SCAN,IOCTL_INDEX+4, METHOD_BUFFERED,FILE_ANY_ACCESS)
  40. #define IOCTL_GET_CHANNEL_ALIGN_RQST CTL_CODE(FILE_DEVICE_USB_SCAN,IOCTL_INDEX+5, METHOD_BUFFERED,FILE_ANY_ACCESS)
  41. #define IOCTL_GET_DEVICE_DESCRIPTOR CTL_CODE(FILE_DEVICE_USB_SCAN,IOCTL_INDEX+6, METHOD_BUFFERED,FILE_ANY_ACCESS)
  42. #define IOCTL_RESET_PIPE CTL_CODE(FILE_DEVICE_USB_SCAN,IOCTL_INDEX+7, METHOD_BUFFERED,FILE_ANY_ACCESS)
  43. #define IOCTL_GET_USB_DESCRIPTOR CTL_CODE(FILE_DEVICE_USB_SCAN,IOCTL_INDEX+8, METHOD_BUFFERED,FILE_ANY_ACCESS)
  44. #define IOCTL_SEND_USB_REQUEST CTL_CODE(FILE_DEVICE_USB_SCAN,IOCTL_INDEX+9, METHOD_BUFFERED,FILE_ANY_ACCESS)
  45. #define IOCTL_GET_PIPE_CONFIGURATION CTL_CODE(FILE_DEVICE_USB_SCAN,IOCTL_INDEX+10,METHOD_BUFFERED,FILE_ANY_ACCESS)
  46. typedef struct _IO_BLOCK {
  47. IN unsigned uOffset;
  48. IN unsigned uLength;
  49. IN OUT PUCHAR pbyData;
  50. IN unsigned uIndex;
  51. } IO_BLOCK, *PIO_BLOCK;
  52. ///////////////////////////////////////////
  53. #define IOCTL_GET_DEVICE_INFO 0x0
  54. #define IOCTL_GET_DEVICE_STATUS 0x1
  55. #define IOCTL_READ_WRITE_DATA 0x82
  56. #define IOCTL_EPP_ADDR 0x83
  57. #define IOCTL_EPP_READ 0x84
  58. #define IOCTL_EPP_WRITE 0x85
  59. #define IOCTL_SPP_STATUS 0x86
  60. #define IOCTL_SPP_CONTROL 0x87
  61. #define IOCTL_SPP_DATA_BUS 0x88
  62. #define IOCTL_GPIO_OE 0x89
  63. #define IOCTL_GPIO_READ 0x8A
  64. #define IOCTL_GPIO_WRITE 0x8B
  65. #define CARRIAGE_HOME 0x04
  66. #define MOTOR_BUSY 0x08
  67. #define CALIBRATION_STEPSIZE 103
  68. #define SCAN_STARTPOS_STEPSIZE 100
  69. #define CCD_LINEOFFSET 4
  70. #define scFirstCompositionMode 0
  71. #define scLineArt 0
  72. #define scHalftone 1
  73. #define scGrayScale 1
  74. #define scBilevelColor 3
  75. #define scFullColor 4
  76. #define scPreview 5
  77. #define sc36BitsColor 6 // 36 bits color mode, for 600 dpi scanner
  78. #define sc30BitsColor 7 // 30 bits color mode, for 300 dpi scanner
  79. #define sc12BitsGray 8
  80. #define sc12BitsLineArt 9
  81. #define sc42BitsColor 10
  82. #define sc14BitsGray 11
  83. #define sc14BitsLineArt 12
  84. #define scLastCompositionMode 13
  85. //
  86. // BYTE operation codes
  87. //
  88. #define CMD_READ 0x00
  89. #define CMD_WRITE 0x01
  90. #define CMD_WRITE_WM 0x03
  91. #define CMD_GETIMAGE 0x05
  92. #define CMD_STOPIMAGE 0x06
  93. //
  94. // Register structures
  95. //
  96. typedef struct _E3_REG0 {
  97. BYTE AsicID :8;
  98. }E3_REG0;
  99. typedef struct _E3_REG3 {
  100. BYTE SystemReset :1;
  101. BYTE FifoReset :1;
  102. BYTE EppUsb :1;
  103. BYTE WatchDog :1;
  104. BYTE SelfTest :1;
  105. BYTE ScanSpeed :3;
  106. }E3_REG3;
  107. typedef struct _E3_REG4 {
  108. BYTE AsicTest :1;
  109. BYTE YTable :1;
  110. BYTE Refresh :1;
  111. BYTE RefreshForever :1;
  112. BYTE WaitDelay :2;
  113. BYTE ScanMode :2;
  114. }E3_REG4;
  115. typedef struct _E3_REG5 {
  116. BYTE Sensor :2;
  117. BYTE Sensor_Res :2;
  118. BYTE Afe :3;
  119. BYTE Adc1210 :1;
  120. }E3_REG5;
  121. typedef struct _E3_REG6 {
  122. BYTE MotorPower :1;
  123. BYTE FullHalf :1;
  124. BYTE Operation :3;
  125. BYTE LineOffset :3;
  126. }E3_REG6;
  127. typedef struct _E3_REG12 {
  128. BYTE MotorMove :1;
  129. BYTE MotorStop :1;
  130. BYTE HomeSensor :1;
  131. BYTE FinishFlag :1;
  132. BYTE FifoEmpty :1;
  133. BYTE HwSelfTest :1;
  134. BYTE ScanStatus :1;
  135. BYTE Lamp :1;
  136. }E3_REG12;
  137. typedef struct _E3_REG13 {
  138. BYTE Sdi :1;
  139. BYTE Sdo :1;
  140. BYTE Sclk :1;
  141. BYTE Cs :1;
  142. BYTE Reserved :1;
  143. BYTE WmVsamp :3;
  144. }E3_REG13;
  145. typedef struct _E3_REG20 {
  146. BYTE AreaStart :6;
  147. BYTE Reserved :2;
  148. }E3_REG20;
  149. typedef struct _E3_REG21 {
  150. BYTE AreaStart :8;
  151. }E3_REG21;
  152. typedef struct _E3_REG22 {
  153. BYTE AreaWidth :6;
  154. BYTE Reserved :2;
  155. }E3_REG22;
  156. typedef struct _E3_REG23 {
  157. BYTE AreaWidth :8;
  158. }E3_REG23;
  159. typedef struct _E3_REG26 {
  160. BYTE Stop :4;
  161. BYTE Start :4;
  162. }E3_REG26;
  163. typedef struct _E3_REG27 {
  164. BYTE YRes :2;
  165. BYTE Reserved :1;
  166. BYTE AutoPattern :1;
  167. BYTE XRes :2;
  168. BYTE Reserved2 :1;
  169. BYTE True16Bits :1;
  170. }E3_REG27;
  171. typedef struct _E3_REG28 {
  172. BYTE XRes :8;
  173. }E3_REG28;
  174. typedef struct _E3_REG29 {
  175. BYTE YRes :8;
  176. }E3_REG29;
  177. typedef struct _E3_REG31 {
  178. BYTE Key0 :1;
  179. BYTE Key1 :1;
  180. BYTE Key2 :1;
  181. BYTE Key3 :1;
  182. BYTE Key4 :1;
  183. BYTE Key5 :1;
  184. BYTE Key6 :1;
  185. BYTE Key7 :1;
  186. }E3_REG31;
  187. class CPMXE3 {
  188. public:
  189. CPMXE3(PDEVCTRL pDeviceControl);
  190. ~CPMXE3();
  191. // overides
  192. BOOL SetXRes(LONG xRes);
  193. BOOL SetYRes(LONG yRes);
  194. BOOL SetXPos(LONG xPos);
  195. BOOL SetYPos(LONG yPos);
  196. BOOL SetXExt(LONG xExt);
  197. BOOL SetYExt(LONG yExt);
  198. BOOL SetDataType(LONG DataType);
  199. BOOL Scan();
  200. PDEVCTRL m_pDeviceControl;
  201. long m_xres;
  202. long m_yres;
  203. long m_xpos;
  204. long m_ypos;
  205. long m_xext;
  206. long m_yext;
  207. long m_datatype;
  208. BOOL RawWrite(LONG lPipeNum,BYTE *pbuffer,LONG lbuffersize,LONG lTimeout);
  209. BOOL RawRead(LONG lPipeNum,BYTE *pbuffer,LONG lbuffersize,LONG *plbytesread,LONG lTimeout);
  210. //
  211. // device specific helpers
  212. //
  213. long m_scanmode; // pPrimax specific member
  214. VOID InitializeRegisters();
  215. BOOL WriteRegister(INT RegisterNumber, BYTE Value);
  216. BOOL WriteRegisterEx(INT RegisterNumber, BYTE Value);
  217. BOOL ReadRegister(INT RegisterNumber, BYTE *pValue);
  218. BOOL ReadRegisterEx(INT RegisterNumber, BYTE *pValue);
  219. BOOL WriteStopImageRegister();
  220. INT GetScanSpeed();
  221. BOOL Lamp(BOOL bON);
  222. BOOL IsCarriageHOME();
  223. BOOL IsMotorBusy();
  224. BOOL IsLampON();
  225. BOOL HomeCarriage();
  226. BOOL StopMode();
  227. BOOL SetMotorSpeed(INT TriggerPeriod, INT ScanSpeed);
  228. BOOL MoveCarriage(BOOL bForward, INT Steps);
  229. BOOL Motor(BOOL bON);
  230. BOOL StopScan();
  231. BOOL GetButtonStatus(PBYTE pButtons);
  232. BOOL ClearButtonPress();
  233. BOOL WakeupScanner();
  234. BOOL SleepScanner();
  235. BOOL ResetFIFO();
  236. BOOL InitADC();
  237. BOOL StartScan();
  238. VOID DebugDumpRegisters();
  239. VOID Trace(LPCTSTR format,...);
  240. BOOL SetXandYResolution();
  241. BOOL SetScanWindow();
  242. //
  243. // simple image processing
  244. //
  245. VOID GrayScaleToThreshold(LPBYTE lpSrc, LPBYTE lpDst, LONG RowBytes);
  246. //
  247. // internal registers, for device communication
  248. //
  249. BYTE Register0; // -- Asic ID
  250. BYTE Register3; // -- reset (System,FIFO), selftest, scan speed, eppusb, watchdog?
  251. BYTE Register4; // -- AsicTest, YTable, refresh DRAM, waitdelay, and scanmode
  252. BYTE Register5; // -- Asic description, Sensor type, sensor resolution, Afe, Adc1210
  253. BYTE Register6; // -- Motor power,motor operations,line offsets
  254. BYTE Register7; // -- carriage step high byte
  255. BYTE Register8; // -- carriage step low byte
  256. BYTE Register9; // -- carriage backstep
  257. BYTE Register10; // -- trigger period high byte
  258. BYTE Register11; // -- trigger period low byte
  259. BYTE Register12; // -- Motor (move/stop), selftest, Lamp, FIFO status, and Scan status
  260. BYTE Register13; // -- Sdi,Sdo,Sclk,Cs,WmVSamp
  261. BYTE Register20; // -- scan area start high byte
  262. BYTE Register21; // -- scan area start low byte
  263. BYTE Register22; // -- scan area width high byte
  264. BYTE Register23; // -- scan area width low byte
  265. BYTE Register25; // -- ?
  266. BYTE Register26; // --
  267. BYTE Register27; // -- (X,Y Resolution setting high byte(use regsiters(27,28)))
  268. BYTE Register28; // -- X Resolution (low byte)
  269. BYTE Register29; // -- Y Resolution (low byte)
  270. BYTE Register31; // -- Button press information
  271. protected:
  272. };
  273. #endif