keybrd library is an open source library for creating custom-keyboard firmware.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

Row.h 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. static const unsigned int DELAY_MICROSECONDS; //delay between each Row scan for debouncing
  29. uint8_t samples[SAMPLE_COUNT]; //bitwise, one bit per key, most recent readings
  30. uint8_t samplesIndex; //samples[] current write index
  31. virtual uint8_t debounce(const uint8_t rowState);
  32. public:
  33. Row( RowPort &refRowPort, const uint8_t rowPin,
  34. ColPort *const ptrsColPorts[], const uint8_t colPortCount, Key *const ptrsKeys[])
  35. : RowBase(refRowPort, rowPin, ptrsColPorts, colPortCount, ptrsKeys), samplesIndex(0) { }
  36. };
  37. #endif