なんとなく興味があったのでついでにフラッシュ・プログラマーも作って見た。Windows版を作るにはVisual-Studioで開発したほうが簡単なんだけど使うと後々面倒なことになるだけなのでEclipse-CDT+MinGW64で開発している。リンカー(ld.exe)の不具合?なのかDLLの一部のシンボルがリンクエラーになってしまうので動的ロードするための余計なコードを書くハメになってしまったが、それはともかくEclipseとの連携を考慮してコマンドライン・ツールとして作成。って、いうとなんだか聞こえはいいがGUIが大の苦手なだけである。(-_-;)
プログラムはFTDIチップのCBUSピンを制御しデバイスのブートローダーを起動し通信を行う仕組みでファームウェアの読み書きに対応している。基本機能的にはモノワイヤレス社のTWE-Programmerと同じものだがブートローダーにはコードをRAMに転送し実行する機能もあるようだ。試してないけど。
ちなみにftd2.h/ftd2.cppは汎用的に使えるFTDIライブラリだ。CBUSピンはArduinoのようにpinMode/digitalWrite/digitalReadで制御できるので使いやすいかも。4ピンしかないけどね。(-_-;)
【コマンドライン(-h)】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
Flash Programmer Utility for NXP JN516X, Version 1.1 Copyright(c) 2022-2024 Sasapea's Lab. All right reserved. Usage: JN516X-PROG [options] options: -s ... FTD2XX Port Scan -p portname ... FTD2XX Serial Number for Open -b ... baudrate (38400,115200,500K,*1M) -d ... device information -w filename ... write device (.bin) -r filename ... read device (.bin) -f sector ... start sector (*0 - n) -h ... this help |
【ポートスキャン(-s)】
1 2 3 4 5 6 7 8 |
Flash Programmer Utility for NXP JN516X, Version 1.1 Copyright(c) 2022-2024 Sasapea's Lab. All right reserved. Device Count: 4 Device-0: -- Open failure -- Device-1: Port: Com8, Serial: MW2Z8X7S, Description: TWE-Lite-R Device-2: Port: Com7, Serial: MW1DKWWS, Description: TWE-Lite-R Device-3: Port: Com12, Serial: MW67J6YY, Description: MONOSTICK |
【デバイス情報(-d)】
1 2 3 4 5 6 7 |
Flash Programmer Utility for NXP JN516X, Version 1.1 Copyright(c) 2022-2024 Sasapea's Lab. All right reserved. Program mode: 1M bps BootLoader Version: 0x02000B00 Flash ID: 0xCCEE, Type: 8 Chip ID: 0x0100B686, Name: JN5169, Flash: 512 Kb, Ram: 32 Kb, Type: 11 |
【デバイス読み込み(-r)】
1 2 3 4 5 6 7 |
Flash Programmer Utility for NXP JN516X, Version 1.1 Copyright(c) 2022-2024 Sasapea's Lab. All right reserved. Program mode: 1M bps Read Device [JN5169] -> "firmware.bin" Progress: 524288/524288 Success. |
【デバイス書き込み(-w)】
1 2 3 4 5 6 7 |
Flash Programmer Utility for NXP JN516X, Version 1.1 Copyright(c) 2022-2024 Sasapea's Lab. All right reserved. Program mode: 1M bps Write Device [JN5169] <- "firmware.bin" Progress: 99968/ 99968 Success. |
【修正履歴】
2024-01-29
ChipIDをJN516X-PROG.chipidファイルに記録&参照するように改良。chipidファイルによりChipIDの誤判定を修正することが可能となる。
2024-01-28
チップ・レビジョンによりデバイスの誤判定が起こるため改良。
2023-11-19
JN5168のChipIDの誤りとJN5164のChipIDが複数あるためにJN5164をJN5168と誤判定してしまうことがあったためJN5168はJN5164として判定するように対策。
2022-11-07
デバイス情報(-d)としてMAC Address表示を追加。
2022-06-01
JN5164で作成したプログラムが書き込みできなくて調べてみたらチップがJN5168だった。JN5161/JN5164/JN5168は同一パイナリーで動作するのでJN5161/JN5164/JN5168については同一チップと見なすように変更した。
2022-05-15
あちこち大幅改修。まずポート指定はシリアル番号指定が必要であったが面倒だったので-sコマンドでの何番目かを数字指定できるように変更した。-wコマンドはセクター単位の消去に変更したので全体を消去する-eコマンドを新たに追加。それと-rコマンドは有効なセクターを検索するようにしたので-fオプションが検索を開始するセクター指定となり複数のプログラムが書き込まれているときでもそれぞれを読み込むことが可能となるようにしてみた。あと物がないから試せないけどJN5179にも対応してみたつもり。
【プロジェクト一式(Eclipse)】
JN516X-PROG
【プログラム】
ftd2xx.hのためにコンパイルには次のシンボル定義が必要となる。
#define _WIN32
#define FTD2XX_STATIC
※モノワイヤレス社のTWELITE-R(2)/MONOSTICKのHW仕様でのみ動作することに注意。
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 |
/* main.cpp - Flash Programmer Utility for NXP JN516x Series Copyright (c) 2022-2024 Sasapea's Lab. All right reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <stdio.h> #include <stdint.h> #include <stdbool.h> #include <string.h> #include <limits.h> #include "jn516x_prog.h" class Device : public JN516x_PROG { public: Device(void) {} virtual ~Device(void) {} protected: void programStart(const char *chipname, const char *filename, bool program) override { if (program) printf("Write Device [%s] <- \"%s\"\n", chipname, filename); else printf("Read Device [%s] -> \"%s\"\n", chipname, filename); } void programProgress(size_t size, size_t processed) override { printf("Progress: %6llu/%6llu\r", processed, size); } void programEnd(STATUS status) override { printf("\n"); if (status != STATUS_OK) printf("Error: [0x%02X] ", status); printf("%s\n", errstr(status)); } }; static Device device; void printMAC(const char *message, bool customer) { uint8_t buf[8]; device.macAddress(buf, customer); printf("%s", message); for (int i = 0; i < 8; ++i) { if (i) printf(":"); printf("%02X", buf[i]); } printf("\n"); } void chipInfo(void) { Device::CHIPID chipid; Device::VERSION chipver; Device::FLASHID flashid; uint32_t bootver; device.chipID(chipid); chipver = device.chipVersion(chipid); device.flashID(flashid); device.bootVersion(bootver); printf("BootLoader Version: 0x%08X\n", bootver); printf("Flash ID: 0x%04X, Type: %u\n", flashid, device.flashType(flashid)); printf("Chip ID: 0x%08X, Name: %s", chipid, device.chipName(chipver)); printf(", Flash: %u Kb, Ram: %u Kb, Type: %u\n", device.chipFlashSize(chipver) / 1024, device.chipRamSize(chipver) / 1024, device.chipType(chipver)); printMAC("Default MAC Address: ", false); printMAC("Customer MAC Address: ", true ); } void portScan(void) { int count = device.getDeviceCount(); printf("Device Count: %d\n", count); for (int i = 0; i < count; ++i) { char buf[128]; printf("Device-%d: ", i); if (device.begin(i)) { printf("Port: Com%u", device.getComPortNumber()); device.end(); device.getDeviceSerial(i, buf); printf(", Serial: %s", buf); device.getDeviceDescription(i, buf); printf(", Description: %s", buf); } else printf("-- Open failure --"); printf("\n"); } } void usage(bool help) { printf("Flash Programmer Utility for NXP JN516X, Version 1.1\n"); printf("Copyright(c) 2022-2024 Sasapea's Lab. All right reserved.\n"); printf("\n"); if (help) { printf("Usage: JN516X-PROG [options]\n"); printf("\n"); printf(" options:\n"); printf(" -s ... FTD2XX Port Scan\n"); printf(" -p portname ... FTD2XX Serial Number for Open\n"); printf(" -b ... baudrate (38400,115200,500K,*1M)\n"); printf(" -d ... device information\n"); printf(" -e ... erase device\n"); printf(" -w filename ... write device (.bin)\n"); printf(" -r filename ... read device (.bin)\n"); printf(" -f sector ... start sector (*0 - n)\n"); printf(" -h ... this help\n"); printf("\n"); } } int main(int argc, char **argv) { bool help = false; bool scan = false; bool info = false; bool erase = false; const char *portname = ""; const char *firmware = ""; const char *savefile = ""; Device::SPEED speed = Device::SPEED_1M; uint8_t sector = 0; for (int i = 1; i < argc; ) { char *p = argv[i++]; if (*p == '-') { switch (*++p) { case 'h': help = true; break; case 's': scan = true; break; case 'p': if (i < argc) portname = argv[i++]; break; case 'w': if (i < argc) firmware = argv[i++]; break; case 'r': if (i < argc) savefile = argv[i++]; break; case 'b': if (i < argc) { switch (strtoul(argv[i++], &p, 10)) { case 38400: speed = Device::SPEED_38400; break; case 115200: speed = Device::SPEED_115200; break; case 500: if (toupper(*p) != 'K') break; /* Fall Through */ case 500000: speed = Device::SPEED_500K; break; case 1: if (toupper(*p) != 'M') break; /* Fall Through */ case 1000000: speed = Device::SPEED_1M; break; } } break; case 'f': if (i < argc) sector = atoi(argv[i++]); break; case 'd': info = true; break; case 'e': erase = true; break; default: help = true; break; } } else help = true; } if (help) usage(true); else if (device.status() != FT_OK) { usage(false); printf("FTD2XX Library Not Found."); } else if (scan) { usage(false); portScan(); } else if (device.begin(portname)) { static char path[PATH_MAX]; snprintf(path, sizeof(path), "%s", argv[0]); char *p = strrchr(path, '.'); if (!p) p = path + strlen(path); snprintf(p, sizeof(path) - strlen(path), "%s", ".chipid"); device.setChipIDPath(path); Device::STATUS rv = device.program(speed); if (rv == Device::STATUS_OK) { usage(false); switch (speed) { case Device::SPEED_1M: printf("Program Mode: 1M bps\n"); break; case Device::SPEED_500K: printf("Program Mode: 500K bps\n"); break; default: printf("Program Mode: %d bps\n", speed); break; } if (info) chipInfo(); if (*savefile) device.readDevice(savefile, sector); if (erase) device.eraseDevice(); if (*firmware) device.writeDevice(firmware, sector); device.restart(); } else printf("Program Mode Failed = 0x%02X\n", rv); device.end(); } else { usage(false); printf("Port Open Failed: \"%s\"\n", portname); } return 0; } |
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 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 |
/* jn516x_prog.h - Flash Programmer Library for NXP JN516x Series Copyright (c) 2022-2024 Sasapea's Lab. All right reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #pragma once #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include "ftd2.h" #include "jn516x.h" #define JN516X_MAX_DATA_SIZE 128 #define OTA_BOOT_FIRMWARE "-OTA-BOOT.bin" class JN516x_PROG : public JN516x, public FTD2 { public: typedef enum { /* boot loader */ STATUS_OK = 0, STATUS_NOT_SUPPORTED = 0xFF, STATUS_WRITE_FAIL = 0xFE, STATUS_INVALID_RESPONSE = 0xFD, STATUS_CRC_ERROR = 0xFC, STATUS_ASSERT_FAIL = 0xFB, STATUS_USER_INTERRUPT = 0xFA, STATUS_READ_FAIL = 0xF9, STATUS_TST_ERROR = 0xF8, STATUS_AUTH_ERROR = 0xF7, STATUS_NO_RESPONSE = 0xF6, /* orignal */ STATUS_FILE_WRITE_FAIL = 0xE3, STATUS_FILE_READ_FAIL = 0xE2, STATUS_FILE_NOT_FOUND = 0xE1, STATUS_INVALID_VERSION = 0xE0, } STATUS; typedef struct __attribute__((packed)) { uint8_t magicNumber[12]; uint8_t configuration; uint8_t status; uint16_t applicationID; } tsBIR; typedef struct __attribute__((packed)) { tsBIR sBIR; // 16-byte Boot Image Record uint8_t encryption[14]; // Encryption Initialisation Vector (ignored if unencrypted) uint16_t configuration; // 16-bit Software Configuration Options uint32_t imageSize; // 32-bit Length of Binary Image in bytes uint32_t dataStart; // 32-bit .data section Flash start address uint16_t dataAddress; // 16-bit .data section load address in RAM (word aligned) uint16_t dataLength; // 16-bit .data section length in 32-bit words uint16_t bssStart; // 16 bit .bss section start address in RAM (word aligned) uint16_t bssLength; // 16-bit .bss section length in 32-bit words uint32_t warmStart; // 32-bit wake-up entry point (word aligned) – warm start uint32_t coldStart; // 32-bit reset entry point (word aligned) – cold start } tsFlashHeader; typedef struct __attribute__((packed)) { uint32_t version; // version tsBIR sBIR; // 16-byte Boot Image Record uint8_t encryption[14]; // Encryption Initialisation Vector (ignored if unencrypted) uint16_t configuration; // 16-bit Software Configuration Options uint32_t imageSize; // 32-bit Length of Binary Image in bytes uint32_t dataStart; // 32-bit .data section Flash start address uint16_t dataAddress; // 16-bit .data section load address in RAM (word aligned) uint16_t dataLength; // 16-bit .data section length in 32-bit words uint16_t bssStart; // 16 bit .bss section start address in RAM (word aligned) uint16_t bssLength; // 16-bit .bss section length in 32-bit words uint32_t warmStart; // 32-bit wake-up entry point (word aligned) – warm start uint32_t coldStart; // 32-bit reset entry point (word aligned) – cold start } tsFlashHeader_JN5179; JN516x_PROG(void) : _debug(false) { } virtual ~JN516x_PROG(void) { } static const char *errstr(STATUS status) { switch (status) { case STATUS_OK: return "Success"; /* boot loader */ case STATUS_NOT_SUPPORTED: return "not supported"; case STATUS_WRITE_FAIL: return "write failed"; case STATUS_INVALID_RESPONSE: return "invalid responce"; case STATUS_CRC_ERROR: return "CRC error"; case STATUS_ASSERT_FAIL: return "assert failed"; case STATUS_USER_INTERRUPT: return "user interrupt"; case STATUS_READ_FAIL: return "read failed"; case STATUS_TST_ERROR: return "test error"; case STATUS_AUTH_ERROR: return "auth error"; case STATUS_NO_RESPONSE: return "no responce"; /* orignal */ case STATUS_FILE_WRITE_FAIL: return "file write failed"; case STATUS_FILE_READ_FAIL: return "file read failed"; case STATUS_FILE_NOT_FOUND: return "file not found"; case STATUS_INVALID_VERSION: return "invalid version"; } return "unknown error"; } void setChipIDPath(const char *path) { _chipidpath = path; } VERSION chipVersion(CHIPID id) { char keyname[16], chipver[16]; if (_chipidpath.length()) { snprintf(keyname, sizeof(keyname), "%08X", id); if (GetPrivateProfileString("chipid", keyname, "", chipver, sizeof(chipver), _chipidpath.c_str())) return (VERSION)strtoul(chipver, nullptr, 16); } VERSION version = JN516x::chipVersion(id); unsigned char b; switch (version) { case VERSION_JN517x: _debug = false; if (readFlash(160 * 1024 - 1, &b, sizeof(b)) != STATUS_OK) version = (VERSION)0; else if (readFlash(256 * 1024 - 1, &b, sizeof(b)) != STATUS_OK) version = VERSION_JN5174; else if (readFlash(512 * 1024 - 1, &b, sizeof(b)) != STATUS_OK) version = VERSION_JN5178; else { version = VERSION_JN5179; break; } /* restart boot mode */ program(_speed, _timeout); break; case VERSION_JN516x: _debug = false; if (readFlash( 64 * 1024 - 1, &b, sizeof(b)) != STATUS_OK) version = (VERSION)0; else if (readFlash(160 * 1024 - 1, &b, sizeof(b)) != STATUS_OK) version = VERSION_JN5161; else if (readFlash(256 * 1024 - 1, &b, sizeof(b)) != STATUS_OK) version = VERSION_JN5164; else { version = VERSION_JN5168; break; } /* restart boot mode */ program(_speed, _timeout); break; default: break; } if (_chipidpath.length() && version) { snprintf(chipver, sizeof(chipver), "%08X", version); WritePrivateProfileString("chipid", keyname, chipver, _chipidpath.c_str()); } return version; } STATUS eraseDevice(void) { CHIPID chipid; STATUS rv = chipID(chipid); if (rv == STATUS_OK) { FLASHID flashid; if ((rv = flashID(flashid)) == STATUS_OK) { if ((rv = selectFlash(flashType(flashid))) == STATUS_OK) { if ((rv = writeSR(0)) == STATUS_OK) rv = eraseFlash(); } } } return rv; } STATUS writeDevice(const char *filename, uint8_t u8Sector = 0) { CHIPID chipid; VERSION chipver; STATUS rv = chipID(chipid); chipver = chipVersion(chipid); programStart(chipName(chipver), filename, true); if (rv == STATUS_OK) { rv = STATUS_FILE_NOT_FOUND; FILE *fp = fopen(filename, "rb"); if (fp) { VERSION filever; if ((rv = fileVersion(filever, fp)) == STATUS_OK) { if (chipType(filever) != chipType(chipver)) rv = STATUS_INVALID_VERSION; else { FLASHID flashid; if ((rv = flashID(flashid)) == STATUS_OK) { if ((rv = selectFlash(flashType(flashid))) == STATUS_OK) { if ((rv = writeSR(0)) == STATUS_OK) { uint8_t data[JN516X_MAX_DATA_SIZE]; size_t fpos = (chipver == VERSION_JN5179 ? 0 : ftell(fp)); fseek(fp, 0, SEEK_END); size_t size = ftell(fp) - fpos; if (strstr(filename, OTA_BOOT_FIRMWARE)) u8Sector = chipFlashSectors(chipver) - 1; size_t offs = FLASH_SECTOR_OFFSET(u8Sector); size_t addr = 0; size_t prog = 0; uint8_t erase = 0xFF; fseek(fp, fpos, SEEK_SET); while (1) { ssize_t n = fread(data, 1, sizeof(data), fp); if (n <= 0) break; u8Sector = (addr + offs) >> 15; if (erase != u8Sector) { erase = u8Sector; if ((rv = eraseFlash(u8Sector))) break; } if ((rv = programFlash(addr + offs, data, n)) != STATUS_OK) break; addr += n; if (prog != (addr >> 10)) { prog = (addr >> 10); programProgress(size, addr); } } programProgress(size, addr); } } } } } fclose(fp); } } programEnd(rv); return rv; } STATUS readDevice(const char *filename, uint8_t u8Sector = 0) { CHIPID chipid; VERSION chipver; STATUS rv = chipID(chipid); chipver = chipVersion(chipid); programStart(chipName(chipver), filename, false); if (rv == STATUS_OK) { rv = STATUS_FILE_NOT_FOUND; FILE *fp = fopen(filename, "wb"); if (fp) { FLASHID flashid; if ((rv = flashID(flashid)) == STATUS_OK) { if ((rv = selectFlash(flashType(flashid))) == STATUS_OK) { if ((rv = writeSR(0)) == STATUS_OK) { /* Search Flash Header */ size_t offs = FLASH_SECTOR_OFFSET(u8Sector); size_t size = chipFlashSize(chipver); bool boot; while (offs < size) { boot = false; if (chipver == VERSION_JN5179) { tsFlashHeader_JN5179 sFlashHeader; if ((rv = readFlash(offs, (uint8_t *)&sFlashHeader, sizeof(sFlashHeader))) != STATUS_OK) break; boot |= memcmp(sFlashHeader.sBIR.magicNumber, JN516x::MAGICNUMBER, sizeof(JN516x::MAGICNUMBER)) == 0; boot |= memcmp(sFlashHeader.sBIR.magicNumber, JN516x::MAGICNUMBER_JN5179, sizeof(JN516x::MAGICNUMBER)) == 0; boot &= sFlashHeader.sBIR.status == 0x01; boot &= sFlashHeader.sBIR.applicationID == 0x0000; if (boot) { size = read32((uint8_t *)&sFlashHeader.imageSize); break; } } else { tsFlashHeader sFlashHeader; if ((rv = readFlash(offs, (uint8_t *)&sFlashHeader, sizeof(sFlashHeader))) != STATUS_OK) break; boot |= memcmp(sFlashHeader.sBIR.magicNumber, JN516x::MAGICNUMBER, sizeof(JN516x::MAGICNUMBER)) == 0; boot &= sFlashHeader.sBIR.status == 0x01; boot &= sFlashHeader.sBIR.applicationID == 0x0000; if (boot) { size = read32((uint8_t *)&sFlashHeader.imageSize); break; } } offs += 0x8000U; } if (boot) { uint8_t data[JN516X_MAX_DATA_SIZE]; if (chipver != VERSION_JN5179) { write32(data, chipver, false); if (fwrite(data, 1, 4, fp) != 4) rv = STATUS_FILE_WRITE_FAIL; } if (rv == STATUS_OK) { size_t addr = 0; size_t prog = 0; while (addr < size) { size_t n = __min(size - addr, sizeof(data)); if ((rv = readFlash(addr + offs, data, n)) != STATUS_OK) break; if (fwrite(data, 1, n, fp) != n) { rv = STATUS_FILE_WRITE_FAIL; break; // write error } addr += n; if (prog != (addr >> 10)) { prog = (addr >> 10); programProgress(size, addr); } } programProgress(size, addr); } } } } } fclose(fp); } } programEnd(rv); return rv; } STATUS program(SPEED speed = SPEED_1M, uint32_t timeout = 1000) { // setup uart init(SPEED_38400, MODE_8N1, FLOW_RTS_CTS, timeout); // setup cbus digitalWrite(PIN_PROG , HIGH); digitalWrite(PIN_RESET, HIGH); pinMode(PIN_PROG , GPIO_OUTPUT); pinMode(PIN_RESET, GPIO_OUTPUT); // start program mode digitalWrite(PIN_PROG, LOW); restart(true); Sleep::sleep(300); digitalWrite(PIN_PROG, HIGH); // change baudrate STATUS status = changeBaudrate(speed); if (status == STATUS_OK) { _debug = true; _speed = speed; _timeout = timeout; } return status; } STATUS restart(bool hardware = true) { if (hardware) { digitalWrite(PIN_RESET, LOW); digitalWrite(PIN_RESET, HIGH); return STATUS_OK; } return protocol(MSGTYPE_SET_RESET_REQUEST); } STATUS changeBaudrate(SPEED speed) { uint8_t arg; switch (speed) { case SPEED_1M : arg = 1; break; case SPEED_500K : arg = 2; break; case SPEED_115200: arg = 9; break; case SPEED_38400 : arg = 26; break; default: return STATUS_NOT_SUPPORTED; } STATUS rv = protocol(MSGTYPE_CHANGE_BAUDRATE_REQUEST, &arg, sizeof(arg)); if (rv == STATUS_OK) baudrate(speed); return rv; } STATUS eraseFlash(void) { return protocol(MSGTYPE_FLASH_ERASE_REQUEST); } STATUS eraseFlash(uint8_t sector) { return protocol(MSGTYPE_SECTOR_ERASE_REQUEST, §or, sizeof(sector)); } STATUS programFlash(uint32_t addr, uint8_t *buf, uint16_t len) { uint8_t data[JN516X_MAX_DATA_SIZE + 4]; if (len > JN516X_MAX_DATA_SIZE) len = JN516X_MAX_DATA_SIZE; write32(data + 0, addr); memcpy(data + 4, buf, len); return protocol(MSGTYPE_FLASH_PROGRAM_REQUEST, data, len + 4); } STATUS readFlash(uint32_t addr, uint8_t *buf, uint16_t len) { if (len > JN516X_MAX_DATA_SIZE) len = JN516X_MAX_DATA_SIZE; uint8_t data[6]; write32(data + 0, addr); write16(data + 4, len); STATUS rv = protocol(MSGTYPE_FLASH_READ_REQUEST, data, sizeof(data)); if (rv == STATUS_OK) memcpy(buf, _packet + 3, len); return rv; } STATUS selectFlash(FLASH type, uint32_t jump = 0) { uint8_t data[5]; data[0] = (uint8_t)type; write32(data + 1, jump); return protocol(MSGTYPE_SELECT_FLASH_TYPE_REQUEST, data, sizeof(data)); } STATUS writeSR(uint8_t data) { return protocol(MSGTYPE_WRITE_SR_REQUEST, &data, sizeof(data)); } STATUS writeRAM(uint32_t addr, uint8_t *buf, uint16_t len) { uint8_t data[JN516X_MAX_DATA_SIZE + 4]; if (len > JN516X_MAX_DATA_SIZE) len = JN516X_MAX_DATA_SIZE; write32(data + 0, addr); memcpy(data + 4, buf, len); return protocol(MSGTYPE_RAM_WRITE_REQUEST, data, len + 4); } STATUS readRAM(uint32_t addr, uint8_t *buf, uint16_t len) { if (len > JN516X_MAX_DATA_SIZE) len = JN516X_MAX_DATA_SIZE; uint8_t data[6]; write32(data + 0, addr); write16(data + 4, len); STATUS rv = protocol(MSGTYPE_RAM_READ_REQUEST, data, sizeof(data)); if (rv == STATUS_OK) memcpy(buf, _packet + 3, len); return rv; } STATUS run(uint32_t jump) { uint8_t data[4]; write32(data, jump); return protocol(MSGTYPE_RUN_REQUEST, data, sizeof(data)); } STATUS chipID(CHIPID& id) { STATUS rv = protocol(MSGTYPE_GET_CHIP_ID_REQUEST); id = (CHIPID)(rv == STATUS_OK ? read32(_packet + 3) : 0); return rv; } STATUS flashID(FLASHID& id) { STATUS rv = protocol(MSGTYPE_READ_FLASH_ID_REQUEST); id = (FLASHID)(rv == STATUS_OK ? read16(_packet + 3) : 0); return rv; } FLASH flashType(FLASHID id) { switch (id) { case FLASHID_ST_M25P05_A: return FLASH_ST_M25P05_A; case FLASHID_ST_M25P10_A: return FLASH_ST_M25P10_A; case FLASHID_ST_M25P20_A: return FLASH_ST_M25P20_A; case FLASHID_ST_M25P40: return FLASH_ST_M25P40; case FLASHID_SST_25VF010A: return FLASH_SST_25VF010A; case FLASHID_ATMEL_25F512: return FLASH_ATMEL_25F512; case FLASHID_INTERNAL_FLASH: return FLASH_INTERNAL_FLASH; default: break; } return (FLASH)0; } STATUS bootVersion(uint32_t& version) { uint8_t buf[sizeof(version)]; STATUS rv = readRAM(0x0004, buf, sizeof(buf)); version = (rv == STATUS_OK ? read32(buf) : 0); return rv; } STATUS macAddress(uint8_t *buf, bool customer = true) { return readRAM(customer ? 0x01001570 : 0x01001580, buf, 8); } protected: virtual void programStart(const char *chipname, const char *filename, bool program) {} virtual void programProgress(size_t size, size_t processed) {} virtual void programEnd(STATUS status) {} private: // // for MONOWIRELESS TWELITE-R(2) / MONOSTICK // static const CBUS PIN_PROG = CBUS_3; static const CBUS PIN_RESET = CBUS_2; typedef enum : uint8_t { MSGTYPE_FLASH_ERASE_REQUEST = 0x07, MSGTYPE_FLASH_ERASE_RESPONSE = 0x08, MSGTYPE_FLASH_PROGRAM_REQUEST = 0x09, MSGTYPE_FLASH_PROGRAM_RESPONSE = 0x0A, MSGTYPE_FLASH_READ_REQUEST = 0x0B, MSGTYPE_FLASH_READ_RESPONSE = 0x0C, MSGTYPE_SECTOR_ERASE_REQUEST = 0x0D, MSGTYPE_SECTOR_ERASE_RESPONSE = 0x0E, MSGTYPE_WRITE_SR_REQUEST = 0x0F, MSGTYPE_WRITE_SR_RESPONSE = 0x10, MSGTYPE_SET_RESET_REQUEST = 0x14, MSGTYPE_SET_RESET_RESPONSE = 0x15, MSGTYPE_RAM_WRITE_REQUEST = 0x1D, MSGTYPE_RAM_WRITE_RESPONSE = 0x1E, MSGTYPE_RAM_READ_REQUEST = 0x1F, MSGTYPE_RAM_READ_RESPONSE = 0x20, MSGTYPE_RUN_REQUEST = 0x21, MSGTYPE_RUN_RESPONSE = 0x22, MSGTYPE_READ_FLASH_ID_REQUEST = 0x25, MSGTYPE_READ_FLASH_ID_RESPONSE = 0x26, MSGTYPE_CHANGE_BAUDRATE_REQUEST = 0x27, MSGTYPE_CHANGE_BAUDRATE_RESPONSE = 0x28, MSGTYPE_SELECT_FLASH_TYPE_REQUEST = 0x2C, MSGTYPE_SELECT_FLASH_TYPE_RESPONSE = 0x2D, MSGTYPE_GET_CHIP_ID_REQUEST = 0x32, MSGTYPE_GET_CHIP_ID_RESPONSE = 0x33, } MSGTYPE; void write32(uint8_t *buf, uint32_t data, bool littleEndian = true) { if (littleEndian) { buf[0] = (uint8_t)data; buf[1] = (uint8_t)(data >> 8); buf[2] = (uint8_t)(data >> 16); buf[3] = (uint8_t)(data >> 24); } else { buf[3] = (uint8_t)data; buf[2] = (uint8_t)(data >> 8); buf[1] = (uint8_t)(data >> 16); buf[0] = (uint8_t)(data >> 24); } } void write16(uint8_t *buf, uint16_t data, bool littleEndian = true) { if (littleEndian) { buf[0] = (uint8_t)data; buf[1] = (uint8_t)(data >> 8); } else { buf[1] = (uint8_t)data; buf[0] = (uint8_t)(data >> 8); } } uint32_t read32(const uint8_t *buf, bool littleEndian = false) { return littleEndian ? ((uint32_t)buf[3] << 24) | ((uint32_t)buf[2] << 16) | ((uint16_t)buf[1] << 8) | buf[0] : ((uint32_t)buf[0] << 24) | ((uint32_t)buf[1] << 16) | ((uint16_t)buf[2] << 8) | buf[3]; } uint16_t read16(const uint8_t *buf, bool littleEndian = false) { return littleEndian ? ((uint16_t)buf[1] << 8) | buf[0] : ((uint16_t)buf[0] << 8) | buf[1]; } STATUS fileVersion(VERSION& version, FILE *fp) { uint8_t data[4]; fseek(fp, 0, SEEK_SET); if (fread(data, 1, sizeof(data), fp) != sizeof(data)) { version = (VERSION)0; return STATUS_FILE_READ_FAIL; } version = (VERSION)read32(data); return STATUS_OK; } uint8_t csum(void *buf, size_t len) { uint8_t *p = (uint8_t *)buf; uint8_t c = 0; while (len--) c ^= *p++; return c; } STATUS protocol(MSGTYPE msg, uint8_t *buf = nullptr, uint8_t len = 0) { memcpy(_packet + 2, buf, len); len += 2; _packet[0] = len; _packet[1] = msg; _packet[len] = csum(_packet, len); len += 1; if (write(_packet, len) != len) return STATUS_WRITE_FAIL; for (len = _packet[0] = 0; len <= _packet[0]; ) { uint8_t n = read(_packet + len, _packet[0] - len + 1); if (n == 0) { if (_debug) printf("Error: Message Type [%02X]\n", msg); return STATUS_NO_RESPONSE; } len += n; } return csum(_packet, len) ? STATUS_CRC_ERROR : (STATUS)_packet[2]; } bool _debug; SPEED _speed; uint32_t _timeout; std::string _chipidpath; uint8_t _packet[256]; }; |
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 |
/* jn516x.h - JN516x Chip Library for NXP JN516x Series Copyright (c) 2022-2024 Sasapea's Lab. All right reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #pragma once #include <stdint.h> #define FLASH_START_ADDRESS 0x80000U #define FLASH_SECTOR_OFFSET(sec) (0x8000U * (sec)) #if defined(JN5161) #define CHIP_VERSION JN516x::VERSION_JN5161 #elif defined(JN5164) #define CHIP_VERSION JN516x::VERSION_JN5164 #elif defined(JN5168) #define CHIP_VERSION JN516x::VERSION_JN5168 #elif defined(JN5169) #define CHIP_VERSION JN516x::VERSION_JN5169 #elif defined(JN5179) #define CHIP_VERSION JN516x::VERSION_JN5179 #else #define CHIP_VERSION 0 #endif class JN516x { public: static const uint8_t MAGICNUMBER[12]; static const uint8_t MAGICNUMBER_JN5179[12]; typedef struct __attribute__((packed)) { uint8_t magicNumber[12]; uint8_t configuration; uint8_t status; uint16_t applicationID; } tsBIR; typedef struct __attribute__((packed)) { tsBIR sBIR; // 16-byte Boot Image Record uint8_t encryption[14]; // Encryption Initialisation Vector (ignored if unencrypted) uint16_t configuration; // 16-bit Software Configuration Options uint32_t imageSize; // 32-bit Length of Binary Image in bytes uint32_t dataStart; // 32-bit .data section Flash start address uint16_t dataAddress; // 16-bit .data section load address in RAM (word aligned) uint16_t dataLength; // 16-bit .data section length in 32-bit words uint16_t bssStart; // 16 bit .bss section start address in RAM (word aligned) uint16_t bssLength; // 16-bit .bss section length in 32-bit words uint32_t warmStart; // 32-bit wake-up entry point (word aligned) – warm start uint32_t coldStart; // 32-bit reset entry point (word aligned) – cold start } tsFlashHeader; typedef struct __attribute__((packed)) { uint32_t version; // version tsBIR sBIR; // 16-byte Boot Image Record uint8_t encryption[14]; // Encryption Initialisation Vector (ignored if unencrypted) uint16_t configuration; // 16-bit Software Configuration Options uint32_t imageSize; // 32-bit Length of Binary Image in bytes uint32_t dataStart; // 32-bit .data section Flash start address uint16_t dataAddress; // 16-bit .data section load address in RAM (word aligned) uint16_t dataLength; // 16-bit .data section length in 32-bit words uint16_t bssStart; // 16 bit .bss section start address in RAM (word aligned) uint16_t bssLength; // 16-bit .bss section length in 32-bit words uint32_t warmStart; // 32-bit wake-up entry point (word aligned) – warm start uint32_t coldStart; // 32-bit reset entry point (word aligned) – cold start } tsFlashHeader_JN5179; typedef enum { CHIPID_JN517x = 0xA686U, CHIPID_JN5169 = 0xB686U, CHIPID_JN516x = 0x8686U, CHIPID_JN5148 = 0x4686U, CHIPID_JN5142 = 0x5686U, CHIPID_JN5139 = 0x2000U, } CHIPID; typedef enum { VERSION_JN517x = 0x0000000AU, VERSION_JN5179 = 0x0F03000AU, VERSION_JN5178 = 0x0703000AU, VERSION_JN5174 = 0x0403000AU, VERSION_JN5169 = 0x0F03000BU, VERSION_JN516x = 0x00000008U, VERSION_JN5168 = 0x07030008U, VERSION_JN5164 = 0x04030008U, VERSION_JN5161 = 0x01000008U, } VERSION; typedef enum { FLASHID_ST_M25P05_A = 0x0505U, FLASHID_ST_M25P10_A = 0x1010U, FLASHID_ST_M25P20_A = 0x1101U, FLASHID_ST_M25P40 = 0x1212U, FLASHID_SST_25VF010A = 0xBF49U, FLASHID_ATMEL_25F512 = 0x1F60U, FLASHID_INTERNAL_FLASH = 0xCCEEU, // JN516x/7x only } FLASHID; typedef enum { FLASH_ST_M25P05_A = 4U, FLASH_ST_M25P10_A = 0U, FLASH_ST_M25P20_A = 5U, FLASH_ST_M25P40 = 3U, FLASH_SST_25VF010A = 1U, FLASH_ATMEL_25F512 = 2U, FLASH_INTERNAL_FLASH = 8U, // JN516x/7x only } FLASH; typedef struct __attribute__((packed)) { uint8_t command; union { uint8_t mode; uint8_t data[96]; uint32_t crc32; } args; } ota_request_t; typedef struct __attribute__((packed)) { uint8_t command; uint8_t status; union { struct __attribute__((packed)) { uint32_t version; uint8_t otaboot; } device; uint32_t crc32; } args; } ota_response_t; typedef enum { ADDR_BROADCAST = 0xFFFFU, ADDR_OTA_BOOT = ADDR_BROADCAST - 1, ADDR_OTA_BRIDGE = ADDR_BROADCAST - 2, ADDR_OTA_BRIDGE2 = ADDR_BROADCAST - 3, } ADDR; typedef enum { OTA_UPDATE_CHIPVER = 0xC0U, OTA_UPDATE_BLDMODE = 0xC1U, OTA_UPDATE_START = 0xC2U, OTA_UPDATE_PROGRAM = 0xC3U, OTA_UPDATE_END = 0xC4U, } OTA_UPDATE; typedef enum { OTA_STATUS_OK = 0x00U, OTA_STATUS_ARG_ERROR = 0xFAU, OTA_STATUS_BLD_ERROR = 0xFBU, OTA_STATUS_CRC_ERROR = 0xFCU, OTA_STATUS_SDK_ERROR = 0xFDU, } OTA_STATUS; static VERSION chipVersion(CHIPID id) { switch (id & 0xFFFF) { case CHIPID_JN517x : return VERSION_JN517x; case CHIPID_JN5169 : return VERSION_JN5169; case CHIPID_JN516x : return VERSION_JN516x; default: break; } return (VERSION)0; } static const char *chipName(VERSION version) { switch (version) { case VERSION_JN5179: return "JN5179"; case VERSION_JN5178: return "JN5178"; case VERSION_JN5174: return "JN5174"; case VERSION_JN5169: return "JN5169"; case VERSION_JN5168: return "JN5168"; case VERSION_JN5164: return "JN5164"; case VERSION_JN5161: return "JN5161"; default: break; } return "(unknown)"; } static uint32_t chipFlashSectors(VERSION version) { return (uint8_t)(version >> 24) + 1; } static uint32_t chipFlashSize(VERSION version) { return 32768U * chipFlashSectors(version); } static uint32_t chipRamSize(VERSION version) { return 8192U * ((uint8_t)(version >> 16) + 1); } static uint16_t chipType(VERSION version) { return (uint16_t)version; } }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
/* jn516x.cpp - JN516x Chip Library for NXP JN516x Series Copyright (c) 2022 Sasapea's Lab. All right reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "jn516x.h" const uint8_t JN516x::MAGICNUMBER[] = { 0x12, 0x34, 0x56, 0x78, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88 }; const uint8_t JN516x::MAGICNUMBER_JN5179[] = { 0x12, 0x34, 0x56, 0x78, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 }; |
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 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
/* ftd2.h - Serial Library for FTDI USB Chip FT2XX Copyright (c) 2022 Sasapea's Lab. All right reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #pragma once #include <stdio.h> #include <stdlib.h> #include <stddef.h> #include <stdint.h> #include <stdbool.h> #include <string.h> #include "ftd2xx.h" #include "sleep.h" #ifndef LOW #define LOW 0 #endif #ifndef HIGH #define HIGH 1 #endif extern FT_STATUS FT_GetLastError(void); class FTD2 { public: // // FT_OpenEx Flags // typedef enum { OPENBY_SERIAL_NUMBER = FT_OPEN_BY_SERIAL_NUMBER, OPENBY_DESCRIPTION = FT_OPEN_BY_DESCRIPTION, OPENBY_LOCATION = FT_OPEN_BY_LOCATION, } OPENBY; // // Baud Rates // typedef enum { SPEED_300 = FT_BAUD_300, SPEED_600 = FT_BAUD_600, SPEED_1200 = FT_BAUD_1200, SPEED_2400 = FT_BAUD_2400, SPEED_4800 = FT_BAUD_4800, SPEED_9600 = FT_BAUD_9600, SPEED_14400 = FT_BAUD_14400, SPEED_19200 = FT_BAUD_19200, SPEED_38400 = FT_BAUD_38400, SPEED_57600 = FT_BAUD_57600, SPEED_115200 = FT_BAUD_115200, SPEED_230400 = FT_BAUD_230400, SPEED_460800 = FT_BAUD_460800, SPEED_500K = 500000, SPEED_921600 = FT_BAUD_921600, SPEED_1M = 1000000, SPEED_2M = 2000000, SPEED_3M = 3000000, } SPEED; // // mode // typedef enum { MODE_7N1 = 0, MODE_8N1 = 1, MODE_7N2 = 2, MODE_8N2 = 3, MODE_7E1 = 4, MODE_8E1 = 5, MODE_7E2 = 6, MODE_8E2 = 7, MODE_7O1 = 8, MODE_8O1 = 9, MODE_7O2 = 10, MODE_8O2 = 11, } MODE; // // Flow Control // typedef enum { FLOW_NONE = FT_FLOW_NONE, FLOW_RTS_CTS = FT_FLOW_RTS_CTS, FLOW_DTR_DSR = FT_FLOW_DTR_DSR, FLOW_XON_XOFF = FT_FLOW_XON_XOFF, } FLOW; // // Bit Modes // typedef enum { BITMODE_RESET = FT_BITMODE_RESET, BITMODE_ASYNC_BITBANG = FT_BITMODE_ASYNC_BITBANG, BITMODE_MPSSE = FT_BITMODE_MPSSE, BITMODE_SYNC_BITBANG = FT_BITMODE_SYNC_BITBANG, BITMODE_MCU_HOST = FT_BITMODE_MCU_HOST, BITMODE_FAST_SERIAL = FT_BITMODE_FAST_SERIAL, BITMODE_CBUS_BITBANG = FT_BITMODE_CBUS_BITBANG, BITMODE_SYNC_FIFO = FT_BITMODE_SYNC_FIFO, } BITMODE; typedef enum { GPIO_INPUT = 0, GPIO_OUTPUT = 1, } GPIO; typedef enum { CBUS_0 = 0, CBUS_1 = 1, CBUS_2 = 2, CBUS_3 = 3, } CBUS; FTD2(BITMODE mode = BITMODE_CBUS_BITBANG) : _handle(0) , _mode(mode) , _cbus(0) { FT_Initialise(); } virtual ~FTD2(void) { end(); FT_Finalise(); } FT_STATUS status(void) { return FT_GetLastError(); } size_t getDeviceCount(void) { DWORD count = 0; FT_ListDevices(&count, NULL, FT_LIST_NUMBER_ONLY); return count; } bool getDeviceSerial(size_t index, char *buf) { strcpy(buf, "(null)"); return FT_SUCCESS(FT_ListDevices((void *)index, buf, FT_LIST_BY_INDEX | FT_OPEN_BY_SERIAL_NUMBER)); } bool getDeviceDescription(size_t index, char *buf) { strcpy(buf, "(null)"); return FT_SUCCESS(FT_ListDevices((void *)index, buf, FT_LIST_BY_INDEX | FT_OPEN_BY_DESCRIPTION)); } bool getDeviceLocation(size_t index, char *buf) { strcpy(buf, "(null)"); return FT_SUCCESS(FT_ListDevices((void *)index, buf, FT_LIST_BY_INDEX | FT_OPEN_BY_LOCATION)); } bool begin(int index, SPEED speed = SPEED_115200, MODE mode = MODE_8N1, FLOW flow = FLOW_NONE) { if (!FT_SUCCESS(FT_Open(index, &_handle))) return false; init(speed, mode, flow); return true; } bool begin(const char *name, SPEED speed = SPEED_115200, MODE mode = MODE_8N1, FLOW flow = FLOW_NONE) { char *eos; int index = strtoul(name, &eos, 10); if (*eos) { if (!FT_SUCCESS(FT_OpenEx((void *)name, OPENBY_SERIAL_NUMBER, &_handle))) return false; } else { if (!FT_SUCCESS(FT_Open(index, &_handle))) return false; } init(speed, mode, flow); return true; } bool end(void) { if (_handle) { FT_HANDLE h = _handle; _handle = nullptr; return FT_SUCCESS(FT_Close(h)); } return true; } int getComPortNumber(void) { LONG com = -1; FT_GetComPortNumber(_handle, &com); return com; } bool baudrate(SPEED speed) { switch (speed) { case SPEED_500K: return FT_SUCCESS(FT_SetDivisor(_handle, 6)); case SPEED_1M: return FT_SUCCESS(FT_SetDivisor(_handle, 3)); case SPEED_2M: return FT_SUCCESS(FT_SetDivisor(_handle, 1)); case SPEED_3M: return FT_SUCCESS(FT_SetDivisor(_handle, 0)); default: break; } return FT_SUCCESS(FT_SetBaudRate(_handle, speed)); } bool frame(MODE mode = MODE_8N1) { return FT_SUCCESS(FT_SetDataCharacteristics(_handle, mode & 1 ? DATA_8 : DATA_7, mode & 2 ? STOP_2 : STOP_1, mode & 4 ? PAR_EVEN : (mode & 8 ? PAR_NONE : PAR_NONE) )); } bool flowCtrl(FLOW mode, uint8_t xon = 0x11, uint8_t xoff = 0x13) { return FT_SUCCESS(FT_SetFlowControl(_handle, mode, xon, xoff)); } bool dtr(bool on) { return FT_SUCCESS(on ? FT_SetDtr(_handle) : FT_ClrDtr(_handle)); } bool rts(bool on) { return FT_SUCCESS(on ? FT_SetRts(_handle) : FT_ClrRts(_handle)); } bool timeout(uint32_t readTimeout, uint32_t writeTimeout) { return FT_SUCCESS(FT_SetTimeouts(_handle, readTimeout, writeTimeout)); } bool purge(void) { return FT_SUCCESS(FT_Purge(_handle, FT_PURGE_RX | FT_PURGE_TX)); } size_t read(void *buf, size_t len) { DWORD bytesReceived = 0; FT_Read(_handle, buf, len, &bytesReceived); return bytesReceived; } size_t write(const void *buf, size_t len) { DWORD bytesWritten = 0; FT_Write(_handle, (void *)buf, len, &bytesWritten); return bytesWritten; } void pinMode(CBUS pin, GPIO mode) { pin = (CBUS)((pin & 3) + 4); if (mode == GPIO_OUTPUT) _cbus |= (1 << pin); else _cbus &= ~(1 << pin); FT_SetBitMode(_handle, _cbus, _mode); } void digitalWrite(CBUS pin, uint8_t value) { pin = (CBUS)(pin & 3); if (value) _cbus |= (1 << pin); else _cbus &= ~(1 << pin); FT_SetBitMode(_handle, _cbus, _mode); } uint8_t digitalRead(CBUS pin) { pin = (CBUS)(pin & 3); uint8_t mask = _cbus >> 4; uint8_t data = 0; FT_GetBitMode(_handle, &data); return (((data & ~mask) | (_cbus & mask)) >> pin) & 1; } protected: void init(SPEED speed, MODE mode, FLOW flow) { baudrate(speed); frame(mode); flowCtrl(flow); rts(true); dtr(true); timeout(1000, 1000); purge(); FT_SetBitMode(_handle, _cbus, BITMODE_RESET); } private: // // Word Lengths // typedef enum { DATA_8 = FT_BITS_8, DATA_7 = FT_BITS_7, } DATA; // // Stop Bits // typedef enum { STOP_1 = FT_STOP_BITS_1, STOP_2 = FT_STOP_BITS_2, } STOP; // // Parity // typedef enum { PAR_NONE = FT_PARITY_NONE, PAR_ODD = FT_PARITY_ODD, PAR_EVEN = FT_PARITY_EVEN, PAR_MARK = FT_PARITY_MARK, PAR_SPACE = FT_PARITY_SPACE, } PAR; FT_HANDLE _handle; uint8_t _mode; uint8_t _cbus; }; |
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 |
/* ftd2.cpp - Serial Library for FTDI USB Chip FT2XX Copyright (c) 2022 Sasapea's Lab. All right reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "ftd2.h" typedef FT_STATUS (WINAPI *LPFN_FT_ListDevices)(PVOID pvArg1, PVOID pvArg2, DWORD dwFlags); typedef FT_STATUS (WINAPI *LPFN_FT_Open)(int iDevice, FT_HANDLE *ftHandle); typedef FT_STATUS (WINAPI *LPFN_FT_OpenEx)(PVOID pArg1, DWORD Flags, FT_HANDLE *pHandle); typedef FT_STATUS (WINAPI *LPFN_FT_Close)(FT_HANDLE ftHandle); typedef FT_STATUS (WINAPI *LPFN_FT_SetTimeouts)(FT_HANDLE ftHandle, DWORD dwReadTimeout, DWORD dwWriteTimeout); typedef FT_STATUS (WINAPI *LPFN_FT_Read)(FT_HANDLE ftHandle, LPVOID lpBuffer, DWORD dwBytesToRead, LPDWORD lpBytesReturned); typedef FT_STATUS (WINAPI *LPFN_FT_Write)(FT_HANDLE ftHandle, LPVOID lpBuffer, DWORD dwBytesToWrite, LPDWORD lpBytesWritten); typedef FT_STATUS (WINAPI *LPFN_FT_SetBaudRate)(FT_HANDLE ftHandle, ULONG BaudRate); typedef FT_STATUS (WINAPI *LPFN_FT_SetDivisor)(FT_HANDLE ftHandle, USHORT usDivisor); typedef FT_STATUS (WINAPI *LPFN_FT_SetDataCharacteristics)(FT_HANDLE ftHandle, UCHAR WordLength, UCHAR StopBits, UCHAR Parity); typedef FT_STATUS (WINAPI *LPFN_FT_SetFlowControl)(FT_HANDLE ftHandle, USHORT FlowControl, UCHAR XonChar, UCHAR XoffChar); typedef FT_STATUS (WINAPI *LPFN_FT_SetDtr)(FT_HANDLE ftHandle); typedef FT_STATUS (WINAPI *LPFN_FT_ClrDtr)(FT_HANDLE ftHandle); typedef FT_STATUS (WINAPI *LPFN_FT_SetRts)(FT_HANDLE ftHandle); typedef FT_STATUS (WINAPI *LPFN_FT_ClrRts)(FT_HANDLE ftHandle); typedef FT_STATUS (WINAPI *LPFN_FT_SetBitMode)(FT_HANDLE ftHandle, UCHAR ucMask, UCHAR ucEnable); typedef FT_STATUS (WINAPI *LPFN_FT_GetBitMode)(FT_HANDLE ftHandle, PUCHAR pucMode); typedef FT_STATUS (WINAPI *LPFN_FT_GetComPortNumber)(FT_HANDLE ftHandle, LPLONG lplComPortNumber); typedef FT_STATUS (WINAPI *LPFN_FT_Purge)(FT_HANDLE ftHandle, ULONG Mask); static HMODULE hFTD2XX; static LPFN_FT_ListDevices lpfn_FT_ListDevices; static LPFN_FT_Open lpfn_FT_Open; static LPFN_FT_OpenEx lpfn_FT_OpenEx; static LPFN_FT_Close lpfn_FT_Close; static LPFN_FT_SetTimeouts lpfn_FT_SetTimeouts; static LPFN_FT_Read lpfn_FT_Read; static LPFN_FT_Write lpfn_FT_Write; static LPFN_FT_SetBaudRate lpfn_FT_SetBaudRate; static LPFN_FT_SetDivisor lpfn_FT_SetDivisor; static LPFN_FT_SetDataCharacteristics lpfn_FT_SetDataCharacteristics; static LPFN_FT_SetFlowControl lpfn_FT_SetFlowControl; static LPFN_FT_SetDtr lpfn_FT_SetDtr; static LPFN_FT_ClrDtr lpfn_FT_ClrDtr; static LPFN_FT_SetRts lpfn_FT_SetRts; static LPFN_FT_ClrRts lpfn_FT_ClrRts; static LPFN_FT_SetBitMode lpfn_FT_SetBitMode; static LPFN_FT_GetBitMode lpfn_FT_GetBitMode; static LPFN_FT_GetComPortNumber lpfn_FT_GetComPortNumber; static LPFN_FT_Purge lpfn_FT_Purge; static FT_STATUS status = FT_OK; FT_STATUS FT_GetLastError(void) { return status; } FT_STATUS WINAPI FT_Initialise(void) { if (!hFTD2XX) { if (!(hFTD2XX = LoadLibrary("ftd2xx.dll"))) return status = FT_NOT_SUPPORTED; lpfn_FT_ListDevices = (LPFN_FT_ListDevices) GetProcAddress(hFTD2XX, "FT_ListDevices"); lpfn_FT_Open = (LPFN_FT_Open) GetProcAddress(hFTD2XX, "FT_Open"); lpfn_FT_OpenEx = (LPFN_FT_OpenEx) GetProcAddress(hFTD2XX, "FT_OpenEx"); lpfn_FT_Close = (LPFN_FT_Close) GetProcAddress(hFTD2XX, "FT_Close"); lpfn_FT_SetTimeouts = (LPFN_FT_SetTimeouts) GetProcAddress(hFTD2XX, "FT_SetTimeouts"); lpfn_FT_Read = (LPFN_FT_Read) GetProcAddress(hFTD2XX, "FT_Read"); lpfn_FT_Write = (LPFN_FT_Write) GetProcAddress(hFTD2XX, "FT_Write"); lpfn_FT_SetBaudRate = (LPFN_FT_SetBaudRate) GetProcAddress(hFTD2XX, "FT_SetBaudRate"); lpfn_FT_SetDivisor = (LPFN_FT_SetDivisor) GetProcAddress(hFTD2XX, "FT_SetDivisor"); lpfn_FT_SetDataCharacteristics = (LPFN_FT_SetDataCharacteristics)GetProcAddress(hFTD2XX, "FT_SetDataCharacteristics"); lpfn_FT_SetFlowControl = (LPFN_FT_SetFlowControl) GetProcAddress(hFTD2XX, "FT_SetFlowControl"); lpfn_FT_SetDtr = (LPFN_FT_SetDtr) GetProcAddress(hFTD2XX, "FT_SetDtr"); lpfn_FT_ClrDtr = (LPFN_FT_ClrDtr) GetProcAddress(hFTD2XX, "FT_ClrDtr"); lpfn_FT_SetRts = (LPFN_FT_SetRts) GetProcAddress(hFTD2XX, "FT_SetRts"); lpfn_FT_ClrRts = (LPFN_FT_ClrRts) GetProcAddress(hFTD2XX, "FT_ClrRts"); lpfn_FT_SetBitMode = (LPFN_FT_SetBitMode) GetProcAddress(hFTD2XX, "FT_SetBitMode"); lpfn_FT_GetBitMode = (LPFN_FT_GetBitMode) GetProcAddress(hFTD2XX, "FT_GetBitMode"); lpfn_FT_GetComPortNumber = (LPFN_FT_GetComPortNumber) GetProcAddress(hFTD2XX, "FT_GetComPortNumber"); lpfn_FT_Purge = (LPFN_FT_Purge) GetProcAddress(hFTD2XX, "FN_FT_Purge"); } return status = FT_OK; } void WINAPI FT_Finalise(void) { if (hFTD2XX) { FreeLibrary(hFTD2XX); hFTD2XX = NULL; } } FTD2XX_API FT_STATUS FT_ListDevices(PVOID pvArg1, PVOID pvArg2, DWORD dwFlags) { return status = (lpfn_FT_ListDevices ? lpfn_FT_ListDevices(pvArg1, pvArg2, dwFlags) : FT_NOT_SUPPORTED); } FTD2XX_API FT_STATUS FT_Open(int iDevice, FT_HANDLE *ftHandle) { return status = (lpfn_FT_Open ? lpfn_FT_Open(iDevice, ftHandle) : FT_NOT_SUPPORTED); } FTD2XX_API FT_STATUS FT_OpenEx(PVOID pArg1, DWORD Flags, FT_HANDLE *pHandle) { return status = (lpfn_FT_OpenEx ? lpfn_FT_OpenEx(pArg1, Flags, pHandle) : FT_NOT_SUPPORTED); } FTD2XX_API FT_STATUS FT_Close(FT_HANDLE ftHandle) { return status = (lpfn_FT_Close ? lpfn_FT_Close(ftHandle) : FT_NOT_SUPPORTED); } FTD2XX_API FT_STATUS FT_SetTimeouts(FT_HANDLE ftHandle, DWORD dwReadTimeout, DWORD dwWriteTimeout) { return status = (lpfn_FT_SetTimeouts ? lpfn_FT_SetTimeouts(ftHandle, dwReadTimeout, dwWriteTimeout) : FT_NOT_SUPPORTED); } FTD2XX_API FT_STATUS FT_Read(FT_HANDLE ftHandle, LPVOID lpBuffer, DWORD dwBytesToRead, LPDWORD lpBytesReturned) { return status = (lpfn_FT_Read ? lpfn_FT_Read(ftHandle, lpBuffer, dwBytesToRead, lpBytesReturned) : FT_NOT_SUPPORTED); } FTD2XX_API FT_STATUS FT_Write(FT_HANDLE ftHandle, LPVOID lpBuffer, DWORD dwBytesToWrite, LPDWORD lpBytesWritten) { return status = (lpfn_FT_Write ? lpfn_FT_Write(ftHandle, lpBuffer, dwBytesToWrite, lpBytesWritten) : FT_NOT_SUPPORTED); } FTD2XX_API FT_STATUS FT_SetBaudRate(FT_HANDLE ftHandle, ULONG BaudRate) { return status = (lpfn_FT_SetBaudRate ? lpfn_FT_SetBaudRate(ftHandle, BaudRate) : FT_NOT_SUPPORTED); } FTD2XX_API FT_STATUS FT_SetDivisor(FT_HANDLE ftHandle, USHORT usDivisor) { return status = (lpfn_FT_SetDivisor ? lpfn_FT_SetDivisor(ftHandle, usDivisor) : FT_NOT_SUPPORTED); } FTD2XX_API FT_STATUS FT_SetDataCharacteristics(FT_HANDLE ftHandle, UCHAR WordLength, UCHAR StopBits, UCHAR Parity) { return status = (lpfn_FT_SetDataCharacteristics ? lpfn_FT_SetDataCharacteristics(ftHandle, WordLength, StopBits, Parity) : FT_NOT_SUPPORTED); } FTD2XX_API FT_STATUS FT_SetFlowControl(FT_HANDLE ftHandle, USHORT FlowControl, UCHAR XonChar, UCHAR XoffChar) { return status = (lpfn_FT_SetFlowControl ? lpfn_FT_SetFlowControl(ftHandle, FlowControl, XonChar, XoffChar) : FT_NOT_SUPPORTED); } FTD2XX_API FT_STATUS FT_SetDtr(FT_HANDLE ftHandle) { return status = (lpfn_FT_SetDtr ? lpfn_FT_SetDtr(ftHandle) : FT_NOT_SUPPORTED); } FTD2XX_API FT_STATUS FT_ClrDtr(FT_HANDLE ftHandle) { return status = (lpfn_FT_ClrDtr ? lpfn_FT_ClrDtr(ftHandle) : FT_NOT_SUPPORTED); } FTD2XX_API FT_STATUS FT_SetRts(FT_HANDLE ftHandle) { return status = (lpfn_FT_SetRts ? lpfn_FT_SetRts(ftHandle) : FT_NOT_SUPPORTED); } FTD2XX_API FT_STATUS FT_ClrRts(FT_HANDLE ftHandle) { return status = (lpfn_FT_ClrRts ? lpfn_FT_ClrRts(ftHandle) : FT_NOT_SUPPORTED); } FTD2XX_API FT_STATUS FT_SetBitMode(FT_HANDLE ftHandle, UCHAR ucMask, UCHAR ucEnable) { return status = (lpfn_FT_SetBitMode ? lpfn_FT_SetBitMode(ftHandle, ucMask, ucEnable) : FT_NOT_SUPPORTED); } FTD2XX_API FT_STATUS FT_GetBitMode(FT_HANDLE ftHandle, PUCHAR pucMode) { return status = (lpfn_FT_GetBitMode ? lpfn_FT_GetBitMode(ftHandle, pucMode) : FT_NOT_SUPPORTED); } FTD2XX_API FT_STATUS FT_GetComPortNumber(FT_HANDLE ftHandle, LPLONG lplComPortNumber) { return status = (lpfn_FT_GetComPortNumber ? lpfn_FT_GetComPortNumber(ftHandle, lplComPortNumber) : FT_NOT_SUPPORTED); } FTD2XX_API FT_STATUS FT_Purge(FT_HANDLE ftHandle, ULONG Mask) { return status = (lpfn_FT_Purge ? lpfn_FT_Purge(ftHandle, Mask) : FT_NOT_SUPPORTED); } |
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 |
/* sleep.h - Sleep Library Copyright (c) 2022 Sasapea's Lab. All right reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #pragma once #ifdef __linux__ #include <time.h> #else #include <windows.h> #endif class Sleep { public: static void sleep(unsigned long ms) { #ifdef __linux__ struct timespec req; req.tv_sec = (ms / 1000); req.tv_nsec = (ms % 1000) * 1000000; nanosleep(&req, NULL); #else ::Sleep(ms); #endif } }; |
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 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 |
/*++ Copyright ゥ 2001-2011 Future Technology Devices International Limited THIS SOFTWARE IS PROVIDED BY FUTURE TECHNOLOGY DEVICES INTERNATIONAL LIMITED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL FUTURE TECHNOLOGY DEVICES INTERNATIONAL LIMITED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE, DATA, OR PROFITS OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. FTDI DRIVERS MAY BE USED ONLY IN CONJUNCTION WITH PRODUCTS BASED ON FTDI PARTS. FTDI DRIVERS MAY BE DISTRIBUTED IN ANY FORM AS LONG AS LICENSE INFORMATION IS NOT MODIFIED. IF A CUSTOM VENDOR ID AND/OR PRODUCT ID OR DESCRIPTION STRING ARE USED, IT IS THE RESPONSIBILITY OF THE PRODUCT MANUFACTURER TO MAINTAIN ANY CHANGES AND SUBSEQUENT WHQL RE-CERTIFICATION AS A RESULT OF MAKING THESE CHANGES. Module Name: ftd2xx.h Abstract: Native USB device driver for FTDI FT232x, FT245x, FT2232x and FT4232x devices FTD2XX library definitions Environment: kernel & user mode --*/ #ifndef FTD2XX_H #define FTD2XX_H #ifdef _WIN32 // Compiling on Windows #include <windows.h> // The following ifdef block is the standard way of creating macros // which make exporting from a DLL simpler. All files within this DLL // are compiled with the FTD2XX_EXPORTS symbol defined on the command line. // This symbol should not be defined on any project that uses this DLL. // This way any other project whose source files include this file see // FTD2XX_API functions as being imported from a DLL, whereas this DLL // sees symbols defined with this macro as being exported. #ifdef FTD2XX_EXPORTS #define FTD2XX_API __declspec(dllexport) #elif defined(FTD2XX_STATIC) // Avoid decorations when linking statically to D2XX. #define FTD2XX_API // Static D2XX depends on these Windows libs: //#pragma comment(lib, "setupapi.lib") //#pragma comment(lib, "advapi32.lib") //#pragma comment(lib, "user32.lib") #else #define FTD2XX_API __declspec(dllimport) #endif #else // _WIN32 // Compiling on non-Windows platform. #include "WinTypes.h" // No decorations needed. #define FTD2XX_API #endif // _WIN32 typedef PVOID FT_HANDLE; typedef ULONG FT_STATUS; // // Device status // enum { FT_OK, FT_INVALID_HANDLE, FT_DEVICE_NOT_FOUND, FT_DEVICE_NOT_OPENED, FT_IO_ERROR, FT_INSUFFICIENT_RESOURCES, FT_INVALID_PARAMETER, FT_INVALID_BAUD_RATE, FT_DEVICE_NOT_OPENED_FOR_ERASE, FT_DEVICE_NOT_OPENED_FOR_WRITE, FT_FAILED_TO_WRITE_DEVICE, FT_EEPROM_READ_FAILED, FT_EEPROM_WRITE_FAILED, FT_EEPROM_ERASE_FAILED, FT_EEPROM_NOT_PRESENT, FT_EEPROM_NOT_PROGRAMMED, FT_INVALID_ARGS, FT_NOT_SUPPORTED, FT_OTHER_ERROR, FT_DEVICE_LIST_NOT_READY, }; #define FT_SUCCESS(status) ((status) == FT_OK) // // FT_OpenEx Flags // #define FT_OPEN_BY_SERIAL_NUMBER 1 #define FT_OPEN_BY_DESCRIPTION 2 #define FT_OPEN_BY_LOCATION 4 #define FT_OPEN_MASK (FT_OPEN_BY_SERIAL_NUMBER | \ FT_OPEN_BY_DESCRIPTION | \ FT_OPEN_BY_LOCATION) // // FT_ListDevices Flags (used in conjunction with FT_OpenEx Flags // #define FT_LIST_NUMBER_ONLY 0x80000000 #define FT_LIST_BY_INDEX 0x40000000 #define FT_LIST_ALL 0x20000000 #define FT_LIST_MASK (FT_LIST_NUMBER_ONLY|FT_LIST_BY_INDEX|FT_LIST_ALL) // // Baud Rates // #define FT_BAUD_300 300 #define FT_BAUD_600 600 #define FT_BAUD_1200 1200 #define FT_BAUD_2400 2400 #define FT_BAUD_4800 4800 #define FT_BAUD_9600 9600 #define FT_BAUD_14400 14400 #define FT_BAUD_19200 19200 #define FT_BAUD_38400 38400 #define FT_BAUD_57600 57600 #define FT_BAUD_115200 115200 #define FT_BAUD_230400 230400 #define FT_BAUD_460800 460800 #define FT_BAUD_921600 921600 // // Word Lengths // #define FT_BITS_8 (UCHAR) 8 #define FT_BITS_7 (UCHAR) 7 // // Stop Bits // #define FT_STOP_BITS_1 (UCHAR) 0 #define FT_STOP_BITS_2 (UCHAR) 2 // // Parity // #define FT_PARITY_NONE (UCHAR) 0 #define FT_PARITY_ODD (UCHAR) 1 #define FT_PARITY_EVEN (UCHAR) 2 #define FT_PARITY_MARK (UCHAR) 3 #define FT_PARITY_SPACE (UCHAR) 4 // // Flow Control // #define FT_FLOW_NONE 0x0000 #define FT_FLOW_RTS_CTS 0x0100 #define FT_FLOW_DTR_DSR 0x0200 #define FT_FLOW_XON_XOFF 0x0400 // // Purge rx and tx buffers // #define FT_PURGE_RX 1 #define FT_PURGE_TX 2 // // Events // typedef void (*PFT_EVENT_HANDLER)(DWORD,DWORD); #define FT_EVENT_RXCHAR 1 #define FT_EVENT_MODEM_STATUS 2 #define FT_EVENT_LINE_STATUS 4 // // Timeouts // #define FT_DEFAULT_RX_TIMEOUT 300 #define FT_DEFAULT_TX_TIMEOUT 300 // // Device types // typedef ULONG FT_DEVICE; enum { FT_DEVICE_BM, FT_DEVICE_AM, FT_DEVICE_100AX, FT_DEVICE_UNKNOWN, FT_DEVICE_2232C, FT_DEVICE_232R, FT_DEVICE_2232H, FT_DEVICE_4232H, FT_DEVICE_232H, FT_DEVICE_X_SERIES, FT_DEVICE_4222H_0, FT_DEVICE_4222H_1_2, FT_DEVICE_4222H_3, FT_DEVICE_4222_PROG, FT_DEVICE_900, FT_DEVICE_930, FT_DEVICE_UMFTPD3A, }; // // Bit Modes // #define FT_BITMODE_RESET 0x00 #define FT_BITMODE_ASYNC_BITBANG 0x01 #define FT_BITMODE_MPSSE 0x02 #define FT_BITMODE_SYNC_BITBANG 0x04 #define FT_BITMODE_MCU_HOST 0x08 #define FT_BITMODE_FAST_SERIAL 0x10 #define FT_BITMODE_CBUS_BITBANG 0x20 #define FT_BITMODE_SYNC_FIFO 0x40 // // FT232R CBUS Options EEPROM values // #define FT_232R_CBUS_TXDEN 0x00 // Tx Data Enable #define FT_232R_CBUS_PWRON 0x01 // Power On #define FT_232R_CBUS_RXLED 0x02 // Rx LED #define FT_232R_CBUS_TXLED 0x03 // Tx LED #define FT_232R_CBUS_TXRXLED 0x04 // Tx and Rx LED #define FT_232R_CBUS_SLEEP 0x05 // Sleep #define FT_232R_CBUS_CLK48 0x06 // 48MHz clock #define FT_232R_CBUS_CLK24 0x07 // 24MHz clock #define FT_232R_CBUS_CLK12 0x08 // 12MHz clock #define FT_232R_CBUS_CLK6 0x09 // 6MHz clock #define FT_232R_CBUS_IOMODE 0x0A // IO Mode for CBUS bit-bang #define FT_232R_CBUS_BITBANG_WR 0x0B // Bit-bang write strobe #define FT_232R_CBUS_BITBANG_RD 0x0C // Bit-bang read strobe // // FT232H CBUS Options EEPROM values // #define FT_232H_CBUS_TRISTATE 0x00 // Tristate #define FT_232H_CBUS_TXLED 0x01 // Tx LED #define FT_232H_CBUS_RXLED 0x02 // Rx LED #define FT_232H_CBUS_TXRXLED 0x03 // Tx and Rx LED #define FT_232H_CBUS_PWREN 0x04 // Power Enable #define FT_232H_CBUS_SLEEP 0x05 // Sleep #define FT_232H_CBUS_DRIVE_0 0x06 // Drive pin to logic 0 #define FT_232H_CBUS_DRIVE_1 0x07 // Drive pin to logic 1 #define FT_232H_CBUS_IOMODE 0x08 // IO Mode for CBUS bit-bang #define FT_232H_CBUS_TXDEN 0x09 // Tx Data Enable #define FT_232H_CBUS_CLK30 0x0A // 30MHz clock #define FT_232H_CBUS_CLK15 0x0B // 15MHz clock #define FT_232H_CBUS_CLK7_5 0x0C // 7.5MHz clock // // FT X Series CBUS Options EEPROM values // #define FT_X_SERIES_CBUS_TRISTATE 0x00 // Tristate #define FT_X_SERIES_CBUS_TXLED 0x01 // Tx LED #define FT_X_SERIES_CBUS_RXLED 0x02 // Rx LED #define FT_X_SERIES_CBUS_TXRXLED 0x03 // Tx and Rx LED #define FT_X_SERIES_CBUS_PWREN 0x04 // Power Enable #define FT_X_SERIES_CBUS_SLEEP 0x05 // Sleep #define FT_X_SERIES_CBUS_DRIVE_0 0x06 // Drive pin to logic 0 #define FT_X_SERIES_CBUS_DRIVE_1 0x07 // Drive pin to logic 1 #define FT_X_SERIES_CBUS_IOMODE 0x08 // IO Mode for CBUS bit-bang #define FT_X_SERIES_CBUS_TXDEN 0x09 // Tx Data Enable #define FT_X_SERIES_CBUS_CLK24 0x0A // 24MHz clock #define FT_X_SERIES_CBUS_CLK12 0x0B // 12MHz clock #define FT_X_SERIES_CBUS_CLK6 0x0C // 6MHz clock #define FT_X_SERIES_CBUS_BCD_CHARGER 0x0D // Battery charger detected #define FT_X_SERIES_CBUS_BCD_CHARGER_N 0x0E // Battery charger detected inverted #define FT_X_SERIES_CBUS_I2C_TXE 0x0F // I2C Tx empty #define FT_X_SERIES_CBUS_I2C_RXF 0x10 // I2C Rx full #define FT_X_SERIES_CBUS_VBUS_SENSE 0x11 // Detect VBUS #define FT_X_SERIES_CBUS_BITBANG_WR 0x12 // Bit-bang write strobe #define FT_X_SERIES_CBUS_BITBANG_RD 0x13 // Bit-bang read strobe #define FT_X_SERIES_CBUS_TIMESTAMP 0x14 // Toggle output when a USB SOF token is received #define FT_X_SERIES_CBUS_KEEP_AWAKE 0x15 // // Driver types #define FT_DRIVER_TYPE_D2XX 0 #define FT_DRIVER_TYPE_VCP 1 #ifdef __cplusplus extern "C" { #endif #ifdef FTD2XX_STATIC FTD2XX_API FT_STATUS WINAPI FT_Initialise( void ); FTD2XX_API void WINAPI FT_Finalise( void ); #endif // FTD2XX_STATIC FTD2XX_API FT_STATUS WINAPI FT_Open( int deviceNumber, FT_HANDLE *pHandle ); FTD2XX_API FT_STATUS WINAPI FT_OpenEx( PVOID pArg1, DWORD Flags, FT_HANDLE *pHandle ); FTD2XX_API FT_STATUS WINAPI FT_ListDevices( PVOID pArg1, PVOID pArg2, DWORD Flags ); FTD2XX_API FT_STATUS WINAPI FT_Close( FT_HANDLE ftHandle ); FTD2XX_API FT_STATUS WINAPI FT_Read( FT_HANDLE ftHandle, LPVOID lpBuffer, DWORD dwBytesToRead, LPDWORD lpBytesReturned ); FTD2XX_API FT_STATUS WINAPI FT_Write( FT_HANDLE ftHandle, LPVOID lpBuffer, DWORD dwBytesToWrite, LPDWORD lpBytesWritten ); FTD2XX_API FT_STATUS WINAPI FT_IoCtl( FT_HANDLE ftHandle, DWORD dwIoControlCode, LPVOID lpInBuf, DWORD nInBufSize, LPVOID lpOutBuf, DWORD nOutBufSize, LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped ); FTD2XX_API FT_STATUS WINAPI FT_SetBaudRate( FT_HANDLE ftHandle, ULONG BaudRate ); FTD2XX_API FT_STATUS WINAPI FT_SetDivisor( FT_HANDLE ftHandle, USHORT Divisor ); FTD2XX_API FT_STATUS WINAPI FT_SetDataCharacteristics( FT_HANDLE ftHandle, UCHAR WordLength, UCHAR StopBits, UCHAR Parity ); FTD2XX_API FT_STATUS WINAPI FT_SetFlowControl( FT_HANDLE ftHandle, USHORT FlowControl, UCHAR XonChar, UCHAR XoffChar ); FTD2XX_API FT_STATUS WINAPI FT_ResetDevice( FT_HANDLE ftHandle ); FTD2XX_API FT_STATUS WINAPI FT_SetDtr( FT_HANDLE ftHandle ); FTD2XX_API FT_STATUS WINAPI FT_ClrDtr( FT_HANDLE ftHandle ); FTD2XX_API FT_STATUS WINAPI FT_SetRts( FT_HANDLE ftHandle ); FTD2XX_API FT_STATUS WINAPI FT_ClrRts( FT_HANDLE ftHandle ); FTD2XX_API FT_STATUS WINAPI FT_GetModemStatus( FT_HANDLE ftHandle, ULONG *pModemStatus ); FTD2XX_API FT_STATUS WINAPI FT_SetChars( FT_HANDLE ftHandle, UCHAR EventChar, UCHAR EventCharEnabled, UCHAR ErrorChar, UCHAR ErrorCharEnabled ); FTD2XX_API FT_STATUS WINAPI FT_Purge( FT_HANDLE ftHandle, ULONG Mask ); FTD2XX_API FT_STATUS WINAPI FT_SetTimeouts( FT_HANDLE ftHandle, ULONG ReadTimeout, ULONG WriteTimeout ); FTD2XX_API FT_STATUS WINAPI FT_GetQueueStatus( FT_HANDLE ftHandle, DWORD *dwRxBytes ); FTD2XX_API FT_STATUS WINAPI FT_SetEventNotification( FT_HANDLE ftHandle, DWORD Mask, PVOID Param ); FTD2XX_API FT_STATUS WINAPI FT_GetStatus( FT_HANDLE ftHandle, DWORD *dwRxBytes, DWORD *dwTxBytes, DWORD *dwEventDWord ); FTD2XX_API FT_STATUS WINAPI FT_SetBreakOn( FT_HANDLE ftHandle ); FTD2XX_API FT_STATUS WINAPI FT_SetBreakOff( FT_HANDLE ftHandle ); FTD2XX_API FT_STATUS WINAPI FT_SetWaitMask( FT_HANDLE ftHandle, DWORD Mask ); FTD2XX_API FT_STATUS WINAPI FT_WaitOnMask( FT_HANDLE ftHandle, DWORD *Mask ); FTD2XX_API FT_STATUS WINAPI FT_GetEventStatus( FT_HANDLE ftHandle, DWORD *dwEventDWord ); FTD2XX_API FT_STATUS WINAPI FT_ReadEE( FT_HANDLE ftHandle, DWORD dwWordOffset, LPWORD lpwValue ); FTD2XX_API FT_STATUS WINAPI FT_WriteEE( FT_HANDLE ftHandle, DWORD dwWordOffset, WORD wValue ); FTD2XX_API FT_STATUS WINAPI FT_EraseEE( FT_HANDLE ftHandle ); // // structure to hold program data for FT_EE_Program, FT_EE_ProgramEx, FT_EE_Read // and FT_EE_ReadEx functions // typedef struct ft_program_data { DWORD Signature1; // Header - must be 0x00000000 DWORD Signature2; // Header - must be 0xffffffff DWORD Version; // Header - FT_PROGRAM_DATA version // 0 = original // 1 = FT2232 extensions // 2 = FT232R extensions // 3 = FT2232H extensions // 4 = FT4232H extensions // 5 = FT232H extensions WORD VendorId; // 0x0403 WORD ProductId; // 0x6001 char *Manufacturer; // "FTDI" char *ManufacturerId; // "FT" char *Description; // "USB HS Serial Converter" char *SerialNumber; // "FT000001" if fixed, or NULL WORD MaxPower; // 0 < MaxPower <= 500 WORD PnP; // 0 = disabled, 1 = enabled WORD SelfPowered; // 0 = bus powered, 1 = self powered WORD RemoteWakeup; // 0 = not capable, 1 = capable // // Rev4 (FT232B) extensions // UCHAR Rev4; // non-zero if Rev4 chip, zero otherwise UCHAR IsoIn; // non-zero if in endpoint is isochronous UCHAR IsoOut; // non-zero if out endpoint is isochronous UCHAR PullDownEnable; // non-zero if pull down enabled UCHAR SerNumEnable; // non-zero if serial number to be used UCHAR USBVersionEnable; // non-zero if chip uses USBVersion WORD USBVersion; // BCD (0x0200 => USB2) // // Rev 5 (FT2232) extensions // UCHAR Rev5; // non-zero if Rev5 chip, zero otherwise UCHAR IsoInA; // non-zero if in endpoint is isochronous UCHAR IsoInB; // non-zero if in endpoint is isochronous UCHAR IsoOutA; // non-zero if out endpoint is isochronous UCHAR IsoOutB; // non-zero if out endpoint is isochronous UCHAR PullDownEnable5; // non-zero if pull down enabled UCHAR SerNumEnable5; // non-zero if serial number to be used UCHAR USBVersionEnable5; // non-zero if chip uses USBVersion WORD USBVersion5; // BCD (0x0200 => USB2) UCHAR AIsHighCurrent; // non-zero if interface is high current UCHAR BIsHighCurrent; // non-zero if interface is high current UCHAR IFAIsFifo; // non-zero if interface is 245 FIFO UCHAR IFAIsFifoTar; // non-zero if interface is 245 FIFO CPU target UCHAR IFAIsFastSer; // non-zero if interface is Fast serial UCHAR AIsVCP; // non-zero if interface is to use VCP drivers UCHAR IFBIsFifo; // non-zero if interface is 245 FIFO UCHAR IFBIsFifoTar; // non-zero if interface is 245 FIFO CPU target UCHAR IFBIsFastSer; // non-zero if interface is Fast serial UCHAR BIsVCP; // non-zero if interface is to use VCP drivers // // Rev 6 (FT232R) extensions // UCHAR UseExtOsc; // Use External Oscillator UCHAR HighDriveIOs; // High Drive I/Os UCHAR EndpointSize; // Endpoint size UCHAR PullDownEnableR; // non-zero if pull down enabled UCHAR SerNumEnableR; // non-zero if serial number to be used UCHAR InvertTXD; // non-zero if invert TXD UCHAR InvertRXD; // non-zero if invert RXD UCHAR InvertRTS; // non-zero if invert RTS UCHAR InvertCTS; // non-zero if invert CTS UCHAR InvertDTR; // non-zero if invert DTR UCHAR InvertDSR; // non-zero if invert DSR UCHAR InvertDCD; // non-zero if invert DCD UCHAR InvertRI; // non-zero if invert RI UCHAR Cbus0; // Cbus Mux control UCHAR Cbus1; // Cbus Mux control UCHAR Cbus2; // Cbus Mux control UCHAR Cbus3; // Cbus Mux control UCHAR Cbus4; // Cbus Mux control UCHAR RIsD2XX; // non-zero if using D2XX driver // // Rev 7 (FT2232H) Extensions // UCHAR PullDownEnable7; // non-zero if pull down enabled UCHAR SerNumEnable7; // non-zero if serial number to be used UCHAR ALSlowSlew; // non-zero if AL pins have slow slew UCHAR ALSchmittInput; // non-zero if AL pins are Schmitt input UCHAR ALDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA UCHAR AHSlowSlew; // non-zero if AH pins have slow slew UCHAR AHSchmittInput; // non-zero if AH pins are Schmitt input UCHAR AHDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA UCHAR BLSlowSlew; // non-zero if BL pins have slow slew UCHAR BLSchmittInput; // non-zero if BL pins are Schmitt input UCHAR BLDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA UCHAR BHSlowSlew; // non-zero if BH pins have slow slew UCHAR BHSchmittInput; // non-zero if BH pins are Schmitt input UCHAR BHDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA UCHAR IFAIsFifo7; // non-zero if interface is 245 FIFO UCHAR IFAIsFifoTar7; // non-zero if interface is 245 FIFO CPU target UCHAR IFAIsFastSer7; // non-zero if interface is Fast serial UCHAR AIsVCP7; // non-zero if interface is to use VCP drivers UCHAR IFBIsFifo7; // non-zero if interface is 245 FIFO UCHAR IFBIsFifoTar7; // non-zero if interface is 245 FIFO CPU target UCHAR IFBIsFastSer7; // non-zero if interface is Fast serial UCHAR BIsVCP7; // non-zero if interface is to use VCP drivers UCHAR PowerSaveEnable; // non-zero if using BCBUS7 to save power for self-powered designs // // Rev 8 (FT4232H) Extensions // UCHAR PullDownEnable8; // non-zero if pull down enabled UCHAR SerNumEnable8; // non-zero if serial number to be used UCHAR ASlowSlew; // non-zero if A pins have slow slew UCHAR ASchmittInput; // non-zero if A pins are Schmitt input UCHAR ADriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA UCHAR BSlowSlew; // non-zero if B pins have slow slew UCHAR BSchmittInput; // non-zero if B pins are Schmitt input UCHAR BDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA UCHAR CSlowSlew; // non-zero if C pins have slow slew UCHAR CSchmittInput; // non-zero if C pins are Schmitt input UCHAR CDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA UCHAR DSlowSlew; // non-zero if D pins have slow slew UCHAR DSchmittInput; // non-zero if D pins are Schmitt input UCHAR DDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA UCHAR ARIIsTXDEN; // non-zero if port A uses RI as RS485 TXDEN UCHAR BRIIsTXDEN; // non-zero if port B uses RI as RS485 TXDEN UCHAR CRIIsTXDEN; // non-zero if port C uses RI as RS485 TXDEN UCHAR DRIIsTXDEN; // non-zero if port D uses RI as RS485 TXDEN UCHAR AIsVCP8; // non-zero if interface is to use VCP drivers UCHAR BIsVCP8; // non-zero if interface is to use VCP drivers UCHAR CIsVCP8; // non-zero if interface is to use VCP drivers UCHAR DIsVCP8; // non-zero if interface is to use VCP drivers // // Rev 9 (FT232H) Extensions // UCHAR PullDownEnableH; // non-zero if pull down enabled UCHAR SerNumEnableH; // non-zero if serial number to be used UCHAR ACSlowSlewH; // non-zero if AC pins have slow slew UCHAR ACSchmittInputH; // non-zero if AC pins are Schmitt input UCHAR ACDriveCurrentH; // valid values are 4mA, 8mA, 12mA, 16mA UCHAR ADSlowSlewH; // non-zero if AD pins have slow slew UCHAR ADSchmittInputH; // non-zero if AD pins are Schmitt input UCHAR ADDriveCurrentH; // valid values are 4mA, 8mA, 12mA, 16mA UCHAR Cbus0H; // Cbus Mux control UCHAR Cbus1H; // Cbus Mux control UCHAR Cbus2H; // Cbus Mux control UCHAR Cbus3H; // Cbus Mux control UCHAR Cbus4H; // Cbus Mux control UCHAR Cbus5H; // Cbus Mux control UCHAR Cbus6H; // Cbus Mux control UCHAR Cbus7H; // Cbus Mux control UCHAR Cbus8H; // Cbus Mux control UCHAR Cbus9H; // Cbus Mux control UCHAR IsFifoH; // non-zero if interface is 245 FIFO UCHAR IsFifoTarH; // non-zero if interface is 245 FIFO CPU target UCHAR IsFastSerH; // non-zero if interface is Fast serial UCHAR IsFT1248H; // non-zero if interface is FT1248 UCHAR FT1248CpolH; // FT1248 clock polarity - clock idle high (1) or clock idle low (0) UCHAR FT1248LsbH; // FT1248 data is LSB (1) or MSB (0) UCHAR FT1248FlowControlH; // FT1248 flow control enable UCHAR IsVCPH; // non-zero if interface is to use VCP drivers UCHAR PowerSaveEnableH; // non-zero if using ACBUS7 to save power for self-powered designs } FT_PROGRAM_DATA, *PFT_PROGRAM_DATA; FTD2XX_API FT_STATUS WINAPI FT_EE_Program( FT_HANDLE ftHandle, PFT_PROGRAM_DATA pData ); FTD2XX_API FT_STATUS WINAPI FT_EE_ProgramEx( FT_HANDLE ftHandle, PFT_PROGRAM_DATA pData, char *Manufacturer, char *ManufacturerId, char *Description, char *SerialNumber ); FTD2XX_API FT_STATUS WINAPI FT_EE_Read( FT_HANDLE ftHandle, PFT_PROGRAM_DATA pData ); FTD2XX_API FT_STATUS WINAPI FT_EE_ReadEx( FT_HANDLE ftHandle, PFT_PROGRAM_DATA pData, char *Manufacturer, char *ManufacturerId, char *Description, char *SerialNumber ); FTD2XX_API FT_STATUS WINAPI FT_EE_UASize( FT_HANDLE ftHandle, LPDWORD lpdwSize ); FTD2XX_API FT_STATUS WINAPI FT_EE_UAWrite( FT_HANDLE ftHandle, PUCHAR pucData, DWORD dwDataLen ); FTD2XX_API FT_STATUS WINAPI FT_EE_UARead( FT_HANDLE ftHandle, PUCHAR pucData, DWORD dwDataLen, LPDWORD lpdwBytesRead ); typedef struct ft_eeprom_header { FT_DEVICE deviceType; // FTxxxx device type to be programmed // Device descriptor options WORD VendorId; // 0x0403 WORD ProductId; // 0x6001 UCHAR SerNumEnable; // non-zero if serial number to be used // Config descriptor options WORD MaxPower; // 0 < MaxPower <= 500 UCHAR SelfPowered; // 0 = bus powered, 1 = self powered UCHAR RemoteWakeup; // 0 = not capable, 1 = capable // Hardware options UCHAR PullDownEnable; // non-zero if pull down in suspend enabled } FT_EEPROM_HEADER, *PFT_EEPROM_HEADER; // FT232B EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program typedef struct ft_eeprom_232b { // Common header FT_EEPROM_HEADER common; // common elements for all device EEPROMs } FT_EEPROM_232B, *PFT_EEPROM_232B; // FT2232 EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program typedef struct ft_eeprom_2232 { // Common header FT_EEPROM_HEADER common; // common elements for all device EEPROMs // Drive options UCHAR AIsHighCurrent; // non-zero if interface is high current UCHAR BIsHighCurrent; // non-zero if interface is high current // Hardware options UCHAR AIsFifo; // non-zero if interface is 245 FIFO UCHAR AIsFifoTar; // non-zero if interface is 245 FIFO CPU target UCHAR AIsFastSer; // non-zero if interface is Fast serial UCHAR BIsFifo; // non-zero if interface is 245 FIFO UCHAR BIsFifoTar; // non-zero if interface is 245 FIFO CPU target UCHAR BIsFastSer; // non-zero if interface is Fast serial // Driver option UCHAR ADriverType; // UCHAR BDriverType; // } FT_EEPROM_2232, *PFT_EEPROM_2232; // FT232R EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program typedef struct ft_eeprom_232r { // Common header FT_EEPROM_HEADER common; // common elements for all device EEPROMs // Drive options UCHAR IsHighCurrent; // non-zero if interface is high current // Hardware options UCHAR UseExtOsc; // Use External Oscillator UCHAR InvertTXD; // non-zero if invert TXD UCHAR InvertRXD; // non-zero if invert RXD UCHAR InvertRTS; // non-zero if invert RTS UCHAR InvertCTS; // non-zero if invert CTS UCHAR InvertDTR; // non-zero if invert DTR UCHAR InvertDSR; // non-zero if invert DSR UCHAR InvertDCD; // non-zero if invert DCD UCHAR InvertRI; // non-zero if invert RI UCHAR Cbus0; // Cbus Mux control UCHAR Cbus1; // Cbus Mux control UCHAR Cbus2; // Cbus Mux control UCHAR Cbus3; // Cbus Mux control UCHAR Cbus4; // Cbus Mux control // Driver option UCHAR DriverType; // } FT_EEPROM_232R, *PFT_EEPROM_232R; // FT2232H EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program typedef struct ft_eeprom_2232h { // Common header FT_EEPROM_HEADER common; // common elements for all device EEPROMs // Drive options UCHAR ALSlowSlew; // non-zero if AL pins have slow slew UCHAR ALSchmittInput; // non-zero if AL pins are Schmitt input UCHAR ALDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA UCHAR AHSlowSlew; // non-zero if AH pins have slow slew UCHAR AHSchmittInput; // non-zero if AH pins are Schmitt input UCHAR AHDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA UCHAR BLSlowSlew; // non-zero if BL pins have slow slew UCHAR BLSchmittInput; // non-zero if BL pins are Schmitt input UCHAR BLDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA UCHAR BHSlowSlew; // non-zero if BH pins have slow slew UCHAR BHSchmittInput; // non-zero if BH pins are Schmitt input UCHAR BHDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA // Hardware options UCHAR AIsFifo; // non-zero if interface is 245 FIFO UCHAR AIsFifoTar; // non-zero if interface is 245 FIFO CPU target UCHAR AIsFastSer; // non-zero if interface is Fast serial UCHAR BIsFifo; // non-zero if interface is 245 FIFO UCHAR BIsFifoTar; // non-zero if interface is 245 FIFO CPU target UCHAR BIsFastSer; // non-zero if interface is Fast serial UCHAR PowerSaveEnable; // non-zero if using BCBUS7 to save power for self-powered designs // Driver option UCHAR ADriverType; // UCHAR BDriverType; // } FT_EEPROM_2232H, *PFT_EEPROM_2232H; // FT4232H EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program typedef struct ft_eeprom_4232h { // Common header FT_EEPROM_HEADER common; // common elements for all device EEPROMs // Drive options UCHAR ASlowSlew; // non-zero if A pins have slow slew UCHAR ASchmittInput; // non-zero if A pins are Schmitt input UCHAR ADriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA UCHAR BSlowSlew; // non-zero if B pins have slow slew UCHAR BSchmittInput; // non-zero if B pins are Schmitt input UCHAR BDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA UCHAR CSlowSlew; // non-zero if C pins have slow slew UCHAR CSchmittInput; // non-zero if C pins are Schmitt input UCHAR CDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA UCHAR DSlowSlew; // non-zero if D pins have slow slew UCHAR DSchmittInput; // non-zero if D pins are Schmitt input UCHAR DDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA // Hardware options UCHAR ARIIsTXDEN; // non-zero if port A uses RI as RS485 TXDEN UCHAR BRIIsTXDEN; // non-zero if port B uses RI as RS485 TXDEN UCHAR CRIIsTXDEN; // non-zero if port C uses RI as RS485 TXDEN UCHAR DRIIsTXDEN; // non-zero if port D uses RI as RS485 TXDEN // Driver option UCHAR ADriverType; // UCHAR BDriverType; // UCHAR CDriverType; // UCHAR DDriverType; // } FT_EEPROM_4232H, *PFT_EEPROM_4232H; // FT232H EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program typedef struct ft_eeprom_232h { // Common header FT_EEPROM_HEADER common; // common elements for all device EEPROMs // Drive options UCHAR ACSlowSlew; // non-zero if AC bus pins have slow slew UCHAR ACSchmittInput; // non-zero if AC bus pins are Schmitt input UCHAR ACDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA UCHAR ADSlowSlew; // non-zero if AD bus pins have slow slew UCHAR ADSchmittInput; // non-zero if AD bus pins are Schmitt input UCHAR ADDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA // CBUS options UCHAR Cbus0; // Cbus Mux control UCHAR Cbus1; // Cbus Mux control UCHAR Cbus2; // Cbus Mux control UCHAR Cbus3; // Cbus Mux control UCHAR Cbus4; // Cbus Mux control UCHAR Cbus5; // Cbus Mux control UCHAR Cbus6; // Cbus Mux control UCHAR Cbus7; // Cbus Mux control UCHAR Cbus8; // Cbus Mux control UCHAR Cbus9; // Cbus Mux control // FT1248 options UCHAR FT1248Cpol; // FT1248 clock polarity - clock idle high (1) or clock idle low (0) UCHAR FT1248Lsb; // FT1248 data is LSB (1) or MSB (0) UCHAR FT1248FlowControl; // FT1248 flow control enable // Hardware options UCHAR IsFifo; // non-zero if interface is 245 FIFO UCHAR IsFifoTar; // non-zero if interface is 245 FIFO CPU target UCHAR IsFastSer; // non-zero if interface is Fast serial UCHAR IsFT1248 ; // non-zero if interface is FT1248 UCHAR PowerSaveEnable; // // Driver option UCHAR DriverType; // } FT_EEPROM_232H, *PFT_EEPROM_232H; // FT X Series EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program typedef struct ft_eeprom_x_series { // Common header FT_EEPROM_HEADER common; // common elements for all device EEPROMs // Drive options UCHAR ACSlowSlew; // non-zero if AC bus pins have slow slew UCHAR ACSchmittInput; // non-zero if AC bus pins are Schmitt input UCHAR ACDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA UCHAR ADSlowSlew; // non-zero if AD bus pins have slow slew UCHAR ADSchmittInput; // non-zero if AD bus pins are Schmitt input UCHAR ADDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA // CBUS options UCHAR Cbus0; // Cbus Mux control UCHAR Cbus1; // Cbus Mux control UCHAR Cbus2; // Cbus Mux control UCHAR Cbus3; // Cbus Mux control UCHAR Cbus4; // Cbus Mux control UCHAR Cbus5; // Cbus Mux control UCHAR Cbus6; // Cbus Mux control // UART signal options UCHAR InvertTXD; // non-zero if invert TXD UCHAR InvertRXD; // non-zero if invert RXD UCHAR InvertRTS; // non-zero if invert RTS UCHAR InvertCTS; // non-zero if invert CTS UCHAR InvertDTR; // non-zero if invert DTR UCHAR InvertDSR; // non-zero if invert DSR UCHAR InvertDCD; // non-zero if invert DCD UCHAR InvertRI; // non-zero if invert RI // Battery Charge Detect options UCHAR BCDEnable; // Enable Battery Charger Detection UCHAR BCDForceCbusPWREN; // asserts the power enable signal on CBUS when charging port detected UCHAR BCDDisableSleep; // forces the device never to go into sleep mode // I2C options WORD I2CSlaveAddress; // I2C slave device address DWORD I2CDeviceId; // I2C device ID UCHAR I2CDisableSchmitt; // Disable I2C Schmitt trigger // FT1248 options UCHAR FT1248Cpol; // FT1248 clock polarity - clock idle high (1) or clock idle low (0) UCHAR FT1248Lsb; // FT1248 data is LSB (1) or MSB (0) UCHAR FT1248FlowControl; // FT1248 flow control enable // Hardware options UCHAR RS485EchoSuppress; // UCHAR PowerSaveEnable; // // Driver option UCHAR DriverType; // } FT_EEPROM_X_SERIES, *PFT_EEPROM_X_SERIES; FTD2XX_API FT_STATUS WINAPI FT_EEPROM_Read( FT_HANDLE ftHandle, void *eepromData, DWORD eepromDataSize, char *Manufacturer, char *ManufacturerId, char *Description, char *SerialNumber ); FTD2XX_API FT_STATUS WINAPI FT_EEPROM_Program( FT_HANDLE ftHandle, void *eepromData, DWORD eepromDataSize, char *Manufacturer, char *ManufacturerId, char *Description, char *SerialNumber ); FTD2XX_API FT_STATUS WINAPI FT_SetLatencyTimer( FT_HANDLE ftHandle, UCHAR ucLatency ); FTD2XX_API FT_STATUS WINAPI FT_GetLatencyTimer( FT_HANDLE ftHandle, PUCHAR pucLatency ); FTD2XX_API FT_STATUS WINAPI FT_SetBitMode( FT_HANDLE ftHandle, UCHAR ucMask, UCHAR ucEnable ); FTD2XX_API FT_STATUS WINAPI FT_GetBitMode( FT_HANDLE ftHandle, PUCHAR pucMode ); FTD2XX_API FT_STATUS WINAPI FT_SetUSBParameters( FT_HANDLE ftHandle, ULONG ulInTransferSize, ULONG ulOutTransferSize ); FTD2XX_API FT_STATUS WINAPI FT_SetDeadmanTimeout( FT_HANDLE ftHandle, ULONG ulDeadmanTimeout ); #ifndef _WIN32 // Extra functions for non-Windows platforms to compensate // for lack of .INF file to specify Vendor and Product IDs. FTD2XX_API FT_STATUS FT_SetVIDPID( DWORD dwVID, DWORD dwPID ); FTD2XX_API FT_STATUS FT_GetVIDPID( DWORD * pdwVID, DWORD * pdwPID ); FTD2XX_API FT_STATUS WINAPI FT_GetDeviceLocId( FT_HANDLE ftHandle, LPDWORD lpdwLocId ); #endif // _WIN32 FTD2XX_API FT_STATUS WINAPI FT_GetDeviceInfo( FT_HANDLE ftHandle, FT_DEVICE *lpftDevice, LPDWORD lpdwID, PCHAR SerialNumber, PCHAR Description, LPVOID Dummy ); FTD2XX_API FT_STATUS WINAPI FT_StopInTask( FT_HANDLE ftHandle ); FTD2XX_API FT_STATUS WINAPI FT_RestartInTask( FT_HANDLE ftHandle ); FTD2XX_API FT_STATUS WINAPI FT_SetResetPipeRetryCount( FT_HANDLE ftHandle, DWORD dwCount ); FTD2XX_API FT_STATUS WINAPI FT_ResetPort( FT_HANDLE ftHandle ); FTD2XX_API FT_STATUS WINAPI FT_CyclePort( FT_HANDLE ftHandle ); // // Win32-type functions // FTD2XX_API FT_HANDLE WINAPI FT_W32_CreateFile( LPCTSTR lpszName, DWORD dwAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreate, DWORD dwAttrsAndFlags, HANDLE hTemplate ); FTD2XX_API BOOL WINAPI FT_W32_CloseHandle( FT_HANDLE ftHandle ); FTD2XX_API BOOL WINAPI FT_W32_ReadFile( FT_HANDLE ftHandle, LPVOID lpBuffer, DWORD nBufferSize, LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped ); FTD2XX_API BOOL WINAPI FT_W32_WriteFile( FT_HANDLE ftHandle, LPVOID lpBuffer, DWORD nBufferSize, LPDWORD lpBytesWritten, LPOVERLAPPED lpOverlapped ); FTD2XX_API DWORD WINAPI FT_W32_GetLastError( FT_HANDLE ftHandle ); FTD2XX_API BOOL WINAPI FT_W32_GetOverlappedResult( FT_HANDLE ftHandle, LPOVERLAPPED lpOverlapped, LPDWORD lpdwBytesTransferred, BOOL bWait ); FTD2XX_API BOOL WINAPI FT_W32_CancelIo( FT_HANDLE ftHandle ); // // Win32 COMM API type functions // typedef struct _FTCOMSTAT { DWORD fCtsHold : 1; DWORD fDsrHold : 1; DWORD fRlsdHold : 1; DWORD fXoffHold : 1; DWORD fXoffSent : 1; DWORD fEof : 1; DWORD fTxim : 1; DWORD fReserved : 25; DWORD cbInQue; DWORD cbOutQue; } FTCOMSTAT, *LPFTCOMSTAT; typedef struct _FTDCB { DWORD DCBlength; /* sizeof(FTDCB) */ DWORD BaudRate; /* Baudrate at which running */ DWORD fBinary: 1; /* Binary Mode (skip EOF check) */ DWORD fParity: 1; /* Enable parity checking */ DWORD fOutxCtsFlow:1; /* CTS handshaking on output */ DWORD fOutxDsrFlow:1; /* DSR handshaking on output */ DWORD fDtrControl:2; /* DTR Flow control */ DWORD fDsrSensitivity:1; /* DSR Sensitivity */ DWORD fTXContinueOnXoff: 1; /* Continue TX when Xoff sent */ DWORD fOutX: 1; /* Enable output X-ON/X-OFF */ DWORD fInX: 1; /* Enable input X-ON/X-OFF */ DWORD fErrorChar: 1; /* Enable Err Replacement */ DWORD fNull: 1; /* Enable Null stripping */ DWORD fRtsControl:2; /* Rts Flow control */ DWORD fAbortOnError:1; /* Abort all reads and writes on Error */ DWORD fDummy2:17; /* Reserved */ WORD wReserved; /* Not currently used */ WORD XonLim; /* Transmit X-ON threshold */ WORD XoffLim; /* Transmit X-OFF threshold */ BYTE ByteSize; /* Number of bits/byte, 4-8 */ BYTE Parity; /* 0-4=None,Odd,Even,Mark,Space */ BYTE StopBits; /* FT_STOP_BITS_1 or FT_STOP_BITS_2 */ char XonChar; /* Tx and Rx X-ON character */ char XoffChar; /* Tx and Rx X-OFF character */ char ErrorChar; /* Error replacement char */ char EofChar; /* End of Input character */ char EvtChar; /* Received Event character */ WORD wReserved1; /* Fill for now. */ } FTDCB, *LPFTDCB; typedef struct _FTTIMEOUTS { DWORD ReadIntervalTimeout; /* Maximum time between read chars. */ DWORD ReadTotalTimeoutMultiplier; /* Multiplier of characters. */ DWORD ReadTotalTimeoutConstant; /* Constant in milliseconds. */ DWORD WriteTotalTimeoutMultiplier; /* Multiplier of characters. */ DWORD WriteTotalTimeoutConstant; /* Constant in milliseconds. */ } FTTIMEOUTS,*LPFTTIMEOUTS; FTD2XX_API BOOL WINAPI FT_W32_ClearCommBreak( FT_HANDLE ftHandle ); FTD2XX_API BOOL WINAPI FT_W32_ClearCommError( FT_HANDLE ftHandle, LPDWORD lpdwErrors, LPFTCOMSTAT lpftComstat ); FTD2XX_API BOOL WINAPI FT_W32_EscapeCommFunction( FT_HANDLE ftHandle, DWORD dwFunc ); FTD2XX_API BOOL WINAPI FT_W32_GetCommModemStatus( FT_HANDLE ftHandle, LPDWORD lpdwModemStatus ); FTD2XX_API BOOL WINAPI FT_W32_GetCommState( FT_HANDLE ftHandle, LPFTDCB lpftDcb ); FTD2XX_API BOOL WINAPI FT_W32_GetCommTimeouts( FT_HANDLE ftHandle, FTTIMEOUTS *pTimeouts ); FTD2XX_API BOOL WINAPI FT_W32_PurgeComm( FT_HANDLE ftHandle, DWORD dwMask ); FTD2XX_API BOOL WINAPI FT_W32_SetCommBreak( FT_HANDLE ftHandle ); FTD2XX_API BOOL WINAPI FT_W32_SetCommMask( FT_HANDLE ftHandle, ULONG ulEventMask ); FTD2XX_API BOOL WINAPI FT_W32_GetCommMask( FT_HANDLE ftHandle, LPDWORD lpdwEventMask ); FTD2XX_API BOOL WINAPI FT_W32_SetCommState( FT_HANDLE ftHandle, LPFTDCB lpftDcb ); FTD2XX_API BOOL WINAPI FT_W32_SetCommTimeouts( FT_HANDLE ftHandle, FTTIMEOUTS *pTimeouts ); FTD2XX_API BOOL WINAPI FT_W32_SetupComm( FT_HANDLE ftHandle, DWORD dwReadBufferSize, DWORD dwWriteBufferSize ); FTD2XX_API BOOL WINAPI FT_W32_WaitCommEvent( FT_HANDLE ftHandle, PULONG pulEvent, LPOVERLAPPED lpOverlapped ); // // Device information // typedef struct _ft_device_list_info_node { ULONG Flags; ULONG Type; ULONG ID; DWORD LocId; char SerialNumber[16]; char Description[64]; FT_HANDLE ftHandle; } FT_DEVICE_LIST_INFO_NODE; // Device information flags enum { FT_FLAGS_OPENED = 1, FT_FLAGS_HISPEED = 2 }; FTD2XX_API FT_STATUS WINAPI FT_CreateDeviceInfoList( LPDWORD lpdwNumDevs ); FTD2XX_API FT_STATUS WINAPI FT_GetDeviceInfoList( FT_DEVICE_LIST_INFO_NODE *pDest, LPDWORD lpdwNumDevs ); FTD2XX_API FT_STATUS WINAPI FT_GetDeviceInfoDetail( DWORD dwIndex, LPDWORD lpdwFlags, LPDWORD lpdwType, LPDWORD lpdwID, LPDWORD lpdwLocId, LPVOID lpSerialNumber, LPVOID lpDescription, FT_HANDLE *pftHandle ); // // Version information // FTD2XX_API FT_STATUS WINAPI FT_GetDriverVersion( FT_HANDLE ftHandle, LPDWORD lpdwVersion ); FTD2XX_API FT_STATUS WINAPI FT_GetLibraryVersion( LPDWORD lpdwVersion ); FTD2XX_API FT_STATUS WINAPI FT_Rescan( void ); FTD2XX_API FT_STATUS WINAPI FT_Reload( WORD wVid, WORD wPid ); FTD2XX_API FT_STATUS WINAPI FT_GetComPortNumber( FT_HANDLE ftHandle, LPLONG lpdwComPortNumber ); // // FT232H additional EEPROM functions // FTD2XX_API FT_STATUS WINAPI FT_EE_ReadConfig( FT_HANDLE ftHandle, UCHAR ucAddress, PUCHAR pucValue ); FTD2XX_API FT_STATUS WINAPI FT_EE_WriteConfig( FT_HANDLE ftHandle, UCHAR ucAddress, UCHAR ucValue ); FTD2XX_API FT_STATUS WINAPI FT_EE_ReadECC( FT_HANDLE ftHandle, UCHAR ucOption, LPWORD lpwValue ); FTD2XX_API FT_STATUS WINAPI FT_GetQueueStatusEx( FT_HANDLE ftHandle, DWORD *dwRxBytes ); FTD2XX_API FT_STATUS WINAPI FT_ComPortIdle( FT_HANDLE ftHandle ); FTD2XX_API FT_STATUS WINAPI FT_ComPortCancelIdle( FT_HANDLE ftHandle ); FTD2XX_API FT_STATUS WINAPI FT_VendorCmdGet( FT_HANDLE ftHandle, UCHAR Request, UCHAR *Buf, USHORT Len ); FTD2XX_API FT_STATUS WINAPI FT_VendorCmdSet( FT_HANDLE ftHandle, UCHAR Request, UCHAR *Buf, USHORT Len ); FTD2XX_API FT_STATUS WINAPI FT_VendorCmdGetEx( FT_HANDLE ftHandle, USHORT wValue, UCHAR *Buf, USHORT Len ); FTD2XX_API FT_STATUS WINAPI FT_VendorCmdSetEx( FT_HANDLE ftHandle, USHORT wValue, UCHAR *Buf, USHORT Len ); #ifdef __cplusplus } #endif #endif /* FTD2XX_H */ |
【関連投稿】
NXP JN516X (TWELITE) をプログラミングする(開発環境の構築)
NXP JN516X (TWELITE) をプログラミングする(メイン・ルーチン)
NXP JN516X (TWELITE) をプログラミングする(TICKTIMER)
NXP JN516X (TWELITE) をプログラミングする(UART)
NXP JN516X (TWELITE) をプログラミングする(SYSTEM)
NXP JN516X (TWELITE) をプログラミングする(GPIO)
NXP JN516X (TWELITE) をプログラミングする(TIMER)
NXP JN516X (TWELITE) をプログラミングする(ALARM)
NXP JN516X (TWELITE) をプログラミングする(WAKETIMER)
NXP JN516X (TWELITE) をプログラミングする(WATCHDOG)
NXP JN516X (TWELITE) をプログラミングする(I2C)
NXP JN516X (TWELITE) をプログラミングする(SPI)
NXP JN516X (TWELITE) をプログラミングする(ADC)
NXP JN516X (TWELITE) をプログラミングする(COMPARATOR)
NXP JN516X (TWELITE) をプログラミングする(CLOCK)
NXP JN516X (TWELITE) をプログラミングする(BROWNOUT)
NXP JN516X (TWELITE) をプログラミングする(PULSCOUNTER)
NXP JN516X (TWELITE) をプログラミングする(INFRARED)
NXP JN516X (TWELITE) をプログラミングする(RANDOM-GENERATOR)
NXP JN516X (TWELITE) をプログラミングする(FLASH)
NXP JN516X (TWELITE) をプログラミングする(EEPROM)
NXP JN516X (TWELITE) をプログラミングする(WPAN)
NXP JN516X (TWELITE) をプログラミングする(Eclipse-CDT+MWSTAGE)
NXP JN516X (TWELITE) をプログラミングする(乗算と除算)
NXP JN516X (TWELITE) をプログラミングする(マルチタスク)
NXP JN516X (TWELITE) をプログラミングする(フラッシュ・プログラマー)
NXP JN516X (TWELITE) をプログラミングする(OTA UPDATE)
NXP JN516X (TWELITE) をプログラミングする(TWELITE CUE/MC3630)
NXP JN516X (TWELITE) をプログラミングする(LED)
NXP JN516X (TWELITE) をプログラミングする(AES)
NXP JN516X (TWELITE) をプログラミングする(Downloads)