1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-06 05:12:21 +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

@@ -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,8 +51,7 @@ 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();
@@ -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

@@ -416,9 +416,12 @@ void DebugComponent::dump_config() {
#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

@@ -14,8 +14,7 @@ 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
@@ -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));
} }

View File

@@ -11,6 +11,7 @@ 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

@@ -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
} }

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

View File

@@ -10,8 +10,7 @@ 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;
}; };
@@ -37,18 +36,12 @@ 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];

View File

@@ -21,8 +21,7 @@ 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];

View File

@@ -14,16 +14,13 @@ 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) {
@@ -48,9 +45,7 @@ struct ISRPinArg {
// 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

@@ -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