| 1 | This document describes the protocol used by the Grandtek/Grandtech 980, |
| 2 | 981,and 9811 chips, supported by the pdc640 driver. |
| 3 | <p> |
| 4 | The chip is serial and USB capable, some cameras have only serial |
| 5 | connections, some have only USB connections. |
| 6 | <p> |
| 7 | This document describes the USB communication. |
| 8 | <p> |
| 9 | The USB command is at most 3 bytes long: A B C |
| 10 | and is converted into an USB control message:<br> |
| 11 | 0xc0 0x10 <A> <B> <C> <checksum> 0x40 |
| 12 | <p> |
| 13 | The checksum is calculated by:<br> |
| 14 | (A^0x34)+(B^0xcb)+(C^0x67)+0x14f; |
| 15 | <p> |
| 16 | All commands return 8 byte of control data, which contains A at |
| 17 | the start of it. |
| 18 | <p> |
| 19 | <table border=1> |
| 20 | <tr> |
| 21 | <td>Name</td> |
| 22 | <td>Structure</td> |
| 23 | <td>Arguments</td> |
| 24 | <td>Result buffer</td> |
| 25 | </tr> |
| 26 | <tr> |
| 27 | <td>READ VERSION</td> |
| 28 | <td>0x05 x x</td> |
| 29 | <td>arguments are unspecified</td> |
| 30 | <td><ol start=0> |
| 31 | <li>0x05 (echo)</li> |
| 32 | <li>hardware version</li> |
| 33 | <li>firmware version</li> |
| 34 | </ol> |
| 35 | </td> |
| 36 | </tr> |
| 37 | <tr> |
| 38 | <td>SELECT PICTURE TYPE</td> |
| 39 | <td>0x61 type 0 0</td> |
| 40 | <td>type can be: |
| 41 | <ul> |
| 42 | <li>0x20: GET CALIBRATION PARAM</li> |
| 43 | ...FIXME: Marcus fill in ... |
| 44 | </ul> |
| 45 | </td> |
| 46 | <td> |
| 47 | This is followed by a SEND DRAM command |
| 48 | and a bulkread usually, depending on type. |
| 49 | </td> |
| 50 | </tr> |
| 51 | <tr> |
| 52 | <td>NEW BAUD</td> |
| 53 | <td>0x69 baudcode</td> |
| 54 | <td>baudcode: |
| 55 | <ol start=0> |
| 56 | <li>2400</li> |
| 57 | <li>3600</li> |
| 58 | <li>4800</li> |
| 59 | <li>7200</li> |
| 60 | <li>9600</li> |
| 61 | <li>14400</li> |
| 62 | <li>19200</li> |
| 63 | <li>28800</li> |
| 64 | <li>38400</li> |
| 65 | <li>57600</li> |
| 66 | <li>76800</li> |
| 67 | <li>115200</li> |
| 68 | <li>153600</li> |
| 69 | <li>230400</li> |
| 70 | <li>307200</li> |
| 71 | <li>460800</li> |
| 72 | </ol> |
| 73 | </td> |
| 74 | <td>Set baudrate. Only useful for serial I guess.</td> |
| 75 | </tr> |
| 76 | <tr> |
| 77 | <td>AT</td> |
| 78 | <td>0x41 0x00 0x00 0x00</td> |
| 79 | <td></td> |
| 80 | <td>Appears to be some kind of ping command.</td> |
| 81 | </tr> |
| 82 | <tr> |
| 83 | <td>SELECT PICTURE</td> |
| 84 | <td>0xf6 picnum 0x00 0x00</td> |
| 85 | <td>picnum is the picture number, starting with 0.</td> |
| 86 | <td>Selects the specified picture. At offset 7 of the return buffer is the new picture.</td> |
| 87 | </tr> |
| 88 | <tr> |
| 89 | <td>SICE DOWNLOAD</td> |
| 90 | <td>0xf2 lsb msb</td> |
| 91 | <td>lsb/msb is the size? offset? of the uploaded firmware.</td> |
| 92 | <td>Function unclear.</td> |
| 93 | </tr> |
| 94 | <tr> |
| 95 | <td>QUERY STORAGE FULL</td> |
| 96 | <td>0x92</td> |
| 97 | <td></td> |
| 98 | <td> |
| 99 | Storage card is:<br> |
| 100 | 1: Full, otherwise: Empty. |
| 101 | </td> |
| 102 | </tr> |
| 103 | <tr> |
| 104 | <td>SEND PARAMETER</td> |
| 105 | <td>0xf8 lsb msb</td> |
| 106 | <td>lsb/msb is the size. This is followed by a USB bulk write.</td> |
| 107 | <td>Unclear.</td> |
| 108 | </tr> |
| 109 | <tr> |
| 110 | <td>WRITE REG</td> |
| 111 | <td>0x81 reg val</td> |
| 112 | <td>Sets register reg to value val</td> |
| 113 | <td>See pseudo function below.</td> |
| 114 | </tr> |
| 115 | <tr> |
| 116 | <td>READ REG</td> |
| 117 | <td>0xf9 reg</td> |
| 118 | <td>Reads register reg</td> |
| 119 | <td>1: return value (1 byte)</td> |
| 120 | </tr> |
| 121 | <tr> |
| 122 | <td>SIMSCANNER</td> |
| 123 | <td>0x86 0 0 0</td> |
| 124 | <td></td> |
| 125 | <td>Only for serial. Whatever it does.</td> |
| 126 | </tr> |
| 127 | <tr> |
| 128 | <td>DUAL CAPTURE</td> |
| 129 | <td>0x87 0</td> |
| 130 | <td></td> |
| 131 | <td>0: echo (0x87) 1..4: some values.</td> |
| 132 | </tr> |
| 133 | <tr> |
| 134 | <td>PUSH BUTTON</td> |
| 135 | <td>0xfd 0 0</td> |
| 136 | <td></td> |
| 137 | <td>0: echo (0xfd) 1: reply value.</td> |
| 138 | </tr> |
| 139 | <tr> |
| 140 | <td>SNAP</td> |
| 141 | <td>0x2d</td> |
| 142 | <td></td> |
| 143 | <td>0: echo (0xfd) 1: reply value.</td> |
| 144 | </tr> |
| 145 | <tr> |
| 146 | <td>WAIT EXPOSURE</td> |
| 147 | <td>0x93</td> |
| 148 | <td></td> |
| 149 | <td>0: echo (0xfd) 1: return value. Wait for 1.</td> |
| 150 | </tr> |
| 151 | <tr> |
| 152 | <td>SEND DRAM</td> |
| 153 | <td>0x15 lsb1 msb1 lsb2 msb2</td> |
| 154 | <td></td> |
| 155 | <td>Followed by bulk read. parameters are a bit unclear.</td> |
| 156 | </tr> |
| 157 | <tr> |
| 158 | <td>LOCK SNAP</td> |
| 159 | <td>0x90</td> |
| 160 | <td></td> |
| 161 | <td></td> |
| 162 | </tr> |
| 163 | <tr> |
| 164 | <td>FREE SNAP</td> |
| 165 | <td>0x91</td> |
| 166 | <td></td> |
| 167 | <td></td> |
| 168 | </tr> |
| 169 | <tr> |
| 170 | <td>RS232 INIT</td> |
| 171 | <td>0x01</td> |
| 172 | <td></td> |
| 173 | <td>Serial only I guess.</td> |
| 174 | </tr> |
| 175 | <tr> |
| 176 | <td>ERASE IMAGE</td> |
| 177 | <td>0x59 x</td> |
| 178 | <td></td> |
| 179 | <td>With x: |
| 180 | <ol start=0> |
| 181 | <li>Delete all images. |
| 182 | <li>Delete the last image. |
| 183 | </ol> |
| 184 | </td> |
| 185 | </tr> |
| 186 | <tr> |
| 187 | <td>NORMAL EXIT</td> |
| 188 | <td>0xfc</td> |
| 189 | <td></td> |
| 190 | <td></td> |
| 191 | </tr> |
| 192 | <tr> |
| 193 | <td>88 Command</td> |
| 194 | <td>0x88</td> |
| 195 | <td></td> |
| 196 | <td></td> |
| 197 | </tr> |
| 198 | </table> |
| 199 | |
| 200 | <pre> |
| 201 | |
| 202 | void |
| 203 | DOWNLOAD_DATA(type, buffer, size) { |
| 204 | SELECT_PICTURE_TYPE(type); |
| 205 | SEND_DRAM(buffer, size); |
| 206 | } |
| 207 | |
| 208 | /* Unclear why and how used */ |
| 209 | void |
| 210 | SEND_USER_COMMAND(cmd, inputbuffer, inputsize, outputbuffer, outputsize) { |
| 211 | SEND_PARAMETER(&cmd, 1); |
| 212 | if (inputbuffer && inputsize) { |
| 213 | SEND_PARAMETER(inputbuffer, inputsize); |
| 214 | } |
| 215 | if (outputbuffer && outputsize) { |
| 216 | SEND_PARAMETER(&outputsize, 4); |
| 217 | DOWNLOAD_DATA(0x21, outputbuffer, outputsize); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | void |
| 222 | WRITE_REG_Command(byte reg, byte val, int porttype) { |
| 223 | // strangely different between USB/SERIAL |
| 224 | if (porttype == USB) { |
| 225 | byte buf[2]; |
| 226 | buf[0] = reg; |
| 227 | buf[1] = val; |
| 228 | SEND_PARAMETERk(buf, 2); |
| 229 | } else { |
| 230 | call_driver(0x81, reg, val); |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | void |
| 235 | take_picture(int checkstoragefull, int locksnapflag, int waitforexpflag) { |
| 236 | byte val; |
| 237 | |
| 238 | if (checkstoragefull) QUERY_STORAGE_FULL(): |
| 239 | if (locksnapflag) LOCK_SNAP(); |
| 240 | SNAP(); |
| 241 | if (waitforexpflag) { |
| 242 | do { |
| 243 | Sleep(500); |
| 244 | WAIT_EXPOSURE(&val); |
| 245 | } while (val != 1); |
| 246 | } |
| 247 | if (locksnapflag) FREE_SNAP(); |
| 248 | } |
| 249 | </pre> |