mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-08-30 14:52:51 +08:00
sleep-interval default value is reduced to 1.
i2c-bus is required argument replace --bus with --i2c-bus for i2c_dump_rtl_regs.py for better consistency format lint clean up
This commit is contained in:
@@ -1,26 +1,24 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
regs = list(range(65536))
|
||||
|
||||
glb_mux = 0x65E0
|
||||
|
||||
led3_0_set1 = 0x6528
|
||||
led1_0_set0 = 0x6548
|
||||
led_port_sel = 0x654c
|
||||
led_port_sel = 0x654C
|
||||
|
||||
|
||||
def get_word(i):
|
||||
val = (regs[i+3] <<24) + (regs[i+2]<<16) + (regs[i+1]<<8) + regs[i]
|
||||
# print(f"READING {i:04x} : {val:08x}")
|
||||
val = (regs[i + 3] << 24) + (regs[i + 2] << 16) + (regs[i + 1] << 8) + regs[i]
|
||||
# print(f"READING {i:04x} : {val:08x}")
|
||||
return val
|
||||
|
||||
with open ('reg_dump.txt', 'r') as file:
|
||||
|
||||
with open("reg_dump.txt", "r") as file:
|
||||
for line in file:
|
||||
(addr, data) = line.split(":")
|
||||
data = [ int(x, 16) for x in data.strip().split(" ") ]
|
||||
addr, data = line.split(":")
|
||||
data = [int(x, 16) for x in data.strip().split(" ")]
|
||||
addr = int(addr, 16)
|
||||
for x in range(len(data)):
|
||||
regs[addr + x] = data[x]
|
||||
@@ -31,9 +29,9 @@ print("LED pad Configuration:")
|
||||
for i in range(28):
|
||||
j = i % 5
|
||||
if j == 0:
|
||||
idx = glb_mux + (i//5)*4
|
||||
idx = glb_mux + (i // 5) * 4
|
||||
val = get_word(idx)
|
||||
ledval = (val>>(6*j)) &0x3f
|
||||
ledval = (val >> (6 * j)) & 0x3F
|
||||
ledstr.append(f"{ledval:02x}")
|
||||
ledfmt.append(f"{i:02x}")
|
||||
print(f"{' '.join(ledfmt)}")
|
||||
@@ -41,26 +39,46 @@ print(f"{' '.join(ledstr)}")
|
||||
print(f".led_mux = {{ 0x{', 0x'.join(ledstr)} }},")
|
||||
|
||||
LED_TYPES = [
|
||||
" 10G", 16,
|
||||
" TWO_5G", 17,
|
||||
" 5G", 18,
|
||||
" TWO_2G5", 19,
|
||||
" 2G5", 0,
|
||||
" TWO_1G", 1,
|
||||
" 1G", 2,
|
||||
" 500M", 3,
|
||||
" 100M", 4,
|
||||
" 10M", 5,
|
||||
" LINK", 6,
|
||||
" LINK_FLASH", 7,
|
||||
" ACT", 8,
|
||||
" RX", 9,
|
||||
" TX", 10,
|
||||
" COL", 11,
|
||||
" DUPLEX", 12,
|
||||
" TRAINING", 13,
|
||||
" MASTER", 14,
|
||||
"", 15,
|
||||
" 10G",
|
||||
16,
|
||||
" TWO_5G",
|
||||
17,
|
||||
" 5G",
|
||||
18,
|
||||
" TWO_2G5",
|
||||
19,
|
||||
" 2G5",
|
||||
0,
|
||||
" TWO_1G",
|
||||
1,
|
||||
" 1G",
|
||||
2,
|
||||
" 500M",
|
||||
3,
|
||||
" 100M",
|
||||
4,
|
||||
" 10M",
|
||||
5,
|
||||
" LINK",
|
||||
6,
|
||||
" LINK_FLASH",
|
||||
7,
|
||||
" ACT",
|
||||
8,
|
||||
" RX",
|
||||
9,
|
||||
" TX",
|
||||
10,
|
||||
" COL",
|
||||
11,
|
||||
" DUPLEX",
|
||||
12,
|
||||
" TRAINING",
|
||||
13,
|
||||
" MASTER",
|
||||
14,
|
||||
"",
|
||||
15,
|
||||
]
|
||||
|
||||
led_set = []
|
||||
@@ -71,23 +89,27 @@ for i in range(4):
|
||||
idval = []
|
||||
idvalstr = []
|
||||
for id in range(4):
|
||||
val = 0xffff & ( get_word(led1_0_set0 - 8*i - ((id>>1)<<2)) >> (16*(id&1)) )
|
||||
valhi = ( 0xf & ( get_word(led3_0_set1 - 4*(i>>1)) >> (16*(i&1) + 4*id)) ) << 16
|
||||
val = 0xFFFF & (
|
||||
get_word(led1_0_set0 - 8 * i - ((id >> 1) << 2)) >> (16 * (id & 1))
|
||||
)
|
||||
valhi = (
|
||||
0xF & (get_word(led3_0_set1 - 4 * (i >> 1)) >> (16 * (i & 1) + 4 * id))
|
||||
) << 16
|
||||
val += valhi
|
||||
idval.append(val)
|
||||
valstr = "("
|
||||
for bit in range(0,len(LED_TYPES),2):
|
||||
if val & (1<<(LED_TYPES[bit+1])):
|
||||
for bit in range(0, len(LED_TYPES), 2):
|
||||
if val & (1 << (LED_TYPES[bit + 1])):
|
||||
valstr += LED_TYPES[bit]
|
||||
valstr += ")"
|
||||
idvalstr.append(valstr)
|
||||
led_set.append(idval)
|
||||
led_set_str.append(idvalstr)
|
||||
idstr = ' '.join([f"{d:05x}" for d in idval])
|
||||
idstr = " ".join([f"{d:05x}" for d in idval])
|
||||
print(f"SET {i}: {idstr}")
|
||||
# print(f"{idvalstr}")
|
||||
|
||||
portsel = get_word(led_port_sel)
|
||||
for i in range(3,9):
|
||||
sel = (portsel>>(i<<1)) & 3
|
||||
for i in range(3, 9):
|
||||
sel = (portsel >> (i << 1)) & 3
|
||||
print(f"Port {i}: SET {sel}: {', '.join(led_set_str[sel])}")
|
||||
|
||||
@@ -1,28 +1,29 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import time
|
||||
import argparse
|
||||
from smbus2 import SMBus, i2c_msg
|
||||
|
||||
# Configuration
|
||||
DEFAULT_I2C_BUS = 1
|
||||
DEVICE_ADDR = 0x5C # Replace with your device address
|
||||
NUM_BYTES = 16 # Bytes to read
|
||||
|
||||
# Parse command line arguments
|
||||
parser = argparse.ArgumentParser(description='Dump RTL registers via I2C')
|
||||
parser.add_argument('-b', '--bus', type=int, default=DEFAULT_I2C_BUS,
|
||||
help='I2C bus number (default: {})'.format(DEFAULT_I2C_BUS))
|
||||
parser = argparse.ArgumentParser(description="Dump RTL registers via I2C")
|
||||
parser.add_argument(
|
||||
"-b",
|
||||
"--i2c-bus",
|
||||
type=int,
|
||||
required=True,
|
||||
help="I2C bus number (use i2cdetect -l to find out the bus number of the dongle)",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
I2C_BUS = args.bus
|
||||
|
||||
# Open I2C bus
|
||||
with SMBus(I2C_BUS) as bus:
|
||||
with SMBus(args.i2c_bus) as bus:
|
||||
|
||||
for addr in range (0, 65536, NUM_BYTES):
|
||||
for addr in range(0, 65536, NUM_BYTES):
|
||||
# Create write message (send register address)
|
||||
write = i2c_msg.write(DEVICE_ADDR, [addr>>8, addr & 0xff])
|
||||
write = i2c_msg.write(DEVICE_ADDR, [addr >> 8, addr & 0xFF])
|
||||
|
||||
# Create read message (read 2 bytes)
|
||||
read = i2c_msg.read(DEVICE_ADDR, NUM_BYTES)
|
||||
@@ -33,5 +34,5 @@ with SMBus(I2C_BUS) as bus:
|
||||
new_data = list(read)
|
||||
|
||||
# Convert read message to string
|
||||
datastr = " ".join([ f"{x:02x}" for x in new_data])
|
||||
datastr = " ".join([f"{x:02x}" for x in new_data])
|
||||
print(f"{addr:04x}: {datastr}")
|
||||
@@ -1,7 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import time
|
||||
import sys
|
||||
import argparse
|
||||
from smbus2 import SMBus, i2c_msg
|
||||
|
||||
@@ -16,20 +15,34 @@ SLEEP_INTERVAL = 1
|
||||
IGNORED_IOS = [28, 31, 32, 34, 35, 42, 43, 44, 45]
|
||||
|
||||
# Setup argument parser
|
||||
parser = argparse.ArgumentParser(description='Read I2C data from RTL GPIO expander')
|
||||
parser.add_argument('--i2c-bus', '-b', type=int, default=1,
|
||||
help='I2C bus number (default: 1)')
|
||||
parser.add_argument('--sleep-interval', '-s', type=int, default=2,
|
||||
help='Sleep interval in seconds (default: 2)')
|
||||
parser.add_argument('--ignored-ios', '-i', nargs='*', type=int, default=[28, 31, 32, 34, 35, 42, 43, 44, 45],
|
||||
help='List of GPIO pins to ignore (default: [28, 31, 32, 34, 35, 42, 43, 44, 45])')
|
||||
parser = argparse.ArgumentParser(description="Read I2C data from RTL GPIO expander")
|
||||
parser.add_argument(
|
||||
"-b",
|
||||
"--i2c-bus",
|
||||
type=int,
|
||||
required=True,
|
||||
help="I2C bus number (use i2cdetect -l to find out the bus number of the dongle)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-s",
|
||||
"--sleep-interval",
|
||||
type=int,
|
||||
default=SLEEP_INTERVAL,
|
||||
help=f"Sleep interval in seconds (default: {SLEEP_INTERVAL})",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-i",
|
||||
"--ignored-ios",
|
||||
nargs="*",
|
||||
type=int,
|
||||
default=IGNORED_IOS,
|
||||
help=f"List of GPIO pins to ignore (default: {IGNORED_IOS})",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
I2C_BUS = args.i2c_bus
|
||||
SLEEP_INTERVAL = args.sleep_interval
|
||||
IGNORED_IOS = args.ignored_ios
|
||||
|
||||
first_read = True
|
||||
last_data = [ 0 for x in range(NUM_BYTES) ]
|
||||
last_data = [0 for x in range(NUM_BYTES)]
|
||||
|
||||
# Open I2C bus
|
||||
with SMBus(I2C_BUS) as bus:
|
||||
@@ -37,7 +50,7 @@ with SMBus(I2C_BUS) as bus:
|
||||
|
||||
while True:
|
||||
# Create write message (send register address)
|
||||
write = i2c_msg.write(DEVICE_ADDR, [addr>>8, addr & 0xff])
|
||||
write = i2c_msg.write(DEVICE_ADDR, [addr >> 8, addr & 0xFF])
|
||||
|
||||
# Create read message (read NUM_BYTES bytes)
|
||||
read = i2c_msg.read(DEVICE_ADDR, NUM_BYTES)
|
||||
@@ -54,17 +67,17 @@ with SMBus(I2C_BUS) as bus:
|
||||
last_data = new_data
|
||||
|
||||
# Convert read message to list
|
||||
datastr = " ".join([ f"{x:02x}" for x in new_data])
|
||||
datastr = " ".join([f"{x:02x}" for x in new_data])
|
||||
deltastr = ""
|
||||
chg_list = []
|
||||
for x in range(NUM_BYTES):
|
||||
if delta_data[x] == 0:
|
||||
continue
|
||||
for y in range(8):
|
||||
if delta_data[x] & ( 1<<y):
|
||||
idx = x*8 + y
|
||||
if idx not in IGNORED_IOS:
|
||||
if delta_data[x] & (1 << y):
|
||||
idx = x * 8 + y
|
||||
if idx not in args.ignored_ios:
|
||||
deltastr += f"\n{' ':8s}GPIO{idx}"
|
||||
# deltastr = " ".join([ f"{x:02x}" for x in delta_data])
|
||||
print(f"{addr:04x}: {datastr}{deltastr}")
|
||||
time.sleep(SLEEP_INTERVAL)
|
||||
time.sleep(args.sleep_interval)
|
||||
|
||||
Reference in New Issue
Block a user