看板 LinuxDev 關於我們 聯絡資訊
雖然我問過相關的問題,不過遇到瓶頸只好再問詳細點 我寫了一個module想用rpi的gpio控制一個含3個LED的小電路 /dev 下也有LED_0 LED_1 LED_2 我希望一般user可以寫入這三個file(用0或1)去控制LED的開關 程式碼如下: https://gist.github.com/gnitnaw/b116f358fa688897fe00 之前不管是用一般user還是root都不能改變/dev/LED_(0,1,2) 改掉一些bug以後,用root可以control了,一般user還是不行 (寫到現在還沒開始ioctl...唉...我的學習速度真慢) 之後可能在kernel學習過程中會有更多問題要上來請教,希望不會違反板規 然後我也會回饋自己所學(拙作請勿見怪)。 我寫了個小程式嘗試去write /dev/LDE_0 : int main(void) { char path[PATH_SIZE], buf[BUF_SIZE]; int i = 0, fd = 0; snprintf(path, sizeof(path), "/dev/LED_0"); fd = open(path, O_WRONLY); if (fd < 0) { perror("Error opening GPIO pin"); exit(EXIT_FAILURE); } printf("Set GPIO pins to output, logic level :\n"); strncpy(buf, "1", 1); buf[1] = '\0'; if (write(fd, buf, sizeof(buf)) < 0) { perror("write, set pin output"); exit(EXIT_FAILURE); } return EXIT_SUCCESS; } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 90.41.242.229 ※ 文章網址: https://www.ptt.cc/bbs/LinuxDev/M.1434447670.A.3A4.html
alongalone: write的時候沒有error 發生嗎? 06/16 18:00
wtchen: 不能直接用echo嗎? 06/16 18:37
wtchen: echo得到的訊息是沒有權限 06/16 18:37
alongalone: 我覺得你要不要先把tasklet那段code拿掉 06/16 22:23
alongalone: 先看會不會亮;另外你能確定gpio跟led是連結正確的嗎 06/16 22:25
抱歉,我把code改了,現在root可以work,但是一般user不行 ※ 編輯: wtchen (90.41.242.229), 06/16/2015 23:00:47
leolarrel: 有檢查/dev/LED_0的檔案權限嗎?看來是檔案權限沒打開 06/17 08:56
wtchen: 對,權限沒打開沒錯,請問是要手動打開嗎? 06/17 15:52
wtchen: 設成666? 06/17 15:52
leolarrel: 設成666應該可以 06/17 18:18
wtchen: 成功了,多謝 06/17 20:39