49 lines
1.2 KiB
C++
49 lines
1.2 KiB
C++
#ifndef INTERFACE_H
|
|
#define INTERFACE_H
|
|
|
|
#include <QObject>
|
|
#include "base/base.h"
|
|
#include "interface/codec.h"
|
|
|
|
using namespace std;
|
|
using namespace std::placeholders;
|
|
|
|
typedef std::function<void(myarray data)> irq_cb;
|
|
|
|
class InterFace : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
InterFace() { irq_fun = nullptr; }
|
|
virtual ~InterFace() {}
|
|
virtual void init() = 0;
|
|
virtual int write(myarray data) = 0;
|
|
virtual void set_irq(irq_cb fun)
|
|
{
|
|
this->irq_fun = fun;
|
|
}
|
|
virtual int write(int dst,myarray data){
|
|
return write(data);
|
|
}
|
|
|
|
protected:
|
|
irq_cb irq_fun;
|
|
};
|
|
|
|
InterFace *interFaceFind(const char *name);
|
|
|
|
typedef struct
|
|
{
|
|
const char *name;
|
|
InterFace *(*if_get_fun)();
|
|
} if_def;
|
|
|
|
#define if_export(name_, fun_) \
|
|
const static char __if_##name_##_name[] __attribute__((section(".rodata.ifstr"))) = #name_; \
|
|
__attribute__((used)) static if_def _if_##name_ __attribute__((section("ifdef"))) = { \
|
|
.name = __if_##name_##_name, \
|
|
.if_get_fun = fun_, \
|
|
}
|
|
|
|
#endif // INTERFACE_H
|