mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 08:28:12 +01:00
Add config to allow suppression of warnings about use of strapping pins (#5287)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
parent
799c3cf439
commit
a794836ebe
10 changed files with 38 additions and 45 deletions
|
@ -11,6 +11,7 @@ from esphome.const import (
|
||||||
CONF_OUTPUT,
|
CONF_OUTPUT,
|
||||||
CONF_PULLDOWN,
|
CONF_PULLDOWN,
|
||||||
CONF_PULLUP,
|
CONF_PULLUP,
|
||||||
|
CONF_IGNORE_STRAPPING_WARNING,
|
||||||
)
|
)
|
||||||
from esphome import pins
|
from esphome import pins
|
||||||
from esphome.core import CORE
|
from esphome.core import CORE
|
||||||
|
@ -176,6 +177,7 @@ ESP32_PIN_SCHEMA = cv.All(
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
cv.Optional(CONF_INVERTED, default=False): cv.boolean,
|
cv.Optional(CONF_INVERTED, default=False): cv.boolean,
|
||||||
|
cv.Optional(CONF_IGNORE_STRAPPING_WARNING, default=False): cv.boolean,
|
||||||
cv.Optional(CONF_DRIVE_STRENGTH, default="20mA"): cv.All(
|
cv.Optional(CONF_DRIVE_STRENGTH, default="20mA"): cv.All(
|
||||||
cv.float_with_unit("current", "mA", optional_unit=True),
|
cv.float_with_unit("current", "mA", optional_unit=True),
|
||||||
cv.enum(DRIVE_STRENGTHS),
|
cv.enum(DRIVE_STRENGTHS),
|
||||||
|
|
|
@ -9,6 +9,7 @@ from esphome.const import (
|
||||||
CONF_PULLUP,
|
CONF_PULLUP,
|
||||||
)
|
)
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
|
from esphome.pins import check_strapping_pin
|
||||||
|
|
||||||
|
|
||||||
_ESP_SDIO_PINS = {
|
_ESP_SDIO_PINS = {
|
||||||
|
@ -35,13 +36,6 @@ def esp32_validate_gpio_pin(value):
|
||||||
"flash interface in QUAD IO flash mode.",
|
"flash interface in QUAD IO flash mode.",
|
||||||
value,
|
value,
|
||||||
)
|
)
|
||||||
if value in _ESP32_STRAPPING_PINS:
|
|
||||||
_LOGGER.warning(
|
|
||||||
"GPIO%d is a Strapping PIN and should be avoided.\n"
|
|
||||||
"Attaching external pullup/down resistors to strapping pins can cause unexpected failures.\n"
|
|
||||||
"See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins",
|
|
||||||
value,
|
|
||||||
)
|
|
||||||
if value in (24, 28, 29, 30, 31):
|
if value in (24, 28, 29, 30, 31):
|
||||||
# These pins are not exposed in GPIO mux (reason unknown)
|
# These pins are not exposed in GPIO mux (reason unknown)
|
||||||
# but they're missing from IO_MUX list in datasheet
|
# but they're missing from IO_MUX list in datasheet
|
||||||
|
@ -74,4 +68,5 @@ def esp32_validate_supports(value):
|
||||||
f"GPIO{num} (34-39) does not support pulldowns.", [CONF_MODE, CONF_PULLDOWN]
|
f"GPIO{num} (34-39) does not support pulldowns.", [CONF_MODE, CONF_PULLDOWN]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
check_strapping_pin(value, _ESP32_STRAPPING_PINS, _LOGGER)
|
||||||
return value
|
return value
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from esphome.const import CONF_INPUT, CONF_MODE, CONF_NUMBER
|
from esphome.const import CONF_INPUT, CONF_MODE, CONF_NUMBER
|
||||||
|
from esphome.pins import check_strapping_pin
|
||||||
|
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
|
|
||||||
|
@ -12,13 +13,6 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
def esp32_c2_validate_gpio_pin(value):
|
def esp32_c2_validate_gpio_pin(value):
|
||||||
if value < 0 or value > 20:
|
if value < 0 or value > 20:
|
||||||
raise cv.Invalid(f"Invalid pin number: {value} (must be 0-20)")
|
raise cv.Invalid(f"Invalid pin number: {value} (must be 0-20)")
|
||||||
if value in _ESP32C2_STRAPPING_PINS:
|
|
||||||
_LOGGER.warning(
|
|
||||||
"GPIO%d is a Strapping PIN and should be avoided.\n"
|
|
||||||
"Attaching external pullup/down resistors to strapping pins can cause unexpected failures.\n"
|
|
||||||
"See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins",
|
|
||||||
value,
|
|
||||||
)
|
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
@ -34,4 +28,6 @@ def esp32_c2_validate_supports(value):
|
||||||
if is_input:
|
if is_input:
|
||||||
# All ESP32 pins support input mode
|
# All ESP32 pins support input mode
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
check_strapping_pin(value, _ESP32C2_STRAPPING_PINS, _LOGGER)
|
||||||
return value
|
return value
|
||||||
|
|
|
@ -6,6 +6,7 @@ from esphome.const import (
|
||||||
CONF_NUMBER,
|
CONF_NUMBER,
|
||||||
)
|
)
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
|
from esphome.pins import check_strapping_pin
|
||||||
|
|
||||||
_ESP32C3_SPI_PSRAM_PINS = {
|
_ESP32C3_SPI_PSRAM_PINS = {
|
||||||
12: "SPIHD",
|
12: "SPIHD",
|
||||||
|
@ -28,13 +29,6 @@ def esp32_c3_validate_gpio_pin(value):
|
||||||
raise cv.Invalid(
|
raise cv.Invalid(
|
||||||
f"This pin cannot be used on ESP32-C3s and is already used by the SPI/PSRAM interface (function: {_ESP32C3_SPI_PSRAM_PINS[value]})"
|
f"This pin cannot be used on ESP32-C3s and is already used by the SPI/PSRAM interface (function: {_ESP32C3_SPI_PSRAM_PINS[value]})"
|
||||||
)
|
)
|
||||||
if value in _ESP32C3_STRAPPING_PINS:
|
|
||||||
_LOGGER.warning(
|
|
||||||
"GPIO%d is a Strapping PIN and should be avoided.\n"
|
|
||||||
"Attaching external pullup/down resistors to strapping pins can cause unexpected failures.\n"
|
|
||||||
"See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins",
|
|
||||||
value,
|
|
||||||
)
|
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
@ -50,4 +44,6 @@ def esp32_c3_validate_supports(value):
|
||||||
if is_input:
|
if is_input:
|
||||||
# All ESP32 pins support input mode
|
# All ESP32 pins support input mode
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
check_strapping_pin(value, _ESP32C3_STRAPPING_PINS, _LOGGER)
|
||||||
return value
|
return value
|
||||||
|
|
|
@ -3,6 +3,7 @@ import logging
|
||||||
from esphome.const import CONF_INPUT, CONF_MODE, CONF_NUMBER
|
from esphome.const import CONF_INPUT, CONF_MODE, CONF_NUMBER
|
||||||
|
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
|
from esphome.pins import check_strapping_pin
|
||||||
|
|
||||||
_ESP32C6_SPI_PSRAM_PINS = {
|
_ESP32C6_SPI_PSRAM_PINS = {
|
||||||
24: "SPICS0",
|
24: "SPICS0",
|
||||||
|
@ -26,13 +27,6 @@ def esp32_c6_validate_gpio_pin(value):
|
||||||
raise cv.Invalid(
|
raise cv.Invalid(
|
||||||
f"This pin cannot be used on ESP32-C6s and is already used by the SPI/PSRAM interface (function: {_ESP32C6_SPI_PSRAM_PINS[value]})"
|
f"This pin cannot be used on ESP32-C6s and is already used by the SPI/PSRAM interface (function: {_ESP32C6_SPI_PSRAM_PINS[value]})"
|
||||||
)
|
)
|
||||||
if value in _ESP32C6_STRAPPING_PINS:
|
|
||||||
_LOGGER.warning(
|
|
||||||
"GPIO%d is a Strapping PIN and should be avoided.\n"
|
|
||||||
"Attaching external pullup/down resistors to strapping pins can cause unexpected failures.\n"
|
|
||||||
"See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins",
|
|
||||||
value,
|
|
||||||
)
|
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
@ -47,4 +41,6 @@ def esp32_c6_validate_supports(value):
|
||||||
if is_input:
|
if is_input:
|
||||||
# All ESP32 pins support input mode
|
# All ESP32 pins support input mode
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
check_strapping_pin(value, _ESP32C6_STRAPPING_PINS, _LOGGER)
|
||||||
return value
|
return value
|
||||||
|
|
|
@ -10,6 +10,7 @@ from esphome.const import (
|
||||||
)
|
)
|
||||||
|
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
|
from esphome.pins import check_strapping_pin
|
||||||
|
|
||||||
_ESP32S2_SPI_PSRAM_PINS = {
|
_ESP32S2_SPI_PSRAM_PINS = {
|
||||||
26: "SPICS1",
|
26: "SPICS1",
|
||||||
|
@ -34,13 +35,6 @@ def esp32_s2_validate_gpio_pin(value):
|
||||||
raise cv.Invalid(
|
raise cv.Invalid(
|
||||||
f"This pin cannot be used on ESP32-S2s and is already used by the SPI/PSRAM interface (function: {_ESP32S2_SPI_PSRAM_PINS[value]})"
|
f"This pin cannot be used on ESP32-S2s and is already used by the SPI/PSRAM interface (function: {_ESP32S2_SPI_PSRAM_PINS[value]})"
|
||||||
)
|
)
|
||||||
if value in _ESP32S2_STRAPPING_PINS:
|
|
||||||
_LOGGER.warning(
|
|
||||||
"GPIO%d is a Strapping PIN and should be avoided.\n"
|
|
||||||
"Attaching external pullup/down resistors to strapping pins can cause unexpected failures.\n"
|
|
||||||
"See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins",
|
|
||||||
value,
|
|
||||||
)
|
|
||||||
|
|
||||||
if value in (22, 23, 24, 25):
|
if value in (22, 23, 24, 25):
|
||||||
# These pins are not exposed in GPIO mux (reason unknown)
|
# These pins are not exposed in GPIO mux (reason unknown)
|
||||||
|
@ -77,4 +71,5 @@ def esp32_s2_validate_supports(value):
|
||||||
f"GPIO{num} does not support pulldowns.", [CONF_MODE, CONF_PULLDOWN]
|
f"GPIO{num} does not support pulldowns.", [CONF_MODE, CONF_PULLDOWN]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
check_strapping_pin(value, _ESP32S2_STRAPPING_PINS, _LOGGER)
|
||||||
return value
|
return value
|
||||||
|
|
|
@ -7,6 +7,7 @@ from esphome.const import (
|
||||||
)
|
)
|
||||||
|
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
|
from esphome.pins import check_strapping_pin
|
||||||
|
|
||||||
_ESP_32S3_SPI_PSRAM_PINS = {
|
_ESP_32S3_SPI_PSRAM_PINS = {
|
||||||
26: "SPICS1",
|
26: "SPICS1",
|
||||||
|
@ -45,14 +46,6 @@ def esp32_s3_validate_gpio_pin(value):
|
||||||
value,
|
value,
|
||||||
)
|
)
|
||||||
|
|
||||||
if value in _ESP_32S3_STRAPPING_PINS:
|
|
||||||
_LOGGER.warning(
|
|
||||||
"GPIO%d is a Strapping PIN and should be avoided.\n"
|
|
||||||
"Attaching external pullup/down resistors to strapping pins can cause unexpected failures.\n"
|
|
||||||
"See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins",
|
|
||||||
value,
|
|
||||||
)
|
|
||||||
|
|
||||||
if value in (22, 23, 24, 25):
|
if value in (22, 23, 24, 25):
|
||||||
# These pins are not exposed in GPIO mux (reason unknown)
|
# These pins are not exposed in GPIO mux (reason unknown)
|
||||||
# but they're missing from IO_MUX list in datasheet
|
# but they're missing from IO_MUX list in datasheet
|
||||||
|
@ -71,4 +64,6 @@ def esp32_s3_validate_supports(value):
|
||||||
if is_input:
|
if is_input:
|
||||||
# All ESP32 pins support input mode
|
# All ESP32 pins support input mode
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
check_strapping_pin(value, _ESP_32S3_STRAPPING_PINS, _LOGGER)
|
||||||
return value
|
return value
|
||||||
|
|
|
@ -335,6 +335,7 @@ CONF_IDLE_LEVEL = "idle_level"
|
||||||
CONF_IDLE_TIME = "idle_time"
|
CONF_IDLE_TIME = "idle_time"
|
||||||
CONF_IF = "if"
|
CONF_IF = "if"
|
||||||
CONF_IGNORE_EFUSE_MAC_CRC = "ignore_efuse_mac_crc"
|
CONF_IGNORE_EFUSE_MAC_CRC = "ignore_efuse_mac_crc"
|
||||||
|
CONF_IGNORE_STRAPPING_WARNING = "ignore_strapping_warning"
|
||||||
CONF_IIR_FILTER = "iir_filter"
|
CONF_IIR_FILTER = "iir_filter"
|
||||||
CONF_ILLUMINANCE = "illuminance"
|
CONF_ILLUMINANCE = "illuminance"
|
||||||
CONF_IMPEDANCE = "impedance"
|
CONF_IMPEDANCE = "impedance"
|
||||||
|
|
|
@ -9,11 +9,11 @@ from esphome.const import (
|
||||||
CONF_OUTPUT,
|
CONF_OUTPUT,
|
||||||
CONF_PULLDOWN,
|
CONF_PULLDOWN,
|
||||||
CONF_PULLUP,
|
CONF_PULLUP,
|
||||||
|
CONF_IGNORE_STRAPPING_WARNING,
|
||||||
)
|
)
|
||||||
from esphome.util import SimpleRegistry
|
from esphome.util import SimpleRegistry
|
||||||
from esphome.core import CORE
|
from esphome.core import CORE
|
||||||
|
|
||||||
|
|
||||||
PIN_SCHEMA_REGISTRY = SimpleRegistry()
|
PIN_SCHEMA_REGISTRY = SimpleRegistry()
|
||||||
|
|
||||||
|
|
||||||
|
@ -146,3 +146,18 @@ internal_gpio_input_pullup_pin_number = _internal_number_creator(
|
||||||
CONF_PULLUP: True,
|
CONF_PULLUP: True,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def check_strapping_pin(conf, strapping_pin_list, logger):
|
||||||
|
import esphome.config_validation as cv
|
||||||
|
|
||||||
|
num = conf[CONF_NUMBER]
|
||||||
|
if num in strapping_pin_list and not conf.get(CONF_IGNORE_STRAPPING_WARNING):
|
||||||
|
logger.warning(
|
||||||
|
f"GPIO{num} is a strapping PIN and should only be used for I/O with care.\n"
|
||||||
|
"Attaching external pullup/down resistors to strapping pins can cause unexpected failures.\n"
|
||||||
|
"See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins",
|
||||||
|
)
|
||||||
|
# mitigate undisciplined use of strapping:
|
||||||
|
if num not in strapping_pin_list and conf.get(CONF_IGNORE_STRAPPING_WARNING):
|
||||||
|
raise cv.Invalid(f"GPIO{num} is not a strapping pin")
|
||||||
|
|
|
@ -65,7 +65,9 @@ i2c:
|
||||||
|
|
||||||
touchscreen:
|
touchscreen:
|
||||||
- platform: tt21100
|
- platform: tt21100
|
||||||
interrupt_pin: GPIO3
|
interrupt_pin:
|
||||||
|
number: GPIO3
|
||||||
|
ignore_strapping_warning: true
|
||||||
reset_pin: GPIO48
|
reset_pin: GPIO48
|
||||||
|
|
||||||
binary_sensor:
|
binary_sensor:
|
||||||
|
|
Loading…
Reference in a new issue