mirror of
https://github.com/esphome/esphome.git
synced 2025-06-22 00:05:37 +01:00
make cdc not sleep
This commit is contained in:
esphome
__main__.py
components
dfu
display
fota
light
logger
nrf52
zephyr
zephyr_ble_server
zephyr_mcumgr
zephyr_ota_mcumgr
zephyr_uart
core
tests
@ -161,6 +161,8 @@ def run_miniterm(config, port):
|
|||||||
ser = serial.Serial()
|
ser = serial.Serial()
|
||||||
ser.baudrate = baud_rate
|
ser.baudrate = baud_rate
|
||||||
ser.port = port
|
ser.port = port
|
||||||
|
# prevent usb port from sleep
|
||||||
|
ser.timeout = 1
|
||||||
|
|
||||||
# We can't set to False by default since it leads to toggling and hence
|
# We can't set to False by default since it leads to toggling and hence
|
||||||
# ESP32 resets on some platforms.
|
# ESP32 resets on some platforms.
|
||||||
@ -175,6 +177,8 @@ def run_miniterm(config, port):
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
raw = ser.readline()
|
raw = ser.readline()
|
||||||
|
if len(raw) == 0:
|
||||||
|
continue
|
||||||
except serial.SerialException:
|
except serial.SerialException:
|
||||||
_LOGGER.error("Serial port closed!")
|
_LOGGER.error("Serial port closed!")
|
||||||
return 0
|
return 0
|
||||||
|
@ -6,7 +6,7 @@ from esphome.const import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from esphome.core import CORE
|
from esphome.core import CORE
|
||||||
from esphome.components.nrf52.zephyr import zephyr_add_prj_conf
|
from esphome.components.zephyr import zephyr_add_prj_conf
|
||||||
|
|
||||||
dfu_ns = cg.esphome_ns.namespace("dfu")
|
dfu_ns = cg.esphome_ns.namespace("dfu")
|
||||||
DeviceFirmwareUpdate = dfu_ns.class_("DeviceFirmwareUpdate", cg.Component)
|
DeviceFirmwareUpdate = dfu_ns.class_("DeviceFirmwareUpdate", cg.Component)
|
||||||
|
@ -15,11 +15,11 @@ class Rect {
|
|||||||
int16_t h; ///< Height of region
|
int16_t h; ///< Height of region
|
||||||
|
|
||||||
Rect() : x(VALUE_NO_SET), y(VALUE_NO_SET), w(VALUE_NO_SET), h(VALUE_NO_SET) {} // NOLINT
|
Rect() : x(VALUE_NO_SET), y(VALUE_NO_SET), w(VALUE_NO_SET), h(VALUE_NO_SET) {} // NOLINT
|
||||||
inline Rect(int16_t x, int16_t y, int16_t w, int16_t h) ALWAYS_INLINE : x(x), y(y), w(w), h(h) {}
|
inline Rect(int16_t x, int16_t y, int16_t w, int16_t h) ESPHOME_ALWAYS_INLINE : x(x), y(y), w(w), h(h) {}
|
||||||
inline int16_t x2() const { return this->x + this->w; }; ///< X coordinate of corner
|
inline int16_t x2() const { return this->x + this->w; }; ///< X coordinate of corner
|
||||||
inline int16_t y2() const { return this->y + this->h; }; ///< Y coordinate of corner
|
inline int16_t y2() const { return this->y + this->h; }; ///< Y coordinate of corner
|
||||||
|
|
||||||
inline bool is_set() const ALWAYS_INLINE { return (this->h != VALUE_NO_SET) && (this->w != VALUE_NO_SET); }
|
inline bool is_set() const ESPHOME_ALWAYS_INLINE { return (this->h != VALUE_NO_SET) && (this->w != VALUE_NO_SET); }
|
||||||
|
|
||||||
void expand(int16_t horizontal, int16_t vertical);
|
void expand(int16_t horizontal, int16_t vertical);
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ from esphome.const import (
|
|||||||
CONF_ID,
|
CONF_ID,
|
||||||
)
|
)
|
||||||
|
|
||||||
from esphome.components.nrf52.zephyr import zephyr_add_prj_conf, zephyr_add_overlay
|
from esphome.components.zephyr import zephyr_add_prj_conf, zephyr_add_overlay
|
||||||
|
|
||||||
fota_ns = cg.esphome_ns.namespace("fota")
|
fota_ns = cg.esphome_ns.namespace("fota")
|
||||||
FOTAComponent = fota_ns.class_("FOTAComponent", cg.Component)
|
FOTAComponent = fota_ns.class_("FOTAComponent", cg.Component)
|
||||||
|
@ -11,54 +11,54 @@ class ESPColorCorrection {
|
|||||||
void set_max_brightness(const Color &max_brightness) { this->max_brightness_ = max_brightness; }
|
void set_max_brightness(const Color &max_brightness) { this->max_brightness_ = max_brightness; }
|
||||||
void set_local_brightness(uint8_t local_brightness) { this->local_brightness_ = local_brightness; }
|
void set_local_brightness(uint8_t local_brightness) { this->local_brightness_ = local_brightness; }
|
||||||
void calculate_gamma_table(float gamma);
|
void calculate_gamma_table(float gamma);
|
||||||
inline Color color_correct(Color color) const ALWAYS_INLINE {
|
inline Color color_correct(Color color) const ESPHOME_ALWAYS_INLINE {
|
||||||
// corrected = (uncorrected * max_brightness * local_brightness) ^ gamma
|
// corrected = (uncorrected * max_brightness * local_brightness) ^ gamma
|
||||||
return Color(this->color_correct_red(color.red), this->color_correct_green(color.green),
|
return Color(this->color_correct_red(color.red), this->color_correct_green(color.green),
|
||||||
this->color_correct_blue(color.blue), this->color_correct_white(color.white));
|
this->color_correct_blue(color.blue), this->color_correct_white(color.white));
|
||||||
}
|
}
|
||||||
inline uint8_t color_correct_red(uint8_t red) const ALWAYS_INLINE {
|
inline uint8_t color_correct_red(uint8_t red) const ESPHOME_ALWAYS_INLINE {
|
||||||
uint8_t res = esp_scale8(esp_scale8(red, this->max_brightness_.red), this->local_brightness_);
|
uint8_t res = esp_scale8(esp_scale8(red, this->max_brightness_.red), this->local_brightness_);
|
||||||
return this->gamma_table_[res];
|
return this->gamma_table_[res];
|
||||||
}
|
}
|
||||||
inline uint8_t color_correct_green(uint8_t green) const ALWAYS_INLINE {
|
inline uint8_t color_correct_green(uint8_t green) const ESPHOME_ALWAYS_INLINE {
|
||||||
uint8_t res = esp_scale8(esp_scale8(green, this->max_brightness_.green), this->local_brightness_);
|
uint8_t res = esp_scale8(esp_scale8(green, this->max_brightness_.green), this->local_brightness_);
|
||||||
return this->gamma_table_[res];
|
return this->gamma_table_[res];
|
||||||
}
|
}
|
||||||
inline uint8_t color_correct_blue(uint8_t blue) const ALWAYS_INLINE {
|
inline uint8_t color_correct_blue(uint8_t blue) const ESPHOME_ALWAYS_INLINE {
|
||||||
uint8_t res = esp_scale8(esp_scale8(blue, this->max_brightness_.blue), this->local_brightness_);
|
uint8_t res = esp_scale8(esp_scale8(blue, this->max_brightness_.blue), this->local_brightness_);
|
||||||
return this->gamma_table_[res];
|
return this->gamma_table_[res];
|
||||||
}
|
}
|
||||||
inline uint8_t color_correct_white(uint8_t white) const ALWAYS_INLINE {
|
inline uint8_t color_correct_white(uint8_t white) const ESPHOME_ALWAYS_INLINE {
|
||||||
uint8_t res = esp_scale8(esp_scale8(white, this->max_brightness_.white), this->local_brightness_);
|
uint8_t res = esp_scale8(esp_scale8(white, this->max_brightness_.white), this->local_brightness_);
|
||||||
return this->gamma_table_[res];
|
return this->gamma_table_[res];
|
||||||
}
|
}
|
||||||
inline Color color_uncorrect(Color color) const ALWAYS_INLINE {
|
inline Color color_uncorrect(Color color) const ESPHOME_ALWAYS_INLINE {
|
||||||
// uncorrected = corrected^(1/gamma) / (max_brightness * local_brightness)
|
// uncorrected = corrected^(1/gamma) / (max_brightness * local_brightness)
|
||||||
return Color(this->color_uncorrect_red(color.red), this->color_uncorrect_green(color.green),
|
return Color(this->color_uncorrect_red(color.red), this->color_uncorrect_green(color.green),
|
||||||
this->color_uncorrect_blue(color.blue), this->color_uncorrect_white(color.white));
|
this->color_uncorrect_blue(color.blue), this->color_uncorrect_white(color.white));
|
||||||
}
|
}
|
||||||
inline uint8_t color_uncorrect_red(uint8_t red) const ALWAYS_INLINE {
|
inline uint8_t color_uncorrect_red(uint8_t red) const ESPHOME_ALWAYS_INLINE {
|
||||||
if (this->max_brightness_.red == 0 || this->local_brightness_ == 0)
|
if (this->max_brightness_.red == 0 || this->local_brightness_ == 0)
|
||||||
return 0;
|
return 0;
|
||||||
uint16_t uncorrected = this->gamma_reverse_table_[red] * 255UL;
|
uint16_t uncorrected = this->gamma_reverse_table_[red] * 255UL;
|
||||||
uint8_t res = ((uncorrected / this->max_brightness_.red) * 255UL) / this->local_brightness_;
|
uint8_t res = ((uncorrected / this->max_brightness_.red) * 255UL) / this->local_brightness_;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
inline uint8_t color_uncorrect_green(uint8_t green) const ALWAYS_INLINE {
|
inline uint8_t color_uncorrect_green(uint8_t green) const ESPHOME_ALWAYS_INLINE {
|
||||||
if (this->max_brightness_.green == 0 || this->local_brightness_ == 0)
|
if (this->max_brightness_.green == 0 || this->local_brightness_ == 0)
|
||||||
return 0;
|
return 0;
|
||||||
uint16_t uncorrected = this->gamma_reverse_table_[green] * 255UL;
|
uint16_t uncorrected = this->gamma_reverse_table_[green] * 255UL;
|
||||||
uint8_t res = ((uncorrected / this->max_brightness_.green) * 255UL) / this->local_brightness_;
|
uint8_t res = ((uncorrected / this->max_brightness_.green) * 255UL) / this->local_brightness_;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
inline uint8_t color_uncorrect_blue(uint8_t blue) const ALWAYS_INLINE {
|
inline uint8_t color_uncorrect_blue(uint8_t blue) const ESPHOME_ALWAYS_INLINE {
|
||||||
if (this->max_brightness_.blue == 0 || this->local_brightness_ == 0)
|
if (this->max_brightness_.blue == 0 || this->local_brightness_ == 0)
|
||||||
return 0;
|
return 0;
|
||||||
uint16_t uncorrected = this->gamma_reverse_table_[blue] * 255UL;
|
uint16_t uncorrected = this->gamma_reverse_table_[blue] * 255UL;
|
||||||
uint8_t res = ((uncorrected / this->max_brightness_.blue) * 255UL) / this->local_brightness_;
|
uint8_t res = ((uncorrected / this->max_brightness_.blue) * 255UL) / this->local_brightness_;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
inline uint8_t color_uncorrect_white(uint8_t white) const ALWAYS_INLINE {
|
inline uint8_t color_uncorrect_white(uint8_t white) const ESPHOME_ALWAYS_INLINE {
|
||||||
if (this->max_brightness_.white == 0 || this->local_brightness_ == 0)
|
if (this->max_brightness_.white == 0 || this->local_brightness_ == 0)
|
||||||
return 0;
|
return 0;
|
||||||
uint16_t uncorrected = this->gamma_reverse_table_[white] * 255UL;
|
uint16_t uncorrected = this->gamma_reverse_table_[white] * 255UL;
|
||||||
|
@ -24,9 +24,9 @@ struct ESPHSVColor {
|
|||||||
};
|
};
|
||||||
uint8_t raw[3];
|
uint8_t raw[3];
|
||||||
};
|
};
|
||||||
inline ESPHSVColor() ALWAYS_INLINE : h(0), s(0), v(0) { // NOLINT
|
inline ESPHSVColor() ESPHOME_ALWAYS_INLINE : h(0), s(0), v(0) { // NOLINT
|
||||||
}
|
}
|
||||||
inline ESPHSVColor(uint8_t hue, uint8_t saturation, uint8_t value) ALWAYS_INLINE : hue(hue),
|
inline ESPHSVColor(uint8_t hue, uint8_t saturation, uint8_t value) ESPHOME_ALWAYS_INLINE : hue(hue),
|
||||||
saturation(saturation),
|
saturation(saturation),
|
||||||
value(value) {}
|
value(value) {}
|
||||||
Color to_rgb() const;
|
Color to_rgb() const;
|
||||||
|
@ -40,7 +40,15 @@ from esphome.components.libretiny.const import (
|
|||||||
COMPONENT_BK72XX,
|
COMPONENT_BK72XX,
|
||||||
COMPONENT_RTL87XX,
|
COMPONENT_RTL87XX,
|
||||||
)
|
)
|
||||||
from esphome.components.nrf52.zephyr import zephyr_add_overlay, zephyr_add_prj_conf
|
from esphome.components.zephyr import zephyr_add_overlay, zephyr_add_prj_conf
|
||||||
|
from esphome.components.zephyr_uart import zephyr_add_cdc_acm
|
||||||
|
|
||||||
|
|
||||||
|
def AUTO_LOAD():
|
||||||
|
if CORE.using_zephyr:
|
||||||
|
return ["zephyr_uart"]
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
CODEOWNERS = ["@esphome/core"]
|
CODEOWNERS = ["@esphome/core"]
|
||||||
logger_ns = cg.esphome_ns.namespace("logger")
|
logger_ns = cg.esphome_ns.namespace("logger")
|
||||||
@ -301,17 +309,7 @@ async def to_code(config):
|
|||||||
zephyr_add_overlay("""&uart0 { status = "okay";};""")
|
zephyr_add_overlay("""&uart0 { status = "okay";};""")
|
||||||
if config[CONF_HARDWARE_UART] == USB_CDC:
|
if config[CONF_HARDWARE_UART] == USB_CDC:
|
||||||
zephyr_add_prj_conf("UART_LINE_CTRL", True)
|
zephyr_add_prj_conf("UART_LINE_CTRL", True)
|
||||||
zephyr_add_prj_conf("USB_DEVICE_STACK", True)
|
zephyr_add_cdc_acm(config)
|
||||||
zephyr_add_prj_conf("USB_CDC_ACM", True)
|
|
||||||
zephyr_add_overlay(
|
|
||||||
"""
|
|
||||||
&zephyr_udc0 {
|
|
||||||
cdc_acm_uart0: cdc_acm_uart0 {
|
|
||||||
compatible = "zephyr,cdc-acm-uart";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
||||||
# Register at end for safe mode
|
# Register at end for safe mode
|
||||||
await cg.register_component(log, config)
|
await cg.register_component(log, config)
|
||||||
|
@ -16,7 +16,7 @@ from esphome.helpers import (
|
|||||||
copy_file_if_changed,
|
copy_file_if_changed,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .zephyr import (
|
from esphome.components.zephyr import (
|
||||||
zephyr_copy_files,
|
zephyr_copy_files,
|
||||||
zephyr_set_core_data,
|
zephyr_set_core_data,
|
||||||
zephyr_to_code,
|
zephyr_to_code,
|
||||||
|
@ -6,10 +6,10 @@ from esphome.helpers import (
|
|||||||
)
|
)
|
||||||
from .const import (
|
from .const import (
|
||||||
ZEPHYR_VARIANT_GENERIC,
|
ZEPHYR_VARIANT_GENERIC,
|
||||||
|
ZEPHYR_VARIANT_NRF_SDK,
|
||||||
KEY_ZEPHYR,
|
KEY_ZEPHYR,
|
||||||
KEY_PRJ_CONF,
|
KEY_PRJ_CONF,
|
||||||
KEY_OVERLAY,
|
KEY_OVERLAY,
|
||||||
ZEPHYR_VARIANT_NRF_SDK,
|
|
||||||
)
|
)
|
||||||
from esphome.const import (
|
from esphome.const import (
|
||||||
CONF_VARIANT,
|
CONF_VARIANT,
|
||||||
@ -75,16 +75,19 @@ def zephyr_to_code(conf):
|
|||||||
# watchdog
|
# watchdog
|
||||||
zephyr_add_prj_conf("WATCHDOG", True)
|
zephyr_add_prj_conf("WATCHDOG", True)
|
||||||
zephyr_add_prj_conf("WDT_DISABLE_AT_BOOT", False)
|
zephyr_add_prj_conf("WDT_DISABLE_AT_BOOT", False)
|
||||||
|
# disable console
|
||||||
|
zephyr_add_prj_conf("UART_CONSOLE", False)
|
||||||
|
zephyr_add_prj_conf("CONSOLE", False)
|
||||||
# TODO debug only
|
# TODO debug only
|
||||||
# zephyr_add_prj_conf("DEBUG_THREAD_INFO", True)
|
zephyr_add_prj_conf("DEBUG_THREAD_INFO", True)
|
||||||
|
# zephyr_add_prj_conf("DEBUG", True)
|
||||||
###
|
###
|
||||||
# zephyr_add_prj_conf("USE_SEGGER_RTT", True)
|
# zephyr_add_prj_conf("USE_SEGGER_RTT", True)
|
||||||
# zephyr_add_prj_conf("RTT_CONSOLE", True)
|
# zephyr_add_prj_conf("RTT_CONSOLE", True)
|
||||||
# zephyr_add_prj_conf("UART_CONSOLE", False)
|
|
||||||
|
|
||||||
# zephyr_add_prj_conf("LOG", True)
|
# zephyr_add_prj_conf("LOG", True)
|
||||||
# zephyr_add_prj_conf("MCUBOOT_UTIL_LOG_LEVEL_WRN", True)
|
|
||||||
# zephyr_add_prj_conf("BOOTLOADER_MCUBOOT", True)
|
# zephyr_add_prj_conf("USB_DEVICE_LOG_LEVEL_ERR", True)
|
||||||
|
# zephyr_add_prj_conf("USB_CDC_ACM_LOG_LEVEL_DBG", True)
|
||||||
|
|
||||||
|
|
||||||
def _format_prj_conf_val(value: PrjConfValueType) -> str:
|
def _format_prj_conf_val(value: PrjConfValueType) -> str:
|
5
esphome/components/zephyr/const.py
Normal file
5
esphome/components/zephyr/const.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
ZEPHYR_VARIANT_GENERIC = "generic"
|
||||||
|
ZEPHYR_VARIANT_NRF_SDK = "nrf-sdk"
|
||||||
|
KEY_ZEPHYR = "zephyr"
|
||||||
|
KEY_PRJ_CONF = "prj_conf"
|
||||||
|
KEY_OVERLAY = "overlay"
|
@ -3,7 +3,7 @@ import esphome.config_validation as cv
|
|||||||
from esphome.const import (
|
from esphome.const import (
|
||||||
CONF_ID,
|
CONF_ID,
|
||||||
)
|
)
|
||||||
from esphome.components.nrf52.zephyr import zephyr_add_prj_conf
|
from esphome.components.zephyr import zephyr_add_prj_conf
|
||||||
|
|
||||||
zephyr_ble_server_ns = cg.esphome_ns.namespace("zephyr_ble_server")
|
zephyr_ble_server_ns = cg.esphome_ns.namespace("zephyr_ble_server")
|
||||||
BLEServer = zephyr_ble_server_ns.class_("BLEServer", cg.Component)
|
BLEServer = zephyr_ble_server_ns.class_("BLEServer", cg.Component)
|
||||||
@ -22,4 +22,5 @@ async def to_code(config):
|
|||||||
var = cg.new_Pvariable(config[CONF_ID])
|
var = cg.new_Pvariable(config[CONF_ID])
|
||||||
zephyr_add_prj_conf("BT", True)
|
zephyr_add_prj_conf("BT", True)
|
||||||
zephyr_add_prj_conf("BT_PERIPHERAL", True)
|
zephyr_add_prj_conf("BT_PERIPHERAL", True)
|
||||||
|
# zephyr_add_prj_conf("BT_LL_SW_SPLIT", True)
|
||||||
await cg.register_component(var, config)
|
await cg.register_component(var, config)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from esphome.components.nrf52.zephyr import zephyr_add_prj_conf
|
from esphome.components.zephyr import zephyr_add_prj_conf
|
||||||
|
|
||||||
|
|
||||||
async def to_code(config):
|
async def to_code(config):
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from esphome.components.nrf52.zephyr import zephyr_add_prj_conf
|
from esphome.components.zephyr import zephyr_add_prj_conf
|
||||||
|
|
||||||
DEPENDENCIES = ["zephyr_ble_server"]
|
DEPENDENCIES = ["zephyr_ble_server"]
|
||||||
AUTO_LOAD = ["zephyr_mcumgr"]
|
AUTO_LOAD = ["zephyr_mcumgr"]
|
||||||
|
17
esphome/components/zephyr_uart/__init__.py
Normal file
17
esphome/components/zephyr_uart/__init__.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
from esphome.components.zephyr import zephyr_add_prj_conf, zephyr_add_overlay
|
||||||
|
|
||||||
|
|
||||||
|
def zephyr_add_cdc_acm(config):
|
||||||
|
zephyr_add_prj_conf("USB_DEVICE_STACK", True)
|
||||||
|
zephyr_add_prj_conf("USB_CDC_ACM", True)
|
||||||
|
# prevent device to go to susspend
|
||||||
|
zephyr_add_prj_conf("USB_DEVICE_REMOTE_WAKEUP", False)
|
||||||
|
zephyr_add_overlay(
|
||||||
|
"""
|
||||||
|
&zephyr_udc0 {
|
||||||
|
cdc_acm_uart0: cdc_acm_uart0 {
|
||||||
|
compatible = "zephyr,cdc-acm-uart";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
"""
|
||||||
|
)
|
58
esphome/components/zephyr_uart/ring_buffer.cpp
Normal file
58
esphome/components/zephyr_uart/ring_buffer.cpp
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#include "ring_buffer.h"
|
||||||
|
#include <zephyr/drivers/uart.h>
|
||||||
|
|
||||||
|
#ifndef CONFIG_UART_INTERRUPT_DRIVEN
|
||||||
|
#error "CONFIG_UART_INTERRUPT_DRIVEN is required"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// while (true) {
|
||||||
|
// uart_line_ctrl_get(dev, UART_LINE_CTRL_DTR, &dtr);
|
||||||
|
// if (dtr) {
|
||||||
|
// break;
|
||||||
|
// } else {
|
||||||
|
// /* Give CPU resources to low priority threads. */
|
||||||
|
// k_sleep(K_MSEC(100));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
namespace esphome {
|
||||||
|
namespace zephyr_uart {
|
||||||
|
|
||||||
|
void RingBuffer::setup(const device *dev, uint8_t *ring_buffer, uint32_t size) {
|
||||||
|
dev_ = dev;
|
||||||
|
ring_buf_init(&ringbuf_, size, ring_buffer);
|
||||||
|
uart_irq_callback_user_data_set(dev, interrupt_handler_, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t RingBuffer::fill(const char *data, uint32_t size) {
|
||||||
|
// TODO block if no space
|
||||||
|
uint32_t rb_len = ring_buf_put(&ringbuf_, reinterpret_cast<const uint8_t*>(data), size);
|
||||||
|
if (rb_len) {
|
||||||
|
uart_irq_tx_enable(dev_);
|
||||||
|
}
|
||||||
|
return rb_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RingBuffer::interrupt_handler_(const device *dev, void *user_data) {
|
||||||
|
auto thiz = static_cast<RingBuffer *>(user_data);
|
||||||
|
while (uart_irq_update(dev) && uart_irq_is_pending(dev)) {
|
||||||
|
if (uart_irq_tx_ready(dev)) {
|
||||||
|
uint8_t buffer[64];
|
||||||
|
int rb_len, send_len;
|
||||||
|
|
||||||
|
rb_len = ring_buf_get(&thiz->ringbuf_, buffer, sizeof(buffer));
|
||||||
|
if (!rb_len) {
|
||||||
|
uart_irq_tx_disable(dev);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
uart_fifo_fill(dev, buffer, rb_len);
|
||||||
|
// TODO add blocking
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace zephyr_uart
|
||||||
|
} // namespace esphome
|
20
esphome/components/zephyr_uart/ring_buffer.h
Normal file
20
esphome/components/zephyr_uart/ring_buffer.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <zephyr/sys/ring_buffer.h>
|
||||||
|
|
||||||
|
class device;
|
||||||
|
|
||||||
|
namespace esphome {
|
||||||
|
namespace zephyr_uart {
|
||||||
|
|
||||||
|
class RingBuffer {
|
||||||
|
public:
|
||||||
|
void setup(const device *dev, uint8_t *ring_buffer, uint32_t size);
|
||||||
|
uint32_t fill(const char* data, uint32_t size);
|
||||||
|
protected:
|
||||||
|
static void interrupt_handler_(const device *dev, void *user_data);
|
||||||
|
ring_buf ringbuf_;
|
||||||
|
const device *dev_ = {nullptr};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace zephyr_uart
|
||||||
|
} // namespace esphome
|
@ -31,19 +31,19 @@ struct Color {
|
|||||||
uint32_t raw_32;
|
uint32_t raw_32;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline Color() ALWAYS_INLINE : r(0), g(0), b(0), w(0) {} // NOLINT
|
inline Color() ESPHOME_ALWAYS_INLINE : r(0), g(0), b(0), w(0) {} // NOLINT
|
||||||
inline Color(uint8_t red, uint8_t green, uint8_t blue) ALWAYS_INLINE : r(red), g(green), b(blue), w(0) {}
|
inline Color(uint8_t red, uint8_t green, uint8_t blue) ESPHOME_ALWAYS_INLINE : r(red), g(green), b(blue), w(0) {}
|
||||||
|
|
||||||
inline Color(uint8_t red, uint8_t green, uint8_t blue, uint8_t white) ALWAYS_INLINE : r(red),
|
inline Color(uint8_t red, uint8_t green, uint8_t blue, uint8_t white) ESPHOME_ALWAYS_INLINE : r(red),
|
||||||
g(green),
|
g(green),
|
||||||
b(blue),
|
b(blue),
|
||||||
w(white) {}
|
w(white) {}
|
||||||
inline explicit Color(uint32_t colorcode) ALWAYS_INLINE : r((colorcode >> 16) & 0xFF),
|
inline explicit Color(uint32_t colorcode) ESPHOME_ALWAYS_INLINE : r((colorcode >> 16) & 0xFF),
|
||||||
g((colorcode >> 8) & 0xFF),
|
g((colorcode >> 8) & 0xFF),
|
||||||
b((colorcode >> 0) & 0xFF),
|
b((colorcode >> 0) & 0xFF),
|
||||||
w((colorcode >> 24) & 0xFF) {}
|
w((colorcode >> 24) & 0xFF) {}
|
||||||
|
|
||||||
inline bool is_on() ALWAYS_INLINE { return this->raw_32 != 0; }
|
inline bool is_on() ESPHOME_ALWAYS_INLINE { return this->raw_32 != 0; }
|
||||||
|
|
||||||
inline bool operator==(const Color &rhs) { // NOLINT
|
inline bool operator==(const Color &rhs) { // NOLINT
|
||||||
return this->raw_32 == rhs.raw_32;
|
return this->raw_32 == rhs.raw_32;
|
||||||
@ -57,30 +57,30 @@ struct Color {
|
|||||||
inline bool operator!=(uint32_t colorcode) { // NOLINT
|
inline bool operator!=(uint32_t colorcode) { // NOLINT
|
||||||
return this->raw_32 != colorcode;
|
return this->raw_32 != colorcode;
|
||||||
}
|
}
|
||||||
inline uint8_t &operator[](uint8_t x) ALWAYS_INLINE { return this->raw[x]; }
|
inline uint8_t &operator[](uint8_t x) ESPHOME_ALWAYS_INLINE { return this->raw[x]; }
|
||||||
inline Color operator*(uint8_t scale) const ALWAYS_INLINE {
|
inline Color operator*(uint8_t scale) const ESPHOME_ALWAYS_INLINE {
|
||||||
return Color(esp_scale8(this->red, scale), esp_scale8(this->green, scale), esp_scale8(this->blue, scale),
|
return Color(esp_scale8(this->red, scale), esp_scale8(this->green, scale), esp_scale8(this->blue, scale),
|
||||||
esp_scale8(this->white, scale));
|
esp_scale8(this->white, scale));
|
||||||
}
|
}
|
||||||
inline Color &operator*=(uint8_t scale) ALWAYS_INLINE {
|
inline Color &operator*=(uint8_t scale) ESPHOME_ALWAYS_INLINE {
|
||||||
this->red = esp_scale8(this->red, scale);
|
this->red = esp_scale8(this->red, scale);
|
||||||
this->green = esp_scale8(this->green, scale);
|
this->green = esp_scale8(this->green, scale);
|
||||||
this->blue = esp_scale8(this->blue, scale);
|
this->blue = esp_scale8(this->blue, scale);
|
||||||
this->white = esp_scale8(this->white, scale);
|
this->white = esp_scale8(this->white, scale);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
inline Color operator*(const Color &scale) const ALWAYS_INLINE {
|
inline Color operator*(const Color &scale) const ESPHOME_ALWAYS_INLINE {
|
||||||
return Color(esp_scale8(this->red, scale.red), esp_scale8(this->green, scale.green),
|
return Color(esp_scale8(this->red, scale.red), esp_scale8(this->green, scale.green),
|
||||||
esp_scale8(this->blue, scale.blue), esp_scale8(this->white, scale.white));
|
esp_scale8(this->blue, scale.blue), esp_scale8(this->white, scale.white));
|
||||||
}
|
}
|
||||||
inline Color &operator*=(const Color &scale) ALWAYS_INLINE {
|
inline Color &operator*=(const Color &scale) ESPHOME_ALWAYS_INLINE {
|
||||||
this->red = esp_scale8(this->red, scale.red);
|
this->red = esp_scale8(this->red, scale.red);
|
||||||
this->green = esp_scale8(this->green, scale.green);
|
this->green = esp_scale8(this->green, scale.green);
|
||||||
this->blue = esp_scale8(this->blue, scale.blue);
|
this->blue = esp_scale8(this->blue, scale.blue);
|
||||||
this->white = esp_scale8(this->white, scale.white);
|
this->white = esp_scale8(this->white, scale.white);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
inline Color operator+(const Color &add) const ALWAYS_INLINE {
|
inline Color operator+(const Color &add) const ESPHOME_ALWAYS_INLINE {
|
||||||
Color ret;
|
Color ret;
|
||||||
if (uint8_t(add.r + this->r) < this->r)
|
if (uint8_t(add.r + this->r) < this->r)
|
||||||
ret.r = 255;
|
ret.r = 255;
|
||||||
@ -100,10 +100,10 @@ struct Color {
|
|||||||
ret.w = this->w + add.w;
|
ret.w = this->w + add.w;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
inline Color &operator+=(const Color &add) ALWAYS_INLINE { return *this = (*this) + add; }
|
inline Color &operator+=(const Color &add) ESPHOME_ALWAYS_INLINE { return *this = (*this) + add; }
|
||||||
inline Color operator+(uint8_t add) const ALWAYS_INLINE { return (*this) + Color(add, add, add, add); }
|
inline Color operator+(uint8_t add) const ESPHOME_ALWAYS_INLINE { return (*this) + Color(add, add, add, add); }
|
||||||
inline Color &operator+=(uint8_t add) ALWAYS_INLINE { return *this = (*this) + add; }
|
inline Color &operator+=(uint8_t add) ESPHOME_ALWAYS_INLINE { return *this = (*this) + add; }
|
||||||
inline Color operator-(const Color &subtract) const ALWAYS_INLINE {
|
inline Color operator-(const Color &subtract) const ESPHOME_ALWAYS_INLINE {
|
||||||
Color ret;
|
Color ret;
|
||||||
if (subtract.r > this->r)
|
if (subtract.r > this->r)
|
||||||
ret.r = 0;
|
ret.r = 0;
|
||||||
@ -123,11 +123,11 @@ struct Color {
|
|||||||
ret.w = this->w - subtract.w;
|
ret.w = this->w - subtract.w;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
inline Color &operator-=(const Color &subtract) ALWAYS_INLINE { return *this = (*this) - subtract; }
|
inline Color &operator-=(const Color &subtract) ESPHOME_ALWAYS_INLINE { return *this = (*this) - subtract; }
|
||||||
inline Color operator-(uint8_t subtract) const ALWAYS_INLINE {
|
inline Color operator-(uint8_t subtract) const ESPHOME_ALWAYS_INLINE {
|
||||||
return (*this) - Color(subtract, subtract, subtract, subtract);
|
return (*this) - Color(subtract, subtract, subtract, subtract);
|
||||||
}
|
}
|
||||||
inline Color &operator-=(uint8_t subtract) ALWAYS_INLINE { return *this = (*this) - subtract; }
|
inline Color &operator-=(uint8_t subtract) ESPHOME_ALWAYS_INLINE { return *this = (*this) - subtract; }
|
||||||
static Color random_color() {
|
static Color random_color() {
|
||||||
uint32_t rand = random_uint32();
|
uint32_t rand = random_uint32();
|
||||||
uint8_t w = rand >> 24;
|
uint8_t w = rand >> 24;
|
||||||
|
@ -39,7 +39,7 @@ from esphome.const import (
|
|||||||
)
|
)
|
||||||
from esphome.core import CORE, coroutine_with_priority
|
from esphome.core import CORE, coroutine_with_priority
|
||||||
from esphome.helpers import copy_file_if_changed, walk_files
|
from esphome.helpers import copy_file_if_changed, walk_files
|
||||||
from esphome.components.nrf52.zephyr import zephyr_add_prj_conf
|
from esphome.components.zephyr import zephyr_add_prj_conf
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
#define HOT __attribute__((hot))
|
#define HOT __attribute__((hot))
|
||||||
#define ESPDEPRECATED(msg, when) __attribute__((deprecated(msg)))
|
#define ESPDEPRECATED(msg, when) __attribute__((deprecated(msg)))
|
||||||
#define ALWAYS_INLINE __attribute__((always_inline))
|
#define ESPHOME_ALWAYS_INLINE __attribute__((always_inline))
|
||||||
#define PACKED __attribute__((packed))
|
#define PACKED __attribute__((packed))
|
||||||
|
|
||||||
// Various functions can be constexpr in C++14, but not in C++11 (because their body isn't just a return statement).
|
// Various functions can be constexpr in C++14, but not in C++11 (because their body isn't just a return statement).
|
||||||
|
@ -12,9 +12,9 @@ esphome:
|
|||||||
name: nrf52-test-nrf
|
name: nrf52-test-nrf
|
||||||
|
|
||||||
logger:
|
logger:
|
||||||
# level: DEBUG
|
level: DEBUG
|
||||||
# logs:
|
logs:
|
||||||
# switch: NONE
|
switch: NONE
|
||||||
|
|
||||||
switch:
|
switch:
|
||||||
- platform: gpio
|
- platform: gpio
|
||||||
|
Reference in New Issue
Block a user