Skip to content

update WS28XX_Init() documentation #2

@MisterHW

Description

@MisterHW

The parameter TimerBusFrequencyMHz may need a little bit of explaining in

/**
  * @brief  Initialize WS28XX hLed
  * @note   Initialize WS28XX hLed and set the Channel and number of Pixels
  *
  * @param  *hLed: Pointer to WS28XX_hLedTypeDef structure
  * @param  *hTim: Pointer to TIM_hLedTypeDef structure
  * @param  Channel: Selected PWM channel
  *         TIM_CHANNEL_1
  *         TIM_CHANNEL_2
  *         TIM_CHANNEL_3
  *         TIM_CHANNEL_4
  *         TIM_CHANNEL_5
  *         TIM_CHANNEL_6
  * @param  Pixel: Number of pixels
  *
  * @retval bool: true or false
  */
bool WS28XX_Init(WS28XX_HandleTypeDef *hLed, TIM_HandleTypeDef *hTim,
      uint16_t TimerBusFrequencyMHz, uint8_t Channel, uint16_t Pixel)
{

Without reading the code, it was not clear to me how to account for a chosen timer prescaler value, with a non-zero PSC set to attempt to reduce power consumption a little. It should be pointed out that Prescaler (PSC) should be left at 0 in CubeMX, since WS28XX_Init() overwrites the value:

    __HAL_TIM_SET_PRESCALER(hLed->hTim, 0);

The user would check in the reference manual which peripheral clock source the timer used is supplied with, and pass HAL_RCC_GetPCLK1Freq() or HAL_RCC_GetPCLK2Freq() accordingly:

WS28XX_Init(&WS2812StatusLEDs, &htim20, HAL_RCC_GetPCLK2Freq()/1000000, TIM_CHANNEL_4, WS28XX_PIXEL_MAX);

It should be pointed out that the parameter does not need to be divided by (TIMnn->PSC+1).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions