23 lines
380 B
C++
23 lines
380 B
C++
|
|
||
|
#pragma once
|
||
|
|
||
|
#include "util.hpp"
|
||
|
|
||
|
namespace dac {
|
||
|
|
||
|
constexpr int BITMASK_B = 0x07;
|
||
|
constexpr int BITMASK_D = 0xf8;
|
||
|
|
||
|
inline void init() {
|
||
|
DDRB |= BITMASK_B;
|
||
|
DDRD |= BITMASK_D;
|
||
|
}
|
||
|
|
||
|
inline void set(float v_f) {
|
||
|
uint8_t v = clamp((int)(v_f * -128) + 127, 0, 255);
|
||
|
PORTB = (PORTB & ~BITMASK_B) | (v & BITMASK_B);
|
||
|
PORTD = (PORTD & ~BITMASK_D) | (v & BITMASK_D);
|
||
|
}
|
||
|
};
|
||
|
|