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

Regmap API #1692

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion plugins/regmap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ configure_file(
)
set(SRC_LIST ${SRC_LIST} ${CMAKE_CURRENT_SOURCE_DIR}/include/${SCOPY_MODULE}/scopy-${SCOPY_MODULE}_config.h)

add_library(${PROJECT_NAME} SHARED ${PROJECT_SOURCES} ${PROJECT_RESOURCES})
add_library(${PROJECT_NAME} SHARED ${PROJECT_SOURCES} ${PROJECT_RESOURCES}
src/regmap_api.h
src/regmap_api.cpp)

generate_export_header(
${PROJECT_NAME} EXPORT_FILE_NAME ${CMAKE_CURRENT_SOURCE_DIR}/include/${SCOPY_MODULE}/${PROJECT_NAME}_export.h
Expand Down
4 changes: 4 additions & 0 deletions plugins/regmap/include/regmap/regmapplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ namespace regmap {

class RegisterMapTool;
class JsonFormatedElement;
class RegMap_API;

class SCOPY_REGMAP_EXPORT RegmapPlugin : public QObject, public PluginBase
{
friend class RegMap_API;
Q_OBJECT
SCOPY_PLUGIN;

Expand Down Expand Up @@ -59,6 +61,8 @@ public Q_SLOTS:
struct iio_device *getIioDevice(iio_context *ctx, const char *dev_name);
bool isBufferCapable(iio_device *dev);
RegisterMapTool *registerMapTool;
void InitApi();
RegMap_API *api;
};
} // namespace regmap
} // namespace scopy
Expand Down
2 changes: 2 additions & 0 deletions plugins/regmap/src/deviceregistermap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ bool DeviceRegisterMap::hasTemplate()
return false;
}

bool DeviceRegisterMap::getAutoread() { return autoread; }

