Start Programm

This commit is contained in:
2020-10-19 18:16:51 +02:00
parent a5a8edfb18
commit da2c79f81a
10 changed files with 492 additions and 0 deletions
+93
View File
@@ -0,0 +1,93 @@
/*
* 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
+40
View File
@@ -0,0 +1,40 @@
/*
* portb.cpp
*
* Created: 19.10.2020 17:46:58
* Author: netz
*/
#ifndef BLUBBLIB_PORTB_HPP
#define BLUBBLIB_PORTB_HPP
#include <avr/io.h>
namespace blubblib {
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
+40
View File
@@ -0,0 +1,40 @@
/*
* portc.cpp
*
* Created: 19.10.2020 17:46:58
* Author: netz
*/
#ifndef BLUBBLIB_PORTC_HPP
#define BLUBBLIB_PORTC_HPP
#include <avr/io.h>
namespace blubblib {
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
+40
View File
@@ -0,0 +1,40 @@
/*
* portd.cpp
*
* Created: 19.10.2020 17:46:58
* Author: netz
*/
#ifndef BLUBBLIB_PORTD_HPP
#define BLUBBLIB_PORTD_HPP
#include <avr/io.h>
namespace blubblib {
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