From 5fc8250f7f76db055d4592b1ca3d691dccda6398 Mon Sep 17 00:00:00 2001
From: "henryk@ploetzli.ch"
 <henryk@ploetzli.ch@ef4ab9da-24cd-11de-8aaa-f3a34680c41f>
Date: Fri, 9 Oct 2009 15:57:07 +0000
Subject: [PATCH] Add command to manually set ADC mux source

---
 armsrc/appmain.c   |  8 ++++++++
 include/usb_cmd.h  |  2 ++
 winsrc/command.cpp | 17 +++++++++++++++++
 3 files changed, 27 insertions(+)

diff --git a/armsrc/appmain.c b/armsrc/appmain.c
index e2bf4033..5313202a 100644
--- a/armsrc/appmain.c
+++ b/armsrc/appmain.c
@@ -646,6 +646,14 @@ void UsbPacketReceived(BYTE *packet, int len)
 		case CMD_SET_LF_DIVISOR:
 			FpgaSendCommand(FPGA_CMD_SET_DIVISOR, c->ext1);
 			break;
+		case CMD_SET_ADC_MUX:
+			switch(c->ext1) {
+			case 0: SetAdcMuxFor(GPIO_MUXSEL_LOPKD); break;
+			case 1: SetAdcMuxFor(GPIO_MUXSEL_LORAW); break;
+			case 2: SetAdcMuxFor(GPIO_MUXSEL_HIPKD); break;
+			case 3: SetAdcMuxFor(GPIO_MUXSEL_HIRAW); break;
+			}
+			break;
 		case CMD_VERSION:
 			SendVersion();
 			break;
diff --git a/include/usb_cmd.h b/include/usb_cmd.h
index 54c6f32b..437629fd 100644
--- a/include/usb_cmd.h
+++ b/include/usb_cmd.h
@@ -52,6 +52,8 @@ typedef struct {
 #define CMD_HID_SIM_TAG																0x020C
 #define CMD_SET_LF_DIVISOR														0x020D
 #define CMD_LF_SIMULATE_BIDIR														0x020E
+#define CMD_SET_ADC_MUX										0x020F
+/* CMD_SET_ADC_MUX: ext1 is 0 for lopkd, 1 for loraw, 2 for hipkd, 3 for hiraw */
 
 // For the 13.56 MHz tags
 #define CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_15693					0x0300
diff --git a/winsrc/command.cpp b/winsrc/command.cpp
index 061ea456..da0f2388 100644
--- a/winsrc/command.cpp
+++ b/winsrc/command.cpp
@@ -2830,6 +2830,22 @@ static void CmdSetDivisor(char *str)
 	}
 }
 
+static void CmdSetMux(char *str)
+{
+	UsbCommand c;
+	c.cmd = CMD_SET_ADC_MUX;
+	if(strncasecmp(str, "lopkd", 5) == 0) {
+		c.ext1 = 0;
+	} else if(strncasecmp(str, "loraw", 5) == 0) {
+		c.ext1 = 1;
+	} else if(strncasecmp(str, "hipkd", 5) == 0) {
+		c.ext1 = 2;
+	} else if(strncasecmp(str, "hiraw", 5) == 0) {
+		c.ext1 = 3;
+	}
+	SendCommand(&c, FALSE);
+}
+
 typedef void HandlerFunction(char *cmdline);
 
 /* in alphabetic order */
@@ -2901,6 +2917,7 @@ static struct {
 	{"save",					CmdSave,						1, "<filename> -- Save trace (from graph window)"},
 	{"scale",					CmdScale,						1, "<int> -- Set cursor display scale"},
 	{"setlfdivisor",	CmdSetDivisor,			0, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"},
+	{"setmux",		CmdSetMux,			0, "<loraw|hiraw|lopkd|hipkd> -- Set the ADC mux to a specific value"},
 	{"sri512read",		CmdSri512read,			0, "<int> -- Read contents of a SRI512 tag"},
 	{"tidemod",				CmdTIDemod,					1, "Demodulate raw bits for TI-type LF tag"},
 	{"tiread",				CmdTIRead,					0, "Read and decode a TI 134 kHz tag"},
-- 
2.39.5