Skip to content

Commit

Permalink
support klipper mcus
Browse files Browse the repository at this point in the history
  • Loading branch information
bwnance authored and sbtoonz committed Feb 16, 2024
1 parent c1f4c21 commit 691df5e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
15 changes: 13 additions & 2 deletions klippy/mcu.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ def _handle_analog_in_state(self, params):
class MCU:
error = error
def __init__(self, config, clocksync):
self._config = config
self._printer = printer = config.get_printer()
self._clocksync = clocksync
self._reactor = printer.get_reactor()
Expand Down Expand Up @@ -678,13 +679,15 @@ def _send_config(self, prev_crc):
cb()
self._config_cmds.insert(0, "allocate_oids count=%d"
% (self._oid_count,))

# Resolve pin names
mcu_type = self._serial.get_msgparser().get_constant('MCU')
ppins = self._printer.lookup_object('pins')
pin_resolver = ppins.get_pin_resolver(self._name)
for cmdlist in (self._config_cmds, self._restart_cmds, self._init_cmds):
for i, cmd in enumerate(cmdlist):
cmdlist[i] = pin_resolver.update_command(cmd)
logging.info("command: %s", cmdlist[i])
# Calculate config CRC
encoded_config = '\n'.join(self._config_cmds).encode()
config_crc = zlib.crc32(encoded_config) & 0xffffffff
Expand Down Expand Up @@ -743,15 +746,23 @@ def recon_mcu(self):
res = self._mcu_identify()
if not res:
return

self.reset_to_initial_state()
self._connect()
self._reactor.update_timer(
self.non_critical_recon_timer, self._reactor.NEVER
)
self._reactor.unregister_timer(self.non_critical_recon_timer)
self.last_noncrit_recon_eventtime = None
logging.info("mcu: %s reconnected", self._name)


def reset_to_initial_state(self):
self._oid_count = 0
self._config_cmds = []
self._restart_cmds = []
self._init_cmds = []
self._reserved_move_slots = 0
self._stepqueues = []
self._steppersync = None
def _connect(self):
if self._non_critical_disconnected:
self.non_critical_recon_timer = self._reactor.register_timer(
Expand Down
4 changes: 2 additions & 2 deletions src/basecmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ DECL_COMMAND(command_finalize_config, "finalize_config crc=%u");
void
config_reset(uint32_t *args)
{
if (! sched_is_shutdown())
shutdown("config_reset only available when shutdown");
// if (! sched_is_shutdown())
// shutdown("config_reset only available when shutdown");
irq_disable();
config_crc = 0;
oid_count = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/linux/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ static char **orig_argv;
void
command_config_reset(uint32_t *args)
{
if (! sched_is_shutdown())
shutdown("config_reset only available when shutdown");
// if (! sched_is_shutdown())
// shutdown("config_reset only available when shutdown");
int ret = execv(orig_argv[0], orig_argv);
report_errno("execv", ret);
}
Expand Down

0 comments on commit 691df5e

Please sign in to comment.