diff --git a/ports/samd/Makefile b/ports/samd/Makefile index 7d27367b6b..291a894ab7 100644 --- a/ports/samd/Makefile +++ b/ports/samd/Makefile @@ -56,10 +56,12 @@ INC += -I$(TOP)/lib/asf4/$(MCU_SERIES_LOWER)/include INC += -I$(TOP)/lib/asf4/$(MCU_SERIES_LOWER)/include/pio INC += -I$(TOP)/lib/tinyusb/src -MAKE_PIN_AF = boards/make-pin-table.py -PIN_AF_TABLE_CSV = mcu/$(MCU_SERIES_LOWER)/pin-af-table.csv +MAKE_PINS = boards/make-pins.py BOARD_PINS = $(BOARD_DIR)/pins.csv -GEN_PIN_AF = pin_af_table.c +PREFIX_FILE = boards/pins_prefix.c +AF_FILE = mcu/$(MCU_SERIES_LOWER)/pin-af-table.csv +GEN_PINS_SRC = $(BUILD)/pins_$(BOARD).c +GEN_PINS_HDR = $(HEADER_BUILD)/pins.h CFLAGS += $(INC) -Wall -Werror -std=c99 -nostdlib -mthumb $(CFLAGS_MCU) -fsingle-precision-constant -Wdouble-promotion CFLAGS += -DMCU_$(MCU_SERIES) -D__$(CMSIS_MCU)__ @@ -179,7 +181,7 @@ DRIVERS_SRC_C += \ drivers/bus/softspi.c \ # List of sources for qstr extraction -SRC_QSTR += $(SRC_C) $(SHARED_SRC_C) $(SRC_CXX) +SRC_QSTR += $(SRC_C) $(SHARED_SRC_C) $(SRC_CXX) $(GEN_PINS_SRC) OBJ += $(PY_O) OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) @@ -190,6 +192,7 @@ OBJ += $(addprefix $(BUILD)/, $(ASF4_SRC_C:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(LIBM_SRC_C:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(DRIVERS_SRC_C:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(TINYUSB_SRC_C:.c=.o)) +OBJ += $(GEN_PINS_SRC:.c=.o) all: $(BUILD)/firmware.uf2 @@ -203,10 +206,14 @@ $(BUILD)/firmware.bin: $(BUILD)/firmware.elf $(BUILD)/firmware.uf2: $(BUILD)/firmware.bin $(Q)$(PYTHON) $(UF2CONV) -b $(TEXT0) -c -o $@ $< -pin_af.c: $(BUILD)/$(GEN_PIN_AF) | $(HEADER_BUILD) +# pin_af.c: $(BUILD)/$(GEN_PIN_AF) | $(HEADER_BUILD) -$(BUILD)/$(GEN_PIN_AF): $(PIN_AF_TABLE_CSV) $(BOARD_PINS) | $(HEADER_BUILD) - $(ECHO) "Create $@" - $(Q)$(PYTHON) $(MAKE_PIN_AF) --csv $(PIN_AF_TABLE_CSV) --board $(BOARD_PINS) --table $(BUILD)/$(GEN_PIN_AF) --mcu $(MCU_SERIES) +# Use a pattern rule here so that make will only call make-pins.py once to make +# both pins_$(BOARD).c and pins.h +$(BUILD)/%_$(BOARD).c $(HEADER_BUILD)/%.h: $(BOARD_DIR)/%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE) | $(HEADER_BUILD) + $(ECHO) "GEN $@" + $(Q)$(PYTHON) $(MAKE_PINS) --board-csv $(BOARD_PINS) --af-csv $(AF_FILE) --prefix $(PREFIX_FILE) \ + --output-source $(GEN_PINS_SRC) --output-header $(GEN_PINS_HDR) \ + --mcu $(MCU_SERIES) include $(TOP)/py/mkrules.mk diff --git a/ports/samd/boards/ADAFRUIT_FEATHER_M0_EXPRESS/pins.csv b/ports/samd/boards/ADAFRUIT_FEATHER_M0_EXPRESS/pins.csv index 6536277062..8993419a26 100644 --- a/ports/samd/boards/ADAFRUIT_FEATHER_M0_EXPRESS/pins.csv +++ b/ports/samd/boards/ADAFRUIT_FEATHER_M0_EXPRESS/pins.csv @@ -1,43 +1,38 @@ -# Pin rows contain Pin number and pin name. -# Pin rows start with PIN_ -# If the pin name is omitted, the pin number is added as name. -# Empty lines and lines starting with # are ignored +LED_TX,PA27 +LED_RX,PB03 -PIN_PA27,LED_TX -PIN_PB03,LED_RX +D0,PA11 +D1,PA10 +FLASH_MOSI,PA08 +FLASH_MISO,PA14 +FLASH_SCK,PA09 +D5,PA15 +D6,PA20 +D7,PA21 +D8,PA06 +D9,PA07 +D10,PA18 +D11,PA16 +D12,PA19 +D13,PA17 +A0,PA02 +A1,PB08 +A2,PB09 +A3,PA04 +A4,PA05 +A5,PB02 +TX,PB22 +RX,PB23 +SCL,PA23 +SDA,PA22 +MOSI,PB10 +MISO,PA12 +SCK,PB11 +NEOPIXEL,PA06 +FLASH_CS,PA13 -PIN_PA11,D0 -PIN_PA10,D1 -PIN_PA08,FLASH_MOSI -PIN_PA14,FLASH_MISO -PIN_PA09,FLASH_SCK -PIN_PA15,D5 -PIN_PA20,D6 -PIN_PA21,D7 -PIN_PA06,D8 -PIN_PA07,D9 -PIN_PA18,D10 -PIN_PA16,D11 -PIN_PA19,D12 -PIN_PA17,D13 -PIN_PA02,A0 -PIN_PB08,A1 -PIN_PB09,A2 -PIN_PA04,A3 -PIN_PA05,A4 -PIN_PB02,A5 -PIN_PB22,TX -PIN_PB23,RX -PIN_PA23,SCL -PIN_PA22,SDA -PIN_PB10,MOSI -PIN_PA12,MISO -PIN_PB11,SCK -PIN_PA06,NEOPIXEL -PIN_PA13,FLASH_CS +USB_DM,PA24 +USB_DP,PA25 -PIN_PA24,USB_DM -PIN_PA25,USB_DP - -PIN_PA30,SWCLK -PIN_PA31,SWDIO +SWCLK,PA30 +SWDIO,PA31 diff --git a/ports/samd/boards/ADAFRUIT_FEATHER_M4_EXPRESS/pins.csv b/ports/samd/boards/ADAFRUIT_FEATHER_M4_EXPRESS/pins.csv index df3373f246..ec7a8bc163 100644 --- a/ports/samd/boards/ADAFRUIT_FEATHER_M4_EXPRESS/pins.csv +++ b/ports/samd/boards/ADAFRUIT_FEATHER_M4_EXPRESS/pins.csv @@ -1,44 +1,39 @@ -# Pin rows contain Pin number and pin name. -# Pin rows start with PIN_ -# If the pin name is omitted, the pin number is added as name. -# Empty lines and lines not starting with PIN_ are ignored +D0,PB17 +D1,PB16 +D4,PA14 +D5,PA16 +D6,PA18 +D8,PB03 +D9,PA19 +D10,PA20 +D11,PA21 +D12,PA22 +D13,PA23 +A0,PA02 +A1,PA05 +A2,PB08 +A3,PB09 +A4,PA04 +A5,PB06 +SCL,PA13 +SDA,PA12 +MOSI,PB23 +MISO,PB22 +SCK,PA17 +VDIV,PB01 +AREF,PA03 +NEOPIXEL,PB03 -PIN_PB17,D0 -PIN_PB16,D1 -PIN_PA14,D4 -PIN_PA16,D5 -PIN_PA18,D6 -PIN_PB03,D8 -PIN_PA19,D9 -PIN_PA20,D10 -PIN_PA21,D11 -PIN_PA22,D12 -PIN_PA23,D13 -PIN_PA02,A0 -PIN_PA05,A1 -PIN_PB08,A2 -PIN_PB09,A3 -PIN_PA04,A4 -PIN_PB06,A5 -PIN_PA13,SCL -PIN_PA12,SDA -PIN_PB23,MOSI -PIN_PB22,MISO -PIN_PA17,SCK -PIN_PB01,VDIV -PIN_PA03,AREF -PIN_PB03,NEOPIXEL +QSPI_CS,PB11 +QSPI_SCK,PB10 +QSPI_D0,PA08 +QSPI_D1,PA09 +QSPI_D2,PA10 +QSPI_D3,PA11 -PIN_PB11,QSPI_CS -PIN_PB10,QSPI_SCK -PIN_PA08,QSPI_D0 -PIN_PA09,QSPI_D1 -PIN_PA10,QSPI_D2 -PIN_PA11,QSPI_D3 +USB_DM,PA24 +USB_DP,PA25 +USB_SOF,PA23 -PIN_PA24,USB_DM -PIN_PA25,USB_DP -PIN_PA26,USB_SOF - -PIN_PA30,SWCLK -PIN_PA31,SWDIO +SWCLK,PA30 +SWDIO,PA31 diff --git a/ports/samd/boards/ADAFRUIT_ITSYBITSY_M0_EXPRESS/pins.csv b/ports/samd/boards/ADAFRUIT_ITSYBITSY_M0_EXPRESS/pins.csv index 04b1a717bd..845cefb8a9 100644 --- a/ports/samd/boards/ADAFRUIT_ITSYBITSY_M0_EXPRESS/pins.csv +++ b/ports/samd/boards/ADAFRUIT_ITSYBITSY_M0_EXPRESS/pins.csv @@ -1,40 +1,35 @@ -# Pin rows contain Pin number and pin name. -# Pin rows start with PIN_ -# If the pin name is omitted, the pin number is added as name. -# Empty lines and lines not starting with PIN_ are ignored +D0,PA11 +D1,PA10 +D2,PA14 +D3,PA09 +D4,PA08 +D5,PA15 +D7,PA21 +D9,PA07 +D10,PA18 +D11,PA16 +D12,PA19 +D13,PA17 +A0,PA02 +A1,PB08 +A2,PB09 +A3,PA04 +A4,PA05 +A5,PB02 +SDA,PA22 +SCL,PA23 +MOSI,PB10 +MISO,PA12 +SCK,PB11 +DOTSTAR_CLK,PA00 +DOTSTAR_DATA,PA01 +FLASH_MOSI,PB22 +FLASH_MISO,PB03 +FLASH_SCK,PB23 +FLASH_CS,PA27 -PIN_PA11,D0 -PIN_PA10,D1 -PIN_PA14,D2 -PIN_PA09,D3 -PIN_PA08,D4 -PIN_PA15,D5 -PIN_PA21,D7 -PIN_PA07,D9 -PIN_PA18,D10 -PIN_PA16,D11 -PIN_PA19,D12 -PIN_PA17,D13 -PIN_PA02,A0 -PIN_PB08,A1 -PIN_PB09,A2 -PIN_PA04,A3 -PIN_PA05,A4 -PIN_PB02,A5 -PIN_PA22,SDA -PIN_PA23,SCL -PIN_PB10,MOSI -PIN_PA12,MISO -PIN_PB11,SCK -PIN_PA00,DOTSTAR_CLK -PIN_PA01,DOTSTAR_DATA -PIN_PB22,FLASH_MOSI -PIN_PB03,FLASH_MISO -PIN_PB23,FLASH_SCK -PIN_PA27,FLASH_CS +USB_DM,PA24 +USB_DP,PA25 -PIN_PA24,USB_DM -PIN_PA25,USB_DP - -PIN_PA30,SWCLK -PIN_PA31,SWDIO +SWCLK,PA30 +SWDIO,PA31 diff --git a/ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/pins.csv b/ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/pins.csv index b63a1f4b13..c82beccfa2 100644 --- a/ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/pins.csv +++ b/ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/pins.csv @@ -1,44 +1,39 @@ -# Pin rows contain Pin number and pin name. -# Pin rows start with PIN_ -# If the pin name is omitted, the pin number is added as name. -# Empty lines and lines not starting with PIN_ are ignored +D0,PA16 +D1,PA17 +D2,PA07 +D3,PB22 +D4,PA14 +D5,PA15 +D7,PA18 +D9,PA19 +D10,PA20 +D11,PA21 +D12,PA23 +D13,PA22 +A0,PA02 +A1,PA05 +A2,PB08 +A3,PB09 +A4,PA04 +A5,PA06 +SDA,PA12 +SCL,PA13 +MOSI,PA00 +MISO,PB23 +SCK,PA01 +DOTSTAR_CLK,PB02 +DOTSTAR_DATA,PB03 -PIN_PA16,D0 -PIN_PA17,D1 -PIN_PA07,D2 -PIN_PB22,D3 -PIN_PA14,D4 -PIN_PA15,D5 -PIN_PA18,D7 -PIN_PA19,D9 -PIN_PA20,D10 -PIN_PA21,D11 -PIN_PA23,D12 -PIN_PA22,D13 -PIN_PA02,A0 -PIN_PA05,A1 -PIN_PB08,A2 -PIN_PB09,A3 -PIN_PA04,A4 -PIN_PA06,A5 -PIN_PA12,SDA -PIN_PA13,SCL -PIN_PA00,MOSI -PIN_PB23,MISO -PIN_PA01,SCK -PIN_PB02,DOTSTAR_CLK -PIN_PB03,DOTSTAR_DATA +QSPI_CS,PB11 +QSPI_SCK,PB10 +QSPI_D0,PA08 +QSPI_D1,PA09 +QSPI_D2,PA10 +QSPI_D3,PA11 -PIN_PB11,QSPI_CS -PIN_PB10,QSPI_SCK -PIN_PA08,QSPI_D0 -PIN_PA09,QSPI_D1 -PIN_PA10,QSPI_D2 -PIN_PA11,QSPI_D3 +USB_DM,PA24 +USB_DP,PA25 +USB_SOF,PA23 -PIN_PA24,USB_DM -PIN_PA25,USB_DP -PIN_PA26,USB_SOF - -PIN_PA30,SWCLK -PIN_PA31,SWDIO +SWCLK,PA30 +SWDIO,PA31 diff --git a/ports/samd/boards/ADAFRUIT_METRO_M4_EXPRESS/pins.csv b/ports/samd/boards/ADAFRUIT_METRO_M4_EXPRESS/pins.csv index 0bda767600..cee4bf02b7 100644 --- a/ports/samd/boards/ADAFRUIT_METRO_M4_EXPRESS/pins.csv +++ b/ports/samd/boards/ADAFRUIT_METRO_M4_EXPRESS/pins.csv @@ -1,66 +1,61 @@ -# Pin rows contain Pin number and pin name. -# Pin rows start with PIN_ -# If the pin name is omitted, the pin number is added as name. -# Empty lines and lines not starting with PIN_ are ignored +A0,PA02 +A1,PA05 +A2,PA06 +A3,PB00 +A4,PB08 +A5,PB09 +AREF,PA03 -PIN_PA02,A0 -PIN_PA05,A1 -PIN_PA06,A2 -PIN_PB00,A3 -PIN_PB08,A4 -PIN_PB09,A5 -PIN_PA03,AREF +D0,PA23 +D1,PA22 +D2,PB17 +D3,PB16 +D4,PB13 +D5,PB14 +D6,PB15 +D7,PB12 +D8,PA21 +D9,PA20 +D10,PA18 +D11,PA19 +D12,PA17 +D13,PA16 -PIN_PA23,D0 -PIN_PA22,D1 -PIN_PB17,D2 -PIN_PB16,D3 -PIN_PB13,D4 -PIN_PB14,D5 -PIN_PB15,D6 -PIN_PB12,D7 -PIN_PA21,D8 -PIN_PA20,D9 -PIN_PA18,D10 -PIN_PA19,D11 -PIN_PA17,D12 -PIN_PA16,D13 +SDA,PB02 +SCL,PB03 -PIN_PB02,SDA -PIN_PB03,SCL +SCK,PA13 +MOSI,PA12 +MISO,PA14 -PIN_PA13,SCK -PIN_PA12,MOSI -PIN_PA14,MISO - -PIN_PB22,NEOPIXEL -PIN_PB06,RXLED -PIN_PB07,TXLED +NEOPIXEL,PB22 +RXLED,PB06 +TXLED,PB07 # Airlift -PIN_PB05,ESP_RESET -PIN_PB04,ESP_BUSY -PIN_PA15,ESP_CS -PIN_PB01,ESP_GPIO0 -PIN_PA07,ESP_RX -PIN_PA04,ESP_TX -PIN_PB23,ESP_RTS +ESP_RESET,PB05 +ESP_BUSY,PB04 +ESP_CS,PA15 +ESP_GPIO0,PB01 +ESP_RX,PA07 +ESP_TX,PA04 +ESP_RTS,PB23 # QSPI flash -PIN_PA08,FLASH_MOSI -PIN_PA09,FLASH_MISO -PIN_PA10,FLASH_WP -PIN_PA11,FLASH_HOLD -PIN_PB10,FLASH_SCK -PIN_PB11,FLASH_CS +FLASH_MOSI,PA08 +FLASH_MISO,PA09 +FLASH_WP,PA10 +FLASH_HOLD,PA11 +FLASH_SCK,PB10 +FLASH_CS,PB11 # USB -PIN_PA24,USB_DM -PIN_PA25,USB_DP -PIN_PA26,USB_SOF -PIN_PA17,USB_HOSTEN +USB_DM,PA24 +USB_DP,PA25 +USB_SOF,PA23 +#USB_HOSTEN,PA17 # JLink -PIN_PA30,SWCLK -PIN_PA31,SWDIO -PIN_PB30,SWO +SWCLK,PA30 +SWDIO,PA31 +SWO,PB30 diff --git a/ports/samd/boards/ADAFRUIT_TRINKET_M0/pins.csv b/ports/samd/boards/ADAFRUIT_TRINKET_M0/pins.csv index b5f1c9801b..47306f8de1 100644 --- a/ports/samd/boards/ADAFRUIT_TRINKET_M0/pins.csv +++ b/ports/samd/boards/ADAFRUIT_TRINKET_M0/pins.csv @@ -1,20 +1,15 @@ -# Pin rows contain Pin number and pin name. -# Pin rows start with PIN_ -# If the pin name is omitted, the pin number is added as name. -# Empty lines and lines not starting with PIN_ are ignored +D0,PA08 +D1,PA02 +D2,PA09 +D3,PA07 +D4,PA06 +DOTSTAR_DATA,PA00 +DOTSTAR_CLK,PA01 -PIN_PA08,D0 -PIN_PA02,D1 -PIN_PA09,D2 -PIN_PA07,D3 -PIN_PA06,D4 -PIN_PA00,DOTSTAR_DATA -PIN_PA01,DOTSTAR_CLK +LED,PA10 -PIN_PA10,LED +USB_DM,PA24 +USB_DP,PA25 -PIN_PA24,USB_DM -PIN_PA25,USB_DP - -PIN_PA30,SWCLK -PIN_PA31,SWDIO +SWCLK,PA30 +SWDIO,PA31 diff --git a/ports/samd/boards/MINISAM_M4/pins.csv b/ports/samd/boards/MINISAM_M4/pins.csv index 3ea5f85cba..3c1ab4c603 100644 --- a/ports/samd/boards/MINISAM_M4/pins.csv +++ b/ports/samd/boards/MINISAM_M4/pins.csv @@ -1,43 +1,38 @@ -# Pin rows contain Pin number and pin name. -# Pin rows start with PIN_ -# If the pin name is omitted, the pin number is added as name. -# Empty lines and lines not starting with PIN_ are ignored +A0,PA02 +A1,PB08 +A2,PB09 +A3,PA04 +A4,PA05 +A5,PA06 +A6,PA07 +RX,PA16 +TX,PA17 +D3,PA19 +D4,PA20 +D5,PA21 +LED,PA15 +BUTTON,PA00 +AREF,PA03 +SDA,PA12 +SCL,PA13 +MOSI,PB22 +MISO,PB23 +SCK,PA01 +DOTSTAR_DATA,PB03 +DOTSTAR_CLK,PB02 -PIN_PA02,A0 -PIN_PB08,A1 -PIN_PB09,A2 -PIN_PA04,A3 -PIN_PA05,A4 -PIN_PA06,A5 -PIN_PA07,A6 -PIN_PA16,RX -PIN_PA17,TX -PIN_PA19,D3 -PIN_PA20,D4 -PIN_PA21,D5 -PIN_PA15,LED -PIN_PA00,BUTTON -PIN_PA03,AREF -PIN_PA12,SDA -PIN_PA13,SCL -PIN_PB22,MOSI -PIN_PB23,MISO -PIN_PA01,SCK -PIN_PB03,DOTSTAR_DATA -PIN_PB02,DOTSTAR_CLK +QSPI_CS,PB11 +QSPI_SCK,PB10 +QSPI_D0,PA08 +QSPI_D1,PA09 +QSPI_D2,PA10 +QSPI_D3,PA11 -PIN_PB11,QSPI_CS -PIN_PB10,QSPI_SCK -PIN_PA08,QSPI_D0 -PIN_PA09,QSPI_D1 -PIN_PA10,QSPI_D2 -PIN_PA11,QSPI_D3 +LED,PA15 -PIN_PA15,LED +USB_DM,PA24 +USB_DP,PA25 +USB_SOF,PA23 -PIN_PA24,USB_DM -PIN_PA25,USB_DP -PIN_PA26,USB_SOF - -PIN_PA30,SWCLK -PIN_PA31,SWDIO +SWCLK,PA30 +SWDIO,PA31 diff --git a/ports/samd/boards/SAMD21_XPLAINED_PRO/pins.csv b/ports/samd/boards/SAMD21_XPLAINED_PRO/pins.csv index 5990c373bf..69d0c136d0 100644 --- a/ports/samd/boards/SAMD21_XPLAINED_PRO/pins.csv +++ b/ports/samd/boards/SAMD21_XPLAINED_PRO/pins.csv @@ -1,60 +1,55 @@ -# Pin rows contain Pin number and pin name. -# Pin rows start with PIN_ -# If the pin name is omitted, the pin number is added as name. -# Empty lines and lines not starting with PIN_ are ignored - # EXT1 -PIN_PB00,EXT1_PIN3 -PIN_PB01,EXT1_PIN4 -PIN_PB06,EXT1_PIN5 -PIN_PB07,EXT1_PIN6 -PIN_PB02,EXT1_PIN7 -PIN_PB03,EXT1_PIN8 -PIN_PB04,EXT1_PIN9 -PIN_PB05,EXT1_PIN10 -PIN_PA08,EXT1_PIN11 -PIN_PA09,EXT1_PIN12 -PIN_PB09,EXT1_PIN13 -PIN_PB08,EXT1_PIN14 -PIN_PA05,EXT1_PIN15 -PIN_PA06,EXT1_PIN16 -PIN_PA04,EXT1_PIN17 -PIN_PA07,EXT1_PIN18 +EXT1_PIN3,PB00 +EXT1_PIN4,PB01 +EXT1_PIN5,PB06 +EXT1_PIN6,PB07 +EXT1_PIN7,PB02 +EXT1_PIN8,PB03 +EXT1_PIN9,PB04 +EXT1_PIN10,PB05 +EXT1_PIN11,PA08 +EXT1_PIN12,PA09 +EXT1_PIN13,PB09 +EXT1_PIN14,PB08 +EXT1_PIN15,PA05 +EXT1_PIN16,PA06 +EXT1_PIN17,PA04 +EXT1_PIN18,PA07 # EXT2 -PIN_PA10,EXT2_PIN3 -PIN_PA11,EXT2_PIN4 -PIN_PA20,EXT2_PIN5 -PIN_PA21,EXT2_PIN6 -PIN_PB12,EXT2_PIN7 -PIN_PB13,EXT2_PIN8 -PIN_PB14,EXT2_PIN9 -PIN_PB15,EXT2_PIN10 -PIN_PB11,EXT2_PIN13 -PIN_PB10,EXT2_PIN14 -PIN_PA17,EXT2_PIN15 -PIN_PA18,EXT2_PIN16 -PIN_PA16,EXT2_PIN17 -PIN_PA19,EXT2_PIN18 +EXT2_PIN3,PA10 +EXT2_PIN4,PA11 +EXT2_PIN5,PA20 +EXT2_PIN6,PA21 +EXT2_PIN7,PB12 +EXT2_PIN8,PB13 +EXT2_PIN9,PB14 +EXT2_PIN10,PB15 +EXT2_PIN13,PB11 +EXT2_PIN14,PB10 +EXT2_PIN15,PA17 +EXT2_PIN16,PA18 +EXT2_PIN17,PA16 +EXT2_PIN18,PA19 # EXT3 -PIN_PA02,EXT3_PIN3 -PIN_PA03,EXT3_PIN4 -PIN_PA15,EXT3_PIN6 -PIN_PA12,EXT3_PIN7 -PIN_PA13,EXT3_PIN8 -PIN_PA28,EXT3_PIN9 -PIN_PA27,EXT3_PIN10 -PIN_PB17,EXT3_PIN15 -PIN_PB22,EXT3_PIN16 -PIN_PB16,EXT3_PIN17 -PIN_PB23,EXT3_PIN18 +EXT3_PIN3,PA02 +EXT3_PIN4,PA03 +EXT3_PIN6,PA15 +EXT3_PIN7,PA12 +EXT3_PIN8,PA13 +EXT3_PIN9,PA28 +EXT3_PIN10,PA27 +EXT3_PIN15,PB17 +EXT3_PIN16,PB22 +EXT3_PIN17,PB16 +EXT3_PIN18,PB23 -PIN_PB30,LED +LED,PB30 -PIN_PA24,USB_DM -PIN_PA25,USB_DP +USB_DM,PA24 +USB_DP,PA25 -PIN_PA30,SWCLK -PIN_PA31,SWDIO +SWCLK,PA30 +SWDIO,PA31 diff --git a/ports/samd/boards/SEEED_WIO_TERMINAL/pins.csv b/ports/samd/boards/SEEED_WIO_TERMINAL/pins.csv index c32108b9f7..f263253cba 100644 --- a/ports/samd/boards/SEEED_WIO_TERMINAL/pins.csv +++ b/ports/samd/boards/SEEED_WIO_TERMINAL/pins.csv @@ -1,76 +1,71 @@ -# Pin rows contain Pin number and pin name. -# Pin rows start with PIN_ -# If the pin name is omitted, the pin number is added as name. -# Empty lines and lines not starting with PIN_ are ignored +A0_D0,PB08 +A1_D1,PB09 +A2_D2,PA07 +A3_D3,PB04 +A4_D4,PB05 +A5_D5,PB06 +A6_D6,PA04 +A7_D7,PB07 +A8_D8,PA06 +SWITCH_X,PD08 +SWITCH_Y,PD09 +SWITCH_Z,PD10 +SWITCH_B,PD12 +SWITCH_U,PD20 +BUTTON_1,PC26 +BUTTON_2,PC27 +BUTTON_3,PC28 +ENABLE_5V,PC14 +ENABLE_3V3,PC15 +TX,PB26 +RX,PB27 +SDA0,PA13 +SCL0,PA12 +SDA1,PA17 +SCL1,PA16 +MOSI,PB02 +MISO,PB00 +SCK,PB03 +CS,PB01 +GPCLK0,PB15 +GPCLK1,PB12 +GPCLK2,PB13 +SD_MOSI,PC16 +SD_MISO,PC18 +SD_SCK,PC17 +SD_CS,PC19 +SD_DET,PD21 +I2S_LRCLK,PA20 +I2S_SDIN,PA21 +I2S_SDOUT,PA22 +I2C_BCLK,PB16 +LCD_MISO,PB18 +LCD_MOSI,PB19 +LCD_SCK,PB20 +LCD_CS,PB21 +LCD_BACKLIGHT,PC05 +LCD_D_C,PC06 +LCD_RESET,PC07 +LCD_XL,PC10 +LCD_YU,PC11 +LCD_XR,PC12 +LCD_YD,PC13 +MIC,PC30 +BUZZER,PD11 -PIN_PB08,A0_D0 -PIN_PB09,A1_D1 -PIN_PA07,A2_D2 -PIN_PB04,A3_D3 -PIN_PB05,A4_D4 -PIN_PB06,A5_D5 -PIN_PA04,A6_D6 -PIN_PB07,A7_D7 -PIN_PA06,A8_D8 -PIN_PD08,SWITCH_X -PIN_PD09,SWITCH_Y -PIN_PD10,SWITCH_Z -PIN_PD12,SWITCH_B -PIN_PD20,SWITCH_U -PIN_PC26,BUTTON_1 -PIN_PC27,BUTTON_2 -PIN_PC28,BUTTON_3 -PIN_PC14,ENABLE_5V -PIN_PC15,ENABLE_3V3 -PIN_PB26,TX -PIN_PB27,RX -PIN_PA13,SDA0 -PIN_PA12,SCL0 -PIN_PA17,SDA1 -PIN_PA16,SCL1 -PIN_PB02,MOSI -PIN_PB00,MISO -PIN_PB03,SCK -PIN_PB01,CS -PIN_PB15,GPCLK0 -PIN_PB12,GPCLK1 -PIN_PB13,GPCLK2 -PIN_PC16,SD_MOSI -PIN_PC18,SD_MISO -PIN_PC17,SD_SCK -PIN_PC19,SD_CS -PIN_PD21,SD_DET -PIN_PA20,I2S_LRCLK -PIN_PA21,I2S_SDIN -PIN_PA22,I2S_SDOUT -PIN_PB16,I2C_BCLK -PIN_PB18,LCD_MISO -PIN_PB19,LCD_MOSI -PIN_PB20,LCD_SCK -PIN_PB21,LCD_CS -PIN_PC05,LCD_BACKLIGHT -PIN_PC06,LCD_D_C -PIN_PC07,LCD_RESET -PIN_PC10,LCD_XL -PIN_PC11,LCD_YU -PIN_PC12,LCD_XR -PIN_PC13,LCD_YD -PIN_PC30,MIC -PIN_PD11,BUZZER +QSPI_CS,PB11 +QSPI_SCK,PB10 +QSPI_D0,PA08 +QSPI_D1,PA09 +QSPI_D2,PA10 +QSPI_D3,PA11 -PIN_PB11,QSPI_CS -PIN_PB10,QSPI_SCK -PIN_PA08,QSPI_D0 -PIN_PA09,QSPI_D1 -PIN_PA10,QSPI_D2 -PIN_PA11,QSPI_D3 +LED_BLUE,PA15 +LED_LCD,PC05 -PIN_PA15,LED_BLUE -PIN_PC05,LED_LCD +USB_DM,PA24 +USB_DP,PA25 +USB_SOF,PA23 -PIN_PA24,USB_DM -PIN_PA25,USB_DP -PIN_PA26,USB_SOF - -PIN_PA30,SWCLK -PIN_PA31,SWDIO +SWCLK,PA30 +SWDIO,PA31 diff --git a/ports/samd/boards/SEEED_XIAO_SAMD21/pins.csv b/ports/samd/boards/SEEED_XIAO_SAMD21/pins.csv index 2f1c180e8a..969c60028b 100644 --- a/ports/samd/boards/SEEED_XIAO_SAMD21/pins.csv +++ b/ports/samd/boards/SEEED_XIAO_SAMD21/pins.csv @@ -1,26 +1,21 @@ -# Pin rows contain Pin number and pin name. -# Pin rows start with PIN_ -# If the pin name is omitted, the pin number is added as name. -# Empty lines and lines not starting with PIN_ are ignored +A0_D0,PA02 +A1_D1,PA04 +A2_D2,PA10 +A3_D3,PA11 +A4_D4,PA08 +A5_D5,PA09 +A6_D6,PB08 +A7_D7,PB09 +A8_D8,PA07 +A9_D9,PA05 +A10_D10,PA06 -PIN_PA02,A0_D0 -PIN_PA04,A1_D1 -PIN_PA10,A2_D2 -PIN_PA11,A3_D3 -PIN_PA08,A4_D4 -PIN_PA09,A5_D5 -PIN_PB08,A6_D6 -PIN_PB09,A7_D7 -PIN_PA07,A8_D8 -PIN_PA05,A9_D9 -PIN_PA06,A10_D10 +USER_LED,PA17 +RX_LED,PA18 +TX_LED,PA19 -PIN_PA17,USER_LED -PIN_PA18,RX_LED -PIN_PA19,TX_LED +USB_DM,PA24 +USB_DP,PA25 -PIN_PA24,USB_DM -PIN_PA25,USB_DP - -PIN_PA30,SWCLK -PIN_PA31,SWDIO +SWCLK,PA30 +SWDIO,PA31 diff --git a/ports/samd/boards/SPARKFUN_SAMD51_THING_PLUS/pins.csv b/ports/samd/boards/SPARKFUN_SAMD51_THING_PLUS/pins.csv index d807b505a7..0ae269724d 100644 --- a/ports/samd/boards/SPARKFUN_SAMD51_THING_PLUS/pins.csv +++ b/ports/samd/boards/SPARKFUN_SAMD51_THING_PLUS/pins.csv @@ -1,41 +1,36 @@ -# Pin rows contain Pin number and pin name. -# Pin rows start with PIN_ -# If the pin name is omitted, the pin number is added as name. -# Empty lines and lines not starting with PIN_ are ignored +D0,PA13 +D1,PA12 +D4,PA06 +D5,PA15 +D6,PA20 +D7,PA21 +D9,PA07 +D10,PA18 +D11,PA16 +D12,PA19 +D13,PA17 +A0,PA02 +A1,PB08 +A2,PB09 +A3,PA04 +A4,PA05 +A5,PB02 +SDA,PA22 +SCL,PA23 +MOSI,PB12 +MISO,PB11 +SCK,PB13 +FLASH_MOSI,PA08 +FLASH_SCK,PA09 +FLASH_CS,PA10 +FLASH_MISO,PA11 -PIN_PA13,D0 -PIN_PA12,D1 -PIN_PA06,D4 -PIN_PA15,D5 -PIN_PA20,D6 -PIN_PA21,D7 -PIN_PA07,D9 -PIN_PA18,D10 -PIN_PA16,D11 -PIN_PA19,D12 -PIN_PA17,D13 -PIN_PA02,A0 -PIN_PB08,A1 -PIN_PB09,A2 -PIN_PA04,A3 -PIN_PA05,A4 -PIN_PB02,A5 -PIN_PA22,SDA -PIN_PA23,SCL -PIN_PB12,MOSI -PIN_PB11,MISO -PIN_PB13,SCK -PIN_PA08,FLASH_MOSI -PIN_PA09,FLASH_SCK -PIN_PA10,FLASH_CS -PIN_PA11,FLASH_MISO +RXLED,PB03 +TXLED,PA27 -PIN_PB03,RXLED -PIN_PA27,TXLED +USB_DM,PA24 +USB_DP,PA25 +USB_SOF,PA23 -PIN_PA24,USB_DM -PIN_PA25,USB_DP -PIN_PA26,USB_SOF - -PIN_PA30,SWCLK -PIN_PA31,SWDIO +SWCLK,PA30 +SWDIO,PA31 diff --git a/ports/samd/boards/make-pin-table.py b/ports/samd/boards/make-pin-table.py deleted file mode 100644 index a187f2a711..0000000000 --- a/ports/samd/boards/make-pin-table.py +++ /dev/null @@ -1,201 +0,0 @@ -#!/usr/bin/env python -"""Generates the pin_cap table file for the SAMD port.""" - -from __future__ import print_function - -import argparse -import sys -import csv - -table_header = """// This file was automatically generated by make-pin-cap.py -// - -// The Pin objects which are available on a board - -""" - - -class Pins: - def __init__(self): - self.board_pins = [] # list of pin objects - self.pin_names = {} - - def parse_csv_file(self, filename): - with open(filename, "r") as csvfile: - rows = csv.reader(csvfile) - for row in rows: - # Pin numbers must start with "PA", "PB", "PC" or "PD" - if len(row) > 0 and row[0].strip().upper()[:2] in ("PA", "PB", "PC", "PD"): - self.board_pins.append(row) - - def parse_pin_file(self, filename): - with open(filename, "r") as csvfile: - rows = csv.reader(csvfile, skipinitialspace=True) - for row in rows: - # Pin numbers must start with "PIN_" - # LED numbers must start with "LED_" - if len(row) > 0: - # for compatibility, map LED_ to PIN_ - if row[0].startswith("LED_"): - row[0] = "PIN_" + row[0][4:] - if row[0].startswith("PIN_"): - if len(row) == 1: - self.pin_names[row[0]] = (row[0][4:], "{&machine_pin_type}") - else: - self.pin_names[row[0]] = (row[1], "{&machine_pin_type}") - - def print_table(self, table_filename, mcu_name): - with open(table_filename, "wt") as table_file: - table_file.write(table_header) - - # Create the Pin objects - - if mcu_name == "SAMD21": - for row in self.board_pins: - pin = "PIN_" + row[0].upper() - table_file.write("#ifdef " + pin + "\n") - table_file.write("static const machine_pin_obj_t %s_obj = " % pin) - eic = row[1] if row[1] else "0xff" - adc = row[2] if row[2] else "0xff" - if pin in self.pin_names: - name = "MP_QSTR_%s" % self.pin_names[pin][0] - type = self.pin_names[pin][1] - else: - name = "MP_QSTR_" - type = "{&machine_pin_type}" - table_file.write("{%s, %s, %s, %s, %s" % (type, pin, name, eic, adc)) - for cell in row[3:]: - if cell: - table_file.write( - ", 0x%s" % cell if len(cell) == 2 else ", 0x0%s" % cell - ) - else: - table_file.write(", 0xff") - table_file.write("};\n") - table_file.write("#endif\n") - else: - for row in self.board_pins: - pin = "PIN_" + row[0].upper() - table_file.write("#ifdef " + pin + "\n") - table_file.write("const machine_pin_obj_t %s_obj = " % pin) - eic = row[1] if row[1] else "0xff" - adc0 = row[2] if row[2] else "0xff" - adc1 = row[3] if row[3] else "0xff" - if pin in self.pin_names: - name = "MP_QSTR_%s" % self.pin_names[pin][0] - type = self.pin_names[pin][1] - else: - name = "MP_QSTR_" - type = "{&machine_pin_type}" - table_file.write( - "{%s, %s, %s, %s, %s, %s" % (type, pin, name, eic, adc0, adc1) - ) - for cell in row[4:]: - if cell: - table_file.write( - ", 0x%s" % cell if len(cell) == 2 else ", 0x0%s" % cell - ) - else: - table_file.write(", 0xff") - table_file.write("};\n") - table_file.write("#endif\n") - - # Create the Pin table - - table_file.write("\n// The table of references to the pin objects.\n\n") - table_file.write("static const machine_pin_obj_t *pin_af_table[] = {\n") - for row in self.board_pins: - pin = "PIN_" + row[0].upper() - table_file.write(" #ifdef " + pin + "\n") - table_file.write(" &%s_obj,\n" % pin) - table_file.write(" #endif\n") - table_file.write("};\n") - - # Create the CPU pins dictionary table - - table_file.write("\n#if MICROPY_PY_MACHINE_PIN_BOARD_CPU\n") - table_file.write("\n// The cpu pins dictionary\n\n") - table_file.write( - "STATIC const mp_rom_map_elem_t pin_cpu_pins_locals_dict_table[] = {\n" - ) - for row in self.board_pins: - pin = "PIN_" + row[0].upper() - table_file.write(" #ifdef " + pin + "\n") - table_file.write( - " { MP_ROM_QSTR(MP_QSTR_%s), MP_ROM_PTR(&%s_obj) },\n" - % (row[0].upper(), pin) - ) - table_file.write(" #endif\n") - table_file.write("};\n") - table_file.write( - "MP_DEFINE_CONST_DICT(machine_pin_cpu_pins_locals_dict, pin_cpu_pins_locals_dict_table);\n" - ) - - # Create the board pins dictionary table - - table_file.write("\n// The board pins dictionary\n\n") - table_file.write( - "STATIC const mp_rom_map_elem_t pin_board_pins_locals_dict_table[] = {\n" - ) - for row in self.board_pins: - pin = "PIN_" + row[0].upper() - if pin in self.pin_names: - table_file.write(" #ifdef " + pin + "\n") - table_file.write( - " { MP_ROM_QSTR(MP_QSTR_%s), MP_ROM_PTR(&%s_obj) },\n" - % (self.pin_names[pin][0], pin) - ) - table_file.write(" #endif\n") - table_file.write("};\n") - table_file.write( - "MP_DEFINE_CONST_DICT(machine_pin_board_pins_locals_dict, pin_board_pins_locals_dict_table);\n" - ) - table_file.write("#endif\n") - - -def main(): - parser = argparse.ArgumentParser( - prog="make-pin-af.py", - usage="%(prog)s [options] [command]", - description="Generate MCU-specific pin cap table file", - ) - parser.add_argument( - "-c", - "--csv", - dest="csv_filename", - help="Specifies the pin-af-table.csv filename", - ) - parser.add_argument( - "-b", - "--board", - dest="pin_filename", - help="Specifies the pins.csv filename", - ) - parser.add_argument( - "-t", - "--table", - dest="table_filename", - help="Specifies the name of the generated pin cap table file", - ) - parser.add_argument( - "-m", - "--mcu", - dest="mcu_name", - help="Specifies type of the MCU (SAMD21 or SAMD51)", - ) - args = parser.parse_args(sys.argv[1:]) - - pins = Pins() - - if args.csv_filename: - pins.parse_csv_file(args.csv_filename) - - if args.pin_filename: - pins.parse_pin_file(args.pin_filename) - - if args.table_filename: - pins.print_table(args.table_filename, args.mcu_name) - - -if __name__ == "__main__": - main() diff --git a/ports/samd/boards/make-pins.py b/ports/samd/boards/make-pins.py new file mode 100644 index 0000000000..302eeae624 --- /dev/null +++ b/ports/samd/boards/make-pins.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python + + +from collections import defaultdict, namedtuple +import os +import re +import sys + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../../tools")) +import boardgen + + +# These are the columns of the af.csv as well as the arguments to the PIN() +# macro in samd_prefix.c. +AFS = { + "SAMD21": ["eic", "adc0", "sercom1", "sercom2", "tcc1", "tcc2"], + "SAMD51": ["eic", "adc0", "adc1", "sercom1", "sercom2", "tc", "tcc1", "tcc2"], +} + + +class SamdPin(boardgen.Pin): + def __init__(self, cpu_pin_name): + super().__init__(cpu_pin_name) + + # P (already verified by validate_cpu_pin_name). + self._port = cpu_pin_name[1] + self._pin = int(cpu_pin_name[2:]) + + # List of uint8 values from the af.csv. Default to 0xff if not + # present. + self._afs = defaultdict(lambda: 0xFF) + + # Called for each AF defined in the csv file for this pin. + def add_af(self, af_idx, af_name, af): + # samd-specific: Any pin in the af.csv is implicitly part of the board + # pins.csv and will therefore be in the Pin.cpu dict. This is + # equivalent to adding `,Pxy` to the board.csv for every pin in the + # af.csv. + self._available = True + + name = AFS[self._generator.args.mcu][af_idx] + assert name == af_name.lower() + if name == "eic" or name.startswith("adc"): + # eic and adc columns are decimal. + v = int(af) + else: + # hex, high nibble is device number, low nibble is pad number. + v = int(af, 16) + self._afs[AFS[self._generator.args.mcu][af_idx]] = v + + # Use the PIN() macro defined in samd_prefix.c for defining the pin + # objects. + def definition(self): + # SAMD21: PIN(p_name, p_eic, p_adc0, p_sercom1, p_sercom2, p_tcc1, p_tcc2) + # SAMD51: PIN(p_name, p_eic, p_adc0, p_adc1, p_sercom1, p_sercom2, p_tc, p_tcc1, p_tcc2) + return "PIN({:s}, {})".format( + self.name(), + ", ".join("0x{:02x}".format(self._afs[x]) for x in AFS[self._generator.args.mcu]), + ) + + # Wrap all definitions to ensure that the ASF defines this pin for this + # particular MCU. + def enable_macro(self): + return "defined(PIN_{})".format(self.name()) + + # SAMD cpu names must be "P", with zero-prefixed two-digit . + @staticmethod + def validate_cpu_pin_name(cpu_pin_name): + boardgen.Pin.validate_cpu_pin_name(cpu_pin_name) + + if not re.match("P[A-D][0-9][0-9]$", cpu_pin_name): + raise boardgen.PinGeneratorError("Invalid cpu pin name '{}'".format(cpu_pin_name)) + + +class SamdPinGenerator(boardgen.PinGenerator): + def __init__(self): + # Use custom pin type above, and also enable the --af-csv argument so + # that add_af gets called on each pin. + super().__init__( + pin_type=SamdPin, + enable_af=True, + ) + + # Override the default implementation just to change the default arguments + # (extra header row, skip first column). + def parse_af_csv(self, filename): + return super().parse_af_csv(filename, header_rows=1, pin_col=0, af_col=1) + + # We need to know the mcu to emit the correct AF list. + def extra_args(self, parser): + parser.add_argument("--mcu") + + +if __name__ == "__main__": + SamdPinGenerator().main() diff --git a/ports/samd/boards/pins_prefix.c b/ports/samd/boards/pins_prefix.c new file mode 100644 index 0000000000..4f0095d332 --- /dev/null +++ b/ports/samd/boards/pins_prefix.c @@ -0,0 +1,21 @@ +// pins_prefix.c becomes the initial portion of the generated pins file. + +#include + +#include "py/obj.h" +#include "py/mphal.h" +#include "extmod/modmachine.h" +#include "pin_af.h" +#include "genhdr/pins.h" + +#if defined(MCU_SAMD21) + +#define PIN(p_name, p_eic, p_adc0, p_sercom1, p_sercom2, p_tcc1, p_tcc2) \ + {{&machine_pin_type}, PIN_##p_name, MP_QSTR_##p_name, p_eic, p_adc0, p_sercom1, p_sercom2, p_tcc1, p_tcc2 } + +#elif defined(MCU_SAMD51) + +#define PIN(p_name, p_eic, p_adc0, p_adc1, p_sercom1, p_sercom2, p_tc, p_tcc1, p_tcc2) \ + {{&machine_pin_type}, PIN_##p_name, MP_QSTR_##p_name, p_eic, p_adc0, p_adc1, p_sercom1, p_sercom2, p_tc, p_tcc1, p_tcc2 } + +#endif diff --git a/ports/samd/machine_adc.c b/ports/samd/machine_adc.c index 981318d33f..2e4d4ed842 100644 --- a/ports/samd/machine_adc.c +++ b/ports/samd/machine_adc.c @@ -89,8 +89,8 @@ STATIC void mp_machine_adc_print(const mp_print_t *print, mp_obj_t self_in, mp_p (void)kind; machine_adc_obj_t *self = MP_OBJ_TO_PTR(self_in); - mp_printf(print, "ADC(%s, device=%u, channel=%u, bits=%u, average=%u, vref=%d)", - pin_name(self->id), self->adc_config.device, + mp_printf(print, "ADC(%q, device=%u, channel=%u, bits=%u, average=%u, vref=%d)", + pin_find_by_id(self->id)->name, self->adc_config.device, self->adc_config.channel, self->bits, 1 << self->avg, self->vref); } diff --git a/ports/samd/machine_dac.c b/ports/samd/machine_dac.c index 195c06e4f4..5c9d77624d 100644 --- a/ports/samd/machine_dac.c +++ b/ports/samd/machine_dac.c @@ -152,7 +152,7 @@ STATIC mp_obj_t dac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_ STATIC void dac_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { dac_obj_t *self = self_in; - mp_printf(print, "DAC(%u, Pin=%s, vref=%d)", self->id, pin_name(self->gpio_id), self->vref); + mp_printf(print, "DAC(%u, Pin=%q, vref=%d)", self->id, pin_find_by_id(self->gpio_id)->name, self->vref); } STATIC mp_obj_t dac_write(mp_obj_t self_in, mp_obj_t value_in) { diff --git a/ports/samd/machine_pin.c b/ports/samd/machine_pin.c index f8e1b96280..30b254722b 100644 --- a/ports/samd/machine_pin.c +++ b/ports/samd/machine_pin.c @@ -54,8 +54,7 @@ typedef struct _machine_pin_irq_obj_t { uint8_t pin_id; } machine_pin_irq_obj_t; -#if MICROPY_PY_MACHINE_PIN_BOARD_CPU -// Pin mapping dictionaries +// Pin mapping dictionaries generated by make-pins.py. MP_DEFINE_CONST_OBJ_TYPE( machine_pin_cpu_pins_obj_type, MP_QSTR_cpu, @@ -69,7 +68,6 @@ MP_DEFINE_CONST_OBJ_TYPE( MP_TYPE_FLAG_NONE, locals_dict, &machine_pin_board_pins_locals_dict ); -#endif // MICROPY_PY_MACHINE_PIN_BOARD_CPU STATIC const mp_irq_methods_t machine_pin_irq_methods; @@ -90,11 +88,10 @@ STATIC void machine_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_prin mode_str = (mp_hal_get_pin_direction(self->pin_id) == GPIO_DIRECTION_OUT) ? "OUT" : "IN"; } - mp_printf(print, "Pin(\"%s\", mode=%s, pull=%s, GPIO=P%c%02u)", - pin_name(self->pin_id), + mp_printf(print, "Pin(Pin.cpu.%q, mode=%s, pull=%s)", + self->name, mode_str, - pull_str[mp_hal_get_pull_mode(self->pin_id)], - "ABCD"[self->pin_id / 32], self->pin_id % 32); + pull_str[mp_hal_get_pull_mode(self->pin_id)]); } STATIC void pin_validate_drive(bool strength) { @@ -292,7 +289,7 @@ STATIC mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_ mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); // Get the IRQ object. - uint8_t eic_id = get_pin_obj_ptr(self->pin_id)->eic; + uint8_t eic_id = self->eic; machine_pin_irq_obj_t *irq = MP_STATE_PORT(machine_pin_irq_objects[eic_id]); if (irq != NULL && irq->pin_id != self->pin_id) { mp_raise_ValueError(MP_ERROR_TEXT("IRQ already used")); @@ -428,11 +425,9 @@ STATIC const mp_rom_map_elem_t machine_pin_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_drive), MP_ROM_PTR(&machine_pin_drive_obj) }, { MP_ROM_QSTR(MP_QSTR_irq), MP_ROM_PTR(&machine_pin_irq_obj) }, - #if MICROPY_PY_MACHINE_PIN_BOARD_CPU // class attributes - { MP_ROM_QSTR(MP_QSTR_board), MP_ROM_PTR(&machine_pin_board_pins_obj_type) }, - { MP_ROM_QSTR(MP_QSTR_cpu), MP_ROM_PTR(&machine_pin_cpu_pins_obj_type) }, - #endif // MICROPY_PY_MACHINE_PIN_BOARD_CPU + { MP_ROM_QSTR(MP_QSTR_board), MP_ROM_PTR(&machine_pin_board_pins_obj_type) }, + { MP_ROM_QSTR(MP_QSTR_cpu), MP_ROM_PTR(&machine_pin_cpu_pins_obj_type) }, // class constants { MP_ROM_QSTR(MP_QSTR_IN), MP_ROM_INT(GPIO_MODE_IN) }, diff --git a/ports/samd/machine_pwm.c b/ports/samd/machine_pwm.c index 196a9b1435..6fc8145372 100644 --- a/ports/samd/machine_pwm.c +++ b/ports/samd/machine_pwm.c @@ -114,8 +114,8 @@ STATIC void mp_machine_pwm_stop(machine_pwm_obj_t *self); STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_pwm_obj_t *self = MP_OBJ_TO_PTR(self_in); - mp_printf(print, "PWM(%s, device=%u, channel=%u, output=%u)", - pin_name(self->pin_id), self->device, self->channel, self->output); + mp_printf(print, "PWM(%q, device=%u, channel=%u, output=%u)", + pin_find_by_id(self->pin_id)->name, self->device, self->channel, self->output); } // called by the constructor and init() diff --git a/ports/samd/machine_uart.c b/ports/samd/machine_uart.c index c081b8814b..ada193020b 100644 --- a/ports/samd/machine_uart.c +++ b/ports/samd/machine_uart.c @@ -120,7 +120,7 @@ STATIC void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_ ", txbuf=%d" #endif #if MICROPY_HW_UART_RTSCTS - ", rts=%s, cts=%s" + ", rts=%q, cts=%q" #endif ")", self->id, self->baudrate, self->bits, _parity_name[self->parity], @@ -129,8 +129,8 @@ STATIC void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_ , self->write_buffer.size - 1 #endif #if MICROPY_HW_UART_RTSCTS - , self->rts != 0xff ? pin_name(self->rts) : "None" - , self->cts != 0xff ? pin_name(self->cts) : "None" + , self->rts != 0xff ? pin_find_by_id(self->rts)->name : MP_QSTR_None + , self->cts != 0xff ? pin_find_by_id(self->cts)->name : MP_QSTR_None #endif ); } diff --git a/ports/samd/mcu/samd21/mpconfigmcu.h b/ports/samd/mcu/samd21/mpconfigmcu.h index f70981acd5..1a3d958729 100644 --- a/ports/samd/mcu/samd21/mpconfigmcu.h +++ b/ports/samd/mcu/samd21/mpconfigmcu.h @@ -37,10 +37,6 @@ unsigned long trng_random_u32(int delay); #define MICROPY_PY_OS_URANDOM (1) -#ifndef MICROPY_PY_MACHINE_PIN_BOARD_CPU -#define MICROPY_PY_MACHINE_PIN_BOARD_CPU (1) -#endif - #define CPU_FREQ (48000000) #define DFLL48M_FREQ (48000000) #define MAX_CPU_FREQ (54000000) diff --git a/ports/samd/mcu/samd21/pin-af-table.csv b/ports/samd/mcu/samd21/pin-af-table.csv index b74db0c8ef..37bb592597 100644 --- a/ports/samd/mcu/samd21/pin-af-table.csv +++ b/ports/samd/mcu/samd21/pin-af-table.csv @@ -9,57 +9,56 @@ # The first column is the pin id, not the number of the board pin. # Rows not starting with pa, pb, pc or pd are ignored. # When editing the table with a spread sheet, take care to import the data as text. -# -# Pin,EIC,ADC,SERCOM1,SERCOM2,TC,TCC -pa00,0,,,10,20, -pa01,1,,,11,21, -pa02,2,0,,,, -pa03,3,1,,,, -pb04,4,12,,,, -pb05,5,13,,,, -pb06,6,14,,,, -pb07,7,15,,,, -pb08,8,2,,40,40, -pb09,9,3,,41,41, -pa04,4,4,,00,00, -pa05,5,5,,01,01, -pa06,6,6,,02,10, -pa07,7,7,,03,11, -pa08,,16,00,20,00,12 -pa09,9,17,01,21,01,13 -pa10,10,18,02,22,10,02 -pa11,11,19,03,23,11,03 -pb10,10,,,42,50,04 -pb11,11,,,43,51,05 -pb12,12,,40,,40,06 -pb13,13,,41,,41,07 -pb14,14,,42,,50, -pb15,15,,43,,51, -pa12,12,,20,40,20,06 -pa13,13,,21,41,20,07 -pa14,14,,22,42,30,04 -pa15,15,,23,43,31,05 -pa16,0,,10,30,20,06 -pa17,1,,11,31,21,07 -pa18,2,,12,32,30,02 -pa19,3,,13,33,31,03 -pb16,9,,50,,60,04 -pb17,1,,51,,61,05 -pa20,4,,52,32,70,04 -pa21,5,,53,33,71,07 -pa22,6,,30,50,40,04 -pa23,7,,31,51,41,05 -pa24,12,,32,52,50,12 -pa25,13,,33,53,51,13 -pb22,6,,,52,70, -pb23,7,,,53,71, -pa27,15,,,,, -pa28,8,,,,, -pa30,10,,,12,10, -pa31,11,,,13,11, -pb30,14,,,50,00,12 -pb31,15,,,51,01,13 -pb00,0,8,,52,70, -pb01,1,9,,53,71, -pb02,2,10,,50,60, -pb03,3,11,,51,61, +Pin,EIC,ADC0,SERCOM1,SERCOM2,TCC1,TCC2 +PA00,0,,,10,20, +PA01,1,,,11,21, +PA02,2,0,,,, +PA03,3,1,,,, +PB04,4,12,,,, +PB05,5,13,,,, +PB06,6,14,,,, +PB07,7,15,,,, +PB08,8,2,,40,40, +PB09,9,3,,41,41, +PA04,4,4,,00,00, +PA05,5,5,,01,01, +PA06,6,6,,02,10, +PA07,7,7,,03,11, +PA08,,16,00,20,00,12 +PA09,9,17,01,21,01,13 +PA10,10,18,02,22,10,02 +PA11,11,19,03,23,11,03 +PB10,10,,,42,50,04 +PB11,11,,,43,51,05 +PB12,12,,40,,40,06 +PB13,13,,41,,41,07 +PB14,14,,42,,50, +PB15,15,,43,,51, +PA12,12,,20,40,20,06 +PA13,13,,21,41,20,07 +PA14,14,,22,42,30,04 +PA15,15,,23,43,31,05 +PA16,0,,10,30,20,06 +PA17,1,,11,31,21,07 +PA18,2,,12,32,30,02 +PA19,3,,13,33,31,03 +PB16,9,,50,,60,04 +PB17,1,,51,,61,05 +PA20,4,,52,32,70,04 +PA21,5,,53,33,71,07 +PA22,6,,30,50,40,04 +PA23,7,,31,51,41,05 +PA24,12,,32,52,50,12 +PA25,13,,33,53,51,13 +PB22,6,,,52,70, +PB23,7,,,53,71, +PA27,15,,,,, +PA28,8,,,,, +PA30,10,,,12,10, +PA31,11,,,13,11, +PB30,14,,,50,00,12 +PB31,15,,,51,01,13 +PB00,0,8,,52,70, +PB01,1,9,,53,71, +PB02,2,10,,50,60, +PB03,3,11,,51,61, diff --git a/ports/samd/mcu/samd51/mpconfigmcu.h b/ports/samd/mcu/samd51/mpconfigmcu.h index 399b48c040..7c95c341b9 100644 --- a/ports/samd/mcu/samd51/mpconfigmcu.h +++ b/ports/samd/mcu/samd51/mpconfigmcu.h @@ -30,10 +30,6 @@ #define MICROPY_PY_RANDOM_SEED_INIT_FUNC (trng_random_u32()) unsigned long trng_random_u32(void); -#ifndef MICROPY_PY_MACHINE_PIN_BOARD_CPU -#define MICROPY_PY_MACHINE_PIN_BOARD_CPU (1) -#endif - // fatfs configuration used in ffconf.h #define MICROPY_FATFS_ENABLE_LFN (1) #define MICROPY_FATFS_RPATH (2) diff --git a/ports/samd/mcu/samd51/pin-af-table.csv b/ports/samd/mcu/samd51/pin-af-table.csv index 249ce6865c..69f51a33ca 100644 --- a/ports/samd/mcu/samd51/pin-af-table.csv +++ b/ports/samd/mcu/samd51/pin-af-table.csv @@ -10,104 +10,103 @@ # The first column is the pin id, not the number of the board pin. # Rows not starting with pa, pb, pc or pd are ignored. # When editing the table with a spread sheet, take care to import the data as text. -# -# Pin,EIC,ADC0,ADC1,SERCOM1,SERCOM2,TC,TCC1,TCC2 -pb03,9,15,,,51,61,, -pa00,0,,,,10,20,, -pa01,1,,,,11,21,, -pc00,0,,10,,,,, -pc01,1,,11,,,,, -pc02,2,,4,,,,, -pc03,3,,5,,,,, -pa02,2,0,,,,,, -pa03,3,10,,,,,, -pb04,4,,6,,,,, -pb05,5,,7,,,,, -pd00,0,,14,,,,, -pd01,1,,15,,,,, -pb06,6,,8,,,,, -pb07,7,,9,,,,, -pb08,8,2,0,,40,40,, -pb09,9,3,1,,41,41,, -pa04,4,4,,,00,00,, -pa05,5,5,,,01,01,, -pa06,6,6,,,02,10,, -pa07,7,7,,,03,11,, -pc04,4,,,60,,,00, -pc05,5,,,61,,,, -pc06,6,,,62,,,, -pc07,9,,,63,,,, -pa08,,8,2,00,21,00,00,14 -pa09,9,9,3,01,20,01,01,15 -pa10,10,10,,02,22,10,02,16 -pa11,11,11,,03,23,11,03,17 -pb10,10,,,,42,50,04,10 -pb11,12,,,,43,51,05,11 -pb12,12,,,40,,40,30,00 -pb13,13,,,41,,41,31,01 -pb14,14,,,42,,50,40,02 -pb15,15,,,43,,51,41,03 -pd08,3,,,70,61,,01, -pd09,4,,,71,60,,02, -pd10,5,,,72,62,,03, -pd11,6,,,73,63,,04, -pd12,7,,,,,,05, -pc10,10,,,62,72,,00,14 -pc11,11,,,63,73,,01,15 -pc12,12,,,70,61,,02,16 -pc13,13,,,71,60,,03,17 -pc14,14,,,72,62,,04,10 -pc15,15,,,73,63,,05,11 -pa12,12,,,20,41,20,06,12 -pa13,13,,,21,40,21,07,13 -pa14,14,,,22,42,30,20,12 -pa15,15,,,23,43,31,21,13 -pa16,0,,,10,31,20,10,04 -pa17,1,,,11,30,21,11,05 -pa18,2,,,12,32,30,12,06 -pa19,3,,,13,33,31,13,07 -pc16,0,,,60,01,,00, -pc17,1,,,61,00,,01, -pc18,2,,,62,02,,02, -pc19,3,,,63,03,,03, -pc20,4,,,,,,04, -pc21,5,,,,,,05, -pc22,6,,,10,31,,05, -pc23,7,,,11,30,,07, -pd20,10,,,12,32,,10, -pd21,11,,,13,33,,11, -pb16,0,,,50,,60,30,04 -pb17,1,,,51,,61,31,05 -pb18,2,,,52,72,,10, -pb19,3,,,53,73,,11, -pb20,4,,,30,71,,12, -pb21,5,,,31,70,,13, -pa20,4,,,52,32,70,14,00 -pa21,5,,,53,33,71,15,01 -pa22,6,,,30,51,40,16,02 -pa23,7,,,31,50,41,17,03 -pa24,8,,,32,52,50,22, -pa25,9,,,33,53,51,, -pb22,22,,,12,52,70,, -pb23,7,,,13,53,71,, -pb24,8,,,00,21,,, -pb25,9,,,01,20,,, -pb26,12,,,20,41,,12, -pb27,13,,,21,40,,13, -pb28,14,,,22,42,,14, -pb29,15,,,23,43,,15, -pc24,8,,,02,22,,, -pc25,9,,,03,23,,, -pc26,10,,,,,,, -pc27,11,,,10,,,, -pc28,12,,,11,,,, -pa27,11,,,,,,, -pa30,14,,,72,12,60,20, -pa31,15,,,73,13,61,21, -pb30,14,,,70,51,00,40,06 -pb31,15,,,71,50,01,41,07 -pc30,14,,12,,,,, -pc31,15,,13,,,,, -pb00,9,12,,,52,70,, -pb01,1,13,,,53,71,, -pb02,2,14,,,50,60,22, +Pin,EIC,ADC0,ADC1,SERCOM1,SERCOM2,TC,TCC1,TCC2 +PB03,9,15,,,51,61,, +PA00,0,,,,10,20,, +PA01,1,,,,11,21,, +PC00,0,,10,,,,, +PC01,1,,11,,,,, +PC02,2,,4,,,,, +PC03,3,,5,,,,, +PA02,2,0,,,,,, +PA03,3,10,,,,,, +PB04,4,,6,,,,, +PB05,5,,7,,,,, +PD00,0,,14,,,,, +PD01,1,,15,,,,, +PB06,6,,8,,,,, +PB07,7,,9,,,,, +PB08,8,2,0,,40,40,, +PB09,9,3,1,,41,41,, +PA04,4,4,,,00,00,, +PA05,5,5,,,01,01,, +PA06,6,6,,,02,10,, +PA07,7,7,,,03,11,, +PC04,4,,,60,,,00, +PC05,5,,,61,,,, +PC06,6,,,62,,,, +PC07,9,,,63,,,, +PA08,,8,2,00,21,00,00,14 +PA09,9,9,3,01,20,01,01,15 +PA10,10,10,,02,22,10,02,16 +PA11,11,11,,03,23,11,03,17 +PB10,10,,,,42,50,04,10 +PB11,12,,,,43,51,05,11 +PB12,12,,,40,,40,30,00 +PB13,13,,,41,,41,31,01 +PB14,14,,,42,,50,40,02 +PB15,15,,,43,,51,41,03 +PD08,3,,,70,61,,01, +PD09,4,,,71,60,,02, +PD10,5,,,72,62,,03, +PD11,6,,,73,63,,04, +PD12,7,,,,,,05, +PC10,10,,,62,72,,00,14 +PC11,11,,,63,73,,01,15 +PC12,12,,,70,61,,02,16 +PC13,13,,,71,60,,03,17 +PC14,14,,,72,62,,04,10 +PC15,15,,,73,63,,05,11 +PA12,12,,,20,41,20,06,12 +PA13,13,,,21,40,21,07,13 +PA14,14,,,22,42,30,20,12 +PA15,15,,,23,43,31,21,13 +PA16,0,,,10,31,20,10,04 +PA17,1,,,11,30,21,11,05 +PA18,2,,,12,32,30,12,06 +PA19,3,,,13,33,31,13,07 +PC16,0,,,60,01,,00, +PC17,1,,,61,00,,01, +PC18,2,,,62,02,,02, +PC19,3,,,63,03,,03, +PC20,4,,,,,,04, +PC21,5,,,,,,05, +PC22,6,,,10,31,,05, +PC23,7,,,11,30,,07, +PD20,10,,,12,32,,10, +PD21,11,,,13,33,,11, +PB16,0,,,50,,60,30,04 +PB17,1,,,51,,61,31,05 +PB18,2,,,52,72,,10, +PB19,3,,,53,73,,11, +PB20,4,,,30,71,,12, +PB21,5,,,31,70,,13, +PA20,4,,,52,32,70,14,00 +PA21,5,,,53,33,71,15,01 +PA22,6,,,30,51,40,16,02 +PA23,7,,,31,50,41,17,03 +PA24,8,,,32,52,50,22, +PA25,9,,,33,53,51,, +PB22,22,,,12,52,70,, +PB23,7,,,13,53,71,, +PB24,8,,,00,21,,, +PB25,9,,,01,20,,, +PB26,12,,,20,41,,12, +PB27,13,,,21,40,,13, +PB28,14,,,22,42,,14, +PB29,15,,,23,43,,15, +PC24,8,,,02,22,,, +PC25,9,,,03,23,,, +PC26,10,,,,,,, +PC27,11,,,10,,,, +PC28,12,,,11,,,, +PA27,11,,,,,,, +PA30,14,,,72,12,60,20, +PA31,15,,,73,13,61,21, +PB30,14,,,70,51,00,40,06 +PB31,15,,,71,50,01,41,07 +PC30,14,,12,,,,, +PC31,15,,13,,,,, +PB00,9,12,,,52,70,, +PB01,1,13,,,53,71,, +PB02,2,14,,,50,60,22, diff --git a/ports/samd/pin_af.c b/ports/samd/pin_af.c index 6de9a74778..ca11e3b7a8 100644 --- a/ports/samd/pin_af.c +++ b/ports/samd/pin_af.c @@ -40,30 +40,26 @@ extern const uint8_t tcc_channel_count[]; -#include "pin_af_table.c" - // Just look for an table entry for a given pin and raise an error // in case of no match (which should not happen). - -const machine_pin_obj_t *get_pin_obj_ptr(int pin_id) { - for (int i = 0; i < MP_ARRAY_SIZE(pin_af_table); i++) { - if (pin_af_table[i]->pin_id == pin_id) { // Pin match - return pin_af_table[i]; +const machine_pin_obj_t *pin_find_by_id(int pin_id) { + const mp_map_t *cpu_map = &machine_pin_cpu_pins_locals_dict.map; + for (uint i = 0; i < cpu_map->alloc; i++) { + machine_pin_obj_t *pin = MP_OBJ_TO_PTR(cpu_map->table[i].value); + if (pin->pin_id == pin_id) { + return pin; } } mp_raise_ValueError(MP_ERROR_TEXT("not a Pin")); } -#if MICROPY_PY_MACHINE_PIN_BOARD_CPU STATIC const machine_pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name) { - mp_map_t *named_map = mp_obj_dict_get_map((mp_obj_t)named_pins); - mp_map_elem_t *named_elem = mp_map_lookup(named_map, name, MP_MAP_LOOKUP); - if (named_elem != NULL && named_elem->value != NULL) { + mp_map_elem_t *named_elem = mp_map_lookup((mp_map_t *)&named_pins->map, name, MP_MAP_LOOKUP); + if (named_elem != NULL) { return named_elem->value; } return NULL; } -#endif const machine_pin_obj_t *pin_find(mp_obj_t pin) { // Is already a object of the proper type @@ -72,10 +68,9 @@ const machine_pin_obj_t *pin_find(mp_obj_t pin) { } if (mp_obj_is_small_int(pin)) { // Pin defined by pin number for PAnn, PBnn, etc. - return get_pin_obj_ptr(mp_obj_get_int(pin)); + return pin_find_by_id(mp_obj_get_int(pin)); } - #if MICROPY_PY_MACHINE_PIN_BOARD_CPU const machine_pin_obj_t *self = NULL; // See if the pin name matches a board pin self = pin_find_named_pin(&machine_pin_board_pins_locals_dict, pin); @@ -87,47 +82,17 @@ const machine_pin_obj_t *pin_find(mp_obj_t pin) { if (self != NULL) { return self; } - #else - if (mp_obj_is_str(pin)) { - // Search by name - size_t slen; - const char *s = mp_obj_str_get_data(pin, &slen); - // Check for a string like PA02 or PD12 - if (slen == 4 && s[0] == 'P' && strchr("ABCD", s[1]) != NULL && - strchr("0123456789", s[2]) != NULL && strchr("0123456789", s[2]) != NULL) { - int num = (s[1] - 'A') * 32 + (s[2] - '0') * 10 + (s[3] - '0'); - return get_pin_obj_ptr(num); - } else { - for (int i = 0; i < MP_ARRAY_SIZE(pin_af_table); i++) { - size_t len; - const char *name = (char *)qstr_data(pin_af_table[i]->name, &len); - if (slen == len && strncmp(s, name, slen) == 0) { - return pin_af_table[i]; - } - } - } - } - #endif // MICROPY_PY_MACHINE_PIN_BOARD_CPU mp_raise_ValueError(MP_ERROR_TEXT("not a Pin")); } -const char *pin_name(int id) { - for (int i = 0; i < sizeof(pin_af_table); i++) { - if (pin_af_table[i]->pin_id == id) { - return qstr_str(pin_af_table[i]->name); - } - } - return "-"; -} - #if MICROPY_PY_MACHINE_I2C || MICROPY_PY_MACHINE_SPI || MICROPY_PY_MACHINE_UART // Test, whether the given pin is defined and has signals for sercom. // If that applies return the alt_fct and pad_nr. // If not, an error will be raised. sercom_pad_config_t get_sercom_config(int pin_id, uint8_t sercom_nr) { - const machine_pin_obj_t *pct_ptr = get_pin_obj_ptr(pin_id); + const machine_pin_obj_t *pct_ptr = pin_find_by_id(pin_id); if ((pct_ptr->sercom1 >> 4) == sercom_nr) { return (sercom_pad_config_t) {ALT_FCT_SERCOM1, pct_ptr->sercom1 & 0x0f}; } else if ((pct_ptr->sercom2 >> 4) == sercom_nr) { @@ -144,7 +109,7 @@ sercom_pad_config_t get_sercom_config(int pin_id, uint8_t sercom_nr) { // If not, an error will be raised. adc_config_t get_adc_config(int pin_id, int32_t flag) { - const machine_pin_obj_t *pct_ptr = get_pin_obj_ptr(pin_id); + const machine_pin_obj_t *pct_ptr = pin_find_by_id(pin_id); if (pct_ptr->adc0 != 0xff && (flag & (1 << pct_ptr->adc0)) == 0) { return (adc_config_t) {0, pct_ptr->adc0}; #if defined(MUC_SAMD51) @@ -166,7 +131,7 @@ adc_config_t get_adc_config(int pin_id, int32_t flag) { // tries to provide an unused device, if available. pwm_config_t get_pwm_config(int pin_id, int wanted_dev, uint8_t device_status[]) { - const machine_pin_obj_t *pct_ptr = get_pin_obj_ptr(pin_id); + const machine_pin_obj_t *pct_ptr = pin_find_by_id(pin_id); uint8_t tcc1 = pct_ptr->tcc1; uint8_t tcc2 = pct_ptr->tcc2; diff --git a/ports/samd/pin_af.h b/ports/samd/pin_af.h index 3a15ae7f35..83839a0503 100644 --- a/ports/samd/pin_af.h +++ b/ports/samd/pin_af.h @@ -92,14 +92,11 @@ typedef struct _pwm_config_t { #define ALT_FCT_SERCOM1 2 #define ALT_FCT_SERCOM2 3 -#if MICROPY_PY_MACHINE_PIN_BOARD_CPU extern const mp_obj_dict_t machine_pin_cpu_pins_locals_dict; extern const mp_obj_dict_t machine_pin_board_pins_locals_dict; -#endif sercom_pad_config_t get_sercom_config(int pin_id, uint8_t sercom); adc_config_t get_adc_config(int pin_id, int32_t flag); pwm_config_t get_pwm_config(int pin_id, int wanted_dev, uint8_t used_dev[]); -const machine_pin_obj_t *get_pin_obj_ptr(int pin_id); -const char *pin_name(int id); +const machine_pin_obj_t *pin_find_by_id(int pin_id); const machine_pin_obj_t *pin_find(mp_obj_t pin);