]> sigrok.org Git - sigrok-firmware-fx2lafw.git/blobdiff - sainsmart_dds120.c
scopes: Factor out LED_CLEAR(), LED_GREEN(), LED_RED().
[sigrok-firmware-fx2lafw.git] / sainsmart_dds120.c
index a45919619b4957485800d595ce990b1c58420394..1ea478087ed6307841057356e7feb6626b7c25c4 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;