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:
rainero84 2022-05-09 07:21:43 +02:00 committed by GitHub
parent 8e3af515c9
commit 2059283707
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 2 deletions

View file

@ -19,6 +19,7 @@ from esphome.helpers import copy_file_if_changed
from .const import ( from .const import (
CONF_RESTORE_FROM_FLASH, CONF_RESTORE_FROM_FLASH,
CONF_EARLY_PIN_INIT,
KEY_BOARD, KEY_BOARD,
KEY_ESP8266, KEY_ESP8266,
KEY_PIN_INITIAL_STATES, KEY_PIN_INITIAL_STATES,
@ -148,6 +149,7 @@ CONFIG_SCHEMA = cv.All(
cv.Required(CONF_BOARD): cv.string_strict, cv.Required(CONF_BOARD): cv.string_strict,
cv.Optional(CONF_FRAMEWORK, default={}): ARDUINO_FRAMEWORK_SCHEMA, cv.Optional(CONF_FRAMEWORK, default={}): ARDUINO_FRAMEWORK_SCHEMA,
cv.Optional(CONF_RESTORE_FROM_FLASH, default=False): cv.boolean, 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( cv.Optional(CONF_BOARD_FLASH_MODE, default="dout"): cv.one_of(
*BUILD_FLASH_MODES, lower=True *BUILD_FLASH_MODES, lower=True
), ),
@ -197,6 +199,9 @@ async def to_code(config):
if config[CONF_RESTORE_FROM_FLASH]: if config[CONF_RESTORE_FROM_FLASH]:
cg.add_define("USE_ESP8266_PREFERENCES_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 # 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 # 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 # new abort instead. Use it so that OOM fails early (on allocation) instead of on dereference of

View file

@ -4,6 +4,7 @@ KEY_ESP8266 = "esp8266"
KEY_BOARD = "board" KEY_BOARD = "board"
KEY_PIN_INITIAL_STATES = "pin_initial_states" KEY_PIN_INITIAL_STATES = "pin_initial_states"
CONF_RESTORE_FROM_FLASH = "restore_from_flash" 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 namespace is already defined by arduino, manually prefix esphome
esp8266_ns = cg.global_ns.namespace("esphome").namespace("esp8266") esp8266_ns = cg.global_ns.namespace("esphome").namespace("esp8266")

View file

@ -1,6 +1,7 @@
#ifdef USE_ESP8266 #ifdef USE_ESP8266
#include "core.h" #include "core.h"
#include "esphome/core/defines.h"
#include "esphome/core/hal.h" #include "esphome/core/hal.h"
#include "esphome/core/helpers.h" #include "esphome/core/helpers.h"
#include "preferences.h" #include "preferences.h"
@ -55,6 +56,7 @@ extern "C" void resetPins() { // NOLINT
// ourselves and this causes pins to toggle during reboot. // ourselves and this causes pins to toggle during reboot.
force_link_symbols(); force_link_symbols();
#ifdef USE_ESP8266_EARLY_PIN_INIT
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
uint8_t mode = ESPHOME_ESP8266_GPIO_INITIAL_MODE[i]; uint8_t mode = ESPHOME_ESP8266_GPIO_INITIAL_MODE[i];
uint8_t level = ESPHOME_ESP8266_GPIO_INITIAL_LEVEL[i]; uint8_t level = ESPHOME_ESP8266_GPIO_INITIAL_LEVEL[i];
@ -63,6 +65,7 @@ extern "C" void resetPins() { // NOLINT
if (level != 255) if (level != 255)
digitalWrite(i, level); // NOLINT digitalWrite(i, level); // NOLINT
} }
#endif
} }
} // namespace esphome } // namespace esphome

View file

@ -1,8 +1,6 @@
esphome: esphome:
name: $device_name name: $device_name
comment: $device_comment comment: $device_comment
platform: ESP8266
board: d1_mini
build_path: build/test3 build_path: build/test3
on_boot: on_boot:
- if: - if:
@ -15,6 +13,10 @@ esphome:
includes: includes:
- custom.h - custom.h
esp8266:
board: d1_mini
early_pin_init: True
substitutions: substitutions:
device_name: test3 device_name: test3
device_comment: test3 device device_comment: test3 device