save a few bytes

This commit is contained in:
Vic 2021-01-07 17:33:57 +01:00
parent 828f6444fb
commit a3b77fa7ab
1 changed files with 6 additions and 9 deletions

View File

@ -102,7 +102,7 @@ void bs814_read(void) { // Poll touch keys
bool bitval; bool bitval;
// generate clock signal & sample frame // generate clock signal & sample frame
for (bitp = 0; bitp < 2 * BS814_KEYS_MAX - 1; ++bitp) { for (bitp = 0; bitp < 2 * BS814_KEYS_MAX; ++bitp) {
digitalWrite(Pin(GPIO_BS814_CLK), LOW); digitalWrite(Pin(GPIO_BS814_CLK), LOW);
os_delay_us(BS814_PULSE); os_delay_us(BS814_PULSE);
digitalWrite(Pin(GPIO_BS814_CLK), HIGH); digitalWrite(Pin(GPIO_BS814_CLK), HIGH);
@ -113,16 +113,13 @@ void bs814_read(void) { // Poll touch keys
} }
#endif // DEBUG_BS814_DRIVER #endif // DEBUG_BS814_DRIVER
frame |= (bitval << bitp); frame |= (bitval << bitp);
if (bitp < 2 * BS814_KEYS_MAX - 1) { // stop bit
if (bitp < BS814_KEYS_MAX) { if (bitp < BS814_KEYS_MAX) {
checksum += bitval; checksum += bitval; // checksum key bits
} }
os_delay_us(BS814_PULSE); os_delay_us(BS814_PULSE);
} }
digitalWrite(Pin(GPIO_BS814_CLK), LOW); }
os_delay_us(BS814_PULSE);
digitalWrite(Pin(GPIO_BS814_CLK), HIGH);
bitval = digitalRead(Pin(GPIO_BS814_DAT));
frame |= (bitval << bitp);
// validate frame // validate frame
if (BS814_KEYS_MAX - checksum != ((frame >> 4) & 0x7)) { // checksum error if (BS814_KEYS_MAX - checksum != ((frame >> 4) & 0x7)) { // checksum error
#ifdef DEBUG_BS814_DRIVER #ifdef DEBUG_BS814_DRIVER