keyscanner::ATmega: Allow setting the scan cycle time at run-time

With this, it is possible to set the time (in milliseconds) between scans. The
aim is to make it possible to change this setting in one's `setup()` in their
own sketch.

One can do that as follows:

  `Kaleidoscope.device().keyscanner().setScanCycleTime(2000);`

This is currently only implemented for the ATmega keyscanner.

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/862/head
Gergely Nagy 5 years ago
parent 25272629ab
commit 2f35c25cd0
No known key found for this signature in database
GPG Key ID: AC1E90BAC433F68F

@ -111,10 +111,14 @@ class ATmega: public kaleidoscope::driver::keyscanner::Base<_KeyScannerProps> {
}
/* Set up Timer1 for 1700usec */
setScanCycleTime(1700);
}
void setScanCycleTime(uint16_t c) {
TCCR1B = _BV(WGM13);
TCCR1A = 0;
const uint32_t cycles = (F_CPU / 2000000) * 1700;
const uint32_t cycles = (F_CPU / 2000000) * c;
ICR1 = cycles;
TCCR1B = _BV(WGM13) | _BV(CS10);

Loading…
Cancel
Save