From 6a787b415596c522aaa9165dcc22a2af4b67a395 Mon Sep 17 00:00:00 2001 From: wolfv6 Date: Tue, 15 Nov 2016 20:01:42 -0700 Subject: [PATCH] add LED_PortOpenDrain --- examples/keybrd_MCP23018/keybrd_MCP23018.ino | 4 +-- src/LED_Port.h | 5 ++- src/LED_PortOpenDrain.cpp | 12 +++++++ src/LED_PortOpenDrain.h | 36 ++++++++++++++++++++ 4 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 src/LED_PortOpenDrain.cpp create mode 100644 src/LED_PortOpenDrain.h diff --git a/examples/keybrd_MCP23018/keybrd_MCP23018.ino b/examples/keybrd_MCP23018/keybrd_MCP23018.ino index 2dabd8e..b108ae5 100644 --- a/examples/keybrd_MCP23018/keybrd_MCP23018.ino +++ b/examples/keybrd_MCP23018/keybrd_MCP23018.ino @@ -39,7 +39,7 @@ DESTINATION PIN PIN_NUMBER PIN DESTINATION //right matrix #include #include -#include +#include // ============ SPEED CONFIGURATION ============ ScanDelay scanDelay(9000); @@ -60,7 +60,7 @@ Port_MCP23018 portB(IOE_ADDR, 1, 0); Scanner_IOE scanner_R(LOW, portB, portA); // ================= RIGHT LED ================= -LED_Port LED_capsLck(portA, 1<<7); +LED_PortOpenDrain LED_capsLck(portA, 1<<7); // =================== CODES =================== Code_Sc s_a(KEY_A); diff --git a/src/LED_Port.h b/src/LED_Port.h index d1d49d5..cbf48f2 100644 --- a/src/LED_Port.h +++ b/src/LED_Port.h @@ -5,9 +5,12 @@ #include #include -/* An LED_Port object is an I/O expander pin that is connected to an LED indicator light. +/* An LED_Port object is an I/O expander output pin that is connected to an LED indicator light. LED_Port functions turn LED on and off. +This is for push-pull ouput pins. +For LEDs connected to open drain output types, use LED_Port class. + Example initialization: const uint8_t IOE_ADDR = 0x20; Port_MCP23S17 portA(IOE_ADDR, 0, 1<<0 | 1<<1 ); diff --git a/src/LED_PortOpenDrain.cpp b/src/LED_PortOpenDrain.cpp new file mode 100644 index 0000000..36a3abb --- /dev/null +++ b/src/LED_PortOpenDrain.cpp @@ -0,0 +1,12 @@ +#include "LED_PortOpenDrain.h" +/* functions are like LED_Port, but writeLow() writeHigh() are swapped. +*/ +void LED_PortOpenDrain::on() +{ + refPort.writeLow(pin); +} + +void LED_PortOpenDrain::off() +{ + refPort.writeHigh(pin); +} diff --git a/src/LED_PortOpenDrain.h b/src/LED_PortOpenDrain.h new file mode 100644 index 0000000..2887db5 --- /dev/null +++ b/src/LED_PortOpenDrain.h @@ -0,0 +1,36 @@ +#ifndef LED_PORT_H +#define LED_PORT_H +#include +#include +#include +#include + +/* An LED_PortOpenDrain object is an I/O expander ouput pin that is connected to an LED. +LED_PortOpenDrain functions turn LED on and off. + +This is for open drain ouput pins. +For LEDs connected to push-pull output types, use LED_Port class. + +Example initialization: + const uint8_t IOE_ADDR = 0x20; + Port_MCP23S17 portA(IOE_ADDR, 0, 1<<0 | 1<<1 ); + LED_PortOpenDrain LED_fn(portA, 1<<5); + +Example initialization: + Port_ShiftRegs shiftRegs(8); + LED_PortOpenDrain LED_fn(shiftRegs, 1<<6); + +*/ +class LED_PortOpenDrain : public LEDInterface +{ + private: + PortWriteInterface& refPort; + const uint8_t pin; //bit pattern, 1 is pin connected to LED + + public: + LED_PortOpenDrain(PortWriteInterface& refPort, const uint8_t pin) + : refPort(refPort), pin(pin) {} + virtual void on(); + virtual void off(); +}; +#endif