Improvement to am335x_lcd_calc_divisor()
Leonardo Fogel
leonardofogel at yahoo.com.br
Tue Jun 30 15:46:57 UTC 2015
I just realized the last proposal would depend on 64-bit multiplication, which may not be available. Here is another approach:
Let f be the fractional part of r, the real number (R%F)/F. If f >= 0.5, then lround(r) rounds up. We can test the multiplicative inverse of f, 1/f, F/(R%F). If 1/f <= 2, then lround(r) rounds up.
if (freq == 0) /* there is a bug somewhere. */
return (255);
if ((reference%freq > 0) && (freq/(reference%freq) <= 2))
div = reference/freq + 1; /* rounds up */
else
div = reference/freq; /* rounds down */
/* Raster mode case: divisors are in range from 2 to 255 */
if (div < 2)
div = 2;
else if (div > 255)
dir = 255;
return (div);
Thank you.
Leonardo
More information about the freebsd-arm
mailing list