Merge pull request #3031 from sambas/betaflightF7
HAL ledstrip N channel support
This commit is contained in:
commit
63bae61e64
|
@ -36,11 +36,11 @@ bool ws2811Initialised = false;
|
|||
|
||||
static TIM_HandleTypeDef TimHandle;
|
||||
static uint16_t timerChannel = 0;
|
||||
static bool timerNChannel = false;
|
||||
|
||||
void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)
|
||||
{
|
||||
if(htim->Instance == TimHandle.Instance)
|
||||
{
|
||||
if(htim->Instance == TimHandle.Instance) {
|
||||
//HAL_TIM_PWM_Stop_DMA(&TimHandle,WS2811_TIMER_CHANNEL);
|
||||
ws2811LedDataTransferInProgress = 0;
|
||||
}
|
||||
|
@ -77,8 +77,7 @@ void ws2811LedStripHardwareInit(ioTag_t ioTag)
|
|||
TimHandle.Init.Period = period; // 800kHz
|
||||
TimHandle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
if(HAL_TIM_PWM_Init(&TimHandle) != HAL_OK)
|
||||
{
|
||||
if(HAL_TIM_PWM_Init(&TimHandle) != HAL_OK) {
|
||||
/* Initialization Error */
|
||||
return;
|
||||
}
|
||||
|
@ -96,8 +95,8 @@ void ws2811LedStripHardwareInit(ioTag_t ioTag)
|
|||
hdma_tim.Init.Direction = DMA_MEMORY_TO_PERIPH;
|
||||
hdma_tim.Init.PeriphInc = DMA_PINC_DISABLE;
|
||||
hdma_tim.Init.MemInc = DMA_MINC_ENABLE;
|
||||
hdma_tim.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD ;
|
||||
hdma_tim.Init.MemDataAlignment = DMA_MDATAALIGN_WORD ;
|
||||
hdma_tim.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
|
||||
hdma_tim.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
|
||||
hdma_tim.Init.Mode = DMA_NORMAL;
|
||||
hdma_tim.Init.Priority = DMA_PRIORITY_HIGH;
|
||||
hdma_tim.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
|
||||
|
@ -117,8 +116,7 @@ void ws2811LedStripHardwareInit(ioTag_t ioTag)
|
|||
dmaSetHandler(timerHardware->dmaIrqHandler, WS2811_DMA_IRQHandler, NVIC_PRIO_WS2811_DMA, dmaSource);
|
||||
|
||||
/* Initialize TIMx DMA handle */
|
||||
if(HAL_DMA_Init(TimHandle.hdma[dmaSource]) != HAL_OK)
|
||||
{
|
||||
if(HAL_DMA_Init(TimHandle.hdma[dmaSource]) != HAL_OK) {
|
||||
/* Initialization Error */
|
||||
return;
|
||||
}
|
||||
|
@ -127,15 +125,21 @@ void ws2811LedStripHardwareInit(ioTag_t ioTag)
|
|||
|
||||
/* PWM1 Mode configuration: Channel1 */
|
||||
TIM_OCInitStructure.OCMode = TIM_OCMODE_PWM1;
|
||||
TIM_OCInitStructure.Pulse = 0;
|
||||
TIM_OCInitStructure.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
TIM_OCInitStructure.OCNPolarity = TIM_OCPOLARITY_HIGH;
|
||||
if (timerHardware->output & TIMER_OUTPUT_N_CHANNEL) {
|
||||
timerNChannel = true;
|
||||
TIM_OCInitStructure.OCIdleState = TIM_OCIDLESTATE_RESET;
|
||||
TIM_OCInitStructure.OCPolarity = (timerHardware->output & TIMER_OUTPUT_INVERTED) ? TIM_OCPOLARITY_HIGH: TIM_OCPOLARITY_LOW;
|
||||
TIM_OCInitStructure.OCNIdleState = TIM_OCNIDLESTATE_RESET;
|
||||
TIM_OCInitStructure.OCNPolarity = (timerHardware->output & TIMER_OUTPUT_INVERTED) ? TIM_OCNPOLARITY_HIGH : TIM_OCNPOLARITY_LOW;
|
||||
} else {
|
||||
TIM_OCInitStructure.OCIdleState = TIM_OCIDLESTATE_RESET;
|
||||
TIM_OCInitStructure.OCPolarity = (timerHardware->output & TIMER_OUTPUT_INVERTED) ? TIM_OCPOLARITY_LOW : TIM_OCPOLARITY_HIGH;
|
||||
TIM_OCInitStructure.OCNIdleState = TIM_OCNIDLESTATE_RESET;
|
||||
TIM_OCInitStructure.OCNPolarity = (timerHardware->output & TIMER_OUTPUT_INVERTED) ? TIM_OCNPOLARITY_LOW : TIM_OCNPOLARITY_HIGH;
|
||||
}
|
||||
TIM_OCInitStructure.Pulse = 0;
|
||||
TIM_OCInitStructure.OCFastMode = TIM_OCFAST_DISABLE;
|
||||
|
||||
if(HAL_TIM_PWM_ConfigChannel(&TimHandle, &TIM_OCInitStructure, timerChannel) != HAL_OK)
|
||||
{
|
||||
if(HAL_TIM_PWM_ConfigChannel(&TimHandle, &TIM_OCInitStructure, timerChannel) != HAL_OK) {
|
||||
/* Configuration Error */
|
||||
return;
|
||||
}
|
||||
|
@ -143,21 +147,25 @@ void ws2811LedStripHardwareInit(ioTag_t ioTag)
|
|||
ws2811Initialised = true;
|
||||
}
|
||||
|
||||
|
||||
void ws2811LedStripDMAEnable(void)
|
||||
{
|
||||
if (!ws2811Initialised)
|
||||
{
|
||||
if (!ws2811Initialised) {
|
||||
ws2811LedDataTransferInProgress = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (HAL_TIM_PWM_Start_DMA(&TimHandle, timerChannel, ledStripDMABuffer, WS2811_DMA_BUFFER_SIZE) != HAL_OK)
|
||||
{
|
||||
if(timerNChannel) {
|
||||
if(HAL_TIMEx_PWMN_Start_DMA(&TimHandle, timerChannel, ledStripDMABuffer, WS2811_DMA_BUFFER_SIZE) != HAL_OK) {
|
||||
/* Starting PWM generation Error */
|
||||
ws2811LedDataTransferInProgress = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (HAL_TIM_PWM_Start_DMA(&TimHandle, timerChannel, ledStripDMABuffer, WS2811_DMA_BUFFER_SIZE) != HAL_OK) {
|
||||
/* Starting PWM generation Error */
|
||||
ws2811LedDataTransferInProgress = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue