RISC-V/V003/hello/generator.h

25 lines
744 B
C
Raw Permalink Normal View History

2024-03-17 16:33:48 +01:00
#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