# HG changeset patch # User Jacob Alexander # Date 1384643449 18000 # Node ID 5be3b6745311a9dffa5a3e17d73a6fe45ec013f0 # Parent 74745739c96a28c070c8afb034bed157fae01055 Cap sense now functional! Alpha begins :D diff -r 74745739c96a -r 5be3b6745311 Scan/avr-capsense/scan_loop.c --- a/Scan/avr-capsense/scan_loop.c Wed Nov 13 23:47:36 2013 -0500 +++ b/Scan/avr-capsense/scan_loop.c Sat Nov 16 18:10:49 2013 -0500 @@ -123,6 +123,7 @@ #define SAMPLE_CONTROL 3 +//#define DEFAULT_KEY_BASE 0xc8 #define DEFAULT_KEY_BASE 0x95 #define KEY_COUNT ((STROBE_LINES) * (MUXES_COUNT)) @@ -242,7 +243,9 @@ uint8_t unstable; uint8_t usb_dirty; -uint16_t threshold = THRESHOLD; +uint16_t threshold = 0x25; // HaaTa Hack -TODO +//uint16_t threshold = 0x16; // HaaTa Hack -TODO +//uint16_t threshold = THRESHOLD; uint16_t tests = 0; uint8_t col_a=0; @@ -267,9 +270,9 @@ uint16_t idle_count=0; uint8_t idle = 1; -/*volatile*/ uint16_t count = 0; +uint16_t count = 0; -/*volatile*/ uint8_t error = 0; +uint8_t error = 0; uint16_t error_data = 0; @@ -293,9 +296,7 @@ void recovery( uint8_t on ); -int sampleColumn ( uint8_t column ); -//int sampleColumn_i( uint8_t column, uint8_t muxes, int16_t * buffer); // XXX Not currently used -int sampleColumn_k( uint8_t column, int16_t *buffer ); +int sampleColumn( uint8_t column ); void setup_ADC( void ); @@ -313,14 +314,6 @@ // TODO dfj code...needs cleanup + commenting... setup_ADC(); - // Configure timer 0 to generate a timer overflow interrupt every - // 256*1024 clock cycles, or approx 61 Hz when using 16 MHz clock - // This demonstrates how to use interrupts to implement a simple - // inactivity timeout. - //TCCR0A = 0x00; - //TCCR0B = 0x05; - //TIMSK0 = (1<= WARMUP_LOOPS) ) { + if( column != cur_keymap[strober] && (boot_count >= WARMUP_LOOPS) ) { tests++; -#if 0 - tries = 1; - while (tries++ && sampleColumn(strober)) { tries &= 0x7; } - col_a = testColumn(strober); - - tries = 1; - while (tries++ && sampleColumn(strober)) { tries &= 0x7; } - col_b = testColumn(strober); - - tries = 1; - while (tries++ && sampleColumn(strober)) { tries &= 0x7; } - col_c = testColumn(strober); - - if( (col_a == col_b) && (col_b == col_c) && (cur_keymap[strober] != col_a) ) { - cur_keymap[strober] = col_a; - usb_dirty = 1; - } -#else cur_keymap[strober] = column; usb_dirty = 1; -#endif } idle |= usb_dirty; // if any keys have changed inc. released, then we are not idle. @@ -500,7 +475,7 @@ boot_count++; } else { // count >= WARMUP_LOOPS if (usb_dirty) { - for (int i=0; i> 1) > (db_threshold = threshold) + (db_delta = delta)) { + + if ((db_sample = samples[SAMPLE_OFFSET + i] >> 1) > (db_threshold = threshold) + (db_delta = delta)) + { column |= bit; } + +#ifdef THRESHOLD_VERIFICATION + if ( db_sample > 0xA0 ) + { + printHex( db_sample ); + print(" : "); + printHex( db_threshold ); + print(" : "); + printHex( db_delta ); + print(" :: "); + printHex( column ); + print(" : "); + printHex( strobe ); + print(NL); + } +#endif + bit <<= 1; } return column; @@ -1038,10 +1050,8 @@ if(usb_dirty) { - /* printHex( key ); - print(" "); - */ + print("\n"); } } } @@ -1053,7 +1063,7 @@ void dump(void) { -#define DEBUG_FULL_SAMPLES_AVERAGES +//#define DEBUG_FULL_SAMPLES_AVERAGES #ifdef DEBUG_FULL_SAMPLES_AVERAGES if(!dump_count) { // we don't want to debug-out during the measurements. @@ -1107,6 +1117,7 @@ #endif +//#define DEBUG_DELTA_SAMPLE_THRESHOLD #ifdef DEBUG_DELTA_SAMPLE_THRESHOLD print("\n"); //uint16_t db_delta = 0; @@ -1121,7 +1132,7 @@ printHex( column ); #endif -#define DEBUG_USB_KEYMAP +//#define DEBUG_USB_KEYMAP #ifdef DEBUG_USB_KEYMAP print("\n ");