+ info_print("Attempting to synchronize the keyboard, do not press any keys...");
+ errorLED( 1 );
+
+ // Do a proper keyboard reset (flushes the ripple counters)
+ RESET_PORT |= (1 << RESET_PIN);
+ _delay_us(10);
+ RESET_PORT &= ~(1 << RESET_PIN);
+
+ // Delay main keyboard scanning, until the bit counter is synchronized
+ uint8_t synchronized = 0;
+ while ( !synchronized )
+ {
+ // Read on each falling edge/after the falling edge of the clock
+ if ( !currentWaveDone )
+ {
+ // Read the current data value
+ if ( DATA_OUT & (1 << DATA_PIN) )
+ {
+ // Check if synchronized
+ // There are 128 positions to scan for with the HP150 keyboard protocol
+ if ( positionCounter == 128 )
+ synchronized = 1;
+
+ positionCounter = 0;
+ }
+
+ // Wait until the next falling clock edge for the next DATA scan
+ currentWaveDone++;
+ }
+ }
+
+ info_print("Keyboard Synchronized!");