diff --git a/doc/keybrd_library_developer_guide.md b/doc/keybrd_library_developer_guide.md index d74bbbc..81aa2e0 100644 --- a/doc/keybrd_library_developer_guide.md +++ b/doc/keybrd_library_developer_guide.md @@ -24,7 +24,9 @@ Keybrd library class inheritance diagram Scanner_uC Scanner_IOE Scanner_ShiftRegsPISO - PortInterface + PortWriteInterface + / \ + PortInterface Port_ShiftRegs (Port class for MOSI shift registers) / \ Port_PCA9655E Port_MCP23S17 (one Port class for each IOE type) diff --git a/src/LED_Port.h b/src/LED_Port.h index c541751..d1d49d5 100644 --- a/src/LED_Port.h +++ b/src/LED_Port.h @@ -3,23 +3,29 @@ #include #include #include -#include +#include /* An LED_Port object is an I/O expander pin that is connected to an LED indicator light. +LED_Port functions turn LED on and off. Example initialization: const uint8_t IOE_ADDR = 0x20; Port_MCP23S17 portA(IOE_ADDR, 0, 1<<0 | 1<<1 ); LED_Port LED_fn(portA, 1<<5); + +Example initialization: + Port_ShiftRegs shiftRegs(8); + LED_Port LED_fn(shiftRegs, 1<<6); + */ class LED_Port : public LEDInterface { private: - PortInterface& refPort; - const uint8_t pin; //bit pattern, 1 is IOE pin to LED + PortWriteInterface& refPort; + const uint8_t pin; //bit pattern, 1 is pin connected to LED public: - LED_Port(PortInterface& refPort, const uint8_t pin) + LED_Port(PortWriteInterface& refPort, const uint8_t pin) : refPort(refPort), pin(pin) {} virtual void on(); virtual void off(); diff --git a/src/LED_ShiftReg.cpp b/src/LED_ShiftReg.cpp deleted file mode 100644 index cfb3b17..0000000 --- a/src/LED_ShiftReg.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "LED_ShiftReg.h" - -void LED_ShiftReg::on() -{ - refPort.write(pin, HIGH); -} - -void LED_ShiftReg::off() -{ - refPort.write(pin, LOW); -} diff --git a/src/LED_ShiftReg.h b/src/LED_ShiftReg.h deleted file mode 100644 index d4a9acf..0000000 --- a/src/LED_ShiftReg.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef LED_SHIFTREG_H -#define LED_SHIFTREG_H -#include -#include -#include -#include - -/* LED_ShiftReg turns LED on and off. -shift register RCLK pin a.k.a. SS or ST -*/ -class LED_ShiftReg: public LEDInterface -{ - private: - PortWriteInterface& refPort; - const uint8_t pin; //bit pattern, 1 is shift-register pin connected to an LED - public: - LED_ShiftReg(PortWriteInterface& refPort, uint8_t pin) - : refPort(refPort), pin(pin) {} - virtual void on(); - virtual void off(); -}; -#endif diff --git a/src/PortInterface.h b/src/PortInterface.h index d8338a4..0f37b1f 100644 --- a/src/PortInterface.h +++ b/src/PortInterface.h @@ -2,11 +2,15 @@ #define PORTINTERFACE_H #include #include +#include /* Port classes are the keybrd library's interface to microcontroller ports or I/O expander ports. + +Port classes that can read and write, inherit from PortInterface. +Port classes that can only write, inherit from PortWriteInterface. */ -class PortInterface +class PortInterface : public PortWriteInterface { public: virtual void beginProtocol()=0; //SPI bus or I2C bus diff --git a/src/PortWriteInterface.h b/src/PortWriteInterface.h index 037be89..b7e3815 100644 --- a/src/PortWriteInterface.h +++ b/src/PortWriteInterface.h @@ -3,6 +3,12 @@ #include #include +/* +Port classes are the keybrd library's interface to MOSI shift registers i.e. Port_ShiftRegs + +Port classes that can read & write, inherit from PortInterface. +Port classes that can only write, inherit from PortWriteInterface. +*/ class PortWriteInterface { public: diff --git a/src/Port_ShiftRegs.h b/src/Port_ShiftRegs.h index f21f432..4f379d9 100644 --- a/src/Port_ShiftRegs.h +++ b/src/Port_ShiftRegs.h @@ -6,12 +6,12 @@ #include /* Port_ShiftRegs -shift register RCLK pin a.k.a. SS or ST +slaveSelect is controller-pin number connected to shift register RCLK pin a.k.a. SS or ST */ class Port_ShiftRegs : public PortWriteInterface { private: - const uint8_t slaveSelect; //controller-pin number connected to shift register RCLK + const uint8_t slaveSelect; //controller-pin number uint8_t outputVal; //bit pattern for LEDs public: Port_ShiftRegs(const uint8_t slaveSelect);