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_i( uint8_t column, uint8_t muxes, int16_t * buffer); // XXX Not currently used
int sampleColumn_k( uint8_t column, int16_t *buffer );
void setup_ADC( void );
void strobe_w(uint8_t strobe_num) {
- PORTC &= ~(D_MASK);
+ PORTC &= ~(C_MASK);
PORTD &= ~(D_MASK);
PORTE &= ~(E_MASK);
#ifdef SHORT_C
strobe_num = 15 - strobe_num;
#endif
+ /*
+ printHex( strobe_num );
+ print(" ");
+ strobe_num = 9 - strobe_num;
+ printHex( strobe_num );
+ print("\n");
+ */
switch(strobe_num) {
- case 0: PORTD |= (1 << 0); break;
- case 1: PORTD |= (1 << 1); break;
+ // XXX Kishsaver strobe (note that D0, D1 are not used)
case 2: PORTD |= (1 << 2); break;
case 3: PORTD |= (1 << 3); break;
case 4: PORTD |= (1 << 4); break;
case 5: PORTD |= (1 << 5); break;
+ // TODO REMOVEME
+ case 6: PORTD |= (1 << 6); break;
+ case 7: PORTD |= (1 << 7); break;
+ case 8: PORTE |= (1 << 0); break;
+ case 9: PORTE |= (1 << 1); break;
+ case 15: PORTC |= (1 << 5); break;
+/*
#ifdef ALL_D
case 6: PORTD |= (1 << 6); break;
#endif
#endif
#endif
+*/
default:
break;
}
-
+#if 0
int sampleColumn_i(uint8_t column, uint8_t muxes, int16_t * buffer) {
// ensure all probe lines are driven low, and chill for recovery delay.
_delay_us(RECOVERY_US);
recovery(0);
- uint8_t index = 0;
+ //uint8_t index = 0;
for (uint8_t i=0; i<8; ++i) {
if(muxes & (1 << i)) {
//uint16_t sample;
while (! (ADCSRA & (1 << ADIF))); // wait until ready.
- //sample = ADC; // 1st sample, icky.
- ADC; // 1st sample, icky. XXX Not sure if the compiler throws this away, but less compiler warnings -HaaTa
+ sample = ADC; // 1st sample, icky.
+ //ADC; // 1st sample, icky. XXX Not sure if the compiler throws this away, but less compiler warnings -HaaTa
strobe_w(column);
//recovery(0);
ADCSRA |= (1 << ADIF); // clear int flag by writing 1.
//wait for last read to complete.
while (! (ADCSRA & (1 << ADIF)));
- //sample = ADC; // throw away strobe'd value.
- ADC; // throw away strobe'd value.
+ sample = ADC; // throw away strobe'd value.
+ //ADC; // throw away strobe'd value.
#if 0
for (uint8_t i=0; i <= index; ++i) {
ADCSRA |= (1 << ADIF); // clear int flag by writing 1.
while (! (ADCSRA & (1 << ADIF)));
- //sample = ADC; // throw away warmup value.
- ADC; // throw away warmup value.
+ sample = ADC; // throw away warmup value.
+ //ADC; // throw away warmup value.
return 0;
}
+#endif
int sampleColumn_k(uint8_t column, int16_t * buffer) {
// ensure all probe lines are driven low, and chill for recovery delay.
- //uint16_t sample;
+ uint16_t sample;
ADCSRA |= (1 << ADEN) | (1 << ADSC); // enable and start conversions
ADCSRA |= (1 << ADIF); // clear int flag by writing 1.
// sync up with adc clock:
while (! (ADCSRA & (1 << ADIF))); // wait until ready.
- ADC; // throw it away. // XXX Not sure if the compiler throws this away, but less compiler warnings -HaaTa
- //sample = ADC; // throw it away.
+ //ADC; // throw it away. // XXX Not sure if the compiler throws this away, but less compiler warnings -HaaTa
+ sample = ADC; // throw it away.
for(uint8_t mux=0; mux < 8; ++mux) {
ADCSRA |= (1 << ADIF); // clear int flag by writing 1.
//wait for last read to complete.
while (! (ADCSRA & (1 << ADIF)));
- //sample = ADC; // throw away strobe'd value.
- ADC; // throw away strobe'd value.
+ sample = ADC; // throw away strobe'd value.
+ //ADC; // throw away strobe'd value.
}
recovery(0);
ADCSRA |= (1 << ADIF); // clear int flag by writing 1.
//wait for last read to complete.
while (! (ADCSRA & (1 << ADIF)));
- //sample = ADC; // throw away strobe'd value.
- ADC; // throw away strobe'd value.
+ sample = ADC; // throw away strobe'd value.
+ //ADC; // throw away strobe'd value.
ADCSRA |= (1 << ADIF); // clear int flag by writing 1.
while (! (ADCSRA & (1 << ADIF)));
rval = sampleColumn_k(column, samples+SAMPLE_OFFSET);
+ //for(uint8_t i=0; i<1; ++i) { // TODO REMOVEME
for(uint8_t i=0; i<8; ++i) {
if(samples[SAMPLE_OFFSET + i] - adc_mux_averages[i] > BUMP_THRESHOLD) {
// was a hump
void dumpkeys(void) {
//print(" \n");
if(error) {
+ if (count >= WARMUP_LOOPS && error) {
+ dump();
+ }
+
+ // Key scan debug
+ /*
for (uint8_t i=0; i < STROBE_LINES; ++i) {
printHex(usb_keymap[i]);
print(" ");
-
- //print(" ");
- }
- if (count >= WARMUP_LOOPS && error) {
- dump();
}
print(" : ");
printHex(error_data);
error_data = 0;
print(" : " NL);
+ */
}
// XXX Will be cleaned up eventually, but this will do for now :P -HaaTa
// Add to the Macro processing buffer
// Automatically handles converting to a USB code and sending off to the PC
- bufferAdd( key );
+ //bufferAdd( key );
- if(usb_dirty) {
+ if(usb_dirty)
+ {
+ /*
printHex( key );
print(" ");
+ */
}
}
}
}
- if(usb_dirty) print("\n");
+ //if(usb_dirty) print("\n");
usb_keyboard_send();
}
if(!dump_count) { // we don't want to debug-out during the measurements.
+ // Averages currently set per key
for(int i =0; i< KEY_COUNT; ++i) {
if(!(i & 0x0f)) {
print("\n");
print("\n");
+ // Previously read full ADC scans?
for(int i =0; i< KEY_COUNT; ++i) {
if(!(i & 0x0f)) {
print("\n");
}
}
-
- //}
-
+ // Per strobe information
// uint8_t cur_strober = 0xe;
uint8_t cur_strober = ze_strober;
print("\n");
printHex(cur_strober);
//print(": ");
- print(": ");
#if 1
- print("\n");
+ // Previously read ADC scans on current strobe
+ print(" :");
for (uint8_t i=0; i < MUXES_COUNT; ++i) {
print(" ");
printHex(full_samples[(cur_strober << MUXES_COUNT_XSHIFT) + i]);
}
- print("\n");
+ // Averages current set on current strobe
+ print(" :");
// printHex(threshold);
-// print(": ");
-
for (uint8_t i=0; i < MUXES_COUNT; ++i) {
print(" ");
printHex(keys_averages[(cur_strober << MUXES_COUNT_XSHIFT) + i]);
//printHex(full_av);
//printHex(count);
//print(" : ");
- print("\n");
+ print("\n ");
+ // Current keymap values
for (uint8_t i=0; i < STROBE_LINES; ++i) {
printHex(cur_keymap[i]);
print(" ");
//print(" ");
-
+ /* Already printing this above...
for (uint8_t i=0; i < MUXES_COUNT; ++i) {
print(" ");
//printHex(adc_mux_averages[i] + adc_strobe_averages[ze_strober] - full_av);
//printHex(keys_averages[(ze_strober << MUXES_COUNT_XSHIFT) + i] + (uint8_t)threshold);
printHex(keys_averages[(ze_strober << MUXES_COUNT_XSHIFT) + i]);
}
+ */
+ /* Being printed in dumpkeys()
if(error) {
print(" ");
printHex(error);
error_data = 0;
}
//print("\n");
+ */
ze_strober++;
ze_strober &= 0xf;
//printHex(ADCSRA);
//print(" ");
- //print("\n");
+ //print("\n");
}