From 0e30c49e3f8ec6be48f6a3a788458cdc5192e35f Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Fri, 28 Oct 2022 10:06:22 +1300 Subject: [PATCH] Allow using LED pin on rpi pico-w (#3957) --- esphome/components/rp2040/boards.py | 2 +- esphome/components/rp2040/gpio.py | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/esphome/components/rp2040/boards.py b/esphome/components/rp2040/boards.py index be3d05369a..e2d34bc02a 100644 --- a/esphome/components/rp2040/boards.py +++ b/esphome/components/rp2040/boards.py @@ -3,5 +3,5 @@ RP2040_BASE_PINS = {} RP2040_BOARD_PINS = { "pico": {"LED": 25}, "rpipico": "pico", - "rpipicow": {}, + "rpipicow": {"LED": 32}, } diff --git a/esphome/components/rp2040/gpio.py b/esphome/components/rp2040/gpio.py index 4bc6dbee1c..2340bed892 100644 --- a/esphome/components/rp2040/gpio.py +++ b/esphome/components/rp2040/gpio.py @@ -53,11 +53,29 @@ def _translate_pin(value): def validate_gpio_pin(value): value = _translate_pin(value) + board = CORE.data[KEY_RP2040][KEY_BOARD] + if board == "rpipicow" and value == 32: + return value # Special case for Pico-w LED pin if value < 0 or value > 29: raise cv.Invalid(f"RP2040: Invalid pin number: {value}") return value +def validate_supports(value): + board = CORE.data[KEY_RP2040][KEY_BOARD] + if board != "rpipicow" or value[CONF_NUMBER] != 32: + return value + mode = value[CONF_MODE] + is_input = mode[CONF_INPUT] + is_output = mode[CONF_OUTPUT] + is_open_drain = mode[CONF_OPEN_DRAIN] + is_pullup = mode[CONF_PULLUP] + is_pulldown = mode[CONF_PULLDOWN] + if not is_output or is_input or is_open_drain or is_pullup or is_pulldown: + raise cv.Invalid("Only output mode is supported for Pico-w LED pin") + return value + + CONF_ANALOG = "analog" RP2040_PIN_SCHEMA = cv.All( @@ -77,7 +95,8 @@ RP2040_PIN_SCHEMA = cv.All( ), cv.Optional(CONF_INVERTED, default=False): cv.boolean, } - ) + ), + validate_supports, )