diff --git a/CMake/Modules/FindnanoFramework.Hardware.Esp32.cmake b/CMake/Modules/FindnanoFramework.Hardware.Esp32.cmake index e5a6bd3af0..5c826af444 100644 --- a/CMake/Modules/FindnanoFramework.Hardware.Esp32.cmake +++ b/CMake/Modules/FindnanoFramework.Hardware.Esp32.cmake @@ -20,7 +20,7 @@ set(nanoFramework.Hardware.Esp32_SRCS nanoFramework_hardware_esp32_native.cpp nanoFramework_hardware_esp32_native_Hardware_Esp32_sleep.cpp nanoFramework_hardware_esp32_native_Hardware_Esp32_Logging.cpp - + nanoFramework_hardware_esp32_native_Hardware_Esp32_HighResTimer.cpp ) foreach(SRC_FILE ${nanoFramework.Hardware.Esp32_SRCS}) diff --git a/targets/FreeRTOS/ESP32_DevKitC/Include/esp32_os.h b/targets/FreeRTOS/ESP32_DevKitC/Include/esp32_os.h index a6da257dcf..22daa07d70 100644 --- a/targets/FreeRTOS/ESP32_DevKitC/Include/esp32_os.h +++ b/targets/FreeRTOS/ESP32_DevKitC/Include/esp32_os.h @@ -20,6 +20,7 @@ #include "esp_wpa2.h" #include "esp_eth.h" #include "esp_event_loop.h" +#include "esp_timer.h" #include "spi_master.h" #include "gpio.h" @@ -27,7 +28,7 @@ #include "uart.h" #include "ledc.h" #include "adc.h" - +#include "timer.h" // Uncomment to support Ethernet //#define ESP32_ETHERNET_SUPPORT 1 diff --git a/targets/FreeRTOS/ESP32_DevKitC/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native.cpp b/targets/FreeRTOS/ESP32_DevKitC/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native.cpp index a1c4016a5c..9ba921dcbe 100644 --- a/targets/FreeRTOS/ESP32_DevKitC/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native.cpp +++ b/targets/FreeRTOS/ESP32_DevKitC/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) 2018 The nanoFramework project contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // @@ -33,16 +33,44 @@ static const CLR_RT_MethodHandler method_lookup[] = Library_nanoFramework_hardware_esp32_native_nanoFramework_Hardware_Esp32_Sleep::NativeGetWakeupTouchpad___STATIC__nanoFrameworkHardwareEsp32SleepTouchPad, NULL, NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + Library_nanoFramework_hardware_esp32_native_nanoFramework_Hardware_Esp32_HighResTimer::NativeEspTimerCreate___I4, + Library_nanoFramework_hardware_esp32_native_nanoFramework_Hardware_Esp32_HighResTimer::NativeEspTimerDispose___VOID, + Library_nanoFramework_hardware_esp32_native_nanoFramework_Hardware_Esp32_HighResTimer::NativeStop___VOID, + Library_nanoFramework_hardware_esp32_native_nanoFramework_Hardware_Esp32_HighResTimer::NativeStartOneShot___VOID__U8, + Library_nanoFramework_hardware_esp32_native_nanoFramework_Hardware_Esp32_HighResTimer::NativeStartPeriodic___VOID__U8, + NULL, + Library_nanoFramework_hardware_esp32_native_nanoFramework_Hardware_Esp32_HighResTimer::NativeGetCurrent___STATIC__U8, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, }; const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_nanoFramework_Hardware_Esp32 = { "nanoFramework.Hardware.Esp32", - 0x3903FAA7, + 0xFF4537C1, method_lookup, - { 1, 0, 0, 0} + { 1, 0, 0, 0 } }; - diff --git a/targets/FreeRTOS/ESP32_DevKitC/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native.h b/targets/FreeRTOS/ESP32_DevKitC/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native.h index d421bc4957..c56714ea44 100644 --- a/targets/FreeRTOS/ESP32_DevKitC/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native.h +++ b/targets/FreeRTOS/ESP32_DevKitC/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native.h @@ -36,6 +36,45 @@ struct Library_nanoFramework_hardware_esp32_native_nanoFramework_Hardware_Esp32_ }; +struct Library_nanoFramework_hardware_esp32_native_nanoFramework_Hardware_Esp32_HighResEventListener +{ + static const int FIELD__HighResTimers = 1; + + + //--// + +}; + +struct Library_nanoFramework_hardware_esp32_native_nanoFramework_Hardware_Esp32_HighResTimer +{ + static const int FIELD_STATIC__s_eventListener = 0; + + static const int FIELD___timerHandle = 1; + static const int FIELD___disposedValue = 2; + static const int FIELD___syncLock = 3; + static const int FIELD__OnHighResTimerExpired = 4; + + NANOCLR_NATIVE_DECLARE(NativeEspTimerCreate___I4); + NANOCLR_NATIVE_DECLARE(NativeEspTimerDispose___VOID); + NANOCLR_NATIVE_DECLARE(NativeStop___VOID); + NANOCLR_NATIVE_DECLARE(NativeStartOneShot___VOID__U8); + NANOCLR_NATIVE_DECLARE(NativeStartPeriodic___VOID__U8); + NANOCLR_NATIVE_DECLARE(NativeGetCurrent___STATIC__U8); + + //--// + +}; + +struct Library_nanoFramework_hardware_esp32_native_nanoFramework_Hardware_Esp32_HighResTimerEvent +{ + static const int FIELD__EventType = 3; + static const int FIELD__TimerHandle = 4; + + + //--// + +}; + extern const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_nanoFramework_Hardware_Esp32; #endif //_HARDWARE_ESP32_NATIVE_H_ diff --git a/targets/FreeRTOS/ESP32_DevKitC/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native_Hardware_Esp32_HighResTimer.cpp b/targets/FreeRTOS/ESP32_DevKitC/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native_Hardware_Esp32_HighResTimer.cpp new file mode 100644 index 0000000000..c13242f9f2 --- /dev/null +++ b/targets/FreeRTOS/ESP32_DevKitC/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native_Hardware_Esp32_HighResTimer.cpp @@ -0,0 +1,145 @@ +// +// Copyright (c) 2018 The nanoFramework project contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +#include "nanoFramework_hardware_esp32_native.h" + +#define MAX_HRTIMERS 10 + +esp_timer_handle_t hrtimers[MAX_HRTIMERS] = {}; + +////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// !!! KEEP IN SYNC WITH nanoFramework.Hardware.Esp32.HighResTimerEventType (in managed code) !!! // +////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +enum HighResTimerEventType +{ + TimerExpired = 101 +}; + +static int FindNextTimerIndex() +{ + for( int index=0; index