Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding XIAO ESP32C6 with BLE support #5421

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
60303b0
Add XIAO ESP32C6
alexbegoon Nov 13, 2024
e4c5de7
Merge remote-tracking branch 'upstream/master' into xiao_esp32c6_with…
alexbegoon Nov 22, 2024
497217b
WIP
alexbegoon Nov 22, 2024
be021cc
Merge branch 'master' into xiao_esp32c6_with_ble
caveman99 Nov 23, 2024
79e9702
reset protobufs
alexbegoon Nov 23, 2024
e65e39a
Improve condition for app_main define
alexbegoon Nov 23, 2024
499316b
Merge branch 'master' into xiao_esp32c6_with_ble
caveman99 Nov 24, 2024
b6c4353
Rework extra_scripts (add missing buildflags)
alexbegoon Nov 25, 2024
6fafd0a
Merge remote-tracking branch 'upstream/master' into xiao_esp32c6_with…
alexbegoon Nov 25, 2024
1e00ed8
Merge branch 'xiao_esp32c6_with_ble' of github.com:alexbegoon/firmwar…
alexbegoon Nov 25, 2024
0d52de3
Merge branch 'master' into xiao_esp32c6_with_ble
caveman99 Nov 26, 2024
62f9c35
Merge remote-tracking branch 'upstream/master' into xiao_esp32c6_with…
alexbegoon Dec 29, 2024
0e304bb
Bump a NimBLE version
alexbegoon Dec 29, 2024
765b7c0
Merge branch 'xiao_esp32c6_with_ble' of github.com:alexbegoon/firmwar…
alexbegoon Dec 29, 2024
b17cead
Bump a pioarduino version
alexbegoon Dec 29, 2024
a4453cf
Bump a NimBLE version
alexbegoon Dec 29, 2024
b2a8e7d
Bump NimBLE version
alexbegoon Dec 29, 2024
11ed799
Bridging Arduino and ESP IDF framework
alexbegoon Dec 30, 2024
9517e08
Bridging Arduino and ESP IDF framework
alexbegoon Dec 30, 2024
013d9ca
Merge branch 'master' into xiao_esp32c6_with_ble
fifieldt Dec 30, 2024
084fa5c
Merge branch 'master' into xiao_esp32c6_with_ble
alexbegoon Jan 1, 2025
a64d91b
Merge remote-tracking branch 'upstream/master' into xiao_esp32c6_with…
alexbegoon Jan 2, 2025
6209ba9
Bridging Arduino and ESP IDF framework
alexbegoon Jan 2, 2025
d64bd3d
Merge remote-tracking branch 'origin/xiao_esp32c6_with_ble' into xiao…
alexbegoon Jan 2, 2025
c86aa23
Merge remote-tracking branch 'upstream/master' into xiao_esp32c6_with…
alexbegoon Jan 2, 2025
11d27df
Merge remote-tracking branch 'upstream/master' into xiao_esp32c6_with…
alexbegoon Jan 3, 2025
e76c036
Bump meshtastic/esp8266-oled-ssd1306
alexbegoon Jan 3, 2025
3c6304f
Merge branch 'master' into xiao_esp32c6_with_ble
caveman99 Jan 4, 2025
e2e5822
Add comments to clarify the use of CMake :)
alexbegoon Jan 4, 2025
428ddd7
Merge remote-tracking branch 'origin/xiao_esp32c6_with_ble' into xiao…
alexbegoon Jan 4, 2025
69d9325
on Windows, PIO finds the wrong RTC.h
caveman99 Jan 4, 2025
934096e
Merge branch 'xiao_esp32c6_with_ble' of https://github.com/alexbegoon…
caveman99 Jan 4, 2025
9ffd0af
Merge remote-tracking branch 'upstream/master' into xiao_esp32c6_with…
alexbegoon Jan 8, 2025
07ff8a9
Merge remote-tracking branch 'upstream/master' into xiao_esp32c6_with…
alexbegoon Jan 10, 2025
0224b6a
Add external antenna support to XIAO ESP32C6
alexbegoon Jan 10, 2025
03973d3
Merge remote-tracking branch 'upstream/master' into xiao_esp32c6_with…
alexbegoon Jan 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@ release/
/compile_commands.json
src/mesh/raspihttp/certificate.pem
src/mesh/raspihttp/private_key.pem

managed_components
CMakeLists.txt
dependencies.lock

log_*
sdkconfig
sdkconfig.*
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributor Covenant Code of Conduct

The Meshtastic Firmware project is subject to the code of conduct for the parent project, which can be found here:
The Meshtastic Firmware project is subject to the code of conduct for the parent project, which can be found here:
https://meshtastic.org/docs/legal/conduct/
12 changes: 12 additions & 0 deletions bin/version_script.py
caveman99 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from readprops import readProps
Import("env")

