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

arduino-esp32 2.0.x support #536

Merged
merged 153 commits into from
Jul 8, 2023
Merged
Show file tree
Hide file tree
Changes from 151 commits
Commits
Show all changes
153 commits
Select commit Hold shift + click to select a range
f7a684f
Exclude gtest dependent file from arduino lib
atanisoft Apr 17, 2021
54f0649
Add required stdint.h header for esp32 endian.h
atanisoft Apr 17, 2021
9fd56ea
WiFi updates for IDF v4.0+
atanisoft Apr 17, 2021
894489b
Initial pass at select() support for IDF v4.0+
atanisoft Apr 17, 2021
1832209
ESP-IDF based GPIO
atanisoft Apr 17, 2021
8eba514
Add arduino-esp32 2.0.0
atanisoft Apr 17, 2021
565033f
Build arduino platforms in parallel
atanisoft Apr 17, 2021
1a9ab7e
Restrict Esp32HardwareCan to only ESP32
atanisoft Apr 23, 2021
a93d476
Mark Esp32HardwareCan as deprecated
atanisoft Apr 23, 2021
552756b
Unify the IDF v4.0+ and v3.x select() VFS impl
atanisoft Apr 23, 2021
0d2272a
Further consolidation of IDF v3.x and IDF v4.x implementation for sel…
atanisoft Apr 29, 2021
cd6a401
Correct portYIELD_FROM_ISR call argument
atanisoft Apr 29, 2021
67c276e
Fix ESP32-C3 IS_GPIO_OUTPUT macro.
atanisoft May 1, 2021
afae71f
Add ESP32-S2 and ESP32-C3 temporary support for __atomic_exchange_1.
atanisoft May 1, 2021
ed8426d
Squash a few warnings for overriding defined values
atanisoft May 1, 2021
8f14daa
Add feature flag for HubDeviceNonBlock/HubDeviceSelect on SimpleCanSt…
atanisoft May 1, 2021
eb05f4e
Ensure the ESP32 variants used the printf variant of HASSERT/DIE
atanisoft May 1, 2021
f56b501
Add note for ESP32-C3 flash pins
atanisoft May 2, 2021
63f5e61
Adjust CpuLoad to work on single or dual core ESP32 chips
atanisoft May 3, 2021
b18adac
Adding WS2812 LED GPIO wrapper using the ESP32 RMT peripheral
atanisoft May 3, 2021
538f4c9
Expose TWAI driver (IDF v4.3+ only)
atanisoft May 3, 2021
c306aae
Initial ESP32-C3 examples
atanisoft May 3, 2021
d2b5ef9
Correct compilation step for esp32 variants
atanisoft May 3, 2021
138c21f
Exclude TWAI from IDF v4.2 and earlier.
atanisoft May 3, 2021
3e42e21
Add temporary CAN -> TWAI adapter to work around issues with the IDF …
atanisoft May 3, 2021
9fba485
Version restrict Esp32WS2812 to IDF v4.3+
atanisoft May 3, 2021
3043c2f
Disable CAN and TWAI by default.
atanisoft May 3, 2021
1c61bf1
Esp32 Bootloader support (TWAI only)
atanisoft May 4, 2021
3ce57c7
Add ESP32-S2 examples and update C3 examples to include variant in SNIP
atanisoft May 4, 2021
d9102f2
Adjust timing of WS2812 and add class docs
atanisoft May 4, 2021
071d768
Add concurrency guard to limit concurrent ESP32 dev builds.
atanisoft May 4, 2021
2ecd0cb
Adding utility class method for SoC info.
atanisoft May 4, 2021
71394a9
add log statements in ISR to debug IDF issue 5604 on ESP32-S2 WROVER …
atanisoft May 4, 2021
339a4c8
Update ESP32-C3 and ESP32-S2 CAN load test apps
atanisoft May 4, 2021
a970333
Add SoC info to ESP32IOBoard
atanisoft May 4, 2021
e609d1a
Name input/output groups
atanisoft May 4, 2021
03833e5
Add TWAI based bootloader to ESP32-S2/C3 IO Board
atanisoft May 4, 2021
da38c51
Correct path to rom/rtc.h for IDF v3.x
atanisoft May 4, 2021
7bb00a8
test matrix build for esp32 dev
atanisoft May 4, 2021
c2233fa
try num 2 for matrix build
atanisoft May 4, 2021
6054031
try num 3
atanisoft May 4, 2021
0eeb6a9
try num 4
atanisoft May 4, 2021
777c540
try num 5
atanisoft May 4, 2021
175bb8e
fix rom/rtc.h logic
atanisoft May 4, 2021
894985c
version mask IDF v4.x APIs
atanisoft May 4, 2021
a130e80
Adjust MultiConfiguredPC to work on the Arduino
atanisoft May 10, 2021
2064f30
WiFi updates for IDF v4.0+
atanisoft May 15, 2021
13a3c48
Converting TWAI stats task to be a watchdog and stats task.
atanisoft May 15, 2021
eaa5383
Add DummyGPIO to Arduino tree
atanisoft May 15, 2021
6b43951
Add check for CONFIG_VFS_SUPPORT_SELECT to protect select() usages wi…
atanisoft May 15, 2021
2c54a4c
Update documentation in examples and expose TWAI for ESP32IOBoard
atanisoft May 15, 2021
447bd7b
Fix variable reference from wifi_manager_task.
atanisoft May 15, 2021
865617d
Fix ESP32S2CanLoadTest example
atanisoft May 15, 2021
901f0ad
Cleanup headers in CanLoadTest examples.
atanisoft May 15, 2021
a15319e
Add missing include
atanisoft May 18, 2021
359035e
Simplify ESP32 OSSelectWakeup code to only use exceptfds since that i…
atanisoft May 18, 2021
9f636fe
Updating TWAI driver to use LOG(X..) instead of ESP_LOGX since logs a…
atanisoft May 18, 2021
534153e
Allow log_output override for ESP32
atanisoft May 18, 2021
09aca29
Updates to the C3 and S2 examples to expose TWAI select usage and pri…
atanisoft May 18, 2021
6d2db07
Add missing ESP32 checks for ESP-IDF usage
atanisoft May 24, 2021
947ed2a
Correct ESP32-C3/S3 chip id name.
atanisoft May 24, 2021
81e0f0f
remove unused variable
atanisoft May 24, 2021
ecdde30
Add ESP32-PICO-V3 and technical reference links
atanisoft May 24, 2021
0374e27
Removed blocking mode from documentation, clarified on the requiremen…
atanisoft May 24, 2021
d26056d
Correct documentation note for the on-board LED
atanisoft May 24, 2021
a06348b
fix missing comma and add chip_id to log statements
atanisoft May 26, 2021
d938e7b
init variable to correct IDF build failure
atanisoft May 26, 2021
e3a6c25
use esp_rom_gpio APIs
atanisoft May 26, 2021
a183495
Split out create_config_descriptor_xml so it can be used without ardu…
atanisoft May 26, 2021
cd4f737
Update libify.sh
atanisoft May 26, 2021
6bea7e1
Add shutdown method for the GcTcpHub
atanisoft May 30, 2021
bdbdd6c
Add ServoConsumer support for arduino/ESP32
atanisoft May 30, 2021
ad41952
Add code to prevent overflow when dividing deadline_nsec.
atanisoft May 30, 2021
59f37c0
Add stack_malloc support since arduino-esp32 2.0 enables FreeRTOS sta…
atanisoft May 30, 2021
b881a5b
Move to using the GcTcpHub from SimpleStackBase rather than maintain …
atanisoft May 30, 2021
30002bf
Adjust CpuLoad tracking after more extensive testing
atanisoft May 30, 2021
3c853d0
Merge branch 'md-esp20' of github.com:bakerstu/openmrn into md-esp20
atanisoft May 30, 2021
c53cb01
Adding Esp32Ledc PWM signal generator
atanisoft Jun 2, 2021
87779b8
Move Esp32Ledc to IDF v4.3+
atanisoft Jun 2, 2021
61a1e0f
IDF version check in cxx
atanisoft Jun 2, 2021
741b6c5
Merge branch 'master' into md-esp20
atanisoft Jun 2, 2021
96ef7da
Add LocalTrackIf to arduino build (feature flag gated)
atanisoft Jun 8, 2021
34b21d8
Make Esp32SocInfo always check PRO_CPU and clarify comment as to why
atanisoft Jun 8, 2021
e0ec8f5
Remove "have_hub" since it is not used now.
atanisoft Jun 11, 2021
dc8b0a4
Remove ESP32 customizations for libatomic as they are now implemented…
atanisoft Jun 11, 2021
7682b23
Clarify comments further on Esp32SocInfo
atanisoft Jun 11, 2021
aebb477
Simplify ESP32 Atomic to use new macros from ESP-IDF v3.3
atanisoft Jun 11, 2021
7060668
Allow defaulting and overriding constants with expansion
atanisoft Jun 11, 2021
fab0e84
Add logging for GPIO initialization
atanisoft Jun 11, 2021
2897125
Move runtime TWAI statistics to a dedicated structure to avoid incorr…
atanisoft Jun 11, 2021
a4df2ad
Add dcc_constants and RailComDriver files to arduino build
atanisoft Jun 11, 2021
758a4f3
Add SNTP callback registration
atanisoft Jun 11, 2021
7859564
Merge branch 'master' into md-esp20
atanisoft Jun 11, 2021
c8f575b
1. Add option to disable both Hub and Uplink.
atanisoft Jun 14, 2021
d937bc5
merge master into md-esp20
atanisoft Jul 25, 2021
d191456
Disable socket fstat validation for ESP32 due to IDF not implementing…
atanisoft Jul 25, 2021
5b47f20
Add ADC_PIN wrapper for initializing/sampling ADC inputs.
atanisoft Jul 25, 2021
45e5cd3
Add locking and only advance TX queue upon success TX.
atanisoft Jul 25, 2021
fb81429
Move Esp32WiFiManager to use a StateFlow pattern and drop the extra t…
atanisoft Jul 25, 2021
9aee231
Fix typo in PSRAM details.
atanisoft Jul 25, 2021
5e4c644
Merge branch 'master' into md-esp20
atanisoft Aug 31, 2021
c4b4621
Comment esp32-dev since 2.0.0 has been released.
atanisoft Aug 31, 2021
1aad092
Workaround for broken endian.h stdint.h dependency on esp32
atanisoft Aug 31, 2021
b87a974
Add minimal support for ESP32-H2 SoC
atanisoft Sep 2, 2021
c126c0b
Only update WiFi config if minimums are not met
atanisoft Sep 2, 2021
f42c6c7
Add documentation to esp32 bootloader code and cleanup examples
atanisoft Sep 2, 2021
70271db
Fix default parameter for softap name/pw and reduce executor priority…
atanisoft Sep 8, 2021
94ba080
Update docs for pin assignments
atanisoft Sep 23, 2021
8a24b79
Update reset reason text based on latest IDF
atanisoft Sep 24, 2021
8184d30
Start Esp32WiFiManager Executor pinned to core on multi-core SoC
atanisoft Oct 9, 2021
afb3bbb
Expose method for retrievial of TWAI stats
atanisoft Oct 9, 2021
86fa0aa
ESP32-S3 support
atanisoft Oct 19, 2021
6241644
cleanup in VFS start_select functions, nfds will always be at least one.
atanisoft Oct 25, 2021
dcf3c07
Split ESP32-S2 and ESP32-S3 GpioInputPin checks.
atanisoft Nov 4, 2021
0544953
IDF v5+ support
atanisoft Jan 17, 2022
1fcd79c
Move rtc.h include to header
atanisoft Jan 17, 2022
b2adaaf
Add missing sdkconfig.h include
atanisoft Jan 17, 2022
597e651
Merge branch 'master' into md-esp20
atanisoft Jan 19, 2022
977313d
Renamed ESP8684 -> ESP32-C2 per IDF v5 rename.
atanisoft Jan 20, 2022
b39a326
Merge branch 'master' into md-esp20
atanisoft Aug 4, 2022
f56824e
Recent updates from OpenMRNIDF
atanisoft Aug 4, 2022
2a04a8f
remove w/a for https://github.com/espressif/esp-idf/issues/7498
atanisoft Aug 4, 2022
e3c7a97
arduino-esp32 1.0.x bug fix for rom/gpio.h reference
atanisoft Aug 4, 2022
d438180
Style fix for CDIXMLGenerator.hxx
atanisoft Aug 4, 2022
83017bb
adjust can_ioctl.h includes for arduino.
atanisoft Aug 4, 2022
abed301
uniquely name the GcTcpHub listener.
atanisoft Aug 4, 2022
d71a3db
Adjust WS2812 RMT channel details for ESP32-S3
atanisoft Aug 12, 2022
0f6173c
Feedback updates:
atanisoft Aug 25, 2022
d461651
Fix variable reference
atanisoft Aug 25, 2022
3af9acd
Esp32Ledc documentation and code updates from feedback.
atanisoft Aug 25, 2022
093c4c9
Remove IO reference from factory_reset
atanisoft Aug 25, 2022
88bed80
Fix HASSERT validations.
atanisoft Aug 25, 2022
df601b1
Update IO board examples with note on OTA partition requirement.
atanisoft Aug 25, 2022
c595eba
Increase SNIPClient default timeout by 500ms.
atanisoft Sep 14, 2022
e5aba8f
Switch ADC API due to ESP32-C3 not supporting per-channel ADC bit width.
atanisoft Sep 26, 2022
0dff897
Merge branch 'master' into md-esp20
atanisoft Sep 26, 2022
f7096b6
Add core dump conversion utility.
atanisoft Sep 26, 2022
e0081ec
Silence compiler warnings in Esp32Ledc
atanisoft Sep 26, 2022
4642143
Add override for mdns_unpublish API
atanisoft Sep 26, 2022
c2e7b6a
Merge branch 'master' into md-esp20
atanisoft Oct 16, 2022
07a7c80
Merge branch 'master' into md-esp20
atanisoft Oct 24, 2022
187cc34
Move includes outside namespace to prevent unintentional namespace bo…
atanisoft Oct 26, 2022
52b9de0
Merge branch 'master' into md-esp20
atanisoft Nov 29, 2022
55b2331
Merge branch 'master' into md-esp20
atanisoft Jan 23, 2023
a38a53d
Update based on OpenMRNIDF edits
atanisoft Jan 23, 2023
e68ea8b
Fix case where Esp32WiFiManager was not correctly cleaning up the pre…
atanisoft Feb 3, 2023
100f4b4
Merge branch 'master' into md-esp20
balazsracz Feb 5, 2023
a647db9
Merge branch 'master' into md-esp20
balazsracz Feb 5, 2023
87050e8
Remove Esp32WS2812 in favor of using led_strip IDF component or Ardui…
atanisoft Feb 6, 2023
06cb5f1
Sync from OpenMRNIDF
atanisoft Feb 6, 2023
f98aa20
remove sdkconfig reference.
atanisoft Feb 6, 2023
2514cb0
Fixes compile error under linux.
balazsracz Jul 8, 2023
ad6459c
Merge branch 'master' into md-esp20
balazsracz Jul 8, 2023
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
52 changes: 43 additions & 9 deletions .github/workflows/ArduinoBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ on:
- '**ArduinoBuild.yml'
pull_request:
jobs:
build:
name: Build ESP32 examples
build-stm32:
name: Build Arduino STM32 examples
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -29,21 +29,55 @@ jobs:
$GITHUB_WORKSPACE/arduino/libify.sh $HOME/Arduino/libraries/OpenMRNLite $GITHUB_WORKSPACE -f -l
rm -f $GITHUB_WORKSPACE/arduino/examples/Stm*/build_opt.h

