Linux內核 GPIO操作部分API


內核中關於GPIO的操作API主要集中在<linux/of_gpio.h>和<linux/gpio.h>中,前者主要是GPIO直接與設備樹相關的操作,在Linux 設備樹操作API中已經記錄過,后者主要是針對GPIO本身的操作,常用的有下面幾個。

//linux/gpio.h
/**
 * gpio_request_one - request a single GPIO with initial configuration
 * @gpio:       the GPIO number
 * @flags:      GPIO configuration as specified by GPIOF_*
 * @label:      a literal description string of this GPIO
 */
int gpio_request_one(unsigned gpio, unsigned long flags, const char *label)

/* 判斷gpio是否有效 */
bool gpio_is_valid(int number)

/**
 * 功能:設置指定gpio的工作模式為輸入模式
 * @gpio - 編號(要找的是那個cell)
 * 失敗:負數,絕對值錯誤碼,成功:0
 */
int gpio_direction_input(unsigned gpio)

/**
 * 功能:設置指定gpio的工作模式為輸出模式
 * gpio - 編號(要找的是那個cell)
 * 失敗:負數,絕對值錯誤碼,成功:0
 */
int gpio_direction_output(unsigned gpio, int value)

/* 設置GPIO的值 */
void gpio_set_value(unsigned gpio, int value)

/* 獲取GPIO的值 */
int gpio_get_value(unsigned gpio)

/* 申請軟中斷到GPIO引腳 */
int gpio_to_irq(unsigned int gpio)

/* 釋放GPIO */
gpio_free(unsigned gpio)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM