20140521-181001
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
#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
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef AVRLIB_PORTB_HPP
|
||||
#define AVRLIB_PORTB_HPP
|
||||
|
||||
#include <avr/io.h>
|
||||
|
||||
namespace avrlib {
|
||||
|
||||
struct portb
|
||||
{
|
||||
static uint8_t port() { return PORTB; }
|
||||
static void port(uint8_t v) { PORTB = v; }
|
||||
|
||||
static uint8_t pin() { return PINB; }
|
||||
static void pin(uint8_t v) { PINB = v; }
|
||||
|
||||
static uint8_t dir() { return DDRB; }
|
||||
static void dir(uint8_t v) { DDRB = v; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef AVRLIB_PORTC_HPP
|
||||
#define AVRLIB_PORTC_HPP
|
||||
|
||||
#include <avr/io.h>
|
||||
|
||||
namespace avrlib {
|
||||
|
||||
struct portc
|
||||
{
|
||||
static uint8_t port() { return PORTC; }
|
||||
static void port(uint8_t v) { PORTC = v; }
|
||||
|
||||
static uint8_t pin() { return PINC; }
|
||||
static void pin(uint8_t v) { PINC = v; }
|
||||
|
||||
static uint8_t dir() { return DDRC; }
|
||||
static void dir(uint8_t v) { DDRC = v; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef AVRLIB_PORTD_HPP
|
||||
#define AVRLIB_PORTD_HPP
|
||||
|
||||
#include <avr/io.h>
|
||||
|
||||
namespace avrlib {
|
||||
|
||||
struct portd
|
||||
{
|
||||
static uint8_t port() { return PORTD; }
|
||||
static void port(uint8_t v) { PORTD = v; }
|
||||
|
||||
static uint8_t pin() { return PIND; }
|
||||
static void pin(uint8_t v) { PIND = v; }
|
||||
|
||||
static uint8_t dir() { return DDRD; }
|
||||
static void dir(uint8_t v) { DDRD = v; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user