Skip to content

Commit

Permalink
Support for LibreTiny platform (RTL8710, BK7231 & other modules) (esp…
Browse files Browse the repository at this point in the history
…home#3509)

Co-authored-by: Kuba Szczodrzyński <[email protected]>
Co-authored-by: Sam Neirinck <[email protected]>
Co-authored-by: David Buezas <[email protected]>
Co-authored-by: Stroe Andrei Catalin <[email protected]>
Co-authored-by: Sam Neirinck <[email protected]>
Co-authored-by: Péter Sárközi <[email protected]>
Co-authored-by: Hajo Noerenberg <[email protected]>
  • Loading branch information
7 people authored Sep 4, 2023
1 parent 22c0b0a commit a9630ac
Show file tree
Hide file tree
Showing 78 changed files with 6,084 additions and 88 deletions.
4 changes: 4 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ esphome/components/bedjet/climate/* @jhansche
esphome/components/bedjet/fan/* @jhansche
esphome/components/bh1750/* @OttoWinter
esphome/components/binary_sensor/* @esphome/core
esphome/components/bk72xx/* @kuba2k2
esphome/components/bl0939/* @ziceva
esphome/components/bl0940/* @tobias-
esphome/components/bl0942/* @dbuezas
Expand Down Expand Up @@ -146,6 +147,8 @@ esphome/components/kuntze/* @ssieb
esphome/components/lcd_menu/* @numo68
esphome/components/ld2410/* @regevbr @sebcaps
esphome/components/ledc/* @OttoWinter
esphome/components/libretiny/* @kuba2k2
esphome/components/libretiny_pwm/* @kuba2k2
esphome/components/light/* @esphome/core
esphome/components/lilygo_t5_47/touchscreen/* @jesserockz
esphome/components/lock/* @esphome/core
Expand Down Expand Up @@ -234,6 +237,7 @@ esphome/components/rgbct/* @jesserockz
esphome/components/rp2040/* @jesserockz
esphome/components/rp2040_pio_led_strip/* @Papa-DMan
esphome/components/rp2040_pwm/* @jesserockz
esphome/components/rtl87xx/* @kuba2k2
esphome/components/rtttl/* @glmnet
esphome/components/safe_mode/* @jsuanet @paulmonigatti
esphome/components/scd4x/* @martgras @sjtrny
Expand Down
21 changes: 14 additions & 7 deletions esphome/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
CONF_ESPHOME,
CONF_PLATFORMIO_OPTIONS,
CONF_SUBSTITUTIONS,
PLATFORM_BK72XX,
PLATFORM_RTL87XX,
PLATFORM_ESP32,
PLATFORM_ESP8266,
PLATFORM_RP2040,
Expand Down Expand Up @@ -278,20 +280,25 @@ def run_esptool(baud_rate):
return run_esptool(115200)


def upload_using_platformio(config, port):
from esphome import platformio_api

upload_args = ["-t", "upload", "-t", "nobuild"]
if port is not None:
upload_args += ["--upload-port", port]
return platformio_api.run_platformio_cli_run(config, CORE.verbose, *upload_args)


def upload_program(config, args, host):
if get_port_type(host) == "SERIAL":
if CORE.target_platform in (PLATFORM_ESP32, PLATFORM_ESP8266):
return upload_using_esptool(config, host)

if CORE.target_platform in (PLATFORM_RP2040):
from esphome import platformio_api
return upload_using_platformio(config, args.device)

upload_args = ["-t", "upload"]
if args.device is not None:
upload_args += ["--upload-port", args.device]
return platformio_api.run_platformio_cli_run(
config, CORE.verbose, *upload_args
)
if CORE.target_platform in (PLATFORM_BK72XX, PLATFORM_RTL87XX):
return upload_using_platformio(config, host)

return 1 # Unknown target platform

Expand Down
9 changes: 6 additions & 3 deletions esphome/components/adc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import pins
from esphome.const import CONF_INPUT
from esphome.const import CONF_ANALOG, CONF_INPUT

from esphome.core import CORE
from esphome.components.esp32 import get_esp32_variant
Expand Down Expand Up @@ -166,8 +166,6 @@ def validate_adc_pin(value):
return pins.internal_gpio_input_pin_schema(value)

if CORE.is_esp8266:
from esphome.components.esp8266.gpio import CONF_ANALOG

value = pins.internal_gpio_pin_number({CONF_ANALOG: True, CONF_INPUT: True})(
value
)
Expand All @@ -184,4 +182,9 @@ def validate_adc_pin(value):
raise cv.Invalid("RP2040: Only pins 26, 27, 28 and 29 support ADC")
return pins.internal_gpio_input_pin_schema(value)

if CORE.is_libretiny:
return pins.gpio_pin_schema(
{CONF_ANALOG: True, CONF_INPUT: True}, internal=True
)(value)

raise NotImplementedError
13 changes: 11 additions & 2 deletions esphome/components/adc/adc_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ extern "C"

void ADCSensor::dump_config() {
LOG_SENSOR("", "ADC Sensor", this);
#ifdef USE_ESP8266
#if defined(USE_ESP8266) || defined(USE_LIBRETINY)
#ifdef USE_ADC_SENSOR_VCC
ESP_LOGCONFIG(TAG, " Pin: VCC");
#else
LOG_PIN(" Pin: ", pin_);
#endif
#endif // USE_ESP8266
#endif // USE_ESP8266 || USE_LIBRETINY

#ifdef USE_ESP32
LOG_PIN(" Pin: ", pin_);
Expand Down Expand Up @@ -254,6 +254,15 @@ float ADCSensor::sample() {
}
#endif

#ifdef USE_LIBRETINY
float ADCSensor::sample() {
if (output_raw_) {
return analogRead(this->pin_->get_pin()); // NOLINT
}
return analogReadVoltage(this->pin_->get_pin()) / 1000.0f; // NOLINT
}
#endif // USE_LIBRETINY

#ifdef USE_ESP8266
std::string ADCSensor::unique_id() { return get_mac_address() + "-adc"; }
#endif
Expand Down
4 changes: 4 additions & 0 deletions esphome/components/api/api_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,10 @@ DeviceInfoResponse APIConnection::device_info(const DeviceInfoRequest &msg) {
resp.manufacturer = "Espressif";
#elif defined(USE_RP2040)
resp.manufacturer = "Raspberry Pi";
#elif defined(USE_BK72XX)
resp.manufacturer = "Beken";
#elif defined(USE_RTL87XX)
resp.manufacturer = "Realtek";
#elif defined(USE_HOST)
resp.manufacturer = "Host";
#endif
Expand Down
6 changes: 3 additions & 3 deletions esphome/components/async_tcp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
CONFIG_SCHEMA = cv.All(
cv.Schema({}),
cv.only_with_arduino,
cv.only_on(["esp32", "esp8266"]),
cv.only_on(["esp32", "esp8266", "bk72xx", "rtl87xx"]),
)


@coroutine_with_priority(200.0)
async def to_code(config):
if CORE.is_esp32:
if CORE.is_esp32 or CORE.is_libretiny:
# https://github.com/esphome/AsyncTCP/blob/master/library.json
cg.add_library("esphome/AsyncTCP-esphome", "1.2.2")
cg.add_library("esphome/AsyncTCP-esphome", "2.0.1")
elif CORE.is_esp8266:
# https://github.com/esphome/ESPAsyncTCP
cg.add_library("esphome/ESPAsyncTCP-esphome", "1.2.3")
51 changes: 51 additions & 0 deletions esphome/components/bk72xx/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# This file was auto-generated by libretiny/generate_components.py
# Do not modify its contents.
# For custom pin validators, put validate_pin() or validate_usage()
# in gpio.py file in this directory.
# For changing schema/pin schema, put COMPONENT_SCHEMA or COMPONENT_PIN_SCHEMA
# in schema.py file in this directory.

from esphome import pins
from esphome.components import libretiny
from esphome.components.libretiny.const import (
COMPONENT_BK72XX,
KEY_COMPONENT_DATA,
KEY_LIBRETINY,
LibreTinyComponent,
)
from esphome.core import CORE

from .boards import BK72XX_BOARDS, BK72XX_BOARD_PINS

CODEOWNERS = ["@kuba2k2"]
AUTO_LOAD = ["libretiny"]

COMPONENT_DATA = LibreTinyComponent(
name=COMPONENT_BK72XX,
boards=BK72XX_BOARDS,
board_pins=BK72XX_BOARD_PINS,
pin_validation=None,
usage_validation=None,
)


def _set_core_data(config):
CORE.data[KEY_LIBRETINY] = {}
CORE.data[KEY_LIBRETINY][KEY_COMPONENT_DATA] = COMPONENT_DATA
return config


CONFIG_SCHEMA = libretiny.BASE_SCHEMA

PIN_SCHEMA = libretiny.gpio.BASE_PIN_SCHEMA

CONFIG_SCHEMA.prepend_extra(_set_core_data)


async def to_code(config):
return await libretiny.component_to_code(config)


@pins.PIN_SCHEMA_REGISTRY.register("bk72xx", PIN_SCHEMA)
async def pin_to_code(config):
return await libretiny.gpio.component_pin_to_code(config)
Loading

0 comments on commit a9630ac

Please sign in to comment.