verObj = readProps("./version.properties")

print("Using meshtastic version_script.py, firmware version " + verObj["long"] + " on " + env.get("PIOENV"))

env.Append(BUILD_FLAGS=[
"-DAPP_VERSION=" + verObj["long"],
"-DAPP_VERSION_SHORT=" + verObj["short"],
"-DAPP_ENV=" + env.get("PIOENV"),
])
2 changes: 1 addition & 1 deletion protobufs
caveman99 marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 11 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1221,4 +1221,15 @@ void loop()
mainDelay.delay(delayMsec);
}
}
#endif
#ifdef CONFIG_IDF_TARGET_ESP32C6
caveman99 marked this conversation as resolved.
Show resolved Hide resolved
// Define app_main to bridge Arduino and ESP-IDF
extern "C" void app_main(void)
{
setup();
while (1) {
loop();
vTaskDelay(1); // Allows FreeRTOS to manage tasks
}
}
#endif
2 changes: 2 additions & 0 deletions src/mesh/eth/ethClient.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if HAS_ETHERNET
#include "mesh/eth/ethClient.h"
#include "NodeDB.h"
#include "RTC.h"
Expand Down Expand Up @@ -188,3 +189,4 @@ bool isEthernetAvailable()
}

#endif
#endif
12 changes: 5 additions & 7 deletions src/mesh/http/ContentHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
// #include <Arduino.h>
// #include "main.h"

void replaceAll(std::string &str, const std::string &from, const std::string &to)
void replaceAll(String &str, const String &from, const String &to)
{
if (from.empty())
return;
size_t start_pos = 0;
while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
str.replace(start_pos, from.length(), to);
start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx'
int start_pos = 0;
while ((start_pos = str.indexOf(from, start_pos)) != -1) {
str.replace(from, to);
start_pos += to.length();
}
}
2 changes: 1 addition & 1 deletion src/mesh/http/ContentHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

#define BoolToString(x) ((x) ? "true" : "false")

void replaceAll(std::string &str, const std::string &from, const std::string &to);
void replaceAll(String &str, const String &from, const String &to);
3 changes: 2 additions & 1 deletion src/modules/ExternalNotificationModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ int32_t ExternalNotificationModule::runOnce()
if (externalTurnedOn[2] + (moduleConfig.external_notification.output_ms ? moduleConfig.external_notification.output_ms
: EXT_NOTIFICATION_MODULE_OUTPUT_MS) <
millis()) {
LOG_DEBUG("EXTERNAL 2 %d compared to %d", externalTurnedOn[2]+moduleConfig.external_notification.output_ms, millis());
LOG_DEBUG("EXTERNAL 2 %d compared to %d", externalTurnedOn[2] + moduleConfig.external_notification.output_ms,
millis());
setExternalState(2, !getExternal(2));
}
#if defined(HAS_NCP5623) || defined(RGBLED_RED) || defined(HAS_NEOPIXEL) || defined(UNPHONE)
Expand Down
10 changes: 5 additions & 5 deletions src/nimble/NimbleBluetooth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static uint8_t lastToRadio[MAX_TO_FROM_RADIO_SIZE];

