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