-/* This gets called from timers.c which holds the 'main' (interrupt)
- * handler for the timer1 overflow. */
-void ledpwm_TIMER1OVF_hook(void) {
- /* Turn on all LEDs */
- if (ledpwm_val[LEDPWM_REDLED] > 0) {
- LEDPORT |= _BV(LEDPINR);
+static void ledpwm_recalculateprogram(void) {
+ uint8_t nextprog = !ledpwm_activemprog;
+ uint8_t i = 0;
+ uint16_t nextminimum = 0;
+ uint8_t orval;
+
+ do {
+ orval = 0;
+ if (ledpwm_val[LEDPWM_REDLED] > nextminimum) {
+ orval |= _BV(LEDPINR);
+ }
+ if (ledpwm_val[LEDPWM_GREENLED] > nextminimum) {
+ orval |= _BV(LEDPING);
+ }
+ if (ledpwm_val[LEDPWM_BLUELED] > nextminimum) {
+ orval |= _BV(LEDPINB);
+ }
+ ledpwm_mprogs[nextprog][i].atcntval = nextminimum;
+ ledpwm_mprogs[nextprog][i].orval = orval;
+ /* now calculate nextminimum */
+ nextminimum = getnextminimum(nextminimum);
+ i++;
+ } while (nextminimum > 0);
+ while (i < 10) { /* Fill the rest with dummys that cause no harm */
+ ledpwm_mprogs[nextprog][i].atcntval = 0;
+ ledpwm_mprogs[nextprog][i].orval = 0;
+ i++;