Skip to content

Commit

Permalink
Add teletype 4 and 5 firmware, add switching menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Dewb committed Aug 27, 2023
1 parent 2147c80 commit 8d4b004
Show file tree
Hide file tree
Showing 19 changed files with 143 additions and 60 deletions.
6 changes: 5 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
url = https://github.com/Dewb/whitewhale
branch = vcvrack_pr
[submodule "firmware/teletype"]
path = firmware/teletype
path = firmware/teletype4
url = https://github.com/Dewb/teletype
branch = vcvrack-4.0.0
[submodule "firmware/meadowphysics"]
Expand All @@ -17,3 +17,7 @@
[submodule "firmware/ansible"]
path = firmware/ansible
url = https://github.com/Dewb/ansible
[submodule "firmware/firmware/teletype-5"]
path = firmware/teletype5
url = https://github.com/Dewb/teletype
branch = vcvrack-5
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ firmware-build: firmware/*.mk firmware/**/*.c firmware/**/*.h firmware/**/**/*.r
cd firmware && $(MAKE) -f whitewhale.mk
cd firmware && $(MAKE) -f meadowphysics.mk
cd firmware && $(MAKE) -f earthsea.mk
cd firmware && $(MAKE) -f teletype.mk
cd firmware && $(MAKE) -f teletype.mk TARGET_NAME=teletype4
cd firmware && $(MAKE) -f teletype.mk TARGET_NAME=teletype5
cd firmware && $(MAKE) -f ansible.mk

firmware-clean:
Expand Down
2 changes: 1 addition & 1 deletion firmware/mock_hardware/mock_hardware_api.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef MOCK_API_SKIP_TYPES
#include "../teletype/src/serializer.h"
#include "../teletype4/src/serializer.h"
#include <stdint.h>
#include <stdbool.h>
#endif
Expand Down
11 changes: 11 additions & 0 deletions firmware/mock_hardware/modules/teletype/adapter_teletype.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "mock_hardware_api.h"
#include "mock_hardware_api_private.h"
#include "flashc.h"

#include "module/edit_mode.h"
#include "module/flash.h"
Expand All @@ -11,6 +12,16 @@
#include "src/teletype_io.h"
#include "types.h"

extern nvram_data_t f;
extern scene_state_t scene_state;

#ifdef DECLARE_NVRAM
DECLARE_NVRAM(&f, sizeof(nvram_data_t))
#endif
#ifdef DECLARE_VRAM
DECLARE_VRAM(&scene_state, sizeof(scene_state))
#endif

void clock_null(uint8_t phase) { }
typedef void (*clock_pulse_t)(uint8_t phase);
volatile uint8_t clock_external;
Expand Down
10 changes: 10 additions & 0 deletions firmware/mock_hardware/modules/teletype/usb_disk_mode.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <stdint.h>

void handler_usb_PollADC(int32_t data) {
}

void handler_usb_Front(int32_t data) {
}

void handler_usb_ScreenRefresh(int32_t data) {
}
1 change: 0 additions & 1 deletion firmware/teletype
Submodule teletype deleted from efd650
76 changes: 37 additions & 39 deletions firmware/teletype.mk
Original file line number Diff line number Diff line change
@@ -1,59 +1,57 @@
TARGET_NAME := teletype

FLAGS += \
-D__AVR32_UC3B0512__ \
-Imock_hardware \
-Imock_hardware/include \
-Iteletype/libavr32/src \
-Iteletype/libavr32/src/usb/midi \
-Iteletype/libavr32/src/usb/hid \
-Iteletype/libavr32/src/usb/cdc \
-Iteletype/libavr32/src/usb/ftdi \
-Iteletype/libavr32/conf \
-Iteletype/libavr32/conf/teletype \
-Iteletype/libavr32/asf/common/services/usb \
-Iteletype/libavr32/asf/common/services/usb/uhc \
-Iteletype/libavr32/asf/common/services/usb/class/hid \
-Iteletype/src \
-Iteletype/src/ops \
-Iteletype/ \
-I$(TARGET_NAME)/libavr32/src \
-I$(TARGET_NAME)/libavr32/src/usb/midi \
-I$(TARGET_NAME)/libavr32/src/usb/hid \
-I$(TARGET_NAME)/libavr32/src/usb/cdc \
-I$(TARGET_NAME)/libavr32/src/usb/ftdi \
-I$(TARGET_NAME)/libavr32/conf \
-I$(TARGET_NAME)/libavr32/conf/teletype \
-I$(TARGET_NAME)/libavr32/asf/common/services/usb \
-I$(TARGET_NAME)/libavr32/asf/common/services/usb/uhc \
-I$(TARGET_NAME)/libavr32/asf/common/services/usb/class/hid \
-I$(TARGET_NAME)/src \
-I$(TARGET_NAME)/src/ops \
-I$(TARGET_NAME)/ \

SOURCES = \
$(wildcard teletype/src/*.c) \
teletype/src/scanner.c \
teletype/src/match_token.c \
teletype/module/gitversion.c \
$(wildcard teletype/src/ops/*.c) \
$(wildcard teletype/module/*.c) \
teletype/libavr32/src/events.c \
teletype/libavr32/src/timers.c \
teletype/libavr32/src/util.c \
teletype/libavr32/src/font.c \
teletype/libavr32/src/kbd.c \
teletype/libavr32/src/region.c \
teletype/libavr32/src/random.c \
teletype/libavr32/src/usb/hid/hid.c \
teletype/libavr32/src/music.c \
teletype/libavr32/src/midi_common.c \
$(wildcard teletype/libavr32/src/euclidean/*.c) \
$(wildcard $(TARGET_NAME)/src/*.c) \
$(TARGET_NAME)/src/scanner.c \
$(TARGET_NAME)/src/match_token.c \
$(TARGET_NAME)/module/gitversion.c \
$(wildcard $(TARGET_NAME)/src/ops/*.c) \
$(wildcard $(TARGET_NAME)/module/*.c) \
$(TARGET_NAME)/libavr32/src/events.c \
$(TARGET_NAME)/libavr32/src/timers.c \
$(TARGET_NAME)/libavr32/src/util.c \
$(TARGET_NAME)/libavr32/src/font.c \
$(TARGET_NAME)/libavr32/src/kbd.c \
$(TARGET_NAME)/libavr32/src/region.c \
$(TARGET_NAME)/libavr32/src/random.c \
$(TARGET_NAME)/libavr32/src/usb/hid/hid.c \
$(TARGET_NAME)/libavr32/src/music.c \
$(TARGET_NAME)/libavr32/src/midi_common.c \
$(wildcard $(TARGET_NAME)/libavr32/src/euclidean/*.c) \
$(wildcard mock_hardware/*.c) \
$(wildcard mock_hardware/common/*.c) \
$(wildcard mock_hardware/modules/teletype/*.c) \

SOURCES := $(filter-out teletype/module/usb_disk_mode.c, $(SOURCES))
SOURCES := $(filter-out $(TARGET_NAME)/module/usb_disk_mode.c, $(SOURCES))

RAGEL ?= ragel

# Add a rule to build match_token.c from match_token.rl
teletype/src/match_token.c: teletype/src/match_token.rl
$(RAGEL) -C -G2 teletype/src/match_token.rl -o teletype/src/match_token.c
$(TARGET_NAME)/src/match_token.c: $(TARGET_NAME)/src/match_token.rl
$(RAGEL) -C -G2 $(TARGET_NAME)/src/match_token.rl -o $(TARGET_NAME)/src/match_token.c

# Add a rule to build scanner.c from scanner.rl
teletype/src/scanner.c: teletype/src/scanner.rl
$(RAGEL) -C -G2 teletype/src/scanner.rl -o teletype/src/scanner.c
$(TARGET_NAME)/src/scanner.c: $(TARGET_NAME)/src/scanner.rl
$(RAGEL) -C -G2 $(TARGET_NAME)/src/scanner.rl -o $(TARGET_NAME)/src/scanner.c

# Add the git commit id to a file for use when printing out the version
teletype/module/gitversion.c: teletype
echo "const char *git_version = \"$(shell cut -d '-' -f 1 <<< $(shell cd teletype; git describe --tags | cut -c 1-)) $(shell cd teletype; git describe --always --dirty --exclude '*' | tr '[a-z]' '[A-Z]')\";" > $@
$(TARGET_NAME)/module/gitversion.c: $(TARGET_NAME)
echo "const char *git_version = \"$(shell cut -d '-' -f 1 <<< $(shell cd $(TARGET_NAME); git describe --tags | cut -c 1-)) $(shell cd $(TARGET_NAME); git describe --always --dirty --exclude '*' | tr '[a-z]' '[A-Z]')\";" > $@

include common.mk
1 change: 1 addition & 0 deletions firmware/teletype4
Submodule teletype4 added at 407c6e
1 change: 1 addition & 0 deletions firmware/teletype5
Submodule teletype5 added at 75e3b7
2 changes: 1 addition & 1 deletion src/ansible/AnsibleModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct AnsibleModule : LibAVR32Module
rack::dsp::SchmittTrigger inputTriggers[2];

AnsibleModule()
: LibAVR32Module("ansible")
: LibAVR32Module("ansible", "ansible")
{
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
configButton(KEY1_PARAM, "KEY 1");
Expand Down
7 changes: 4 additions & 3 deletions src/common/core/FirmwareManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,17 @@ FirmwareManager::~FirmwareManager()
delete impl;
}

bool FirmwareManager::load(std::string modulePath)
bool FirmwareManager::load(std::string firmwareName)
{
delete impl;
impl = new FirmwareManagerImpl();
if (!impl->load(modulePath))
if (!impl->load(firmwareName))
{
impl = nullptr;
WARN("Could not load firmware %s", modulePath.c_str());
WARN("Could not load firmware %s", firmwareName.c_str());
return false;
}
loadedName = firmwareName;
return true;
}

Expand Down
6 changes: 5 additions & 1 deletion src/common/core/FirmwareManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ struct FirmwareManager
FirmwareManager();
~FirmwareManager();

bool load(std::string firmwarePath);
bool load(std::string firmwareName);
void unload();

const std::string& getLoadedName() const { return loadedName; }

void setClockPeriod(float seconds);
void advanceClock(float seconds);

Expand All @@ -30,4 +32,6 @@ struct FirmwareManager
#include "mock_hardware_api.h"

struct FirmwareManagerImpl* impl;
protected:
std::string loadedName;
};
26 changes: 21 additions & 5 deletions src/common/core/LibAVR32Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
#include "base64.h"
#include <string.h>

LibAVR32Module::LibAVR32Module(std::string firmwareName)
LibAVR32Module::LibAVR32Module(std::string firmwarePrefix, std::string defaultFirmwareName)
: lastConnectedDeviceId("")
, currentConnectedDeviceId("")
, firmwareName(firmwareName)
, firmwarePrefix(firmwarePrefix)
, firmwareName(defaultFirmwareName)
, defaultFirmwareName(defaultFirmwareName)
, usbParamId(-1)
, theme(GridTheme::Yellow)
{
Expand Down Expand Up @@ -274,16 +276,21 @@ void LibAVR32Module::readSerialMessages()
}
}

void LibAVR32Module::requestReloadFirmware(bool preserveMemory)
void LibAVR32Module::requestReloadFirmware(bool preserveMemory, const std::string& firmwareName)
{
audioThreadActions.push([this, preserveMemory]() { this->reloadFirmware(preserveMemory); });
audioThreadActions.push([this, preserveMemory, firmwareName]() { this->reloadFirmware(preserveMemory, firmwareName); });
}

void LibAVR32Module::reloadFirmware(bool preserveMemory)
void LibAVR32Module::reloadFirmware(bool preserveMemory, const std::string& newName)
{
void *data, *nvram_copy, *vram_copy = 0;
uint32_t nvram_size, vram_size = 0;

firmwareName = newName.empty() ? firmware.getLoadedName() : newName;
if (firmwareName != firmware.getLoadedName()) {
preserveMemory = false;
}

if (preserveMemory) {
firmware.readNVRAM(&data, &nvram_size);
nvram_copy = malloc(nvram_size);
Expand Down Expand Up @@ -351,6 +358,7 @@ json_t* LibAVR32Module::dataToJson()
}

json_t* rootJ = json_object();
json_object_set_new(rootJ, "firmwareName", json_string(firmwareName.c_str()));
json_object_set_new(rootJ, "connectedDeviceId", json_string(deviceId.c_str()));
json_object_set_new(rootJ, "connectionOwned", json_boolean(connectionOwned));
json_object_set_new(rootJ, "inputRate", json_integer(inputRate));
Expand All @@ -376,6 +384,14 @@ json_t* LibAVR32Module::dataToJson()

void LibAVR32Module::dataFromJson(json_t* rootJ)
{
json_t* jsonFirmwareName = json_object_get(rootJ, "firmwareName");
std::string newFirmwareName = jsonFirmwareName ? json_string_value(jsonFirmwareName) : defaultFirmwareName;

if (newFirmwareName != firmwareName)
{
reloadFirmware(false, newFirmwareName);
}

json_t* id = json_object_get(rootJ, "connectedDeviceId");
if (id)
{
Expand Down
8 changes: 5 additions & 3 deletions src/common/core/LibAVR32Module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct LibAVR32Module : rack::engine::Module, GridConsumer
{
FirmwareManager firmware;

LibAVR32Module(std::string firmwareName);
LibAVR32Module(std::string firmwarePrefix, std::string defaultFirmwareName);
~LibAVR32Module();

// Rack module methods
Expand All @@ -58,7 +58,7 @@ struct LibAVR32Module : rack::engine::Module, GridConsumer
void userToggleGridConnection(Grid* grid);
virtual void readSerialMessages();

void requestReloadFirmware(bool preserveMemory);
void requestReloadFirmware(bool preserveMemory, const std::string& firmwareName = "");

float dacToVolts(uint16_t adc);
uint16_t voltsToAdc(float volts);
Expand All @@ -67,7 +67,9 @@ struct LibAVR32Module : rack::engine::Module, GridConsumer
std::string currentConnectedDeviceId;
bool connectionOwned;

std::string firmwarePrefix;
std::string firmwareName;
std::string defaultFirmwareName;

int inputRate;
int outputRate;
Expand All @@ -77,7 +79,7 @@ struct LibAVR32Module : rack::engine::Module, GridConsumer
virtual uint8_t* getScreenBuffer() { return 0; }

protected:
void reloadFirmware(bool preserveMemory);
void reloadFirmware(bool preserveMemory, const std::string& newFirmware = "");
void toggleGridConnection(Grid* grid);

Grid* gridConnection;
Expand Down
35 changes: 35 additions & 0 deletions src/common/core/LibAVR32ModuleWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,33 @@ struct ReloadFirmwareItem : rack::ui::MenuItem
}
};

struct SwitchFirmwareItem : rack::ui::MenuItem
{
LibAVR32Module* module;

ui::Menu* createChildMenu() override
{
ui::Menu* menu = new ui::Menu;

// TODO: populate this from looking in the firmware folder for binaries starting with the module basename
std::string names[] = { "teletype4", "teletype5" };

for (int i = 0; i < 2; i++)
{
menu->addChild(createCheckMenuItem(
names[i],
"",
[=]()
{ return module->firmware.getLoadedName() == names[i]; },
[=]()
{ module->requestReloadFirmware(false, names[i]); }
));
}

return menu;
}
};

struct ioRateItem : rack::ui::MenuItem
{
int* target = nullptr;
Expand Down Expand Up @@ -91,6 +118,14 @@ struct FirmwareSubmenuItem : MenuItem

menu->addChild(new MenuSeparator());

// TODO: enable for other modules
if (m->firmwarePrefix == "teletype") {
menu->addChild(construct<SwitchFirmwareItem>(
&MenuItem::text, "Switch Firmware", &MenuItem::rightText, RIGHT_ARROW,
&SwitchFirmwareItem::module, m
));
}

auto reloadItem = new ReloadFirmwareItem();
reloadItem->text = "Reload & Restart";
reloadItem->module = m;
Expand Down
2 changes: 1 addition & 1 deletion src/earthsea/EarthseaModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct EarthseaModule : LibAVR32Module
};

EarthseaModule()
: LibAVR32Module("earthsea")
: LibAVR32Module("earthsea", "earthsea")
{
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);

Expand Down
2 changes: 1 addition & 1 deletion src/meadowphysics/MeadowphysicsModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct MeadowphysicsModule : LibAVR32Module
rack::dsp::SchmittTrigger clockTrigger;

MeadowphysicsModule()
: LibAVR32Module("meadowphysics")
: LibAVR32Module("meadowphysics", "meadowphysics")
{
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
configButton(BUTTON_PARAM, "PRESET");
Expand Down
2 changes: 1 addition & 1 deletion src/teletype/TeletypeModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct TTParamQuantity : rack::engine::ParamQuantity
};

TeletypeModule::TeletypeModule()
: LibAVR32Module("teletype")
: LibAVR32Module("teletype", "teletype4")
, _iiDevice(this)
, screenBuffer{}
{
Expand Down
Loading

0 comments on commit 8d4b004

Please sign in to comment.