20141119-235733

This commit is contained in:
2014-11-19 22:57:35 +00:00
parent 7a55618696
commit 6de094275f
20 changed files with 2251 additions and 257 deletions
+50
View File
@@ -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
+22
View File
@@ -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
+22
View File
@@ -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