Simplify SoftwareSerial::write
Before, there was nearly identical code for the inverted and regular cases. However, simply inverting the byte in the inverted case allows using the regular code twice, reducing the generated code size by 100 bytes (on an Arduino Uno and gcc 4.3, on gcc 4.8 the reduction is 50 bytes).
This commit is contained in:
parent
cf0cc48d9a
commit
ddcdc901a7
|
@ -486,21 +486,8 @@ size_t SoftwareSerial::write(uint8_t b)
|
||||||
|
|
||||||
// Write each of the 8 bits
|
// Write each of the 8 bits
|
||||||
if (_inverse_logic)
|
if (_inverse_logic)
|
||||||
{
|
b = ~b;
|
||||||
for (byte mask = 0x01; mask; mask <<= 1)
|
|
||||||
{
|
|
||||||
if (b & mask) // choose bit
|
|
||||||
tx_pin_write(LOW); // send 1
|
|
||||||
else
|
|
||||||
tx_pin_write(HIGH); // send 0
|
|
||||||
|
|
||||||
tunedDelay(_tx_delay);
|
|
||||||
}
|
|
||||||
|
|
||||||
tx_pin_write(LOW); // restore pin to natural state
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (byte mask = 0x01; mask; mask <<= 1)
|
for (byte mask = 0x01; mask; mask <<= 1)
|
||||||
{
|
{
|
||||||
if (b & mask) // choose bit
|
if (b & mask) // choose bit
|
||||||
|
@ -511,8 +498,8 @@ size_t SoftwareSerial::write(uint8_t b)
|
||||||
tunedDelay(_tx_delay);
|
tunedDelay(_tx_delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
tx_pin_write(HIGH); // restore pin to natural state
|
// restore pin to natural state
|
||||||
}
|
tx_pin_write(_inverse_logic ? LOW : HIGH);
|
||||||
|
|
||||||
SREG = oldSREG; // turn interrupts back on
|
SREG = oldSREG; // turn interrupts back on
|
||||||
tunedDelay(_tx_delay);
|
tunedDelay(_tx_delay);
|
||||||
|
|
Loading…
Reference in New Issue