diff --git a/src/RowScanner_SPIShiftRegisters.cpp b/src/RowScanner_SPIShiftRegisters.cpp index bfa1cf8..9379a39 100644 --- a/src/RowScanner_SPIShiftRegisters.cpp +++ b/src/RowScanner_SPIShiftRegisters.cpp @@ -2,8 +2,12 @@ void RowScanner_SPIShiftRegisters::begin() { - pinMode (SS, OUTPUT); - digitalWrite (SS, HIGH); + //configure row + pinMode(STROBE_PIN, OUTPUT); + + //todo there is only one slave, is select needed? + pinMode (SHIFT_LOAD, OUTPUT); + digitalWrite (SHIFT_LOAD, HIGH); } /* @@ -11,12 +15,20 @@ Sets rowEnd and returns rowState. */ read_pins_t RowScanner_SPIShiftRegisters::scan(read_pins_mask_t& rowEnd) { -//todo rowEnd, rowState, return int size depend on BYTE_COUNT, like in send(), set in config_keybrd? read_pins_t rowState = 0; - digitalWrite(SS, LOW); //load parallel inputs to the register - digitalWrite(SS, HIGH); //shift the data toward a serial output + //strobe row on + digitalWrite(STROBE_PIN, LOW); + delayMicroseconds(3); //time to stablize voltage + + //read all the column pins + digitalWrite(SHIFT_LOAD, LOW); //load parallel inputs to the register + digitalWrite(SHIFT_LOAD, HIGH); //shift the data toward a serial output SPI.transfer(&rowState, BYTE_COUNT); + + //strobe row off + digitalWrite(STROBE_PIN, HIGH); + rowEnd = 1 << KEY_COUNT; return rowState; } diff --git a/src/RowScanner_SPIShiftRegisters.h b/src/RowScanner_SPIShiftRegisters.h index d8f0028..fd045e9 100644 --- a/src/RowScanner_SPIShiftRegisters.h +++ b/src/RowScanner_SPIShiftRegisters.h @@ -14,12 +14,16 @@ The maximum keys per row is 31, because Arduino's largest type is 32 bits and ro class RowScanner_SPIShiftRegisters : public RowScannerInterface { private: - const uint8_t SS; //pin on master that selects slave + //todo static const bool ACTIVE_HIGH; //logic level of strobe pin: 0=activeLow, 1=activeHigh + const uint8_t STROBE_PIN; //Arduino pin number connected to this row + const uint8_t SHIFT_LOAD; //controller's pin number that is connected to shift register's SHIFT_LOAD pin const uint8_t BYTE_COUNT; //number of bytes to read from shift registers const uint8_t KEY_COUNT; //number of keys in row public: - RowScanner_SPIShiftRegisters(const uint8_t SS, uint8_t BYTE_COUNT, uint8_t KEY_COUNT) - : SS(SS), BYTE_COUNT(BYTE_COUNT), KEY_COUNT(KEY_COUNT) {} + RowScanner_SPIShiftRegisters(const uint8_t STROBE_PIN, const uint8_t SHIFT_LOAD, + uint8_t BYTE_COUNT, uint8_t KEY_COUNT) + : STROBE_PIN(STROBE_PIN), SHIFT_LOAD(SHIFT_LOAD), + BYTE_COUNT(BYTE_COUNT), KEY_COUNT(KEY_COUNT) {} virtual read_pins_t scan(read_pins_mask_t& rowEnd); void begin(); }; diff --git a/src/Row_ShiftRegisters.h b/src/Row_ShiftRegisters.h index 777e1e7..cf244ad 100644 --- a/src/Row_ShiftRegisters.h +++ b/src/Row_ShiftRegisters.h @@ -4,6 +4,7 @@ #include #include #include +//todo #include /* Row_DH_IOE is a row connected to an Input/Output Expander. @@ -28,9 +29,11 @@ class Row_ShiftRegisters : public RowBase private: RowScanner_SPIShiftRegisters scanner; Debouncer_4Samples debouncer; + //Debouncer_Not debouncer; //todo test public: - Row_ShiftRegisters(const uint8_t SS, uint8_t BYTE_COUNT, Key *const ptrsKeys[], uint8_t KEY_COUNT) - : RowBase(ptrsKeys), scanner(SS, BYTE_COUNT, KEY_COUNT) { } + Row_ShiftRegisters(const uint8_t STROBE_PIN, const uint8_t SHIFT_LOAD, uint8_t BYTE_COUNT, + Key *const ptrsKeys[], uint8_t KEY_COUNT) + : RowBase(ptrsKeys), scanner(STROBE_PIN, SHIFT_LOAD, BYTE_COUNT, KEY_COUNT) { } void begin(); read_pins_t scan(read_pins_mask_t& rowEnd); read_pins_t debounce(const read_pins_t rowState, read_pins_t& debounced);