#pragma once #include #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 _dshotDmaBuffer; };