RISC-V/V003/hello/generator.h
2024-05-07 11:46:49 +02:00

24 lines
744 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 {
const unsigned freq;
unsigned base, incr;
volatile unsigned ms_count;
public:
explicit Generator (const unsigned f) noexcept : OneWay(),
freq (f), base(0u), incr (0u), ms_count (0u) { }
unsigned Send (uint16_t * const ptr, const unsigned len) override;
void delay (const unsigned ms) {
ms_count = ms;
while (ms_count);// asm volatile ("wfi"); // ???
}
void on () volatile { incr = freq; }
void off () volatile { base = 0u; incr = 0u; }
protected:
uint16_t step ();
};
#endif // GENERATOR_H