2023-05-13 22:00:23 +02:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2023 Alexey Starikovskiy <aystarik@gmail.com>
|
|
|
|
|
*/
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <libusb.h>
|
|
|
|
|
|
|
|
|
|
#include "jtagInterface.hpp"
|
|
|
|
|
|
|
|
|
|
class CH347Jtag : public JtagInterface {
|
|
|
|
|
public:
|
2023-07-30 08:39:15 +02:00
|
|
|
CH347Jtag(uint32_t clkHZ, int8_t verbose);
|
2023-05-13 22:00:23 +02:00
|
|
|
virtual ~CH347Jtag();
|
|
|
|
|
|
2023-08-08 15:54:27 +02:00
|
|
|
int setClkFreq(uint32_t clkHZ) override { return _setClkFreq(clkHZ); };
|
|
|
|
|
int _setClkFreq(uint32_t clkHZ);
|
2023-05-13 22:00:23 +02:00
|
|
|
/* TMS */
|
2023-08-08 15:54:27 +02:00
|
|
|
int writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer) override;
|
2023-05-13 22:00:23 +02:00
|
|
|
/* TDI */
|
2023-08-08 15:54:27 +02:00
|
|
|
int writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override;
|
2023-05-13 22:00:23 +02:00
|
|
|
/* clk */
|
|
|
|
|
int toggleClk(uint8_t tms, uint8_t tdo, uint32_t clk_len) override;
|
|
|
|
|
|
|
|
|
|
int get_buffer_size() override { return 0;}
|
|
|
|
|
|
|
|
|
|
bool isFull() override { return false;}
|
|
|
|
|
|
|
|
|
|
int flush() override {return 0;}
|
|
|
|
|
|
|
|
|
|
private:
|
2023-07-30 08:39:15 +02:00
|
|
|
bool _verbose;
|
2023-05-13 22:00:23 +02:00
|
|
|
int setClk(const uint8_t &factor);
|
|
|
|
|
|
|
|
|
|
libusb_device_handle *dev_handle;
|
|
|
|
|
libusb_context *usb_ctx;
|
|
|
|
|
struct libusb_transfer *wtrans, *rtrans;
|
|
|
|
|
int rcomplete, wcomplete;
|
|
|
|
|
uint8_t ibuf[512];
|
|
|
|
|
uint8_t obuf[512];
|
|
|
|
|
int usb_xfer(unsigned wlen, unsigned rlen, unsigned *actual);
|
|
|
|
|
};
|