ronantakizawa/codereview-bench huggingface dataset:
Repository: rails/rails
File: actiontext/test/unit/markdown_conversion_test.rb (Ruby)

Code before:
    assert_converted_to("### hello", "<h3>hello</h3>")
    assert_converted_to("#### hello", "<h4>hello</h4>")
    assert_converted_to("##### hello", "<h5>hello</h5>")
    assert_converted_to("###### hello", "<h6>hello</h6>")
  end

  test "<blockquote> tags are converted to quoted lines" do
    assert_converted_to("> hello", "<blockquote>hello</blockquote>")
  end

  test "<blockquote> with multiple lines prefixes each line" do
    assert_converted_to(
      "> line1\n> line2",
      "<blockquote>line1\nline2</blockquote>"
    )
  end

  test "nested <blockquote> tags produce nested quotes" do
    assert_converted_to(
      "> this is a quote\n> > of a quote",
      "<blockquote>this is a quote<blockquote>of a quote</blockquote></blockquote>"
    )
  end

  test "<br> tags are converted to newlines" do
    assert_converted_to("hello\nworld", "hello<br>world")
  end

  test "<hr> tags are converted to thematic breaks" do
    assert_converted_to("---", "<hr>")
  end

  test "<pre> tags are converted to fenced code blocks" do
    assert_converted_to("```\nhello\n```", "<pre>hello</pre>")
  end

  test "<pre> with nested <code> tag is converted to fenced code block" do
    assert_converted_to("```\nhello\n```", "<pre><code>hello</code></pre>")
  end

  test "<pre> preserves inner blank lines" do
    assert_converted_to(
      "```\n\nblank first line\n```",
      "<pre><code>\n\nblank first line\n</code></pre>"
    )
  end

  test "<pre> preserves leading and trailing spaces on lines" do
    assert_converted_to(
      "```\n  indented\nline  \n```",
      "<pre><code>  indented\nline  </code></pre>"

Review comment (suggestion):
Consider a pretty-printed/indented HTML case to ensure indentation text nodes don’t leak into markdown output

Code after:
      "hello\n\nworld",
      "<p>hello</p><p>world</p>"
    )
  end

  test "Lexxy-style pretty-printed <p> tags do not leak indentation into markdown" do
    assert_converted_to(
      "hello\n\nworld",
      <<~HTML
        <p>
          hello
        </p>
        <p>
          world
        </p>
      HTML
    )
  end

  test "Trix-style <div> blocks with <br> line breaks do not get additional newlines" do
    assert_converted_to(
      "Line one.\n\n**Subject header**\n\nLine two.",
      "<div>Line one.<br><br></div><div><strong>Subject header<br></strong><br></div><div>Line two.<br><br></div><div><br></div>"
    )
  end

  test "Trix-style pretty-printed HTML does not leak indentation into markdown" do
    assert_converted_to(
      "Line one.\n\n**Subject header**\n\nLine two.",
      <<~HTML
        <div>
          Line one.
          <br>
          <br>
        </div>
        <div>
          <strong>
            Subject header
            <br>
          </strong>
          <br>
        </div>
        <div>
          Line two.
          <br>
          <br>
        </div>
        <div>
          <br>
        </div>
      HTML
Repository: raspberrypi/pico-sdk
File: src/rp2_common/hardware_xosc/xosc.c (C)

Code before:
/*
 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include "pico.h"

// For MHZ definitions etc
#include "hardware/clocks.h"

#include "hardware/platform_defs.h"
#include "hardware/regs/xosc.h"
#include "hardware/structs/xosc.h"

// Allow lengthening startup delay to accommodate slow-starting oscillators

// PICO_CONFIG: PICO_XOSC_STARTUP_DELAY_MULTIPLIER, Multiplier to lengthen xosc startup delay to accommodate slow-starting oscillators, type=int, min=1, default=1, group=hardware_xosc
#ifndef PICO_XOSC_STARTUP_DELAY_MULTIPLIER
#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 1
#endif

#if XOSC_MHZ < 1 || XOSC_MHZ > 15
#error XOSC_MHZ must be in the range 1-15
#endif

#define STARTUP_DELAY (((((XOSC_MHZ * MHZ) / 1000) + 128) / 256) * PICO_XOSC_STARTUP_DELAY_MULTIPLIER)

// The DELAY field in xosc_hw->startup is 14 bits wide.
#if STARTUP_DELAY >= (1 << 13)
#error PICO_XOSC_STARTUP_DELAY_MULTIPLIER is too large: XOSC STARTUP.DELAY must be < 8192
#endif

void xosc_init(void) {
    // Assumes 1-15 MHz input, checked above.
    xosc_hw->ctrl = XOSC_CTRL_FREQ_RANGE_VALUE_1_15MHZ;

    // Set xosc startup delay
    xosc_hw->startup = STARTUP_DELAY;

    // Set the enable bit now that we have set freq range and startup delay
    hw_set_bits(&xosc_hw->ctrl, XOSC_CTRL_ENABLE_VALUE_ENABLE << XOSC_CTRL_ENABLE_LSB);


Review comment (refactor):
stylistically (going forward, there may be a few stragglers) we are trying to put these  defaulted values in the header in case any other code (source files) cares about the actual value. can you move this to xsoc.h

Code after:
/*
 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include "pico.h"

// For MHZ definitions etc
#include "hardware/clocks.h"

#include "hardware/platform_defs.h"
#include "hardware/regs/xosc.h"
#include "hardware/xosc.h"

#if XOSC_MHZ < 1 || XOSC_MHZ > 15
#error XOSC_MHZ must be in the range 1-15
#endif

#define STARTUP_DELAY (((((XOSC_MHZ * MHZ) / 1000) + 128) / 256) * PICO_XOSC_STARTUP_DELAY_MULTIPLIER)

// The DELAY field in xosc_hw->startup is 14 bits wide.
#if STARTUP_DELAY >= (1 << 13)
#error PICO_XOSC_STARTUP_DELAY_MULTIPLIER is too large: XOSC STARTUP.DELAY must be < 8192
#endif

void xosc_init(void) {
    // Assumes 1-15 MHz input, checked above.
    xosc_hw->ctrl = XOSC_CTRL_FREQ_RANGE_VALUE_1_15MHZ;

    // Set xosc startup delay
    xosc_hw->startup = STARTUP_DELAY;

    // Set the enable bit now that we have set freq range and startup delay
    hw_set_bits(&xosc_hw->ctrl, XOSC_CTRL_ENABLE_VALUE_ENABLE << XOSC_CTRL_ENABLE_LSB);

    // Wait for XOSC to be stable
    while(!(xosc_hw->status & XOSC_STATUS_STABLE_BITS));
}

void xosc_disable(void) {
    uint32_t tmp = xosc_hw->ctrl;
    tmp &= (~XOSC_CTRL_ENABLE_BITS);
Repository: raspberrypi/pico-sdk
File: src/common/pico_sync/mutex.c (C)

Code before:
    lock_internal_spin_unlock_with_notify(&mtx->core, save);
}

static void __time_critical_func(mutex_exit_r_guts)(mutex_t *mtx) {
    uint32_t save = spin_lock_blocking(mtx->core.spin_lock);
    assert(mtx->enter_count);
    if (!--mtx->enter_count) {
        lock_internal_spin_unlock_with_notify(&mtx->core, save);
    } else {
        spin_unlock(mtx->core.spin_lock, save);
    }
}

void __time_critical_func(mutex_exit_nr)(mutex_t *mtx) {
    assert(!mtx->recursive);
    mutex_exit_nr_guts(mtx);
}

void __time_critical_func(mutex_exit_r)(mutex_t *mtx) {
    assert(mtx->recursive);
    mutex_exit_r_guts(mtx);
}

void __time_critical_func(mutex_exit)(mutex_t *mtx) {
    if (!mtx->recursive) {
        mutex_exit_nr_guts(mtx);
    } else {
        mutex_exit_r_guts(mtx);
    }
}

Review comment (suggestion):
Trying to compare the old-code with the new-code, is an `mtx->owner = LOCK_INVALID_OWNER_ID;` also needed before this line? Or is that not necessary now? :shrug: 

Code after:
            }
            // not timed out; spin lock already unlocked, so loop again
        }
    } while (true);
}

void __time_critical_func(mutex_exit)(mutex_t *mtx) {
#if PICO_MUTEX_ENABLE_SDK120_COMPATIBILITY
    if (mtx->recursive) {
        recursive_mutex_exit(mtx);
        return;
    }
#endif
    uint32_t save = spin_lock_blocking(mtx->core.spin_lock);
    assert(lock_is_owner_id_valid(mtx->owner));
    mtx->owner = LOCK_INVALID_OWNER_ID;
    lock_internal_spin_unlock_with_notify(&mtx->core, save);
}

void __time_critical_func(recursive_mutex_exit)(recursive_mutex_t *mtx) {
    uint32_t save = spin_lock_blocking(mtx->core.spin_lock);
    assert(lock_is_owner_id_valid(mtx->owner));
    assert(mtx->enter_count);
    if (!--mtx->enter_count) {
        mtx->owner = LOCK_INVALID_OWNER_ID;
        lock_internal_spin_unlock_with_notify(&mtx->core, save);
    } else {
        spin_unlock(mtx->core.spin_lock, save);
    }
}
Repository: raspberrypi/pico-sdk
File: src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h (C/C++)

Code before:
#define PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS 100
#endif

#ifdef __cplusplus
extern "C" {
#endif

extern stdio_driver_t stdio_usb;

/*! \brief Explicitly initialize USB stdio and add it to the current set of stdin drivers
 *  \ingroup pico_stdio_usb
 *
 *  \ref PICO_STDIO_USB_POST_CONNECT_WAIT_DELAY_MS can be set to cause this method to wait for a CDC connection
 *  from the host before returning, which is useful if you don't want any initial stdout output to be discarded
 *  before the connections is established.
 *
 *  \return true if the USB CDC was initialized, false if an error occurred
 */
bool stdio_usb_init(void);

/*! \brief Check if there is an active stdio CDC connection to a host
 *  \ingroup pico_stdio_usb
 *
 *  This method can be used in a loop to wait for a connection to be established with the host
 *  before starting to write to stdout (otherwise output is discarded).
 *
 *  Note that some host side terminal emulators seem to occasionally miss the first output
 *  even though the connection is established, so you may also want to sleep a few milliseconds after this
 *  method returns true.
 *
 *  \return true if stdio is connected over CDC
 */
bool stdio_usb_connected(void);
#ifdef __cplusplus
}
#endif

