altera_up_ps2_mouse.c

来自「花了半个月才改好的Atera DE1/DE2 ps2 IP 驱动核。放在FPGA」· C语言 代码 · 共 35 行

C
35
字号
#include "altera_up_ps2_mouse.h"

int alt_up_ps2_mouse_reset(alt_up_ps2_dev *ps2)
{
	if (ps2->device_type != PS2_MOUSE)
		return -EINVAL;

	alt_u8 byte;

	//send the reset command
	int status = alt_up_ps2_write_data_byte_with_ack(ps2, MOUSE_RESET);
	if (status == 0) 
	{
		// get the ACK, now read the BAT result
		status = alt_up_ps2_read_data_byte(ps2, &byte);
		if ( status == 0 && byte == 0xAA) 
		{
			// BAT is passed, now get the device ID
			status = alt_up_ps2_read_data_byte(ps2, &byte); 
			// mouse should return 0x00 for device ID
			if ( byte == 0x00 )
				status = 0;
			else 
				status = -EIO;
		}
	}
	return status;
}

int alt_up_ps2_mouse_set_mode(alt_up_ps2_dev *ps2, alt_u8 byte)
{
	return alt_up_ps2_write_data_byte_with_ack(ps2, byte);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?