- name: Compile all STM32 examples
uses: ArminJo/arduino-test-compile@v3.0.0
- name: Compile STM32 examples
uses: ArminJo/arduino-test-compile@v3
with:
platform-url: https://raw.githubusercontent.com/stm32duino/BoardManagerFiles/master/STM32/package_stm_index.json
arduino-board-fqbn: STM32:stm32:Nucleo_144:pnum=NUCLEO_F767ZI,upload_method=MassStorage,xserial=generic,usb=CDCgen,xusb=FS,opt=osstd,rtlib=nano
sketch-names: Stm32*.ino
build-properties: '{ "All": "-DHAL_CAN_MODULE_ENABLED" }'
debug-compile: true

- name: Compile all ESP32 examples
uses: ArminJo/[email protected]

build-esp32:
name: Build Arduino ${{ matrix.target }} examples
runs-on: ubuntu-latest
strategy:
max-parallel: 2
matrix:
target: [esp32, esp32c3, esp32s2]
steps:
- name: Checkout
uses: actions/checkout@master

- name: Generate OpenMRNLite library
run: |
mkdir --parents $HOME/Arduino/libraries/OpenMRNLite
$GITHUB_WORKSPACE/arduino/libify.sh $HOME/Arduino/libraries/OpenMRNLite $GITHUB_WORKSPACE -f -l
rm -f $GITHUB_WORKSPACE/arduino/examples/Stm*/build_opt.h

