Skip to content

Commit 9c0fe60

Browse files
committed
use CYW43_DEFAULT_PIN_WL_CLOCK when checking for CYW43 shared GPIO29 use
1 parent a8b55b4 commit 9c0fe60

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

ports/raspberrypi/common-hal/analogbufio/BufferedIn.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@
2020

2121
void common_hal_analogbufio_bufferedin_construct(analogbufio_bufferedin_obj_t *self, const mcu_pin_obj_t *pin, uint32_t sample_rate) {
2222
// Make sure pin number is in range for ADC
23-
if ((pin->number < ADC_BASE_PIN) ||
24-
(pin->number > ADC_BASE_PIN + NUM_ADC_CHANNELS - 1) ||
25-
// On Pico W and Pico 2 W, GPIO29 is both a voltage monitor and used for SPI to the CYW43.
23+
if ((pin->number < ADC_BASE_PIN)
24+
|| (pin->number > ADC_BASE_PIN + NUM_ADC_CHANNELS - 1)
25+
// On many boards with a CYW43 radio co-processor, CYW43_DEFAULT_PIN_WL_CLOCK (usually GPIO29),
26+
// is both a voltage monitor and also SPI SCK to the CYW43.
2627
// Disallow its use for BufferedIn.
27-
(CIRCUITPY_CYW43 && pin->number == 29)
28+
#if defined(CIRCUITPY_CYW43) && defined(CYW43_DEFAULT_PIN_WL_CLOCK)
29+
|| (pin->number == CYW43_DEFAULT_PIN_WL_CLOCK)
30+
#endif
2831
) {
2932
raise_ValueError_invalid_pin();
3033
}

ports/raspberrypi/common-hal/analogio/AnalogIn.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212

1313
#include "hardware/adc.h"
1414

15-
// Voltage monitor is special on Pico W and Pico 2 W, because this pin is shared between the
16-
// voltage monitor function and the wifi function. Special handling is required
17-
// to read the analog voltage.
15+
// On many boards with a CYW43 radio co-processor, CYW43_DEFAULT_PIN_WL_CLOCK (usually GPIO29),
16+
// is both a voltage monitor and also SPI SCK to the CYW43.
17+
// Special handling is required to read the analog voltage.
1818
#if CIRCUITPY_CYW43
1919
#include "bindings/cyw43/__init__.h"
20-
#define SPECIAL_PIN(pin) (pin->number == 29)
20+
#define SPECIAL_PIN(pin) (pin->number == CYW43_DEFAULT_PIN_WL_CLOCK)
2121

2222
const mcu_pin_obj_t *common_hal_analogio_analogin_validate_pin(mp_obj_t obj) {
2323
return validate_obj_is_free_pin_or_gpio29(obj, MP_QSTR_pin);

shared-bindings/analogbufio/BufferedIn.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@
3939
//| def __init__(self, pin: microcontroller.Pin, *, sample_rate: int) -> None:
4040
//| """Create a `BufferedIn` on the given pin and given sample rate.
4141
//|
42-
//| **Limitations**: On Pi Pico W and Pi Pico 2 W, pin ``board.A3`` is not supported
43-
//| because it is also used to control the CYW43 radio module.
44-
//|
4542
//| :param ~microcontroller.Pin pin: the pin to read from
4643
//| :param ~int sample_rate: rate: sampling frequency, in samples per second"""
44+
//|
45+
//| **Limitations**: On many boards with a CYW43 radio module, such as Pico W,
46+
//| GPIO29 (often ``board.A3``) is also used to control the CYW43,
47+
// } and is therefore not available to use as the `BufferedIn` pin.
4748
//| ...
4849
//|
4950
static mp_obj_t analogbufio_bufferedin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {

0 commit comments

Comments
 (0)