blob: 62062c41c4b4e17d9db548d422b2d60ee00474ca [file] [log] [blame]
Sean McBride8e1a2822016-09-14 12:45:39 -04001#ifndef ezusb_H
2#define ezusb_H
Pete Batard05975332012-09-11 01:01:07 +01003/*
4 * Copyright © 2001 Stephen Williams (steve@icarus.com)
5 * Copyright © 2002 David Brownell (dbrownell@users.sourceforge.net)
Federico Manzanb74b7f72013-03-10 21:00:00 +00006 * Copyright © 2013 Federico Manzan (f.manzan@gmail.com)
Pete Batard05975332012-09-11 01:01:07 +01007 *
8 * This source code is free software; you can redistribute it
9 * and/or modify it in source code form under the terms of the GNU
10 * General Public License as published by the Free Software
11 * Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22 */
Chris Dickensf90d0762020-01-20 18:02:19 -080023
Chris Dickensf2e551a2020-11-27 15:22:29 -080024#include <config.h>
Pete Batard05975332012-09-11 01:01:07 +010025
Chris Dickensf90d0762020-01-20 18:02:19 -080026#include <stdbool.h>
27
Pete Batard05975332012-09-11 01:01:07 +010028#define FX_TYPE_UNDEFINED -1
29#define FX_TYPE_AN21 0 /* Original AnchorChips parts */
30#define FX_TYPE_FX1 1 /* Updated Cypress versions */
31#define FX_TYPE_FX2 2 /* USB 2.0 versions */
32#define FX_TYPE_FX2LP 3 /* Updated FX2 */
Federico Manzanb74b7f72013-03-10 21:00:00 +000033#define FX_TYPE_FX3 4 /* USB 3.0 versions */
34#define FX_TYPE_MAX 5
35#define FX_TYPE_NAMES { "an21", "fx", "fx2", "fx2lp", "fx3" }
Pete Batard05975332012-09-11 01:01:07 +010036
37#define IMG_TYPE_UNDEFINED -1
38#define IMG_TYPE_HEX 0 /* Intel HEX */
39#define IMG_TYPE_IIC 1 /* Cypress 8051 IIC */
40#define IMG_TYPE_BIX 2 /* Cypress 8051 BIX */
Federico Manzanb74b7f72013-03-10 21:00:00 +000041#define IMG_TYPE_IMG 3 /* Cypress IMG format */
42#define IMG_TYPE_MAX 4
43#define IMG_TYPE_NAMES { "Intel HEX", "Cypress 8051 IIC", "Cypress 8051 BIX", "Cypress IMG format" }
Pete Batard05975332012-09-11 01:01:07 +010044
Federico Manzand345a1e2013-03-10 07:56:56 +000045#ifdef __cplusplus
46extern "C" {
47#endif
48
Chris Dickensf90d0762020-01-20 18:02:19 -080049/*
Pete Batard05975332012-09-11 01:01:07 +010050 * Automatically identified devices (VID, PID, type, designation).
51 * TODO: Could use some validation. Also where's the FX2?
52 */
53typedef struct {
54 uint16_t vid;
55 uint16_t pid;
56 int type;
57 const char* designation;
58} fx_known_device;
59
60#define FX_KNOWN_DEVICES { \
61 { 0x0547, 0x2122, FX_TYPE_AN21, "Cypress EZ-USB (2122S)" },\
62 { 0x0547, 0x2125, FX_TYPE_AN21, "Cypress EZ-USB (2121S/2125S)" },\
63 { 0x0547, 0x2126, FX_TYPE_AN21, "Cypress EZ-USB (2126S)" },\
64 { 0x0547, 0x2131, FX_TYPE_AN21, "Cypress EZ-USB (2131Q/2131S/2135S)" },\
65 { 0x0547, 0x2136, FX_TYPE_AN21, "Cypress EZ-USB (2136S)" },\
66 { 0x0547, 0x2225, FX_TYPE_AN21, "Cypress EZ-USB (2225)" },\
67 { 0x0547, 0x2226, FX_TYPE_AN21, "Cypress EZ-USB (2226)" },\
68 { 0x0547, 0x2235, FX_TYPE_AN21, "Cypress EZ-USB (2235)" },\
69 { 0x0547, 0x2236, FX_TYPE_AN21, "Cypress EZ-USB (2236)" },\
70 { 0x04b4, 0x6473, FX_TYPE_FX1, "Cypress EZ-USB FX1" },\
71 { 0x04b4, 0x8613, FX_TYPE_FX2LP, "Cypress EZ-USB FX2LP (68013A/68014A/68015A/68016A)" }, \
Federico Manzanb74b7f72013-03-10 21:00:00 +000072 { 0x04b4, 0x00f3, FX_TYPE_FX3, "Cypress FX3" },\
Pete Batard05975332012-09-11 01:01:07 +010073}
74
75/*
76 * This function uploads the firmware from the given file into RAM.
77 * Stage == 0 means this is a single stage load (or the first of
78 * two stages). Otherwise it's the second of two stages; the
79 * caller having preloaded the second stage loader.
80 *
81 * The target processor is reset at the end of this upload.
82 */
83extern int ezusb_load_ram(libusb_device_handle *device,
84 const char *path, int fx_type, int img_type, int stage);
85
86/*
87 * This function uploads the firmware from the given file into EEPROM.
88 * This uses the right CPUCS address to terminate the EEPROM load with
89 * a reset command where FX parts behave differently than FX2 ones.
90 * The configuration byte is as provided here (zero for an21xx parts)
91 * and the EEPROM type is set so that the microcontroller will boot
92 * from it.
93 *
94 * The caller must have preloaded a second stage loader that knows
95 * how to respond to the EEPROM write request.
96 */
97extern int ezusb_load_eeprom(libusb_device_handle *device,
98 const char *path, int fx_type, int img_type, int config);
99
Pete Batard77a37cb2013-04-14 22:38:52 +0100100/* Verbosity level (default 1). Can be increased or decreased with options v/q */
Pete Batard05975332012-09-11 01:01:07 +0100101extern int verbose;
Federico Manzand345a1e2013-03-10 07:56:56 +0000102
Chris Dickensf2e551a2020-11-27 15:22:29 -0800103extern void logerror(const char *format, ...) PRINTF_FORMAT(1, 2);
104
Federico Manzand345a1e2013-03-10 07:56:56 +0000105#ifdef __cplusplus
106}
107#endif
108
Pete Batard05975332012-09-11 01:01:07 +0100109#endif