diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index 71d37bc2e..8f938ce9e 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -12,7 +12,7 @@ lint: - trufflehog@3.88.18 - yamllint@1.37.0 - bandit@1.8.3 - - checkov@3.2.392 + - checkov@3.2.394 - terrascan@1.19.9 - trivy@0.60.0 - taplo@0.9.3 diff --git a/arch/portduino/portduino.ini b/arch/portduino/portduino.ini index 55234914f..3b5ec1a9b 100644 --- a/arch/portduino/portduino.ini +++ b/arch/portduino/portduino.ini @@ -1,6 +1,6 @@ ; The Portduino based 'native' environment. Currently supported on Linux targets with real LoRa hardware (or simulated). [portduino_base] -platform = https://github.com/meshtastic/platform-native.git#e82ba1a19b6cd1dc55cbde29b33ea8dd0640014f +platform = https://github.com/meshtastic/platform-native.git#c5bd469ab9b5a6966321e09557b27d906961da63 framework = arduino build_src_filter = diff --git a/boards/ThinkNode-M1.json b/boards/ThinkNode-M1.json new file mode 100644 index 000000000..e55da3ec7 --- /dev/null +++ b/boards/ThinkNode-M1.json @@ -0,0 +1,53 @@ +{ + "build": { + "arduino": { + "ldscript": "nrf52840_s140_v6.ld" + }, + "core": "nRF5", + "cpu": "cortex-m4", + "extra_flags": "-DARDUINO_NRF52840_TTGO_EINK -DNRF52840_XXAA", + "f_cpu": "64000000L", + "hwids": [ + ["0x239A", "0x4405"], + ["0x239A", "0x0029"], + ["0x239A", "0x002A"] + ], + "usb_product": "elecrow_eink", + "mcu": "nrf52840", + "variant": "ELECROW-ThinkNode-M1", + "variants_dir": "variants", + "bsp": { + "name": "adafruit" + }, + "softdevice": { + "sd_flags": "-DS140", + "sd_name": "s140", + "sd_version": "6.1.1", + "sd_fwid": "0x00B6" + }, + "bootloader": { + "settings_addr": "0xFF000" + } + }, + "connectivity": ["bluetooth"], + "debug": { + "jlink_device": "nRF52840_xxAA", + "onboard_tools": ["jlink"], + "svd_path": "nrf52840.svd", + "openocd_target": "nrf52840-mdk-rs" + }, + "frameworks": ["arduino"], + "name": "elecrow eink", + "upload": { + "maximum_ram_size": 248832, + "maximum_size": 815104, + "speed": 115200, + "protocol": "nrfutil", + "protocols": ["jlink", "nrfjprog", "nrfutil", "stlink"], + "use_1200bps_touch": true, + "require_upload_port": true, + "wait_for_upload_port": true + }, + "url": "FIXME", + "vendor": "ELECROW" +} diff --git a/protobufs b/protobufs index b4044f8f9..f00e96f12 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit b4044f8f9f3681d4d20521dbe13ee42c96eae353 +Subproject commit f00e96f12da48abfa9a992f8b5546fd75a370250 diff --git a/src/ButtonThread.cpp b/src/ButtonThread.cpp index 12f81353c..2363f804c 100644 --- a/src/ButtonThread.cpp +++ b/src/ButtonThread.cpp @@ -73,23 +73,28 @@ ButtonThread::ButtonThread() : OSThread("Button") userButton.setDebounceMs(1); userButton.attachDoubleClick(userButtonDoublePressed); userButton.attachMultiClick(userButtonMultiPressed, this); // Reference to instance: get click count from non-static OneButton -#ifndef T_DECK // T-Deck immediately wakes up after shutdown, so disable this function +#if !defined(T_DECK) && \ + !defined( \ + ELECROW_ThinkNode_M2) // T-Deck immediately wakes up after shutdown, Thinknode M2 has this on the smaller ALT button userButton.attachLongPressStart(userButtonPressedLongStart); userButton.attachLongPressStop(userButtonPressedLongStop); #endif #endif #ifdef BUTTON_PIN_ALT - userButtonAlt = OneButton(BUTTON_PIN_ALT, true, true); +#if defined(ELECROW_ThinkNode_M2) + this->userButtonAlt = OneButton(BUTTON_PIN_ALT, false, false); +#else + this->userButtonAlt = OneButton(BUTTON_PIN_ALT, true, true); +#endif #ifdef INPUT_PULLUP_SENSE // Some platforms (nrf52) have a SENSE variant which allows wake from sleep - override what OneButton did pinMode(BUTTON_PIN_ALT, INPUT_PULLUP_SENSE); #endif - userButtonAlt.attachClick(userButtonPressed); + userButtonAlt.attachClick(userButtonPressedScreen); userButtonAlt.setClickMs(BUTTON_CLICK_MS); userButtonAlt.setPressMs(BUTTON_LONGPRESS_MS); userButtonAlt.setDebounceMs(1); - userButtonAlt.attachDoubleClick(userButtonDoublePressed); userButtonAlt.attachLongPressStart(userButtonPressedLongStart); userButtonAlt.attachLongPressStop(userButtonPressedLongStop); #endif @@ -117,6 +122,40 @@ int32_t ButtonThread::runOnce() canSleep = true; // Assume we should not keep the board awake #if defined(BUTTON_PIN) || defined(USERPREFS_BUTTON_PIN) + // #if defined(ELECROW_ThinkNode_M1) || defined(ELECROW_ThinkNode_M2) + // buzzer_updata(); + // if (buttonPressed) { + // buttonPressed = false; // 清除标志 + // LOG_INFO("PIN_BUTTON2 pressed!"); // 串口打印信息 + // // off_currentTime = millis(); + // while (digitalRead(PIN_BUTTON2) == HIGH) { + // if (cont < 40) { + // // unsigned long currentTime = millis(); // 获取当前时间 + // // if (currentTime - off_currentTime >= 1000) { + // cont++; + // // off_currentTime = currentTime; + // // } + // delay(100); + // } else { + + // currentState = OFF; + // isBuzzing = false; + // cont = 0; + // BEEP_STATE = false; + // analogWrite(M2_buzzer, 0); + // pinMode(M2_buzzer, INPUT); + // screen->setOn(false); + // cont = 0; + // LOG_INFO("GGGGGGGGGGGGGGGGGGGGGGGGG"); + // pinMode(1, OUTPUT); + // digitalWrite(1, LOW); + // pinMode(6, OUTPUT); + // digitalWrite(6, LOW); + // } + // } + // } + + // #endif userButton.tick(); canSleep &= userButton.isIdle(); #elif defined(ARCH_PORTDUINO) @@ -166,6 +205,14 @@ int32_t ButtonThread::runOnce() break; } + case BUTTON_EVENT_PRESSED_SCREEN: { + // turn screen on or off + screen_flag = !screen_flag; + if (screen) + screen->setOn(screen_flag); + break; + } + case BUTTON_EVENT_DOUBLE_PRESSED: { LOG_BUTTON("Double press!"); service->refreshLocalMeshNode(); @@ -192,7 +239,16 @@ int32_t ButtonThread::runOnce() screen->forceDisplay(true); // Force a new UI frame, then force an EInk update } break; +#elif defined(ELECROW_ThinkNode_M2) + case 3: + LOG_INFO("3 clicks: toggle buzzer"); + buzzer_flag = !buzzer_flag; + if (buzzer_flag) { + playBeep(); + } + break; #endif + #if defined(USE_EINK) && defined(PIN_EINK_EN) // i.e. T-Echo // 4 clicks: toggle backlight case 4: diff --git a/src/ButtonThread.h b/src/ButtonThread.h index 54b833d03..a8f1f77c3 100644 --- a/src/ButtonThread.h +++ b/src/ButtonThread.h @@ -24,6 +24,7 @@ class ButtonThread : public concurrency::OSThread enum ButtonEventType { BUTTON_EVENT_NONE, BUTTON_EVENT_PRESSED, + BUTTON_EVENT_PRESSED_SCREEN, BUTTON_EVENT_DOUBLE_PRESSED, BUTTON_EVENT_MULTI_PRESSED, BUTTON_EVENT_LONG_PRESSED, @@ -42,7 +43,6 @@ class ButtonThread : public concurrency::OSThread int beforeLightSleep(void *unused); int afterLightSleep(esp_sleep_wakeup_cause_t cause); #endif - private: #if defined(BUTTON_PIN) || defined(ARCH_PORTDUINO) || defined(USERPREFS_BUTTON_PIN) static OneButton userButton; // Static - accessed from an interrupt @@ -64,6 +64,8 @@ class ButtonThread : public concurrency::OSThread // set during IRQ static volatile ButtonEventType btnEvent; + bool buzzer_flag = false; + bool screen_flag = true; // Store click count during callback, for later use volatile int multipressClickCount = 0; @@ -72,6 +74,12 @@ class ButtonThread : public concurrency::OSThread // IRQ callbacks static void userButtonPressed() { btnEvent = BUTTON_EVENT_PRESSED; } + static void userButtonPressedScreen() + { + if (millis() > c_holdOffTime) { + btnEvent = BUTTON_EVENT_PRESSED_SCREEN; + } + } static void userButtonDoublePressed() { btnEvent = BUTTON_EVENT_DOUBLE_PRESSED; } static void userButtonMultiPressed(void *callerThread); // Retrieve click count from non-static Onebutton while still valid static void userButtonPressedLongStart(); diff --git a/src/Power.cpp b/src/Power.cpp index 8c2ef998d..ec3550869 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -713,6 +713,9 @@ void Power::readPowerStatus() const PowerStatus powerStatus2 = PowerStatus(hasBattery, usbPowered, isCharging, batteryVoltageMv, batteryChargePercent); LOG_DEBUG("Battery: usbPower=%d, isCharging=%d, batMv=%d, batPct=%d", powerStatus2.getHasUSB(), powerStatus2.getIsCharging(), powerStatus2.getBatteryVoltageMv(), powerStatus2.getBatteryChargePercent()); +#if defined(ELECROW_ThinkNode_M1) || defined(POWER_CFG) + power_num = powerStatus2.getBatteryVoltageMv(); +#endif newStatus.notifyObservers(&powerStatus2); #ifdef DEBUG_HEAP if (lastheap != memGet.getFreeHeap()) { @@ -756,9 +759,13 @@ void Power::readPowerStatus() // If we have a battery at all and it is less than 0%, force deep sleep if we have more than 10 low readings in // a row. NOTE: min LiIon/LiPo voltage is 2.0 to 2.5V, current OCV min is set to 3100 that is large enough. // + if (batteryLevel && powerStatus2.getHasBattery() && !powerStatus2.getHasUSB()) { if (batteryLevel->getBattVoltage() < OCV[NUM_OCV_POINTS - 1]) { low_voltage_counter++; +#if defined(ELECROW_ThinkNode_M1) + low_voltage_counter_led3 = low_voltage_counter; +#endif LOG_DEBUG("Low voltage counter: %d/10", low_voltage_counter); if (low_voltage_counter > 10) { #ifdef ARCH_NRF52 @@ -771,7 +778,13 @@ void Power::readPowerStatus() } } else { low_voltage_counter = 0; +#if defined(ELECROW_ThinkNode_M1) + low_voltage_counter_led3 = low_voltage_counter; +#endif } +#ifdef POWER_CFG + low_voltage_counter_led3 = low_voltage_counter; +#endif } } diff --git a/src/buzz/buzz.cpp b/src/buzz/buzz.cpp index 8db9602bc..6ba2f4140 100644 --- a/src/buzz/buzz.cpp +++ b/src/buzz/buzz.cpp @@ -30,8 +30,11 @@ struct ToneDuration { #define NOTE_B3 247 #define NOTE_CS4 277 -const int DURATION_1_8 = 125; // 1/8 note -const int DURATION_1_4 = 250; // 1/4 note +const int DURATION_1_8 = 125; // 1/8 note +const int DURATION_1_4 = 250; // 1/4 note +const int DURATION_1_2 = 500; // 1/2 note +const int DURATION_3_4 = 750; // 1/4 note +const int DURATION_1_1 = 1000; // 1/1 note void playTones(const ToneDuration *tone_durations, int size) { @@ -55,6 +58,12 @@ void playBeep() playTones(melody, sizeof(melody) / sizeof(ToneDuration)); } +void playLongBeep() +{ + ToneDuration melody[] = {{NOTE_B3, DURATION_1_1}}; + playTones(melody, sizeof(melody) / sizeof(ToneDuration)); +} + void playGPSEnableBeep() { ToneDuration melody[] = {{NOTE_C3, DURATION_1_8}, {NOTE_FS3, DURATION_1_4}, {NOTE_CS4, DURATION_1_4}}; diff --git a/src/buzz/buzz.h b/src/buzz/buzz.h index c52c3020c..adeaca73d 100644 --- a/src/buzz/buzz.h +++ b/src/buzz/buzz.h @@ -1,6 +1,7 @@ #pragma once void playBeep(); +void playLongBeep(); void playStartMelody(); void playShutdownMelody(); void playGPSEnableBeep(); diff --git a/src/graphics/EInkDisplay2.cpp b/src/graphics/EInkDisplay2.cpp index 1bf1bc300..96c6b44c1 100644 --- a/src/graphics/EInkDisplay2.cpp +++ b/src/graphics/EInkDisplay2.cpp @@ -128,16 +128,24 @@ bool EInkDisplay::connect() #ifdef PIN_EINK_EN // backlight power, HIGH is backlight on, LOW is off pinMode(PIN_EINK_EN, OUTPUT); +#ifdef ELECROW_ThinkNode_M1 digitalWrite(PIN_EINK_EN, LOW); +#else + digitalWrite(PIN_EINK_EN, HIGH); +#endif #endif -#if defined(TTGO_T_ECHO) +#if defined(TTGO_T_ECHO) || defined(ELECROW_ThinkNode_M1) { auto lowLevel = new EINK_DISPLAY_MODEL(PIN_EINK_CS, PIN_EINK_DC, PIN_EINK_RES, PIN_EINK_BUSY, SPI1); adafruitDisplay = new GxEPD2_BW(*lowLevel); adafruitDisplay->init(); +#ifdef ELECROW_ThinkNode_M1 + adafruitDisplay->setRotation(4); +#else adafruitDisplay->setRotation(3); +#endif adafruitDisplay->setPartialWindow(0, 0, displayWidth, displayHeight); } #elif defined(MESHLINK) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 0c18f3287..635cd5164 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -1641,6 +1641,11 @@ void Screen::handleSetOn(bool on, FrameCallback einkScreensaver) setScreensaverFrames(einkScreensaver); #endif LOG_INFO("Turn off screen"); +#ifdef ELECROW_ThinkNode_M1 + if (digitalRead(PIN_EINK_EN) == HIGH) { + digitalWrite(PIN_EINK_EN, LOW); + } +#endif dispdev->displayOff(); #ifdef USE_ST7789 SPI1.end(); diff --git a/src/main.cpp b/src/main.cpp index b4e8cd521..59cd6d8e9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -262,6 +262,32 @@ void printInfo() #ifndef PIO_UNIT_TESTING void setup() { + +#ifdef POWER_CHRG + pinMode(POWER_CHRG, OUTPUT); + digitalWrite(POWER_CHRG, HIGH); +#endif + +#if defined(PIN_POWER_EN) + pinMode(PIN_POWER_EN, OUTPUT); + digitalWrite(PIN_POWER_EN, HIGH); +#endif + +#ifdef LED_POWER + pinMode(LED_POWER, OUTPUT); + digitalWrite(LED_POWER, HIGH); +#endif + +#ifdef POWER_LED + pinMode(POWER_LED, OUTPUT); + digitalWrite(POWER_LED, HIGH); +#endif + +#ifdef USER_LED + pinMode(USER_LED, OUTPUT); + digitalWrite(USER_LED, LOW); +#endif + #if defined(T_DECK) // GPIO10 manages all peripheral power supplies // Turn on peripheral power immediately after MUC starts. @@ -325,13 +351,6 @@ void setup() initDeepSleep(); - // power on peripherals -#if defined(PIN_POWER_EN) - pinMode(PIN_POWER_EN, OUTPUT); - digitalWrite(PIN_POWER_EN, HIGH); - // digitalWrite(PIN_POWER_EN1, INPUT); -#endif - #if defined(LORA_TCXO_GPIO) pinMode(LORA_TCXO_GPIO, OUTPUT); digitalWrite(LORA_TCXO_GPIO, HIGH); @@ -1303,5 +1322,4 @@ void loop() mainDelay.delay(delayMsec); } } - #endif diff --git a/src/modules/SerialModule.cpp b/src/modules/SerialModule.cpp index 34ece2312..f3f23b080 100644 --- a/src/modules/SerialModule.cpp +++ b/src/modules/SerialModule.cpp @@ -60,7 +60,7 @@ SerialModule *serialModule; SerialModuleRadio *serialModuleRadio; -#if defined(TTGO_T_ECHO) || defined(CANARYONE) || defined(MESHLINK) +#if defined(TTGO_T_ECHO) || defined(CANARYONE) || defined(MESHLINK) || defined(ELECROW_ThinkNode_M1) SerialModule::SerialModule() : StreamAPI(&Serial), concurrency::OSThread("Serial") {} static Print *serialPrint = &Serial; #elif defined(CONFIG_IDF_TARGET_ESP32C6) @@ -158,7 +158,7 @@ int32_t SerialModule::runOnce() Serial.begin(baud); Serial.setTimeout(moduleConfig.serial.timeout > 0 ? moduleConfig.serial.timeout : TIMEOUT); } -#elif !defined(TTGO_T_ECHO) && !defined(CANARYONE) && !defined(MESHLINK) +#elif !defined(TTGO_T_ECHO) && !defined(CANARYONE) && !defined(MESHLINK) && !defined(ELECROW_ThinkNode_M1) if (moduleConfig.serial.rxd && moduleConfig.serial.txd) { #ifdef ARCH_RP2040 Serial2.setFIFOSize(RX_BUFFER); @@ -214,7 +214,7 @@ int32_t SerialModule::runOnce() } } -#if !defined(TTGO_T_ECHO) && !defined(CANARYONE) && !defined(MESHLINK) +#if !defined(TTGO_T_ECHO) && !defined(CANARYONE) && !defined(MESHLINK) && !defined(ELECROW_ThinkNode_M1) else if ((moduleConfig.serial.mode == meshtastic_ModuleConfig_SerialConfig_Serial_Mode_WS85)) { processWXSerial(); @@ -416,7 +416,8 @@ uint32_t SerialModule::getBaudRate() */ void SerialModule::processWXSerial() { -#if !defined(TTGO_T_ECHO) && !defined(CANARYONE) && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(MESHLINK) +#if !defined(TTGO_T_ECHO) && !defined(CANARYONE) && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(MESHLINK) && \ + !defined(ELECROW_ThinkNode_M1) static unsigned int lastAveraged = 0; static unsigned int averageIntervalMillis = 300000; // 5 minutes hard coded. static double dir_sum_sin = 0; diff --git a/src/platform/esp32/architecture.h b/src/platform/esp32/architecture.h index 631df0fe4..0af6d4d04 100644 --- a/src/platform/esp32/architecture.h +++ b/src/platform/esp32/architecture.h @@ -144,6 +144,8 @@ #define HW_VENDOR meshtastic_HardwareModel_HELTEC_HT62 #elif defined(EBYTE_ESP32_S3) #define HW_VENDOR meshtastic_HardwareModel_EBYTE_ESP32_S3 +#elif defined(ELECROW_ThinkNode_M2) +#define HW_VENDOR meshtastic_HardwareModel_THINKNODE_M2 #elif defined(ESP32_S3_PICO) #define HW_VENDOR meshtastic_HardwareModel_ESP32_S3_PICO #elif defined(SENSELORA_S3) diff --git a/src/platform/esp32/main-esp32.cpp b/src/platform/esp32/main-esp32.cpp index d0fe31f21..ab1e5c922 100644 --- a/src/platform/esp32/main-esp32.cpp +++ b/src/platform/esp32/main-esp32.cpp @@ -109,6 +109,11 @@ void esp32Setup() randomSeed(seed); */ +#ifdef POWER_FULL + pinMode(POWER_FULL, INPUT); + pinMode(7, INPUT); +#endif + LOG_DEBUG("Total heap: %d", ESP.getHeapSize()); LOG_DEBUG("Free heap: %d", ESP.getFreeHeap()); LOG_DEBUG("Total PSRAM: %d", ESP.getPsramSize()); diff --git a/src/platform/nrf52/architecture.h b/src/platform/nrf52/architecture.h index 71db98da6..1a06f173a 100644 --- a/src/platform/nrf52/architecture.h +++ b/src/platform/nrf52/architecture.h @@ -53,6 +53,8 @@ #define HW_VENDOR meshtastic_HardwareModel_RAK4631 #elif defined(TTGO_T_ECHO) #define HW_VENDOR meshtastic_HardwareModel_T_ECHO +#elif defined(ELECROW_ThinkNode_M1) +#define HW_VENDOR meshtastic_HardwareModel_NRF52_UNKNOWN // HW_VENDOR meshtastic_HardwareModel_ThinkNode_M1 #elif defined(NANO_G2_ULTRA) #define HW_VENDOR meshtastic_HardwareModel_NANO_G2_ULTRA #elif defined(CANARYONE) diff --git a/src/platform/nrf52/main-nrf52.cpp b/src/platform/nrf52/main-nrf52.cpp index 8483d21c6..53971e95a 100644 --- a/src/platform/nrf52/main-nrf52.cpp +++ b/src/platform/nrf52/main-nrf52.cpp @@ -235,6 +235,14 @@ void nrf52InitSemiHosting() void nrf52Setup() { +#ifdef USB_CHECK + pinMode(USB_CHECK, INPUT); +#endif + +#ifdef ADC_V + pinMode(ADC_V, INPUT); +#endif + uint32_t why = NRF_POWER->RESETREAS; // per // https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fpower.html @@ -275,9 +283,11 @@ void cpuDeepSleep(uint32_t msecToWake) Wire.end(); #endif SPI.end(); +#if SPI_INTERFACES_COUNT > 1 + SPI1.end(); +#endif // This may cause crashes as debug messages continue to flow. Serial.end(); - #ifdef PIN_SERIAL_RX1 Serial1.end(); #endif @@ -315,6 +325,31 @@ void cpuDeepSleep(uint32_t msecToWake) detachInterrupt(PIN_GPS_PPS); detachInterrupt(PIN_BUTTON1); #endif + +#ifdef ELECROW_ThinkNode_M1 + for (int pin = 0; pin < 48; pin++) { + if (pin == 17 || pin == 19 || pin == 20 || pin == 22 || pin == 23 || pin == 24 || pin == 25 || pin == 9 || pin == 10 || + pin == PIN_BUTTON1 || pin == PIN_BUTTON2) { + continue; + } + pinMode(pin, OUTPUT); + } + for (int pin = 0; pin < 48; pin++) { + if (pin == 17 || pin == 19 || pin == 20 || pin == 22 || pin == 23 || pin == 24 || pin == 25 || pin == 9 || pin == 10 || + pin == PIN_BUTTON1 || pin == PIN_BUTTON2) { + continue; + } + digitalWrite(pin, LOW); + } + for (int pin = 0; pin < 48; pin++) { + if (pin == 17 || pin == 19 || pin == 20 || pin == 22 || pin == 23 || pin == 24 || pin == 25 || pin == 9 || pin == 10 || + pin == PIN_BUTTON1 || pin == PIN_BUTTON2) { + continue; + } + NRF_GPIO->DIRCLR = (1 << pin); + } +#endif + // Sleepy trackers or sensors can low power "sleep" // Don't enter this if we're sleeping portMAX_DELAY, since that's a shutdown event if (msecToWake != portMAX_DELAY && @@ -333,6 +368,17 @@ void cpuDeepSleep(uint32_t msecToWake) // FIXME, use system off mode with ram retention for key state? // FIXME, use non-init RAM per // https://devzone.nordicsemi.com/f/nordic-q-a/48919/ram-retention-settings-with-softdevice-enabled + +#ifdef ELECROW_ThinkNode_M1 + nrf_gpio_cfg_input(PIN_BUTTON1, NRF_GPIO_PIN_PULLUP); // Configure the pin to be woken up as an input + nrf_gpio_pin_sense_t sense = NRF_GPIO_PIN_SENSE_LOW; + nrf_gpio_cfg_sense_set(PIN_BUTTON1, sense); + + nrf_gpio_cfg_input(PIN_BUTTON2, NRF_GPIO_PIN_PULLUP); + nrf_gpio_pin_sense_t sense1 = NRF_GPIO_PIN_SENSE_LOW; + nrf_gpio_cfg_sense_set(PIN_BUTTON2, sense1); +#endif + auto ok = sd_power_system_off(); if (ok != NRF_SUCCESS) { LOG_ERROR("FIXME: Ignoring soft device (EasyDMA pending?) and forcing system-off!"); diff --git a/src/platform/portduino/PortduinoGlue.cpp b/src/platform/portduino/PortduinoGlue.cpp index 9da65c92c..7b13971b4 100644 --- a/src/platform/portduino/PortduinoGlue.cpp +++ b/src/platform/portduino/PortduinoGlue.cpp @@ -210,7 +210,10 @@ void portduinoSetup() } char serial[9] = {0}; ch341Hal->getSerialString(serial, 8); - std::cout << "Serial " << serial << std::endl; + std::cout << "CH341 Serial " << serial << std::endl; + char product_string[96] = {0}; + ch341Hal->getProductString(product_string, 95); + std::cout << "CH341 Product " << product_string << std::endl; if (strlen(serial) == 8 && settingsStrings[mac_address].length() < 12) { uint8_t hash[32] = {0}; memcpy(hash, serial, 8); diff --git a/src/platform/portduino/USBHal.h b/src/platform/portduino/USBHal.h index 0d6b361f4..ce2a5cfd3 100644 --- a/src/platform/portduino/USBHal.h +++ b/src/platform/portduino/USBHal.h @@ -61,6 +61,12 @@ class Ch341Hal : public RadioLibHal strncpy(_serial, pinedio.serial_number, len); } + void getProductString(char *_product_string, size_t len) + { + len = len > 95 ? 95 : len; + strncpy(_product_string, pinedio.product_string, len); + } + void init() override {} void term() override {} diff --git a/src/power.h b/src/power.h index e9c0deb7c..97944fef7 100644 --- a/src/power.h +++ b/src/power.h @@ -84,6 +84,11 @@ class Power : private concurrency::OSThread void setStatusHandler(meshtastic::PowerStatus *handler) { statusHandler = handler; } const uint16_t OCV[11] = {OCV_ARRAY}; +#if defined(ELECROW_ThinkNode_M1) || defined(POWER_CFG) + uint8_t low_voltage_counter_led3; + int power_num = 0; +#endif + protected: meshtastic::PowerStatus *statusHandler; diff --git a/src/sleep.cpp b/src/sleep.cpp index 202b8c354..02fa8d871 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -228,6 +228,7 @@ void doDeepSleep(uint32_t msecToWake, bool skipPreflight = false, bool skipSaveN } #ifdef PIN_POWER_EN + digitalWrite(PIN_POWER_EN, LOW); pinMode(PIN_POWER_EN, INPUT); // power off peripherals // pinMode(PIN_POWER_EN1, INPUT_PULLDOWN); #endif diff --git a/variants/ELECROW-ThinkNode-M1/platformio.ini b/variants/ELECROW-ThinkNode-M1/platformio.ini new file mode 100644 index 000000000..f37f6d310 --- /dev/null +++ b/variants/ELECROW-ThinkNode-M1/platformio.ini @@ -0,0 +1,29 @@ +; First prototype eink/nrf52840/sx1262 device +[env:thinknode_m1] +extends = nrf52840_base +board = ThinkNode-M1 +board_check = true +debug_tool = jlink + +# add -DCFG_SYSVIEW if you want to use the Segger systemview tool for OS profiling. +build_flags = ${nrf52840_base.build_flags} -Ivariants/ELECROW-ThinkNode-M1 + -DELECROW_ThinkNode_M1 + -DGPS_POWER_TOGGLE + -L "${platformio.libdeps_dir}/${this.__env__}/bsec2/src/cortex-m4/fpv4-sp-d16-hard" + -DEINK_DISPLAY_MODEL=GxEPD2_154_D67 + -DEINK_WIDTH=200 + -DEINK_HEIGHT=200 + -DUSE_EINK_DYNAMICDISPLAY ; Enable Dynamic EInk + -DEINK_LIMIT_FASTREFRESH=10 ; How many consecutive fast-refreshes are permitted //20 + -DEINK_LIMIT_RATE_BACKGROUND_SEC=10 ; Minimum interval between BACKGROUND updates //30 + -DEINK_LIMIT_RATE_RESPONSIVE_SEC=1 ; Minimum interval between RESPONSIVE updates +; -DEINK_LIMIT_GHOSTING_PX=2000 ; (Optional) How much image ghosting is tolerated + -DEINK_BACKGROUND_USES_FAST ; (Optional) Use FAST refresh for both BACKGROUND and RESPONSIVE, until a limit is reached. + +build_src_filter = ${nrf52_base.build_src_filter} +<../variants/ELECROW-ThinkNode-M1> +lib_deps = + ${nrf52840_base.lib_deps} + https://github.com/meshtastic/GxEPD2/archive/33db3fa8ee6fc47d160bdb44f8f127c9a9203a10.zip + lewisxhe/PCF8563_Library@^1.0.1 + khoih-prog/nRF52_PWM@^1.0.1 +;upload_protocol = fs \ No newline at end of file diff --git a/variants/ELECROW-ThinkNode-M1/variant.cpp b/variants/ELECROW-ThinkNode-M1/variant.cpp new file mode 100644 index 000000000..cae079b74 --- /dev/null +++ b/variants/ELECROW-ThinkNode-M1/variant.cpp @@ -0,0 +1,44 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry All right reserved. + Copyright (c) 2018, Adafruit Industries (adafruit.com) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "variant.h" +#include "nrf.h" +#include "wiring_constants.h" +#include "wiring_digital.h" + +const uint32_t g_ADigitalPinMap[] = { + // P0 - pins 0 and 1 are hardwired for xtal and should never be enabled + 0xff, 0xff, 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}; + +void initVariant() +{ + // LED1 & LED2 + pinMode(PIN_LED1, OUTPUT); + ledOff(PIN_LED1); + + pinMode(PIN_LED2, OUTPUT); + ledOff(PIN_LED2); + + pinMode(PIN_LED3, OUTPUT); + ledOff(PIN_LED3); +} diff --git a/variants/ELECROW-ThinkNode-M1/variant.h b/variants/ELECROW-ThinkNode-M1/variant.h new file mode 100644 index 000000000..3bfa360f6 --- /dev/null +++ b/variants/ELECROW-ThinkNode-M1/variant.h @@ -0,0 +1,205 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry All right reserved. + Copyright (c) 2018, Adafruit Industries (adafruit.com) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _VARIANT_ELECROW_EINK_V1_0_ +#define _VARIANT_ELECROW_EINK_V1_0_ + +/** Master clock frequency */ +#define VARIANT_MCK (64000000ul) + +#define USE_LFXO // Board uses 32khz crystal for LF + +/*---------------------------------------------------------------------------- + * Headers + *----------------------------------------------------------------------------*/ + +#include "WVariant.h" + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +// Number of pins defined in PinDescription array +// 在PinDescription数组中定义的引脚数 +#define PINS_COUNT (48) +#define NUM_DIGITAL_PINS (48) +#define NUM_ANALOG_INPUTS (1) +#define NUM_ANALOG_OUTPUTS (0) + +#define PIN_LED1 -1 +#define PIN_LED2 -1 +#define PIN_LED3 -1 + +// LED +#define POWER_LED (32 + 6) // red +#define LED_POWER (32 + 4) +#define USER_LED (0 + 13) // green +// USB_CHECK +#define USB_CHECK (32 + 3) +#define ADC_V (0 + 8) + +#define LED_RED PIN_LED3 +#define LED_BLUE PIN_LED1 +#define LED_GREEN PIN_LED2 +#define LED_BUILTIN LED_BLUE +#define LED_CONN PIN_GREEN +#define LED_STATE_ON 0 // State when LED is lit // LED灯亮时的状态 +#define M1_buzzer (0 + 6) +/* + * Buttons + */ +#define PIN_BUTTON2 (32 + 10) +#define PIN_BUTTON1 (32 + 7) + +// #define PIN_BUTTON1 (0 + 11) +// #define PIN_BUTTON1 (32 + 7) + +// #define BUTTON_CLICK_MS 400 +// #define BUTTON_TOUCH_MS 200 + +/* + * Analog pins + */ +#define PIN_A0 (4) // Battery ADC + +#define BATTERY_PIN PIN_A0 + +static const uint8_t A0 = PIN_A0; + +#define ADC_RESOLUTION 14 + +#define PIN_NFC1 (9) +#define PIN_NFC2 (10) + +/*Wire Interfaces*/ +#define WIRE_INTERFACES_COUNT 1 + +#define PIN_WIRE_SDA (26) +#define PIN_WIRE_SCL (27) + +/* touch sensor, active high */ + +#define TP_SER_IO (0 + 11) + +#define PIN_RTC_INT (0 + 16) // Interrupt from the PCF8563 RTC + +/* +External serial flash WP25R1635FZUIL0 +*/ + +// QSPI Pins +#define PIN_QSPI_SCK (32 + 14) +#define PIN_QSPI_CS (32 + 15) +#define PIN_QSPI_IO0 (32 + 12) // MOSI if using two bit interface +#define PIN_QSPI_IO1 (32 + 13) // MISO if using two bit interface +#define PIN_QSPI_IO2 (0 + 7) // WP if using two bit interface (i.e. not used) +#define PIN_QSPI_IO3 (0 + 5) // HOLD if using two bit interface (i.e. not used) + +// On-board QSPI Flash +#define EXTERNAL_FLASH_DEVICES MX25R1635F +#define EXTERNAL_FLASH_USE_QSPI + +/* + * Lora radio + */ +#define SX126X_POWER_EN (0 + 21) +#define USE_SX1262 +#define SX126X_CS (0 + 24) // FIXME - we really should define LORA_CS instead +#define SX126X_DIO1 (0 + 20) +// Note DIO2 is attached internally to the module to an analog switch for TX/RX switching +// #define SX1262_DIO3 (0 + 21) // This is used as an *output* from the sx1262 and connected internally to power the tcxo, do not +// drive from the main +#define SX126X_BUSY (0 + 17) +#define SX126X_RESET (0 + 25) +#define SX126X_DIO2_AS_RF_SWITCH +#define SX126X_DIO3_TCXO_VOLTAGE 3.3 + +#define PIN_EINK_EN (32 + 11) // Note: this is really just backlight power +#define PIN_EINK_CS (0 + 30) +#define PIN_EINK_BUSY (0 + 3) +#define PIN_EINK_DC (0 + 28) +#define PIN_EINK_RES (0 + 2) +#define PIN_EINK_SCLK (0 + 31) +#define PIN_EINK_MOSI (0 + 29) // also called SDI + +// Controls power for all peripherals (eink + GPS + LoRa + Sensor) +#define PIN_POWER_EN (0 + 12) + +#define USE_EINK + +#define PIN_SPI1_MISO (32 + 7) +#define PIN_SPI1_MOSI PIN_EINK_MOSI +#define PIN_SPI1_SCK PIN_EINK_SCLK + +/* + * GPS pins + */ +// #define HAS_GPS 1 +#define GPS_L76K +#define GPS_BAUDRATE 9600 +#define PIN_GPS_REINIT (32 + 5) // An output to reset L76K GPS. As per datasheet, low for > 100ms will reset the L76K +#define PIN_GPS_STANDBY (32 + 2) // An output to wake GPS, low means allow sleep, high means force wake +// Seems to be missing on this new board +// #define PIN_GPS_PPS (32 + 4) // Pulse per second input from the GPS +#define GPS_TX_PIN (32 + 9) // This is for bits going TOWARDS the CPU +#define GPS_RX_PIN (32 + 8) // This is for bits going TOWARDS the GPS + +#define GPS_THREAD_INTERVAL 50 + +#define PIN_GPS_PPS (32 + 1) // GPS开关判断 + +#define PIN_SERIAL1_RX GPS_TX_PIN +#define PIN_SERIAL1_TX GPS_RX_PIN + +// PCF8563 RTC Module +#define PCF8563_RTC 0x51 + +/* + * SPI Interfaces + */ +#define SPI_INTERFACES_COUNT 2 + +// For LORA, spi 0 +#define PIN_SPI_MISO (0 + 23) +#define PIN_SPI_MOSI (0 + 22) +#define PIN_SPI_SCK (0 + 19) + +#define PIN_PWR_EN (0 + 6) + +// To debug via the segger JLINK console rather than the CDC-ACM serial device +// #define USE_SEGGER + +// Battery +// The battery sense is hooked to pin A0 (4) +// it is defined in the anlaolgue pin section of this file +// and has 12 bit resolution +#define BATTERY_SENSE_RESOLUTION_BITS 12 +#define BATTERY_SENSE_RESOLUTION 4096.0 +#undef AREF_VOLTAGE +#define AREF_VOLTAGE 3.0 +#define VBAT_AR_INTERNAL AR_INTERNAL_3_0 +#define ADC_MULTIPLIER (2.02F) + +// #define HAS_RTC 0 +// #define HAS_SCREEN 0 + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/variants/ELECROW-ThinkNode-M2/pins_arduino.h b/variants/ELECROW-ThinkNode-M2/pins_arduino.h new file mode 100644 index 000000000..46415d30f --- /dev/null +++ b/variants/ELECROW-ThinkNode-M2/pins_arduino.h @@ -0,0 +1,28 @@ +// Need this file for ESP32-S3 +// No need to modify this file, changes to pins imported from variant.h +// Most is similar to https://github.com/espressif/arduino-esp32/blob/master/variants/esp32s3/pins_arduino.h + +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include +#include + +#define USB_VID 0x303a +#define USB_PID 0x1001 + +// Serial +static const uint8_t TX = UART_TX; +static const uint8_t RX = UART_RX; + +// Default SPI will be mapped to Radio +static const uint8_t SS = LORA_CS; +static const uint8_t SCK = LORA_SCK; +static const uint8_t MOSI = LORA_MOSI; +static const uint8_t MISO = LORA_MISO; + +// The default Wire will be mapped to PMU and RTC +static const uint8_t SCL = I2C_SCL; +static const uint8_t SDA = I2C_SDA; + +#endif /* Pins_Arduino_h */ diff --git a/variants/ELECROW-ThinkNode-M2/platformio.ini b/variants/ELECROW-ThinkNode-M2/platformio.ini new file mode 100644 index 000000000..c08c94a71 --- /dev/null +++ b/variants/ELECROW-ThinkNode-M2/platformio.ini @@ -0,0 +1,7 @@ +[env:thinknode_m2] +extends = esp32s3_base +board = ESP32-S3-WROOM-1-N4 +build_flags = + ${esp32s3_base.build_flags} + -D ELECROW_ThinkNode_M2 + -I variants/ELECROW-ThinkNode-M2 diff --git a/variants/ELECROW-ThinkNode-M2/variant.h b/variants/ELECROW-ThinkNode-M2/variant.h new file mode 100644 index 000000000..801d5606f --- /dev/null +++ b/variants/ELECROW-ThinkNode-M2/variant.h @@ -0,0 +1,64 @@ +// Status +#define LED_PIN_POWER 1 +#define BIAS_T_ENABLE LED_PIN_POWER +#define BIAS_T_VALUE HIGH + +#define PIN_BUTTON1 47 // 功能键 +#define PIN_BUTTON2 4 // 电源键 + +#define POWER_CFG +#define POWER_CHRG 6 +#define POWER_FULL 42 + +#define PIN_BUZZER 5 + +#define I2C_SCL 15 +#define I2C_SDA 16 + +#define UART_TX 43 +#define UART_RX 44 + +#define VEXT_ENABLE 46 // for OLED +#define VEXT_ON_VALUE HIGH + +#define SX126X_CS 10 +#define LORA_SCK 12 +#define LORA_MOSI 11 +#define LORA_MISO 13 +#define SX126X_RESET 21 +#define SX126X_BUSY 14 +#define SX126X_DIO1 3 +#define SX126X_DIO2_AS_RF_SWITCH +// #define SX126X_DIO3 9 +#define SX126X_DIO3_TCXO_VOLTAGE 3.3 + +#define SX126X_MAX_POWER 22 // SX126xInterface.cpp defaults to 22 if not defined, but here we define it for good practice +#define USE_SX1262 +#define LORA_CS SX126X_CS // FIXME: for some reason both are used in /src +#define LORA_DIO1 SX126X_DIO1 +#define SX126X_POWER_EN 48 + +// Battery +// #define BATTERY_PIN 2 +#define BATTERY_PIN 17 +// #define ADC_CHANNEL ADC1_GPIO2_CHANNEL +#define ADC_CHANNEL ADC2_GPIO17_CHANNEL +#define BATTERY_SENSE_RESOLUTION_BITS 12 +#define BATTERY_SENSE_RESOLUTION 4096.0 +#undef AREF_VOLTAGE +#define AREF_VOLTAGE 3.0 +#define VBAT_AR_INTERNAL AR_INTERNAL_3_0 +#define ADC_MULTIPLIER (1.548F) +#define BAT_MEASURE_ADC_UNIT 2 + +#define HAS_SCREEN 1 +#define USE_SH1106 1 + +// PCF8563 RTC Module +// #define PCF8563_RTC 0x51 +// #define PIN_RTC_INT 48 // Interrupt from the PCF8563 RTC +#define HAS_RTC 0 +#define HAS_GPS 0 + +#define BUTTON_PIN PIN_BUTTON1 +#define BUTTON_PIN_ALT PIN_BUTTON2 diff --git a/version.properties b/version.properties index 9d6d2a464..56a8e4f3a 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 2 minor = 6 -build = 3 +build = 4