[OHSW.org] Nachtrag zum U-Boot 'systest keyboard'

Dr. H. Nikolaus Schaller hns at goldelico.com
Mon Dec 3 17:17:59 CET 2012


Wir waren schon auf dem richtigen Weg. Man muß dem Controller
noch sagen, welche Pins als Keypad-Matrix oder GPIO laufen
sollen. Und der Default ist GPIO. D.h. man muß die Matrix setzen-

Dann ist warten auf Interrupt und Keycode auslesen kein Problem.

Allerdings scheint meine Hardware nicht gut zu funktionieren. Es
gehen nur einzelne Tasten.

Grüße,
Nikolaus

PS: hier der Code (ist auch schon im git):

#define TCA8418_BUS (2-1)	// I2C1=0, I2C2=1, I2C3=2
#define TCA8418_ADDRESS 0x34

int keytest(void)
{
	unsigned char byte;
	printf("testing TCA8418 keyboard\n");
	if(i2c_set_bus_num(TCA8418_BUS))
		{
		printf ("could not select I2C%d\n", TCA8418_BUS+1);
		return 1;
		}
	
	if(i2c_probe(TCA8418_ADDRESS))
		{
		printf ("could not probe TCA8418 at 0x%02x\n", TCA8418_ADDRESS);
		return 1;		
		}
	
	byte = 0x01;
	i2c_write(TCA8418_ADDRESS, 0x01, 1, &byte, 1);	// enable keyboard IRQ
	byte = 0xff;
	i2c_write(TCA8418_ADDRESS, 0x1d, 1, &byte, 1);	// enable all lines as KP matrix
	i2c_write(TCA8418_ADDRESS, 0x1e, 1, &byte, 1);	// enable all lines as KP matrix
	i2c_write(TCA8418_ADDRESS, 0x1f, 1, &byte, 1);	// enable all lines as KP matrix
		
	while (!tstc())
		{
		int keyint=(status_get_buttons() & (1<<5)) != 0;	// get_button() knows how to read the KEYIRQ
#if 1
		if(!keyint)
		   continue;	// wait for key interrupt
#endif
		i2c_read(TCA8418_ADDRESS, 0x02, 1, &byte, 1);	// read int-status register
#if 0
		printf("keyint=%d intstat=%02x\r", keyint, byte);
#endif
		if(byte&1)
			{ // read matrix
			int i;
			unsigned char events;
			i2c_read(TCA8418_ADDRESS, 0x03, 1, &events, 1);	// read number of events in FIFO
			events &= 0x0f;	// up to 10
			for(i=0; i < events; i++)
				{
				i2c_read(TCA8418_ADDRESS, 0x04, 1, &byte, 1);	// read keypad event as often as there is an event
				if(byte & 0x80)
					printf("press   %2d\n", byte&0x7f);
				else
					printf("release %2d\n", byte&0x7f);
				}
			byte=0x01;
			i2c_write(TCA8418_ADDRESS, 0x02, 1, &byte, 1);	// write int-status register to reset keypad int
			}
		}
	if(tstc())
		getc();
	printf("\n");
	return 0;
}



More information about the Open-hard-software-event mailing list