1 /* Copyright (C) 2011-2013 by Joseph Makuch
2 * Additions by Jacob Alexander (2013)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 3.0 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
18 // ----- Includes -----
21 #include <Lib/ScanLib.h>
28 #include "scan_loop.h"
32 // ----- Defines -----
34 // TODO dfj defines...needs commenting and maybe some cleaning...
35 #define MAX_PRESS_DELTA_MV 470
36 #define THRESHOLD_MV (MAX_PRESS_DELTA_MV >> 1)
37 //(2560 / (0x3ff/2)) ~= 5
41 #define THRESHOLD (THRESHOLD_MV / MV_PER_ADC)
43 #define BUMP_DETECTION 0
44 #define BUMP_THRESHOLD 0x50
45 #define BUMP_REST_US 1200
47 #define STROBE_SETTLE 1
50 #define TEST_KEY_STROBE (0x05)
51 #define TEST_KEY_MASK (1 << 0)
55 #define RIGHT_JUSTIFY 0
56 #define LEFT_JUSTIFY (0xff)
58 // set left or right justification here:
59 #define JUSTIFY_ADC RIGHT_JUSTIFY
60 #define ADLAR_MASK (1 << ADLAR)
63 #define ADLAR_BITS ((ADLAR_MASK) & (JUSTIFY_ADC))
64 #else // defaults to right justification.
69 #define FULL_MUX_MASK ((1 << MUX0) | (1 << MUX1) | (1 << MUX2) | (1 << MUX3) | (1 << MUX4))
71 // F0-f7 pins only muxmask.
72 #define MUX_MASK ((1 << MUX0) | (1 << MUX1) | (1 << MUX2))
79 // set ADC clock prescale
80 #define PRESCALE_MASK ((1 << ADPS0) | (1 << ADPS1) | (1 << ADPS2))
81 #define PRESCALE_SHIFT (ADPS0)
84 // TODO Remove this define when unnecessary -HaaTa
85 #define STROBE_LINES 16
88 #define MUXES_COUNT_XSHIFT 3
90 #define WARMUP_LOOPS ( 1024 )
91 #define WARMUP_STOP (WARMUP_LOOPS - 1)
94 #define SAMPLE_OFFSET ((SAMPLES) - MUXES_COUNT)
95 #define SAMPLE_CONTROL 3
97 // TODO Figure out calculation or best way to determine at startup -HaaTa
98 //#define DEFAULT_KEY_BASE 0xc8
99 #define DEFAULT_KEY_BASE 0x95
101 #define KEY_COUNT ((STROBE_LINES) * (MUXES_COUNT))
103 #define RECOVERY_CONTROL 1
104 #define RECOVERY_SOURCE 0
105 #define RECOVERY_SINK 2
110 // mix in 1/4 of the current average to the running average. -> (@mux_mix = 2)
113 #define IDLE_COUNT_MASK 0xff
114 #define IDLE_COUNT_SHIFT 8
116 // av = (av << shift) - av + sample; av >>= shift
117 // e.g. 1 -> (av + sample) / 2 simple average of new and old
118 // 2 -> (3 * av + sample) / 4 i.e. 3:1 mix of old to new.
119 // 3 -> (7 * av + sample) / 8 i.e. 7:1 mix of old to new.
120 #define KEYS_AVERAGES_MIX_SHIFT 3
124 // ----- Macros -----
126 // Make sure we haven't overflowed the buffer
127 #define bufferAdd(byte) \
128 if ( KeyIndex_BufferUsed < KEYBOARD_BUFFER ) \
129 KeyIndex_Buffer[KeyIndex_BufferUsed++] = byte
132 #define SET_FULL_MUX(X) ((ADMUX) = (((ADMUX) & ~(FULL_MUX_MASK)) | ((X) & (FULL_MUX_MASK))))
136 // ----- Variables -----
138 // Buffer used to inform the macro processing module which keys have been detected as pressed
139 volatile uint8_t KeyIndex_Buffer[KEYBOARD_BUFFER];
140 volatile uint8_t KeyIndex_BufferUsed;
143 // TODO dfj variables...needs cleaning up and commenting
144 volatile uint16_t full_av = 0;
146 uint8_t ze_strober = 0;
148 uint16_t samples [SAMPLES];
150 uint16_t adc_mux_averages [MUXES_COUNT];
151 uint16_t adc_strobe_averages[STROBE_LINES];
153 uint8_t cur_keymap[STROBE_LINES];
155 uint8_t keymap_change;
157 uint16_t threshold = 0x25; // HaaTa Hack -TODO
158 //uint16_t threshold = 0x16; // HaaTa Hack -TODO
159 //uint16_t threshold = THRESHOLD;
163 uint16_t keys_averages_acc[KEY_COUNT];
164 uint16_t keys_averages[KEY_COUNT];
166 uint8_t full_samples[KEY_COUNT];
168 // TODO: change this to 'booting', then count down.
169 uint16_t boot_count = 0;
171 uint16_t idle_count = 0;
175 uint16_t error_data = 0;
177 uint16_t mux_averages[MUXES_COUNT];
178 uint16_t strobe_averages[STROBE_LINES];
180 uint8_t dump_count = 0;
182 uint16_t db_delta = 0;
183 uint8_t db_sample = 0;
184 uint16_t db_threshold = 0;
188 // ----- Function Declarations -----
192 void recovery( uint8_t on );
194 int sampleColumn( uint8_t column );
196 void setup_ADC( void );
198 void strobe_w( uint8_t strobe_num );
200 uint8_t testColumn( uint8_t strobe );
204 // ----- Functions -----
206 // Initial setup for cap sense controller
207 inline void scan_setup()
209 // TODO dfj code...needs cleanup + commenting...
220 // TODO all this code should probably be in scan_resetKeyboard
221 for (int i=0; i < STROBE_LINES; ++i) {
225 for(int i=0; i < MUXES_COUNT; ++i) {
226 adc_mux_averages[i] = 0x20; // experimentally determined.
228 for(int i=0; i < STROBE_LINES; ++i) {
229 adc_strobe_averages[i] = 0x20; // yup.
232 for(int i=0; i < KEY_COUNT; ++i) {
233 keys_averages[i] = DEFAULT_KEY_BASE;
234 keys_averages_acc[i] = (DEFAULT_KEY_BASE);
237 /** warm things up a bit before we start collecting data, taking real samples. */
238 for(uint8_t i = 0; i < STROBE_LINES; ++i) {
243 // Reset the keyboard before scanning, we might be in a wierd state
244 // Also sets the KeyIndex_BufferUsed to 0
245 scan_resetKeyboard();
249 // Main Detection Loop
250 // This is where the important stuff happens
251 inline uint8_t scan_loop()
253 // TODO dfj code...needs commenting + cleanup...
255 uint32_t full_av_acc = 0;
257 for (strober = 0; strober < STROBE_LINES; ++strober)
261 while ( tries++ && sampleColumn( strober ) ) { tries &= 0x7; } // don't waste this one just because the last one was poop.
262 column = testColumn(strober);
264 idle |= column; // if column has any pressed keys, then we are not idle.
266 if( column != cur_keymap[strober] && ( boot_count >= WARMUP_LOOPS ) )
268 cur_keymap[strober] = column;
271 // The keypresses on this strobe are now know, send them right away
272 for ( uint8_t mux = 0; mux < MUXES_COUNT; ++mux )
274 if ( column & (1 << mux) )
276 uint8_t key = (strober << MUXES_COUNT_XSHIFT) + mux;
278 // Add to the Macro processing buffer
279 // Automatically handles converting to a USB code and sending off to the PC
288 idle |= keymap_change; // if any keys have changed inc. released, then we are not idle.
292 error_data |= (((uint16_t)strober) << 12);
295 uint8_t strobe_line = strober << MUXES_COUNT_XSHIFT;
296 for ( int i = 0; i < MUXES_COUNT; ++i )
298 // discard sketchy low bit, and meaningless high bits.
299 uint8_t sample = samples[SAMPLE_OFFSET + i] >> 1;
300 full_samples[strobe_line + i] = sample;
301 keys_averages_acc[strobe_line + i] += sample;
304 strobe_averages[strober] = 0;
305 for ( uint8_t i = SAMPLE_OFFSET; i < ( SAMPLE_OFFSET + MUXES_COUNT ); ++i )
307 full_av_acc += (samples[i]);
308 #ifdef COLLECT_STROBE_AVERAGES
309 mux_averages[i - SAMPLE_OFFSET] += samples[i];
310 strobe_averages[strober] += samples[i];
314 #ifdef COLLECT_STROBE_AVERAGES
315 adc_strobe_averages[strober] += strobe_averages[strober] >> 3;
316 adc_strobe_averages[strober] >>= 1;
318 /** test if we went negative. */
319 if ( ( adc_strobe_averages[strober] & 0xFF00 ) && ( boot_count >= WARMUP_LOOPS ) )
321 error = 0xf; error_data = adc_strobe_averages[strober];
326 #ifdef VERIFY_TEST_PAD
327 // verify test key is not down.
328 if ( ( cur_keymap[TEST_KEY_STROBE] & TEST_KEY_MASK ) )
331 error_data = cur_keymap[TEST_KEY_STROBE] << 8;
332 error_data += full_samples[TEST_KEY_STROBE * 8];
337 #ifdef COLLECT_STROBE_AVERAGES
338 // calc mux averages.
339 if ( boot_count < WARMUP_LOOPS )
341 full_av += (full_av_acc >> (7));
345 for ( int i = 0; i < MUXES_COUNT; ++i )
347 adc_mux_averages[i] = (adc_mux_averages[i] << MUX_MIX) - adc_mux_averages[i];
348 adc_mux_averages[i] += (mux_averages[i] >> 4);
349 adc_mux_averages[i] >>= MUX_MIX;
356 /** aggregate if booting, or if idle;
357 * else, if not booting, check for dirty USB.
361 idle_count &= IDLE_COUNT_MASK;
363 // Warm up voltage references
364 if ( boot_count < WARMUP_LOOPS )
368 switch ( boot_count )
372 // Show msg at first iteration only
373 info_msg("Warming up the voltage references");
385 info_msg("Warmup finished using ");
386 printInt16( WARMUP_LOOPS );
387 print(" iterations\n");
393 // Reset accumulators and idle flag/counter
396 for ( uint8_t c = 0; c < KEY_COUNT; ++c ) { keys_averages_acc[c] = 0; }
408 for ( uint8_t i = 0; i < KEY_COUNT; ++i )
410 uint16_t acc = keys_averages_acc[i] >> IDLE_COUNT_SHIFT;
411 uint32_t av = keys_averages[i];
413 av = (av << KEYS_AVERAGES_MIX_SHIFT) - av + acc;
414 av >>= KEYS_AVERAGES_MIX_SHIFT;
416 keys_averages[i] = av;
417 keys_averages_acc[i] = 0;
421 if ( boot_count >= WARMUP_LOOPS )
426 sampleColumn(0x0); // to resync us if we dumped a mess 'o text.
431 // Error case, should not occur in normal operation
434 erro_msg("Problem detected... ");
437 for ( uint8_t i = 0; i < STROBE_LINES; ++i )
439 printHex(cur_keymap[i]);
447 printHex(error_data);
450 // Display keymaps and other debug information if warmup completede
451 if ( boot_count >= WARMUP_LOOPS )
458 // Return non-zero if macro and USB processing should be delayed
459 // Macro processing will always run if returning 0
460 // USB processing only happens once the USB send timer expires, if it has not, scan_loop will be called
461 // after the macro processing has been completed
467 void scan_resetKeyboard( void )
469 // Empty buffer, now that keyboard has been reset
470 KeyIndex_BufferUsed = 0;
474 // Send data to keyboard
475 // NOTE: Only used for converters, since the scan module shouldn't handle sending data in a controller
476 uint8_t scan_sendData( uint8_t dataPayload )
482 // Reset/Hold keyboard
483 // NOTE: Only used for converters, not needed for full controllers
484 void scan_lockKeyboard( void )
488 // NOTE: Only used for converters, not needed for full controllers
489 void scan_unlockKeyboard( void )
494 // Signal KeyIndex_Buffer that it has been properly read
495 // NOTE: Only really required for implementing "tricks" in converters for odd protocols
496 void scan_finishedWithBuffer( uint8_t sentKeys )
498 // Convenient place to clear the KeyIndex_Buffer
499 KeyIndex_BufferUsed = 0;
504 // Signal KeyIndex_Buffer that it has been properly read and sent out by the USB module
505 // NOTE: Only really required for implementing "tricks" in converters for odd protocols
506 void scan_finishedWithUSBBuffer( uint8_t sentKeys )
512 void _delay_loop( uint8_t __count )
525 // disable adc digital pins.
526 DIDR1 |= (1 << AIN0D) | (1<<AIN1D); // set disable on pins 1,0.
529 uint8_t mux = 0 & 0x1f; // 0 == first. // 0x1e = 1.1V ref.
531 // 0 = external aref 1,1 = 2.56V internal ref
532 uint8_t aref = ((1 << REFS1) | (1 << REFS0)) & ((1 << REFS1) | (1 << REFS0));
533 uint8_t adate = (1 << ADATE) & (1 << ADATE); // trigger enable
534 uint8_t trig = 0 & ((1 << ADTS0) | (1 << ADTS1) | (1 << ADTS2)); // 0 = free running
535 // ps2, ps1 := /64 ( 2^6 ) ps2 := /16 (2^4), ps1 := 4, ps0 :=2, PS1,PS0 := 8 (2^8)
536 uint8_t prescale = ( ((PRESCALE) << PRESCALE_SHIFT) & PRESCALE_MASK ); // 001 == 2^1 == 2
537 uint8_t hispeed = (1 << ADHSM);
538 uint8_t en_mux = (1 << ACME);
540 ADCSRA = (1 << ADEN) | prescale; // ADC enable
543 //ADMUX |= ((1 << REFS1) | (1 << REFS0)); // 2.56 V internal.
544 //ADMUX |= ((1 << REFS0) ); // Vcc with external cap.
545 //ADMUX &= ~((1 << REFS1) | (1 << REFS0)); // 0,0 : aref.
546 ADMUX = aref | mux | ADLAR_BITS;
549 ADCSRA |= adate; // trigger enable
550 ADCSRB = en_mux | hispeed | trig | (ADCSRB & ~((1 << ADTS0) | (1 << ADTS1) | (1 << ADTS2))); // trigger select free running
552 ADCSRA |= (1 << ADEN); // ADC enable
553 ADCSRA |= (1 << ADSC); // start conversions q
557 void recovery( uint8_t on )
559 DDRB |= (1 << RECOVERY_CONTROL);
560 PORTB &= ~(1 << RECOVERY_SINK); // SINK always zero
561 DDRB &= ~(1 << RECOVERY_SOURCE); // SOURCE high imp
565 // set strobes to sink to gnd.
574 DDRB |= (1 << RECOVERY_SINK); // SINK pull
575 PORTB |= (1 << RECOVERY_CONTROL);
576 PORTB |= (1 << RECOVERY_SOURCE); // SOURCE high
577 DDRB |= (1 << RECOVERY_SOURCE);
581 PORTB &= ~(1 << RECOVERY_CONTROL);
582 DDRB &= ~(1 << RECOVERY_SOURCE);
583 PORTB &= ~(1 << RECOVERY_SOURCE); // SOURCE low
584 DDRB &= ~(1 << RECOVERY_SINK); // SINK high-imp
589 void hold_sample( uint8_t on )
593 PORTB |= (1 << SAMPLE_CONTROL);
594 DDRB |= (1 << SAMPLE_CONTROL);
598 DDRB |= (1 << SAMPLE_CONTROL);
599 PORTB &= ~(1 << SAMPLE_CONTROL);
604 void strobe_w( uint8_t strobe_num )
611 //strobe_num = 15 - strobe_num;
614 printHex( strobe_num );
616 strobe_num = 9 - strobe_num;
617 printHex( strobe_num );
623 // XXX Kishsaver strobe (note that D0, D1 are not used)
624 case 0: PORTD |= (1 << 0); break;
625 case 1: PORTD |= (1 << 1); break;
626 case 2: PORTD |= (1 << 2); break;
627 case 3: PORTD |= (1 << 3); break;
628 case 4: PORTD |= (1 << 4); break;
629 case 5: PORTD |= (1 << 5); break;
632 case 6: PORTD |= (1 << 6); break;
633 case 7: PORTD |= (1 << 7); break;
634 case 8: PORTE |= (1 << 0); break;
635 case 9: PORTE |= (1 << 1); break;
636 //case 15: PORTC |= (1 << 5); break; // Test strobe on kishsaver
639 // XXX Kishsaver strobe (note that D0, D1 are not used)
640 case 0: PORTD |= (1 << 2); break;
641 case 1: PORTD |= (1 << 3); break;
642 case 2: PORTD |= (1 << 4); break;
643 case 3: PORTD |= (1 << 5); break;
646 case 4: PORTD |= (1 << 6); break;
647 case 5: PORTD |= (1 << 7); break;
648 case 6: PORTE |= (1 << 0); break;
649 case 7: PORTE |= (1 << 1); break;
650 case 15: PORTC |= (1 << 5); break; // Test strobe on kishsaver
655 case 6: PORTD |= (1 << 6); break;
656 case 7: PORTD |= (1 << 7); break;
658 case 8: PORTC |= (1 << 0); break;
659 case 9: PORTC |= (1 << 1); break;
660 case 10: PORTC |= (1 << 2); break;
661 case 11: PORTC |= (1 << 3); break;
662 case 12: PORTC |= (1 << 4); break;
663 case 13: PORTC |= (1 << 5); break;
664 case 14: PORTC |= (1 << 6); break;
665 case 15: PORTC |= (1 << 7); break;
667 case 16: PORTE |= (1 << 0); break;
668 case 17: PORTE |= (1 << 1); break;
673 case 6: PORTE |= (1 << 0); break;
674 case 7: PORTE |= (1 << 1); break;
676 case 8: PORTC |= (1 << 0); break;
677 case 9: PORTC |= (1 << 1); break;
678 case 10: PORTC |= (1 << 2); break;
679 case 11: PORTC |= (1 << 3); break;
680 case 12: PORTC |= (1 << 4); break;
681 case 13: PORTC |= (1 << 5); break;
682 case 14: PORTC |= (1 << 6); break;
683 case 15: PORTC |= (1 << 7); break;
688 case 6: PORTD |= (1 << 6); break;
689 case 7: PORTD |= (1 << 7); break;
691 case 8: PORTE |= (1 << 0); break;
692 case 9: PORTE |= (1 << 1); break;
694 case 10: PORTC |= (1 << 0); break;
695 case 11: PORTC |= (1 << 1); break;
696 case 12: PORTC |= (1 << 2); break;
697 case 13: PORTC |= (1 << 3); break;
698 case 14: PORTC |= (1 << 4); break;
699 case 15: PORTC |= (1 << 5); break;
701 case 16: PORTC |= (1 << 6); break;
702 case 17: PORTC |= (1 << 7); break;
714 #if 0 // New code from dfj -> still needs redoing for kishsaver and autodetection of strobes
716 strobe_num = 15 - strobe_num;
719 #ifdef SINGLE_COLUMN_TEST
725 case 0: PORTD |= (1 << 0); DDRD &= ~(1 << 0); break;
726 case 1: PORTD |= (1 << 1); DDRD &= ~(1 << 1); break;
727 case 2: PORTD |= (1 << 2); DDRD &= ~(1 << 2); break;
728 case 3: PORTD |= (1 << 3); DDRD &= ~(1 << 3); break;
729 case 4: PORTD |= (1 << 4); DDRD &= ~(1 << 4); break;
730 case 5: PORTD |= (1 << 5); DDRD &= ~(1 << 5); break;
734 case 6: PORTD |= (1 << 6); break;
735 case 7: PORTD |= (1 << 7); break;
737 case 8: PORTC |= (1 << 0); break;
738 case 9: PORTC |= (1 << 1); break;
739 case 10: PORTC |= (1 << 2); break;
740 case 11: PORTC |= (1 << 3); break;
741 case 12: PORTC |= (1 << 4); break;
742 case 13: PORTC |= (1 << 5); break;
743 case 14: PORTC |= (1 << 6); break;
744 case 15: PORTC |= (1 << 7); break;
746 case 16: PORTE |= (1 << 0); break;
747 case 17: PORTE |= (1 << 1); break;
752 case 6: PORTE |= (1 << 0); break;
753 case 7: PORTE |= (1 << 1); break;
755 case 8: PORTC |= (1 << 0); break;
756 case 9: PORTC |= (1 << 1); break;
757 case 10: PORTC |= (1 << 2); break;
758 case 11: PORTC |= (1 << 3); break;
759 case 12: PORTC |= (1 << 4); break;
760 case 13: PORTC |= (1 << 5); break;
761 case 14: PORTC |= (1 << 6); break;
762 case 15: PORTC |= (1 << 7); break;
767 case 6: PORTD |= (1 << 6); DDRD &= ~(1 << 6); break;
768 case 7: PORTD |= (1 << 7); DDRD &= ~(1 << 7); break;
770 case 8: PORTE |= (1 << 0); DDRE &= ~(1 << 0); break;
771 case 9: PORTE |= (1 << 1); DDRE &= ~(1 << 1); break;
773 case 10: PORTC |= (1 << 0); DDRC &= ~(1 << 0); break;
774 case 11: PORTC |= (1 << 1); DDRC &= ~(1 << 1); break;
775 case 12: PORTC |= (1 << 2); DDRC &= ~(1 << 2); break;
776 case 13: PORTC |= (1 << 3); DDRC &= ~(1 << 3); break;
777 case 14: PORTC |= (1 << 4); DDRC &= ~(1 << 4); break;
778 case 15: PORTC |= (1 << 5); DDRC &= ~(1 << 5); break;
780 case 16: PORTC |= (1 << 6); DDRC &= ~(1 << 6); break;
781 case 17: PORTC |= (1 << 7); DDRC &= ~(1 << 7); break;
797 inline uint16_t getADC(void)
799 ADCSRA |= (1 << ADIF); // clear int flag by writing 1.
801 //wait for last read to complete.
802 while ( !( ADCSRA & (1 << ADIF) ) );
804 return ADC; // return sample
808 int sampleColumn_8x( uint8_t column, uint16_t * buffer )
810 // ensure all probe lines are driven low, and chill for recovery delay.
811 ADCSRA |= (1 << ADEN) | (1 << ADSC); // enable and start conversions
826 for ( uint8_t i = 0; i < STROBE_SETTLE; ++i ) { getADC(); }
833 for ( uint8_t mux = 0; mux < 8; ++mux )
835 SET_FULL_MUX(mux); // our sample will use this
837 // wait for mux to settle.
838 for ( uint8_t i = 0; i < MUX_SETTLE; ++i ) { getADC(); }
840 // retrieve current read.
841 buffer[mux] = getADC();
846 getADC(); // throw away; unknown mux.
848 SET_FULL_MUX(mux + 1); // our *next* sample will use this
850 // retrieve current read.
851 buffer[mux] = getADC();
861 ADCSRA &= ~(1 << ADEN);
863 // pull all columns' strobe-lines low.
876 int sampleColumn( uint8_t column )
880 rval = sampleColumn_8x( column, samples + SAMPLE_OFFSET );
883 for ( uint8_t i = 0; i < 8; ++i )
885 if ( samples[SAMPLE_OFFSET + i] - adc_mux_averages[i] > BUMP_THRESHOLD )
888 _delay_us(BUMP_REST_US);
891 error_data = samples[SAMPLE_OFFSET +i]; // | ((uint16_t)i << 8);
901 uint8_t testColumn( uint8_t strobe )
905 for ( uint8_t i = 0; i < MUXES_COUNT; ++i )
907 uint16_t delta = keys_averages[(strobe << MUXES_COUNT_XSHIFT) + i];
909 if ( (db_sample = samples[SAMPLE_OFFSET + i] >> 1) > (db_threshold = threshold) + (db_delta = delta) )
914 #ifdef THRESHOLD_VERIFICATION
915 if ( db_sample > 0xA0 )
917 printHex( db_sample );
919 printHex( db_threshold );
921 printHex( db_delta );
938 #ifdef DEBUG_FULL_SAMPLES_AVERAGES
939 // we don't want to debug-out during the measurements.
942 // Averages currently set per key
943 for ( int i = 0; i < KEY_COUNT; ++i )
949 else if ( !(i & 0x07) )
955 printHex( keys_averages[i] );
960 // Previously read full ADC scans?
961 for ( int i = 0; i< KEY_COUNT; ++i)
967 else if ( !(i & 0x07) )
973 printHex(full_samples[i]);
978 #ifdef DEBUG_STROBE_SAMPLES_AVERAGES
979 // Per strobe information
980 uint8_t cur_strober = ze_strober;
983 printHex(cur_strober);
985 // Previously read ADC scans on current strobe
987 for ( uint8_t i = 0; i < MUXES_COUNT; ++i )
990 printHex(full_samples[(cur_strober << MUXES_COUNT_XSHIFT) + i]);
993 // Averages current set on current strobe
996 for ( uint8_t i = 0; i < MUXES_COUNT; ++i )
999 printHex(keys_averages[(cur_strober << MUXES_COUNT_XSHIFT) + i]);
1004 #ifdef DEBUG_DELTA_SAMPLE_THRESHOLD
1006 printHex( db_delta );
1008 printHex( db_sample );
1010 printHex( db_threshold );
1015 #ifdef DEBUG_USB_KEYMAP
1018 // Current keymap values
1019 for ( uint8_t i = 0; i < STROBE_LINES; ++i )
1021 printHex(cur_keymap[i]);