X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=sainsmart_dds120.c;h=1ea478087ed6307841057356e7feb6626b7c25c4;hb=65b34f7ea6d5f250a09c878d929e5c5312093e54;hp=a2867e5c52340bfd578f287bc5e99bf4b6ece1f5;hpb=3968bbfb63b0946841e4f2d78339523a55ef9124;p=sigrok-firmware-fx2lafw.git diff --git a/sainsmart_dds120.c b/sainsmart_dds120.c index a2867e5c..1ea47808 100644 --- a/sainsmart_dds120.c +++ b/sainsmart_dds120.c @@ -24,9 +24,21 @@ #include #include +#define SET_ANALOG_MODE() PA7 = 1 + +/* Toggle the 1kHz calibration pin, only accurate up to ca. 8MHz. */ +/* 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; @@ -64,8 +76,11 @@ void suspend_isr(void) __interrupt SUSPEND_ISR void timer2_isr(void) __interrupt TF2_ISR { - /* Toggle the 1kHz calibration pin, only accurate up to ca. 8MHz. */ - IOE = IOE^0x04; + TOGGLE_CALIBRATION_PIN(); + + if (ledcounter && (--ledcounter == 0)) + LED_CLEAR(); + TF2 = 0; } @@ -208,6 +223,8 @@ static void start_sampling(void) { int i; + SET_ANALOG_MODE(); + clear_fifo(); for (i = 0; i < 1000; i++); @@ -221,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) @@ -421,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; @@ -459,6 +483,8 @@ static void init(void) EP4CFG = 0; EP8CFG = 0; + SET_ANALOG_MODE(); + /* In idle mode tristate all outputs. */ GPIFIDLECTL = 0x00; /* Don't enable CTL0-5 outputs. */ GPIFCTLCFG = 0x80; /* TRICTL=1. CTL0-2: CMOS outputs, tri-statable. */ @@ -509,7 +535,7 @@ static void main(void) OEC = 0xff; OEA = 0x80; - PA7 = 1; + SET_ANALOG_MODE(); while (TRUE) { if (dosud) {