@@ -54,10 +54,12 @@ static version_specific v_options[4] ={{0, 240}, {0, 240}, {NO_READ, 496},
5454
5555
5656enum dirtyJtagSig {
57- SIG_TCK = (1 << 1 ),
58- SIG_TDI = (1 << 2 ),
59- SIG_TDO = (1 << 3 ),
60- SIG_TMS = (1 << 4 )
57+ SIG_TCK = (1 << 1 ),
58+ SIG_TDI = (1 << 2 ),
59+ SIG_TDO = (1 << 3 ),
60+ SIG_TMS = (1 << 4 ),
61+ SIG_TRST = (1 << 5 ),
62+ SIG_SRST = (1 << 6 )
6163};
6264
6365DirtyJtag::DirtyJtag (uint32_t clkHZ, int8_t verbose):
@@ -384,3 +386,56 @@ int DirtyJtag::writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end)
384386 }
385387 return EXIT_SUCCESS;
386388}
389+
390+ /* GPIOs */
391+ /* Read GPIOs */
392+ uint8_t DirtyJtag::gpio_get ()
393+ {
394+ int actual_length;
395+ uint8_t sig;
396+ uint8_t buf[] = {CMD_GETSIG, CMD_STOP};
397+ if (libusb_bulk_transfer (dev_handle, DIRTYJTAG_WRITE_EP, buf, sizeof (buf),
398+ &actual_length, DIRTYJTAG_TIMEOUT) < 0 ) {
399+ printError (" writeTDI: last bit error: usb bulk write failed 1" );
400+ return -EXIT_FAILURE;
401+ }
402+
403+ do {
404+ if (libusb_bulk_transfer (dev_handle, DIRTYJTAG_READ_EP, &sig, 1 ,
405+ &actual_length, DIRTYJTAG_TIMEOUT) < 0 ) {
406+ printError (" writeTDI: last bit error: usb bulk read failed" );
407+ return -EXIT_FAILURE;
408+ }
409+ } while (actual_length == 0 );
410+
411+ return sig;
412+ }
413+
414+ bool DirtyJtag::_set_gpio_level (uint8_t gpio, uint8_t val)
415+ {
416+ int actual_length;
417+ uint8_t buf[] = {
418+ CMD_SETSIG,
419+ static_cast <uint8_t >(gpio), // mask
420+ static_cast <uint8_t >(val), // bit set
421+ CMD_STOP,
422+ };
423+ if (libusb_bulk_transfer (dev_handle, DIRTYJTAG_WRITE_EP, buf, 4 ,
424+ &actual_length, DIRTYJTAG_TIMEOUT) < 0 ) {
425+ printError (" GPIO set: usb bulk write failed 1" );
426+ return false ;
427+ }
428+
429+ return true ;
430+ }
431+
432+ /* update selected gpio */
433+ bool DirtyJtag::gpio_set (uint8_t gpio)
434+ {
435+ return _set_gpio_level (gpio, gpio);
436+ }
437+
438+ bool DirtyJtag::gpio_clear (uint8_t gpio)
439+ {
440+ return _set_gpio_level (gpio, 0 );
441+ }
0 commit comments