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