ch347_spi: Add CH347F ID and loop over the entries

Tested with CH347T in mode 1 and CH347F.

Change-Id: I2f8246521b359c5cf574b952b32bee603abcc800
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/198
Reviewed-by: Nicholas Chin <nic.c3.14@gmail.com>
diff --git a/ch347_spi.c b/ch347_spi.c
index 822f7a9..2b42077 100644
--- a/ch347_spi.c
+++ b/ch347_spi.c
@@ -51,6 +51,7 @@
 /* TODO: Add support for HID mode */
 static const struct dev_entry devs_ch347_spi[] = {
 	{0x1A86, 0x55DB, OK, "QinHeng Electronics", "USB To UART+SPI+I2C"},
+	{0x1A86, 0x55DE, OK, "QinHeng Electronics", "USB To UART+SPI+I2C+JTAG"},
 	{0}
 };
 
@@ -309,11 +310,15 @@
 	libusb_set_option(NULL, LIBUSB_OPTION_LOG_LEVEL, LIBUSB_LOG_LEVEL_INFO);
 #endif
 
-	uint16_t vid = devs_ch347_spi[0].vendor_id;
-	uint16_t pid = devs_ch347_spi[0].device_id;
-	ch347_data->handle = libusb_open_device_with_vid_pid(NULL, vid, pid);
+	const struct dev_entry *dev_entry;
+	for (dev_entry = devs_ch347_spi; dev_entry->vendor_id != 0; ++dev_entry) {
+		ch347_data->handle = libusb_open_device_with_vid_pid(
+					NULL, dev_entry->vendor_id, dev_entry->device_id);
+		if (ch347_data->handle)
+			break;
+	}
 	if (ch347_data->handle == NULL) {
-		msg_perr("Couldn't open device %04x:%04x.\n", vid, pid);
+		msg_perr("Couldn't find CH347 device.\n");
 		free(ch347_data);
 		return 1;
 	}
diff --git a/util/z60_flashprog.rules b/util/z60_flashprog.rules
index 3efad57..a0304d0 100644
--- a/util/z60_flashprog.rules
+++ b/util/z60_flashprog.rules
@@ -93,7 +93,8 @@
 # Winchiphead (WCH) CH341a based programmer
 ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="5512", MODE="664", GROUP="plugdev"
 
-# Winchiphead (WCH) CH347 based programmer
+# Winchiphead (WCH) CH347T/F based programmers
 ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="55db", MODE="664", GROUP="plugdev"
+ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="55de", MODE="664", GROUP="plugdev"
 
 LABEL="flashprog_rules_end"