Archived
1
0
This repo is archived. You can view files and clone it, but cannot push or open issues or pull requests.
keybrd/src/Scanner_ShiftRegsPISOSingleRow.cpp

46 lines
1.3 KiB
C++
Raw Normal View History

2016-09-25 04:27:06 +00:00
#include "Scanner_ShiftRegsPISOSingleRow.h"
/* constructor
Parameter strobeOn is not used.
2016-09-25 04:27:06 +00:00
*/
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()
{
SPI.begin();
digitalWrite(slaveSelect, HIGH);
}
/* scan() returns state of the shift register's input pins.
Parameter strobePin is not used.
2016-09-25 04:27:06 +00:00
No strobe pin is needed, the shift register is wired so the strobe is effectivley always "on".
Bit patterns are 1 bit per key.
*/
read_pins_t Scanner_ShiftRegsPISOSingleRow::scan(const uint8_t strobePin)
{
read_pins_t readState = 0; //bits, 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;
}