diff --git a/doc/keybrd_library_developer_guide.md b/doc/keybrd_library_developer_guide.md index 6f79b9b..539b153 100644 --- a/doc/keybrd_library_developer_guide.md +++ b/doc/keybrd_library_developer_guide.md @@ -71,15 +71,15 @@ Keybrd library class inheritance diagram Scanner_uC Scanner_Port Scanner_ShiftRegs74HC165 - IOEPort + PortIOE - StrobePort + PortWrite | - StrobePort_PCA9655E (one StrobePort class for each IOE type) + PortWrite_PCA9655E (one PortWrite class for each IOE type) - ReadPort + PortRead | - ReadPort_PCA9655E (one ReadPort class for each IOE type) + PortRead_PCA9655E (one PortRead class for each IOE type) ____ LED ____ / \ @@ -159,13 +159,13 @@ Example secondary matrix with I/O Expander dependency diagram with LEDs ``` ___ Row_IOE[1..*] _________ / \ \ - __ Scanner_Port[1] _ Debouncer[1] Keys[1..*] __ - / | \ | \ - StrobePort[1] RowPin[1] ReadPort[1] Code[1..*] Code_LEDLock[1..*] + _ Scanner_Port[1] _ Debouncer[1] Keys[1..*] __ + / | \ | \ + PortWrite[1] RowPin[1] PortRead[1] Code[1..*] Code_LEDLock[1..*] \ / \ | \ / ColPins[1..*] LED[1] \ / - IOEPort[0..*] + PortIOE[0..*] ``` diff --git a/src/LED_PCA9655E.h b/src/LED_PCA9655E.h index 4034260..5da2111 100644 --- a/src/LED_PCA9655E.h +++ b/src/LED_PCA9655E.h @@ -4,21 +4,21 @@ #include #include #include -#include +#include /* A LED_PCA9655E object is an PCA9655E pin that is connected to an LED indicator light. -Input/Ouput Direction configuration are set to ouput in StrobePort_PCA9655E.begin() and ReadPort_PCA9655E.begin(). +Input/Ouput Direction configuration are set to ouput in PortWrite_PCA9655E.begin() and PortRead_PCA9655E.begin(). */ class LED_PCA9655E: public LED { private: - //IOEPort& port; + //PortIOE& port; //const uint8_t outputByteCommand; //General Purpose Input/Ouput register address - StrobePort_PCA9655E& refPort; + PortWrite_PCA9655E& refPort; const uint8_t pin; //bitwise pin to LED public: - LED_PCA9655E(StrobePort_PCA9655E& refPort, const uint8_t pin) + LED_PCA9655E(PortWrite_PCA9655E& refPort, const uint8_t pin) : refPort(refPort), pin(pin) {} virtual void on(); diff --git a/src/IOEPort.h b/src/PortIOE.h similarity index 65% rename from src/IOEPort.h rename to src/PortIOE.h index 6153a0f..3406e7a 100644 --- a/src/IOEPort.h +++ b/src/PortIOE.h @@ -1,20 +1,20 @@ -#ifndef IOEXPANDERPORT_H -#define IOEXPANDERPORT_H +#ifndef PORTIOE_H +#define PORTIOE_H #include -/* The pins of an IC's port can be split between StrobePort, ReadPort, and LED. +/* The pins of an IC's port can be split between PortWrite, PortRead, and LED. -IOEPort contains outputVal, the value of a port's output register. -outputVal is used for port manipulation by classes StrobePort and LED. -One port's outputVal can be shared by one StrobePort object and multiple LED objects. +PortIOE contains outputVal, the value of a port's output register. +outputVal is used for port manipulation by classes PortWrite and LED. +One port's outputVal can be shared by one PortWrite object and multiple LED objects. -IOEPort is only used by I/O expander port classes. +PortIOE is only used by I/O expander port classes. AVR port classes do not need a similar class because PORTx is global in the Arduino library. Instantiation ------------ -Example IOEPort::ADDR initilization: - const uint8_t IOEPort::ADDR = 0x18; +Example PortIOE::ADDR initilization: + const uint8_t PortIOE::ADDR = 0x18; Be careful with the ADDR. Table 6 in PCA9655E datasheet lists 8-bit versions of I2C addresses. The Arduino Wire library uses 7-bit addresses throughout, so drop the low bit. @@ -29,21 +29,21 @@ outputVal: For pins that are connected to active low rows, set outputVal bit to Set all other outputVal bits to 0. Example instantiation for port0 with active low rows on all pins: - IOEPort port0(0, ~0); + PortIOE port0(0, ~0); Example instantiation for portA with active low rows on pins 0,1,2: - IOEPort portA(0, 1<<0 | 1<<1 | 1<<2 ); + PortIOE portA(0, 1<<0 | 1<<1 | 1<<2 ); Example instantiation for portB with active high rows on pins 0,1,2: - IOEPort portB(1, 0); + PortIOE portB(1, 0); */ -struct IOEPort +struct PortIOE { static const uint8_t ADDR; //I2C address const uint8_t num; //port number uint8_t outputVal; //bitwise value of output register - IOEPort(const uint8_t portNumber, uint8_t outputVal) + PortIOE(const uint8_t portNumber, uint8_t outputVal) : num(portNumber), outputVal(outputVal) {} }; #endif diff --git a/src/ReadPort.h b/src/PortRead.h similarity index 67% rename from src/ReadPort.h rename to src/PortRead.h index cc14235..5422173 100644 --- a/src/ReadPort.h +++ b/src/PortRead.h @@ -1,18 +1,18 @@ -#ifndef READPORT_H -#define READPORT_H +#ifndef PORTREAD_H +#define PORTREAD_H #include #include /* -ReadPort is an abstract base class. +PortRead is an abstract base class. Port classes are the keybrd library's interface to microcontoller ports or I/O expander ports. */ -class ReadPort +class PortRead { protected: const uint8_t READ_PINS; //bitwise pin configuration, 1 means read column public: - ReadPort(const uint8_t READ_PINS): READ_PINS(READ_PINS) {} + PortRead(const uint8_t READ_PINS): READ_PINS(READ_PINS) {} //read port and return readState virtual uint8_t read()=0; diff --git a/src/ReadPort_PCA9655E.cpp b/src/PortRead_PCA9655E.cpp similarity index 73% rename from src/ReadPort_PCA9655E.cpp rename to src/PortRead_PCA9655E.cpp index 3663e1b..258f99e 100644 --- a/src/ReadPort_PCA9655E.cpp +++ b/src/PortRead_PCA9655E.cpp @@ -1,13 +1,13 @@ -#include "ReadPort_PCA9655E.h" +#include "PortRead_PCA9655E.h" /* configures column port's configuration, input, and pins. */ -ReadPort_PCA9655E::ReadPort_PCA9655E (IOEPort& port, const uint8_t READ_PINS) - : ReadPort(READ_PINS), port(port), configurationByteCommand(port.num + 6), inputByteCommand(port.num) +PortRead_PCA9655E::PortRead_PCA9655E (PortIOE& port, const uint8_t READ_PINS) + : PortRead(READ_PINS), port(port), configurationByteCommand(port.num + 6), inputByteCommand(port.num) {} -void ReadPort_PCA9655E::begin() +void PortRead_PCA9655E::begin() { Wire.beginTransmission(port.ADDR); Wire.write(configurationByteCommand); @@ -18,7 +18,7 @@ void ReadPort_PCA9655E::begin() /* Saves all port-pin values to portState. */ -uint8_t ReadPort_PCA9655E::read() +uint8_t PortRead_PCA9655E::read() { Wire.beginTransmission(port.ADDR); Wire.write(inputByteCommand); //input immediately before requestFrom diff --git a/src/ReadPort_PCA9655E.h b/src/PortRead_PCA9655E.h similarity index 69% rename from src/ReadPort_PCA9655E.h rename to src/PortRead_PCA9655E.h index 3042933..82b8f6c 100644 --- a/src/ReadPort_PCA9655E.h +++ b/src/PortRead_PCA9655E.h @@ -1,10 +1,10 @@ -#ifndef READPORT_PCA9655E_H -#define READPORT_PCA9655E_H +#ifndef PORTREAD_PCA9655E_H +#define PORTREAD_PCA9655E_H #include #include #include -#include -#include "IOEPort.h" +#include +#include "PortIOE.h" /* One PCA9655E I/O expander port connected to matrix columns. PCA9655E does not have internal pull-up resistors (PCA9535E does). @@ -16,11 +16,11 @@ READ_PINS parameter is port's bitwise pin configuration 0=configure as output (for LED or not connected to a column) Example instantiation for column port 0, with pins 2 and 3 connected to columns: - IOEPort port0(0, 0); - ReadPort_PCA9655E colPort0(port0, 2<<0 | 1<<3 ); + PortIOE port0(0, 0); + PortRead_PCA9655E colPort0(port0, 2<<0 | 1<<3 ); Example instantiation for column port 1, with pins 2 and 3 connected to columns: - IOEPort port1(1, 0); - ReadPort_PCA9655E colPort1(port1, 2<<0 | 1<<3 ); + PortIOE port1(1, 0); + PortRead_PCA9655E colPort1(port1, 2<<0 | 1<<3 ); READ_PINS are read from pin 0 on up. @@ -28,15 +28,15 @@ Diode orientation ---------------- Rows, columns, and diode orientation are explained in Matrix.h */ -class ReadPort_PCA9655E : public ReadPort +class PortRead_PCA9655E : public PortRead { private: - IOEPort& port; + PortIOE& port; const uint8_t configurationByteCommand; const uint8_t inputByteCommand; public: //The constructor initialization list is in .cpp - ReadPort_PCA9655E(IOEPort& port, const uint8_t READ_PINS); + PortRead_PCA9655E(PortIOE& port, const uint8_t READ_PINS); void begin(); //read port and store result in portState diff --git a/src/StrobePort.h b/src/PortWrite.h similarity index 67% rename from src/StrobePort.h rename to src/PortWrite.h index b8b827b..bbfba71 100644 --- a/src/StrobePort.h +++ b/src/PortWrite.h @@ -1,13 +1,13 @@ -#ifndef STROBEPORT_H -#define STROBEPORT_H +#ifndef PORTWRITE_H +#define PORTWRITE_H #include #include /* -StrobePort is an abstract base class. +PortWrite is an abstract base class. Port classes are the keybrd library's interface to microcontoller ports or I/O expander ports. */ -class StrobePort +class PortWrite { public: virtual void write(const uint8_t pin, const bool level)=0; diff --git a/src/StrobePort_PCA9655E.cpp b/src/PortWrite_PCA9655E.cpp similarity index 70% rename from src/StrobePort_PCA9655E.cpp rename to src/PortWrite_PCA9655E.cpp index 072521f..ed2791a 100644 --- a/src/StrobePort_PCA9655E.cpp +++ b/src/PortWrite_PCA9655E.cpp @@ -1,12 +1,16 @@ -#include "StrobePort_PCA9655E.h" +#include "PortWrite_PCA9655E.h" /* configures column port's configuration and output. */ -StrobePort_PCA9655E::StrobePort_PCA9655E(IOEPort& port) +PortWrite_PCA9655E::PortWrite_PCA9655E(PortIOE& port) : port(port), configurationByteCommand(port.num + 6), outputByteCommand(port.num + 2) {} -void StrobePort_PCA9655E::begin() +/* +If PortRead_PCA9655E is instantiated on the same port, do not use PortWrite_PCA9655E::begin(). +Use PortRead_PCA9655E::begin() instead. Otherwise READ_PINS could be overwritten. +*/ +void PortWrite_PCA9655E::begin() { Wire.beginTransmission(port.ADDR); Wire.write(configurationByteCommand); @@ -20,7 +24,7 @@ value is HIGH or LOW. Does not reset the other pins because LEDs could be using some of the pins. Syntax is similar to Arduino DigitalWrite(). */ -void StrobePort_PCA9655E::write(const uint8_t pin, const bool value) +void PortWrite_PCA9655E::write(const uint8_t pin, const bool value) { if (value == LOW) //if active low { diff --git a/src/StrobePort_PCA9655E.h b/src/PortWrite_PCA9655E.h similarity index 61% rename from src/StrobePort_PCA9655E.h rename to src/PortWrite_PCA9655E.h index 594bc04..16c54d9 100644 --- a/src/StrobePort_PCA9655E.h +++ b/src/PortWrite_PCA9655E.h @@ -1,25 +1,28 @@ -#ifndef STROBEPORT_PCA9655E_H -#define STROBEPORT_PCA9655E_H +#ifndef PORTWRITE_PCA9655E_H +#define PORTWRITE_PCA9655E_H #include #include #include -#include -#include "IOEPort.h" +#include +#include "PortIOE.h" /* One PCA9655E I/O expander port connected to matrix rows. begin() configures column port's configuration and output. This should normally be called only once. +If PortRead_PCA9655E is instantiated on the same port, do not use PortWrite_PCA9655E::begin(). +Use PortRead_PCA9655E::begin() instead. Otherwise READ_PINS could be overwritten. + Instantiation ------------ Example instantiation for row port 0: - IOEPort port0(0, 0); - StrobePort_PCA9655E rowPort0(port0); + PortIOE port0(0, 0); + PortWrite_PCA9655E rowPort0(port0); Example instantiation for row port 1: - IOEPort port1(1, 0); - StrobePort_PCA9655E rowPort1(port1); + PortIOE port1(1, 0); + PortWrite_PCA9655E rowPort1(port1); Diode orientation ---------------- @@ -32,16 +35,16 @@ PCA9655E data sheet http://www.onsemi.com/pub_link/Collateral/PCA9655E-D.PDF */ -class StrobePort_PCA9655E : public StrobePort +class PortWrite_PCA9655E : public PortWrite { private: - IOEPort& port; + PortIOE& port; const uint8_t configurationByteCommand; const uint8_t outputByteCommand; public: //The constructor initialization list is in .cpp - StrobePort_PCA9655E(IOEPort& port); + PortWrite_PCA9655E(PortIOE& port); void begin(); virtual void write(const uint8_t pin, const bool level); diff --git a/src/Scanner_Port.cpp b/src/Scanner_Port.cpp index 7facb8c..e3b99ab 100644 --- a/src/Scanner_Port.cpp +++ b/src/Scanner_Port.cpp @@ -7,15 +7,15 @@ uint8_t Scanner_Port::scan() uint8_t readState; //strobe row on - refStrobePort.write(STROBE_PIN, STROBE_ON); + refPortWrite.write(STROBE_PIN, STROBE_ON); delayMicroseconds(3); //time to stablize voltage //read the port pins - readState = refReadPort.read(); + readState = refPortRead.read(); //strobe row off - refStrobePort.write(STROBE_PIN, STROBE_OFF); + refPortWrite.write(STROBE_PIN, STROBE_OFF); - //return refReadPort.getPortState(); + //return refPortRead.getPortState(); return readState; } diff --git a/src/Scanner_Port.h b/src/Scanner_Port.h index bdbf425..36d1d44 100644 --- a/src/Scanner_Port.h +++ b/src/Scanner_Port.h @@ -2,8 +2,8 @@ #define SCANNER_PORT_H #include #include -#include -#include +#include +#include /* Scanner_Port uses bit manipulation to read all pins of one port. The maximum keys per row is 8, because ports have a maximum of 8 pins each. @@ -13,12 +13,12 @@ class Scanner_Port private: static const bool STROBE_ON; //HIGH or LOW logic level of strobe on, active state static const bool STROBE_OFF; //logic level of strobe off, complement of STROBE_ON - StrobePort& refStrobePort; //this row's IC port + PortWrite& refPortWrite; //this row's IC port const uint8_t STROBE_PIN; //bitwise, 1 indicates IC pin connected to this row - ReadPort& refReadPort; + PortRead& refPortRead; public: - Scanner_Port(StrobePort &refStrobePort, const uint8_t STROBE_PIN, ReadPort& refReadPort) - : refStrobePort(refStrobePort), STROBE_PIN(STROBE_PIN), refReadPort(refReadPort) {} + Scanner_Port(PortWrite &refPortWrite, const uint8_t STROBE_PIN, PortRead& refPortRead) + : refPortWrite(refPortWrite), STROBE_PIN(STROBE_PIN), refPortRead(refPortRead) {} uint8_t scan(); }; #endif diff --git a/src/Scanner_ShiftRegs74HC165.h b/src/Scanner_ShiftRegs74HC165.h index 21b443b..594fdf7 100644 --- a/src/Scanner_ShiftRegs74HC165.h +++ b/src/Scanner_ShiftRegs74HC165.h @@ -4,8 +4,8 @@ #include #include #include -#include -#include +#include +#include /* Scanner_ShiftRegs74HC165 reads shift registers. shift registers 74HC165 is Parallel-In-Serial-Out (PISO) diff --git a/src/Scanner_uC.h b/src/Scanner_uC.h index a6d4c44..72e8225 100644 --- a/src/Scanner_uC.h +++ b/src/Scanner_uC.h @@ -3,8 +3,8 @@ #include #include #include -#include -#include +#include +#include /* Scanner_uC class uses Arduino pin numbers (not port pin numbers). Constructor is in Scanner_uC.cpp