#endif


Review comment (bug):
I guess a common usage-idiom (for example-code that wants to be switchable between UART and USB-CDC using just the `CMakeLists.txt` mechanism) would be to wrap this inside a `#if LIB_PICO_STDIO_USB` ? Would that code need to also explicitly include `stdio_usb.h` inside a `#if LIB_PICO_STDIO_USB` too?
Or have I grabbed the totally wrong end of the stick? :upside_down_face: 

Code after:
#define PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS 100
#endif

#ifdef __cplusplus
extern "C" {
#endif

extern stdio_driver_t stdio_usb;

/*! \brief Explicitly initialize USB stdio and add it to the current set of stdin drivers
 *  \ingroup pico_stdio_usb
 *
 *  \ref PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS can be set to cause this method to wait for a CDC connection
 *  from the host before returning, which is useful if you don't want any initial stdout output to be discarded
 *  before the connection is established.
 *
 *  \return true if the USB CDC was initialized, false if an error occurred
 */
bool stdio_usb_init(void);

/*! \brief Check if there is an active stdio CDC connection to a host
 *  \ingroup pico_stdio_usb
 *
 *  \return true if stdio is connected over CDC
 */
bool stdio_usb_connected(void);
#ifdef __cplusplus
}
#endif

#endif
Repository: raspberrypi/pico-sdk
File: src/boards/include/boards/pybstick26_rp2040.h (C/C++)

