ftdipp_mpsse: init take ftdi mode
This commit is contained in:
parent
7b4902c460
commit
5eb4286cb4
|
|
@ -138,6 +138,7 @@ int FTDIpp_MPSSE::close_device()
|
||||||
|
|
||||||
|
|
||||||
int FTDIpp_MPSSE::init(unsigned char latency, unsigned char bitmask_mode,
|
int FTDIpp_MPSSE::init(unsigned char latency, unsigned char bitmask_mode,
|
||||||
|
unsigned char mode,
|
||||||
mpsse_bit_config & bit_conf)
|
mpsse_bit_config & bit_conf)
|
||||||
{
|
{
|
||||||
unsigned char buf_cmd[6] = { SET_BITS_LOW, 0, 0,
|
unsigned char buf_cmd[6] = { SET_BITS_LOW, 0, 0,
|
||||||
|
|
@ -149,9 +150,11 @@ int FTDIpp_MPSSE::init(unsigned char latency, unsigned char bitmask_mode,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ftdi_set_bitmode(_ftdi, 0x00, BITMODE_RESET) < 0) {
|
if (mode == BITMODE_MPSSE) {
|
||||||
cout << "bitmode_reset error" << endl;
|
if (ftdi_set_bitmode(_ftdi, 0x00, BITMODE_RESET) < 0) {
|
||||||
return -1;
|
cout << "bitmode_reset error" << endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (ftdi_usb_purge_buffers(_ftdi) != 0) {
|
if (ftdi_usb_purge_buffers(_ftdi) != 0) {
|
||||||
cout << "reset error" << endl;
|
cout << "reset error" << endl;
|
||||||
|
|
@ -162,24 +165,26 @@ int FTDIpp_MPSSE::init(unsigned char latency, unsigned char bitmask_mode,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
/* enable MPSSE mode */
|
/* enable MPSSE mode */
|
||||||
if (ftdi_set_bitmode(_ftdi, bitmask_mode, BITMODE_MPSSE) < 0) {
|
if (ftdi_set_bitmode(_ftdi, bitmask_mode, mode) < 0) {
|
||||||
cout << "bitmode_mpsse error" << endl;
|
cout << "bitmode_mpsse error" << endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (mode == BITMODE_MPSSE) {
|
||||||
|
|
||||||
unsigned char buf1[5];
|
unsigned char buf1[5];
|
||||||
ftdi_read_data(_ftdi, buf1, 5);
|
ftdi_read_data(_ftdi, buf1, 5);
|
||||||
|
|
||||||
if (setClkFreq(_clkHZ, 0) < 0)
|
if (setClkFreq(_clkHZ, 0) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
buf_cmd[1] = bit_conf.bit_low_val; // 0xe8;
|
buf_cmd[1] = bit_conf.bit_low_val; // 0xe8;
|
||||||
buf_cmd[2] = bit_conf.bit_low_dir; // 0xeb;
|
buf_cmd[2] = bit_conf.bit_low_dir; // 0xeb;
|
||||||
|
|
||||||
buf_cmd[4] = bit_conf.bit_high_val; // 0x00;
|
buf_cmd[4] = bit_conf.bit_high_val; // 0x00;
|
||||||
buf_cmd[5] = bit_conf.bit_high_dir; // 0x60;
|
buf_cmd[5] = bit_conf.bit_high_dir; // 0x60;
|
||||||
mpsse_store(buf_cmd, 6);
|
mpsse_store(buf_cmd, 6);
|
||||||
mpsse_write();
|
mpsse_write();
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,8 @@ class FTDIpp_MPSSE {
|
||||||
int bit_high_dir;
|
int bit_high_dir;
|
||||||
} mpsse_bit_config;
|
} mpsse_bit_config;
|
||||||
|
|
||||||
int init(unsigned char latency, unsigned char bitmask_mode, mpsse_bit_config &bit_conf);
|
int init(unsigned char latency, unsigned char bitmask_mode, unsigned char mode,
|
||||||
|
mpsse_bit_config &bit_conf);
|
||||||
int setClkFreq(uint32_t clkHZ);
|
int setClkFreq(uint32_t clkHZ);
|
||||||
int setClkFreq(uint32_t clkHZ, char use_divide_by_5);
|
int setClkFreq(uint32_t clkHZ, char use_divide_by_5);
|
||||||
|
|
||||||
|
|
@ -39,8 +40,6 @@ class FTDIpp_MPSSE {
|
||||||
unsigned int udevstufftoint(const char *udevstring, int base);
|
unsigned int udevstufftoint(const char *udevstring, int base);
|
||||||
bool search_with_dev(const std::string &device);
|
bool search_with_dev(const std::string &device);
|
||||||
bool _verbose;
|
bool _verbose;
|
||||||
struct ftdi_context *_ftdi;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _vid;
|
int _vid;
|
||||||
int _pid;
|
int _pid;
|
||||||
|
|
@ -49,7 +48,10 @@ class FTDIpp_MPSSE {
|
||||||
char _product[64];
|
char _product[64];
|
||||||
unsigned char _interface;
|
unsigned char _interface;
|
||||||
int _clkHZ;
|
int _clkHZ;
|
||||||
|
protected:
|
||||||
|
struct ftdi_context *_ftdi;
|
||||||
int _buffer_size;
|
int _buffer_size;
|
||||||
|
private:
|
||||||
int _num;
|
int _num;
|
||||||
unsigned char *_buffer;
|
unsigned char *_buffer;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue