前言
前面我們直接在開發(fā)板上安裝了GCC等開發(fā)環(huán)境,可以直接在板上進行開發(fā)。
剛好手里有個USB的游戲手柄,我們就來編寫代碼讀取手柄按鍵,體驗下板上直接C開發(fā)。
輸入設(shè)備
插入USB手柄,可以看到多了/dev/input文件夾,多了event0設(shè)備
代碼
vi key.c添加如下代碼
1. /* 單獨測試:#define KEY_TEST 1
1. * 作為接口:#define KEY_TEST 0
1. * 編譯 aarch64-linux-gnu-gcc key.c -o key -lpthread
1. * 運行 chmod +x key
1. * ./key /dev/input/event8
1. */
1.
1. #include< stdint.h >
1. #include< stdio.h >
1. #include< stdlib.h >
1. #include< string.h >
1. #include< unistd.h >
1.
1. #include< pthread.h >
1.
1. #include < linux/input.h >
1. #include < sys/types.h >
1. #include < sys/stat.h >
1. #include < fcntl.h >
1.
1. #define KEY_TEST 1
1.
1. int s_keys_fd = -1;
1. uint32_t s_keys_state = 0;
1.
1.
1. void key_setstate(int code , int vaule, uint32_t* key)
1. {
1. if(vaule == 0)
1. {
1. switch(code)
1. {
1. case 296:
1. *key &= ~(1u< 3);
1. break;
1. case 297:
1. *key &= ~(1u< 4);
1. break;
1. case 288:
1. *key &= ~(1u< 5);
1. break;
1. case 289:
1. *key &= ~(1u< 8);
1. break;
1. case 290:
1. *key &= ~(1u< 6);
1. break;
1. case 291:
1. *key &= ~(1u< 7);
1. break;
1. case 292:
1. *key &= ~(1u< 1);
1. break;
1. case 294:
1. *key &= ~(1u< 2);
1. break;
1. default:
1. break;
1. }
1. }
1. else
1. {
1. switch(code)
1. {
1. case 296:
1. *key |= (1u< 3);
1. break;
1. case 297:
1. *key |= (1u< 4);
1. break;
1. case 288:
1. *key |= (1u< 5);
1. break;
1. case 289:
1. *key |= (1u< 8);
1. break;
1. case 290:
1. *key |= (1u< 6);
1. break;
1. case 291:
1. *key |= (1u< 7);
1. break;
1. case 292:
1. *key |= (1u< 1);
1. break;
1. case 294:
1. *key |= (1u< 2);
1. break;
1. default:
1. break;
1. }
1. }
1. }
1.
1. /*
1. * SELECT 296 SELECT 3
1. * START 297 START 4
1. * UP 288 右上 5
1. * RIGHT 289 右右 8
1. * DOWN 290 右下 6
1. * LEFT 291 右左 7
1. * A 292 左前上 1
1. * B 294 左前下 2
1. */
1. int key_getstate(int key)
1. {
1. if(s_keys_state & (1u<
編譯
gcc key.c -o key
測試
按不同的按鍵,打印如下
總結(jié)
可以看到直接在板上開發(fā)非常方便,免去了交叉編譯的繁瑣。
審核編輯:湯梓紅
-
計算機
+關(guān)注
關(guān)注
19文章
7607瀏覽量
89823 -
編程
+關(guān)注
關(guān)注
88文章
3673瀏覽量
94692 -
開發(fā)板
+關(guān)注
關(guān)注
25文章
5389瀏覽量
100891 -
交叉編譯
+關(guān)注
關(guān)注
0文章
32瀏覽量
12802 -
單板計算機
+關(guān)注
關(guān)注
0文章
82瀏覽量
15863 -
RISC-V
+關(guān)注
關(guān)注
46文章
2461瀏覽量
48006 -
RISC-V處理器
+關(guān)注
關(guān)注
0文章
80瀏覽量
10258
發(fā)布評論請先 登錄
相關(guān)推薦
昉·星光單板計算機正式發(fā)售,加速RISC-V生態(tài)發(fā)展

【昉·星光 2 高性能RISC-V單板計算機體驗】VisionFive2開箱+安裝Ubuntu
賽昉科技昉·星光RISC-V單板計算機首發(fā)試用
【RISC-V專題】賽昉科技昉·星光RISC-V單板計算機首發(fā)試用
RISC-V VisionFive (昉星光單板計算機)系列課程
【RISC-V專題】昉·星光 2(VisionFive 2)RISC-V單板計算機免費試用
【昉·星光 2 高性能RISC-V單板計算機體驗】2更換Debian操作系統(tǒng)
【RISC-V + OpenCV 計算機視覺】用 VisionFive 2 昉·星光 2 進行物體識別
【昉·星光 2(VisionFive 2)RISC-V單板計算機】根目錄擴容-愉快的install大型軟件
昉·星光2 RISC-V單板計算機體驗(二) - 系統(tǒng)環(huán)境

評論