Code before:
/*
 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

// -----------------------------------------------------
// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO
//       SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES
// -----------------------------------------------------

// This header may be included by other board headers as "boards/pybstick26_rp2040.h"

#ifndef _BOARDS_PYBSTICK26_RP2040_H
#define _BOARDS_PYBSTICK26_RP2040_H

// For board detection
#define PYBSTICK26_RP2040

// --- UART ---
#ifndef PICO_DEFAULT_UART
#define PICO_DEFAULT_UART 0
#endif
#ifndef PICO_DEFAULT_UART_TX_PIN
#define PICO_DEFAULT_UART_TX_PIN 0
#endif
#ifndef PICO_DEFAULT_UART_RX_PIN
#define PICO_DEFAULT_UART_RX_PIN 1
#endif

// --- LED ---
#ifndef PICO_DEFAULT_LED_PIN
#define PICO_DEFAULT_LED_PIN 23
#endif
// no PICO_DEFAULT_WS2812_PIN

// --- I2C ---

Review comment (suggestion):
Sorry, looking at the other files in the `src/boards/include/boards/` directory, I now realise that it's probably better to get rid of this line entirely.

Code after:
/*
 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

// -----------------------------------------------------
// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO
//       SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES
// -----------------------------------------------------

#ifndef _BOARDS_PYBSTICK26_RP2040_H
#define _BOARDS_PYBSTICK26_RP2040_H

// For board detection
#define PYBSTICK26_RP2040

// --- UART ---
#ifndef PICO_DEFAULT_UART
#define PICO_DEFAULT_UART 0
#endif
#ifndef PICO_DEFAULT_UART_TX_PIN
#define PICO_DEFAULT_UART_TX_PIN 0
#endif
#ifndef PICO_DEFAULT_UART_RX_PIN
#define PICO_DEFAULT_UART_RX_PIN 1
#endif

// --- LED ---
#ifndef PICO_DEFAULT_LED_PIN
#define PICO_DEFAULT_LED_PIN 23
#endif
// no PICO_DEFAULT_WS2812_PIN

// --- I2C ---
#ifndef PICO_DEFAULT_I2C
#define PICO_DEFAULT_I2C 1
Repository: raspberrypi/pico-sdk
File: src/boards/include/boards/pybstick26_rp2040.h (C/C++)

Code before:
#endif
#ifndef PICO_DEFAULT_SPI_RX_PIN
#define PICO_DEFAULT_SPI_RX_PIN 8
#endif
#ifndef PICO_DEFAULT_SPI_CSN_PIN
#define PICO_DEFAULT_SPI_CSN_PIN 9
#endif

// --- FLASH ---

#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1

#ifndef PICO_FLASH_SPI_CLKDIV
#define PICO_FLASH_SPI_CLKDIV 2 
#endif

#ifndef PICO_FLASH_SIZE_BYTES
#define PICO_FLASH_SIZE_BYTES (1 * 1024 * 1024)
#endif

// Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads)
// Linear regulator on Pybstick26
//#define PICO_SMPS_MODE_PIN 23

// All boards have B1 RP2040
#ifndef PICO_RP2040_B0_SUPPORTED 
#define PICO_RP2040_B0_SUPPORTED  0
#endif


Review comment (suggestion):
This `#endif` matches up with `#ifndef PICO_RP2040_B0_SUPPORTED`, but you seem to have lost the final `#endif` that matches up with the `#ifndef _BOARDS_PYBSTICK26_RP2040_H` ?
TLDR: you need another `#endif` line at the bottom :wink: 

Code after:
#define PICO_DEFAULT_SPI_RX_PIN 8
#endif
#ifndef PICO_DEFAULT_SPI_CSN_PIN
#define PICO_DEFAULT_SPI_CSN_PIN 9
#endif

// --- FLASH ---

#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1

#ifndef PICO_FLASH_SPI_CLKDIV
#define PICO_FLASH_SPI_CLKDIV 2 
#endif

#ifndef PICO_FLASH_SIZE_BYTES
#define PICO_FLASH_SIZE_BYTES (1 * 1024 * 1024)
#endif

// Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads)
// Linear regulator on Pybstick26
//#define PICO_SMPS_MODE_PIN 23

// All boards have B1 RP2040
#ifndef PICO_RP2040_B0_SUPPORTED 
#define PICO_RP2040_B0_SUPPORTED  0
#endif

#endif
// of #define _BOARDS_PYBSTICK26_RP2040_H
Repository: raspberrypi/pico-sdk
File: src/boards/include/boards/solderparty_rp2040_stamp.h (C/C++)

Code before:
//
// This header may be included by other board headers as "boards/solderparty_rp2040_stamp.h"

#ifndef _BOARDS_SOLDERPARTY_RP2040_STAMP_H
#define _BOARDS_SOLDERPARTY_RP2040_STAMP_H

// For board detection
#define SOLDERPARTY_RP2040_STAMP

// --- UART ---
#ifndef PICO_DEFAULT_UART
#define PICO_DEFAULT_UART 0
#endif
#ifndef PICO_DEFAULT_UART_TX_PIN
#define PICO_DEFAULT_UART_TX_PIN 0
#endif
#ifndef PICO_DEFAULT_UART_RX_PIN
#define PICO_DEFAULT_UART_RX_PIN 1
#endif

// Red LED on the Carrier
#ifndef PICO_DEFAULT_LED_PIN
#define PICO_DEFAULT_LED_PIN   20
#endif

// Neopixel on the Stamp
#ifndef PICO_DEFAULT_WS2812_PIN
#define PICO_DEFAULT_WS2812_PIN 21
#endif

// --- I2C ---
#ifndef PICO_DEFAULT_I2C
#define PICO_DEFAULT_I2C       0
#endif
#ifndef PICO_DEFAULT_I2C_SDA_PIN
#define PICO_DEFAULT_I2C_SDA_PIN   4
#endif
#ifndef PICO_DEFAULT_I2C_SCL_PIN
#define PICO_DEFAULT_I2C_SCL_PIN   5
#endif

// --- SPI ---
#ifndef PICO_DEFAULT_SPI
#define PICO_DEFAULT_SPI 0
#endif
#ifndef PICO_DEFAULT_SPI_SCK_PIN
#define PICO_DEFAULT_SPI_SCK_PIN 18
#endif
#ifndef PICO_DEFAULT_SPI_TX_PIN
#define PICO_DEFAULT_SPI_TX_PIN 19
#endif

Review comment (suggestion):
My version of this was:

```
// no PICO_DEFAULT_LED_PIN
// WS2812 can be jumpered out of circuit (JP1/JP2).
#ifndef PICO_NO_WS2812
#ifndef PICO_DEFAULT_WS2812_PIN
#define PICO_DEFAULT_WS2812_PIN 21
#endif
#endif // PICO_NO_WS2812
```

I decided not to set 'LED PIN' because it's only on the carrier, not the stamp itself.

Code after:
//
// This header may be included by other board headers as "boards/solderparty_rp2040_stamp.h"

#ifndef _BOARDS_SOLDERPARTY_RP2040_STAMP_H
#define _BOARDS_SOLDERPARTY_RP2040_STAMP_H

// For board detection
#define SOLDERPARTY_RP2040_STAMP

// --- UART ---
#ifndef PICO_DEFAULT_UART
#define PICO_DEFAULT_UART 0
#endif
#ifndef PICO_DEFAULT_UART_TX_PIN
#define PICO_DEFAULT_UART_TX_PIN 0
#endif
#ifndef PICO_DEFAULT_UART_RX_PIN
#define PICO_DEFAULT_UART_RX_PIN 1
#endif

// --- Neopixel ---
#ifndef PICO_DEFAULT_WS2812_PIN
#define PICO_DEFAULT_WS2812_PIN 21
#endif

// --- I2C ---
#ifndef PICO_DEFAULT_I2C
#define PICO_DEFAULT_I2C       0
#endif
#ifndef PICO_DEFAULT_I2C_SDA_PIN
#define PICO_DEFAULT_I2C_SDA_PIN   4
#endif
#ifndef PICO_DEFAULT_I2C_SCL_PIN
#define PICO_DEFAULT_I2C_SCL_PIN   5
#endif

// --- SPI ---
#ifndef PICO_DEFAULT_SPI
#define PICO_DEFAULT_SPI 0
#endif
#ifndef PICO_DEFAULT_SPI_SCK_PIN
#define PICO_DEFAULT_SPI_SCK_PIN 18
#endif
#ifndef PICO_DEFAULT_SPI_TX_PIN
#define PICO_DEFAULT_SPI_TX_PIN 19
#endif
#ifndef PICO_DEFAULT_SPI_RX_PIN
#define PICO_DEFAULT_SPI_RX_PIN 16
#endif
#ifndef PICO_DEFAULT_SPI_CSN_PIN
#define PICO_DEFAULT_SPI_CSN_PIN 17
Repository: raspberrypi/pico-sdk
File: src/boards/include/boards/pimoroni_motor2040.h (C/C++)

Code before:
#define MOTOR2040_ENCODER_B_A_PIN 2
#endif

#ifndef MOTOR2040_ENCODER_B_B_PIN
#define MOTOR2040_ENCODER_B_B_PIN 3
#endif

#ifndef MOTOR2040_ENCODER_C_A_PIN
#define MOTOR2040_ENCODER_C_A_PIN 12
#endif

#ifndef MOTOR2040_ENCODER_C_B_PIN
#define MOTOR2040_ENCODER_C_B_PIN 13
#endif

#ifndef MOTOR2040_ENCODER_D_A_PIN
#define MOTOR2040_ENCODER_D_A_PIN 14
#endif

#ifndef MOTOR2040_ENCODER_D_B_PIN
#define MOTOR2040_ENCODER_D_B_PIN 15
#endif

#ifndef MOTOR2040_NUM_ENCODERS
#define MOTOR2040_NUM_ENCODERS 4
#endif

#ifndef MOTOR2040_TX_TRIG_PIN
#define MOTOR2040_TX_TRIG_PIN 16
#endif

#ifndef MOTOR2040_RX_ECHO_PIN
#define MOTOR2040_RX_ECHO_PIN 17
#endif

#ifndef MOTOR2040_LED_DATA_PIN
#define MOTOR2040_LED_DATA_PIN 18
#endif

#ifndef MOTOR2040_NUM_LEDS
#define MOTOR2040_NUM_LEDS 1
#endif

#ifndef MOTOR2040_I2C
#define MOTOR2040_I2C 0
#endif

#ifndef MOTOR2040_INT_PIN
#define MOTOR2040_INT_PIN 19
#endif


Review comment (suggestion):
Just as an FYI, if you have any values which you know won't ever change (and the number of encoders _probably_ falls into that camp), then you don't **have** to wrap it in an `#ifndef` block :wink: 

Code after:
#define MOTOR2040_A1_PIN 27
#define MOTOR2040_A2_PIN 28
#define MOTOR2040_NUM_ADC_PINS 3

#define MOTOR2040_SHARED_ADC_PIN 29
#define MOTOR2040_ADC_ADDR_0_PIN 22
#define MOTOR2040_ADC_ADDR_1_PIN 24
#define MOTOR2040_ADC_ADDR_2_PIN 25

#define MOTOR2040_CURRENT_SENSE_A_ADDR 0b000
#define MOTOR2040_CURRENT_SENSE_B_ADDR 0b001
#define MOTOR2040_CURRENT_SENSE_C_ADDR 0b010
#define MOTOR2040_CURRENT_SENSE_D_ADDR 0b011
#define MOTOR2040_VOLTAGE_SENSE_ADDR 0b100
#define MOTOR2040_FAULT_SENSE_ADDR 0b101
#define MOTOR2040_SENSOR_1_ADDR 0b110
#define MOTOR2040_SENSOR_2_ADDR 0b111
#define MOTOR2040_NUM_SENSORS 2

// --- UART ---
#if MOTOR2040_USE_DISTANCE_SENSOR
// no PICO_DEFAULT_UART
#else
#ifndef PICO_DEFAULT_UART
#define PICO_DEFAULT_UART MOTOR2040_UART
#endif
#ifndef PICO_DEFAULT_UART_TX_PIN
#define PICO_DEFAULT_UART_TX_PIN MOTOR2040_TX_PIN
#endif
#ifndef PICO_DEFAULT_UART_RX_PIN
#define PICO_DEFAULT_UART_RX_PIN MOTOR2040_RX_PIN
#endif
#endif

// --- LED ---
// no PICO_DEFAULT_LED_PIN
#ifndef PICO_DEFAULT_WS2812_PIN
#define PICO_DEFAULT_WS2812_PIN MOTOR2040_LED_DATA_PIN
#endif

// --- I2C ---
#ifndef PICO_DEFAULT_I2C
#define PICO_DEFAULT_I2C MOTOR2040_I2C
#endif
#ifndef PICO_DEFAULT_I2C_SDA_PIN
#define PICO_DEFAULT_I2C_SDA_PIN MOTOR2040_SDA_PIN
#endif
#ifndef PICO_DEFAULT_I2C_SCL_PIN
#define PICO_DEFAULT_I2C_SCL_PIN MOTOR2040_SCL_PIN
#endif
Repository: raspberrypi/pico-sdk
File: src/boards/include/boards/pimoroni_motor2040.h (C/C++)

Code before:
/*
 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

// -----------------------------------------------------
// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO
//       SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES
// -----------------------------------------------------

#ifndef _BOARDS_PIMORONI_MOTOR2040_H
#define _BOARDS_PIMORONI_MOTOR2040_H

// For board detection
#define PIMORONI_MOTOR2040

#ifndef MOTOR2040_USE_DISTANCE_SENSOR
// default to 0, unless explicitly set to 1
#define MOTOR2040_USE_DISTANCE_SENSOR 0
#endif

// --- BOARD SPECIFIC ---
#define MOTOR2040_MOTOR_A_P_PIN 4
#define MOTOR2040_MOTOR_A_N_PIN 5
#define MOTOR2040_MOTOR_B_P_PIN 6
#define MOTOR2040_MOTOR_B_N_PIN 7
#define MOTOR2040_MOTOR_C_P_PIN 8
#define MOTOR2040_MOTOR_C_N_PIN 9
#define MOTOR2040_MOTOR_D_P_PIN 10
#define MOTOR2040_MOTOR_D_N_PIN 11
#define MOTOR2040_NUM_MOTORS 4

#define MOTOR2040_ENCODER_A_A_PIN 0
#define MOTOR2040_ENCODER_A_B_PIN 1
#define MOTOR2040_ENCODER_B_A_PIN 2
#define MOTOR2040_ENCODER_B_B_PIN 3
#define MOTOR2040_ENCODER_C_A_PIN 12
#define MOTOR2040_ENCODER_C_B_PIN 13
#define MOTOR2040_ENCODER_D_A_PIN 14
#define MOTOR2040_ENCODER_D_B_PIN 15
#define MOTOR2040_NUM_ENCODERS 4

#if MOTOR2040_USE_DISTANCE_SENSOR

Review comment (suggestion):
Sorry, in hindsight this comment should have probably said
```
// default to 0, if not explicitly set
```

The rest of this looks pretty good to me though! :+1: 

Code after:
/*
 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

// -----------------------------------------------------
// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO
//       SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES
// -----------------------------------------------------

#ifndef _BOARDS_PIMORONI_MOTOR2040_H
#define _BOARDS_PIMORONI_MOTOR2040_H

// For board detection
#define PIMORONI_MOTOR2040

#ifndef MOTOR2040_USE_DISTANCE_SENSOR
// default to 0, if not explicitly set
#define MOTOR2040_USE_DISTANCE_SENSOR 0
#endif

// --- BOARD SPECIFIC ---
#define MOTOR2040_MOTOR_A_P_PIN 4
#define MOTOR2040_MOTOR_A_N_PIN 5
#define MOTOR2040_MOTOR_B_P_PIN 6
#define MOTOR2040_MOTOR_B_N_PIN 7
#define MOTOR2040_MOTOR_C_P_PIN 8
#define MOTOR2040_MOTOR_C_N_PIN 9
#define MOTOR2040_MOTOR_D_P_PIN 10
#define MOTOR2040_MOTOR_D_N_PIN 11
#define MOTOR2040_NUM_MOTORS 4

#define MOTOR2040_ENCODER_A_A_PIN 0
#define MOTOR2040_ENCODER_A_B_PIN 1
#define MOTOR2040_ENCODER_B_A_PIN 2
#define MOTOR2040_ENCODER_B_B_PIN 3
#define MOTOR2040_ENCODER_C_A_PIN 12
#define MOTOR2040_ENCODER_C_B_PIN 13
#define MOTOR2040_ENCODER_D_A_PIN 14
#define MOTOR2040_ENCODER_D_B_PIN 15
#define MOTOR2040_NUM_ENCODERS 4

#if MOTOR2040_USE_DISTANCE_SENSOR