- name: Compile ESP32 examples
uses: ArminJo/arduino-test-compile@v3
with:
platform-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
arduino-board-fqbn: esp32:esp32:node32s
sketch-names: ESP*.ino
sketch-names: ESP32CanLoadTest.ino,ESP32IOBoard.ino,ESP32SerialBridge.ino,ESP32WifiCanBridge.ino
debug-compile: true
if: ${{ matrix.target == 'esp32' }}


- name: Compile ESP32-C3 examples
uses: ArminJo/arduino-test-compile@v3
with:
platform-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
arduino-board-fqbn: esp32:esp32:esp32c3
sketch-names: ESP32C3CanLoadTest.ino,ESP32C3IOBoard.ino
debug-compile: true
if: ${{ matrix.target == 'esp32c3' }}

- name: Compile ESP32-S2 examples
uses: ArminJo/arduino-test-compile@v3
with:
platform-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
arduino-board-fqbn: esp32:esp32:esp32s2
sketch-names: ESP32S2CanLoadTest.ino,ESP32S2IOBoard.ino
debug-compile: true
if: ${{ matrix.target == 'esp32s2' }}
126 changes: 126 additions & 0 deletions arduino/CDIXMLGenerator.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/** \copyright
* Copyright (c) 2018, Balazs Racz
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* \file CDIXMLGenerator.hxx
*
* Standalone CDI XML generation class.
*
* @author Balazs Racz, Mike Dunston
* @date 24 July 2018
*/

