void TriggerManager::init(PinSettings* pins, uint8_t* preDelay, uint8_t* holdTime) { // save arguments for (uint8_t index=0; index<numbChannels; index++) { setPreDelay(index,preDelay[index]); setHoldTime(index,holdTime[index]); this->pins[index] = pins[index]; } setAllOff(); // set pins in output mode for (uint8_t index=0; index<numbChannels; index++) { *(this->pins[index].PORT_REG) &= ~(1<<(this->pins[index].PinIndex)); *(this->pins[index].DDR_REG) |= 1<<(this->pins[index].PinIndex); states[index] = false; } //setup timer TCCR0A = (1<<WGM01); TCCR0B = (1<<CS02) | (1<<CS00); OCR0A = F_CPU/1024/interruptFreq; TIMSK0 = (1<<OCIE0A); #ifdef DEBUG_IR bit_dir_outp(DEBUGPIN); bit_set(DEBUGPIN); #endif }
inline void sekvojHW::isr_updateReset(){ if(rstMaster){ bit_dir_outp(RST_PIN); if(bitRead(trigState,1)) bit_set(RST_PIN); else bit_clear(RST_PIN); } else{ if(rstInCallback!=0){ bit_dir_inp(RST_PIN); bit_set(RST_PIN); static bool rstInState; bool newState=bit_read_in(RST_PIN); if(newState && !rstInState) rstInCallback(); rstInState=newState; } } }
void sekvojHW::init(void(*buttonChangeCallback)(uint8_t number),void(*clockInCallback)(),void(*rstInCallback)()) { cli(); shiftRegFast::setup(); // BUTTONS bit_dir_inp(BUTTONCOL_0); bit_dir_inp(BUTTONCOL_1); bit_dir_inp(BUTTONCOL_2); bit_dir_inp(BUTTONCOL_3); bit_dir_outp(LEDCOL_0); bit_dir_outp(LEDCOL_1); bit_dir_outp(LEDCOL_2); bit_dir_outp(LEDCOL_3); bit_set(BUTTONCOL_0); bit_set(BUTTONCOL_1); bit_set(BUTTONCOL_2); bit_set(BUTTONCOL_3); bit_clear(LEDCOL_0); bit_clear(LEDCOL_1); bit_clear(LEDCOL_2); bit_clear(LEDCOL_3); bit_dir_inp(CLOCK_IN_PIN); bit_clear(CLOCK_IN_PIN); // LEDS /*for (uint8_t row=0; row<leds_rows; row++) { ledStatesBeg[row] = 1<<(15-row); //set row hit high ledStatesBeg[row] |= (B00001111<<8) | (B11111111); //disable all rows ledStatesEnd [row] = ledStatesBeg[row]; // copy to second set of states }*/ // store callback pointer for changed buttons this->buttonChangeCallback = buttonChangeCallback; this->clockInCallback = clockInCallback; this->rstInCallback = rstInCallback; // Disable Timer1 interrupt //TIMSK1 &= ~_BV(TOIE1); // TIMER 2 TCCR2A = (1 << WGM21); // turn on CTC mode TIMSK2 |= (1 << OCIE2A);// enable interrupt TCCR2B = B00000111; //prescaler = 1024 OCR2A = (F_CPU/1024)/(updateFreq*rowsTotal); TCNT2 = 0; sei(); bit_dir_outp(CLOCK_OUT_PIN); bit_clear(CLOCK_OUT_PIN); //bit_dir_outp(RST_PIN); //bit_clear(RST_PIN); }