From 4d1c3478ab4cc627e7c182fa8864866582638fbe Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 19 Mar 2022 20:12:35 -0400 Subject: [PATCH] angle: Add support for reading tle5012b chip registers (for debugging) Signed-off-by: Kevin O'Connor --- docs/G-Codes.md | 12 ++++++++++++ klippy/extras/angle.py | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/docs/G-Codes.md b/docs/G-Codes.md index 131ee6e8..2adcb0d9 100644 --- a/docs/G-Codes.md +++ b/docs/G-Codes.md @@ -127,6 +127,18 @@ use this tool the Python "numpy" package must be installed (see the [measuring resonance document](Measuring_Resonances.md#software-installation) for more information). +#### ANGLE_DEBUG_READ +`ANGLE_DEBUG_READ CHIP= REG=`: 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= REG= VAL=`: +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] The following commands are available when the diff --git a/klippy/extras/angle.py b/klippy/extras/angle.py index a508b878..d61a7634 100644 --- a/klippy/extras/angle.py +++ b/klippy/extras/angle.py @@ -300,6 +300,14 @@ class HelperTLE5012B: self.spi_angle_transfer_cmd = None self.last_chip_mcu_clock = self.last_chip_clock = 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): cmdqueue = self.spi.get_command_queue() self.spi_angle_transfer_cmd = self.mcu.lookup_query_command( @@ -385,6 +393,17 @@ class HelperTLE5012B: self.last_chip_mcu_clock = mcu_clock self.chip_freq = float(1<<5) / self.mcu.seconds_to_clock(1. / 750000.) 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