2016-06-18 22:32:21 +00:00
|
|
|
#ifndef ROWSCANNER_SPI_SHIFTREGISTERS_H
|
|
|
|
#define ROWSCANNER_SPI_SHIFTREGISTERS_H
|
|
|
|
#include <Arduino.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <SPI.h>
|
|
|
|
#include <RowScannerInterface.h>
|
|
|
|
#include <RowPort.h>
|
|
|
|
#include <ColPort.h>
|
|
|
|
|
2016-07-02 11:18:45 +00:00
|
|
|
/* RowScanner_SPIShiftRegisters reads shift registers.
|
|
|
|
shift registers 74HC165 Parallel-In-Serial-Out (PISO)
|
|
|
|
|
|
|
|
in sketch:
|
|
|
|
const uint8_t RowScanner_SPIShiftRegisters::SHIFT_LOAD = 10;
|
|
|
|
call begin() from setup()
|
2016-07-02 07:54:57 +00:00
|
|
|
|
2016-07-02 11:18:45 +00:00
|
|
|
Upto 4 shift registers can be in a daisy chained.
|
|
|
|
The maximum keys per row is 31, because Arduino's largest type is 32 bits and rowEnd consumes the last bit.
|
2016-07-02 07:54:57 +00:00
|
|
|
|
2016-07-02 11:18:45 +00:00
|
|
|
The shift registers are active high:
|
2016-07-02 07:54:57 +00:00
|
|
|
10k pull-down resistors are grounded
|
|
|
|
connect controller's MISO pin to shift register's QH pin
|
|
|
|
|
2016-07-02 21:10:02 +00:00
|
|
|
The shift register needs 5 wires.
|
|
|
|
In addition, each row needs to be connected to a strobe pin from controller.
|
|
|
|
The two parts of a split keyboard can be connected by one of:
|
|
|
|
* eSATA cable (has 7 wires, good for 2 rows)
|
|
|
|
* Ethernet cable (has 8 wires, good for 3 rows)
|
|
|
|
|
2016-06-18 22:32:21 +00:00
|
|
|
*/
|
|
|
|
class RowScanner_SPIShiftRegisters : public RowScannerInterface
|
|
|
|
{
|
|
|
|
private:
|
2016-07-02 11:18:45 +00:00
|
|
|
static const uint8_t SHIFT_LOAD; //controller's pin number that is connected to shift register's SHIFT_LOAD pin
|
2016-07-01 04:46:28 +00:00
|
|
|
const uint8_t STROBE_PIN; //Arduino pin number connected to this row
|
2016-07-02 11:18:45 +00:00
|
|
|
const read_pins_mask_t ROW_END; //bitwise, 1 bit marks positioned after last key of row
|
2016-07-02 07:54:57 +00:00
|
|
|
const uint8_t BYTE_COUNT; //number of bytes to read from shift registers
|
2016-06-18 22:32:21 +00:00
|
|
|
public:
|
2016-07-02 10:41:02 +00:00
|
|
|
RowScanner_SPIShiftRegisters(const uint8_t STROBE_PIN, uint8_t KEY_COUNT);
|
2016-06-22 02:40:35 +00:00
|
|
|
virtual read_pins_t scan(read_pins_mask_t& rowEnd);
|
2016-06-18 22:32:21 +00:00
|
|
|
void begin();
|
|
|
|
};
|
|
|
|
#endif
|