summaryrefslogtreecommitdiff
path: root/daemon/src/Gpio.cpp
blob: 23341aa3758bcafe33908e27014686d97aefd96c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "Gpio.h"

#include <limits>

#include <rpc/server.h>

#include "Assembly.h"


void Gpio::apply(AssemblyContext ctx)
{
	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];
}