From 9a41722dd3bf5052d494ac399a4a8dda452c4584 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Tue, 20 Aug 2024 18:47:20 +0100 Subject: [PATCH] More board header checks (#1814) * Modify check_board_header.py to work with both RP2040- and RP2350-based boards * Tweaks to the board-header files so that they pass check_board_header.py * Update tools/check_board_header.py so that it handles pico_cmake_set_default the same way as cmake/generic_board.cmake does --- src/boards/include/boards/amethyst_fpga.h | 2 + src/boards/include/boards/defcon32_badge.h | 18 +- src/boards/include/boards/gen4_rp2350_24.h | 4 +- src/boards/include/boards/gen4_rp2350_24ct.h | 4 +- src/boards/include/boards/gen4_rp2350_24t.h | 4 +- src/boards/include/boards/gen4_rp2350_28.h | 4 +- src/boards/include/boards/gen4_rp2350_28ct.h | 4 +- src/boards/include/boards/gen4_rp2350_28t.h | 4 +- src/boards/include/boards/gen4_rp2350_32.h | 4 +- src/boards/include/boards/gen4_rp2350_32ct.h | 4 +- src/boards/include/boards/gen4_rp2350_32t.h | 4 +- src/boards/include/boards/gen4_rp2350_35.h | 4 +- src/boards/include/boards/gen4_rp2350_35ct.h | 4 +- src/boards/include/boards/gen4_rp2350_35t.h | 4 +- .../boards/hellbender_2350A_devboard.h | 4 +- .../boards/ilabs_challenger_rp2350_bconnect.h | 8 +- .../boards/ilabs_challenger_rp2350_wifi_ble.h | 8 +- .../include/boards/phyx_rick_tny_rp2350.h | 2 +- src/boards/include/boards/pico2.h | 2 +- .../include/boards/pimoroni_plasma2350.h | 4 +- src/boards/include/boards/pimoroni_tiny2350.h | 4 +- .../include/boards/solderparty_rp2350_stamp.h | 4 - .../boards/solderparty_rp2350_stamp_xl.h | 4 - .../switchscience_picossci2_conta_base.h | 2 +- .../switchscience_picossci2_rp2350_breakout.h | 2 +- .../boards/switchscience_picossci2_tiny.h | 2 +- src/rp2350/rp2350a_interface_pins.json | 95 ++++ src/rp2350/rp2350b_interface_pins.json | 111 +++++ tools/check_board_header.py | 463 ++++++++++++++---- 29 files changed, 617 insertions(+), 166 deletions(-) create mode 100644 src/rp2350/rp2350a_interface_pins.json create mode 100644 src/rp2350/rp2350b_interface_pins.json diff --git a/src/boards/include/boards/amethyst_fpga.h b/src/boards/include/boards/amethyst_fpga.h index d41dff41e..ea6b9a2d4 100644 --- a/src/boards/include/boards/amethyst_fpga.h +++ b/src/boards/include/boards/amethyst_fpga.h @@ -11,6 +11,8 @@ // FIXME delete this file before release (board file for Amethyst FPGA platform) +// pico_cmake_set PICO_PLATFORM=rp2350 + #ifndef _BOARDS_AMETHYST_FPGA_H #define _BOARDS_AMETHYST_FPGA_H diff --git a/src/boards/include/boards/defcon32_badge.h b/src/boards/include/boards/defcon32_badge.h index 6e99ca58a..0c5f3d45c 100644 --- a/src/boards/include/boards/defcon32_badge.h +++ b/src/boards/include/boards/defcon32_badge.h @@ -9,13 +9,6 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// NOTE: since there is no UART on the badge, you should probably pass: -// -DPICO_BOARD=defcon32_badge -DPICO_STDIO_USB=1 -DPICO_STDIO_UART+0 -// when building to set up stdio over USB CDC by default -#define PICO_DEFAULT_UART 0 -#define PICO_DEFAULT_UART_TX_PIN 30 -#define PICO_DEFAULT_UART_RX_PIN 31 - // pico_cmake_set PICO_PLATFORM=rp2350 #ifndef _BOARDS_DEFCON32_BADGE_H @@ -56,6 +49,11 @@ #define DEFCON32_BADGE_IR_RX_PIN 27 #define DEFCON32_BADGE_IR_TX_PIN 28 +// --- UART --- +// NOTE: since there is no UART on the badge, you should probably pass: +// -DPICO_BOARD=defcon32_badge -DPICO_STDIO_USB=1 -DPICO_STDIO_UART=0 +// when building to set up stdio over USB CDC by default + // --- LED --- // no PICO_DEFAULT_LED_PIN #ifndef PICO_DEFAULT_WS2812_PIN @@ -75,16 +73,16 @@ // --- SPI --- #ifndef PICO_DEFAULT_SPI -#define PICO_DEFAULT_SPI 0 +#define PICO_DEFAULT_SPI 1 #endif #ifndef PICO_DEFAULT_SPI_SCK_PIN #define PICO_DEFAULT_SPI_SCK_PIN DEFCON32_BADGE_SPI_CK_PIN #endif #ifndef PICO_DEFAULT_SPI_TX_PIN -#define PICO_DEFAULT_SPI_TX_PIN DEFCON32_BADGE_SPI_MISO_PIN +#define PICO_DEFAULT_SPI_TX_PIN DEFCON32_BADGE_SPI_MOSI_PIN #endif #ifndef PICO_DEFAULT_SPI_RX_PIN -#define PICO_DEFAULT_SPI_RX_PIN DEFCON32_BADGE_SPI_MOSI_PIN +#define PICO_DEFAULT_SPI_RX_PIN DEFCON32_BADGE_SPI_MISO_PIN #endif // multiple devices, so this doesn't make much sense // no PICO_DEFAULT_SPI_CSN_PIN diff --git a/src/boards/include/boards/gen4_rp2350_24.h b/src/boards/include/boards/gen4_rp2350_24.h index c569c15cb..dc8b9f899 100644 --- a/src/boards/include/boards/gen4_rp2350_24.h +++ b/src/boards/include/boards/gen4_rp2350_24.h @@ -11,8 +11,8 @@ // pico_cmake_set PICO_PLATFORM=rp2350 -#ifndef _BOARDS_GEN4_RP2350_24 -#define _BOARDS_GEN4_RP2350_24 +#ifndef _BOARDS_GEN4_RP2350_24_H +#define _BOARDS_GEN4_RP2350_24_H // For board detection #define GEN4_RP2350_24 diff --git a/src/boards/include/boards/gen4_rp2350_24ct.h b/src/boards/include/boards/gen4_rp2350_24ct.h index 2f6f15429..39632fac3 100644 --- a/src/boards/include/boards/gen4_rp2350_24ct.h +++ b/src/boards/include/boards/gen4_rp2350_24ct.h @@ -11,8 +11,8 @@ // pico_cmake_set PICO_PLATFORM=rp2350 -#ifndef _BOARDS_GEN4_RP2350_24CT -#define _BOARDS_GEN4_RP2350_24CT +#ifndef _BOARDS_GEN4_RP2350_24CT_H +#define _BOARDS_GEN4_RP2350_24CT_H // For board detection #define GEN4_RP2350_24CT // CLB variants are exactly the same in operation diff --git a/src/boards/include/boards/gen4_rp2350_24t.h b/src/boards/include/boards/gen4_rp2350_24t.h index 2d01017b8..d1bfbf418 100644 --- a/src/boards/include/boards/gen4_rp2350_24t.h +++ b/src/boards/include/boards/gen4_rp2350_24t.h @@ -11,8 +11,8 @@ // pico_cmake_set PICO_PLATFORM=rp2350 -#ifndef _BOARDS_GEN4_RP2350_24T -#define _BOARDS_GEN4_RP2350_24T +#ifndef _BOARDS_GEN4_RP2350_24T_H +#define _BOARDS_GEN4_RP2350_24T_H // For board detection #define GEN4_RP2350_24T diff --git a/src/boards/include/boards/gen4_rp2350_28.h b/src/boards/include/boards/gen4_rp2350_28.h index 804b2a99d..a005be77b 100644 --- a/src/boards/include/boards/gen4_rp2350_28.h +++ b/src/boards/include/boards/gen4_rp2350_28.h @@ -11,8 +11,8 @@ // pico_cmake_set PICO_PLATFORM=rp2350 -#ifndef _BOARDS_GEN4_RP2350_28 -#define _BOARDS_GEN4_RP2350_28 +#ifndef _BOARDS_GEN4_RP2350_28_H +#define _BOARDS_GEN4_RP2350_28_H // For board detection #define GEN4_RP2350_28 diff --git a/src/boards/include/boards/gen4_rp2350_28ct.h b/src/boards/include/boards/gen4_rp2350_28ct.h index 1714ef115..c93126ad2 100644 --- a/src/boards/include/boards/gen4_rp2350_28ct.h +++ b/src/boards/include/boards/gen4_rp2350_28ct.h @@ -11,8 +11,8 @@ // pico_cmake_set PICO_PLATFORM=rp2350 -#ifndef _BOARDS_GEN4_RP2350_28CT -#define _BOARDS_GEN4_RP2350_28CT +#ifndef _BOARDS_GEN4_RP2350_28CT_H +#define _BOARDS_GEN4_RP2350_28CT_H // For board detection #define GEN4_RP2350_28CT // CLB variants are exactly the same in operation diff --git a/src/boards/include/boards/gen4_rp2350_28t.h b/src/boards/include/boards/gen4_rp2350_28t.h index b61c230e8..9c3f908bd 100644 --- a/src/boards/include/boards/gen4_rp2350_28t.h +++ b/src/boards/include/boards/gen4_rp2350_28t.h @@ -11,8 +11,8 @@ // pico_cmake_set PICO_PLATFORM=rp2350 -#ifndef _BOARDS_GEN4_RP2350_28T -#define _BOARDS_GEN4_RP2350_28T +#ifndef _BOARDS_GEN4_RP2350_28T_H +#define _BOARDS_GEN4_RP2350_28T_H // For board detection #define GEN4_RP2350_28T diff --git a/src/boards/include/boards/gen4_rp2350_32.h b/src/boards/include/boards/gen4_rp2350_32.h index 9660a4776..33caaf550 100644 --- a/src/boards/include/boards/gen4_rp2350_32.h +++ b/src/boards/include/boards/gen4_rp2350_32.h @@ -11,8 +11,8 @@ // pico_cmake_set PICO_PLATFORM=rp2350 -#ifndef _BOARDS_GEN4_RP2350_32 -#define _BOARDS_GEN4_RP2350_32 +#ifndef _BOARDS_GEN4_RP2350_32_H +#define _BOARDS_GEN4_RP2350_32_H // For board detection #define GEN4_RP2350_32 diff --git a/src/boards/include/boards/gen4_rp2350_32ct.h b/src/boards/include/boards/gen4_rp2350_32ct.h index 9f883d4fb..839fdc01a 100644 --- a/src/boards/include/boards/gen4_rp2350_32ct.h +++ b/src/boards/include/boards/gen4_rp2350_32ct.h @@ -11,8 +11,8 @@ // pico_cmake_set PICO_PLATFORM=rp2350 -#ifndef _BOARDS_GEN4_RP2350_32CT -#define _BOARDS_GEN4_RP2350_32CT +#ifndef _BOARDS_GEN4_RP2350_32CT_H +#define _BOARDS_GEN4_RP2350_32CT_H // For board detection #define GEN4_RP2350_32CT // CLB variants are exactly the same in operation diff --git a/src/boards/include/boards/gen4_rp2350_32t.h b/src/boards/include/boards/gen4_rp2350_32t.h index 04f4e0c0b..2a1be7d2a 100644 --- a/src/boards/include/boards/gen4_rp2350_32t.h +++ b/src/boards/include/boards/gen4_rp2350_32t.h @@ -11,8 +11,8 @@ // pico_cmake_set PICO_PLATFORM=rp2350 -#ifndef _BOARDS_GEN4_RP2350_32T -#define _BOARDS_GEN4_RP2350_32T +#ifndef _BOARDS_GEN4_RP2350_32T_H +#define _BOARDS_GEN4_RP2350_32T_H // For board detection #define GEN4_RP2350_32T diff --git a/src/boards/include/boards/gen4_rp2350_35.h b/src/boards/include/boards/gen4_rp2350_35.h index d333c22f4..c0e2c0752 100644 --- a/src/boards/include/boards/gen4_rp2350_35.h +++ b/src/boards/include/boards/gen4_rp2350_35.h @@ -11,8 +11,8 @@ // pico_cmake_set PICO_PLATFORM=rp2350 -#ifndef _BOARDS_GEN4_RP2350_35 -#define _BOARDS_GEN4_RP2350_35 +#ifndef _BOARDS_GEN4_RP2350_35_H +#define _BOARDS_GEN4_RP2350_35_H // For board detection #define GEN4_RP2350_35 diff --git a/src/boards/include/boards/gen4_rp2350_35ct.h b/src/boards/include/boards/gen4_rp2350_35ct.h index 778e1995e..987804799 100644 --- a/src/boards/include/boards/gen4_rp2350_35ct.h +++ b/src/boards/include/boards/gen4_rp2350_35ct.h @@ -11,8 +11,8 @@ // pico_cmake_set PICO_PLATFORM=rp2350 -#ifndef _BOARDS_GEN4_RP2350_35CT -#define _BOARDS_GEN4_RP2350_35CT +#ifndef _BOARDS_GEN4_RP2350_35CT_H +#define _BOARDS_GEN4_RP2350_35CT_H // For board detection #define GEN4_RP2350_35CT // CLB variants are exactly the same in operation diff --git a/src/boards/include/boards/gen4_rp2350_35t.h b/src/boards/include/boards/gen4_rp2350_35t.h index 832337253..079143f86 100644 --- a/src/boards/include/boards/gen4_rp2350_35t.h +++ b/src/boards/include/boards/gen4_rp2350_35t.h @@ -11,8 +11,8 @@ // pico_cmake_set PICO_PLATFORM=rp2350 -#ifndef _BOARDS_GEN4_RP2350_35T -#define _BOARDS_GEN4_RP2350_35T +#ifndef _BOARDS_GEN4_RP2350_35T_H +#define _BOARDS_GEN4_RP2350_35T_H // For board detection #define GEN4_RP2350_35T diff --git a/src/boards/include/boards/hellbender_2350A_devboard.h b/src/boards/include/boards/hellbender_2350A_devboard.h index 03895e1b4..404e95647 100644 --- a/src/boards/include/boards/hellbender_2350A_devboard.h +++ b/src/boards/include/boards/hellbender_2350A_devboard.h @@ -9,8 +9,8 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -#ifndef _BOARDS_HB_2350A_H -#define _BOARDS_HB_2350A_H +#ifndef _BOARDS_HELLBENDER_2350A_DEVBOARD_H +#define _BOARDS_HELLBENDER_2350A_DEVBOARD_H // pico_cmake_set PICO_PLATFORM=rp2350 diff --git a/src/boards/include/boards/ilabs_challenger_rp2350_bconnect.h b/src/boards/include/boards/ilabs_challenger_rp2350_bconnect.h index b0bbebe28..66a4a7ea3 100644 --- a/src/boards/include/boards/ilabs_challenger_rp2350_bconnect.h +++ b/src/boards/include/boards/ilabs_challenger_rp2350_bconnect.h @@ -13,8 +13,8 @@ // pico_cmake_set PICO_PLATFORM=rp2350 -#ifndef _BOARDS_CHALLENGER_RP2350_BCONNECT_H -#define _BOARDS_CHALLENGER_RP2350_BCONNECT_H +#ifndef _BOARDS_ILABS_CHALLENGER_RP2350_BCONNECT_H +#define _BOARDS_ILABS_CHALLENGER_RP2350_BCONNECT_H // For board detection #define ILABS_CHALLENGER_RP2350_BCONNECT @@ -83,10 +83,6 @@ #define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) #endif -#ifndef PICO_RP2040_B0_SUPPORTED -#define PICO_RP2040_B0_SUPPORTED 1 -#endif - #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/ilabs_challenger_rp2350_wifi_ble.h b/src/boards/include/boards/ilabs_challenger_rp2350_wifi_ble.h index 29ac3df3e..a88e797c0 100644 --- a/src/boards/include/boards/ilabs_challenger_rp2350_wifi_ble.h +++ b/src/boards/include/boards/ilabs_challenger_rp2350_wifi_ble.h @@ -13,8 +13,8 @@ // pico_cmake_set PICO_PLATFORM=rp2350 -#ifndef _BOARDS_CHALLENGER_RP2350_WIFI_BLE_H -#define _BOARDS_CHALLENGER_RP2350_WIFI_BLE_H +#ifndef _BOARDS_ILABS_CHALLENGER_RP2350_WIFI_BLE_H +#define _BOARDS_ILABS_CHALLENGER_RP2350_WIFI_BLE_H // For board detection #define ILABS_CHALLENGER_RP2350_WIFI_BLE @@ -80,10 +80,6 @@ #define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) #endif -#ifndef PICO_RP2040_B0_SUPPORTED -#define PICO_RP2040_B0_SUPPORTED 1 -#endif - #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/phyx_rick_tny_rp2350.h b/src/boards/include/boards/phyx_rick_tny_rp2350.h index eb9e678f1..7db839540 100644 --- a/src/boards/include/boards/phyx_rick_tny_rp2350.h +++ b/src/boards/include/boards/phyx_rick_tny_rp2350.h @@ -42,7 +42,7 @@ // --- I2C --- #ifndef PICO_DEFAULT_I2C -#define PICO_DEFAULT_I2C 0 +#define PICO_DEFAULT_I2C 1 #endif #ifndef PICO_DEFAULT_I2C_SDA_PIN #define PICO_DEFAULT_I2C_SDA_PIN 6 diff --git a/src/boards/include/boards/pico2.h b/src/boards/include/boards/pico2.h index 4146f397c..e47dcc547 100644 --- a/src/boards/include/boards/pico2.h +++ b/src/boards/include/boards/pico2.h @@ -9,7 +9,7 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// This header may be included by other board headers as "boards/pico.h" +// This header may be included by other board headers as "boards/pico2.h" // pico_cmake_set PICO_PLATFORM=rp2350 diff --git a/src/boards/include/boards/pimoroni_plasma2350.h b/src/boards/include/boards/pimoroni_plasma2350.h index 9fb63eb8f..fa79e15de 100644 --- a/src/boards/include/boards/pimoroni_plasma2350.h +++ b/src/boards/include/boards/pimoroni_plasma2350.h @@ -60,7 +60,7 @@ // --- LED --- #ifndef PICO_DEFAULT_LED_PIN -#define PICO_DEFAULT_LED_PIN TINY2350_LED_G_PIN +#define PICO_DEFAULT_LED_PIN PLASMA2350_LED_G_PIN #endif // no PICO_DEFAULT_WS2812_PIN @@ -82,7 +82,7 @@ // --- SPI --- #ifndef PICO_DEFAULT_SPI -#define PICO_DEFAULT_SPI 0 +#define PICO_DEFAULT_SPI 1 #endif #ifndef PICO_DEFAULT_SPI_SCK_PIN #define PICO_DEFAULT_SPI_SCK_PIN SPICE_NETLIGHT_SCK_PIN diff --git a/src/boards/include/boards/pimoroni_tiny2350.h b/src/boards/include/boards/pimoroni_tiny2350.h index f6472a619..09f32e65d 100644 --- a/src/boards/include/boards/pimoroni_tiny2350.h +++ b/src/boards/include/boards/pimoroni_tiny2350.h @@ -84,9 +84,9 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024) +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) #ifndef PICO_FLASH_SIZE_BYTES -#define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) +#define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif #ifndef PICO_RP2350_A2_SUPPORTED diff --git a/src/boards/include/boards/solderparty_rp2350_stamp.h b/src/boards/include/boards/solderparty_rp2350_stamp.h index fee982c8c..64ac474e3 100644 --- a/src/boards/include/boards/solderparty_rp2350_stamp.h +++ b/src/boards/include/boards/solderparty_rp2350_stamp.h @@ -78,10 +78,6 @@ #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif -#ifndef PICO_RP2040_B0_SUPPORTED -#define PICO_RP2040_B0_SUPPORTED 1 -#endif - #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/solderparty_rp2350_stamp_xl.h b/src/boards/include/boards/solderparty_rp2350_stamp_xl.h index 97fa0bf18..90a17b98c 100644 --- a/src/boards/include/boards/solderparty_rp2350_stamp_xl.h +++ b/src/boards/include/boards/solderparty_rp2350_stamp_xl.h @@ -78,10 +78,6 @@ #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif -#ifndef PICO_RP2040_B0_SUPPORTED -#define PICO_RP2040_B0_SUPPORTED 1 -#endif - #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/switchscience_picossci2_conta_base.h b/src/boards/include/boards/switchscience_picossci2_conta_base.h index fcd7d85b2..1da3ddfe5 100644 --- a/src/boards/include/boards/switchscience_picossci2_conta_base.h +++ b/src/boards/include/boards/switchscience_picossci2_conta_base.h @@ -17,7 +17,7 @@ #define _BOARDS_SWITCHSCIENCE_PICOSSCI2_CONTA_BASE_H // For board detection -#define SWITCHSCIENCE_PICOSSCI2_CONTA_BASE_H +#define SWITCHSCIENCE_PICOSSCI2_CONTA_BASE // --- RP2350 VARIANT --- #define PICO_RP2350A 1 diff --git a/src/boards/include/boards/switchscience_picossci2_rp2350_breakout.h b/src/boards/include/boards/switchscience_picossci2_rp2350_breakout.h index 0ac128b13..68d39f926 100644 --- a/src/boards/include/boards/switchscience_picossci2_rp2350_breakout.h +++ b/src/boards/include/boards/switchscience_picossci2_rp2350_breakout.h @@ -17,7 +17,7 @@ #define _BOARDS_SWITCHSCIENCE_PICOSSCI2_RP2350_BREAKOUT_H // For board detection -#define SWITCHSCIENCE_PICOSSCI2_RP2350_BREAKOUT_H +#define SWITCHSCIENCE_PICOSSCI2_RP2350_BREAKOUT // --- RP2350 VARIANT --- #define PICO_RP2350A 1 diff --git a/src/boards/include/boards/switchscience_picossci2_tiny.h b/src/boards/include/boards/switchscience_picossci2_tiny.h index 48e3a9e83..f43307cef 100644 --- a/src/boards/include/boards/switchscience_picossci2_tiny.h +++ b/src/boards/include/boards/switchscience_picossci2_tiny.h @@ -17,7 +17,7 @@ #define _BOARDS_SWITCHSCIENCE_PICOSSCI2_TINY_H // For board detection -#define SWITCHSCIENCE_PICOSSCI2_TINY_H +#define SWITCHSCIENCE_PICOSSCI2_TINY // --- RP2350 VARIANT --- #define PICO_RP2350A 1 diff --git a/src/rp2350/rp2350a_interface_pins.json b/src/rp2350/rp2350a_interface_pins.json new file mode 100644 index 000000000..7869d2aad --- /dev/null +++ b/src/rp2350/rp2350a_interface_pins.json @@ -0,0 +1,95 @@ +{ + "interfaces": { + "UART": { + "instances": { + "0": { + "TX": [0, 2, 12, 14, 16, 18, 28], + "RX": [1, 3, 13, 15, 17, 19, 29], + "CTS": [2, 14, 18], + "RTS": [3, 15, 19] + }, + "1": { + "TX": [4, 6, 8, 10, 20, 22, 24, 26], + "RX": [5, 7, 9, 11, 21, 23, 25, 27], + "CTS": [6, 10, 22, 26], + "RTS": [7, 11, 23, 27] + } + }, + "expected_functions": { + "one_of": ["TX", "RX"] + } + }, + "I2C": { + "instances": { + "0": { + "SDA": [0, 4, 8, 12, 16, 20, 24, 28], + "SCL": [1, 5, 9, 13, 17, 21, 25, 29] + }, + "1": { + "SDA": [2, 6, 10, 14, 18, 22, 26], + "SCL": [3, 7, 11, 15, 19, 23, 27] + } + }, + "expected_functions": { + "required": ["SDA", "SCL"] + } + }, + "SPI": { + "instances": { + "0": { + "RX": [0, 4, 16, 20], + "CSN": [1, 5, 17, 21], + "SCK": [2, 6, 18, 22], + "TX": [3, 7, 19, 23] + }, + "1": { + "RX": [8, 12, 24, 28], + "CSN": [9, 13, 25, 29], + "SCK": [10, 14, 26], + "TX": [11, 15, 27] + } + }, + "expected_functions": { + "required": ["SCK"], + "one_of": ["RX", "TX"] + } + }, + "PWM": { + "instances": { + "0": { + "A": [0, 16], + "B": [1, 17] + }, + "1": { + "A": [2, 18], + "B": [3, 19] + }, + "2": { + "A": [4, 20], + "B": [5, 21] + }, + "3": { + "A": [6, 22], + "B": [7, 23] + }, + "4": { + "A": [8, 24], + "B": [9, 25] + }, + "5": { + "A": [10, 26], + "B": [11, 27] + }, + "6": { + "A": [12, 28], + "B": [13, 29] + }, + "7": { + "A": [14], + "B": [15] + } + } + } + }, + "pins": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29] +} diff --git a/src/rp2350/rp2350b_interface_pins.json b/src/rp2350/rp2350b_interface_pins.json new file mode 100644 index 000000000..ee90ad27f --- /dev/null +++ b/src/rp2350/rp2350b_interface_pins.json @@ -0,0 +1,111 @@ +{ + "interfaces": { + "UART": { + "instances": { + "0": { + "TX": [0, 2, 12, 14, 16, 18, 28, 30, 32, 34, 44, 46], + "RX": [1, 3, 13, 15, 17, 19, 29, 31, 33, 35, 45, 47], + "CTS": [2, 14, 18, 30, 34, 46], + "RTS": [3, 15, 19, 31, 35, 47] + }, + "1": { + "TX": [4, 6, 8, 10, 20, 22, 24, 26, 36, 38, 40, 42], + "RX": [5, 7, 9, 11, 21, 23, 25, 27, 37, 39, 41, 43], + "CTS": [6, 10, 22, 26, 38, 42], + "RTS": [7, 11, 23, 27, 39, 43] + } + }, + "expected_functions": { + "one_of": ["TX", "RX"] + } + }, + "I2C": { + "instances": { + "0": { + "SDA": [0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44], + "SCL": [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45] + }, + "1": { + "SDA": [2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46], + "SCL": [3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47] + } + }, + "expected_functions": { + "required": ["SDA", "SCL"] + } + }, + "SPI": { + "instances": { + "0": { + "RX": [0, 4, 16, 20, 32, 36], + "CSN": [1, 5, 17, 21, 33, 37], + "SCK": [2, 6, 18, 22, 34, 38], + "TX": [3, 7, 19, 23, 35, 39] + }, + "1": { + "RX": [8, 12, 24, 28, 40, 44], + "CSN": [9, 13, 25, 29, 41, 45], + "SCK": [10, 14, 26, 30, 42, 46], + "TX": [11, 15, 27, 31, 43, 47] + } + }, + "expected_functions": { + "required": ["SCK"], + "one_of": ["RX", "TX"] + } + }, + "PWM": { + "instances": { + "0": { + "A": [0, 16], + "B": [1, 17] + }, + "1": { + "A": [2, 18], + "B": [3, 19] + }, + "2": { + "A": [4, 20], + "B": [5, 21] + }, + "3": { + "A": [6, 22], + "B": [7, 23] + }, + "4": { + "A": [8, 24], + "B": [9, 25] + }, + "5": { + "A": [10, 26], + "B": [11, 27] + }, + "6": { + "A": [12, 28], + "B": [13, 29] + }, + "7": { + "A": [14, 30], + "B": [15, 31] + }, + "8": { + "A": [32, 40], + "B": [33, 41] + }, + "9": { + "A": [34, 42], + "B": [35, 43] + }, + "10": { + "A": [36, 44], + "B": [37, 45] + }, + "11": { + "A": [38, 46], + "B": [39, 47] + } + } + } + }, + "pins": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47] +} diff --git a/tools/check_board_header.py b/tools/check_board_header.py index 617f3940b..60ff0af5a 100755 --- a/tools/check_board_header.py +++ b/tools/check_board_header.py @@ -23,41 +23,179 @@ # warnings off by default, because some boards use the same pin for multiple purposes show_warnings = False -interfaces_json = "src/rp2040/rp2040_interface_pins.json" -if not os.path.isfile(interfaces_json): - raise Exception("{} doesn't exist".format(interfaces_json)) +chip_interfaces = { + 'RP2040': "src/rp2040/rp2040_interface_pins.json", + 'RP2350A': "src/rp2350/rp2350a_interface_pins.json", + 'RP2350B': "src/rp2350/rp2350b_interface_pins.json", +} + +DefineType = namedtuple("DefineType", ["name", "value", "resolved_value", "lineno"]) + +def list_to_string_with(lst, joiner): + elems = len(lst) + if elems == 0: + return "" + elif elems == 1: + return str(lst[0]) + else: + return "{} {} {}".format(", ".join(str(l) for l in lst[:-1]), joiner, lst[-1]) + board_header = sys.argv[1] if not os.path.isfile(board_header): raise Exception("{} doesn't exist".format(board_header)) +board_header_basename = os.path.basename(board_header) -with open(interfaces_json) as interfaces_fh: - interface_pins = json.load(interfaces_fh) - allowed_interfaces = interface_pins["interfaces"] - allowed_pins = set(interface_pins["pins"]) - # convert instance-keys to integers (allowed by Python but not by JSON) - for interface in allowed_interfaces: - instances = allowed_interfaces[interface]["instances"] - # can't modify a list that we're iterating over, so iterate over a copy - instances_copy = list(instances) - for instance in instances_copy: - instance_num = int(instance) - instances[instance_num] = instances.pop(instance) - -DefineType = namedtuple("DefineType", ["name", "value", "resolved_value", "lineno"]) +expected_include_suggestion = "/".join(board_header.split("/")[-2:]) +expected_include_guard = "_" + re.sub(r"\W", "_", expected_include_suggestion.upper()) +expected_board_detection = re.sub(r"\W", "_", expected_include_suggestion.split("/")[-1].upper()[:-2]) defines = dict() -pins = dict() # dict of lists +cmake_settings = dict() +cmake_default_settings = dict() + has_include_guard = False has_board_detection = False has_include_suggestion = False -expected_include_suggestion = "/".join(board_header.split("/")[-2:]) -expected_include_guard = "_" + re.sub(r"\W", "_", expected_include_suggestion.upper()) -expected_board_detection = re.sub(r"\W", "_", expected_include_suggestion.split("/")[-1].upper()[:-2]) + + +def read_defines_from(header_file, defines_dict): + with open(header_file) as fh: + last_ifndef = None + last_ifndef_lineno = -1 + validity_stack = [True] + board_detection_is_next = False + for lineno, line in enumerate(fh.readlines()): + lineno += 1 + # strip trailing comments + line = re.sub(r"(?<=\S)\s*//.*$", "", line) + + # look for "// pico_cmake_set BLAH_BLAH=42" + m = re.match(r"^\s*//\s*pico_cmake_set\s+(\w+)\s*=\s*(.+?)\s*$", line) + if m: + #print(m.groups()) + name = m.group(1) + value = m.group(2) + # check all uppercase + if name != name.upper(): + raise Exception("{}:{} Expected \"{}\" to be all uppercase".format(board_header, lineno, name)) + # check for multiply-defined values + if name in cmake_settings: + if cmake_settings[name].value != value: + raise Exception("{}:{} Conflicting values for pico_cmake_set {} ({} and {})".format(board_header, lineno, name, cmake_settings[name].value, value)) + else: + if show_warnings: + warnings.warn("{}:{} Multiple values for pico_cmake_set {} ({} and {})".format(board_header, lineno, name, cmake_settings[name].value, value)) + else: + cmake_settings[name] = DefineType(name, value, None, lineno) + continue + + # look for "// pico_cmake_set_default BLAH_BLAH=42" + m = re.match(r"^\s*//\s*pico_cmake_set_default\s+(\w+)\s*=\s*(.+?)\s*$", line) + if m: + #print(m.groups()) + name = m.group(1) + value = m.group(2) + # check all uppercase + if name != name.upper(): + raise Exception("{}:{} Expected \"{}\" to be all uppercase".format(board_header, lineno, name)) + if name not in cmake_default_settings: + cmake_default_settings[name] = DefineType(name, value, None, lineno) + continue + + # look for "#else" + m = re.match(r"^\s*#else\s*$", line) + if m: + validity_stack[-1] = not validity_stack[-1] + continue + + # look for #endif + m = re.match(r"^\s*#endif\s*$", line) + if m: + validity_stack.pop() + continue + + if validity_stack[-1]: + # look for "#include "foo.h" + m = re.match(r"""^\s*#include\s+"(.+?)"\s*$""", line) + if m: + include = m.group(1) + #print("Found nested include \"{}\" in {}".format(include, header_file)) + assert include.endswith(".h") + # assume that the include is also in the boards directory + assert "/" not in include or include.startswith("boards/") + read_defines_from(os.path.join(os.path.dirname(board_header), os.path.basename(include)), defines) + continue + + # look for "#if BLAH_BLAH" + m = re.match(r"^\s*#if\s+(\w+)\s*$", line) + if m: + last_if = m.group(1) + last_if_lineno = lineno + validity_stack.append(bool(defines[last_if].resolved_value)) + continue + + # look for "#ifdef BLAH_BLAH" + m = re.match(r"^\s*#ifdef\s+(\w+)\s*$", line) + if m: + last_ifdef = m.group(1) + last_ifdef_lineno = lineno + validity_stack.append(last_ifdef in defines) + continue + + # look for "#ifndef BLAH_BLAH" + m = re.match(r"^\s*#ifndef\s+(\w+)\s*$", line) + if m: + last_ifndef = m.group(1) + last_ifndef_lineno = lineno + validity_stack.append(last_ifndef not in defines) + continue + + # look for "#define BLAH_BLAH" or "#define BLAH_BLAH 42" + m = re.match(r"^\s*#define\s+(\w+)(?:\s+(.+?))?\s*$", line) + if m: + #print(m.groups()) + name = m.group(1) + value = m.group(2) + # check all uppercase + if name != name.upper(): + raise Exception("{}:{} Expected \"{}\" to be all uppercase".format(board_header, lineno, name)) + # check that adjacent #ifndef and #define lines match up + if last_ifndef_lineno + 1 == lineno: + if last_ifndef != name: + raise Exception("{}:{} #ifndef {} / #define {} mismatch".format(board_header, last_ifndef_lineno, last_ifndef, name)) + if value: + try: + # most board-defines are integer values + value = int(value, 0) + except ValueError: + pass + + # resolve nested defines + resolved_value = value + while resolved_value in defines_dict: + resolved_value = defines_dict[resolved_value].resolved_value + else: + resolved_value = None + + # check for multiply-defined values + if name in defines_dict: + if defines_dict[name].value != value: + raise Exception("{}:{} Conflicting definitions for {} ({} and {})".format(board_header, lineno, name, defines_dict[name].value, value)) + else: + if show_warnings: + warnings.warn("{}:{} Multiple definitions for {} ({} and {})".format(board_header, lineno, name, defines_dict[name].value, value)) + else: + defines_dict[name] = DefineType(name, value, resolved_value, lineno) + + +if board_header_basename == "amethyst_fpga.h": + defines['PICO_RP2350'] = DefineType('PICO_RP2350', 1, 1, -1) with open(board_header) as header_fh: last_ifndef = None last_ifndef_lineno = -1 + validity_stack = [True] board_detection_is_next = False for lineno, line in enumerate(header_fh.readlines()): lineno += 1 @@ -65,100 +203,231 @@ line = re.sub(r"(?<=\S)\s*//.*$", "", line) # look for board-detection comment - if re.match("// For board detection", line): + if re.match("^\s*// For board detection", line): board_detection_is_next = True continue + # check include-suggestion - m = re.match(r"^// This header may be included by other board headers as \"(.+?)\"", line) + m = re.match("^\s*// This header may be included by other board headers as \"(.+?)\"", line) if m: include_suggestion = m.group(1) if include_suggestion == expected_include_suggestion: has_include_suggestion = True else: - raise Exception(r"{}:{} Suggests including \"{}\" but file is named \"{}\"".format(board_header, lineno, include_suggestion, expected_include_suggestion)) - # look for "#ifndef BLAH_BLAH" - m = re.match(r"^#ifndef (\w+)\s*$", line) + raise Exception("{}:{} Suggests including \"{}\" but file is named \"{}\"".format(board_header, lineno, include_suggestion, expected_include_suggestion)) + continue + + # look for "// pico_cmake_set BLAH_BLAH=42" + m = re.match(r"^\s*//\s*pico_cmake_set\s+(\w+)\s*=\s*(.+?)\s*$", line) if m: - last_ifndef = m.group(1) - last_ifndef_lineno = lineno - # look for "#define BLAH_BLAH" or "#define BLAH_BLAH 42" - m = re.match(r"^#define (\w+)(?:\s+(.+?))?\s*$", line) + #print(m.groups()) + name = m.group(1) + value = m.group(2) + # check all uppercase + if name != name.upper(): + raise Exception("{}:{} Expected \"{}\" to be all uppercase".format(board_header, lineno, name)) + # check for multiply-defined values + if name in cmake_settings: + raise Exception("{}:{} Multiple values for pico_cmake_set {} ({} and {})".format(board_header, lineno, name, cmake_settings[name].value, value)) + else: + cmake_settings[name] = DefineType(name, value, None, lineno) + continue + + # look for "// pico_cmake_set_default BLAH_BLAH=42" + m = re.match(r"^\s*//\s*pico_cmake_set_default\s+(\w+)\s*=\s*(.+?)\s*$", line) if m: #print(m.groups()) name = m.group(1) value = m.group(2) # check all uppercase if name != name.upper(): - raise Exception(r"{}:{} Expected \"{}\" to be all uppercase".format(board_header, lineno, name)) - # check that adjacent #ifndef and #define lines match up - if last_ifndef_lineno + 1 == lineno: - if last_ifndef != name: - raise Exception("{}:{} #ifndef {} / #define {} mismatch".format(board_header, last_ifndef_lineno, last_ifndef, name)) - if value: - try: - # most board-defines are integer values - value = int(value, 0) - except ValueError: - pass - - # resolve nested defines - resolved_value = value - while resolved_value in defines: - resolved_value = defines[resolved_value].resolved_value + raise Exception("{}:{} Expected \"{}\" to be all uppercase".format(board_header, lineno, name)) + # check for multiply-defined values + if name in cmake_default_settings: + raise Exception("{}:{} Multiple values for pico_cmake_set_default {} ({} and {})".format(board_header, lineno, name, cmake_default_settings[name].value, value)) else: - resolved_value = None + cmake_default_settings[name] = DefineType(name, value, None, lineno) + continue - define = DefineType(name, value, resolved_value, lineno) + # look for "#else" + m = re.match(r"^\s*#else\s*$", line) + if m: + validity_stack[-1] = not validity_stack[-1] + continue - # check the include-guard define - if re.match(r"^_BOARDS_(\w+)_H$", name): - # check it has an #ifndef - if last_ifndef_lineno +1 != lineno: - raise Exception("{}:{} Include-guard #define {} is missing an #ifndef".format(board_header, lineno, name)) - if value: - raise Exception("{}:{} Include-guard #define {} shouldn't have a value".format(board_header, lineno, name)) - if len(defines): - raise Exception("{}:{} Include-guard #define {} should be the first define".format(board_header, lineno, name)) - if name == expected_include_guard: - has_include_guard = True - else: - raise Exception("{}:{} Found include-guard #define {} but expected {}".format(board_header, lineno, name, expected_include_guard)) - # check board-detection define - if board_detection_is_next: - board_detection_is_next = False + # look for #endif + m = re.match(r"^\s*#endif\s*$", line) + if m: + validity_stack.pop() + continue + + if validity_stack[-1]: + # look for "#include "foo.h" + m = re.match(r"""^\s*#include\s+"(.+?)"\s*$""", line) + if m: + include = m.group(1) + #print("Found include \"{}\" in {}".format(include, board_header)) + assert include.endswith(".h") + # assume that the include is also in the boards directory + assert "/" not in include or include.startswith("boards/") + read_defines_from(os.path.join(os.path.dirname(board_header), os.path.basename(include)), defines) + continue + + # look for "#if BLAH_BLAH" + m = re.match(r"^\s*#if\s+(!)?\s*(\w+)\s*$", line) + if m: + valid = bool(defines[m.group(2)].resolved_value) + if m.group(1): + valid = not valid + validity_stack.append(valid) + continue + + # look for "#ifdef BLAH_BLAH" + m = re.match(r"^\s*#ifdef\s+(\w+)\s*$", line) + if m: + validity_stack.append(m.group(1) in defines) + continue + + # look for "#ifndef BLAH_BLAH" + m = re.match(r"^\s*#ifndef\s+(\w+)\s*$", line) + if m: + last_ifndef = m.group(1) + last_ifndef_lineno = lineno + validity_stack.append(last_ifndef not in defines) + continue + + # look for "#define BLAH_BLAH" or "#define BLAH_BLAH 42" + m = re.match(r"^\s*#define\s+(\w+)(?:\s+(.+?))?\s*$", line) + if m: + #print(m.groups()) + name = m.group(1) + value = m.group(2) + # check all uppercase + if name != name.upper(): + raise Exception("{}:{} Expected \"{}\" to be all uppercase".format(board_header, lineno, name)) + # check that adjacent #ifndef and #define lines match up + if last_ifndef_lineno + 1 == lineno: + if last_ifndef != name: + raise Exception("{}:{} #ifndef {} / #define {} mismatch".format(board_header, last_ifndef_lineno, last_ifndef, name)) if value: - raise Exception("{}:{} Board-detection #define {} shouldn't have a value".format(board_header, lineno, name)) - # this is a bit messy because pico.h does "#define RASPBERRYPI_PICO" and metrotech_xerxes_rp2040.h does "#define XERXES_RP2040" - if name.endswith(expected_board_detection) or expected_board_detection.endswith(name): - has_board_detection = True - else: - raise Exception("{}:{} Board-detection #define {} should end with {}".format(board_header, lineno, name, expected_board_detection)) - # check for multiply-defined values - if name in defines: - raise Exception("{}:{} Multiple definitions for {} ({} and {})".format(board_header, lineno, name, defines[name].value, value)) - else: - defines[name] = define - - # check for pin-conflicts - if name.endswith("_PIN"): - if resolved_value is None: - raise Exception("{}:{} {} is set to an undefined value".format(board_header, lineno, name)) - elif not isinstance(resolved_value, int): - raise Exception("{}:{} {} resolves to a non-integer value {}".format(board_header, lineno, name, resolved_value)) + try: + # most board-defines are integer values + value = int(value, 0) + except ValueError: + pass + + # resolve nested defines + resolved_value = value + while resolved_value in defines: + resolved_value = defines[resolved_value].resolved_value else: - if resolved_value in pins and resolved_value == value: - if show_warnings: - warnings.warn("{}:{} Both {} and {} claim to be pin {}".format(board_header, lineno, pins[resolved_value][0].name, name, resolved_value)) - pins[resolved_value].append(define) + resolved_value = None + + # check the include-guard define + if re.match(r"^_BOARDS_(\w+)_H$", name): + # check it has an #ifndef + if last_ifndef_lineno +1 != lineno: + raise Exception("{}:{} Include-guard #define {} is missing an #ifndef".format(board_header, lineno, name)) + if value: + raise Exception("{}:{} Include-guard #define {} shouldn't have a value".format(board_header, lineno, name)) + if len(defines) and not (len(defines) == 1 and defines[list(defines.keys())[0]].lineno < 0): + raise Exception("{}:{} Include-guard #define {} should be the first define".format(board_header, lineno, name)) + if name == expected_include_guard: + has_include_guard = True else: - if resolved_value not in allowed_pins: - raise Exception("{}:{} Pin {} for {} isn't a valid pin-number".format(board_header, lineno, resolved_value, name)) - pins[resolved_value] = [define] + raise Exception("{}:{} Found include-guard #define {} but expected {}".format(board_header, lineno, name, expected_include_guard)) + # check board-detection define + if board_detection_is_next: + board_detection_is_next = False + if value: + raise Exception("{}:{} Board-detection #define {} shouldn't have a value".format(board_header, lineno, name)) + # this is a bit messy because pico.h does "#define RASPBERRYPI_PICO" and metrotech_xerxes_rp2040.h does "#define XERXES_RP2040" + if name.endswith(expected_board_detection) or expected_board_detection.endswith(name): + has_board_detection = True + else: + raise Exception("{}:{} Board-detection #define {} should end with {}".format(board_header, lineno, name, expected_board_detection)) + # check for multiply-defined values + if name in defines: + raise Exception("{}:{} Multiple definitions for {} ({} and {})".format(board_header, lineno, name, defines[name].value, value)) + else: + defines[name] = DefineType(name, value, resolved_value, lineno) + continue + #import pprint; pprint.pprint(dict(sorted(defines.items(), key=lambda x: x[1].lineno))) +#import pprint; pprint.pprint(dict(sorted(cmake_settings.items(), key=lambda x: x[1].lineno))) +#import pprint; pprint.pprint(dict(sorted(cmake_default_settings.items(), key=lambda x: x[1].lineno))) +chip = None +if board_header_basename == "none.h": + chip = 'RP2040' + other_chip = 'RP2350' +else: + if 'PICO_PLATFORM' not in cmake_settings: + raise Exception("{} is missing a pico_cmake_set {} comment".format(board_header, 'PICO_PLATFORM')) + if cmake_settings['PICO_PLATFORM'].value == "rp2040": + chip = 'RP2040' + other_chip = 'RP2350' + elif cmake_settings['PICO_PLATFORM'].value == "rp2350": + other_chip = 'RP2040' + if 'PICO_RP2350A' in defines and defines['PICO_RP2350A'].resolved_value == 1: + chip = 'RP2350A' + else: + chip = 'RP2350B' + if not board_header.endswith("amethyst_fpga.h"): + if 'PICO_RP2350_A2_SUPPORTED' not in defines: + raise Exception("{} uses chip {} but is missing a #define {}".format(board_header, chip, 'PICO_RP2350_A2_SUPPORTED')) + if defines['PICO_RP2350_A2_SUPPORTED'].resolved_value != 1: + raise Exception("{} sets #define {} {} (should be 1)".format(board_header, chip, 'PICO_RP2350_A2_SUPPORTED', defines['PICO_RP2350_A2_SUPPORTED'].resolved_value)) + if 'PICO_FLASH_SIZE_BYTES' not in cmake_default_settings: + raise Exception("{} is missing a pico_cmake_set_default {} comment".format(board_header, 'PICO_FLASH_SIZE_BYTES')) + if 'PICO_FLASH_SIZE_BYTES' not in defines: + raise Exception("{} is missing a #define {}".format(board_header, 'PICO_FLASH_SIZE_BYTES')) + if cmake_default_settings['PICO_FLASH_SIZE_BYTES'].value != defines['PICO_FLASH_SIZE_BYTES'].resolved_value: + raise Exception("{} has mismatched pico_cmake_set_default and #define values for {}".format(board_header, 'PICO_FLASH_SIZE_BYTES')) -# check for invalid DEFAULT mappings +if chip is None: + raise Exception("Couldn't determine chip for {}".format(board_header)) +interfaces_json = chip_interfaces[chip] +if not os.path.isfile(interfaces_json): + raise Exception("{} doesn't exist".format(interfaces_json)) + +with open(interfaces_json) as interfaces_fh: + interface_pins = json.load(interfaces_fh) + allowed_interfaces = interface_pins["interfaces"] + allowed_pins = set(interface_pins["pins"]) + # convert instance-keys to integers (allowed by Python but not by JSON) + for interface in allowed_interfaces: + instances = allowed_interfaces[interface]["instances"] + # can't modify a list that we're iterating over, so iterate over a copy + instances_copy = list(instances) + for instance in instances_copy: + instance_num = int(instance) + instances[instance_num] = instances.pop(instance) + +pins = dict() # dict of lists for name, define in defines.items(): + + # check for other-chip defines + if other_chip in name: + raise Exception("{}:{} Header is for {} and so shouldn't have settings for {} ({})".format(board_header, define.lineno, chip, other_chip, name)) + + # check for pin-conflicts + if name.endswith("_PIN"): + if define.resolved_value is None: + raise Exception("{}:{} {} is set to an undefined value".format(board_header, define.lineno, name)) + elif not isinstance(define.resolved_value, int): + raise Exception("{}:{} {} resolves to a non-integer value {}".format(board_header, define.lineno, name, define.resolved_value)) + else: + if define.resolved_value in pins and define.resolved_value == define.value: + if show_warnings: + warnings.warn("{}:{} Both {} and {} claim to be pin {}".format(board_header, define.lineno, pins[define.resolved_value][0].name, name, define.resolved_value)) + pins[define.resolved_value].append(define) + else: + if define.resolved_value not in allowed_pins: + raise Exception("{}:{} Pin {} for {} isn't a valid pin-number".format(board_header, define.lineno, define.resolved_value, name)) + pins[define.resolved_value] = [define] + + # check for invalid DEFAULT mappings m = re.match("^(PICO_DEFAULT_([A-Z0-9]+))_([A-Z0-9]+)_PIN$", name) if m: instance_name = m.group(1) @@ -180,17 +449,7 @@ if define.resolved_value not in interface_instance[function]: raise Exception("{}:{} {} is set to {} which isn't a valid pin for {} on {} {}".format(board_header, define.lineno, name, define.resolved_value, function, interface, instance_num)) -def list_to_string_with(lst, joiner): - elems = len(lst) - if elems == 0: - return "" - elif elems == 1: - return str(lst[0]) - else: - return "{} {} {}".format(", ".join(str(l) for l in lst[:-1]), joiner, lst[-1]) - -# check that each used DEFAULT interface includes (at least) the expected pin-functions -for name, define in defines.items(): + # check that each used DEFAULT interface includes (at least) the expected pin-functions m = re.match("^PICO_DEFAULT_([A-Z0-9]+)$", name) if m: interface = m.group(1) @@ -216,3 +475,5 @@ def list_to_string_with(lst, joiner): #if not has_include_suggestion: # raise Exception("{} has no include-suggestion (expected {})".format(board_header, expected_include_suggestion)) +# Check that #if / #ifdef / #ifndef / #else / #endif are correctly balanced +assert len(validity_stack) == 1 and validity_stack[0]