RISC-V/V203/pwm/pwmclass.h

33 lines
821 B
C
Raw Permalink Normal View History

2024-05-07 15:50:51 +02:00
#ifndef PWMCLASS_H
#define PWMCLASS_H
#include "system.h"
#include "gpio.h"
#include "oneway.h"
static constexpr unsigned HALF_LEN = 160u;
static constexpr unsigned FULL_LEN = 2u * HALF_LEN;
static constexpr unsigned MAXPWM = 6000u;
/* Používá TIM1, PWM kanál 1, DMA1 kanál 5, přerušení DMA1_Channel5_IRQHandler */
class PwmClass {
GpioClass led;
unsigned count;
uint16_t * const pL;
uint16_t * const pH;
uint16_t buffer [FULL_LEN];
OneWay * src;
public:
explicit PwmClass () noexcept;
void attach (OneWay & s) { src = & s; }
void send (const bool b) {
if (!src) return;
if (b) src->Send (pH, HALF_LEN);
else src->Send (pL, HALF_LEN);
}
void signalize () {
const bool b = count & 8u;
led << b;
count += 1u;
}
};
#endif // PWMCLASS_H