Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 9 additions & 2 deletions CMake/Modules/FindNF_NativeAssemblies.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#
#
# Copyright (c) .NET Foundation and Contributors
# See LICENSE file in the project root for full license information.
#
Expand Down Expand Up @@ -38,6 +38,7 @@ option(API_nanoFramework.System.Security.Cryptography "option for nanoFramewor
# Esp32 only
option(API_Hardware.Esp32 "option for Hardware.Esp32")
option(API_nanoFramework.Hardware.Esp32.Rmt "option for nanoFramework.Hardware.Esp32.Rmt")
option(API_nanoFramework.EspNow "option for nanoFramework.EspNow")
option(API_nanoFramework.Networking.Thread "option for nanoFramework.Networking.Thread API")

# Stm32 only
Expand Down Expand Up @@ -252,6 +253,12 @@ if(API_nanoFramework.Hardware.Esp32.Rmt)
PerformSettingsForApiEntry("nanoFramework.Hardware.Esp32.Rmt")
endif()

# nanoFramework.EspNow
if(API_nanoFramework.EspNow)
##### API name here (doted name)
PerformSettingsForApiEntry("nanoFramework.EspNow")
endif()

# nanoFramework.Networking.Thread
if(API_nanoFramework.Networking.Thread)
##### API name here (doted name)
Expand Down Expand Up @@ -565,4 +572,4 @@ macro(nf_add_lib_native_assemblies)
# add alias
add_library("nano::${LIB_NAME}" ALIAS ${LIB_NAME})

endmacro()
endmacro()
41 changes: 41 additions & 0 deletions CMake/Modules/FindnanoFramework.EspNow.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# Copyright (c) .NET Foundation and Contributors
# See LICENSE file in the project root for full license information.
#

# native code directory
set(BASE_PATH_FOR_THIS_MODULE ${BASE_PATH_FOR_CLASS_LIBRARIES_MODULES}/nanoFramework.EspNow)


# set include directories
list(APPEND nanoFramework.EspNow_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src/CLR/Core)
list(APPEND nanoFramework.EspNow_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src/CLR/Include)
list(APPEND nanoFramework.EspNow_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src/HAL/Include)
list(APPEND nanoFramework.EspNow_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src/PAL/Include)
list(APPEND nanoFramework.EspNow_INCLUDE_DIRS ${BASE_PATH_FOR_THIS_MODULE})

# source files
set(nanoFramework.EspNow_SRCS
nanoFramework_espnow_native.cpp
nanoFramework_espnow_native_nanoFramework_EspNow_EspNowController.cpp
)

foreach(SRC_FILE ${nanoFramework.EspNow_SRCS})
set(nanoFramework.EspNow_SRC_FILE SRC_FILE-NOTFOUND)
find_file(nanoFramework.EspNow_SRC_FILE ${SRC_FILE}
PATHS
${BASE_PATH_FOR_THIS_MODULE}
${TARGET_BASE_LOCATION}
CMAKE_FIND_ROOT_PATH_BOTH
)

if (BUILD_VERBOSE)
message("${SRC_FILE} >> ${nanoFramework.EspNow_SRC_FILE}")
endif()

list(APPEND nanoFramework.EspNow_SOURCES ${nanoFramework.EspNow_SRC_FILE})
endforeach()

include(FindPackageHandleStandardArgs)

FIND_PACKAGE_HANDLE_STANDARD_ARGS(nanoFramework.EspNow DEFAULT_MSG nanoFramework.EspNow_INCLUDE_DIRS nanoFramework.EspNow_SOURCES)
1 change: 1 addition & 0 deletions CMake/Modules/NF_Kconfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ set(_NF_KCONFIG_API_MAP
"API_NANOFRAMEWORK_SYSTEM_TEXT|API_nanoFramework.System.Text"
"API_NANOFRAMEWORK_SYSTEM_SECURITY_CRYPTOGRAPHY|API_nanoFramework.System.Security.Cryptography"
"API_NANOFRAMEWORK_SYSTEM_IO_HASHING|API_nanoFramework.System.IO.Hashing"
"API_NANOFRAMEWORK_ESPNOW|API_nanoFramework.EspNow"
"API_NANOFRAMEWORK_NETWORKING_THREAD|API_nanoFramework.Networking.Thread"

# Platform-specific APIs
Expand Down
5 changes: 5 additions & 0 deletions Kconfig.apis
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ config API_NANOFRAMEWORK_SYSTEM_IO_HASHING
bool "nanoFramework.System.IO.Hashing"
default n

config API_NANOFRAMEWORK_ESPNOW
bool "nanoFramework.EspNow"
depends on RTOS_ESP32
default n

Comment thread
torbacz marked this conversation as resolved.
config API_NANOFRAMEWORK_NETWORKING_THREAD
bool "nanoFramework.Networking.Thread"
default n
Expand Down
5 changes: 5 additions & 0 deletions src/CLR/Core/Hardware/Hardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ void CLR_HW_Hardware::ProcessActivity()
eventsCLR |= Event_RmtRx;
}

if (events & SYSTEM_EVENT_FLAG_ESPNOW)
{
eventsCLR |= Event_EspNow;
}

if (events & SYSTEM_EVENT_FLAG_ONEWIRE_MASTER)
{
eventsCLR |= Event_OneWireHost;
Expand Down
3 changes: 2 additions & 1 deletion src/CLR/Include/nanoCLR_Hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ struct CLR_HW_Hardware
SYSTEM_EVENT_FLAG_SPI_MASTER | SYSTEM_EVENT_FLAG_I2C_MASTER | SYSTEM_EVENT_FLAG_I2C_SLAVE |
SYSTEM_EVENT_HW_INTERRUPT | SYSTEM_EVENT_FLAG_SOCKET | SYSTEM_EVENT_FLAG_DEBUGGER_ACTIVITY |
SYSTEM_EVENT_FLAG_MESSAGING_ACTIVITY | SYSTEM_EVENT_FLAG_ONEWIRE_MASTER | SYSTEM_EVENT_FLAG_RADIO |
SYSTEM_EVENT_FLAG_WIFI_STATION | SYSTEM_EVENT_FLAG_BLUETOOTH | SYSTEM_EVENT_FLAG_RMT_RX;
SYSTEM_EVENT_FLAG_WIFI_STATION | SYSTEM_EVENT_FLAG_BLUETOOTH | SYSTEM_EVENT_FLAG_RMT_RX |
SYSTEM_EVENT_FLAG_ESPNOW;
//--//

struct HalInterruptRecord
Expand Down
1 change: 1 addition & 0 deletions src/CLR/Include/nanoCLR_Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -3499,6 +3499,7 @@ typedef enum Events
Event_IO = 0x00008000,
Event_I2cSlave = 0x00010000,
Event_RmtRx = 0x00020000,
Event_EspNow = 0x00040000,
Event_AppDomain = 0x02000000,
Event_Socket = 0x20000000,
Event_IdleCPU = 0x40000000,
Expand Down
3 changes: 2 additions & 1 deletion src/HAL/Include/nanoHAL_v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ typedef enum SLEEP_LEVEL

#define SYSTEM_EVENT_FLAG_RMT_RX 0x00080000

// #define SYSTEM_EVENT_FLAG_UNUSED_0x00100000 0x00100000
#define SYSTEM_EVENT_FLAG_ESPNOW 0x00100000

// #define SYSTEM_EVENT_FLAG_UNUSED_0x00200000 0x00200000
// #define SYSTEM_EVENT_FLAG_UNUSED_0x00400000 0x00400000
Expand Down Expand Up @@ -113,6 +113,7 @@ typedef enum SLEEP_LEVEL
#define EVENT_TOUCH 120
#define EVENT_GESTURE 130
#define EVENT_OPENTHREAD 140
#define EVENT_ESPNOW 150

#define PAL_EVENT_TOUCH 0x1
#define PAL_EVENT_KEY 0x2
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.

#include "nanoFramework_espnow_native.h"

// clang-format off

static const CLR_RT_MethodHandler method_lookup[] =
{
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
Library_nf_espnow_nanoFramework_EspNow_EspNowController::NativeInitialize___I4,
Library_nf_espnow_nanoFramework_EspNow_EspNowController::NativeDispose___VOID__BOOLEAN,
Library_nf_espnow_nanoFramework_EspNow_EspNowController::NativeEspNowSend___I4__SZARRAY_U1__SZARRAY_U1__I4,
Library_nf_espnow_nanoFramework_EspNow_EspNowController::NativeEspNowAddPeer___I4__SZARRAY_U1__U1__BOOLEAN__SZARRAY_U1,
Library_nf_espnow_nanoFramework_EspNow_EspNowController::NativeGetMaximumDataLength___I4,
Library_nf_espnow_nanoFramework_EspNow_EspNowController::NativeReadPacket___I4__SZARRAY_U1__SZARRAY_U1__I4,
Library_nf_espnow_nanoFramework_EspNow_EspNowController::NativeGetReceiveOverflowCount___I4,
Library_nf_espnow_nanoFramework_EspNow_EspNowController::NativeReadSendStatus___I4__SZARRAY_U1,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
};

const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_nanoFramework_EspNow =
{
"nanoFramework.EspNow",
0x65E7BDBE,
method_lookup,
{ 100, 0, 0, 1 }
};

// clang-format on
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

#ifndef NANOFRAMEWORK_ESPNOW_NATIVE_H
#define NANOFRAMEWORK_ESPNOW_NATIVE_H

#include <nanoCLR_Interop.h>
#include <nanoCLR_Runtime.h>
#include <nanoPackStruct.h>
#include <corlib_native.h>
#include <nanoHAL.h>

#include <esp_interface.h>
#include <esp_wifi.h>
#include <esp_now.h>

#ifdef ESP_NOW_MAX_DATA_LEN_V2
#define NF_ESPNOW_MAX_DATA_LEN ESP_NOW_MAX_DATA_LEN_V2
#else
#define NF_ESPNOW_MAX_DATA_LEN ESP_NOW_MAX_DATA_LEN
#endif

static constexpr uint32_t NF_ESPNOW_RX_QUEUE_DEPTH = 10;

typedef enum __nfpack EspNowEventType
{
EspNowEventType_DataSent = 1,
EspNowEventType_DataReceived = 2,
} EspNowEventType;

typedef enum __nfpack EspNowSendStatus
{
EspNowSendStatus_Success = 0,
EspNowSendStatus_Fail = 1,
} EspNowSendStatus;

struct EspNowPacket
{
uint8_t peer_mac[ESP_NOW_ETH_ALEN];
uint8_t *data;
uint16_t data_len;
};

struct Library_nf_espnow_nanoFramework_EspNow_DataReceivedEventArgs
{
static const int FIELD___peerMac = 1;
static const int FIELD___data = 2;
static const int FIELD___dataLen = 3;

//--//
};

struct Library_nf_espnow_nanoFramework_EspNow_DataSentEventArgs
{
static const int FIELD___peerMac = 1;
static const int FIELD___status = 2;

//--//
};

struct Library_nf_espnow_nanoFramework_EspNow_EspNowController
{
static const int FIELD_STATIC__s_instance = 0;
static const int FIELD_STATIC__s_syncLock = 1;
static const int FIELD_STATIC__s_eventListener = 2;

static const int FIELD___disposed = 1;
static const int FIELD___syncLock = 2;
static const int FIELD___callbacksDataReceivedEvent = 3;
static const int FIELD___callbacksDataSentEvent = 4;

NANOCLR_NATIVE_DECLARE(NativeInitialize___I4);
NANOCLR_NATIVE_DECLARE(NativeDispose___VOID__BOOLEAN);
NANOCLR_NATIVE_DECLARE(NativeEspNowSend___I4__SZARRAY_U1__SZARRAY_U1__I4);
NANOCLR_NATIVE_DECLARE(NativeEspNowAddPeer___I4__SZARRAY_U1__U1__BOOLEAN__SZARRAY_U1);
NANOCLR_NATIVE_DECLARE(NativeGetMaximumDataLength___I4);
NANOCLR_NATIVE_DECLARE(NativeReadPacket___I4__SZARRAY_U1__SZARRAY_U1__I4);
NANOCLR_NATIVE_DECLARE(NativeGetReceiveOverflowCount___I4);
NANOCLR_NATIVE_DECLARE(NativeReadSendStatus___I4__SZARRAY_U1);

//--//
static void DataSentCb(const wifi_tx_info_t *tx_info, esp_now_send_status_t status);
static void DataRecvCb(const esp_now_recv_info *recv_info, const uint8_t *incomingData, int len);
};

struct Library_nf_espnow_nanoFramework_EspNow_EspNowEvent
{
static const int FIELD__EventType = 3;

//--//
};

struct Library_nf_espnow_nanoFramework_EspNow_EspNowEventListener
{
static const int FIELD___controller = 1;

//--//
};

struct Library_nf_espnow_nanoFramework_EspNow_EspNowException
{
static const int FIELD___espErr = 5;

//--//
};

extern const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_nanoFramework_EspNow;

#endif // NANOFRAMEWORK_ESPNOW_NATIVE_H
Loading
Loading