RISC-V/V203F6P6/blink/generator.h
2025-01-29 15:29:40 +01:00

23 lines
657 B
C++

#ifndef GENERATOR_H
#define GENERATOR_H
#include "oneway.h"
/* Něco jako DDS, přesná frekvence není řešena (závisí na TIM1). */
class Generator : public OneWay<uint16_t> {
const unsigned freq;
unsigned base, incr;
volatile unsigned ms_count;
public:
explicit Generator (const unsigned f) noexcept;
unsigned Send (uint16_t * const ptr, const unsigned len) override;
void delay (const unsigned ms) {
ms_count = ms;
while (ms_count);
}
void on () volatile { incr = freq; }
void off () volatile { base = 0u; incr = 0u; }
protected:
uint16_t step ();
};
#endif // GENERATOR_H