29 lines
785 B
C++
29 lines
785 B
C++
#ifndef PCMDMA_H
|
|
#define PCMDMA_H
|
|
#include "oneway.h"
|
|
#ifdef HAVE_CONFIG
|
|
/* Umožní použít externí parametry. */
|
|
#include "pwmconfig.h"
|
|
#else
|
|
static constexpr unsigned HALF_LEN = 0x40u;
|
|
static constexpr unsigned MAXPWM = 2000u;
|
|
#endif
|
|
static constexpr unsigned FULL_LEN = 2u * HALF_LEN;
|
|
/* Používá TIM1, PWM kanál 1, DMA1 kanál 5, přerušení DMA1_Channel5_IRQHandler */
|
|
class PcmDma {
|
|
uint16_t * const pL;
|
|
uint16_t * const pH;
|
|
uint16_t buffer [FULL_LEN];
|
|
OneWay * src;
|
|
public:
|
|
explicit PcmDma () noexcept;
|
|
uint16_t * getBuff () { return buffer; };
|
|
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);
|
|
}
|
|
};
|
|
|
|
#endif // PCMDMA_H
|