* optimisation: -C3 compiler flag for optimised size

* bugfix: correct order of setting `DDRn` and `PORTn`
* optimisation: `enum` and `static const` instead of macros
* optimisation: `PT6302_startup` is now `inline`
* optimisation: functions are now static
* bugfix: `data` is now rotated and stored instead of just rotating
* special thanks to @kissadamfkut for pointing all of this out to me
This commit is contained in:
2022-03-02 23:47:26 +01:00
parent 69c4eb43e0
commit 60a7b1309e
4 changed files with 60 additions and 55 deletions

View File

@@ -5,42 +5,3 @@
#include <util/delay.h>
#include "PT6302.h"
void PT6302_startup (void)
{
PORTB |= (CSBpin | CLKBpin);
PORTB &= ~DINpin;
PORTC |= RSTpin;
DDRB |= (CSBpin | CLKBpin | DINpin);
DDRC |= RSTpin;
_delay_us (TPRZ);
PORTC &= ~RSTpin;
_delay_us (TWRSTB);
};
void transmit_bytes (const uint8_t *payload, const uint8_t size)
{
PORTB &= ~CSBpin;
for (int i = 0; i < size; ++i)
{
uint8_t data = payload[i];
for (int j = 0; j < 8; ++j)
{
PORTB &= ~CLKBpin;
if ((data & 0x01) == 0)
{
PORTB |= DINpin;
}
else
{
PORTB &= ~DINpin;
}
_delay_us (TCW);
PORTB |= CLKBpin;
_delay_us (TCW);
data >> 1;
}
_delay_us (TDOFF);
}
_delay_us (DTCSH);
PORTB |= CSBpin;
}