angle: Add support for reading tle5012b chip registers (for debugging)

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2022-03-19 20:12:35 -04:00
parent 1275281ab6
commit 4d1c3478ab
2 changed files with 31 additions and 0 deletions

View File

@ -127,6 +127,18 @@ use this tool the Python "numpy" package must be installed (see the
[measuring resonance document](Measuring_Resonances.md#software-installation) [measuring resonance document](Measuring_Resonances.md#software-installation)
for more information). for more information).
#### ANGLE_DEBUG_READ
`ANGLE_DEBUG_READ CHIP=<config_name> REG=<register>`: Queries sensor
register "register" (e.g. 44 or 0x2C). Can be useful for debugging
purposes. This is only available for tle5012b chips.
#### ANGLE_DEBUG_WRITE
`ANGLE_DEBUG_WRITE CHIP=<config_name> REG=<register> VAL=<value>`:
Writes raw "value" into register "register". Both "value" and
"register" can be a decimal or a hexadecimal integer. Use with care,
and refer to sensor data sheet for the reference. This is only
available for tle5012b chips.
### [bed_mesh] ### [bed_mesh]
The following commands are available when the The following commands are available when the

View File

@ -300,6 +300,14 @@ class HelperTLE5012B:
self.spi_angle_transfer_cmd = None self.spi_angle_transfer_cmd = None
self.last_chip_mcu_clock = self.last_chip_clock = 0 self.last_chip_mcu_clock = self.last_chip_clock = 0
self.chip_freq = 0. self.chip_freq = 0.
name = config.get_name().split()[-1]
gcode = self.printer.lookup_object("gcode")
gcode.register_mux_command("ANGLE_DEBUG_READ", "CHIP", name,
self.cmd_ANGLE_DEBUG_READ,
desc=self.cmd_ANGLE_DEBUG_READ_help)
gcode.register_mux_command("ANGLE_DEBUG_WRITE", "CHIP", name,
self.cmd_ANGLE_DEBUG_WRITE,
desc=self.cmd_ANGLE_DEBUG_WRITE_help)
def _build_config(self): def _build_config(self):
cmdqueue = self.spi.get_command_queue() cmdqueue = self.spi.get_command_queue()
self.spi_angle_transfer_cmd = self.mcu.lookup_query_command( self.spi_angle_transfer_cmd = self.mcu.lookup_query_command(
@ -385,6 +393,17 @@ class HelperTLE5012B:
self.last_chip_mcu_clock = mcu_clock self.last_chip_mcu_clock = mcu_clock
self.chip_freq = float(1<<5) / self.mcu.seconds_to_clock(1. / 750000.) self.chip_freq = float(1<<5) / self.mcu.seconds_to_clock(1. / 750000.)
self.update_clock() self.update_clock()
cmd_ANGLE_DEBUG_READ_help = "Query low-level angle sensor register"
def cmd_ANGLE_DEBUG_READ(self, gcmd):
reg = gcmd.get("REG", minval=0, maxval=0x30, parser=lambda x: int(x, 0))
val = self._read_reg(reg)
gcmd.respond_info("ANGLE REG[0x%02x] = 0x%04x" % (reg, val))
cmd_ANGLE_DEBUG_WRITE_help = "Set low-level angle sensor register"
def cmd_ANGLE_DEBUG_WRITE(self, gcmd):
reg = gcmd.get("REG", minval=0, maxval=0x30, parser=lambda x: int(x, 0))
val = gcmd.get("VAL", minval=0, maxval=0xffff,
parser=lambda x: int(x, 0))
self._write_reg(reg, val)
SAMPLE_PERIOD = 0.000400 SAMPLE_PERIOD = 0.000400