教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 范文大全 > 公文资料 >

ARM9教程DSP教程FPGA教程CPLD教程42A软硬件设计0229

来源:网络收集 时间:2026-07-11
导读: ARM9教程DSP教程FPGA教程CPLD教程42A软硬件设计0229 ARM9教程DSP教程FPGA教程CPLD教程 42A多核软硬件系统设计 PS2 Keyboard Mouse Software 第一部分 原理图 1.1 PS2_keyboard_mouse.SchDoc ARM9教程DSP教程FPGA教程CPLD教程42A软硬件设计0229 1.2 PS2_Keybo

ARM9教程DSP教程FPGA教程CPLD教程42A软硬件设计0229

ARM9教程DSP教程FPGA教程CPLD教程 42A多核软硬件系统设计

PS2 Keyboard Mouse Software

第一部分 原理图

1.1 PS2_keyboard_mouse.SchDoc

ARM9教程DSP教程FPGA教程CPLD教程42A软硬件设计0229

1.2 PS2_Keyboard_Mouse_System. OpenBus

IO

MEM

XRAM

SOFT_TERMINAL

MOUSE

KEYBOARD

ARM9教程DSP教程FPGA教程CPLD教程42A软硬件设计0229

1.3 main.c

/***************************************************************************** |*

|* PS/2 Example |*

|* Keyboard functions:

|* - low level driver: scancodes

|* - device I/O (i.e. c library) interface: keyboard as stdin |*

|* Mouse functions: |* - polling mode

|* - streaming mode, with event callback |* |* NOTE:

|* Only one keyboard interface can be used. To test lower interface, |* unlink the context from the keyboard stack in the SwPlatform file and |* adjust the defines below.

\*****************************************************************************/

// choose one of the keyboard interfaces below and adjust the SwPlatform file accordingly #define USE_KEYBOARD_DEVIO 1 #define USE_PS2KB_DRIVER 0

#if ( USE_KEYBOARD_DEVIO == 1 ) // stdio.h is our interface #else

# include <drv_ps2kb.h> #endif

#include <stdio.h>

ARM9教程DSP教程FPGA教程CPLD教程42A软硬件设计0229

#include <timing.h> #include <drv_ps2mouse.h>

#include "devices.h"

// Save mouse packets

static ps2mouse_state_t mouse_state[100];

// Event synchronization

volatile uint8_t event_sync = 0;

// Event callback

static void mouse_event(ps2mouse_t *ps2mouse, ps2mouse_state_t *state, void *data) {

// Normally one would update program state here event_sync ^= 0x1; }

extern int main(void) {

#if ( USE_KEYBOARD_DEVIO == 1 ) // we use stdin #else

ps2kb_t *kbd; #endif

ps2mouse_t *mouse; ps2mouse_state_t state;

#if ( USE_KEYBOARD_DEVIO == 1 )

// In the SwPlatform file set the Posix name in the keyboard devio configuration to KEYBOARD_1 #else

ARM9教程DSP教程FPGA教程CPLD教程42A软硬件设计0229

// low level keyboard driver kbd = ps2kb_open(DRV_PS2KB_1); if (!kbd) {

return -1; } #endif

// mouse driver

mouse = ps2mouse_open(PS2MOUSE); if (!mouse) {

printf("Error opening mouse\n"); return -2; }

#if ( USE_KEYBOARD_DEVIO == 1 ) // Keyboard as stdin

printf("POSIX device I/O Example\n"); printf("- typing will print characters\n"); printf("- type 'q' to quit\n"); printf("Echo> ");

while (1) {

int ch = getchar();

if (ch != -1) {

putchar(ch); if (ch == 'q')

ARM9教程DSP教程FPGA教程CPLD教程42A软硬件设计0229

{

printf("\nFinished Keyboard Example\n\n"); break; } } } #else

// Low level keyboard example

printf("PS/2 Keyboard Driver Example\n"); printf("- typing will print scancodes\n"); printf("- type 'q' to quit\n"); printf("Scancodes:\n");

ps2kb_setleds(kbd, 0x0); // LED's off while (1) {

const uint8_t *scancode = ps2kb_get_scancode(kbd);

if (scancode[0] != 0) {

printf("0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",

scancode[0], scancode[1], scancode[2], scancode[3], scancode[4], scancode[5], scancode[6], scancode[7]); if (scancode[0] == 0x15) // 'q' {

printf("\nFinished Keyboard Example\n\n"); break; } } }

ps2kb_setleds(kbd, 0x7); // LED's on #endif

ARM9教程DSP教程FPGA教程CPLD教程42A软硬件设计0229

// PS/2 mouse in polling mode

printf("PS/2 Mouse Test 1: polling mode\n"); printf("- move the mouse or press a button\n");

ps2mouse_set_streaming(mouse, false); // set remote mode // collect packets

for (int i = 0; i < 100; i++) {

while (ps2mouse_get_state(mouse, &state) < 0) /**/;

mouse_state[i] = state; delay_ms(50); }

// print packets

for (int i = 0; i < 100; i++) {

ps2mouse_state_t *state = &mouse_state[i]; printf("(x, y) buttons = (%d, %d) 0x%x\n", state->xmov, state->ymov, state->buttons); }

printf("\nFinished Mouse Test 1!\n\n");

// PS/2 mouse in streaming mode with event callback printf("PS/2 Mouse Test 2: event callback\n"); printf("- move the mouse or press a button\n");

ps2mouse_install_callback(mouse, mouse_event, &state, NULL); ps2mouse_set_streaming(mouse, true); // set streaming mode // collect packets

for (int i = 0; i < 100; i++)

ARM9教程DSP教程FPGA教程CPLD教程42A软硬件设计0229

{

uint8_t x = event_sync;

while (x == event_sync) /* wait for event */;

mouse_state[i] = state; }

ps2mouse_set_streaming(mouse, false); // stop interrupts // print packets

for (int i = 0; i < 100; i++) {

ps2mouse_state_t *state = &mouse_state[i]; printf("(x, y) buttons = (%d, %d) 0x%x\n", state->xmov, state->ymov, state->buttons); }

printf("\n\nFinished Mouse Test 2!\n\n");

printf("Finished all tests.\n"); return 0; }

ARM9教程DSP教程FPGA教程CPLD教程42A软硬件设计0229

1.4 PS2_keyboard_mouse. SwPlatform

…… 此处隐藏:2400字,全部文档内容请下载后查看。喜欢就下载吧 ……
ARM9教程DSP教程FPGA教程CPLD教程42A软硬件设计0229.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/fanwen/708315.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)