Android深度探索第七章

來源:互聯網
上載者:User

標籤:

控制發光二極體

建立LED驅動的裝置檔案

1.使用cdev_init函數初始化cdev

cdev結構體

struct cdev{

  struct kobject kobj;

  struct module *owner;

  const struct file_operations *ops;

  struct list_head list;

  dev_t dev;

  unsigned int count;

}

2.指定裝置號

  直接在代碼中指定:使用MKDEV宏將主次裝置號組合成裝置號,使用MAJOR和MINOR宏從裝置號中擷取主次裝置號

  動態分配:alloc_chrdev_region函數

3.使用cdev_add函數將字元裝置添加到核心中的字元裝置數組中

  指定裝置檔案指標,裝置號和裝置檔案數量。調用cdev_add函數

4.使用class_creat宏建立struct class

5.使用device_creat函數建立裝置檔案

卸載LED驅動的裝置檔案

  依次調用device_destroy,class_destroy和unregister_chrdev_region方法

設定寄存器與初始化LED驅動

控制LED

  1、通過字串控制LED    2、通過I/O命令控制LED

Android深度探索第七章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.