Skip to content

Commit

Permalink
Merge pull request #4 from matrix-io/ac/matrix_voice
Browse files Browse the repository at this point in the history
Ac/matrix voice
  • Loading branch information
eljuguetero authored Feb 7, 2017
2 parents 8b85fd1 + b888e21 commit 84614ec
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 4 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,17 @@ ADD_CUSTOM_COMMAND(OUTPUT cables.h
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_BINARY_DIR})

add_library(xc3sproglib STATIC sysfs.cpp ioftdi.cpp iofx2.cpp
devicedb.cpp jtag.cpp jedecfile.cpp bitfile.cpp
devicedb.cpp jtag.cpp jedecfile.cpp bitfile.cpp
iomatrixpi.cpp iomatrixvoice.cpp iowiringpi.cpp
iobase.cpp progalgxc95x.cpp utilities.cpp
progalgxcf.cpp progalgxcfp.cpp progalgxc3s.cpp
progalgavr.cpp progalgxc2c.cpp mapfile_xc2c.cpp
ioxpc.cpp progalgspiflash.cpp bitrev.cpp
cabledb.cpp pdioverjtag.cpp xmega_pdi_nvm.cpp
${CONDITIONAL_FILES} devices.h cables.h)

set(LIBS ${LIBS} wiringPiDev wiringPi)

add_executable(xc2c_warp xc2c_warp.cpp)
target_link_libraries(xc2c_warp xc3sproglib ${CONDITIONAL_LIBS})

Expand Down
7 changes: 7 additions & 0 deletions cabledb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ CABLES_TYPES CableDB::getCableType(const char *given_name)
return CABLE_XPC;
if (strcasecmp(given_name, "sysfsgpio") == 0)
return CABLE_SYSFS_GPIO;
if (strcasecmp(given_name, "matrix_pi") == 0)
return CABLE_MATRIX_PI;
if (strcasecmp(given_name, "matrix_voice") == 0)
return CABLE_MATRIX_VOICE;

return CABLE_UNKNOWN;
}

Expand All @@ -168,6 +173,8 @@ const char *CableDB::getCableName(const CABLES_TYPES type )
case CABLE_FTDI: return "ftdi";
case CABLE_FX2: return "fx2";
case CABLE_XPC: return "xpc";
case CABLE_MATRIX_PI: return "matrix_pi";
case CABLE_MATRIX_VOICE: return "matrix_voice";
case CABLE_SYSFS_GPIO: return "sysfsgpio";
case CABLE_NONE: return "none";
case CABLE_UNKNOWN: return "unknown";
Expand Down
4 changes: 3 additions & 1 deletion cabledb.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ enum CABLES_TYPES
CABLE_FTDI,
CABLE_FX2,
CABLE_XPC,
CABLE_SYSFS_GPIO
CABLE_SYSFS_GPIO,
CABLE_MATRIX_PI,
CABLE_MATRIX_VOICE
};

struct cable_t
Expand Down
5 changes: 3 additions & 2 deletions cablelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ jtaghs2 ftdi 6000000 0x0403:0x6014:Digilent USB Device:0:0xe8:0xeb:0x00
turtelizer ftdi 1500000 0x0403:0xbdc8:Turtelizer JTAG/RS232 Adapter:0:0x00:0x10:0x00:0x0
arm-usb-ocd-h ftdi 1500000 0x15ba:0x002b::1:0x00:0x10:0x00:0x08
tumpa ftdi 1500000 0x0403:0x8a98:TIAO USB Multi-Protocol Adapter:1
sysfsgpio sysfsgpio 0 NULL

sysfsgpio sysfsgpio 0 NULL
matrix_pi matrix_pi 0 NULL
matrix_voice matrix_voice 0 NULL
7 changes: 7 additions & 0 deletions iomatrixpi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "iomatrixpi.h"

IOMatrixPi::IOMatrixPi()
: IOWiringPi(4, 17, 22, 27)
{
}

12 changes: 12 additions & 0 deletions iomatrixpi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef __IO_MATRIX_PI__
#define __IO_MATRIX_PI__

#include "iowiringpi.h"

class IOMatrixPi : public IOWiringPi
{
public:
IOMatrixPi();
};

#endif
7 changes: 7 additions & 0 deletions iomatrixvoice.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "iomatrixvoice.h"

IOMatrixVoice::IOMatrixVoice()
: IOWiringPi(27, 4, 17, 22)
{
}

