64 lines
1.0 KiB
C++
64 lines
1.0 KiB
C++
|
|
#pragma once
|
|
|
|
#include "util.hpp"
|
|
|
|
namespace port {
|
|
struct Drain {
|
|
uint8_t mask;
|
|
volatile uint8_t* mode;
|
|
volatile uint8_t* in;
|
|
|
|
inline Drain(unsigned pin) AW_IN {
|
|
mask = digitalPinToBitMask(pin);
|
|
mode = portModeRegister(digitalPinToPort(pin));
|
|
in = portInputRegister(digitalPinToPort(pin));
|
|
}
|
|
|
|
inline void set(uint8_t b) AW_IN {
|
|
if(b) {
|
|
*mode &= ~mask;
|
|
} else {
|
|
*mode |= mask;
|
|
}
|
|
}
|
|
|
|
inline uint8_t get() AW_IN {
|
|
return *in & mask;
|
|
}
|
|
};
|
|
|
|
struct Input {
|
|
uint8_t mask;
|
|
volatile uint8_t* in;
|
|
|
|
inline Input(unsigned pin) AW_IN {
|
|
mask = digitalPinToBitMask(pin);
|
|
in = portInputRegister(digitalPinToPort(pin));
|
|
}
|
|
|
|
inline uint8_t get() AW_IN {
|
|
return *in & mask;
|
|
}
|
|
};
|
|
|
|
struct Output {
|
|
uint8_t mask;
|
|
volatile uint8_t* out;
|
|
|
|
inline Output(unsigned pin) AW_IN {
|
|
mask = digitalPinToBitMask(pin);
|
|
out = portOutputRegister(digitalPinToPort(pin));
|
|
}
|
|
|
|
inline void set(uint8_t b) AW_IN {
|
|
if(b) {
|
|
*out |= mask;
|
|
} else {
|
|
*out &= ~mask;
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|