Windows: Display error code in default case of windows_transfer_callback
[libusbx.git] / examples / ezusb.h
blob5ea42376676a13818c44e59aae67802d72ef0ad3
1 #ifndef __ezusb_H
2 #define __ezusb_H
3 /*
4 * Copyright © 2001 Stephen Williams (steve@icarus.com)
5 * Copyright © 2002 David Brownell (dbrownell@users.sourceforge.net)
7 * This source code is free software; you can redistribute it
8 * and/or modify it in source code form under the terms of the GNU
9 * General Public License as published by the Free Software
10 * Foundation; either version 2 of the License, or (at your option)
11 * any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22 #if !defined(_MSC_VER)
23 #include <stdbool.h>
24 #else
25 #define __attribute__(x)
26 #if !defined(bool)
27 #define bool int
28 #endif
29 #if !defined(true)
30 #define true (1 == 1)
31 #endif
32 #if !defined(false)
33 #define false (!true)
34 #endif
35 #if defined(_PREFAST_)
36 #pragma warning(disable:28193)
37 #endif
38 #endif
40 #define FX_TYPE_UNDEFINED -1
41 #define FX_TYPE_AN21 0 /* Original AnchorChips parts */
42 #define FX_TYPE_FX1 1 /* Updated Cypress versions */
43 #define FX_TYPE_FX2 2 /* USB 2.0 versions */
44 #define FX_TYPE_FX2LP 3 /* Updated FX2 */
45 #define FX_TYPE_MAX 4
46 #define FX_TYPE_NAMES { "an21", "fx", "fx2", "fx2lp" }
48 #define IMG_TYPE_UNDEFINED -1
49 #define IMG_TYPE_HEX 0 /* Intel HEX */
50 #define IMG_TYPE_IIC 1 /* Cypress 8051 IIC */
51 #define IMG_TYPE_BIX 2 /* Cypress 8051 BIX */
52 #define IMG_TYPE_MAX 3
53 #define IMG_TYPE_NAMES { "Intel HEX", "Cypress 8051 IIC", "Cypress 8051 BIX" }
55 /*
56 * Automatically identified devices (VID, PID, type, designation).
57 * TODO: Could use some validation. Also where's the FX2?
59 typedef struct {
60 uint16_t vid;
61 uint16_t pid;
62 int type;
63 const char* designation;
64 } fx_known_device;
66 #define FX_KNOWN_DEVICES { \
67 { 0x0547, 0x2122, FX_TYPE_AN21, "Cypress EZ-USB (2122S)" },\
68 { 0x0547, 0x2125, FX_TYPE_AN21, "Cypress EZ-USB (2121S/2125S)" },\
69 { 0x0547, 0x2126, FX_TYPE_AN21, "Cypress EZ-USB (2126S)" },\
70 { 0x0547, 0x2131, FX_TYPE_AN21, "Cypress EZ-USB (2131Q/2131S/2135S)" },\
71 { 0x0547, 0x2136, FX_TYPE_AN21, "Cypress EZ-USB (2136S)" },\
72 { 0x0547, 0x2225, FX_TYPE_AN21, "Cypress EZ-USB (2225)" },\
73 { 0x0547, 0x2226, FX_TYPE_AN21, "Cypress EZ-USB (2226)" },\
74 { 0x0547, 0x2235, FX_TYPE_AN21, "Cypress EZ-USB (2235)" },\
75 { 0x0547, 0x2236, FX_TYPE_AN21, "Cypress EZ-USB (2236)" },\
76 { 0x04b4, 0x6473, FX_TYPE_FX1, "Cypress EZ-USB FX1" },\
77 { 0x04b4, 0x8613, FX_TYPE_FX2LP, "Cypress EZ-USB FX2LP (68013A/68014A/68015A/68016A)" }, \
81 * This function uploads the firmware from the given file into RAM.
82 * Stage == 0 means this is a single stage load (or the first of
83 * two stages). Otherwise it's the second of two stages; the
84 * caller having preloaded the second stage loader.
86 * The target processor is reset at the end of this upload.
88 extern int ezusb_load_ram(libusb_device_handle *device,
89 const char *path, int fx_type, int img_type, int stage);
92 * This function uploads the firmware from the given file into EEPROM.
93 * This uses the right CPUCS address to terminate the EEPROM load with
94 * a reset command where FX parts behave differently than FX2 ones.
95 * The configuration byte is as provided here (zero for an21xx parts)
96 * and the EEPROM type is set so that the microcontroller will boot
97 * from it.
99 * The caller must have preloaded a second stage loader that knows
100 * how to respond to the EEPROM write request.
102 extern int ezusb_load_eeprom(libusb_device_handle *device,
103 const char *path, int fx_type, int img_type, int config);
105 /* boolean flag, says whether to write extra messages to stderr */
106 extern int verbose;
107 #endif