Skip to content

Commit

Permalink
Merge pull request #53 from okyeron/T4-compatibility
Browse files Browse the repository at this point in the history
Apply T4 changes
  • Loading branch information
okyeron authored Mar 5, 2023
2 parents 32b29ab + d358b21 commit 515c692
Show file tree
Hide file tree
Showing 18 changed files with 37,812 additions and 2,781 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
.DS_Store
.DS_Store
.DS_Store
.DS_Store
.DS_Store
15,398 changes: 15,398 additions & 0 deletions Firmware-Hexes/OMX-27-1.12.15-T32.hex

Large diffs are not rendered by default.

16,015 changes: 16,015 additions & 0 deletions Firmware-Hexes/OMX-27-1.12.15-T4.hex

Large diffs are not rendered by default.

94 changes: 58 additions & 36 deletions OMX-27-firmware/OMX-27-firmware.ino
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ int V_scale;

// ENCODER
Encoder myEncoder(12, 11); // encoder pins on hardware
Button encButton(0); // encoder button pin on hardware
const int buttonPin = 0;
int buttonState = 1;
Button encButton(buttonPin);

// long newPosition = 0;
// long oldPosition = -999;

Expand Down Expand Up @@ -201,22 +204,25 @@ void readPotentimeters()
{
int prevValue = potSettings.analogValues[k];
int prevAnalog = potSettings.analog[k]->getValue();

temp = analogRead(analogPins[k]);
potSettings.analog[k]->update(temp);

// read from the smoother, constrain (to account for tolerances), and map it
temp = potSettings.analog[k]->getValue();
temp = constrain(temp, potMinVal, potMaxVal);
potSettings.hiResPotVal[k] = temp;
temp = map(temp, potMinVal, potMaxVal, 0, 16383);
potSettings.hiResPotVal[k] = temp;

// map and update the value
potSettings.analogValues[k] = temp >> 7;

int newAnalog = potSettings.analog[k]->getValue();

// delta is way smaller on T4 - what to do??
int analogDelta = abs(newAnalog - prevAnalog);


// if (k == 1)
// {
// Serial.print(analogPins[k]);
Expand Down Expand Up @@ -383,7 +389,7 @@ bool loadHeader(void)
uint8_t unMidiChannel = storage->read(EEPROM_HEADER_ADDRESS + 3);
sysSettings.midiChannel = unMidiChannel + 1;

Serial.println( "loading banks" );
Serial.println( "Loading banks" );
for (int b = 0; b < NUM_CC_BANKS; b++)
{
for (int i = 0; i < NUM_CC_POTS; i++)
Expand Down Expand Up @@ -440,7 +446,6 @@ void savePatterns(void)
{
return;
}

Serial.println((String)"nLocalAddress: " + nLocalAddress);

// Grids patterns
Expand All @@ -460,25 +465,23 @@ void savePatterns(void)

nLocalAddress += patternSize;
}

Serial.println((String)"nLocalAddress: " + nLocalAddress); // 5968

Serial.println("Saving Euclidean");
nLocalAddress = omxModeEuclid.saveToDisk(nLocalAddress, storage);
Serial.println((String)"nLocalAddress: " + nLocalAddress); // 6321

Serial.println("Saving Chords");
nLocalAddress = omxModeChords.saveToDisk(nLocalAddress, storage);
Serial.println((String)"nLocalAddress: " + nLocalAddress); // 6321

Serial.println("Saving MidiFX");

for(uint8_t i = 0; i < NUM_MIDIFX_GROUPS; i++)
{
nLocalAddress = subModeMidiFx[i].saveToDisk(nLocalAddress, storage);
// Serial.println((String)"Saved: " + i);
// Serial.println((String)"nLocalAddress: " + nLocalAddress);
}

Serial.println((String)"nLocalAddress: " + nLocalAddress); // 6321

// Seq patternSize: 715
Expand All @@ -498,7 +501,7 @@ void loadPatterns(void)
int patternSize = serializedPatternSize(isEeprom);
int nLocalAddress = EEPROM_PATTERN_ADDRESS;

Serial.println( "seq patterns nLocalAddress" );
Serial.print( "Seq patterns - nLocalAddress: " );
Serial.println( nLocalAddress );

int seqPatternNum = isEeprom ? NUM_SEQ_PATTERNS_EEPROM : NUM_SEQ_PATTERNS;
Expand All @@ -522,7 +525,7 @@ void loadPatterns(void)
return;
}

Serial.println( "grids patterns nLocalAddress" );
Serial.print( "Grids patterns - nLocalAddress: " );
Serial.println( nLocalAddress );
// 332 - eeprom size
// 332 * 8 = 2656
Expand All @@ -544,29 +547,29 @@ void loadPatterns(void)
nLocalAddress += patternSize;
}

Serial.println( "Pattern size" );
Serial.println( patternSize );
Serial.println( "nLocalAddress" );
Serial.print( "Pattern size: " );
Serial.print( patternSize );

Serial.print( " - nLocalAddress: " );
Serial.println( nLocalAddress );

