diff --git a/.vscode/cmake-variants.TEMPLATE.json b/.vscode/cmake-variants.TEMPLATE.json index 1adf55e95f..b2f1222576 100644 --- a/.vscode/cmake-variants.TEMPLATE.json +++ b/.vscode/cmake-variants.TEMPLATE.json @@ -91,6 +91,7 @@ "API_Windows.Devices.Adc": "OFF-default-ON-to-add-this-API", "API_System.Device.Dac": "OFF-default-ON-to-add-this-API", "API_Windows.Devices.Gpio": "OFF-default-ON-to-add-this-API", + "API_System.Device.Gpio": "OFF-default-ON-to-add-this-API", "API_Windows.Devices.I2c": "OFF-default-ON-to-add-this-API", "API_Windows.Devices.Pwm": "OFF-default-ON-to-add-this-API", "API_Windows.Devices.SerialCommunication": "OFF-default-ON-to-add-this-API", diff --git a/CMake/Modules/FindSystem.Device.Gpio.cmake b/CMake/Modules/FindSystem.Device.Gpio.cmake new file mode 100644 index 0000000000..e40574c3e3 --- /dev/null +++ b/CMake/Modules/FindSystem.Device.Gpio.cmake @@ -0,0 +1,58 @@ +# +# 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}/System.Device.Gpio) + + +# set include directories +list(APPEND System.Device.Gpio_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/CLR/Core) +list(APPEND System.Device.Gpio_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/CLR/Include) +list(APPEND System.Device.Gpio_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/HAL/Include) +list(APPEND System.Device.Gpio_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/PAL/Include) +list(APPEND System.Device.Gpio_INCLUDE_DIRS ${BASE_PATH_FOR_THIS_MODULE}) +list(APPEND System.Device.Gpio_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/System.Device.Gpio) + +# source files +set(System.Device.Gpio_SRCS + + sys_dev_gpio_native.cpp + # TODO add this here when Windows.Devices.Gpio is removed + # cpu_gpio.cpp + + sys_dev_gpio_native_System_Device_Gpio_GpioController.cpp + sys_dev_gpio_native_System_Device_Gpio_GpioPin.cpp + + # core source files + AsyncCompletions.cpp + AsyncContinuations.cpp + NativeEventDispatcher.cpp + InterruptHandler.cpp + Hardware.cpp +) + +foreach(SRC_FILE ${System.Device.Gpio_SRCS}) + set(System.Device.Gpio_SRC_FILE SRC_FILE-NOTFOUND) + find_file(System.Device.Gpio_SRC_FILE ${SRC_FILE} + PATHS + ${BASE_PATH_FOR_THIS_MODULE} + ${TARGET_BASE_LOCATION} + ${PROJECT_SOURCE_DIR}/src/System.Device.Gpio + + # core source files + ${PROJECT_SOURCE_DIR}/src/PAL/AsyncProcCall + ${PROJECT_SOURCE_DIR}/src/CLR/Core/NativeEventDispatcher + ${PROJECT_SOURCE_DIR}/src/CLR/Core/InterruptHandler + ${PROJECT_SOURCE_DIR}/src/CLR/Core/Hardware + + CMAKE_FIND_ROOT_PATH_BOTH + ) + # message("${SRC_FILE} >> ${System.Device.Gpio_SRC_FILE}") # debug helper + list(APPEND System.Device.Gpio_SOURCES ${System.Device.Gpio_SRC_FILE}) +endforeach() + +include(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(System.Device.Gpio DEFAULT_MSG System.Device.Gpio_INCLUDE_DIRS System.Device.Gpio_SOURCES) diff --git a/CMake/Modules/NF_NativeAssemblies.cmake b/CMake/Modules/NF_NativeAssemblies.cmake index c713e96bbf..6f6f37a64d 100644 --- a/CMake/Modules/NF_NativeAssemblies.cmake +++ b/CMake/Modules/NF_NativeAssemblies.cmake @@ -19,7 +19,8 @@ option(API_nanoFramework.System.Text "option for nanoFramework.System option(API_System.Math "option for System.Math") option(API_System.Net "option for System.Net") option(API_Windows.Devices.Adc "option for Windows.Devices.Adc API") -option(API_System.Device.Dac "option for System.Device.Dac API") +option(API_System.Device.Dac "option for System.Device.Dac API") +option(API_System.Device.Gpio "option for System.Device.Gpio API") option(API_Windows.Devices.Gpio "option for Windows.Devices.Gpio API") option(API_Windows.Devices.I2c "option for Windows.Devices.I2c API") option(API_Windows.Devices.Pwm "option for Windows.Devices.Pwm API") @@ -193,6 +194,12 @@ macro(ParseNativeAssemblies) PerformSettingsForApiEntry("System.Device.Dac") endif() + # System.Device.Gpio + if(API_System.Device.Gpio) + ##### API name here (doted name) + PerformSettingsForApiEntry("System.Device.Gpio") + endif() + # Windows.Devices.Gpio if(API_Windows.Devices.Gpio) ##### API name here (doted name) diff --git a/CMakeLists.txt b/CMakeLists.txt index 914c4f274a..9bbb3cafe9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -508,6 +508,13 @@ else() endif() +if(API_System.Device.Gpio) + set(HAL_USE_GPIO_OPTION TRUE CACHE INTERNAL "HAL GPIO for System.Device.Gpio") +else() + set(HAL_USE_GPIO_OPTION FALSE CACHE INTERNAL "HAL GPIO for System.Device.Gpio") +endif() + + if(API_Windows.Devices.Gpio) set(HAL_USE_GPIO_OPTION TRUE CACHE INTERNAL "HAL GPIO for Windows.Devices.Gpio") else() @@ -577,6 +584,7 @@ endif() # include nanoFramework.Runtime.Events API if( API_nanoFramework.Devices.OneWire OR API_System.Net OR + API_System.Device.Gpio OR API_Windows.Devices.Gpio OR API_Windows.Devices.SerialCommunication OR API_Windows.Networking.Sockets OR diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 2482c4011d..335ce58c97 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -159,32 +159,32 @@ jobs: matrix: MBN_QUAIL: BoardName: MBN_QUAIL - BuildOptions: -DTARGET_SERIES=STM32F4xx -DRTOS=CHIBIOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_HAS_SDCARD=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_nanoFramework.Devices.OneWire=ON -DAPI_Windows.Storage=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON + BuildOptions: -DTARGET_SERIES=STM32F4xx -DRTOS=CHIBIOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_HAS_SDCARD=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_System.Device.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_nanoFramework.Devices.OneWire=ON -DAPI_Windows.Storage=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON GccArm_Version: NeedsDFU: true NETDUINO3_WIFI: BoardName: NETDUINO3_WIFI - BuildOptions: -DTARGET_SERIES=STM32F4xx -DRTOS=CHIBIOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_HAS_SDCARD=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_System.Device.Dac=OFF -DAPI_nanoFramework.Devices.OneWire=ON -DAPI_Windows.Storage=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON + BuildOptions: -DTARGET_SERIES=STM32F4xx -DRTOS=CHIBIOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_HAS_SDCARD=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_System.Device.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_System.Device.Dac=OFF -DAPI_nanoFramework.Devices.OneWire=ON -DAPI_Windows.Storage=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON GccArm_Version: NeedsDFU: true ORGPAL_PALTHREE: BoardName: ORGPAL_PALTHREE - BuildOptions: -DTARGET_SERIES=STM32F7xx -DRTOS=CHIBIOS -DCHIBIOS_CONTRIB_REQUIRED=ON -DSTM32_CUBE_PACKAGE_REQUIRED=ON -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_HAS_USB_MSD=ON -DNF_FEATURE_HAS_SDCARD=ON -DNF_FEATURE_USE_SPIFFS=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_System.Device.Dac=ON -DAPI_System.Net=ON -DNF_SECURITY_MBEDTLS=ON -DAPI_Windows.Storage=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON + BuildOptions: -DTARGET_SERIES=STM32F7xx -DRTOS=CHIBIOS -DCHIBIOS_CONTRIB_REQUIRED=ON -DSTM32_CUBE_PACKAGE_REQUIRED=ON -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_HAS_USB_MSD=ON -DNF_FEATURE_HAS_SDCARD=ON -DNF_FEATURE_USE_SPIFFS=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_System.Device.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_System.Device.Dac=ON -DAPI_System.Net=ON -DNF_SECURITY_MBEDTLS=ON -DAPI_Windows.Storage=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON GccArm_Version: NeedsDFU: true ST_STM32F429I_DISCOVERY: BoardName: ST_STM32F429I_DISCOVERY - BuildOptions: -DTARGET_SERIES=STM32F4xx -DRTOS=CHIBIOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_nanoFramework.Devices.OneWire=ON -DAPI_nanoFramework.Devices.Can=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON + BuildOptions: -DTARGET_SERIES=STM32F4xx -DRTOS=CHIBIOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_System.Device.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_nanoFramework.Devices.OneWire=ON -DAPI_nanoFramework.Devices.Can=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON GccArm_Version: NeedsDFU: false ST_NUCLEO64_F091RC: BoardName: ST_NUCLEO64_F091RC - BuildOptions: -DTARGET_SERIES=STM32F0xx -DRTOS=CHIBIOS -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DUSE_RNG=OFF -DNF_PLATFORM_NO_CLR_TRACE=ON -DNF_CLR_NO_IL_INLINE=ON -DAPI_Hardware.Stm32=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_nanoFramework.System.Text=ON + BuildOptions: -DTARGET_SERIES=STM32F0xx -DRTOS=CHIBIOS -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DUSE_RNG=OFF -DNF_PLATFORM_NO_CLR_TRACE=ON -DNF_CLR_NO_IL_INLINE=ON -DAPI_Hardware.Stm32=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_System.Device.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_nanoFramework.System.Text=ON GccArm_Version: NeedsDFU: false ST_STM32F769I_DISCOVERY: BoardName: ST_STM32F769I_DISCOVERY - BuildOptions: -DTARGET_SERIES=STM32F7xx -DRTOS=CHIBIOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_HAS_SDCARD=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_System.Device.Dac=ON -DAPI_System.Net=ON -DNF_SECURITY_MBEDTLS=ON -DAPI_nanoFramework.Devices.OneWire=ON -DAPI_nanoFramework.Devices.Can=ON -DAPI_Windows.Storage=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON -DAPI_nanoFramework.Graphics=ON -DGRAPHICS_MEMORY=Graphics_Memory.cpp -DGRAPHICS_DISPLAY=Otm8009a_DSI_Video_Mode.cpp -DGRAPHICS_DISPLAY_INTERFACE=DSI_To_Display_Video_Mode.cpp -DTOUCHPANEL_DEVICE=ft6x06_I2C.cpp -DTOUCHPANEL_INTERFACE=I2C_To_TouchPanel.cpp + BuildOptions: -DTARGET_SERIES=STM32F7xx -DRTOS=CHIBIOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_HAS_SDCARD=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_System.Device.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_System.Device.Dac=ON -DAPI_System.Net=ON -DNF_SECURITY_MBEDTLS=ON -DAPI_nanoFramework.Devices.OneWire=ON -DAPI_nanoFramework.Devices.Can=ON -DAPI_Windows.Storage=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON -DAPI_nanoFramework.Graphics=ON -DGRAPHICS_MEMORY=Graphics_Memory.cpp -DGRAPHICS_DISPLAY=Otm8009a_DSI_Video_Mode.cpp -DGRAPHICS_DISPLAY_INTERFACE=DSI_To_Display_Video_Mode.cpp -DTOUCHPANEL_DEVICE=ft6x06_I2C.cpp -DTOUCHPANEL_INTERFACE=I2C_To_TouchPanel.cpp GccArm_Version: NeedsDFU: false @@ -226,7 +226,7 @@ jobs: matrix: ESP32_WROOM_32: BoardName: ESP32_WROOM_32 - BuildOptions: -DTARGET_SERIES=ESP32 -DRTOS=FREERTOS_ESP32 -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DNF_FEATURE_HAS_SDCARD=ON -DAPI_System.Math=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_System.Net=ON -DAPI_Windows.Devices.Wifi=ON -DAPI_Windows.Storage=ON -DNF_SECURITY_MBEDTLS=ON -DAPI_Hardware.Esp32=ON -DSUPPORT_ANY_BASE_CONVERSION=ON -DAPI_nanoFramework.Devices.OneWire=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON -DAPI_nanoFramework.Hardware.Esp32.Rmt=ON + BuildOptions: -DTARGET_SERIES=ESP32 -DRTOS=FREERTOS_ESP32 -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DNF_FEATURE_HAS_SDCARD=ON -DAPI_System.Math=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_System.Device.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_System.Net=ON -DAPI_Windows.Devices.Wifi=ON -DAPI_Windows.Storage=ON -DNF_SECURITY_MBEDTLS=ON -DAPI_Hardware.Esp32=ON -DSUPPORT_ANY_BASE_CONVERSION=ON -DAPI_nanoFramework.Devices.OneWire=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON -DAPI_nanoFramework.Hardware.Esp32.Rmt=ON variables: ESP32_TOOLCHAIN_PATH: $(Agent.TempDirectory)\ESP32_Tools\xtensa-esp32-elf @@ -270,7 +270,7 @@ jobs: matrix: NXP_MIMXRT1060_EVK: BoardName: NXP_MIMXRT1060_EVK - BuildOptions: -DTARGET_SERIES=IMXRT10xx -DRTOS=FREERTOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_HAS_SDCARD=ON -DAPI_System.Math=ON -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_System.Net=ON -DAPI_Windows.Storage=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.I2c=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON + BuildOptions: -DTARGET_SERIES=IMXRT10xx -DRTOS=FREERTOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_HAS_SDCARD=ON -DAPI_System.Math=ON -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_System.Device.Gpio=ON -DAPI_System.Net=ON -DAPI_Windows.Storage=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.I2c=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON GccArm_Version: NeedsSRECORD: true @@ -312,11 +312,11 @@ jobs: # disabled: waiting to update SDK to latest version with Sys Config # TI_CC3220SF_LAUNCHXL: # BoardName: TI_CC3220SF_LAUNCHXL - # BuildOptions: -DTARGET_SERIES=CC32xx -DRTOS=TI_SIMPLELINK -DSUPPORT_ANY_BASE_CONVERSION=OFF -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_WATCHDOG=OFF -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=OFF -DAPI_Windows.Devices.Adc=ON -DAPI_System.Net=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON + # BuildOptions: -DTARGET_SERIES=CC32xx -DRTOS=TI_SIMPLELINK -DSUPPORT_ANY_BASE_CONVERSION=OFF -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_WATCHDOG=OFF -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_System.Device.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=OFF -DAPI_Windows.Devices.Adc=ON -DAPI_System.Net=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON # GccArm_Version: TI_CC1352R1_LAUNCHXL: BoardName: TI_CC1352R1_LAUNCHXL - BuildOptions: -DTARGET_SERIES=CC13x2_26x2 -DRTOS=TI_SIMPLELINK -DSUPPORT_ANY_BASE_CONVERSION=OFF -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_WATCHDOG=OFF -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=OFF -DAPI_Windows.Devices.I2c=OFF -DAPI_Windows.Devices.Pwm=OFF -DAPI_Windows.Devices.SerialCommunication=OFF -DAPI_Windows.Devices.Adc=ON -DAPI_nanoFramework.TI.EasyLink=ON -DAPI_nanoFramework.Hardware.TI=ON + BuildOptions: -DTARGET_SERIES=CC13x2_26x2 -DRTOS=TI_SIMPLELINK -DSUPPORT_ANY_BASE_CONVERSION=OFF -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_WATCHDOG=OFF -DAPI_Windows.Devices.Gpio=ON -DAPI_System.Device.Gpio=ON -DAPI_Windows.Devices.Spi=OFF -DAPI_Windows.Devices.I2c=OFF -DAPI_Windows.Devices.Pwm=OFF -DAPI_Windows.Devices.SerialCommunication=OFF -DAPI_Windows.Devices.Adc=ON -DAPI_nanoFramework.TI.EasyLink=ON -DAPI_nanoFramework.Hardware.TI=ON GccArm_Version: variables: diff --git a/src/PAL/Include/CPU_GPIO_decl.h b/src/PAL/Include/CPU_GPIO_decl.h index 90928a7c7a..a0e4429489 100644 --- a/src/PAL/Include/CPU_GPIO_decl.h +++ b/src/PAL/Include/CPU_GPIO_decl.h @@ -33,6 +33,20 @@ typedef enum __nfpack GpioPinDriveMode GpioPinDriveMode_OutputOpenSourcePullDown = 7, } GpioPinDriveMode; +// from declaration at src\Windows.Devices.Gpio\win_dev_gpio_native.h +// TODO replace GpioPinDriveMode with this one when Windows.Devices.Gpio is removed +// typedef enum __nfpack PinMode +// { +// PinMode_Input = 0, +// PinMode_InputPullDown = 1, +// PinMode_InputPullUp = 2, +// PinMode_Output = 3, +// PinMode_OutputOpenDrain = 4, +// PinMode_OutputOpenDrainPullUp = 5, +// PinMode_OutputOpenSource = 6, +// PinMode_OutputOpenSourcePullDown = 7, +// } PinMode; + // from declaration at src\Windows.Devices.Gpio\win_dev_gpio_native.h typedef enum __nfpack GpioPinValue { diff --git a/src/System.Device.Gpio/sys_dev_gpio_native.cpp b/src/System.Device.Gpio/sys_dev_gpio_native.cpp new file mode 100644 index 0000000000..9dd3e9a98a --- /dev/null +++ b/src/System.Device.Gpio/sys_dev_gpio_native.cpp @@ -0,0 +1,107 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#include "sys_dev_gpio_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, + Library_sys_dev_gpio_native_System_Device_Gpio_GpioController::get_PinCount___I4, + NULL, + NULL, + NULL, + NULL, + Library_sys_dev_gpio_native_System_Device_Gpio_GpioController::DisposeNative___VOID, + NULL, + Library_sys_dev_gpio_native_System_Device_Gpio_GpioController::IsPinModeSupported___BOOLEAN__I4__SystemDeviceGpioPinMode, + Library_sys_dev_gpio_native_System_Device_Gpio_GpioController::IsPinOpen___BOOLEAN__I4, + NULL, + NULL, + NULL, + Library_sys_dev_gpio_native_System_Device_Gpio_GpioController::SetPinMode___VOID__I4__SystemDeviceGpioPinMode, + NULL, + NULL, + Library_sys_dev_gpio_native_System_Device_Gpio_GpioController::NativeRead___U1__I4, + Library_sys_dev_gpio_native_System_Device_Gpio_GpioController::NativeWrite___VOID__I4__U1, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + Library_sys_dev_gpio_native_System_Device_Gpio_GpioPin::Read___SystemDeviceGpioPinValue, + NULL, + NULL, + NULL, + NULL, + Library_sys_dev_gpio_native_System_Device_Gpio_GpioPin::Toggle___VOID, + NULL, + Library_sys_dev_gpio_native_System_Device_Gpio_GpioPin::DisposeNative___VOID, + Library_sys_dev_gpio_native_System_Device_Gpio_GpioPin::NativeIsDriveModeSupported___BOOLEAN__SystemDeviceGpioPinMode, + Library_sys_dev_gpio_native_System_Device_Gpio_GpioPin::NativeSetDriveMode___VOID__SystemDeviceGpioPinMode, + Library_sys_dev_gpio_native_System_Device_Gpio_GpioPin::NativeInit___BOOLEAN__I4, + Library_sys_dev_gpio_native_System_Device_Gpio_GpioPin::NativeSetDebounceTimeout___VOID, + Library_sys_dev_gpio_native_System_Device_Gpio_GpioPin::WriteNative___VOID__SystemDeviceGpioPinValue, + Library_sys_dev_gpio_native_System_Device_Gpio_GpioPin::NativeSetAlternateFunction___VOID__I4, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_System_Device_Gpio = +{ + "System.Device.Gpio", + 0x4F4DD7A8, + method_lookup, + { 100, 1, 0, 0 } +}; + +// clang-format on diff --git a/src/System.Device.Gpio/sys_dev_gpio_native.h b/src/System.Device.Gpio/sys_dev_gpio_native.h new file mode 100644 index 0000000000..0cd7e3dc80 --- /dev/null +++ b/src/System.Device.Gpio/sys_dev_gpio_native.h @@ -0,0 +1,104 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +#ifndef _SYS_DEV_GPIO_NATIVE_H_ +#define _SYS_DEV_GPIO_NATIVE_H_ + +#include +#include +#include +#include + +typedef enum __nfpack PinEventTypes +{ + PinEventTypes_None = 0, + PinEventTypes_Rising = 1, + PinEventTypes_Falling = 2, +} PinEventTypes; + +// moved to src\PAL\Include\CPU_GPIO_decl.h for convenience +// typedef enum __nfpack PinMode +// { +// PinMode_Input = 0, +// PinMode_InputPullDown = 1, +// PinMode_InputPullUp = 2, +// PinMode_Output = 3, +// PinMode_OutputOpenDrain = 4, +// PinMode_OutputOpenDrainPullUp = 5, +// PinMode_OutputOpenSource = 6, +// PinMode_OutputOpenSourcePullDown = 7, +// } PinMode; + +struct Library_sys_dev_gpio_native_System_Device_Gpio_PinValue +{ + static const int FIELD___value = 1; + + //--// +}; + +struct Library_sys_dev_gpio_native_System_Device_Gpio_GpioController +{ + static const int FIELD_STATIC__s_GpioPins = 0; + static const int FIELD_STATIC___syncLock = 1; + + static const int FIELD___disposedValue = 1; + static const int FIELD___NumberingScheme_k__BackingField = 2; + + NANOCLR_NATIVE_DECLARE(get_PinCount___I4); + NANOCLR_NATIVE_DECLARE(DisposeNative___VOID); + NANOCLR_NATIVE_DECLARE(IsPinModeSupported___BOOLEAN__I4__SystemDeviceGpioPinMode); + NANOCLR_NATIVE_DECLARE(IsPinOpen___BOOLEAN__I4); + NANOCLR_NATIVE_DECLARE(SetPinMode___VOID__I4__SystemDeviceGpioPinMode); + NANOCLR_NATIVE_DECLARE(NativeRead___U1__I4); + NANOCLR_NATIVE_DECLARE(NativeWrite___VOID__I4__U1); + + //--// + + static void GetGpioPin(CLR_INT32 index, CLR_RT_StackFrame &stack, CLR_RT_HeapBlock *&gpioPin); +}; + +struct Library_sys_dev_gpio_native_System_Device_Gpio_GpioPin +{ + static const int FIELD_STATIC__s_gpioPinEventManager = 2; + + static const int FIELD___syncLock = 1; + static const int FIELD___pinNumber = 2; + static const int FIELD___driveMode = 3; + static const int FIELD___debounceTimeout = 4; + static const int FIELD___callbacks = 5; + static const int FIELD___lastOutputValue = 6; + static const int FIELD___lastInputValue = 7; + static const int FIELD___disposedValue = 8; + + NANOCLR_NATIVE_DECLARE(Read___SystemDeviceGpioPinValue); + NANOCLR_NATIVE_DECLARE(Toggle___VOID); + NANOCLR_NATIVE_DECLARE(DisposeNative___VOID); + NANOCLR_NATIVE_DECLARE(NativeIsDriveModeSupported___BOOLEAN__SystemDeviceGpioPinMode); + NANOCLR_NATIVE_DECLARE(NativeSetDriveMode___VOID__SystemDeviceGpioPinMode); + NANOCLR_NATIVE_DECLARE(NativeSetDebounceTimeout___VOID); + NANOCLR_NATIVE_DECLARE(WriteNative___VOID__SystemDeviceGpioPinValue); + NANOCLR_NATIVE_DECLARE(NativeSetAlternateFunction___VOID__I4); + NANOCLR_NATIVE_DECLARE(NativeInit___BOOLEAN__I4); + + //--// + + static HRESULT ExtractDebounceTimeSpanValue(CLR_RT_HeapBlock &timeSpanValue, CLR_UINT64 &value); +}; + +struct Library_sys_dev_gpio_native_System_Device_Gpio_GpioPinBundle +{ + static const int FIELD__PinNumber = 1; + static const int FIELD__GpioPin = 2; + static const int FIELD__GpioEvents = 3; + static const int FIELD__GpioPinChange = 4; + static const int FIELD__GpioEventsHappening = 5; + + //--// +}; + +extern const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_System_Device_Gpio; + +#endif //_SYS_DEV_GPIO_NATIVE_H_ diff --git a/src/System.Device.Gpio/sys_dev_gpio_native_System_Device_Gpio_GpioController.cpp b/src/System.Device.Gpio/sys_dev_gpio_native_System_Device_Gpio_GpioController.cpp new file mode 100644 index 0000000000..bfb0950551 --- /dev/null +++ b/src/System.Device.Gpio/sys_dev_gpio_native_System_Device_Gpio_GpioController.cpp @@ -0,0 +1,210 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +#include "sys_dev_gpio_native.h" + +typedef Library_sys_dev_gpio_native_System_Device_Gpio_GpioPin GpioPin; +typedef Library_sys_dev_gpio_native_System_Device_Gpio_GpioPinBundle GpioPinBundle; + +HRESULT Library_sys_dev_gpio_native_System_Device_Gpio_GpioController::get_PinCount___I4(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + + // return value to the managed application + stack.SetResult_I4(CPU_GPIO_GetPinCount()); + + NANOCLR_NOCLEANUP_NOLABEL(); +} + +HRESULT Library_sys_dev_gpio_native_System_Device_Gpio_GpioController::DisposeNative___VOID(CLR_RT_StackFrame &stack) +{ + (void)stack; + + NANOCLR_HEADER(); + + CPU_GPIO_Uninitialize(); + + NANOCLR_NOCLEANUP_NOLABEL(); +} + +HRESULT Library_sys_dev_gpio_native_System_Device_Gpio_GpioController:: + IsPinModeSupported___BOOLEAN__I4__SystemDeviceGpioPinMode(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + + GpioPinDriveMode driveMode; + + GPIO_PIN pinNumber = (GPIO_PIN)stack.Arg1().NumericByRef().s4; + + driveMode = (GpioPinDriveMode)stack.Arg2().NumericByRef().s4; + + // Return value to the managed call + stack.SetResult_Boolean(CPU_GPIO_DriveModeSupported(pinNumber, driveMode)); + + NANOCLR_NOCLEANUP_NOLABEL(); +} + +HRESULT Library_sys_dev_gpio_native_System_Device_Gpio_GpioController::IsPinOpen___BOOLEAN__I4(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + + GPIO_PIN pinNumber = (GPIO_PIN)stack.Arg1().NumericByRef().s4; + + // Return value to the managed call + stack.SetResult_Boolean(CPU_GPIO_PinIsBusy(pinNumber)); + + NANOCLR_NOCLEANUP_NOLABEL(); +} + +HRESULT Library_sys_dev_gpio_native_System_Device_Gpio_GpioController::SetPinMode___VOID__I4__SystemDeviceGpioPinMode( + CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + + GPIO_PIN pinNumber; + GpioPinDriveMode driveMode; + bool validPin; + + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + if (pThis[FIELD___disposedValue].NumericByRef().u1 != 0) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } + + pinNumber = (GPIO_PIN)stack.Arg1().NumericByRef().s4; + driveMode = (GpioPinDriveMode)stack.Arg2().NumericByRef().s4; + + if (driveMode >= (int)GpioPinDriveMode_Output) + { + validPin = CPU_GPIO_EnableOutputPin(pinNumber, GpioPinValue_Low, (GpioPinDriveMode)driveMode); + } + else + { + validPin = CPU_GPIO_EnableInputPin(pinNumber, -1, NULL, NULL, GPIO_INT_EDGE_BOTH, (GpioPinDriveMode)driveMode); + } + + if (!validPin) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } + + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_sys_dev_gpio_native_System_Device_Gpio_GpioController::NativeRead___U1__I4(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + + GPIO_PIN pinNumber; + CLR_RT_HeapBlock *gpioPin = NULL; + + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + if (pThis[FIELD___disposedValue].NumericByRef().u1 != 0) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } + + pinNumber = (GPIO_PIN)stack.Arg1().NumericByRef().s4; + + // try to get GpioPin object + GetGpioPin(pinNumber, stack, gpioPin); + + if (gpioPin == NULL) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_OPERATION); + } + + // read pin and set result + stack.SetResult_U1(CPU_GPIO_GetPinState(pinNumber)); + + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_sys_dev_gpio_native_System_Device_Gpio_GpioController::NativeWrite___VOID__I4__U1( + CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + + GPIO_PIN pinNumber; + GpioPinValue state; + CLR_RT_HeapBlock *gpioPin = NULL; + + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + if (pThis[FIELD___disposedValue].NumericByRef().u1 != 0) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } + + pinNumber = (GPIO_PIN)stack.Arg1().NumericByRef().s4; + state = (GpioPinValue)stack.Arg2().NumericByRef().u1; + + // try to get GpioPin object + GetGpioPin(pinNumber, stack, gpioPin); + + if (gpioPin == NULL) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_OPERATION); + } + + // write to pin + CPU_GPIO_SetPinState(pinNumber, state); + + // store the output value in the field + gpioPin[GpioPin::FIELD___lastOutputValue].NumericByRef().s4 = state; + + NANOCLR_NOCLEANUP(); +} + +void Library_sys_dev_gpio_native_System_Device_Gpio_GpioController::GetGpioPin( + CLR_INT32 pinNumber, + CLR_RT_StackFrame &stack, + CLR_RT_HeapBlock *&gpioPin) +{ + CLR_IDX assemblyIdx; + CLR_INT32 index = 0; + CLR_RT_Assembly *thisAssembly = NULL; + CLR_RT_HeapBlock *gpioPinBundle = NULL; + CLR_RT_HeapBlock_ArrayList *gpioPins = NULL; + + // get "This" because we need to access the s_GpioPins field + CLR_RT_HeapBlock *pThis = stack.This(); + + // s_GpioPins it's a static field, need to access it through the assembly + assemblyIdx = pThis->ObjectCls().Assembly(); + thisAssembly = g_CLR_RT_TypeSystem.m_assemblies[assemblyIdx - 1]; + + // finally dereference s_GpioPins (as an ArrayList) + gpioPins = (CLR_RT_HeapBlock_ArrayList *)thisAssembly->GetStaticField(FIELD_STATIC__s_GpioPins)->Dereference(); + + do + { + // try to get item from the array list + gpioPins->GetItem(index++, gpioPinBundle); + + if (gpioPinBundle == NULL) + { + // no more items in the array + break; + } + + // check if the pin number matches the one we are looking for + if (gpioPinBundle[GpioPinBundle::FIELD__PinNumber].NumericByRef().s4 == pinNumber) + { + // matches, get the GpioPin + gpioPin = gpioPinBundle[GpioPinBundle::FIELD__GpioPin].Dereference(); + + // done here + break; + } + + } while (true); +} diff --git a/src/System.Device.Gpio/sys_dev_gpio_native_System_Device_Gpio_GpioPin.cpp b/src/System.Device.Gpio/sys_dev_gpio_native_System_Device_Gpio_GpioPin.cpp new file mode 100644 index 0000000000..48ea057113 --- /dev/null +++ b/src/System.Device.Gpio/sys_dev_gpio_native_System_Device_Gpio_GpioPin.cpp @@ -0,0 +1,266 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +#include +#include +#include "sys_dev_gpio_native_target.h" +#include "nf_rt_events_native.h" +#include "sys_dev_gpio_native.h" + +// declared here as external +// the implementation will be moved here when Windows.Devices.Gpio is removed +extern void Gpio_Interupt_ISR(GPIO_PIN pinNumber, bool pinState); + +HRESULT Library_sys_dev_gpio_native_System_Device_Gpio_GpioPin::Read___SystemDeviceGpioPinValue( + CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + if (pThis[FIELD___disposedValue].NumericByRef().u1 != 0) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } + + GPIO_PIN pinNumber = (GPIO_PIN)pThis[FIELD___pinNumber].NumericByRefConst().s4; + + stack.SetResult_I4(CPU_GPIO_GetPinState(pinNumber)); + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_sys_dev_gpio_native_System_Device_Gpio_GpioPin::Toggle___VOID(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + // check if object has been disposed + if (pThis[FIELD___disposedValue].NumericByRef().u1 != 0) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } + + GPIO_PIN pinNumber = (GPIO_PIN)pThis[FIELD___pinNumber].NumericByRefConst().s4; + GpioPinDriveMode driveMode = (GpioPinDriveMode)pThis[FIELD___driveMode].NumericByRefConst().s4; + + // sanity check for drive mode set to output so we don't mess up writing to an input pin + if (driveMode >= GpioPinDriveMode_Output) + { + // Not all lower level API offer a 'toggle', so need to rely on the last output value field and toggle that + // one + GpioPinValue newState = + (GpioPinValue)(GpioPinValue_High ^ (GpioPinValue)pThis[FIELD___lastOutputValue].NumericByRef().s4); + + // ...write back to the GPIO... + CPU_GPIO_SetPinState(pinNumber, newState); + + // ... and finally store it + pThis[FIELD___lastOutputValue].NumericByRef().s4 = newState; + } + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_sys_dev_gpio_native_System_Device_Gpio_GpioPin::DisposeNative___VOID(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + // set pin to input to save power + // clear interrupts + // releases the pin + GPIO_PIN pinNumber = (GPIO_PIN)pThis[FIELD___pinNumber].NumericByRefConst().s4; + + CPU_GPIO_DisablePin(pinNumber, GpioPinDriveMode_Input, 0); + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_sys_dev_gpio_native_System_Device_Gpio_GpioPin:: + NativeIsDriveModeSupported___BOOLEAN__SystemDeviceGpioPinMode(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + GPIO_PIN pinNumber = (GPIO_PIN)pThis[FIELD___pinNumber].NumericByRefConst().s4; + + GpioPinDriveMode driveMode = (GpioPinDriveMode)stack.Arg1().NumericByRef().s4; + + // Return value to the managed application + stack.SetResult_Boolean(CPU_GPIO_DriveModeSupported(pinNumber, driveMode)); + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_sys_dev_gpio_native_System_Device_Gpio_GpioPin::NativeSetDriveMode___VOID__SystemDeviceGpioPinMode( + CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + { + bool validPin; + CLR_UINT64 debounceTimeoutMilsec; + bool callbacksRegistered = false; + + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + if (pThis[FIELD___disposedValue].NumericByRef().u1 != 0) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } + + GPIO_PIN pinNumber = (GPIO_PIN)pThis[FIELD___pinNumber].NumericByRefConst().s4; + GpioPinDriveMode driveMode = (GpioPinDriveMode)stack.Arg1().NumericByRef().s4; + + if (driveMode >= (int)GpioPinDriveMode_Output) + { + validPin = CPU_GPIO_EnableOutputPin(pinNumber, GpioPinValue_Low, driveMode); + } + else + { + NANOCLR_CHECK_HRESULT(ExtractDebounceTimeSpanValue(pThis[FIELD___debounceTimeout], debounceTimeoutMilsec)); + + // flag to determine if there are any callbacks registered in managed code + // this is use to determine if there is any need to setup and process INT handler + callbacksRegistered = (pThis[FIELD___callbacks].Dereference() != NULL); + + validPin = CPU_GPIO_EnableInputPin( + pinNumber, + debounceTimeoutMilsec, + callbacksRegistered ? Gpio_Interupt_ISR : NULL, + NULL, + GPIO_INT_EDGE_BOTH, + driveMode); + } + + if (!validPin) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } + + // protect this from GC so that the callback is where it's supposed to + CLR_RT_ProtectFromGC gc(*pThis); + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_sys_dev_gpio_native_System_Device_Gpio_GpioPin::NativeSetDebounceTimeout___VOID( + CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + { + CLR_UINT64 debounceTimeoutMilsec; + + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + GPIO_PIN pinNumber = (GPIO_PIN)pThis[FIELD___pinNumber].NumericByRefConst().s4; + + NANOCLR_CHECK_HRESULT(ExtractDebounceTimeSpanValue(pThis[FIELD___debounceTimeout], debounceTimeoutMilsec)); + + // developer note: + // the following call will FAIL if the pin hasn't been previously setup as input + // that's OK because the debounce timeout will be eventually set when the pin is configured + CPU_GPIO_SetPinDebounce(pinNumber, debounceTimeoutMilsec); + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_sys_dev_gpio_native_System_Device_Gpio_GpioPin::WriteNative___VOID__SystemDeviceGpioPinValue( + CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + // check if object has been disposed + if (pThis[FIELD___disposedValue].NumericByRef().u1 != 0) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } + + GPIO_PIN pinNumber = (GPIO_PIN)pThis[FIELD___pinNumber].NumericByRefConst().s4; + GpioPinDriveMode driveMode = (GpioPinDriveMode)pThis[FIELD___driveMode].NumericByRefConst().s4; + + GpioPinValue state = (GpioPinValue)stack.Arg1().NumericByRef().s4; + + // sanity check for drive mode set to output so we don't mess up writing to an input pin + if ((driveMode >= GpioPinDriveMode_Output)) + { + CPU_GPIO_SetPinState(pinNumber, state); + + // store the output value in the field + pThis[FIELD___lastOutputValue].NumericByRef().s4 = state; + } + else + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_sys_dev_gpio_native_System_Device_Gpio_GpioPin::NativeSetAlternateFunction___VOID__I4( + CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + // check if object has been disposed + if (pThis[FIELD___disposedValue].NumericByRef().u1 != 0) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } + + // get pin number and take the port and pad references from that one + int16_t pinNumber = pThis[FIELD___pinNumber].NumericByRefConst().s4; + + // get alternate function argument + int32_t alternateFunction = stack.Arg1().NumericByRef().s4; + + CPU_GPIO_DisablePin(pinNumber, GpioPinDriveMode_Input, alternateFunction); + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_sys_dev_gpio_native_System_Device_Gpio_GpioPin::NativeInit___BOOLEAN__I4(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + { + GPIO_PIN pinNumber = (GPIO_PIN)stack.Arg1().NumericByRef().s4; + + // Return value to the managed application + stack.SetResult_Boolean(CPU_GPIO_ReservePin(pinNumber, true)); + } + NANOCLR_NOCLEANUP_NOLABEL(); +} + +HRESULT Library_sys_dev_gpio_native_System_Device_Gpio_GpioPin::ExtractDebounceTimeSpanValue( + CLR_RT_HeapBlock &timeSpanValue, + CLR_UINT64 &value) +{ + NANOCLR_HEADER(); + { + // debounceTimeout field its a TimeSpan, which is a primitive type stored as an heap block, therefore needs to + // be accessed indirectly + CLR_INT64 *debounceValue = Library_corlib_native_System_TimeSpan::GetValuePtr(timeSpanValue); + FAULT_ON_NULL(debounceValue); + + value = *(CLR_UINT64 *)debounceValue / TIME_CONVERSION__TO_MILLISECONDS; + } + NANOCLR_NOCLEANUP(); +} diff --git a/src/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioPin.cpp b/src/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioPin.cpp index d9483167e2..cca552fd30 100644 --- a/src/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioPin.cpp +++ b/src/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioPin.cpp @@ -12,6 +12,7 @@ /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// +// move this to sys_dev_gpio_native_System_Device_Gpio_GpioPin when Windows.Devices.Gpio is removed void Gpio_Interupt_ISR(GPIO_PIN pinNumber, bool pinState) { // if handle registered then post a managed event with the current pin reading diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/cmake-variants.json b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/cmake-variants.json index ce11100a08..e39d670bc0 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/cmake-variants.json +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/cmake-variants.json @@ -44,6 +44,7 @@ "API_System.Math": "ON", "API_Hardware.Stm32": "ON", "API_Windows.Devices.Gpio": "ON", + "API_System.Device.Gpio": "ON", "API_Windows.Devices.Spi": "ON", "API_Windows.Devices.I2c": "ON", "API_Windows.Devices.Pwm": "ON", diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/cmake-variants.json b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/cmake-variants.json index 7716d7cbe9..fe7c320ea8 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/cmake-variants.json +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/cmake-variants.json @@ -47,6 +47,7 @@ "API_System.Math": "ON", "API_Hardware.Stm32": "ON", "API_Windows.Devices.Gpio": "ON", + "API_System.Device.Gpio": "ON", "API_Windows.Devices.Spi": "ON", "API_Windows.Devices.I2c": "ON", "API_Windows.Devices.Pwm": "ON", diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/cmake-variants.json b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/cmake-variants.json index 8850243b86..802063f6b7 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/cmake-variants.json +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/cmake-variants.json @@ -52,6 +52,7 @@ "API_System.Math": "ON", "API_Hardware.Stm32": "ON", "API_Windows.Devices.Gpio": "ON", + "API_System.Device.Gpio": "ON", "API_Windows.Devices.Spi": "ON", "API_Windows.Devices.I2c": "ON", "API_Windows.Devices.Pwm": "ON", diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/cmake-variants.json b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/cmake-variants.json index 6b887e165d..5d85c2d080 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/cmake-variants.json +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/cmake-variants.json @@ -45,6 +45,7 @@ "NF_BUILD_RTM": "OFF", "API_Hardware.Stm32": "ON", "API_Windows.Devices.Gpio": "ON", + "API_System.Device.Gpio": "ON", "API_Windows.Devices.Spi": "ON", "API_Windows.Devices.I2c": "ON", "API_Windows.Devices.Pwm": "ON", diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/cmake-variants.json b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/cmake-variants.json index a164d85406..490f31ae56 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/cmake-variants.json +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/cmake-variants.json @@ -45,6 +45,7 @@ "API_System.Math": "ON", "API_Hardware.Stm32": "ON", "API_Windows.Devices.Gpio": "ON", + "API_System.Device.Gpio": "ON", "API_Windows.Devices.Spi": "ON", "API_Windows.Devices.I2c": "ON", "API_Windows.Devices.Pwm": "ON", diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/cmake-variants.json b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/cmake-variants.json index 8df41513fb..e7210c6e3a 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/cmake-variants.json +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/cmake-variants.json @@ -50,6 +50,7 @@ "API_System.Math": "ON", "API_Hardware.Stm32": "ON", "API_Windows.Devices.Gpio": "ON", + "API_System.Device.Gpio": "ON", "API_Windows.Devices.Spi": "ON", "API_Windows.Devices.I2c": "ON", "API_Windows.Devices.Pwm": "ON", diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/System.Device.Gpio/sys_dev_gpio_native_target.h b/targets/CMSIS-OS/ChibiOS/nanoCLR/System.Device.Gpio/sys_dev_gpio_native_target.h new file mode 100644 index 0000000000..fe2ed5c21b --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/System.Device.Gpio/sys_dev_gpio_native_target.h @@ -0,0 +1,12 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + + +#ifndef _SYS_DEV_GPIO_NATIVE_TARGET_H_ +#define _SYS_DEV_GPIO_NATIVE_TARGET_H_ + +#include + +#endif //_SYS_DEV_GPIO_NATIVE_TARGET_H_ diff --git a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/cmake-variants.json b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/cmake-variants.json index 394a5bfb09..f52f491f8f 100644 --- a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/cmake-variants.json +++ b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/cmake-variants.json @@ -43,6 +43,7 @@ "NF_FEATURE_RTC": "ON", "NF_FEATURE_HAS_CONFIG_BLOCK": "ON", "API_Windows.Devices.Gpio": "ON", + "API_System.Device.Gpio": "ON", "API_Windows.Devices.Spi": "OFF", "API_Windows.Devices.I2c": "OFF", "API_Windows.Devices.Adc": "OFF", diff --git a/targets/FreeRTOS/NXP/nanoCLR/System.Device.Gpio/sys_dev_gpio_native_target.h b/targets/FreeRTOS/NXP/nanoCLR/System.Device.Gpio/sys_dev_gpio_native_target.h new file mode 100644 index 0000000000..fe2ed5c21b --- /dev/null +++ b/targets/FreeRTOS/NXP/nanoCLR/System.Device.Gpio/sys_dev_gpio_native_target.h @@ -0,0 +1,12 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + + +#ifndef _SYS_DEV_GPIO_NATIVE_TARGET_H_ +#define _SYS_DEV_GPIO_NATIVE_TARGET_H_ + +#include + +#endif //_SYS_DEV_GPIO_NATIVE_TARGET_H_ diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/cmake-variants.json b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/cmake-variants.json index b3a6d906b8..ad09cacc81 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/cmake-variants.json +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/cmake-variants.json @@ -51,6 +51,7 @@ "API_Windows.Devices.Adc": "ON", "API_System.Device.Dac": "OFF", "API_Windows.Devices.Gpio": "ON", + "API_System.Device.Gpio": "ON", "API_Windows.Devices.I2c": "ON", "API_Windows.Devices.Pwm": "ON", "API_Windows.Devices.SerialCommunication": "ON", diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/System.Device.Gpio/sys_dev_gpio_native_target.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/System.Device.Gpio/sys_dev_gpio_native_target.h new file mode 100644 index 0000000000..fe2ed5c21b --- /dev/null +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/System.Device.Gpio/sys_dev_gpio_native_target.h @@ -0,0 +1,12 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + + +#ifndef _SYS_DEV_GPIO_NATIVE_TARGET_H_ +#define _SYS_DEV_GPIO_NATIVE_TARGET_H_ + +#include + +#endif //_SYS_DEV_GPIO_NATIVE_TARGET_H_ diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/cmake-variants.json b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/cmake-variants.json index 29001e1e22..6fc0de8a62 100644 --- a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/cmake-variants.json +++ b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/cmake-variants.json @@ -41,6 +41,7 @@ "NF_BUILD_RTM": "OFF", "API_System.Math": "ON", "API_Windows.Devices.Gpio": "ON", + "API_System.Device.Gpio": "ON", "API_Windows.Devices.Spi": "OFF", "API_Windows.Devices.I2c": "OFF", "API_Windows.Devices.Pwm": "OFF", diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/cmake-variants.json b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/cmake-variants.json index 21aa5aa161..4375758c58 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/cmake-variants.json +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/cmake-variants.json @@ -40,6 +40,7 @@ "NF_BUILD_RTM": "OFF", "API_System.Math": "ON", "API_Windows.Devices.Gpio": "ON", + "API_System.Device.Gpio": "ON", "API_Windows.Devices.Spi": "ON", "API_Windows.Devices.I2c": "ON", "API_Windows.Devices.Pwm": "ON", diff --git a/targets/TI-SimpleLink/nanoCLR/System.Device.Gpio/sys_dev_gpio_native_target.h b/targets/TI-SimpleLink/nanoCLR/System.Device.Gpio/sys_dev_gpio_native_target.h new file mode 100644 index 0000000000..fe2ed5c21b --- /dev/null +++ b/targets/TI-SimpleLink/nanoCLR/System.Device.Gpio/sys_dev_gpio_native_target.h @@ -0,0 +1,12 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + + +#ifndef _SYS_DEV_GPIO_NATIVE_TARGET_H_ +#define _SYS_DEV_GPIO_NATIVE_TARGET_H_ + +#include + +#endif //_SYS_DEV_GPIO_NATIVE_TARGET_H_