void DeviceRegisterMap::initSettings()
{
QObject::connect(this, &DeviceRegisterMap::requestRead, registerMapValues, &RegisterMapValues::requestRead);
Expand Down
2 changes: 2 additions & 0 deletions plugins/regmap/src/deviceregistermap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class RegisterMapTable;

class SCOPY_REGMAP_EXPORT DeviceRegisterMap : public QWidget
{
friend class RegMap_API;
Q_OBJECT
public:
explicit DeviceRegisterMap(RegisterMapTemplate *registerMapTemplate = nullptr,
Expand All @@ -34,6 +35,7 @@ class SCOPY_REGMAP_EXPORT DeviceRegisterMap : public QWidget
void toggleAutoread(bool toggled);
void applyFilters(QString filter);
bool hasTemplate();
bool getAutoread();

private:
ToolTemplate *tool;
Expand Down
1 change: 1 addition & 0 deletions plugins/regmap/src/registermapsettingsmenu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace regmap {
class RegisterMapSettingsMenu : public QWidget
{
friend class RegmapStyleHelper;
friend class RegMap_API;

Q_OBJECT

Expand Down
1 change: 1 addition & 0 deletions plugins/regmap/src/registermaptool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class SearchBarWidget;

class SCOPY_REGMAP_EXPORT RegisterMapTool : public QWidget
{
friend class RegMap_API;
Q_OBJECT
public:
explicit RegisterMapTool(QWidget *parent = nullptr);
Expand Down
101 changes: 101 additions & 0 deletions plugins/regmap/src/regmap_api.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#include "regmap_api.h"

using namespace scopy::regmap;

Q_LOGGING_CATEGORY(CAT_REGMAP_API, "RegMap_API")

RegMap_API::RegMap_API(RegmapPlugin *regMapPlugin)
: ApiObject()
, m_regMapPlugin(regMapPlugin)
{}

RegMap_API::~RegMap_API() {}

void RegMap_API::write(QString addr, QString val)
{
DeviceRegisterMap *devRegMap = getActiveDevRegMap();
Q_EMIT devRegMap->registerMapValues->requestWrite(addr.toUInt(nullptr, 16), val.toUInt(nullptr, 16));
}

QStringList RegMap_API::getAvailableDevicesName()
{
QStringList devicesName;
if(m_regMapPlugin->m_deviceList->size() != 0) {
for(const auto &dev : *(m_regMapPlugin->m_deviceList)) {
devicesName.append(iio_device_get_name(dev));
}
} else {
qWarning(CAT_REGMAP_API) << "No devices available";
}
return devicesName;
}

bool RegMap_API::setDevice(QString device)
{
m_regMapPlugin->registerMapTool->updateActiveRegisterMap(device);
QString currentRegMap = m_regMapPlugin->registerMapTool->activeRegisterMap;
if(currentRegMap == device) {
return true;
}
qWarning(CAT_REGMAP_API) << "Device " << device << " was not set";
return false;
}

QStringList RegMap_API::search(QString searchParam)
{
QList<uint32_t> resultIndexes;
DeviceRegisterMap *devRegMap = getActiveDevRegMap();
resultIndexes = Search::searchForRegisters(devRegMap->registerMapTemplate->getRegisterList(), searchParam);

QStringList resultList;
for(int i = 0; i < resultIndexes.size(); i++) {
RegisterModel *model = devRegMap->registerMapTemplate->getRegisterTemplate(resultIndexes[i]);
resultList.append(model->getName());
}
return resultList;
}

QStringList RegMap_API::readInterval(QString startAddr, QString stopAddr)
{
DeviceRegisterMap *devRegMap = getActiveDevRegMap();
uint32_t start = startAddr.toUInt(nullptr, 16);
uint32_t stop = stopAddr.toUInt(nullptr, 16);
QStringList readValues;
for(int i = start; i < stop; i++) {
Q_EMIT devRegMap->registerMapValues->requestRead(i);
}
return readValues;
}

bool RegMap_API::enableAutoread(bool enable)
{
DeviceRegisterMap *devRegMap = getActiveDevRegMap();
devRegMap->toggleAutoread(enable);
if(devRegMap->getAutoread() == enable) {
return true;
}
qWarning(CAT_REGMAP_API) << "Autoread was not changed to " << enable;
return false;
}

bool RegMap_API::isAutoreadEnabled()
{
DeviceRegisterMap *devRegMap = getActiveDevRegMap();
return devRegMap->getAutoread();
}

void RegMap_API::registerDump(QString filePath)
{
DeviceRegisterMap *devRegMap = getActiveDevRegMap();
Q_EMIT devRegMap->registerMapValues->registerDump(filePath);
}

void RegMap_API::writeFromFile(QString filePath)
{

}

DeviceRegisterMap *RegMap_API::getActiveDevRegMap()
{
return m_regMapPlugin->registerMapTool->deviceList->value(m_regMapPlugin->registerMapTool->activeRegisterMap);
}
39 changes: 39 additions & 0 deletions plugins/regmap/src/regmap_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef REGMAP_API_H
#define REGMAP_API_H

#include "scopy-regmap_export.h"

#include <regmapplugin.h>
#include <deviceregistermap.hpp>
#include <registermaptool.hpp>
#include <register/registermodel.hpp>
#include <registermapvalues.hpp>
#include "search.hpp"

namespace scopy::regmap {

class SCOPY_REGMAP_EXPORT RegMap_API : public ApiObject
{

Q_OBJECT

public:
explicit RegMap_API(RegmapPlugin *regMapPlugin);
~RegMap_API();

Q_INVOKABLE void write(QString addr, QString val);
Q_INVOKABLE QStringList getAvailableDevicesName();
Q_INVOKABLE bool setDevice(QString device);
Q_INVOKABLE QStringList search(QString searchParam);
Q_INVOKABLE QStringList readInterval(QString startAddr, QString stopAddr);
Q_INVOKABLE bool enableAutoread(bool enable);
Q_INVOKABLE bool isAutoreadEnabled();
Q_INVOKABLE void registerDump(QString filePath);
Q_INVOKABLE void writeFromFile(QString filePath);

private:
RegmapPlugin *m_regMapPlugin;
DeviceRegisterMap *getActiveDevRegMap();
};
} // namespace scopy::regmap
#endif // REGMAP_API_H
10 changes: 10 additions & 0 deletions plugins/regmap/src/regmapplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
#include <readwrite/fileregisterreadstrategy.hpp>
#include <readwrite/fileregisterwritestrategy.hpp>
#include "logging_categories.h"
#include <regmap_api.h>

#include "iioutil/connectionprovider.h"
#include "jsonformatedelement.hpp"
#include "scopy-regmap_config.h"
#include "utils.hpp"
#include "utils.hpp"
#include <pluginbase/scopyjs.h>
#if defined __APPLE__
#include <QApplication>
#endif
Expand Down Expand Up @@ -185,6 +187,7 @@ bool RegmapPlugin::onConnect()

m_toolList[0]->setEnabled(true);
m_toolList[0]->setTool(m_registerMapWidget);
InitApi();

return true;
}
Expand Down Expand Up @@ -275,4 +278,11 @@ bool RegmapPlugin::isBufferCapable(iio_device *dev)
return false;
}

void RegmapPlugin::InitApi()
{
api = new RegMap_API(this);
ScopyJS *js = ScopyJS::GetInstance();
api->setObjectName("regmap");
js->registerApi(api);
}
#include "moc_regmapplugin.cpp"
2 changes: 2 additions & 0 deletions tools/plugingenerator/plugin_generator.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/python3

import json
import os
import argparse
Expand Down
Loading