diff --git a/esphome/components/adc/adc_sensor.cpp b/esphome/components/adc/adc_sensor.cpp index 23b95a42f9..7394237a06 100644 --- a/esphome/components/adc/adc_sensor.cpp +++ b/esphome/components/adc/adc_sensor.cpp @@ -302,8 +302,8 @@ float ADCSensor::sample() { // With internal reference, single-ended input (grounded negative input) and a gain of 1/6, the input range will be: // Input range = (0.6 V)/(1/6) = 3.6 V - uint32_t raw = analogRead(this->pin_->get_pin()); // NOLINT - if(output_raw_) { + uint32_t raw = analogRead(this->pin_->get_pin()); // NOLINT + if (output_raw_) { return raw; } // default 10-bit resolution diff --git a/esphome/components/beacon/beacon.cpp b/esphome/components/beacon/beacon.cpp index 661f814d05..a629d7676e 100644 --- a/esphome/components/beacon/beacon.cpp +++ b/esphome/components/beacon/beacon.cpp @@ -12,20 +12,17 @@ // - 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 +#define MANUFACTURER_ID 0x0059 // "nRF Connect" app can be used to detect beacon -uint8_t beaconUuid[16] = { - 0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, - 0x89, 0x9a, 0xab, 0xbc, 0xcd, 0xde, 0xef, 0xf0 -}; +uint8_t beaconUuid[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 beacon(beaconUuid, 1, 2, -54); -void startAdv(void) -{ +void startAdv(void) { // Advertising packet // Set the beacon payload using the BLEBeacon class populated // earlier in this example @@ -34,35 +31,34 @@ void startAdv(void) // 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 + 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 ble { -void Beacon::loop() { -} +void Beacon::loop() {} -void Beacon::setup(){ - Bluefruit.begin(); +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.setTxPower(0); // Check bluefruit.h for supported values Bluefruit.setName("ESPHome"); // Manufacturer ID is required for Manufacturer Specific Data @@ -72,5 +68,5 @@ void Beacon::setup(){ startAdv(); } -} // namespace dfu +} // namespace ble } // namespace esphome diff --git a/esphome/components/beacon/beacon.h b/esphome/components/beacon/beacon.h index 03ae27f697..32597807f6 100644 --- a/esphome/components/beacon/beacon.h +++ b/esphome/components/beacon/beacon.h @@ -4,8 +4,8 @@ namespace esphome { namespace ble { class Beacon : public Component { - void loop() override; - void setup() override; + void loop() override; + void setup() override; }; -} -} +} // namespace ble +} // namespace esphome diff --git a/esphome/components/debug/debug_component.cpp b/esphome/components/debug/debug_component.cpp index 52885dfd11..15691fc66b 100644 --- a/esphome/components/debug/debug_component.cpp +++ b/esphome/components/debug/debug_component.cpp @@ -54,39 +54,39 @@ static uint32_t get_free_heap() { #elif defined(USE_LIBRETINY) return lt_heap_get_free(); #elif defined(USE_NRF52) - //TODO + // TODO return 0; #endif } #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(); - if (rr & POWER_RESETREAS_VBUS_Msk){ + if (rr & POWER_RESETREAS_VBUS_Msk) { return "VBUS"; } - if (rr & POWER_RESETREAS_NFC_Msk){ + if (rr & POWER_RESETREAS_NFC_Msk) { return "NFC"; } - if (rr & POWER_RESETREAS_DIF_Msk){ + if (rr & POWER_RESETREAS_DIF_Msk) { return "DIF"; } - if (rr & POWER_RESETREAS_LPCOMP_Msk){ + if (rr & POWER_RESETREAS_LPCOMP_Msk) { return "LPCOMP"; } - if (rr & POWER_RESETREAS_OFF_Msk){ + if (rr & POWER_RESETREAS_OFF_Msk) { return "OFF"; } - if (rr & POWER_RESETREAS_LOCKUP_Msk){ + if (rr & POWER_RESETREAS_LOCKUP_Msk) { return "LOCKUP"; } - if (rr & POWER_RESETREAS_SREQ_Msk){ + if (rr & POWER_RESETREAS_SREQ_Msk) { return "SREQ"; } - if (rr & POWER_RESETREAS_DOG_Msk){ + if (rr & POWER_RESETREAS_DOG_Msk) { return "DOG"; } - if (rr & POWER_RESETREAS_RESETPIN_Msk){ + if (rr & POWER_RESETREAS_RESETPIN_Msk) { return "RESETPIN"; } return "NONE"; @@ -415,10 +415,13 @@ void DebugComponent::dump_config() { #endif // USE_LIBRETINY #if defined(USE_NRF52) && defined(USE_ARDUINO) - //TODO fixme - ESP_LOGD(TAG, "bootloader version %lu.%lu.%lu", (bootloaderVersion >> 16) & 0xFF, (bootloaderVersion >> 8) & 0xFF, bootloaderVersion & 0xFF); - 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]); + // TODO fixme + ESP_LOGD(TAG, "bootloader version %lu.%lu.%lu", (bootloaderVersion >> 16) & 0xFF, (bootloaderVersion >> 8) & 0xFF, + bootloaderVersion & 0xFF); + 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(); ESP_LOGD(TAG, "Reset Reason: %s", reset_reason.c_str()); #endif diff --git a/esphome/components/deep_sleep/deep_sleep_backend_nrf52.cpp b/esphome/components/deep_sleep/deep_sleep_backend_nrf52.cpp index cf29421c5d..175b6be71f 100644 --- a/esphome/components/deep_sleep/deep_sleep_backend_nrf52.cpp +++ b/esphome/components/deep_sleep/deep_sleep_backend_nrf52.cpp @@ -8,33 +8,31 @@ namespace esphome { namespace deep_sleep { -#define DFU_MAGIC_SKIP 0x6d +#define DFU_MAGIC_SKIP 0x6d static const char *const TAG = "deep_sleep.nrf52"; -void Nrf52DeepSleepBackend::begin_sleep(const optional& sleep_duration) { +void Nrf52DeepSleepBackend::begin_sleep(const optional &sleep_duration) { // RTC works only during System On - if (sleep_duration.has_value()) - { + 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)); + 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. + 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 + 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... } @@ -42,7 +40,7 @@ void Nrf52DeepSleepBackend::begin_sleep(const optional& sleep_duration void Nrf52DeepSleepBackend::dump_config() { 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 { ESP_LOGD(TAG, "Last sleep duration: unknown"); } diff --git a/esphome/components/deep_sleep/deep_sleep_backend_nrf52.h b/esphome/components/deep_sleep/deep_sleep_backend_nrf52.h index 0b5f5f5506..b96ee11323 100644 --- a/esphome/components/deep_sleep/deep_sleep_backend_nrf52.h +++ b/esphome/components/deep_sleep/deep_sleep_backend_nrf52.h @@ -9,8 +9,9 @@ namespace deep_sleep { class Nrf52DeepSleepBackend { public: - void begin_sleep(const optional& sleep_duration); + void begin_sleep(const optional &sleep_duration); void dump_config(); + protected: optional last_sleep_duration_; }; diff --git a/esphome/components/deep_sleep/deep_sleep_component.cpp b/esphome/components/deep_sleep/deep_sleep_component.cpp index e79dc8d4b1..7b772b8982 100644 --- a/esphome/components/deep_sleep/deep_sleep_component.cpp +++ b/esphome/components/deep_sleep/deep_sleep_component.cpp @@ -37,8 +37,7 @@ optional DeepSleepComponent::get_run_duration_() const { return this->run_duration_; } -void DeepSleepComponent::setup_deep_sleep_() -{ +void DeepSleepComponent::setup_deep_sleep_() { this->next_enter_deep_sleep_ = false; const optional run_duration = get_run_duration_(); if (run_duration.has_value()) { @@ -153,7 +152,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 // USE_ESP32_VARIANT_ESP32C3 #ifdef USE_ESP32_VARIANT_ESP32C3 if (this->sleep_duration_.has_value()) esp_sleep_enable_timer_wakeup(*this->sleep_duration_); @@ -165,9 +164,9 @@ void DeepSleepComponent::begin_sleep(bool manual) { esp_deep_sleep_enable_gpio_wakeup(1 << this->wakeup_pin_->get_pin(), static_cast(level)); } -#endif // USE_ESP32_VARIANT_ESP32C3 +#endif // USE_ESP32_VARIANT_ESP32C3 esp_deep_sleep_start(); -#endif // USE_ESP32 +#endif // USE_ESP32 #ifdef USE_ESP8266 ESP.deepSleep(*this->sleep_duration_); // NOLINT(readability-static-accessed-through-instance) diff --git a/esphome/components/dfu/dfu.cpp b/esphome/components/dfu/dfu.cpp index 37fb1a725f..87fd2c9295 100644 --- a/esphome/components/dfu/dfu.cpp +++ b/esphome/components/dfu/dfu.cpp @@ -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)}; -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) { goto_dfu = true; } diff --git a/esphome/components/dfu/dfu.h b/esphome/components/dfu/dfu.h index 5589a58b55..84b45f6fbd 100644 --- a/esphome/components/dfu/dfu.h +++ b/esphome/components/dfu/dfu.h @@ -19,5 +19,5 @@ class DeviceFirmwareUpdate : public Component { output::BinaryOutput *reset_output_; #endif }; -} -} +} // namespace dfu +} // namespace esphome diff --git a/esphome/components/logger/logger.cpp b/esphome/components/logger/logger.cpp index 42768add41..36b85b7de3 100644 --- a/esphome/components/logger/logger.cpp +++ b/esphome/components/logger/logger.cpp @@ -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); #ifdef USE_ARDUINO } 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 } @@ -152,17 +153,17 @@ Logger::Logger(uint32_t baud_rate, size_t tx_buffer_size) : baud_rate_(baud_rate } #ifdef USE_USB_CDC -# ifndef USE_ZEPHYR +#ifndef USE_ZEPHYR void Logger::loop() { #ifdef USE_ARDUINO if (this->uart_ != UART_SELECTION_USB_CDC) { return; } static bool opened = false; - if (opened == Serial){ + if (opened == Serial) { return; } - if(false == opened){ + if (false == opened) { App.schedule_dump_config(); } opened = !opened; diff --git a/esphome/components/logger/logger.h b/esphome/components/logger/logger.h index 617e21aad3..5722daec3e 100644 --- a/esphome/components/logger/logger.h +++ b/esphome/components/logger/logger.h @@ -161,7 +161,7 @@ class Logger : public Component { #elif defined(USE_ESP_IDF) uart_port_t uart_num_; #elif defined(USE_ZEPHYR) - const device * uart_dev_{nullptr}; + const device *uart_dev_{nullptr}; #endif struct LogLevelOverride { std::string tag; diff --git a/esphome/components/logger/logger_nrf52.cpp b/esphome/components/logger/logger_nrf52.cpp index a539ae8764..b16a7d4a4a 100644 --- a/esphome/components/logger/logger_nrf52.cpp +++ b/esphome/components/logger/logger_nrf52.cpp @@ -1,6 +1,6 @@ #ifdef USE_NRF52 #ifdef USE_ARDUINO -#include // for Serial +#include // for Serial #endif #include "logger.h" #include "esphome/core/log.h" @@ -15,7 +15,6 @@ namespace esphome { namespace logger { - static const char *const TAG = "logger"; #ifdef USE_ZEPHYR @@ -28,11 +27,11 @@ void Logger::loop() { uart_line_ctrl_get(uart_dev_, UART_LINE_CTRL_DTR, &dtr); /* Poll if the DTR flag was set, optional */ - if(opened == dtr) { + if (opened == dtr) { return; } - - if(false == opened){ + + if (false == opened) { App.schedule_dump_config(); } opened = !opened; @@ -59,10 +58,10 @@ void Logger::pre_setup() { uart_dev = DEVICE_DT_GET_OR_NULL(DT_NODELABEL(uart0)); break; case UART_SELECTION_USB_CDC: - uart_dev = DEVICE_DT_GET_OR_NULL(DT_NODELABEL(cdc_acm_uart0)); - if(device_is_ready(uart_dev)) { - usb_enable(NULL); - } + uart_dev = DEVICE_DT_GET_OR_NULL(DT_NODELABEL(cdc_acm_uart0)); + if (device_is_ready(uart_dev)) { + usb_enable(NULL); + } break; } if (!device_is_ready(uart_dev)) { @@ -78,10 +77,10 @@ void Logger::pre_setup() { #ifdef USE_ZEPHYR void HOT Logger::write_msg_(const char *msg) { - if(nullptr == uart_dev_) { + if (nullptr == uart_dev_) { return; } - while(*msg) { + while (*msg) { uart_poll_out(uart_dev_, *msg); ++msg; } diff --git a/esphome/components/nrf52/core_arduino.cpp b/esphome/components/nrf52/core_arduino.cpp index 55c54bf7e9..a1f50fe1c8 100644 --- a/esphome/components/nrf52/core_arduino.cpp +++ b/esphome/components/nrf52/core_arduino.cpp @@ -10,12 +10,11 @@ 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; +struct nrf5x_wdt_obj { + nrfx_wdt_t wdt; + 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 struct nrf5x_wdt_obj nrf5x_wdt = { @@ -23,39 +22,33 @@ static struct nrf5x_wdt_obj nrf5x_wdt = { }; 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); + // 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_feed_wdt() { nrfx_wdt_feed(&nrf5x_wdt.wdt); } -void arch_restart() { - NVIC_SystemReset(); -} +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 +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 diff --git a/esphome/components/nrf52/core_zephyr.cpp b/esphome/components/nrf52/core_zephyr.cpp index 0b0ad7595b..6ed759199a 100644 --- a/esphome/components/nrf52/core_zephyr.cpp +++ b/esphome/components/nrf52/core_zephyr.cpp @@ -11,25 +11,24 @@ void delay(uint32_t ms) { ::k_msleep(ms); } uint32_t micros() { return k_ticks_to_us_floor32(k_uptime_ticks()); } void arch_init() { - // TODO + // TODO } void arch_feed_wdt() { - // TODO + // TODO } void arch_restart() { - // TODO + // TODO } -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 +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 @@ -37,13 +36,13 @@ void nrf52GetMacAddr(uint8_t *mac) void setup(); void loop(); -int main(){ - setup(); - while(1) { - loop(); - esphome::yield(); - } - return 0; +int main() { + setup(); + while (1) { + loop(); + esphome::yield(); + } + return 0; } #endif diff --git a/esphome/components/nrf52/gpio.h b/esphome/components/nrf52/gpio.h index 9c9d59abd2..7dc8a3ee57 100644 --- a/esphome/components/nrf52/gpio.h +++ b/esphome/components/nrf52/gpio.h @@ -30,7 +30,7 @@ class NRF52GPIOPin : public InternalGPIOPin { bool inverted_; gpio::Flags flags_; #ifdef USE_ZEPHYR - const device * gpio_ = nullptr; + const device *gpio_ = nullptr; bool value_ = false; #endif }; diff --git a/esphome/components/nrf52/gpio_arduino.cpp b/esphome/components/nrf52/gpio_arduino.cpp index 7d6404f5c0..fc2d05caca 100644 --- a/esphome/components/nrf52/gpio_arduino.cpp +++ b/esphome/components/nrf52/gpio_arduino.cpp @@ -13,17 +13,14 @@ 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 + // 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) { @@ -33,7 +30,7 @@ static int IRAM_ATTR flags_to_mode(gpio::Flags flags, uint8_t pin) { } 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; + return OUTPUT_S0D1; } else { return INPUT; } @@ -44,13 +41,11 @@ struct ISRPinArg { bool inverted; }; -//TODO implement -//TODO test +// TODO implement +// TODO test void (*irq_cb)(void *); -void* irq_arg; -static void pin_irq(void){ - irq_cb(irq_arg); -} +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) @@ -82,9 +77,7 @@ void NRF52GPIOPin::attach_interrupt(void (*func)(void *), void *arg, gpio::Inter void NRF52GPIOPin::setup() { pin_mode(flags_); } -void NRF52GPIOPin::pin_mode(gpio::Flags flags) { - pinMode(pin_, flags_to_mode(flags, pin_)); -} +void NRF52GPIOPin::pin_mode(gpio::Flags flags) { pinMode(pin_, flags_to_mode(flags, pin_)); } std::string NRF52GPIOPin::dump_summary() const { char buffer[32]; @@ -92,15 +85,9 @@ std::string NRF52GPIOPin::dump_summary() const { 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_); -} +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 diff --git a/esphome/components/nrf52/gpio_zephyr.cpp b/esphome/components/nrf52/gpio_zephyr.cpp index 017bdecfc8..6814f27b7c 100644 --- a/esphome/components/nrf52/gpio_zephyr.cpp +++ b/esphome/components/nrf52/gpio_zephyr.cpp @@ -16,7 +16,7 @@ static int flags_to_mode(gpio::Flags flags, uint8_t pin, bool inverted, bool val } if (flags & gpio::FLAG_OUTPUT) { ret |= GPIO_OUTPUT; - if(value != inverted){ + if (value != inverted) { ret |= GPIO_OUTPUT_INIT_HIGH; } else { ret |= GPIO_OUTPUT_INIT_LOW; @@ -51,18 +51,18 @@ void NRF52GPIOPin::attach_interrupt(void (*func)(void *), void *arg, gpio::Inter } void NRF52GPIOPin::setup() { - const struct device * gpio = nullptr; - if(pin_ < 32) { + const struct device *gpio = nullptr; + if (pin_ < 32) { #define GPIO0 DT_NODELABEL(gpio0) #if DT_NODE_HAS_STATUS(GPIO0, okay) - gpio = DEVICE_DT_GET(GPIO0); + gpio = DEVICE_DT_GET(GPIO0); #else #error "gpio0 is disabled" #endif } else { #define GPIO1 DT_NODELABEL(gpio1) #if DT_NODE_HAS_STATUS(GPIO1, okay) - gpio = DEVICE_DT_GET(GPIO1); + gpio = DEVICE_DT_GET(GPIO1); #else #error "gpio1 is disabled" #endif @@ -77,7 +77,7 @@ void NRF52GPIOPin::setup() { } void NRF52GPIOPin::pin_mode(gpio::Flags flags) { - if(nullptr == gpio_) { + if (nullptr == gpio_) { return; } 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() { - if(nullptr == gpio_) { + if (nullptr == gpio_) { return false; } 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 // that way init state should be correct value_ = value; - if(nullptr == gpio_) { + if (nullptr == gpio_) { return; } - gpio_pin_set(gpio_, pin_, value != inverted_ ? 1 : 0 ); + gpio_pin_set(gpio_, pin_, value != inverted_ ? 1 : 0); } void NRF52GPIOPin::detach_interrupt() const { // TODO diff --git a/esphome/components/nrf52/nrf52840/variant.cpp b/esphome/components/nrf52/nrf52840/variant.cpp index 4c977f7edd..d625b79625 100644 --- a/esphome/components/nrf52/nrf52840/variant.cpp +++ b/esphome/components/nrf52/nrf52840/variant.cpp @@ -1,15 +1,9 @@ #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 -}; +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}; diff --git a/esphome/components/nrf52/nrf52840/variant.h b/esphome/components/nrf52/nrf52840/variant.h index d6bd85f7bb..0f12e53b80 100644 --- a/esphome/components/nrf52/nrf52840/variant.h +++ b/esphome/components/nrf52/nrf52840/variant.h @@ -2,15 +2,14 @@ #include "WVariant.h" -#define PINS_COUNT (48) +#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 - +#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 diff --git a/esphome/components/nrf52/preferences.cpp b/esphome/components/nrf52/preferences.cpp index 80bb198a00..5b3030011e 100644 --- a/esphome/components/nrf52/preferences.cpp +++ b/esphome/components/nrf52/preferences.cpp @@ -12,30 +12,30 @@ class NRF52Preferences : public ESPPreferences { } ESPPreferenceObject make_preference(size_t length, uint32_t type) override { - //TODO + // TODO return {}; } bool sync() override { - //TODO + // TODO return true; } bool reset() override { - // TODO + // TODO return true; } -// protected: -// uint8_t *eeprom_sector_; + // protected: + // uint8_t *eeprom_sector_; }; void setup_preferences() { auto *prefs = new NRF52Preferences(); // NOLINT(cppcoreguidelines-owning-memory) global_preferences = prefs; } -//TODO -// void preferences_prevent_write(bool prevent) { s_prevent_write = prevent; } +// TODO +// void preferences_prevent_write(bool prevent) { s_prevent_write = prevent; } } // namespace nrf52 diff --git a/esphome/components/nrf52/preferences.h b/esphome/components/nrf52/preferences.h index 9bb9ffc668..4eb42d93e8 100644 --- a/esphome/components/nrf52/preferences.h +++ b/esphome/components/nrf52/preferences.h @@ -6,8 +6,8 @@ namespace esphome { namespace nrf52 { void setup_preferences(); -//TODO -// void preferences_prevent_write(bool prevent); +// TODO +// void preferences_prevent_write(bool prevent); } // namespace nrf52 } // namespace esphome diff --git a/esphome/core/helpers.cpp b/esphome/core/helpers.cpp index fdc508be9f..f2580a0c84 100644 --- a/esphome/core/helpers.cpp +++ b/esphome/core/helpers.cpp @@ -252,7 +252,7 @@ bool random_bytes(uint8_t *data, size_t len) { #ifdef USE_ARDUINO return nRFCrypto.Random.generate(data, len); #elif USE_ZEPHYR -//TODO +// TODO #endif #else #error "No random source available for this configuration." @@ -531,7 +531,7 @@ Mutex::Mutex() {} void Mutex::lock() {} bool Mutex::try_lock() { return true; } void Mutex::unlock() {} -//TODO +// TODO #elif defined(USE_ESP32) || defined(USE_LIBRETINY) /*|| defined(USE_NRF52)*/ Mutex::Mutex() { handle_ = xSemaphoreCreateMutex(); } void Mutex::lock() { xSemaphoreTake(this->handle_, portMAX_DELAY); } diff --git a/esphome/core/helpers.h b/esphome/core/helpers.h index 53bb6c79e3..ed009ab021 100644 --- a/esphome/core/helpers.h +++ b/esphome/core/helpers.h @@ -551,7 +551,7 @@ class Mutex { Mutex &operator=(const Mutex &) = delete; private: -//TODO +// TODO #if defined(USE_ESP32) || defined(USE_LIBRETINY) /*|| defined(USE_NRF52)*/ SemaphoreHandle_t handle_; #endif