mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	revmoe arduino
This commit is contained in:
		| @@ -1,24 +0,0 @@ | ||||
| import esphome.codegen as cg | ||||
| import esphome.config_validation as cv | ||||
| from esphome.const import ( | ||||
|     CONF_ID, | ||||
| ) | ||||
|  | ||||
| dfu_ns = cg.esphome_ns.namespace("beacon") | ||||
| Beacon = dfu_ns.class_("Beacon", cg.Component) | ||||
|  | ||||
| CONFIG_SCHEMA = cv.All( | ||||
|     cv.Schema( | ||||
|         { | ||||
|             cv.GenerateID(): cv.declare_id(Beacon), | ||||
|         } | ||||
|     ).extend(cv.COMPONENT_SCHEMA), | ||||
|     cv.only_on_nrf52, | ||||
|     # TODO implement | ||||
|     cv.only_with_arduino, | ||||
| ) | ||||
|  | ||||
|  | ||||
| async def to_code(config): | ||||
|     var = cg.new_Pvariable(config[CONF_ID]) | ||||
|     await cg.register_component(var, config) | ||||
| @@ -1,72 +0,0 @@ | ||||
| #include "beacon.h" | ||||
| #include <bluefruit.h> | ||||
|  | ||||
| // Beacon uses the Manufacturer Specific Data field in the advertising packet, | ||||
| // which means you must provide a valid Manufacturer ID. Update | ||||
| // the field below to an appropriate value. For a list of valid IDs see: | ||||
| // https://www.bluetooth.com/specifications/assigned-numbers/company-identifiers | ||||
| // - 0x004C is Apple | ||||
| // - 0x0822 is Adafruit | ||||
| // - 0x0059 is Nordic | ||||
| // For testing with this sketch, you can use nRF Beacon app | ||||
| // - on Android you may need change the MANUFACTURER_ID to Nordic | ||||
| // - on iOS you may need to change the MANUFACTURER_ID to Apple. | ||||
| //   You will also need to "Add Other Beacon, then enter Major, Minor that you set in the sketch | ||||
| #define MANUFACTURER_ID 0x0059 | ||||
|  | ||||
| // "nRF Connect" app can be used to detect beacon | ||||
| const uint8_t BEACON_UUID[16] = {0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, | ||||
|                           0x89, 0x9a, 0xab, 0xbc, 0xcd, 0xde, 0xef, 0xf0}; | ||||
|  | ||||
| // A valid Beacon packet consists of the following information: | ||||
| // UUID, Major, Minor, RSSI @ 1M | ||||
| BLEBeacon ble_beacon(BEACON_UUID, 1, 2, -54); | ||||
|  | ||||
| void start_adv() { | ||||
|   // Advertising packet | ||||
|   // Set the beacon payload using the BLEBeacon class populated | ||||
|   // earlier in this example | ||||
|   Bluefruit.Advertising.setBeacon(ble_beacon); | ||||
|  | ||||
|   // Secondary Scan Response packet (optional) | ||||
|   // Since there is no room for 'Name' in Advertising packet | ||||
|   Bluefruit.ScanResponse.addName(); | ||||
|  | ||||
|   /* Start Advertising | ||||
|    * - Enable auto advertising if disconnected | ||||
|    * - Timeout for fast mode is 30 seconds | ||||
|    * - Start(timeout) with timeout = 0 will advertise forever (until connected) | ||||
|    * | ||||
|    * Apple Beacon specs | ||||
|    * - Type: Non-connectable, scannable, undirected | ||||
|    * - Fixed interval: 100 ms -> fast = slow = 100 ms | ||||
|    */ | ||||
|   Bluefruit.Advertising.setType(BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED); | ||||
|   Bluefruit.Advertising.restartOnDisconnect(true); | ||||
|   Bluefruit.Advertising.setInterval(160, 160);  // in unit of 0.625 ms | ||||
|   Bluefruit.Advertising.setFastTimeout(30);     // number of seconds in fast mode | ||||
|   Bluefruit.Advertising.start(0);               // 0 = Don't stop advertising after n seconds | ||||
| } | ||||
|  | ||||
| namespace esphome { | ||||
| namespace beacon { | ||||
|  | ||||
| void Beacon::loop() {} | ||||
|  | ||||
| void Beacon::setup() { | ||||
|   Bluefruit.begin(); | ||||
|  | ||||
|   // off Blue LED for lowest power consumption | ||||
|   Bluefruit.autoConnLed(false); | ||||
|   Bluefruit.setTxPower(0);  // Check bluefruit.h for supported values | ||||
|   Bluefruit.setName("ESPHome"); | ||||
|  | ||||
|   // Manufacturer ID is required for Manufacturer Specific Data | ||||
|   ble_beacon.setManufacturer(MANUFACTURER_ID); | ||||
|  | ||||
|   // Setup the advertising packet | ||||
|   start_adv(); | ||||
| } | ||||
|  | ||||
| }  // namespace beacon | ||||
| }  // namespace esphome | ||||
| @@ -1,11 +0,0 @@ | ||||
| #pragma once | ||||
| #include "esphome/core/component.h" | ||||
|  | ||||
| namespace esphome { | ||||
| namespace beacon { | ||||
| class Beacon : public Component { | ||||
|   void loop() override; | ||||
|   void setup() override; | ||||
| }; | ||||
| }  // namespace beacon | ||||
| }  // namespace esphome | ||||
| @@ -16,7 +16,6 @@ from esphome.const import ( | ||||
|     CONF_WAKEUP_PIN, | ||||
|     PLATFORM_ESP32, | ||||
|     PLATFORM_ESP8266, | ||||
|     PLATFORM_NRF52, | ||||
| ) | ||||
|  | ||||
| from esphome.components.esp32 import get_esp32_variant | ||||
| @@ -199,7 +198,7 @@ CONFIG_SCHEMA = cv.All( | ||||
|             cv.Optional(CONF_TOUCH_WAKEUP): cv.All(cv.only_on_esp32, cv.boolean), | ||||
|         } | ||||
|     ).extend(cv.COMPONENT_SCHEMA), | ||||
|     cv.only_on([PLATFORM_ESP32, PLATFORM_ESP8266, PLATFORM_NRF52]), | ||||
|     cv.only_on([PLATFORM_ESP32, PLATFORM_ESP8266]), | ||||
| ) | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -1,52 +0,0 @@ | ||||
| #if defined(USE_NRF52) && defined(USE_ARDUINO) | ||||
| #include "deep_sleep_backend_nrf52.h" | ||||
| #include "nrf_power.h" | ||||
| #include <cassert> | ||||
| #include "Adafruit_TinyUSB.h" | ||||
| #include "esphome/core/log.h" | ||||
|  | ||||
| namespace esphome { | ||||
| namespace deep_sleep { | ||||
|  | ||||
| #define DFU_MAGIC_SKIP 0x6d | ||||
|  | ||||
| static const char *const TAG = "deep_sleep.nrf52"; | ||||
|  | ||||
| void Nrf52DeepSleepBackend::begin_sleep(const optional<uint64_t> &sleep_duration) { | ||||
|   // RTC works only during System On | ||||
|   if (sleep_duration.has_value()) { | ||||
|     // TinyUSBDevice.detach(); | ||||
|     // TODO deinit USB | ||||
|     // TOOD and the rest of peripherals | ||||
|     uint32_t start_time = millis(); | ||||
|     portSUPPRESS_TICKS_AND_SLEEP(ms2tick(*sleep_duration / 1000)); | ||||
|     last_sleep_duration_ = millis() - start_time; | ||||
|     // TinyUSBDevice.attach(); | ||||
|   } else { | ||||
|     NRF_POWER->GPREGRET = DFU_MAGIC_SKIP; | ||||
|     // Enter System OFF. | ||||
| #ifdef SOFTDEVICE_PRESENT | ||||
|     uint8_t sd_en = 0; | ||||
|     (void) sd_softdevice_is_enabled(&sd_en); | ||||
|     if (sd_en) { | ||||
|       uint32_t ret_code = sd_power_system_off(); | ||||
|       assert((ret_code == NRF_SUCCESS) || (ret_code == NRF_ERROR_SOFTDEVICE_NOT_ENABLED)); | ||||
|     } | ||||
| #endif  // SOFTDEVICE_PRESENT | ||||
|     nrf_power_system_off(NRF_POWER); | ||||
|     // it should never reach here... | ||||
|   } | ||||
| } | ||||
|  | ||||
| void Nrf52DeepSleepBackend::dump_config() { | ||||
|   if (last_sleep_duration_.has_value()) { | ||||
|     ESP_LOGD(TAG, "Last sleep duration: %lu ms", *last_sleep_duration_); | ||||
|   } else { | ||||
|     ESP_LOGD(TAG, "Last sleep duration: unknown"); | ||||
|   } | ||||
| } | ||||
|  | ||||
| }  // namespace deep_sleep | ||||
| }  // namespace esphome | ||||
|  | ||||
| #endif | ||||
| @@ -1,22 +0,0 @@ | ||||
| #pragma once | ||||
| #if defined(USE_NRF52) && defined(USE_ARDUINO) | ||||
|  | ||||
| #include "esphome/core/optional.h" | ||||
| #include "Arduino.h" | ||||
|  | ||||
| namespace esphome { | ||||
| namespace deep_sleep { | ||||
|  | ||||
| class Nrf52DeepSleepBackend { | ||||
|  public: | ||||
|   void begin_sleep(const optional<uint64_t> &sleep_duration); | ||||
|   void dump_config(); | ||||
|  | ||||
|  protected: | ||||
|   optional<uint32_t> last_sleep_duration_; | ||||
| }; | ||||
|  | ||||
| }  // namespace deep_sleep | ||||
| }  // namespace esphome | ||||
|  | ||||
| #endif | ||||
| @@ -7,10 +7,6 @@ | ||||
| #include <Esp.h> | ||||
| #endif | ||||
|  | ||||
| #ifdef USE_NRF52 | ||||
| #include "deep_sleep_backend_nrf52.h" | ||||
| #endif | ||||
|  | ||||
| namespace esphome { | ||||
| namespace deep_sleep { | ||||
|  | ||||
| @@ -37,8 +33,10 @@ optional<uint32_t> DeepSleepComponent::get_run_duration_() const { | ||||
|   return this->run_duration_; | ||||
| } | ||||
|  | ||||
| void DeepSleepComponent::setup_deep_sleep_() { | ||||
|   this->next_enter_deep_sleep_ = false; | ||||
| void DeepSleepComponent::setup() { | ||||
|   ESP_LOGCONFIG(TAG, "Setting up Deep Sleep..."); | ||||
|   global_has_deep_sleep = true; | ||||
|  | ||||
|   const optional<uint32_t> run_duration = get_run_duration_(); | ||||
|   if (run_duration.has_value()) { | ||||
|     ESP_LOGI(TAG, "Scheduling Deep Sleep to start in %" PRIu32 " ms", *run_duration); | ||||
| @@ -47,14 +45,6 @@ void DeepSleepComponent::setup_deep_sleep_() { | ||||
|     ESP_LOGD(TAG, "Not scheduling Deep Sleep, as no run duration is configured."); | ||||
|   } | ||||
| } | ||||
|  | ||||
| void DeepSleepComponent::setup() { | ||||
|   ESP_LOGCONFIG(TAG, "Setting up Deep Sleep..."); | ||||
|   global_has_deep_sleep = true; | ||||
|  | ||||
|   setup_deep_sleep_(); | ||||
| } | ||||
|  | ||||
| void DeepSleepComponent::dump_config() { | ||||
|   ESP_LOGCONFIG(TAG, "Setting up Deep Sleep..."); | ||||
|   if (this->sleep_duration_.has_value()) { | ||||
| @@ -75,9 +65,6 @@ void DeepSleepComponent::dump_config() { | ||||
|     ESP_LOGCONFIG(TAG, "  GPIO Wakeup Run Duration: %" PRIu32 " ms", this->wakeup_cause_to_run_duration_->gpio_cause); | ||||
|   } | ||||
| #endif | ||||
| #if defined(USE_NRF52) && defined(USE_ARDUINO) | ||||
|   backend_.dump_config(); | ||||
| #endif | ||||
| } | ||||
| void DeepSleepComponent::loop() { | ||||
|   if (this->next_enter_deep_sleep_) | ||||
| @@ -152,7 +139,7 @@ void DeepSleepComponent::begin_sleep(bool manual) { | ||||
|     esp_sleep_enable_touchpad_wakeup(); | ||||
|     esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON); | ||||
|   } | ||||
| #endif  // USE_ESP32_VARIANT_ESP32C3 | ||||
| #endif | ||||
| #ifdef USE_ESP32_VARIANT_ESP32C3 | ||||
|   if (this->sleep_duration_.has_value()) | ||||
|     esp_sleep_enable_timer_wakeup(*this->sleep_duration_); | ||||
| @@ -164,17 +151,13 @@ void DeepSleepComponent::begin_sleep(bool manual) { | ||||
|     esp_deep_sleep_enable_gpio_wakeup(1 << this->wakeup_pin_->get_pin(), | ||||
|                                       static_cast<esp_deepsleep_gpio_wake_up_mode_t>(level)); | ||||
|   } | ||||
| #endif  // USE_ESP32_VARIANT_ESP32C3 | ||||
| #endif | ||||
|   esp_deep_sleep_start(); | ||||
| #endif  // USE_ESP32 | ||||
| #endif | ||||
|  | ||||
| #ifdef USE_ESP8266 | ||||
|   ESP.deepSleep(*this->sleep_duration_);  // NOLINT(readability-static-accessed-through-instance) | ||||
| #endif | ||||
| #if defined(USE_NRF52) && defined(USE_ARDUINO) | ||||
|   backend_.begin_sleep(this->sleep_duration_); | ||||
|   setup_deep_sleep_(); | ||||
| #endif | ||||
| } | ||||
| float DeepSleepComponent::get_setup_priority() const { return setup_priority::LATE; } | ||||
| void DeepSleepComponent::prevent_deep_sleep() { this->prevent_ = true; } | ||||
|   | ||||
| @@ -14,10 +14,6 @@ | ||||
| #include "esphome/core/time.h" | ||||
| #endif | ||||
|  | ||||
| #ifdef USE_NRF52 | ||||
| #include "deep_sleep_backend_nrf52.h" | ||||
| #endif | ||||
|  | ||||
| #include <cinttypes> | ||||
|  | ||||
| namespace esphome { | ||||
| @@ -110,8 +106,6 @@ class DeepSleepComponent : public Component { | ||||
|   // duration before entering deep sleep. | ||||
|   optional<uint32_t> get_run_duration_() const; | ||||
|  | ||||
|   void setup_deep_sleep_(); | ||||
|  | ||||
|   optional<uint64_t> sleep_duration_; | ||||
| #ifdef USE_ESP32 | ||||
|   InternalGPIOPin *wakeup_pin_; | ||||
| @@ -123,9 +117,6 @@ class DeepSleepComponent : public Component { | ||||
|   optional<uint32_t> run_duration_; | ||||
|   bool next_enter_deep_sleep_{false}; | ||||
|   bool prevent_{false}; | ||||
| #if defined(USE_NRF52) && defined(USE_ARDUINO) | ||||
|   Nrf52DeepSleepBackend backend_; | ||||
| #endif | ||||
| }; | ||||
|  | ||||
| extern bool global_has_deep_sleep;  // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user