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);
}
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);
}

View File

@ -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;
};

View File

@ -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);
}

View File

@ -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;
};