Skip to content

Commit 815dc73

Browse files
import changes, test changes, tool instructions added to readme, new environment variable JETSON_TESTING_MODEL_NAME overrides device models entirely, pinmux as one word, addressing comments
Co-authored-by: Tharun Ganeshram <tharun.ganeshram@gmail.com>
1 parent ddeaa27 commit 815dc73

File tree

5 files changed

+46
-18
lines changed

5 files changed

+46
-18
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,23 @@ rules by running:
8282
sudo udevadm control --reload-rules && sudo udevadm trigger
8383
```
8484

85+
# Pinmux Lookup Tool
86+
87+
The `jetson-gpio-pinmux-lookup` command-line tool helps you find the pinmux register address for GPIO pins. This is useful for debugging or setting up pinmux configurations.
88+
89+
**Usage:**
90+
```shell
91+
jetson-gpio-pinmux-lookup <gpio_pin_number>
92+
```
93+
94+
**Example:**
95+
```shell
96+
jetson-gpio-pinmux-lookup 7
97+
# Output on Orin Device: GPIO Pin 7: Mux Register Address = 0x2430070
98+
```
99+
100+
The tool accepts BOARD mode GPIO pin numbers (1-40) and returns the corresponding pinmux register address in hexadecimal format.
101+
85102
# Running the sample scripts
86103

87104
With the permissions set as needed, the sample applications provided in the

lib/python/Jetson/GPIO/gpio_pin_data.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,16 @@ def get_compatibles(compatible_path):
573573
def get_model():
574574
compatible_path = '/proc/device-tree/compatible'
575575

576+
# check first to see whether a testing model name is set
577+
model_name = os.environ.get("JETSON_TESTING_MODEL_NAME")
578+
if model_name is not None:
579+
model_name = model_name.strip()
580+
if model_name in JETSON_MODELS:
581+
return model_name
582+
else:
583+
msg = f"Environment variable 'JETSON_TESTING_MODEL_NAME={model_name}' is invalid."
584+
sys.stderr.write(msg)
585+
576586
# get model info from compatible_path
577587
if os.path.exists(compatible_path):
578588
compatibles = get_compatibles(compatible_path)

lib/python/Jetson/GPIO/gpio_pin_mux_lookup.py renamed to lib/python/Jetson/GPIO/gpio_pinmux_lookup.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python
12
# Copyright (c) 2019-2023, NVIDIA CORPORATION. All rights reserved.
23
#
34
# Permission is hereby granted, free of charge, to any person obtaining a
@@ -18,14 +19,14 @@
1819
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1920
# DEALINGS IN THE SOFTWARE.
2021

21-
# @File name: gpio_pin_mux_lookup.py
22+
# @File name: gpio_pinmux_lookup.py
2223
# @Date:
2324
# @Last modified by:
2425
# @Last Modified time: 9/17/2025
25-
# @Description: Simple tool to lookup pin mux register address for GPIO pins. User must specify the BOARD mode GPIO pin number.
26+
# @Description: Simple tool to lookup pinmux register address for GPIO pins. User must specify the BOARD mode GPIO pin number.
2627

2728
import sys
28-
import gpio_pin_data
29+
from Jetson.GPIO import gpio_pin_data
2930

3031
# @brief Get pin register address for a given BOARD mode GPIO pin number.
3132
# @param[in] gpio_pin: BOARD mode GPIO pin number
@@ -44,11 +45,11 @@ def lookup_mux_register(gpio_pin, pin_defs):
4445
# @brief Main function to handle command line interface.
4546
def main():
4647
if len(sys.argv) != 2:
47-
print("Usage: jetson-gpio-pin-mux-lookup <gpio_pin_number>")
48-
print("\nLookup pin mux register address for GPIO pins.")
48+
print("Usage: jetson-gpio-pinmux-lookup <gpio_pin_number>")
49+
print("\nLookup pinmux register address for GPIO pins.")
4950
print("Specify the Board Mode GPIO pin number (e.g., 7, 11, 40, etc.)")
5051
print("\nExample:")
51-
print(" jetson-gpio-pin-mux-lookup 7")
52+
print(" jetson-gpio-pinmux-lookup 7")
5253
sys.exit(1)
5354

5455
try:
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ def test(f):
8989
return f
9090

9191
# command to run the script
92-
script_path = 'jetson-gpio-pin-mux-lookup'
92+
script_command = 'jetson-gpio-pinmux-lookup'
9393

9494
def run_gpio_tool(args, env=None):
95-
cmd = [sys.executable, script_path] + args
95+
cmd = [script_command] + args
9696
current_env = os.environ.copy()
9797
if env:
9898
current_env.update(env)
@@ -114,7 +114,7 @@ def test_no_arguments():
114114
returncode, stdout, stderr = run_gpio_tool([])
115115
assert returncode == 1
116116
assert "Usage:" in stdout
117-
assert "jetson-gpio-pin-mux-lookup <gpio_pin_number>" in stdout
117+
assert "jetson-gpio-pinmux-lookup <gpio_pin_number>" in stdout
118118
print("✓ No arguments test passed")
119119

120120
@test
@@ -133,7 +133,7 @@ def test_non_integer_argument():
133133

134134
@test
135135
def test_negative_pin():
136-
test_env = {'JETSON_MODEL_NAME': 'JETSON_ORIN'}
136+
test_env = {'JETSON_TESTING_MODEL_NAME': 'JETSON_ORIN'}
137137
returncode, stdout, stderr = run_gpio_tool(['-1'], env=test_env)
138138
assert returncode == 1
139139
error_msg = stderr + stdout
@@ -142,7 +142,7 @@ def test_negative_pin():
142142

143143
@test
144144
def test_pin_too_high():
145-
test_env = {'JETSON_MODEL_NAME': 'JETSON_ORIN'}
145+
test_env = {'JETSON_TESTING_MODEL_NAME': 'JETSON_ORIN'}
146146
returncode, stdout, stderr = run_gpio_tool(['41'], env=test_env)
147147
assert returncode == 1
148148
error_msg = stderr + stdout
@@ -153,7 +153,7 @@ def test_pin_too_high():
153153

154154
@test
155155
def test_jetson_orin_valid_pins():
156-
test_env = {'JETSON_MODEL_NAME': 'JETSON_ORIN'}
156+
test_env = {'JETSON_TESTING_MODEL_NAME': 'JETSON_ORIN'}
157157

158158
# Test all valid GPIO pins for Jetson Orin
159159
for gpio_pin in test_data['JETSON_ORIN']['expected_addresses'].keys():
@@ -166,7 +166,7 @@ def test_jetson_orin_valid_pins():
166166

167167
@test
168168
def test_jetson_orin_nx_valid_pins():
169-
test_env = {'JETSON_MODEL_NAME': 'JETSON_ORIN_NX'}
169+
test_env = {'JETSON_TESTING_MODEL_NAME': 'JETSON_ORIN_NX'}
170170

171171
# Test all valid GPIO pins for Jetson Orin NX
172172
for gpio_pin in test_data['JETSON_ORIN_NX']['expected_addresses'].keys():
@@ -179,7 +179,7 @@ def test_jetson_orin_nx_valid_pins():
179179

180180
@test
181181
def test_jetson_orin_nano_valid_pins():
182-
test_env = {'JETSON_MODEL_NAME': 'JETSON_ORIN_NANO'}
182+
test_env = {'JETSON_TESTING_MODEL_NAME': 'JETSON_ORIN_NANO'}
183183

184184
# Test all valid GPIO pins for Jetson Orin Nano
185185
for gpio_pin in test_data['JETSON_ORIN_NX']['expected_addresses'].keys():
@@ -194,7 +194,7 @@ def test_jetson_orin_nano_valid_pins():
194194

195195
@test
196196
def test_invalid_pins_jetson_orin():
197-
test_env = {'JETSON_MODEL_NAME': 'JETSON_ORIN'}
197+
test_env = {'JETSON_TESTING_MODEL_NAME': 'JETSON_ORIN'}
198198

199199
# Test a few invalid pins
200200
for pin in [1, 2, 3, 4, 5, 6]:
@@ -208,7 +208,7 @@ def test_invalid_pins_jetson_orin():
208208
@test
209209
def test_no_model_environment():
210210
# Remove model environment variable
211-
test_env = {k: v for k, v in os.environ.items() if k != 'JETSON_MODEL_NAME'}
211+
test_env = {k: v for k, v in os.environ.items() if k != 'JETSON_TESTING_MODEL_NAME'}
212212

213213
returncode, stdout, stderr = run_gpio_tool(['7'], env=test_env)
214214

@@ -227,7 +227,7 @@ def test_no_model_environment():
227227
def run_all_tests():
228228
# Run all tests and report results.
229229
print("=" * 60)
230-
print("GPIO Pin Mux Lookup Tool - Test Suite")
230+
print("GPIO Pinmux Lookup Tool - Test Suite")
231231
print("=" * 60)
232232

233233
passed = 0

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
include_package_data = True,
4646
entry_points={
4747
'console_scripts': [
48-
'jetson-gpio-pin-mux-lookup=Jetson.GPIO.gpio_pin_mux_lookup:main'
48+
'jetson-gpio-pinmux-lookup=Jetson.GPIO.gpio_pinmux_lookup:main'
4949
]
5050
},
5151
)

0 commit comments

Comments
 (0)