THW-Funk-Audio-Switch/Programm/Audio-Switch/io/ports/pin.hpp
2020-10-19 18:16:51 +02:00

94 lines
1.6 KiB
C++

/*
* pin.cpp
*
* Created: 25.01.2020 21:02:41
* Author: netz
*/
#ifndef BLUBBLIB_PIN_HPP
#define BLUBBLIB_PIN_HPP
#include <avr/io.h>
namespace blubblib {
template <typename PortT, uint8_t Pin>
struct pin {
static void Set(bool value = true) {
if (value) {
PortT::Port(PortT::Port() | (1<<Pin));
} else {
PortT::Port(PortT::Port() & ~(1<<Pin));
}
}
static void Clear() {
Set(false);
}
static void Toggle() {
PortT::Port(PortT::Port() ^ (1<<Pin));
}
static bool Get() {
return (PortT::Port() & (1<<Pin)) != 0;
}
static bool Value() {
return (PortT::Pin() & (1<<Pin)) != 0;
}
static void Output(bool value) {
if (value) {
PortT::Dir(PortT::Dir() | (1<<Pin));
} else {
PortT::Dir(PortT::Dir() & ~(1<<Pin));
}
}
static bool Output() {
return (PortT::Dir() & (1<<Pin)) != 0;
}
static void MakeOutput() {
Output(true);
}
static void MakeInput() {
Output(false);
Clear();
}
static void MakeLow() {
Clear();
Output(true);
}
static void MakeHigh() {
Set();
Output(true);
}
static void SetValue(bool value) {
Set(value);
}
static void SetHigh() {
Set(true);
}
static void SetLow() {
Set(false);
}
static bool Read() {
return Value();
}
static void Pullup() {
Output(false);
SetHigh();
}
};
}
#endif