THW-Funk-Audio-Switch/Programm/Audio-Switch/io/ports/pin.hpp

130 lines
2.2 KiB
C++
Raw Normal View History

2020-10-19 18:16:51 +02:00
/*
* 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 {
2020-10-30 23:22:11 +01:00
/**
* \brief
* Set or Unset the Output
* \param value
* true = set, false = unset
* \return void
*/
2020-10-19 18:16:51 +02:00
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));
}
2020-11-02 00:27:02 +01:00
2020-10-19 18:16:51 +02:00
static bool Get() {
return (PortT::Port() & (1<<Pin)) != 0;
}
2020-11-02 00:27:02 +01:00
/**
* \brief
* Return Value of the Pin (High or Low)
* \return bool
*/
2020-10-19 18:16:51 +02:00
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);
}
2020-11-02 00:27:02 +01:00
/**
* \brief
* Set as Input and no Pullup
* \return void
*/
2020-10-19 18:16:51 +02:00
static void MakeInput() {
Output(false);
Clear();
}
2020-10-30 23:22:11 +01:00
/**
* \brief
2020-11-02 00:27:02 +01:00
* Set as Output and Low
2020-10-30 23:22:11 +01:00
* \return void
*/
2020-10-19 18:16:51 +02:00
static void MakeLow() {
Clear();
Output(true);
}
static void MakeHigh() {
Set();
Output(true);
}
static void SetValue(bool value) {
Set(value);
}
2020-10-30 23:22:11 +01:00
/**
* \brief
* Set High
*
* \return void
*/
2020-10-19 18:16:51 +02:00
static void SetHigh() {
Set(true);
}
2020-10-30 23:22:11 +01:00
/**
* \brief
* Set Low
*
* \return void
*/
2020-10-19 18:16:51 +02:00
static void SetLow() {
Set(false);
}
static bool Read() {
return Value();
}
static void Pullup() {
Output(false);
SetHigh();
}
};
}
#endif