summaryrefslogtreecommitdiff
path: root/daemon
diff options
context:
space:
mode:
Diffstat (limited to 'daemon')
-rw-r--r--daemon/src/Gpio.cpp30
-rw-r--r--daemon/src/Gpio.h10
2 files changed, 39 insertions, 1 deletions
diff --git a/daemon/src/Gpio.cpp b/daemon/src/Gpio.cpp
index 656c585..23341aa 100644
--- a/daemon/src/Gpio.cpp
+++ b/daemon/src/Gpio.cpp
@@ -1,5 +1,7 @@
#include "Gpio.h"
+#include <limits>
+
#include <rpc/server.h>
#include "Assembly.h"
@@ -7,5 +9,31 @@
void Gpio::apply(AssemblyContext ctx)
{
- ctx.bind("nothing", []{});
+ ctx.bind("/set_mode", [&](const unsigned port, const short mode){ set_mode(port, mode); });
+ ctx.bind("/write", [&](const unsigned port, const short value){ write(port, value); });
+ ctx.bind("/read", [&](const unsigned port) -> short { return read(port); });
+}
+
+
+void Gpio::set_mode(const unsigned port, const short mode)
+{
+ if (SIZE <= port)
+ return;
+ mode_of[port] = mode & 0x1;
+}
+
+
+void Gpio::write(const unsigned port, const short value)
+{
+ if (SIZE <= port)
+ return;
+ value_of[port] = value & 0x1;
+}
+
+
+short Gpio::read(const unsigned port) const
+{
+ if (SIZE <= port)
+ return std::numeric_limits<short>::max();
+ return value_of[port];
}
diff --git a/daemon/src/Gpio.h b/daemon/src/Gpio.h
index ef77631..e3941f6 100644
--- a/daemon/src/Gpio.h
+++ b/daemon/src/Gpio.h
@@ -1,5 +1,7 @@
#pragma once
+#include <array>
+
#include <rpc/server.h>
#include "Assembly.h"
@@ -9,4 +11,12 @@ class Gpio
{
public:
void apply(AssemblyContext ctx);
+private:
+ static constexpr unsigned SIZE {24};
+ std::array<short, SIZE> mode_of;
+ std::array<short, SIZE> value_of;
+
+ void set_mode(const unsigned port, const short mode);
+ void write(const unsigned port, const short value);
+ short read(const unsigned port) const;
};