1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-18 11:12:20 +01:00

remove arduino

This commit is contained in:
Tomasz Duda
2024-02-16 00:09:32 +01:00
parent 50dbb460e2
commit b4f9c84677
7 changed files with 2 additions and 240 deletions

View File

@@ -168,19 +168,7 @@ async def to_code(config):
cg.add_platformio_option("board_upload.wait_for_upload_port", "true") cg.add_platformio_option("board_upload.wait_for_upload_port", "true")
# #
cg.add_platformio_option("extra_scripts", [f"pre:build_{conf[CONF_TYPE]}.py"]) cg.add_platformio_option("extra_scripts", [f"pre:build_{conf[CONF_TYPE]}.py"])
if CORE.using_arduino: if CORE.using_zephyr:
cg.add_build_flag("-DUSE_ARDUINO")
# watchdog
cg.add_build_flag("-DNRFX_WDT_ENABLED=1")
cg.add_build_flag("-DNRFX_WDT0_ENABLED=1")
cg.add_build_flag("-DNRFX_WDT_CONFIG_NO_IRQ=1")
# prevent setting up GPIO PINs
cg.add_platformio_option("board_build.variant", "nrf52840")
cg.add_platformio_option(
"board_build.variants_dir", os.path.dirname(os.path.realpath(__file__))
)
cg.add_library("https://github.com/NordicSemiconductor/nrfx#v2.1.0", None, None)
elif CORE.using_zephyr:
zephyr_to_code(conf) zephyr_to_code(conf)
else: else:
raise NotImplementedError raise NotImplementedError

View File

@@ -1,14 +0,0 @@
import os
Import("env")
def skip_nrfx_from_build(env, node):
if os.path.join("FrameworkArduino", "nordic", "nrfx") in node.path:
return node
if os.path.join("nrfx") in node.path:
if os.path.join("drivers", "src", "nrfx_wdt.c") in node.path:
return node
return None
return node
env.AddBuildMiddleware(skip_nrfx_from_build)

View File

@@ -1,56 +0,0 @@
#ifdef USE_NRF52
#ifdef USE_ARDUINO
#include <Arduino.h>
#include "Adafruit_nRFCrypto.h"
#include "nrfx_wdt.h"
namespace esphome {
void yield() { ::yield(); }
uint32_t millis() { return ::millis(); }
void delay(uint32_t ms) { ::delay(ms); }
uint32_t micros() { return ::micros(); }
struct nrf5x_wdt_obj {
nrfx_wdt_t wdt;
nrfx_wdt_channel_id ch;
};
// TODO what value for watchdog?
static nrfx_wdt_config_t nrf5x_wdt_cfg = NRFX_WDT_DEFAULT_CONFIG;
static struct nrf5x_wdt_obj nrf5x_wdt = {
.wdt = NRFX_WDT_INSTANCE(0),
};
void arch_init() {
// Configure WDT.
nrf5x_wdt_cfg.behaviour = NRF_WDT_BEHAVIOUR_PAUSE_SLEEP_HALT;
nrfx_wdt_init(&nrf5x_wdt.wdt, &nrf5x_wdt_cfg, nullptr);
nrfx_wdt_channel_alloc(&nrf5x_wdt.wdt, &nrf5x_wdt.ch);
nrfx_wdt_enable(&nrf5x_wdt.wdt);
nRFCrypto.begin();
// Init random seed
union seedParts {
uint32_t seed32;
uint8_t seed8[4];
} seed;
nRFCrypto.Random.generate(seed.seed8, sizeof(seed.seed8));
randomSeed(seed.seed32);
}
void arch_feed_wdt() { nrfx_wdt_feed(&nrf5x_wdt.wdt); }
void arch_restart() { NVIC_SystemReset(); }
void nrf52GetMacAddr(uint8_t *mac) {
const uint8_t *src = (const uint8_t *) NRF_FICR->DEVICEADDR;
mac[5] = src[0];
mac[4] = src[1];
mac[3] = src[2];
mac[2] = src[3];
mac[1] = src[4];
mac[0] = src[5] | 0xc0; // MSB high two bits get set elsewhere in the bluetooth stack
}
} // namespace esphome
#endif
#endif // USE_RP2040

View File

