16const std::vector<std::string>
RC_SpeedNames = {
"20ms",
"15ms",
"10ms",
"5ms"};
17const std::vector<std::string>
PWM_SpeedNames = {
"3khz",
"9khz",
"17khz",
"24khz"};
19const std::vector<std::string>
PwmModeNames = {
"RC PPM",
"0%-50%-100% Centered",
"0-100% PWM/DIR",
"0-100% dual PWM"};
73 float val = ((pval * 1000)/0x7fff)*
tFreq;
90 int32_t val = (uint32_t)((abs(
power) *
period)/0x7fff);
94 int32_t pval = 0x7fff+
power;
95 int32_t val = (pval *
period)/0xffff;
99 int32_t val = (uint32_t)((abs(
power) *
period)/0x7fff);
116 uint32_t arr = arr_raw / (
prescaler + 1);
207 uint16_t var = (uint8_t)this->
mode & 0x7;
208 var |= ((uint8_t)this->
pwmspeed & 0x7) << 4;
215 uint8_t m = var & 0xf;
218 uint8_t s = (var >> 4) & 0x7;
257 replies.emplace_back((uint8_t)this->
getPwmSpeed());
265 for(uint8_t i = 0; i<names.size();i++){
266 replies.emplace_back(names[i] +
":" + std::to_string(i)+
"\n");
276 replies.emplace_back((uint8_t)this->
getMode());
279 replies.emplace_back(
PwmModeNames[i] +
":" + std::to_string(i)+
"\n");
297void pwmInitTimer(TIM_HandleTypeDef* timer,uint32_t channel,uint32_t period,uint32_t prescaler){
298 timer->Instance->ARR = period;
299 timer->Instance->PSC = prescaler;
300 TIM_OC_InitTypeDef sConfigOC = {0};
301 sConfigOC.OCMode = TIM_OCMODE_PWM1;
303 sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
304 sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
305 sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
306 sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
307 sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
309 HAL_TIM_PWM_Stop(timer, channel);
310 HAL_TIM_PWM_ConfigChannel(timer, &sConfigOC, channel);
312 HAL_TIM_PWM_Start(timer, channel);
321void setPWM_HAL(uint32_t value,TIM_HandleTypeDef* timer,uint32_t channel,uint32_t period){
322 TIM_OC_InitTypeDef sConfigOC;
324 sConfigOC.OCMode = TIM_OCMODE_PWM1;
325 sConfigOC.Pulse = value;
326 sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
327 sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
328 sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
329 HAL_TIM_PWM_ConfigChannel(timer, &sConfigOC, channel);
330 HAL_TIM_PWM_Start(timer, channel);
const std::vector< std::string > PWM_SpeedNames
cpp_freertos::MutexStandard pwmTimMutex
const std::vector< std::string > RC_SpeedNames
const std::vector< std::string > PwmModeNames
void setPWM_HAL(uint32_t value, TIM_HandleTypeDef *timer, uint32_t channel, uint32_t period)
void pwmInitTimer(TIM_HandleTypeDef *timer, uint32_t channel, uint32_t period, uint32_t prescaler)
void registerCommand(const char *cmd, const ID cmdid, const char *help=nullptr, uint32_t flags=0)
static CommandStatus handleGetSet(const ParsedCommand &cmd, std::vector< CommandReply > &replies, TVal &value)
SpeedPWM_DRV getPwmSpeed()
static bool pwmDriverInUse
static const PWMConfig timerConfig
void setPwmSpeed(SpeedPWM_DRV spd)
static std::pair< uint16_t, uint16_t > freqToPeriodPsc(uint32_t freq)
static ClassIdentifier info
const ClassIdentifier getInfo()
Command handlers always have class infos. Works well with ChoosableClass.
void setPWM(uint32_t value, uint8_t ccr)
void setMode(ModePWM_DRV mode)
static bool isCreatable()
CommandStatus command(const ParsedCommand &cmd, std::vector< CommandReply > &replies)
virtual bool Lock(TickType_t Timeout=portMAX_DELAY)
bool Flash_Write(uint16_t adr, uint16_t dat)
bool Flash_Read(uint16_t adr, uint16_t *buf, bool checkempty=true)
TIM_HandleTypeDef * timer