1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-05 21:02:20 +01:00

fix clang-format

This commit is contained in:
Tomasz Duda
2024-02-03 14:35:32 +01:00
parent 431e89648b
commit 3675a7a83d
23 changed files with 172 additions and 203 deletions

View File

@@ -303,7 +303,7 @@ float ADCSensor::sample() {
// Input range = (0.6 V)/(1/6) = 3.6 V // Input range = (0.6 V)/(1/6) = 3.6 V
uint32_t raw = analogRead(this->pin_->get_pin()); // NOLINT uint32_t raw = analogRead(this->pin_->get_pin()); // NOLINT
if(output_raw_) { if (output_raw_) {
return raw; return raw;
} }
// default 10-bit resolution // default 10-bit resolution

View File

@@ -15,17 +15,14 @@
#define MANUFACTURER_ID 0x0059 #define MANUFACTURER_ID 0x0059
// "nRF Connect" app can be used to detect beacon // "nRF Connect" app can be used to detect beacon
uint8_t beaconUuid[16] = { uint8_t beaconUuid[16] = {0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78,
0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89, 0x9a, 0xab, 0xbc, 0xcd, 0xde, 0xef, 0xf0};
0x89, 0x9a, 0xab, 0xbc, 0xcd, 0xde, 0xef, 0xf0
};
// A valid Beacon packet consists of the following information: // A valid Beacon packet consists of the following information:
// UUID, Major, Minor, RSSI @ 1M // UUID, Major, Minor, RSSI @ 1M
BLEBeacon beacon(beaconUuid, 1, 2, -54); BLEBeacon beacon(beaconUuid, 1, 2, -54);
void startAdv(void) void startAdv(void) {
{
// Advertising packet // Advertising packet
// Set the beacon payload using the BLEBeacon class populated // Set the beacon payload using the BLEBeacon class populated
// earlier in this example // earlier in this example
@@ -54,10 +51,9 @@ void startAdv(void)
namespace esphome { namespace esphome {
namespace ble { namespace ble {
void Beacon::loop() { void Beacon::loop() {}
}
void Beacon::setup(){ void Beacon::setup() {
Bluefruit.begin(); Bluefruit.begin();
// off Blue LED for lowest power consumption // off Blue LED for lowest power consumption
@@ -72,5 +68,5 @@ void Beacon::setup(){
startAdv(); startAdv();
} }
} // namespace dfu } // namespace ble
} // namespace esphome } // namespace esphome

View File

@@ -7,5 +7,5 @@ class Beacon : public Component {
void loop() override; void loop() override;
void setup() override; void setup() override;
}; };
} } // namespace ble
} } // namespace esphome

View File

@@ -54,39 +54,39 @@ static uint32_t get_free_heap() {
#elif defined(USE_LIBRETINY) #elif defined(USE_LIBRETINY)
return lt_heap_get_free(); return lt_heap_get_free();
#elif defined(USE_NRF52) #elif defined(USE_NRF52)
//TODO // TODO
return 0; return 0;
#endif #endif
} }
#if defined(USE_NRF52) && defined(USE_ARDUINO) #if defined(USE_NRF52) && defined(USE_ARDUINO)
static std::string nrf52_get_reset_reason_name(){ static std::string nrf52_get_reset_reason_name() {
uint32_t rr = readResetReason(); uint32_t rr = readResetReason();
if (rr & POWER_RESETREAS_VBUS_Msk){ if (rr & POWER_RESETREAS_VBUS_Msk) {
return "VBUS"; return "VBUS";
} }
if (rr & POWER_RESETREAS_NFC_Msk){ if (rr & POWER_RESETREAS_NFC_Msk) {
return "NFC"; return "NFC";
} }
if (rr & POWER_RESETREAS_DIF_Msk){ if (rr & POWER_RESETREAS_DIF_Msk) {
return "DIF"; return "DIF";
} }
if (rr & POWER_RESETREAS_LPCOMP_Msk){ if (rr & POWER_RESETREAS_LPCOMP_Msk) {
return "LPCOMP"; return "LPCOMP";
} }
if (rr & POWER_RESETREAS_OFF_Msk){ if (rr & POWER_RESETREAS_OFF_Msk) {
return "OFF"; return "OFF";
} }
if (rr & POWER_RESETREAS_LOCKUP_Msk){ if (rr & POWER_RESETREAS_LOCKUP_Msk) {
return "LOCKUP"; return "LOCKUP";
} }
if (rr & POWER_RESETREAS_SREQ_Msk){ if (rr & POWER_RESETREAS_SREQ_Msk) {
return "SREQ"; return "SREQ";
} }
if (rr & POWER_RESETREAS_DOG_Msk){ if (rr & POWER_RESETREAS_DOG_Msk) {
return "DOG"; return "DOG";
} }
if (rr & POWER_RESETREAS_RESETPIN_Msk){ if (rr & POWER_RESETREAS_RESETPIN_Msk) {
return "RESETPIN"; return "RESETPIN";
} }
return "NONE"; return "NONE";
@@ -415,10 +415,13 @@ void DebugComponent::dump_config() {
#endif // USE_LIBRETINY #endif // USE_LIBRETINY
#if defined(USE_NRF52) && defined(USE_ARDUINO) #if defined(USE_NRF52) && defined(USE_ARDUINO)
//TODO fixme // TODO fixme
ESP_LOGD(TAG, "bootloader version %lu.%lu.%lu", (bootloaderVersion >> 16) & 0xFF, (bootloaderVersion >> 8) & 0xFF, bootloaderVersion & 0xFF); ESP_LOGD(TAG, "bootloader version %lu.%lu.%lu", (bootloaderVersion >> 16) & 0xFF, (bootloaderVersion >> 8) & 0xFF,
ESP_LOGD(TAG, "MBR bootloader addr 0x%08lx, UICR bootloader addr 0x%08lx", (*((uint32_t *)MBR_BOOTLOADER_ADDR)), NRF_UICR->NRFFW[0]); bootloaderVersion & 0xFF);
ESP_LOGD(TAG, "MBR param page addr 0x%08lx, UICR param page addr 0x%08lx", (*((uint32_t *) MBR_PARAM_PAGE_ADDR)), NRF_UICR->NRFFW[1]); ESP_LOGD(TAG, "MBR bootloader addr 0x%08lx, UICR bootloader addr 0x%08lx", (*((uint32_t *) MBR_BOOTLOADER_ADDR)),
NRF_UICR->NRFFW[0]);
ESP_LOGD(TAG, "MBR param page addr 0x%08lx, UICR param page addr 0x%08lx", (*((uint32_t *) MBR_PARAM_PAGE_ADDR)),
NRF_UICR->NRFFW[1]);
reset_reason = nrf52_get_reset_reason_name(); reset_reason = nrf52_get_reset_reason_name();
ESP_LOGD(TAG, "Reset Reason: %s", reset_reason.c_str()); ESP_LOGD(TAG, "Reset Reason: %s", reset_reason.c_str());
#endif #endif

View File

@@ -12,15 +12,14 @@ namespace deep_sleep {
static const char *const TAG = "deep_sleep.nrf52"; static const char *const TAG = "deep_sleep.nrf52";
void Nrf52DeepSleepBackend::begin_sleep(const optional<uint64_t>& sleep_duration) { void Nrf52DeepSleepBackend::begin_sleep(const optional<uint64_t> &sleep_duration) {
// RTC works only during System On // RTC works only during System On
if (sleep_duration.has_value()) if (sleep_duration.has_value()) {
{
// TinyUSBDevice.detach(); // TinyUSBDevice.detach();
// TODO deinit USB // TODO deinit USB
// TOOD and the rest of peripherals // TOOD and the rest of peripherals
uint32_t start_time = millis(); uint32_t start_time = millis();
portSUPPRESS_TICKS_AND_SLEEP(ms2tick(*sleep_duration/1000)); portSUPPRESS_TICKS_AND_SLEEP(ms2tick(*sleep_duration / 1000));
last_sleep_duration_ = millis() - start_time; last_sleep_duration_ = millis() - start_time;
// TinyUSBDevice.attach(); // TinyUSBDevice.attach();
} else { } else {
@@ -29,8 +28,7 @@ void Nrf52DeepSleepBackend::begin_sleep(const optional<uint64_t>& sleep_duration
#ifdef SOFTDEVICE_PRESENT #ifdef SOFTDEVICE_PRESENT
uint8_t sd_en = 0; uint8_t sd_en = 0;
(void) sd_softdevice_is_enabled(&sd_en); (void) sd_softdevice_is_enabled(&sd_en);
if (sd_en) if (sd_en) {
{
uint32_t ret_code = sd_power_system_off(); uint32_t ret_code = sd_power_system_off();
assert((ret_code == NRF_SUCCESS) || (ret_code == NRF_ERROR_SOFTDEVICE_NOT_ENABLED)); assert((ret_code == NRF_SUCCESS) || (ret_code == NRF_ERROR_SOFTDEVICE_NOT_ENABLED));
} }
@@ -42,7 +40,7 @@ void Nrf52DeepSleepBackend::begin_sleep(const optional<uint64_t>& sleep_duration
void Nrf52DeepSleepBackend::dump_config() { void Nrf52DeepSleepBackend::dump_config() {
if (last_sleep_duration_.has_value()) { if (last_sleep_duration_.has_value()) {
ESP_LOGD(TAG, "Last sleep duration: %lu ms", *last_sleep_duration_ ); ESP_LOGD(TAG, "Last sleep duration: %lu ms", *last_sleep_duration_);
} else { } else {
ESP_LOGD(TAG, "Last sleep duration: unknown"); ESP_LOGD(TAG, "Last sleep duration: unknown");
} }

View File

@@ -9,8 +9,9 @@ namespace deep_sleep {
class Nrf52DeepSleepBackend { class Nrf52DeepSleepBackend {
public: public:
void begin_sleep(const optional<uint64_t>& sleep_duration); void begin_sleep(const optional<uint64_t> &sleep_duration);
void dump_config(); void dump_config();
protected: protected:
optional<uint32_t> last_sleep_duration_; optional<uint32_t> last_sleep_duration_;
}; };

View File

@@ -37,8 +37,7 @@ optional<uint32_t> DeepSleepComponent::get_run_duration_() const {
return this->run_duration_; return this->run_duration_;
} }
void DeepSleepComponent::setup_deep_sleep_() void DeepSleepComponent::setup_deep_sleep_() {
{
this->next_enter_deep_sleep_ = false; this->next_enter_deep_sleep_ = false;
const optional<uint32_t> run_duration = get_run_duration_(); const optional<uint32_t> run_duration = get_run_duration_();
if (run_duration.has_value()) { if (run_duration.has_value()) {

View File

@@ -23,7 +23,7 @@ uint32_t *dbl_reset_mem = ((uint32_t *) DFU_DBL_RESET_MEM);
const struct device *cdc_dev[] = {DT_FOREACH_STATUS_OKAY(zephyr_cdc_acm_uart, DEVICE_AND_COMMA)}; const struct device *cdc_dev[] = {DT_FOREACH_STATUS_OKAY(zephyr_cdc_acm_uart, DEVICE_AND_COMMA)};
static void cdc_dte_rate_callback(const struct device *, uint32_t rate){ static void cdc_dte_rate_callback(const struct device *, uint32_t rate) {
if (rate == 1200) { if (rate == 1200) {
goto_dfu = true; goto_dfu = true;
} }

View File

@@ -19,5 +19,5 @@ class DeviceFirmwareUpdate : public Component {
output::BinaryOutput *reset_output_; output::BinaryOutput *reset_output_;
#endif #endif
}; };
} } // namespace dfu
} } // namespace esphome

View File

@@ -46,7 +46,8 @@ void Logger::write_header_(int level, const char *tag, int line) {
this->printf_to_buffer_("%s[%s][%s:%03u]: ", color, letter, tag, line); this->printf_to_buffer_("%s[%s][%s:%03u]: ", color, letter, tag, line);
#ifdef USE_ARDUINO #ifdef USE_ARDUINO
} else { } else {
this->printf_to_buffer_("%s[%s][%s:%03u]%s[%s]%s: ", color, letter, tag, line, ESPHOME_LOG_BOLD(ESPHOME_LOG_COLOR_RED), pcTaskGetName(current_task), color); this->printf_to_buffer_("%s[%s][%s:%03u]%s[%s]%s: ", color, letter, tag, line,
ESPHOME_LOG_BOLD(ESPHOME_LOG_COLOR_RED), pcTaskGetName(current_task), color);
} }
#endif #endif
} }
@@ -152,17 +153,17 @@ Logger::Logger(uint32_t baud_rate, size_t tx_buffer_size) : baud_rate_(baud_rate
} }
#ifdef USE_USB_CDC #ifdef USE_USB_CDC
# ifndef USE_ZEPHYR #ifndef USE_ZEPHYR
void Logger::loop() { void Logger::loop() {
#ifdef USE_ARDUINO #ifdef USE_ARDUINO
if (this->uart_ != UART_SELECTION_USB_CDC) { if (this->uart_ != UART_SELECTION_USB_CDC) {
return; return;
} }
static bool opened = false; static bool opened = false;
if (opened == Serial){ if (opened == Serial) {
return; return;
} }
if(false == opened){ if (false == opened) {
App.schedule_dump_config(); App.schedule_dump_config();
} }
opened = !opened; opened = !opened;

View File

@@ -161,7 +161,7 @@ class Logger : public Component {
#elif defined(USE_ESP_IDF) #elif defined(USE_ESP_IDF)
uart_port_t uart_num_; uart_port_t uart_num_;
#elif defined(USE_ZEPHYR) #elif defined(USE_ZEPHYR)
const device * uart_dev_{nullptr}; const device *uart_dev_{nullptr};
#endif #endif
struct LogLevelOverride { struct LogLevelOverride {
std::string tag; std::string tag;

View File

@@ -15,7 +15,6 @@
namespace esphome { namespace esphome {
namespace logger { namespace logger {
static const char *const TAG = "logger"; static const char *const TAG = "logger";
#ifdef USE_ZEPHYR #ifdef USE_ZEPHYR
@@ -28,11 +27,11 @@ void Logger::loop() {
uart_line_ctrl_get(uart_dev_, UART_LINE_CTRL_DTR, &dtr); uart_line_ctrl_get(uart_dev_, UART_LINE_CTRL_DTR, &dtr);
/* Poll if the DTR flag was set, optional */ /* Poll if the DTR flag was set, optional */
if(opened == dtr) { if (opened == dtr) {
return; return;
} }
if(false == opened){ if (false == opened) {
App.schedule_dump_config(); App.schedule_dump_config();
} }
opened = !opened; opened = !opened;
@@ -60,7 +59,7 @@ void Logger::pre_setup() {
break; break;
case UART_SELECTION_USB_CDC: case UART_SELECTION_USB_CDC:
uart_dev = DEVICE_DT_GET_OR_NULL(DT_NODELABEL(cdc_acm_uart0)); uart_dev = DEVICE_DT_GET_OR_NULL(DT_NODELABEL(cdc_acm_uart0));
if(device_is_ready(uart_dev)) { if (device_is_ready(uart_dev)) {
usb_enable(NULL); usb_enable(NULL);
} }
break; break;
@@ -78,10 +77,10 @@ void Logger::pre_setup() {
#ifdef USE_ZEPHYR #ifdef USE_ZEPHYR
void HOT Logger::write_msg_(const char *msg) { void HOT Logger::write_msg_(const char *msg) {
if(nullptr == uart_dev_) { if (nullptr == uart_dev_) {
return; return;
} }
while(*msg) { while (*msg) {
uart_poll_out(uart_dev_, *msg); uart_poll_out(uart_dev_, *msg);
++msg; ++msg;
} }

View File

@@ -10,12 +10,11 @@ uint32_t millis() { return ::millis(); }
void delay(uint32_t ms) { ::delay(ms); } void delay(uint32_t ms) { ::delay(ms); }
uint32_t micros() { return ::micros(); } uint32_t micros() { return ::micros(); }
struct nrf5x_wdt_obj struct nrf5x_wdt_obj {
{
nrfx_wdt_t wdt; nrfx_wdt_t wdt;
nrfx_wdt_channel_id ch; nrfx_wdt_channel_id ch;
}; };
//TODO what value for watchdog? // TODO what value for watchdog?
static nrfx_wdt_config_t nrf5x_wdt_cfg = NRFX_WDT_DEFAULT_CONFIG; static nrfx_wdt_config_t nrf5x_wdt_cfg = NRFX_WDT_DEFAULT_CONFIG;
static struct nrf5x_wdt_obj nrf5x_wdt = { static struct nrf5x_wdt_obj nrf5x_wdt = {
@@ -23,7 +22,7 @@ static struct nrf5x_wdt_obj nrf5x_wdt = {
}; };
void arch_init() { void arch_init() {
//Configure WDT. // Configure WDT.
nrf5x_wdt_cfg.behaviour = NRF_WDT_BEHAVIOUR_PAUSE_SLEEP_HALT; nrf5x_wdt_cfg.behaviour = NRF_WDT_BEHAVIOUR_PAUSE_SLEEP_HALT;
nrfx_wdt_init(&nrf5x_wdt.wdt, &nrf5x_wdt_cfg, nullptr); nrfx_wdt_init(&nrf5x_wdt.wdt, &nrf5x_wdt_cfg, nullptr);
nrfx_wdt_channel_alloc(&nrf5x_wdt.wdt, &nrf5x_wdt.ch); nrfx_wdt_channel_alloc(&nrf5x_wdt.wdt, &nrf5x_wdt.ch);
@@ -37,19 +36,13 @@ void arch_init() {
} seed; } seed;
nRFCrypto.Random.generate(seed.seed8, sizeof(seed.seed8)); nRFCrypto.Random.generate(seed.seed8, sizeof(seed.seed8));
randomSeed(seed.seed32); randomSeed(seed.seed32);
}
void arch_feed_wdt() {
nrfx_wdt_feed(&nrf5x_wdt.wdt);
} }
void arch_feed_wdt() { nrfx_wdt_feed(&nrf5x_wdt.wdt); }
void arch_restart() { void arch_restart() { NVIC_SystemReset(); }
NVIC_SystemReset();
}
void nrf52GetMacAddr(uint8_t *mac) void nrf52GetMacAddr(uint8_t *mac) {
{ const uint8_t *src = (const uint8_t *) NRF_FICR->DEVICEADDR;
const uint8_t *src = (const uint8_t *)NRF_FICR->DEVICEADDR;
mac[5] = src[0]; mac[5] = src[0];
mac[4] = src[1]; mac[4] = src[1];
mac[3] = src[2]; mac[3] = src[2];

View File

@@ -21,9 +21,8 @@ void arch_restart() {
// TODO // TODO
} }
void nrf52GetMacAddr(uint8_t *mac) void nrf52GetMacAddr(uint8_t *mac) {
{ const uint8_t *src = (const uint8_t *) NRF_FICR->DEVICEADDR;
const uint8_t *src = (const uint8_t *)NRF_FICR->DEVICEADDR;
mac[5] = src[0]; mac[5] = src[0];
mac[4] = src[1]; mac[4] = src[1];
mac[3] = src[2]; mac[3] = src[2];
@@ -37,9 +36,9 @@ void nrf52GetMacAddr(uint8_t *mac)
void setup(); void setup();
void loop(); void loop();
int main(){ int main() {
setup(); setup();
while(1) { while (1) {
loop(); loop();
esphome::yield(); esphome::yield();
} }

View File

@@ -30,7 +30,7 @@ class NRF52GPIOPin : public InternalGPIOPin {
bool inverted_; bool inverted_;
gpio::Flags flags_; gpio::Flags flags_;
#ifdef USE_ZEPHYR #ifdef USE_ZEPHYR
const device * gpio_ = nullptr; const device *gpio_ = nullptr;
bool value_ = false; bool value_ = false;
#endif #endif
}; };

View File

@@ -13,17 +13,14 @@ namespace nrf52 {
static const char *const TAG = "nrf52"; static const char *const TAG = "nrf52";
static int IRAM_ATTR flags_to_mode(gpio::Flags flags, uint8_t pin) { static int IRAM_ATTR flags_to_mode(gpio::Flags flags, uint8_t pin) {
// For nRF52 extra modes are available. // 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) // Standard drive is typically 2mA (min 1mA) '0' sink (low) or '1' source (high). High drive (VDD > 2.7V) is typically
// OUTPUT_S0S1 Standard '0', standard '1' same as OUTPUT // 10mA low, 9mA high (min 6mA) OUTPUT_S0S1 Standard '0', standard '1' same as OUTPUT OUTPUT_H0S1 High drive '0',
// OUTPUT_H0S1 High drive '0', standard '1' // standard '1' OUTPUT_S0H1 Standard '0', high drive '1' OUTPUT_H0H1 High drive '0', high 'drive '1'' OUTPUT_D0S1
// OUTPUT_S0H1 Standard '0', high drive '1' // Disconnect '0' standard '1' (normally used for wired-or connections) OUTPUT_D0H1 Disconnect '0', high drive '1'
// OUTPUT_H0H1 High drive '0', high 'drive '1'' // (normally used for wired-or connections) OUTPUT_S0D1 Standard '0'. disconnect '1' (normally used for wired-and
// OUTPUT_D0S1 Disconnect '0' standard '1' (normally used for wired-or connections) // connections) OUTPUT_H0D1 High drive '0', disconnect '1' (normally used for wired-and connections) NOTE P0.27 should
// OUTPUT_D0H1 Disconnect '0', high drive '1' (normally used for wired-or connections) // be only low (standard) drive, low frequency
// 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) if (flags == gpio::FLAG_INPUT) { // NOLINT(bugprone-branch-clone)
return INPUT; return INPUT;
} else if (flags == gpio::FLAG_OUTPUT) { } else if (flags == gpio::FLAG_OUTPUT) {
@@ -44,13 +41,11 @@ struct ISRPinArg {
bool inverted; bool inverted;
}; };
//TODO implement // TODO implement
//TODO test // TODO test
void (*irq_cb)(void *); void (*irq_cb)(void *);
void* irq_arg; void *irq_arg;
static void pin_irq(void){ static void pin_irq(void) { irq_cb(irq_arg); }
irq_cb(irq_arg);
}
ISRInternalGPIOPin NRF52GPIOPin::to_isr() const { ISRInternalGPIOPin NRF52GPIOPin::to_isr() const {
auto *arg = new ISRPinArg{}; // NOLINT(cppcoreguidelines-owning-memory) auto *arg = new ISRPinArg{}; // NOLINT(cppcoreguidelines-owning-memory)
@@ -82,9 +77,7 @@ void NRF52GPIOPin::attach_interrupt(void (*func)(void *), void *arg, gpio::Inter
void NRF52GPIOPin::setup() { pin_mode(flags_); } void NRF52GPIOPin::setup() { pin_mode(flags_); }
void NRF52GPIOPin::pin_mode(gpio::Flags flags) { void NRF52GPIOPin::pin_mode(gpio::Flags flags) { pinMode(pin_, flags_to_mode(flags, pin_)); }
pinMode(pin_, flags_to_mode(flags, pin_));
}
std::string NRF52GPIOPin::dump_summary() const { std::string NRF52GPIOPin::dump_summary() const {
char buffer[32]; char buffer[32];
@@ -92,15 +85,9 @@ std::string NRF52GPIOPin::dump_summary() const {
return buffer; return buffer;
} }
bool NRF52GPIOPin::digital_read() { bool NRF52GPIOPin::digital_read() { return bool(digitalRead(pin_)) != inverted_; }
return bool(digitalRead(pin_)) != inverted_; void NRF52GPIOPin::digital_write(bool value) { digitalWrite(pin_, value != inverted_ ? 1 : 0); }
} void NRF52GPIOPin::detach_interrupt() const { detachInterrupt(pin_); }
void NRF52GPIOPin::digital_write(bool value) {
digitalWrite(pin_, value != inverted_ ? 1 : 0);
}
void NRF52GPIOPin::detach_interrupt() const {
detachInterrupt(pin_);
}
} // namespace nrf52 } // namespace nrf52

View File

@@ -16,7 +16,7 @@ static int flags_to_mode(gpio::Flags flags, uint8_t pin, bool inverted, bool val
} }
if (flags & gpio::FLAG_OUTPUT) { if (flags & gpio::FLAG_OUTPUT) {
ret |= GPIO_OUTPUT; ret |= GPIO_OUTPUT;
if(value != inverted){ if (value != inverted) {
ret |= GPIO_OUTPUT_INIT_HIGH; ret |= GPIO_OUTPUT_INIT_HIGH;
} else { } else {
ret |= GPIO_OUTPUT_INIT_LOW; ret |= GPIO_OUTPUT_INIT_LOW;
@@ -51,8 +51,8 @@ void NRF52GPIOPin::attach_interrupt(void (*func)(void *), void *arg, gpio::Inter
} }
void NRF52GPIOPin::setup() { void NRF52GPIOPin::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)
#if DT_NODE_HAS_STATUS(GPIO0, okay) #if DT_NODE_HAS_STATUS(GPIO0, okay)
gpio = DEVICE_DT_GET(GPIO0); gpio = DEVICE_DT_GET(GPIO0);
@@ -77,7 +77,7 @@ void NRF52GPIOPin::setup() {
} }
void NRF52GPIOPin::pin_mode(gpio::Flags flags) { void NRF52GPIOPin::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_));
@@ -90,7 +90,7 @@ std::string NRF52GPIOPin::dump_summary() const {
} }
bool NRF52GPIOPin::digital_read() { bool NRF52GPIOPin::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_);
@@ -100,10 +100,10 @@ void NRF52GPIOPin::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;
if(nullptr == gpio_) { if (nullptr == gpio_) {
return; return;
} }
gpio_pin_set(gpio_, pin_, value != inverted_ ? 1 : 0 ); gpio_pin_set(gpio_, pin_, value != inverted_ ? 1 : 0);
} }
void NRF52GPIOPin::detach_interrupt() const { void NRF52GPIOPin::detach_interrupt() const {
// TODO // TODO

View File

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

View File

@@ -13,4 +13,3 @@
#define LED_STATE_ON (1) #define LED_STATE_ON (1)
#define PIN_SERIAL1_RX (33) // P1.01 #define PIN_SERIAL1_RX (33) // P1.01
#define PIN_SERIAL1_TX (34) // P1.02 #define PIN_SERIAL1_TX (34) // P1.02

View File

@@ -12,12 +12,12 @@ class NRF52Preferences : public ESPPreferences {
} }
ESPPreferenceObject make_preference(size_t length, uint32_t type) override { ESPPreferenceObject make_preference(size_t length, uint32_t type) override {
//TODO // TODO
return {}; return {};
} }
bool sync() override { bool sync() override {
//TODO // TODO
return true; return true;
} }
@@ -26,15 +26,15 @@ class NRF52Preferences : public ESPPreferences {
return true; return true;
} }
// protected: // protected:
// uint8_t *eeprom_sector_; // uint8_t *eeprom_sector_;
}; };
void setup_preferences() { void setup_preferences() {
auto *prefs = new NRF52Preferences(); // NOLINT(cppcoreguidelines-owning-memory) auto *prefs = new NRF52Preferences(); // NOLINT(cppcoreguidelines-owning-memory)
global_preferences = prefs; global_preferences = prefs;
} }
//TODO // TODO
// void preferences_prevent_write(bool prevent) { s_prevent_write = prevent; } // void preferences_prevent_write(bool prevent) { s_prevent_write = prevent; }
} // namespace nrf52 } // namespace nrf52

View File

@@ -6,7 +6,7 @@ namespace esphome {
namespace nrf52 { namespace nrf52 {
void setup_preferences(); void setup_preferences();
//TODO // TODO
// void preferences_prevent_write(bool prevent); // void preferences_prevent_write(bool prevent);
} // namespace nrf52 } // namespace nrf52

View File

@@ -252,7 +252,7 @@ bool random_bytes(uint8_t *data, size_t len) {
#ifdef USE_ARDUINO #ifdef USE_ARDUINO
return nRFCrypto.Random.generate(data, len); return nRFCrypto.Random.generate(data, len);
#elif USE_ZEPHYR #elif USE_ZEPHYR
//TODO // TODO
#endif #endif
#else #else
#error "No random source available for this configuration." #error "No random source available for this configuration."
@@ -531,7 +531,7 @@ Mutex::Mutex() {}
void Mutex::lock() {} void Mutex::lock() {}
bool Mutex::try_lock() { return true; } bool Mutex::try_lock() { return true; }
void Mutex::unlock() {} void Mutex::unlock() {}
//TODO // TODO
#elif defined(USE_ESP32) || defined(USE_LIBRETINY) /*|| defined(USE_NRF52)*/ #elif defined(USE_ESP32) || defined(USE_LIBRETINY) /*|| defined(USE_NRF52)*/
Mutex::Mutex() { handle_ = xSemaphoreCreateMutex(); } Mutex::Mutex() { handle_ = xSemaphoreCreateMutex(); }
void Mutex::lock() { xSemaphoreTake(this->handle_, portMAX_DELAY); } void Mutex::lock() { xSemaphoreTake(this->handle_, portMAX_DELAY); }

View File

@@ -551,7 +551,7 @@ class Mutex {
Mutex &operator=(const Mutex &) = delete; Mutex &operator=(const Mutex &) = delete;
private: private:
//TODO // TODO
#if defined(USE_ESP32) || defined(USE_LIBRETINY) /*|| defined(USE_NRF52)*/ #if defined(USE_ESP32) || defined(USE_LIBRETINY) /*|| defined(USE_NRF52)*/
SemaphoreHandle_t handle_; SemaphoreHandle_t handle_;
#endif #endif