]> sigrok.org Git - sigrok-firmware-fx2lafw.git/blobdiff - sainsmart_dds120.c
scopes: Initialize PORTA/C/E consistently for all devices.
[sigrok-firmware-fx2lafw.git] / sainsmart_dds120.c
index a45919619b4957485800d595ce990b1c58420394..8a05df195aa25bd7f871350689a0d14871b41bcb 100644 (file)
 /* Note: There's no PE2 as IOE is not bit-addressable (see TRM 15.2). */
 #define TOGGLE_CALIBRATION_PIN() IOE = IOE ^ 0x04
 
+#define LED_CLEAR() NOP
+#define LED_GREEN() NOP
+#define LED_RED()   NOP
+
 /* Change to support as many interfaces as you need. */
 static BYTE altiface = 0;
 
+static volatile WORD ledcounter = 0;
+
 static volatile __bit dosud = FALSE;
 static volatile __bit dosuspend = FALSE;
 
@@ -72,6 +78,9 @@ void timer2_isr(void) __interrupt TF2_ISR
 {
        TOGGLE_CALIBRATION_PIN();
 
+       if (ledcounter && (--ledcounter == 0))
+               LED_CLEAR();
+
        TF2 = 0;
 }
 
@@ -229,6 +238,9 @@ static void start_sampling(void)
        GPIFTCB0 = 0;
        GPIFTRIG = (altiface == 0) ? 6 : 4;
 
+       /* Set green LED, don't clear LED afterwards (ledcounter = 0). */
+       LED_GREEN();
+       ledcounter = 0;
 }
 
 static void select_interface(BYTE alt)
@@ -429,6 +441,10 @@ BOOL handle_vendorcommand(BYTE cmd)
 {
        stop_sampling();
 
+       /* Set red LED, clear after timeout. */
+       LED_RED();
+       ledcounter = 1000;
+
        /* Clear EP0BCH/L for each valid command. */
        if (cmd >= 0xe0 && cmd <= 0xe6) {
                EP0BCH = 0;
@@ -512,12 +528,12 @@ static void main(void)
 
        RENUMERATE_UNCOND();
 
+       PORTECFG = 0;
        PORTCCFG = 0;
        PORTACFG = 0;
-       PORTECFG = 0;
-       OEE = 0xFF;
+       OEE = 0xff;
        OEC = 0xff;
-       OEA = 0x80;
+       OEA = 0xff;
 
        SET_ANALOG_MODE();