class NimbleBluetoothToRadioCallback : public NimBLECharacteristicCallbacks
{
virtual void onWrite(NimBLECharacteristic *pCharacteristic)
virtual void onWrite(NimBLECharacteristic *pCharacteristic, NimBLEConnInfo &connInfo)
{
LOG_INFO("To Radio onwrite");
auto val = pCharacteristic->getValue();
Expand All @@ -66,7 +66,7 @@ class NimbleBluetoothToRadioCallback : public NimBLECharacteristicCallbacks

class NimbleBluetoothFromRadioCallback : public NimBLECharacteristicCallbacks
{
virtual void onRead(NimBLECharacteristic *pCharacteristic)
virtual void onRead(NimBLECharacteristic *pCharacteristic, NimBLEConnInfo &connInfo)
{
uint8_t fromRadioBytes[meshtastic_FromRadio_size];
size_t numBytes = bluetoothPhoneAPI->getFromRadio(fromRadioBytes);
Expand All @@ -79,7 +79,7 @@ class NimbleBluetoothFromRadioCallback : public NimBLECharacteristicCallbacks

class NimbleBluetoothServerCallback : public NimBLEServerCallbacks
{
virtual uint32_t onPassKeyRequest()
virtual void onPassKeyEntry(NimBLEConnInfo &connInfo)
{
uint32_t passkey = config.bluetooth.fixed_pin;

Expand Down Expand Up @@ -120,7 +120,7 @@ class NimbleBluetoothServerCallback : public NimBLEServerCallbacks
#endif
passkeyShowing = true;

return passkey;
NimBLEDevice::injectPassKey(connInfo, passkey);
}

virtual void onAuthenticationComplete(ble_gap_conn_desc *desc)
Expand Down Expand Up @@ -183,7 +183,7 @@ int NimbleBluetooth::getRssi()
if (bleServer && isConnected()) {
auto service = bleServer->getServiceByUUID(MESH_SERVICE_UUID);
uint16_t handle = service->getHandle();
return NimBLEDevice::getClientByID(handle)->getRssi();
return NimBLEDevice::getClientByHandle(handle)->getRssi();
}
return 0; // FIXME figure out where to source this
}
Expand Down
9 changes: 7 additions & 2 deletions src/platform/esp32/main-esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,12 @@ void esp32Setup()
LOG_DEBUG("Total PSRAM: %d", ESP.getPsramSize());
LOG_DEBUG("Free PSRAM: %d", ESP.getFreePsram());

auto res = nvs_flash_init();
assert(res == ESP_OK);

nvs_stats_t nvs_stats;
auto res = nvs_get_stats(NULL, &nvs_stats);
res = nvs_get_stats(NULL, &nvs_stats);

assert(res == ESP_OK);
LOG_DEBUG("NVS: UsedEntries %d, FreeEntries %d, AllEntries %d, NameSpaces %d", nvs_stats.used_entries, nvs_stats.free_entries,
nvs_stats.total_entries, nvs_stats.namespace_count);
Expand Down Expand Up @@ -155,8 +159,9 @@ void esp32Setup()
#ifdef CONFIG_IDF_TARGET_ESP32C6
esp_task_wdt_config_t *wdt_config = (esp_task_wdt_config_t *)malloc(sizeof(esp_task_wdt_config_t));
wdt_config->timeout_ms = APP_WATCHDOG_SECS * 1000;
wdt_config->idle_core_mask = 0;
wdt_config->trigger_panic = true;
res = esp_task_wdt_init(wdt_config);
res = esp_task_wdt_reconfigure(wdt_config);
assert(res == ESP_OK);
#else
res = esp_task_wdt_init(APP_WATCHDOG_SECS, true);
Expand Down
4 changes: 4 additions & 0 deletions src/platform/nrf52/BLEDfuScure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
*/
/**************************************************************************/

#ifdef ARCH_NRF52

#include "BLEDfuSecure.h"
#include "bluefruit.h"

Expand Down Expand Up @@ -141,3 +143,5 @@ err_t BLEDfuSecure::begin(void)

return ERROR_NONE;
}

#endif // ARCH_NRF52
3 changes: 3 additions & 0 deletions src/platform/nrf52/BLEDfuSecure.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#ifndef BLEDFUSECURE_H_
#define BLEDFUSECURE_H_

#ifdef ARCH_NRF52

#include "bluefruit_common.h"

#include "BLECharacteristic.h"
Expand All @@ -52,4 +54,5 @@ class BLEDfuSecure : public BLEService
virtual err_t begin(void);
};

#endif // ARCH_NRF52
#endif /* BLEDFUSECURE_H_ */
5 changes: 4 additions & 1 deletion src/platform/nrf52/NRF52Bluetooth.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef ARCH_NRF52

#include "NRF52Bluetooth.h"
#include "BLEDfuSecure.h"
#include "BluetoothCommon.h"
Expand Down Expand Up @@ -374,4 +376,5 @@ void NRF52Bluetooth::sendLog(const uint8_t *logMessage, size_t length)
logRadio.indicate(logMessage, (uint16_t)length);
else
logRadio.notify(logMessage, (uint16_t)length);
}
}
#endif // ARCH_NRF52
5 changes: 4 additions & 1 deletion src/platform/nrf52/NRF52CryptoEngine.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef ARCH_NRF52

#include "CryptoEngine.h"
#include "aes-256/tiny-aes.h"
#include "configuration.h"
Expand Down Expand Up @@ -29,4 +31,5 @@ class NRF52CryptoEngine : public CryptoEngine
}
};

CryptoEngine *crypto = new NRF52CryptoEngine();
CryptoEngine *crypto = new NRF52CryptoEngine();
#endif // ARCH_NRF52
6 changes: 5 additions & 1 deletion src/platform/nrf52/alloc.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef ARCH_NRF52

#include "configuration.h"
#include "rtos.h"
#include <assert.h>
Expand Down Expand Up @@ -29,4 +31,6 @@ void operator delete(void *ptr)
void operator delete[](void *ptr)
{
rtos_free(ptr);
}
}

#endif // ARCH_NRF52
2 changes: 2 additions & 0 deletions src/platform/nrf52/hardfault.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef ARCH_NRF52
#include "configuration.h"
#include <core_cm4.h>

