I'm writing a helper class to manage timers, and I'm writing a lot of code like
if (timer == 1)
ICR1 = icr;
else if (timer == 3)
ICR3 = icr;
else if (timer == 4)
ICR4 = icr;
else if (timer == 5)
ICR5 = icr;
Is there a better way to store these registers? e.g. an array
timers {
{ ICR1, TCCR1A, OCR1A, OCR1B },
{ ICR2, TCCR2A, OCR2A, OCR2B }
etc.
to be accessed like
timers[1][0]
for ICR1.
And ultimately, how would I assign a value? e.g.
*timers[1][0] = 100;
UPDATE:
I solved the problem with
volatile uint16_t* ICRs[5];
ICRs[1] = &ICR1;
ICRs[3] = &ICR3;
ICRs[4] = &ICR4;
ICRs[5] = &ICR5;
*ICRs[1] = x;