Size optimizations

This commit is contained in:
Michael Mandl 2017-03-02 08:18:07 +01:00
parent f7393f0661
commit b5a3d68008
4 changed files with 45 additions and 43 deletions

View file

@ -7,29 +7,39 @@ LcdShiftReg::LcdShiftReg()
DDRA |= (1 << PA0) | (1 << PA1) | (1 << PA2); 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);
{ }
*port |= (1 << pin);
} void LcdShiftReg::clearPin(volatile uint8_t *port, uint8_t pin) const
else {
{ *port &= ~(1 << pin);
*port &= ~(1 << pin);
}
} }
void LcdShiftReg::setSerialPin(bool value) 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);
} }

View file

@ -4,13 +4,15 @@
class LcdShiftReg : public ShiftRegister class LcdShiftReg : public ShiftRegister
{ {
public: public:
LcdShiftReg(); LcdShiftReg();
private: private:
void setPin(volatile uint8_t *port, uint8_t pin, bool value) const; 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 setSerialPin(bool value) override;
virtual void setShiftPin(bool value) override;
virtual void setStoragePin(bool value) override; virtual void pulseShiftPin() override;
virtual void pulseStoragePin() override;
}; };

View file

@ -1,37 +1,25 @@
#include "MyLcd.h" #include "MyLcd.h"
#include "Hardware.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 eMask = 0b00000010;
static const uint8_t rsMask = 0b01000000; static const uint8_t rsMask = 0b01000000;
//static const double pulseLength = 0.5;
if (RS)
{ {
uint8_t output = (cmd.data & 0xf0) >> 2; data |= rsMask;
if (RS)
{
output |= rsMask;
}
m_lcdShiftReg.set(output | eMask);
//delay_us(pulseLength);
m_lcdShiftReg.set(output);
} }
{ m_lcdShiftReg.set(data | eMask);
uint8_t output = (cmd.data & 0x0f) << 2; m_lcdShiftReg.set(data);
if (RS) }
{
output |= rsMask;
}
m_lcdShiftReg.set(output | eMask); void MyLcd::execute(const Command &cmd, bool RS, uint16_t delay)
//delay_us(pulseLength); {
m_lcdShiftReg.set(output); execute((cmd.data & 0xf0) >> 2, RS);
} execute((cmd.data & 0x0f) << 2, RS);
delay_us(delay);
delay_ms(delay);
} }

View file

@ -9,5 +9,7 @@ private:
LcdShiftReg m_lcdShiftReg; LcdShiftReg m_lcdShiftReg;
private: 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;
}; };