Expand Down Expand Up @@ -110,3 +111,4 @@ extern "C" void HardFault_Handler(void)
" handler2_address_const: .word HardFault_Impl \n");
}
#endif
#endif // ARCH_NRF52
3 changes: 3 additions & 0 deletions src/platform/nrf52/main-nrf52.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef ARCH_NRF52

#include "configuration.h"
#include <Adafruit_TinyUSB.h>
#include <Adafruit_nRFCrypto.h>
Expand Down Expand Up @@ -310,3 +312,4 @@ void enterDfuMode()
enterUf2Dfu();
#endif
}
#endif // ARCH_NRF52
5 changes: 4 additions & 1 deletion src/platform/portduino/PortduinoGlue.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef ARCH_PORTDUINO

#include "CryptoEngine.h"
#include "PortduinoGPIO.h"
#include "SPIChip.h"
Expand Down Expand Up @@ -417,4 +419,5 @@ bool loadConfig(const char *configPath)
static bool ends_with(std::string_view str, std::string_view suffix)
{
return str.size() >= suffix.size() && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
}
}
#endif // ARCH_PORTDUINO
4 changes: 3 additions & 1 deletion src/platform/rp2xx0/hardware_rosc/rosc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifdef ARCH_RP2040

#include "pico.h"

Expand Down Expand Up @@ -67,4 +68,5 @@ void rosc_set_dormant(void)
// Wait for it to become stable once woken up
while (!(rosc_hw->status & ROSC_STATUS_STABLE_BITS))
;
}
}
#endif // ARCH_RP2040
5 changes: 4 additions & 1 deletion src/platform/rp2xx0/main-rp2xx0.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef ARCH_RP2040

#include "configuration.h"
#include "hardware/xosc.h"
#include <hardware/clocks.h>
Expand Down Expand Up @@ -144,4 +146,5 @@ void initVariant()
/* Turn off USB PLL */
pll_deinit(pll_usb);
}
#endif
#endif
#endif // ARCH_RP2040
4 changes: 3 additions & 1 deletion src/platform/rp2xx0/pico_sleep/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifdef ARCH_RP2040

#include "pico.h"

Expand Down Expand Up @@ -152,4 +153,5 @@ void sleep_goto_dormant_until_pin(uint gpio_pin, bool edge, bool high)

// Clear the irq so we can go back to dormant mode again if we want
gpio_acknowledge_irq(gpio_pin, event);
}
}
#endif // ARCH_RP2040
4 changes: 4 additions & 0 deletions src/platform/stm32wl/main-stm32wl.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef ARCH_STM32WL

#include "RTC.h"
#include "configuration.h"
#include <stm32wle5xx.h>
Expand Down Expand Up @@ -26,3 +28,5 @@ void getMacAddr(uint8_t *dmac)
}

void cpuDeepSleep(uint32_t msecToWake) {}

#endif // ARCH_STM32WL
39 changes: 39 additions & 0 deletions variants/seeed_xiao_esp32c6/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[env:seeed-xiao-esp32c6]
extends = esp32c6_base
platform = https://github.com/pioarduino/platform-espressif32.git#60f9b158c4b83644f6d00722928a9ab04a93cfb9
framework = arduino, espidf
board = esp32-c6-devkitm-1
board_check = true
board_build.partitions = partition-table.csv
upload_protocol = esptool
upload_speed = 921600
monitor_speed = 460800
monitor_filters = esp32_c3_exception_decoder
extra_scripts = pre:bin/version_script.py
build_unflags =
-D HAS_BLUETOOTH=0
-D MESHTASTIC_EXCLUDE_BLUETOOTH
build_flags =
${esp32c6_base.build_flags}
-D PRIVATE_HW
-I variants/seeed_xiao_esp32c6
-D ARDUINO_USB_CDC_ON_BOOT=1
-D ARDUINO_USB_MODE=1
-L "${platformio.libdeps_dir}/${this.__env__}/bsec2/src/esp32c3"
-D HAS_BLUETOOTH=1
-D HAS_ETHERNET=0
-D MESHTASTIC_EXCLUDE_WEBSERVER
-D HAS_WIFI=0

board_build.embed_txtfiles =
managed_components/espressif__esp_insights/server_certs/https_server.crt
managed_components/espressif__esp_rainmaker/server_certs/rmaker_mqtt_server.crt
managed_components/espressif__esp_rainmaker/server_certs/rmaker_claim_service_server.crt
managed_components/espressif__esp_rainmaker/server_certs/rmaker_ota_server.crt

lib_deps =
${esp32c6_base.lib_deps}
https://github.com/h2zero/esp-nimble-cpp.git#38e764d15787f6cb1f3b6016a79ea72d7e37ce02

lib_ignore =
${esp32c6_base.lib_ignore}
Loading
Loading