#ifndef _CDIXMLGENERATOR_HXX_
#define _CDIXMLGENERATOR_HXX_

#include "openlcb/SimpleStack.hxx"
#include "utils/FileUtils.hxx"

/// Standalone utility class for generating the XML representation of the node
/// configuration structure. This is primarily used in Arduino environments.
class CDIXMLGenerator
{
public:
/// Creates the XML representation of the configuration structure and saves
/// it to a file on the filesystem. Must be called after SPIFFS.begin() but
/// before calling the {\link create_config_file_if_needed} method. The
/// config file will be re-written whenever there was a change in the
/// contents. It is also necessary to declare the static compiled-in CDI to
/// be empty:
/// ```
/// namespace openlcb {
/// // This will stop openlcb from exporting the CDI memory space
/// // upon start.
/// extern const char CDI_DATA[] = "";
/// } // namespace openlcb
/// ```
/// @param cfg is the global configuration instance (usually called cfg).
/// @param filename is where the xml file can be stored on the
/// filesystem. For example "/spiffs/cdi.xml".
/// @return true if the configuration xml file was modified by this method,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing documentation of the "stack" variable. Also add to the docs that this method also exports the memory space if stack is specified.

/// false if the file was already up-to-date.
template <class ConfigDef>
static bool create_config_descriptor_xml(
const ConfigDef &config, const char *filename,
openlcb::SimpleStackBase *stack = nullptr)
{
string cdi_string;
ConfigDef cfg(config.offset());
cfg.config_renderer().render_cdi(&cdi_string);

cdi_string += '\0';

bool need_write = false;
LOG(INFO, "[CDI] Checking %s...", filename);
FILE *ff = fopen(filename, "rb");
if (!ff)
{
LOG(INFO, "[CDI] File %s does not exist", filename);
need_write = true;
}
else
{
fclose(ff);
string current_str = read_file_to_string(filename);
if (current_str != cdi_string)
{
LOG(INFO, "[CDI] File %s is not up-to-date", filename);
need_write = true;
}
else
{
LOG(INFO, "[CDI] File %s appears up-to-date (len %u vs %u)",
filename, current_str.size(), cdi_string.size());
}
}
if (need_write)
{
LOG(INFO, "[CDI] Updating %s (len %u)", filename,
cdi_string.size());
write_string_to_file(filename, cdi_string);
}

if (stack)
{
LOG(INFO, "[CDI] Registering CDI with stack...");
// Creates list of event IDs for factory reset.
auto *v = new vector<uint16_t>();
cfg.handle_events([v](unsigned o) { v->push_back(o); });
v->push_back(0);
stack->set_event_offsets(v);
// We leak v because it has to stay alive for the entire lifetime
// of the stack.

// Add the file memory space to the stack.
openlcb::MemorySpace *space =
new openlcb::ROFileMemorySpace(filename);
stack->memory_config_handler()->registry()->insert(
stack->node(), openlcb::MemoryConfigDefs::SPACE_CDI, space);
}
return need_write;
}
};

