Add keyboard patch from Andrew Warkentin <andreww591 gmail com>

Tue, 01 Mar 2011 21:33:32 +0000

author
Philip Pemberton <philpem@philpem.me.uk>
date
Tue, 01 Mar 2011 21:33:32 +0000
changeset 96
45ae4c97155b
parent 95
6e01339b218d
child 97
240e195e4bed

Add keyboard patch from Andrew Warkentin <andreww591 gmail com>

I fixed the keyboard in FreeBee. I looked at the keyboard driver source available on a few sites, and it appears that BEGKBD/KEY_BEGIN_KEYBOARD is only supposed to be sent after the end of mouse data, and that KLAST/KEY_LIST_END is not a separate code, but a flag that is set on the last non-KALLUP/KEY_ALL_UP code in a list. I have attached a patch that implements these changes. I have also attached a patch that adds the 60Hz timer interrupt (I'm not sure if it's totally correct, though, since the cursor blinks rather slowly).

Received-From: Andrew Warkentin <andreww591 gmail com>
Signed-Off-By: Philip Pemberton <philpem@philpem.me.uk>

src/keyboard.c file | annotate | diff | revisions
     1.1 diff -r 6e01339b218d -r 45ae4c97155b src/keyboard.c
     1.2 --- a/src/keyboard.c	Thu Feb 10 01:09:42 2011 +0000
     1.3 +++ b/src/keyboard.c	Tue Mar 01 21:33:32 2011 +0000
     1.4 @@ -204,7 +204,6 @@
     1.5  		}
     1.6  	}
     1.7  }
     1.8 -
     1.9  void keyboard_scan(KEYBOARD_STATE *ks)
    1.10  {
    1.11  	int nkeys = 0;
    1.12 @@ -212,26 +211,30 @@
    1.13  	// Skip doing the scan if the keyboard hasn't changed state
    1.14  	if (!ks->update_flag) return;
    1.15  
    1.16 +
    1.17  	// if buffer empty, do a keyboard scan
    1.18  	if (ks->buflen == 0) {
    1.19 +		size_t last_writep;
    1.20  		// Keyboard Data Begins Here (BEGKBD)
    1.21 -		ks->buffer[ks->writep] = KEY_BEGIN_KEYBOARD;
    1.22 -		ks->writep = (ks->writep + 1) % KEYBOARD_BUFFER_SIZE;
    1.23 -		if (ks->buflen < KEYBOARD_BUFFER_SIZE) ks->buflen++;
    1.24 +		//ks->buffer[ks->writep] = KEY_BEGIN_KEYBOARD;
    1.25 +		//ks->writep = (ks->writep + 1) % KEYBOARD_BUFFER_SIZE;
    1.26 +		//if (ks->buflen < KEYBOARD_BUFFER_SIZE) ks->buflen++;
    1.27  
    1.28  		for (int i=0; i<(sizeof(ks->keystate)/sizeof(ks->keystate[0])); i++) {
    1.29  			if (ks->keystate[i]) {
    1.30  				printf("\tKBC KEY DOWN: %d\n", i);
    1.31  				ks->buffer[ks->writep] = i;
    1.32 +				last_writep = ks->writep;
    1.33  				ks->writep = (ks->writep + 1) % KEYBOARD_BUFFER_SIZE;
    1.34  				if (ks->buflen < KEYBOARD_BUFFER_SIZE) ks->buflen++;
    1.35  				nkeys++;
    1.36  			}
    1.37  		}
    1.38 -
    1.39 -		// If no keys down, then send All Keys Up byte
    1.40 -		if (nkeys == 0) {
    1.41 -				printf("\tKBC ALL KEYS UP\n");
    1.42 +		if (nkeys) {
    1.43 +			ks->buffer[ks->writep - 1] |= 0x80;
    1.44 +		}else{
    1.45 +			// If no keys down, then send All Keys Up byte
    1.46 +			printf("\tKBC ALL KEYS UP\n");
    1.47  			ks->buffer[ks->writep] = KEY_ALL_UP;
    1.48  			ks->writep = (ks->writep + 1) % KEYBOARD_BUFFER_SIZE;
    1.49  			if (ks->buflen < KEYBOARD_BUFFER_SIZE) ks->buflen++;
    1.50 @@ -239,10 +242,6 @@
    1.51  
    1.52  		// TODO: inject "mouse data follows" chunk header and mouse movement info
    1.53  
    1.54 -		// Last Entry In List
    1.55 -//		ks->buffer[ks->writep] = KEY_LIST_END;
    1.56 -//		ks->writep = (ks->writep + 1) % KEYBOARD_BUFFER_SIZE;
    1.57 -//		if (ks->buflen < KEYBOARD_BUFFER_SIZE) ks->buflen++;
    1.58  	}
    1.59  
    1.60  	// Clear the update flag
    1.61 @@ -288,6 +287,7 @@
    1.62  		uint8_t x = ks->buffer[ks->readp];
    1.63  		ks->readp = (ks->readp + 1) % KEYBOARD_BUFFER_SIZE;
    1.64  		if (ks->buflen > 0) ks->buflen--;
    1.65 +		//printf("\tKBC DBG: rxd=%02X\n", x);
    1.66  		return x;
    1.67  	}
    1.68  }