add Scanner_ShiftRegsPISO, update keybrd_4b_split_keyboard_with_shift_registers.ino
This commit is contained in:
parent
cefecb62a3
commit
15ebb4b6cf
@ -1,51 +0,0 @@
|
||||
#include "Scanner_ShiftRegs74HC165.h"
|
||||
|
||||
Scanner_ShiftRegs74HC165::Scanner_ShiftRegs74HC165(const bool strobeOn, const uint8_t slaveSelect,
|
||||
const uint8_t readPinCount)
|
||||
: strobeOn(strobeOn), strobeOff(!strobeOn), slaveSelect(slaveSelect),
|
||||
byte_count( ceil(float(readPinCount)/8) )
|
||||
{
|
||||
pinMode(slaveSelect, OUTPUT);
|
||||
}
|
||||
|
||||
/* init() is called once for each row from Row constructor.
|
||||
Configure controller to communicate with shift register matrix.
|
||||
*/
|
||||
void Scanner_ShiftRegs74HC165::init(const uint8_t strobePin)
|
||||
{
|
||||
pinMode(strobePin, OUTPUT);
|
||||
}
|
||||
|
||||
/* begin() should be called once from sketch setup().
|
||||
*/
|
||||
void Scanner_ShiftRegs74HC165::begin()
|
||||
{
|
||||
//initialize shift register's shift/load pin
|
||||
digitalWrite(slaveSelect, HIGH);
|
||||
}
|
||||
|
||||
/* scan() strobes the row's strobePin and returns state of the shift register's input pins.
|
||||
strobePin is Arduino pin number connected to this row
|
||||
Bitwise variables are 1 bit per key.
|
||||
*/
|
||||
read_pins_t Scanner_ShiftRegs74HC165::scan(const uint8_t strobePin)
|
||||
{
|
||||
read_pins_t readState = 0; //bitwise, 1 means key is pressed, 0 means released
|
||||
|
||||
//strobe row on
|
||||
digitalWrite(strobePin, strobeOn);
|
||||
//delayMicroseconds(3); //time to stablize voltage
|
||||
delayMicroseconds(333); //todo
|
||||
|
||||
//read all the column pins
|
||||
digitalWrite(slaveSelect, LOW); //load parallel inputs to the register
|
||||
digitalWrite(slaveSelect, HIGH); //shift the data toward a serial output
|
||||
//SPI.transfer(&readState, byte_count);
|
||||
SPI.transfer(&readState, 4);//todo
|
||||
|
||||
//strobe row off
|
||||
digitalWrite(strobePin, strobeOff);
|
||||
|
||||
return readState;
|
||||
}
|
||||
|
@ -1,49 +0,0 @@
|
||||
#ifndef ROWSCANNER_SHIFTREGS74HC165_H
|
||||
#define ROWSCANNER_SHIFTREGS74HC165_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <inttypes.h>
|
||||
#include <config_keybrd.h>
|
||||
#include <SPI.h>
|
||||
#include <ScannerInterface.h>
|
||||
#include <PortWriteInterface.h>
|
||||
#include <PortReadInterface.h>
|
||||
|
||||
/* Scanner_ShiftRegs74HC165 reads shift registers.
|
||||
shift registers 74HC165 are Parallel-In-Serial-Out (PISO)
|
||||
Upto 4 shift registers can be in a daisy chained for a total of 32 read pins.
|
||||
|
||||
For active low:
|
||||
Shift register parallel input pins have 10k pull-up resistors powered
|
||||
Orient diodes with cathode (banded end) towards the write pins (row)
|
||||
Controller's MISO pin is connected to shift register's complementary serial output (/QH) pin
|
||||
Use these two lines in the sketch:
|
||||
const bool Scanner_ShiftRegs74HC165::strobeOn = LOW;
|
||||
const bool Scanner_ShiftRegs74HC165::strobeOff = HIGH;
|
||||
|
||||
For active high:
|
||||
Shift register parallel input pins have 10k pull-down resistors grounded
|
||||
Orient diodes with cathode (banded end) towards the read pins.
|
||||
Controller's MISO pin is connected to shift register's serial output (QH) pin
|
||||
Use these two lines in the sketch:
|
||||
const bool Scanner_ShiftRegs74HC165::strobeOn = HIGH;
|
||||
const bool Scanner_ShiftRegs74HC165::strobeOff = LOW;
|
||||
|
||||
In addition, each row needs to be connected to a strobe pin from the controller.
|
||||
*/
|
||||
class Scanner_ShiftRegs74HC165 : public ScannerInterface
|
||||
{
|
||||
private:
|
||||
const bool strobeOn; //logic level of strobe on, active state HIGH or LOW
|
||||
const bool strobeOff; //logic level of strobe off, complement of active state
|
||||
const uint8_t slaveSelect; //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
|
||||
public:
|
||||
Scanner_ShiftRegs74HC165(const bool strobeOn, const uint8_t slaveSelect,
|
||||
const uint8_t readPinCount);
|
||||
void init(const uint8_t strobePin);
|
||||
void begin();
|
||||
virtual read_pins_t scan(const uint8_t strobePin);
|
||||
};
|
||||
#endif
|
51
src/Scanner_ShiftRegsPISOMultiRow.cpp
Normal file
51
src/Scanner_ShiftRegsPISOMultiRow.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#include "Scanner_ShiftRegsPISOMultiRow.h"
|
||||
|
||||
/* constructor
|
||||
*/
|
||||
Scanner_ShiftRegsPISOMultiRow::Scanner_ShiftRegsPISOMultiRow(const bool strobeOn,
|
||||
const uint8_t slaveSelect, const uint8_t byte_count)
|
||||
: strobeOn(strobeOn), strobeOff(!strobeOn),
|
||||
slaveSelect(slaveSelect), byte_count(byte_count)
|
||||
{
|
||||
pinMode(slaveSelect, OUTPUT);
|
||||
}
|
||||
|
||||
/* init() is called once for each row from Row constructor.
|
||||
Configures controller to communicate with shift register matrix.
|
||||
*/
|
||||
void Scanner_ShiftRegsPISOMultiRow::init(const uint8_t strobePin)
|
||||
{
|
||||
pinMode(strobePin, OUTPUT);
|
||||
}
|
||||
|
||||
/* begin() should be called once from sketch setup().
|
||||
Initializes shift register's shift/load pin.
|
||||
*/
|
||||
void Scanner_ShiftRegsPISOMultiRow::begin()
|
||||
{
|
||||
digitalWrite(slaveSelect, HIGH);
|
||||
}
|
||||
|
||||
/* scan() strobes the row's strobePin and returns state of the shift register's input pins.
|
||||
strobePin is Arduino pin number connected to this row.
|
||||
Bitwise variables are 1 bit per key.
|
||||
*/
|
||||
read_pins_t Scanner_ShiftRegsPISOMultiRow::scan(const uint8_t strobePin)
|
||||
{
|
||||
read_pins_t readState = 0; //bitwise, 1 means key is pressed, 0 means released
|
||||
|
||||
//strobe row on
|
||||
digitalWrite(strobePin, strobeOn);
|
||||
delayMicroseconds(3); //time to stablize voltage
|
||||
|
||||
//read all the column pins
|
||||
digitalWrite(slaveSelect, LOW); //load parallel inputs to the register
|
||||
digitalWrite(slaveSelect, HIGH); //shift the data toward a serial output
|
||||
SPI.transfer(&readState, byte_count);
|
||||
|
||||
//strobe row off
|
||||
digitalWrite(strobePin, strobeOff);
|
||||
|
||||
return readState;
|
||||
}
|
||||
|
58
src/Scanner_ShiftRegsPISOMultiRow.h
Normal file
58
src/Scanner_ShiftRegsPISOMultiRow.h
Normal file
@ -0,0 +1,58 @@
|
||||
#ifndef ROWSCANNER_SHIFTREGSPISOMULTIROW_H
|
||||
#define ROWSCANNER_SHIFTREGSPISOMULTIROW_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <inttypes.h>
|
||||
#include <config_keybrd.h>
|
||||
#include <SPI.h>
|
||||
#include <ScannerInterface.h>
|
||||
#include <PortWriteInterface.h>
|
||||
#include <PortReadInterface.h>
|
||||
|
||||
/* Scanner_ShiftRegsPISOMultiRow reads shift registers.
|
||||
This was tested on 74HC165 shift registers, which are Parallel-In-Serial-Out (PISO).
|
||||
Upto 4 shift registers can be in a daisy chained for a total of 32 read pins.
|
||||
|
||||
Example instantiation:
|
||||
Scanner_ShiftRegsPISOMultiRow scanner_R(HIGH, SS, 4);
|
||||
|
||||
There are three Scanner_ShiftRegsPISOMultiRow parameters.
|
||||
"strobeOn" paramter is active state HIGH or LOW.
|
||||
|
||||
"slaveSelect" paramter can be any controller pin connected to shift register's SHIFT-LOAD pin.
|
||||
slaveSelect pin SS (Arduino pin 10) has the fastest scan.
|
||||
|
||||
"byte_count" is the number of bytes to read from shift registers (1 to 4).
|
||||
byte_count should cover all the row's keys:
|
||||
byte_count*8 >= row's keyCount
|
||||
|
||||
Hardware setup:
|
||||
Each row needs to be connected to a strobe pin from the controller.
|
||||
Switche and diode in series are connected to shift-register parallel-input pins and strobed row.
|
||||
|
||||
For active low:
|
||||
Shift-register parallel-input pins need 10k pull-up resistors powered.
|
||||
Orient diodes with cathode (banded end) towards the write pins (row)
|
||||
Controller's MISO pin is connected to shift register's complementary serial output (/QH) pin
|
||||
|
||||
For active high:
|
||||
Shift-register parallel-input pins need 10k pull-down resistors grounded.
|
||||
Orient diodes with cathode (banded end) towards the read pins.
|
||||
Controller's MISO pin is connected to shift register's serial output (QH) pin
|
||||
*/
|
||||
class Scanner_ShiftRegsPISOMultiRow : public ScannerInterface
|
||||
{
|
||||
private:
|
||||
const bool strobeOn; //logic level of strobe on, active state HIGH or LOW
|
||||
const bool strobeOff; //logic level of strobe off, complement of strobeOn
|
||||
const uint8_t slaveSelect; //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
|
||||
public:
|
||||
Scanner_ShiftRegsPISOMultiRow(const bool strobeOn,
|
||||
const uint8_t slaveSelect, const uint8_t byte_count);
|
||||
virtual void init(const uint8_t strobePin);
|
||||
virtual void begin();
|
||||
virtual read_pins_t scan(const uint8_t strobePin);
|
||||
};
|
||||
#endif
|
42
src/Scanner_ShiftRegsPISOSingleRow.cpp
Normal file
42
src/Scanner_ShiftRegsPISOSingleRow.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include "Scanner_ShiftRegsPISOSingleRow.h"
|
||||
|
||||
/* constructor
|
||||
*/
|
||||
Scanner_ShiftRegsPISOSingleRow::Scanner_ShiftRegsPISOSingleRow(const bool strobeOn,
|
||||
const uint8_t slaveSelect, const uint8_t byte_count)
|
||||
: slaveSelect(slaveSelect), byte_count(byte_count)
|
||||
{
|
||||
pinMode(slaveSelect, OUTPUT);
|
||||
}
|
||||
|
||||
/* init() is called once for each row from Row constructor.
|
||||
*/
|
||||
void Scanner_ShiftRegsPISOSingleRow::init(const uint8_t strobePin)
|
||||
{
|
||||
//empty function
|
||||
}
|
||||
|
||||
/* begin() should be called once from sketch setup().
|
||||
Initializes shift register's shift/load pin.
|
||||
*/
|
||||
void Scanner_ShiftRegsPISOSingleRow::begin()
|
||||
{
|
||||
digitalWrite(slaveSelect, HIGH);
|
||||
}
|
||||
|
||||
/* scan() returns state of the shift register's input pins.
|
||||
No strobe pin is needed, the shift register is wired so the strobe is effectivley always "on".
|
||||
Bitwise variables are 1 bit per key.
|
||||
*/
|
||||
read_pins_t Scanner_ShiftRegsPISOSingleRow::scan(const uint8_t strobePin)
|
||||
{
|
||||
read_pins_t readState = 0; //bitwise, 1 means key is pressed, 0 means released
|
||||
|
||||
//read all the column pins
|
||||
digitalWrite(slaveSelect, LOW); //load parallel inputs to the register
|
||||
digitalWrite(slaveSelect, HIGH); //shift the data toward a serial output
|
||||
SPI.transfer(&readState, byte_count);
|
||||
|
||||
return readState;
|
||||
}
|
||||
|
60
src/Scanner_ShiftRegsPISOSingleRow.h
Normal file
60
src/Scanner_ShiftRegsPISOSingleRow.h
Normal file
@ -0,0 +1,60 @@
|
||||
#ifndef ROWSCANNER_SHIFTREGSPISOSINGLEROW_H
|
||||
#define ROWSCANNER_SHIFTREGSPISOSINGLEROW_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <inttypes.h>
|
||||
#include <config_keybrd.h>
|
||||
#include <SPI.h>
|
||||
#include <ScannerInterface.h>
|
||||
#include <PortWriteInterface.h>
|
||||
#include <PortReadInterface.h>
|
||||
|
||||
/* Scanner_ShiftRegsPISOSingleRow reads shift registers.
|
||||
This was tested on 74HC165 shift registers, which are Parallel-In-Serial-Out (PISO).
|
||||
Upto 4 shift registers can be in a daisy chained for a total of 32 read pins.
|
||||
|
||||
Example instantiation:
|
||||
Row row_R0(scanner_R, 0, ptrsKeys_R0, sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0));
|
||||
Scanner_ShiftRegsPISOSingleRow scanner_R(HIGH, SS, 4);
|
||||
|
||||
The Row "strobePin" parameter is ignored.
|
||||
In the above example, the "strobePin" argument is 0, but it doesn't matter what value is given.
|
||||
|
||||
There are three Scanner_ShiftRegsPISOSingleRow parameters.
|
||||
"strobeOn" paramter is active state HIGH or LOW.
|
||||
|
||||
"slaveSelect" paramter can be any controller pin connected to shift register's SHIFT-LOAD pin.
|
||||
slaveSelect pin SS (Arduino pin 10) has the fastest scan.
|
||||
|
||||
"byte_count" is the number of bytes to read from shift registers (1 to 4).
|
||||
byte_count should cover all the row's keys:
|
||||
byte_count*8 >= row's keyCount
|
||||
|
||||
Hardware setup:
|
||||
There is only one row, and it is permanently active.
|
||||
Switches are connected to shift-register parallel-input pins (diodes are not needed) and row.
|
||||
|
||||
For active low:
|
||||
Shift-register parallel-input pins need 10k pull-up resistors powered.
|
||||
Switches connect powered row to parallel-input pins.
|
||||
Controller's MISO pin is connected to shift register's complementary serial output (/QH) pin
|
||||
|
||||
For active high:
|
||||
Shift-register parallel-input pins need 10k pull-down resistors grounded.
|
||||
Switches connect grouned row to parallel-input pins.
|
||||
Controller's MISO pin is connected to shift register's serial output (QH) pin
|
||||
*/
|
||||
class Scanner_ShiftRegsPISOSingleRow : public ScannerInterface
|
||||
{
|
||||
private:
|
||||
const uint8_t slaveSelect; //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
|
||||
public:
|
||||
Scanner_ShiftRegsPISOSingleRow(const bool strobeOn,
|
||||
const uint8_t slaveSelect, const uint8_t byte_count);
|
||||
void init(const uint8_t strobePin);
|
||||
void begin();
|
||||
virtual read_pins_t scan(const uint8_t strobePin);
|
||||
};
|
||||
#endif
|
@ -19,8 +19,8 @@ The right matrix has 2 shift registers daisy chained.
|
||||
#include <Row.h>
|
||||
|
||||
//Right matrix
|
||||
#include <SPI.h>//needed?? todo
|
||||
#include <Scanner_ShiftRegs74HC165.h>
|
||||
//#include <SPI.h>//needed?? todo
|
||||
#include <Scanner_ShiftRegsPISOSingleRow.h>
|
||||
|
||||
// =============== CONFIGURATION ===============
|
||||
ScanDelay scanDelay(9000);
|
||||
@ -62,7 +62,7 @@ Row row_L1(scanner_L, 1, ptrsKeys_L1, KEY_COUNT_L1);
|
||||
|
||||
// =============== RIGHT MATRIX ================
|
||||
//use slaveSelect pin SS (Arduino pin 10) for fastest scan
|
||||
Scanner_ShiftRegs74HC165 scanner_R(HIGH, SS, 14); //active HIGH
|
||||
Scanner_ShiftRegsPISOSingleRow scanner_R(HIGH, SS, 2); //active HIGH
|
||||
|
||||
//rows
|
||||
Key* ptrsKeys_R0[] = { &s_6, &s_5, &s_4, &s_3, //shift register on right
|
||||
|
Reference in New Issue
Block a user