From: Maciej Kurc Date: Wed, 24 Jan 2018 18:39:04 +0000 (+0100) Subject: fx2lafw: Factor out LED control. X-Git-Tag: sigrok-firmware-fx2lafw-0.1.6~3 X-Git-Url: http://sigrok.org/gitweb/?a=commitdiff_plain;h=553c0ee354bb2ae5eb36c8ba84f22b948708e785;p=sigrok-firmware-fx2lafw.git fx2lafw: Factor out LED control. Also, make the LED polarity compile-time configurable. [Note: This is a slightly modified version of a patch from Maciej Kurc.] --- diff --git a/fx2lafw.c b/fx2lafw.c index d601e277..1035713d 100644 --- a/fx2lafw.c +++ b/fx2lafw.c @@ -215,7 +215,7 @@ void ibn_isr(void) __interrupt IBN_ISR */ if ((IBNIRQ & bmEP2IBN) && (gpif_acquiring == PREPARED)) { ledcounter = 1; - PA1 = 0; + LED_OFF(); gpif_acquisition_start(); } @@ -246,11 +246,11 @@ void timer2_isr(void) __interrupt TF2_ISR /* Blink LED during acquisition, keep it on otherwise. */ if (gpif_acquiring == RUNNING) { if (--ledcounter == 0) { - PA1 = !PA1; + LED_TOGGLE(); ledcounter = 1000; } } else if (gpif_acquiring == STOPPED) { - PA1 = 1; /* LED on. */ + LED_ON(); } TF2 = 0; } @@ -276,10 +276,8 @@ void fx2lafw_init(void) ENABLE_HISPEED(); ENABLE_USBRESET(); - /* PA1 (LED) is an output. */ - PORTACFG = 0; - OEA = (1 << 1); - PA1 = 1; /* LED on. */ + LED_INIT(); + LED_ON(); /* Init timer2. */ RCAP2L = -500 & 0xff; diff --git a/include/fx2lafw.h b/include/fx2lafw.h index 7a24cf66..07f378f0 100644 --- a/include/fx2lafw.h +++ b/include/fx2lafw.h @@ -39,4 +39,11 @@ #define FX2LAFW_VERSION_MAJOR 1 #define FX2LAFW_VERSION_MINOR 2 +#define LED_POLARITY 1 /* 1: active-high, 0: active-low */ + +#define LED_INIT() do { PORTACFG = 0; OEA = (1 << 1); } while (0) +#define LED_ON() do { PA1 = LED_POLARITY; } while (0) +#define LED_OFF() do { PA1 = !LED_POLARITY; } while (0) +#define LED_TOGGLE() do { PA1 = !PA1; } while (0) + #endif