From a09fbc1f988371b2ffd75bcc1f0c753999b4e66d Mon Sep 17 00:00:00 2001 From: BayCom GmbH Date: Thu, 9 Jul 2015 11:26:18 +0200 Subject: [PATCH] Add some customization methods to make the library usable for other pin assignments --- sblib/inc/sblib/eib/bcu.h | 48 +++++++++++++++++++++++++++++++++++++++ sblib/inc/sblib/serial.h | 12 ++++++++++ sblib/src/eib/bcu.cpp | 5 ++-- sblib/src/serial.cpp | 10 ++++++++ 4 files changed, 73 insertions(+), 2 deletions(-) diff --git a/sblib/inc/sblib/eib/bcu.h b/sblib/inc/sblib/eib/bcu.h index 95dd5879..c7b338dc 100644 --- a/sblib/inc/sblib/eib/bcu.h +++ b/sblib/inc/sblib/eib/bcu.h @@ -51,6 +51,48 @@ class BCU */ void begin(int manufacturer, int deviceType, int version); + /** + * Set RxPin of board, must be called before begin method + * @param rxPin pin definition + */ + void setRxPin(int rxPin) { + bus.rxPin=rxPin; + } + /** + * Set TxPin of board, must be called before begin method + * @param txPin pin definition + */ + void setTxPin(int txPin) { + bus.txPin=txPin; + } + /** + * Set timer class, must be called before begin method + * @param timer + */ + void setTimer(Timer& timer) { + bus.timer=timer; + } + /** + * Set capture channel of processor, must be called before begin method + * @param capture channel definition of processor + */ + void setCaptureChannel(TimerCapture captureChannel) { + bus.captureChannel=captureChannel; + } + /** + * Set ProgPin of board, must be called before begin method + * @param progPin Pin definition + */ + void setProgPin(int prgPin) { + progPin=prgPin; + } + /** + * Set ProgPin output inverted, must be called before begin method + * @param progPin output inverted + */ + void setProgPinInverted(int prgPinInv) { + progPinInv=prgPinInv; + } /** * End using the EIB bus coupling unit. */ @@ -125,6 +167,12 @@ class BCU */ int progPin; + /** + * Programming LED output inverted: If set to 1 the programming LED output is + * being inverted + */ + int progPinInv; + protected: /** * Process a unicast connection control telegram with our physical address as diff --git a/sblib/inc/sblib/serial.h b/sblib/inc/sblib/serial.h index be5a10da..502a6d6a 100644 --- a/sblib/inc/sblib/serial.h +++ b/sblib/inc/sblib/serial.h @@ -70,6 +70,18 @@ class Serial: public BufferedStream */ Serial(int rxPin, int txPin); + /** + * Set rx pin for serial communication. + * + * @param rxPin - the pin to use for RXD: PIO1_6, PIO2_7, PIO3_1, or PIO3_4 + */ + void setRxPin(int rxPin); + /** + * Set tx pin for serial communication. + * + * @param txPin - the pin to use for TXD: PIO1_7, PIO2_8, PIO3_0, or PIO3_5 + */ + void setTxPin(int txPin); /** * Begin using the serial port with the specified baud rate and 8 data bits, * no parity bit, and 1 stop bit (SERIAL_8N1). diff --git a/sblib/src/eib/bcu.cpp b/sblib/src/eib/bcu.cpp index 2899f808..fd7bfaf4 100644 --- a/sblib/src/eib/bcu.cpp +++ b/sblib/src/eib/bcu.cpp @@ -46,6 +46,7 @@ BCU::BCU() :progButtonDebouncer() { progPin = DEFAULT_PROG_PIN; + progPinInv = true; enabled = false; } @@ -164,14 +165,14 @@ void BCU::loop() if (bcu.progPin) { // Detect the falling edge of pressing the prog button - pinMode(bcu.progPin, INPUT); + pinMode(bcu.progPin, INPUT|PULL_UP); int oldValue = progButtonDebouncer.value(); if (!progButtonDebouncer.debounce(digitalRead(bcu.progPin), 50) && oldValue) { userRam.status ^= 0x81; // toggle programming mode and checksum bit } pinMode(bcu.progPin, OUTPUT); - digitalWrite(bcu.progPin, !(userRam.status & BCU_STATUS_PROG)); + digitalWrite(bcu.progPin, (userRam.status & BCU_STATUS_PROG)^progPinInv); } if (userEeprom.isModified() && bus.idle() && bus.telegramLen == 0 && connectedAddr == 0) diff --git a/sblib/src/serial.cpp b/sblib/src/serial.cpp index 385d1c51..49cdffb4 100644 --- a/sblib/src/serial.cpp +++ b/sblib/src/serial.cpp @@ -47,8 +47,18 @@ Serial::Serial(int rxPin, int txPin) +{ + setRxPin(rxPin); + setTxPin(txPin); +} + +void Serial::setRxPin(int rxPin) { pinMode(rxPin, SERIAL_RXD); +} + +void Serial::setTxPin(int txPin) +{ pinMode(txPin, SERIAL_TXD); }