GPIO全稱是General Purpose Input/Output,其關聯SOC上的一個管腳。平臺會分配相應的GPIO和外設關聯,諸如audio codec外設,GPIO和平臺強相關。
GPIO可由平臺配置輸入輸出,輸出即可寫,高電平為1,低電平為0。輸入即可讀,除了讀入數據外,輸入還能作為中斷信號。
二、GPIO標識GPIO標識有效范圍在0..MAX_INT,負數代表該平臺不支持(可用作初始化)。
平臺定義了它們如何使用這些接口,并且通常為每個GPIO線使用#define宏定義符號,以便單板的啟動代碼與相關設計直接保持一致。與此相反,驅動應該只使用從setup代碼傳遞給他們的GPIO號碼,使用platform_data來保存單板特定的管腳配置數據(與其它所需的單板特定數據一起)。這避免了移植問題。
諸如一個平臺使用32-159,另一個平臺使用0-64。
int gpio_is_valid(int number);
可用此函數判斷此gpio線是否有效。
三、GPIO使用/* request GPIO, returning 0 or negative errno. * non-null labels may be useful for diagnostics. */ int gpio_request(unsigned gpio, const char *label); /* release PReviously-claimed GPIO */ void gpio_free(unsigned gpio);
此函數實現兩個目的:
Note that requesting a GPIO does NOT cause it to be configured in any way; it just marks that GPIO as in use. Separate code must handle any pin setup (e.g. controlling which pin the GPIO uses, pullup/pulldown).
Also note that it's your responsibility to have stopped using a GPIO before you free it.
/* set as input or output, returning 0 or negative errno */ int gpio_direction_input(unsigned gpio); int gpio_direction_output(unsigned gpio, int value);
/* GPIO INPUT: return zero or nonzero */ int gpio_get_value(unsigned gpio); /* GPIO OUTPUT */ void gpio_set_value(unsigned gpio, int value);
int gpio_cansleep(unsigned gpio);
/* GPIO INPUT: return zero or nonzero, might sleep */ int gpio_get_value_cansleep(unsigned gpio); /* GPIO OUTPUT, might sleep */ void gpio_set_value_cansleep(unsigned gpio, int value);
Other than the fact that these calls might sleep, and will not be ignored for GPIOs that can't be accessed from IRQ handlers, these calls act the same as the spinlock-safe calls.
/* map GPIO numbers to IRQ numbers */ int gpio_to_irq(unsigned gpio);
/* map IRQ numbers to GPIO numbers (avoid using this) */ int irq_to_gpio(unsigned irq);
gpio和中斷線都是用整形標識的,其在兩個name space中,這兩個函數建立了gpio和中斷線之間的映射關系
新聞熱點
疑難解答