Yes, the reason it seems unfinished is because the way the hardware timers were being built originally were very Atmel AVR-centric, which led to a lot of AVR-isms. We've been working on developing the Wiring Framework to be target independent, and as such, the settings for the hardware timers in the AVR series differ from other controllers.
As I built out the WHardwareTimer library, I started realizing that it was not going to go away from the the AVR-isms, so I ended up half-finishing the setMode and other register management functions.
But, in a nutshell, setMode writes to the WGM (Waveform Generation Mode) bits of the AVR 8 bit series TCCR (Timer/Counter Control Register).
Have a look at the HardwareTimer::setMode() function to see exact details:
void HardwareTimer::setMode(uint8_t mode)
// WGMn3 and WGMn2 are in positions 4 and 3, respectively, in TCCRnB
// WGMn1 and WGNn0 are in positions 1 and 0, respectively, in TCCRnA
// For devices with global TIMSK, 8 bit timers have:
// WGMn0 in position 6 of TCCRn register
// WGMn1 in position 3 of TCCRn register
#if defined (TIMSK)
if (_timerNumber == 0 || _timerNumber == 2)
// only a single control register on these devices (TCCRn)
*_tccrna = (*_tccrna & 0b10110111)
| ((mode & 0b00000001) << 6)
| ((mode & 0b00000010) << 2);
// everything else conforms (the two control registers for the WGM)
*_tccrna = (*_tccrna & 0b11111100) | (mode & 0b00000011);
*_tccrnb = (*_tccrnb & 0b11100111) | ((mode & 0b00001100) << 1);
#if defined (TIMSK)
The same applies to setOutputMode - which sets the COM (Compare Output Mode) bits of the TCCR register:
void HardwareTimer::setOutputMode(uint8_t channel, uint8_t outputMode)
uint8_t COMbitMask = 0b11;
outputMode &= 0b11; // only 4 modes
if (channel < _channelCount)
if ((_timerNumber == 0 || _timerNumber == 2) && _channelCount == 1)
// 8 bit timers with only 1 OCR
shiftCount = COMn0;
// 16 bit timers
if (channel == CHANNEL_A)
shiftCount = COMnA0;
else if (channel == CHANNEL_B)
shiftCount = COMnB0;
else if (channel == CHANNEL_C)
shiftCount = COMnC0;
COMbitMask <<= shiftCount;
outputMode <<= shiftCount;
*_tccrna = (*_tccrna & ~(COMbitMask)) | outputMode;
I'd like to develop the HardwareTimer class into a cross-platform Framework class, such that the functions we use are generic enough to apply to any target controller. I know that there will still be specific functions that will need to be supported, and may be handled by platform specific functions (i.e. incompatible), but target independent is what I'd personally like to shoot for.
As always, any help in designing and defining the Framework would be greatly appreciated.