From: Uwe Hermann Date: Sun, 17 Dec 2017 14:19:26 +0000 (+0100) Subject: fx2lafw: Blink LED on pin PA1 during acquisition. X-Git-Tag: sigrok-firmware-fx2lafw-0.1.6~27 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=cf43e09a111d7d6bf482521149bd33d85947dede;p=sigrok-firmware-fx2lafw.git fx2lafw: Blink LED on pin PA1 during acquisition. All FX2 based logic analyzer devices will now toggle PA1 during acquisition, and keep it high while idle. On fx2grok-tiny and fx2grok-flat there's a LED connected to PA1. Thus, those devices will visually indicate whether a firmware has been uploaded (LED will light up and stay like that while the device is idle). During any acquisition the LED will blink. The PA1 pin is not used on most other FX2 based LA devices, so that shouldn't cause any issues (tested on hardware). On certain devices with LA and analog support the PA1 pin is used for other purposes (e.g. Hantek 6022BL, Instrustar ISDS205X) but even there this won't cause any issues in practice (tested on hardware). --- diff --git a/fx2lafw.c b/fx2lafw.c index 45368cf2..1949a7c1 100644 --- a/fx2lafw.c +++ b/fx2lafw.c @@ -38,6 +38,7 @@ #include #include +#include #include #include #include @@ -50,6 +51,10 @@ volatile __bit got_sud; BYTE vendor_command; +volatile WORD ledcounter = 1000; + +extern __bit gpif_acquiring; + static void setup_endpoints(void) { /* Setup EP2 (IN). */ @@ -208,6 +213,20 @@ void hispeed_isr(void) __interrupt HISPEED_ISR CLEAR_HISPEED(); } +void timer2_isr(void) __interrupt TF2_ISR +{ + /* Blink LED during acquisition, keep it on otherwise. */ + if (gpif_acquiring) { + if (--ledcounter == 0) { + PA1 = !PA1; + ledcounter = 1000; + } + } else { + PA1 = 1; /* LED on. */ + } + TF2 = 0; +} + void fx2lafw_init(void) { /* Set DYN_OUT and ENH_PKT bits, as recommended by the TRM. */ @@ -229,6 +248,18 @@ void fx2lafw_init(void) ENABLE_HISPEED(); ENABLE_USBRESET(); + /* PA1 (LED) is an output. */ + PORTACFG = 0; + OEA = (1 << 1); + PA1 = 1; /* LED on. */ + + /* Init timer2. */ + RCAP2L = -500 & 0xff; + RCAP2H = (-500 & 0xff00) >> 8; + T2CON = 0; + ET2 = 1; + TR2 = 1; + /* Global (8051) interrupt enable. */ EA = 1;