12 changes: 12 additions & 0 deletions iomatrixvoice.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef __IO_MATRIX_VOICE__
#define __IO_MATRIX_VOICE__

#include "iowiringpi.h"

class IOMatrixVoice : public IOWiringPi
{
public:
IOMatrixVoice();
};

#endif
90 changes: 90 additions & 0 deletions iowiringpi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#include "iowiringpi.h"

#include <wiringPi.h>

IOWiringPi::IOWiringPi(int tms, int tck, int tdi, int tdo)
: TMSPin(tms), TCKPin(tck), TDIPin(tdi), TDOPin(tdo)
{
wiringPiSetupGpio();
pinMode(TDIPin, OUTPUT);
pinMode(TMSPin, OUTPUT);
pinMode(TCKPin, OUTPUT);
pinMode(TDOPin, INPUT);
}

IOWiringPi::~IOWiringPi()
{
}

void IOWiringPi::txrx_block(const unsigned char *tdi, unsigned char *tdo, int length, bool last)
{
int i=0;
int j=0;
unsigned char tdo_byte=0;
unsigned char tdi_byte;
if (tdi)
tdi_byte = tdi[j];

while(i<length-1){
tdo_byte=tdo_byte+(txrx(false, (tdi_byte&1)==1)<<(i%8));
if (tdi)
tdi_byte=tdi_byte>>1;
i++;
if((i%8)==0){ // Next byte
if(tdo)
tdo[j]=tdo_byte; // Save the TDO byte
tdo_byte=0;
j++;
if (tdi)
tdi_byte=tdi[j]; // Get the next TDI byte
}
};
tdo_byte=tdo_byte+(txrx(last, (tdi_byte&1)==1)<<(i%8));
if(tdo)
tdo[j]=tdo_byte;

digitalWrite(TCKPin, LOW);
return;
}

void IOWiringPi::tx_tms(unsigned char *pat, int length, int force)
{
int i;
unsigned char tms;
for (i = 0; i < length; i++)
{
if ((i & 0x7) == 0)
tms = pat[i>>3];
tx((tms & 0x01), true);
tms = tms >> 1;
}

digitalWrite(TCKPin, LOW);
}

void IOWiringPi::tx(bool tms, bool tdi)
{
digitalWrite(TCKPin, LOW);

if(tdi)
digitalWrite(TDIPin, HIGH);
else
digitalWrite(TDIPin, LOW);

if(tms)
digitalWrite(TMSPin, HIGH);
else
digitalWrite(TMSPin, LOW);

digitalWrite(TCKPin, HIGH);
}


bool IOWiringPi::txrx(bool tms, bool tdi)
{
tx(tms, tdi);

return digitalRead(TDOPin);
}


25 changes: 25 additions & 0 deletions iowiringpi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef __IO_WIRING_PI__
#define __IO_WIRING_PI__

#include "iobase.h"

class IOWiringPi : public IOBase
{
public:
IOWiringPi(int tms, int tck, int tdi, int tdo);
virtual ~IOWiringPi();

protected:
void tx(bool tms, bool tdi);
bool txrx(bool tms, bool tdi);

void txrx_block(const unsigned char *tdi, unsigned char *tdo, int length, bool last);
void tx_tms(unsigned char *pat, int length, int force);

int TMSPin;
int TCKPin;
int TDIPin;
int TDOPin;
};

#endif
14 changes: 14 additions & 0 deletions utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "ioftdi.h"
#include "ioxpc.h"
#include "sysfs.h"
#include "iomatrixpi.h"
#include "iomatrixvoice.h"
#include "utilities.h"

extern char *optarg;
Expand Down Expand Up @@ -91,6 +93,18 @@ int getIO( std::auto_ptr<IOBase> *io, struct cable_t * cable, char const *dev,
io->get()->setVerbose(verbose);
res = io->get()->Init(cable, serial, use_freq);
}
else if(cable->cabletype == CABLE_MATRIX_PI)
{
io->reset(new IOMatrixPi());
io->get()->setVerbose(verbose);
res = io->get()->Init(cable, serial, use_freq);
}
else if(cable->cabletype == CABLE_MATRIX_VOICE)
{
io->reset(new IOMatrixVoice());
io->get()->setVerbose(verbose);
res = io->get()->Init(cable, serial, use_freq);
}
else
{
fprintf(stderr, "Unknown Cable \"%s\" \n", getCableName(cable->cabletype));
Expand Down

0 comments on commit 84614ec

Please sign in to comment.