From a3e24d2172525aaada595d86114735b28e7a822f Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 15 Dec 2025 21:52:47 -0500 Subject: [PATCH] rp2040: Add support for ADC on rp2350b chips Signed-off-by: Kevin O'Connor --- src/rp2040/adc.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/rp2040/adc.c b/src/rp2040/adc.c index 2daf380a6..477858c54 100644 --- a/src/rp2040/adc.c +++ b/src/rp2040/adc.c @@ -1,6 +1,6 @@ // ADC functions on rp2040 // -// Copyright (C) 2021 Kevin O'Connor +// Copyright (C) 2021-2025 Kevin O'Connor // // This file may be distributed under the terms of the GNU GPLv3 license. @@ -10,6 +10,7 @@ #include "hardware/structs/adc.h" // adc_hw #include "hardware/structs/padsbank0.h" // padsbank0_hw #include "hardware/structs/resets.h" // RESETS_RESET_ADC_BITS +#include "hardware/structs/sysinfo.h" // sysinfo_hw #include "internal.h" // enable_pclock #include "sched.h" // sched_shutdown @@ -21,7 +22,19 @@ DECL_ENUMERATION("pin", "ADC_TEMPERATURE", ADC_TEMPERATURE_PIN); struct gpio_adc gpio_adc_setup(uint32_t pin) { - if ((pin < 26 || pin > 29) && pin != ADC_TEMPERATURE_PIN) + uint32_t min_gpio = 26, max_gpio = 29, adc_temp_chan = 4; +#if CONFIG_MACH_RP2350 + // Check for rp2350b package + if (!is_enabled_pclock(RESETS_RESET_SYSINFO_BITS)) + enable_pclock(RESETS_RESET_SYSINFO_BITS); + if (!(sysinfo_hw->package_sel & SYSINFO_PACKAGE_SEL_BITS)) { + min_gpio = 40; + max_gpio = 47; + adc_temp_chan = 8; + } +#endif + + if ((pin < min_gpio || pin > max_gpio) && pin != ADC_TEMPERATURE_PIN) shutdown("Not a valid ADC pin"); // Enable the ADC @@ -32,10 +45,10 @@ gpio_adc_setup(uint32_t pin) uint8_t chan; if (pin == ADC_TEMPERATURE_PIN) { - chan = 4; + chan = adc_temp_chan; adc_hw->cs |= ADC_CS_TS_EN_BITS; } else { - chan = pin - 26; + chan = pin - min_gpio; padsbank0_hw->io[pin] = PADS_BANK0_GPIO0_OD_BITS; }