Skip to content

Commit 3c7324d

Browse files
committed
dirtyJtag: added SRST/TRST values. Added method to read/set GPIOs level
1 parent ab8d8fc commit 3c7324d

File tree

2 files changed

+68
-4
lines changed

2 files changed

+68
-4
lines changed

src/dirtyJtag.cpp

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ static version_specific v_options[4] ={{0, 240}, {0, 240}, {NO_READ, 496},
5454

5555

5656
enum 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

6365
DirtyJtag::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+
}

src/dirtyJtag.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,21 @@ class DirtyJtag : public JtagInterface {
4242

4343
int flush() override;
4444

45+
/* access gpio */
46+
/* read gpio */
47+
uint8_t gpio_get();
48+
/* update selected gpio */
49+
bool gpio_set(uint8_t gpio);
50+
bool gpio_clear(uint8_t gpio);
51+
4552
private:
4653
int8_t _verbose;
4754

4855
int sendBitBang(uint8_t mask, uint8_t val, uint8_t *read, bool last);
4956
bool getVersion();
5057

58+
bool _set_gpio_level(uint8_t gpio, uint8_t val);
59+
5160
libusb_device_handle *dev_handle;
5261
libusb_context *usb_ctx;
5362
uint8_t _tdi;

0 commit comments

Comments
 (0)