From: Uwe Hermann Date: Sat, 8 Apr 2017 14:58:42 +0000 (+0200) Subject: scopes: Factor out LED_CLEAR(), LED_GREEN(), LED_RED(). X-Git-Tag: sigrok-firmware-fx2lafw-0.1.6~23 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=65b34f7ea6d5f250a09c878d929e5c5312093e54;p=sigrok-firmware-fx2lafw.git scopes: Factor out LED_CLEAR(), LED_GREEN(), LED_RED(). --- diff --git a/hantek_6022be.c b/hantek_6022be.c index 4dc34f2b..04ca6eb2 100644 --- a/hantek_6022be.c +++ b/hantek_6022be.c @@ -29,6 +29,10 @@ /* Toggle the 1kHz calibration pin, only accurate up to ca. 8MHz. */ #define TOGGLE_CALIBRATION_PIN() PA7 = !PA7 +#define LED_CLEAR() PC0 = 1; PC1 = 1; +#define LED_GREEN() PC0 = 1; PC1 = 0; +#define LED_RED() PC0 = 0; PC1 = 1; + /* Change to support as many interfaces as you need. */ static BYTE altiface = 0; @@ -73,13 +77,8 @@ void timer2_isr(void) __interrupt TF2_ISR { TOGGLE_CALIBRATION_PIN(); - if (ledcounter) { - if (--ledcounter == 0) { - /* Clear LED. */ - PC0 = 1; - PC1 = 1; - } - } + if (ledcounter && (--ledcounter == 0)) + LED_CLEAR(); TF2 = 0; } @@ -183,10 +182,9 @@ static void start_sampling(void) GPIFTCB0 = 0; GPIFTRIG = (altiface == 0) ? 6 : 4; - /* Set green LED, don't clear LED. */ + /* Set green LED, don't clear LED afterwards (ledcounter = 0). */ + LED_GREEN(); ledcounter = 0; - PC0 = 1; - PC1 = 0; } static void select_interface(BYTE alt) @@ -358,9 +356,8 @@ BOOL handle_vendorcommand(BYTE cmd) { stop_sampling(); - /* Set red LED. */ - PC0 = 0; - PC1 = 1; + /* Set red LED, clear after timeout. */ + LED_RED(); ledcounter = 1000; /* Clear EP0BCH/L for each valid command. */ diff --git a/hantek_6022bl.c b/hantek_6022bl.c index 4920047c..af445cf2 100644 --- a/hantek_6022bl.c +++ b/hantek_6022bl.c @@ -29,6 +29,10 @@ /* Toggle the 1kHz calibration pin, only accurate up to ca. 8MHz. */ #define TOGGLE_CALIBRATION_PIN() PC2 = !PC2 +#define LED_CLEAR() PC0 = 1; PC1 = 1; +#define LED_GREEN() PC0 = 1; PC1 = 0; +#define LED_RED() PC0 = 0; PC1 = 1; + /* Change to support as many interfaces as you need. */ static BYTE altiface = 0; @@ -73,13 +77,8 @@ void timer2_isr(void) __interrupt TF2_ISR { TOGGLE_CALIBRATION_PIN(); - if (ledcounter) { - if (--ledcounter == 0) { - /* Clear LED. */ - PC0 = 1; - PC1 = 1; - } - } + if (ledcounter && (--ledcounter == 0)) + LED_CLEAR(); TF2 = 0; } @@ -184,10 +183,9 @@ static void start_sampling(void) GPIFTCB0 = 0; GPIFTRIG = (altiface == 0) ? 6 : 4; - /* Set green LED, don't clear LED. */ + /* Set green LED, don't clear LED afterwards (ledcounter = 0). */ + LED_GREEN(); ledcounter = 0; - PC0 = 1; - PC1 = 0; } static void select_interface(BYTE alt) @@ -359,9 +357,8 @@ BOOL handle_vendorcommand(BYTE cmd) { stop_sampling(); - /* Set red LED. */ - PC0 = 0; - PC1 = 1; + /* Set red LED, clear after timeout. */ + LED_RED(); ledcounter = 1000; /* Clear EP0BCH/L for each valid command. */ diff --git a/sainsmart_dds120.c b/sainsmart_dds120.c index a4591961..1ea47808 100644 --- a/sainsmart_dds120.c +++ b/sainsmart_dds120.c @@ -30,9 +30,15 @@ /* 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;