-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New i2c implementation, support up to 4 faderbanks with teletype 5.0
- Loading branch information
Showing
11 changed files
with
89 additions
and
103 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 |
---|---|---|
@@ -1,55 +1,62 @@ | ||
#include "iiBus.h" | ||
#include "IIBus.h" | ||
#include "LibAVR32Module.hpp" | ||
|
||
iiFollowerData_t iiBus::FollowerData; | ||
#define FADERBANK_II_MAX_VALUE 16383 | ||
|
||
void iiBus::Initialize() | ||
{ | ||
for (int device = 0x34; device <= 0x37; device++) | ||
{ | ||
for (int fader = 0; fader < 16; fader++) | ||
{ | ||
iiBus::FollowerData.emplace(std::make_pair((device << 8) | fader, 0)); | ||
} | ||
} | ||
} | ||
extern rack::plugin::Model* modelFaderbank; | ||
|
||
iiDevice::iiDevice(rack::Module* module) | ||
: _module(module) | ||
IIBus::IIBus(LibAVR32Module* leader) | ||
: leader(leader) | ||
{ | ||
if (_module) | ||
{ | ||
_module->rightExpander.producerMessage = new iiCommand(); | ||
_module->leftExpander.producerMessage = new iiCommand(); | ||
} | ||
} | ||
|
||
void iiDevice::setAddress(uint8_t address) | ||
bool IIBus::isFollower(rack::Module* module) | ||
{ | ||
_address = address; | ||
// Only faderbanks participate in II right now | ||
return module != nullptr && module->model == modelFaderbank; | ||
} | ||
|
||
void iiDevice::updateFollowerData(uint8_t id, uint16_t data) | ||
void IIBus::step() | ||
{ | ||
const auto record = iiBus::FollowerData.find((_address << 8) | id); | ||
if (record != iiBus::FollowerData.end()) | ||
if (leader == nullptr) | ||
{ | ||
record->second.store(data, std::memory_order_relaxed); | ||
return; | ||
} | ||
} | ||
|
||
void iiDevice::transmit(const iiCommand& msg) | ||
{ | ||
if (_module) | ||
// let's tentatively define a bus as an unbroken chain of II-supporting | ||
// modules directly attached to either the left or right of the leader. | ||
|
||
// scan the "bus" for eligible modules, starting to the leader's left | ||
std::vector<rack::Module*> followers; | ||
auto module = leader->getLeftExpander().module; | ||
while (isFollower(module)) | ||
{ | ||
if (_module->rightExpander.producerMessage) | ||
{ | ||
*(reinterpret_cast<iiCommand*>(_module->rightExpander.producerMessage)) = msg; | ||
_module->rightExpander.messageFlipRequested = true; | ||
} | ||
if (_module->leftExpander.producerMessage) | ||
followers.push_back(module); | ||
module = module->getLeftExpander().module; | ||
} | ||
|
||
// flip the order, so we can prioritize left-to-right | ||
if (followers.size() > 1) | ||
{ | ||
std::reverse(followers.begin(), followers.end()); | ||
} | ||
|
||
// scan to the leader's right | ||
module = leader->getRightExpander().module; | ||
while (isFollower(module)) | ||
{ | ||
followers.push_back(module); | ||
module = module->getRightExpander().module; | ||
} | ||
|
||
// gather params from all followers | ||
for (size_t follower = 0; follower < std::min(static_cast<size_t>(4), followers.size()); follower++) | ||
{ | ||
for (uint8_t fader = 0; fader < std::min(16, followers[follower]->getNumParams()); fader++) | ||
{ | ||
*(reinterpret_cast<iiCommand*>(_module->leftExpander.producerMessage)) = msg; | ||
_module->leftExpander.messageFlipRequested = true; | ||
float voltage = followers[follower]->params[fader].getValue(); | ||
uint16_t value = static_cast<uint16_t>(voltage / 10.0 * FADERBANK_II_MAX_VALUE); | ||
leader->firmware.iiUpdateFollowerData(follower + 0x34, fader, value); | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
#pragma once | ||
#include "rack.hpp" | ||
#include "iiBus.h" | ||
|
||
#include <map> | ||
|
||
|
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