Files

35 lines
950 B
C++
Raw Permalink Normal View History

2025-05-13 02:03:18 +03:00
#pragma once
#include <stm32h7xx_hal.h>
#include "DshotProtocol.h"
extern "C" {
extern TIM_HandleTypeDef htim2;
}
class EscController {
public:
void sendThrottle(std::uint16_t value) {
value += 48;
_dshotDmaBuffer.fill(Driver::Esc::DShot::encodePacket(value, false));
_dmaRunning = true;
if(HAL_TIM_PWM_Start_DMA(&htim2, TIM_CHANNEL_1, _dshotDmaBuffer.data(), _dshotDmaBuffer.size()) != HAL_OK){
lfDebug() << "Failed to start timer DMA";
}else{
//Wait DMA complete
while(_dmaRunning){
asm("nop");
}
}
}
void onTimPwmPulseFinished(TIM_HandleTypeDef* htim) {
__HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
(void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
_dmaRunning = false;
}
private:
bool _dmaRunning = 0;
Driver::Esc::DShot::DmaBuffer<std::uint32_t> _dshotDmaBuffer;
};