drivers: display_nrf_led_matrix: Correct calculation of pixel period

This is a follow-up to commit 4dfab40cac.

The calculation of the pixel period is done incorrectly and results
in higher than configured refresh frequency if pixels are refreshed
in groups. Fix that and lower the base frequency for the timer and
PWM so that wider range of refresh frequency can be used also with
the pixel grouping.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
This commit is contained in:
Andrzej Głąbek 2021-12-22 11:28:16 +01:00 committed by Carles Cufí
parent 0813d09df9
commit ea81b4b812

View file

@ -60,13 +60,15 @@ LOG_MODULE_REGISTER(nrf_led_matrix, CONFIG_DISPLAY_LOG_LEVEL);
DT_FOREACH_PROP_ELEM(MATRIX_NODE, pixel_mapping, CHECK_PIXEL)
#define REFRESH_FREQUENCY DT_PROP(MATRIX_NODE, refresh_frequency)
#define BASE_FREQUENCY 16000000
#define TIMER_CLK_CONFIG NRF_TIMER_FREQ_16MHz
#define PWM_CLK_CONFIG NRF_PWM_CLK_16MHz
#define BASE_FREQUENCY 8000000
#define TIMER_CLK_CONFIG NRF_TIMER_FREQ_8MHz
#define PWM_CLK_CONFIG NRF_PWM_CLK_8MHz
#define BRIGHTNESS_MAX 255
#define QUANTUM (BASE_FREQUENCY / (REFRESH_FREQUENCY * BRIGHTNESS_MAX * \
PIXEL_COUNT * GROUP_SIZE))
/* Always round up, as even a partially filled group uses the full time slot. */
#define PIXEL_SLOTS (ROW_COUNT * NRFX_CEIL_DIV(COL_COUNT, GROUP_SIZE))
#define QUANTUM (BASE_FREQUENCY \
/ (REFRESH_FREQUENCY * PIXEL_SLOTS * BRIGHTNESS_MAX))
#define PIXEL_PERIOD (BRIGHTNESS_MAX * QUANTUM)
#if (PIXEL_PERIOD > BIT_MASK(16)) || \
(USE_PWM && PIXEL_PERIOD > PWM_COUNTERTOP_COUNTERTOP_Msk)