Skip to content

Commit

Permalink
Examples/TMC9660: Little cleanup in read_all_mcc_register_and_fields.py
Browse files Browse the repository at this point in the history
* Less verbose
* Fix issues with negative hex values
  • Loading branch information
trinamic-bp committed Jan 31, 2025
1 parent 65890e9 commit 9e980df
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
+-----+ +-------------------+
"""

import time
import ctypes

from pytrinamic.connections import ConnectionManager

Expand All @@ -30,11 +29,18 @@

for register in TMC9660.MCC.registers():
register_value = tmc9660_eval.read(register)
# Convert to unsigned for the hex print not to be negative
register_value = ctypes.c_uint32(register_value).value
print(f"{register.name:17}: 0x{register_value:08X}")
if len(register.fields()) == 1 and register.fields()[0].name == register.name:
# Do not print the field value if the field is the same as the register
continue
for field in register.fields():
field_value = field.get(register_value)
if field.choice:
print(f" {field.name:22}: {field.choice.get(field_value).name}")
# Print text representation of the field value if its an enumeration
print(f" {field.name:24}: {field.choice.get(field_value).name}")
else:
print(f" {field.name:22}: {field_value}")
# Just print the field value decimal
print(f" {field.name:24}: {field_value}")

0 comments on commit 9e980df

Please sign in to comment.