keybrd library is an open source library for creating custom-keyboard firmware.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

RowDelay.h 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #ifndef ROWDELAY_H
  2. #define ROWDELAY_H
  3. #include <Arduino.h>
  4. #include <inttypes.h>
  5. /* RowDelay() delay's scan to give switches time to debounce.
  6. For fastest response time, RowDelay() should be placed before scan() or after pressRelease()
  7. (RowDelay() between scan and send would unnecessarily delay send).
  8. DELAY_MICROSECONDS explained
  9. ----------------------------
  10. A keyboard with a faster scan rate responds faster.
  11. Follow these step to tune DELAY_MICROSECONDS for maximum scan rate for a given SAMPLE_COUNT:
  12. Initialize DELAY_MICROSECONDS in your sketch:
  13. const unsigned int RowDelay::DELAY_MICROSECONDS = 1000;
  14. Add this to the sketch's loop() function:
  15. debug.print_microseconds_per_scan();
  16. Compile and load the sketch into the microcontroller; microseconds_per_scan is printed every second.
  17. Adjust the value of DELAY_MICROSECONDS and repeat until:
  18. debug.print_microseconds_per_scan() <= DEBOUNCE_TIME / SAMPLE_COUNT
  19. DEBOUNCE_TIME can be obtained from the switch's datasheet. Some switch bounce times are:
  20. Cherry MX specifies 5msec bounce time http://www.cherrycorp.com/english/switches/key/mx.htm
  21. hasu measured Cherry MX bounce times .3ms to 1.4ms http://geekhack.org/index.php?topic=42385.0
  22. Tactile switch MJTP series bounce 10 ms http://www.apem.com/files/apem/brochures/MJTP_6MM.pdf
  23. Avoid sampling the switch input at a rate synchronous to events in the environment
  24. that might create periodic EMI. For instance, 50 and 60 Hz.
  25. The largest allowable DELAY_MICROSECONDS is 65535 (.065535 seconds).
  26. Polling I2C may slow the scan rate enough so that no additional delay is needed:
  27. const unsigned int RowDelay::DELAY_MICROSECONDS = 0;
  28. DELAY_MICROSECONDS is static so multiple row types can share it.
  29. For example, primary and secondary matrices would share the same DELAY_MICROSECONDS.
  30. */
  31. class RowDelay
  32. {
  33. private:
  34. static const unsigned int DELAY_MICROSECONDS; //delay between each Row scan for debouncing
  35. public:
  36. void delay();
  37. };
  38. #endif