mirror of
https://github.com/esphome/esphome.git
synced 2025-10-05 03:13:49 +01:00
Updates for 1.13 (#546)
* Update CI matcher * Check Executable bit * Quicklint * Updates * Allow pm1.0 and pm10.0 for PMS5003ST Fixes https://github.com/esphome/feature-requests/issues/225 * PowerSupplyRequester * Lint * Include debug data in generated main.cpp * Updates * Auto-select bit_depth * Updates
This commit is contained in:
@@ -1,20 +1,54 @@
|
||||
import math
|
||||
|
||||
from esphome import pins
|
||||
from esphome.components import output
|
||||
import esphome.config_validation as cv
|
||||
import esphome.codegen as cg
|
||||
from esphome.const import APB_CLOCK_FREQ, CONF_BIT_DEPTH, CONF_CHANNEL, CONF_FREQUENCY, \
|
||||
from esphome.const import CONF_BIT_DEPTH, CONF_CHANNEL, CONF_FREQUENCY, \
|
||||
CONF_ID, CONF_PIN, ESP_PLATFORM_ESP32
|
||||
|
||||
ESP_PLATFORMS = [ESP_PLATFORM_ESP32]
|
||||
|
||||
|
||||
def calc_max_frequency(bit_depth):
|
||||
return 80e6 / (2**bit_depth)
|
||||
|
||||
|
||||
def calc_min_frequency(bit_depth):
|
||||
# LEDC_DIV_NUM_HSTIMER is 15-bit unsigned integer
|
||||
# lower 8 bits represent fractional part
|
||||
max_div_num = ((1 << 16) - 1) / 256.0
|
||||
return 80e6 / (max_div_num * (2**bit_depth))
|
||||
|
||||
|
||||
def validate_frequency_bit_depth(obj):
|
||||
frequency = obj[CONF_FREQUENCY]
|
||||
if CONF_BIT_DEPTH not in obj:
|
||||
obj = obj.copy()
|
||||
for bit_depth in range(15, 0, -1):
|
||||
if calc_min_frequency(bit_depth) <= frequency <= calc_max_frequency(bit_depth):
|
||||
obj[CONF_BIT_DEPTH] = bit_depth
|
||||
break
|
||||
else:
|
||||
min_freq = min(calc_min_frequency(x) for x in range(1, 16))
|
||||
max_freq = max(calc_max_frequency(x) for x in range(1, 16))
|
||||
if frequency < min_freq:
|
||||
raise cv.Invalid("This frequency setting is not possible, please choose a higher "
|
||||
"frequency (at least {}Hz)".format(int(min_freq)))
|
||||
if frequency > max_freq:
|
||||
raise cv.Invalid("This frequency setting is not possible, please choose a lower "
|
||||
"frequency (at most {}Hz)".format(int(max_freq)))
|
||||
raise cv.Invalid("Invalid frequency!")
|
||||
|
||||
bit_depth = obj[CONF_BIT_DEPTH]
|
||||
max_freq = APB_CLOCK_FREQ / (2**bit_depth)
|
||||
min_freq = calc_min_frequency(bit_depth)
|
||||
max_freq = calc_max_frequency(bit_depth)
|
||||
if frequency > max_freq:
|
||||
raise cv.Invalid('Maximum frequency for bit depth {} is {}Hz'.format(bit_depth, max_freq))
|
||||
raise cv.Invalid('Maximum frequency for bit depth {} is {}Hz. Please decrease the '
|
||||
'bit_depth.'.format(bit_depth, int(math.floor(max_freq))))
|
||||
if frequency < calc_min_frequency(bit_depth):
|
||||
raise cv.Invalid('Minimum frequency for bit depth {} is {}Hz. Please increase the '
|
||||
'bit_depth.'.format(bit_depth, int(math.ceil(min_freq))))
|
||||
return obj
|
||||
|
||||
|
||||
@@ -25,7 +59,7 @@ CONFIG_SCHEMA = cv.All(output.FLOAT_OUTPUT_SCHEMA.extend({
|
||||
cv.Required(CONF_ID): cv.declare_id(LEDCOutput),
|
||||
cv.Required(CONF_PIN): pins.internal_gpio_output_pin_schema,
|
||||
cv.Optional(CONF_FREQUENCY, default='1kHz'): cv.frequency,
|
||||
cv.Optional(CONF_BIT_DEPTH, default=12): cv.int_range(min=1, max=15),
|
||||
cv.Optional(CONF_BIT_DEPTH): cv.int_range(min=1, max=15),
|
||||
cv.Optional(CONF_CHANNEL): cv.int_range(min=0, max=15),
|
||||
}).extend(cv.COMPONENT_SCHEMA), validate_frequency_bit_depth)
|
||||
|
||||
|
Reference in New Issue
Block a user