#endif // _CDIXMLGENERATOR_HXX_
129 changes: 80 additions & 49 deletions arduino/OpenMRNLite.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

#include <Arduino.h>

#include "freertos_drivers/arduino/ArduinoGpio.hxx"
#include "CDIXMLGenerator.hxx"
#include "freertos_drivers/arduino/Can.hxx"
#include "freertos_drivers/arduino/WifiDefs.hxx"
#include "openlcb/SimpleStack.hxx"
Expand All @@ -49,25 +49,57 @@

#if defined(ESP32)

#include <esp_idf_version.h>
#include <esp_task.h>
#include <esp_task_wdt.h>

namespace openmrn_arduino {
namespace openmrn_arduino
{

/// Default stack size to use for all OpenMRN tasks on the ESP32 platform.
constexpr uint32_t OPENMRN_STACK_SIZE = 4096L;

/// Default thread priority for any OpenMRN owned tasks on the ESP32 platform.
/// ESP32 hardware CAN RX and TX tasks run at lower priority (-1 and -2
/// respectively) of this default priority to ensure timely consumption of CAN
/// frames from the hardware driver.
/// Note: This is set to one priority level lower than the TCP/IP task uses on
/// the ESP32.
constexpr UBaseType_t OPENMRN_TASK_PRIORITY = ESP_TASK_TCPIP_PRIO - 1;

} // namespace openmrn_arduino

#include "freertos_drivers/esp32/Esp32Gpio.hxx"
#include "freertos_drivers/esp32/Esp32SocInfo.hxx"

#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4,3,0)

// If we are using ESP-IDF v4.3 (or later) enable the Esp32Ledc API.
#include "freertos_drivers/esp32/Esp32Ledc.hxx"

// ESP32-H2 and ESP32-C2 do not have a built-in TWAI controller.
#if !defined(CONFIG_IDF_TARGET_ESP32H2) && !defined(CONFIG_IDF_TARGET_ESP32C2)

// If we are using ESP-IDF v4.3 (or later) enable the usage of the TWAI device
// which allows usage of the filesystem based CAN interface methods.
#include "freertos_drivers/esp32/Esp32HardwareTwai.hxx"
#define HAVE_CAN_FS_DEVICE

// The ESP-IDF VFS layer has an optional wrapper around the select() interface
// when disabled we can not use select() for the CAN/TWAI driver. Normally this
// is enabled for arduino-esp32.
#if CONFIG_VFS_SUPPORT_SELECT
#define HAVE_CAN_FS_SELECT
#endif

#endif // NOT ESP32-H2 and NOT ESP32-C2

#endif // IDF v4.3+

#if defined(CONFIG_IDF_TARGET_ESP32)
// Note: This code is deprecated in favor of the TWAI interface which exposes
// both select() and fnctl() interfaces. Support for this may be removed in the
// future.
#include "freertos_drivers/esp32/Esp32HardwareCanAdapter.hxx"
#endif // ESP32 only

#include "freertos_drivers/esp32/Esp32HardwareSerialAdapter.hxx"
#include "freertos_drivers/esp32/Esp32WiFiManager.hxx"

Expand All @@ -79,11 +111,13 @@ constexpr UBaseType_t OPENMRN_TASK_PRIORITY = ESP_TASK_TCPIP_PRIO - 1;

#ifdef ARDUINO_ARCH_STM32

#include "freertos_drivers/arduino/ArduinoGpio.hxx"
#include "freertos_drivers/stm32/Stm32Can.hxx"

#endif

namespace openmrn_arduino {
namespace openmrn_arduino
{

/// Bridge class that connects an Arduino API style serial port (sending CAN
/// frames via gridconnect format) to the OpenMRN core stack. This can be
Expand Down Expand Up @@ -409,9 +443,9 @@ class OpenMRN : private Executable
, OPENMRN_TASK_PRIORITY // priority
, nullptr // task handle
, PRO_CPU_NUM); // cpu core
#else
#else // NOT ESP32
stack_->executor()->start_thread(
"OpenMRN", OPENMRN_TASK_PRIORITY, OPENMRN_STACK_SIZE);
"OpenMRN", 0 /* default priority */, 0 /* default stack size */);
#endif // ESP32
}
#endif // OPENMRN_FEATURE_SINGLE_THREADED
Expand Down Expand Up @@ -444,6 +478,40 @@ class OpenMRN : private Executable
loopMembers_.push_back(new CanBridge(port, stack()->can_hub()));
}

