2019-02-19 08:32:37 +03:00
|
|
|
# SAMD Sercom configuration
|
|
|
|
#
|
|
|
|
# Copyright (C) 2019 Florian Heilmann <Florian.Heilmann@gmx.net>
|
|
|
|
#
|
|
|
|
# This file may be distributed under the terms of the GNU GPLv3 license.
|
|
|
|
|
|
|
|
class SamdSERCOM:
|
|
|
|
def __init__(self, config):
|
|
|
|
self.printer = config.get_printer()
|
|
|
|
|
2021-07-04 05:52:42 +03:00
|
|
|
self.sercom = config.get("sercom")
|
2019-02-19 08:32:37 +03:00
|
|
|
self.tx_pin = config.get("tx_pin")
|
|
|
|
self.rx_pin = config.get("rx_pin", None)
|
|
|
|
self.clk_pin = config.get("clk_pin")
|
|
|
|
|
2019-04-01 06:37:17 +03:00
|
|
|
ppins = self.printer.lookup_object("pins")
|
2019-02-19 08:32:37 +03:00
|
|
|
tx_pin_params = ppins.lookup_pin(self.tx_pin)
|
|
|
|
self.mcu = tx_pin_params['chip']
|
|
|
|
self.mcu.add_config_cmd(
|
2019-04-01 06:37:17 +03:00
|
|
|
"set_sercom_pin bus=%s sercom_pin_type=tx pin=%s" % (
|
2021-07-04 05:52:42 +03:00
|
|
|
self.sercom, tx_pin_params['pin']))
|
2019-02-19 08:32:37 +03:00
|
|
|
|
|
|
|
clk_pin_params = ppins.lookup_pin(self.clk_pin)
|
|
|
|
if self.mcu is not clk_pin_params['chip']:
|
2021-07-04 05:52:42 +03:00
|
|
|
raise ppins.error("%s: SERCOM pins must be on same mcu" % (
|
|
|
|
config.get_name(),))
|
2019-02-19 08:32:37 +03:00
|
|
|
self.mcu.add_config_cmd(
|
2019-04-01 06:37:17 +03:00
|
|
|
"set_sercom_pin bus=%s sercom_pin_type=clk pin=%s" % (
|
2021-07-04 05:52:42 +03:00
|
|
|
self.sercom, clk_pin_params['pin']))
|
2019-02-19 08:32:37 +03:00
|
|
|
|
|
|
|
if self.rx_pin:
|
|
|
|
rx_pin_params = ppins.lookup_pin(self.rx_pin)
|
|
|
|
if self.mcu is not rx_pin_params['chip']:
|
|
|
|
raise ppins.error("%s: SERCOM pins must be on same mcu" % (
|
|
|
|
config.get_name(),))
|
|
|
|
self.mcu.add_config_cmd(
|
2019-04-01 06:37:17 +03:00
|
|
|
"set_sercom_pin bus=%s sercom_pin_type=rx pin=%s" % (
|
2021-07-04 05:52:42 +03:00
|
|
|
self.sercom, rx_pin_params['pin']))
|
2019-02-19 08:32:37 +03:00
|
|
|
|
|
|
|
def load_config_prefix(config):
|
|
|
|
return SamdSERCOM(config)
|