-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from matrix-io/ac/matrix_voice
Ac/matrix voice
- Loading branch information
Showing
11 changed files
with
184 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "iomatrixpi.h" | ||
|
||
IOMatrixPi::IOMatrixPi() | ||
: IOWiringPi(4, 17, 22, 27) | ||
{ | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "iomatrixvoice.h" | ||
|
||
IOMatrixVoice::IOMatrixVoice() | ||
: IOWiringPi(27, 4, 17, 22) | ||
{ | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters