#include "Gpio.h" #include #include #include "Assembly.h" Gpio::Gpio() noexcept : mode_of {}, value_of {} {} 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) mode_of[port] = mode & 0x1; } void Gpio::write(const unsigned port, const short value) { if (SIZE > port && mode_of[port] == 0x1) value_of[port] = value & 0x1; } short Gpio::read(const unsigned port) const { if (SIZE <= port) return std::numeric_limits::max(); return value_of[port]; }