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>
|
|
|
|
|
|
|
|
/* RowScanner_SPIShiftRegisters reads all shift registers in a daisy chain.
|
2016-06-22 02:40:35 +00:00
|
|
|
The maximum keys per row is 31, because Arduino's largest type is 32 bits and rowEnd consumes the last bit.
|
2016-06-18 22:32:21 +00:00
|
|
|
//todo delete: Assumes only one row of shift registers is connected (no Slave Select).
|
2016-07-02 07:54:57 +00:00
|
|
|
|
|
|
|
For active low:
|
|
|
|
10k pull-up resistor are connected to power
|
|
|
|
connect controller's MISO pin to shift register's /QH pin
|
|
|
|
in sketch, const bool RowScanner_PinsArray::ACTIVE_HIGH = 0;
|
|
|
|
|
|
|
|
For active high:
|
|
|
|
10k pull-down resistors are grounded
|
|
|
|
connect controller's MISO pin to shift register's QH pin
|
|
|
|
in sketch, const bool RowScanner_PinsArray::ACTIVE_HIGH = 1;
|
|
|
|
|
|
|
|
shift registers 74HC165 Parallel-In-Serial-Out (PISO) are Daisy chained
|
|
|
|
|
|
|
|
The maximum keys per row is 31, because Arduino's largest type is 32 bits and rowEnd consumes the last bit.
|
|
|
|
call begin() from setup()
|
|
|
|
|
2016-06-18 22:32:21 +00:00
|
|
|
*/
|
|
|
|
class RowScanner_SPIShiftRegisters : public RowScannerInterface
|
|
|
|
{
|
|
|
|
private:
|
2016-07-01 04:46:28 +00:00
|
|
|
//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
|
2016-06-18 22:32:21 +00:00
|
|
|
const uint8_t KEY_COUNT; //number of keys in 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-01 04:46:28 +00:00
|
|
|
RowScanner_SPIShiftRegisters(const uint8_t STROBE_PIN, const uint8_t SHIFT_LOAD,
|
2016-07-02 07:54:57 +00:00
|
|
|
uint8_t KEY_COUNT)
|
2016-07-01 04:46:28 +00:00
|
|
|
: STROBE_PIN(STROBE_PIN), SHIFT_LOAD(SHIFT_LOAD),
|
2016-07-02 07:54:57 +00:00
|
|
|
KEY_COUNT(KEY_COUNT), BYTE_COUNT(ceil (float(KEY_COUNT)/8)) {}
|
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
|