samd_sercom: Specify the sercom explicitly in a config option

Do not infer the sercom from the config section name, as that
prevents one from using SPI buses on multiple samd mcus.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2021-07-03 22:52:42 -04:00
parent df43c9e9bf
commit d1bdde56cc
3 changed files with 18 additions and 11 deletions

View File

@ -6,6 +6,9 @@ All dates in this document are approximate.
# Changes # Changes
20210703: A `samd_sercom` config section must now specify the sercom
bus it is configuring via the `sercom` option.
20210612: The `pid_integral_max` config option in heater and 20210612: The `pid_integral_max` config option in heater and
temperature_fan sections is deprecated. The option will be removed in temperature_fan sections is deprecated. The option will be removed in
the near future. the near future.

View File

@ -3793,13 +3793,17 @@ i2c_address:
## [samd_sercom] ## [samd_sercom]
SAMD SERCOM configuration to specify which pins to use on a given SAMD SERCOM configuration to specify which pins to use on a given
SERCOM. One may define one section with the "samd_sercom" prefix per SERCOM. One may define any number of sections with a "samd_sercom"
SERCOM available. Each SERCOM must be configured prior to using it as prefix. Each SERCOM must be configured prior to using it as SPI or I2C
SPI or I2C peripheral. Place this config section above any other peripheral. Place this config section above any other section that
section that makes use of SPI or I2C buses. makes use of SPI or I2C buses.
``` ```
[samd_sercom sercom0] [samd_sercom my_sercom]
sercom:
# The name of the sercom bus to configure in the micro-controller.
# Available names are "sercom0", "sercom1", etc.. This parameter
# must be provided.
tx_pin: tx_pin:
# MOSI pin for SPI communication, or SDA (data) pin for I2C # MOSI pin for SPI communication, or SDA (data) pin for I2C
# communication. The pin must have a valid pinmux configuration # communication. The pin must have a valid pinmux configuration

View File

@ -7,8 +7,8 @@
class SamdSERCOM: class SamdSERCOM:
def __init__(self, config): def __init__(self, config):
self.printer = config.get_printer() self.printer = config.get_printer()
self.name = config.get_name().split()[1]
self.sercom = config.get("sercom")
self.tx_pin = config.get("tx_pin") self.tx_pin = config.get("tx_pin")
self.rx_pin = config.get("rx_pin", None) self.rx_pin = config.get("rx_pin", None)
self.clk_pin = config.get("clk_pin") self.clk_pin = config.get("clk_pin")
@ -18,15 +18,15 @@ class SamdSERCOM:
self.mcu = tx_pin_params['chip'] self.mcu = tx_pin_params['chip']
self.mcu.add_config_cmd( self.mcu.add_config_cmd(
"set_sercom_pin bus=%s sercom_pin_type=tx pin=%s" % ( "set_sercom_pin bus=%s sercom_pin_type=tx pin=%s" % (
self.name, tx_pin_params['pin'])) self.sercom, tx_pin_params['pin']))
clk_pin_params = ppins.lookup_pin(self.clk_pin) clk_pin_params = ppins.lookup_pin(self.clk_pin)
if self.mcu is not clk_pin_params['chip']: if self.mcu is not clk_pin_params['chip']:
raise ppins.error("%s: SERCOM pins must be on same mcu" % ( raise ppins.error("%s: SERCOM pins must be on same mcu" % (
config.get_name(),)) config.get_name(),))
self.mcu.add_config_cmd( self.mcu.add_config_cmd(
"set_sercom_pin bus=%s sercom_pin_type=clk pin=%s" % ( "set_sercom_pin bus=%s sercom_pin_type=clk pin=%s" % (
self.name, clk_pin_params['pin'])) self.sercom, clk_pin_params['pin']))
if self.rx_pin: if self.rx_pin:
rx_pin_params = ppins.lookup_pin(self.rx_pin) rx_pin_params = ppins.lookup_pin(self.rx_pin)
@ -35,7 +35,7 @@ class SamdSERCOM:
config.get_name(),)) config.get_name(),))
self.mcu.add_config_cmd( self.mcu.add_config_cmd(
"set_sercom_pin bus=%s sercom_pin_type=rx pin=%s" % ( "set_sercom_pin bus=%s sercom_pin_type=rx pin=%s" % (
self.name, rx_pin_params['pin'])) self.sercom, rx_pin_params['pin']))
def load_config_prefix(config): def load_config_prefix(config):
return SamdSERCOM(config) return SamdSERCOM(config)