mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 01:07:45 +01:00
Early pin init (#3439)
* Added early_pin_init configuration parameter for ESP8266 platform * Added #include to core * Updated test3.yaml to include early_pin_init parameter Co-authored-by: Rainer Oellermann <ro@playplaycode.com>
This commit is contained in:
parent
8e3af515c9
commit
2059283707
4 changed files with 13 additions and 2 deletions
|
@ -19,6 +19,7 @@ from esphome.helpers import copy_file_if_changed
|
|||
|
||||
from .const import (
|
||||
CONF_RESTORE_FROM_FLASH,
|
||||
CONF_EARLY_PIN_INIT,
|
||||
KEY_BOARD,
|
||||
KEY_ESP8266,
|
||||
KEY_PIN_INITIAL_STATES,
|
||||
|
@ -148,6 +149,7 @@ CONFIG_SCHEMA = cv.All(
|
|||
cv.Required(CONF_BOARD): cv.string_strict,
|
||||
cv.Optional(CONF_FRAMEWORK, default={}): ARDUINO_FRAMEWORK_SCHEMA,
|
||||
cv.Optional(CONF_RESTORE_FROM_FLASH, default=False): cv.boolean,
|
||||
cv.Optional(CONF_EARLY_PIN_INIT, default=True): cv.boolean,
|
||||
cv.Optional(CONF_BOARD_FLASH_MODE, default="dout"): cv.one_of(
|
||||
*BUILD_FLASH_MODES, lower=True
|
||||
),
|
||||
|
@ -197,6 +199,9 @@ async def to_code(config):
|
|||
if config[CONF_RESTORE_FROM_FLASH]:
|
||||
cg.add_define("USE_ESP8266_PREFERENCES_FLASH")
|
||||
|
||||
if config[CONF_EARLY_PIN_INIT]:
|
||||
cg.add_define("USE_ESP8266_EARLY_PIN_INIT")
|
||||
|
||||
# Arduino 2 has a non-standards conformant new that returns a nullptr instead of failing when
|
||||
# out of memory and exceptions are disabled. Since Arduino 2.6.0, this flag can be used to make
|
||||
# new abort instead. Use it so that OOM fails early (on allocation) instead of on dereference of
|
||||
|
|
|
@ -4,6 +4,7 @@ KEY_ESP8266 = "esp8266"
|
|||
KEY_BOARD = "board"
|
||||
KEY_PIN_INITIAL_STATES = "pin_initial_states"
|
||||
CONF_RESTORE_FROM_FLASH = "restore_from_flash"
|
||||
CONF_EARLY_PIN_INIT = "early_pin_init"
|
||||
|
||||
# esp8266 namespace is already defined by arduino, manually prefix esphome
|
||||
esp8266_ns = cg.global_ns.namespace("esphome").namespace("esp8266")
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifdef USE_ESP8266
|
||||
|
||||
#include "core.h"
|
||||
#include "esphome/core/defines.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "preferences.h"
|
||||
|
@ -55,6 +56,7 @@ extern "C" void resetPins() { // NOLINT
|
|||
// ourselves and this causes pins to toggle during reboot.
|
||||
force_link_symbols();
|
||||
|
||||
#ifdef USE_ESP8266_EARLY_PIN_INIT
|
||||
for (int i = 0; i < 16; i++) {
|
||||
uint8_t mode = ESPHOME_ESP8266_GPIO_INITIAL_MODE[i];
|
||||
uint8_t level = ESPHOME_ESP8266_GPIO_INITIAL_LEVEL[i];
|
||||
|
@ -63,6 +65,7 @@ extern "C" void resetPins() { // NOLINT
|
|||
if (level != 255)
|
||||
digitalWrite(i, level); // NOLINT
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace esphome
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
esphome:
|
||||
name: $device_name
|
||||
comment: $device_comment
|
||||
platform: ESP8266
|
||||
board: d1_mini
|
||||
build_path: build/test3
|
||||
on_boot:
|
||||
- if:
|
||||
|
@ -15,6 +13,10 @@ esphome:
|
|||
includes:
|
||||
- custom.h
|
||||
|
||||
esp8266:
|
||||
board: d1_mini
|
||||
early_pin_init: True
|
||||
|
||||
substitutions:
|
||||
device_name: test3
|
||||
device_comment: test3 device
|
||||
|
|
Loading…
Reference in a new issue