3
我一直在使用這個代碼從這個example下的C gpio例子。我能夠設置和寫入針沒有問題與定義:閱讀引腳級別樹莓派
// GPIO setup macros. Always use INP_GPIO(x) before using OUT_GPIO(x) or SET_GPIO_ALT(x,y)
#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
#define OUT_GPIO(g) *(gpio+((g)/10)) |= (1<<(((g)%10)*3))
#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
#define GPIO_SET *(gpio+7) // sets bits which are 1 ignores bits which are 0
#define GPIO_CLR *(gpio+10) // clears bits which are 1 ignores bits which are 0
和
INP_GPIO(4); // must use INP_GPIO before we can use OUT_GPIO
OUT_GPIO(4);
GPIO_SET = 1<<4;
這工作得很好。不過,我不確定如果我想從一個別針讀取,該怎麼辦。我試圖通過返回gpio + thePin
來閱讀它,但我相信這是給我的地址,而不是價值。我試圖返回一個指針,但也給了我垃圾(-232783856)。
任何想法如何讀取銷釘的價值?