Serial.println("Loading Euclidean");
Serial.print("Loading Euclidean - ");
nLocalAddress = omxModeEuclid.loadFromDisk(nLocalAddress, storage);
Serial.println((String)"nLocalAddress: " + nLocalAddress); // 5988
Serial.println("Loading Chords");

Serial.print("Loading Chords - ");
nLocalAddress = omxModeChords.loadFromDisk(nLocalAddress, storage);
Serial.println((String)"nLocalAddress: " + nLocalAddress); // 5988

// Serial.println((String)"nLocalAddress: " + nLocalAddress); // 5968

Serial.println("Loading MidiFX");

Serial.print("Loading MidiFX - ");
for(uint8_t i = 0; i < NUM_MIDIFX_GROUPS; i++)
{
nLocalAddress = subModeMidiFx[i].loadFromDisk(nLocalAddress, storage);
// Serial.println((String)"Loaded: " + i);
// Serial.println((String)"nLocalAddress: " + nLocalAddress);
}

Serial.println((String)"nLocalAddress: " + nLocalAddress); // 5988

// with 8 note chords, 10929
Expand Down Expand Up @@ -602,12 +605,12 @@ bool loadFromStorage(void)
// This load can happen soon after Serial.begin - enable this 'wait for Serial' if you need to Serial.print during loading
// while( !Serial );

Serial.println( "read the header" );
Serial.println( "Read the header" );
bool bContainedData = loadHeader();

if (bContainedData)
{
Serial.println( "loading patterns" );
Serial.println( "Loading patterns" );
loadPatterns();
changeOmxMode(sysSettings.omxMode);

Expand All @@ -616,7 +619,7 @@ bool loadFromStorage(void)
return true;
}

Serial.println( "failed to load" );
Serial.println( "-- Failed to load --" );

