Skip to content

Commit

Permalink
extend compatibility to non-AVR boards
Browse files Browse the repository at this point in the history
  • Loading branch information
ni-vpacella committed Nov 24, 2016
1 parent f52bc89 commit 641b07b
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
65 changes: 62 additions & 3 deletions Synapse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,31 @@ void Synapse::begin(unsigned spiDivider_)
{
pinMode(k_pinCVInA, INPUT);
pinMode(k_pinCVInB, INPUT);
pinMode(k_pinGateInA, INPUT);
pinMode(k_pinGateInB, INPUT);

pinMode(k_pinChipSelectDAC, OUTPUT);
pinMode(k_pinCVOutConfA, OUTPUT);
pinMode(k_pinCVOutConfB, OUTPUT);
pinMode(k_pinGateOutA, OUTPUT);
pinMode(k_pinGateOutB, OUTPUT);

#if defined __AVR__
m_outputChipSelectDAC = HIGH;
m_outputCVOutConfA = LOW;
m_outputCVOutConfB = LOW;
#else
digitalWrite(k_pinChipSelectDAC, HIGH);
digitalWrite(k_pinCVOutConfA, LOW);
digitalWrite(k_pinCVOutConfB, LOW);
#endif

SPI.begin();

SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);

setSPIDivider(spiDivider_);

updateCVRanges();
}

Expand Down Expand Up @@ -91,10 +106,21 @@ void Synapse::writeCV(CVChannel channel_, uint16_t value_)
return;
}
}

#if defined __AVR__
m_outputChipSelectDAC = LOW;
#else
digitalWrite(k_pinChipSelectDAC, LOW);
#endif

SPI.transfer(msg1);
SPI.transfer(msg2);

#if defined __AVR__
m_outputChipSelectDAC = HIGH;
#else
digitalWrite(k_pinChipSelectDAC, HIGH);
#endif
}

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -151,11 +177,19 @@ bool Synapse::readGate(GateChannel channel_)
{
case GateChannel::A:
{
#if defined __AVR__
return m_inputGateA;
#else
return digitalRead(k_pinGateInA);
#endif
}
case GateChannel::B:
{
#if defined __AVR__
return m_inputGateB;
#else
return digitalRead(k_pinGateInB);
#endif
}
default:
{
Expand All @@ -172,12 +206,21 @@ void Synapse::writeGate(GateChannel channel_, bool state_)
{
case GateChannel::A:
{
#if defined __AVR__
m_outputGateA = state_ ? LOW : HIGH;
#else
digitalWrite(k_pinGateOutA, (state_ ? LOW : HIGH));
#endif

break;
}
case GateChannel::B:
{
#if defined __AVR__
m_outputGateB = state_ ? LOW : HIGH;
#else
digitalWrite(k_pinGateOutB, (state_ ? LOW : HIGH));
#endif
break;
}
default:
Expand Down Expand Up @@ -230,11 +273,11 @@ void Synapse::setSPIDivider(unsigned spiDivider_)
}
default:
{
m_spiDivider = SPI_CLOCK_DIV8;
m_spiDivider = SPI_CLOCK_DIV2;
}
}
#else
m_spiDivider = SPI_CLOCK_DIV8;
m_spiDivider = SPI_CLOCK_DIV2;
#endif
SPI.setClockDivider(m_spiDivider);
}
Expand All @@ -251,23 +294,39 @@ void Synapse::updateCVRanges()
{
if (channel == 0)
{
#if defined __AVR__
m_outputCVOutConfA = LOW;
#else
digitalWrite(k_pinCVOutConfA, LOW);
#endif
}
else
{
#if defined __AVR__
m_outputCVOutConfB = LOW;
#else
digitalWrite(k_pinCVOutConfB, LOW);
#endif
}
break;
}
case Range::MinusFiveToFiveVolts:
{
if (channel == 0)
{
#if defined __AVR__
m_outputCVOutConfA = HIGH;
#else
digitalWrite(k_pinCVOutConfA, HIGH);
#endif
}
else
{
#if defined __AVR__
m_outputCVOutConfB = HIGH;
#else
digitalWrite(k_pinCVOutConfB, HIGH);
#endif
}
break;
}
Expand Down
4 changes: 4 additions & 0 deletions Synapse.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#pragma once

#include <SPI.h>
#if defined __AVR__
#include <DirectIO.h> // --> https://github.com/mmarchetti/DirectIO.git
#endif

//--------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -130,6 +132,7 @@ class Synapse
void setSPIDivider(unsigned spiDivider_);
void updateCVRanges();

#if defined __AVR__
Input<k_pinGateInA> m_inputGateA;
Input<k_pinGateInB> m_inputGateB;

Expand All @@ -138,6 +141,7 @@ class Synapse
Output<k_pinGateOutB> m_outputGateB;
Output<k_pinCVOutConfA> m_outputCVOutConfA;
Output<k_pinCVOutConfB> m_outputCVOutConfB;
#endif

Range m_channelRange[k_numCVOutputs]{Range::ZeroToTenVolts, Range::ZeroToTenVolts};
unsigned m_spiDivider;
Expand Down

0 comments on commit 641b07b

Please sign in to comment.