Zeitschaltung/V6/Program/rfm12_rs232/Zeitschaltung_V6/io/hardware/pin.hpp

51 lines
1.1 KiB
C++
Raw Normal View History

2014-05-21 18:10:07 +02:00
#ifndef AVRLIB_PIN_HPP
#define AVRLIB_PIN_HPP
#include <avr/io.h>
namespace avrlib {
template <typename Port, uint8_t Pin>
struct pin
{
static void set(bool value = true)
{
if (value)
Port::port(Port::port() | (1<<Pin));
else
Port::port(Port::port() & ~(1<<Pin));
}
static void clear() { set(false); }
static void toggle() { Port::port(Port::port() ^ (1<<Pin)); }
static bool get() { return (Port::port() & (1<<Pin)) != 0; }
static bool value() { return (Port::pin() & (1<<Pin)) != 0; }
static void output(bool value)
{
if (value)
Port::dir(Port::dir() | (1<<Pin));
else
Port::dir(Port::dir() & ~(1<<Pin));
}
static bool output() { return (Port::dir() & (1<<Pin)) != 0; }
static void make_output() { output(true); }
static void make_input() { output(false); clear(); }
static void make_low() { clear(); output(true); }
static void make_high() { set(); output(true); }
static void set_value(bool value) { set(value); }
static void set_high() { set(true); }
static void set_low() { set(false); }
static bool read() { return value(); }
static void pullup() { set_high(); }
};
}
#endif