ShiftRegister-PWM-Library icon indicating copy to clipboard operation
ShiftRegister-PWM-Library copied to clipboard

Improvement hints

Open HSyr opened this issue 4 years ago • 0 comments

Just a few quick thoughts:

  • Multi statement macros (e.g. ShiftRegisterPWM_toggleClockPinTwice) should be written using do{"statements"}while(0).
  • Consider calloc in the ShiftRegisterPWM to allocate and clear the memory at the same time, this avoids two nested loops.
  • Also floating point calculation (slow and long) code “value = (uint8_t) (value / 255.0 * resolution + .5)” can be avoided by something like “value = (uint8_t)( ( (uint_16)value * resolution + 127 ) / 255 )”.
  • I think one dimensional array (just to store channel values) is enough for this task as the actual output value is very easy to “compute” in the interrupt by comparing actual time variable to resolution variable. Sure it would be slower compared to the using the precomputed values at the large array.
  • A believe 74595 can be effectively fed by SPI.

HSyr avatar Dec 29 '20 20:12 HSyr