26 lines
375 B
C++
26 lines
375 B
C++
#include "pwm.hpp"
|
|
|
|
#include "io/io.hpp"
|
|
|
|
namespace pwm {
|
|
|
|
static constexpr uint8_t PWM_TOP = 40;
|
|
|
|
void init()
|
|
{
|
|
io::Pin<io::P::D5> pwmPin;
|
|
pwmPin.dir(io::Dir::OUT);
|
|
pwmPin = false;
|
|
|
|
TCCR0A = (1 << COM0B1) | (1 << WGM00);
|
|
TCCR0B = (1 << WGM02) | (1 << CS01);
|
|
OCR0A = PWM_TOP;
|
|
}
|
|
|
|
void setDuty(uint8_t percent)
|
|
{
|
|
OCR0B = (percent * PWM_TOP) / 100;
|
|
}
|
|
|
|
} // namespace pwm
|