@@ -1,38 +1,11 @@
#pragma once #pragma once
#include "esphome/core/hal.h"
#ifdef USE_ZEPHYR
#include "esphome/components/zephyr/gpio.h" #include "esphome/components/zephyr/gpio.h"
#endif
namespace esphome { namespace esphome {
namespace nrf52 { namespace nrf52 {
#ifdef USE_ARDUINO
class NRF52GPIOPin : public InternalGPIOPin {
public:
void set_pin(uint8_t pin) { pin_ = pin; }
void set_inverted(bool inverted) { inverted_ = inverted; }
void set_flags(gpio::Flags flags) { flags_ = flags; }
void setup() override;
void pin_mode(gpio::Flags flags) override;
bool digital_read() override;
void digital_write(bool value) override;
std::string dump_summary() const override;
void detach_interrupt() const override;
ISRInternalGPIOPin to_isr() const override;
uint8_t get_pin() const override { return pin_; }
bool is_inverted() const override { return inverted_; }
protected:
void attach_interrupt(void (*func)(void *), void *arg, gpio::InterruptType type) const override;
uint8_t pin_;
bool inverted_;
gpio::Flags flags_;
};
#else
class NRF52GPIOPin : public zephyr::NRF52GPIOPin {}; class NRF52GPIOPin : public zephyr::NRF52GPIOPin {};
#endif // USE_ARDUINO
} // namespace nrf52 } // namespace nrf52
} // namespace esphome } // namespace esphome

View File

@@ -1,105 +0,0 @@
#ifdef USE_NRF52
#ifdef USE_ARDUINO
#include "gpio.h"
#include "esphome/core/log.h"
#include <functional>
#include <vector>
#include "Arduino.h"
namespace esphome {
namespace nrf52 {
static const char *const TAG = "nrf52";
static int IRAM_ATTR flags_to_mode(gpio::Flags flags, uint8_t pin) {
// For nRF52 extra modes are available.
// Standard drive is typically 2mA (min 1mA) '0' sink (low) or '1' source (high). High drive (VDD > 2.7V) is typically
// 10mA low, 9mA high (min 6mA) OUTPUT_S0S1 Standard '0', standard '1' same as OUTPUT OUTPUT_H0S1 High drive '0',
// standard '1' OUTPUT_S0H1 Standard '0', high drive '1' OUTPUT_H0H1 High drive '0', high 'drive '1'' OUTPUT_D0S1
// Disconnect '0' standard '1' (normally used for wired-or connections) OUTPUT_D0H1 Disconnect '0', high drive '1'
// (normally used for wired-or connections) OUTPUT_S0D1 Standard '0'. disconnect '1' (normally used for wired-and
// connections) OUTPUT_H0D1 High drive '0', disconnect '1' (normally used for wired-and connections) NOTE P0.27 should
// be only low (standard) drive, low frequency
if (flags == gpio::FLAG_INPUT) { // NOLINT(bugprone-branch-clone)
return INPUT;
} else if (flags == gpio::FLAG_OUTPUT) {
return OUTPUT;
} else if (flags == (gpio::FLAG_INPUT | gpio::FLAG_PULLUP)) {
return INPUT_PULLUP;
} else if (flags == (gpio::FLAG_INPUT | gpio::FLAG_PULLDOWN)) {
return INPUT_PULLDOWN;
} else if (flags == (gpio::FLAG_OUTPUT | gpio::FLAG_OPEN_DRAIN)) {
return OUTPUT_S0D1;
} else {
return INPUT;
}
}
struct ISRPinArg {
uint8_t pin;
bool inverted;
};
// TODO implement
// TODO test
void (*irq_cb)(void *);
void *irq_arg;
static void pin_irq(void) { irq_cb(irq_arg); }
ISRInternalGPIOPin NRF52GPIOPin::to_isr() const {
auto *arg = new ISRPinArg{}; // NOLINT(cppcoreguidelines-owning-memory)
arg->pin = pin_;
arg->inverted = inverted_;
return ISRInternalGPIOPin((void *) arg);
}
void NRF52GPIOPin::attach_interrupt(void (*func)(void *), void *arg, gpio::InterruptType type) const {
uint32_t mode = ISR_DEFERRED;
switch (type) {
case gpio::INTERRUPT_RISING_EDGE:
mode |= inverted_ ? FALLING : RISING;
break;
case gpio::INTERRUPT_FALLING_EDGE:
mode |= inverted_ ? RISING : FALLING;
break;
case gpio::INTERRUPT_ANY_EDGE:
mode |= CHANGE;
break;
default:
return;
}
irq_cb = func;
irq_arg = arg;
attachInterrupt(pin_, pin_irq, mode);
}
void NRF52GPIOPin::setup() { pin_mode(flags_); }
void NRF52GPIOPin::pin_mode(gpio::Flags flags) { pinMode(pin_, flags_to_mode(flags, pin_)); }
std::string NRF52GPIOPin::dump_summary() const {
char buffer[32];
snprintf(buffer, sizeof(buffer), "GPIO%u", pin_);
return buffer;
}
bool NRF52GPIOPin::digital_read() { return bool(digitalRead(pin_)) != inverted_; }
void NRF52GPIOPin::digital_write(bool value) { digitalWrite(pin_, value != inverted_ ? 1 : 0); }
void NRF52GPIOPin::detach_interrupt() const { detachInterrupt(pin_); }
} // namespace nrf52
// using namespace nrf52;
// TODO seems to not work???
bool IRAM_ATTR ISRInternalGPIOPin::digital_read() {
auto *arg = reinterpret_cast<nrf52::ISRPinArg *>(arg_);
return bool(digitalRead(arg->pin)) != arg->inverted;
}
} // namespace esphome
#endif
#endif // USE_NRF52

View File

@@ -1,9 +0,0 @@
#include "variant.h"
const uint32_t g_ADigitalPinMap[] = {
// P0
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31,
// P1
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47};

View File

@@ -1,15 +0,0 @@
#pragma once
#include "WVariant.h"
#define PINS_COUNT (48)
#define LED_BUILTIN (64)
#if PINS_COUNT > LED_BUILTIN
#error LED_BUILTIN should be bigger than PINS_COUNT. To ignore settings.
#endif
#define LED_BLUE (LED_BUILTIN)
// TODO other are also needed?
#define USE_LFXO // Board uses 32khz crystal for LF
#define LED_STATE_ON (1)
#define PIN_SERIAL1_RX (33) // P1.01
#define PIN_SERIAL1_TX (34) // P1.02