From 967cbc5c3dae186e0c364712f1ac860fe116d0e4 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Tue, 2 Mar 2021 21:37:46 +0000 Subject: [PATCH] Fixup PICO_CONFIG entries (#208) * remove default=undefined * fix a couple of typos / syntax "errors" * perform even better default-value-checking in extract_configs.py --- src/common/pico_stdlib/include/pico/stdlib.h | 8 ++++---- src/rp2_common/hardware_i2c/include/hardware/i2c.h | 6 +++--- src/rp2_common/hardware_spi/include/hardware/spi.h | 10 +++++----- src/rp2_common/hardware_uart/include/hardware/uart.h | 6 +++--- .../pico_stdio_usb/include/pico/stdio_usb.h | 2 +- tools/extract_configs.py | 11 ++++++++--- 6 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/common/pico_stdlib/include/pico/stdlib.h b/src/common/pico_stdlib/include/pico/stdlib.h index 7f72376..a35b64f 100644 --- a/src/common/pico_stdlib/include/pico/stdlib.h +++ b/src/common/pico_stdlib/include/pico/stdlib.h @@ -56,15 +56,15 @@ extern "C" { #include "pico/stdio_semihosting.h" #endif -// PICO_CONFIG: PICO_DEFAULT_LED_PIN, Optionally defined a pin that drives a regular LED on the board, default=undefined, group=pico_stdlib +// PICO_CONFIG: PICO_DEFAULT_LED_PIN, Optionally define a pin that drives a regular LED on the board, group=pico_stdlib -// PICO_CONFIG: PICO_DEFAULT_LED_PIN_INVERTED, 1 if LED is inverted, 0 otherwise, type=int, default=0, group=pico_stdlib +// PICO_CONFIG: PICO_DEFAULT_LED_PIN_INVERTED, 1 if LED is inverted or 0 if not, type=int, default=0, group=pico_stdlib #ifndef PICO_DEFAULT_LED_PIN_INVERTED #define PICO_DEFAULT_LED_PIN_INVERTED 0 #endif -// PICO_CONFIG: PICO_DEFAULT_WS2812_PIN, Optionally defined a pin that controls data to a WS2812 compatible LED on the board, default=undefined, group=pico_stdlib -// PICO_CONFIG: PICO_DEFAULT_WS2812_POWER_PIN, Optionally defined a pin that controls power to a WS2812 compatible LED on the board, default=undefined, group=pico_stdlib +// PICO_CONFIG: PICO_DEFAULT_WS2812_PIN, Optionally define a pin that controls data to a WS2812 compatible LED on the board, group=pico_stdlib +// PICO_CONFIG: PICO_DEFAULT_WS2812_POWER_PIN, Optionally define a pin that controls power to a WS2812 compatible LED on the board, group=pico_stdlib /*! \brief Set up the default UART and assign it to the default GPIO's * \ingroup pico_stdlib diff --git a/src/rp2_common/hardware_i2c/include/hardware/i2c.h b/src/rp2_common/hardware_i2c/include/hardware/i2c.h index 7d6760d..b0886df 100644 --- a/src/rp2_common/hardware_i2c/include/hardware/i2c.h +++ b/src/rp2_common/hardware_i2c/include/hardware/i2c.h @@ -48,9 +48,9 @@ extern "C" { typedef struct i2c_inst i2c_inst_t; -// PICO_CONFIG: PICO_DEFAULT_I2C, Define the default I2C for a board, default=undefined, group=hardware_i2c -// PICO_CONFIG: PICO_DEFAULT_I2C_SDA_PIN, Define the default I2C SDA, min=0, max=29, default=undefined, group=hardware_i2c -// PICO_CONFIG: PICO_DEFAULT_I2C_SCL_PIN, Define the default I2C SCL pin, min=0, max=29, default=undefined, group=hardware_i2c +// PICO_CONFIG: PICO_DEFAULT_I2C, Define the default I2C for a board, group=hardware_i2c +// PICO_CONFIG: PICO_DEFAULT_I2C_SDA_PIN, Define the default I2C SDA pin, min=0, max=29, group=hardware_i2c +// PICO_CONFIG: PICO_DEFAULT_I2C_SCL_PIN, Define the default I2C SCL pin, min=0, max=29, group=hardware_i2c /** The I2C identifiers for use in I2C functions. * diff --git a/src/rp2_common/hardware_spi/include/hardware/spi.h b/src/rp2_common/hardware_spi/include/hardware/spi.h index a913e67..98fb4bd 100644 --- a/src/rp2_common/hardware_spi/include/hardware/spi.h +++ b/src/rp2_common/hardware_spi/include/hardware/spi.h @@ -35,11 +35,11 @@ extern "C" { * Each controller can be connected to a number of GPIO pins, see the datasheet GPIO function selection table for more information. */ -// PICO_CONFIG: PICO_DEFAULT_SPI, Define the default SPI for a board, default=undefined, group=hardware_spi -// PICO_CONFIG: PICO_DEFAULT_SPI_SCK_PIN, Define the default SPI SCK pin, min=0, max=29, default=undefined, group=hardware_spi -// PICO_CONFIG: PICO_DEFAULT_SPI_TX_PIN, Define the default SPI TX pin, min=0, max=29, default=undefined, group=hardware_spi -// PICO_CONFIG: PICO_DEFAULT_SPI_RX_PIN, Define the default SPI RX pin, min=0, max=29, default=undefined, group=hardware_spi -// PICO_CONFIG: PICO_DEFAULT_SPI_CSN_PIN, Define the default SPI CSN pin, min=0, max=29, default=undefined, group=hardware_spi +// PICO_CONFIG: PICO_DEFAULT_SPI, Define the default SPI for a board, group=hardware_spi +// PICO_CONFIG: PICO_DEFAULT_SPI_SCK_PIN, Define the default SPI SCK pin, min=0, max=29, group=hardware_spi +// PICO_CONFIG: PICO_DEFAULT_SPI_TX_PIN, Define the default SPI TX pin, min=0, max=29, group=hardware_spi +// PICO_CONFIG: PICO_DEFAULT_SPI_RX_PIN, Define the default SPI RX pin, min=0, max=29, group=hardware_spi +// PICO_CONFIG: PICO_DEFAULT_SPI_CSN_PIN, Define the default SPI CSN pin, min=0, max=29, group=hardware_spi /** * Opaque type representing an SPI instance. diff --git a/src/rp2_common/hardware_uart/include/hardware/uart.h b/src/rp2_common/hardware_uart/include/hardware/uart.h index 69ade78..7cfa78e 100644 --- a/src/rp2_common/hardware_uart/include/hardware/uart.h +++ b/src/rp2_common/hardware_uart/include/hardware/uart.h @@ -29,9 +29,9 @@ extern "C" { #define PICO_UART_DEFAULT_CRLF 0 #endif -// PICO_CONFIG: PICO_DEFAULT_UART, Define the default UART used for printf etc, default=undefined, group=hardware_uart -// PICO_CONFIG: PICO_DEFAULT_UART_TX_PIN, Define the default UART TX pin, min=0, max=29, default=undefined, group=hardware_uart -// PICO_CONFIG: PICO_DEFAULT_UART_RX_PIN, Define the default UART RX pin, min=0, max=29, default=undefined, group=hardware_uart +// PICO_CONFIG: PICO_DEFAULT_UART, Define the default UART used for printf etc, group=hardware_uart +// PICO_CONFIG: PICO_DEFAULT_UART_TX_PIN, Define the default UART TX pin, min=0, max=29, group=hardware_uart +// PICO_CONFIG: PICO_DEFAULT_UART_RX_PIN, Define the default UART RX pin, min=0, max=29, group=hardware_uart // PICO_CONFIG: PICO_DEFAULT_UART_BAUD_RATE, Define the default UART baudrate, max=921600, default=115200, group=hardware_uart #ifndef PICO_DEFAULT_UART_BAUD_RATE diff --git a/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h b/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h index acb9dce..b85b83b 100644 --- a/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h +++ b/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h @@ -49,7 +49,7 @@ #define PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE 1 #endif -// PICO_CONFIG: PICO_STDIO_USB_RESET_MAGIC_BAUD_RATE, baud rate that if selected causes a reset into BOOTSEL mode (if PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE==1), default=1200, group=pico_stdio_usb +// PICO_CONFIG: PICO_STDIO_USB_RESET_MAGIC_BAUD_RATE, baud rate that if selected causes a reset into BOOTSEL mode (if PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE is set), default=1200, group=pico_stdio_usb #ifndef PICO_STDIO_USB_RESET_MAGIC_BAUD_RATE #define PICO_STDIO_USB_RESET_MAGIC_BAUD_RATE 1200 #endif diff --git a/tools/extract_configs.py b/tools/extract_configs.py index 3c0a2e7..0c8a881 100755 --- a/tools/extract_configs.py +++ b/tools/extract_configs.py @@ -149,7 +149,7 @@ for dirpath, dirnames, filenames in os.walk(scandir): k, v = (i.strip() for i in item.split('=')) except ValueError: raise Exception('{} at {}:{} has malformed value {}'.format(config_name, file_path, linenum, item)) - config_attrs[k] = v.replace('\0', ',') if v != 'undefined' else None + config_attrs[k] = v.replace('\0', ',') all_attrs.add(k) prev = item #print(file_path, config_name, config_attrs) @@ -178,9 +178,14 @@ for dirpath, dirnames, filenames in os.walk(scandir): all_defines[name][value] = (file_path, linenum) # Check for defines with missing PICO_CONFIG entries +resolved_defines = dict() for d in all_defines: if d not in all_configs and d.startswith("PICO_"): logger.warning("Potential unmarked PICO define {}".format(d)) + # resolve "nested defines" - this allows e.g. USB_DPRAM_MAX to resolve to USB_DPRAM_SIZE which is set to 4096 (which then matches the relevant PICO_CONFIG entry) + for val in all_defines[d]: + if val in all_defines: + resolved_defines[d] = all_defines[val] for config_name in all_configs: @@ -189,8 +194,8 @@ for config_name in all_configs: # Check that default values match up if 'default' in all_configs[config_name]['attrs']: if config_name in all_defines: - if all_configs[config_name]['attrs']['default'] not in all_defines[config_name] and (all_configs[config_name]['attrs'].get('type', 'int') != 'bool'): - if config_name in ['USB_DPRAM_MAX'] or '/' in all_configs[config_name]['attrs']['default']: + if all_configs[config_name]['attrs']['default'] not in all_defines[config_name] and (config_name not in resolved_defines or all_configs[config_name]['attrs']['default'] not in resolved_defines[config_name]): + if '/' in all_configs[config_name]['attrs']['default'] or ' ' in all_configs[config_name]['attrs']['default']: continue # There _may_ be multiple matching defines, but arbitrarily display just one in the error message first_define_value = list(all_defines[config_name].keys())[0]