/* Process recurring actions for stella */ void stella_process (void) { /* the main loop is too fast, slow down */ if (stella_fade_counter == 0) { uint8_t i; /* Fade channels. stella_fade_counter is 0 currently. Set to 1 if fading changed a channel brigthness value */ for (i = 0; i < STELLA_PINS; ++i) { if (stella_brightness[i] == stella_fade[i]) continue; stella_fade_funcs[stella_fade_func].p (i); stella_fade_counter = 1; } if (stella_fade_counter) stella_sync = UPDATE_VALUES; /* reset counter */ stella_fade_counter = stella_fade_step; } /* sort if new values are available */ if (stella_sync == UPDATE_VALUES) stella_sort(); }
void stella_process (unsigned char *buf, uint8_t len) { int re_sort = 0; for (; len >= 2; buf += 2, len -= 2) if(*buf >= STELLA_SET_COLOR_0 && *buf < (STELLA_SET_COLOR_0 + STELLA_PINS)) { stella_fade[*buf] = buf[1]; stella_color[*buf] = buf[1]; re_sort = 1; } else if(*buf >= STELLA_FADE_COLOR_0 && *buf < (STELLA_FADE_COLOR_0 + STELLA_PINS)) { stella_fade[*buf & 0x07] = buf[1]; } else if(*buf >= STELLA_FLASH_COLOR_0 && *buf < (STELLA_FLASH_COLOR_0 + STELLA_PINS)) { stella_fade[*buf & 0x07] = 0; stella_color[*buf & 0x07] = buf[1]; re_sort = 1; } else if(*buf == STELLA_SELECT_FADE_FUNC) { stella_fade_func = buf[1]; } if (re_sort) stella_sort (stella_color); }
/* Initialize stella */ void stella_init (void) { int_table = &timetable_1; cal_table = &timetable_2; int_table->head = 0; cal_table->head = 0; int_table->portmask = 0; cal_table->portmask = 0; stella_sync = NOTHING_NEW; /* set stella port pins to output and save the negated port mask */ stella_portmask_neg = (uint8_t)~(((1 << STELLA_PINS) - 1) << STELLA_OFFSET); STELLA_DDR = ((1 << STELLA_PINS) - 1) << STELLA_OFFSET; //DDRC = 255; //debug_printf("stella ok_ %i \n", ((1 << STELLA_PINS) - 1) << STELLA_OFFSET); /* we need at least 64 ticks for the compare interrupt, * therefore choose a prescaler of at least 64. */ #ifdef STELLA_HIGHFREQ /* Normal PWM Mode, 64 Prescaler */ _TCCR2_PRESCALE = _BV(CS22); debug_printf("Stella freq: %u Hz\n", F_CPU/64/(256*2)); #else /* Normal PWM Mode, 128 Prescaler */ _TCCR2_PRESCALE |= _BV(CS20) | _BV(CS22); debug_printf("Stella freq: %u Hz\n", F_CPU/128/(256*2)); #endif /* Interrupt on overflow and CompareMatch */ _TIMSK_TIMER2 |= _BV(TOIE2) | _BV(_OUTPUT_COMPARE_IE2); /* initialise the fade counter. Fading works like this: * -> decrement fade_counter * -> on zero, fade if neccessary * -> reset counter to fade_step */ stella_fade_counter = stella_fade_step; #if STELLA_START == stella_start_eeprom stella_loadFromEEROMFading(); #endif #if STELLA_START == stella_start_all memset(stella_fade, 1, sizeof(stella_fade)); #endif stella_sort(); }
void stella_process(void) { #ifdef DMX_STORAGE_SUPPORT if (get_dmx_slot_state(STELLA_UNIVERSE, stella_dmx_conn_id) == DMX_NEWVALUES) { uint8_t mode = get_dmx_channel_slot(STELLA_UNIVERSE, STELLA_UNIVERSE_OFFSET, stella_dmx_conn_id); for (uint8_t i = 0; i < STELLA_CHANNELS; i++) { stella_setValue(mode, i, get_dmx_channel_slot(STELLA_UNIVERSE, STELLA_UNIVERSE_OFFSET + i + 1, stella_dmx_conn_id)); } } #endif /* the main loop is too fast, slow down */ if (stella_fade_counter == 0) { uint8_t i; /* Fade channels. stella_fade_counter is 0 currently. Set to 1 * if fading changed a channel brigthness value */ for (i = 0; i < STELLA_CHANNELS; ++i) { if (stella_brightness[i] == stella_fade[i]) continue; stella_fade_funcs[stella_fade_func].p(i); stella_fade_counter = 1; } if (stella_fade_counter) stella_sync = UPDATE_VALUES; /* reset counter */ stella_fade_counter = stella_fade_step; } /* sort if new values are available */ if (stella_sync == UPDATE_VALUES) stella_sort(); }
void stella_init(void) { int_table = &timetable_1; cal_table = &timetable_2; cal_table->head = 0; stella_sync = NOTHING_NEW; /* set stella port pins to output and save the port mask */ stella_portmask[0] = ((1 << STELLA_PINS_PORT1) - 1) << STELLA_OFFSET_PORT1; STELLA_DDR_PORT1 |= stella_portmask[0]; cal_table->port[0].port = &STELLA_PORT1; cal_table->port[0].mask = 0; #ifdef STELLA_PINS_PORT2 stella_portmask[1] = ((1 << STELLA_PINS_PORT2) - 1) << STELLA_OFFSET_PORT2; STELLA_DDR_PORT2 |= stella_portmask[1]; cal_table->port[0].port = &STELLA_PORT2; cal_table->port[1].mask = 0; #endif /* initialise the fade counter. Fading works like this: * -> decrement fade_counter * -> on zero, fade if neccessary * -> reset counter to fade_step */ stella_fade_counter = stella_fade_step; #if !defined(TEENSY_SUPPORT) && STELLA_START == stella_start_eeprom stella_loadFromEEROMFading(); #endif #if STELLA_START == stella_start_all memset(stella_fade, 255, sizeof(stella_fade)); #endif #if STELLA_START == stella_start_zero memset(stella_fade, 0, sizeof(stella_fade)); #endif stella_sort(); /* we need at least 64 ticks for the compare interrupt, * therefore choose a prescaler of at least 64. */ #if STELLA_FREQ == stella_vslow STELLA_TC_PRESCALER_1024; debug_printf("Stella freq: %u Hz\n", F_CPU / 1024 / (256 * 2)); #elif STELLA_FREQ == stella_slow STELLA_TC_PRESCALER_256; debug_printf("Stella freq: %u Hz\n", F_CPU / 256 / (256 * 2)); #elif STELLA_FREQ == stella_normal STELLA_TC_PRESCALER_128; debug_printf("Stella freq: %u Hz\n", F_CPU / 128 / (256 * 2)); #elif STELLA_FREQ == stella_fast STELLA_TC_PRESCALER_64; debug_printf("Stella freq: %u Hz\n", F_CPU / 64 / (256 * 2)); #endif STELLA_TC_INT_OVERFLOW_ON; STELLA_TC_INT_COMPARE_ON; #ifdef DMX_STORAGE_SUPPORT /* Setup DMX-Storage Connection */ stella_dmx_conn_id = dmx_storage_connect(STELLA_UNIVERSE); #endif }