2 * This file is part of the sigrok project.
4 * Copyright (C) 2010 Bert Vermeulen <bert@biot.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * Helper functions for the Cypress EZ-USB / FX2 series chips.
31 int ezusb_reset(struct libusb_device_handle *hdl, int set_clear)
36 g_message("setting CPU reset mode %s...", set_clear ? "on" : "off");
37 buf[0] = set_clear ? 1 : 0;
38 err = libusb_control_transfer(hdl, LIBUSB_REQUEST_TYPE_VENDOR, 0xa0,
39 0xe600, 0x0000, buf, 1, 100);
41 g_warning("Unable to send control request: %d", err);
47 int ezusb_install_firmware(libusb_device_handle *hdl, const char *filename)
50 int offset, chunksize, err, result;
51 unsigned char buf[4096];
53 g_message("Uploading firmware at %s", filename);
54 if((fw = fopen(filename, "r")) == NULL)
56 g_warning("Unable to open firmware file %s for reading: %s", filename, strerror(errno));
64 chunksize = fread(buf, 1, 4096, fw);
67 err = libusb_control_transfer(hdl, LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT, 0xa0,
68 offset, 0x0000, buf, chunksize, 100);
71 g_warning("Unable to send firmware to device: %d", err);
75 g_message("Uploaded %d bytes", chunksize);
79 g_message("Firmware upload done");