From b5a3d68008bf64fe99e9b2ca4a7dd34984f5ca2c Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Thu, 2 Mar 2017 08:18:07 +0100 Subject: [PATCH] Size optimizations --- LcdShiftReg.cpp | 38 ++++++++++++++++++++++++-------------- LcdShiftReg.h | 12 +++++++----- MyLcd.cpp | 34 +++++++++++----------------------- MyLcd.h | 4 +++- 4 files changed, 45 insertions(+), 43 deletions(-) diff --git a/LcdShiftReg.cpp b/LcdShiftReg.cpp index 817ac44..1fd2153 100644 --- a/LcdShiftReg.cpp +++ b/LcdShiftReg.cpp @@ -7,29 +7,39 @@ LcdShiftReg::LcdShiftReg() DDRA |= (1 << PA0) | (1 << PA1) | (1 << PA2); } -void LcdShiftReg::setPin(volatile uint8_t *port, uint8_t pin, bool value) const +void LcdShiftReg::setPin(volatile uint8_t *port, uint8_t pin) const { - if (value == true) - { - *port |= (1 << pin); - } - else - { - *port &= ~(1 << pin); - } + *port |= (1 << pin); +} + +void LcdShiftReg::clearPin(volatile uint8_t *port, uint8_t pin) const +{ + *port &= ~(1 << pin); } void LcdShiftReg::setSerialPin(bool value) { - setPin(&PORTA, PA2, value); + if (value == true) + { + setPin(&PORTA, PA2); + } + else + { + clearPin(&PORTA, PA2); + } } -void LcdShiftReg::setShiftPin(bool value) +void LcdShiftReg::pulseShiftPin() { - setPin(&PORTA, PA0, value); + clearPin(&PORTA, PA0); + setPin(&PORTA, PA0); + clearPin(&PORTA, PA0); } -void LcdShiftReg::setStoragePin(bool value) +void LcdShiftReg::pulseStoragePin() { - setPin(&PORTA, PA1, value); + clearPin(&PORTA, PA1); + setPin(&PORTA, PA1); + clearPin(&PORTA, PA1); } + diff --git a/LcdShiftReg.h b/LcdShiftReg.h index ecbff6f..e9a2604 100644 --- a/LcdShiftReg.h +++ b/LcdShiftReg.h @@ -4,13 +4,15 @@ class LcdShiftReg : public ShiftRegister { - public: +public: LcdShiftReg(); - private: - void setPin(volatile uint8_t *port, uint8_t pin, bool value) const; +private: + void setPin(volatile uint8_t *port, uint8_t pin) const; + void clearPin(volatile uint8_t *port, uint8_t pin) const; virtual void setSerialPin(bool value) override; - virtual void setShiftPin(bool value) override; - virtual void setStoragePin(bool value) override; + + virtual void pulseShiftPin() override; + virtual void pulseStoragePin() override; }; \ No newline at end of file diff --git a/MyLcd.cpp b/MyLcd.cpp index f1f5652..f5f1e1f 100644 --- a/MyLcd.cpp +++ b/MyLcd.cpp @@ -1,37 +1,25 @@ #include "MyLcd.h" #include "Hardware.h" -void MyLcd::execute(const Command &cmd, bool RS, double delay) +void MyLcd::execute(uint8_t data, bool RS) { static const uint8_t eMask = 0b00000010; static const uint8_t rsMask = 0b01000000; - //static const double pulseLength = 0.5; + if (RS) { - uint8_t output = (cmd.data & 0xf0) >> 2; - if (RS) - { - output |= rsMask; - } - - m_lcdShiftReg.set(output | eMask); - //delay_us(pulseLength); - m_lcdShiftReg.set(output); + data |= rsMask; } - { - uint8_t output = (cmd.data & 0x0f) << 2; - if (RS) - { - output |= rsMask; - } + m_lcdShiftReg.set(data | eMask); + m_lcdShiftReg.set(data); +} - m_lcdShiftReg.set(output | eMask); - //delay_us(pulseLength); - m_lcdShiftReg.set(output); - } - - delay_ms(delay); +void MyLcd::execute(const Command &cmd, bool RS, uint16_t delay) +{ + execute((cmd.data & 0xf0) >> 2, RS); + execute((cmd.data & 0x0f) << 2, RS); + delay_us(delay); } diff --git a/MyLcd.h b/MyLcd.h index cc338d5..bff18d5 100644 --- a/MyLcd.h +++ b/MyLcd.h @@ -9,5 +9,7 @@ private: LcdShiftReg m_lcdShiftReg; private: - virtual void execute(const Command &cmd, bool RS, double delay) override; + void execute(uint8_t data, bool RS); + + virtual void execute(const Command &cmd, bool RS, uint16_t delay_us) override; };