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.

Row.h 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifndef ROW_H
  2. #define ROW_H
  3. #include <RowBase.h>
  4. #define SAMPLE_COUNT 4 //number of consecutive equal bits needed to change a debounced bit
  5. /*
  6. Configuration
  7. -------------
  8. #define SAMPLE_COUNT in this header file.
  9. define and initilize DELAY_MICROSECONDS in sketch.
  10. const unsigned int Row::DELAY_MICROSECONDS = 0;
  11. Instantiation
  12. ------------
  13. Example instantiation of a row:
  14. RowPort_AVR rowPortF(DDRF, PORTF);
  15. ColPort_AVR colPortB(DDRB, PORTB, PINB, 1<<0 | 1<<1 | 1<<2 | 1<<3 );
  16. ColPort_AVR colPortD(DDRD, PORTD, PIND, 1<<2 | 1<<3 );
  17. ColPort* const ptrsColPorts[] = { &colPortB, &colPortD };
  18. const uint8_t COL_PORTS_COUNT = sizeof(ptrsColPorts)/sizeof(*ptrsColPorts);
  19. const PROGMEM Key* const ptrsKeys_0[] = { &k_00, &k_01, &k_02, &k_03, &k_04, &k_05 };
  20. Row row_0(ptrsKeys_0, &rowPortF, 1<<0, ptrsColPorts, COL_PORTS_COUNT);
  21. Number of ColPort::colPins should equal number of keys in Row::ptrsKeys array
  22. if a pin is missing, a key will be unresposive
  23. if a Key pointer is missing, the keyboard will fail in an unprdictable way
  24. */
  25. class Row : public RowBase
  26. {
  27. private:
  28. uint8_t samples[SAMPLE_COUNT]; //bitwise, one bit per key, most recent readings
  29. uint8_t samplesIndex; //samples[] current write index
  30. virtual uint8_t debounce(const uint8_t rowState);
  31. public:
  32. Row( RowPort &refRowPort, const uint8_t rowPin,
  33. ColPort *const ptrsColPorts[], const uint8_t colPortCount, Key *const ptrsKeys[])
  34. : RowBase(refRowPort, rowPin, ptrsColPorts, colPortCount, ptrsKeys), samplesIndex(0) { }
  35. };
  36. #endif