Size optimizations

This commit is contained in:
mandlm 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);
} }
else
void LcdShiftReg::clearPin(volatile uint8_t *port, uint8_t pin) const
{ {
*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

@ -8,9 +8,11 @@ class LcdShiftReg : public ShiftRegister
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;
{
uint8_t output = (cmd.data & 0xf0) >> 2;
if (RS) if (RS)
{ {
output |= rsMask; data |= rsMask;
} }
m_lcdShiftReg.set(output | eMask); m_lcdShiftReg.set(data | eMask);
//delay_us(pulseLength); m_lcdShiftReg.set(data);
m_lcdShiftReg.set(output);
} }
void MyLcd::execute(const Command &cmd, bool RS, uint16_t delay)
{ {
uint8_t output = (cmd.data & 0x0f) << 2; execute((cmd.data & 0xf0) >> 2, RS);
if (RS) execute((cmd.data & 0x0f) << 2, RS);
{ delay_us(delay);
output |= rsMask;
}
m_lcdShiftReg.set(output | eMask);
//delay_us(pulseLength);
m_lcdShiftReg.set(output);
}
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;
}; };