X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=fx2lafw.c;h=f69955161eb18b88aeda21a5775e7c4658e34a78;hb=8ee491edbe31d980abe261307ef893bce9a16760;hp=7972060f81de411c679c7d32b4bd98f75eb7086f;hpb=4ad20a4c57699f7ea5ce88fc132feaf7471743c1;p=sigrok-firmware-fx2lafw.git diff --git a/fx2lafw.c b/fx2lafw.c index 7972060f..f6995516 100644 --- a/fx2lafw.c +++ b/fx2lafw.c @@ -46,6 +46,13 @@ #include #include +/* Protocol commands */ +#define CMD_SET_SAMPLERATE 0xb0 +#define CMD_START 0xb1 +#define CMD_STOP 0xb2 +#define CMD_GET_FW_VERSION 0xb3 +/* ... */ + #define SYNCDELAY() SYNCDELAY4 /* ... */ @@ -252,21 +259,36 @@ static void setup_endpoints(void) (0 << 1) | (0 << 0); /* EP buffering: quad buffering */ SYNCDELAY(); - /* Disable all other EPs (EP1, EP4, EP6, and EP8). */ + /* Setup EP6 (IN) in the debug build. */ +#ifdef DEBUG + EP6CFG = (1 << 7) | /* EP is valid/activated */ + (1 << 6) | /* EP direction: IN */ + (1 << 5) | (0 << 4) | /* EP Type: bulk */ + (0 << 3) | /* EP buffer size: 512 */ + (0 << 2) | /* Reserved */ + (1 << 1) | (0 << 0); /* EP buffering: double buffering */ +#else + EP6CFG &= ~bmVALID; +#endif + SYNCDELAY(); + + /* Disable all other EPs (EP4 and EP8). */ EP1INCFG &= ~bmVALID; SYNCDELAY(); EP1OUTCFG &= ~bmVALID; SYNCDELAY(); EP4CFG &= ~bmVALID; SYNCDELAY(); - EP6CFG &= ~bmVALID; - SYNCDELAY(); EP8CFG &= ~bmVALID; SYNCDELAY(); /* EP2: Reset the FIFOs. */ /* Note: RESETFIFO() gets the EP number WITHOUT bit 7 set/cleared. */ RESETFIFO(0x02) +#ifdef DEBUG + /* Reset the FIFOs of EP6 when in debug mode. */ + RESETFIFO(0x06) +#endif /* EP2: Enable AUTOIN mode. Set FIFO width to 8bits. */ EP2FIFOCFG = bmAUTOIN | ~bmWORDWIDE; @@ -285,12 +307,27 @@ static void setup_endpoints(void) BOOL handle_vendorcommand(BYTE cmd) { - (void)cmd; - - /* - * TODO: Implement the protocol using control requests of type - * 'vendor-specific' (bmRequestType[6:5] = 2). - */ + /* Protocol implementation */ + + switch (cmd) { + case CMD_SET_SAMPLERATE: + /* TODO */ + break; + case CMD_START: + /* TODO */ + break; + case CMD_STOP: + GPIFABORT = 0xff; + /* TODO */ + return TRUE; + break; + case CMD_GET_FW_VERSION: + /* TODO */ + break; + default: + /* Unimplemented command. */ + break; + } return FALSE; } @@ -318,12 +355,15 @@ BOOL handle_set_interface(BYTE ifc, BYTE alt_ifc) /* (2) Reset data toggles of the EPs in the interface. */ /* Note: RESETTOGGLE() gets the EP number WITH bit 7 set/cleared. */ RESETTOGGLE(0x82); + RESETTOGGLE(0x76); /* (3) Restore EPs to their default conditions. */ /* Note: RESETFIFO() gets the EP number WITHOUT bit 7 set/cleared. */ RESETFIFO(0x02); /* TODO */ + RESETFIFO(0x06); + /* (4) Clear the HSNAK bit. Not needed, fx2lib does this. */ return TRUE;