Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add clock selection got bladerf devices #1496

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion source_modules/bladerf_source/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <libbladeRF.h>
#include <gui/smgui.h>
#include <algorithm>
#include <utils/optionlist.h>

#define CONCAT(a, b) ((std::string(a) + b).c_str())

Expand Down Expand Up @@ -37,6 +38,10 @@ class BladeRFSourceModule : public ModuleManager::Instance {
BladeRFSourceModule(std::string name) {
this->name = name;

// Define clocks
clocks.define("onboard", "On-Board", CLOCK_SELECT_ONBOARD);
clocks.define("external", "External", CLOCK_SELECT_EXTERNAL);

sampleRate = 1000000.0;

handler.ctx = this;
Expand Down Expand Up @@ -267,6 +272,15 @@ class BladeRFSourceModule : public ModuleManager::Instance {
}
config.release(true);

// Load clock source
clkId = clocks.keyId("onboard");
if (config.conf["devices"][selectedSerial].contains("clock")) {
std::string clkStr = config.conf["devices"][selectedSerial]["clock"];
if (clocks.keyExists(clkStr)) {
clkId = clocks.keyId(clkStr);
}
}

// Load gain mode
if (config.conf["devices"][selectedSerial].contains("gainMode")) {
std::string gm = config.conf["devices"][selectedSerial]["gainMode"];
Expand Down Expand Up @@ -364,6 +378,7 @@ class BladeRFSourceModule : public ModuleManager::Instance {
if (_this->bufferSize < 1024) { _this->bufferSize = 1024; }

// Setup device parameters
_this->setClockSource(_this->clocks[_this->clkId]);
bladerf_set_sample_rate(_this->openDev, BLADERF_CHANNEL_RX(_this->chanId), _this->sampleRate, NULL);
bladerf_set_frequency(_this->openDev, BLADERF_CHANNEL_RX(_this->chanId), _this->freq);
bladerf_set_bandwidth(_this->openDev, BLADERF_CHANNEL_RX(_this->chanId), (_this->bwId == _this->bandwidths.size()) ? std::clamp<uint64_t>(_this->sampleRate, _this->bwRange->min, _this->bwRange->max) : _this->bandwidths[_this->bwId], NULL);
Expand Down Expand Up @@ -486,6 +501,19 @@ class BladeRFSourceModule : public ModuleManager::Instance {
}
}

SmGui::LeftLabel("Clock Source");
SmGui::FillWidth();
if (SmGui::Combo(CONCAT("##_balderf_clk_sel_", _this->name), &_this->clkId, _this->clocks.txt)) {
if (_this->running) {
_this->setClockSource(_this->clocks[_this->clkId]);
}
if (_this->selectedSerial != "") {
config.acquire();
config.conf["devices"][_this->selectedSerial]["clock"] = _this->clocks.key(_this->clkId);
config.release(true);
}
}

// General config BS
SmGui::LeftLabel("Gain control mode");
SmGui::FillWidth();
Expand Down Expand Up @@ -537,6 +565,15 @@ class BladeRFSourceModule : public ModuleManager::Instance {
}
}

void setClockSource(bladerf_clock_select clk) {
if (selectedBladeType == BLADERF_TYPE_V1) {
bladerf_set_smb_mode(openDev, (clk == CLOCK_SELECT_EXTERNAL) ? BLADERF_SMB_MODE_INPUT : BLADERF_SMB_MODE_DISABLED);
}
else {
bladerf_set_clock_select(openDev, clk);
}
}

void worker() {
int16_t* buffer = new int16_t[bufferSize * 2];
bladerf_metadata meta;
Expand Down Expand Up @@ -565,6 +602,7 @@ class BladeRFSourceModule : public ModuleManager::Instance {
int devId = 0;
int srId = 0;
int bwId = 0;
int clkId = 0;
int chanId = 0;
int gainMode = 0;
bool streamingEnabled = false;
Expand All @@ -580,8 +618,8 @@ class BladeRFSourceModule : public ModuleManager::Instance {
std::string sampleRatesTxt;
std::vector<uint64_t> bandwidths;
std::string bandwidthsTxt;

std::string channelNamesTxt;
OptionList<std::string, bladerf_clock_select> clocks;

int bufferSize;
struct bladerf_stream* rxStream;
Expand Down
Loading