//sometimes OS takes 6 seconds to recongnize keyboard, LED blinks from the begining | //sometimes OS takes 6 seconds to recongnize keyboard, LED blinks from the begining | ||||
void wait() | void wait() | ||||
{ | { | ||||
for (uint8_t count = 0; count < 6; count++) | |||||
for (uint8_t count = 0; count < 7; count++) | |||||
{ | { | ||||
//print count | //print count | ||||
Keyboard.print(count); | Keyboard.print(count); | ||||
{ | { | ||||
pinMode (LED_PIN, OUTPUT); | pinMode (LED_PIN, OUTPUT); | ||||
Keyboard.begin(); | Keyboard.begin(); | ||||
wait(); | |||||
SPI.begin(); | SPI.begin(); | ||||
row_R0.begin(); | row_R0.begin(); | ||||
row_R1.begin(); | row_R1.begin(); | ||||
wait(); | |||||
Keyboard.print(F("keybrd_shift_reg.ino ")); | Keyboard.print(F("keybrd_shift_reg.ino ")); | ||||
debug.print_free_RAM(); | debug.print_free_RAM(); | ||||
} | } |
#include "RowScanner_SPIShiftRegisters.h" | #include "RowScanner_SPIShiftRegisters.h" | ||||
void RowScanner_SPIShiftRegisters::begin() | |||||
//constructor | |||||
RowScanner_SPIShiftRegisters::RowScanner_SPIShiftRegisters(const uint8_t STROBE_PIN, uint8_t KEY_COUNT) | |||||
: STROBE_PIN(STROBE_PIN), ROW_END(1 << KEY_COUNT), BYTE_COUNT(ceil (float(KEY_COUNT)/8)) | |||||
{ | { | ||||
//configure row | |||||
//configure controller to communicate with shift register matrix | |||||
pinMode(STROBE_PIN, OUTPUT); | pinMode(STROBE_PIN, OUTPUT); | ||||
pinMode(SHIFT_LOAD, OUTPUT); | |||||
} | |||||
void RowScanner_SPIShiftRegisters::begin() | |||||
{ | |||||
//initialize shift register's shift/load pin | //initialize shift register's shift/load pin | ||||
pinMode(SHIFT_LOAD, OUTPUT); | |||||
digitalWrite(SHIFT_LOAD, HIGH); | digitalWrite(SHIFT_LOAD, HIGH); | ||||
} | } | ||||
//strobe row off | //strobe row off | ||||
digitalWrite(STROBE_PIN, LOW); | digitalWrite(STROBE_PIN, LOW); | ||||
rowEnd = 1 << KEY_COUNT; | |||||
rowEnd = ROW_END; | |||||
//rowEnd = 1 << 8; | |||||
//clear unpowered pins (for testing bb) todo | //clear unpowered pins (for testing bb) todo | ||||
rowState &= 0b01010001000100010001000100010001; //also 31st key | rowState &= 0b01010001000100010001000100010001; //also 31st key |
//todo static const bool ACTIVE_HIGH; //logic level of strobe pin: 0=activeLow, 1=activeHigh | //todo static const bool ACTIVE_HIGH; //logic level of strobe pin: 0=activeLow, 1=activeHigh | ||||
static const uint8_t SHIFT_LOAD; //controller's pin number that is connected to shift register's SHIFT_LOAD pin | static const uint8_t SHIFT_LOAD; //controller's pin number that is connected to shift register's SHIFT_LOAD pin | ||||
const uint8_t STROBE_PIN; //Arduino pin number connected to this row | const uint8_t STROBE_PIN; //Arduino pin number connected to this row | ||||
const uint8_t KEY_COUNT; //number of keys in row | |||||
const read_pins_mask_t ROW_END; //number of keys in row + 1 | |||||
const uint8_t BYTE_COUNT; //number of bytes to read from shift registers | const uint8_t BYTE_COUNT; //number of bytes to read from shift registers | ||||
public: | public: | ||||
RowScanner_SPIShiftRegisters(const uint8_t STROBE_PIN, uint8_t KEY_COUNT) | |||||
: STROBE_PIN(STROBE_PIN), KEY_COUNT(KEY_COUNT), BYTE_COUNT(ceil (float(KEY_COUNT)/8)) {} | |||||
RowScanner_SPIShiftRegisters(const uint8_t STROBE_PIN, uint8_t KEY_COUNT); | |||||
virtual read_pins_t scan(read_pins_mask_t& rowEnd); | virtual read_pins_t scan(read_pins_mask_t& rowEnd); | ||||
void begin(); | void begin(); | ||||
}; | }; |