mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 01:07:45 +01:00
Better/stricter pin validation (#903)
* Better/stricter pin validation * Update tests
This commit is contained in:
parent
064589934c
commit
0698be3995
3 changed files with 38 additions and 18 deletions
|
@ -289,30 +289,48 @@ def _translate_pin(value):
|
|||
return _lookup_pin(value)
|
||||
|
||||
|
||||
_ESP_SDIO_PINS = {
|
||||
6: 'Flash Clock',
|
||||
7: 'Flash Data 0',
|
||||
8: 'Flash Data 1',
|
||||
11: 'Flash Command',
|
||||
}
|
||||
|
||||
|
||||
def validate_gpio_pin(value):
|
||||
value = _translate_pin(value)
|
||||
if CORE.is_esp32:
|
||||
if value < 0 or value > 39:
|
||||
raise cv.Invalid(u"ESP32: Invalid pin number: {}".format(value))
|
||||
if 6 <= value <= 11:
|
||||
_LOGGER.warning(u"ESP32: Pin %s (6-11) might already be used by the "
|
||||
u"flash interface. Be warned.", value)
|
||||
if value in _ESP_SDIO_PINS:
|
||||
raise cv.Invalid("This pin cannot be used on ESP32s and is already used by "
|
||||
"the flash interface (function: {})".format(_ESP_SDIO_PINS[value]))
|
||||
if 9 <= value <= 10:
|
||||
_LOGGER.warning(u"ESP32: Pin %s (9-10) might already be used by the "
|
||||
u"flash interface in QUAD IO flash mode.", value)
|
||||
if value in (20, 24, 28, 29, 30, 31):
|
||||
_LOGGER.warning(u"ESP32: Pin %s (20, 24, 28-31) can usually not be used. "
|
||||
u"Be warned.", value)
|
||||
# These pins are not exposed in GPIO mux (reason unknown)
|
||||
# but they're missing from IO_MUX list in datasheet
|
||||
raise cv.Invalid("The pin GPIO{} is not usable on ESP32s.".format(value))
|
||||
return value
|
||||
if CORE.is_esp8266:
|
||||
if 6 <= value <= 11:
|
||||
_LOGGER.warning(u"ESP8266: Pin %s (6-11) might already be used by the "
|
||||
u"flash interface. Be warned.", value)
|
||||
if value < 0 or value > 17:
|
||||
raise cv.Invalid(u"ESP8266: Invalid pin number: {}".format(value))
|
||||
if value in _ESP_SDIO_PINS:
|
||||
raise cv.Invalid("This pin cannot be used on ESP8266s and is already used by "
|
||||
"the flash interface (function: {})".format(_ESP_SDIO_PINS[value]))
|
||||
if 9 <= value <= 10:
|
||||
_LOGGER.warning(u"ESP8266: Pin %s (9-10) might already be used by the "
|
||||
u"flash interface in QUAD IO flash mode.", value)
|
||||
return value
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
def input_pin(value):
|
||||
return validate_gpio_pin(value)
|
||||
value = validate_gpio_pin(value)
|
||||
if CORE.is_esp8266 and value == 17:
|
||||
raise cv.Invalid("GPIO17 (TOUT) is an analog-only pin on the ESP8266.")
|
||||
return value
|
||||
|
||||
|
||||
def input_pullup_pin(value):
|
||||
|
@ -335,6 +353,8 @@ def output_pin(value):
|
|||
u"input pin.".format(value))
|
||||
return value
|
||||
if CORE.is_esp8266:
|
||||
if value == 17:
|
||||
raise cv.Invalid("GPIO17 (TOUT) is an analog-only pin on the ESP8266.")
|
||||
return value
|
||||
raise NotImplementedError
|
||||
|
||||
|
@ -348,7 +368,7 @@ def analog_pin(value):
|
|||
if CORE.is_esp8266:
|
||||
if value == 17: # A0
|
||||
return value
|
||||
raise cv.Invalid(u"ESP8266: Only pin A0 (17) supports ADC.")
|
||||
raise cv.Invalid(u"ESP8266: Only pin A0 (GPIO17) supports ADC.")
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
|
|
|
@ -435,7 +435,7 @@ sensor:
|
|||
- platform: hx711
|
||||
name: "HX711 Value"
|
||||
dout_pin: GPIO23
|
||||
clk_pin: GPIO24
|
||||
clk_pin: GPIO25
|
||||
gain: 128
|
||||
update_interval: 15s
|
||||
- platform: ina219
|
||||
|
@ -542,7 +542,7 @@ sensor:
|
|||
name: "Rotary Encoder"
|
||||
id: rotary_encoder1
|
||||
pin_a: GPIO23
|
||||
pin_b: GPIO24
|
||||
pin_b: GPIO25
|
||||
pin_reset: GPIO25
|
||||
filters:
|
||||
- or:
|
||||
|
@ -655,7 +655,7 @@ sensor:
|
|||
integration_time: 402ms
|
||||
gain: 16x
|
||||
- platform: ultrasonic
|
||||
trigger_pin: GPIO24
|
||||
trigger_pin: GPIO25
|
||||
echo_pin:
|
||||
number: GPIO23
|
||||
inverted: true
|
||||
|
@ -1396,11 +1396,11 @@ display:
|
|||
dimensions: 18x4
|
||||
data_pins:
|
||||
- GPIO19
|
||||
- GPIO20
|
||||
- GPIO21
|
||||
- GPIO22
|
||||
- GPIO23
|
||||
enable_pin: GPIO23
|
||||
rs_pin: GPIO24
|
||||
rs_pin: GPIO25
|
||||
lambda: |-
|
||||
it.print("Hello World!");
|
||||
- platform: lcd_pcf8574
|
||||
|
@ -1528,7 +1528,7 @@ stepper:
|
|||
- platform: a4988
|
||||
id: my_stepper
|
||||
step_pin: GPIO23
|
||||
dir_pin: GPIO24
|
||||
dir_pin: GPIO25
|
||||
sleep_pin: GPIO25
|
||||
max_speed: 250 steps/s
|
||||
acceleration: 100 steps/s^2
|
||||
|
|
|
@ -10,7 +10,7 @@ substitutions:
|
|||
ethernet:
|
||||
type: LAN8720
|
||||
mdc_pin: GPIO23
|
||||
mdio_pin: GPIO24
|
||||
mdio_pin: GPIO25
|
||||
clk_mode: GPIO0_IN
|
||||
phy_addr: 0
|
||||
power_pin: GPIO25
|
||||
|
@ -286,7 +286,7 @@ stepper:
|
|||
- platform: uln2003
|
||||
id: my_stepper
|
||||
pin_a: GPIO23
|
||||
pin_b: GPIO24
|
||||
pin_b: GPIO27
|
||||
pin_c: GPIO25
|
||||
pin_d: GPIO26
|
||||
sleep_when_done: no
|
||||
|
|
Loading…
Reference in a new issue