Submitting a pull request | Submitting a pull request | ||||
------------------------- | ------------------------- | ||||
Pull request is the preferred way to contribute code and documentation. | Pull request is the preferred way to contribute code and documentation. | ||||
[How to contribute to an open source project on GitHub](http://blog.davidecoppola.com/2016/11/howto-contribute-to-open-source-project-on-github/) | |||||
If you want to contribute some other way, please make a request in | If you want to contribute some other way, please make a request in | ||||
[GitHub issues](https://github.com/wolfv6/Keybrd/issues) | [GitHub issues](https://github.com/wolfv6/Keybrd/issues) | ||||
or [geekhack thread](https://geekhack.org/index.php?topic=83599.0). | or [geekhack thread](https://geekhack.org/index.php?topic=83599.0). |
[keybrd_DH_library_developer_guide.md](https://github.com/wolfv6/keybrd_DH/blob/master/doc/keybrd_DH_library_developer_guide.md)<br> | [keybrd_DH_library_developer_guide.md](https://github.com/wolfv6/keybrd_DH/blob/master/doc/keybrd_DH_library_developer_guide.md)<br> | ||||
[mainSketch.ino](https://github.com/wolfv6/keybrd_DH/blob/master/examples/keybrd_DH/mainSketch.cpp)<br> | [mainSketch.ino](https://github.com/wolfv6/keybrd_DH/blob/master/examples/keybrd_DH/mainSketch.cpp)<br> | ||||
[instantiations_scannersLEDs.h](https://github.com/wolfv6/keybrd_DH/blob/master/src/instantiations_pins.h)<br> | |||||
[instantiations_scannersLEDs.h](https://github.com/wolfv6/keybrd_DH/blob/master/src/instantiations_scannersLEDs.h)<br> | |||||
[instantiations_scancodes.h](https://github.com/wolfv6/keybrd_DH/blob/master/src/instantiations_scancodes.h)<br> | [instantiations_scancodes.h](https://github.com/wolfv6/keybrd_DH/blob/master/src/instantiations_scancodes.h)<br> | ||||
[instantiations_layercodes.h](https://github.com/wolfv6/keybrd_DH/blob/master/src/instantiations_layercodes.h)<br> | [instantiations_layercodes.h](https://github.com/wolfv6/keybrd_DH/blob/master/src/instantiations_layercodes.h)<br> | ||||
[instantiations_rows_L.h](https://github.com/wolfv6/keybrd_DH/blob/master/src/instantiations_rows_L.h)<br> | [instantiations_rows_L.h](https://github.com/wolfv6/keybrd_DH/blob/master/src/instantiations_rows_L.h)<br> |
name=keybrd | name=keybrd | ||||
version=0.5.0 | |||||
version=0.6.1 | |||||
author=Wolfram Volpi | author=Wolfram Volpi | ||||
maintainer=Wolfram Volpi | maintainer=Wolfram Volpi | ||||
sentence=A library for creating custom-keyboard firmware. | sentence=A library for creating custom-keyboard firmware. |
void Scanner_IOE::begin() | void Scanner_IOE::begin() | ||||
{ | { | ||||
refPortWrite.beginProtocol(); | refPortWrite.beginProtocol(); | ||||
refPortWrite.begin(strobeOn); | |||||
refPortRead.begin(strobeOn); | |||||
refPortWrite.begin(activeState); | |||||
refPortRead.begin(activeState); | |||||
} | } | ||||
/* scan() is called on every iteration of sketch loop(). | /* scan() is called on every iteration of sketch loop(). | ||||
uint8_t readState; //bits, 1 means key is pressed, 0 means released | uint8_t readState; //bits, 1 means key is pressed, 0 means released | ||||
//strobe on | //strobe on | ||||
refPortWrite.write(strobePin, strobeOn); | |||||
refPortWrite.write(strobePin, activeState); | |||||
delayMicroseconds(3); //time to stabilize voltage | delayMicroseconds(3); //time to stabilize voltage | ||||
//read the port pins | //read the port pins | ||||
readState = refPortRead.read(); | readState = refPortRead.read(); | ||||
//strobe off | //strobe off | ||||
refPortWrite.write(strobePin, strobeOff); | |||||
refPortWrite.write(strobePin, !activeState); | |||||
if (strobeOn == LOW) //if active low | |||||
if (activeState == LOW) //if active low | |||||
{ | { | ||||
readState = ~readState; | readState = ~readState; | ||||
} | } |
class Scanner_IOE : public ScannerInterface | class Scanner_IOE : public ScannerInterface | ||||
{ | { | ||||
private: | private: | ||||
const bool strobeOn; //logic level of strobe on, HIGH or LOW | |||||
const bool strobeOff; //logic level of strobe off, complement of strobeOn | |||||
const bool activeState; //logic level of strobe on, HIGH or LOW | |||||
PortInterface& refPortWrite; //the IC port containing the strobePin | PortInterface& refPortWrite; //the IC port containing the strobePin | ||||
PortInterface& refPortRead; //the IC's read port | PortInterface& refPortRead; //the IC's read port | ||||
public: | public: | ||||
Scanner_IOE(const bool strobeOn, | |||||
PortInterface &refPortWrite, PortInterface& refPortRead) | |||||
: strobeOn(strobeOn), strobeOff(!strobeOn), | |||||
refPortWrite(refPortWrite), refPortRead(refPortRead) {} | |||||
Scanner_IOE(const bool activeState, PortInterface &refPortWrite, PortInterface& refPortRead) | |||||
: activeState(activeState) refPortWrite(refPortWrite), refPortRead(refPortRead) {} | |||||
void init(const uint8_t strobePin); | void init(const uint8_t strobePin); | ||||
void begin(); | void begin(); | ||||
read_pins_t scan(const uint8_t strobePin); | read_pins_t scan(const uint8_t strobePin); |
#include "Scanner_ShiftRegsRead.h" | #include "Scanner_ShiftRegsRead.h" | ||||
/* constructor | /* constructor | ||||
Parameter strobeOn is not used. | |||||
Parameter activeState is not used. | |||||
*/ | */ | ||||
Scanner_ShiftRegsRead::Scanner_ShiftRegsRead(const bool strobeOn, | |||||
Scanner_ShiftRegsRead::Scanner_ShiftRegsRead(const bool activeState, | |||||
const uint8_t slaveSelect, const uint8_t byte_count) | const uint8_t slaveSelect, const uint8_t byte_count) | ||||
: slaveSelect(slaveSelect), byte_count(byte_count) | : slaveSelect(slaveSelect), byte_count(byte_count) | ||||
{ | { |
In the above Row instantiation, argument 0 for "strobePin" is ignored because there is no strobe. | In the above Row instantiation, argument 0 for "strobePin" is ignored because there is no strobe. | ||||
There are three Scanner_ShiftRegsRead parameters. | There are three Scanner_ShiftRegsRead parameters. | ||||
1. "strobeOn" paramter is ignored, but should be active state HIGH or LOW for ScannerInterface. | |||||
1. "activeState" paramter is ignored, but should be active state HIGH or LOW for ScannerInterface. | |||||
2. "slaveSelect" paramter can be any controller pin connected to shift register's SHIFT-LOAD pin. | 2. "slaveSelect" paramter can be any controller pin connected to shift register's SHIFT-LOAD pin. | ||||
3. "byte_count" is the number of bytes to read from shift registers (1 to 4). | 3. "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 | byte_count should cover all the row's keys: byte_count*8 >= row's keyCount | ||||
const uint8_t slaveSelect;//controller pin number connected to shift register SHIFT-LOAD pin | const uint8_t slaveSelect;//controller pin number connected to shift register SHIFT-LOAD pin | ||||
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: | ||||
Scanner_ShiftRegsRead(const bool strobeOn, | |||||
Scanner_ShiftRegsRead(const bool activeState, | |||||
const uint8_t slaveSelect, const uint8_t byte_count); | const uint8_t slaveSelect, const uint8_t byte_count); | ||||
void init(const uint8_t strobePin); | void init(const uint8_t strobePin); | ||||
void begin(); | void begin(); |
#include "Scanner_ShiftRegsReadStrobed.h" | #include "Scanner_ShiftRegsReadStrobed.h" | ||||
Scanner_ShiftRegsReadStrobed::Scanner_ShiftRegsReadStrobed(const bool strobeOn, | |||||
Scanner_ShiftRegsReadStrobed::Scanner_ShiftRegsReadStrobed(const bool activeState, | |||||
const uint8_t slaveSelect, const uint8_t byte_count) | const uint8_t slaveSelect, const uint8_t byte_count) | ||||
: strobeOn(strobeOn), strobeOff(!strobeOn), | |||||
: activeState(activeState), | |||||
slaveSelect(slaveSelect), byte_count(byte_count) | slaveSelect(slaveSelect), byte_count(byte_count) | ||||
{ | { | ||||
pinMode(slaveSelect, OUTPUT); | pinMode(slaveSelect, OUTPUT); | ||||
{ | { | ||||
read_pins_t readState = 0; //bits, 1 means key is pressed, 0 means released | read_pins_t readState = 0; //bits, 1 means key is pressed, 0 means released | ||||
digitalWrite(strobePin, strobeOn); //strobe on | |||||
digitalWrite(strobePin, activeState); //strobe on | |||||
//SPI.beginTransaction( SPISettings(5000000, MSBFIRST, SPI_MODE0) ); //control SPI bus, 5 MHz | //SPI.beginTransaction( SPISettings(5000000, MSBFIRST, SPI_MODE0) ); //control SPI bus, 5 MHz | ||||
digitalWrite(slaveSelect, HIGH); //shift the data toward a serial output | digitalWrite(slaveSelect, HIGH); //shift the data toward a serial output | ||||
digitalWrite(strobePin, strobeOff); //strobe off | |||||
digitalWrite(strobePin, !activeState); //strobe off to preserv IR LED life | |||||
SPI.transfer(&readState, byte_count); | SPI.transfer(&readState, byte_count); | ||||
Scanner_ShiftRegsReadStrobed scanner_R(HIGH, 6, 4); | Scanner_ShiftRegsReadStrobed scanner_R(HIGH, 6, 4); | ||||
There are three Scanner_ShiftRegsReadStrobed parameters. | There are three Scanner_ShiftRegsReadStrobed parameters. | ||||
1. "strobeOn" paramter is active state HIGH or LOW. | |||||
1. "activeState" paramter is active state HIGH or LOW. | |||||
2. "slaveSelect" paramter is controller pin connected to shift register's SHIFT-LOAD pin. | 2. "slaveSelect" paramter is controller pin connected to shift register's SHIFT-LOAD pin. | ||||
3. "byte_count" is the number of bytes to read from shift registers (1 to 4). | 3. "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 | byte_count should cover all the row's keys: byte_count*8 >= row's keyCount | ||||
class Scanner_ShiftRegsReadStrobed : public ScannerInterface | class Scanner_ShiftRegsReadStrobed : public ScannerInterface | ||||
{ | { | ||||
private: | 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 bool activeState; //logic level of strobe on, active state HIGH or LOW | |||||
const uint8_t slaveSelect;//controller pin number connected to shift register SHIFT-LOAD pin | const uint8_t slaveSelect;//controller pin number connected to shift register SHIFT-LOAD pin | ||||
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: | ||||
Scanner_ShiftRegsReadStrobed(const bool strobeOn, | |||||
Scanner_ShiftRegsReadStrobed(const bool activeState, | |||||
const uint8_t slaveSelect, const uint8_t byte_count); | const uint8_t slaveSelect, const uint8_t byte_count); | ||||
virtual void init(const uint8_t strobePin); | virtual void init(const uint8_t strobePin); | ||||
virtual void begin(); | virtual void begin(); |
/* constructor | /* constructor | ||||
*/ | */ | ||||
Scanner_uC::Scanner_uC(const bool strobeOn, const uint8_t readPins[], const uint8_t readPinCount) | |||||
: strobeOn(strobeOn), strobeOff(!strobeOn), readPins(readPins), readPinCount(readPinCount) | |||||
Scanner_uC::Scanner_uC(const bool activeState, const uint8_t readPins[], const uint8_t readPinCount) | |||||
: activeState(activeState), readPins(readPins), readPinCount(readPinCount) | |||||
{ | { | ||||
uint8_t mode; | uint8_t mode; | ||||
//configure read pins | //configure read pins | ||||
if (strobeOn == LOW) //if active low | |||||
if (activeState == LOW) //if active low | |||||
{ | { | ||||
mode = INPUT_PULLUP; //use internal pull-up resistor | mode = INPUT_PULLUP; //use internal pull-up resistor | ||||
} | } | ||||
read_pins_t readState = 0; //bits, 1 means key is pressed, 0 means released | read_pins_t readState = 0; //bits, 1 means key is pressed, 0 means released | ||||
read_pins_t readMask = 1; //bits, active bit is 1 | read_pins_t readMask = 1; //bits, active bit is 1 | ||||
//strobe row on | |||||
digitalWrite(strobePin, strobeOn); | |||||
//strobe on | |||||
digitalWrite(strobePin, activeState); | |||||
delayMicroseconds(3); //time to stablize voltage | delayMicroseconds(3); //time to stablize voltage | ||||
//read all the read pins | //read all the read pins | ||||
for (uint8_t i=0; i < readPinCount; i++) | for (uint8_t i=0; i < readPinCount; i++) | ||||
{ | { | ||||
if ( digitalRead(readPins[i]) == strobeOn ) | |||||
if ( digitalRead(readPins[i]) == activeState ) | |||||
{ | { | ||||
readState |= readMask; | readState |= readMask; | ||||
} | } | ||||
readMask <<= 1; | readMask <<= 1; | ||||
} | } | ||||
//strobe row off | |||||
digitalWrite(strobePin, strobeOff); | |||||
//strobe off | |||||
digitalWrite(strobePin, !activeState); | |||||
return readState; | return readState; | ||||
} | } |
class Scanner_uC : public ScannerInterface | class Scanner_uC : public ScannerInterface | ||||
{ | { | ||||
private: | private: | ||||
const bool strobeOn; //logic level of strobe on, HIGH or LOW | |||||
const bool strobeOff; //logic level of strobe off, complement of strobeOn | |||||
const bool activeState; //logic level of strobe on, HIGH or LOW | |||||
const uint8_t* const readPins; //array of read pin numbers | const uint8_t* const readPins; //array of read pin numbers | ||||
const uint8_t readPinCount; //number of readPins | const uint8_t readPinCount; //number of readPins | ||||
public: | public: | ||||
Scanner_uC(const bool strobeOn, const uint8_t readPins[], const uint8_t readPinCount); | |||||
Scanner_uC(const bool activeState, const uint8_t readPins[], const uint8_t readPinCount); | |||||
void init(const uint8_t strobePin); | void init(const uint8_t strobePin); | ||||
virtual read_pins_t scan(const uint8_t strobePin); | virtual read_pins_t scan(const uint8_t strobePin); | ||||
}; | }; |