mirror of
https://github.com/esphome/esphome.git
synced 2025-09-05 21:02:20 +01:00
move some files around
This commit is contained in:
@@ -145,12 +145,9 @@ CONFIG_SCHEMA = cv.All(
|
|||||||
_detect_bootloader,
|
_detect_bootloader,
|
||||||
)
|
)
|
||||||
|
|
||||||
nrf52_ns = cg.esphome_ns.namespace("nrf52")
|
|
||||||
|
|
||||||
|
|
||||||
@coroutine_with_priority(1000)
|
@coroutine_with_priority(1000)
|
||||||
async def to_code(config):
|
async def to_code(config):
|
||||||
cg.add(nrf52_ns.setup_preferences())
|
|
||||||
cg.add_platformio_option("board", config[CONF_BOARD])
|
cg.add_platformio_option("board", config[CONF_BOARD])
|
||||||
cg.add_build_flag("-DUSE_NRF52")
|
cg.add_build_flag("-DUSE_NRF52")
|
||||||
cg.add_define("ESPHOME_BOARD", config[CONF_BOARD])
|
cg.add_define("ESPHOME_BOARD", config[CONF_BOARD])
|
||||||
|
@@ -1,8 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
namespace esphome {
|
|
||||||
|
|
||||||
void nrf52GetMacAddr(uint8_t *mac);
|
|
||||||
|
|
||||||
}
|
|
@@ -1,11 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "esphome/components/zephyr/gpio.h"
|
|
||||||
|
|
||||||
namespace esphome {
|
|
||||||
namespace nrf52 {
|
|
||||||
|
|
||||||
class NRF52GPIOPin : public zephyr::NRF52GPIOPin {};
|
|
||||||
|
|
||||||
} // namespace nrf52
|
|
||||||
} // namespace esphome
|
|
@@ -8,9 +8,11 @@ from esphome.const import (
|
|||||||
CONF_INVERTED,
|
CONF_INVERTED,
|
||||||
CONF_NUMBER,
|
CONF_NUMBER,
|
||||||
)
|
)
|
||||||
|
from esphome.components.zephyr.const import (
|
||||||
|
zephyr_ns,
|
||||||
|
)
|
||||||
|
|
||||||
nrf52_ns = cg.esphome_ns.namespace("nrf52")
|
GPIOPin = zephyr_ns.class_("GPIOPin", cg.InternalGPIOPin)
|
||||||
NRF52GPIOPin = nrf52_ns.class_("NRF52GPIOPin", cg.InternalGPIOPin)
|
|
||||||
|
|
||||||
|
|
||||||
def _translate_pin(value):
|
def _translate_pin(value):
|
||||||
@@ -41,9 +43,7 @@ def validate_gpio_pin(value):
|
|||||||
|
|
||||||
|
|
||||||
NRF52_PIN_SCHEMA = cv.All(
|
NRF52_PIN_SCHEMA = cv.All(
|
||||||
pins.gpio_base_schema(
|
pins.gpio_base_schema(GPIOPin, validate_gpio_pin, modes=pins.GPIO_STANDARD_MODES),
|
||||||
NRF52GPIOPin, validate_gpio_pin, modes=pins.GPIO_STANDARD_MODES
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -10,6 +10,7 @@ from .const import (
|
|||||||
KEY_ZEPHYR,
|
KEY_ZEPHYR,
|
||||||
KEY_PRJ_CONF,
|
KEY_PRJ_CONF,
|
||||||
KEY_OVERLAY,
|
KEY_OVERLAY,
|
||||||
|
zephyr_ns,
|
||||||
)
|
)
|
||||||
from esphome.const import (
|
from esphome.const import (
|
||||||
CONF_VARIANT,
|
CONF_VARIANT,
|
||||||
@@ -48,6 +49,7 @@ def zephyr_add_overlay(content):
|
|||||||
|
|
||||||
|
|
||||||
def zephyr_to_code(conf):
|
def zephyr_to_code(conf):
|
||||||
|
cg.add(zephyr_ns.setup_preferences())
|
||||||
cg.add_build_flag("-DUSE_ZEPHYR")
|
cg.add_build_flag("-DUSE_ZEPHYR")
|
||||||
if conf[CONF_VARIANT] == ZEPHYR_VARIANT_GENERIC:
|
if conf[CONF_VARIANT] == ZEPHYR_VARIANT_GENERIC:
|
||||||
cg.add_platformio_option(
|
cg.add_platformio_option(
|
||||||
|
@@ -1,5 +1,9 @@
|
|||||||
|
import esphome.codegen as cg
|
||||||
|
|
||||||
ZEPHYR_VARIANT_GENERIC = "generic"
|
ZEPHYR_VARIANT_GENERIC = "generic"
|
||||||
ZEPHYR_VARIANT_NRF_SDK = "nrf-sdk"
|
ZEPHYR_VARIANT_NRF_SDK = "nrf-sdk"
|
||||||
KEY_ZEPHYR = "zephyr"
|
KEY_ZEPHYR = "zephyr"
|
||||||
KEY_PRJ_CONF = "prj_conf"
|
KEY_PRJ_CONF = "prj_conf"
|
||||||
KEY_OVERLAY = "overlay"
|
KEY_OVERLAY = "overlay"
|
||||||
|
|
||||||
|
zephyr_ns = cg.esphome_ns.namespace("zephyr")
|
||||||
|
@@ -38,18 +38,18 @@ struct ISRPinArg {
|
|||||||
bool inverted;
|
bool inverted;
|
||||||
};
|
};
|
||||||
|
|
||||||
ISRInternalGPIOPin NRF52GPIOPin::to_isr() const {
|
ISRInternalGPIOPin GPIOPin::to_isr() const {
|
||||||
auto *arg = new ISRPinArg{};
|
auto *arg = new ISRPinArg{};
|
||||||
arg->pin = pin_;
|
arg->pin = pin_;
|
||||||
arg->inverted = inverted_;
|
arg->inverted = inverted_;
|
||||||
return ISRInternalGPIOPin((void *) arg);
|
return ISRInternalGPIOPin((void *) arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NRF52GPIOPin::attach_interrupt(void (*func)(void *), void *arg, gpio::InterruptType type) const {
|
void GPIOPin::attach_interrupt(void (*func)(void *), void *arg, gpio::InterruptType type) const {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
void NRF52GPIOPin::setup() {
|
void GPIOPin::setup() {
|
||||||
const struct device *gpio = nullptr;
|
const struct device *gpio = nullptr;
|
||||||
if (pin_ < 32) {
|
if (pin_ < 32) {
|
||||||
#define GPIO0 DT_NODELABEL(gpio0)
|
#define GPIO0 DT_NODELABEL(gpio0)
|
||||||
@@ -75,27 +75,27 @@ void NRF52GPIOPin::setup() {
|
|||||||
pin_mode(flags_);
|
pin_mode(flags_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NRF52GPIOPin::pin_mode(gpio::Flags flags) {
|
void GPIOPin::pin_mode(gpio::Flags flags) {
|
||||||
if (nullptr == gpio_) {
|
if (nullptr == gpio_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
gpio_pin_configure(gpio_, pin_, flags_to_mode(flags, pin_, inverted_, value_));
|
gpio_pin_configure(gpio_, pin_, flags_to_mode(flags, pin_, inverted_, value_));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string NRF52GPIOPin::dump_summary() const {
|
std::string GPIOPin::dump_summary() const {
|
||||||
char buffer[32];
|
char buffer[32];
|
||||||
snprintf(buffer, sizeof(buffer), "GPIO%u", pin_);
|
snprintf(buffer, sizeof(buffer), "GPIO%u", pin_);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NRF52GPIOPin::digital_read() {
|
bool GPIOPin::digital_read() {
|
||||||
if (nullptr == gpio_) {
|
if (nullptr == gpio_) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return bool(gpio_pin_get(gpio_, pin_) != inverted_);
|
return bool(gpio_pin_get(gpio_, pin_) != inverted_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NRF52GPIOPin::digital_write(bool value) {
|
void GPIOPin::digital_write(bool value) {
|
||||||
// make sure that value is not ignored since it can be inverted e.g. on switch side
|
// make sure that value is not ignored since it can be inverted e.g. on switch side
|
||||||
// that way init state should be correct
|
// that way init state should be correct
|
||||||
value_ = value;
|
value_ = value;
|
||||||
@@ -104,7 +104,7 @@ void NRF52GPIOPin::digital_write(bool value) {
|
|||||||
}
|
}
|
||||||
gpio_pin_set(gpio_, pin_, value != inverted_ ? 1 : 0);
|
gpio_pin_set(gpio_, pin_, value != inverted_ ? 1 : 0);
|
||||||
}
|
}
|
||||||
void NRF52GPIOPin::detach_interrupt() const {
|
void GPIOPin::detach_interrupt() const {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -6,7 +6,7 @@ struct device;
|
|||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace zephyr {
|
namespace zephyr {
|
||||||
|
|
||||||
class NRF52GPIOPin : public InternalGPIOPin {
|
class GPIOPin : public InternalGPIOPin {
|
||||||
public:
|
public:
|
||||||
void set_pin(uint8_t pin) { pin_ = pin; }
|
void set_pin(uint8_t pin) { pin_ = pin; }
|
||||||
void set_inverted(bool inverted) { inverted_ = inverted; }
|
void set_inverted(bool inverted) { inverted_ = inverted; }
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
#ifdef USE_NRF52
|
#ifdef USE_ZEPHYR
|
||||||
|
|
||||||
#include "esphome/core/preferences.h"
|
#include "esphome/core/preferences.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace nrf52 {
|
namespace zephyr {
|
||||||
|
|
||||||
class NRF52Preferences : public ESPPreferences {
|
class Preferences : public ESPPreferences {
|
||||||
public:
|
public:
|
||||||
ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash) override {
|
ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash) override {
|
||||||
return make_preference(length, type);
|
return make_preference(length, type);
|
||||||
@@ -31,7 +31,7 @@ class NRF52Preferences : public ESPPreferences {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void setup_preferences() {
|
void setup_preferences() {
|
||||||
auto *prefs = new NRF52Preferences(); // NOLINT(cppcoreguidelines-owning-memory)
|
auto *prefs = new Preferences(); // NOLINT(cppcoreguidelines-owning-memory)
|
||||||
global_preferences = prefs;
|
global_preferences = prefs;
|
||||||
}
|
}
|
||||||
// TODO
|
// TODO
|
@@ -1,15 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifdef USE_NRF52
|
#ifdef USE_ZEPHYR
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace nrf52 {
|
namespace zephyr {
|
||||||
|
|
||||||
void setup_preferences();
|
void setup_preferences();
|
||||||
// TODO
|
// TODO
|
||||||
// void preferences_prevent_write(bool prevent);
|
// void preferences_prevent_write(bool prevent);
|
||||||
|
|
||||||
} // namespace nrf52
|
} // namespace zephyr
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
|
||||||
#endif // USE_RP2040
|
#endif // USE_RP2040
|
@@ -48,12 +48,6 @@
|
|||||||
#include <WiFi.h> // for macAddress()
|
#include <WiFi.h> // for macAddress()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_NRF52
|
|
||||||
#ifdef USE_ARDUINO
|
|
||||||
#include "Adafruit_nRFCrypto.h"
|
|
||||||
#endif
|
|
||||||
#include "esphome/components/nrf52/core.h"
|
|
||||||
#endif
|
|
||||||
#ifdef USE_ZEPHYR
|
#ifdef USE_ZEPHYR
|
||||||
#include <zephyr/random/rand32.h>
|
#include <zephyr/random/rand32.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -212,7 +206,7 @@ uint32_t random_uint32() {
|
|||||||
std::mt19937 rng(dev());
|
std::mt19937 rng(dev());
|
||||||
std::uniform_int_distribution<uint32_t> dist(0, std::numeric_limits<uint32_t>::max());
|
std::uniform_int_distribution<uint32_t> dist(0, std::numeric_limits<uint32_t>::max());
|
||||||
return dist(rng);
|
return dist(rng);
|
||||||
#elif defined(USE_NRF52)
|
#elif defined(USE_ZEPHYR)
|
||||||
return rand();
|
return rand();
|
||||||
#else
|
#else
|
||||||
#error "No random source available for this configuration."
|
#error "No random source available for this configuration."
|
||||||
@@ -251,8 +245,6 @@ bool random_bytes(uint8_t *data, size_t len) {
|
|||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return true;
|
return true;
|
||||||
#elif defined(USE_NRF52) && defined(USE_ARDUINO)
|
|
||||||
return nRFCrypto.Random.generate(data, len);
|
|
||||||
#elif defined(USE_ZEPHYR)
|
#elif defined(USE_ZEPHYR)
|
||||||
sys_rand_get(data, len);
|
sys_rand_get(data, len);
|
||||||
return true;
|
return true;
|
||||||
@@ -538,7 +530,7 @@ Mutex::Mutex() { k_mutex_init(&handle_); }
|
|||||||
void Mutex::lock() { k_mutex_lock(&this->handle_, K_FOREVER); }
|
void Mutex::lock() { k_mutex_lock(&this->handle_, K_FOREVER); }
|
||||||
bool Mutex::try_lock() { return k_mutex_lock(&this->handle_, K_NO_WAIT) == 0; }
|
bool Mutex::try_lock() { return k_mutex_lock(&this->handle_, K_NO_WAIT) == 0; }
|
||||||
void Mutex::unlock() { k_mutex_unlock(&this->handle_); }
|
void Mutex::unlock() { k_mutex_unlock(&this->handle_); }
|
||||||
#elif defined(USE_ESP32) || defined(USE_LIBRETINY) || defined(USE_NRF52)
|
#elif defined(USE_ESP32) || defined(USE_LIBRETINY)
|
||||||
Mutex::Mutex() { handle_ = xSemaphoreCreateMutex(); }
|
Mutex::Mutex() { handle_ = xSemaphoreCreateMutex(); }
|
||||||
void Mutex::lock() { xSemaphoreTake(this->handle_, portMAX_DELAY); }
|
void Mutex::lock() { xSemaphoreTake(this->handle_, portMAX_DELAY); }
|
||||||
bool Mutex::try_lock() { return xSemaphoreTake(this->handle_, 0) == pdTRUE; }
|
bool Mutex::try_lock() { return xSemaphoreTake(this->handle_, 0) == pdTRUE; }
|
||||||
@@ -592,8 +584,6 @@ void get_mac_address_raw(uint8_t *mac) { // NOLINT(readability-non-const-parame
|
|||||||
WiFi.macAddress(mac);
|
WiFi.macAddress(mac);
|
||||||
#elif defined(USE_LIBRETINY)
|
#elif defined(USE_LIBRETINY)
|
||||||
WiFi.macAddress(mac);
|
WiFi.macAddress(mac);
|
||||||
#elif defined(USE_NRF52)
|
|
||||||
nrf52GetMacAddr(mac);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
std::string get_mac_address() {
|
std::string get_mac_address() {
|
||||||
|
@@ -21,8 +21,6 @@
|
|||||||
#elif defined(USE_LIBRETINY)
|
#elif defined(USE_LIBRETINY)
|
||||||
#include <FreeRTOS.h>
|
#include <FreeRTOS.h>
|
||||||
#include <semphr.h>
|
#include <semphr.h>
|
||||||
#elif defined(USE_NRF52) && defined(USE_ARDUINO)
|
|
||||||
#include <Arduino.h>
|
|
||||||
#elif defined(USE_ZEPHYR)
|
#elif defined(USE_ZEPHYR)
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -553,7 +551,7 @@ class Mutex {
|
|||||||
private:
|
private:
|
||||||
#if defined(USE_ZEPHYR)
|
#if defined(USE_ZEPHYR)
|
||||||
k_mutex handle_;
|
k_mutex handle_;
|
||||||
#elif defined(USE_ESP32) || defined(USE_LIBRETINY) || defined(USE_NRF52)
|
#elif defined(USE_ESP32) || defined(USE_LIBRETINY)
|
||||||
SemaphoreHandle_t handle_;
|
SemaphoreHandle_t handle_;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user