NVIDIA GPIO
NVIDIA Resource:
Forum GPIO Description
GPIO 分类 MAIN 和 AON GPIO(TX1/NANO无AON)
Main GPIO Controller: 0x02200000
AON GPIO Controller: 0x0C2F0000
In order to access your GPIO device you need to get your GPIO number. To do this:
1. Find the processor base value:
Main Processor base value is: 320
AON Processor base value is: 256
2. From the port listing above find the index of your port.
As an example AA would be: 5
3. Get the offset from your port, which is the number after your port.
AA0 -> Offset 0
4. Use the following formula to to calculate the userland GPIO:
+ <8 * Port Index> + Offset
256 + 8 * 5 + 0 = 296
This is value you should put into /sys/class/gpio/export
1. GPIO 4Pin控制门锁(GPIO for DoorLocker)
Multifunction Port W5 for the GPIO interface:
- GPIO9 as output (with 3.3volt level) --- GPIO298.No(TX2)
- GPIO8 as input --- GPIO388.No(TX2)
- GPIO_EXP0_INT as input --- GPIO480.No(TX2)
- GPIO_EXP1_INT as input --- GPIO486.No(TX2)
gpio@2200000 {
rgb-control-output-high {
gpio-hog;
output-low;
enable-active-high;
gpios = <
TEGRA_MAIN_GPIO(I, 4) 0
TEGRA_MAIN_GPIO(Y, 6) 0
TEGRA_MAIN_GPIO(Y, 0) 0
>;
label = "gpio8-input","rgb-b","rgb-r";
/*
gpio388:rgb-b GPIO3_PI.04---GPIO8_ALS_PROX_INT
gpio480:rgb-r GPIO3_PY.00---GPIO_EXP0_INT
gpio486:rgb-b GPIO3_PY.06---GPIO_EXP1_INT
*/
};
};
gpio@c2f0000 {
red-control-output-high {
gpio-hog;
output-high;
enable-active-high;
gpios = <
TEGRA_AON_GPIO(AA, 2) 0
>;
label = "rgb-g";
/* gpio298:rgb-g GPIO3_PAA.02---GPIO9_MOTION_INT */
};
};
2.操作方法(Operate Method:root)
$sudo -s
---Set GPIO file to operate
echo 388 > export
---Set input/output
echo 'out' > gpio388/direction
---Set low/high
echo 1 > gpio388/value
echo 0 > gpio388/value
The same to GPIO480/486/298 and so on.
3. Python GPIO 操作手册
安装 Python GPIO库
import time
import gpio
fan_output_pin = 388 #GPIO8 as input --- GPIO388(TX2 TEGRA-SOC)
gpio.setup(fan_output_pin, gpio.OUT)
gpio.set(fan_output_pin, 0)
print("Starting now! Press CTRL+C to exit")
try:
while True:
gpio.set(fan_output_pin, 1)
print("GPIO8 High.")
time.sleep(5)
gpio.set(fan_output_pin, 0)
print("GPIO8 Low")
time.sleep(5)
finally:
gpio.cleanup()
案例HC-SR04 Sonar 超声波测距Python 代码:
import gpio
import time
trig = 480 #GPIO_EXP0_INT as input --- GPIO480.No(TX2)
echo = 486 #GPIO_EXP1_INT as input --- GPIO486.No(TX2)
print "HC-SR04 Sonar"
def main():
# Pin Setup:
gpio.setup(trig, gpio.OUT)
gpio.set(trig,0)
gpio.setup(echo, gpio.IN)
print("Starting Measure now! Press CTRL+C to exit")
while True:
gpio.set(trig, 1)
time.sleep(0.00001)
gpio.set(trig, 0)
pulse_start = time.time()
while gpio.read(echo)==0:
pulse_start = time.time()
pulse_end = time.time()
while gpio.read(echo)==1:
pulse_end = time.time()
pulse_duration = pulse_end - pulse_start
distance = pulse_duration * 17150
distance = round(distance, 2)
print ("Distance" , distance)
if __name__ == '__main__':
main()
4. 查看当下GPIO状态:GPIO.No、输入/出、Hi/Lo
root@tegra-ubuntu:~# cat /sys/kernel/debug/gpio
GPIOs 232-239, platform/max77620-gpio, max77620-gpio, can sleep:
gpio-232 ( |external-connection:) in hi
gpio-237 ( |spmic_gpio_input_5 ) in lo
gpio-238 ( |spmic_gpio_input_6 ) in hi
GPIOs 240-255, i2c/0-0074, tca9539, can sleep:
gpio-240 ( |vdd-usb2-5v ) out hi
gpio-241 ( |en-vdd-ts-1v8 ) out hi
gpio-242 ( |en-vdd-ts-hv-3v3 ) out hi
gpio-243 ( |en-vdd-disp-3v3 ) out lo
gpio-244 ( |vdd-fan ) out hi
gpio-247 ( |en-mdm-pwr-3v7 ) out lo
gpio-249 ( |en-vdd-disp-1v8 ) out lo
gpio-250 ( |dis-vdd-1v2 ) out hi
gpio-252 ( |vdd-hdmi ) out hi
gpio-253 ( |en-vdd-cam-hv-2v8 ) out lo
GPIOs 256-319, platform/c2f0000.gpio, tegra-gpio-aon:
gpio-272 ( |temp_alert ) in hi
gpio-298 ( |locker-gpio9 ) out hi
gpio-312 ( |Power ) in hi
gpio-313 ( |Volume Up ) in hi
gpio-314 ( |Volume Down ) in hi
gpio-315 ( |wifi-wake-ap ) in hi
gpio-316 ( |bt_host_wake ) in hi
GPIOs 320-511, platform/2200000.gpio, tegra-gpio:
gpio-381 ( |reset_gpio ) out lo
gpio-388 ( |gpio8-input ) in hi
gpio-412 ( |vdd-usb0-5v ) out lo
gpio-413 ( |vdd-usb1-5v ) in hi
gpio-420 ( |eqos_phy_reset ) out hi
gpio-421 ( |eqos_phy_intr ) in hi
gpio-424 ( |wlan_pwr ) out lo
gpio-426 ( |cam1-pwdn ) out lo
gpio-441 ( |hdmi2.0_hpd ) in lo
gpio-444 ( |wp ) in lo
gpio-445 ( |cd ) in hi
gpio-446 ( |en-vdd-sd ) out lo
gpio-456 ( |cam0-pwdn ) out lo
gpio-457 ( |cam1-rst ) out lo
gpio-459 ( |pcie-lane2-mux ) out lo
gpio-461 ( |cam0-rst ) out lo
gpio-479 ( |external-connection:) in lo
gpio-480 ( |exp0-int ) in lo
gpio-484 ( |bt_ext_wake ) out hi
gpio-486 ( |exp1-int ) in lo
TX2 开发板J21 GPIO列表