omxDisp.isDirty();
omxLeds.isDirty();
Expand Down Expand Up @@ -873,6 +876,10 @@ void setup()
{
Serial.begin(115200);
// while( !Serial );
#if T4
// Serial.println("DAC Start!");
dac.begin(DAC_ADDR);
#endif
storage = Storage::initStorage();
sysEx = new SysEx(storage, &sysSettings);

Expand All @@ -893,40 +900,55 @@ void setup()
lastProcessTime = micros();
omxUtil.resetClocks();

// HW MIDI
MM::begin();

randomSeed(analogRead(13));
srand(analogRead(13));

// SET ANALOG READ resolution to teensy's 13 usable bits
analogReadResolution(13);
#if T4
analogReadResolution(10); // Teensy 4 = 10 bits
#else
analogReadResolution(13); // Teensy 3.x = 13 bits
#endif

// CV GATE pin
pinMode(CVGATE_PIN, OUTPUT);
// ENCODER BUTTON pin
pinMode(buttonPin, INPUT_PULLUP);

// initialize ResponsiveAnalogRead
// initialize ANALOG INPUTS and ResponsiveAnalogRead
for (int i = 0; i < potCount; i++)
{
potSettings.analog[i] = new ResponsiveAnalogRead(0, true, .001);
potSettings.analog[i]->setAnalogResolution(1 << 13);
// potSettings.analog[i] = new ResponsiveAnalogRead(0, true, .001);
// potSettings.analog[i]->setAnalogResolution(1 << 13);
pinMode(analogPins[i], INPUT);
potSettings.analog[i] = new ResponsiveAnalogRead(analogPins[i], true, .001);

// ResponsiveAnalogRead is designed for 10-bit ADCs
// meanining its threshold defaults to 4. Let's bump that for
// our 13-bit adc by setting it to 4 << (13-10)
potSettings.analog[i]->setActivityThreshold(32);
#if T4
// potSettings.analog[i]->setAnalogResolution(10);
// potSettings.analog[i]->setActivityThreshold(8);
#else
potSettings.analog[i]->setAnalogResolution(1 << 13);
potSettings.analog[i]->setActivityThreshold(32);
#endif

currentValue[i] = 0;
lastMidiValue[i] = 0;
}


// HW MIDI
MM::begin();

// CV gate pin
pinMode(CVGATE_PIN, OUTPUT);

// set DAC Resolution CV/GATE
RES = 12;
analogWriteResolution(RES); // set resolution for DAC
AMAX = pow(2, RES);
V_scale = 64; // pow(2,(RES-7)); 4095 max

#if T4
dac.setVoltage(0, false);
#else
analogWriteResolution(RES); // set resolution for DAC
analogWrite(CVPITCH_PIN, 0);
#endif

globalScale.calculateScale(scaleConfig.scaleRoot, scaleConfig.scalePattern);
omxModeMidi.SetScale(&globalScale);
Expand Down
16 changes: 12 additions & 4 deletions OMX-27-firmware/src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@ const int LED_COUNT = 27;

#if DEV
const int analogPins[] = {23,22,21,20,16}; // DEV/beta boards
const byte DAC_ADDR = 0x62;
#elif MIDIONLY
const int analogPins[] = {23,22,21,20,16}; // on MIDI only boards - {23,A10,21,20,16} on Bodged MIDI boards
const byte DAC_ADDR = 0x60;
#elif T4
const int analogPins[] = {23,22,21,20,16}; // on 2.0
const byte DAC_ADDR = 0x60;
#else
const int analogPins[] = {34,22,21,20,16}; // on 1.0
const byte DAC_ADDR = 0x60;
#endif

const int potCount = NUM_CC_POTS;
Expand All @@ -41,7 +47,11 @@ int pots[NUM_CC_BANKS][NUM_CC_POTS] = {
}; // the MIDI CC (continuous controller) for each analog input

int potMinVal = 0;
int potMaxVal = 8190;
#if T4
int potMaxVal = 1019; // T4 = 1019 // T3.2 = 8190;
#else
int potMaxVal = 8190; // T4 = 1019 // T3.2 = 8190;
#endif

const int gridh = 32;
const int gridw = 128;
Expand Down Expand Up @@ -89,8 +99,7 @@ const int steps[] = {0,

const int midiKeyMap[] = {12,1,13,2,14,15,3,16,4,17,5,18,19,6,20,7,21,22,8,23,9,24,10,25,26};



Adafruit_MCP4725 dac;
SysSettings sysSettings;
PotSettings potSettings;
MidiConfig midiSettings;
Expand All @@ -103,4 +112,3 @@ ScaleConfig scaleConfig;

// MidiPage midiPageParams;
// SequencerPage seqPageParams;

7 changes: 7 additions & 0 deletions OMX-27-firmware/src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <stdarg.h>
#include <stdint.h>
#include <ResponsiveAnalogRead.h>
#include <Wire.h>
#include <Adafruit_MCP4725.h>
#include "colors.h"

// #include <cstdarg>
Expand All @@ -20,6 +22,9 @@ const int POINT_VERSION = 15;

const int DEVICE_ID = 2;

// DAC
extern Adafruit_MCP4725 dac;

enum OMXMode
{
MODE_MIDI = 0,
Expand Down Expand Up @@ -65,6 +70,8 @@ extern const uint8_t EEPROM_VERSION;

// next address 1104 (was 1096 before clock)

extern const byte DAC_ADDR;

// DEFINE CC NUMBERS FOR POTS // CCS mapped to Organelle Defaults
extern const int CC1;
extern const int CC2;
Expand Down
9 changes: 8 additions & 1 deletion OMX-27-firmware/src/consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,25 @@

// HW_VERSIONS
#define DEV 0
#define T4 1
#define MIDIONLY 0

// HARDWARE Pin for CVGATE_PIN = 13 on beta1 boards, 22 on bodge/midi, 23 on 1.0
#if DEV
const int CVGATE_PIN = 13;
#elif T4
const int CVGATE_PIN = 13;
#elif MIDIONLY
const int CVGATE_PIN = 22; // 13 on beta1 boards, A10 (broken) on test/midi, 23 on 1.0
#else
const int CVGATE_PIN = 23; // 13 on beta1 boards, 22 on test, 23 on 1.0
#endif

const int CVPITCH_PIN = A14;
#if T4
// const int CVPITCH_PIN = A14;
#else
const int CVPITCH_PIN = A14;
#endif

const int loSkip = 0;
const int hiSkip = 0;
Expand Down
12 changes: 9 additions & 3 deletions OMX-27-firmware/src/noteoffs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <Arduino.h>
#include "consts.h"
#include "config.h"
#include "MM.h"

PendingNoteHistory::PendingNoteHistory()
Expand Down Expand Up @@ -124,7 +125,7 @@ bool PendingNoteOffs::sendOffIfPresent(int note, int channel, bool sendCV)
if (queue[i].inUse && queue[i].channel == channel && queue[i].note == note)
{
// Send note off event for first note found
// Other pending note offs just get set to not in use.
// Other pending note offs just get set to not in use.
if (!noteOffSent)
{
pendingNoteHistory.insert(queue[i].note, queue[i].channel);
Expand Down Expand Up @@ -194,7 +195,7 @@ PendingNoteOns::PendingNoteOns() {
}

bool PendingNoteOns::insert(int note, int velocity, int channel, uint32_t time, bool sendCV) {

// pendingNoteOffs.sendOffIfPresent(note, channel, sendCV);

for (int i = 0; i < queueSize; ++i) {
Expand Down Expand Up @@ -241,8 +242,13 @@ void PendingNoteOns::play(uint32_t now)
if (queue[i].note >= midiLowestNote && queue[i].note < midiHightestNote)
{
pCV = static_cast<int>(roundf((queue[i].note - midiLowestNote) * stepsPerSemitone));
// map (adjnote, 36, 91, 0, 4080);
digitalWrite(CVGATE_PIN, HIGH);
analogWrite(CVPITCH_PIN, pCV);
#if T4
dac.setVoltage(pCV, false);
#else
analogWrite(CVPITCH_PIN, pCV);
#endif
}
}
queue[i].inUse = false;
Expand Down
Loading

0 comments on commit 515c692

Please sign in to comment.