#if defined(HAVE_CAN_FS_DEVICE)
/// Adds a CAN bus port with synchronous driver API.
void add_can_port_blocking(const char *device)
{
stack_->add_can_port_blocking(device);
}

/// Adds a CAN bus port with asynchronous driver API.
void add_can_port_async(const char *device)
{
stack_->add_can_port_async(device);
}

#if defined(HAVE_CAN_FS_SELECT)
/// Adds a CAN bus port with select-based asynchronous driver API.
///
/// NOTE: Be sure to call @ref start_executor_thread in the setup() method.
void add_can_port_select(const char *device)
{
stack_->add_can_port_select(device);
}

/// Adds a CAN bus port with select-based asynchronous driver API.
/// @param fd file descriptor to add to can hub
/// @param on_error Notifiable to wakeup on error
///
/// NOTE: Be sure to call @ref start_executor_thread in the setup() method.
void add_can_port_select(int fd, Notifiable *on_error = nullptr)
{
stack_->add_can_port_select(fd, on_error);
}
#endif // HAVE_CAN_FS_SELECT
#endif // HAVE_CAN_FS_DEVICE

#if defined(HAVE_FILESYSTEM)
/// Creates the XML representation of the configuration structure and saves
/// it to a file on the filesystem. Must be called after SPIFFS.begin() but
Expand All @@ -461,50 +529,13 @@ class OpenMRN : private Executable
/// @param cfg is the global configuration instance (usually called cfg).
/// @param filename is where the xml file can be stored on the
/// filesystem. For example "/spiffs/cdi.xml".
/// @returns true if the cdi.xml was updated, false otherwise.
template <class ConfigDef>
void create_config_descriptor_xml(
bool create_config_descriptor_xml(
const ConfigDef &config, const char *filename)
{
string cdi_string;
ConfigDef cfg(config.offset());
cfg.config_renderer().render_cdi(&cdi_string);

cdi_string += '\0';

bool need_write = false;
FILE *ff = fopen(filename, "rb");
if (!ff)
{
need_write = true;
}
else
{
fclose(ff);
string current_str = read_file_to_string(filename);
if (current_str != cdi_string)
{
need_write = true;
}
}
if (need_write)
{
LOG(INFO, "Updating CDI file %s (len %u)", filename,
cdi_string.size());
write_string_to_file(filename, cdi_string);
}

// Creates list of event IDs for factory reset.
auto *v = new vector<uint16_t>();
cfg.handle_events([v](unsigned o) { v->push_back(o); });
v->push_back(0);
stack()->set_event_offsets(v);
// We leak v because it has to stay alive for the entire lifetime of
// the stack.

// Exports the file memory space.
openlcb::MemorySpace *space = new openlcb::ROFileMemorySpace(filename);
stack()->memory_config_handler()->registry()->insert(
stack()->node(), openlcb::MemoryConfigDefs::SPACE_CDI, space);
return CDIXMLGenerator::create_config_descriptor_xml(
config, filename, stack());
}
#endif // HAVE_FILESYSTEM

Expand Down
1 change: 1 addition & 0 deletions arduino/examples/ESP32C3CanLoadTest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wifi_params.cpp
Loading